1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492 |
- #pragma warning(push)
- #pragma warning(disable:4146)
- #pragma warning(disable:4996)
- #pragma warning(disable:4800)
- #pragma warning(disable:4244)
- #include "DbgModule.h"
- #include "DWARFInfo.h"
- #include <windows.h>
- #include <stddef.h>
- #include <stdio.h>
- #include <string>
- #include <inttypes.h>
- #include <assert.h>
- #include <vector>
- #include "WinDebugger.h"
- #include "DebugManager.h"
- #include "DebugTarget.h"
- #include "COFFData.h"
- #include "Compiler/BfDemangler.h"
- #include "BeefySysLib/util/Hash.h"
- #include "BeefySysLib/util/BeefPerf.h"
- #include "DbgSymSrv.h"
- #include "MiniDumpDebugger.h"
- #pragma warning(pop)
- #pragma warning(disable:4996)
- #include "BeefySysLib/util/AllocDebug.h"
- USING_NS_BF_DBG;
- void SetBreakpoint(int64_t address);
- NS_BF_DBG_BEGIN
- #ifdef BF_DBG_32
- typedef PEOptionalHeader32 PEOptionalHeader;
- typedef PE_NTHeaders32 PE_NTHeaders;
- #else
- typedef PEOptionalHeader64 PEOptionalHeader;
- typedef PE_NTHeaders64 PE_NTHeaders;
- #endif
- #define GET(T) *((T*)(data += sizeof(T)) - 1)
- #define GET_FROM(ptr, T) *((T*)(ptr += sizeof(T)) - 1)
- //////////////////////////////////////////////////////////////////////////
- DbgCompileUnit::DbgCompileUnit(DbgModule* dbgModule)
- {
- mDbgModule = dbgModule;
- mLanguage = DbgLanguage_Unknown;
- mGlobalBlock = mDbgModule->mAlloc.Alloc<DbgBlock>();
- mGlobalType = mDbgModule->mAlloc.Alloc<DbgType>();
- mGlobalType->mTypeCode = DbgType_Root;
- mGlobalType->mPriority = DbgTypePriority_Primary_Explicit;
- mGlobalType->mCompileUnit = this;
- mLowPC = (addr_target)-1;
- mHighPC = 0;
- //mDoPrimaryRemapping = true;
- mNeedsLineDataFixup = true;
- mWasHotReplaced = false;
- mIsMaster = false;
- }
- //////////////////////////////////////////////////////////////////////////
- addr_target DbgLineDataEx::GetAddress()
- {
- return mSubprogram->GetLineAddr(*mLineData);
- }
- DbgSrcFile* DbgLineDataEx::GetSrcFile()
- {
- auto inlineRoot = mSubprogram->GetRootInlineParent();
- return inlineRoot->mLineInfo->mContexts[mLineData->mCtxIdx].mSrcFile;
- }
- addr_target DbgSubprogram::GetLineAddr(const DbgLineData& lineData)
- {
- return (addr_target)(lineData.mRelAddress + mCompileUnit->mDbgModule->mImageBase);
- }
- DbgSubprogram* DbgSubprogram::GetLineInlinee(const DbgLineData& lineData)
- {
- auto inlineRoot = GetRootInlineParent();
- return inlineRoot->mLineInfo->mContexts[lineData.mCtxIdx].mInlinee;
- }
- DbgSrcFile* DbgSubprogram::GetLineSrcFile(const DbgLineData& lineData)
- {
- auto inlineRoot = GetRootInlineParent();
- return inlineRoot->mLineInfo->mContexts[lineData.mCtxIdx].mSrcFile;
- }
- bool DbgSubprogram::HasValidLines()
- {
- auto inlineRoot = GetRootInlineParent();
- for (int lineIdx = 0; lineIdx < (int)inlineRoot->mLineInfo->mLines.size(); lineIdx++)
- {
- auto& lineInfo = inlineRoot->mLineInfo->mLines[lineIdx];
- if (lineInfo.mColumn >= 0)
- return true;
- }
- return false;
- }
- void DbgSubprogram::PopulateSubprogram()
- {
- if (mDeferredInternalsSize == 0)
- return;
- mCompileUnit->mDbgModule->PopulateSubprogram(this);
- }
- //////////////////////////////////////////////////////////////////////////
- DbgLineDataBuilder::DbgLineDataBuilder(DbgModule* dbgModule)
- {
- mDbgModule = dbgModule;
- mCurSubprogram = NULL;
- mCurRecord = NULL;
- }
- DbgLineData* DbgLineDataBuilder::Add(DbgCompileUnit* compileUnit, DbgLineData& lineData, DbgSrcFile* srcFile, DbgSubprogram* inlinee)
- {
- addr_target address = (addr_target)(lineData.mRelAddress + mDbgModule->mImageBase);
- if ((compileUnit->mLowPC != (addr_target)-1) && ((address < (addr_target)compileUnit->mLowPC) || (address >= (addr_target)compileUnit->mHighPC)))
- return NULL;
- if ((mCurSubprogram == NULL) || (address < mCurSubprogram->mBlock.mLowPC) || (address >= mCurSubprogram->mBlock.mHighPC))
- {
- DbgSubprogramMapEntry* mapEntry = mDbgModule->mDebugTarget->mSubprogramMap.Get(address, DBG_MAX_LOOKBACK);
- if (mapEntry != NULL)
- {
- mCurSubprogram = mapEntry->mEntry;
- if (address > mCurSubprogram->mBlock.mHighPC)
- mCurSubprogram = NULL;
- if (mCurSubprogram != NULL)
- {
- SubprogramRecord** recordPtr = NULL;
- if (mRecords.TryAdd(mCurSubprogram, NULL, &recordPtr))
- {
- // It's not too expensive to over-reserve here, because these are just temporary structures that get copied
- // exactly sized when we Commit
- mCurRecord = mAlloc.Alloc<SubprogramRecord>();
- *recordPtr = mCurRecord;
- mCurRecord->mContexts.mAlloc = &mAlloc;
- mCurRecord->mContexts.Reserve(16);
- mCurRecord->mLines.mAlloc = &mAlloc;
- mCurRecord->mLines.Reserve(128);
- mCurRecord->mCurContext = -1;
- mCurRecord->mHasInlinees = false;
- }
- else
- mCurRecord = *recordPtr;
- }
- else
- mCurRecord = NULL;
- }
- }
- if (mCurSubprogram == NULL)
- return NULL;
- bool needsNewCtx = false;
- if (mCurRecord->mCurContext == -1)
- {
- needsNewCtx = true;
- }
- else
- {
- auto& curContext = mCurRecord->mContexts[mCurRecord->mCurContext];
- if ((curContext.mInlinee != inlinee) || (curContext.mSrcFile != srcFile))
- {
- needsNewCtx = true;
- for (int ctxIdx = 0; ctxIdx < (int)mCurRecord->mContexts.size(); ctxIdx++)
- {
- auto& ctx = mCurRecord->mContexts[ctxIdx];
- if ((ctx.mInlinee == inlinee) && (ctx.mSrcFile == srcFile))
- {
- needsNewCtx = false;
- mCurRecord->mCurContext = ctxIdx;
- break;
- }
- }
- }
- }
- if (needsNewCtx)
- {
- DbgLineInfoCtx ctx;
- ctx.mInlinee = inlinee;
- ctx.mSrcFile = srcFile;
- if (inlinee != NULL)
- mCurRecord->mHasInlinees = true;
- mCurRecord->mContexts.Add(ctx);
- mCurRecord->mCurContext = (int)mCurRecord->mContexts.size() - 1;
- }
- lineData.mCtxIdx = mCurRecord->mCurContext;
- if ((mCurSubprogram->mPrologueSize > 0) && (mCurRecord->mLines.size() == 1) && (inlinee == NULL))
- {
- auto& firstLine = mCurRecord->mLines[0];
- auto dbgStartAddr = firstLine.mRelAddress + mCurSubprogram->mPrologueSize;
- if (lineData.mRelAddress != dbgStartAddr)
- {
- DbgLineData dbgStartLine = firstLine;
- dbgStartLine.mRelAddress = dbgStartAddr;
- mCurRecord->mLines.Add(dbgStartLine);
- }
- firstLine.mColumn = -2; // Marker for 'in prologue'
- }
- if (inlinee != NULL)
- {
- if (inlinee->mInlineeInfo->mFirstLineData.mRelAddress == 0)
- inlinee->mInlineeInfo->mFirstLineData = lineData;
- inlinee->mInlineeInfo->mLastLineData = lineData;
- }
- mCurRecord->mLines.Add(lineData);
- return &mCurRecord->mLines.back();
- }
- void DbgLineDataBuilder::Commit()
- {
- HashSet<DbgSrcFile*> usedSrcFiles;
- for (auto& recordKV : mRecords)
- {
- auto dbgSubprogram = recordKV.mKey;
- auto record = recordKV.mValue;
- usedSrcFiles.Clear();
- for (auto& ctx : record->mContexts)
- {
- if (usedSrcFiles.Add(ctx.mSrcFile))
- {
- ctx.mSrcFile->mLineDataRefs.Add(dbgSubprogram);
- }
- }
- for (int lineIdx = 0; lineIdx < (int)record->mLines.size() - 1; lineIdx++)
- {
- auto& lineData = record->mLines[lineIdx];
- auto& nextLineData = record->mLines[lineIdx + 1];
- if ((lineData.mContribSize == 0) && (lineData.mCtxIdx == nextLineData.mCtxIdx))
- {
- lineData.mContribSize = (uint32)(nextLineData.mRelAddress - lineData.mRelAddress);
- }
- bool sameInliner = lineData.mCtxIdx == nextLineData.mCtxIdx;
- if (!sameInliner)
- {
- auto ctx = record->mContexts[lineData.mCtxIdx];
- auto nextCtx = record->mContexts[lineData.mCtxIdx];
- sameInliner = ctx.mInlinee == nextCtx.mInlinee;
- }
- if ((sameInliner) && (lineData.mRelAddress + lineData.mContribSize < nextLineData.mRelAddress))
- {
- auto ctx = record->mContexts[lineData.mCtxIdx];
- if (ctx.mInlinee != NULL)
- ctx.mInlinee->mHasLineAddrGaps = true;
- }
- }
- DbgLineData* lastLine = NULL;
- for (int lineIdx = 0; lineIdx < (int)record->mLines.size(); lineIdx++)
- {
- auto& lineData = record->mLines[lineIdx];
- if (lineData.mContribSize == 0)
- {
- auto ctx = record->mContexts[lineData.mCtxIdx];
- if (ctx.mInlinee == NULL)
- lastLine = &lineData;
- }
- }
- if (lastLine != NULL)
- lastLine->mContribSize = (uint32)(dbgSubprogram->mBlock.mHighPC - (mDbgModule->mImageBase + lastLine->mRelAddress));
- BF_ASSERT(dbgSubprogram->mLineInfo == NULL);
- dbgSubprogram->mLineInfo = mDbgModule->mAlloc.Alloc<DbgLineInfo>();
- dbgSubprogram->mLineInfo->mLines.CopyFrom(&record->mLines[0], (int)record->mLines.size(), mDbgModule->mAlloc);
- BfSizedArray<DbgLineInfoCtx> contexts;
- contexts.CopyFrom(&record->mContexts[0], (int)record->mContexts.size(), mDbgModule->mAlloc);
- dbgSubprogram->mLineInfo->mContexts = contexts.mVals;
- dbgSubprogram->mLineInfo->mHasInlinees = record->mHasInlinees;
- }
- }
- //////////////////////////////////////////////////////////////////////////
- static const char* DataGetString(const uint8*& data)
- {
- const char* prevVal = (const char*)data;
- while (*data != 0)
- data++;
- data++;
- return prevVal;
- }
- struct AbstractOriginEntry
- {
- public:
- int mClassType;
- DbgDebugData* mDestination;
- DbgDebugData* mAbstractOrigin;
- private:
- AbstractOriginEntry()
- {
- }
- public:
- static AbstractOriginEntry Create(int classType, DbgDebugData* destination, DbgDebugData* abstractOrigin)
- {
- AbstractOriginEntry abstractOriginEntry;
- abstractOriginEntry.mClassType = classType;
- abstractOriginEntry.mDestination = destination;
- abstractOriginEntry.mAbstractOrigin = abstractOrigin;
- return abstractOriginEntry;
- }
- void Replace()
- {
- if (mClassType == DbgSubprogram::ClassType)
- {
- DbgSubprogram* destSubprogram = (DbgSubprogram*)mDestination;
- DbgSubprogram* originSubprogram = (DbgSubprogram*)mAbstractOrigin;
- if (destSubprogram->mName == NULL)
- {
- destSubprogram->mName = originSubprogram->mName;
- destSubprogram->mParentType = originSubprogram->mParentType;
- }
- destSubprogram->mHasThis = originSubprogram->mHasThis;
- if (destSubprogram->mFrameBaseData == NULL)
- {
- destSubprogram->mFrameBaseData = originSubprogram->mFrameBaseData;
- destSubprogram->mFrameBaseLen = originSubprogram->mFrameBaseLen;
- }
- destSubprogram->mReturnType = originSubprogram->mReturnType;
- auto originItr = originSubprogram->mParams.begin();
- for (auto destParam : destSubprogram->mParams)
- {
- DbgVariable* originParam = *originItr;
- if (originParam != NULL)
- {
- if (destParam->mName == NULL)
- destParam->mName = originParam->mName;
- if (destParam->mType == NULL)
- destParam->mType = originParam->mType;
- }
- ++originItr;
- }
- //BF_ASSERT(originItr == originSubprogram->mParams.end());
- }
- else if (mClassType == DbgVariable::ClassType)
- {
- DbgVariable* destVariable = (DbgVariable*)mDestination;
- DbgVariable* originVariable = (DbgVariable*)mAbstractOrigin;
- if (destVariable->mName == NULL)
- destVariable->mName = originVariable->mName;
- if (destVariable->mType == NULL)
- destVariable->mType = originVariable->mType;
- }
- else
- {
- BF_FATAL("Unhandled");
- }
- }
- };
- NS_BF_DBG_END
- //////////////////////////////////////////////////////////////////////////
- void DbgSubprogram::ToString(StringImpl& str, bool internalName)
- {
- if ((mInlineeInfo != NULL) && (mInlineeInfo->mInlineeId != 0))
- mCompileUnit->mDbgModule->FixupInlinee(this);
- PopulateSubprogram();
- if (mCheckedKind == BfCheckedKind_Checked)
- str += "[Checked] ";
- else if (mCheckedKind == BfCheckedKind_Unchecked)
- str += "[Unchecked] ";
- auto language = GetLanguage();
- if (mName == NULL)
- {
- if (mLinkName[0] == '<')
- {
- str += mLinkName;
- return;
- }
- str = BfDemangler::Demangle(StringImpl::MakeRef(mLinkName), language);
- // Strip off the params since we need to generate those ourselves
- int parenPos = (int)str.IndexOf('(');
- if (parenPos != -1)
- str = str.Substring(0, parenPos);
- }
- else if ((mHasQualifiedName) && (!internalName))
- {
- const char* cPtr = mName;
- if (strncmp(cPtr, "_bf::", 5) == 0)
- {
- cPtr += 5;
- for ( ; true; cPtr++)
- {
- char c = *cPtr;
- if (c == 0)
- break;
- if ((c == '_') && (cPtr[-1] == ':'))
- {
- if (strcmp(cPtr, "__BfCtor") == 0)
- {
- str += "this";
- break;
- }
- if (strcmp(cPtr, "__BfStaticCtor") == 0)
- {
- str += "this$static";
- break;
- }
- if (strcmp(cPtr, "__BfCtorClear") == 0)
- {
- str += "this$clear";
- break;
- }
- }
- if ((c == ':') && (cPtr[1] == ':'))
- {
- str.Append('.');
- cPtr++;
- }
- else
- str.Append(c);
- }
- }
- else
- str += mName;
- }
- else
- {
- if (mParentType != NULL)
- {
- mParentType->ToString(str, language, true, internalName);
- if (!str.empty())
- {
- if (language == DbgLanguage_Beef)
- str += ".";
- else
- str += "::";
- }
- }
- const char* name = mName;
- if (mHasQualifiedName)
- {
- const char* cPtr = name;
- for (; true; cPtr++)
- {
- char c = *cPtr;
- if (c == 0)
- break;
- if ((c == ':') && (cPtr[1] == ':'))
- {
- name = cPtr + 2;
- }
- }
- }
- if ((language == DbgLanguage_Beef) && (mParentType != NULL) && (mParentType->mTypeName != NULL) && (strcmp(name, mParentType->mTypeName) == 0))
- str += "this";
- else if ((language == DbgLanguage_Beef) && (name[0] == '~'))
- str += "~this";
- else if (strncmp(name, "_bf::", 5) == 0)
- str += name + 5;
- else
- {
- bool handled = false;
- if ((language == DbgLanguage_Beef) && (name[0] == '_'))
- {
- if (strcmp(name, "__BfCtor") == 0)
- {
- str += "this";
- handled = true;
- }
- else if (strcmp(name, "__BfStaticCtor") == 0)
- {
- str += "this";
- handled = true;
- }
- else if (strcmp(name, "__BfCtorClear") == 0)
- {
- str += "this$clear";
- handled = true;
- }
- }
- if (!handled)
- str += name;
- }
- }
- //if (mTemplateName != NULL)
- //str += mTemplateName;
- if (str.empty())
- str += "`anon";
- if ((str[str.length() - 1] == '!') || (str[0] == '<'))
- {
- if (language == DbgLanguage_Beef)
- {
- // It's a mixin - assert that there's no params
- //BF_ASSERT(mParams.Size() == 0);
- }
- //return str;
- }
- str += "(";
- bool showedParam = false;
- int i = 0;
- for (auto variable : mParams)
- {
- if ((variable->mName != NULL) && (strcmp(variable->mName, "this") == 0))
- continue;
- if (showedParam)
- str += ", ";
- if (variable->mType != NULL)
- {
- auto varType = variable->mType;
- if (varType->mTypeCode == DbgType_Const)
- varType = varType->mTypeParam;
- if (variable->mSigNoPointer)
- {
- BF_ASSERT(varType->IsPointer());
- varType = varType->mTypeParam;
- }
- varType->ToString(str, language, false, internalName);
- if (variable->mName != NULL)
- str += " ";
- }
- if (variable->mName != NULL)
- str += variable->mName;
- showedParam = true;
- i++;
- }
- str += ")";
- }
- String DbgSubprogram::ToString()
- {
- String str;
- ToString(str, false);
- return str;
- }
- // For inlined subprograms, the "root" inliner means the bottom-most non-inlined function. This subprogram contains
- // all the line data for it's own non-inlined instructions, PLUS line data for all inlined functions that it calls.
- // The inlined functions has empty mLineInfo structures.
- //
- // When we pass a non-NULL value into inlinedSubprogram, we are requesting to ONLY return lines that were emitted from
- // that subprogram (inlined or not).
- //
- // If we call FindClosestLine on an inlined subprogram, we only want results of functions that are inside or inlined by
- // the 'this' subprogram. Thus, we do a "get any line" call on the root inliner and then filter the results based
- // on whether they are relevant.
- DbgLineData* DbgSubprogram::FindClosestLine(addr_target addr, DbgSubprogram** inlinedSubprogram, DbgSrcFile** srcFile, int* outLineIdx)
- {
- if (mLineInfo == NULL)
- {
- if (mInlineeInfo == NULL)
- return NULL;
- if ((inlinedSubprogram != NULL) && (*inlinedSubprogram != NULL))
- {
- // Keep explicit inlinee requirement
- return mInlineeInfo->mRootInliner->FindClosestLine(addr, inlinedSubprogram, srcFile, outLineIdx);
- }
- else
- {
- DbgSubprogram* rootInlinedSubprogram = NULL;
- auto result = mInlineeInfo->mRootInliner->FindClosestLine(addr, &rootInlinedSubprogram, srcFile, outLineIdx);
- if (result == NULL)
- return NULL;
- if (rootInlinedSubprogram == NULL) // Do not allow root parent, as we cannot be a parent to the root parent (duh)
- return NULL;
- // We need to check to see if we are a parent of the found line
- auto checkSubprogram = rootInlinedSubprogram;
- while ((checkSubprogram != NULL) && (checkSubprogram->mInlineeInfo != NULL))
- {
- if (checkSubprogram == this)
- {
- if (inlinedSubprogram != NULL)
- *inlinedSubprogram = rootInlinedSubprogram;
- return result;
- }
- checkSubprogram = checkSubprogram->mInlineeInfo->mInlineParent;
- }
- return NULL;
- }
- }
- // Binary search - lineData is sorted
- int first = 0;
- int last = (int)mLineInfo->mLines.mSize - 1;
- int middle = (first + last) / 2;
- int useIdx = -1;
- while (first <= last)
- {
- addr_target midAddr = (addr_target)(mLineInfo->mLines.mVals[middle].mRelAddress + mCompileUnit->mDbgModule->mImageBase);
- if (midAddr < addr)
- first = middle + 1;
- else if (midAddr == addr)
- {
- useIdx = middle;
- break;
- }
- else
- last = middle - 1;
- middle = (first + last) / 2;
- }
- if (useIdx == -1)
- useIdx = last;
- if (last == -1)
- return NULL;
- // If we have lines with the same addr, take the more inner one
- while (true)
- {
- auto lineData = &mLineInfo->mLines.mVals[useIdx];
- if (useIdx + 1 < mLineInfo->mLines.mSize)
- {
- auto peekNext = &mLineInfo->mLines.mVals[useIdx + 1];
- if (lineData->mRelAddress != peekNext->mRelAddress)
- break;
- useIdx++;
- }
- else
- {
- break;
- }
- }
- while (true)
- {
- auto lineData = &mLineInfo->mLines.mVals[useIdx];
- if (addr < lineData->mRelAddress + lineData->mContribSize + mCompileUnit->mDbgModule->mImageBase)
- {
- auto& ctx = mLineInfo->mContexts[lineData->mCtxIdx];
- if (srcFile != NULL)
- *srcFile = ctx.mSrcFile;
- if (inlinedSubprogram != NULL)
- {
- auto subprogram = (ctx.mInlinee != NULL) ? ctx.mInlinee : this;
- if (*inlinedSubprogram != NULL)
- {
- // Strictness check
- if (subprogram == *inlinedSubprogram)
- {
- if (outLineIdx != NULL)
- *outLineIdx = useIdx;
- return lineData;
- }
- }
- else
- {
- *inlinedSubprogram = subprogram;
- if (outLineIdx != NULL)
- *outLineIdx = useIdx;
- return lineData;
- }
- }
- else
- {
- if (outLineIdx != NULL)
- *outLineIdx = useIdx;
- return lineData;
- }
- }
- // Hope we can find an earlier entry whose "contribution" is still valid
- if (--useIdx < 0)
- break;
- }
- return NULL;
- }
- DbgType* DbgSubprogram::GetParent()
- {
- if ((mParentType == NULL) && (mCompileUnit != NULL))
- mCompileUnit->mDbgModule->MapCompileUnitMethods(mCompileUnit);
- return mParentType;
- }
- DbgType* DbgSubprogram::GetTargetType()
- {
- if (!mHasThis)
- return mParentType;
- auto thisType = mParams.mHead->mType;
- if (thisType == NULL)
- return mParentType;
- if (thisType->IsPointer())
- return thisType->mTypeParam;
- return thisType;
- }
- DbgLanguage DbgSubprogram::GetLanguage()
- {
- if (mParentType != NULL)
- return mParentType->GetLanguage();
- if (mCompileUnit->mLanguage != DbgLanguage_Unknown)
- return mCompileUnit->mLanguage;
- return DbgLanguage_C; // Parent type would have been set for Beef, so it must be C
- }
- bool DbgSubprogram::Equals(DbgSubprogram* checkMethod, bool allowThisMismatch)
- {
- if ((mLinkName != NULL) && (checkMethod->mLinkName != NULL))
- {
- return strcmp(mLinkName, checkMethod->mLinkName) == 0;
- }
- if (strcmp(mName, checkMethod->mName) != 0)
- return false;
- if (mHasThis != checkMethod->mHasThis)
- return false;
- int paramIdx = 0;
- auto param = mParams.mHead;
- auto checkParam = checkMethod->mParams.mHead;
- while ((param != NULL) && (checkParam != NULL))
- {
- if ((paramIdx == 0) && (allowThisMismatch))
- {
- // Allow
- }
- else if ((param->mType != checkParam->mType) && (!param->mType->Equals(checkParam->mType)))
- return false;
- param = param->mNext;
- checkParam = checkParam->mNext;
- paramIdx++;
- }
- if ((param != NULL) || (checkParam != NULL))
- return false;
- if (!mReturnType->Equals(checkMethod->mReturnType))
- return false;
- return true;
- }
- int DbgSubprogram::GetParamCount()
- {
- int paramCount = mParams.Size();
- if (mHasThis)
- paramCount--;
- return paramCount;
- }
- String DbgSubprogram::GetParamName(int paramIdx)
- {
- auto param = mParams[paramIdx];
- if (param->mName != NULL)
- {
- String name = "'";
- name += param->mName;
- name += "'";
- return name;
- }
- return StrFormat("%d", paramIdx + 1);
- }
- bool DbgSubprogram::IsGenericMethod()
- {
- if (mName == NULL)
- return false;
- for (const char* cPtr = mName; true; cPtr++)
- {
- char c = *cPtr;
- if (c == '\0')
- break;
- if (c == '<')
- return true;
- }
- return false;
- }
- bool DbgSubprogram::ThisIsSplat()
- {
- if (mBlock.mVariables.mHead == NULL)
- return false;
- return strncmp(mBlock.mVariables.mHead->mName, "$this$", 6) == 0;
- }
- bool DbgSubprogram::IsLambda()
- {
- if (mName == NULL)
- return false;
- return StringView(mName).Contains('$');
- }
- //////////////////////////////////////////////////////////////////////////
- DbgSubprogram::~DbgSubprogram()
- {
- BfLogDbg("DbgSubprogram::~DbgSubprogram %p\n", this);
- }
- ////////////////////
- bool DbgSrcFile::IsBeef()
- {
- int dotPos = (int)mFilePath.LastIndexOf('.');
- if (dotPos == -1)
- return false;
- const char* ext = mFilePath.c_str() + dotPos;
- // The ".cs" is legacy. Remove that eventually.
- return (stricmp(ext, ".bf") == 0) || (stricmp(ext, ".cs") == 0);
- }
- DbgSrcFile::~DbgSrcFile()
- {
- for (auto replacedLineInfo : mHotReplacedDbgLineInfo)
- delete replacedLineInfo;
- }
- void DbgSrcFile::RemoveDeferredRefs(DbgModule* debugModule)
- {
- for (int deferredIdx = 0; deferredIdx < (int)mDeferredRefs.size(); )
- {
- if (mDeferredRefs[deferredIdx].mDbgModule == debugModule)
- {
- // Fast remove
- mDeferredRefs[deferredIdx] = mDeferredRefs.back();
- mDeferredRefs.pop_back();
- }
- else
- deferredIdx++;
- }
- }
- void DbgSrcFile::RemoveLines(DbgModule* debugModule)
- {
- if (!mHasLineDataFromMultipleModules)
- {
- // Fast-out case
- mLineDataRefs.Clear();
- mFirstLineDataDbgModule = NULL;
- return;
- }
- for (int idx = 0; idx < (int)mLineDataRefs.size(); idx++)
- {
- auto dbgSubprogram = mLineDataRefs[idx];
- if (dbgSubprogram->mCompileUnit->mDbgModule == debugModule)
- {
- mLineDataRefs.RemoveAtFast(idx);
- idx--;
- }
- }
- }
- void DbgSrcFile::RemoveLines(DbgModule* debugModule, DbgSubprogram* dbgSubprogram, bool isHotReplaced)
- {
- debugModule->mDebugTarget->mPendingSrcFileRehup.Add(this);
- if (isHotReplaced)
- {
- int vecIdx = dbgSubprogram->mCompileUnit->mDbgModule->mHotIdx;
- BF_ASSERT(vecIdx >= 0);
- while (vecIdx >= (int)mHotReplacedDbgLineInfo.size())
- mHotReplacedDbgLineInfo.push_back(new HotReplacedLineInfo());
- auto hotReplacedLineInfo = mHotReplacedDbgLineInfo[vecIdx];
- HotReplacedLineInfo::Entry entry;
- entry.mSubprogram = dbgSubprogram;
- entry.mLineInfo = dbgSubprogram->mLineInfo;
- hotReplacedLineInfo->mEntries.Add(entry);
- }
- }
- void DbgSrcFile::RehupLineData()
- {
- for (int idx = 0; idx < (int)mLineDataRefs.size(); idx++)
- {
- auto dbgSubprogram = mLineDataRefs[idx];
- if (dbgSubprogram->mHotReplaceKind != DbgSubprogram::HotReplaceKind_None)
- {
- mLineDataRefs.RemoveAtFast(idx);
- idx--;
- }
- }
- }
- const String& DbgSrcFile::GetLocalPath()
- {
- return (!mLocalPath.IsEmpty()) ? mLocalPath : mFilePath;
- }
- void DbgSrcFile::GetHash(String& outStr)
- {
- if (mHashKind == DbgHashKind_MD5)
- {
- for (int i = 0; i < 16; i++)
- {
- outStr += StrFormat("%02X", mHash[i]);
- }
- }
- else if (mHashKind == DbgHashKind_SHA256)
- {
- for (int i = 0; i < 32; i++)
- {
- outStr += StrFormat("%02X", mHash[i]);
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////
- DbgType::DbgType()
- {
- mTypeIdx = -1;
- mIsDeclaration = false;
- mParent = NULL;
- mTypeName = NULL;
- mTypeCode = DbgType_Null;
- mSize = 0;
- mPtrType = NULL;
- mTypeParam = NULL;
- mBlockParam = NULL;
- mNext = NULL;
- mPriority = DbgTypePriority_Normal;
- }
- DbgType::~DbgType()
- {
- BfLogDbg("DbgType::~DWType %p\n", this);
- }
- DbgType* DbgType::ResolveTypeDef()
- {
- if (mTypeCode == DbgType_TypeDef)
- return mTypeParam->ResolveTypeDef();
- return this;
- }
- bool DbgType::Equals(DbgType* dbgType)
- {
- if (dbgType == NULL)
- return false;
- if (mTypeCode != dbgType->mTypeCode)
- {
- if ((mTypeCode == DbgType_Enum) || (dbgType->mTypeCode == DbgType_Enum))
- {
- // These may change mTypeCode, so redo the check afterward
- GetPrimaryType();
- dbgType->GetPrimaryType();
- }
- if (mTypeCode != dbgType->mTypeCode)
- return false;
- }
- if ((mName == NULL) != (dbgType->mName == NULL))
- return false;
- if (mName != NULL)
- {
- if (dbgType->mFixedName)
- FixName();
- else if (mFixedName)
- dbgType->FixName();
- if (strcmp(mName, dbgType->mName) != 0)
- return false;
- }
- if ((mTypeParam != NULL) && (!mTypeParam->Equals(dbgType->mTypeParam)))
- return false;
- // Did mName already include the parent name?
- if (mCompileUnit->mDbgModule->mDbgFlavor == DbgFlavor_MS)
- return true;
- if ((mParent != NULL) != (dbgType->mParent != NULL))
- return false;
- if (mParent != NULL)
- return mParent->Equals(dbgType->mParent);
- return true;
- }
- bool DbgType::IsStruct()
- {
- return mTypeCode == DbgType_Struct;
- }
- bool DbgType::IsPrimitiveType()
- {
- return (mTypeCode >= DbgType_i8) && (mTypeCode <= DbgType_Bool);
- }
- bool DbgType::IsNull()
- {
- return mTypeCode == DbgType_Null;
- }
- bool DbgType::IsVoid()
- {
- return (mTypeCode == DbgType_Void);
- }
- bool DbgType::IsValuelessType()
- {
- return ((mTypeCode == DbgType_Struct) && (GetByteCount() == 0)) || (mTypeCode == DbgType_Void);
- }
- bool DbgType::IsValueType()
- {
- return (mTypeCode <= DbgType_DefinitionEnd);
- }
- bool DbgType::IsTypedPrimitive()
- {
- PopulateType();
- if (mTypeCode != DbgType_Struct)
- return false;
- if (mTypeParam != NULL)
- return true;
- auto baseType = GetBaseType();
- if (baseType == NULL)
- return false;
- if (!baseType->IsTypedPrimitive())
- return false;
- mTypeParam = baseType->mTypeParam;
- return true;
- }
- bool DbgType::IsBoolean()
- {
- return mTypeCode == DbgType_Bool;
- }
- bool DbgType::IsInteger()
- {
- return (mTypeCode >= DbgType_i8) && (mTypeCode <= DbgType_u64);
- }
- bool DbgType::IsIntegral()
- {
- return ((mTypeCode >= DbgType_i8) && (mTypeCode <= DbgType_u64)) ||
- ((mTypeCode >= DbgType_SChar) && (mTypeCode <= DbgType_UChar32));
- }
- bool DbgType::IsChar()
- {
- return (mTypeCode >= DbgType_SChar) && (mTypeCode <= DbgType_UChar32);
- }
- bool DbgType::IsChar(DbgLanguage language)
- {
- if (language == DbgLanguage_Beef)
- return (mTypeCode >= DbgType_UChar) && (mTypeCode <= DbgType_UChar32);
- return (mTypeCode >= DbgType_SChar) && (mTypeCode <= DbgType_SChar32);
- }
- bool DbgType::IsFloat()
- {
- return (mTypeCode == DbgType_Single) || (mTypeCode == DbgType_Double);
- }
- // "Struct" in this sense means that we do NOT have a pointer to this value, but it may or may not be a Beef Struct
- bool DbgType::IsCompositeType()
- {
- if (((mTypeCode == DbgType_TypeDef) || (mTypeCode == DbgType_Const)) && (mTypeParam != NULL))
- return mTypeParam->IsCompositeType();
- return ((mTypeCode == DbgType_Struct) || (mTypeCode == DbgType_Class) || (mTypeCode == DbgType_SizedArray));
- }
- bool DbgType::WantsRefThis()
- {
- return (GetLanguage() == DbgLanguage_Beef) && (!IsBfObject());
- }
- bool DbgType::IsBfObjectPtr()
- {
- if ((mTypeCode == DbgType_Ptr) && (mTypeParam != NULL))
- return mTypeParam->IsBfObject();
- return false;
- }
- DbgExtType DbgType::CalcExtType()
- {
- auto language = GetLanguage();
- if ((!mFixedName) && (language == DbgLanguage_Beef))
- {
- FixName();
- }
- auto primaryType = GetPrimaryType();
- if (this != primaryType)
- {
- return primaryType->CalcExtType();
- }
- if (mCompileUnit == NULL)
- return DbgExtType_Normal;
- if (language != DbgLanguage_Beef)
- return DbgExtType_Normal;
- if ((mTypeCode != DbgType_Struct) && (mTypeCode != DbgType_Class))
- return DbgExtType_Normal;
- PopulateType();
- if (mExtType != DbgExtType_Unknown)
- return mExtType;
- auto baseType = GetBaseType();
- if (baseType == NULL)
- {
- if (mParent == NULL)
- return DbgExtType_Normal;
- if (mParent->mTypeCode != DbgType_Namespace)
- return DbgExtType_Normal;
- if (mParent->mParent != NULL)
- return DbgExtType_Normal;
- if (strcmp(mParent->mTypeName, "System") != 0)
- return DbgExtType_Normal;
- if (strcmp(mTypeName, "Object") != 0)
- return DbgExtType_Normal;
- return DbgExtType_BfObject;
- }
- else
- {
- if (strcmp(baseType->mTypeName, "Enum") == 0)
- {
- for (auto member : mMemberList)
- {
- if ((member->mName != NULL) && (strcmp(member->mName, "__bftag") == 0))
- return DbgExtType_BfPayloadEnum;
- }
- return DbgExtType_Normal;
- }
- else if (strcmp(baseType->mTypeName, "ValueType") == 0)
- {
- for (auto member : mMemberList)
- {
- if ((member->mName != NULL) && (strcmp(member->mName, "$bfunion") == 0))
- return DbgExtType_BfUnion;
- }
- }
- }
- auto baseExtType = baseType->CalcExtType();
- if ((baseExtType == DbgExtType_BfObject) && (GetByteCount() == 0))
- baseExtType = DbgExtType_Interface;
- return baseExtType;
- }
- DbgLanguage DbgType::GetLanguage()
- {
- return mLanguage;
- }
- void DbgType::FixName()
- {
- if (mFixedName)
- return;
- int depthCount = 0;
- auto dbgModule = mCompileUnit->mDbgModule;
- if ((dbgModule->mDbgFlavor == DbgFlavor_MS) && (mName != NULL) && (strlen(mName) > 0))
- {
- bool modified = false;
- if (!dbgModule->DbgIsStrMutable(mName))
- mName = dbgModule->DbgDupString(mName);
- const char* typeNamePtr = mTypeName;
- char* nameP = (char*)mName;
- // Fix the name
- char* inPtr = nameP;
- char* outPtr = nameP;
- while (true)
- {
- char c = *(inPtr++);
- if ((c == '<') || (c == '('))
- depthCount++;
- else if ((c == '>') || (c == ')'))
- depthCount--;
- if ((c == ':') && (inPtr[0] == ':'))
- {
- if (mLanguage == DbgLanguage_Beef)
- {
- modified = true;
- inPtr++;
- *(outPtr++) = '.';
- if (depthCount == 0)
- typeNamePtr = outPtr;
- }
- else if (depthCount == 0)
- mTypeName = inPtr + 1;
- }
- else if (modified)
- *(outPtr++) = c;
- else
- outPtr++;
- if (c == 0)
- break;
- }
- if ((modified) && (mName != mTypeName) && (typeNamePtr != NULL))
- {
- mTypeName = typeNamePtr;
- }
- }
- mFixedName = true;
- }
- bool DbgType::IsBfObject()
- {
- if (mExtType == DbgExtType_Unknown)
- mExtType = CalcExtType();
- return (mExtType == DbgExtType_BfObject) || (mExtType == DbgExtType_Interface);
- }
- bool DbgType::IsBfPayloadEnum()
- {
- if (mExtType == DbgExtType_Unknown)
- mExtType = CalcExtType();
- return mExtType == DbgExtType_BfPayloadEnum;
- }
- bool DbgType::IsBfUnion()
- {
- if (mExtType == DbgExtType_Unknown)
- mExtType = CalcExtType();
- return mExtType == DbgExtType_BfUnion;
- }
- bool DbgType::IsBfEnum()
- {
- if (mTypeCode != DbgType_Struct)
- return false;
- auto baseType = GetBaseType();
- if (baseType == NULL)
- {
- if (mParent == NULL)
- return false;
- if (mParent->mTypeCode != DbgType_Namespace)
- return false;
- if (mParent->mParent != NULL)
- return false;
- if (strcmp(mParent->mTypeName, "System") != 0)
- return false;
- return strcmp(mTypeName, "Enum") == 0;
- }
- return baseType->IsBfEnum();
- }
- bool DbgType::IsBfTuple()
- {
- if (mTypeCode != DbgType_Struct)
- return false;
- if (GetLanguage() != DbgLanguage_Beef)
- return false;
- if (mName == NULL)
- return false;
- return mName[0] == '(';
- }
- bool DbgType::HasCPPVTable()
- {
- if ((mTypeCode != DbgType_Struct) && (mTypeCode != DbgType_Class))
- return false;
- /*if (!mMemberList.IsEmpty())
- {
- //TODO: We commented this out at some point- why did we do that?
- if ((mMemberList.mHead->mName != NULL) && (strncmp(mMemberList.mHead->mName, "_vptr$", 6) == 0))
- return true;
- }*/
- if (mHasVTable)
- return true;
- if (GetLanguage() == DbgLanguage_Beef)
- return false;
- for (auto checkBaseType : mBaseTypes)
- {
- if (checkBaseType->mBaseType->HasCPPVTable())
- return true;
- }
- return false;
- }
- bool DbgType::IsBaseBfObject()
- {
- auto baseType = GetBaseType();
- return (baseType == NULL) && (IsBfObject());
- }
- bool DbgType::IsInterface()
- {
- if (mExtType == DbgExtType_Unknown)
- mExtType = CalcExtType();
- return mExtType == DbgExtType_Interface;
- }
- bool DbgType::IsNamespace()
- {
- return mTypeCode == DbgType_Namespace;
- }
- bool DbgType::IsEnum()
- {
- return (mTypeCode == DbgType_Enum);
- }
- bool DbgType::IsRoot()
- {
- return (mTypeCode == DbgType_Root);
- }
- bool DbgType::IsRef()
- {
- return
- (mTypeCode == DbgType_Ref) ||
- (mTypeCode == DbgType_RValueReference);
- }
- bool DbgType::IsSigned()
- {
- return
- (mTypeCode == DbgType_i8) ||
- (mTypeCode == DbgType_i16) ||
- (mTypeCode == DbgType_i32) ||
- (mTypeCode == DbgType_i64);
- }
- bool DbgType::IsConst()
- {
- if ((mTypeCode == DbgType_Ptr) || (mTypeCode == DbgType_Ref))
- {
- if (mTypeParam != NULL)
- return mTypeParam->IsConst();
- }
- return mTypeCode == DbgType_Const;
- }
- bool DbgType::IsPointer(bool includeBfObjectPointer)
- {
- if (mTypeCode != DbgType_Ptr)
- return false;
- if ((!includeBfObjectPointer) && (mTypeParam != NULL) && (mTypeParam->IsBfObject()))
- return false;
- return true;
- }
- bool DbgType::HasPointer(bool includeBfObjectPointer)
- {
- if (((mTypeCode == DbgType_Const) || (mTypeCode == DbgType_Ref)) && (mTypeParam != NULL))
- return mTypeParam->IsPointer(includeBfObjectPointer);
- return IsPointer(includeBfObjectPointer);
- }
- bool DbgType::IsPointerOrRef(bool includeBfObjectPointer)
- {
- if ((mTypeCode != DbgType_Ptr) && (mTypeCode != DbgType_Ref) && (mTypeCode != DbgType_RValueReference))
- return false;
- if ((!includeBfObjectPointer) && (mTypeParam != NULL) && (mTypeParam->IsBfObject()))
- return false;
- return true;
- }
- bool DbgType::IsSizedArray()
- {
- return (mTypeCode == DbgType_SizedArray);
- }
- bool DbgType::IsAnonymous()
- {
- return (mTypeName == NULL) || (mTypeName[0] == '<');
- }
- bool DbgType::IsGlobalsContainer()
- {
- return (mTypeName != NULL) && (mTypeName[0] == 'G') && (mTypeName[1] == '$');
- }
- DbgType* DbgType::GetUnderlyingType()
- {
- return mTypeParam;
- }
- void DbgType::PopulateType()
- {
- if (mIsIncomplete)
- {
- mCompileUnit->mDbgModule->PopulateType(this);
- mIsIncomplete = false;
- }
- }
- DbgModule* DbgType::GetDbgModule()
- {
- if (mCompileUnit == NULL)
- return NULL;
- return mCompileUnit->mDbgModule;
- }
- DbgType* DbgType::GetPrimaryType()
- {
- if (mPrimaryType != NULL)
- return mPrimaryType;
- mPrimaryType = this;
- if (mPriority <= DbgTypePriority_Normal)
- {
- if ((mCompileUnit != NULL) &&
- ((mCompileUnit->mLanguage == DbgLanguage_Beef)|| (mLanguage == DbgLanguage_Beef) ||
- (mTypeCode == DbgType_Namespace) || (mIsDeclaration)))
- {
- mPrimaryType = mCompileUnit->mDbgModule->GetPrimaryType(this);
- mPrimaryType->PopulateType();
- mTypeCode = mPrimaryType->mTypeCode;
- mTypeParam = mPrimaryType->mTypeParam;
- }
- }
- return mPrimaryType;
- }
- DbgType* DbgType::GetBaseType()
- {
- auto primaryType = GetPrimaryType();
- if (primaryType != this)
- return primaryType->GetBaseType();
- PopulateType();
- if (mBaseTypes.mHead == NULL)
- return NULL;
- if (GetLanguage() != DbgLanguage_Beef)
- return NULL;
- auto baseType = mBaseTypes.mHead->mBaseType;
- BF_ASSERT(!baseType->IsInterface());
- if ((baseType == NULL) || (baseType->mPriority > DbgTypePriority_Normal))
- return baseType;
- baseType = mCompileUnit->mDbgModule->GetPrimaryType(baseType);
- mBaseTypes.mHead->mBaseType = baseType;
- if (baseType->mIsDeclaration)
- {
- // That's no good, try to fix it up
- if (baseType->GetLanguage() == DbgLanguage_Beef)
- {
- if (baseType->GetBaseType() == NULL)
- {
- if (baseType->ToString() == "System.Function")
- {
- DbgBaseTypeEntry* baseTypeEntry = mCompileUnit->mDbgModule->mAlloc.Alloc<DbgBaseTypeEntry>();
- baseTypeEntry->mBaseType = mCompileUnit->mDbgModule->GetPrimitiveType(DbgType_IntPtr_Alias, DbgLanguage_Beef);
- baseType->mBaseTypes.PushBack(baseTypeEntry);
- }
- }
- }
- }
- return baseType;
- }
- DbgType* DbgType::GetRootBaseType()
- {
- auto baseType = GetBaseType();
- if (baseType != NULL)
- return baseType->GetRootBaseType();
- return this;
- }
- DbgType* DbgType::RemoveModifiers(bool* hadRef)
- {
- DbgType* dbgType = this;
- while (dbgType != NULL)
- {
- bool curHadRef = (dbgType->mTypeCode == DbgType_Ref) || (dbgType->mTypeCode == DbgType_RValueReference);
- if ((curHadRef) && (hadRef != NULL))
- *hadRef = true;
- if ((dbgType->mTypeCode == DbgType_Const) || (dbgType->mTypeCode == DbgType_TypeDef) || (dbgType->mTypeCode == DbgType_Volatile) || (dbgType->mTypeCode == DbgType_Bitfield) ||
- (dbgType->mTypeCode == DbgType_Unaligned) || (curHadRef))
- {
- if (dbgType->mTypeParam == NULL)
- break;
- dbgType = dbgType->mTypeParam;
- }
- else
- break;
- }
- return dbgType;
- }
- String DbgType::ToStringRaw(DbgLanguage language)
- {
- if (mTypeIdx != -1)
- return StrFormat("_T_%d_%d", mCompileUnit->mDbgModule->GetLinkedModule()->mId, mTypeIdx);
- return ToString(language);
- }
- void DbgType::ToString(StringImpl& str, DbgLanguage language, bool allowDirectBfObject, bool internalName)
- {
- if (language == DbgLanguage_Unknown)
- language = GetLanguage();
- if (language == DbgLanguage_Beef)
- {
- switch (mTypeCode)
- {
- case DbgType_UChar:
- str += "char8";
- return;
- case DbgType_UChar16:
- str += "char16";
- return;
- case DbgType_UChar32:
- str += "char32";
- return;
- case DbgType_i8:
- str += "int8";
- return;
- case DbgType_u8:
- str += "uint8";
- return;
- case DbgType_i16:
- str += "int16";
- return;
- case DbgType_u16:
- str += "uint16";
- return;
- case DbgType_i32:
- str += "int32";
- return;
- case DbgType_u32:
- str += "uint32";
- return;
- case DbgType_i64:
- str += "int64";
- return;
- case DbgType_u64:
- str += "uint64";
- return;
- }
- }
- else
- {
- switch (mTypeCode)
- {
- case DbgType_SChar:
- str += "char";
- return;
- case DbgType_SChar16:
- str += "wchar_t";
- return;
- case DbgType_SChar32:
- str += "int32_t";
- return;
- case DbgType_UChar:
- str += "uint8_t";
- return;
- case DbgType_UChar16:
- str += "uint16_t";
- return;
- case DbgType_UChar32:
- str += "uint32_t";
- return;
- case DbgType_i8:
- str += "char";
- return;
- case DbgType_u8:
- str += "uint8_t";
- return;
- case DbgType_i16:
- str += "short";
- return;
- case DbgType_u16:
- str += "uint16_t";
- return;
- case DbgType_i32:
- str += "int";
- return;
- case DbgType_u32:
- str += "uint32_t";
- return;
- case DbgType_i64:
- str += "int64_t";
- return;
- case DbgType_u64:
- str += "uint64_t";
- return;
- }
- }
- if (mTypeCode == DbgType_Namespace)
- internalName = false;
- auto parent = mParent;
- if ((parent == NULL) && (internalName))
- {
- auto primaryType = GetPrimaryType();
- parent = primaryType->mParent;
- }
- if (mTypeName != NULL)
- {
- if ((!allowDirectBfObject) && (IsBfObject()))
- {
- // Only use the '#' for testing
- //return ToString(true) + "#";
- ToString(str, DbgLanguage_Unknown, true, internalName);
- return;
- }
- if (IsGlobalsContainer())
- {
- if (mParent != NULL)
- {
- mParent->ToString(str, language, false, internalName);
- return;
- }
- return;
- }
- //String combName;
- /*if (mTemplateParams != NULL)
- {
- combName = nameP;
- combName += mTemplateParams;
- nameP = combName.c_str();
- }*/
- if ((!mFixedName) /*&& (language == DbgLanguage_Beef)*/)
- {
- FixName();
- }
- char* nameP = (char*)mTypeName;
- if (parent == NULL)
- {
- if (strncmp(nameP, "Box<", 4) == 0)
- {
- str += String(nameP + 4, nameP + strlen(nameP) - 1);
- str += "^";
- return;
- }
- // For declarations, may also include namespaces
- str += mName;
- return;
- }
- if (GetLanguage() == DbgLanguage_Beef)
- {
- parent->ToString(str, language, allowDirectBfObject, internalName);
- if ((internalName) && (parent->mTypeCode != DbgType_Namespace))
- str += "+";
- else
- str += ".";
- str += nameP;
- }
- else
- {
- parent->ToString(str, language, allowDirectBfObject, internalName);
- if ((internalName) && (parent->mTypeCode != DbgType_Namespace))
- str += "+";
- else
- str += "::";
- str += nameP;
- }
- return;
- }
- switch (mTypeCode)
- {
- case DbgType_Struct:
- {
- if ((mTypeName == NULL) && (parent != NULL))
- {
- parent->ToString(str, language, allowDirectBfObject, internalName);
- return;
- }
- str += "@struct";
- return;
- }
- case DbgType_Class:
- {
- str += "@class";
- return;
- }
- case DbgType_TypeDef:
- {
- str += "@typedef";
- return;
- }
- case DbgType_Const:
- {
- if (language == DbgLanguage_Beef)
- {
- str += "readonly";
- if (mTypeParam != NULL)
- {
- str += " ";
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- }
- return;
- }
- str += "const";
- if (mTypeParam != NULL)
- {
- str += " ";
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- }
- return;
- }
- case DbgType_Volatile:
- {
- str += "volatile";
- if (mTypeParam != NULL)
- {
- str += " ";
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- }
- return;
- }
- case DbgType_Unaligned:
- {
- str += "unaligned";
- if (mTypeParam != NULL)
- {
- str += " ";
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- }
- }
- case DbgType_Restrict:
- {
- str += "restrict";
- if (mTypeParam != NULL)
- {
- str += " ";
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- }
- }
- case DbgType_Ptr:
- {
- if (mTypeParam == NULL)
- {
- str += "void*";
- return;
- }
- if (mTypeParam->IsBfObject())
- {
- mTypeParam->ToString(str, DbgLanguage_Unknown, true, internalName);
- return;
- }
- // Don't put a "*" on the end of a function type, it's implicit
- if (mTypeParam->mTypeCode == DbgType_Subroutine)
- {
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- return;
- }
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- str += "*";
- return;
- }
- case DbgType_Ref:
- {
- if (language == DbgLanguage_Beef)
- {
- str += "ref";
- if (mTypeParam != NULL)
- {
- str += " ";
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- }
- return;
- }
- if (mTypeParam == NULL)
- {
- str += "&";
- return;
- }
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- str += "&";
- return;
- }
- case DbgType_RValueReference:
- {
- if (language == DbgLanguage_Beef)
- {
- // Ignore this - this is used for passing structs when we're not using the 'byval' attribute
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- return;
- }
- if (mTypeParam == NULL)
- {
- str += "&&";
- return;
- }
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- str += "&&";
- return;
- }
- case DbgType_Unspecified:
- str += mTypeName;
- return;
- case DbgType_SizedArray:
- {
- StringT<128> name;
- auto checkType = this;
- while (checkType->mTypeCode == DbgType_SizedArray)
- {
- intptr innerSize = checkType->mTypeParam->GetStride();
- intptr arrSize = 0;
- if (innerSize > 0)
- {
- arrSize = checkType->GetStride() / innerSize;
- }
- name += StrFormat("[%lld]", arrSize);
- checkType = checkType->mTypeParam;
- }
- checkType->ToString(str, language, allowDirectBfObject, internalName);
- str += name;
- return;
- }
- case DbgType_Union:
- {
- str += "union";
- if (mTypeParam != NULL)
- {
- str += " ";
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- }
- return;
- }
- case DbgType_Single:
- str += "float";
- return;
- case DbgType_Double:
- str += "double";
- return;
- case DbgType_Null:
- str += "void";
- return;
- case DbgType_Subroutine:
- {
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- str += " (";
- int paramIdx = 0;
- for (auto param : mBlockParam->mVariables)
- {
- if (paramIdx > 0)
- str += ", ";
- param->mType->ToString(str, language, allowDirectBfObject, internalName);
- paramIdx++;
- }
- str += ")";
- return;
- }
- case DbgType_VTable:
- str += "@vtable";
- return;
- case DbgType_Enum:
- str += "@enum";
- return;
- case DbgType_Namespace:
- {
- // Anonymous
- str += "`anon`";
- return;
- }
- case DbgType_PtrToMember:
- str += "@ptrToMember";
- return;
- case DbgType_Bitfield:
- {
- auto dbgBitfieldType = (DbgBitfieldType*)this;
- mTypeParam->ToString(str, language, allowDirectBfObject, internalName);
- str += StrFormat("{%d:%d}", dbgBitfieldType->mPosition, dbgBitfieldType->mLength);
- return;
- }
- default:
- break;
- }
- BF_FATAL("Unhandled type");
- str += "???";
- }
- String DbgType::ToString(DbgLanguage language, bool allowDirectBfObject)
- {
- String str;
- ToString(str, language, allowDirectBfObject, false);
- return str;
- }
- intptr DbgType::GetByteCount()
- {
- if (!mSizeCalculated)
- {
- PopulateType();
- if ((mSize == 0) && (GetLanguage() == DbgLanguage_Beef))
- CalcExtType();
- if ((mTypeCode == DbgType_Struct) || (mTypeCode == DbgType_Class) || (mTypeCode == DbgType_Union))
- {
- if (mPriority <= DbgTypePriority_Normal)
- {
- auto primaryType = GetPrimaryType();
- if (primaryType != this)
- {
- mSize = primaryType->GetByteCount();
- mAlign = primaryType->mAlign;
- }
- }
- }
- else if ((mTypeCode == DbgType_Ref) || (mTypeCode == DbgType_Ptr) || (mTypeCode == DbgType_PtrToMember))
- {
- #ifdef BF_DBG_32
- mSize = 4;
- #else
- mSize = 8;
- #endif
- }
- else if (mTypeCode == DbgType_SizedArray)
- {
- auto language = GetLanguage();
- if (language == DbgLanguage_Beef)
- {
- if (mTypeParam->mAlign == 0)
- {
- NOP;
- }
- auto primaryType = mTypeParam->GetPrimaryType();
- if (primaryType->mAlign == 0)
- {
- NOP;
- }
- else
- {
- intptr elemCount = BF_ALIGN(mSize, primaryType->mAlign) / primaryType->GetStride();
- if (elemCount > 0)
- {
- mSize = ((elemCount - 1) * primaryType->GetStride()) + primaryType->GetByteCount();
- }
- }
- mAlign = primaryType->mAlign;
- }
- }
- else if (mTypeParam != NULL) // typedef, const, volatile, restrict, etc
- mSize = mTypeParam->GetByteCount();
- mSizeCalculated = true;
- }
- return mSize;
- }
- intptr DbgType::GetStride()
- {
- return BF_ALIGN(GetByteCount(), GetAlign());
- }
- int DbgType::GetAlign()
- {
- if (mAlign == 0)
- {
- auto primaryType = GetPrimaryType();
- if (primaryType != this)
- return primaryType->GetAlign();
- if (IsCompositeType())
- {
- PopulateType();
- }
- }
- if (mAlign != 0)
- return mAlign;
- return 1;
- }
- void DbgType::EnsureMethodsMapped()
- {
- for (auto methodNameEntry : mMethodNameList)
- {
- if (methodNameEntry->mCompileUnitId != -1)
- {
- mCompileUnit->mDbgModule->MapCompileUnitMethods(methodNameEntry->mCompileUnitId);
- methodNameEntry->mCompileUnitId = -1;
- }
- }
- }
- #define CREATE_PRIMITIVE_C(typeCode, cTypeName, type) \
- dbgType = mAlloc.Alloc<DbgType>(); \
- dbgType->mCompileUnit = &mDefaultCompileUnit; \
- dbgType->mName = cTypeName; \
- dbgType->mLanguage = DbgLanguage_C;\
- dbgType->mTypeName = cTypeName; \
- dbgType->mTypeCode = typeCode; \
- dbgType->mSize = sizeof(type); \
- dbgType->mAlign = sizeof(type); \
- mCPrimitiveTypes[typeCode] = dbgType; \
- mTypeMap.Insert(dbgType);
- #define CREATE_PRIMITIVE(typeCode, cTypeName, bfTypeName, structName, type) \
- dbgType = mAlloc.Alloc<DbgType>(); \
- dbgType->mCompileUnit = &mDefaultCompileUnit; \
- dbgType->mName = cTypeName; \
- dbgType->mLanguage = DbgLanguage_C;\
- dbgType->mTypeName = cTypeName; \
- dbgType->mTypeCode = typeCode; \
- dbgType->mSize = sizeof(type); \
- dbgType->mAlign = sizeof(type); \
- mCPrimitiveTypes[typeCode] = dbgType; \
- mTypeMap.Insert(dbgType); \
- dbgType = mAlloc.Alloc<DbgType>(); \
- dbgType->mCompileUnit = &mDefaultCompileUnit; \
- dbgType->mName = bfTypeName; \
- dbgType->mLanguage = DbgLanguage_Beef;\
- dbgType->mTypeName = bfTypeName; \
- dbgType->mTypeCode = typeCode; \
- dbgType->mSize = sizeof(type); \
- dbgType->mAlign = sizeof(type); \
- mBfPrimitiveTypes[typeCode] = dbgType; \
- mPrimitiveStructNames[typeCode] = structName; \
- mTypeMap.Insert(dbgType);
- DbgModule::DbgModule(DebugTarget* debugTarget) : mDefaultCompileUnit(this)
- {
- mMemReporter = NULL;
- mLoadState = DbgModuleLoadState_NotLoaded;
- mMappedImageFile = NULL;
- mEntryPoint = 0;
- mFailMsgPtr = NULL;
- mFailed = false;
- for (int i = 0; i < DbgType_COUNT; i++)
- {
- mBfPrimitiveTypes[i] = NULL;
- mCPrimitiveTypes[i] = NULL;
- mPrimitiveStructNames[i] = NULL;
- }
- DbgType* dbgType;
- mDefaultCompileUnit.mLanguage = DbgLanguage_Beef;
- mDefaultCompileUnit.mDbgModule = this;
- if (debugTarget != NULL)
- {
- // These are 'alias' definitions for C, but get overwritten by their official
- // stdint.h versions (ie: int8_t)
- CREATE_PRIMITIVE_C(DbgType_i8, "int8", int8);
- CREATE_PRIMITIVE_C(DbgType_i16, "int16", int16);
- CREATE_PRIMITIVE_C(DbgType_i32, "int32", int32);
- CREATE_PRIMITIVE_C(DbgType_i64, "int64", int64);
- CREATE_PRIMITIVE_C(DbgType_i8, "uint8", uint8);
- CREATE_PRIMITIVE_C(DbgType_i16, "uint16", uint16);
- CREATE_PRIMITIVE_C(DbgType_i32, "uint32", uint32);
- CREATE_PRIMITIVE_C(DbgType_i64, "uint64", uint64);
- CREATE_PRIMITIVE(DbgType_Void, "void", "void", "void", void*);
- dbgType->mSize = 0;
- dbgType->mAlign = 0;
- CREATE_PRIMITIVE(DbgType_Null, "null", "null", "null", void*);
- CREATE_PRIMITIVE(DbgType_IntPtr_Alias, "intptr_t", "int", "System.Int", intptr_target);
- CREATE_PRIMITIVE(DbgType_UIntPtr_Alias, "uintptr_t", "uint", "System.UInt", addr_target);
- CREATE_PRIMITIVE(DbgType_SChar, "char", "char", "System.Char", char);
- CREATE_PRIMITIVE(DbgType_SChar16, "wchar_t", "wchar", "System.Char16", wchar_t);
- CREATE_PRIMITIVE(DbgType_i8, "int8_t", "int8", "System.SByte", int8);
- CREATE_PRIMITIVE(DbgType_i16, "short", "int16", "System.Int16", int16);
- CREATE_PRIMITIVE(DbgType_i32, "int", "int32", "System.Int32", int32);
- CREATE_PRIMITIVE(DbgType_i64, "int64_t", "int64", "System.Int64", int64);
- CREATE_PRIMITIVE(DbgType_u8, "uint8_t", "uint8", "System.UInt8", uint8);
- CREATE_PRIMITIVE(DbgType_u16, "uint16_t", "uint16", "System.UInt16", uint16);
- CREATE_PRIMITIVE(DbgType_u32, "uint32_t", "uint32", "System.UInt32", uint32);
- CREATE_PRIMITIVE(DbgType_u64, "uint64_t", "uint64", "System.UInt64", uint64);
- CREATE_PRIMITIVE(DbgType_Single, "float", "float", "System.Single", float);
- CREATE_PRIMITIVE(DbgType_Double, "double", "double", "System.Double", double);
- CREATE_PRIMITIVE(DbgType_UChar, "char8", "char8", "System.Char", char);
- CREATE_PRIMITIVE(DbgType_UChar16, "char16", "char16", "System.Char16", short);
- CREATE_PRIMITIVE(DbgType_UChar32, "char32", "char32", "System.Char32", int);
- CREATE_PRIMITIVE(DbgType_Bool, "bool", "bool", "System.Boolean", bool);
- CREATE_PRIMITIVE(DbgType_Subroutine, "@Func", "@Func", "@Func", bool);
- CREATE_PRIMITIVE(DbgType_RawText, "@RawText", "@RawText", "@RawText", bool);
- CREATE_PRIMITIVE(DbgType_RegGroup, "@RegGroup", "@RegGroup", "@RegGroup", void*);
- CREATE_PRIMITIVE_C(DbgType_i16, "int16_t", int16_t);
- CREATE_PRIMITIVE_C(DbgType_i32, "int32_t", int32_t);
- CREATE_PRIMITIVE_C(DbgType_i64, "__int64", int64);
- CREATE_PRIMITIVE_C(DbgType_u64, "unsigned __int64", uint64);
- CREATE_PRIMITIVE_C(DbgType_u8, "unsigned char", uint8);
- CREATE_PRIMITIVE_C(DbgType_u16, "unsigned short", uint16);
- CREATE_PRIMITIVE_C(DbgType_u32, "unsigned int", uint32);
- CREATE_PRIMITIVE_C(DbgType_u32, "unsigned int32_t", uint32_t);
- CREATE_PRIMITIVE_C(DbgType_u32, "unsigned long", uint32);
- CREATE_PRIMITIVE_C(DbgType_u64, "unsigned int64_t", uint64);
- }
- mIsDwarf64 = false;
- mDebugTarget = debugTarget;
- if (debugTarget != NULL)
- mDebugger = debugTarget->mDebugger;
- else
- mDebugger = NULL;
- mDebugLineData = NULL;
- mDebugInfoData = NULL;
- mDebugPubNames = NULL;
- mDebugFrameAddress = 0;
- mDebugFrameData = NULL;
- mDebugLocationData = NULL;
- mDebugRangesData = NULL;
- mDebugAbbrevData = NULL;
- mDebugStrData = NULL;
- mDebugAbbrevPtrData = NULL;
- mEHFrameData = NULL;
- mEHFrameAddress = 0;
- mStringTable = NULL;
- mSymbolData = NULL;
- mCheckedBfObject = false;
- mBfObjectHasFlags = false;
- mModuleKind = DbgModuleKind_Module;
- mStartTypeIdx = 0;
- mEndTypeIdx = 0;
- mHotIdx = 0;
- mId = 0;
- mStartSubprogramIdx = 0;
- mEndSubprogramIdx = 0;
- mCodeAddress = NULL;
- mMayBeOld = false;
- mTimeStamp = 0;
- mExpectedFileSize = 0;
- mBfTypeType = NULL;
- mBfTypesInfoAddr = 0;
- mImageBase = 0;
- mPreferredImageBase = 0;
- mImageSize = 0;
- mOrigImageData = NULL;
- mDeleting = false;
- mAllocSizeData = 0;
- mParsedSymbolData = false;
- mParsedTypeData = false;
- mParsedGlobalsData = false;
- mPopulatedStaticVariables = false;
- mParsedFrameDescriptors = false;
- mTLSAddr = 0;
- mTLSSize = 0;
- mTLSExtraAddr = 0;
- mTLSExtraSize = 0;
- mTLSIndexAddr = 0;
- mDbgFlavor = DbgFlavor_Unknown;
- mMasterCompileUnit = NULL;
- }
- DbgModule::~DbgModule()
- {
- delete mMemReporter;
- for (auto dwSrcFile : mEmptySrcFiles)
- delete dwSrcFile;
- for (auto dwCompileUnit : mCompileUnits)
- delete dwCompileUnit;
- delete mSymbolData;
- delete mStringTable;
- delete mDebugLineData;
- delete mDebugInfoData;
- delete mDebugPubNames;
- delete mDebugFrameData;
- delete mDebugLocationData;
- delete mDebugRangesData;
- delete mDebugAbbrevData;
- delete mDebugAbbrevPtrData;
- delete mDebugStrData;
- for (auto entry : mExceptionDirectory)
- delete entry.mData;
- delete mEHFrameData;
- delete mOrigImageData;
- if ((IsObjectFile()) && (mImageBase != 0))
- {
- mDebugger->ReleaseHotTargetMemory((addr_target)mImageBase, (int)mImageSize);
- }
- for (auto data : mOwnedSectionData)
- delete data;
- }
- DbgSubprogram* DbgModule::FindSubprogram(DbgType* dbgType, const char * methodName)
- {
- dbgType = dbgType->GetPrimaryType();
- dbgType->PopulateType();
- if (dbgType->mNeedsGlobalsPopulated)
- PopulateTypeGlobals(dbgType);
- for (auto methodNameEntry : dbgType->mMethodNameList)
- {
- if ((methodNameEntry->mCompileUnitId != -1) && (strcmp(methodNameEntry->mName, methodName) == 0))
- {
- // If we hot-replaced this type then we replaced and parsed all the methods too
- if (!dbgType->mCompileUnit->mDbgModule->IsObjectFile())
- dbgType->mCompileUnit->mDbgModule->MapCompileUnitMethods(methodNameEntry->mCompileUnitId);
- methodNameEntry->mCompileUnitId = -1;
- }
- }
- DbgSubprogram* result = NULL;
- for (auto method : dbgType->mMethodList)
- {
- if (strcmp(method->mName, methodName) == 0)
- {
- method->PopulateSubprogram();
- if ((result == NULL) || (method->mBlock.mLowPC != 0))
- result = method;
- }
- }
- return result;
- }
- void DbgModule::Fail(const StringImpl& error)
- {
- if (mFailMsgPtr != NULL)
- {
- if (mFailMsgPtr->IsEmpty())
- *mFailMsgPtr = error;
- }
- String errorStr = "error ";
- if (!mFilePath.IsEmpty())
- {
- errorStr += "Error in ";
- errorStr += mFilePath;
- errorStr += ": ";
- }
- errorStr += error;
- errorStr += "\n";
- mDebugger->OutputRawMessage(errorStr);
- mFailed = true;
- }
- void DbgModule::SoftFail(const StringImpl& error)
- {
- if (mFailMsgPtr != NULL)
- {
- if (mFailMsgPtr->IsEmpty())
- *mFailMsgPtr = error;
- }
- String errorStr = "errorsoft ";
- if (!mFilePath.IsEmpty())
- {
- errorStr += "Error in ";
- errorStr += mFilePath;
- errorStr += ": ";
- }
- errorStr += error;
- errorStr += "\n";
- mDebugger->OutputRawMessage(errorStr);
- mFailed = true;
- }
- void DbgModule::HardFail(const StringImpl& error)
- {
- if (mFailMsgPtr != NULL)
- {
- if (mFailMsgPtr->IsEmpty())
- *mFailMsgPtr = error;
- }
- String errorStr;
- if (!mFilePath.IsEmpty())
- {
- errorStr += "Error in ";
- errorStr += mFilePath;
- errorStr += ": ";
- }
- errorStr += error;
- errorStr += "\n";
- BF_FATAL(errorStr.c_str());
- }
- char* DbgModule::DbgDupString(const char* str, const char* allocName)
- {
- int strLen = (int)strlen(str);
- if (strLen == 0)
- return NULL;
- char* dupStr = (char*)mAlloc.AllocBytes(strLen + 1, (allocName != NULL) ? allocName : "DbgDupString");
- memcpy(dupStr, str, strLen);
- return dupStr;
- }
- DbgModule* DbgModule::GetLinkedModule()
- {
- if (IsObjectFile())
- return mDebugTarget->mTargetBinary;
- return this;
- }
- addr_target DbgModule::GetTargetImageBase()
- {
- if (IsObjectFile())
- return (addr_target)mDebugTarget->mTargetBinary->mImageBase;
- return (addr_target)mImageBase;
- }
- void DbgModule::ParseGlobalsData()
- {
- mParsedGlobalsData = true;
- }
- void DbgModule::ParseSymbolData()
- {
- mParsedSymbolData = true;
- }
- void DbgModule::ParseTypeData()
- {
- mParsedTypeData = true;
- }
- DbgCompileUnit* DbgModule::ParseCompileUnit(int compileUnitId)
- {
- return NULL;
- }
- void DbgModule::MapCompileUnitMethods(DbgCompileUnit * compileUnit)
- {
- }
- void DbgModule::MapCompileUnitMethods(int compileUnitId)
- {
- }
- void DbgModule::PopulateType(DbgType* dbgType)
- {
- }
- void DbgModule::PopulateTypeGlobals(DbgType* dbgType)
- {
- }
- void DbgModule::PopulateStaticVariableMap()
- {
- if (mPopulatedStaticVariables)
- return;
- for (auto staticVariable : mStaticVariables)
- {
- mStaticVariableMap[staticVariable->GetMappedName()] = staticVariable;
- }
- mPopulatedStaticVariables = true;
- }
- void DbgModule::ProcessDebugInfo()
- {
- }
- addr_target DbgModule::RemapAddr(addr_target addr)
- {
- if ((addr != 0) && (mPreferredImageBase != 0) && (mImageBase != 0))
- return addr + (intptr_target)(mImageBase - mPreferredImageBase);
- return addr;
- }
- void DbgModule::ParseAbbrevData(const uint8* data)
- {
- while (true)
- {
- int abbrevIdx = (int)DecodeULEB128(data);
- mDebugAbbrevPtrData[abbrevIdx] = data;
- if (abbrevIdx == 0)
- break;
- int entryTag = (int)DecodeULEB128(data);
- bool hasChildren = GET(char) == DW_CHILDREN_yes;
- while (true)
- {
- int attrName = (int)DecodeULEB128(data);
- int form = (int)DecodeULEB128(data);
- if ((attrName == 0) && (form == 0))
- break;
- }
- }
- }
- void DbgModule::ParseExceptionData()
- {
- if (mExceptionDirectory.IsEmpty())
- return;
- BP_ZONE("DbgModule::ParseExceptionData");
- for (auto entry : mExceptionDirectory)
- {
- const uint8* data = entry.mData;
- const uint8* dataEnd = data + entry.mSize;
- static int entryCount = 0;
- addr_target imageBase = GetTargetImageBase();
- while (data < dataEnd)
- {
- addr_target beginAddress = GET(uint32);
- addr_target endAddress = GET(uint32);
- uint32 unwindData = GET(uint32);
- //TODO: Apparently unwindData can refer to another runtime entry in the .pdata if the LSB is set to 1?
- beginAddress += (addr_target)imageBase;
- endAddress += (addr_target)imageBase;
- int exSize = (int)(endAddress - beginAddress);
- for (int exOffset = 0; true; exOffset += DBG_MAX_LOOKBACK)
- {
- int curSize = exSize - exOffset;
- if (curSize <= 0)
- break;
- BP_ALLOC_T(DbgExceptionDirectoryEntry);
- DbgExceptionDirectoryEntry* exceptionDirectoryEntry = mAlloc.Alloc<DbgExceptionDirectoryEntry>();
- exceptionDirectoryEntry->mAddress = beginAddress + exOffset;
- exceptionDirectoryEntry->mOrigAddressOffset = exOffset;
- exceptionDirectoryEntry->mAddressLength = curSize;
- exceptionDirectoryEntry->mExceptionPos = (int)unwindData;
- exceptionDirectoryEntry->mDbgModule = this;
- mDebugTarget->mExceptionDirectoryMap.Insert(exceptionDirectoryEntry);
- entryCount++;
- }
- }
- }
- }
- static int gIdx = 0;
- template <typename T> static bool IsTypeSigned() { return false; }
- template <> bool IsTypeSigned<int8>() { return true; }
- template <> bool IsTypeSigned<int16>() { return true; }
- template <> bool IsTypeSigned<int32>() { return true; }
- template <> bool IsTypeSigned<int64>() { return true; }
- #pragma warning(push)
- #pragma warning(disable:4302)
- #pragma warning(disable:4311)
- #pragma warning(disable:4312)
- #pragma warning(disable:4800)
- #pragma warning(disable:4800)
- template <typename T>
- T DbgModule::ReadValue(const uint8*& data, int form, int refOffset, const uint8** extraData, const uint8* startData)
- {
- gIdx++;
- switch (form)
- {
- case DW_FORM_strp:
- {
- int strOffset = GET(int);
- BF_ASSERT(mDebugStrData != NULL);
- const char* str = (const char*)mDebugStrData + strOffset;
- return (T)(intptr)str;
- }
- break;
- case DW_FORM_data1:
- {
- if (IsTypeSigned<T>())
- return (T)(intptr)GET(int8);
- else
- return (T)(uintptr)GET(uint8);
- }
- break;
- case DW_FORM_data2:
- {
- if (IsTypeSigned<T>())
- return (T)(intptr)GET(int16);
- else
- return (T)(uintptr)GET(uint16);
- }
- break;
- case DW_FORM_data4:
- {
- if (IsTypeSigned<T>())
- return (T)(intptr)GET(int32);
- else
- return (T)(uintptr)GET(uint32);
- }
- break;
- case DW_FORM_data8:
- {
- if (IsTypeSigned<T>())
- return (T)GET(int64);
- else
- return (T)GET(uint64);
- }
- break;
- case DW_FORM_ref1:
- {
- return (T)(intptr)GET(int8) + refOffset;
- }
- break;
- case DW_FORM_ref2:
- {
- return (T)(intptr)GET(int16) + refOffset;
- }
- break;
- case DW_FORM_ref4:
- {
- return (T)(intptr)GET(int32) + refOffset;
- }
- break;
- case DW_FORM_sec_offset:
- {
- intptr_target offset;
- if (mIsDwarf64)
- offset = (intptr_target)GET(int64);
- else
- offset = GET(int32);
- if (extraData != NULL)
- {
- *extraData = mDebugLocationData + offset;
- return 0;
- }
- return (T)offset;
- }
- break;
- case DW_FORM_addr:
- {
- return (T)GET(addr_target);
- }
- break;
- case DW_FORM_exprloc:
- {
- int64_t exprLen = DecodeULEB128(data);
- const uint8* endData = data + exprLen;
- if (extraData != NULL)
- *extraData = data;
- data = endData;
- return (T)exprLen;
- }
- break;
- case DW_FORM_flag_present:
- {
- //
- return (T)1;
- }
- break;
- case DW_FORM_flag:
- {
- //
- return (T)(intptr)GET(char);
- }
- break;
- case DW_FORM_sdata:
- return (T)DecodeSLEB128(data);
- case DW_FORM_udata:
- return (T)DecodeULEB128(data);
- case DW_FORM_string:
- {
- const char* str = (const char*)data;
- while (true)
- {
- uint8 val = *data;
- data++;
- if (val == 0)
- return (T)(intptr)str;
- }
- }
- case DW_FORM_block:
- {
- int blockLen = (int)DecodeULEB128(data);
- const uint8* retVal = data;
- data += blockLen;
- return (T)(intptr)retVal;
- }
- case DW_FORM_block1:
- {
- int blockLen = (int)*((uint8*)data);
- data += sizeof(uint8);
- const uint8* retVal = data;
- data += blockLen;
- return (T)(intptr)retVal;
- }
- default:
- assert("Not covered!" == 0);
- break;
- }
- return (T)0;
- }
- #pragma warning(pop)
- static int gAbbrevNum = 0;
- DbgType* DbgModule::GetOrCreateType(int typeIdx, DbgDataMap& dataMap)
- {
- if (typeIdx == 0)
- return NULL;
- DbgModule* linkedModule = GetLinkedModule();
- DbgType* dbgType = dataMap.Get<DbgType*>(typeIdx);
- if (dbgType != NULL)
- return dbgType;
- dbgType = mAlloc.Alloc<DbgType>();
- dbgType->mTypeIdx = (int)linkedModule->mTypes.size();
- linkedModule->mTypes.push_back(dbgType);
- dataMap.Set(typeIdx, dbgType);
- return dbgType;
- }
- typedef std::pair<DbgClassType, void*> DataPair;
- typedef llvm::SmallVector<DataPair, 16> DataStack;
- template <typename T>
- T DbgModule::GetOrCreate(int idx, DbgDataMap& dataMap)
- {
- if (idx == 0)
- return NULL;
- T val = dataMap.Get<T>(idx);
- if (val != NULL)
- return val;
- val = mAlloc.Alloc<typename RemoveTypePointer<T>::type >();
- dataMap.Set(idx, val);
- return val;
- }
- template <typename T>
- static T GetStackTop(DataStack* dataStack)
- {
- auto dataPair = dataStack->back();
- if (dataPair.first == RemoveTypePointer<T>::type::ClassType)
- return (T)dataPair.second;
- return NULL;
- }
- template <>
- DbgBlock* GetStackTop<DbgBlock*>(DataStack* dataStack)
- {
- auto dataPair = dataStack->back();
- if (dataPair.first == DbgBlock::ClassType)
- return (DbgBlock*)dataPair.second;
- if (dataPair.first == DbgSubprogram::ClassType)
- return &((DbgSubprogram*)dataPair.second)->mBlock;
- if (dataPair.first == DbgType::ClassType)
- return ((DbgType*)dataPair.second)->mBlockParam;
- return NULL;
- }
- template <typename T>
- static bool StackHasType(DataStack* dataStack)
- {
- for (auto itr : *dataStack)
- if (itr.first == RemoveTypePointer<T>::type::ClassType)
- return true;
- return false;
- }
- template <typename T>
- static T GetStackLast(DataStack* dataStack)
- {
- for (int i = (int)dataStack->size() - 1; i >= 0; i--)
- {
- if ((*dataStack)[i].first == RemoveTypePointer<T>::type::ClassType)
- return (T)(*dataStack)[i].second;
- }
- return NULL;
- }
- template <typename T>
- static DataPair MakeDataPair(T* data)
- {
- return DataPair(T::ClassType, data);
- }
- void DbgModule::FixupInnerTypes(int startingTypeIdx)
- {
- BP_ZONE("DbgModule_FixupInnerTypes");
- for (int typeIdx = startingTypeIdx; typeIdx < (int)mTypes.size(); typeIdx++)
- {
- DbgType* dbgType = mTypes[typeIdx];
- if ((dbgType->mPriority == DbgTypePriority_Primary_Implicit) && (dbgType->mParent != NULL) && (dbgType->mParent->mTypeCode != DbgType_Namespace) &&
- (dbgType->mParent->mPriority <= DbgTypePriority_Primary_Implicit))
- {
- auto primaryParent = dbgType->mParent->GetPrimaryType();
- dbgType->mParent->mSubTypeList.Clear();
- dbgType->mParent = primaryParent;
- primaryParent->mSubTypeList.PushBack(dbgType);
- }
- }
- }
- void DbgModule::MapTypes(int startingTypeIdx)
- {
- BP_ZONE("DbgModule_MapTypes");
- bool needsInnerFixups = false;
- for (int typeIdx = startingTypeIdx; typeIdx < (int)mTypes.size(); typeIdx++)
- {
- DbgType* dbgType = mTypes[typeIdx];
- BF_ASSERT(dbgType->mTypeCode != DbgType_Null);
- if ((dbgType->mTypeCode == DbgType_Namespace) && (dbgType->mPriority < DbgTypePriority_Primary_Implicit))
- continue;
- //TODO: Always valid?
- if (dbgType->mIsDeclaration)
- continue;
- // We were avoiding adding '<' names before, but that made it impossible to look up auto-named primary types ,
- // like in-place unions like '<unnamed-type-u>'
- if ((dbgType->mTypeName == NULL) || (dbgType->mName == NULL) /*|| (dbgType->mTypeName[0] == '<')*/)
- continue;
- if (dbgType->mTypeCode > DbgType_DefinitionEnd)
- {
- // Only add "definition types"
- continue;
- }
- if (dbgType->mTypeCode == DbgType_Namespace)
- {
- bool isQualifiedNamespace = false;
- for (const char* cPtr = dbgType->mTypeName; *cPtr != '\0'; cPtr++)
- if (*cPtr == '.')
- isQualifiedNamespace = true;
- if (isQualifiedNamespace)
- continue; // Don't add fully qualified namespaces (they come from the 'using' implementation)*
- }
- if (dbgType->mHasStaticMembers)
- {
- for (auto member : dbgType->mMemberList)
- if ((member->mIsStatic) && (member->mLocationData != NULL))
- dbgType->mDefinedMembersSize++;
- }
- if ((dbgType->mTypeName != NULL) && (strcmp(dbgType->mTypeName, "@") == 0))
- {
- // Globals type.
- continue;
- }
- auto prevTypeEntry = FindType(dbgType->mName, dbgType->mLanguage);
- // Only replace previous instance if its a declaration
- if (prevTypeEntry != NULL)
- {
- auto prevType = prevTypeEntry->mValue;
- if (dbgType->mCompileUnit->mDbgModule != prevType->mCompileUnit->mDbgModule)
- {
- // Don't replace original types with hot types -- those need to be inserted in the the hot alternates list
- BF_ASSERT(dbgType->mCompileUnit->mDbgModule->IsObjectFile());
- prevType->mHotNewType = dbgType;
- continue;
- }
- // Never override explicit primaries
- if (prevType->mPriority == DbgTypePriority_Primary_Explicit)
- continue;
- if (dbgType->mTypeCode == DbgType_TypeDef)
- {
- // Typedef can never override anything
- continue;
- }
- if (prevType->mTypeCode == DbgType_TypeDef)
- {
- if (dbgType->mTypeCode != DbgType_TypeDef)
- {
- // Allow this to override
- prevTypeEntry->mValue = dbgType;
- }
- continue;
- }
- // Don't replace a ptr to an BfObject with a BfObject
- if ((prevType->mTypeCode == DbgType_Ptr) && (dbgType->mTypeCode == DbgType_Struct))
- continue;
- if ((prevType->mTypeCode == DbgType_Struct) && (dbgType->mTypeCode == DbgType_Ptr))
- {
- // Allow this to override
- prevTypeEntry->mValue = dbgType;
- continue;
- }
- if (prevType->mTypeCode == DbgType_Namespace)
- {
- if (dbgType->mTypeCode != DbgType_Namespace)
- {
- // Old type was namespace but new isn't? Replace old type.
- while (!prevType->mSubTypeList.IsEmpty())
- {
- DbgType* subType = prevType->mSubTypeList.PopFront();
- subType->mParent = dbgType;
- dbgType->mSubTypeList.PushBack(subType);
- }
- prevType->mPriority = DbgTypePriority_Normal;
- if (dbgType->mPriority < DbgTypePriority_Primary_Implicit)
- dbgType->mPriority = DbgTypePriority_Primary_Implicit;
- prevTypeEntry->mValue = dbgType;
- continue;
- }
- // We definitely didn't want to do this for MS. For DWARF?
- //prevType->mAlternates.PushFront(dbgType, &mAlloc);
- continue;
- }
- else
- {
- // New type is namespace but old wasn't? Ignore new type.
- if (dbgType->mTypeCode == DbgType_Namespace)
- continue;
- if (dbgType->mIsDeclaration)
- continue;
- if (!prevType->mIsDeclaration)
- {
- if ((prevType->mCompileUnit == NULL) || (dbgType->mLanguage < prevType->mLanguage))
- {
- // We always want 'Beef' types to supersede 'C' types, but don't override the built-in primitive types
- continue;
- }
- if (prevType->mDefinedMembersSize > 0)
- {
- if (dbgType->mDefinedMembersSize > 0)
- {
- // We create an 'alternates' list for all types that define at least one static field
- if (prevType->mHasStaticMembers)
- prevType->mAlternates.PushFront(dbgType, &mAlloc);
- }
- continue;
- }
- // if (prevType->mDefinedMembersSize > dbgType->mDefinedMembersSize)
- // {
- // continue;
- // }
- if (prevType->mMethodsWithParamsCount > dbgType->mMethodsWithParamsCount)
- {
- // This handles a special case where methods without line data like <Enum>.HasFlags doesn't show containing
- // params in cases where it gets inlined
- continue;
- }
- // Types with method lists are preferred
- if ((!prevType->mMethodList.IsEmpty()) && (dbgType->mMethodList.IsEmpty()))
- continue;
- if ((prevType->mTypeCode == DbgType_Ptr) && (prevType->mTypeParam != NULL) && (!prevType->mTypeParam->mMethodList.IsEmpty()))
- continue;
- }
- // Replace type
- if (!prevType->mSubTypeList.IsEmpty())
- needsInnerFixups = true;
- prevType->mPriority = DbgTypePriority_Normal;
- if (dbgType->mPriority == DbgTypePriority_Normal)
- dbgType->mPriority = DbgTypePriority_Primary_Implicit;
- prevTypeEntry->mValue = dbgType;
- continue;
- }
- }
- if ((dbgType->mParent != NULL) && (dbgType->mParent->mTypeCode != DbgType_Namespace) && (dbgType->mParent->mPriority <= DbgTypePriority_Primary_Implicit))
- needsInnerFixups = true;
- if (dbgType->mPriority == DbgTypePriority_Normal)
- dbgType->mPriority = DbgTypePriority_Primary_Implicit;
- mTypeMap.Insert(dbgType);
- }
- if (needsInnerFixups)
- FixupInnerTypes(startingTypeIdx);
- }
- void DbgModule::CreateNamespaces()
- {
- BP_ZONE("DbgModule::CreateNamespaces");
- int startLength = (int)mTypes.size();
- for (int typeIdx = 0; typeIdx < startLength; typeIdx++)
- {
- DbgType* dbgType = mTypes[typeIdx];
- if (dbgType->mName == NULL)
- continue;
- if ((dbgType->mTypeCode == DbgType_Namespace) && (dbgType->mTagIdx != 0))
- {
- auto namespaceTypeEntry = FindType(dbgType->mName, dbgType->GetLanguage());
- DbgType* namespaceType;
- if (namespaceTypeEntry == NULL)
- {
- namespaceType = mAlloc.Alloc<DbgType>();
- namespaceType->mTypeCode = DbgType_Namespace;
- namespaceType->mLanguage = dbgType->mLanguage;
- namespaceType->mCompileUnit = dbgType->mCompileUnit;
- namespaceType->mTypeIdx = (int)mTypes.size();
- namespaceType->mPriority = DbgTypePriority_Primary_Explicit;
- namespaceType->mName = dbgType->mName;
- namespaceType->mTypeName = dbgType->mTypeName;
- if (dbgType->mParent != NULL)
- {
- namespaceType->mParent = dbgType->mParent->GetPrimaryType();
- namespaceType->mParent->mSubTypeList.PushBack(namespaceType);
- }
- else
- {
- namespaceType->mCompileUnit->mGlobalType->mSubTypeList.PushBack(namespaceType);
- }
- mTypes.push_back(namespaceType);
- mTypeMap.Insert(namespaceType);
- }
- else
- namespaceType = namespaceTypeEntry->mValue;
- while (!dbgType->mMemberList.IsEmpty())
- {
- DbgVariable* curVar = dbgType->mMemberList.PopFront();
- namespaceType->mMemberList.PushBack(curVar);
- }
- DbgType* prevType = NULL;
- DbgType* curType = dbgType->mSubTypeList.mHead;
- while (curType != NULL)
- {
- DbgType* nextType = curType->mNext;
- if (curType->mPriority >= DbgTypePriority_Primary_Implicit)
- {
- dbgType->mSubTypeList.Remove(curType, prevType);
- namespaceType->mSubTypeList.PushBack(curType);
- }
- prevType = curType;
- curType = nextType;
- }
- continue;
- }
- }
- // If we didn't have a parent type for a namespace (ie: if System.Collections wasn't linked to System) then we wait
- // until the end and move those from the global list to the parent list
- for (int typeIdx = startLength; typeIdx < (int)mTypes.size(); typeIdx++)
- {
- DbgType* dbgType = mTypes[typeIdx];
- if (dbgType->mParent != NULL)
- continue;
- char* typeName = (char*)dbgType->mTypeName;
- int lastDotIdx = -1;
- for (int i = 0; true; i++)
- {
- char c = typeName[i];
- if (c == 0)
- break;
- if (c == '.')
- lastDotIdx = i;
- }
- if (lastDotIdx == -1)
- continue;
- typeName[lastDotIdx] = 0;
- dbgType->mTypeName = typeName + lastDotIdx + 1;
- auto parentEntry = FindType(typeName, dbgType->GetLanguage());
- typeName[lastDotIdx] = '.';
- if (parentEntry == NULL)
- continue;
- auto parentType = parentEntry->mValue;
- dbgType->mCompileUnit->mGlobalType->mSubTypeList.Remove(dbgType);
- dbgType->mParent = parentType;
- parentType->mSubTypeList.PushBack(dbgType);
- }
- }
- void DbgModule::FindTemplateStr(const char*& name, int& templateNameIdx)
- {
- if (templateNameIdx == 0)
- {
- for (int i = 0; name[i] != 0; i++)
- {
- if (name[i] == '<')
- {
- templateNameIdx = i;
- return;
- }
- }
- templateNameIdx = -1;
- }
- }
- void DbgModule::TempRemoveTemplateStr(const char*& name, int& templateNameIdx)
- {
- if (templateNameIdx == 0)
- FindTemplateStr(name, templateNameIdx);
- if (templateNameIdx == -1)
- return;
- if (!DbgIsStrMutable(name))
- name = DbgDupString(name);
- ((char*)name)[templateNameIdx] = 0;
- }
- void DbgModule::ReplaceTemplateStr(const char*& name, int& templateNameIdx)
- {
- if (templateNameIdx > 0)
- ((char*)name)[templateNameIdx] = '<';
- }
- void DbgModule::MapSubprogram(DbgSubprogram* dbgSubprogram)
- {
- if (dbgSubprogram->mBlock.IsEmpty())
- return;
- int progSize = (int)(dbgSubprogram->mBlock.mHighPC - dbgSubprogram->mBlock.mLowPC);
- for (int progOffset = 0; true; progOffset += DBG_MAX_LOOKBACK)
- {
- int curSize = progSize - progOffset;
- if (curSize <= 0)
- break;
- BP_ALLOC_T(DbgSubprogramMapEntry);
- DbgSubprogramMapEntry* subprogramMapEntry = mAlloc.Alloc<DbgSubprogramMapEntry>();
- subprogramMapEntry->mAddress = dbgSubprogram->mBlock.mLowPC + progOffset;
- subprogramMapEntry->mEntry = dbgSubprogram;
- mDebugTarget->mSubprogramMap.Insert(subprogramMapEntry);
- }
- }
- bool DbgModule::ParseDWARF(const uint8*& dataPtr)
- {
- BP_ZONE("ParseDWARF");
- const uint8* data = dataPtr;
- const uint8* startData = mDebugInfoData;
- int dataOfs = (int)(data - mDebugInfoData);
- intptr_target length = GET(int);
- DbgModule* linkedModule = GetLinkedModule();
- if (length == -1)
- {
- mIsDwarf64 = true;
- length = (intptr_target)GET(int64);
- }
- else
- mIsDwarf64 = false;
- if (length == 0)
- return false;
- const uint8* dataEnd = data + length;
- int version = GET(short);
- int abbrevOffset = GET(int);
- char pointerSize = GET(char);
- ParseAbbrevData(mDebugAbbrevData + abbrevOffset);
- DbgCompileUnit* compileUnit = new DbgCompileUnit(this);
- mDbgFlavor = DbgFlavor_GNU;
- compileUnit->mDbgModule = this;
- mCompileUnits.push_back(compileUnit);
- DbgSubprogram* subProgram = NULL;
- //std::map<int, DbgType*> typeMap;
- //std::map<int, DbgSubprogram*> subprogramMap;
- int tagStart = (int)(data - startData);
- int tagEnd = (int)(dataEnd - startData);
- DbgDataMap dataMap(tagStart, tagEnd);
- DataStack dataStack;
- Array<AbstractOriginEntry> abstractOriginReplaceList;
- Array<int> deferredArrayDims;
- int startingTypeIdx = (int)linkedModule->mTypes.size();
- while (data < dataEnd)
- {
- gAbbrevNum++;
- const uint8* tagDataStart = data;
- int tagIdx = (int)(tagDataStart - startData);
- int abbrevIdx = (int)DecodeULEB128(data);
- const uint8* abbrevData = mDebugAbbrevPtrData[abbrevIdx];
- if (abbrevIdx == 0)
- {
- if (deferredArrayDims.size() > 0)
- {
- DbgType* arrType = GetStackTop<DbgType*>(&dataStack);
- BF_ASSERT(arrType->mTypeCode == DbgType_SizedArray);
- arrType->mSize = deferredArrayDims[0]; // Byte count still needs to be multiplied by the underlying type size
- DbgType* rootArrType = arrType;
- for (int dimIdx = 0; dimIdx < (int)deferredArrayDims.size() - 1; dimIdx++)
- {
- int dimSize = deferredArrayDims[dimIdx];
- DbgType* subArrType = mAlloc.Alloc<DbgType>();
- subArrType->mCompileUnit = compileUnit;
- subArrType->mLanguage = compileUnit->mLanguage;
- subArrType->mTypeIdx = (int)linkedModule->mTypes.size();
- linkedModule->mTypes.push_back(subArrType);
- subArrType->mTypeCode = DbgType_SizedArray;
- subArrType->mTypeParam = arrType->mTypeParam;
- subArrType->mSize = deferredArrayDims[dimIdx + 1];
- arrType->mTypeParam = subArrType;
- arrType = subArrType;
- }
- deferredArrayDims.Clear();
- }
- dataStack.pop_back();
- continue;
- }
- int entryTag = (int) DecodeULEB128(abbrevData);
- bool hasChildren = GET_FROM(abbrevData, char) == DW_CHILDREN_yes;
- int64 atLowPC = 0;
- int64 atHighPC = 0;
- int64 atRanges = 0;
- bool hasRanges = false;
- const uint8* atFrameBase = NULL;
- int64_t atFrameBaseLength = 0;
- int64 atLocationLen = 0;
- const uint8* atLocationData = 0;
- const char* atProducer = NULL;
- const char* atName = NULL;
- const char* atCompDir = NULL;
- const char* atLinkageName = NULL;
- int64 atConstValue = 0;
- int atDataMemberLocation = 0;
- const uint8* atDataMemberData = NULL;
- int atDeclFile = 0;
- int atDeclLine = 0;
- int atCallFile = 0;
- int atCallLine = 0;
- int atCount = 0;
- int atType = 0;
- int atImport = 0;
- int atInline = 0;
- int atArtificial = 0;
- int atExternal = 0;
- int atByteSize = -1;
- int atEncoding = 0;
- int atSpecification = 0;
- int atObjectPointer = 0;
- int atBitOffset = 0;
- int atBitSize = 0;
- int atAbstractOrigin = 0;
- const uint8* atVirtualLocData = NULL;
- bool atDeclaration = false;
- bool atVirtual = false;
- bool hadConstValue = false;
- bool hadMemberLocation = false;
- bool isOptimized = false;
- DataPair newDataPair;
- while (true)
- {
- int attrName = (int)DecodeULEB128(abbrevData);
- int form = (int)DecodeULEB128(abbrevData);
- if ((attrName == 0) && (form == 0))
- break;
- switch (attrName)
- {
- case DW_AT_sibling:
- ReadValue<char>(data, form);
- break;
- case DW_AT_location:
- atLocationLen = (int)ReadValue<uint>(data, form, dataOfs, &atLocationData, startData);
- break;
- case DW_AT_name:
- atName = ReadValue<const char*>(data, form);
- break;
- case DW_AT_ordering:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_byte_size:
- atByteSize = ReadValue<int>(data, form);
- break;
- case DW_AT_bit_offset:
- atBitOffset = ReadValue<int>(data, form);
- break;
- case DW_AT_bit_size:
- atBitSize = ReadValue<int>(data, form);
- break;
- case DW_AT_stmt_list:
- ReadValue<int64_t>(data, form);
- break;
- case DW_AT_low_pc:
- atLowPC = RemapAddr((addr_target)ReadValue<int64_t>(data, form));
- break;
- case DW_AT_high_pc:
- atHighPC = ReadValue<int64_t>(data, form);
- break;
- case DW_AT_language:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_discr:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_discr_value:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_visibility:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_import:
- atImport = ReadValue<int>(data, form) + dataOfs;
- break;
- case DW_AT_string_length:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_common_reference:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_comp_dir:
- atCompDir = ReadValue<const char*>(data, form);
- break;
- case DW_AT_const_value:
- atConstValue = ReadValue<int64>(data, form);
- hadConstValue = true;
- break;
- case DW_AT_containing_type:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_default_value:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_inline:
- atInline = ReadValue<int>(data, form);
- break;
- case DW_AT_is_optional:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_lower_bound:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_producer:
- atProducer = ReadValue<const char*>(data, form);
- break;
- case DW_AT_prototyped:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_return_addr:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_start_scope:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_bit_stride:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_upper_bound:
- // Lower bound not supported
- atCount = ReadValue<int>(data, form);
- break;
- case DW_AT_abstract_origin:
- atAbstractOrigin = ReadValue<int>(data, form, dataOfs);
- break;
- case DW_AT_accessibility:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_address_class:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_artificial:
- atArtificial = ReadValue<int>(data, form);
- break;
- case DW_AT_base_types:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_calling_convention:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_count:
- atCount = ReadValue<uint>(data, form);
- break;
- case DW_AT_data_member_location:
- if (form == DW_FORM_exprloc)
- {
- atDataMemberLocation = (int)ReadValue<uint>(data, form, dataOfs, &atDataMemberData);
- hadMemberLocation = true;
- }
- else
- {
- atDataMemberLocation = (int)ReadValue<uint>(data, form);
- hadMemberLocation = true;
- }
- break;
- case DW_AT_decl_column:
- /*TODO:*/ ReadValue<uint32>(data, form);
- break;
- case DW_AT_decl_file:
- atDeclFile = ReadValue<uint32>(data, form);
- break;
- case DW_AT_decl_line:
- atDeclLine = ReadValue<uint32>(data, form);
- break;
- case DW_AT_declaration:
- atDeclaration = ReadValue<bool>(data, form);
- break;
- case DW_AT_discr_list:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_encoding:
- atEncoding = ReadValue<int>(data, form);
- break;
- case DW_AT_external:
- atExternal = ReadValue<int>(data, form);
- break;
- case DW_AT_frame_base:
- atFrameBaseLength = (int64_t)ReadValue<uint64_t>(data, form, dataOfs, &atFrameBase);
- break;
- case DW_AT_friend:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_identifier_case:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_macro_info:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_namelist_item:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_priority:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_segment:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_specification:
- atSpecification = ReadValue<int>(data, form, dataOfs);
- break;
- case DW_AT_static_link:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_type:
- atType = ReadValue<int>(data, form, dataOfs);
- break;
- case DW_AT_use_location:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_variable_parameter:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_virtuality:
- atVirtual = ReadValue<int>(data, form) != 0;
- break;
- case DW_AT_vtable_elem_location:
- ReadValue<uint64_t>(data, form, dataOfs, &atVirtualLocData);
- break;
- case DW_AT_allocated:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_associated:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_data_location:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_byte_stride:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_entry_pc:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_use_UTF8:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_extension:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_ranges:
- atRanges = (int)ReadValue<uint>(data, form);
- hasRanges = true;
- break;
- case DW_AT_trampoline:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_call_column:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_call_file:
- atCallFile = ReadValue<uint32>(data, form);
- break;
- case DW_AT_call_line:
- atCallLine = ReadValue<uint32>(data, form);
- break;
- case DW_AT_description:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_binary_scale:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_decimal_scale:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_small:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_decimal_sign:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_digit_count:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_picture_string:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_mutable:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_threads_scaled:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_explicit:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_object_pointer:
- atObjectPointer = ReadValue<int>(data, form);
- break;
- case DW_AT_endianity:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_elemental:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_pure:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_recursive:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_signature:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_main_subprogram:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_data_bit_offset:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_const_expr:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_enum_class:
- /*TODO:*/ ReadValue<int>(data, form);
- break;
- case DW_AT_linkage_name:
- atLinkageName = ReadValue<const char*>(data, form);
- break;
- //
- case DW_AT_MIPS_linkage_name:
- atLinkageName = ReadValue<const char*>(data, form);
- break;
- case DW_AT_APPLE_optimized:
- isOptimized = ReadValue<bool>(data, form);
- break;
- default:
- ReadValue<int>(data, form);
- break;
- }
- }
- if ((hasRanges) && (atLowPC == 0))
- {
- addr_target* rangeData = (addr_target*)(mDebugRangesData + atRanges);
- while (true)
- {
- addr_target lowPC = *(rangeData++);
- if (lowPC == 0)
- break;
- addr_target highPC = *(rangeData++);
- if (compileUnit->mLowPC != (addr_target)-1)
- {
- // These are sometimes relative to the compile unit and sometimes absolute
- if (highPC + compileUnit->mLowPC <= compileUnit->mHighPC)
- {
- lowPC += compileUnit->mLowPC;
- highPC += compileUnit->mLowPC;
- }
- }
- highPC -= lowPC;
- // Select the largest range. We have some cases where some hoisting and such will
- // give us a small inlining aberration much earlier than expected so this ignores that
- if ((int64)highPC > atHighPC)
- {
- atLowPC = lowPC;
- atHighPC = highPC;
- }
- /*if ((atLowPC == 0) || (lowPC < (addr_target)atLowPC))
- atLowPC = lowPC;
- if (highPC > (addr_target)atHighPC)
- atHighPC = highPC;*/
- }
- }
- switch (entryTag)
- {
- case DW_TAG_compile_unit:
- {
- newDataPair = MakeDataPair(compileUnit);
- compileUnit->mName = atName;
- compileUnit->mProducer = atProducer;
- if (atCompDir != NULL)
- compileUnit->mCompileDir = atCompDir;
- if (atLowPC != 0)
- {
- compileUnit->mLowPC = (addr_target)atLowPC;
- compileUnit->mHighPC = (addr_target)(atLowPC + atHighPC);
- }
- if (compileUnit->mProducer.IndexOf("Beef") != -1)
- {
- compileUnit->mLanguage = DbgLanguage_Beef;
- }
- else
- {
- compileUnit->mLanguage = DbgLanguage_C;
- }
- compileUnit->mGlobalType->mLanguage = compileUnit->mLanguage;
- }
- break;
- case DW_TAG_imported_module:
- {
- DbgType* parentType = GetStackTop<DbgType*>(&dataStack);
- DbgType* importType = GetOrCreateType(atImport, dataMap);
- if (parentType != NULL) // Parent type is NULL for Clang DbgModule info
- parentType->mUsingNamespaces.PushFront(importType, &mAlloc);
- }
- break;
- case DW_TAG_inlined_subroutine:
- case DW_TAG_subprogram:
- {
- /*//TODO: This is a test. See if it breaks anything.
- if ((atExternal != 0) && (atLowPC == 0))
- break;*/
- if (atSpecification == 0)
- {
- subProgram = GetOrCreate<DbgSubprogram*>(tagIdx, dataMap);
- subProgram->mCompileUnit = compileUnit;
- subProgram->mVirtual = atVirtual;
- subProgram->mIsOptimized = isOptimized;
- if (atVirtualLocData != NULL)
- {
- const uint8* opPtr = atVirtualLocData;
- if (*(opPtr++) == DW_OP_constu)
- {
- subProgram->mVTableLoc = (int)DecodeSLEB128(opPtr) * sizeof(addr_target);
- }
- }
- //subProgram->mVTableLoc = atVirtualLoc * sizeof(addr_target);
- //SplitName(atName, subProgram->mName, subProgram->mTemplateName);
- subProgram->mName = atName;
- subProgram->mLinkName = atLinkageName;
- if (atAbstractOrigin != NULL)
- {
- DbgSubprogram* originSubProgram = GetOrCreate<DbgSubprogram*>(atAbstractOrigin, dataMap);
- auto abstractOriginEntry = AbstractOriginEntry::Create(DbgSubprogram::ClassType, subProgram, originSubProgram);
- abstractOriginReplaceList.push_back(abstractOriginEntry);
- }
- subProgram->mParentType = GetStackTop<DbgType*>(&dataStack);
- newDataPair = MakeDataPair(subProgram);
- //if ((atLinkageName != NULL) && (subProgram->mParentType != NULL))
- //subProgram->mParentType->mDefinedMembersCount++;
- mSubprograms.push_back(subProgram);
- if (subProgram->mParentType != NULL)
- {
- subProgram->mParentType->mMethodList.PushBack(subProgram);
- }
- else
- {
- compileUnit->mGlobalType->mMethodList.PushBack(subProgram);
- }
- }
- else
- {
- subProgram = dataMap.Get<DbgSubprogram*>(atSpecification);
- BF_ASSERT(subProgram != NULL);
- // We remove params form the declaration and re-add the real ones here
- subProgram->mParams.Clear();
- }
- newDataPair = MakeDataPair(subProgram);
- DbgBlock* dwBlock = &subProgram->mBlock;
- if (atType != 0)
- subProgram->mReturnType = GetOrCreateType(atType, dataMap);
- if (!atDeclaration)
- {
- dwBlock->mLowPC = (addr_target)atLowPC;
- dwBlock->mHighPC = (addr_target)(atLowPC + atHighPC);
- if (dwBlock->mLowPC != 0)
- {
- compileUnit->mLowPC = std::min(compileUnit->mLowPC, dwBlock->mLowPC);
- compileUnit->mHighPC = std::max(compileUnit->mHighPC, dwBlock->mHighPC);
- }
- if (atObjectPointer != 0)
- subProgram->mHasThis = true;
- subProgram->mFrameBaseLen = (int)atFrameBaseLength;
- subProgram->mFrameBaseData = atFrameBase;
- if (atHighPC > 0)
- {
- MapSubprogram(subProgram);
- }
- }
- if (entryTag == DW_TAG_inlined_subroutine)
- {
- DbgSubprogram* parentSubProgram = GetStackLast<DbgSubprogram*>(&dataStack);
- subProgram->mInlineeInfo = mAlloc.Alloc<DbgInlineeInfo>();
- subProgram->mInlineeInfo->mInlineParent = parentSubProgram;
- subProgram->mInlineeInfo->mRootInliner = parentSubProgram->GetRootInlineParent();
- subProgram->mFrameBaseData = parentSubProgram->mFrameBaseData;
- subProgram->mFrameBaseLen = parentSubProgram->mFrameBaseLen;
- }
- //if (subProgram->mParentType != NULL)
- //subProgram->mParentType->mDefinedMembersCount++;
- }
- break;
- case DW_TAG_lexical_block:
- {
- DbgBlock* prevBlock = GetStackTop<DbgBlock*>(&dataStack);
- DbgBlock* dwBlock = mAlloc.Alloc<DbgBlock>();
- if (hasRanges)
- {
- dwBlock->mLowPC = -1;
- dwBlock->mHighPC = (addr_target)atRanges;
- }
- else
- {
- dwBlock->mLowPC = (addr_target)atLowPC;
- dwBlock->mHighPC = (addr_target)(atLowPC + atHighPC);
- }
- newDataPair = MakeDataPair(dwBlock);
- prevBlock->mSubBlocks.PushBack(dwBlock);
- }
- break;
- case DW_TAG_variable:
- {
- DbgBlock* dwBlock = GetStackTop<DbgBlock*>(&dataStack);
- if (atName && !strncmp(atName, "__asmLines", 10))
- {
- const char* ptr = strchr(atName, '.');
- if (!ptr)
- break;
- int declLine = atDeclLine;
- Array<int> asmLines;
- int curAsmLine = 0;
- int curRunCount = 1; // initial value is starting line, with an assumed run count of 1
- bool parity = true; // starting line is standalone; everything afterwards is in pairs
- while (true)
- {
- ++ptr;
- if (!*ptr)
- break;
- String s;
- if (*ptr == '$')
- {
- ++ptr;
- const char* dollarPtr = strchr(ptr, '$');
- if (!dollarPtr)
- break;
- s = String(ptr, (int)(dollarPtr - ptr));
- ptr = dollarPtr;
- }
- else
- {
- s += *ptr;
- }
- //int asmLine = atoi(s.c_str());
- //asmLines.push_back(asmLine);
- const char* sPtr = s.c_str();
- int decodedValue = (int)DecodeULEB32(sPtr);
- if (!parity)
- {
- curRunCount = decodedValue;
- }
- else
- {
- for (int iLine=0; iLine<curRunCount; ++iLine)
- {
- curAsmLine += decodedValue;
- asmLines.push_back(curAsmLine);
- }
- }
- parity = !parity;
- }
- BF_ASSERT(!parity);
- if (dwBlock->mAsmDebugLineMap == NULL)
- {
- mAsmDebugLineMaps.resize(mAsmDebugLineMaps.size() + 1);
- dwBlock->mAsmDebugLineMap = &mAsmDebugLineMaps.back();
- }
- auto mapIter = dwBlock->mAsmDebugLineMap->find(declLine);
- if (mapIter != dwBlock->mAsmDebugLineMap->end())
- {
- auto& dstVec = mapIter->second;
- dstVec.Reserve(dstVec.size() + asmLines.size());
- //dstVec.insert(dstVec.end(), asmLines.begin(), asmLines.end());
- if (!asmLines.IsEmpty())
- dstVec.Insert(dstVec.size(), &asmLines[0], asmLines.size());
- }
- else
- {
- (*dwBlock->mAsmDebugLineMap)[declLine] = std::move(asmLines);
- }
- break;
- }
- bool addToGlobalVarMap = false;
- bool isNewVariable = true;
- DbgVariable* dbgVariable = NULL;
- if (atSpecification != 0)
- {
- //dbgVariable = dataMap.Get<DbgVariable*>(atSpecification);
- //BF_ASSERT(dbgVariable != NULL);
- dbgVariable = GetOrCreate<DbgVariable*>(atSpecification, dataMap);
- //dbgVariable = dataMap.Get<DbgVariable*>(atSpecification);
- //BF_ASSERT(dbgVariable != NULL);
- }
- else if (dwBlock != NULL)
- {
- dbgVariable = GetOrCreate<DbgVariable*>(tagIdx, dataMap);
- dwBlock->mVariables.PushBack(dbgVariable);
- }
- else
- {
- DbgType* dbgType = GetStackTop<DbgType*>(&dataStack);
- bool wantGlobal = true;
- if (compileUnit->mLanguage == DbgLanguage_Beef)
- {
- // Don't show certain global variables in Beef -- that includes things like VTable data
- if (atName[0] == '_')
- wantGlobal = false;
- }
- if ((dbgType == NULL) && (wantGlobal))
- {
- /*DbgCompileUnit* topCompileUnit = GetStackTop<DbgCompileUnit*>(&dataStack);
- if (topCompileUnit != NULL)
- dbgType = &topCompileUnit->mGlobalType;*/
- dbgType = linkedModule->mMasterCompileUnit->mGlobalType;
- auto foundEntry = mGlobalVarMap.Find(atName);
- if (foundEntry != NULL)
- {
- isNewVariable = false;
- dbgVariable = foundEntry->mValue;
- }
- else
- {
- addToGlobalVarMap = true;
- }
- }
- if (dbgVariable == NULL)
- dbgVariable = GetOrCreate<DbgVariable*>(tagIdx, dataMap);
- dbgVariable->mIsStatic = true;
- //TODO: dbgType can be NULL. This only (apparently?) happens for DW_TAG_inlined_subroutine, which we don't handle right now...
- if (dbgType != NULL)
- {
- BF_ASSERT(dbgType->IsNamespace() || (dbgType->mTypeCode == DbgType_Root));
- if (isNewVariable)
- dbgType->mMemberList.PushBack(dbgVariable);
- }
- }
- if (dbgVariable != NULL)
- {
- if (atSpecification == 0)
- {
- dbgVariable->mIsParam = false;
- dbgVariable->mName = atName;
- dbgVariable->mConstValue = atConstValue;
- dbgVariable->mType = GetOrCreateType(atType, dataMap);
- dbgVariable->mIsConst = hadConstValue;
- dbgVariable->mIsStatic = !hadMemberLocation;
- dbgVariable->mIsExtern = atExternal != 0;
- }
- if (atLinkageName != NULL)
- dbgVariable->mLinkName = atLinkageName;
- dbgVariable->mLocationLen = (int8)atLocationLen;
- dbgVariable->mLocationData = atLocationData;
- dbgVariable->mCompileUnit = compileUnit;
- /*if (dbgVariable->mIsStatic && !dbgVariable->mIsConst && (dbgVariable->mLocationLen > 0) && (dbgVariable->mIsExtern))
- {
- DbgAddrType addrType = DbgAddrType_Value;
- //
- addr_target valAddr = mDebugTarget->EvaluateLocation(dbgVariable->mCompileUnit->mDbgModule, NULL, dbgVariable->mLocationData, dbgVariable->mLocationLen, NULL, &addrType);
- if ((addrType == DbgAddrType_Target) && (valAddr != 0))
- {
- dbgVariable->mStaticCachedAddr = valAddr;
- if (dbgVariable->mLinkName != NULL)
- mStaticVariables.push_back(dbgVariable);
- }
- else
- dbgVariable->mIsStatic = false;
- }*/
- // We had to remove the above for hot loading, calculate the mStaticCachedAddr later. Just put into mStaticVariables for now
- mStaticVariables.push_back(dbgVariable);
- if (atAbstractOrigin != NULL)
- {
- DbgVariable* originVariable = GetOrCreate<DbgVariable*>(atAbstractOrigin, dataMap);
- auto abstractOriginEntry = AbstractOriginEntry::Create(DbgVariable::ClassType, dbgVariable, originVariable);
- if (atAbstractOrigin < tagIdx)
- abstractOriginEntry.Replace();
- else
- abstractOriginReplaceList.push_back(abstractOriginEntry);
- }
- else if (dbgVariable->mName == NULL)
- dbgVariable->mName = "_unnamed";
- if (addToGlobalVarMap)
- mGlobalVarMap.Insert(dbgVariable);
- newDataPair = MakeDataPair(dbgVariable);
- }
- }
- break;
- case DW_TAG_formal_parameter:
- {
- DbgSubprogram* dwSubprogram = GetStackTop<DbgSubprogram*>(&dataStack);
- if (dwSubprogram == NULL)
- {
- if ((atName == NULL) && (atAbstractOrigin == 0))
- {
- DbgType* dbgType = GetStackTop<DbgType*>(&dataStack);
- if ((dbgType == NULL) || (dbgType->mTypeCode != DbgType_Subroutine))
- break;
- //TODO: Add params to subroutine type
- break;
- }
- break;
- }
- if ((dwSubprogram->mParams.IsEmpty()) && (dwSubprogram->mParentType != 0))
- dwSubprogram->mParentType->mMethodsWithParamsCount++;
- //DbgVariable* dbgVariable = mAlloc.Alloc<DbgVariable>();
- DbgVariable* dwVariable = GetOrCreate<DbgVariable*>(tagIdx, dataMap);
- dwSubprogram->mParams.PushBack(dwVariable);
- if (atArtificial != 0)
- {
- dwSubprogram->mHasThis = true;
- if (atName == NULL)
- atName = "this";
- }
- dwVariable->mCompileUnit = compileUnit;
- dwVariable->mIsParam = true;
- dwVariable->mName = atName;
- dwVariable->mLocationLen = (int)atLocationLen;
- dwVariable->mLocationData = atLocationData;
- dwVariable->mType = GetOrCreateType(atType, dataMap);
- if (atAbstractOrigin != 0)
- {
- }
- }
- break;
- case DW_TAG_enumerator:
- {
- DbgVariable* member = mAlloc.Alloc<DbgVariable>();
- member->mCompileUnit = compileUnit;
- member->mConstValue = atConstValue;
- member->mName = atName;
- member->mIsStatic = true;
- member->mIsConst = true;
- DbgType* parentType = GetStackTop<DbgType*>(&dataStack);
- parentType->mMemberList.PushBack(member);
- member->mMemberOffset = atDataMemberLocation;
- //member->mType = parentType->mTypeParam;
- member->mType = parentType;
- // Insert into parent's namespace
- auto prevTop = dataStack.back();
- dataStack.pop_back();
- DbgBlock* dwBlock = GetStackTop<DbgBlock*>(&dataStack);
- dataStack.push_back(prevTop);
- if (dwBlock != NULL)
- {
- DbgVariable* dwVariable = mAlloc.Alloc<DbgVariable>();
- dwBlock->mVariables.PushBack(dwVariable);
- if (atSpecification == 0)
- {
- dwVariable->mIsParam = false;
- dwVariable->mName = atName;
- dwVariable->mConstValue = atConstValue;
- dwVariable->mType = parentType->mTypeParam;
- dwVariable->mIsConst = hadConstValue;
- dwVariable->mIsStatic = !hadMemberLocation;
- }
- dwVariable->mLocationLen = (int)atLocationLen;
- dwVariable->mLocationData = atLocationData;
- dwVariable->mCompileUnit = compileUnit;
- BF_ASSERT(dwVariable->mName != 0);
- newDataPair = MakeDataPair(dwVariable);
- }
- }
- break;
- /*case DW_TAG_subrange_type:
- {
- DbgType* parentType = GetStackTop<DbgType*>(&dataStack);
- parentType->mArraySize = atUpperBound;
- }
- break;*/
- case DW_TAG_inheritance:
- {
- DbgType* derivedType = GetStackTop<DbgType*>(&dataStack);
- DbgBaseTypeEntry* baseTypeEntry = mAlloc.Alloc<DbgBaseTypeEntry>();
- baseTypeEntry->mBaseType = GetOrCreateType(atType, dataMap);
- if (atDataMemberData != NULL)
- {
- bool foundVirtOffset = false;
- const uint8* opPtr = atDataMemberData;
- if (*(opPtr++) == DW_OP_dup)
- {
- if (*(opPtr++) == DW_OP_deref)
- {
- if (*(opPtr++) == DW_OP_constu)
- {
- baseTypeEntry->mVTableOffset = (int)DecodeSLEB128(opPtr) / sizeof(int32);
- foundVirtOffset = true;
- if (*(opPtr++) == DW_OP_minus)
- baseTypeEntry->mVTableOffset = -baseTypeEntry->mVTableOffset;
- }
- }
- }
- BF_ASSERT(foundVirtOffset);
- }
- else
- baseTypeEntry->mThisOffset = atDataMemberLocation;
- derivedType->mBaseTypes.PushBack(baseTypeEntry);
- }
- break;
- case DW_TAG_member:
- {
- DbgType* parentType = GetStackTop<DbgType*>(&dataStack);
- if ((atName != NULL) && (strncmp(atName, "_vptr$", 6) == 0))
- {
- parentType->mHasVTable = true;
- break;
- }
- //DbgVariable* member = mAlloc.Alloc<DbgVariable>();
- DbgVariable* member = GetOrCreate<DbgVariable*>(tagIdx, dataMap);
- member->mIsMember = true;
- member->mCompileUnit = compileUnit;
- member->mName = atName;
- member->mType = GetOrCreateType(atType, dataMap);
- member->mConstValue = atConstValue;
- member->mIsConst = hadConstValue;
- member->mIsStatic = !hadMemberLocation;
- member->mBitSize = atBitSize;
- member->mBitOffset = atBitOffset;
- member->mIsExtern = atExternal != 0;
- parentType->mMemberList.PushBack(member);
- member->mMemberOffset = atDataMemberLocation;
- if ((member->mIsStatic) && (!member->mIsConst))
- parentType->mHasStaticMembers = true;
- /*if ((member->mIsStatic) && (!member->mIsConst))
- mStaticVariables.push_back(member);*/
- newDataPair = MakeDataPair(member);
- //dataMap.Set(tagIdx, member);
- }
- break;
- case DW_TAG_subrange_type:
- {
- int typeIdx = (int)(tagDataStart - startData);
- DbgType* parentType = GetStackTop<DbgType*>(&dataStack);
- int arrSize = atCount;
- deferredArrayDims.push_back(arrSize);
- }
- break;
- case DW_TAG_namespace:
- case DW_TAG_const_type:
- case DW_TAG_base_type:
- case DW_TAG_pointer_type:
- case DW_TAG_ptr_to_member_type:
- case DW_TAG_array_type:
- case DW_TAG_reference_type:
- case DW_TAG_rvalue_reference_type:
- case DW_TAG_unspecified_type:
- case DW_TAG_class_type:
- case DW_TAG_enumeration_type:
- case DW_TAG_structure_type:
- case DW_TAG_union_type:
- case DW_TAG_typedef:
- case DW_TAG_volatile_type:
- case DW_TAG_subroutine_type:
- //case DW_TAG_subrange_type:
- case DW_TAG_restrict_type:
- {
- int typeIdx = (int)(tagDataStart - startData);
- DbgType* dbgType = GetOrCreateType(typeIdx, dataMap);
- const char* nameSep = (compileUnit->mLanguage == DbgLanguage_Beef) ? "." : "::";
- if ((atName != NULL) &&
- ((entryTag == DW_TAG_structure_type) || (entryTag == DW_TAG_class_type) ||
- (entryTag == DW_TAG_typedef) || (entryTag == DW_TAG_union_type) || (entryTag == DW_TAG_enumeration_type) ||
- (entryTag == DW_TAG_namespace)))
- {
- BF_ASSERT(dbgType->mTypeCode == DbgType_Null);
- DbgType* parentType = GetStackTop<DbgType*>(&dataStack);
- if (parentType != NULL)
- {
- dbgType->mParent = parentType;
- dbgType->mParent->mSubTypeList.PushBack(dbgType);
- /*if (dbgType->mParent->mName != NULL)
- {
- if (atName == NULL)
- {
- dbgType->mName = dbgType->mParent->mName; // Extend from name of parent if we're anonymous
- }
- else
- {
- int nameSepLen = strlen(nameSep);
- int parentNameLen = strlen(dbgType->mParent->mName);
- int nameLen = strlen(atName);
- char* name = (char*)mAlloc.AllocBytes(parentNameLen + nameSepLen + nameLen + 1);
- memcpy(name, dbgType->mParent->mName, parentNameLen);
- memcpy(name + parentNameLen, nameSep, nameSepLen);
- memcpy(name + parentNameLen + nameSepLen, atName, nameLen);
- dbgType->mName = name;
- }
- }*/
- }
- else
- {
- // Add to global subtype list but don't set dbgType->mParent
- compileUnit->mGlobalType->mSubTypeList.PushBack(dbgType);
- }
- }
- const char* useName = atName;
- /*if ((useName != NULL) && (strcmp(useName, "@") == 0))
- useName = NULL;*/
- dbgType->mCompileUnit = compileUnit;
- dbgType->mLanguage = compileUnit->mLanguage;
- //SplitName(atName, dbgType->mTypeName, dbgType->mTemplateParams);
- dbgType->mName = useName;
- if (dbgType->mTypeName == NULL)
- dbgType->mTypeName = useName;
- //if (dbgType->mName == NULL)
- //dbgType->mName = atName;
- int parentNameLen = ((dbgType->mParent != NULL) && (dbgType->mParent->mName != NULL)) ? (int)strlen(dbgType->mParent->mName) : 0;
- int typeNameLen = (dbgType->mTypeName != NULL) ? (int)strlen(dbgType->mTypeName) : 0;
- //int templateParamsLen = (dbgType->mTemplateParams != NULL) ? strlen(dbgType->mTemplateParams) : 0;
- if ((parentNameLen != 0) /*&& (templateParamsLen == 0)*/)
- {
- int nameSepLen = (int)strlen(nameSep);
- int nameLen = parentNameLen + typeNameLen /*+ templateParamsLen*/;
- if ((parentNameLen > 0) && (nameLen > 0))
- nameLen += nameSepLen;
- char* namePtr = (char*)mAlloc.AllocBytes(nameLen + 1, "DWARF");
- dbgType->mName = namePtr;
- if (parentNameLen > 0)
- {
- memcpy(namePtr, dbgType->mParent->mName, parentNameLen);
- namePtr += parentNameLen;
- if (nameLen > 0)
- {
- memcpy(namePtr, nameSep, nameSepLen);
- namePtr += nameSepLen;
- }
- }
- if (nameLen > 0)
- {
- memcpy(namePtr, useName, typeNameLen);
- namePtr += typeNameLen;
- }
- /*if (templateParamsLen > 0)
- {
- memcpy(namePtr, dbgType->mTemplateParams, templateParamsLen);
- namePtr += templateParamsLen;
- }*/
- }
- dbgType->mTypeCode = DbgType_Null;
- dbgType->mIsDeclaration = atDeclaration;
- if (atByteSize != -1)
- {
- dbgType->mSize = atByteSize;
- dbgType->mSizeCalculated = true;
- }
- switch (entryTag)
- {
- case DW_TAG_base_type:
- // Types that may do fallover to int/uints on size mismatch
- switch (atEncoding)
- {
- case DW_ATE_UTF:
- if (atByteSize == 1)
- dbgType->mTypeCode = DbgType_Utf8;
- else if (atByteSize == 2)
- dbgType->mTypeCode = DbgType_Utf16;
- else
- dbgType->mTypeCode = DbgType_Utf32;
- break;
- case DW_ATE_signed_char:
- if (atByteSize == 1)
- dbgType->mTypeCode = DbgType_SChar;
- else if (atByteSize == 2)
- dbgType->mTypeCode = DbgType_SChar16;
- else if (atByteSize == 4)
- dbgType->mTypeCode = DbgType_SChar32;
- else
- atEncoding = DW_ATE_signed;
- break;
- case DW_ATE_unsigned_char:
- if (atByteSize == 1)
- dbgType->mTypeCode = DbgType_UChar;
- else if (atByteSize == 2)
- dbgType->mTypeCode = DbgType_UChar16;
- else if (atByteSize == 4)
- dbgType->mTypeCode = DbgType_UChar32;
- atEncoding = DW_ATE_unsigned;
- break;
- case DW_ATE_boolean:
- if (atByteSize == 1)
- dbgType->mTypeCode = DbgType_Bool;
- else
- atEncoding = DW_ATE_unsigned;
- break;
- }
- if (dbgType->mTypeCode == DbgType_Null)
- {
- switch (atEncoding)
- {
- case DW_ATE_address:
- if (atByteSize == 0)
- dbgType->mTypeCode = DbgType_Void;
- break;
- case DW_ATE_boolean:
- if (atByteSize == 1)
- {
- dbgType->mTypeCode = DbgType_Bool;
- break;
- }
- //Fall through
- case DW_ATE_signed:
- switch (atByteSize)
- {
- case 1:
- dbgType->mTypeCode = DbgType_i8;
- break;
- case 2:
- dbgType->mTypeCode = DbgType_i16;
- break;
- case 4:
- dbgType->mTypeCode = DbgType_i32;
- break;
- case 8:
- dbgType->mTypeCode = DbgType_i64;
- break;
- case 16:
- dbgType->mTypeCode = DbgType_i128;
- break;
- }
- break;
- case DW_ATE_unsigned:
- switch (atByteSize)
- {
- case 1:
- dbgType->mTypeCode = DbgType_u8;
- break;
- case 2:
- if ((atName != NULL) && (strcmp(atName, "wchar_t") == 0))
- dbgType->mTypeCode = DbgType_UChar16;
- else
- dbgType->mTypeCode = DbgType_u16;
- break;
- case 4:
- dbgType->mTypeCode = DbgType_u32;
- break;
- case 8:
- dbgType->mTypeCode = DbgType_u64;
- break;
- case 16:
- dbgType->mTypeCode = DbgType_u128;
- break;
- }
- break;
- case DW_ATE_float:
- if (atByteSize == 4)
- dbgType->mTypeCode = DbgType_Single;
- else if (atByteSize == 8)
- dbgType->mTypeCode = DbgType_Double;
- else if (atByteSize == 12)
- dbgType->mTypeCode = DbgType_Float96;
- else if (atByteSize == 16)
- dbgType->mTypeCode = DbgType_Float128;
- break;
- case DW_ATE_complex_float:
- if (atByteSize == 8)
- dbgType->mTypeCode = DbgType_ComplexFloat;
- else if (atByteSize == 16)
- dbgType->mTypeCode = DbgType_ComplexDouble;
- else if (atByteSize == 24)
- dbgType->mTypeCode = DbgType_ComplexDouble96;
- else if (atByteSize == 32)
- dbgType->mTypeCode = DbgType_ComplexDouble128;
- break;
- default:
- BF_FATAL("Unknown DW_ATE type");
- break;
- }
- }
- break;
- case DW_TAG_enumeration_type: //TODO: Handle these differently
- dbgType->mTypeCode = DbgType_Enum;
- dbgType->mTypeParam = mAlloc.Alloc<DbgType>();
- if (atByteSize == 8)
- dbgType->mTypeParam->mTypeCode = DbgType_i64;
- else if (atByteSize == 4)
- dbgType->mTypeParam->mTypeCode = DbgType_i32;
- else if (atByteSize == 2)
- dbgType->mTypeParam->mTypeCode = DbgType_i16;
- else if (atByteSize == 1)
- dbgType->mTypeParam->mTypeCode = DbgType_i8;
- else
- {
- BF_DBG_FATAL("Invalid enum type");
- }
- break;
- case DW_TAG_namespace:
- dbgType->mTypeCode = DbgType_Namespace;
- break;
- case DW_TAG_const_type:
- dbgType->mTypeCode = DbgType_Const;
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- break;
- case DW_TAG_rvalue_reference_type:
- dbgType->mTypeCode = DbgType_RValueReference;
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- break;
- case DW_TAG_unspecified_type:
- dbgType->mTypeCode = DbgType_Unspecified;
- dbgType->mTypeName = atName;
- break;
- case DW_TAG_reference_type:
- dbgType->mTypeCode = DbgType_Ref;
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- break;
- case DW_TAG_pointer_type:
- dbgType->mTypeCode = DbgType_Ptr;
- dbgType->mSize = sizeof(addr_target);
- dbgType->mSizeCalculated = true;
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- if (dbgType->mTypeParam != NULL)
- dbgType->mTypeParam->mPtrType = dbgType;
- break;
- case DW_TAG_ptr_to_member_type:
- dbgType->mTypeCode = DbgType_PtrToMember;
- dbgType->mSize = sizeof(addr_target);
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- if (dbgType->mTypeParam != NULL)
- dbgType->mTypeParam->mPtrType = dbgType;
- break;
- case DW_TAG_array_type:
- dbgType->mTypeCode = DbgType_SizedArray;
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- break;
- case DW_TAG_structure_type:
- dbgType->mTypeCode = DbgType_Struct;
- break;
- case DW_TAG_class_type:
- dbgType->mTypeCode = DbgType_Class;
- break;
- case DW_TAG_union_type:
- dbgType->mTypeCode = DbgType_Union;
- break;
- case DW_TAG_typedef:
- dbgType->mTypeCode = DbgType_TypeDef;
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- break;
- case DW_TAG_volatile_type:
- dbgType->mTypeCode = DbgType_Volatile;
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- break;
- case DW_TAG_subroutine_type:
- dbgType->mTypeCode = DbgType_Subroutine;
- if (atType != 0) // Return value
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- dbgType->mBlockParam = mAlloc.Alloc<DbgBlock>();
- break;
- case DW_TAG_restrict_type:
- dbgType->mTypeCode = DbgType_Restrict;
- dbgType->mTypeParam = GetOrCreateType(atType, dataMap);
- break;
- }
- newDataPair = MakeDataPair(dbgType);
- }
- break;
- }
- if (hasChildren)
- dataStack.push_back(newDataPair);
- }
- for (auto& abstractOriginEntry : abstractOriginReplaceList)
- abstractOriginEntry.Replace();
- GetLinkedModule()->MapTypes(startingTypeIdx);
- dataPtr = dataEnd;
- return true;
- }
- void DbgModule::ParseDebugFrameData()
- {
- BP_ZONE("ParseDebugFrameData");
- const uint8* data = mDebugFrameData;
- if (data == NULL)
- return;
- mParsedFrameDescriptors = true;
- Dictionary<addr_target, DwCommonFrameDescriptor*> commonFrameDescriptorMap;
- while (true)
- {
- addr_target relSectionAddr = (addr_target)(data - mDebugFrameData);
- int length = GET(int);
- if (length == 0)
- break;
- const uint8* dataEnd = data + length;
- int cieID = GET(int);
- if (cieID < 0)
- {
- BP_ALLOC_T(DwCommonFrameDescriptor);
- DwCommonFrameDescriptor* commonFrameDescriptor = mAlloc.Alloc<DwCommonFrameDescriptor>();
- char version = GET(char);
- commonFrameDescriptor->mDbgModule = this;
- commonFrameDescriptor->mAugmentation = DataGetString(data);
- if (version >= 4)
- {
- commonFrameDescriptor->mPointerSize = GET(int8);
- commonFrameDescriptor->mSegmentSize = GET(int8);
- }
- commonFrameDescriptor->mCodeAlignmentFactor = (int)DecodeULEB128(data);
- commonFrameDescriptor->mDataAlignmentFactor = (int)DecodeSLEB128(data);
- commonFrameDescriptor->mReturnAddressColumn = (int)DecodeULEB128(data);
- commonFrameDescriptor->mInstData = data;
- commonFrameDescriptor->mInstLen = (int)(dataEnd - data);
- mDebugTarget->mCommonFrameDescriptors.push_back(commonFrameDescriptor);
- if (version < 3)
- commonFrameDescriptorMap[relSectionAddr] = commonFrameDescriptor;
- else
- commonFrameDescriptorMap[mDebugFrameAddress + relSectionAddr] = commonFrameDescriptor;
- }
- else
- {
- addr_target lowPC = GET(addr_target);
- addr_target highPC = lowPC + GET(addr_target);
- DwCommonFrameDescriptor* commonFrameDescriptor = commonFrameDescriptorMap[(addr_target)cieID];
- BF_ASSERT(commonFrameDescriptor != NULL);
- typedef decltype(mDebugTarget->mDwFrameDescriptorMap) MapType;
- auto resultPair = mDebugTarget->mDwFrameDescriptorMap.insert(MapType::value_type(lowPC, DwFrameDescriptor()));
- auto frameDescriptor = &resultPair.first->second;
- //frameDescriptor->
- frameDescriptor->mLowPC = lowPC;
- frameDescriptor->mHighPC = highPC;
- frameDescriptor->mInstData = data;
- frameDescriptor->mInstLen = (int)(dataEnd - data);
- frameDescriptor->mCommonFrameDescriptor = commonFrameDescriptor;
- }
- data = dataEnd;
- }
- }
- void DbgModule::ParseEHFrameData()
- {
- const uint8* data = mEHFrameData;
- if (data == NULL)
- return;
- Dictionary<addr_target, DwCommonFrameDescriptor*> commonFrameDescriptorMap;
- while (true)
- {
- addr_target sectionAddress = (addr_target)(data - mEHFrameData);
- int length = GET(int);
- if (length == 0)
- break;
- const uint8* dataEnd = data + length;
- int cieID = GET(int);
- if (cieID <= 0)
- {
- BP_ALLOC_T(DwCommonFrameDescriptor);
- DwCommonFrameDescriptor* commonFrameDescriptor = mAlloc.Alloc<DwCommonFrameDescriptor>();
- char version = GET(char);
- const char* augmentation = DataGetString(data);
- commonFrameDescriptor->mDbgModule = this;
- commonFrameDescriptor->mCodeAlignmentFactor = (int)DecodeULEB128(data);
- commonFrameDescriptor->mDataAlignmentFactor = (int)DecodeSLEB128(data);
- commonFrameDescriptor->mReturnAddressColumn = (int)DecodeULEB128(data);
- commonFrameDescriptor->mAugmentation = augmentation;
- if (*augmentation == 'z')
- {
- ++augmentation;
- int augLen = (int)DecodeULEB128(data);
- commonFrameDescriptor->mAugmentationLength = augLen;
- const uint8* augEnd = data + augLen;
- while (*augmentation != '\0')
- {
- if (*augmentation == 'R')
- commonFrameDescriptor->mAddressPointerEncoding = (int) GET(uint8);
- else if (*augmentation == 'P')
- {
- int encodingType = GET(uint8);
- BF_ASSERT(encodingType == 0);
- commonFrameDescriptor->mLSDARoutine = GET(addr_target);
- }
- else if (*augmentation == 'L')
- commonFrameDescriptor->mLSDAPointerEncodingFDE = GET(uint8);
- else if (*augmentation == 'S')
- {
- // mIsSignalHandler - on return from stack frame, CFA is before next instruction rather than after it
- }
- else
- BF_FATAL("Unknown CIE augmentation");
- ++augmentation;
- }
- data = augEnd;
- }
- commonFrameDescriptor->mInstData = data;
- commonFrameDescriptor->mInstLen = (int)(dataEnd - data);
- mDebugTarget->mCommonFrameDescriptors.push_back(commonFrameDescriptor);
- commonFrameDescriptorMap[sectionAddress] = commonFrameDescriptor;
- }
- else
- {
- int ciePos = (int)(sectionAddress - cieID) + 4;
- DwCommonFrameDescriptor* commonFrameDescriptor = commonFrameDescriptorMap[(addr_target)ciePos];
- addr_target lowPC;
- addr_target highPC;
- if (commonFrameDescriptor->mAddressPointerEncoding == (DW_EH_PE_pcrel | DW_EH_PE_sdata4))
- {
- lowPC = GET(int);
- lowPC += mEHFrameAddress + sectionAddress + 8;
- highPC = lowPC + GET(int);
- }
- else
- {
- lowPC = GET(int);
- highPC = lowPC + GET(int);
- }
- typedef decltype(mDebugTarget->mDwFrameDescriptorMap) MapType;
- auto resultPair = mDebugTarget->mDwFrameDescriptorMap.insert(MapType::value_type(lowPC, DwFrameDescriptor()));
- auto frameDescriptor = &resultPair.first->second;
- frameDescriptor->mLSDARoutine = commonFrameDescriptor->mLSDARoutine;
- const char* augmentation = commonFrameDescriptor->mAugmentation;
- if (*augmentation == 'z')
- {
- int augLen = GET(uint8);
- const uint8* augEnd = data + augLen;
- ++augmentation;
- while (*augmentation != '\0')
- {
- if (*augmentation == 'R')
- {
- }
- else if (*augmentation == 'P')
- {
- }
- else if (*augmentation == 'L')
- {
- BF_ASSERT(commonFrameDescriptor->mLSDAPointerEncodingFDE == 0);
- frameDescriptor->mLSDARoutine = GET(addr_target);
- }
- else if (*augmentation == 'S')
- {
- }
- else
- BF_FATAL("Unknown CIE augmentation");
- augmentation++;
- }
- data = augEnd;
- }
- frameDescriptor->mLowPC = lowPC;
- frameDescriptor->mHighPC = highPC;
- frameDescriptor->mInstData = data;
- frameDescriptor->mInstLen = (int)(dataEnd - data);
- frameDescriptor->mCommonFrameDescriptor = commonFrameDescriptor;
- }
- data = dataEnd;
- }
- }
- void DbgModule::FlushLineData(DbgSubprogram* curSubprogram, std::list<DbgLineData>& queuedLineData)
- {
- }
- DbgSrcFile* DbgModule::AddSrcFile(DbgCompileUnit* compileUnit, const String& srcFilePath)
- {
- DbgSrcFile* dwSrcFile = mDebugTarget->AddSrcFile(srcFilePath);
- if (compileUnit != NULL)
- {
- DbgSrcFileReference srcFileRef;
- srcFileRef.mSrcFile = dwSrcFile;
- srcFileRef.mCompileUnit = compileUnit;
- compileUnit->mSrcFileRefs.push_back(srcFileRef);
- }
- return dwSrcFile;
- }
- bool DbgModule::ParseDebugLineInfo(const uint8*& dataPtr, int compileUnitIdx)
- {
- BP_ZONE("ParseDebugLineInfo");
- const uint8* data = dataPtr;
- const int startOffset = (int)(data - mDebugLineData);
- int length = GET(int);
- if (length == 0)
- return false;
- DbgCompileUnit* dwCompileUnit = mCompileUnits[compileUnitIdx];
- const uint8* dataEnd = data + length;
- short version = GET(short);
- int headerLength = GET(int);
- char minimumInstructionLength = GET(char);
- int maximumOperationsPerInstruction = 1;
- char defaultIsStmt = GET(char);
- char lineBase = GET(char);
- char lineRange = GET(char);
- char opcodeBase = GET(char);
- for (int i = 0; i < opcodeBase - 1; i++)
- {
- char standardOpcodeLengths = GET(char);
- }
- Array<const char*> directoryNames;
- while (true)
- {
- const char* name = DataGetString(data);
- if (name[0] == 0)
- break;
- directoryNames.push_back(name);
- }
- DbgSrcFileReference* dwSrcFileRef = NULL;
- HashSet<String> foundPathSet;
- int curFileIdx = 0;
- DbgSubprogram* curSubprogram = NULL;
- #define ADD_LINEDATA(lineData) \
- lineBuilder.Add(dwCompileUnit, lineData, dwSrcFileRef->mSrcFile, NULL);
- while (true)
- {
- const char* path = DataGetString(data);
- if (path[0] == 0)
- break;
- int directoryIdx = (int)DecodeULEB128(data);
- int lastModificationTime = (int)DecodeULEB128(data);
- int fileLength = (int)DecodeULEB128(data);
- String filePath;
- if (directoryIdx > 0)
- filePath = String(directoryNames[directoryIdx - 1]) + "/";
- filePath += path;
- filePath = GetAbsPath(filePath, dwCompileUnit->mCompileDir);
- AddSrcFile(dwCompileUnit, filePath.c_str());
- }
- if (dwCompileUnit->mSrcFileRefs.size() > 0)
- dwSrcFileRef = &dwCompileUnit->mSrcFileRefs.front();
- DbgLineDataBuilder lineBuilder(this);
- bool queuedPostPrologue = false;
- DbgLineDataState dwLineData;
- dwLineData.mLine = 0;
- dwLineData.mRelAddress = 0;
- dwLineData.mOpIndex = 0;
- dwLineData.mBasicBlock = false;
- dwLineData.mDiscriminator = 0;
- dwLineData.mIsStmt = defaultIsStmt != 0;
- dwLineData.mIsa = 0;
- dwLineData.mColumn = -2;
- while (data < dataEnd)
- {
- uint8_t opcode = GET(uint8_t);
- switch (opcode)
- {
- case DW_LNS_extended_op:
- {
- int len = (int)DecodeULEB128(data);
- uint8_t exOpcode = GET(uint8_t);
- switch (exOpcode)
- {
- case DW_LNE_end_sequence:
- {
- ADD_LINEDATA(dwLineData);
- dwSrcFileRef = &dwCompileUnit->mSrcFileRefs[0];
- dwLineData.mLine = 0;
- dwLineData.mRelAddress = 0;
- dwLineData.mOpIndex = 0;
- dwLineData.mBasicBlock = false;
- dwLineData.mDiscriminator = 0;
- dwLineData.mIsStmt = defaultIsStmt != 0;
- dwLineData.mIsa = 0;
- dwLineData.mColumn = -2;
- }
- break;
- case DW_LNE_set_address:
- dwLineData.mRelAddress = (uint32)(RemapAddr(GET(addr_target)) - mImageBase);
- break;
- case DW_LNE_define_file:
- {
- const char* path = DataGetString(data);
- int directoryIdx = (int)DecodeULEB128(data);
- int lastModificationTime = (int)DecodeULEB128(data);
- int fileLength = (int)DecodeULEB128(data);
- }
- break;
- case DW_LNE_set_discriminator:
- dwLineData.mDiscriminator = (int)DecodeULEB128(data);
- break;
- }
- }
- break;
- case DW_LNS_copy:
- ADD_LINEDATA(dwLineData);
- dwLineData.mDiscriminator = 0;
- dwLineData.mBasicBlock = false;
- break;
- case DW_LNS_advance_pc:
- {
- int advance = (int)DecodeULEB128(data);
- dwLineData.mRelAddress += advance;
- // How to advance opCode addr?
- }
- break;
- case DW_LNS_advance_line:
- {
- int advance = (int)DecodeSLEB128(data);
- dwLineData.mLine += advance;
- }
- break;
- case DW_LNS_set_file:
- {
- curFileIdx = (int)DecodeULEB128(data) - 1;
- dwSrcFileRef = &dwCompileUnit->mSrcFileRefs[curFileIdx];
- //dwLineData.mSrcFileRef = dwSrcFileRef;
- }
- break;
- case DW_LNS_set_column:
- {
- dwLineData.mColumn = (int)DecodeULEB128(data) - 1;
- }
- break;
- case DW_LNS_negate_stmt:
- {
- dwLineData.mIsStmt = !dwLineData.mIsStmt;
- }
- break;
- case DW_LNS_set_basic_block:
- {
- dwLineData.mBasicBlock = true;
- }
- break;
- case DW_LNS_const_add_pc:
- {
- int adjustedOpcode = 255 - opcodeBase;
- int opAdvance = adjustedOpcode / lineRange;
- uint32 newAddress = dwLineData.mRelAddress + minimumInstructionLength * ((dwLineData.mOpIndex + opAdvance) / maximumOperationsPerInstruction);
- int newOpIndex = (dwLineData.mOpIndex + opAdvance) % maximumOperationsPerInstruction;
- dwLineData.mRelAddress = newAddress;
- dwLineData.mOpIndex = newOpIndex;
- }
- break;
- case DW_LNS_fixed_advance_pc:
- {
- uint16_t advance = GET(uint16_t);
- dwLineData.mRelAddress += advance;
- dwLineData.mOpIndex = 0;
- }
- break;
- case DW_LNS_set_prologue_end:
- {
- queuedPostPrologue = true;
- }
- break;
- case DW_LNS_set_epilogue_begin:
- {
- dwLineData.mColumn = -2;
- }
- break;
- case DW_LNS_set_isa:
- {
- dwLineData.mIsa = (int)DecodeULEB128(data);
- }
- break;
- default:
- {
- // Special opcode
- int adjustedOpcode = opcode - opcodeBase;
- int opAdvance = adjustedOpcode / lineRange;
- uint32 oldAddress = dwLineData.mRelAddress;
- uint32 newAddress = dwLineData.mRelAddress + minimumInstructionLength * ((dwLineData.mOpIndex + opAdvance) / maximumOperationsPerInstruction);
- int newOpIndex = (dwLineData.mOpIndex + opAdvance) % maximumOperationsPerInstruction;
- int lineIncrement = lineBase + (adjustedOpcode % lineRange);
- dwLineData.mLine += lineIncrement;
- dwLineData.mRelAddress = newAddress;
- dwLineData.mOpIndex = newOpIndex;
- DbgLineData* lastLineData = NULL;
- if ((newAddress == oldAddress) && (queuedPostPrologue) && (curSubprogram != NULL) && (curSubprogram->mBlock.mLowPC == newAddress))
- {
- // Adjust this line later
- ADD_LINEDATA(dwLineData);
- }
- queuedPostPrologue = false;
- }
- break;
- }
- }
- lineBuilder.Commit();
- dataPtr = data;
- return true;
- }
- addr_target DbgModule::GetHotTargetAddress(DbgHotTargetSection* hotTargetSection)
- {
- if ((hotTargetSection->mTargetSectionAddr == NULL) && (hotTargetSection->mDataSize > 0))
- {
- if (hotTargetSection->mNoTargetAlloc)
- return 0;
- hotTargetSection->mTargetSectionAddr = mDebugger->AllocHotTargetMemory(hotTargetSection->mDataSize, hotTargetSection->mCanExecute, hotTargetSection->mCanWrite, &hotTargetSection->mTargetSectionSize);
- hotTargetSection->mImageOffset = (int)mImageSize;
- if (mImageBase == NULL)
- {
- mImageBase = hotTargetSection->mTargetSectionAddr;
- mOrigImageData->mAddr = mImageBase;
- }
- mImageSize += hotTargetSection->mTargetSectionSize;
- /*if (mExceptionData == hotTargetSection->mData)
- mExceptionDataRVA = (addr_target)(hotTargetSection->mTargetSectionAddr - mImageBase);*/
- }
- return hotTargetSection->mTargetSectionAddr;
- }
- uint8* DbgModule::GetHotTargetData(addr_target address)
- {
- for (int sectNum = 0; sectNum < (int)mHotTargetSections.size(); sectNum++)
- {
- if (mHotTargetSections[sectNum] != NULL)
- {
- DbgHotTargetSection* hotTargetSection = mHotTargetSections[sectNum];
- if ((address >= hotTargetSection->mTargetSectionAddr) && (address < hotTargetSection->mTargetSectionAddr + hotTargetSection->mTargetSectionSize))
- {
- return hotTargetSection->mData + (address - hotTargetSection->mTargetSectionAddr);
- }
- }
- }
- return NULL;
- }
- void DbgModule::DoReloc(DbgHotTargetSection* hotTargetSection, COFFRelocation& coffReloc, addr_target resolvedSymbolAddr, PE_SymInfo* symInfo)
- {
- #ifdef BF_DBG_32
- if (coffReloc.mType == IMAGE_REL_I386_DIR32)
- {
- *(uint32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += resolvedSymbolAddr;
- }
- else if (coffReloc.mType == IMAGE_REL_I386_DIR32NB)
- {
- GetHotTargetAddress(hotTargetSection); // Just to make sure we have mImageBase
- // We were previously using mImageBase instead of mDebugTarget->mTargetBinary->mImageBase. Was there a reason for that?
- // It was causing hot-loaded jump tables to have invalid addresses since the need to be relative to __ImageBase
- *(uint32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += (uint32)(resolvedSymbolAddr - GetTargetImageBase());
- }
- else if (coffReloc.mType == IMAGE_REL_I386_REL32)
- {
- addr_target myAddr = GetHotTargetAddress(hotTargetSection) + coffReloc.mVirtualAddress;
- *(uint32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += resolvedSymbolAddr - myAddr - sizeof(int32);
- }
- else if (coffReloc.mType == IMAGE_REL_I386_SECTION)
- {
- // auto linkedModule = GetLinkedModule();
- // addr_target mappedAddr = resolvedSymbolAddr & ~0x7FFFFFF;
- // int* encodingPtr = NULL;
- // if (linkedModule->mSecRelEncodingMap.TryAdd(mappedAddr, NULL, &encodingPtr))
- // {
- // *encodingPtr = (int)linkedModule->mSecRelEncodingVec.size();
- // linkedModule->mSecRelEncodingVec.push_back(mappedAddr);
- // }
- // *(uint16*)(hotTargetSection->mData + coffReloc.mVirtualAddress) = 0x8000 | *encodingPtr;
- *(uint16*)(hotTargetSection->mData + coffReloc.mVirtualAddress) = 0;
- }
- else if (coffReloc.mType == IMAGE_REL_I386_SECREL)
- {
- //*(uint32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += symInfo->mValue;
- *(uint32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += resolvedSymbolAddr;
- }
- else
- {
- BF_ASSERT(0=="Invalid COFF reloc type");
- }
- #else
- // CodeView uses SECTION:SECREL locations, and we just want to find a mapping such that
- // COFF::GetSectionAddr can map it to the 64-bit address. We do this by encoding the
- // lower 31 bits in the SECREL (allowing a 31-bit offset at the destination as well)
- // and then we use a 15-bit key to map the upper bits
- if (coffReloc.mType == IMAGE_REL_AMD64_REL32)
- {
- addr_target myAddr = GetHotTargetAddress(hotTargetSection) + coffReloc.mVirtualAddress;
- intptr_target addrOffset = resolvedSymbolAddr - myAddr - sizeof(int32);
- BF_ASSERT((int64)(int32)addrOffset == addrOffset);
- *(uint32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += (int32)addrOffset;
- }
- else if (coffReloc.mType == IMAGE_REL_AMD64_SECTION)
- {
- /*if (symInfo != NULL)
- {
- *(uint16*)(hotTargetSection->mData + coffReloc.mVirtualAddress) = symInfo->mSectionNum;
- }
- else*/
- {
- auto linkedModule = GetLinkedModule();
- addr_target mappedAddr = resolvedSymbolAddr & ~0x7FFFFFF;
- /*auto pair = linkedModule->mSecRelEncodingMap.insert(std::make_pair(mappedAddr, (int)linkedModule->mSecRelEncodingMap.size()));
- if (pair.second)
- linkedModule->mSecRelEncodingVec.push_back(mappedAddr);*/
- int* encodingPtr = NULL;
- if (linkedModule->mSecRelEncodingMap.TryAdd(mappedAddr, NULL, &encodingPtr))
- {
- *encodingPtr = (int)linkedModule->mSecRelEncodingVec.size();
- linkedModule->mSecRelEncodingVec.push_back(mappedAddr);
- }
- //*(uint16*)(hotTargetSection->mData + coffReloc.mVirtualAddress) = 0x8000 | pair.first->second;
- *(uint16*)(hotTargetSection->mData + coffReloc.mVirtualAddress) = 0x8000 | *encodingPtr;
- }
- }
- else if (coffReloc.mType == IMAGE_REL_AMD64_SECREL)
- {
- auto linkedModule = GetLinkedModule();
- if ((resolvedSymbolAddr >= linkedModule->mTLSAddr) && (resolvedSymbolAddr < linkedModule->mTLSAddr + linkedModule->mTLSSize))
- {
- // Make relative to actual TLS data
- resolvedSymbolAddr -= linkedModule->mTLSAddr;
- }
- *(uint32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += (uint32)(resolvedSymbolAddr & 0x7FFFFFF);
- }
- else if (coffReloc.mType == IMAGE_REL_AMD64_ADDR64)
- {
- *(uint64*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += resolvedSymbolAddr;
- }
- else if (coffReloc.mType == IMAGE_REL_AMD64_ADDR32NB)
- {
- GetHotTargetAddress(hotTargetSection); // Just to make sure we have mImageBase
- // We were previously using mImageBase instead of mDebugTarget->mTargetBinary->mImageBase. Was there a reason for that?
- // It was causing hot-loaded jump tables to have invalid addresses since the need to be relative to __ImageBase
- *(uint32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += (uint32)(resolvedSymbolAddr - GetTargetImageBase());
- //*(int32*)(hotTargetSection->mData + coffReloc.mVirtualAddress) += secRelAddr;
- }
- else
- {
- BF_ASSERT(0=="Invalid COFF reloc type");
- }
- #endif
- }
- bool DbgModule::IsHotSwapPreserve(const String& name)
- {
- // We have different rules for overwriting symbols in DWARF vs CodeView
- // Since MS mangling includes return types, we know that a type change of a static
- // member will mangle to a new name whereas with DWARF we DO want a new
- // address if the type changes but we can't tell that based on the mangle alone,
- // thus the reliance on the side table of mStaticVariables. We still do need
- // to determine whether the symbol is data (and thus we do preserve) or a method
- // (in which case we don't)
- if ((mDbgFlavor == DbgFlavor_MS) && (BfDemangler::IsData(name)))
- {
- if ((!name.StartsWith("?")) && (name.Contains("sBfTypeData"))) // We DO need to replace the fields/methods/etc but not the base sBfTypeData
- return false;
- if (name.StartsWith("?bf_hs_replace_"))
- return false;
- return true;
- }
- const char* prefix = "bf_hs_preserve@";
- return strncmp(name.c_str(), prefix, strlen(prefix)) == 0;
- }
- void DbgModule::ParseHotTargetSections(DataStream* stream, addr_target* resolvedSymbolAddrs)
- {
- auto mainModule = mDebugTarget->mTargetBinary;
- mainModule->ParseSymbolData();
- String name;
- for (int sectNum = 0; sectNum < (int)mHotTargetSections.size(); sectNum++)
- {
- if (mHotTargetSections[sectNum] != NULL)
- {
- DbgHotTargetSection* hotTargetSection = mHotTargetSections[sectNum];
- stream->SetPos(hotTargetSection->mPointerToRelocations);
- for (int relocIdx = 0; relocIdx < hotTargetSection->mNumberOfRelocations; relocIdx++)
- {
- COFFRelocation coffReloc;
- stream->Read(&coffReloc, sizeof(COFFRelocation));
- PE_SymInfo* symInfo = (PE_SymInfo*)&mSymbolData[coffReloc.mSymbolTableIndex * 18];
- //const char* symName = mSymbolData[coffReloc.mSymbolTableIndex];
- bool isStaticSymbol = symInfo->mStorageClass == COFF_SYM_CLASS_STATIC;
- if (symInfo->mNameOfs[0] != 0)
- {
- if (symInfo->mName[7] != 0)
- {
- // Name is exactly 8 chars, not null terminated yet
- name = String(symInfo->mName, symInfo->mName + 8);
- }
- else
- name = symInfo->mName;
- }
- else
- name = mStringTable + symInfo->mNameOfs[1];
- bool didNameMatch = false;
- addr_target resolvedSymbolAddr = resolvedSymbolAddrs[coffReloc.mSymbolTableIndex];
- #ifdef BF_DBG_32
- bool needsSymbolAddr = (coffReloc.mType == IMAGE_REL_I386_DIR32) || (coffReloc.mType == IMAGE_REL_I386_REL32) || (coffReloc.mType == IMAGE_REL_I386_SECREL) || (coffReloc.mType == IMAGE_REL_I386_SECTION);
- if (name[0] == '_')
- name.Remove(0, 1);
- #else
- bool needsSymbolAddr = (coffReloc.mType == IMAGE_REL_AMD64_ADDR64) || (coffReloc.mType == IMAGE_REL_AMD64_ADDR32) || (coffReloc.mType == IMAGE_REL_AMD64_ADDR32NB) ||
- ((coffReloc.mType >= IMAGE_REL_AMD64_REL32) || (coffReloc.mType <= IMAGE_REL_AMD64_REL32_5));
- #endif
- bool isHsPrev = false;
- if (name.StartsWith("bf_hs_prev@"))
- {
- isHsPrev = true;
- name.Remove(0, 11);
- }
- bool deferResolve = false;
- if ((resolvedSymbolAddr == 0) && (needsSymbolAddr))
- {
- bool isHotSwapPreserve = IsHotSwapPreserve(name);
- if ((symInfo->mSectionNum == 0) || (isHotSwapPreserve) || (isHsPrev))
- {
- auto origSymbolEntry = mainModule->mSymbolNameMap.Find(name.c_str());
- if (origSymbolEntry != NULL)
- {
- resolvedSymbolAddr = origSymbolEntry->mValue->mAddress;
- }
- else
- {
- //BF_FATAL("Symbol lookup error");
- deferResolve = true;
- }
- }
- if ((symInfo->mSectionNum != 0) && (resolvedSymbolAddr == NULL))
- {
- DbgHotTargetSection* refHotTargetSection = mHotTargetSections[symInfo->mSectionNum - 1];
- resolvedSymbolAddr = GetHotTargetAddress(refHotTargetSection) + symInfo->mValue;
- // Using the !hotTargetSection->mNoTargetAlloc check down here caused us to not properly remap reloaded
- // static members in the debug info. Even though we parse the debug info before we apply the deferred
- // resolves, the mLocData points into the original data so we still get it remapped when we use that
- // mLocData
- if (/*(!hotTargetSection->mNoTargetAlloc) &&*/ ((refHotTargetSection->mData == NULL) || (refHotTargetSection->mNoTargetAlloc)) &&
- (!isStaticSymbol))
- deferResolve = true;
- else
- deferResolve = false;
- }
- }
- if (deferResolve)
- {
- // It's a static field, defer resolution, but don't bother replacing for debug info sections
- DbgDeferredHotResolve* deferredResolve = mDeferredHotResolveList.Alloc();
- deferredResolve->mHotTargetSection = hotTargetSection;
- deferredResolve->mName = name;
- deferredResolve->mNewAddr = resolvedSymbolAddr;
- deferredResolve->mReloc = coffReloc;
- continue;
- }
- else
- {
- resolvedSymbolAddrs[coffReloc.mSymbolTableIndex] = resolvedSymbolAddr;
- DoReloc(hotTargetSection, coffReloc, resolvedSymbolAddr, symInfo);
- }
- }
- }
- }
- }
- void DbgModule::CommitHotTargetSections()
- {
- for (int sectNum = 0; sectNum < (int)mHotTargetSections.size(); sectNum++)
- {
- if (mHotTargetSections[sectNum] != NULL)
- {
- DbgHotTargetSection* hotTargetSection = mHotTargetSections[sectNum];
- addr_target hotAddr = GetHotTargetAddress(hotTargetSection);
- if (hotAddr != 0)
- {
- // void* imageDestPtr = mOrigImageData->mBlocks[0] + hotTargetSection->mImageOffset;
- // if (hotTargetSection->mData != NULL)
- // memcpy(imageDestPtr, hotTargetSection->mData, hotTargetSection->mDataSize);
- // else
- // memset(imageDestPtr, 0, hotTargetSection->mDataSize);
- BF_ASSERT(mOrigImageData->mAddr != 0);
- void* imageDestPtr = hotTargetSection->mData;
- bool isTemp = false;
- if (imageDestPtr == NULL)
- {
- imageDestPtr = new uint8[hotTargetSection->mDataSize];
- memset(imageDestPtr, 0, hotTargetSection->mDataSize);
- isTemp = true;
- }
- if (hotTargetSection->mCanExecute)
- {
- bool success = mDebugger->WriteInstructions(hotAddr, imageDestPtr, hotTargetSection->mDataSize);
- BF_ASSERT(success);
- }
- else
- {
- bool success = mDebugger->WriteMemory(hotAddr, imageDestPtr, hotTargetSection->mDataSize);
- BF_ASSERT(success);
- }
- if (isTemp)
- delete imageDestPtr;
- }
- }
- }
- }
- void DbgModule::HotReplaceType(DbgType* newType)
- {
- auto linkedModule = GetLinkedModule();
- newType->PopulateType();
- DbgType* primaryType = linkedModule->GetPrimaryType(newType);
- if (primaryType == newType)
- {
- // There was no previous type
- BF_ASSERT(primaryType->mHotNewType == NULL);
- return;
- }
- if (primaryType->mHotNewType != newType)
- {
- // We have already pulled in the new data from a previous new type
- BF_ASSERT(primaryType->mHotNewType == NULL);
- return;
- }
- primaryType->mHotNewType = NULL;
- primaryType->PopulateType();
- linkedModule->ParseGlobalsData();
- linkedModule->ParseSymbolData();
- if (primaryType->mNeedsGlobalsPopulated)
- {
- // These aren't proper TPI types so we don't have any method declarations until we PopulateTypeGlobals
- linkedModule->PopulateTypeGlobals(primaryType);
- }
- for (auto methodNameEntry : primaryType->mMethodNameList)
- {
- if (methodNameEntry->mCompileUnitId != -1)
- {
- linkedModule->MapCompileUnitMethods(methodNameEntry->mCompileUnitId);
- methodNameEntry->mCompileUnitId = -1;
- }
- }
- // Now actually remove the linedata from the defining module
- HashSet<DbgSrcFile*> checkedFiles;
- for (auto method : primaryType->mMethodList)
- {
- //method->mWasModuleHotReplaced = true;
- method->mHotReplaceKind = DbgSubprogram::HotReplaceKind_Orphaned; // May be temporarily orphaned
- if (method->mLineInfo == NULL)
- continue;
- //FIXME: Hot replacing lines
- DbgSrcFile* lastSrcFile = NULL;
- checkedFiles.Clear();
- int prevCtx = -1;
- auto inlineRoot = method->GetRootInlineParent();
- for (int lineIdx = 0; lineIdx < method->mLineInfo->mLines.mSize; lineIdx++)
- {
- auto& lineData = method->mLineInfo->mLines[lineIdx];
- if (lineData.mCtxIdx != prevCtx)
- {
- auto ctxInfo = inlineRoot->mLineInfo->mContexts[lineData.mCtxIdx];
- auto srcFile = ctxInfo.mSrcFile;
- prevCtx = lineData.mCtxIdx;
- if (srcFile != lastSrcFile)
- {
- if (checkedFiles.Add(srcFile))
- {
- // Remove linedata for old type
- // These go into a hot-replaced list so we can still bind to them -- that is necessary because
- // we may still have old versions of this method running (and may forever, if its in a loop on some thread)
- // since we only patch entry points
- //srcFile->RemoveLines(primaryType->mCompileUnit->mDbgModule, primaryType->mCompileUnit, true);
- //srcFile->RemoveLines(primaryType->mCompileUnit->mDbgModule, method, true);
- srcFile->RemoveLines(method->mCompileUnit->mDbgModule, method, true);
- }
- lastSrcFile = srcFile;
- }
- }
- }
- }
- //DbgType* primaryType = newType->GetPrimaryType();
- // We need to keep a persistent list of hot replaced methods so we can set hot jumps
- // in old methods that may still be on the callstack. These entries get removed when
- // we unload unused hot files in
- while (!primaryType->mMethodList.IsEmpty())
- {
- auto method = primaryType->mMethodList.PopFront();
- method->PopulateSubprogram();
- primaryType->mHotReplacedMethodList.PushFront(method);
- mHotPrimaryTypes.Add(primaryType);
- }
- Dictionary<StringView, DbgSubprogram*> oldProgramMap;
- for (auto oldMethod : primaryType->mHotReplacedMethodList)
- {
- oldMethod->PopulateSubprogram();
- if (oldMethod->mBlock.IsEmpty())
- continue;
- auto symInfo = mDebugTarget->mSymbolMap.Get(oldMethod->mBlock.mLowPC);
- if (symInfo != NULL)
- {
- oldProgramMap.TryAdd(symInfo->mName, oldMethod);
- }
- }
- bool setHotJumpFailed = false;
- while (!newType->mMethodList.IsEmpty())
- {
- DbgSubprogram* newMethod = newType->mMethodList.PopFront();
- if (!newMethod->mBlock.IsEmpty())
- {
- BfLogDbg("Hot added new method %p %s Address:%p\n", newMethod, newMethod->mName, newMethod->mBlock.mLowPC);
- newMethod->PopulateSubprogram();
- auto symInfo = mDebugTarget->mSymbolMap.Get(newMethod->mBlock.mLowPC);
- if (symInfo != NULL)
- {
- DbgSubprogram* oldMethod = NULL;
- if (oldProgramMap.TryGetValue(symInfo->mName, &oldMethod))
- {
- bool doHotJump = false;
- if (oldMethod->Equals(newMethod))
- {
- doHotJump = true;
- }
- else
- {
- // When mangles match but the actual signatures don't match, that can mean that the call signature was changed
- // and thus it's actually a different method and shouldn't hot jump OR it could be lambda whose captures changed.
- // When the lambda captures change, the user didn't actually enter a different signature so we want to do a hard
- // fail if the old code gets called to avoid confusion of "why aren't my changes working?"
- // If we removed captures then we can still do the hot jump. Otherwise we have to fail...
- doHotJump = false;
- if ((oldMethod->IsLambda()) && (oldMethod->Equals(newMethod, true)) &&
- (oldMethod->mHasThis) && (newMethod->mHasThis))
- {
- auto oldParam = oldMethod->mParams.front();
- auto newParam = newMethod->mParams.front();
- if ((oldParam->mType->IsPointer()) && (newParam->mType->IsPointer()))
- {
- auto oldType = oldParam->mType->mTypeParam->GetPrimaryType();
- oldType->PopulateType();
- auto newType = newParam->mType->mTypeParam->GetPrimaryType();
- newType->PopulateType();
- if ((oldType->IsStruct()) && (newType->IsStruct()))
- {
- bool wasMatch = true;
- auto oldMember = oldType->mMemberList.front();
- auto newMember = newType->mMemberList.front();
- while (newMember != NULL)
- {
- if (oldMember == NULL)
- {
- wasMatch = false;
- break;
- }
- if ((oldMember->mName == NULL) || (newMember->mName == NULL))
- {
- wasMatch = false;
- break;
- }
- if (strcmp(oldMember->mName, newMember->mName) != 0)
- {
- wasMatch = false;
- break;
- }
- if (!oldMember->mType->Equals(newMember->mType))
- {
- wasMatch = false;
- break;
- }
- oldMember = oldMember->mNext;
- newMember = newMember->mNext;
- }
- if (wasMatch)
- doHotJump = true;
- }
- }
- if (!doHotJump)
- {
- mDebugTarget->mDebugger->PhysSetBreakpoint(oldMethod->mBlock.mLowPC);
- oldMethod->mHotReplaceKind = DbgSubprogram::HotReplaceKind_Invalid;
- }
- }
- }
- if (doHotJump)
- {
- if (!setHotJumpFailed)
- {
- if (!mDebugger->SetHotJump(oldMethod, newMethod->mBlock.mLowPC, (int)(newMethod->mBlock.mHighPC - newMethod->mBlock.mLowPC)))
- setHotJumpFailed = true;
- }
- oldMethod->mHotReplaceKind = DbgSubprogram::HotReplaceKind_Replaced;
- }
- }
- }
- }
- newMethod->mParentType = primaryType;
- primaryType->mMethodList.PushBack(newMethod);
- }
- //mDebugTarget->mSymbolMap.Get()
- // bool setHotJumpFailed = false;
- // while (!newType->mMethodList.IsEmpty())
- // {
- // DbgSubprogram* newMethod = newType->mMethodList.PopFront();
- // if (!newMethod->mBlock.IsEmpty())
- // {
- // newMethod->PopulateSubprogram();
- //
- // bool found = false;
- // for (auto oldMethod : primaryType->mHotReplacedMethodList)
- // {
- // if (oldMethod->mBlock.IsEmpty())
- // continue;
- // if (oldMethod->Equals(newMethod))
- // {
- // if (!setHotJumpFailed)
- // {
- // if (!mDebugger->SetHotJump(oldMethod, newMethod))
- // setHotJumpFailed = true;
- // oldMethod->mWasHotReplaced = true;
- // }
- // }
- // }
- // }
- // newMethod->mParentType = primaryType;
- // primaryType->mMethodList.PushBack(newMethod);
- // }
- primaryType->mCompileUnit->mWasHotReplaced = true;
- primaryType->mNeedsGlobalsPopulated = newType->mNeedsGlobalsPopulated;
- primaryType->mUsingNamespaces = newType->mUsingNamespaces;
- primaryType->mMemberList = newType->mMemberList;
- primaryType->mCompileUnit = newType->mCompileUnit;
- }
- bool DbgModule::CanRead(DataStream* stream, DebuggerResult* outResult)
- {
- PEHeader hdr;
- memset(&hdr, 0, sizeof(hdr));
- PE_NTHeaders ntHdr;
- memset(&ntHdr, 0, sizeof(ntHdr));
- stream->Read(&hdr, sizeof(PEHeader));
- stream->SetPos(hdr.e_lfanew);
- stream->Read(&ntHdr, sizeof(PE_NTHeaders));
- if ((hdr.e_magic != PE_DOS_SIGNATURE) || (ntHdr.mSignature != PE_NT_SIGNATURE))
- {
- *outResult = DebuggerResult_UnknownError;
- return false;
- }
- #ifdef BF_DBG_32
- if (ntHdr.mFileHeader.mMachine != PE_MACHINE_X86)
- {
- if (ntHdr.mFileHeader.mMachine == PE_MACHINE_X64)
- *outResult = DebuggerResult_WrongBitSize;
- else
- *outResult = DebuggerResult_UnknownError;
- return false;
- }
- #else
- if (ntHdr.mFileHeader.mMachine != PE_MACHINE_X64)
- {
- if (ntHdr.mFileHeader.mMachine == PE_MACHINE_X86)
- *outResult = DebuggerResult_WrongBitSize;
- else
- *outResult = DebuggerResult_UnknownError;
- return false;
- }
- #endif
- return true;
- }
- const char* DbgModule::GetStringTable(DataStream* stream, int stringTablePos)
- {
- if (mStringTable == NULL)
- {
- int prevPos = stream->GetPos();
- stream->SetPos(stringTablePos);
- int strTableSize = 0;
- stream->Read(&strTableSize, 4);
- if (strTableSize != 0)
- {
- strTableSize -= 4;
- char* strTableData = new char[strTableSize + 4];
- memcpy(strTableData, &strTableSize, 4);
- stream->Read(strTableData + 4, strTableSize);
- mStringTable = strTableData;
- }
- stream->SetPos(prevPos);
- }
- return mStringTable;
- }
- bool DbgModule::ReadCOFF(DataStream* stream, DbgModuleKind moduleKind)
- {
- BP_ZONE("DbgModule::ReadCOFF");
- //if (this == mDebugTarget->mTargetBinary)
- //mMemReporter = new MemReporter();
- BfLogDbg("DbgModule::ReadCOFF %s\n", mFilePath.c_str());
- if (mMemReporter != NULL)
- {
- mMemReporter->BeginSection(StrFormat("Module: %s", mFilePath.c_str()));
- mMemReporter->Add(mImageSize);
- }
- defer
- (
- if (mMemReporter != NULL)
- mMemReporter->EndSection();
- );
- DbgModule* mainModule = mDebugTarget->mTargetBinary;
- MiniDumpDebugger* miniDumpDebugger = NULL;
- if (mDebugger->IsMiniDumpDebugger())
- {
- miniDumpDebugger = (MiniDumpDebugger*)mDebugger;
- }
- mModuleKind = moduleKind;
- bool isHotSwap = mModuleKind == DbgModuleKind_HotObject;
- bool isObjectFile = mModuleKind != DbgModuleKind_Module;
- auto linkedModule = GetLinkedModule();
- if (isObjectFile)
- linkedModule->PopulateStaticVariableMap();
- mStartTypeIdx = (int)linkedModule->mTypes.size();
- int startSrcFile = (int)mDebugTarget->mSrcFiles.size();
- mStartSubprogramIdx = (int)mSubprograms.size();
- PEHeader hdr;
- memset(&hdr, 0, sizeof(hdr));
- PE_NTHeaders ntHdr;
- memset(&ntHdr, 0, sizeof(ntHdr));
- if (!isObjectFile)
- {
- stream->Read(&hdr, sizeof(PEHeader));
- stream->SetPos(hdr.e_lfanew);
- stream->Read(&ntHdr, sizeof(PE_NTHeaders));
- mPreferredImageBase = ntHdr.mOptionalHeader.mImageBase;
- if (mImageBase == 0)
- {
- BF_ASSERT(this == mainModule);
- mImageBase = mPreferredImageBase;
- }
- if ((hdr.e_magic != PE_DOS_SIGNATURE) || (ntHdr.mSignature != PE_NT_SIGNATURE))
- {
- mLoadState = DbgModuleLoadState_Failed;
- return false;
- }
- #ifdef BF_DBG_32
- if (ntHdr.mFileHeader.mMachine != PE_MACHINE_X86)
- return false;
- #else
- if (ntHdr.mFileHeader.mMachine != PE_MACHINE_X64)
- {
- mLoadState = DbgModuleLoadState_Failed;
- return false;
- }
- #endif
- int pos = hdr.e_lfanew + FIELD_OFFSET(PE_NTHeaders, mOptionalHeader) + ntHdr.mFileHeader.mSizeOfOptionalHeader;
- stream->SetPos(pos);
- }
- else
- {
- stream->Read(&ntHdr.mFileHeader, sizeof(PEFileHeader));
- if (mMemReporter != NULL)
- mMemReporter->Add("PEFileHeader", sizeof(PEFileHeader));
- #ifdef BF_DBG_32
- if (ntHdr.mFileHeader.mMachine != PE_MACHINE_X86)
- return false;
- #else
- if (ntHdr.mFileHeader.mMachine != PE_MACHINE_X64)
- {
- mLoadState = DbgModuleLoadState_Failed;
- return false;
- }
- #endif
- }
- int sectionStartPos = stream->GetPos();
- int sectionDataEndPos = 0;
- if (miniDumpDebugger != NULL)
- {
- // Map header
- miniDumpDebugger->MapMemory((addr_target)mImageBase, (uint8*)mMappedImageFile->mData, 0x1000);
- }
- bool wantStringTable = isObjectFile;
- stream->SetPos(sectionStartPos);
- for (int dirNum = 0; dirNum < (int) ntHdr.mFileHeader.mNumberOfSections; dirNum++)
- {
- PESectionHeader sectHdr;
- char* name = sectHdr.mName;
- stream->Read(§Hdr, sizeof(PESectionHeader));
- if (sectHdr.mSizeOfRawData > 0)
- sectionDataEndPos = BF_MAX(sectionDataEndPos, (int)(sectHdr.mPointerToRawData + sectHdr.mSizeOfRawData));
- if (sectHdr.mNumberOfRelocations > 0)
- sectionDataEndPos = BF_MAX(sectionDataEndPos, (int)(sectHdr.mPointerToRelocations + sectHdr.mNumberOfRelocations * sizeof(COFFRelocation)));
- if (miniDumpDebugger != NULL)
- {
- miniDumpDebugger->MapMemory((addr_target)(mImageBase + sectHdr.mVirtualAddress), (uint8*)mMappedImageFile->mData + sectHdr.mPointerToRawData, sectHdr.mSizeOfRawData);
- }
- }
- //fseek(fp, sectionDataEndPos + ntHdr.mFileHeader.mNumberOfSymbols * 18, SEEK_SET);
- stream->SetPos(sectionDataEndPos);
- uint8* symbolData = new uint8[ntHdr.mFileHeader.mNumberOfSymbols * 18];
- mAllocSizeData += ntHdr.mFileHeader.mNumberOfSymbols * 18;
- mSymbolData = symbolData;
- stream->Read(symbolData, ntHdr.mFileHeader.mNumberOfSymbols * 18);
- int curPos = stream->GetPos();
- int stringTablePos = curPos;
- if (isObjectFile)
- GetStringTable(stream, stringTablePos);
- int mDebugFrameDataLen = 0;
- stream->SetPos(sectionStartPos);
- PEDataDirectory* exportDataDir = &ntHdr.mOptionalHeader.mDataDirectory[0];
- mHotTargetSections.Resize(ntHdr.mFileHeader.mNumberOfSections);
- Array<PESectionHeader> sectionHeaders;
- sectionHeaders.Resize(ntHdr.mFileHeader.mNumberOfSections);
- mSectionRVAs.Resize(sectionHeaders.size() + 1);
- Array<String> sectionNames;
- sectionNames.Resize(ntHdr.mFileHeader.mNumberOfSections);
- stream->Read(§ionHeaders[0], sizeof(PESectionHeader) * ntHdr.mFileHeader.mNumberOfSections);
- for (int sectNum = 0; sectNum < ntHdr.mFileHeader.mNumberOfSections; sectNum++)
- {
- mSectionRVAs[sectNum] = sectionHeaders[sectNum].mVirtualAddress;
- }
- int tlsSection = -1;
- for (int sectNum = 0; sectNum < ntHdr.mFileHeader.mNumberOfSections; sectNum++)
- {
- //PEDataDirectory* dataDir = &ntHdr.mOptionalHeader.mDataDirectory[dirNum];
- PESectionHeader& sectHdr = sectionHeaders[sectNum];
- //stream->Read(§Hdr, sizeof(PESectionHeader));
- const char* name = sectHdr.mName;
- if (name[0] == '/')
- {
- int strIdx = atoi(name + 1);
- name = &GetStringTable(stream, stringTablePos)[strIdx];
- }
- sectionNames[sectNum] = name;
- DbgHotTargetSection* targetSection = NULL;
- if (IsObjectFile())
- {
- targetSection = new DbgHotTargetSection();
- targetSection->mDataSize = sectHdr.mSizeOfRawData;
- targetSection->mPointerToRelocations = sectHdr.mPointerToRelocations;
- targetSection->mNumberOfRelocations = sectHdr.mNumberOfRelocations;
- targetSection->mTargetSectionAddr = 0; // TODO: Allocate!
- targetSection->mCanExecute = (sectHdr.mCharacteristics & IMAGE_SCN_MEM_EXECUTE) != 0;
- targetSection->mCanWrite = (sectHdr.mCharacteristics & IMAGE_SCN_MEM_WRITE) != 0;
- targetSection->mNoTargetAlloc = (sectHdr.mCharacteristics & IMAGE_SCN_MEM_DISCARDABLE) != 0;
- mHotTargetSections[sectNum] = targetSection;
- }
- DbgSection dwSection;
- dwSection.mIsExecutable = (sectHdr.mCharacteristics & IMAGE_SCN_MEM_EXECUTE) != 0;
- dwSection.mAddrStart = sectHdr.mVirtualAddress;
- dwSection.mAddrLength = BF_MAX(sectHdr.mSizeOfRawData, sectHdr.mVirtualSize);
- mSections.push_back(dwSection);
- if (sectHdr.mPointerToRawData == 0)
- continue;
- if (strcmp(name, ".tls") == 0)
- mTLSAddr = (addr_target)(sectHdr.mVirtualAddress + mImageBase);
- if ((IsObjectFile()) && (strcmp(name, ".tls$") == 0))
- {
- tlsSection = sectNum;
- mTLSSize = sectHdr.mSizeOfRawData;
- targetSection->mNoTargetAlloc = true;
- }
- bool isExportDataDir = ((exportDataDir->mVirtualAddress != 0) && (exportDataDir->mVirtualAddress >= sectHdr.mVirtualAddress) && (exportDataDir->mVirtualAddress < sectHdr.mVirtualAddress + sectHdr.mSizeOfRawData));
- if ((!IsObjectFile()) && (!isExportDataDir))
- {
- if (((strcmp(name, ".text")) == 0) ||
- ((strcmp(name, ".textbss")) == 0) ||
- ((strcmp(name, ".reloc")) == 0)/* ||
- ((strcmp(name, ".data")) == 0)*/)
- {
- // Big unneeded sections
- continue;
- }
- }
- stream->SetPos(sectHdr.mPointerToRawData);
- int dataSize = sectHdr.mSizeOfRawData + 8;
- mAllocSizeData += dataSize;
- uint8* data = new uint8[dataSize];
- {
- BP_ZONE("DbgModule::ReadCOFF_ReadSectionData");
- stream->Read(data, sectHdr.mSizeOfRawData);
- }
- BfLogDbg("Read section data %s %p\n", name, data);
- memset(data + sectHdr.mSizeOfRawData, 0, 8);
- if (IsObjectFile())
- targetSection->mData = data;
- addr_target addrOffset = sectHdr.mVirtualAddress;
- if (isExportDataDir)
- {
- BP_ZONE("DbgModule::ReadCOFF_SymbolMap");
- IMAGE_EXPORT_DIRECTORY* imageExportDir = (IMAGE_EXPORT_DIRECTORY*)(data + (exportDataDir->mVirtualAddress - addrOffset));
- for (int funcIdx = 0; funcIdx < (int)imageExportDir->NumberOfNames; funcIdx++)
- {
- //addr_target strAddr = *(addr_target*)(data + (imageExportDir->AddressOfNames - addrOffset) + funcIdx * sizeof(addr_target));
- int32 strAddr = *(int32*)(data + (imageExportDir->AddressOfNames - addrOffset) + funcIdx * sizeof(int32));
- const char* name = (const char*)(data + (strAddr - addrOffset));
- #ifdef BF_DBG_32
- if (name[0] == '_')
- name++;
- #endif
- int funcOrd = *(uint16*)(data + (imageExportDir->AddressOfNameOrdinals - addrOffset) + funcIdx * sizeof(uint16));
- addr_target funcAddr = *(uint32*)(data + (imageExportDir->AddressOfFunctions - addrOffset) + funcOrd * sizeof(int32));
- int strLen = (int)strlen(name);
- BP_ALLOC("ReadCOFF_SymbolMap", strLen + 1);
- char* allocStr = (char*)mAlloc.AllocBytes(strLen + 1, "ReadCOFF_SymbolMap");
- memcpy(allocStr, name, strLen);
- BP_ALLOC_T(DbgSymbol);
- DbgSymbol* dwSymbol = mAlloc.Alloc<DbgSymbol>();
- dwSymbol->mDbgModule = this;
- dwSymbol->mName = allocStr;
- dwSymbol->mAddress = funcAddr;
- if (strcmp(name, "_tls_index") == 0)
- {
- mTLSIndexAddr = funcAddr;
- }
- //TODO:
- //mDeferredSymbols.PushFront(dwSymbol);
- dwSymbol->mAddress = (addr_target)(dwSymbol->mAddress + mImageBase);
- mDebugTarget->mSymbolMap.Insert(dwSymbol);
- linkedModule->mSymbolNameMap.Insert(dwSymbol);
- }
- }
- if ((IsObjectFile()) && (sectHdr.mNumberOfRelocations > 0))
- {
- //mDebugger->AllocTargetMemory(sectHdr.mSizeOfRawData, true, true);
- }
- if (strcmp(name, ".text") == 0)
- {
- if (!IsObjectFile())
- mCodeAddress = ntHdr.mOptionalHeader.mImageBase + sectHdr.mVirtualAddress;
- }
- //if (strcmp(name, ".rdata") == 0)
- {
- PEDataDirectory& debugDirEntry = ntHdr.mOptionalHeader.mDataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG];
- if (debugDirEntry.mSize > 0)
- {
- if (mMemReporter != NULL)
- mMemReporter->Add("DataDirectory", debugDirEntry.mSize);
- if ((debugDirEntry.mVirtualAddress >= sectHdr.mVirtualAddress) && (debugDirEntry.mVirtualAddress < sectHdr.mVirtualAddress + sectHdr.mSizeOfRawData))
- {
- int count = debugDirEntry.mSize / sizeof(IMAGE_DEBUG_DIRECTORY);
- for (int dirIdx = 0; dirIdx < count; dirIdx++)
- {
- IMAGE_DEBUG_DIRECTORY* debugDirectory = (IMAGE_DEBUG_DIRECTORY*)(data + debugDirEntry.mVirtualAddress - sectHdr.mVirtualAddress) + dirIdx;
- if (debugDirectory->Type == IMAGE_DEBUG_TYPE_CODEVIEW)
- {
- struct _CodeViewEntry
- {
- public:
- int32 mSig;
- uint8 mGUID[16];
- int32 mAge;
- const char mPDBPath[1];
- };
- if (debugDirectory->AddressOfRawData != 0)
- {
- _CodeViewEntry* codeViewEntry = (_CodeViewEntry*)(data + debugDirectory->AddressOfRawData - sectHdr.mVirtualAddress);
- if (codeViewEntry->mSig == 'SDSR')
- {
- LoadPDB(codeViewEntry->mPDBPath, codeViewEntry->mGUID, codeViewEntry->mAge);
- }
- }
- }
- }
- }
- //stream->SetPos(debugDirEntry.mVirtualAddress);
- }
- }
- //
- {
- PEDataDirectory& tlsDirEntry = ntHdr.mOptionalHeader.mDataDirectory[IMAGE_DIRECTORY_ENTRY_TLS];
- if (tlsDirEntry.mSize > 0)
- {
- if ((tlsDirEntry.mVirtualAddress >= sectHdr.mVirtualAddress) && (tlsDirEntry.mVirtualAddress < sectHdr.mVirtualAddress + sectHdr.mSizeOfRawData))
- {
- uint8* relPtr = data + tlsDirEntry.mVirtualAddress - sectHdr.mVirtualAddress;
- uint8* endPtr = relPtr + tlsDirEntry.mSize;
- addr_target tlsDataStart = GET_FROM(relPtr, addr_target) - ntHdr.mOptionalHeader.mImageBase;
- addr_target tlsDataEnd = GET_FROM(relPtr, addr_target) - ntHdr.mOptionalHeader.mImageBase;
- mTLSAddr = (addr_target)(tlsDataStart + mImageBase);
- mTLSSize = (int)(tlsDataEnd - tlsDataStart);
- }
- }
- }
- //
- {
- PEDataDirectory& debugDirEntry = ntHdr.mOptionalHeader.mDataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE];
- if (debugDirEntry.mSize > 0)
- {
- if ((debugDirEntry.mVirtualAddress >= sectHdr.mVirtualAddress) && (debugDirEntry.mVirtualAddress < sectHdr.mVirtualAddress + sectHdr.mSizeOfRawData))
- {
- uint8* relPtr = data + debugDirEntry.mVirtualAddress - sectHdr.mVirtualAddress;
- uint8* endPtr = relPtr + debugDirEntry.mSize;
- IMAGE_RESOURCE_DIRECTORY* typeDir = (IMAGE_RESOURCE_DIRECTORY*)(relPtr);
- // Skip named entries
- for (int typeIdx = 0; typeIdx < typeDir->NumberOfIdEntries; typeIdx++)
- {
- IMAGE_RESOURCE_DIRECTORY_ENTRY* typeEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)((uint8*)typeDir + sizeof(IMAGE_RESOURCE_DIRECTORY) +
- (typeDir->NumberOfNamedEntries + typeIdx)*sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
- if (typeEntry->Id == 0x10) //VERSION
- {
- IMAGE_RESOURCE_DIRECTORY* idDir = (IMAGE_RESOURCE_DIRECTORY*)(relPtr + (typeEntry->OffsetToData & 0x7FFFFFFF));
- if (idDir->NumberOfIdEntries < 1)
- break;
- IMAGE_RESOURCE_DIRECTORY_ENTRY* idEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)((uint8*)idDir + sizeof(IMAGE_RESOURCE_DIRECTORY) +
- (idDir->NumberOfNamedEntries + 0) * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
- IMAGE_RESOURCE_DIRECTORY* langDir = (IMAGE_RESOURCE_DIRECTORY*)(relPtr + (idEntry->OffsetToData & 0x7FFFFFFF));
- if (langDir->NumberOfIdEntries < 1)
- break;
- IMAGE_RESOURCE_DIRECTORY_ENTRY* langEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)((uint8*)langDir + sizeof(IMAGE_RESOURCE_DIRECTORY) +
- (langDir->NumberOfNamedEntries + 0) * sizeof(IMAGE_RESOURCE_DIRECTORY_ENTRY));
- IMAGE_RESOURCE_DATA_ENTRY* dataEntry = (IMAGE_RESOURCE_DATA_ENTRY*)(relPtr + (langEntry->OffsetToData & 0x7FFFFFFF));
- uint8* versionData = data + dataEntry->OffsetToData - sectHdr.mVirtualAddress;
- uint8* vPtr = versionData;
- auto vSize = GET_FROM(vPtr, uint16);
- auto verEnd = vPtr + vSize;
- auto vLength = GET_FROM(vPtr, uint16);
- vPtr += 36; // "VS_VERSION_INFO"
- auto fixedFileInfo = GET_FROM(vPtr, VS_FIXEDFILEINFO);
- auto _GetString = [&]()
- {
- wchar_t* cPtr = (wchar_t*)vPtr;
- int len = (int)wcslen(cPtr);
- vPtr += (len + 1) * 2;
- if (((intptr)vPtr & 3) != 0)
- vPtr += 2;
- UTF16String str16(cPtr, len);
- return UTF8Encode(str16);
- };
- while (vPtr < verEnd)
- {
- auto size = GET_FROM(vPtr, uint16);
- auto childEnd = vPtr + size;
- auto valueLength = GET_FROM(vPtr, uint16);
- auto type = GET_FROM(vPtr, uint16);
- String infoType = _GetString();
- if (infoType == "StringFileInfo")
- {
- while (vPtr < childEnd)
- {
- auto strsSize = GET_FROM(vPtr, uint16);
- auto strsEnd = vPtr + strsSize;
- auto strsLength = GET_FROM(vPtr, uint16);
- auto strsType = GET_FROM(vPtr, uint16);
- String hexNum = _GetString();
- while (vPtr < strsEnd)
- {
- auto strSize = GET_FROM(vPtr, uint16);
- auto strEnd = vPtr + strSize;
- auto strLength = GET_FROM(vPtr, uint16);
- auto strType = GET_FROM(vPtr, uint16);
- String key = _GetString();
- String value = _GetString();
- if (key == "FileVersion")
- mVersion = value;
- }
- }
- }
- vPtr = childEnd;
- }
- }
- }
- }
- //stream->SetPos(debugDirEntry.mVirtualAddress);
- }
- }
- bool usedData = true;
- /*if (isUnwindSection)
- {
- mExceptionData = data;
- mExceptionDataRVA = sectHdr.mVirtualAddress;
- }*/
- if (strcmp(name, ".pdata") == 0)
- {
- DbgSectionData entry;
- entry.mData = data;
- entry.mSize = sectHdr.mSizeOfRawData;
- mExceptionDirectory.Add(entry);
- }
- // Old, unsupported DWARF debug info
- /*
- else if (strcmp(name, ".debug_info") == 0)
- {
- mDebugInfoData = data;
- }
- else if (strcmp(name, ".debug_line") == 0)
- {
- mDebugLineData = data;
- }
- else if (strcmp(name, ".debug_str") == 0)
- {
- mDebugStrData = data;
- }
- else if (strcmp(name, ".debug_frame") == 0)
- {
- mDebugFrameAddress = ntHdr.mOptionalHeader.mImageBase + sectHdr.mVirtualAddress;
- mDebugFrameData = data;
- mDebugFrameDataLen = sectHdr.mSizeOfRawData;
- }
- else if (strcmp(name, ".eh_frame") == 0)
- {
- mEHFrameAddress = ntHdr.mOptionalHeader.mImageBase + sectHdr.mVirtualAddress;
- mEHFrameData = data;
- }
- else if (strcmp(name, ".debug_abbrev") == 0)
- {
- mDebugAbbrevData = data;
- mDebugAbbrevPtrData = new const uint8*[sectHdr.mSizeOfRawData];
- }
- else if (strcmp(name, ".debug_loc") == 0)
- {
- mDebugLocationData = data;
- }
- else if (strcmp(name, ".debug_ranges") == 0)
- {
- mDebugRangesData = data;
- }
- */
- // else if (strcmp(name, ".rsrc") == 0)
- // {
- // //IMAGE_DIRECTORY_ENTRY_RESOURCE
- // }
- else if (CheckSection(name, data, sectHdr.mSizeOfRawData))
- {
- // Was used
- }
- else
- {
- /*if (isUnwindSection)
- mOwnsExceptionData = true;
- else*/
- usedData = false;
- }
- if (!usedData)
- {
- if (IsObjectFile())
- {
- mOwnedSectionData.push_back(data);
- }
- else
- {
- mAllocSizeData -= dataSize;
- delete [] data;
- }
- }
- //stream->SetPos(prevPos);
- }
- int needHotTargetMemory = 0;
- if (isObjectFile)
- {
- for (int sectNum = 0; sectNum < ntHdr.mFileHeader.mNumberOfSections; sectNum++)
- {
- auto targetSection = mHotTargetSections[sectNum];
- if (!targetSection->mNoTargetAlloc)
- needHotTargetMemory += (targetSection->mDataSize + (mDebugger->mPageSize - 1)) & ~(mDebugger->mPageSize - 1);
- }
- mDebugger->ReserveHotTargetMemory(needHotTargetMemory);
- // '0' address is temporary
- //mOrigImageData = new DbgModuleMemoryCache(0, NULL, needHotTargetMemory, true);
- mOrigImageData = new DbgModuleMemoryCache(0, needHotTargetMemory);
- }
- int numSections = ntHdr.mFileHeader.mNumberOfSections;
- if (isObjectFile)
- {
- addr_target* resolvedSymbolAddrs = new addr_target[ntHdr.mFileHeader.mNumberOfSymbols];
- memset(resolvedSymbolAddrs, 0, ntHdr.mFileHeader.mNumberOfSymbols * sizeof(addr_target));
- ParseHotTargetSections(stream, resolvedSymbolAddrs);
- delete [] resolvedSymbolAddrs;
- }
- ProcessDebugInfo();
- if (mDebugInfoData != NULL)
- {
- mDbgFlavor = DbgFlavor_GNU;
- mMasterCompileUnit = new DbgCompileUnit(this);
- mMasterCompileUnit->mDbgModule = this;
- mMasterCompileUnit->mIsMaster = true;
- const uint8* data = mDebugInfoData;
- while (ParseDWARF(data)) {}
- CreateNamespaces();
- // Must be added last so module reference indices still map correctly
- mCompileUnits.push_back(mMasterCompileUnit);
- }
- ParseDebugFrameData();
- ParseEHFrameData();
- mEndTypeIdx = (int)linkedModule->mTypes.size();
- mEndSubprogramIdx = (int)mSubprograms.size();
- if (mDebugLineData != NULL)
- {
- const uint8* data = mDebugLineData;
- for (int compileUnitIdx = 0; true; compileUnitIdx++)
- if (!ParseDebugLineInfo(data, compileUnitIdx))
- break;
- }
- {
- BP_ZONE("ReadPE_ReadSymbols");
- //linkedModule->mSymbolNameMap.reserve(linkedModule->mSymbolNameMap.size() + ntHdr.mFileHeader.mNumberOfSymbols * 2);
- bool tlsFailed = false;
- addr_target tlsMappingAddr = 0;
- for (int symNum = 0; symNum < (int)ntHdr.mFileHeader.mNumberOfSymbols; symNum++)
- {
- PE_SymInfo* symInfo = (PE_SymInfo*)&mSymbolData[symNum * 18];
- char* name = symInfo->mName;
- if (symInfo->mNameOfs[0] != 0)
- {
- if (name[7] != 0)
- {
- // Name is exactly 8 chars, not null terminated yet
- name = (char*)mAlloc.AllocBytes(9, "PESymbol");
- memcpy(name, symInfo->mName, 8);
- name[8] = 0;
- }
- }
- else
- name = (char*)GetStringTable(stream, stringTablePos) + symInfo->mNameOfs[1];
- if ((symInfo->mStorageClass == COFF_SYM_CLASS_EXTERNAL) ||
- (symInfo->mStorageClass == COFF_SYM_CLASS_STATIC))
- {
- // 'static' in the C sense.
- // It means local to the compile unit, so may have multiple copies of the same symbol name.
- bool isStaticSymbol = symInfo->mStorageClass == COFF_SYM_CLASS_STATIC;
- if (symInfo->mSectionNum == 0xFFFF)
- continue;
- if (symInfo->mSectionNum > 0)
- {
- bool isTLS = false;
- addr_target targetAddr = 0;
- if (isObjectFile)
- {
- if (symInfo->mSectionNum - 1 == tlsSection)
- {
- isTLS = true;
- }
- else
- {
- auto hotTargetSection = mHotTargetSections[symInfo->mSectionNum - 1];
- if (hotTargetSection != NULL)
- targetAddr = GetHotTargetAddress(hotTargetSection) + symInfo->mValue;
- }
- }
- else
- targetAddr = mSectionRVAs[symInfo->mSectionNum - 1] + symInfo->mValue;
- if (((targetAddr != 0) || (isTLS)) &&
- (name[0] != '.'))
- {
- const char* symbolName = name;
- #ifdef BF_DBG_32
- if (symbolName[0] == '_')
- symbolName++;
- #endif
- if (strcmp(symbolName, "_tls_index") == 0)
- {
- mTLSIndexAddr = (addr_target)(targetAddr + mImageBase);
- }
- if ((isStaticSymbol) && (IsHotSwapPreserve(symbolName)))
- isStaticSymbol = false;
- if ((isObjectFile) && (!isStaticSymbol))
- {
- DbgSymbol* dwSymbol = NULL;
- linkedModule->ParseSymbolData() ;
- BP_ALLOC_T(DbgSymbol);
- dwSymbol = mAlloc.Alloc<DbgSymbol>();
- dwSymbol->mDbgModule = this;
- dwSymbol->mName = symbolName;
- dwSymbol->mAddress = targetAddr;
- if (dwSymbol != NULL)
- {
- bool isHotSwapPreserve = IsHotSwapPreserve(dwSymbol->mName);
- bool insertIntoNameMap = true;
- bool oldFound = false;
- auto nameMapEntry = linkedModule->mSymbolNameMap.Find(dwSymbol->mName);
- if (nameMapEntry != NULL)
- {
- oldFound = true;
- if (!isHotSwapPreserve)
- {
- nameMapEntry->mValue = dwSymbol;
- }
- else if (mDbgFlavor == DbgFlavor_MS)
- {
- // Store in our own map - this is needed for storing address of the new vdata
- // so the new values can be copied in
- mSymbolNameMap.Insert(dwSymbol);
- }
- }
- else
- {
- if (isTLS)
- {
- if (mainModule->mTLSExtraAddr == 0)
- {
- auto extraSym = mainModule->mSymbolNameMap.Find("__BFTLS_EXTRA");
- if (extraSym != NULL)
- {
- mainModule->ParseGlobalsData();
- auto itr = mainModule->mStaticVariableMap.find("__BFTLS_EXTRA");
- if (itr != mainModule->mStaticVariableMap.end())
- {
- auto staticVar = itr->second;
- mainModule->mTLSExtraAddr = extraSym->mValue->mAddress;
- mainModule->mTLSExtraSize = (int)staticVar->mType->GetByteCount();
- }
- }
- }
- if ((mainModule->mTLSExtraAddr != 0) && (tlsMappingAddr == 0))
- {
- // Take a chunk out of __BFTLS_EXTRA
- if (mTLSSize <= mainModule->mTLSExtraSize)
- {
- tlsMappingAddr = mainModule->mTLSExtraAddr;
- mainModule->mTLSExtraAddr += mTLSSize;
- mainModule->mTLSExtraSize -= mTLSSize;
- }
- }
- if (tlsMappingAddr != 0)
- {
- BF_ASSERT(symInfo->mValue < mTLSSize);
- dwSymbol->mAddress = tlsMappingAddr + symInfo->mValue;
- }
- if (dwSymbol->mAddress == 0)
- {
- if (!tlsFailed)
- {
- Fail(StrFormat("Hot swapping failed to allocate TLS address for '%s'. Program restart required.", name));
- }
- dwSymbol->mAddress = (addr_target)0xCDCDCDCD;
- tlsFailed = true;
- }
- }
- }
- if (dwSymbol->mAddress != 0)
- {
- if (!oldFound)
- linkedModule->mSymbolNameMap.Insert(dwSymbol);
- mDebugTarget->mSymbolMap.Insert(dwSymbol);
- }
- }
- }
- else
- {
- //TODO: We don't need to defer symbols anymore... we can just do a Fixup on their addr
- //mDeferredSymbols.PushFront(dwSymbol);
- BP_ALLOC_T(DbgSymbol);
- DbgSymbol* dwSymbol = mAlloc.Alloc<DbgSymbol>();
- dwSymbol->mDbgModule = this;
- dwSymbol->mName = symbolName;
- dwSymbol->mAddress = targetAddr;
- if (!IsObjectFile())
- dwSymbol->mAddress += (addr_target)mImageBase;
- if (IsObjectFile())
- BF_ASSERT((dwSymbol->mAddress >= mImageBase) && (dwSymbol->mAddress < mImageBase + mImageSize));
- mDebugTarget->mSymbolMap.Insert(dwSymbol);
- if (!isStaticSymbol)
- linkedModule->mSymbolNameMap.Insert(dwSymbol);
- }
- }
- }
- }
- if (symInfo->mStorageClass == COFF_SYM_CLASS_FILE)
- {
- const char* fileName = (const char*)&mSymbolData[(symNum + 1) * 18];
- }
- symNum += symInfo->mNumOfAuxSymbols;
- }
- }
- int subProgramSizes = 0;
- for (int subProgramIdx = mStartSubprogramIdx; subProgramIdx < mEndSubprogramIdx; subProgramIdx++)
- {
- auto dwSubprogram = mSubprograms[subProgramIdx];
- subProgramSizes += (int)(dwSubprogram->mBlock.mHighPC - dwSubprogram->mBlock.mLowPC);
- /*for (int i = 0; i < dwSubprogram->mLineDataArray.mSize; i++)
- {
- auto lineData = dwSubprogram->mLineDataArray.mData[i];
- auto srcFile = lineData->mSrcFileRef->mSrcFile;
- srcFile->mLineData.push_back(lineData);
- srcFile->mHadLineData = true;
- if ((srcFile->mFirstLineDataDbgModule == NULL) || (srcFile->mFirstLineDataDbgModule == this))
- srcFile->mFirstLineDataDbgModule = this;
- else
- srcFile->mHasLineDataFromMultipleModules = true;
- }*/
- }
- // Delete srcFiles without line data
- int lineDataCount = 0;
- /*for (int srcFileIdx = startSrcFile; srcFileIdx < (int)mDebugTarget->mSrcFiles.size(); srcFileIdx++)
- {
- if (!mDebugTarget->mSrcFiles[srcFileIdx]->mHadLineData)
- {
- mEmptySrcFiles.push_back(mDebugTarget->mSrcFiles[srcFileIdx]);
- mDebugTarget->mSrcFiles.erase(mDebugTarget->mSrcFiles.begin() + srcFileIdx);
- }
- else
- lineDataCount += (int)mDebugTarget->mSrcFiles[srcFileIdx]->mLineData.size();
- }*/
- auto srcFilesItr = mDebugTarget->mSrcFiles.begin();
- while (srcFilesItr != mDebugTarget->mSrcFiles.end())
- {
- DbgSrcFile* srcFile = srcFilesItr->mValue;
- if ((!srcFile->mHadLineData) && (srcFile->mLocalPath.IsEmpty()))
- {
- mEmptySrcFiles.push_back(srcFile);
- srcFilesItr = mDebugTarget->mSrcFiles.Remove(srcFilesItr);
- }
- else
- {
- ++srcFilesItr;
- }
- }
- if (!isObjectFile)
- {
- mImageSize = ntHdr.mOptionalHeader.mSizeOfImage;
- mEntryPoint = ntHdr.mOptionalHeader.mAddressOfEntryPoint;
- }
- /*OutputDebugStrF("%s:\n CompileUnits:%d DebugLines: %d Types: %d (%d in map) SubPrograms: %d (%dk) AllocSize:%dk\n", mFilePath.c_str(), mCompileUnits.size(),
- lineDataCount, mEndTypeIdx - mStartTypeIdx, (int)linkedModule->mTypes.size() - mStartTypeIdx, mEndSubprogramIdx - mStartSubprogramIdx, subProgramSizes / 1024, mAlloc.GetAllocSize() / 1024);*/
- if (isHotSwap)
- {
- // In COFF, we don't necessarily add an actual primary type during MapCompileUnitMethods, so this fixes that
- while (true)
- {
- bool didReplaceType = false;
- for (auto itr = mHotPrimaryTypes.begin(); itr != mHotPrimaryTypes.end(); ++itr)
- {
- auto dbgType = *itr;
- auto primaryType = dbgType->GetPrimaryType();
- if (primaryType != dbgType)
- {
- mHotPrimaryTypes.Remove(itr);
- mHotPrimaryTypes.Add(primaryType);
- didReplaceType = true;
- break;
- }
- }
- if (!didReplaceType)
- break;
- }
- BF_ASSERT(mTypes.size() == 0);
- for (int typeIdx = mStartTypeIdx; typeIdx < (int)linkedModule->mTypes.size(); typeIdx++)
- {
- DbgType* newType = linkedModule->mTypes[typeIdx];
- //if (!newType->mMethodList.IsEmpty())
- if (!newType->mIsDeclaration)
- HotReplaceType(newType);
- }
- }
- if (needHotTargetMemory != 0)
- {
- BF_ASSERT(needHotTargetMemory >= (int)mImageSize);
- }
- //BF_ASSERT(mEndTypeIdx == (int)linkedModule->mTypes.size());
- //BF_ASSERT(mEndSubprogramIdx == (int)mSubprograms.size());
- ParseExceptionData();
- mLoadState = DbgModuleLoadState_Loaded;
- if (mMemReporter != NULL)
- {
- mMemReporter->BeginSection("Sections");
- ParseSymbolData();
- Array<DbgSymbol*> orderedSyms;
- for (auto sym : mSymbolNameMap)
- {
- auto dbgSym = sym->mValue;
- orderedSyms.Add(dbgSym);
- }
- orderedSyms.Sort([](DbgSymbol* lhs, DbgSymbol* rhs) { return lhs->mAddress < rhs->mAddress; });
- for (int sectNum = 0; sectNum < ntHdr.mFileHeader.mNumberOfSections; sectNum++)
- {
- PESectionHeader& sectHdr = sectionHeaders[sectNum];
- mMemReporter->BeginSection(sectionNames[sectNum]);
- DbgSymbol* lastSym = NULL;
- for (auto dbgSym : orderedSyms)
- {
- if (dbgSym->mAddress < mImageBase + sectHdr.mVirtualAddress)
- continue;
- if (dbgSym->mAddress >= mImageBase + sectHdr.mVirtualAddress + sectHdr.mSizeOfRawData)
- break;
- if (lastSym != NULL)
- {
- mMemReporter->Add(lastSym->mName, (int)(dbgSym->mAddress - lastSym->mAddress));
- }
- else
- {
- int startingOffset = (int)(dbgSym->mAddress - (mImageBase + sectHdr.mVirtualAddress + sectHdr.mSizeOfRawData));
- if (startingOffset > 0)
- mMemReporter->Add("<StartData>", startingOffset);
- }
- lastSym = dbgSym;
- }
- if (lastSym != NULL)
- mMemReporter->Add(lastSym->mName, (int)((mImageBase + sectHdr.mVirtualAddress + sectHdr.mSizeOfRawData) - lastSym->mAddress));
- else
- {
- mMemReporter->Add("<Unaccounted>", (int)(sectHdr.mSizeOfRawData));
- }
- mMemReporter->EndSection();
- }
- mMemReporter->EndSection();
- mMemReporter->mShowInKB = false;
- mMemReporter->Report();
- }
- return true;
- }
- void DbgModule::FinishHotSwap()
- {
- BF_ASSERT(IsObjectFile());
- auto linkedModule = GetLinkedModule();
- auto mainModule = mDebugTarget->mTargetBinary;
- HashSet<String> failSet;
- String findName;
- for (auto deferredHotResolve : mDeferredHotResolveList)
- {
- addr_target resolveTargetAddr = deferredHotResolve->mNewAddr;
- findName = deferredHotResolve->mName;
- if (mDbgFlavor == DbgFlavor_MS)
- {
- // ... why do we need to find these variables in the variable map instead of the symbol name map?
- }
- auto itr = mainModule->mStaticVariableMap.find(findName.c_str());
- if (itr != mainModule->mStaticVariableMap.end())
- {
- DbgVariable* variable = itr->second;
- resolveTargetAddr = mDebugTarget->GetStaticAddress(variable);
- }
- else
- {
- auto symbolEntry = mainModule->mSymbolNameMap.Find(findName.c_str());
- if (symbolEntry != NULL)
- {
- resolveTargetAddr = symbolEntry->mValue->mAddress;
- }
- else
- {
- if (deferredHotResolve->mName == "__ImageBase")
- {
- resolveTargetAddr = (addr_target)mainModule->mImageBase;
- }
- else
- {
- resolveTargetAddr = mainModule->LocateSymbol(deferredHotResolve->mName);
- if (resolveTargetAddr == 0)
- {
- failSet.Add(deferredHotResolve->mName);
- continue;
- }
- }
- }
- }
- DoReloc(deferredHotResolve->mHotTargetSection, deferredHotResolve->mReloc, resolveTargetAddr, NULL);
- }
- mDeferredHotResolveList.Clear();
- if (!failSet.IsEmpty())
- {
- bool handled = false;
- if (!mDebugger->mDebugManager->mOutMessages.empty())
- {
- auto& str = mDebugger->mDebugManager->mOutMessages.back();
- if (str.Contains("failed to resolve"))
- {
- for (auto& sym : failSet)
- {
- str += ", ";
- str += sym;
- }
- handled = true;
- }
- }
- if (!handled)
- {
- int symIdx = 0;
- String str;
- if (failSet.size() == 1)
- str = "Hot swapping failed to resolve symbol: ";
- else
- str = "Hot swapping failed to resolve symbols: ";
- for (auto& sym : failSet)
- {
- if (symIdx != 0)
- str += ", ";
- str += sym;
- symIdx++;
- }
- mDebugger->Fail(str);
- }
- }
- CommitHotTargetSections();
- // We need this here because vdata gets loaded first, so we need to wait until we have the addrs for the new methods (from other modules)
- // before we can finalize the class vdata.
- ProcessHotSwapVariables();
- for (auto hotTargetSection : mHotTargetSections)
- delete hotTargetSection;
- mHotTargetSections.Clear();
- mSymbolNameMap.Clear();
- }
- addr_target DbgModule::ExecuteOps(DbgSubprogram* dwSubprogram, const uint8* locData, int locDataLen, WdStackFrame* stackFrame, CPURegisters* registers, DbgAddrType* outAddrType, DbgEvalLocFlags flags, addr_target* pushValue)
- {
- bool allowReg = (flags & DbgEvalLocFlag_IsParam) == 0;
- const uint8* locDataEnd = locData + locDataLen;
- int regNum = -1;
- addr_target stackFrameData[256];
- int stackIdx = 0;
- if (pushValue != NULL)
- stackFrameData[stackIdx++] = *pushValue;
- while (locData < locDataEnd)
- {
- uint8 opCode = GET_FROM(locData, uint8);
- switch (opCode)
- {
- case DW_OP_piece:
- {
- if (*outAddrType == DbgAddrType_Register)
- *outAddrType = DbgAddrType_Value;
- addr_target val = stackFrameData[--stackIdx];
- int pieceSize = (int)DecodeULEB128(locData);
- if (pieceSize == 4)
- val &= 0xFFFFFFFF;
- else if (pieceSize == 2)
- val &= 0xFFFF;
- else if (pieceSize == 1)
- val &= 0xFF;
- stackFrameData[stackIdx++] = val;
- }
- break;
- case DW_OP_consts:
- {
- int64 val = DecodeSLEB128(locData);
- stackFrameData[stackIdx++] = (addr_target)val;
- }
- break;
- case DW_OP_stack_value:
- {
- *outAddrType = DbgAddrType_Value;
- }
- break;
- case DW_OP_addr_noRemap:
- {
- addr_target addr = GET_FROM(locData, addr_target);
- stackFrameData[stackIdx++] = addr;
- //*outIsAddr = true;
- *outAddrType = DbgAddrType_Target;
- }
- break;
- case DW_OP_addr:
- {
- addr_target addr = GET_FROM(locData, addr_target);
- //if (dwarf != NULL)
- addr = RemapAddr(addr);
- stackFrameData[stackIdx++] = addr;
- //*outIsAddr = true;
- *outAddrType = DbgAddrType_Target;
- }
- break;
- case DW_OP_deref:
- {
- addr_target addr = stackFrameData[--stackIdx];
- addr_target value = mDebugger->ReadMemory<addr_target>(addr);
- stackFrameData[stackIdx++] = value;
- }
- break;
- case DW_OP_fbreg:
- {
- if (registers == NULL)
- return 0;
- BF_ASSERT(dwSubprogram != NULL);
- DbgSubprogram* nonInlinedSubProgram = dwSubprogram->GetRootInlineParent();
- if (nonInlinedSubProgram->mFrameBaseData == NULL)
- {
- *outAddrType = DbgAddrType_Target; //TODO: why?
- return 0;
- }
- BF_ASSERT(nonInlinedSubProgram->mFrameBaseData != NULL);
- intptr loc = EvaluateLocation(nonInlinedSubProgram, nonInlinedSubProgram->mFrameBaseData, nonInlinedSubProgram->mFrameBaseLen, stackFrame, outAddrType, DbgEvalLocFlag_DisallowReg);
- int64 offset = DecodeSLEB128(locData);
- loc += offset;
- //loc = BfDebuggerReadMemory(loc);
- //*outIsAddr = true;
- *outAddrType = DbgAddrType_Target;
- stackFrameData[stackIdx++] = (addr_target)loc;
- }
- break;
- case DW_OP_reg0:
- case DW_OP_reg1:
- case DW_OP_reg2:
- case DW_OP_reg3:
- case DW_OP_reg4:
- case DW_OP_reg5:
- case DW_OP_reg6:
- case DW_OP_reg7:
- case DW_OP_reg8:
- case DW_OP_reg9:
- case DW_OP_reg10:
- case DW_OP_reg11:
- case DW_OP_reg12:
- case DW_OP_reg13:
- case DW_OP_reg14:
- case DW_OP_reg15:
- if (registers == NULL)
- return 0;
- BF_ASSERT((opCode - DW_OP_reg0) < CPURegisters::kNumIntRegs);
- regNum = opCode - DW_OP_reg0;
- stackFrameData[stackIdx++] = registers->mIntRegsArray[regNum];
- *outAddrType = DbgAddrType_Register;
- break;
- case DW_OP_reg21: //XMM0
- BF_FATAL("XMM registers not supported yet");
- break;
- case DW_OP_breg0:
- case DW_OP_breg1:
- case DW_OP_breg2:
- case DW_OP_breg3:
- case DW_OP_breg4:
- case DW_OP_breg5:
- case DW_OP_breg6:
- case DW_OP_breg7:
- case DW_OP_breg8:
- case DW_OP_breg9:
- case DW_OP_breg10:
- case DW_OP_breg11:
- case DW_OP_breg12:
- case DW_OP_breg13:
- case DW_OP_breg14:
- case DW_OP_breg15:
- {
- if (registers == NULL)
- return 0;
- int64 offset = DecodeSLEB128(locData);
- BF_ASSERT((opCode - DW_OP_breg0) < CPURegisters::kNumIntRegs);
- auto loc = registers->mIntRegsArray[opCode - DW_OP_breg0] + offset;
- //loc = BfDebuggerReadMemory(loc);
- //*outIsAddr = true;
- *outAddrType = DbgAddrType_Target;
- stackFrameData[stackIdx++] = (addr_target)loc;
- }
- break;
- case DW_OP_bregx:
- {
- if (registers == NULL)
- return 0;
- int regNum = (int)DecodeULEB128(locData);
- int64 offset = DecodeSLEB128(locData);
- BF_ASSERT(regNum < CPURegisters::kNumIntRegs);
- auto loc = registers->mIntRegsArray[regNum] + offset;
- //loc = BfDebuggerReadMemory(loc);
- //*outIsAddr = true;
- *outAddrType = DbgAddrType_Target;
- stackFrameData[stackIdx++] = (addr_target)loc;
- }
- break;
- case DW_OP_const4u:
- {
- uint32 val = GET_FROM(locData, uint32);
- stackFrameData[stackIdx++] = val;
- }
- break;
- case DW_OP_const8u:
- {
- uint64 val = GET_FROM(locData, uint64);
- stackFrameData[stackIdx++] = (addr_target)val;
- }
- break;
- case DW_OP_GNU_push_tls_address:
- {
- if ((mTLSAddr == 0) || (mTLSIndexAddr == 0))
- return 0;
- int tlsIndex = mDebugger->ReadMemory<int>(mTLSIndexAddr);
- addr_target tlsEntry = mDebugger->GetTLSOffset(tlsIndex);
- intptr_target tlsValueIndex = stackFrameData[--stackIdx];
- stackFrameData[stackIdx++] = (tlsValueIndex - mTLSAddr) + tlsEntry;
- *outAddrType = DbgAddrType_Target;
- }
- break;
- case DW_OP_nop:
- break;
- default:
- BF_FATAL("Unknown DW_OP");
- break;
- }
- }
- if (*outAddrType == DbgAddrType_Register)
- {
- if (allowReg)
- return regNum;
- *outAddrType = DbgAddrType_Value;
- }
- //BF_ASSERT(stackIdx == 1);
- return stackFrameData[--stackIdx];
- }
- intptr DbgModule::EvaluateLocation(DbgSubprogram* dwSubprogram, const uint8* locData, int locDataLen, WdStackFrame* stackFrame, DbgAddrType* outAddrType, DbgEvalLocFlags flags)
- {
- BP_ZONE("DebugTarget::EvaluateLocation");
- auto dbgModule = this;
- if (locDataLen == DbgLocationLenKind_SegPlusOffset)
- {
- BF_ASSERT(dbgModule->mDbgFlavor == DbgFlavor_MS);
- if (dbgModule->mDbgFlavor == DbgFlavor_MS)
- {
- COFF* coff = (COFF*)dbgModule;
- struct SegOfsData
- {
- uint32 mOfs;
- uint16 mSeg;
- };
- SegOfsData* segOfsData = (SegOfsData*)locData;
- *outAddrType = DbgAddrType_Target;
- return coff->GetSectionAddr(segOfsData->mSeg, segOfsData->mOfs);
- }
- else
- {
- *outAddrType = DbgAddrType_Target;
- return 0;
- }
- }
- CPURegisters* registers = NULL;
- if (stackFrame != NULL)
- registers = &stackFrame->mRegisters;
- if (locDataLen < 0)
- {
- if (registers == NULL)
- return 0;
- int64 ipAddr = stackFrame->GetSourcePC();
- const uint8* checkLocData = locData;
- int64 startLoc = (int64)GET_FROM(checkLocData, addr_target);
- int64 endLoc = startLoc + GET_FROM(checkLocData, uint16);
- BF_ASSERT(dwSubprogram != NULL);
- startLoc += dwSubprogram->mCompileUnit->mLowPC;
- endLoc += dwSubprogram->mCompileUnit->mLowPC;
- if ((ipAddr >= startLoc) && (ipAddr < endLoc))
- {
- locDataLen = -locDataLen - sizeof(addr_target) - sizeof(uint16);
- locData = checkLocData;
- }
- else
- {
- *outAddrType = DbgAddrType_OptimizedOut;
- return 0;
- }
- }
- else if (locDataLen == 0)
- {
- if (registers == NULL)
- return 0;
- int64 ipAddr = stackFrame->GetSourcePC();
- const uint8* checkLocData = locData;
- while (true)
- {
- int64 startLoc = (int64)GET_FROM(checkLocData, addr_target);
- int64 endLoc = (int64)GET_FROM(checkLocData, addr_target);
- if ((startLoc == 0) && (endLoc == 0))
- {
- *outAddrType = DbgAddrType_OptimizedOut;
- return 0;
- }
- BF_ASSERT(dwSubprogram != NULL);
- startLoc += dwSubprogram->mCompileUnit->mLowPC;
- endLoc += dwSubprogram->mCompileUnit->mLowPC;
- if ((ipAddr >= startLoc) && (ipAddr < endLoc))
- {
- locDataLen = GET_FROM(checkLocData, int16);
- locData = checkLocData;
- break;
- }
- else
- {
- int len = GET_FROM(checkLocData, int16);;
- checkLocData += len;
- }
- }
- }
- return ExecuteOps(dwSubprogram, locData, locDataLen, stackFrame, registers, outAddrType, flags);
- }
- void DbgModule::ProcessHotSwapVariables()
- {
- BP_ZONE("DbgModule::ProcessHotSwapVariables");
- auto linkedModule = GetLinkedModule();
- for (auto staticVariable : mStaticVariables)
- {
- bool replaceVariable = false;
- const char* findName = staticVariable->GetMappedName();
- auto itr = linkedModule->mStaticVariableMap.find(findName);
- if (itr != linkedModule->mStaticVariableMap.end())
- {
- DbgVariable* oldVariable = itr->second;
- // If the old static field has the same type as the new static field then we keep the same
- // address, otherwise we use the new (zeroed-out) allocated space
- auto _GetNewAddress = [&]()
- {
- addr_target newAddress = 0;
- if (mDbgFlavor == DbgFlavor_GNU)
- {
- newAddress = mDebugTarget->GetStaticAddress(staticVariable);
- }
- else
- {
- // In CodeView, the newVariable ends up pointing to the old address, so we need to store
- // the location in our own mSymbolNameMap
- auto entry = mSymbolNameMap.Find(oldVariable->mLinkName);
- if (entry != NULL)
- newAddress = entry->mValue->mAddress;
- }
- return newAddress;
- };
- if (oldVariable->mType->IsSizedArray())
- {
- mDebugTarget->GetCompilerSettings();
- bool doMerge = strstr(oldVariable->mName, "sBfClassVData") != NULL;
- bool keepInPlace = (doMerge) && (strstr(oldVariable->mName, ".vext") == NULL);
- if (doMerge)
- {
- addr_target oldAddress = mDebugTarget->GetStaticAddress(oldVariable);
- addr_target newAddress = _GetNewAddress();
- if (newAddress == 0)
- continue;
- uint8* newData = GetHotTargetData(newAddress);
- int newArraySize = (int)staticVariable->mType->GetByteCount();
- int oldArraySize = (int)oldVariable->mType->GetByteCount();
- int copySize = std::min(newArraySize, oldArraySize);
- BF_ASSERT((oldArraySize & (sizeof(addr_target) - 1)) == 0);
- DbgModule* defModule = oldVariable->mType->mCompileUnit->mDbgModule;
- defModule->EnableWriting(oldAddress);
- uint8* mergedData = new uint8[copySize];
- mDebugger->ReadMemory(oldAddress, copySize, mergedData);
- // The new vtable may have 0's in it when virtual methods are removed. Keep the old virtual addresses in those.
- addr_target* newDataPtr = (addr_target*)newData;
- addr_target* mergedPtr = (addr_target*)mergedData;
- while (mergedPtr < (addr_target*)(mergedData + copySize))
- {
- if (*newDataPtr != 0)
- *mergedPtr = *newDataPtr;
- mergedPtr++;
- newDataPtr++;
- }
- bool success;
- success = mDebugger->WriteMemory(oldAddress, mergedData, copySize);
- BF_ASSERT(success);
- memcpy(newData, mergedData, copySize);
- delete mergedData;
- }
- else if (strstr(oldVariable->mName, "sStringLiterals") != NULL)
- {
- addr_target oldAddress = mDebugTarget->GetStaticAddress(oldVariable);
- addr_target newAddress = NULL;
- if (mDbgFlavor == DbgFlavor_GNU)
- {
- newAddress = mDebugTarget->GetStaticAddress(staticVariable);
- }
- else
- {
- // In CodeView, the newVariable ends up pointing to the old address, so we need to store
- // the location in our own mSymbolNameMap
- auto entry = mSymbolNameMap.Find(oldVariable->mLinkName);
- if (entry == NULL)
- continue;
- newAddress = entry->mValue->mAddress;
- }
- // Make sure newAddress doesn't have anything linked to it
- addr_target val = 0;
- bool success = mDebugger->ReadMemory((intptr)newAddress, sizeof(addr_target), &val);
- BF_ASSERT(success);
- BF_ASSERT(val == 0);
- // Link the new table to the old extended table
- addr_target prevLinkage = 0;
- success = mDebugger->ReadMemory((intptr)oldAddress, sizeof(addr_target), &prevLinkage);
- BF_ASSERT(success);
- success = mDebugger->WriteMemory((intptr)newAddress, &prevLinkage, sizeof(addr_target));
- BF_ASSERT(success);
- mDebugger->EnableWriting((intptr)oldAddress, sizeof(addr_target));
- success = mDebugger->WriteMemory((intptr)oldAddress, &newAddress, sizeof(addr_target));
- BF_ASSERT(success);
- keepInPlace = true;
- }
- if (keepInPlace)
- {
- // We have to maintain the OLD size because we can't overwrite the original bounds
- staticVariable->mType = oldVariable->mType;
- staticVariable->mLocationLen = oldVariable->mLocationLen;
- staticVariable->mLocationData = oldVariable->mLocationData;
- staticVariable->mCompileUnit = oldVariable->mCompileUnit;
- }
- }
- else if (oldVariable->mType->Equals(staticVariable->mType))
- {
- if (oldVariable->mType->IsStruct())
- {
- if ((strncmp(oldVariable->mName, "?sBfTypeData@", 13) == 0) || (strncmp(oldVariable->mName, "sBfTypeData.", 12) == 0))
- {
- int size = (int)staticVariable->mType->GetByteCount();
- addr_target oldAddress = mDebugTarget->GetStaticAddress(oldVariable);
- addr_target newAddress = _GetNewAddress();
- if (newAddress == 0)
- continue;
- uint8* data = new uint8[size];
- bool success = mDebugger->ReadMemory(newAddress, size, data);
- if (success)
- {
- mDebugger->EnableWriting((intptr)oldAddress, size);
- success = mDebugger->WriteMemory(oldAddress, data, size);
- }
- delete data;
- BF_ASSERT(success);
- staticVariable->mLocationLen = oldVariable->mLocationLen;
- staticVariable->mLocationData = oldVariable->mLocationData;
- }
- }
- //staticVariable->mLocationLen = oldVariable->mLocationLen;
- //staticVariable->mLocationData = oldVariable->mLocationData;
- replaceVariable = false;
- }
- else
- {
- BF_ASSERT(!oldVariable->mType->IsSizedArray());
- }
- if (!replaceVariable)
- {
- auto symbolVal = linkedModule->mSymbolNameMap.Find(staticVariable->GetMappedName());
- if (symbolVal != NULL)
- {
- addr_target oldAddress = mDebugTarget->GetStaticAddress(oldVariable);
- DbgSymbol* oldSymbol = mDebugTarget->mSymbolMap.Get(oldAddress);
- if (oldSymbol != NULL)
- symbolVal->mValue = oldSymbol;
- }
- }
- }
- else // Not found - new variable
- replaceVariable = true;
- if (replaceVariable)
- {
- linkedModule->mStaticVariableMap[staticVariable->GetMappedName()] = staticVariable;
- }
- }
- }
- int64 DbgModule::GetImageSize()
- {
- return mImageSize;
- }
- /*const uint8* DbgModule::GetOrigImageData(addr_target address)
- {
- return mOrigImageData + (address - mImageBase);
- }*/
- DbgFileExistKind DbgModule::CheckSourceFileExist(const StringImpl& path)
- {
- DbgFileExistKind existsKind = DbgFileExistKind_NotFound;
- if (path.StartsWith("$Emit"))
- return DbgFileExistKind_Found;
- if (FileExists(path))
- existsKind = DbgFileExistKind_Found;
- String oldSourceCommand = GetOldSourceCommand(path);
- if (!oldSourceCommand.IsEmpty())
- {
- int crPos = (int)oldSourceCommand.IndexOf('\n');
- if (crPos != -1)
- {
- String targetPath = oldSourceCommand.Substring(0, crPos);
- if (FileExists(targetPath))
- existsKind = DbgFileExistKind_Found;
- else
- existsKind = DbgFileExistKind_HasOldSourceCommand;
- }
- }
- return existsKind;
- }
- void DbgModule::EnableWriting(addr_target address)
- {
- for (int sectionIdx = 0; sectionIdx < (int)mSections.size(); sectionIdx++)
- {
- DbgSection* section = &mSections[sectionIdx];
- if ((address >= mImageBase + section->mAddrStart) && (address < mImageBase + section->mAddrStart + section->mAddrLength))
- {
- if (!section->mWritingEnabled)
- {
- section->mOldProt = mDebugger->EnableWriting(mImageBase + section->mAddrStart, (int32)section->mAddrLength);
- section->mWritingEnabled = true;
- }
- }
- }
- }
- void DbgModule::RevertWritingEnable()
- {
- for (int sectionIdx = 0; sectionIdx < (int)mSections.size(); sectionIdx++)
- {
- DbgSection* section = &mSections[sectionIdx];
- if (section->mWritingEnabled)
- {
- mDebugger->SetProtection(mImageBase + section->mAddrStart, (int32)section->mAddrLength, section->mOldProt);
- section->mWritingEnabled = false;
- }
- }
- }
- template <typename TRadixMap>
- static void RemoveInvalidRange(TRadixMap& radixMap, addr_target startAddr, int addrLength)
- {
- radixMap.RemoveRange(startAddr, addrLength);
- }
- template <typename TMap>
- static void RemoveInvalidMapRange(TMap& map, addr_target startAddr, int addrLength)
- {
- auto itr = map.lower_bound(startAddr);
- while (itr != map.end())
- {
- auto val = itr->first;
- if (val >= startAddr + addrLength)
- return;
- itr = map.erase(itr);
- }
- }
- void DbgModule::RemoveTargetData()
- {
- BP_ZONE("DbgModule::RemoveTargetData");
- for (auto srcFileRef : mSrcFileDeferredRefs)
- srcFileRef->RemoveDeferredRefs(this);
- HashSet<DbgSrcFile*> visitedFiles;
- for (auto compileUnit : mCompileUnits)
- {
- for (auto& fileRef : compileUnit->mSrcFileRefs)
- {
- if (visitedFiles.Add(fileRef.mSrcFile))
- {
- fileRef.mSrcFile->RemoveLines(this);
- }
- }
- }
- RemoveInvalidRange(mDebugTarget->mSymbolMap, (addr_target)mImageBase, (int32)mImageSize);
- RemoveInvalidRange(mDebugTarget->mSubprogramMap, (addr_target)mImageBase, (int32)mImageSize);
- RemoveInvalidRange(mDebugTarget->mExceptionDirectoryMap, (addr_target)mImageBase, (int32)mImageSize);
- RemoveInvalidRange(mDebugTarget->mContribMap, (addr_target)mImageBase, (int32)mImageSize);
- RemoveInvalidMapRange(mDebugTarget->mDwFrameDescriptorMap, (addr_target)mImageBase, (int32)mImageSize);
- RemoveInvalidMapRange(mDebugTarget->mCOFFFrameDescriptorMap, (addr_target)mImageBase, (int32)mImageSize);
- //mDebugTarget->mDwFrameDescriptorMap.erase()
- // Remove any of our entries from the mHotReplacedMethodList from 'primary modules' that are not going away
- for (auto dbgType : mHotPrimaryTypes)
- {
- DbgSubprogram** nextSrc = &dbgType->mHotReplacedMethodList.mHead;
- while (*nextSrc != NULL)
- {
- auto* subprogram = *nextSrc;
- if (subprogram->mCompileUnit->mDbgModule == this)
- *nextSrc = subprogram->mNext;
- else
- nextSrc = &(*nextSrc)->mNext;;
- }
- }
- }
- void DbgModule::ReportMemory(MemReporter* memReporter)
- {
- //memReporter->Add("BumpAlloc_Used", mAlloc.GetAllocSize());
- //memReporter->Add("BumpAlloc_Unused", mAlloc.GetTotalAllocSize() - mAlloc.GetAllocSize());
- memReporter->AddBumpAlloc("BumpAlloc", mAlloc);
- memReporter->AddVec(mTypes);
- memReporter->AddVec(mSubprograms);
- //memReporter->Add("TypeMap", mTypeMap.mAlloc.GetTotalAllocSize() + sizeof(StrHashMap<DbgType*>));
- memReporter->AddHashSet("TypeMap", mTypeMap.mMap);
- memReporter->Add("SymbolNameMap", mSymbolNameMap.mAlloc.GetTotalAllocSize() + sizeof(StrHashMap<DbgType*>));
- if (mOrigImageData != NULL)
- {
- memReporter->BeginSection("OrigImageData");
- mOrigImageData->ReportMemory(memReporter);
- memReporter->EndSection();
- }
- }
- DbgType* DbgModule::GetPointerType(DbgType* innerType)
- {
- auto linkedModule = GetLinkedModule();
- BF_ASSERT(innerType->GetDbgModule()->GetLinkedModule() == linkedModule);
- if (innerType->mPtrType == NULL)
- {
- BP_ALLOC_T(DbgType);
- auto ptrType = mAlloc.Alloc<DbgType>();
- ptrType->mCompileUnit = innerType->mCompileUnit;
- ptrType->mLanguage = innerType->mLanguage;
- ptrType->mTypeCode = DbgType_Ptr;
- ptrType->mTypeParam = innerType;
- ptrType->mSize = sizeof(addr_target);
- ptrType->mAlign = (int)ptrType->mSize;
- ptrType->mTypeIdx = (int32)linkedModule->mTypes.size();
- linkedModule->mTypes.push_back(ptrType);
- innerType->mPtrType = ptrType;
- }
- return innerType->mPtrType;
- }
- DbgType* DbgModule::GetConstType(DbgType* innerType)
- {
- auto linkedModule = GetLinkedModule();
- BF_ASSERT(innerType->GetDbgModule()->GetLinkedModule() == linkedModule);
- /*auto itr = linkedModule->mConstTypes.find(innerType);
- if (itr != linkedModule->mConstTypes.end())
- return itr->second;*/
- DbgType* constType = NULL;
- if (linkedModule->mConstTypes.TryGetValue(innerType, &constType))
- return constType;
- BP_ALLOC_T(DbgType);
- constType = mAlloc.Alloc<DbgType>();
- constType->mCompileUnit = innerType->mCompileUnit;
- constType->mLanguage = innerType->mLanguage;
- constType->mTypeCode = DbgType_Const;
- constType->mTypeParam = innerType;
- constType->mSize = sizeof(addr_target);
- constType->mTypeIdx = (int32)linkedModule->mTypes.size();
- linkedModule->mTypes.push_back(constType);
- linkedModule->mConstTypes[innerType] = constType;
- return constType;
- }
- DbgType* DbgModule::GetPrimaryType(DbgType* dbgType)
- {
- if (dbgType->mPriority <= DbgTypePriority_Normal)
- {
- if ((dbgType->mLanguage == DbgLanguage_Beef) && (dbgType->mName != NULL))
- {
- auto newTypeEntry = FindType(dbgType->mName, dbgType->mLanguage);
- if (newTypeEntry != NULL)
- {
- DbgType* newType = newTypeEntry->mValue;
- if ((newType->mTypeCode == DbgType_Ptr) && (newType->IsBfObjectPtr()))
- newType = newType->mTypeParam;
- newType->mPriority = DbgTypePriority_Primary_Implicit;
- return newType;
- }
- }
- else if (dbgType->mName != NULL)
- {
- auto newTypeEntry = FindType(dbgType->mName, dbgType->mLanguage);
- if (newTypeEntry != NULL)
- {
- DbgType* newType = newTypeEntry->mValue;
- newType = newType->RemoveModifiers();
- if (newType != dbgType)
- newType = GetPrimaryType(newType);
- newType->mPriority = DbgTypePriority_Primary_Implicit;
- return newType;
- }
- }
- }
- return dbgType;
- }
- DbgType* DbgModule::GetInnerTypeOrVoid(DbgType* dbgType)
- {
- if (dbgType->mTypeParam != NULL)
- return dbgType->mTypeParam;
- return GetPrimitiveType(DbgType_Void, dbgType->mLanguage);
- }
- DbgType* DbgModule::FindTypeHelper(const String& typeName, DbgType* checkType)
- {
- for (auto subType : checkType->mSubTypeList)
- {
- if (strcmp(subType->mTypeName, typeName.c_str()) == 0)
- return subType;
- }
- for (auto baseType : checkType->mBaseTypes)
- {
- auto retType = FindTypeHelper(typeName, baseType->mBaseType);
- if (retType != NULL)
- return retType;
- }
- return NULL;
- }
- DbgType* DbgModule::FindType(const String& typeName, DbgType* contextType, DbgLanguage language, bool bfObjectPtr)
- {
- if ((language == DbgLanguage_Unknown) && (contextType != NULL))
- language = contextType->mLanguage;
- if (typeName.length() > 0)
- {
- if (typeName[typeName.length() - 1] == '*')
- {
- DbgType* dbgType = FindType(typeName.Substring(0, typeName.length() - 1), contextType, language, bfObjectPtr);
- if (dbgType == NULL)
- return NULL;
- return GetPointerType(dbgType);
- }
- }
- auto entry = GetLinkedModule()->mTypeMap.Find(typeName.c_str(), language);
- if (entry != NULL)
- {
- if ((bfObjectPtr) && (entry->mValue->IsBfObject()))
- return GetPointerType(entry->mValue);
- return entry->mValue;
- }
- if (contextType != NULL)
- {
- DbgType* checkType = contextType;
- if (checkType->IsPointer())
- checkType = checkType->mTypeParam;
- return FindTypeHelper(typeName, checkType);
- }
- return NULL;
- }
- DbgTypeMap::Entry* DbgModule::FindType(const char* typeName, DbgLanguage language)
- {
- return GetLinkedModule()->mTypeMap.Find(typeName, language);
- /*auto& typeMap = GetLinkedModule()->mTypeMap;
- auto dbgTypeEntry = typeMap.Find(typeName);
- if (dbgTypeEntry == NULL)
- return NULL;
- if (dbgTypeEntry->mValue->mLanguage == language)
- return dbgTypeEntry;
- while (dbgTypeEntry != NULL)
- {
- DbgType* dbgType = dbgTypeEntry->mValue;
- if ((dbgType->GetLanguage() == language) && (typeMap.StrEqual(dbgType->mName, typeName)))
- return dbgTypeEntry;
- dbgTypeEntry = dbgTypeEntry->mNext;
- }*/
- //return NULL;
- }
- DbgType* DbgModule::GetPrimitiveType(DbgTypeCode typeCode, DbgLanguage language)
- {
- if (language == DbgLanguage_Beef)
- return mBfPrimitiveTypes[(int)typeCode];
- else
- return mCPrimitiveTypes[(int)typeCode];
- }
- DbgType* DbgModule::GetPrimitiveStructType(DbgTypeCode typeCode)
- {
- const char* name = mPrimitiveStructNames[typeCode];
- if (name == NULL)
- return NULL;
- return FindType(name, NULL, DbgLanguage_Beef);
- }
- DbgType* DbgModule::GetSizedArrayType(DbgType * elementType, int count)
- {
- auto linkedModule = GetLinkedModule();
- if ((linkedModule != NULL) && (linkedModule != this))
- {
- return linkedModule->GetSizedArrayType(elementType, count);
- }
- DbgType** sizedArrayTypePtr;
- DbgSizedArrayEntry entry;
- entry.mElementType = elementType;
- entry.mCount = count;
- if (mSizedArrayTypes.TryAdd(entry, NULL, &sizedArrayTypePtr))
- {
- BP_ALLOC_T(DbgType);
- auto sizedArrayType = mAlloc.Alloc<DbgType>();
- sizedArrayType->mCompileUnit = elementType->mCompileUnit;
- sizedArrayType->mLanguage = elementType->mLanguage;
- sizedArrayType->mTypeCode = DbgType_SizedArray;
- sizedArrayType->mTypeParam = elementType;
- sizedArrayType->mSize = count * elementType->GetStride();
- sizedArrayType->mAlign = elementType->GetAlign();
- sizedArrayType->mSizeCalculated = true;
- sizedArrayType->mTypeIdx = (int32)mTypes.size();
- linkedModule->mTypes.push_back(sizedArrayType);
- *sizedArrayTypePtr = sizedArrayType;
- }
- return *sizedArrayTypePtr;
- }
|