123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317 |
- #include "COFF.h"
- #include "BeefySysLib/FileStream.h"
- #include "BeefySysLib/MemStream.h"
- #include "codeview/cvinfo.h"
- #include "DebugTarget.h"
- #include "DebugManager.h"
- #include "DWARFInfo.h"
- #include "BeefySysLib/util/PerfTimer.h"
- #include "BeefySysLib/util/Dictionary.h"
- #include "BeefySysLib/util/BeefPerf.h"
- #include "BeefySysLib/util/BeefPerf.h"
- #include "BeefySysLib/util/ZipFile.h"
- #include "BeefySysLib/util/Hash.h"
- #include "BeefySysLib/platform/PlatformHelper.h"
- #include "WinDebugger.h"
- #include "MiniDumpDebugger.h"
- #include "Linker/BlHash.h"
- #include "Backend/BeLibManger.h"
- #include "Compiler/BfUtil.h"
- #include <shlobj.h>
- #include "BeefySysLib/util/AllocDebug.h"
- #define LF_CLASS_EX 0x1608
- #define LF_STRUCTURE_EX 0x1609
- USING_NS_BF_DBG;
- #define MSF_SIGNATURE_700 "Microsoft C/C++ MSF 7.00\r\n\032DS\0\0"
- static const int NUM_ROOT_DIRS = 73;
- #pragma warning(default:4800)
- #define ADDR_FLAG_ABS 0x8000000000000000L
- #define GET(T) *((T*)(data += sizeof(T)) - 1)
- #define GET_INTO(T, name) T name = GET(T)
- #define GET_FROM(ptr, T) *((T*)(ptr += sizeof(T)) - 1)
- #define PTR_ALIGN(ptr, origPtr, alignSize) ptr = ( (origPtr)+( ((ptr - origPtr) + (alignSize - 1)) & ~(alignSize - 1) ) )
- static const char* DataGetString(uint8*& data)
- {
- const char* prevVal = (const char*)data;
- while (*data != 0)
- data++;
- data++;
- return prevVal;
- }
- static const char* SafeDataGetString(uint8*& data, uint8* dataEnd)
- {
- if (data >= dataEnd)
- return NULL;
- const char* prevVal = (const char*)data;
- while (*data != 0)
- {
- data++;
- if (data >= dataEnd)
- return NULL;
- }
- data++;
- return prevVal;
- }
- #define CREATE_PRIMITIVE(pdbTypeCode, dwTypeCode, typeName, type) \
- BP_ALLOC_T(DbgType); \
- dbgType = mAlloc.Alloc<DbgType>(); \
- dbgType->mCompileUnit = mMasterCompileUnit; \
- dbgType->mTypeName = typeName; \
- dbgType->mName = typeName; \
- dbgType->mTypeCode = dwTypeCode; \
- dbgType->mSize = sizeof(type); \
- dbgType->mAlign = sizeof(type); \
- mCvSystemTypes[(int)pdbTypeCode] = dbgType; \
- \
- BP_ALLOC_T(DbgType); \
- ptrType = mAlloc.Alloc<DbgType>(); \
- ptrType->mCompileUnit = mMasterCompileUnit; \
- ptrType->mTypeCode = DbgType_Ptr; \
- ptrType->mSize = sizeof(addr_target); \
- ptrType->mAlign = sizeof(addr_target); \
- ptrType->mTypeParam = dbgType; \
- dbgType->mPtrType = ptrType; \
- mCvSystemTypes[(int)pdbTypeCode | ptrMask] = ptrType;
- #define REGISTER_PRIMITIVE() mTypeMap.Insert(dbgType)
- static const char* GetLastDoubleColon(const char* name)
- {
- int templateDepth = 0;
- int parenDepth = 0;
- const char* lastDblColon = NULL;
- for (const char* checkPtr = name; *checkPtr != '\0'; checkPtr++)
- {
- char c = checkPtr[0];
- if (c == '<')
- templateDepth++;
- else if (c == '>')
- templateDepth--;
- else if (c == '(')
- parenDepth++;
- else if (c == ')')
- parenDepth--;
- if ((templateDepth == 0) && (parenDepth == 0) && (c == ':') && (checkPtr[1] == ':'))
- lastDblColon = checkPtr;
- if ((templateDepth == 0) && (parenDepth == 0) && (c == ' '))
- {
- // This catches cases like "Beefy::BfMethodRef::operator Beefy::BfMethodInstance*", where we want to match the :: right before "operator"
- break;
- }
- }
- return lastDblColon;
- }
- static const char* GetNamespaceEnd(const char* name)
- {
- int templateDepth = 0;
- const char* lastDblColon = NULL;
- for (const char* checkPtr = name; *checkPtr != '\0'; checkPtr++)
- {
- char c = checkPtr[0];
- if ((c == '<') || (c == ' '))
- return NULL;
- if ((c == ':') && (checkPtr[1] == ':'))
- lastDblColon = checkPtr;
- }
- return lastDblColon;
- }
- // This version inserts namespaces that contain specialized methods, but since we don't (at the time of this comment) support
- // calling specialized methods, we don't bother doing this -- it increases the scan time
- #if 0
- static const char* GetNamespaceEnd(const char* name)
- {
- bool hadTemplate = false;
- int templateDepth = 0;
- const char* lastDblColon = NULL;
- for (const char* checkPtr = name; *checkPtr != '\0'; checkPtr++)
- {
- char c = checkPtr[0];
- if (c == '<')
- {
- hadTemplate = true;
- templateDepth++;
- }
- else if (c == '>')
- templateDepth--;
- if ((templateDepth == 0) && (c == ':') && (checkPtr[1] == ':'))
- {
- if (hadTemplate)
- {
- // This is to reject cases like NameSpace::TypeName<int>::sField - since we know that there's a typename attached and we just want 'loose' namespaces,
- // But this still allows NameSpace::Method<int>, where "NameSpace" is indeed a loose namespace we need to catch
- return NULL;
- }
- lastDblColon = checkPtr;
- }
- if ((templateDepth == 0) && (c == ' '))
- {
- // This catches cases like "Beefy::BfMethodRef::operator Beefy::BfMethodInstance*", where we want to match the :: right before "operator"
- // In these cases we do know this is an operator method name so it's not in a loose namespace
- return NULL;
- }
- }
- return lastDblColon;
- }
- #endif
- //////////////////////////////////////////////////////////////////////////
- uint8* CvStreamReader::GetTempPtr(int offset, int size, bool mayRecurse, bool* madeCopy)
- {
- int pageStart = offset >> mPageBits;
- int pageEnd = (offset + size - 1) >> mPageBits;
- if (pageStart >= pageEnd)
- return mStreamPtrs.mVals[pageStart] + (offset & ((1<<mPageBits) - 1));
- // Handle the relatively-rare case of spanning multiple pages
- if (madeCopy != NULL)
- *madeCopy = true;
- uint8* destPtr;
- if (mayRecurse)
- {
- if (mCOFF->mTempBufIdx >= mCOFF->mTempBufs.size())
- mCOFF->mTempBufs.push_back(Array<uint8>());
- auto& arr = mCOFF->mTempBufs[mCOFF->mTempBufIdx++];
- if (arr.size() < size)
- arr.Resize(size);
- destPtr = arr.mVals;
- }
- else
- {
- if (mTempData.size() < size)
- mTempData.Resize(size);
- destPtr = mTempData.mVals;
- }
- uint8* dest = destPtr;
- while (size > 0)
- {
- int copyPage = offset >> mPageBits;
- int pageOffset = offset & ((1 << mPageBits) - 1);
- int copyBytes = BF_MIN(mCOFF->mCvPageSize - pageOffset, size);
- memcpy(destPtr, mStreamPtrs.mVals[copyPage] + pageOffset, copyBytes);
- destPtr += copyBytes;
- offset += copyBytes;
- size -= copyBytes;
- }
- return dest;
- }
- uint8* CvStreamReader::GetPermanentPtr(int offset, int size, bool* madeCopy)
- {
- int pageStart = offset >> mPageBits;
- int pageEnd = (offset + size - 1) >> mPageBits;
- if (pageStart == pageEnd)
- return mStreamPtrs.mVals[pageStart] + (offset & ((1 << mPageBits) - 1));
- // Handle the relatively-rare case of spanning multiple pages
- BP_ALLOC("GetPermanentPtr", size);
- uint8* destData = mCOFF->mAlloc.AllocBytes(size, "GetPermanentPtr");
- if (madeCopy != NULL)
- *madeCopy = true;
- uint8* destPtr = destData;
- while (size > 0)
- {
- int copyPage = offset >> mPageBits;
- int pageOffset = offset & ((1 << mPageBits) - 1);
- int copyBytes = BF_MIN(mCOFF->mCvPageSize - pageOffset, size);
- memcpy(destPtr, mStreamPtrs.mVals[copyPage] + pageOffset, copyBytes);
- destPtr += copyBytes;
- offset += copyBytes;
- size -= copyBytes;
- }
- return destData;
- }
- //////////////////////////////////////////////////////////////////////////
- COFF::COFF(DebugTarget* debugTarget) : DbgModule(debugTarget)
- {
- mParseKind = ParseKind_Full;
- memset(mWantPDBGuid, 0, 16);
- memset(mPDBGuid, 0, 16);
- mWantAge = -1;
- mDebugAge = -1;
- mFileAge = -1;
- mCvMinTag = -1;
- mCvMaxTag = -1;
- mCvIPIMinTag = -1;
- mCvIPIMaxTag = -1;
- mMasterCompileUnit = NULL;
- mTempBufIdx = 0;
- mIs64Bit = false;
- mCvPageSize = 0;
- mCvPageBits = 31;
- mCvDataStream = NULL;
- mCvHeaderData = NULL;
- mCvStrTableData = NULL;
- mCvPublicSymbolData = NULL;
- mCvGlobalSymbolData = NULL;
- mNewFPOData = NULL;
- mCvGlobalSymbolInfoStream = 0;
- mCvPublicSymbolInfoStream = 0;
- mCvSymbolRecordStream = 0;
- mCvNewFPOStream = 0;
- mCvMappedFile = INVALID_HANDLE_VALUE;
- mCvMappedFileMapping = INVALID_HANDLE_VALUE;
- mCvMappedViewOfFile = NULL;
- mCvMappedFileSize = 0;
- //mParsedProcRecs = false;
- mGlobalsTargetType = NULL;
- mPrevScanName = NULL;
- mProcSymCount = 0;
- mCvSrcSrvStream = -1;
- mCvEmitStream = -1;
- mIsFastLink = false;
- mHotThunkCurAddr = 0;
- mHotThunkDataLeft = 0;
- mTriedSymSrv = false;
- mDbgSymRequest = NULL;
- mWantsAutoLoadDebugInfo = false;
- mPDBLoaded = false;
- mEmitSourceFile = NULL;
- }
- COFF::~COFF()
- {
- BF_ASSERT(mTempBufIdx == 0);
- ClosePDB();
- mDebugger->mDbgSymSrv.ReleaseRequest(mDbgSymRequest);
- }
- const char* COFF::CvCheckTargetMatch(const char* name, bool& wasBeef)
- {
- if (mGlobalsTargetType == NULL)
- return NULL;
- /*if (mGlobalsTargetType->IsGlobalsContainer())
- {
- wasBeef = true;
- }
- else*/ if (mGlobalsTargetType->mLanguage == DbgLanguage_Beef)
- {
- if (strncmp(name, "_bf::", 5) != 0)
- return NULL;
- name += 5;
- wasBeef = true;
- }
- else if (mGlobalsTargetType->mTypeCode == DbgType_Root)
- {
- if (strncmp(name, "_bf::", 5) == 0)
- {
- wasBeef = true;
- name += 5;
- }
- }
- if (mGlobalsTargetType->mName == NULL)
- {
- for (const char* cPtr = name; *cPtr != '\0'; cPtr++)
- {
- if (*cPtr == ':')
- return NULL;
- if (*cPtr == '<')
- return NULL;
- }
- return name;
- }
- const char* memberNamePtr = name;
- const char* typeName = mGlobalsTargetType->mName;
- while (true)
- {
- char cm = *(memberNamePtr++);
- char ct = *(typeName++);
- if (ct == 0)
- {
- if (cm == ':')
- {
- const char* memberName = memberNamePtr + 1;
- for (const char* cPtr = memberName; *cPtr != '\0'; cPtr++)
- {
- if (*cPtr == ':')
- return NULL;
- if (*cPtr == '<')
- return NULL;
- }
- return memberName;
- }
- return NULL;
- }
- if (cm != ct)
- {
- if ((cm == ':') && (ct == '.') && (memberNamePtr[0] == ':'))
- {
- memberNamePtr++;
- continue;
- }
- return NULL;
- }
- }
- }
- int COFF::CvGetStringHash(const char* str)
- {
- if (str == NULL)
- return 0;
- int curHash = 0;
- const char* curHashPtr = str;
- while (*curHashPtr != 0)
- {
- char c = *curHashPtr;
- curHash = ((curHash ^ *curHashPtr) << 5) - curHash;
- curHashPtr++;
- }
- return curHash & 0x3FFFFFFF;
- }
- // Remove "__ptr64"
- void COFF::CvFixupName(char* name)
- {
- char* cPtrOut = NULL;
- for (char* cPtr = name; *cPtr != '\0'; cPtr++)
- {
- if ((cPtr[0] == '_') && (cPtr[1] == '_'))
- {
- if (strncmp(cPtr + 2, "ptr64", 5) == 0)
- {
- if (cPtrOut == NULL)
- cPtrOut = cPtr;
- cPtr += 6;
- }
- }
- else if (cPtrOut != NULL)
- {
- *(cPtrOut++) = *cPtr;
- }
- }
- if (cPtrOut != NULL)
- *(cPtrOut++) = '\0';
- }
- void COFF::InitCvTypes()
- {
- if (mMasterCompileUnit != NULL)
- {
- BF_ASSERT(mCompileUnits.size() == 1);
- return;
- }
- mDbgFlavor = DbgFlavor_MS;
- mCvSystemTypes.Resize(0x700);
- DbgType* dbgType;
- DbgType* ptrType;
- #ifdef BF_DBG_32
- const int ptrMask = 0x0400; // T_32*
- #else
- const int ptrMask = 0x0600; // T_64*
- #endif
- mMasterCompileUnit = new DbgCompileUnit(this);
- mMasterCompileUnit->mDbgModule = this;
- mMasterCompileUnit->mIsMaster = true;
- mCompileUnits.push_back(mMasterCompileUnit);
- CREATE_PRIMITIVE(T_NOTTRANS, DbgType_Void, "void", void*);
- mCvSystemTypes[T_NOTTRANS]->mSize = 0;
- mCvSystemTypes[T_NOTTRANS]->mAlign = 0;
- CREATE_PRIMITIVE(T_NOTYPE, DbgType_Void, "void", void*);
- mCvSystemTypes[T_NOTYPE]->mSize = 0;
- mCvSystemTypes[T_NOTYPE]->mAlign = 0;
- CREATE_PRIMITIVE(T_VOID, DbgType_Void, "void", void*);
- mCvSystemTypes[T_VOID]->mSize = 0;
- mCvSystemTypes[T_VOID]->mAlign = 0;
- mCvSystemTypes[T_PVOID] = ptrType;
- #ifdef BF_DBG_32
- BP_ALLOC_T(DbgType);
- ptrType = mAlloc.Alloc<DbgType>();
- ptrType->mCompileUnit = mMasterCompileUnit;
- ptrType->mTypeCode = DbgType_Ptr;
- ptrType->mSize = 8;
- ptrType->mAlign = 8;
- ptrType->mTypeParam = dbgType;
- dbgType->mPtrType = ptrType;
- mCvSystemTypes[(int)T_VOID | 0x0600] = ptrType;
- #endif
- #ifdef BF_DBG_32
- CREATE_PRIMITIVE(T_HRESULT, DbgType_u32, "HRESULT", addr_target);
- #else
- CREATE_PRIMITIVE(T_HRESULT, DbgType_u64, "HRESULT", addr_target);
- #endif
- CREATE_PRIMITIVE(T_CHAR, DbgType_SChar, "char", char);
- CREATE_PRIMITIVE(T_RCHAR, DbgType_SChar, "char", char); REGISTER_PRIMITIVE();
- CREATE_PRIMITIVE(T_UCHAR, DbgType_UChar, "char8", uint8); REGISTER_PRIMITIVE();
- CREATE_PRIMITIVE(T_WCHAR, DbgType_SChar16, "wchar", uint16); REGISTER_PRIMITIVE();
- CREATE_PRIMITIVE(T_CHAR16, DbgType_UChar16, "char16", uint16);
- CREATE_PRIMITIVE(T_CHAR32, DbgType_UChar32, "char32", uint32);
- CREATE_PRIMITIVE(T_INT1, DbgType_i8, "sbyte", int8);
- CREATE_PRIMITIVE(T_UINT1, DbgType_u8, "byte", uint8);
- CREATE_PRIMITIVE(T_SHORT, DbgType_i16, "short", int16);
- CREATE_PRIMITIVE(T_INT2, DbgType_i16, "short", int16);
- CREATE_PRIMITIVE(T_USHORT, DbgType_u16, "ushort", uint16);
- CREATE_PRIMITIVE(T_UINT2, DbgType_u16, "ushort", uint16);
- CREATE_PRIMITIVE(T_LONG, DbgType_i32, "int", int32);
- CREATE_PRIMITIVE(T_INT4, DbgType_i32, "int", int32);
- CREATE_PRIMITIVE(T_ULONG, DbgType_i32, "uint", uint32);
- CREATE_PRIMITIVE(T_UINT4, DbgType_u32, "uint", uint32);
- CREATE_PRIMITIVE(T_QUAD, DbgType_i64, "int64", int64);
- CREATE_PRIMITIVE(T_INT8, DbgType_i64, "int64", int64); REGISTER_PRIMITIVE();
- CREATE_PRIMITIVE(T_UQUAD, DbgType_u64, "uint64", uint64);
- CREATE_PRIMITIVE(T_UINT8, DbgType_u64, "uint64", uint64); REGISTER_PRIMITIVE();
- CREATE_PRIMITIVE(T_OCT, DbgType_i128, "int128", uint128);
- CREATE_PRIMITIVE(T_INT16, DbgType_i128, "int128", uint128);
- CREATE_PRIMITIVE(T_UOCT, DbgType_u128, "uint128", uint128);
- CREATE_PRIMITIVE(T_UINT16, DbgType_u128, "uint128", uint128);
- CREATE_PRIMITIVE(T_BOOL08, DbgType_Bool, "bool", bool);
- CREATE_PRIMITIVE(T_BOOL32, DbgType_Bool, "bool", int32);
- CREATE_PRIMITIVE(T_REAL32, DbgType_Single, "float", float);
- CREATE_PRIMITIVE(T_REAL64, DbgType_Double, "double", double);
- CREATE_PRIMITIVE(T_REAL80, DbgType_Double, "double80", double); // This isn't correct
- }
- addr_target COFF::GetSectionAddr(uint16 section, uint32 offset)
- {
- if (section == 0)
- return offset;
- if ((section & 0x8000) != 0)
- {
- auto linkedModule = GetLinkedModule();
- addr_target hiBase = linkedModule->mSecRelEncodingVec[section & 0x7FFF];
- return hiBase + offset;
- }
- int rva = mSectionHeaders[section - 1].mVirtualAddress;
- if (rva == 0)
- return ADDR_FLAG_ABS + offset;
- return (addr_target)mImageBase + rva + offset;
- }
- DbgType* COFF::CvGetType(int typeId)
- {
- //TODO: How do we handle types that have the high bit set?
- if (typeId < 0)
- return NULL;
- /*if (typeId == 0)
- return NULL;*/
- if (typeId < 0x1000)
- {
- TYPE_ENUM_e typeEnum = (TYPE_ENUM_e)typeId;
- DbgType* type = mCvSystemTypes[typeId];
- return type;
- }
- DbgType* type = mCvTypeMap[typeId - mCvMinTag];
- if (type == NULL)
- type = CvParseType(typeId);
- /*if ((!allowNull) || (type != NULL))
- {
- BF_ASSERT(type->mCompileUnit->mDbgModule == this);
- }*/
- return type;
- }
- DbgType* COFF::CvGetTypeSafe(int typeId)
- {
- DbgType* type = CvGetType(typeId);
- if (type != NULL)
- return type;
- return CvGetType(T_VOID);
- }
- DbgType* COFF::CvGetType(int typeId, CvCompileUnit* compileUnit)
- {
- if ((typeId & 0x80000000) != 0)
- {
- return CvGetType(MapImport(compileUnit, typeId));
- }
- return CvGetType(typeId);
- }
- int COFF::CvGetTagStart(int tagIdx, bool ipi)
- {
- if (tagIdx == 0)
- return NULL;
- if (ipi)
- return mCvIPITagStartMap[tagIdx - mCvMinTag];
- else
- return mCvTagStartMap[tagIdx - mCvMinTag];
- }
- int COFF::CvGetTagSize(int tagIdx, bool ipi)
- {
- if (tagIdx == 0)
- return 0;
- if (ipi)
- return mCvIPITagStartMap[tagIdx - mCvMinTag + 1] - mCvIPITagStartMap[tagIdx - mCvMinTag];
- else
- return mCvTagStartMap[tagIdx - mCvMinTag + 1] - mCvTagStartMap[tagIdx - mCvMinTag];
- }
- uint8* COFF::CvGetTagData(int tagIdx, bool ipi, int* outDataSize)
- {
- if (tagIdx == 0)
- return NULL;
- if ((ipi) && (tagIdx < mCvIPIMinTag))
- return NULL;
- if ((!ipi) && (tagIdx < mCvMinTag))
- return NULL;
- auto& reader = ipi ? mCvIPIReader : mCvTypeSectionReader;
- int offset = ipi ? mCvIPITagStartMap[tagIdx - mCvIPIMinTag] : mCvTagStartMap[tagIdx - mCvMinTag];
- uint8* data = reader.GetTempPtr(offset, 4);
- uint16 trLength = *(uint16*)data;
- data = reader.GetTempPtr(offset + 2, trLength, true);
- if (outDataSize != NULL)
- *outDataSize = trLength;
- return data;
- }
- int64 COFF::CvParseConstant(uint16 constVal, uint8*& data)
- {
- if (constVal < LF_NUMERIC) // 0x8000
- return constVal;
- switch (constVal)
- {
- case LF_CHAR:
- return GET(int8);
- case LF_SHORT:
- return GET(int16);
- case LF_USHORT:
- return GET(uint16);
- case LF_LONG:
- return GET(int32);
- case LF_ULONG:
- return GET(uint32);
- case LF_QUADWORD:
- return GET(int64);
- case LF_UQUADWORD:
- return (int64)GET(uint64);
- default:
- BF_FATAL("Not handled");
- }
- return 0;
- }
- int64 COFF::CvParseConstant(uint8*& data)
- {
- uint16 val = GET(uint16);
- return CvParseConstant(val, data);
- }
- const char* COFF::CvParseString(uint8*& data)
- {
- const char* strStart = (const char*)data;
- int strLen = strlen((const char*)data);
- if (strLen == 0)
- return NULL;
- data += strLen + 1;
- return strStart;
- }
- const char* COFF::CvParseAndDupString(uint8*& data)
- {
- int strLen = strlen((const char*)data);
- if (strLen == 0)
- {
- data++;
- return NULL;
- }
- BP_ALLOC("CvParseAndDupString", strLen + 1);
- char* dupStr = (char*)mAlloc.AllocBytes(strLen + 1, "CvParseAndDupString");
- memcpy(dupStr, data, strLen);
- data += strLen + 1;
- return dupStr;
- }
- const char* COFF::CvDupString(const char* str, int strLen)
- {
- BP_ALLOC("CvDupString", strLen + 1);
- char* dupStr = (char*)mAlloc.AllocBytes(strLen + 1, "CvParseAndDupString");
- memcpy(dupStr, str, strLen);
- dupStr[strLen] = 0;
- return dupStr;
- }
- void COFF::CvParseArgList(DbgSubprogram* subprogram, int tagIdx, bool ipi)
- {
- uint8* data = CvGetTagData(tagIdx, ipi);
- CvAutoReleaseTempData releaseTempData(this, data);
- int16 trLeafType = GET(int16);
- BF_ASSERT(trLeafType == LF_ARGLIST);
- int argCount = GET(int32);
- for (int argIdx = 0; argIdx < argCount; argIdx++)
- {
- CV_typ_t argTypeId = GET(CV_typ_t);
- DbgType* argType = CvGetType(argTypeId);
- BP_ALLOC_T(DbgVariable);
- DbgVariable* arg = mAlloc.Alloc<DbgVariable>();
- arg->mType = argType;
- arg->mIsParam = true;
- subprogram->mParams.PushBack(arg);
- }
- ReleaseTempBuf(data);
- }
- DbgSubprogram* COFF::CvParseMethod(DbgType* parentType, const char* methodName, int tagIdx, bool ipi, DbgSubprogram* subprogram)
- {
- BP_ZONE("COFF::CvParseMethod");
- uint8* data = CvGetTagData(tagIdx, ipi);
- if (data == NULL)
- return NULL;
- CvAutoReleaseTempData releaseTempData(this, data);
- bool fromTypeSection = methodName != NULL;
- uint8* dataStart = data;
- int16 trLeafType = GET(int16);
- if (trLeafType == LF_FUNC_ID)
- {
- lfFuncId* funcData = (lfFuncId*)dataStart;
- subprogram = CvParseMethod(NULL, (const char*)funcData->name, funcData->type, false, subprogram);
- return subprogram;
- }
- if (trLeafType == LF_MFUNC_ID)
- {
- lfMFuncId* funcData = (lfMFuncId*)dataStart;
- auto parentType = CvGetType(funcData->parentType);
- //subprogram = CvParseMethod(parentType, (const char*)funcData->name, funcData->type, false, subprogram);
- // We shouldn't pass parentType in there, because that would be the declType and not the actual primary type (ie: definition type)
- subprogram = CvParseMethod(NULL, (const char*)funcData->name, funcData->type, false, subprogram);
- return subprogram;
- }
- //DbgSubprogram* subprogram = mAlloc.Alloc<DbgSubprogram>();
- if (subprogram == NULL)
- {
- BP_ALLOC_T(DbgSubprogram);
- subprogram = mAlloc.Alloc<DbgSubprogram>();
- }
- subprogram->mName = methodName;
- int argListId = 0;
- if (trLeafType == LF_MFUNCTION)
- {
- static int gMFuncIdx = 0;
- gMFuncIdx++;
- lfMFunc* funcData = (lfMFunc*)dataStart;
- argListId = funcData->arglist;
- subprogram->mReturnType = CvGetType(funcData->rvtype);
- //TODO:
- if (parentType == NULL)
- subprogram->mParentType = CvGetType(funcData->classtype);
- DbgType* thisType = CvGetType(funcData->thistype);
- if ((thisType != NULL) && (!thisType->IsVoid()))
- {
- BP_ALLOC_T(DbgVariable);
- DbgVariable* arg = mAlloc.Alloc<DbgVariable>();
- arg->mType = thisType;
- arg->mIsParam = true;
- arg->mTagIdx = gMFuncIdx;
- subprogram->mParams.PushBack(arg);
- //TODO: Why did we have this "fromTypeSection" check? It caused non-static methods from S_GPROC32_ID to look like static methods in the autocomplete list
- //if (fromTypeSection)
- {
- arg->mType = thisType;
- subprogram->mHasThis = true;
- arg->mName = "this";
- }
- }
- }
- else if (trLeafType == LF_METHODLIST)
- {
- int32 flags = GET(int32);
- int methodIndex = GET(int32);
- return CvParseMethod(parentType, methodName, methodIndex, ipi, subprogram);
- }
- else if (trLeafType == LF_PROCEDURE)
- {
- lfProc* funcData = (lfProc*)dataStart;
- subprogram->mReturnType = CvGetType(funcData->rvtype);
- argListId = funcData->arglist;
- }
- else if (trLeafType == LF_MFUNC_ID)
- {
- //
- }
- else
- {
- SoftFail(StrFormat("Unhandled func type at tagId %d ipi %d", tagIdx, ipi));
- }
- if ((parentType != NULL) && (!IsObjectFile()))
- {
- subprogram->mCompileUnit = parentType->mCompileUnit;
- parentType->mMethodList.PushBack(subprogram);
- }
- mSubprograms.push_back(subprogram);
- CvParseArgList(subprogram, argListId, ipi);
- return subprogram;
- }
- void COFF::CvParseMethodList(DbgType* parentType, const char* methodName, int tagIdx, bool ipi)
- {
- int dataSize = 0;
- uint8* data = CvGetTagData(tagIdx, ipi, &dataSize);
- CvAutoReleaseTempData releaseTempData(this, data);
- uint8* dataEnd = data + dataSize;
- int16 trLeafType = GET(int16);
- BF_ASSERT(trLeafType == LF_METHODLIST);
- while (data < dataEnd)
- {
- int32 flags = GET(int32);
- int32 methodIndex = GET(int32);
- CvParseMethod(parentType, methodName, methodIndex, ipi);
- }
- }
- void COFF::CvParseMembers(DbgType* parentType, int tagIdx, bool ipi)
- {
- if (tagIdx == NULL)
- return;
- auto& reader = ipi ? mCvIPIReader : mCvTypeSectionReader;
- int offset = ipi ? mCvIPITagStartMap[tagIdx - mCvIPIMinTag] : mCvTagStartMap[tagIdx - mCvMinTag];
- uint8* data = reader.GetTempPtr(offset, 4);
- uint16 trLength = *(uint16*)data;
- offset += 2;
- data = reader.GetTempPtr(offset, trLength, true);
- CvAutoReleaseTempData releaseTempData(this, data);
- uint8* dataStart = data;
- uint8* dataEnd = data + trLength;
- int16 trLeafType = GET(int16);
- bool strMadeCopy;
- auto _ParseString = [&]()
- {
- strMadeCopy = false;
- int nameLen = strlen((const char*)data);
- int nameOfs = data - dataStart;
- const char* name = (const char*)reader.GetPermanentPtr(offset + nameOfs, nameLen + 1, &strMadeCopy);
- data += nameLen + 1;
- return name;
- };
- if (trLeafType == 0)
- return;
- switch (trLeafType)
- {
- case LF_FIELDLIST:
- {
- uint8* sectionStart = data;
- while (data < dataEnd)
- {
- uint8* leafDataStart = data;
- int leafType = (int)GET(uint16);
- switch (leafType)
- {
- case LF_VFUNCTAB:
- {
- lfVFuncTab& vfuncTab = *(lfVFuncTab*)leafDataStart;
- DbgType* vtableType = CvGetType(vfuncTab.type);
- BP_ALLOC_T(DbgVariable);
- DbgVariable* vtableMember = mAlloc.Alloc<DbgVariable>();
- vtableMember->mType = vtableType;
- parentType->mMemberList.PushFront(vtableMember);
- data = (uint8*)(&vfuncTab + 1);
- }
- break;
- case LF_BCLASS:
- {
- lfBClass& baseClassInfo = *(lfBClass*)leafDataStart;
- BP_ALLOC_T(DbgBaseTypeEntry);
- DbgBaseTypeEntry* baseTypeEntry = mAlloc.Alloc<DbgBaseTypeEntry>();
- data = (uint8*)&baseClassInfo.offset;
- baseTypeEntry->mThisOffset = (int)CvParseConstant(data);
- if (baseClassInfo.index != 0)
- {
- baseTypeEntry->mBaseType = CvGetType(baseClassInfo.index);
- // if (parentType->mLanguage == DbgLanguage_Beef)
- // {
- // if (!parentType->mBaseTypes.IsEmpty())
- // parentType->mTypeParam = baseTypeEntry->mBaseType;
- // }
- parentType->mBaseTypes.PushBack(baseTypeEntry);
- parentType->mAlign = std::max(parentType->mAlign, baseTypeEntry->mBaseType->GetAlign());
- if (!parentType->mSizeCalculated)
- {
- if ((baseTypeEntry->mBaseType->GetByteCount() == 0) && (baseTypeEntry->mBaseType->IsBfObject()))
- {
- parentType->mExtType = DbgExtType_Interface;
- }
- parentType->mSize = BF_MAX(parentType->mSize, baseTypeEntry->mBaseType->GetByteCount());
- }
- }
- }
- break;
- case LF_VBCLASS:
- case LF_IVBCLASS:
- {
- lfVBClass& baseClassInfo = *(lfVBClass*)leafDataStart;
- BP_ALLOC_T(DbgBaseTypeEntry);
- DbgBaseTypeEntry* baseTypeEntry = mAlloc.Alloc<DbgBaseTypeEntry>();
- baseTypeEntry->mBaseType = CvGetType(baseClassInfo.index);
- data = (uint8*)&baseClassInfo.vbpoff;
- baseTypeEntry->mThisOffset = (int)CvParseConstant(data);
- baseTypeEntry->mVTableOffset = (int)CvParseConstant(data);
- parentType->mBaseTypes.PushBack(baseTypeEntry);
- }
- break;
- case LF_ENUMERATE:
- {
- CV_fldattr_t fieldAttr = GET(CV_fldattr_t);
- int64 fieldVal = CvParseConstant(data);
- const char* fieldName = _ParseString();
- BP_ALLOC_T(DbgVariable);
- DbgVariable* member = mAlloc.Alloc<DbgVariable>();
- member->mCompileUnit = parentType->mCompileUnit;
- member->mConstValue = fieldVal;
- member->mName = fieldName;
- member->mIsStatic = true;
- member->mIsConst = true;
- member->mType = parentType->mTypeParam;
- FixConstant(member);
- parentType->mMemberList.PushBack(member);
- }
- break;
- case LF_NESTTYPE:
- {
- // Resolve nested types at end through 'primary type'
- // Nested types also include nested TypeDefs, so the embedded type index may even be a primitive type here
- // Why did we have this check to avoid unnamed nested types?
- // it seems we added this and removed it a couple times.
- // Disallowing NULL nested types here breaks the "_BUF_SIZE" in String, which is
- // an anonymous enum
- /*int16 pad = GET(int16);
- int32 nestedTypeId = GET(int32);
- const char* typeName = CvParseAndDupString(data);
- if ((typeName != NULL) && (typeName[0] != '<'))
- {
- DbgType* nestedType = CvCreateType();
- nestedType->mTypeParam = CvGetType(nestedTypeId);
- nestedType->mTypeCode = DbgType_TypeDef;
- nestedType->mName = typeName;
- nestedType->mTypeName = typeName;
- nestedType->mParent = parentType;
- parentType->mSubTypeList.PushBack(nestedType);
- }*/
- int16 pad = GET(int16);
- int32 nestedTypeId = GET(int32);
- const char* typeName = _ParseString();
- DbgType* nestedType = CvCreateType();
- nestedType->mTypeParam = CvGetType(nestedTypeId);
- nestedType->mTypeCode = DbgType_TypeDef;
- if ((typeName != NULL) && (typeName[0] != '<'))
- {
- nestedType->mName = typeName;
- nestedType->mTypeName = typeName;
- }
- nestedType->mParent = parentType;
- parentType->mSubTypeList.PushBack(nestedType);
- }
- break;
- case LF_ONEMETHOD:
- {
- CV_fldattr_t attr = GET(CV_fldattr_t);
- CV_typ_t methodTypeId = GET(CV_typ_t);
- int virtOffset = -1;
- if ((attr.mprop == CV_MTintro) || (attr.mprop == CV_MTpureintro))
- virtOffset = GET(int32);
- const char* methodName = _ParseString();
- DbgSubprogram* subProgram = CvParseMethod(parentType, methodName, methodTypeId, ipi);
- subProgram->mVirtual = (attr.mprop == CV_MTintro) || (attr.mprop == CV_MTpureintro) || (attr.mprop == CV_MTvirtual);
- subProgram->mVTableLoc = virtOffset;
- }
- break;
- case LF_METHOD:
- {
- int count = (int)GET(uint16);
- int32 methodList = GET(int32);
- const char* methodName = _ParseString();
- uint8* listData = CvGetTagData(methodList, ipi);
- CvAutoReleaseTempData releaseTempData(this, listData);
- int16 trLeafType = GET_FROM(listData, int16);
- if (trLeafType != LF_METHODLIST)
- {
- SoftFail("Invalid LF_METHOD member");
- return;
- }
- BF_ASSERT(trLeafType == LF_METHODLIST);
- for (int methodIdx = 0; methodIdx < count; methodIdx++)
- {
- CV_fldattr_t attr = GET_FROM(listData, CV_fldattr_t);
- int16 unused = GET_FROM(listData, int16);
- CV_typ_t methodTypeId = GET_FROM(listData, CV_typ_t);
- int virtOffset = -1;
- if ((attr.mprop == CV_MTintro) || (attr.mprop == CV_MTpureintro))
- virtOffset = GET_FROM(listData, int32);
- DbgSubprogram* subProgram = CvParseMethod(parentType, methodName, methodTypeId, ipi);
- subProgram->mVirtual = (attr.mprop == CV_MTintro) || (attr.mprop == CV_MTpureintro) || (attr.mprop == CV_MTvirtual);
- subProgram->mVTableLoc = virtOffset;
- }
- }
- break;
- case LF_MEMBER:
- case LF_STMEMBER:
- {
- bool isStatic = leafType == LF_STMEMBER;
- bool isConst = false;
- CV_fldattr_t attr = GET(CV_fldattr_t);
- CV_typ_t fieldTypeId = GET(CV_typ_t);
- if (parentType->mTagIdx == 29184)
- {
- NOP;
- }
- int memberOffset = -1;
- if (isStatic)
- {
- //?
- }
- else
- {
- memberOffset = (int)CvParseConstant(data);
- }
- char* fieldName = (char*)_ParseString();
- if ((fieldName != NULL) && (parentType->mLanguage == DbgLanguage_Beef))
- {
- if (strcmp(fieldName, "$prim") == 0)
- {
- parentType->mTypeParam = CvGetType(fieldTypeId);
- parentType->mTypeParam = GetPrimitiveType(parentType->mTypeParam->mTypeCode, DbgLanguage_Beef);
- parentType->mSize = parentType->mTypeParam->mSize;
- parentType->mAlign = parentType->mTypeParam->mAlign;
- if ((parentType->mBaseTypes.mHead != NULL) && (strcmp(parentType->mBaseTypes.mHead->mBaseType->mName, "System.Enum") == 0))
- parentType->mTypeCode = DbgType_Enum;
- break;
- }
- if (strncmp(fieldName, "$using$", 7) == 0)
- {
- fieldName = NULL;
- }
- }
- int64 constVal = 0;
- if ((fieldName != NULL) && (parentType->mLanguage == DbgLanguage_Beef) && (isStatic))
- {
- for (char* cPtr = fieldName; true; cPtr++)
- {
- char c = *cPtr;
- if (c == 0)
- break;
- if (c == '$')
- {
- if (!strMadeCopy)
- {
- int ofs = cPtr - fieldName;
- fieldName = DbgDupString(fieldName, "CvParseMembers.LF_MEMBER");
- cPtr = fieldName + ofs;
- }
- isConst = true;
- if (cPtr[1] == '_')
- {
- cPtr[1] = '-';
- constVal = atoll(cPtr + 1);
- }
- else
- constVal = atoll(cPtr + 1);
- *cPtr = 0;
- break;
- }
- }
- }
- if ((isStatic) && (!isConst) && (IsObjectFile()))
- {
- // Already has statics filled in
- break;
- }
- BP_ALLOC_T(DbgVariable);
- DbgVariable* member = mAlloc.Alloc<DbgVariable>();
- member->mIsStatic = isStatic;
- DbgType* fieldType = CvGetType(fieldTypeId);
- // if (fieldType == NULL)
- // {
- // uint8* fieldTypeData = CvGetTagData(fieldTypeId, ipi);
- // CvAutoReleaseTempData releaseTempData(this, fieldTypeData);
- //
- // // It's a section data ptr
- // int16 memberLeafType = *((int16*)fieldTypeData);
- // switch (memberLeafType)
- // {
- // case LF_BITFIELD:
- // {
- // lfBitfield& bitfield = *(lfBitfield*)fieldTypeData;
- // fieldType = CvGetType(bitfield.type);
- //
- // // Bit offset is expressed in MSB form
- // member->mBitOffset = (fieldType->mSize * 8) - bitfield.position - bitfield.length;
- // member->mBitSize = bitfield.length;
- // }
- // break;
- // default:
- // BF_FATAL("Unhandled");
- // }
- // }
- if (fieldType == NULL)
- fieldType = CvGetType(fieldTypeId);
- if ((fieldType->mTypeCode == DbgType_Enum) && (fieldType->GetByteCount() == 0))
- fieldType = fieldType->GetPrimaryType();
- // if (fieldType->mTypeCode == DbgType_Bitfield)
- // {
- // auto bitfieldType = (DbgBitfieldType*)fieldType;
- // member->mBitOffset = bitfieldType->mPosition;
- // member->mBitSize = bitfieldType->mLength;
- // fieldType = fieldType->mTypeParam;
- // }
- if (isConst)
- {
- member->mConstValue = constVal;
- member->mIsConst = true;
- }
- else if (isStatic)
- {
- // NOP
- }
- else
- member->mMemberOffset = memberOffset;
- member->mType = fieldType;
- member->mCompileUnit = parentType->mCompileUnit;
- member->mName = fieldName;
- // Size should already be set, right? It gets set on 'dataSize' in the LF_STRUCT/LF_CLASS
- //parentType->mSize = std::max(memberOffset + fieldType->mSize, parentType->mSize);
- if ((!isStatic) && (member->mMemberOffset >= 0))
- {
- if (!parentType->mIsPacked)
- parentType->mAlign = std::max(parentType->mAlign, fieldType->GetAlign());
- if (!parentType->mSizeCalculated)
- {
- parentType->mSize = std::max(memberOffset + fieldType->GetByteCount(), parentType->mSize);
- }
- }
- //if (parentType->mAlign > 1)
- //parentType->mSize = (parentType->mSize + (parentType->mAlign - 1)) & ~(parentType->mAlign - 1);
- //parentType->mSizeCalculated = true;
- parentType->mMemberList.PushBack(member);
- if (isStatic)
- parentType->mNeedsGlobalsPopulated = true;
- }
- break;
- case LF_INDEX:
- {
- int _pad = (int)GET(uint16);
- int32 indexType = GET(int32);
- CvParseMembers(parentType, indexType, ipi);
- }
- break;
- default:
- SoftFail(StrFormat("Unhandled leaf id 0x%X", leafType));
- return;
- }
- PTR_ALIGN(data, sectionStart, 4);
- }
- }
- break;
- }
- }
- int COFF::CvConvRegNum(int regNum, int* outBits)
- {
- if ((regNum >= CV_AMD64_R8B) && (regNum <= CV_AMD64_R15B))
- {
- if (outBits != NULL)
- *outBits = 8;
- regNum -= CV_AMD64_R8B - CV_AMD64_R8;
- }
- else if ((regNum >= CV_AMD64_R8W) && (regNum <= CV_AMD64_R15W))
- {
- if (outBits != NULL)
- *outBits = 16;
- regNum -= CV_AMD64_R8W - CV_AMD64_R8;
- }
- else if ((regNum >= CV_AMD64_R8D) && (regNum <= CV_AMD64_R15D))
- {
- if (outBits != NULL)
- *outBits = 32;
- regNum -= CV_AMD64_R8D - CV_AMD64_R8;
- }
- switch (regNum)
- {
- #ifdef BF_DBG_64
- case CV_AMD64_RAX: return X64Reg_RAX;
- case CV_AMD64_RDX: return X64Reg_RDX;
- case CV_AMD64_RCX: return X64Reg_RCX;
- case CV_AMD64_RBX: return X64Reg_RBX;
- case CV_AMD64_RSI: return X64Reg_RSI;
- case CV_AMD64_RDI: return X64Reg_RDI;
- case CV_AMD64_RBP: return X64Reg_RBP;
- case CV_AMD64_RSP: return X64Reg_RSP;
- case CV_AMD64_R8: return X64Reg_R8;
- case CV_AMD64_R9: return X64Reg_R9;
- case CV_AMD64_R10: return X64Reg_R10;
- case CV_AMD64_R11: return X64Reg_R11;
- case CV_AMD64_R12: return X64Reg_R12;
- case CV_AMD64_R13: return X64Reg_R13;
- case CV_AMD64_R14: return X64Reg_R14;
- case CV_AMD64_R15: return X64Reg_R15;
- case CV_AMD64_RIP: return X64Reg_RIP;
- case CV_REG_AL: if (outBits != NULL) *outBits = 8; return X64Reg_RAX;
- case CV_REG_AX: if (outBits != NULL) *outBits = 16; return X64Reg_RAX;
- case CV_REG_EAX: if (outBits != NULL) *outBits = 32; return X64Reg_RAX;
- case CV_REG_CL: if (outBits != NULL) *outBits = 8; return X64Reg_RCX;
- case CV_REG_CX: if (outBits != NULL) *outBits = 16; return X64Reg_RCX;
- case CV_REG_ECX: if (outBits != NULL) *outBits = 32; return X64Reg_RCX;
- case CV_REG_DL: if (outBits != NULL) *outBits = 8; return X64Reg_RDX;
- case CV_REG_DX: if (outBits != NULL) *outBits = 16; return X64Reg_RDX;
- case CV_REG_EDX: if (outBits != NULL) *outBits = 32; return X64Reg_RDX;
- case CV_REG_BL: if (outBits != NULL) *outBits = 8; return X64Reg_RBX;
- case CV_REG_BX: if (outBits != NULL) *outBits = 16; return X64Reg_RBX;
- case CV_REG_EBX: if (outBits != NULL) *outBits = 32; return X64Reg_RBX;
- case CV_REG_ESP: if (outBits != NULL) *outBits = 32; return X64Reg_RSP;
- case CV_REG_EBP: if (outBits != NULL) *outBits = 32; return X64Reg_RBP;
- case CV_AMD64_SIL: if (outBits != NULL) *outBits = 8; return X64Reg_RSI;
- case CV_REG_SI: if (outBits != NULL) *outBits = 16; return X64Reg_RSI;
- case CV_REG_ESI: if (outBits != NULL) *outBits = 32; return X64Reg_RSI;
- case CV_AMD64_DIL: if (outBits != NULL) *outBits = 8; return X64Reg_RDI;
- case CV_REG_DI: if (outBits != NULL) *outBits = 16; return X64Reg_RDI;
- case CV_REG_EDI: if (outBits != NULL) *outBits = 32; return X64Reg_RDI;
- case CV_AMD64_R8B: *outBits = 8; return X64Reg_R8;
- case CV_AMD64_R8W: *outBits = 16; return X64Reg_R8;
- case CV_AMD64_R8D: *outBits = 32; return X64Reg_R8;
- case CV_AMD64_R9B: *outBits = 8; return X64Reg_R9;
- case CV_AMD64_R9W: *outBits = 16; return X64Reg_R9;
- case CV_AMD64_R9D: *outBits = 32; return X64Reg_R9;
- case CV_AMD64_R10B: *outBits = 8; return X64Reg_R10;
- case CV_AMD64_R10W: *outBits = 16; return X64Reg_R10;
- case CV_AMD64_R10D: *outBits = 32; return X64Reg_R10;
- case CV_AMD64_R11B: *outBits = 8; return X64Reg_R11;
- case CV_AMD64_R11W: *outBits = 16; return X64Reg_R11;
- case CV_AMD64_R11D: *outBits = 32; return X64Reg_R11;
- case CV_AMD64_R12B: *outBits = 8; return X64Reg_R12;
- case CV_AMD64_R12W: *outBits = 16; return X64Reg_R12;
- case CV_AMD64_R12D: *outBits = 32; return X64Reg_R12;
- case CV_AMD64_R13B: *outBits = 8; return X64Reg_R13;
- case CV_AMD64_R13W: *outBits = 16; return X64Reg_R13;
- case CV_AMD64_R13D: *outBits = 32; return X64Reg_R13;
- case CV_AMD64_R14B: *outBits = 8; return X64Reg_R14;
- case CV_AMD64_R14W: *outBits = 16; return X64Reg_R14;
- case CV_AMD64_R14D: *outBits = 32; return X64Reg_R14;
- case CV_AMD64_R15B: *outBits = 8; return X64Reg_R15;
- case CV_AMD64_R15W: *outBits = 16; return X64Reg_R15;
- case CV_AMD64_R15D: *outBits = 32; return X64Reg_R15;
- case CV_AMD64_XMM0_0: return X64Reg_XMM00;
- case CV_AMD64_XMM0_1: return X64Reg_XMM01;
- case CV_AMD64_XMM0_2: return X64Reg_XMM02;
- case CV_AMD64_XMM0_3: return X64Reg_XMM03;
- case CV_AMD64_XMM1_0: return X64Reg_XMM10;
- case CV_AMD64_XMM1_1: return X64Reg_XMM11;
- case CV_AMD64_XMM1_2: return X64Reg_XMM12;
- case CV_AMD64_XMM1_3: return X64Reg_XMM13;
- case CV_AMD64_XMM2_0: return X64Reg_XMM20;
- case CV_AMD64_XMM2_1: return X64Reg_XMM21;
- case CV_AMD64_XMM2_2: return X64Reg_XMM22;
- case CV_AMD64_XMM2_3: return X64Reg_XMM23;
- case CV_AMD64_XMM3_0: return X64Reg_XMM30;
- case CV_AMD64_XMM3_1: return X64Reg_XMM31;
- case CV_AMD64_XMM3_2: return X64Reg_XMM32;
- case CV_AMD64_XMM3_3: return X64Reg_XMM33;
- case CV_AMD64_XMM4_0: return X64Reg_XMM40;
- case CV_AMD64_XMM4_1: return X64Reg_XMM41;
- case CV_AMD64_XMM4_2: return X64Reg_XMM42;
- case CV_AMD64_XMM4_3: return X64Reg_XMM43;
- case CV_AMD64_XMM5_0: return X64Reg_XMM50;
- case CV_AMD64_XMM5_1: return X64Reg_XMM51;
- case CV_AMD64_XMM5_2: return X64Reg_XMM52;
- case CV_AMD64_XMM5_3: return X64Reg_XMM53;
- case CV_AMD64_XMM6_0: return X64Reg_XMM60;
- case CV_AMD64_XMM6_1: return X64Reg_XMM61;
- case CV_AMD64_XMM6_2: return X64Reg_XMM62;
- case CV_AMD64_XMM6_3: return X64Reg_XMM63;
- case CV_AMD64_XMM7_0: return X64Reg_XMM70;
- case CV_AMD64_XMM7_1: return X64Reg_XMM71;
- case CV_AMD64_XMM7_2: return X64Reg_XMM72;
- case CV_AMD64_XMM7_3: return X64Reg_XMM73;
- case CV_AMD64_XMM8_0: return X64Reg_XMM80;
- case CV_AMD64_XMM8_1: return X64Reg_XMM81;
- case CV_AMD64_XMM8_2: return X64Reg_XMM82;
- case CV_AMD64_XMM8_3: return X64Reg_XMM83;
- case CV_AMD64_XMM9_0: return X64Reg_XMM90;
- case CV_AMD64_XMM9_1: return X64Reg_XMM91;
- case CV_AMD64_XMM9_2: return X64Reg_XMM92;
- case CV_AMD64_XMM9_3: return X64Reg_XMM93;
- case CV_AMD64_XMM10_0: return X64Reg_XMM10_0;
- case CV_AMD64_XMM10_1: return X64Reg_XMM10_1;
- case CV_AMD64_XMM10_2: return X64Reg_XMM10_2;
- case CV_AMD64_XMM10_3: return X64Reg_XMM10_3;
- case CV_AMD64_XMM11_0: return X64Reg_XMM11_0;
- case CV_AMD64_XMM11_1: return X64Reg_XMM11_1;
- case CV_AMD64_XMM11_2: return X64Reg_XMM11_2;
- case CV_AMD64_XMM11_3: return X64Reg_XMM11_3;
- case CV_AMD64_XMM12_0: return X64Reg_XMM12_0;
- case CV_AMD64_XMM12_1: return X64Reg_XMM12_1;
- case CV_AMD64_XMM12_2: return X64Reg_XMM12_2;
- case CV_AMD64_XMM12_3: return X64Reg_XMM12_3;
- case CV_AMD64_XMM13_0: return X64Reg_XMM13_0;
- case CV_AMD64_XMM13_1: return X64Reg_XMM13_1;
- case CV_AMD64_XMM13_2: return X64Reg_XMM13_2;
- case CV_AMD64_XMM13_3: return X64Reg_XMM13_3;
- case CV_AMD64_XMM14_0: return X64Reg_XMM14_0;
- case CV_AMD64_XMM14_1: return X64Reg_XMM14_1;
- case CV_AMD64_XMM14_2: return X64Reg_XMM14_2;
- case CV_AMD64_XMM14_3: return X64Reg_XMM14_3;
- case CV_AMD64_XMM15_0: return X64Reg_XMM15_0;
- case CV_AMD64_XMM15_1: return X64Reg_XMM15_1;
- case CV_AMD64_XMM15_2: return X64Reg_XMM15_2;
- case CV_AMD64_XMM15_3: return X64Reg_XMM15_3;
- #else
- case CV_REG_AL: return X86Reg_EAX;
- case CV_REG_CL: return X86Reg_ECX;
- case CV_REG_DL: return X86Reg_EDX;
- case CV_REG_BL: return X86Reg_EBX;
- case CV_REG_AH: return X86Reg_EAX;
- case CV_REG_AX: return X86Reg_EAX;
- case CV_REG_CX: return X86Reg_ECX;
- case CV_REG_DX: return X86Reg_EDX;
- case CV_REG_BX: return X86Reg_EBX;
- case CV_REG_SP: return X86Reg_ESP;
- case CV_REG_BP: return X86Reg_EBP;
- case CV_REG_SI: return X86Reg_ESI;
- case CV_REG_DI: return X86Reg_EDI;
- case CV_REG_EAX: return X86Reg_EAX;
- case CV_REG_ECX: return X86Reg_ECX;
- case CV_REG_EDX: return X86Reg_EDX;
- case CV_REG_EBX: return X86Reg_EBX;
- case CV_REG_ESP: return X86Reg_ESP;
- case CV_REG_EBP: return X86Reg_EBP;
- case CV_REG_ESI: return X86Reg_ESI;
- case CV_REG_EDI: return X86Reg_EDI;
- case CV_REG_IP: return X86Reg_EIP;
- // case CV_REG_XMM0: return X86Reg_XMM00;
- // case CV_REG_XMM1: return X86Reg_XMM01;
- // case CV_REG_XMM2: return X86Reg_XMM02;
- // case CV_REG_XMM3: return X86Reg_XMM03;
- // case CV_REG_XMM4: return X86Reg_XMM04;
- // case CV_REG_XMM5: return X86Reg_XMM05;
- // case CV_REG_XMM6: return X86Reg_XMM06;
- // case CV_REG_XMM7: return X86Reg_XMM07;
- #endif
- }
- return 0; // Nope
- BF_FATAL("Invalid register");
- return 0;
- }
- DbgType* COFF::CvCreateType()
- {
- DbgModule* linkedModule = GetLinkedModule();
- BP_ALLOC_T(DbgType);
- DbgType* dbgType = mAlloc.Alloc<DbgType>();
- dbgType->mCompileUnit = mMasterCompileUnit;
- dbgType->mTypeIdx = (int)linkedModule->mTypes.size();
- linkedModule->mTypes.push_back(dbgType);
- return dbgType;
- }
- DbgType* COFF::CvParseType(int tagIdx, bool ipi)
- {
- auto& reader = ipi ? mCvIPIReader : mCvTypeSectionReader;
- int offset = ipi ? mCvIPITagStartMap[tagIdx - mCvIPIMinTag] : mCvTagStartMap[tagIdx - mCvMinTag];
- uint8* data = reader.GetTempPtr(offset, 4);
- uint16 trLength = *(uint16*)data;
- offset += 2;
- data = reader.GetTempPtr(offset, trLength, true);
- CvAutoReleaseTempData releaseTempData(this, data);
- uint8* dataStart = data;
- uint8* dataEnd = data + trLength;
- int16 trLeafType = GET(int16);
- bool strMadeCopy;
- auto _ParseString = [&]()
- {
- strMadeCopy = false;
- int nameLen = strlen((const char*)data);
- int nameOfs = data - dataStart;
- const char* name = (const char*)reader.GetPermanentPtr(offset + nameOfs, nameLen + 1, &strMadeCopy);
- data += nameLen + 1;
- return name;
- };
- DbgType* dbgType = NULL;
- switch (trLeafType)
- {
- case LF_ENUM:
- {
- int elemCount = (int)GET(uint16);
- int prop = (int)GET(uint16);
- int underlyingType = GET(int32);
- int typeIndex = GET(int32);
- const char* name = _ParseString();
- dbgType = CvCreateType();
- dbgType->mCompileUnit = mMasterCompileUnit;
- dbgType->mName = name;
- dbgType->mTypeName = name;
- //SplitName(dbgType->mName, dbgType->mTypeName, dbgType->mTemplateParams);
- dbgType->mTypeCode = DbgType_Enum;
- dbgType->mTypeParam = CvGetTypeSafe(underlyingType);
- dbgType->mIsIncomplete = true;
- if (dbgType->mTypeParam->GetByteCount() == 0)
- dbgType->mIsDeclaration = true;
- dbgType->mSize = dbgType->mTypeParam->mSize;
- dbgType->mAlign = dbgType->mTypeParam->mAlign;
- /*if (dbgType->mTypeParam->GetByteCount() == 0)
- {
- // Appears to be a bug where byte-sized enums come out as void (sometimes?)
- dbgType->mTypeParam = mBfPrimitiveTypes[DbgType_u8];
- }*/
- //dbgType->mIsDeclaration = typeIndex == 0;
- //CvParseMembers(dbgType, typeIndex, sectionData);
- }
- break;
- case LF_VTSHAPE:
- {
- lfVTShape& vtShape = *(lfVTShape*)dataStart;
- dbgType = CvCreateType();
- dbgType->mTypeCode = DbgType_VTable;
- dbgType->mSize = vtShape.count * sizeof(addr_target);
- dbgType->mSizeCalculated = true;
- }
- break;
- case LF_BITFIELD:
- {
- //DbgType
- lfBitfield& bitfield = *(lfBitfield*)dataStart;
- //dbgType = CvCreateType();
- DbgBitfieldType* bitfieldType = mAlloc.Alloc<DbgBitfieldType>();
- dbgType = bitfieldType;
- dbgType->mTypeParam = CvGetTypeSafe(bitfield.type);
- dbgType->mTypeCode = DbgType_Bitfield;
- //bitfieldType->mPosition = (dbgType->mTypeParam->mSize * 8) - bitfield.position - bitfield.length;
- bitfieldType->mPosition = bitfield.position;
- bitfieldType->mLength = bitfield.length;
- bitfieldType->mSize = dbgType->mTypeParam->mSize;
- bitfieldType->mAlign = dbgType->mTypeParam->mAlign;
- dbgType->mSizeCalculated = true;
- dbgType->mPriority = DbgTypePriority_Unique;
- }
- break;
- case LF_CLASS:
- case LF_STRUCTURE:
- case LF_CLASS_EX:
- case LF_STRUCTURE_EX:
- {
- unsigned short count; // count of number of elements in class
- CV_prop_t property; // property attribute field (prop_t)
- CV_typ_t field; // type index of LF_FIELD descriptor list
- CV_typ_t derived; // type index of derived from list if not zero
- CV_typ_t vshape; // type index of vshape table for this class
- int dataSize;
- int16 extra = 0;
- if ((trLeafType == 0x1608) || (trLeafType == 0x1609))
- {
- property = GET(CV_prop_t);
- extra = GET(int16);
- field = GET(CV_typ_t);
- derived = GET(CV_typ_t);
- vshape = GET(CV_typ_t);
- count = GET(unsigned short);
- dataSize = (int)CvParseConstant(data);
- }
- else
- {
- count = GET(unsigned short);
- property = GET(CV_prop_t);
- field = GET(CV_typ_t);
- derived = GET(CV_typ_t);
- vshape = GET(CV_typ_t);
- dataSize = (int)CvParseConstant(data);
- }
- const char* name = _ParseString();
- // if (strstr(name, "TestStruct") != NULL)
- // {
- // NOP;
- // }
- // if ((strstr(name, "`") != NULL) || (strstr(name, "::__l") != NULL))
- // {
- // OutputDebugStrF("Local type: %s\n", name);
- // }
- // Remove "enum " from type names
- bool isPartialDef = false;
- for (int i = 0; true; i++)
- {
- char c = name[i];
- if (c == 0)
- break;
- if (c == '$')
- {
- if ((i >= 5) && (strncmp(&name[i - 5], "$part$", 6) == 0))
- {
- if (!strMadeCopy)
- name = DbgDupString(name, "CvParseType.LF_CLASS");
- strcpy((char*)&name[i - 5], &name[i + 1]);
- if (name[i - 5] == '\0')
- {
- isPartialDef = true;
- break;
- }
- }
- }
- if ((c == ' ') && (i >= 5))
- {
- if ((name[i - 4] == 'e') &&
- (name[i - 3] == 'n') &&
- (name[i - 2] == 'u') &&
- (name[i - 1] == 'm'))
- {
- char prevC = name[i - 5];
- if ((!isalnum(prevC)) && (prevC != '_'))
- {
- if (!strMadeCopy)
- name = DbgDupString(name, "CvParseType.LF_CLASS");
- memmove((char*)name + i - 4, name + i + 1, strlen(name + i + 1) + 1);
- i -= 5;
- continue;
- }
- }
- }
- }
- dbgType = CvCreateType();
- dbgType->mCompileUnit = mMasterCompileUnit;
- dbgType->mIsDeclaration = property.fwdref;
- if (isPartialDef)
- dbgType->mIsDeclaration = true;
- dbgType->mName = name;
- dbgType->mTypeName = name;
- //SplitName(dbgType->mName, dbgType->mTypeName, dbgType->mTemplateParams);
- if ((trLeafType == LF_CLASS) || (trLeafType == LF_CLASS_EX))
- dbgType->mTypeCode = DbgType_Class;
- else
- dbgType->mTypeCode = DbgType_Struct;
- DbgType* baseType = NULL;
- if (derived != 0)
- {
- baseType = CvGetTypeSafe(derived);
- BP_ALLOC_T(DbgBaseTypeEntry);
- DbgBaseTypeEntry* baseTypeEntry = mAlloc.Alloc<DbgBaseTypeEntry>();
- baseTypeEntry->mBaseType = baseType;
- dbgType->mBaseTypes.PushBack(baseTypeEntry);
- }
- if (property.packed)
- {
- dbgType->mAlign = 1;
- dbgType->mIsPacked = true;
- }
- if (!dbgType->mIsDeclaration)
- {
- dbgType->mSizeCalculated = true;
- dbgType->mSize = dataSize;
- if (strncmp(name, "_bf:", 4) == 0)
- {
- // Beef types have different strides from size. Note we MUST set size to zero here, because there are
- // some BF_MAX calculations we perform on it
- dbgType->mSizeCalculated = false;
- dbgType->mSize = 0;
- }
- }
- if (vshape != 0)
- {
- CvGetTypeSafe(vshape);
- dbgType->mHasVTable = true;
- }
- dbgType->mIsIncomplete = true;
- // if (classInfo.field != 0)
- // dbgType->mDefinedMembersSize = CvGetTagSize(classInfo.field, ipi);
- //CvParseMembers(dbgType, classInfo.field, sectionData);
- }
- break;
- case LF_UNION:
- {
- lfUnion& classInfo = *(lfUnion*)dataStart;
- data = (uint8*)&classInfo.data;
- int dataSize = (int)CvParseConstant(data);
- const char* name = _ParseString();
- dbgType = CvCreateType();
- dbgType->mCompileUnit = mMasterCompileUnit;
- dbgType->mIsDeclaration = classInfo.property.fwdref;
- dbgType->mName = name;
- dbgType->mTypeName = name;
- //SplitName(dbgType->mName, dbgType->mTypeName, dbgType->mTemplateParams);
- dbgType->mTypeCode = DbgType_Union;
- dbgType->mSize = dataSize;
- dbgType->mAlign = 1;
- dbgType->mSizeCalculated = !dbgType->mIsDeclaration;
- dbgType->mIsIncomplete = true;
- //CvParseMembers(dbgType, classInfo.field, sectionData);
- }
- break;
- case LF_MODIFIER:
- {
- lfModifier& modifier = *(lfModifier*)dataStart;
- DbgType* outerType = CvGetTypeSafe(modifier.type);
- dbgType = outerType;
- if (modifier.attr.MOD_const)
- {
- DbgType* innerType = dbgType;
- dbgType = CvCreateType();
- dbgType->mTypeParam = innerType;
- dbgType->mTypeCode = DbgType_Const;
- dbgType->mLanguage = innerType->mLanguage;
- }
- if (modifier.attr.MOD_volatile)
- {
- DbgType* innerType = dbgType;
- dbgType = CvCreateType();
- dbgType->mTypeParam = innerType;
- dbgType->mTypeCode = DbgType_Volatile;
- dbgType->mLanguage = innerType->mLanguage;
- }
- if (modifier.attr.MOD_unaligned)
- {
- DbgType* innerType = dbgType;
- dbgType = CvCreateType();
- dbgType->mTypeParam = innerType;
- dbgType->mTypeCode = DbgType_Unaligned;
- dbgType->mLanguage = innerType->mLanguage;
- }
- }
- break;
- case LF_POINTER:
- {
- lfPointer* pointerInfo = (lfPointer*)dataStart;
- dbgType = CvCreateType();
- dbgType->mTypeParam = CvGetTypeSafe(pointerInfo->utype);
- if (pointerInfo->attr.ptrmode == CV_PTR_MODE_RVREF)
- dbgType->mTypeCode = DbgType_RValueReference;
- else if (pointerInfo->attr.ptrmode == CV_PTR_MODE_LVREF)
- dbgType->mTypeCode = DbgType_Ref;
- else
- {
- dbgType->mTypeCode = DbgType_Ptr;
- if ((dbgType->mTypeParam != NULL) && (dbgType->mTypeParam->mPtrType == NULL))
- dbgType->mTypeParam->mPtrType = dbgType;
- }
- //dbgType->mSize = pointerInfo->attr.size;
- dbgType->mSize = sizeof(addr_target);
- dbgType->mAlign = dbgType->mSize;
- dbgType->mSizeCalculated = true;
- dbgType->mLanguage = dbgType->mTypeParam->mLanguage;
- /*if (prop.isconst)
- {
- DbgType* innerType = dbgType;
- dbgType = CvCreateType();
- dbgType->mTypeParam = innerType;
- dbgType->mTypeCode = DbgType_Const;
- dbgType->mSize = innerType->mSize;
- }*/
- //TODO: Handle const, volatile, ref, restrict, etc
- }
- break;
- case LF_DIMARRAY:
- {
- }
- break;
- case LF_ARRAY:
- {
- lfArray* array = (lfArray*)dataStart;
- DbgType* indexType = CvGetTypeSafe(array->idxtype);
- dbgType = CvCreateType();
- dbgType->mTypeParam = CvGetTypeSafe(array->elemtype);
- dbgType->mTypeCode = DbgType_SizedArray;
- dbgType->mLanguage = dbgType->mTypeParam->mLanguage;
- data = (uint8*)&array->data;
- int size = (int)CvParseConstant(data);
- const char* name = _ParseString();
- dbgType->mName = name;
- dbgType->mSize = size;
- dbgType->mAlign = dbgType->mTypeParam->GetAlign();
- // Beef arrays do not necessarily have aligned sizes
- dbgType->mSizeCalculated = false;
- dbgType->mLanguage = dbgType->mTypeParam->mLanguage;
- }
- break;
- case LF_PROCEDURE:
- {
- dbgType = CvCreateType();
- //TODO: Calling convetion, etc
- lfProc* proc = (lfProc*)dataStart;
- dbgType->mTypeCode = DbgType_Subroutine;
- dbgType->mTypeParam = CvGetTypeSafe(proc->rvtype);
- BP_ALLOC_T(DbgBlock);
- dbgType->mBlockParam = mAlloc.Alloc<DbgBlock>();
- uint8* argData = CvGetTagData(proc->arglist, ipi);
- CvAutoReleaseTempData releaseTempData(this, argData);
- int16 argLeafType = GET_FROM(argData, int16);
- BF_ASSERT(argLeafType == LF_ARGLIST);
- int argCount = GET_FROM(argData, int32);
- CV_typ_t* argTypes = (CV_typ_t*)argData;
- for (int paramIdx = 0; paramIdx < proc->parmcount; paramIdx++)
- {
- BP_ALLOC_T(DbgVariable);
- DbgVariable* arg = mAlloc.Alloc<DbgVariable>();
- arg->mIsParam = true;
- arg->mType = CvGetTypeSafe(argTypes[paramIdx]);
- arg->mName = "$arg";
- dbgType->mBlockParam->mVariables.PushBack(arg);
- }
- }
- break;
- case LF_MFUNCTION:
- {
- dbgType = CvCreateType();
- //TODO: Calling convetion, etc
- lfMFunc* proc = (lfMFunc*)dataStart;
- dbgType->mTypeCode = DbgType_Subroutine;
- dbgType->mTypeParam = CvGetTypeSafe(proc->rvtype);
- BP_ALLOC_T(DbgBlock);
- dbgType->mBlockParam = mAlloc.Alloc<DbgBlock>();
- uint8* argData = CvGetTagData(proc->arglist, ipi);
- CvAutoReleaseTempData releaseTempData(this, argData);
- int16 argLeafType = GET_FROM(argData, int16);
- BF_ASSERT(argLeafType == LF_ARGLIST);
- int argCount = GET_FROM(argData, int32);
- CV_typ_t* argTypes = (CV_typ_t*)argData;
- for (int paramIdx = 0; paramIdx < proc->parmcount; paramIdx++)
- {
- BP_ALLOC_T(DbgVariable);
- DbgVariable* arg = mAlloc.Alloc<DbgVariable>();
- arg->mIsParam = true;
- arg->mType = CvGetTypeSafe(argTypes[paramIdx]);
- arg->mName = "$arg";
- dbgType->mBlockParam->mVariables.PushBack(arg);
- }
- }
- break;
- // case 0x1609:
- // NOP;
- // break;
- default:
- NOP;
- break;
- }
- if (dbgType != NULL)
- {
- if (tagIdx == 14709)
- {
- NOP;
- }
- dbgType->mTagIdx = tagIdx;
- int wantIdx = tagIdx - mCvMinTag;
- mCvTypeMap[wantIdx] = dbgType;
- }
- return dbgType;
- }
- void COFF::ParseTypeData(CvStreamReader& reader, int dataOffset)
- {
- BP_ZONE("COFF::ParseTypeData");
- //uint8* sectionEnd = sectionData + sectionSize;
- //uint8* data = sectionData;
- if (mCvMinTag == -1)
- mCvMinTag = 0x1000;
- int offset = dataOffset;
- bool isTagMapEmpty = mCvTagStartMap.empty();
- for (int tagIdx = mCvMinTag; true; tagIdx++)
- {
- if (tagIdx == mCvMaxTag)
- break;
- if (offset >= reader.mSize)
- break;
- //OutputDebugStrF("%X %X\n", tagIdx, (int)(data - sectionData));
- BF_ASSERT(((offset) & 3) == 0);
- //PTR_ALIGN(data, sectionData, 4);
- uint8* data = reader.GetTempPtr(offset, 4);
- uint16 trLength = *(uint16*)data;
- uint16 trLeafType = *(uint16*)(data + 2);
- // uint16 trLength = GET(uint16);
- // uint8* dataStart = data;
- // uint16 trLeafType = GET(uint16);
- // uint8* dataEnd = dataStart + trLength;
- if (isTagMapEmpty)
- {
- mCvTagStartMap.push_back(offset);
- mCvTypeMap.push_back(NULL);
- }
- else
- mCvTagStartMap[tagIdx - mCvMinTag] = offset;
- offset += trLength + 2;
- DbgType* dbgType = NULL;
- if (trLeafType == 0)
- continue;
- if ((trLeafType == LF_ENUM) || (trLeafType == LF_CLASS) || (trLeafType == LF_STRUCTURE) || (trLeafType == LF_UNION) ||
- (trLeafType == LF_CLASS_EX) || (trLeafType == LF_STRUCTURE_EX))
- {
- CvParseType(tagIdx);
- }
- }
- if (isTagMapEmpty)
- mCvTagStartMap.Add(offset);
- }
- void COFF::ParseTypeData(int sectionNum, CvStreamReader& reader, int& sectionSize, int& dataOfs, int& hashStream, int& hashAdjOffset, int& hashAdjSize, int& minVal, int& maxVal)
- {
- BP_ZONE("COFF::ParseTypeData");
- sectionSize = 0;
- // sectionData = CvReadStream(sectionNum, §ionSize);
- // if (sectionData == NULL)
- // return;
- // uint8* data = sectionData;
- CvReadStream(sectionNum, reader);
- uint8* data = reader.GetTempPtr(0, 0);
- uint8* sectionData = data;
- int32 ver = GET(int32);
- int32 headerSize = GET(int32);
- minVal = GET(int32);
- maxVal = GET(int32);
- int32 followSize = GET(int32);
- hashStream = GET(int16);
- int16 hashStreamPadding = GET(int16); // -1
- int32 hashKeySize = GET(int32); // 4
- int32 hashBucketsSize = GET(int32); // 0x3ffff
- int32 hashValsOffset = GET(int32); // 0
- int32 hashValsSize = GET(int32);
- int32 hashTypeIndexOffset = GET(int32);
- int32 hashTypeIndexSize = GET(int32);
- hashAdjOffset = GET(int32);
- hashAdjSize = GET(int32);
- dataOfs = 14 * 4;
- uint8* typeDataHead = data;
- bool validate = false;
- // Validate hash info - not necessary, just for debugging
- if (validate)
- {
- BF_FATAL("Fix validate stuff to work with new CvReader");
- int hashStreamSize = 0;
- uint8* hashDataHead = CvReadStream(hashStream, &hashStreamSize);
- int tagId = minVal;
- //////// Validate Type indices
- int typeIndexCount = hashTypeIndexSize / 8;
- // We expect a TypeIndexOffset for every 8k of data, plus the zero at the start
- int expectedTypeIndices = (sectionSize - (int)(data - sectionData)) / 8192 + 1;
- // Assert it's in some acceptable range...
- BF_ASSERT((typeIndexCount > expectedTypeIndices / 2) && (typeIndexCount < expectedTypeIndices * 2));
- for (int entryIdx = 0; entryIdx < typeIndexCount; entryIdx++)
- {
- data = hashDataHead + hashTypeIndexOffset + entryIdx * 8;
- GET_INTO(int, typeIdx);
- GET_INTO(int, ofs);
- uint8* dataEnd;
- int endTagId;
- if (entryIdx < typeIndexCount - 1)
- {
- endTagId = GET(int);
- int endOfs = GET(int);
- dataEnd = typeDataHead + endOfs;
- }
- else
- {
- endTagId = maxVal;
- dataEnd = sectionData + sectionSize;
- }
- data = typeDataHead + ofs;
- while (data < dataEnd)
- {
- int tagSize = GET(uint16);
- data += tagSize;
- tagId++;
- }
- BF_ASSERT(data == dataEnd);
- BF_ASSERT(tagId == endTagId);
- }
- BF_ASSERT(tagId == maxVal);
- ////// Validate hashes
- int hashCount = hashValsSize / 4;
- BF_ASSERT(hashCount == maxVal - minVal);
- tagId = minVal;
- int32* hashVals = (int32*)(hashDataHead + hashValsOffset);
- data = typeDataHead;
- Array<int> tagStarts;
- tagStarts.Reserve(maxVal - minVal);
- for (int hashIdx = 0; hashIdx < hashCount; hashIdx++)
- {
- int32 expectHashVal = hashVals[hashIdx];
- PTR_ALIGN(data, sectionData, 4);
- tagStarts.push_back((int)(data - sectionData));
- int32 hashVal = BlHash::GetTypeHash(data) % hashBucketsSize;
- BF_ASSERT(hashVal == expectHashVal);
- tagId++;
- }
- //////// Validate hash adjusters
- if (hashAdjSize > 0)
- {
- data = hashDataHead + hashAdjOffset;
- uint8* dataEnd = data + hashAdjSize;
- GET_INTO(int32, adjustCount);
- GET_INTO(int32, adjustCapacity);
- GET_INTO(int32, usedLen);
- uint32* usedBitsArr = (uint32*)data;
- data += usedLen * sizeof(int32);
- GET_INTO(int32, deletedLen);
- uint32* deletedBitsArr = (uint32*)data;
- data += deletedLen * sizeof(int32);
- int curAdjIdx = 0;
- for (int usedIdx = 0; usedIdx < usedLen; usedIdx++)
- {
- int usedBits = usedBitsArr[usedIdx];
- for (int i = 0; i < 32; i++)
- {
- if ((usedBits & (1 << i)) != 0)
- {
- GET_INTO(int32, adjVal);
- GET_INTO(CV_typ_t, typeId);
- uint8* typeData = sectionData + tagStarts[typeId - minVal];
- int32 hashVal = BlHash::GetTypeHash(typeData) % hashBucketsSize;
- const char* strVal = mStringTable.mStrTable + adjVal;
- int32 strHashVal = BlHash::HashStr_PdbV1(strVal) % hashBucketsSize;
- BF_ASSERT(hashVal == strHashVal);
- curAdjIdx++;
- }
- }
- }
- BF_ASSERT(curAdjIdx == adjustCount);
- }
- data = typeDataHead;
- }
- }
- void COFF::ParseTypeData()
- {
- if (!mPDBLoaded)
- return;
- if (mParsedTypeData)
- return;
- mParsedTypeData = true;
- auto linkedModule = GetLinkedModule();
- int startingTypeIdx = (int)linkedModule->mTypes.size();
- //uint8* sectionData;
- int sectionSize = 0;
- int hashAdjOffset = 0;
- int32 hashStream = -1;
- int32 hashAdjSize = 0;
- int32 dataOffset = 0;
- ParseTypeData(2, mCvTypeSectionReader, sectionSize, dataOffset, hashStream, hashAdjOffset, hashAdjSize, mCvMinTag, mCvMaxTag);
- //mCvTypeSectionData = sectionData;
- mCvTypeMap.Clear();
- mCvTagStartMap.Clear();
- mCvTypeMap.Resize(mCvMaxTag - mCvMinTag);
- mCvTagStartMap.Resize(mCvMaxTag - mCvMinTag);
- //DbgDataMap dataMap(minVal, maxVal);
- //uint8* data = sectionData + dataOffset;
- ParseTypeData(mCvTypeSectionReader, dataOffset);
- if (hashAdjSize > 0)
- {
- int sectionSize = 0;
- uint8* data = CvReadStream(hashStream, §ionSize);
- uint8* sectionData = data;
- data = sectionData + hashAdjOffset;
- GET_INTO(int32, adjustCount);
- GET_INTO(int32, unk0);
- GET_INTO(int32, unkCount);
- for (int i = 0; i < unkCount; i++)
- {
- GET_INTO(int32, unk2);
- }
- GET_INTO(int32, unkCount2);
- for (int i = 0; i < unkCount2; i++)
- {
- GET_INTO(int32, unk3);
- }
- // Types listed in the adjustment table are always primary types,
- // they should override any "old types" with the same name
- for (int adjIdx = 0; adjIdx < adjustCount; adjIdx++)
- {
- GET_INTO(int32, adjVal);
- GET_INTO(CV_typ_t, typeId);
- DbgType* dbgType = CvGetType(typeId);
- if (dbgType != NULL)
- {
- dbgType->mPriority = DbgTypePriority_Primary_Explicit;
- }
- }
- delete [] sectionData;
- }
- FixTypes(startingTypeIdx);
- MapTypes(startingTypeIdx);
- BF_ASSERT(mTempBufIdx == 0);
- }
- void COFF::FixConstant(DbgVariable* constVar)
- {
- if (constVar->mType->mTypeCode == DbgType_u8)
- constVar->mConstValue &= 0xFF;
- else if (constVar->mType->mTypeCode == DbgType_u16)
- constVar->mConstValue &= 0xFFFF;
- else if (constVar->mType->mTypeCode == DbgType_u32)
- constVar->mConstValue &= 0xFFFFFFFF;
- }
- void COFF::MapRanges(DbgVariable* variable, CV_LVAR_ADDR_RANGE* range, CV_LVAR_ADDR_GAP* gaps)
- {
- auto rangeStart = GetSectionAddr(range->isectStart, range->offStart);
- if (variable->mRangeStart == 0)
- {
- variable->mRangeStart = rangeStart;
- variable->mRangeLen = (rangeStart + range->cbRange) - variable->mRangeStart;
- }
- else
- {
- addr_target maxEnd = BF_MAX(variable->mRangeStart + variable->mRangeLen, rangeStart + range->cbRange);
- variable->mRangeStart = BF_MIN(variable->mRangeStart, rangeStart);
- variable->mRangeLen = maxEnd - variable->mRangeStart;
- }
- }
- void COFF::MakeThis(DbgSubprogram* curSubprogram, DbgVariable*& curParam)
- {
- if ((curParam != NULL) || (curSubprogram->mParams.mHead != NULL))
- return;
- BP_ALLOC_T(DbgVariable);
- curParam = mAlloc.Alloc<DbgVariable>();
- curParam->mIsParam = true;
- curParam->mName = "this";
- curSubprogram->mParams.mHead = curParam;
- }
- static int gSymCount = 0;
- void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionData, uint8* data, uint8* symDataEnd, CvInlineInfoVec& inlineDataVec, bool wantDeferInternals, DbgSubprogram* useSubprogram)
- {
- bool isOptimized = false;
- uint8* dataHead = data;
- CvCompileUnit* cvCompileUnit = (CvCompileUnit*)compileUnit;
- uint8* symDataStart = data;
- DbgSubprogram* curSubprogram = NULL;
- DbgVariable* curRegRelVariable = NULL;
- DbgVariable* curParam = NULL;
- DbgVariable* localVar = NULL;
- bool inLocalVarRanged = false;
- SizedArray<DbgBlock*, 16> blockStack;
- blockStack.push_back(compileUnit->mGlobalBlock);
- int deferBlockDepth = 0;
- int deferInlineDepth = 0;
- uint8* newLocationDataStart = NULL;
- uint8* locationDataStart = NULL;
- uint8* locationDataEnd = NULL;
- int locationDataCount = 0;
- struct _DeferredVariableLocation
- {
- DbgVariable* mVariable;
- uint8* mRangedStart;
- int mRangedLength;
- _DeferredVariableLocation()
- {
- mVariable = NULL;
- mRangedStart = NULL;
- mRangedLength = 0;
- }
- };
- SizedArray<_DeferredVariableLocation, 16> deferredVariableLocations;
- int unrangedIdx = -1;
- auto _NextUnrangedLocalVar = [&](const char* name, DbgType* varType)
- {
- inLocalVarRanged = false;
- localVar = NULL;
- unrangedIdx++;
- while (unrangedIdx < deferredVariableLocations.size())
- {
- localVar = deferredVariableLocations[unrangedIdx].mVariable;
- if (strcmp(localVar->mName, name) == 0)
- break;
- localVar = NULL;
- unrangedIdx++;
- }
- bool isParam = false;
- if (localVar == NULL)
- {
- if (curParam != NULL)
- {
- isParam = true;
- if (curParam->mType != varType)
- {
- // Type was different, probably from a 'ref' being added when we are passing composites
- curParam->mName = name;
- curParam = curParam->mNext;
- }
- else
- {
- localVar = curParam;
- curParam = curParam->mNext;
- }
- }
- }
- if (localVar == NULL)
- {
- BP_ALLOC_T(DbgVariable);
- localVar = mAlloc.Alloc<DbgVariable>();
- if (name != NULL)
- blockStack.back()->mVariables.PushBack(localVar);
- //return;
- }
- localVar->mName = name;
- if (isParam)
- localVar->mIsParam = true;
- if (strcmp(name, "this") == 0)
- {
- MakeThis(curSubprogram, localVar);
- //BF_ASSERT(varType->mTypeCode == DbgType_Ptr);
- curSubprogram->mParentType = varType->mTypeParam;
- curSubprogram->mHasThis = true;
- }
- };
- auto _FinishLocationData = [&]()
- {
- if (locationDataStart == NULL)
- return;
- if (inLocalVarRanged)
- {
- auto& deferredVariableLocation = deferredVariableLocations.back();
- BF_ASSERT(deferredVariableLocation.mRangedLength == 0);
- deferredVariableLocation.mRangedStart = locationDataStart;
- deferredVariableLocation.mRangedLength = (int)(locationDataEnd - locationDataStart);
- }
- else
- {
- if (localVar->mLocationData != NULL)
- {
- // Already handled
- NOP;
- }
- else if (unrangedIdx >= deferredVariableLocations.size())
- {
- // There was no ranged data, commit just the unranged entry
- BF_ASSERT(locationDataCount == localVar->mLocationLen);
- BP_ALLOC("DeferredVarLoc0", locationDataEnd - locationDataStart);
- localVar->mLocationData = mAlloc.AllocBytes(locationDataEnd - locationDataStart, "DeferredVarLoc0");
- memcpy((uint8*)localVar->mLocationData, locationDataStart, locationDataEnd - locationDataStart);
- }
- else
- {
- // We have both ranged an unranged data. Merge them!
- auto& deferredVariableLocation = deferredVariableLocations[unrangedIdx];
- auto deferredVar = deferredVariableLocation.mVariable;
- BF_ASSERT(deferredVar == localVar);
- if (deferredVariableLocation.mRangedLength == 0)
- BF_ASSERT(locationDataCount == localVar->mLocationLen);
- else
- BF_ASSERT(locationDataCount < localVar->mLocationLen);
- BP_ALLOC("DeferredVarLoc1", deferredVariableLocation.mRangedLength + (locationDataEnd - locationDataStart));
- localVar->mLocationData = mAlloc.AllocBytes(deferredVariableLocation.mRangedLength + (locationDataEnd - locationDataStart), "DeferredVarLoc1");
- memcpy((uint8*)localVar->mLocationData, deferredVariableLocation.mRangedStart, deferredVariableLocation.mRangedLength);
- memcpy((uint8*)localVar->mLocationData + deferredVariableLocation.mRangedLength, locationDataStart, locationDataEnd - locationDataStart);
- deferredVariableLocation.mRangedLength = -1; // Mark as 'handled'
- }
- }
- locationDataStart = NULL;
- locationDataEnd = NULL;
- locationDataCount = 0;
- };
- auto _FlushDeferredVariableLocations = [&]()
- {
- for (auto& deferredVariableLocation : deferredVariableLocations)
- {
- if (deferredVariableLocation.mRangedLength == -1)
- continue;
- auto deferredVar = deferredVariableLocation.mVariable;
- if (deferredVar->mLocationData != NULL)
- {
- // Already handled
- continue;
- }
- BP_ALLOC("DeferredVarLoc2", deferredVariableLocation.mRangedLength);
- deferredVar->mLocationData = mAlloc.AllocBytes(deferredVariableLocation.mRangedLength, "DeferredVarLoc2");
- memcpy((uint8*)deferredVar->mLocationData, deferredVariableLocation.mRangedStart, deferredVariableLocation.mRangedLength);
- }
- deferredVariableLocations.clear();
- unrangedIdx = -1;
- };
- bool inlineDebugDump = false;
- if (useSubprogram != NULL)
- {
- curSubprogram = useSubprogram;
- blockStack.push_back(&curSubprogram->mBlock);
- curParam = curSubprogram->mParams.mHead;
- curRegRelVariable = curParam;
- }
- while (data < symDataEnd)
- {
- bool deferInternals = (wantDeferInternals) || (deferInlineDepth > 0);
- gSymCount++;
- uint8* dataStart = data;
- GET_INTO(uint16, symLen);
- uint8* dataEnd = data + symLen;
- GET_INTO(uint16, symType);
- if (!IsObjectFile())
- BF_ASSERT(symLen % 4 == 2);
- bool newLocalVarHasLocData = false;
- DbgVariable* prevLocalVar = localVar;
- switch (symType)
- {
- case S_LOCAL:
- case S_BPREL32:
- case S_REGISTER:
- case S_REGREL32:
- case S_GPROC32:
- case S_LPROC32:
- case S_GPROC32_ID:
- case S_LPROC32_ID:
- // Starting a new var or method
- if ((!deferInternals) && (locationDataStart != NULL))
- {
- _FinishLocationData();
- }
- break;
- }
- /*if (handled)
- {
- data = dataEnd;
- continue;
- }*/
- if (inlineDebugDump)
- BfLogCv("SYMTYPE: %X\n", symType);
- switch (symType)
- {
- case S_UDT:
- {
- UDTSYM& udtSym = *(UDTSYM*)dataStart;
- DbgType* typeDefType = CvCreateType();
- typeDefType->mTypeCode = DbgType_TypeDef;
- typeDefType->mTypeParam = CvGetTypeSafe(udtSym.typind);
- typeDefType->mName = DbgDupString((const char*)udtSym.name, "DbgDupString.S_UDT");
- if (strncmp(typeDefType->mName, "_bf::", 5) == 0)
- {
- typeDefType->mLanguage = DbgLanguage_Beef;
- typeDefType->mName += 5;
- }
- else
- {
- typeDefType->mLanguage = DbgLanguage_C;
- }
- typeDefType->mTypeName = typeDefType->mName;
- }
- break;
- case S_OBJNAME:
- {
- GET_INTO(int32, objSig);
- const char* objName = CvParseAndDupString(data);
- }
- break;
- case S_CONSTANT:
- {
- CONSTSYM& constSym = *(CONSTSYM*)dataStart;
- BP_ALLOC_T(DbgVariable);
- DbgVariable* constVar = mAlloc.Alloc<DbgVariable>();
- constVar->mName = DbgDupString((const char*)constSym.name, "DbgDupString.S_CONSTANT");
- constVar->mType = CvGetTypeSafe(constSym.typind);
- constVar->mIsConst = true;
- constVar->mIsStatic = true;
- constVar->mConstValue = constSym.value;
- data = constSym.name + strlen((const char*)constSym.name) + 1;
- constVar->mConstValue = CvParseConstant(constSym.value, data);
- FixConstant(constVar);
- if (constVar->mName != NULL)
- blockStack.back()->mVariables.PushBack(constVar);
- }
- break;
- case S_EXPORT:
- {
- GET_INTO(int16, ord);
- struct ExpFlags
- {
- unsigned short fConstant : 1; // CONSTANT
- unsigned short fData : 1; // DATA
- unsigned short fPrivate : 1; // PRIVATE
- unsigned short fNoName : 1; // NONAME
- unsigned short fOrdinal : 1; // Ordinal was explicitly assigned
- unsigned short fForwarder : 1; // This is a forwarder
- unsigned short reserved : 10; // Reserved. Must be zero.
- };
- GET_INTO(ExpFlags, flags);
- const char* symName = CvParseAndDupString(data);
- }
- break;
- case S_GDATA32:
- case S_LDATA32:
- // In PDB reads we get this from the symbol stream
- if ((IsObjectFile()) || (curSubprogram != NULL))
- {
- auto linkedModule = GetLinkedModule();
- DATASYM32& dataSym = *(DATASYM32*)dataStart;
- char* name = (char*)dataSym.name;
- char* targetName = NULL;
- DbgType* targetType = mMasterCompileUnit->mGlobalType;
- bool overrideBeef = false;
- char* lastDblColon = (char*)GetLastDoubleColon(name);
- if (lastDblColon != NULL)
- {
- targetName = name;
- name = lastDblColon + 2;
- *lastDblColon = 0;
- if (strcmp(targetName, "_bf") == 0)
- {
- overrideBeef = true;
- }
- else
- {
- targetType = CvGetTypeOrNamespace(targetName);
- }
- }
- DbgType* dbgType = CvGetTypeSafe(dataSym.typind);
- BP_ALLOC_T(DbgVariable);
- DbgVariable* variable = mAlloc.Alloc<DbgVariable>();
- variable->mType = dbgType;
- variable->mLocationData = dataStart;
- variable->mLocationLen = 1;
- variable->mIsStatic = true;
- variable->mCompileUnit = mMasterCompileUnit;
- variable->mName = name;
- if (targetType == mMasterCompileUnit->mGlobalType)
- variable->mLinkName = name;
- variable->mIsExtern = symType == S_GDATA32;
- if (curSubprogram != NULL)
- {
- if (!IsObjectFile())
- {
- // Copy this, we free the source data
- variable->mName = DbgDupString(name, "DbgDupString.S_GDATA32");
- BP_ALLOC_T(DATASYM32)
- auto newPtr = mAlloc.Alloc<DATASYM32>();
- memcpy(newPtr, variable->mLocationData, sizeof(DATASYM32));
- variable->mLocationData = (uint8*)newPtr;
- }
- if (variable->mName != NULL)
- blockStack.back()->mVariables.PushBack(variable);
- break;
- }
- //variable->mCompileUnit = m;
- // Push front so we will find before the original static declaration (that has no memory associated with it)
- if (targetType != NULL)
- targetType->mMemberList.PushFront(variable);
- if ((variable->mIsExtern) && (variable->mLinkName != NULL))
- mStaticVariables.push_back(variable);
- }
- break;
- case S_GTHREAD32:
- case S_LTHREAD32:
- {
- if ((IsObjectFile()) || (curSubprogram != NULL))
- {
- auto linkedModule = GetLinkedModule();
- THREADSYM32& dataSym = *(THREADSYM32*)dataStart;
- char* name = (char*)dataSym.name;
- char* targetName = NULL;
- DbgType* targetType = mMasterCompileUnit->mGlobalType;
- bool overrideBeef = false;
- char* lastDblColon = (char*)GetLastDoubleColon(name);
- if (lastDblColon != NULL)
- {
- targetName = name;
- name = lastDblColon + 2;
- *lastDblColon = 0;
- if (strcmp(targetName, "_bf") == 0)
- {
- overrideBeef = true;
- }
- else
- {
- targetType = CvGetTypeOrNamespace(targetName);
- }
- }
- DbgType* dbgType = CvGetTypeSafe(dataSym.typind);
- BP_ALLOC_T(DbgVariable);
- DbgVariable* variable = mAlloc.Alloc<DbgVariable>();
- variable->mType = dbgType;
- variable->mLocationData = dataStart;
- variable->mLocationLen = 1;
- variable->mIsStatic = true;
- variable->mCompileUnit = mMasterCompileUnit;
- variable->mName = name;
- if (targetType == mMasterCompileUnit->mGlobalType)
- variable->mLinkName = name;
- variable->mIsExtern = symType == S_GTHREAD32;
- if (curSubprogram != NULL)
- {
- if (!IsObjectFile())
- {
- // Copy this, we free the source data
- variable->mName = DbgDupString(name, "DbgDupString.S_GTHREAD32");
- BP_ALLOC_T(DATASYM32)
- auto newPtr = mAlloc.Alloc<DATASYM32>();
- memcpy(newPtr, variable->mLocationData, sizeof(DATASYM32));
- variable->mLocationData = (uint8*)newPtr;
- }
- if (variable->mName != NULL)
- blockStack.back()->mVariables.PushBack(variable);
- break;
- }
- //variable->mCompileUnit = m;
- // Push front so we will find before the original static declaration (that has no memory associated with it)
- targetType->mMemberList.PushFront(variable);
- if ((variable->mIsExtern) && (variable->mLinkName != NULL))
- mStaticVariables.push_back(variable);
- }
- }
- break;
- case S_GPROC32:
- case S_LPROC32:
- case S_GPROC32_ID:
- case S_LPROC32_ID:
- {
- BF_ASSERT(curSubprogram == NULL);
- PROCSYM32* procSym = (PROCSYM32*)dataStart;
- DbgType* parentType = NULL;
- auto addr = GetSectionAddr(procSym->seg, procSym->off);
- DbgSubprogram* subprogram = NULL;
- if (procSym->typind != 0)
- {
- bool ipi = false;
- if ((!IsObjectFile()) &&
- ((symType == S_GPROC32_ID) || (symType == S_LPROC32_ID)))
- {
- if (!mCvIPIReader.IsSetup())
- CvParseIPI();
- ipi = true;
- }
- subprogram = CvParseMethod(parentType, NULL, procSym->typind, ipi);
- }
- if (subprogram == NULL)
- {
- BP_ALLOC_T(DbgSubprogram);
- subprogram = mAlloc.Alloc<DbgSubprogram>();
- }
- subprogram->mTagIdx = (int)(dataEnd - sectionData); // Position for method data
- subprogram->mIsOptimized = isOptimized;
- subprogram->mCompileUnit = compileUnit;
- char* name = DbgDupString((const char*)procSym->name, "DbgDupString.S_GPROC32");
- if (procSym->flags.CV_PFLAG_OPTDBGINFO)
- {
- subprogram->mIsOptimized = true;
- }
- if ((name[0] == '_') && (name[1] == '_'))
- {
- // This matches things like "__chkstk" or other system (supposedly) functions
- subprogram->mIsStepFilteredDefault = true;
- }
- if (strncmp(name, "_bf::", 5) == 0)
- {
- compileUnit->mLanguage = DbgLanguage_Beef;
- }
- localVar = NULL;
- bool hasColon = false;
- for (char* cPtr = name; *cPtr != 0; cPtr++)
- {
- char c = *cPtr;
- hasColon |= c == ':';
- if (c == '$')
- {
- if (strcmp(cPtr, "$CHK") == 0)
- {
- subprogram->mCheckedKind = BfCheckedKind_Checked;
- *cPtr = NULL;
- break;
- }
- else if (strcmp(cPtr, "$UCHK") == 0)
- {
- subprogram->mCheckedKind = BfCheckedKind_Unchecked;
- *cPtr = NULL;
- break;
- }
- }
- }
- subprogram->mPrologueSize = procSym->DbgStart;
- subprogram->mBlock.mLowPC = addr;
- subprogram->mBlock.mHighPC = subprogram->mBlock.mLowPC + (int32)procSym->len;
- BF_ASSERT(procSym->len >= 0);
- MapSubprogram(subprogram);
- curSubprogram = subprogram;
- curParam = subprogram->mParams.mHead;
- curRegRelVariable = curParam;
- blockStack.push_back(&subprogram->mBlock);
- //OutputDebugStrF("Func: %s\n", subprogram->mName);
- if (hasColon)
- {
- subprogram->mName = name;
- subprogram->mHasQualifiedName = true;
- compileUnit->mOrphanMethods.PushBack(curSubprogram);
- }
- else
- {
- subprogram->mName = name;
- compileUnit->mGlobalType->mMethodList.PushBack(curSubprogram);
- }
- BF_ASSERT(unrangedIdx == -1);
- }
- break;
- case S_THUNK32:
- {
- THUNKSYM32& thunkSym = *(THUNKSYM32*)dataStart;
- DbgType* parentType = NULL;
- DbgSubprogram* subprogram;
- BP_ALLOC_T(DbgSubprogram);
- subprogram = mAlloc.Alloc<DbgSubprogram>();
- subprogram->mCompileUnit = compileUnit;
- subprogram->mHasQualifiedName = true;
- subprogram->mName = DbgDupString((const char*)thunkSym.name, "DbgDupString.S_THUNK32");
- subprogram->mTagIdx = (int)(dataEnd - sectionData); // Position for method data
- subprogram->mBlock.mLowPC = GetSectionAddr(thunkSym.seg, thunkSym.off);
- subprogram->mBlock.mHighPC = subprogram->mBlock.mLowPC + thunkSym.len;
- BF_ASSERT(thunkSym.len >= 0);
- MapSubprogram(subprogram);
- curSubprogram = subprogram;
- curParam = subprogram->mParams.mHead;
- blockStack.push_back(&subprogram->mBlock);
- BF_ASSERT(unrangedIdx == -1);
- //OutputDebugStrF("Func: %s\n", subprogram->mName);
- }
- break;
- case S_BLOCK32:
- {
- if (deferInternals)
- {
- deferBlockDepth++;
- break;
- }
- BP_ALLOC_T(DbgBlock);
- DbgBlock* block = mAlloc.Alloc<DbgBlock>();
- blockStack.back()->mSubBlocks.PushBack(block);
- blockStack.push_back(block);
- BLOCKSYM32* blockSym = (BLOCKSYM32*)dataStart;
- block->mLowPC = GetSectionAddr(blockSym->seg, blockSym->off);
- block->mHighPC = block->mLowPC + blockSym->len;
- }
- break;
- case S_FRAMEPROC:
- {
- FRAMEPROCSYM* frameProc = (FRAMEPROCSYM*)dataStart;
- if (curSubprogram != NULL)
- {
- // if ((curSubprogram->mName != NULL) && (strcmp(curSubprogram->mName, "_bf::IDETest::HotTester::TestFuncs") == 0))
- // {
- // NOP;
- // }
- curSubprogram->mFrameBaseLen = frameProc->cbFrame + frameProc->cbSaveRegs;
- curSubprogram->mParamBaseReg = (DbgSubprogram::LocalBaseRegKind)(uint8)frameProc->flags.encodedParamBasePointer;
- curSubprogram->mLocalBaseReg = (DbgSubprogram::LocalBaseRegKind)(uint8)frameProc->flags.encodedLocalBasePointer;
- }
- }
- break;
- case S_BPREL32:
- {
- if (deferInternals)
- break;
- BPRELSYM32* bpRel32 = (BPRELSYM32*)dataStart;
- const char* name = DbgDupString((const char*)bpRel32->name, "DbgDupString.S_BPREL32");
- DbgType* varType = CvGetTypeSafe(bpRel32->typind);
- _NextUnrangedLocalVar(name, varType);
- localVar->mName = name;
- localVar->mCompileUnit = compileUnit;
- localVar->mType = varType;
- // This is location data now, not just a S_LOCAL opener
- //prevLocalVar = localVar;
- newLocalVarHasLocData = true;
- }
- break;
- case S_REGISTER:
- {
- if (deferInternals)
- break;
- REGSYM* regSym = (REGSYM*)dataStart;
- const char* name = DbgDupString((const char*)regSym->name);
- DbgType* varType = CvGetTypeSafe(regSym->typind);
- _NextUnrangedLocalVar(name, varType);
- localVar->mName = name;
- localVar->mCompileUnit = compileUnit;
- localVar->mType = varType;
- // This is location data now, not just a S_LOCAL opener
- //prevLocalVar = localVar;
- newLocalVarHasLocData = true;
- }
- break;
- case S_REGREL32:
- {
- if (deferInternals)
- break;
- REGREL32* regRel32 = (REGREL32*)dataStart;
- const char* name = DbgDupString((const char*)regRel32->name);
- DbgType* varType = CvGetTypeSafe(regRel32->typind);
- _NextUnrangedLocalVar(name, varType);
- localVar->mName = name;
- localVar->mCompileUnit = compileUnit;
- if ((localVar->mType != NULL) && (!localVar->mType->IsPointer()) && (varType != NULL) && (varType->IsPointer()))
- localVar->mSigNoPointer = true;
- localVar->mType = varType;
- // This is location data now, not just a S_LOCAL opener
- //prevLocalVar = localVar;
- newLocalVarHasLocData = true;
- }
- break;
- case S_LOCAL:
- {
- if (deferInternals)
- break;
- inLocalVarRanged = true;
- LOCALSYM& localSym = *(LOCALSYM*)dataStart;
- char* name = DbgDupString((const char*)localSym.name);
- bool isConst = false;
- int64 constVal = 0;
- if ((compileUnit->mLanguage == DbgLanguage_Beef) && (name != NULL) && (name[0] != '$'))
- {
- for (char* cPtr = name + 1; true; cPtr++)
- {
- char c = *cPtr;
- if (c == 0)
- break;
- if (c == '$')
- {
- if (cPtr[1] == '_')
- {
- cPtr[1] = '-';
- isConst = true;
- constVal = atoll(cPtr + 1);
- *cPtr = 0;
- }
- else if ((cPtr[1] >= '0') && (cPtr[1] <= '9'))
- {
- isConst = true;
- constVal = atoll(cPtr + 1);
- *cPtr = 0;
- }
- }
- }
- }
- if ((name != NULL) && (name[0] == '#'))
- {
- if (strcmp(name + 1, "StepOver") == 0)
- {
- curSubprogram->mIsStepFilteredDefault = true;
- }
- localVar = NULL;
- break;
- }
- DbgType* varType = CvGetType(localSym.typind, cvCompileUnit);
- if (varType == NULL)
- varType = CvGetType(T_VOID);
- if (name != NULL)
- {
- if ((localSym.flags.fIsOptimizedOut) && (name[0] != '$'))
- {
- if (varType->mSize > 0)
- curSubprogram->mIsOptimized = true;
- }
- if ((strcmp(name, "this") == 0) && (varType != NULL))
- {
- //BF_ASSERT(varType->mTypeCode == DbgType_Ptr);
- MakeThis(curSubprogram, curParam);
- curSubprogram->mParentType = varType->mTypeParam;
- curSubprogram->mHasThis = true;
- }
- }
- bool handledLocalVar = false;
- if (curParam != NULL)
- {
- if ((name != NULL) && (name[0] == '$'))
- {
- int strLen = strlen(name);
- // Splat head
- const char* dollarPos = strchr(name + 1, '$');
- const char* nameStr = name + 1;
- int nameLen = dollarPos - name - 1;
- if ((dollarPos != NULL) &&
- ((localVar == NULL) || (strncmp(localVar->mName, name, nameLen + 1) != 0)))
- {
- BP_ALLOC("ParamName", nameLen + 1);
- char* dupStr = (char*)mAlloc.AllocBytes(nameLen + 1, "ParamName");
- memcpy(dupStr, nameStr, nameLen);
- curParam->mName = dupStr;
- curParam->mIsConst = true;
- curParam = curParam->mNext;
- if (strcmp(dupStr, "this") == 0)
- curSubprogram->mHasThis = true;
- }
- }
- else if ((curParam->mType != varType) && (varType->mTypeCode != DbgType_Void))
- {
- // Type was different, probably from a 'ref' being added when we are passing composites
- curParam->mName = name;
- curParam = curParam->mNext;
- }
- else
- {
- localVar = curParam;
- curParam = curParam->mNext;
- handledLocalVar = true;
- }
- }
- if (!handledLocalVar)
- {
- BP_ALLOC_T(DbgVariable);
- localVar = mAlloc.Alloc<DbgVariable>();
- if (name != NULL)
- blockStack.back()->mVariables.PushBack(localVar);
- }
- localVar->mName = name;
- localVar->mCompileUnit = compileUnit;
- localVar->mType = varType;
- localVar->mIsConst = isConst;
- localVar->mConstValue = constVal;
- _DeferredVariableLocation deferredLocation;
- deferredLocation.mVariable = localVar;
- deferredVariableLocations.Add(deferredLocation);
- }
- break;
- case S_DEFRANGE_REGISTER:
- {
- if (deferInternals)
- break;
- DEFRANGESYMREGISTER& defRangeReg = *(DEFRANGESYMREGISTER*)dataStart;
- if (localVar != NULL)
- MapRanges(localVar, &defRangeReg.range, defRangeReg.gaps);
- }
- break;
- case S_DEFRANGE_FRAMEPOINTER_REL:
- {
- if (deferInternals)
- break;
- DEFRANGESYMFRAMEPOINTERREL& defRangeFPRel = *(DEFRANGESYMFRAMEPOINTERREL*)dataStart;
- MapRanges(localVar, &defRangeFPRel.range, defRangeFPRel.gaps);
- }
- break;
- case S_DEFRANGE_SUBFIELD_REGISTER:
- {
- if (deferInternals)
- break;
- DEFRANGESYMSUBFIELDREGISTER& defRangeSubFieldReg = *(DEFRANGESYMSUBFIELDREGISTER*)dataStart;
- }
- break;
- case S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE:
- {
- if (deferInternals)
- break;
- DEFRANGESYMFRAMEPOINTERREL_FULL_SCOPE& defRangeFPRel = *(DEFRANGESYMFRAMEPOINTERREL_FULL_SCOPE*)dataStart;
- }
- break;
- case S_DEFRANGE_REGISTER_REL:
- {
- if (deferInternals)
- break;
- DEFRANGESYMREGISTERREL& defRangeRegRel = *(DEFRANGESYMREGISTERREL*)dataStart;
- if (localVar != NULL)
- MapRanges(localVar, &defRangeRegRel.range, defRangeRegRel.gaps);
- }
- break;
- case S_ENDARG:
- if (deferInternals)
- break;
- BF_ASSERT(curParam == NULL);
- break;
- case S_END:
- case S_PROC_ID_END:
- if (deferBlockDepth > 0)
- --deferBlockDepth;
- else
- blockStack.pop_back();
- BF_ASSERT(blockStack.size() > 0);
- if (blockStack.size() == 1)
- {
- _FinishLocationData();
- _FlushDeferredVariableLocations();
- // Done with forced subprogram?
- if (useSubprogram != NULL)
- {
- return;
- }
- else if (deferInternals)
- {
- if (curSubprogram->mTagIdx != -1)
- {
- int endOffset = (int)(dataEnd - sectionData);
- curSubprogram->mDeferredInternalsSize = endOffset - curSubprogram->mTagIdx;
- }
- }
- inlineDebugDump = false;
- curSubprogram = NULL;
- curParam = NULL;
- }
- break;
- case S_COMPILE2:
- {
- COMPILESYM* compileSym = (COMPILESYM*)dataStart;
- }
- break;
- case S_COMPILE3:
- {
- COMPILESYM3* compileSym = (COMPILESYM3*)dataStart;
- }
- break;
- case S_ENVBLOCK:
- {
- GET_INTO(uint8, flags);
- while (true)
- {
- const char* envKey = CvParseAndDupString(data);
- if (envKey == NULL)
- break;
- const char* envValue = CvParseAndDupString(data);
- }
- }
- break;
- case S_BUILDINFO:
- {
- CV_ItemId buildInfoId = GET(CV_ItemId);
- }
- break;
- case S_TRAMPOLINE:
- break;
- case S_COFFGROUP:
- break;
- case S_SECTION:
- break;
- case S_FRAMECOOKIE:
- {
- FRAMECOOKIE& frameCookie = *(FRAMECOOKIE*)dataStart;
- }
- break;
- case S_LABEL32:
- {
- LABELSYM32& labelSym = *(LABELSYM32*)dataStart;
- }
- break;
- case S_CALLSITEINFO:
- {
- CALLSITEINFO& callSiteInfo = *(CALLSITEINFO*)dataStart;
- }
- break;
- case S_HEAPALLOCSITE:
- {
- HEAPALLOCSITE& heapAllocSite = *(HEAPALLOCSITE*)dataStart;
- }
- break;
- case S_FILESTATIC:
- {
- FILESTATICSYM& fileStaticSym = *(FILESTATICSYM*)dataStart;
- }
- break;
- case S_CALLEES:
- {
- FUNCTIONLIST& calleeList = *(FUNCTIONLIST*)dataStart;
- }
- break;
- case S_CALLERS:
- {
- FUNCTIONLIST& calleeList = *(FUNCTIONLIST*)dataStart;
- }
- break;
- case S_POGODATA:
- {
- POGOINFO& pogoInfo = *(POGOINFO*)dataStart;
- }
- break;
- case S_INLINESITE:
- case S_INLINESITE2:
- {
- if (useSubprogram != NULL)
- {
- deferInlineDepth++;
- break; // Already handled this
- }
- uint32 inlinee;
- uint8* binaryAnnotations;
- if (symType == S_INLINESITE)
- {
- INLINESITESYM& inlineSite = *(INLINESITESYM*)dataStart;
- inlinee = inlineSite.inlinee;
- binaryAnnotations = (uint8*)&inlineSite.binaryAnnotations;
- }
- else // S_INLINESITE2
- {
- INLINESITESYM2& inlineSite = *(INLINESITESYM2*)dataStart;
- inlinee = inlineSite.inlinee;
- binaryAnnotations = (uint8*)&inlineSite.binaryAnnotations;
- }
- DbgSubprogram* inlineParent = curSubprogram;
- DbgSubprogram* subprogram = NULL;
- if (IsObjectFile())
- {
- subprogram = CvParseMethod(NULL, NULL, inlinee, false);
- subprogram->mCompileUnit = compileUnit;
- curSubprogram = subprogram;
- }
- else if ((inlinee & 0x80000000) != 0)
- {
- BP_ALLOC_T(DbgSubprogram);
- subprogram = mAlloc.Alloc<DbgSubprogram>(); // ??
- subprogram->mCompileUnit = compileUnit;
- if (!mCvIPIReader.IsSetup())
- CvParseIPI();
- curSubprogram = subprogram;
- }
- else
- {
- BP_ALLOC_T(DbgSubprogram);
- subprogram = mAlloc.Alloc<DbgSubprogram>();
- subprogram->mCompileUnit = compileUnit;
- curSubprogram = subprogram;
- FixupInlinee(curSubprogram, inlinee);
- }
- BF_ASSERT(subprogram == curSubprogram);
- curSubprogram->mTagIdx = (int)(dataEnd - sectionData); // Position for method data
- BP_ALLOC_T(DbgInlineeInfo);
- curSubprogram->mInlineeInfo = mAlloc.Alloc<DbgInlineeInfo>();
- curSubprogram->mInlineeInfo->mInlineParent = inlineParent;
- if (inlineParent->mInlineeInfo != NULL)
- curSubprogram->mInlineeInfo->mInlineDepth = inlineParent->mInlineeInfo->mInlineDepth + 1;
- else
- curSubprogram->mInlineeInfo->mInlineDepth = 1;
- curSubprogram->mInlineeInfo->mRootInliner = inlineParent->GetRootInlineParent();
- curSubprogram->mInlineeInfo->mInlineeId = 0;
- curSubprogram->mFrameBaseData = inlineParent->mFrameBaseData;
- curSubprogram->mFrameBaseLen = inlineParent->mFrameBaseLen;
- curSubprogram->mLocalBaseReg = inlineParent->mLocalBaseReg;
- if (curSubprogram->mName == NULL)
- {
- /*curSubprogram->mName = "<Inline>";
- String name = StrFormat("<Inline>@%@", curSubprogram);
- curSubprogram->mName = DbgDupString(name.c_str());*/
- String name = StrFormat("<Inline>@%@", curSubprogram);
- curSubprogram->mName = DbgDupString(name.c_str());
- curSubprogram->mInlineeInfo->mInlineeId = inlinee;
- }
- if (inlineDebugDump)
- {
- int depth = curSubprogram->GetInlineDepth();
- BfLogCv("S_INLINESITE Ofs:%d Depth:%d Inlinee:%X Subprogram:%@ %s\n Parent:%@ %s\n", (dataStart - symDataStart), depth, inlinee,
- curSubprogram, curSubprogram->mName, curSubprogram->mInlineeInfo->mInlineParent, curSubprogram->mInlineeInfo->mInlineParent->mName);
- }
- CvInlineInfo inlineInfo;
- inlineInfo.mNext = NULL;
- inlineInfo.mTail = NULL;
- inlineInfo.mInlinee = inlinee;
- inlineInfo.mSubprogram = NULL;
- inlineInfo.mSubprogram = curSubprogram;
- inlineInfo.mData = binaryAnnotations;
- inlineInfo.mDataLen = dataEnd - inlineInfo.mData;
- inlineInfo.mDebugDump = inlineDebugDump;
- inlineDataVec.push_back(inlineInfo);
- blockStack.push_back(&curSubprogram->mBlock);
- }
- break;
- case S_INLINESITE_END:
- {
- if (inlineDebugDump)
- BfLogCv("S_INLINESITE_END\n");
- if (deferInlineDepth > 0)
- {
- deferInlineDepth--;
- }
- else
- {
- if (deferInternals)
- {
- int endOffset = (int)(dataEnd - sectionData);
- curSubprogram->mDeferredInternalsSize = endOffset - curSubprogram->mTagIdx;
- }
- curSubprogram = curSubprogram->mInlineeInfo->mInlineParent;
- blockStack.pop_back();
- }
- }
- break;
- case S_SSEARCH:
- {
- SEARCHSYM* searchSym = (SEARCHSYM*)dataStart;
- }
- break;
- case S_SEPCODE:
- {
- BP_ALLOC_T(DbgSubprogram);
- curSubprogram = mAlloc.Alloc<DbgSubprogram>();
- curSubprogram->mCompileUnit = compileUnit;
- blockStack.push_back(&curSubprogram->mBlock);
- SEPCODESYM* sepCodeSym = (SEPCODESYM*)dataStart;
- auto addr = GetSectionAddr(sepCodeSym->sect, sepCodeSym->off);
- auto parentAddr = GetSectionAddr(sepCodeSym->sectParent, sepCodeSym->offParent);
- curSubprogram->mBlock.mLowPC = addr;
- curSubprogram->mBlock.mHighPC = addr + sepCodeSym->length;
- String name = StrFormat("SEPCODE@%p", parentAddr);
- curSubprogram->mName = DbgDupString(name.c_str());
- curSubprogram->mTagIdx = (int)(dataEnd - sectionData); // Position for method data
- MapSubprogram(curSubprogram);
- }
- break;
- case S_COMPILE:
- break;
- case S_ANNOTATION:
- break;
- case S_UNAMESPACE:
- break;
- case /*S_FASTLINK*/0x1167:
- break;
- case /*S_INLINEES*/0x1168:
- break;
- case 0x1176:
- case 0x1178:
- case 0x1179:
- case 0x117A:
- case 0x117B:
- case 0x117C:
- case 0x117D:
- case 0x117E:
- case 0x117F:
- case 0x1180:
- break;
- case 7:
- // Unknown
- break;
- default:
- BF_DBG_FATAL("Unhandled");
- break;
- }
- bool hasNewLocalVar = (localVar != prevLocalVar) && (localVar != NULL);
- if (newLocalVarHasLocData)
- {
- prevLocalVar = localVar;
- }
- if (deferInlineDepth == 0)
- {
- switch (symType)
- {
- case S_BPREL32:
- case S_REGISTER:
- case S_REGREL32:
- case S_DEFRANGE_REGISTER:
- case S_DEFRANGE_FRAMEPOINTER_REL:
- case S_DEFRANGE_SUBFIELD_REGISTER:
- case S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE:
- case S_DEFRANGE_REGISTER_REL:
- {
- if (prevLocalVar != NULL)
- {
- /*if (localVar->mLocationData == NULL)
- localVar->mLocationData = dataStart;
- localVar->mLocationLen++;*/
- if (locationDataStart == NULL)
- locationDataStart = dataStart;
- locationDataEnd = dataEnd;
- locationDataCount++;
- if (localVar->mLocationData == NULL)
- localVar->mLocationLen++;
- }
- }
- break;
- }
- }
- if (hasNewLocalVar)
- {
- if ((localVar->mName != NULL) && (localVar->mName[0] == '$'))
- {
- char* aliasPos = (char*)strstr(localVar->mName, "$alias$");
- // This $alias$ hack is unfortunate, but LLVM gets confused when we attempt to tie multiple debug variables
- // to the same memory location, which can happen during mixin injection. The result is that the mixin gets
- // some premature instructions attributed to it from the variable declaration. This fixes that.
- if ((aliasPos != NULL) && (aliasPos > localVar->mName))
- {
- String findName = String(aliasPos + 7);
- localVar->mName = CvDupString(localVar->mName + 1, aliasPos - localVar->mName - 1);
- auto curBlock = blockStack.back();
- localVar->mLocationData = (uint8*)CvDupString(aliasPos + 7, strlen(aliasPos + 7));
- localVar->mRangeStart = curBlock->mLowPC;
- localVar->mRangeLen = curBlock->mHighPC - curBlock->mLowPC;
- /*bool found = false;
- auto _CheckBlock = [&](DbgBlock* block)
- {
- for (auto checkVar : block->mVariables)
- {
- if (checkVar->mName == NULL)
- continue;
- if (findName == checkVar->mName)
- {
- localVar->mConstValue = checkVar->mConstValue;
- localVar->mType = checkVar->mType;
- localVar->mLocationData = checkVar->mLocationData;
- localVar->mLocationLen = checkVar->mLocationLen;
- found = true;
- return true;
- }
- }
- return false;
- };
- for (int blockIdx = (int)blockStack.size() - 1; blockIdx >= 0; blockIdx--)
- {
- DbgBlock* block = blockStack[blockIdx];
- if (_CheckBlock(block))
- break;
- }
- if (!found)
- {
- addr_target checkAddr = 0;
- DbgSubprogram* checkSubprogram = curSubprogram;
- while (checkSubprogram != NULL)
- {
- auto checkAddr = checkSubprogram->mBlock.mLowPC;
- if (checkSubprogram->mInlineeInfo == NULL)
- break;
- checkSubprogram = checkSubprogram->mInlineeInfo->mInlineParent;
- std::function<void(DbgBlock*)> _RecurseBlock = [&](DbgBlock* block)
- {
- if ((checkAddr < block->mLowPC) || (checkAddr >= block->mHighPC))
- return;
- if (_CheckBlock(block))
- return;
- for (auto block : block->mSubBlocks)
- _RecurseBlock(block);
- };
- _RecurseBlock(&checkSubprogram->mBlock);
- }
- }*/
- }
- }
- if ((compileUnit->mLanguage != DbgLanguage_Beef) && (localVar->mName != NULL))
- {
- for (char* cPtr = (char*)localVar->mName; true; cPtr++)
- {
- char c = *cPtr;
- if (c == 0)
- break;
- if ((c == '<') || (c == '>'))
- *cPtr = '$';
- }
- }
- }
- /*if (prevLocalVar != NULL)
- {
- BF_ASSERT(locationDataCount == prevLocalVar->mLocationLen);
- }*/
- data = dataEnd;
- //PTR_ALIGN(data, sectionData, 4);
- }
- if (localVar != NULL)
- {
- if (locationDataStart != NULL)
- {
- _FinishLocationData();
- }
- }
- _FlushDeferredVariableLocations();
- }
- CvCompileUnit* COFF::ParseCompileUnit(CvModuleInfo* moduleInfo, CvCompileUnit* compileUnit, uint8* sectionData, int sectionSize)
- {
- BP_ZONE("COFF::ParseCompileUnit");
- CvInlineInfoVec inlineDataVec;
- Dictionary<uint32, CvInlineInfo*> inlineDataDict;
- if (moduleInfo != NULL)
- {
- BfLogDbg("ParseCompileUnit %s %s\n", mPDBPath.c_str(), moduleInfo->mModuleName);
- }
- else
- {
- BfLogDbg("ParseCompileUnit %s NULL\n", mPDBPath.c_str());
- }
- int allocSizeStart = mAlloc.GetAllocSize();
- if (compileUnit == NULL)
- {
- compileUnit = new CvCompileUnit(this);
- mCompileUnits.push_back(compileUnit);
- }
- compileUnit->mDbgModule = this;
- if (moduleInfo != NULL)
- {
- compileUnit->mModuleIdx = moduleInfo->mIdx;
- compileUnit->mName = moduleInfo->mModuleName;
- moduleInfo->mCompileUnit = compileUnit;
- }
- else
- {
- compileUnit->mModuleIdx = NULL;
- compileUnit->mName = mFilePath.c_str();
- }
- uint8* data = sectionData;
- uint8* dataEnd = NULL;
- GET_INTO(uint32, infoType);
- BF_ASSERT(infoType == CV_SIGNATURE_C13);
- int taggedSize = sectionSize;
- uint8* debugSubSectionsStart = data;
- if (moduleInfo != NULL)
- {
- taggedSize = moduleInfo->mLinesBytes;
- debugSubSectionsStart = data + moduleInfo->mSymbolBytes - sizeof(uint32);
- }
- else
- {
- taggedSize = sectionSize - sizeof(uint32);
- }
- if (mStringTable.mStrTable == NULL)
- {
- data = debugSubSectionsStart;
- dataEnd = data + taggedSize;
- while (data < dataEnd)
- {
- PTR_ALIGN(data, sectionData, 4);
- GET_INTO(int32, lineInfoType);
- GET_INTO(int32, lineInfoLength);
- uint8* dataStart = data;
- uint8* dataEnd = data + lineInfoLength;
- if (lineInfoType == DEBUG_S_STRINGTABLE)
- {
- if (mStringTable.mStrTable == NULL)
- mStringTable.mStrTable = (const char*)data;
- }
- data = dataEnd;
- }
- }
- //
- {
- data = debugSubSectionsStart;
- dataEnd = data + taggedSize;
- while (data < dataEnd)
- {
- PTR_ALIGN(data, sectionData, 4);
- GET_INTO(int32, lineInfoType);
- GET_INTO(int32, lineInfoLength);
- uint8* dataStart = data;
- uint8* dataEnd = data + lineInfoLength;
- if (lineInfoType == DEBUG_S_CROSSSCOPEIMPORTS)
- {
- while (data < dataEnd)
- {
- compileUnit->mImports.Add(CvCrossScopeImport());
- auto& crossScopeImport = compileUnit->mImports.back();
- crossScopeImport.mScopeCompileUnit = NULL;
- GET_INTO(uint32, externalScope);
- const char* fileName = mStringTable.mStrTable + externalScope;
- BfLogCv("DEBUG_S_CROSSSCOPEIMPORTS Scope:%s ", fileName);
- crossScopeImport.mScopeName = fileName;
- //
- /*for (int checkIdx = 0; checkIdx < (int)mCvModuleInfo.size(); checkIdx++)
- {
- auto checkModuleInfo = mCvModuleInfo[checkIdx];
- if ((checkModuleInfo != NULL) && (checkModuleInfo->mModuleName != NULL) && (stricmp(checkModuleInfo->mModuleName, fileName) == 0))
- {
- ParseCompileUnit(checkIdx);
- }
- }*/
- GET_INTO(int32, numRefs);
- for (int i = 0; i < numRefs; i++)
- {
- GET_INTO(uint32, refId);
- BfLogCv(" %X", refId);
- crossScopeImport.mImports.Add(refId);
- }
- BfLogCv("\n");
- }
- }
- else if (lineInfoType == DEBUG_S_CROSSSCOPEEXPORTS)
- {
- BfLogCv("DEBUG_S_CROSSSCOPEEXPORTS");
- while (data < dataEnd)
- {
- GET_INTO(int32, localId);
- GET_INTO(int32, globalId);
- BfLogCv(" %X=%X", globalId, localId);
- CvCrossScopeExportEntry entry;
- entry.mLocalId = localId;
- entry.mGlobalId = globalId;
- compileUnit->mExports.Add(entry);
- }
- BfLogCv("\n");
- }
- else if (lineInfoType == DEBUG_S_FRAMEDATA)
- {
- uint8* dataPtr = data;
- addr_target baseAddr = 0;
- int relAddr = GET_FROM(dataPtr, int32);
- ParseFrameDescriptors(dataPtr, dataEnd - dataPtr, GetLinkedModule()->mImageBase + relAddr);
- }
- data = dataEnd;
- }
- }
- if (moduleInfo != NULL)
- {
- data = sectionData + 4;
- dataEnd = data + moduleInfo->mSymbolBytes - sizeof(uint32);
- bool wantsDeferInternals = true;
- ParseCompileUnit_Symbols(compileUnit, sectionData, data, dataEnd, inlineDataVec, wantsDeferInternals, NULL);
- //ParseCompileUnit_Symbols(compileUnit, sectionData, data, dataEnd, inlineDataVec, false, NULL);
- data = dataEnd;
- }
- // Scan debug subsections to find file checksum table, and to load symbol data for hotloads
- Dictionary<int, int> checksumFileRefs;
- {
- BP_ZONE("ParseCompileUnit_SrcFiles");
- data = debugSubSectionsStart;
- dataEnd = data + taggedSize;
- while (true)
- {
- PTR_ALIGN(data, sectionData, 4);
- if (data >= dataEnd)
- break;
- GET_INTO(int32, lineInfoType);
- GET_INTO(int32, lineInfoLength);
- uint8* dataStart = data;
- uint8* dataEnd = data + lineInfoLength;
- if (lineInfoType < 0)
- {
- // Ignore
- }
- else if (lineInfoType == DEBUG_S_SYMBOLS)
- {
- ParseCompileUnit_Symbols(compileUnit, sectionData, data, dataEnd, inlineDataVec, false, NULL);
- }
- else if (lineInfoType == DEBUG_S_FILECHKSMS)
- {
- BF_ASSERT(checksumFileRefs.size() == 0);
- while (data < dataEnd)
- {
- int dataOfs = (int)(data - dataStart);
- GET_INTO(uint, fileTableOfs);
- const char* fileName = mStringTable.mStrTable + fileTableOfs;
- if ((fileName[0] == '\\') && (fileName[1] == '$'))
- fileName++;
- DbgSrcFile* srcFile = NULL;
- if (fileName[0] == '$')
- {
- srcFile = AddSrcFile(compileUnit, fileName);
- }
- else if ((fileName[0] == '/') || (fileName[0] == '\\') ||
- ((fileName[0] != 0) && (fileName[1] == ':')))
- {
- srcFile = AddSrcFile(compileUnit, fileName);
- }
- else
- {
- String fullDir = GetFileDir(mFilePath);
- fullDir.Append("\\");
- fullDir.Append(fileName);
- srcFile = AddSrcFile(compileUnit, fullDir);
- }
- if (srcFile->IsBeef())
- compileUnit->mLanguage = DbgLanguage_Beef;
- GET_INTO(uint8, hashLen);
- GET_INTO(uint8, hashType);
- if ((hashType == 1) && (hashLen == 16))
- {
- srcFile->mHashKind = DbgHashKind_MD5;
- memcpy(srcFile->mHash, data, 16);
- }
- else if ((hashType == 3) && (hashLen == 32))
- {
- srcFile->mHashKind = DbgHashKind_SHA256;
- memcpy(srcFile->mHash, data, 32);
- }
- data += hashLen;
- checksumFileRefs.TryAdd(dataOfs, (int)compileUnit->mSrcFileRefs.size() - 1);
- PTR_ALIGN(data, sectionData, 4);
- }
- }
- else if (lineInfoType == 255)
- {
- // Ignore
- }
- else
- {
- BF_ASSERT((lineInfoType >= DEBUG_S_SYMBOLS) && (lineInfoType <= DEBUG_S_COFF_SYMBOL_RVA));
- }
- data = dataEnd;
- }
- }
- if (!inlineDataVec.IsEmpty())
- {
- for (auto& inlineData : inlineDataVec)
- {
- uint32* keyPtr;
- CvInlineInfo** valuePtr;
- if (inlineDataDict.TryAdd(inlineData.mInlinee, &keyPtr, &valuePtr))
- {
- inlineData.mTail = &inlineData;
- *valuePtr = &inlineData;
- }
- else
- {
- (*valuePtr)->mTail->mNext = &inlineData;
- (*valuePtr)->mTail = &inlineData;
- }
- }
- }
- int inlineDataIdx = 0;
- DbgLineDataBuilder lineBuilder(this);
- //
- {
- BP_ZONE("ParseCompileUnit_LineInfo");
- //int totalLineCount = 0;
- //int targetLineCount = 0;
- int inlineIdx = 0;
- // struct _InlinerData
- // {
- // bool mWantSummaryDump;
- // Array<DbgInlinee> mInlinees;
- // Array<DbgInlineLineData> mInlineLineData;
- //
- // _InlinerData()
- // {
- // mWantSummaryDump = false;
- // }
- // };
- //
- // Dictionary<DbgSubprogram*, _InlinerData> deferredInlinerDatas;
- // Line info
- data = debugSubSectionsStart;
- dataEnd = data + taggedSize;
- while (data < dataEnd)
- {
- PTR_ALIGN(data, sectionData, 4);
- GET_INTO(int32, lineInfoType);
- GET_INTO(int32, lineInfoLength);
- uint8* dataStart = data;
- uint8* dataEnd = data + lineInfoLength;
- if (lineInfoType == DEBUG_S_FILECHKSMS)
- {
- // Already handled
- }
- else if (lineInfoType == DEBUG_S_LINES)
- {
- CV_DebugSLinesHeader_t& lineSec = GET(CV_DebugSLinesHeader_t);
- Array<DbgLineData> lineDataVec;
- addr_target contribStartAddr = GetSectionAddr(lineSec.segCon, lineSec.offCon);
- while (data < dataEnd)
- {
- lineDataVec.Clear();
- CV_DebugSLinesFileBlockHeader_t& linesFileHeader = GET(CV_DebugSLinesFileBlockHeader_t);
- DbgSrcFileReference* srcFileRef = &compileUnit->mSrcFileRefs[checksumFileRefs[linesFileHeader.offFile]];
- bool isBeef = srcFileRef->mSrcFile->IsBeef();
- int expectSize = (int)sizeof(CV_DebugSLinesFileBlockHeader_t) + (int)(linesFileHeader.nLines * sizeof(CV_Line_t));
- if ((lineSec.flags & CV_LINES_HAVE_COLUMNS) != 0)
- expectSize += (int)(linesFileHeader.nLines * sizeof(int16) * 2);
- BF_ASSERT(expectSize == linesFileHeader.cbBlock);
- lineDataVec.Resize(linesFileHeader.nLines);
- for (int lineIdx = 0; lineIdx < linesFileHeader.nLines; lineIdx++)
- {
- CV_Line_t& srcLineData = GET(CV_Line_t);
- DbgLineData& lineData = lineDataVec[lineIdx];
- lineData.mRelAddress = (uint32)((contribStartAddr + srcLineData.offset) - mImageBase);
- if (srcLineData.linenumStart == 0xf00f00) // Never step into
- {
- if (lineIdx > 0)
- lineData.mLine = lineDataVec[lineIdx - 1].mLine;
- lineData.mColumn = -2; // Never step into marker
- }
- else if (srcLineData.linenumStart == 0xfeefee) // Always step into
- {
- if (lineIdx > 0)
- lineData.mLine = lineDataVec[lineIdx - 1].mLine;
- lineData.mColumn = -1; // Always step into marker
- }
- else
- lineData.mLine = srcLineData.linenumStart - 1;
- // In Beef we always set the column, so a section without CV_LINES_HAVE_COLUMNS indicates a block of invalid
- // positions that we want to skip over
- if (isBeef)
- lineData.mColumn = -1;
- }
- if ((lineSec.flags & CV_LINES_HAVE_COLUMNS) != 0)
- {
- for (int lineIdx = 0; lineIdx < linesFileHeader.nLines; lineIdx++)
- {
- CV_Column_t& srcColumnData = GET(CV_Column_t);
- DbgLineData& lineData = lineDataVec[lineIdx];
- lineData.mColumn = (int)srcColumnData.offColumnStart - 1;
- }
- }
- DbgLineData* lastLineData = NULL;
- for (int lineIdx = 0; lineIdx < linesFileHeader.nLines; lineIdx++)
- {
- DbgLineData& lineData = lineDataVec[lineIdx];
- lastLineData = lineBuilder.Add(compileUnit, lineData, srcFileRef->mSrcFile, NULL);
- }
- }
- }
- else if (lineInfoType == DEBUG_S_INLINEELINES)
- {
- int linesType = GET(int);
- while (data < dataEnd)
- {
- int inlinee = 0;
- int srcFileIdx = -1;
- int startLine;
- DbgSrcFileReference* startSrcFileRef = NULL;
- if (linesType == 0)
- {
- CodeViewInfo::InlineeSourceLine& lineInfo = GET(CodeViewInfo::InlineeSourceLine);
- srcFileIdx = checksumFileRefs[lineInfo.fileId];
- startSrcFileRef = &compileUnit->mSrcFileRefs[srcFileIdx];
- startLine = lineInfo.sourceLineNum;
- inlinee = lineInfo.inlinee;
- }
- else if (linesType == 1)
- {
- CodeViewInfo::InlineeSourceLineEx& lineInfo = *(CodeViewInfo::InlineeSourceLineEx*)data;
- srcFileIdx = checksumFileRefs[lineInfo.fileId];
- startSrcFileRef = &compileUnit->mSrcFileRefs[srcFileIdx];
- startLine = lineInfo.sourceLineNum;
- inlinee = lineInfo.inlinee;
- data += sizeof(CodeViewInfo::InlineeSourceLineEx);
- data += (int)sizeof(CV_off32_t) * lineInfo.countOfExtraFiles;
- }
- else
- BF_FATAL("Invalid DEBUG_S_INLINEELINES lines type");
- CvInlineInfo* inlineData = NULL;
- inlineDataDict.TryGetValue(inlinee, &inlineData);
- while (inlineData != NULL)
- {
- bool inlineDebugDump = inlineData->mDebugDump;
- if (inlineData->mInlinee == -1)
- {
- if (inlineDebugDump)
- BfLogCv("Duplicate data: %X\n", inlinee);
- break;
- }
- // Mark as done
- inlineData->mInlinee = -1;
- int chunkNum = 0;
- int curLine = startLine;
- int curValidLine = curLine;
- bool flushOnLineOffset = false;
- addr_target lastLineAddr = 0;
- DbgSrcFileReference* srcFileRef = startSrcFileRef;
- DbgSubprogram* curSubprogram = inlineData->mSubprogram;
- DbgSubprogram* inlineParent = inlineData->mSubprogram->GetRootInlineParent();
- addr_target curAddr = inlineParent->mBlock.mLowPC;
- lastLineAddr = 0;
- if (inlineDebugDump)
- {
- //inlinerData->mWantSummaryDump = true;
- BfLogCv("------------------------------------------------\nINLINE DATA:%X Idx:%d CurAddr:%@ Line:%d\n SubProgram:%@ %s\n File:%s\n", inlinee, inlineIdx, curAddr, curLine,
- curSubprogram, curSubprogram->mName, srcFileRef->mSrcFile->mFilePath.c_str());
- }
- uint8* annData = inlineData->mData;
- uint8* annDataEnd = inlineData->mData + inlineData->mDataLen;
- DbgLineData* curLineData = NULL;
- auto _AddLine = [&]()
- {
- if (chunkNum != 0)
- {
- curLineData = NULL;
- return;
- }
- DbgLineData lineData;
- lineData.mLine = curValidLine - 1;
- lineData.mRelAddress = (uint32)(curAddr - mImageBase);
- lineData.mColumn = 0;
- if (curLine <= 0) // Negative lines mean "invalid position" for inlining
- lineData.mColumn = -1;
- lineData.mContribSize = 0;
- if ((curSubprogram->mBlock.mLowPC == 0) && (curLineData != NULL))
- curSubprogram->mBlock.mLowPC = mImageBase + curLineData->mRelAddress;
- if (inlineDebugDump)
- BfLogCv(" Adding Line:%d Addr:%@\n", lineData.mLine + 1, lineData.mRelAddress + mImageBase);
- curLineData = lineBuilder.Add(compileUnit, lineData, srcFileRef->mSrcFile, curSubprogram);
- };
- int codeIdx = 0;
- while (annData < annDataEnd)
- {
- auto annVal = CodeViewInfo::CVUncompressData(annData);
- switch (annVal)
- {
- case CodeViewInfo::BA_OP_Invalid: // link time pdb contains PADDINGs
- break;
- case CodeViewInfo::BA_OP_CodeOffset: // param : start offset
- {
- int32 offset = (int32)CodeViewInfo::CVUncompressData(annData);
- curAddr = inlineParent->mBlock.mLowPC + offset;
- if (inlineDebugDump)
- BfLogCv(" BA_OP_CodeOffset(%d) CurAddr:%@ Line:%d\n", offset, curAddr, curLine);
- }
- break;
- case CodeViewInfo::BA_OP_ChangeCodeOffsetBase: // param : nth separated code chunk (main code chunk == 0)
- {
- chunkNum = (int32)CodeViewInfo::CVUncompressData(annData);
- if (inlineDebugDump)
- BfLogCv("xxxxxxxxx BA_OP_ChangeCodeOffsetBase(%d) CurAddr:%@ Line:%d\n", chunkNum, curAddr, curLine);
- }
- break;
- case CodeViewInfo::BA_OP_ChangeCodeOffset: // param : delta of offset
- {
- int32 offset = (int32)CodeViewInfo::CVUncompressData(annData);
- curAddr += offset;
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeCodeOffset(%d) CurAddr:%@ Line:%d\n", offset, curAddr, curLine);
- if ((curLineData != NULL) && (curLineData->mContribSize == 0))
- {
- curLineData->mRelAddress = (uint32)(curAddr - mImageBase);
- if (inlineDebugDump)
- BfLogCv(" Setting addr on previous entry\n");
- }
- else
- _AddLine();
- flushOnLineOffset = true;
- }
- break;
- case CodeViewInfo::BA_OP_ChangeCodeLength: // param : length of code, default next start
- {
- int newCodeLen = (int32)CodeViewInfo::CVUncompressData(annData);
- curAddr += newCodeLen;
- if (curLineData != NULL)
- curLineData->mContribSize = newCodeLen;
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeCodeLength(%d) Addr:%@ EndAddr:%@\n", newCodeLen, curLineData->mRelAddress + mImageBase, curLineData->mRelAddress + mImageBase + curLineData->mContribSize);
- }
- break;
- case CodeViewInfo::BA_OP_ChangeFile: // param : fileId
- {
- uint32 newFileId = CodeViewInfo::CVUncompressData(annData);
- srcFileRef = &compileUnit->mSrcFileRefs[checksumFileRefs[newFileId]];
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeFile(%s) CurAddr:%@ Line:%d\n", srcFileRef->mSrcFile->mFilePath.c_str(), curAddr, curLine);
- }
- break;
- case CodeViewInfo::BA_OP_ChangeLineOffset: // param : line offset (signed)
- {
- int32 lineOfs = (int32)CodeViewInfo::DecodeSignedInt32(CodeViewInfo::CVUncompressData(annData));
- curLine += lineOfs;
- if (curLine > 0)
- curValidLine = curLine;
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeLineOffset(%d) CurAddr:%@ Line:%d\n", lineOfs, curAddr, curLine);
- _AddLine();
- }
- break;
- case CodeViewInfo::BA_OP_ChangeLineEndDelta: // param : how many lines, default 1
- {
- int numLines = (int32)CodeViewInfo::CVUncompressData(annData);
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeLineEndDelta(%d) CurAddr:%@ Line:%d\n", numLines, curAddr, curLine);
- }
- break;
- case CodeViewInfo::BA_OP_ChangeRangeKind: // param : either 1 (default, for statement) or 0 (for expression)
- {
- int32 readKind = (int32)CodeViewInfo::CVUncompressData(annData);
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeRangeKind(%d) CurAddr:%@ Line:%d\n", readKind, curAddr, curLine);
- }
- break;
- case CodeViewInfo::BA_OP_ChangeColumnStart: // param : start column number, 0 means no column info
- {
- int column = (int32)CodeViewInfo::CVUncompressData(annData);
- if (curLineData != NULL)
- curLineData->mColumn = column;
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeColumnStart(%d) CurAddr:%@ Line:%d\n", column, curAddr, curLine);
- }
- break;
- case CodeViewInfo::BA_OP_ChangeColumnEndDelta: // param : end column number delta (signed)
- {
- int columnEndDelta = (int32)CodeViewInfo::DecodeSignedInt32(CodeViewInfo::CVUncompressData(annData));
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeColumnEndDelta(%d) CurAddr:%@ Line:%d\n", columnEndDelta, curAddr, curLine);
- }
- break;
- // Combo opcodes for smaller encoding size.
- case CodeViewInfo::BA_OP_ChangeCodeOffsetAndLineOffset: // param : ((sourceDelta << 4) | CodeDelta)
- {
- int offsetData = (int32)CodeViewInfo::CVUncompressData(annData);
- int codeDelta = offsetData & 0xF;
- int sourceDelta = CodeViewInfo::DecodeSignedInt32(offsetData >> 4);
- curAddr += codeDelta;
- curLine += sourceDelta;
- if (curLine > 0)
- curValidLine = curLine;
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeCodeOffsetAndLineOffset(%d, %d) CurAddr:%@ Line:%d\n", codeDelta, sourceDelta, curAddr, curLine);
- _AddLine();
- }
- break;
- case CodeViewInfo::BA_OP_ChangeCodeLengthAndCodeOffset: // param : codeLength, codeOffset
- {
- curValidLine = curLine;
- int codeLen = (int32)CodeViewInfo::CVUncompressData(annData);
- int codeOffset = (int32)CodeViewInfo::CVUncompressData(annData);
- curAddr += codeOffset;
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeCodeLengthAndCodeOffset(%d, %d) CurAddr:%@ Line:%d\n", codeLen, codeOffset, curAddr, curLine);
- _AddLine();
- if (curLineData != NULL)
- {
- if (inlineDebugDump)
- BfLogCv(" ContribSize:%d\n", codeLen);
- curLineData->mContribSize = codeLen;
- }
- }
- break;
- case CodeViewInfo::BA_OP_ChangeColumnEnd: // param : end column number
- {
- int columnEnd = (int32)CodeViewInfo::CVUncompressData(annData);
- if (inlineDebugDump)
- BfLogCv(" BA_OP_ChangeColumnEnd(%d) CurAddr:%@ Line:%d\n", columnEnd, curAddr, curLine);
- }
- break;
- }
- codeIdx++;
- }
- if (curLineData != NULL)
- {
- if (curSubprogram->mBlock.mLowPC == 0)
- curSubprogram->mBlock.mLowPC = mImageBase + curLineData->mRelAddress;
- curSubprogram->mBlock.mHighPC = mImageBase + curLineData->mRelAddress + curLineData->mContribSize;
- }
- inlineData = inlineData->mNext;
- }
- }
- }
- data = dataEnd;
- }
- // for (auto& deferredInlinerDataKV : deferredInlinerDatas)
- // {
- // auto inlinerParent = deferredInlinerDataKV.mKey;
- // auto deferredInlinerData = &deferredInlinerDataKV.mValue;
- //
- // inlinerParent->mInlinerData = mAlloc.Alloc<DbgInlinerData>();
- // inlinerParent->mInlinerData->mInlinees.CopyFrom(deferredInlinerData->mInlinees.mVals, deferredInlinerData->mInlinees.mSize, mAlloc);
- // inlinerParent->mInlinerData->mInlineLineData.CopyFrom(deferredInlinerData->mInlineLineData.mVals, deferredInlinerData->mInlineLineData.mSize, mAlloc);
- // //deferredInlinerData->
- //
- // if (deferredInlinerData->mWantSummaryDump)
- // {
- // BfLogCv("------------------------------\nSUMMARY FOR: %s\n", inlinerParent->mName);
- //
- // for (auto& inlineLine : inlinerParent->mInlinerData->mInlineLineData)
- // {
- // BfLogCv("Addr:%@ EndAddr:%@ Line:%d Column:%d Inlinee:%d\n", inlineLine.mAddress, inlineLine.mAddress + inlineLine.mContribSize,
- // inlineLine.mLine + 1, inlineLine.mColumn + 1, inlineLine.mInlineIdx);
- // }
- // }
- // }
- }
- lineBuilder.Commit();
- //OutputDebugStrF("Module loaded, AllocSize added: %d\n", (mAlloc.GetAllocSize() - allocSizeStart) / 1024);
- return compileUnit;
- }
- CvCompileUnit* COFF::ParseCompileUnit(int compileUnitId)
- {
- CvModuleInfo* moduleInfo = mCvModuleInfo[compileUnitId];
- if (moduleInfo->mCompileUnit != NULL)
- return moduleInfo->mCompileUnit;
- BP_ZONE("ParseCompileUnit");
- ParseTypeData();
- if (moduleInfo->mStream == -1)
- return NULL;
- int sectionSize = 0;
- uint8* sectionData = CvReadStream(moduleInfo->mStream, §ionSize);
- if (sectionData == NULL)
- return NULL;
- ParseCompileUnit(moduleInfo, NULL, sectionData, sectionSize);
- delete sectionData;
- return moduleInfo->mCompileUnit;
- }
- void COFF::ParseCompileUnits()
- {
- for (int i = 0; i < (int)mCvModuleInfo.size(); i++)
- ParseCompileUnit(i);
- }
- DbgType* COFF::CvGetTypeOrNamespace(char* name, DbgLanguage language)
- {
- if (language == DbgLanguage_Unknown)
- {
- if (strncmp(name, "_bf::", 5) == 0)
- {
- language = DbgLanguage_Beef;
- name += 5;
- }
- else if ((name[0] == 'G') && (name[1] == '$'))
- {
- language = DbgLanguage_Beef;
- }
- else
- {
- language = DbgLanguage_C;
- // Check for a primitive array type like 'double[]'
- for (int i = 0; i < 10; i++)
- {
- char c = name[i];
- if (c == 0)
- break;
- if (c == '[')
- language = DbgLanguage_Beef;
- }
- }
- }
- auto linkedModule = GetLinkedModule();
- auto dbgTypeEntry = linkedModule->mTypeMap.Find(name, language);
- if (dbgTypeEntry != NULL)
- {
- auto dbgType = dbgTypeEntry->mValue;
- if (dbgType->mHotNewType != NULL)
- return dbgType->mHotNewType;
- return dbgType;
- }
- // It's possible that we get a reference to a template name that isn't actually in our type database
- // These may indicate VS compiler bugs or anonymous namespaces
- bool isValidName = true;
- for (const char* cPtr = name; *cPtr != '\0'; cPtr++)
- if ((*cPtr == '<') || (*cPtr == '`') || (*cPtr == '$'))
- isValidName = false;
- if (!isValidName)
- return NULL;
- //OutputDebugStrF("CvGetTypeOrNamespace Creating: %s\n", name);
- char* lastDblColon = (char*)GetLastDoubleColon(name);
- DbgType* dbgType = CvCreateType();
- DbgType* parentType = mMasterCompileUnit->mGlobalType;
- if (lastDblColon != NULL)
- {
- *lastDblColon = 0;
- parentType = CvGetTypeOrNamespace(name, language);
- dbgType->mTypeName = DbgDupString(lastDblColon + 2, "DbgDupString.TypeOrNamespace0");
- *lastDblColon = ':';
- dbgType->mName = DbgDupString(name, "DbgDupString.TypeOrNamespace1");
- }
- else
- {
- dbgType->mTypeName = DbgDupString(name, "DbgDupString.TypeOrNamespace2");
- dbgType->mName = dbgType->mTypeName;
- }
- parentType->mSubTypeList.PushBack(dbgType);
- dbgType->mTypeCode = DbgType_Namespace;
- dbgType->mLanguage = language;
- linkedModule->mTypeMap.Insert(dbgType);
- return dbgType;
- }
- void COFF::MapCompileUnitMethods(DbgCompileUnit* compileUnit)
- {
- bool addHotTypes = (IsObjectFile()) && (mHotPrimaryTypes.size() == 0);
- DbgSubprogram* prevDbgMethod = NULL;
- DbgSubprogram* dbgMethod = compileUnit->mOrphanMethods.mHead;
- while (dbgMethod != NULL)
- {
- auto nextDbgMethod = dbgMethod->mNext;
- bool movedMethod = false;
- if (dbgMethod->mHasQualifiedName)
- {
- char* name = (char*)dbgMethod->mName;
- char* lastDblColon = (char*)GetLastDoubleColon(name);
- if (lastDblColon != NULL)
- {
- dbgMethod->mName = lastDblColon + 2;
- dbgMethod->mHasQualifiedName = false;
- const char* typeName = name;
- *lastDblColon = 0;
- DbgType* parentType = CvGetTypeOrNamespace(name);
- if (parentType != NULL)
- {
- if (addHotTypes)
- {
- mHotPrimaryTypes.Add(parentType);
- }
- compileUnit->mOrphanMethods.Remove(dbgMethod, prevDbgMethod);
- parentType->mMethodList.PushBack(dbgMethod);
- dbgMethod->mParentType = parentType;
- movedMethod = true;
- }
- }
- }
- if (!movedMethod)
- prevDbgMethod = dbgMethod;
- dbgMethod = nextDbgMethod;
- }
- }
- void COFF::MapCompileUnitMethods(int compileUnitId)
- {
- CvModuleInfo* moduleInfo = mCvModuleInfo[compileUnitId];
- if (moduleInfo->mHasMappedMethods)
- return;
- ParseCompileUnit(compileUnitId);
- auto compileUnit = moduleInfo->mCompileUnit;
- //for (auto dbgMethod : compileUnit->mGlobalType.mMethodList)
- MapCompileUnitMethods(compileUnit);
- moduleInfo->mHasMappedMethods = true;
- }
- void COFF::PopulateType(DbgType* dbgType)
- {
- uint8* data = CvGetTagData(dbgType->mTagIdx, false);
- CvAutoReleaseTempData releaseTempData(this, data);
- uint8* dataStart = data;
- uint16 trLeafType = GET(uint16);
- switch (trLeafType)
- {
- case LF_ENUM:
- {
- lfEnum& enumInfo = *(lfEnum*)dataStart;
- CvParseMembers(dbgType, enumInfo.field, false);
- }
- break;
- case LF_CLASS:
- case LF_STRUCTURE:
- {
- lfClass& classInfo = *(lfClass*)dataStart;
- CvParseMembers(dbgType, classInfo.field, false);
- }
- break;
- case LF_CLASS_EX:
- case LF_STRUCTURE_EX:
- {
- auto property = GET(CV_prop_t);
- auto extra = GET(int16);
- auto field = GET(CV_typ_t);
- CvParseMembers(dbgType, field, false);
- }
- break;
- case LF_UNION:
- {
- lfUnion& classInfo = *(lfUnion*)dataStart;
- CvParseMembers(dbgType, classInfo.field, false);
- }
- break;
- default:
- BF_FATAL("Invalid type");
- }
- }
- void COFF::PopulateTypeGlobals(DbgType* dbgType)
- {
- //gDbgPerfManager->StartRecording();
- {
- BP_ZONE_F("COFF::PopulateTypeGlobals %s", (dbgType->mName != NULL) ? dbgType->mName : "?");
- ParseTypeData();
- dbgType->mNeedsGlobalsPopulated = false;
- dbgType->mHasGlobalsPopulated = true;
- mGlobalsTargetType = dbgType;
- ParseSymbolStream(CvSymStreamType_Globals_Targeted);
- mGlobalsTargetType = NULL;
- }
- //gDbgPerfManager->StopRecording(true);
- }
- void COFF::PopulateSubprogram(DbgSubprogram* dbgSubprogram)
- {
- if (dbgSubprogram->mDeferredInternalsSize == 0)
- return;
- BP_ZONE("COFF::PopulateSubprogram");
- auto compileUnit = (CvCompileUnit*)dbgSubprogram->mCompileUnit;
- CvModuleInfo* moduleInfo = mCvModuleInfo[compileUnit->mModuleIdx];
- int sectionSize = 0;
- uint8* sectionData = CvReadStreamSegment(moduleInfo->mStream, dbgSubprogram->mTagIdx, dbgSubprogram->mDeferredInternalsSize);
- CvInlineInfoVec inlineDataVec;
- ParseCompileUnit_Symbols(compileUnit, NULL, sectionData, sectionData + dbgSubprogram->mDeferredInternalsSize, inlineDataVec, false, dbgSubprogram);
- delete sectionData;
- dbgSubprogram->mDeferredInternalsSize = 0;
- }
- void COFF::FixSubprogramName(DbgSubprogram* dbgSubprogram)
- {
- const char* name = dbgSubprogram->mName;
- for (const char* cPtr = name; *cPtr != 0; cPtr++)
- {
- char c = *cPtr;
- if (c == '$')
- {
- bool isChecked = strcmp(cPtr, "$CHK") == 0;
- bool isUnchecked = strcmp(cPtr, "$UCHK") == 0;
- if (isChecked || isUnchecked)
- {
- dbgSubprogram->mCheckedKind = isChecked ? BfCheckedKind_Checked : BfCheckedKind_Unchecked;
- dbgSubprogram->mName = CvDupString(name, cPtr - name);
- return;
- }
- }
- }
- }
- void COFF::FixupInlinee(DbgSubprogram* dbgSubprogram, uint32 ipiTag)
- {
- if (!mCvIPIReader.IsSetup())
- CvParseIPI();
- //int idx = (ipiTag & 0x7FFFFFFF) - mCvIPIMinTag;
- //uint8* dataStart = mCvIPIData + mCvIPITagStartMap[idx];
- uint8* dataStart = CvGetTagData(ipiTag & 0x7FFFFFFF, true);
- CvAutoReleaseTempData releaseTempData(this, dataStart);
- lfEasy& funcLeaf = *(lfEasy*)dataStart;
- switch (funcLeaf.leaf)
- {
- case LF_FUNC_ID:
- {
- lfFuncId* funcData = (lfFuncId*)dataStart;
- CvParseMethod(NULL, NULL, funcData->type, false, dbgSubprogram);
- dbgSubprogram->mName = (const char*)funcData->name;
- bool doScope = true;
- if ((funcData->scopeId != 0) && (doScope))
- {
- uint8* data = CvGetTagData(funcData->scopeId, true);
- CvAutoReleaseTempData releaseTempData(this, data);
- lfEasy& leaf = *(lfEasy*)data;
- switch (leaf.leaf)
- {
- case LF_STRING_ID:
- {
- lfStringId& str = *(lfStringId*)data;
- const char* parentStr = (const char*)str.name;
- int allocLen = strlen(parentStr) + 2 + strlen(dbgSubprogram->mName) + 1;
- BP_ALLOC("String", allocLen);
- char* dupStr = (char*)mAlloc.AllocBytes(allocLen, "String");
- strcpy(dupStr, parentStr);
- strcat(dupStr, "::");
- strcat(dupStr, dbgSubprogram->mName);
- dbgSubprogram->mName = dupStr;
- }
- break;
- case LF_UDT_MOD_SRC_LINE:
- {
- /*auto udtModSrcLine = *(lfUdtModSrcLine*)data;
- auto parentType = CvGetType(udtModSrcLine.type);
- curSubprogram->mParentType = parentType;*/
- }
- break;
- }
- }
- break;
- }
- case LF_MFUNC_ID:
- {
- lfMFuncId* funcData = (lfMFuncId*)dataStart;
- CvParseMethod(NULL, NULL, funcData->type, false, dbgSubprogram);
- dbgSubprogram->mName = (const char*)funcData->name;
- if (dbgSubprogram->mName != NULL)
- {
- for (const char* cPtr = dbgSubprogram->mName + 1; true; cPtr++)
- {
- char c = *cPtr;
- if (c == 0)
- break;
- // For removing the mangled name from the mixins
- if (c == '?')
- {
- int nameLen = cPtr - dbgSubprogram->mName;
- char* dupStr = (char*)mAlloc.AllocBytes(nameLen + 1);
- memcpy(dupStr, dbgSubprogram->mName, nameLen);
- dupStr[nameLen] = 0;
- dbgSubprogram->mName = dupStr;
- break;
- }
- }
- }
- FixSubprogramName(dbgSubprogram);
- dbgSubprogram->mParentType = CvGetType(funcData->parentType);
- }
- break;
- }
- }
- int COFF::MapImport(CvCompileUnit* compileUnit, int id)
- {
- BF_ASSERT((id & 0x80000000) != 0);
- int scopeIdx = (id & 0x7FFF0000) >> 20;
- int itemId = (id & 0x0000FFFF);
- if (mModuleNameSet.IsEmpty())
- {
- for (auto moduleInfo : mCvModuleInfo)
- {
- String name = moduleInfo->mModuleName;
- name = ToUpper(name);
- CvModuleInfoNameEntry entry;
- entry.mModuleInfo = moduleInfo;
- mModuleNameSet.Add(entry);
- }
- }
- if (scopeIdx < (int)compileUnit->mImports.size())
- {
- auto& importSection = compileUnit->mImports[scopeIdx];
- if (itemId < (int)importSection.mImports.size())
- {
- auto importId = importSection.mImports[itemId];
- if (importSection.mScopeCompileUnit == NULL)
- {
- CvModuleInfo* moduleInfo = NULL;
- size_t nameHash = CvModuleInfoNameEntry::GetHashCode(importSection.mScopeName);
- for (auto& nameEntry : mModuleNameSet.SelectHashes(nameHash))
- {
- String checkModuleName = nameEntry.mModuleInfo->mModuleName;
- checkModuleName.Replace("\\", "/");
- checkModuleName = ToUpper(checkModuleName);
- String checkScopeName = importSection.mScopeName;
- checkScopeName.Replace("\\", "/");
- checkScopeName = ToUpper(checkScopeName);
- bool matches = false;
- if (checkModuleName == checkScopeName)
- matches = true;
- else if (checkScopeName.EndsWith("/" + checkModuleName))
- matches = true;
- if (matches)
- {
- ParseCompileUnit(nameEntry.mModuleInfo->mIdx);
- auto externCompileUnit = nameEntry.mModuleInfo->mCompileUnit;
- if (externCompileUnit->mExportMap.IsEmpty())
- {
- for (auto& exportEntry : externCompileUnit->mExports)
- externCompileUnit->mExportMap[exportEntry.mLocalId] = exportEntry.mGlobalId;
- }
- if (externCompileUnit->mExportMap.ContainsKey(importId))
- {
- importSection.mScopeCompileUnit = nameEntry.mModuleInfo->mCompileUnit;
- break;
- }
- }
- }
- }
- if (importSection.mScopeCompileUnit != NULL)
- {
- uint32 exportId;
- if (importSection.mScopeCompileUnit->mExportMap.TryGetValue(importId, &exportId))
- {
- if ((exportId & 0x80000000) != 0)
- {
- // Does this mean a recursive lookup?
- return exportId & 0x7FFFFFFF;
- }
- else
- {
- return exportId;
- }
- }
- }
- }
- }
- return 0;
- }
- void COFF::FixupInlinee(DbgSubprogram* dbgSubprogram)
- {
- BF_ASSERT(dbgSubprogram->mInlineeInfo != NULL);
- BF_ASSERT((dbgSubprogram->mInlineeInfo->mInlineeId & 0x80000000) != 0);
- int scopeIdx = (dbgSubprogram->mInlineeInfo->mInlineeId & 0x7FFF0000) >> 20;
- int itemId = (dbgSubprogram->mInlineeInfo->mInlineeId & 0x0000FFFF);
- if (mModuleNameMap.IsEmpty())
- {
- for (auto moduleInfo : mCvModuleInfo)
- {
- mModuleNameMap[CaseInsensitiveString(moduleInfo->mModuleName)] = moduleInfo;
- }
- }
- auto compileUnit = (CvCompileUnit*)dbgSubprogram->mCompileUnit;
- if (scopeIdx < (int)compileUnit->mImports.size())
- {
- auto& importSection = compileUnit->mImports[scopeIdx];
- if (itemId < (int)importSection.mImports.size())
- {
- auto importId = importSection.mImports[itemId];
- if (importSection.mScopeCompileUnit == NULL)
- {
- CvModuleInfo* moduleInfo = NULL;
- mModuleNameMap.TryGetValue(CaseInsensitiveString(importSection.mScopeName), &moduleInfo);
- if (moduleInfo != NULL)
- {
- ParseCompileUnit(moduleInfo->mIdx);
- importSection.mScopeCompileUnit = moduleInfo->mCompileUnit;
- }
- if (importSection.mScopeCompileUnit != NULL)
- {
- for (auto& exportEntry : importSection.mScopeCompileUnit->mExports)
- {
- if (exportEntry.mLocalId == importId)
- {
- if (exportEntry.mGlobalId < mCvIPITagStartMap.size())
- {
- FixupInlinee(dbgSubprogram, exportEntry.mGlobalId);
- }
- }
- }
- }
- }
- }
- }
- dbgSubprogram->mInlineeInfo->mInlineeId = 0;
- }
- void COFF::PopulateStaticVariableMap()
- {
- if (mPopulatedStaticVariables)
- return;
- BP_ZONE("COFF::PopulateStaticVariableMap");
- if (mMasterCompileUnit != NULL)
- {
- PopulateTypeGlobals(mMasterCompileUnit->mGlobalType);
- for (auto variable : mMasterCompileUnit->mGlobalType->mMemberList)
- {
- if ((variable->mIsExtern) && (variable->mLinkName != NULL))
- mStaticVariables.push_back(variable);
- }
- }
- DbgModule::PopulateStaticVariableMap();
- }
- void COFF::ScanCompileUnit(int compileUnitId)
- {
- BP_ZONE("COFF::ScanCompileUnit");
- CvModuleInfo* moduleInfo = mCvModuleInfo[compileUnitId];
- if (moduleInfo->mStream < 0)
- return;
- BF_ASSERT(moduleInfo->mSymbolBytes % 4 == 0);
- uint8* sectionData = CvReadStreamSegment(moduleInfo->mStream, moduleInfo->mSymbolBytes, moduleInfo->mLinesBytes);
- uint8* data = sectionData;
- uint8* dataEnd = sectionData + moduleInfo->mLinesBytes;
- while (data < dataEnd)
- {
- GET_INTO(int32, lineInfoType);
- GET_INTO(int32, lineInfoLength);
- uint8* dataEnd = data + lineInfoLength;
- if (lineInfoType == DEBUG_S_FILECHKSMS)
- {
- while (data < dataEnd)
- {
- GET_INTO(uint, fileTableOfs);
- DbgSrcFile* srcFile;
- DbgSrcFile** srcFilePtr = NULL;
- if (!mCVSrcFileRefCache.TryAdd(fileTableOfs, NULL, &srcFilePtr))
- {
- srcFile = *srcFilePtr;
- }
- else
- {
- const char* fileName = mStringTable.mStrTable + fileTableOfs;
- if ((fileName[0] == '\\') && (fileName[1] == '$'))
- fileName++;
- srcFile = AddSrcFile(NULL, fileName);
- mSrcFileDeferredRefs.Add(srcFile);
- *srcFilePtr = srcFile;
- //mCVSrcFileRefCache[fileTableOfs] = srcFile;
- }
- DbgDeferredSrcFileReference dbgDeferredSrcFileReference;
- dbgDeferredSrcFileReference.mDbgModule = this;
- dbgDeferredSrcFileReference.mCompileUnitId = compileUnitId;
- srcFile->mDeferredRefs.push_back(dbgDeferredSrcFileReference);
- srcFile->mHadLineData = true;
- GET_INTO(uint8, hashLen);
- GET_INTO(uint8, hashType);
- data += hashLen;
- PTR_ALIGN(data, sectionData, 4);
- }
- break; // Stop once we handle the file checksums
- }
- data = dataEnd;
- }
- delete [] sectionData;
- }
- void COFF::FixTypes(int startingIdx)
- {
- BP_ZONE("COFF::FixTypes");
- //std::unordered_map<String, DbgType*> namespaceMap;
- auto linkedModule = GetLinkedModule();
- String wholeNamespace;
- for (int typeIdx = startingIdx; typeIdx < (int)linkedModule->mTypes.size(); typeIdx++)
- {
- DbgType* dbgType = linkedModule->mTypes[typeIdx];
- DbgType* prevNamespaceType = NULL;
- if (dbgType->mName == NULL)
- {
- // Internal typedef
- continue;
- }
- if (dbgType->mLanguage == DbgLanguage_Unknown)
- {
- if (strncmp(dbgType->mName, "_bf::", 5) == 0)
- {
- dbgType->mLanguage = DbgLanguage_Beef;
- dbgType->mName += 5;
- dbgType->mTypeName += 5;
- }
- else if ((dbgType->mName[0] == 'G') && (dbgType->mName[1] == '$'))
- {
- dbgType->mLanguage = DbgLanguage_Beef;
- }
- else
- {
- dbgType->mLanguage = DbgLanguage_C;
- // Check for a primitive array type like 'double[]'
- for (int i = 0; i < 10; i++)
- {
- char c = dbgType->mName[i];
- if (c == 0)
- break;
- if (c == '[')
- dbgType->mLanguage = DbgLanguage_Beef;
- }
- }
- }
- if (dbgType->mIsDeclaration)
- continue;
- if (IsObjectFile())
- {
- auto entry = linkedModule->mTypeMap.Find(dbgType->mName, dbgType->mLanguage);
- if (entry != NULL)
- {
- // Just do hot replacing unless this type is new
- continue;
- }
- }
- // This never happens anymore - nested types are always handled as "internal typedefs"
- //TODO: Check the 'isnested' flag on the leaf instead of counting on parent to be specified?
- bool hadParent = dbgType->mParent != NULL;
- int chevronDepth = 0;
- if ((dbgType->mTypeCode == DbgType_Class) || (dbgType->mTypeCode == DbgType_Struct) || (dbgType->mTypeCode == DbgType_Union) ||
- (dbgType->mTypeCode == DbgType_Enum) || (dbgType->mTypeCode == DbgType_TypeDef))
- {
- int startIdx = -1;
- const char* name = dbgType->mTypeName;
- for (int i = 0; true; i++)
- {
- char c = name[i];
- if (c == '<')
- chevronDepth++;
- else if (c == '>')
- chevronDepth--;
- if ((chevronDepth == 0) && ((c == ':') || (c == '.')))
- {
- if ((!hadParent) && (i - startIdx > 1))
- {
- //String wholeNamespace = String(name, name + i);
- wholeNamespace.clear();
- wholeNamespace.Insert(0, name, i);
- auto entry = linkedModule->mTypeMap.Find(wholeNamespace.c_str(), dbgType->mLanguage);
- if (entry == NULL)
- {
- DbgType* namespaceType = CvCreateType();
- namespaceType->mTypeCode = DbgType_Namespace;
- namespaceType->mName = DbgDupString(wholeNamespace.c_str(), "DbgDupString.FixTypes");
- namespaceType->mTypeName = namespaceType->mName + startIdx + 1;
- namespaceType->mPriority = DbgTypePriority_Primary_Implicit;
- namespaceType->mLanguage = dbgType->mLanguage;
- linkedModule->mTypeMap.Insert(namespaceType);
- if (prevNamespaceType != NULL)
- {
- namespaceType->mParent = prevNamespaceType;
- prevNamespaceType->mSubTypeList.PushBack(namespaceType);
- }
- prevNamespaceType = namespaceType;
- }
- else
- {
- prevNamespaceType = entry->mValue;
- }
- }
- startIdx = i;
- }
- else if ((c == 0) /*|| (c == '<')*/ || (c == '('))
- break;
- }
- if (prevNamespaceType != NULL)
- {
- dbgType->mParent = prevNamespaceType;
- prevNamespaceType->mSubTypeList.PushBack(dbgType);
- }
- dbgType->mTypeName = dbgType->mTypeName + startIdx + 1; // Just take last part of name
- }
- if (dbgType->mParent == NULL)
- dbgType->mCompileUnit->mGlobalType->mSubTypeList.PushBack(dbgType);
- }
- }
- void COFF::CvReadStream(int streamIdx, CvStreamReader& streamReader)
- {
- BF_ASSERT(streamReader.mCOFF == NULL);
- streamReader.mCOFF = this;
- streamReader.mPageBits = mCvPageBits;
- int streamSize = mCvStreamSizes[streamIdx];
- int streamPageCount = (streamSize + mCvPageSize - 1) / mCvPageSize;
- streamReader.mStreamPtrs.Resize(streamPageCount);
- streamReader.mSize = streamSize;
- int streamPtrIdx = mCvStreamPtrStartIdxs[streamIdx];
- for (int streamPageIdx = 0; streamPageIdx < streamPageCount; streamPageIdx++)
- {
- streamReader.mStreamPtrs[streamPageIdx] = (uint8*)mCvMappedViewOfFile + mCvStreamPtrs[streamPtrIdx] * mCvPageSize;
- streamPtrIdx++;
- }
- }
- void COFF::CvInitStreamRaw(CvStreamReader & streamReader, uint8 * data, int size)
- {
- BF_ASSERT(streamReader.mCOFF == NULL);
- streamReader.mCOFF = this;
- streamReader.mPageBits = 31;
- streamReader.mStreamPtrs.Add(data);
- streamReader.mSize = size;
- }
- uint8* COFF::CvReadStream(int streamIdx, int* outSize)
- {
- BP_ZONE("ReadCvSection");
- if (streamIdx >= mCvStreamSizes.size())
- return NULL;
- if ((streamIdx < 0) || (streamIdx >= mCvStreamSizes.mSize))
- {
- return NULL;
- }
- int streamSize = mCvStreamSizes[streamIdx];
- if (outSize != NULL)
- *outSize = streamSize;
- if (streamSize <= 0)
- return NULL;
- int streamPageCount = (streamSize + mCvPageSize - 1) / mCvPageSize;
- uint8* sectionData = new uint8[streamSize];
- bool deferDeleteSectionData = false;
- int streamPtrIdx = mCvStreamPtrStartIdxs[streamIdx];
- for (int streamPageIdx = 0; streamPageIdx < streamPageCount; streamPageIdx++)
- {
- mCvDataStream->SetPos(mCvStreamPtrs[streamPtrIdx] * mCvPageSize);
- mCvDataStream->Read(sectionData + streamPageIdx * mCvPageSize, std::min(streamSize - (streamPageIdx * mCvPageSize), mCvPageSize));
- streamPtrIdx++;
- }
- return sectionData;
- }
- uint8* COFF::CvReadStreamSegment(int streamIdx, int offset, int size)
- {
- BP_ZONE("ReadCvSection");
- //int streamSize = mCvStreamSizes[streamIdx];
- //int streamPageCount = (streamSize + mCvPageSize - 1) / mCvPageSize;
- uint8* sectionData = new uint8[size];
- //delete [] sectionData;
- bool deferDeleteSectionData = false;
- uint8* data = sectionData;
- int curOffset = offset;
- int sizeLeft = size;
- int streamPtrIdx = mCvStreamPtrStartIdxs[streamIdx];
- streamPtrIdx += offset / mCvPageSize;
- curOffset = offset - (offset / mCvPageSize) * mCvPageSize;
- //for (int streamPageIdx = 0; streamPageIdx < streamPageCount; streamPageIdx++)
- while (sizeLeft > 0)
- {
- mCvDataStream->SetPos(mCvStreamPtrs[streamPtrIdx] * mCvPageSize + curOffset);
- int readSize = std::min(mCvPageSize - curOffset, sizeLeft);
- mCvDataStream->Read(data, readSize);
- data += readSize;
- sizeLeft -= readSize;
- curOffset = 0;
- streamPtrIdx++;
- }
- return sectionData;
- }
- void COFF::ReleaseTempBuf(uint8* buf)
- {
- if ((mTempBufIdx > 0) && (mTempBufs.mVals[mTempBufIdx - 1].mVals == buf))
- mTempBufIdx--;
- }
- bool COFF::CvParseHeader(uint8 wantGuid[16], int32 wantAge)
- {
- int streamSize = 0;
- uint8* data = CvReadStream(1, &streamSize);
- mCvHeaderData = data;
- int32 pdbVersion = GET(int32);
- int32 timestamp = GET(int32);
- int32 pdbAge = GET(int32);
- for (int i = 0; i < 16; i++)
- mPDBGuid[i] = GET(int8);
- if ((wantAge != -1) &&
- (/*(pdbAge != wantAge) ||*/ (memcmp(mPDBGuid, wantGuid, 16) != 0)))
- {
- if (mDebugger != NULL)
- {
- String msg = "PDB GUID did not match requested version\n";
- msg += StrFormat(" Module GUID: ");
- for (int i = 0; i < 16; i++)
- msg += StrFormat("%02X", (uint8)wantGuid[i]);
- msg += "\n";
- msg += StrFormat(" PDB GUID : ");
- for (int i = 0; i < 16; i++)
- msg += StrFormat("%02X", (uint8)mPDBGuid[i]);
- Fail(msg);
- }
- return false;
- }
- if (mParseKind == ParseKind_Header)
- return true;
- int nameTableIdx = -1;
- GET_INTO(int32, strTabLen);
- const char* strTab = (const char*)data;
- data += strTabLen;
- GET_INTO(int32, numStrItems);
- GET_INTO(int32, strItemMax);
- GET_INTO(int32, usedLen);
- data += usedLen * sizeof(int32);
- GET_INTO(int32, deletedLen);
- data += deletedLen * sizeof(int32);
- for (int tableIdx = 0; tableIdx < numStrItems; tableIdx++)
- {
- GET_INTO(int32, strOfs);
- GET_INTO(int32, streamNum);
- const char* tableName = strTab + strOfs;
- if (strcmp(tableName, "/names") == 0)
- mStringTable.mStream = streamNum;
- if (strcmp(tableName, "srcsrv") == 0)
- mCvSrcSrvStream = streamNum;
- if (strcmp(tableName, "emit") == 0)
- mCvEmitStream = streamNum;
- /*if (tableIdx == nameTableIdx)
- {
- nameStringTable.mStream = streamNum;
- nameStringTable.mStreamOffset = strOfs;
- }*/
- }
- return true;
- }
- bool COFF::CvParseDBI(int wantAge)
- {
- BP_ZONE("CvParseDBI");
- uint8* data = CvReadStream(3);
- if (data == NULL)
- return false;
- uint8* sectionData = data;
- defer
- (
- delete sectionData;
- );
- // Header
- GET_INTO(int32, signature);
- GET_INTO(uint32, version);
- GET_INTO(uint32, age);
- mDebugAge = (int32)age;
- if ((wantAge != -1) && (wantAge != age))
- {
- if (mDebugger != NULL)
- {
- String msg = "PDB age did not match requested age\n";
- msg += StrFormat(" Module Age: %d PDB Age: %d", wantAge, age);
- Fail(msg);
- }
- return false;
- }
- if (mParseKind == ParseKind_Header)
- return true;
- mCvGlobalSymbolInfoStream = GET(int16); // hash1_file, snGSSyms
- GET_INTO(uint16, pdb_dll_version);
- mCvPublicSymbolInfoStream = GET(int16); // hash2_file, snPSSyms
- GET_INTO(uint16, pdb_dll_build_major);
- mCvSymbolRecordStream = GET(int16); // gsym_file, snSymRecs
- GET_INTO(uint16, pdb_dll_build_minor);
- GET_INTO(uint32, gp_modi_size); //module_size
- GET_INTO(uint32, section_contribution_size); //offset_size
- GET_INTO(uint32, section_map_size); //hash_size
- GET_INTO(uint32, file_info_size); //srcmodule_size
- GET_INTO(uint32, ts_map_size); //pdb_import_size
- GET_INTO(uint32, mfc_index); //resvd0
- GET_INTO(uint32, dbg_header_size); // stream_index_size
- GET_INTO(uint32, ec_info_size); //unknown_size
- GET_INTO(uint16, flags); //resvd3
- GET_INTO(uint16, machine);
- GET_INTO(uint32, reserved); //resvd4
- if (machine == 0x8664)
- mIs64Bit = true;
- else if (machine == 0x014C)
- mIs64Bit = false;
- else // Unknown machine
- return false;
- uint8* headerEnd = data;
- // Skip to debug header
- data += gp_modi_size;
- data += section_contribution_size;
- data += section_map_size;
- data += file_info_size;
- data += ts_map_size;
- data += ec_info_size;
- // Debug header
- GET_INTO(int16, fpo);
- GET_INTO(int16, exception);
- GET_INTO(int16, fixup);
- GET_INTO(int16, omap_to_src);
- GET_INTO(int16, omap_from_src);
- GET_INTO(int16, section_header); // 0x0a, all others are -1 (segments)
- GET_INTO(int16, token_rid_map);
- GET_INTO(int16, x_data);
- GET_INTO(int16, p_data);
- mCvNewFPOStream = GET(int16);
- GET_INTO(int16, section_header_origin);
- if (section_header != -1)
- ParseSectionHeader(section_header);
- // Module info
- data = headerEnd;
- uint8* dataEnd = data + gp_modi_size;
- while (data < dataEnd)
- {
- BP_ALLOC_T(CvModuleInfo);
- CvModuleInfo* moduleInfo = mAlloc.Alloc<CvModuleInfo>();
- memcpy(moduleInfo, data, sizeof(CvModuleInfoBase));
- data += sizeof(CvModuleInfoBase);
- moduleInfo->mModuleName = CvParseAndDupString(data);//DataGetString(data);
- moduleInfo->mObjectName = CvParseAndDupString(data);//DataGetString(data);
- moduleInfo->mIdx = (int)mCvModuleInfo.size();
- //BfLogCv("Module %d: %s Obj: %s\n", mCvModuleInfo.size(), moduleInfo->mModuleName, moduleInfo->mObjectName);
- mCvModuleInfo.push_back(moduleInfo);
- /*if (moduleInfo->mStream != -1)
- {
- if (moduleInfo->mStream >= mDeferredModuleInfo.size())
- mDeferredModuleInfo.resize(moduleInfo->mStream + 1);
- mDeferredModuleInfo[moduleInfo->mStream].push_back(moduleInfo);
- }*/
- PTR_ALIGN(data, sectionData, 4);
- }
- // Section contrib
- {
- BP_ZONE("CvParseDBI_Contrib");
- dataEnd = data + section_contribution_size;
- int32 sig = GET(int32);
- BF_ASSERT((sig == 0xF12EBA2D) || (sig == 0xf13151e4));
- bool isV2 = sig == 0xf13151e4;
- if (isV2)
- {
- Fail("FastLink PDBs are not supported. Consider adding full debug info (/DEBUG:FULL).");
- mIsFastLink = true;
- }
- while (data < dataEnd)
- {
- CvSectionContrib& contrib = GET(CvSectionContrib);
- if (isV2)
- {
- uint32_t isectCoff = GET(uint32_t);
- }
- for (int contribOffset = 0; true; contribOffset += DBG_MAX_LOOKBACK)
- {
- int curSize = contrib.mSize - contribOffset;
- if (curSize <= 0)
- break;
- BP_ALLOC_T(DbgCompileUnitContrib);
- auto contribEntry = mAlloc.Alloc<DbgCompileUnitContrib>();
- contribEntry->mAddress = GetSectionAddr(contrib.mSection, contrib.mOffset) + contribOffset;
- if ((contribEntry->mAddress & 0xFFFF0000'00000000) != 0)
- continue;
- contribEntry->mLength = curSize;
- contribEntry->mDbgModule = this;
- contribEntry->mCompileUnitId = contrib.mModule;
- contribEntry->mSection = contrib.mSection;
- mDebugTarget->mContribMap.Insert(contribEntry);
- }
- }
- }
- // Dbi section map
- dataEnd = data + section_map_size;
- GET_INTO(int16, numSections);
- GET_INTO(int16, numSectionsCopy);
- while (data < dataEnd)
- {
- GET_INTO(uint8, flags);
- GET_INTO(uint8, section_type);
- // This field hasn't been deciphered but it is always 0x00000000 or 0xFFFFFFFF
- // and modifying it doesn't seem to invalidate the Cv.
- GET_INTO(int32, unknownData);
- GET_INTO(uint16, section_number);
- // Same thing as for unknown_data_1.
- GET_INTO(int32, unknownData2);
- // Value added to the address offset when calculating the RVA.
- GET_INTO(uint32, rva_offset);
- GET_INTO(uint32, section_length);
- }
- // Dbi File info
- dataEnd = data + file_info_size;
- GET_INTO(uint16, fileInfoNumModules);
- GET_INTO(uint16, bad_fileInfoNumSourceFiles);
- int fileInfoNumSourceFiles = 0;
- uint16* modIndices = (uint16*)data;
- data += fileInfoNumModules * sizeof(uint16);
- uint16* modFileCounts = (uint16*)data;
- data += fileInfoNumModules * sizeof(uint16);
- for (int moduleIdx = 0; moduleIdx < fileInfoNumModules; moduleIdx++)
- fileInfoNumSourceFiles += modFileCounts[moduleIdx];
- int32* fileNameOffsets = (int32*)data;
- data += fileInfoNumSourceFiles * sizeof(int32);
- char* nameBuffer = (char*)data;
- char* namePtr = nameBuffer;
- int curFileOfs = 0;
- for (int moduleIdx = 0; moduleIdx < fileInfoNumModules; moduleIdx++)
- {
- //TODO: LLD-LINK does not emit this properly
- //BF_ASSERT((modIndices[moduleIdx] == curFileOfs) || (moduleIdx >= 32));
- for (int fileIdx = 0; fileIdx < modFileCounts[moduleIdx]; fileIdx++)
- {
- char* fileName = namePtr + *fileNameOffsets;
- curFileOfs++;
- fileNameOffsets++;
- }
- //int blockStart = fileBlockTable[i];
- //int blockLength = fileBlockTable[fileInfoNumModules + i];
- //int offset = offsetTable[blockStart]; through blockLength...
- }
- // File name table
- /*uint8* dataStart = data;
- while (data < dataEnd)
- {
- int offset = (int)(data - dataStart);
- const char* fileName = SafeDataGetString(data, dataEnd);
- if (fileName == NULL)
- break;
- //DbgSrcFile* srcFile = AddSrcFile(mMasterCompileUnit, fileName);
- //fileTable.insert(std::make_pair(offset, srcFile));
- }*/
- data = dataEnd;
- BF_ASSERT(ts_map_size == 0);
- // EC Info
- dataEnd = data + ec_info_size;
- GET_INTO(uint32, strTabSig);
- GET_INTO(uint32, strTabVer);
- BF_ASSERT(strTabSig == 0xEFFEEFFE);
- GET_INTO(int32, strTabSize);
- uint8* strTabData = data;
- data += strTabSize;
- int pdbNameIdx = -1;
- for (auto moduleInfo : mCvModuleInfo)
- {
- if (moduleInfo->mCompilerNameCount > 0)
- pdbNameIdx = moduleInfo->mCompilerNameCount;
- }
- if ((pdbNameIdx > 0) && (pdbNameIdx < strTabSize))
- mOrigPDBPath = (const char*)strTabData + pdbNameIdx;
- GET_INTO(int32, strTabEntryCount);
- for (int entryIdx = 0; entryIdx < strTabEntryCount; entryIdx++)
- {
- GET_INTO(int32, strOffset);
- const char* str = (const char*)strTabData + strOffset;
- }
- return true;
- }
- void COFF::ParseSectionHeader(int sectionIdx)
- {
- bool fakeRVAS = mSectionHeaders.empty();
- int sectionSize = 0;
- uint8* sectionData = CvReadStream(sectionIdx, §ionSize);
- uint8* data = sectionData;
- uint8* dataEnd = data + sectionSize;
- while (data < dataEnd)
- {
- auto& sectionHeader = GET(PESectionHeader);
- if (fakeRVAS)
- {
- mSectionHeaders.push_back(sectionHeader);
- }
- }
- if (fakeRVAS)
- {
- PESectionHeader sectionHeader = { 0 };
- mSectionHeaders.push_back(sectionHeader);
- }
- delete sectionData;
- }
- void COFF::CvParseIPI()
- {
- BF_ASSERT(!mCvIPIReader.IsSetup());
- //uint8* sectionData;
- int sectionSize = 0;
- int hashAdjOffset = 0;
- int32 hashStream = -1;
- int32 hashAdjSize = 0;
- int32 dataOffset = 0;
- ParseTypeData(4, mCvIPIReader, sectionSize, dataOffset, hashStream, hashAdjOffset, hashAdjSize, mCvIPIMinTag, mCvIPIMaxTag);
- //mCvIPIData = sectionData;
- int recordCount = mCvIPIMaxTag - mCvIPIMinTag;
- mCvIPITagStartMap.Resize(recordCount + 1);
- //uint8* data = sectionData + dataOffset;
- int offset = dataOffset;
- for (int idx = 0; idx < recordCount; idx++)
- {
- //BF_ASSERT(((offset) & 3) == 0);
- uint8* data = mCvIPIReader.GetTempPtr(offset, 4);
- uint16 trLength = GET(uint16);
- int offsetStart = offset;
- offset += 2;
- data = mCvIPIReader.GetTempPtr(offset, trLength);
- uint8* dataStart = data;
- uint16 trLeafType = GET(uint16);
- //uint8* dataEnd = dataStart + trLength;
- offset += trLength;
- /*
- */
- lfEasy& funcLeaf = *(lfEasy*)dataStart;
- switch (funcLeaf.leaf)
- {
- case LF_FUNC_ID:
- {
- lfFuncId* funcData = (lfFuncId*)dataStart;
- //subprogram->mName = (const char*)funcData->name;
- bool doScope = true;
- /*if (strcmp(curSubprogram->mName, "DispatchToMethod") == 0)
- {
- doScope = true;
- }*/
- if ((funcData->scopeId != 0) && (doScope))
- {
- uint8* data = CvGetTagData(funcData->scopeId, true);
- CvAutoReleaseTempData releaseTempData(this, data);
- lfEasy& leaf = *(lfEasy*)data;
- switch (leaf.leaf)
- {
- case LF_STRING_ID:
- {
- lfStringId& str = *(lfStringId*)data;
- const char* parentStr = (const char*)str.name;
- }
- break;
- case LF_UDT_MOD_SRC_LINE:
- {
- /*auto udtModSrcLine = *(lfUdtModSrcLine*)data;
- auto parentType = CvGetType(udtModSrcLine.type);
- curSubprogram->mParentType = parentType;*/
- }
- break;
- }
- }
- break;
- }
- case LF_MFUNC_ID:
- {
- lfMFuncId* funcData = (lfMFuncId*)dataStart;
- auto parentType = CvGetType(funcData->parentType);
- }
- break;
- }
- mCvIPITagStartMap[idx] = offsetStart;
- }
- mCvIPITagStartMap[recordCount] = offset;
- }
- const char* COFF::CvParseSymbol(int offset, CvSymStreamType symStreamType, addr_target& outAddr)
- {
- const char* retName = NULL;
- int offsetStart = offset;
- uint8* data = mCvSymbolRecordReader.GetTempPtr(offset, 4);
- uint16 symLen = *(uint16*)data;
- bool madeCopy = false;
- data = mCvSymbolRecordReader.GetTempPtr(offset, symLen + 2, false, &madeCopy);
- uint8* dataStart = data;
- uint16 symType = *(uint16*)(data + 2);
- BF_ASSERT(symLen % 4 == 2);
- BF_ASSERT((intptr)data % 4 == 0);
- char* scanName = NULL;
- switch (symType)
- {
- case S_UDT:
- {
- UDTSYM& udt = *(UDTSYM*)dataStart;
- const char* name = (const char*)udt.name;
- #ifdef _DEBUG
- ParseTypeData();
- auto type = CvGetType(udt.typind);
- #endif
- retName = name;
- }
- break;
- case S_PUB32:
- {
- PUBSYM32& pubSym = *(PUBSYM32*)dataStart;
- if (symStreamType != CvSymStreamType_Symbols)
- break;
- BP_ALLOC_T(DbgSymbol);
- DbgSymbol* dbgSymbol = mAlloc.Alloc<DbgSymbol>();
- const char* name = (const char*)mCvSymbolRecordReader.GetPermanentPtr(offsetStart + offsetof(PUBSYM32, name), symLen - offsetof(PUBSYM32, name) + 2); // pubSym.name;
- //OutputDebugStrF("Sym: %s\n", name);
- #ifdef BF_DBG_32
- if ((name != NULL) && (name[0] == '_'))
- name++;
- #endif
- dbgSymbol->mName = name;
- dbgSymbol->mAddress = GetSectionAddr(pubSym.seg, pubSym.off);
- dbgSymbol->mDbgModule = this;
- if ((dbgSymbol->mAddress >= mImageBase) && (dbgSymbol->mAddress < mImageBase + mImageSize))
- {
- if ((dbgSymbol->mAddress & 0xFFFF'0000'0000'0000) == 0)
- mDebugTarget->mSymbolMap.Insert(dbgSymbol);
- }
- else
- {
- NOP;
- }
- mSymbolNameMap.Insert(dbgSymbol);
- outAddr = dbgSymbol->mAddress;
- retName = name;
- }
- break;
- case S_CONSTANT:
- {
- CONSTSYM& constSym = *(CONSTSYM*)dataStart;
- }
- break;
- case S_GDATA32:
- case S_LDATA32:
- {
- uint8* permDataPtr = madeCopy ? mCvSymbolRecordReader.GetPermanentPtr(offsetStart, symLen + 2) : dataStart;
- DATASYM32& dataSym = *(DATASYM32*)permDataPtr;
- if (strcmp((const char*)dataSym.name, "_tls_index") == 0)
- {
- mTLSIndexAddr = GetSectionAddr(dataSym.seg, dataSym.off);
- }
- char* name = (char*)dataSym.name;
- retName = name;
- if (symStreamType == CvSymStreamType_Globals_Scan)
- {
- scanName = (char*)dataSym.name;
- break;
- }
- bool wasBeef = false;
- const char* memberName = CvCheckTargetMatch(name, wasBeef);
- if (memberName == NULL)
- break;
- DbgType* dbgType = CvGetType(dataSym.typind);
- BP_ALLOC_T(DbgVariable);
- DbgVariable* variable = mAlloc.Alloc<DbgVariable>();
- variable->mType = dbgType;
- variable->mLocationData = permDataPtr;
- variable->mLocationLen = 1;
- variable->mIsStatic = true;
- variable->mCompileUnit = mMasterCompileUnit;
- variable->mName = memberName;
- variable->mLinkName = name;
- if (strcmp((const char*)dataSym.name, "__ImageBase") == 0)
- variable->mLinkName = NULL; // Avoid adding to map
- variable->mIsExtern = symType == S_GDATA32;
- variable->mCompileUnit = mGlobalsTargetType->mCompileUnit;
- // Push front so we will find before the original static declaration (that has no memory associated with it)
- mGlobalsTargetType->mMemberList.PushFront(variable);
- if (IsObjectFile())
- {
- if ((variable->mIsExtern) && (variable->mLinkName != NULL))
- mStaticVariables.push_back(variable);
- }
- }
- break;
- case S_GTHREAD32:
- case S_LTHREAD32:
- {
- uint8* permDataPtr = madeCopy ? mCvSymbolRecordReader.GetPermanentPtr(offsetStart, symLen + 2) : dataStart;
- THREADSYM32& threadSym = *(THREADSYM32*)permDataPtr;
- if (symStreamType == CvSymStreamType_Globals_Scan)
- {
- scanName = (char*)threadSym.name;
- break;
- }
- char* name = (char*)threadSym.name;
- retName = name;
- bool wasBeef = false;
- const char* memberName = CvCheckTargetMatch(name, wasBeef);
- if (memberName == NULL)
- break;
- addr_target addr = GetSectionAddr(threadSym.seg, threadSym.off);
- DbgType* dbgType = CvGetType(threadSym.typind);
- BP_ALLOC_T(DbgVariable);
- DbgVariable* variable = mAlloc.Alloc<DbgVariable>();
- variable->mType = dbgType;
- variable->mLocationData = permDataPtr;
- variable->mLocationLen = 1;
- variable->mIsStatic = true;
- variable->mCompileUnit = mMasterCompileUnit;
- variable->mName = memberName;
- variable->mLinkName = name;
- variable->mIsExtern = symType == S_GTHREAD32;
- variable->mCompileUnit = mGlobalsTargetType->mCompileUnit;
- // Push front so we will find before the original static declaration (that has no memory associated with it)
- mGlobalsTargetType->mMemberList.PushFront(variable);
- }
- break;
- case S_PROCREF:
- {
- REFSYM2& refSym = *(REFSYM2*)dataStart;
- if (refSym.imod == 0)
- break;
- char* name = (char*)refSym.name;
- retName = name;
- if (symStreamType == CvSymStreamType_Globals_Scan)
- {
- scanName = (char*)refSym.name;
- break;
- }
- int moduleId = refSym.imod - 1;
- bool wasBeef = false;
- char* memberName = (char*)CvCheckTargetMatch(name, wasBeef);
- if (memberName == NULL)
- break;
- bool wantsCopy = madeCopy;
- bool isIllegal = false;
- for (const char* cPtr = memberName; *cPtr != 0; cPtr++)
- {
- char c = *cPtr;
- if (c == '$')
- {
- if ((strcmp(cPtr, "$CHK") == 0) || (strcmp(cPtr, "$UCHK") == 0))
- {
- auto prevName = memberName;
- memberName = DbgDupString(prevName);
- memberName[cPtr - prevName] = 0;
- wantsCopy = false;
- break;
- }
- else
- isIllegal = true;
- }
- if ((c == '<') || (c == '`'))
- isIllegal = true;
- }
- if (!isIllegal)
- {
- BP_ALLOC_T(DbgMethodNameEntry);
- auto methodNameEntry = mAlloc.Alloc<DbgMethodNameEntry>();
- methodNameEntry->mCompileUnitId = moduleId;
- methodNameEntry->mName = wantsCopy ? DbgDupString(memberName) : memberName;
- mGlobalsTargetType->mMethodNameList.PushBack(methodNameEntry);
- }
- }
- break;
- default:
- //BF_FATAL("Unhandled");
- break;
- }
- if (scanName != NULL)
- {
- //TODO: Remove
- //String origName = name;
- //CvFixupName(name);
- char* lastDblColon = (char*)GetNamespaceEnd(scanName);
- if (lastDblColon != NULL)
- {
- if (mPrevScanName != NULL)
- {
- int namespaceLen = lastDblColon - scanName;
- if (strncmp(scanName, mPrevScanName, namespaceLen + 2) == 0) // +2 includes the ending '::'
- {
- // We've already inserted this namespace
- return retName;
- }
- }
- StringT<256> tempName;
- tempName = String(scanName, lastDblColon - scanName);
- DbgType* dbgType = CvGetTypeOrNamespace((char*)tempName.c_str());
- // *lastDblColon = '\0';
- // DbgType* dbgType = CvGetTypeOrNamespace(scanName);
- // *lastDblColon = ':';
- /*if (strcmp(lastDblColon, "::this") == 0)
- {
- dbgType->mLanguage = DbgLanguage_Beef;
- }*/
- if (dbgType != NULL)
- dbgType->mNeedsGlobalsPopulated = true;
- mPrevScanName = scanName;
- /*const char* methodName = NULL;
- DbgType* dbgParent = NULL;
- if (lastDblColon != NULL)
- {
- *lastDblColon = 0;
- const char* namespaceName = name;
- dbgParent = CvGetTypeOrNamespace(namespaceName);
- methodName = lastDblColon + 2;
- }
- else
- {
- dbgParent = &mMasterCompileUnit->mGlobalType;
- //mStaticVariables.push_back(variable);
- methodName = name;
- }
- if (dbgParent != NULL)
- {
- auto methodNameEntry = mAlloc.Alloc<DbgMethodNameEntry>();
- methodNameEntry->mCompileUnitId = moduleId;
- methodNameEntry->mName = methodName;
- dbgParent->mMethodNameList.PushBack(methodNameEntry);
- }*/
- }
- else
- {
- mMasterCompileUnit->mGlobalType->mNeedsGlobalsPopulated = true;
- }
- }
- return retName;
- }
- uint8* COFF::HandleSymStreamEntries(CvSymStreamType symStreamType, uint8* data, uint8* addrMap)
- {
- uint32 tickStart = BFTickCount();
- GET_INTO(uint32, verSig);
- GET_INTO(uint32, verHdr);
- GET_INTO(int32, sizeHr);
- GET_INTO(int32, sizeBuckets);
- BF_ASSERT(verSig == 0xffffffff);
- BF_ASSERT(verHdr == 0xf12f091a);
- uint8* dataEnd = data + sizeHr;
- uint8* refDataHead = data;
- int entryIdxMax = sizeHr / 8;
- data = dataEnd;
- dataEnd = data + sizeBuckets ;
- int32* hashBucketHead = (int32*)(data + 0x81 * 4);
- int32* hashBucketPtr = hashBucketHead;
- int numRecordsRead = 0;
- #ifdef _DEBUG
- bool verify = false;
- #endif
- if (mIsFastLink)
- return dataEnd; // Format changed
- if (sizeBuckets == 0)
- return dataEnd; // No hash
- std::multimap<addr_target, int> checkAddrMap;
- int bitCount = 0;
- for (int blockIdx = 0; blockIdx < 0x81; blockIdx++)
- {
- GET_INTO(uint32, bits);
- for (int i = 0; i < 32; i++)
- {
- if ((bits & (1 << i)) != 0)
- {
- bitCount++;
- int32 entryStart = *(hashBucketPtr++) / 12;
- int32 entryEnd;
- if ((uint8*)hashBucketPtr != (uint8*)dataEnd)
- entryEnd = *(hashBucketPtr) / 12;
- else
- entryEnd = entryIdxMax;
- BF_ASSERT(entryStart <= entryEnd);
- for (int entryIdx = entryStart; entryIdx < entryEnd; entryIdx++)
- {
- int32 symDataPtr = *(int32*)(refDataHead + entryIdx * 8);
- if (symDataPtr == 0)
- continue;
- addr_target addr = 0;
- const char* symName = CvParseSymbol(symDataPtr - 1, symStreamType, addr);
- #ifdef _DEBUG
- if ((verify) && (addrMap != NULL))
- {
- checkAddrMap.insert(std::make_pair(addr, symDataPtr - 1));
- }
- if ((verify) && (symName != NULL))
- {
- int hashIdx = (blockIdx * 32) + i;
- int wantHash = BlHash::HashStr_PdbV1(symName) % 4096;
- BF_ASSERT(hashIdx == wantHash);
- }
- #endif
- numRecordsRead++;
- }
- }
- }
- }
- #ifdef _DEBUG
- if ((verify) && (addrMap != NULL))
- {
- auto itr = checkAddrMap.begin();
- data = addrMap;
- for (int entryIdx = 0; entryIdx < numRecordsRead; entryIdx++)
- {
- int verifyIdx = GET(int32);
- int actualIdx = itr->second;
- if (actualIdx != verifyIdx)
- {
- OutputDebugStrF("Mismatch #%X %X %X %08X\n", entryIdx, verifyIdx, actualIdx, itr->first);
- }
- ++itr;
- }
- }
- #endif
- BF_ASSERT(numRecordsRead == entryIdxMax);
- //OutputDebugStrF("HandleSymStreamEntries Ticks: %d\n", BFTickCount() - tickStart);
- return dataEnd;
- }
- void COFF::ParseSymbolStream(CvSymStreamType symStreamType)
- {
- if (mCvSymbolRecordStream == 0)
- return;
- BP_ZONE("COFF::ParseSymbolStream");
- if (!mCvSymbolRecordReader.IsSetup())
- CvReadStream(mCvSymbolRecordStream, mCvSymbolRecordReader);
- if ((symStreamType == CvSymStreamType_Globals_Scan) || (symStreamType == CvSymStreamType_Globals_Targeted))
- {
- int streamSize = 0;
- uint8* data;
- if (mCvGlobalSymbolData == NULL)
- mCvGlobalSymbolData = CvReadStream(mCvGlobalSymbolInfoStream, &streamSize);
- data = mCvGlobalSymbolData;
- HandleSymStreamEntries(symStreamType, data, NULL);
- }
- else
- {
- int streamSize = 0;
- uint8* data;
- if (mCvPublicSymbolData == NULL)
- mCvPublicSymbolData = CvReadStream(mCvPublicSymbolInfoStream, &streamSize); // psgsi
- data = mCvPublicSymbolData;
- uint8* sectionData = data;
- GET_INTO(int32, symHashSize);
- GET_INTO(int32, addrMapSize);
- GET_INTO(int32, thunkCount);
- GET_INTO(int32, thunkSize);
- GET_INTO(int32, thunkTableStream);
- GET_INTO(int32, thunkTableOfs);
- GET_INTO(int32, thunkSectCount);
- data = HandleSymStreamEntries(symStreamType, data, data + symHashSize);
- //TODO: Hm, not quite right?
- /*int addrMapEntryCount = addrMapSize / 4;
- for (int addrIdx = 0; addrIdx < addrMapEntryCount; addrIdx++)
- {
- GET_INTO(int32, addrVal);
- }
- for (int thunkIdx = 0; thunkIdx < thunkCount; thunkIdx++)
- {
- GET_INTO(int32, thunkVal);
- }
- for (int sectionIdx = 0; sectionIdx < thunkSectCount; sectionIdx++)
- {
- GET_INTO(int32, ofs);
- GET_INTO(int32, sectNum);
- }*/
- }
- }
- void COFF::Fail(const StringImpl& error)
- {
- DbgModule::Fail(StrFormat("%s in %s", error.c_str(), mPDBPath.c_str()));
- }
- void COFF::SoftFail(const StringImpl& error)
- {
- DbgModule::SoftFail(StrFormat("%s in %s", error.c_str(), mPDBPath.c_str()));
- }
- void COFF::HardFail(const StringImpl& error)
- {
- DbgModule::HardFail(StrFormat("%s in %s", error.c_str(), mPDBPath.c_str()));
- }
- void COFF::ParseGlobalsData()
- {
- if (!mPDBLoaded)
- return;
- if (mParsedGlobalsData)
- return;
- ParseTypeData();
- mParsedGlobalsData = true;
- //gDbgPerfManager->StartRecording();
- int startTypeIdx = (int)mTypes.size();
- ParseSymbolStream(CvSymStreamType_Globals_Scan);
- //gDbgPerfManager->StopRecording(true);
- //int addedTypes = (int)mTypes.size() - startTypeIdx;
- //OutputDebugStrF("Types Added: %d ProcSymCount: %d\n", addedTypes, mProcSymCount);
- }
- void COFF::ParseSymbolData()
- {
- if (!mPDBLoaded)
- return;
- if (mParsedSymbolData)
- return;
- ParseGlobalsData();
- mParsedSymbolData = true;
- ParseSymbolStream(CvSymStreamType_Symbols);
- }
- bool COFF::ParseCv(DataStream& pdbFS, uint8* rootDirData, int pageSize, uint8 wantGuid[16], int32 wantAge)
- {
- BP_ZONE("ParseCv");
- mParsedGlobalsData = false;
- mParsedSymbolData = false;
- mParsedTypeData = false;
- mPopulatedStaticVariables = false;
- InitCvTypes();
- int startingTypeIdx = mTypes.size();
- uint8* data = rootDirData;
- bool failed = false;
- int numStreams = GET(int32);
- if (numStreams == 0)
- return true;
- mCvStreamSizes.Resize(numStreams);
- mCvStreamPtrStartIdxs.Resize(numStreams);
- int streamPages = 0;
- for (int i = 0; i < (int)mCvStreamSizes.size(); i++)
- mCvStreamSizes[i] = GET(int32);
- for (int streamIdx = 0; streamIdx < numStreams; streamIdx++)
- {
- mCvStreamPtrStartIdxs[streamIdx] = streamPages;
- if (mCvStreamSizes[streamIdx] > 0)
- streamPages += (mCvStreamSizes[streamIdx] + pageSize - 1) / pageSize;
- }
- mCvStreamPtrs.Resize(streamPages);
- for (int i = 0; i < (int)mCvStreamPtrs.size(); i++)
- mCvStreamPtrs[i] = GET(int32);
- //////////////////////////////////////////////////////////////////////////
- if (!CvParseHeader(wantGuid, wantAge))
- return false;
- if (!CvParseDBI(wantAge))
- return false;
- if (mParseKind == ParseKind_Header)
- return true;
- ///
- {
- BP_ZONE("COFF::ParseCv_ReadStrTable");
- if (mStringTable.mStream != -1)
- {
- mCvStrTableData = CvReadStream(mStringTable.mStream);
- mStringTable.mStrTable = (const char*)mCvStrTableData + 12;
- }
- }
- for (int compileUnitId = 0; compileUnitId < (int)mCvModuleInfo.size(); compileUnitId++)
- {
- ScanCompileUnit(compileUnitId);
- }
- //////////////////////////////////////////////////////////////////////////
- return true;
- }
- void COFF::ReportMemory(MemReporter* memReporter)
- {
- DbgModule::ReportMemory(memReporter);
- memReporter->AddVec("mCvTypeMap", mCvTypeMap);
- memReporter->AddVec("mCvTagStartMap", mCvTagStartMap);
- memReporter->AddVec("mCvIPITagStartMap", mCvIPITagStartMap);
- memReporter->AddVec(mCvStreamSizes);
- memReporter->AddVec(mCvStreamPtrStartIdxs);
- memReporter->AddVec(mCvStreamPtrs);
- memReporter->AddVec(mCvModuleInfo);
- memReporter->AddVec(mCVSrcFileRefCache);
- if (mCvHeaderData != NULL)
- memReporter->Add("mCvHeaderData", mCvStreamSizes[1]);
- for (auto& entry : mCvTypeSectionData)
- {
- if (entry.mSize != -1)
- memReporter->Add("mCvTypeSectionData", entry.mSize);
- else
- memReporter->Add("mCvTypeSectionData", mCvStreamSizes[2]);
- }
- if (mCvStrTableData != NULL)
- memReporter->Add("mCvStrTableData", mCvStreamSizes[mStringTable.mStream]);
- if (mCvPublicSymbolData != NULL)
- memReporter->Add("mCvPublicSymbolData", mCvStreamSizes[mCvPublicSymbolInfoStream]);
- if (mCvGlobalSymbolData != NULL)
- memReporter->Add("mCvGlobalSymbolData", mCvStreamSizes[mCvGlobalSymbolInfoStream]);
- //memReporter->AddVec(mCvNamespaceStaticEntries);
- }
- bool COFF::TryLoadPDB(const String& pdbPath, uint8 wantGuid[16], int32 wantAge)
- {
- bool isVerifyOnly = mDebugger == NULL;
- if (!mPDBPath.IsEmpty())
- return false; // Already have a PDB loaded
- mCvMappedFile = CreateFileA(pdbPath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
- if (mCvMappedFile == INVALID_HANDLE_VALUE)
- {
- return false;
- }
- BP_ZONE("COFF::TryLoadPDB");
- if (!isVerifyOnly && !(gDebugManager->GetOutputFilterFlags() & BfOutputFilterFlags_SymbolLoadMessages))
- mDebugger->OutputMessage(StrFormat("Loading PDB %s\n", pdbPath.c_str()));
- DWORD highFileSize = 0;
- int fileSize = (int)GetFileSize(mCvMappedFile, &highFileSize);
- mCvMappedFileMapping = CreateFileMapping(mCvMappedFile, NULL, PAGE_READONLY, 0, fileSize, NULL);
- mCvMappedViewOfFile = MapViewOfFile(mCvMappedFileMapping, FILE_MAP_READ, 0, 0, fileSize);
- mCvMappedFileSize = fileSize;
- //FileStream pdbFS;
- //if (!pdbFS.Open(pdbPath, "rb"))
- //return false;
- mPDBPath = pdbPath;
- mCvDataStream = new SafeMemStream(mCvMappedViewOfFile, fileSize, false);
- //Cv_HEADER
- //pdbFS.Read
- char sig[32];
- mCvDataStream->Read(sig, 32);
- if (memcmp(sig, MSF_SIGNATURE_700, 32) != 0)
- {
- if (!isVerifyOnly)
- Fail("PDB signature error");
- return false;
- }
- BfLogDbg("Loading PDB %s\n", pdbPath.c_str());
- BP_ZONE_F("LoadCv %s", pdbPath.c_str());
- int pageSize = mCvDataStream->ReadInt32();
- int fpmPageNum = mCvDataStream->ReadInt32();
- int totalPageCount = mCvDataStream->ReadInt32();
- int rootDirSize = mCvDataStream->ReadInt32();
- int unknown = mCvDataStream->ReadInt32();
- int rootDirPtrs[NUM_ROOT_DIRS];
- mCvDataStream->ReadT(rootDirPtrs);
- bool failed = false;
- mCvPageSize = pageSize;
- for (int i = 0; i < 31; i++)
- {
- if (mCvPageSize < (1 << i))
- break;
- mCvPageBits = i;
- }
- int rootPageCount = (rootDirSize + pageSize - 1) / pageSize;
- int rootPointersPages = (rootPageCount*sizeof(int32) + pageSize - 1) / pageSize;
- int rootPageIdx = 0;
- Array<uint8> rootDirData;
- rootDirData.Resize(rootPageCount * pageSize);
- for (int rootDirIdx = 0; rootDirIdx < rootPointersPages; rootDirIdx++)
- {
- int rootDirPtr = rootDirPtrs[rootDirIdx];
- if (rootDirPtr == 0)
- continue;
- mCvDataStream->SetPos(rootDirPtr * pageSize);
- int32 rootPages[1024];
- mCvDataStream->Read(rootPages, pageSize);
- for (int subRootPageIdx = 0; subRootPageIdx < pageSize / 4; subRootPageIdx++, rootPageIdx++)
- {
- if (rootPageIdx >= rootPageCount)
- break;
- int rootPagePtr = rootPages[subRootPageIdx];
- if (rootPagePtr == 0)
- break;
- mCvDataStream->SetPos(rootPagePtr * pageSize);
- mCvDataStream->Read(&rootDirData[rootPageIdx * pageSize], pageSize);
- }
- }
- int startingTypeIdx = mTypes.size();
- if (!ParseCv(*mCvDataStream, &rootDirData[0], pageSize, wantGuid, wantAge))
- {
- //mDebugger->OutputMessage("Failed to parse PDB\n");
- return false;
- }
- if (mCvDataStream->mFailed)
- return false;
- //OutputDebugStrF("COFF::TryLoadPDB %s\n", pdbPath.c_str());
- if (!isVerifyOnly)
- mDebugger->ModuleChanged(this);
- mPDBLoaded = true;
- return true;
- }
- void COFF::ClosePDB()
- {
- delete mCvDataStream;
- mCvDataStream = NULL;
- delete mCvHeaderData;
- mCvHeaderData = NULL;
- delete mCvStrTableData;
- mCvStrTableData = NULL;
- for (auto& entry : mCvTypeSectionData)
- delete entry.mData;
- mCvTypeSectionData.Clear();
- for (auto& entry : mCvCompileUnitData)
- delete entry.mData;
- mCvCompileUnitData.Clear();
- delete mCvPublicSymbolData;
- mCvPublicSymbolData = NULL;
- delete mCvGlobalSymbolData;
- mCvGlobalSymbolData = NULL;
- delete mNewFPOData;
- mNewFPOData = NULL;
- if (mCvMappedViewOfFile != NULL)
- ::UnmapViewOfFile(mCvMappedViewOfFile);
- mCvMappedViewOfFile = NULL;
- if (mCvMappedFileMapping != INVALID_HANDLE_VALUE)
- ::CloseHandle(mCvMappedFileMapping);
- mCvMappedFileMapping = NULL;
- if (mCvMappedFile != INVALID_HANDLE_VALUE)
- ::CloseHandle(mCvMappedFile);
- mCvMappedFile = NULL;
- for (auto kv : mHotLibMap)
- delete kv.mValue;
- mHotLibMap.Clear();
- mHotLibSymMap.Clear();
- delete mEmitSourceFile;
- mEmitSourceFile = NULL;
- }
- bool COFF::LoadPDB(const String& pdbPath, uint8 wantGuid[16], int32 wantAge)
- {
- if (mDebugTarget->mTargetBinary == this)
- {
- // If we don't have to load the debug symbols from a remote source or the cache
- // then we assume we were locally built, meaning we don't attempt to auto-load
- // any symbols since we assume we already have what we built for all referenced
- // dlls
- mDebugTarget->mWasLocallyBuilt = FileExists(pdbPath);
- }
- memcpy(mWantPDBGuid, wantGuid, 16);
- mWantAge = wantAge;
- mDbgSymRequest = mDebugger->mDbgSymSrv.CreateRequest(mFilePath, pdbPath, wantGuid, wantAge);
- mDbgSymRequest->SearchLocal();
- if (!mDbgSymRequest->mFinalPDBPath.IsEmpty())
- {
- TryLoadPDB(mDbgSymRequest->mFinalPDBPath, wantGuid, wantAge);
- mDebugger->mDbgSymSrv.ReleaseRequest(mDbgSymRequest);
- mDbgSymRequest = NULL;
- }
- else
- mMayBeOld = true;
- String fileName = GetFileName(mFilePath);
- mWantsAutoLoadDebugInfo = !mDebugTarget->mWasLocallyBuilt;
- if ((fileName.Equals("KERNEL32.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("KERNELBASE.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("USER32.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("SHELL32.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("GDI32.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("GDI32FULL.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("NTDLL.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("COMDLG32.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("MSVCRT.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("COMBASE.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("UCRTBASE.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("RPCRT4.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("BCRYPTPRIMITIVES.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("SHCORE.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("WIN32U.DLL", String::CompareKind_OrdinalIgnoreCase)) ||
- (fileName.Equals("MSWSOCK.DLL", String::CompareKind_OrdinalIgnoreCase)))
- {
- mWantsAutoLoadDebugInfo = false;
- }
- /*if (pdbPath.IndexOf('\\') != -1) // Do we have an absolute path at all?
- {
- if (TryLoadPDB(pdbPath, wantGuid, wantAge))
- return true;
- ClosePDB();
- }*/
- //char exePath[MAX_PATH];
- //GetModuleFileNameA(NULL, exePath, sizeof(exePath));
- /*String checkPath = ::GetFileDir(mFilePath);
- checkPath += "/";
- checkPath += GetFileName(pdbPath);
- if (!FileNameEquals(checkPath, pdbPath))
- {
- if (TryLoadPDB(checkPath, wantGuid, wantAge))
- return true;
- }*/
- return false;
- }
- bool COFF::CheckSection(const char* name, uint8* sectionData, int sectionSize)
- {
- if (strcmp(name, ".debug$T") == 0)
- {
- mDbgFlavor = DbgFlavor_MS;
- DbgSectionData entry;
- entry.mData = sectionData;
- entry.mSize = sectionSize;
- mCvTypeSectionData.Add(entry);
- return true;
- }
- if (strcmp(name, ".debug$S") == 0)
- {
- DbgSectionData entry;
- entry.mData = sectionData;
- entry.mSize = sectionSize;
- mCvCompileUnitData.Add(entry);
- return true;
- }
- return false;
- }
- void COFF::ProcessDebugInfo()
- {
- BP_ZONE("COFF::ProcessDebugInfo");
- if ((!mCvTypeSectionData.IsEmpty()) && (!mCvCompileUnitData.IsEmpty()))
- {
- auto linkedModule = (COFF*)GetLinkedModule();
- int startingTypeIdx = (int)linkedModule->mTypes.size();
- InitCvTypes();
- for (auto entry : mCvTypeSectionData)
- {
- uint8* data = entry.mData;
- GET_INTO(uint32, infoType);
- BF_ASSERT(infoType == CV_SIGNATURE_C13);
- CvInitStreamRaw(mCvTypeSectionReader, entry.mData + 4, entry.mSize - 4);
- ParseTypeData(mCvTypeSectionReader, 0);
- }
- FixTypes(startingTypeIdx);
- linkedModule->MapTypes(startingTypeIdx);
- CvCompileUnit* compileUnit = NULL;
- for (auto entry : mCvCompileUnitData)
- {
- compileUnit = ParseCompileUnit(NULL, compileUnit, entry.mData, entry.mSize);
- }
- if (compileUnit != NULL)
- {
- compileUnit->mLanguage = DbgLanguage_Beef;
- mMasterCompileUnit->mLanguage = DbgLanguage_Beef;
- MapCompileUnitMethods(compileUnit);
- mEndTypeIdx = (int)linkedModule->mTypes.size();
- }
- }
- }
- void COFF::FinishHotSwap()
- {
- DbgModule::FinishHotSwap();
- mTypeMap.Clear();
- }
- intptr COFF::EvaluateLocation(DbgSubprogram* dwSubprogram, const uint8* locData, int locDataLen, WdStackFrame* stackFrame, DbgAddrType* outAddrType, DbgEvalLocFlags flags)
- {
- if (mDbgFlavor == DbgFlavor_GNU)
- return DbgModule::EvaluateLocation(dwSubprogram, locData, locDataLen, stackFrame, outAddrType, flags);
- if ((locDataLen == 0) && (locData != NULL))
- {
- // locData is actually a string, the aliased name
- *outAddrType = DbgAddrType_Alias;
- return (intptr)locData;
- }
- addr_target pc = 0;
- if (stackFrame != NULL)
- {
- // Use 'GetSourcePC', which will offset the RSP when we're not at the top position of the call stack, since RSP will be the
- // return address in those cases
- pc = stackFrame->GetSourcePC();
- }
- int inlineDepth = 0;
- uint8* data = (uint8*)locData;
- for (int locIdx = 0; locIdx < locDataLen; locIdx++)
- {
- uint8* dataStart = data;
- GET_INTO(uint16, symLen);
- uint8* dataEnd = data + symLen;
- GET_INTO(uint16, symType);
- CV_LVAR_ADDR_RANGE* rangeInfo = NULL;
- CV_LVAR_ADDR_GAP* gapsInfo = NULL;
- addr_target result = 0;
- if (inlineDepth > 0)
- {
- if (symType == S_INLINESITE)
- inlineDepth++;
- else if (symType == S_INLINESITE_END)
- inlineDepth--;
- data = dataEnd;
- continue;
- }
- bool handled = false;
- switch (symType)
- {
- case S_GDATA32:
- case S_LDATA32:
- {
- DATASYM32& dataSym = *(DATASYM32*)dataStart;
- *outAddrType = DbgAddrType_Target;
- return GetSectionAddr(dataSym.seg, dataSym.off);
- }
- break;
- case S_BPREL32:
- {
- BPRELSYM32* bpRel32 = (BPRELSYM32*)dataStart;
- #if BF_DBG_32
- *outAddrType = DbgAddrType_Target;
- return stackFrame->mRegisters.mIntRegs.ebp + (int)bpRel32->off;
- #else
- *outAddrType = DbgAddrType_Target;
- return stackFrame->mRegisters.mIntRegs.rbp + (int)bpRel32->off;
- #endif
- }
- break;
- case S_LTHREAD32:
- case S_GTHREAD32:
- {
- THREADSYM32& threadSym = *(THREADSYM32*)dataStart;
- int tlsIndex = mDebugger->ReadMemory<int>(mTLSIndexAddr);
- addr_target tlsEntry = mDebugger->GetTLSOffset(tlsIndex);
- *outAddrType = DbgAddrType_Target;
- return threadSym.off + tlsEntry;
- }
- break;
- case S_REGISTER:
- {
- REGSYM* regSym = (REGSYM*)dataStart;
- *outAddrType = DbgAddrType_Register;
- int regNum = CvConvRegNum(regSym->reg);
- return regNum;
- }
- break;
- case S_REGREL32:
- {
- REGREL32* regRel32 = (REGREL32*)dataStart;
- *outAddrType = DbgAddrType_Target;
- int regNum = CvConvRegNum(regRel32->reg);
- return stackFrame->mRegisters.mIntRegsArray[regNum] + regRel32->off;
- }
- break;
- case S_DEFRANGE_REGISTER:
- {
- DEFRANGESYMREGISTER& defRangeReg = *(DEFRANGESYMREGISTER*)dataStart;
- *outAddrType = DbgAddrType_Register;
- result = CvConvRegNum(defRangeReg.reg);
- rangeInfo = &defRangeReg.range;
- gapsInfo = &defRangeReg.gaps[0];
- }
- break;
- case S_DEFRANGE_FRAMEPOINTER_REL:
- {
- DEFRANGESYMFRAMEPOINTERREL& defRangeFPRel = *(DEFRANGESYMFRAMEPOINTERREL*)dataStart;
- DbgSubprogram::LocalBaseRegKind baseReg = ((flags & DbgEvalLocFlag_IsParam) != 0) ? dwSubprogram->mParamBaseReg : dwSubprogram->mLocalBaseReg;
- *outAddrType = DbgAddrType_Target;
- #ifdef BF_DBG_64
- if (baseReg == DbgSubprogram::LocalBaseRegKind_RSP)
- result = stackFrame->mRegisters.mIntRegsArray[X64Reg_RSP] + defRangeFPRel.offFramePointer;
- else if (baseReg == DbgSubprogram::LocalBaseRegKind_R13)
- result = stackFrame->mRegisters.mIntRegsArray[X64Reg_R13] + defRangeFPRel.offFramePointer;
- else
- result = stackFrame->mRegisters.mIntRegsArray[X64Reg_RBP] + defRangeFPRel.offFramePointer;
- #else
- if (baseReg == DbgSubprogram::LocalBaseRegKind_VFRAME)
- result = stackFrame->mRegisters.mIntRegsArray[X86Reg_ESP] + dwSubprogram->mFrameBaseLen + defRangeFPRel.offFramePointer;
- else if (baseReg == DbgSubprogram::LocalBaseRegKind_EBX)
- result = stackFrame->mRegisters.mIntRegsArray[X86Reg_EBX] + defRangeFPRel.offFramePointer;
- else
- result = stackFrame->mRegisters.mIntRegsArray[X86Reg_EBP] + defRangeFPRel.offFramePointer;
- #endif
- rangeInfo = &defRangeFPRel.range;
- gapsInfo = &defRangeFPRel.gaps[0];
- }
- break;
- case S_DEFRANGE_SUBFIELD_REGISTER:
- {
- DEFRANGESYMSUBFIELDREGISTER& defRangeSubfieldReg = *(DEFRANGESYMSUBFIELDREGISTER*)dataStart;
- *outAddrType = DbgAddrType_Target;
- int regNum = CvConvRegNum(defRangeSubfieldReg.reg);
- result = stackFrame->mRegisters.mIntRegsArray[regNum] + defRangeSubfieldReg.offParent;
- rangeInfo = &defRangeSubfieldReg.range;
- gapsInfo = &defRangeSubfieldReg.gaps[0];
- }
- break;
- case S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE:
- {
- DEFRANGESYMFRAMEPOINTERREL_FULL_SCOPE& defFPRel = *(DEFRANGESYMFRAMEPOINTERREL_FULL_SCOPE*)dataStart;
- #ifdef BF_DBG_64
- int regNum = X64Reg_RSP;
- #else
- int regNum = X86Reg_ESP;
- #endif
- *outAddrType = DbgAddrType_Target;
- result = stackFrame->mRegisters.mIntRegsArray[regNum] + defFPRel.offFramePointer;
- return result;
- }
- break;
- case S_DEFRANGE_REGISTER_REL:
- {
- DEFRANGESYMREGISTERREL& defRangeRegRel = *(DEFRANGESYMREGISTERREL*)dataStart;
- *outAddrType = DbgAddrType_Target;
- int regNum = CvConvRegNum(defRangeRegRel.baseReg);
- result = stackFrame->mRegisters.mIntRegsArray[regNum] + defRangeRegRel.offBasePointer;
- rangeInfo = &defRangeRegRel.range;
- gapsInfo = &defRangeRegRel.gaps[0];
- }
- break;
- case S_PROCREF:
- {
- // Not currently handled.
- }
- break;
- case S_INLINESITE:
- {
- inlineDepth++;
- }
- break;
- case S_FILESTATIC:
- {
- FILESTATICSYM& fileStaticSym = *(FILESTATICSYM*)dataStart;
- }
- break;
- default:
- if (!mFailed)
- SoftFail(StrFormat("Unknown symbol type '0x%X' in EvaluateLocation", symType));
- return 0;
- }
- if (rangeInfo != NULL)
- {
- auto rangeStart = GetSectionAddr(rangeInfo->isectStart, rangeInfo->offStart);
- if ((pc >= rangeStart) && (pc < rangeStart + rangeInfo->cbRange))
- {
- bool inRange = true;
- while ((uint8*)gapsInfo < (uint8*)dataEnd)
- {
- if ((pc >= rangeStart + gapsInfo->gapStartOffset) && (pc < rangeStart + gapsInfo->gapStartOffset + gapsInfo->cbRange))
- {
- inRange = false;
- break;
- }
- gapsInfo++;
- }
- if (inRange)
- return result;
- }
- }
- data = dataEnd;
- }
- if ((dwSubprogram != NULL) && (dwSubprogram->mIsOptimized))
- *outAddrType = DbgAddrType_OptimizedOut;
- else
- *outAddrType = DbgAddrType_NoValue;
- return 0;
- }
- bool COFF::CanGetOldSource()
- {
- return mCvSrcSrvStream != -1;
- }
- String COFF::GetOldSourceCommand(const StringImpl& path)
- {
- if (mCvSrcSrvStream == -1)
- return "";
- int outSize;
- uint8* data = CvReadStream(mCvSrcSrvStream, &outSize);
- String cmdBlock = String((char*)data, outSize);
- delete data;
- bool inFileSection = false;
- Dictionary<String, String> defs;
- enum _SectType
- {
- _SectType_None,
- _SectType_Ini,
- _SectType_Variables,
- _SectType_SourceFiles
- };
- _SectType sectType = _SectType_None;
- //
- {
- AutoCrit autoCrit(gDebugManager->mCritSect);
- defs["TARG"] = gDebugManager->mSymSrvOptions.mSourceServerCacheDir;
- }
- std::function<void (String&)> _Expand = [&](String& str)
- {
- for (int i = 0; i < str.length(); i++)
- {
- if (str[i] == '%')
- {
- int endIdx = str.IndexOf('%', i + 1);
- if (endIdx != -1)
- {
- String varName = ToUpper(str.Substring(i + 1, endIdx - i - 1));
- if (((endIdx < str.length() - 1) && (str[endIdx + 1] == '(')) &&
- ((varName == "FNVAR") || (varName == "FNBKSL") || (varName == "FNFILE")))
- {
- int closePos = str.IndexOf(')', endIdx + 2);
- if (closePos != -1)
- {
- String paramStr = str.Substring(endIdx + 2, closePos - endIdx - 2);
- _Expand(paramStr);
- if (varName == "FNVAR")
- {
- paramStr = defs[paramStr];
- }
- else
- {
- if (varName == "FNBKSL")
- {
- paramStr.Replace("/", "\\");
- }
- else if (varName == "FNFILE")
- {
- paramStr = GetFileName(paramStr);
- }
- }
- str.Remove(i, closePos - i + 1);
- str.Insert(i, paramStr);
- i--;
- }
- }
- else
- {
- auto replaceStr = defs[varName];
- if (!replaceStr.IsEmpty())
- {
- str.Remove(i, endIdx - i + 1);
- str.Insert(i, replaceStr);
- i--;
- }
- }
- }
- }
- }
- };
- int linePos = 0;
- while (true)
- {
- int crPos = cmdBlock.IndexOf('\n', linePos);
- if (crPos == -1)
- break;
- int lineEndPos = crPos;
- if (cmdBlock[lineEndPos - 1] == '\r')
- lineEndPos--;
- String line = cmdBlock.Substring(linePos, lineEndPos - linePos);
- if (line.StartsWith("SRCSRV: ini -"))
- {
- sectType = _SectType_Ini;
- }
- else if (line.StartsWith("SRCSRV: variables -"))
- {
- sectType = _SectType_Variables;
- }
- else if (line.StartsWith("SRCSRV: source files -"))
- {
- sectType = _SectType_SourceFiles;
- }
- else if (line.StartsWith("SRCSRV: end -"))
- {
- break;
- }
- else
- {
- switch (sectType)
- {
- case _SectType_Ini:
- case _SectType_Variables:
- {
- int eqPos = line.IndexOf('=');
- if (eqPos != -1)
- {
- defs[ToUpper(line.Substring(0, eqPos))] = line.Substring(eqPos + 1);
- }
- break;
- }
- case _SectType_SourceFiles:
- {
- int curStrIdx = 0;
- int curStrPos = 0;
- StringT<256> var;
- bool matches = false;
- while (curStrPos < (int)line.length())
- {
- int starPos = line.IndexOf('*', curStrPos);
- if (starPos == -1)
- starPos = line.length();
- //var = line.Substring(curStrPos, starPos - curStrPos);
- var.Clear();
- var.Insert(0, line.c_str() + curStrPos, starPos - curStrPos);
- if (curStrIdx == 0)
- {
- matches = FileNameEquals(var, path);
- if (!matches)
- break;
- }
- defs[StrFormat("VAR%d", curStrIdx + 1)] = var;
- curStrIdx++;
- curStrPos = starPos + 1;
- }
- if (!matches)
- break;
- String target = defs["SRCSRVTRG"];
- String cmd = defs["SRCSRVCMD"];
- String env = defs["SRCSRVENV"];
- _Expand(target);
- _Expand(cmd);
- _Expand(env);
- String retVal;
- if ((cmd.IsEmpty()) && (target.StartsWith("HTTP", StringImpl::CompareKind_OrdinalIgnoreCase)))
- {
- String localFile;
- BfpFileResult result;
- BFP_GETSTR_HELPER(localFile, result, BfpFile_GetTempPath(__STR, __STRLEN, &result));
- int dotPos = target.IndexOf("://");
- if (dotPos != -1)
- {
- localFile.Append("SymbolCache\\src\\");
- localFile.Append(StringView(target, dotPos + 3));
- localFile.Replace("/", "\\");
- }
- retVal = localFile;
- retVal += "\n";
- retVal += target;
- retVal += "\n";
- retVal += env;
- }
- else if (!cmd.IsWhitespace())
- {
- retVal = target;
- retVal += "\n";
- retVal += cmd;
- retVal += "\n";
- retVal += env;
- }
- return retVal;
- }
- break;
- }
- }
- linePos = crPos + 1;
- }
- return "";
- }
- bool COFF::GetEmitSource(const StringImpl& filePath, String& outText)
- {
- if (!filePath.StartsWith("$Emit"))
- return false;
- if (mEmitSourceFile == NULL)
- {
- mEmitSourceFile = new ZipFile();
- String zipPath = mPDBPath;
- int dotPos = zipPath.LastIndexOf('.');
- zipPath.RemoveToEnd(dotPos);
- zipPath.Append("__emit.zip");
- if (!mEmitSourceFile->Open(zipPath))
- {
- if (mCvEmitStream == -1)
- return "";
- int outSize;
- uint8* data = CvReadStream(mCvEmitStream, &outSize);
- FileStream fileStream;
- fileStream.Open(zipPath, "wb");
- fileStream.Write(data, outSize);
- fileStream.Close();
- delete data;
- mEmitSourceFile->Open(zipPath);
- }
- }
- if (mEmitSourceFile->IsOpen())
- {
- String usePath = filePath;
- if (usePath.StartsWith("$Emit"))
- {
- int dollarPos = usePath.IndexOf('$', 1);
- usePath.Remove(0, dollarPos + 1);
- }
- usePath = EncodeFileName(usePath);
- usePath.Append(".bf");
- Array<uint8> data;
- if (mEmitSourceFile->Get(usePath, data))
- {
- outText.Insert(outText.mLength, (char*)data.mVals, data.mSize);
- return true;
- }
- }
- return false;
- }
- bool COFF::HasPendingDebugInfo()
- {
- if (mDbgSymRequest == NULL)
- return false;
- return true;
- }
- void COFF::PreCacheImage()
- {
- if (!mDebugger->IsMiniDumpDebugger())
- return;
- if (mLoadState != DbgModuleLoadState_NotLoaded)
- return;
- auto miniDumpDebugger = (MiniDumpDebugger*)mDebugger;
- if (mOrigImageData != NULL)
- return;
- mDebugger->mDbgSymSrv.PreCacheImage(mFilePath, mTimeStamp, mImageSize);
- }
- void COFF::PreCacheDebugInfo()
- {
- if (mDbgSymRequest == NULL)
- return;
- if (mDbgSymRequest->mInProcess)
- return;
- bool hasDebugInfo = false;
- mDbgSymRequest->SearchCache();
- if (mDbgSymRequest->mFinalPDBPath.IsEmpty())
- {
- if (GetCurrentThreadId() == mDebugger->mDebuggerThreadId)
- {
- mDbgSymRequest->mIsPreCache = true;
- mDbgSymRequest->SearchSymSrv();
- mDbgSymRequest->mIsPreCache = false;
- mDbgSymRequest->mFailed = false;
- }
- }
- }
- bool COFF::LoadModuleImage(const StringImpl& imagePath)
- {
- if (!mDebugger->IsMiniDumpDebugger())
- return false;
- auto miniDumpDebugger = (MiniDumpDebugger*)mDebugger;
- if (!imagePath.IsEmpty())
- {
- MappedFile* mappedFile = miniDumpDebugger->MapModule(this, imagePath);
- mMappedImageFile = mappedFile;
- if (mappedFile != NULL)
- {
- MemStream memStream(mappedFile->mData, mappedFile->mFileSize, false);
- ReadCOFF(&memStream, DbgModuleKind_Module);
- mOrigImageData = new DbgModuleMemoryCache(mImageBase, mImageSize);
- }
- }
- if (mOrigImageData == NULL) // Failed?
- {
- mLoadState = DbgModuleLoadState_Failed;
- return false;
- }
- return true;
- }
- bool COFF::RequestImage()
- {
- if (!mDebugger->IsMiniDumpDebugger())
- return false;
- if (mLoadState != DbgModuleLoadState_NotLoaded)
- return false;
- auto miniDumpDebugger = (MiniDumpDebugger*)mDebugger;
- if (mOrigImageData != NULL)
- return false;
- if (GetCurrentThreadId() == mDebugger->mDebuggerThreadId)
- {
- auto prevRunState = mDebugger->mRunState;
- mDebugger->mRunState = RunState_SearchingSymSrv;
- mDebugger->mDebugManager->mOutMessages.push_back(StrFormat("symsrv Searching for image '%s'", mFilePath.c_str()));
- auto dbgSymRequest = mDebugger->mDbgSymSrv.CreateRequest();
- mDebugger->mActiveSymSrvRequest = dbgSymRequest;
- BF_ASSERT(mDebugger->mDebugManager->mCritSect.mLockCount == 1);
- mDebugger->mDebugManager->mCritSect.Unlock();
- // We unlock to allow the IDE to continue updating while we search
- String imagePath = dbgSymRequest->SearchForImage(mFilePath, mTimeStamp, mImageSize);
- mDebugger->mDebugManager->mCritSect.Lock();
- delete mDebugger->mActiveSymSrvRequest;
- mDebugger->mActiveSymSrvRequest = NULL;
- mDebugger->mRunState = prevRunState;
- return LoadModuleImage(imagePath);
- }
- else
- {
- return false;
- }
- return false;
- }
- bool COFF::RequestDebugInfo(bool allowRemote)
- {
- if (mDbgSymRequest == NULL)
- return false;
- if (mDbgSymRequest->mInProcess)
- return false;
- bool hasDebugInfo = false;
- mDbgSymRequest->SearchCache();
- if (mDbgSymRequest->mFinalPDBPath.IsEmpty())
- {
- if (!allowRemote)
- return false;
- if (GetCurrentThreadId() == mDebugger->mDebuggerThreadId)
- {
- auto prevRunState = mDebugger->mRunState;
- mDebugger->mRunState = RunState_SearchingSymSrv;
- mDbgSymRequest->mInProcess = true;
- mDebugger->mActiveSymSrvRequest = mDbgSymRequest;
- BF_ASSERT(mDebugger->mDebugManager->mCritSect.mLockCount == 1);
- mDebugger->mDebugManager->mCritSect.Unlock();
- mDbgSymRequest->SearchSymSrv();
- mDebugger->mDebugManager->mCritSect.Lock();
- mDebugger->mActiveSymSrvRequest = NULL;
- mDbgSymRequest->mInProcess = false;
- mDebugger->mRunState = prevRunState;
- }
- else
- {
- return false;
- }
- }
- if (!mDbgSymRequest->mFinalPDBPath.IsEmpty())
- hasDebugInfo = TryLoadPDB(mDbgSymRequest->mFinalPDBPath, mDbgSymRequest->mWantGuid, mDbgSymRequest->mWantAge);
- mDebugger->mDbgSymSrv.ReleaseRequest(mDbgSymRequest);
- mDbgSymRequest = NULL;
- return hasDebugInfo;
- }
- bool COFF::WantsAutoLoadDebugInfo()
- {
- return mWantsAutoLoadDebugInfo;
- }
- bool COFF::DbgIsStrMutable(const char* str)
- {
- if (IsObjectFile())
- {
- return GetLinkedModule()->DbgIsStrMutable(str);
- }
- if (mCvMappedViewOfFile == NULL)
- return true;
- if ((str >= (const char*)mCvMappedViewOfFile) && (str < (const char*)mCvMappedViewOfFile + mCvMappedFileSize))
- return false;
- return true;
- }
- // We don't need this for Beef linkining because of "FORCELINK_", but we DO need it for
- // libraries we linked to, either in the DLL or in the LIB
- addr_target COFF::LocateSymbol(const StringImpl& name)
- {
- BP_ZONE("COFF::LocateSymbol");
- BfLogDbg("COFF:LocateSymbol '%s'\n", name.c_str());
- if (mHotLibMap.IsEmpty())
- {
- for (auto moduleInfo : mCvModuleInfo)
- {
- if (moduleInfo->mObjectName == NULL)
- continue;
- String libName = moduleInfo->mObjectName;
- if (!libName.EndsWith(".lib", StringImpl::CompareKind_OrdinalIgnoreCase))
- continue;
- CvLibInfo** libInfoPtr;
- if (!mHotLibMap.TryAdd(libName, NULL, &libInfoPtr))
- continue;
- CvLibInfo* libInfo = new CvLibInfo();
- *libInfoPtr = libInfo;
- if (!libInfo->mLibFile.Init(libName, false))
- continue;
- for (auto kv : libInfo->mLibFile.mOldEntries)
- {
- auto libEntry = kv.mValue;
- while (libEntry != NULL)
- {
- for (auto sym : libEntry->mSymbols)
- {
- #ifdef BF_DBG_32
- if (sym.StartsWith('_'))
- mHotLibSymMap[sym.Substring(1)] = libEntry;
- else
- // Fallthrough
- #endif
- mHotLibSymMap[sym] = libEntry;
- }
- libEntry = libEntry->mNextWithSameName;
- }
- }
- }
- }
- BeLibEntry* libEntry;
- if (!mHotLibSymMap.TryGetValue(name, &libEntry))
- return 0;
- if (libEntry->mLength == -1)
- {
- BfLogDbg("Already loaded obj '%s' in '%s'\n", libEntry->mName.c_str(), libEntry->mLibFile->mFilePath.c_str());
- // We already tried to load this
- return 0;
- }
- auto fileExt = GetFileExtension(libEntry->mName);
- if (String::Equals(fileExt, ".dll", StringImpl::CompareKind_OrdinalIgnoreCase))
- {
- for (auto dbgModule : mDebugTarget->mDbgModules)
- {
- if (String::Equals(libEntry->mName, dbgModule->mDisplayName))
- {
- dbgModule->ParseSymbolData();
- auto entry = dbgModule->mSymbolNameMap.Find(name.c_str());
- if (entry == NULL)
- continue;
- addr_target callTarget;
- #ifdef BF_DBG_32
- callTarget = entry->mValue->mAddress;
- #else
- BfLogDbg("Setting up DLL thunk for '%s' in '%s'\n", name.c_str(), dbgModule->mFilePath.c_str());
- int wantHotSize = 16;
- if (mHotThunkDataLeft < wantHotSize)
- {
- int allocSize = 4096;
- mDebugger->ReserveHotTargetMemory(allocSize);
- int outAllocSize = 0;
- mHotThunkCurAddr = mDebugger->AllocHotTargetMemory(allocSize, true, false, &outAllocSize);
- mHotThunkDataLeft = outAllocSize;
- }
- int outAllocSize = 0;
- addr_target hotAddr = mHotThunkCurAddr;
- mHotThunkCurAddr += wantHotSize;
- mHotThunkDataLeft -= wantHotSize;
- #pragma pack(push, 1)
- struct HotLongJmpOp
- {
- uint8 mOpCode0;
- uint8 mOpCode1;
- int32 mRIPRel;
- uint64 mTarget;
- };
- #pragma pack(pop)
- HotLongJmpOp jumpOp;
- jumpOp.mOpCode0 = 0xFF;
- jumpOp.mOpCode1 = 0x25;
- jumpOp.mRIPRel = 0;
- jumpOp.mTarget = entry->mValue->mAddress;
- mDebugger->WriteMemory(hotAddr, jumpOp);
- callTarget = hotAddr;
- #endif
- char* dupStr = (char*)mAlloc.AllocBytes(name.length() + 1);
- memcpy(dupStr, name.c_str(), name.length());
- DbgSymbol* dwSymbol = mAlloc.Alloc<DbgSymbol>();
- dwSymbol->mDbgModule = this;
- dwSymbol->mName = dupStr;
- dwSymbol->mAddress = callTarget;
- mSymbolNameMap.Insert(dwSymbol);
- return callTarget;
- }
- }
- return 0;
- }
- BfLogDbg("Loading obj '%s' in '%s'\n", libEntry->mName.c_str(), libEntry->mLibFile->mFilePath.c_str());
- // #ifdef _DEBUG
- // FILE* fpTest = fopen("c:\\temp\\locateSym.obj", "wb");
- //
- // uint8* data = new uint8[libEntry->mLength];
- //
- // fseek(libEntry->mLibFile->mOldFileStream.mFP, libEntry->mOldDataPos + sizeof(BeLibMemberHeader), SEEK_SET);
- // fread(data, 1, libEntry->mLength, libEntry->mLibFile->mOldFileStream.mFP);
- // fwrite(data, 1, libEntry->mLength, fpTest);
- // fclose(fpTest);
- // delete data;
- // #endif
- FileSubStream fileStream;
- fileStream.mFP = libEntry->mLibFile->mOldFileStream.mFP;
- fileStream.mOffset = libEntry->mOldDataPos + sizeof(BeLibMemberHeader);
- fileStream.mSize = libEntry->mLength;
- fileStream.SetPos(0);
- DbgModule* dbgModule = new COFF(mDebugger->mDebugTarget);
- dbgModule->mHotIdx = mDebugger->mActiveHotIdx;
- dbgModule->mFilePath = libEntry->mName + "@" + libEntry->mLibFile->mFilePath;
- bool success = dbgModule->ReadCOFF(&fileStream, DbgModuleKind_FromLocateSymbol);
- fileStream.mFP = NULL;
- // Mark as loaded
- libEntry->mLength = -1;
- if (!success)
- {
- BfLogDbg("Failed\n");
- Fail(StrFormat("Debugger failed to read binary '%s' in '%s'", libEntry->mName.c_str(), libEntry->mLibFile->mFilePath.c_str()));
- delete dbgModule;
- return 0;
- }
- mDebugger->mDebugTarget->AddDbgModule(dbgModule);
- auto symbolEntry = mSymbolNameMap.Find(name.c_str());
- if (symbolEntry != NULL)
- return symbolEntry->mValue->mAddress;
- return 0;
- }
- void COFF::ParseFrameDescriptors(uint8* data, int size, addr_target baseAddr)
- {
- uint8* ptr = data;
- uint8* endPtr = data + size;
- Dictionary<int, COFFFrameProgram> programMap;
- Array<COFFFrameProgram::Command> cmds;
- while (ptr < endPtr)
- {
- COFFFrameDescriptor* frame = (COFFFrameDescriptor*)ptr;
- ptr += sizeof(COFFFrameDescriptor);
- COFFFrameDescriptorEntry entry;
- entry.mFrameDescriptor = frame;
- bool failed = false;
- COFFFrameProgram* programPtr = NULL;
- if (programMap.TryAdd(frame->mFrameFunc, NULL, &programPtr))
- {
- COFFFrameProgram program;
- cmds.Clear();
- String curCmd;
- const char* ptr = mStringTable.mStrTable + frame->mFrameFunc;
- while (true)
- {
- char c = *(ptr++);
- if ((c == ' ') || (c == 0))
- {
- if (curCmd == "$eip")
- cmds.Add(COFFFrameProgram::Command_EIP);
- else if ((curCmd == "$esp") || (curCmd == "$21"))
- cmds.Add(COFFFrameProgram::Command_ESP);
- else if ((curCmd == "$ebp") || (curCmd == "$22"))
- cmds.Add(COFFFrameProgram::Command_EBP);
- else if ((curCmd == "$eax") || (curCmd == "$17"))
- cmds.Add(COFFFrameProgram::Command_EAX);
- else if ((curCmd == "$ebx") || (curCmd == "$20"))
- cmds.Add(COFFFrameProgram::Command_EBX);
- else if ((curCmd == "$ecx") || (curCmd == "$18"))
- cmds.Add(COFFFrameProgram::Command_ECX);
- else if ((curCmd == "$edx") || (curCmd == "$19"))
- cmds.Add(COFFFrameProgram::Command_EDX);
- else if ((curCmd == "$esi") || (curCmd == "$23"))
- cmds.Add(COFFFrameProgram::Command_ESI);
- else if ((curCmd == "$edi") || (curCmd == "$24"))
- cmds.Add(COFFFrameProgram::Command_EDI);
- else if (curCmd == "$T0")
- cmds.Add(COFFFrameProgram::Command_T0);
- else if (curCmd == "$T1")
- cmds.Add(COFFFrameProgram::Command_T1);
- else if (curCmd == "$T2")
- cmds.Add(COFFFrameProgram::Command_T2);
- else if (curCmd == "$T3")
- cmds.Add(COFFFrameProgram::Command_T3);
- else if ((curCmd == ".raSearch") || (curCmd == ".raSearchStart"))
- cmds.Add(COFFFrameProgram::Command_RASearch);
- else if (curCmd == "+")
- cmds.Add(COFFFrameProgram::Command_Add);
- else if (curCmd == "-")
- cmds.Add(COFFFrameProgram::Command_Subtract);
- else if (curCmd == "@")
- cmds.Add(COFFFrameProgram::Command_Align);
- else if (curCmd == "=")
- cmds.Add(COFFFrameProgram::Command_Set);
- else if (curCmd == "^")
- cmds.Add(COFFFrameProgram::Command_Deref);
- else if (!curCmd.IsEmpty())
- {
- if ((curCmd[0] >= '0') && (curCmd[0] <= '9'))
- {
- int val = atoi(curCmd.c_str());
- if ((val >= 0) && (val <= 255))
- {
- cmds.Add(COFFFrameProgram::Command_Value8);
- cmds.Add((COFFFrameProgram::Command)val);
- }
- else
- {
- cmds.Add(COFFFrameProgram::Command_Value);
- cmds.Insert(cmds.size(), (COFFFrameProgram::Command*)&val, 4);
- }
- }
- else
- {
- failed = true;
- SoftFail(StrFormat("Invalid COFF frame program: %s", curCmd.c_str()));
- }
- }
- if (c == 0)
- break;
- curCmd.Clear();
- }
- else
- curCmd.Append(c);
- }
- if (failed)
- cmds.Clear();
- cmds.Add(COFFFrameProgram::Command_None);
- program.mCommands = (COFFFrameProgram::Command*)mAlloc.AllocBytes(cmds.size());
- memcpy(program.mCommands, &cmds[0], cmds.size());
- *programPtr = program;
- }
- entry.mProgram = *programPtr;
- mDebugTarget->mCOFFFrameDescriptorMap.insert(std::make_pair(baseAddr + frame->mRvaStart, entry));
- }
- mParsedFrameDescriptors = true;
- }
- void COFF::ParseFrameDescriptors()
- {
- if (mParsedFrameDescriptors)
- return;
- if (mCvNewFPOStream == 0)
- return;
- int streamSize = 0;
- mNewFPOData = CvReadStream(mCvNewFPOStream, &streamSize);
- ParseFrameDescriptors(mNewFPOData, streamSize, mImageBase);
- }
- NS_BF_DBG_BEGIN
- // void TestCoff(void* tdata, int tdataSize, void* cuData, int cuDataSize)
- // {
- // DebugTarget* debugTarget = new DebugTarget(NULL);
- // {
- // COFF coff(debugTarget);
- // coff.mCvTypeSectionData = (uint8*)tdata;
- // coff.mCvTypeSectionDataSize = tdataSize;
- //
- // coff.mCvCompileUnitData = (uint8*)cuData;
- // coff.mCvCompileUnitDataSize = cuDataSize;
- //
- // coff.ProcessDebugInfo();
- // }
- // delete debugTarget;
- // }
- void TestPDB(const StringImpl& fileName, WinDebugger* debugger)
- {
- DebugTarget* debugTarget = new DebugTarget(NULL);
- COFF coff(debugTarget);
- coff.mDebugger = debugger;
- uint8 wantGuid[16];
- coff.TryLoadPDB(fileName, wantGuid, -1);
- coff.ParseTypeData();
- coff.CvParseIPI();
- coff.ParseGlobalsData();
- coff.ParseSymbolData();
- for (int compileUnitId = 0; compileUnitId < (int)coff.mCvModuleInfo.size(); compileUnitId++)
- coff.ParseCompileUnit(compileUnitId);
- }
- NS_BF_DBG_END
|