dwarf.c 209 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653
  1. /* dwarf.c -- display DWARF contents of a BFD binary file
  2. Copyright (C) 2005-2015 Free Software Foundation, Inc.
  3. This file is part of GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "libiberty.h"
  18. #include "bfd.h"
  19. #include "bfd_stdint.h"
  20. #include "bucomm.h"
  21. #include "elfcomm.h"
  22. #include "elf/common.h"
  23. #include "dwarf2.h"
  24. #include "dwarf.h"
  25. #include "gdb/gdb-index.h"
  26. static const char *regname (unsigned int regno, int row);
  27. static int have_frame_base;
  28. static int need_base_address;
  29. static unsigned int last_pointer_size = 0;
  30. static int warned_about_missing_comp_units = FALSE;
  31. static unsigned int num_debug_info_entries = 0;
  32. static unsigned int alloc_num_debug_info_entries = 0;
  33. static debug_info *debug_information = NULL;
  34. /* Special value for num_debug_info_entries to indicate
  35. that the .debug_info section could not be loaded/parsed. */
  36. #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
  37. unsigned int eh_addr_size;
  38. int do_debug_info;
  39. int do_debug_abbrevs;
  40. int do_debug_lines;
  41. int do_debug_pubnames;
  42. int do_debug_pubtypes;
  43. int do_debug_aranges;
  44. int do_debug_ranges;
  45. int do_debug_frames;
  46. int do_debug_frames_interp;
  47. int do_debug_macinfo;
  48. int do_debug_str;
  49. int do_debug_loc;
  50. int do_gdb_index;
  51. int do_trace_info;
  52. int do_trace_abbrevs;
  53. int do_trace_aranges;
  54. int do_debug_addr;
  55. int do_debug_cu_index;
  56. int do_wide;
  57. int dwarf_cutoff_level = -1;
  58. unsigned long dwarf_start_die;
  59. int dwarf_check = 0;
  60. /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
  61. sections. For version 1 package files, each set is stored in SHNDX_POOL
  62. as a zero-terminated list of section indexes comprising one set of debug
  63. sections from a .dwo file. */
  64. static int cu_tu_indexes_read = 0;
  65. static unsigned int *shndx_pool = NULL;
  66. static unsigned int shndx_pool_size = 0;
  67. static unsigned int shndx_pool_used = 0;
  68. /* For version 2 package files, each set contains an array of section offsets
  69. and an array of section sizes, giving the offset and size of the
  70. contribution from a CU or TU within one of the debug sections.
  71. When displaying debug info from a package file, we need to use these
  72. tables to locate the corresponding contributions to each section. */
  73. struct cu_tu_set
  74. {
  75. uint64_t signature;
  76. dwarf_vma section_offsets[DW_SECT_MAX];
  77. size_t section_sizes[DW_SECT_MAX];
  78. };
  79. static int cu_count = 0;
  80. static int tu_count = 0;
  81. static struct cu_tu_set *cu_sets = NULL;
  82. static struct cu_tu_set *tu_sets = NULL;
  83. static void load_cu_tu_indexes (void *file);
  84. /* Values for do_debug_lines. */
  85. #define FLAG_DEBUG_LINES_RAW 1
  86. #define FLAG_DEBUG_LINES_DECODED 2
  87. static unsigned int
  88. size_of_encoded_value (int encoding)
  89. {
  90. switch (encoding & 0x7)
  91. {
  92. default: /* ??? */
  93. case 0: return eh_addr_size;
  94. case 2: return 2;
  95. case 3: return 4;
  96. case 4: return 8;
  97. }
  98. }
  99. static dwarf_vma
  100. get_encoded_value (unsigned char **pdata,
  101. int encoding,
  102. struct dwarf_section *section,
  103. unsigned char * end)
  104. {
  105. unsigned char * data = * pdata;
  106. unsigned int size = size_of_encoded_value (encoding);
  107. dwarf_vma val;
  108. if (data + size >= end)
  109. {
  110. warn (_("Encoded value extends past end of section\n"));
  111. * pdata = end;
  112. return 0;
  113. }
  114. /* PR 17512: file: 002-829853-0.004. */
  115. if (size > 8)
  116. {
  117. warn (_("Encoded size of %d is too large to read\n"), size);
  118. * pdata = end;
  119. return 0;
  120. }
  121. /* PR 17512: file: 1085-5603-0.004. */
  122. if (size == 0)
  123. {
  124. warn (_("Encoded size of 0 is too small to read\n"));
  125. * pdata = end;
  126. return 0;
  127. }
  128. if (encoding & DW_EH_PE_signed)
  129. val = byte_get_signed (data, size);
  130. else
  131. val = byte_get (data, size);
  132. if ((encoding & 0x70) == DW_EH_PE_pcrel)
  133. val += section->address + (data - section->start);
  134. * pdata = data + size;
  135. return val;
  136. }
  137. #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
  138. # ifndef __MINGW32__
  139. # define DWARF_VMA_FMT "ll"
  140. # define DWARF_VMA_FMT_LONG "%16.16llx"
  141. # else
  142. # define DWARF_VMA_FMT "I64"
  143. # define DWARF_VMA_FMT_LONG "%016I64x"
  144. # endif
  145. #else
  146. # define DWARF_VMA_FMT "l"
  147. # define DWARF_VMA_FMT_LONG "%16.16lx"
  148. #endif
  149. /* Convert a dwarf vma value into a string. Returns a pointer to a static
  150. buffer containing the converted VALUE. The value is converted according
  151. to the printf formating character FMTCH. If NUM_BYTES is non-zero then
  152. it specifies the maximum number of bytes to be displayed in the converted
  153. value and FMTCH is ignored - hex is always used. */
  154. static const char *
  155. dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
  156. {
  157. /* As dwarf_vmatoa is used more then once in a printf call
  158. for output, we are cycling through an fixed array of pointers
  159. for return address. */
  160. static int buf_pos = 0;
  161. static struct dwarf_vmatoa_buf
  162. {
  163. char place[64];
  164. } buf[16];
  165. char *ret;
  166. ret = buf[buf_pos++].place;
  167. buf_pos %= ARRAY_SIZE (buf);
  168. if (num_bytes)
  169. {
  170. /* Printf does not have a way of specifiying a maximum field width for an
  171. integer value, so we print the full value into a buffer and then select
  172. the precision we need. */
  173. snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
  174. if (num_bytes > 8)
  175. num_bytes = 8;
  176. return ret + (16 - 2 * num_bytes);
  177. }
  178. else
  179. {
  180. char fmt[32];
  181. sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
  182. snprintf (ret, sizeof (buf[0].place), fmt, value);
  183. return ret;
  184. }
  185. }
  186. static inline const char *
  187. dwarf_vmatoa (const char * fmtch, dwarf_vma value)
  188. {
  189. return dwarf_vmatoa_1 (fmtch, value, 0);
  190. }
  191. /* Print a dwarf_vma value (typically an address, offset or length) in
  192. hexadecimal format, followed by a space. The length of the VALUE (and
  193. hence the precision displayed) is determined by the NUM_BYTES parameter. */
  194. static void
  195. print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
  196. {
  197. printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
  198. }
  199. /* Format a 64-bit value, given as two 32-bit values, in hex.
  200. For reentrancy, this uses a buffer provided by the caller. */
  201. static const char *
  202. dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
  203. unsigned int buf_len)
  204. {
  205. int len = 0;
  206. if (hvalue == 0)
  207. snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
  208. else
  209. {
  210. len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
  211. snprintf (buf + len, buf_len - len,
  212. "%08" DWARF_VMA_FMT "x", lvalue);
  213. }
  214. return buf;
  215. }
  216. /* Read in a LEB128 encoded value starting at address DATA.
  217. If SIGN is true, return a signed LEB128 value.
  218. If LENGTH_RETURN is not NULL, return in it the number of bytes read.
  219. No bytes will be read at address END or beyond. */
  220. dwarf_vma
  221. read_leb128 (unsigned char *data,
  222. unsigned int *length_return,
  223. bfd_boolean sign,
  224. const unsigned char * const end)
  225. {
  226. dwarf_vma result = 0;
  227. unsigned int num_read = 0;
  228. unsigned int shift = 0;
  229. unsigned char byte = 0;
  230. while (data < end)
  231. {
  232. byte = *data++;
  233. num_read++;
  234. result |= ((dwarf_vma) (byte & 0x7f)) << shift;
  235. shift += 7;
  236. if ((byte & 0x80) == 0)
  237. break;
  238. /* PR 17512: file: 0ca183b8.
  239. FIXME: Should we signal this error somehow ? */
  240. if (shift >= sizeof (result) * 8)
  241. break;
  242. }
  243. if (length_return != NULL)
  244. *length_return = num_read;
  245. if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
  246. result |= (dwarf_vma) -1 << shift;
  247. return result;
  248. }
  249. /* Create a signed version to avoid painful typecasts. */
  250. static inline dwarf_signed_vma
  251. read_sleb128 (unsigned char * data,
  252. unsigned int * length_return,
  253. const unsigned char * const end)
  254. {
  255. return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end);
  256. }
  257. static inline dwarf_vma
  258. read_uleb128 (unsigned char * data,
  259. unsigned int * length_return,
  260. const unsigned char * const end)
  261. {
  262. return read_leb128 (data, length_return, FALSE, end);
  263. }
  264. #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
  265. do \
  266. { \
  267. int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
  268. unsigned int amount = (AMOUNT); \
  269. if (((PTR) + amount) >= (END)) \
  270. { \
  271. if ((PTR) < (END)) \
  272. amount = (END) - (PTR); \
  273. else \
  274. amount = 0; \
  275. } \
  276. if (amount == 0 || amount > 8) \
  277. VAL = 0; \
  278. else \
  279. VAL = byte_get ((PTR), amount); \
  280. } \
  281. while (0)
  282. #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
  283. do \
  284. { \
  285. SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
  286. PTR += AMOUNT; \
  287. } \
  288. while (0)
  289. #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
  290. do \
  291. { \
  292. unsigned int amount = (AMOUNT); \
  293. if (((PTR) + amount) >= (END)) \
  294. { \
  295. if ((PTR) < (END)) \
  296. amount = (END) - (PTR); \
  297. else \
  298. amount = 0; \
  299. } \
  300. if (amount) \
  301. VAL = byte_get_signed ((PTR), amount); \
  302. else \
  303. VAL = 0; \
  304. } \
  305. while (0)
  306. #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
  307. do \
  308. { \
  309. SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
  310. PTR += AMOUNT; \
  311. } \
  312. while (0)
  313. #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
  314. do \
  315. { \
  316. if (((PTR) + 8) <= (END)) \
  317. { \
  318. byte_get_64 ((PTR), (HIGH), (LOW)); \
  319. } \
  320. else \
  321. { \
  322. * (LOW) = * (HIGH) = 0; \
  323. } \
  324. } \
  325. while (0)
  326. typedef struct State_Machine_Registers
  327. {
  328. dwarf_vma address;
  329. unsigned int file;
  330. unsigned int line;
  331. unsigned int column;
  332. int is_stmt;
  333. int basic_block;
  334. unsigned char op_index;
  335. unsigned char end_sequence;
  336. /* This variable hold the number of the last entry seen
  337. in the File Table. */
  338. unsigned int last_file_entry;
  339. } SMR;
  340. static SMR state_machine_regs;
  341. static void
  342. reset_state_machine (int is_stmt)
  343. {
  344. state_machine_regs.address = 0;
  345. state_machine_regs.op_index = 0;
  346. state_machine_regs.file = 1;
  347. state_machine_regs.line = 1;
  348. state_machine_regs.column = 0;
  349. state_machine_regs.is_stmt = is_stmt;
  350. state_machine_regs.basic_block = 0;
  351. state_machine_regs.end_sequence = 0;
  352. state_machine_regs.last_file_entry = 0;
  353. }
  354. /* Handled an extend line op.
  355. Returns the number of bytes read. */
  356. static int
  357. process_extended_line_op (unsigned char * data,
  358. int is_stmt,
  359. unsigned char * end)
  360. {
  361. unsigned char op_code;
  362. unsigned int bytes_read;
  363. unsigned int len;
  364. unsigned char *name;
  365. unsigned char *orig_data = data;
  366. dwarf_vma adr;
  367. len = read_uleb128 (data, & bytes_read, end);
  368. data += bytes_read;
  369. if (len == 0 || data == end || len > (uintptr_t) (end - data))
  370. {
  371. warn (_("Badly formed extended line op encountered!\n"));
  372. return bytes_read;
  373. }
  374. len += bytes_read;
  375. op_code = *data++;
  376. printf (_(" Extended opcode %d: "), op_code);
  377. switch (op_code)
  378. {
  379. case DW_LNE_end_sequence:
  380. printf (_("End of Sequence\n\n"));
  381. reset_state_machine (is_stmt);
  382. break;
  383. case DW_LNE_set_address:
  384. /* PR 17512: file: 002-100480-0.004. */
  385. if (len - bytes_read - 1 > 8)
  386. {
  387. warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
  388. len - bytes_read - 1);
  389. adr = 0;
  390. }
  391. else
  392. SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end);
  393. printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
  394. state_machine_regs.address = adr;
  395. state_machine_regs.op_index = 0;
  396. break;
  397. case DW_LNE_define_file:
  398. printf (_("define new File Table entry\n"));
  399. printf (_(" Entry\tDir\tTime\tSize\tName\n"));
  400. printf (" %d\t", ++state_machine_regs.last_file_entry);
  401. name = data;
  402. data += strnlen ((char *) data, end - data) + 1;
  403. printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
  404. data += bytes_read;
  405. printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
  406. data += bytes_read;
  407. printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
  408. data += bytes_read;
  409. printf ("%s\n\n", name);
  410. if (((unsigned int) (data - orig_data) != len) || data == end)
  411. warn (_("DW_LNE_define_file: Bad opcode length\n"));
  412. break;
  413. case DW_LNE_set_discriminator:
  414. printf (_("set Discriminator to %s\n"),
  415. dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
  416. break;
  417. /* HP extensions. */
  418. case DW_LNE_HP_negate_is_UV_update:
  419. printf ("DW_LNE_HP_negate_is_UV_update\n");
  420. break;
  421. case DW_LNE_HP_push_context:
  422. printf ("DW_LNE_HP_push_context\n");
  423. break;
  424. case DW_LNE_HP_pop_context:
  425. printf ("DW_LNE_HP_pop_context\n");
  426. break;
  427. case DW_LNE_HP_set_file_line_column:
  428. printf ("DW_LNE_HP_set_file_line_column\n");
  429. break;
  430. case DW_LNE_HP_set_routine_name:
  431. printf ("DW_LNE_HP_set_routine_name\n");
  432. break;
  433. case DW_LNE_HP_set_sequence:
  434. printf ("DW_LNE_HP_set_sequence\n");
  435. break;
  436. case DW_LNE_HP_negate_post_semantics:
  437. printf ("DW_LNE_HP_negate_post_semantics\n");
  438. break;
  439. case DW_LNE_HP_negate_function_exit:
  440. printf ("DW_LNE_HP_negate_function_exit\n");
  441. break;
  442. case DW_LNE_HP_negate_front_end_logical:
  443. printf ("DW_LNE_HP_negate_front_end_logical\n");
  444. break;
  445. case DW_LNE_HP_define_proc:
  446. printf ("DW_LNE_HP_define_proc\n");
  447. break;
  448. case DW_LNE_HP_source_file_correlation:
  449. {
  450. unsigned char *edata = data + len - bytes_read - 1;
  451. printf ("DW_LNE_HP_source_file_correlation\n");
  452. while (data < edata)
  453. {
  454. unsigned int opc;
  455. opc = read_uleb128 (data, & bytes_read, edata);
  456. data += bytes_read;
  457. switch (opc)
  458. {
  459. case DW_LNE_HP_SFC_formfeed:
  460. printf (" DW_LNE_HP_SFC_formfeed\n");
  461. break;
  462. case DW_LNE_HP_SFC_set_listing_line:
  463. printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
  464. dwarf_vmatoa ("u",
  465. read_uleb128 (data, & bytes_read, edata)));
  466. data += bytes_read;
  467. break;
  468. case DW_LNE_HP_SFC_associate:
  469. printf (" DW_LNE_HP_SFC_associate ");
  470. printf ("(%s",
  471. dwarf_vmatoa ("u",
  472. read_uleb128 (data, & bytes_read, edata)));
  473. data += bytes_read;
  474. printf (",%s",
  475. dwarf_vmatoa ("u",
  476. read_uleb128 (data, & bytes_read, edata)));
  477. data += bytes_read;
  478. printf (",%s)\n",
  479. dwarf_vmatoa ("u",
  480. read_uleb128 (data, & bytes_read, edata)));
  481. data += bytes_read;
  482. break;
  483. default:
  484. printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
  485. data = edata;
  486. break;
  487. }
  488. }
  489. }
  490. break;
  491. default:
  492. {
  493. unsigned int rlen = len - bytes_read - 1;
  494. if (op_code >= DW_LNE_lo_user
  495. /* The test against DW_LNW_hi_user is redundant due to
  496. the limited range of the unsigned char data type used
  497. for op_code. */
  498. /*&& op_code <= DW_LNE_hi_user*/)
  499. printf (_("user defined: "));
  500. else
  501. printf (_("UNKNOWN: "));
  502. printf (_("length %d ["), rlen);
  503. for (; rlen; rlen--)
  504. printf (" %02x", *data++);
  505. printf ("]\n");
  506. }
  507. break;
  508. }
  509. return len;
  510. }
  511. static const unsigned char *
  512. fetch_indirect_string (dwarf_vma offset)
  513. {
  514. struct dwarf_section *section = &debug_displays [str].section;
  515. if (section->start == NULL)
  516. return (const unsigned char *) _("<no .debug_str section>");
  517. if (offset > section->size)
  518. {
  519. warn (_("DW_FORM_strp offset too big: %s\n"),
  520. dwarf_vmatoa ("x", offset));
  521. return (const unsigned char *) _("<offset is too big>");
  522. }
  523. return (const unsigned char *) section->start + offset;
  524. }
  525. static const char *
  526. fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
  527. dwarf_vma offset_size, int dwo)
  528. {
  529. enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
  530. enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
  531. struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
  532. struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
  533. dwarf_vma index_offset = idx * offset_size;
  534. dwarf_vma str_offset;
  535. if (index_section->start == NULL)
  536. return (dwo ? _("<no .debug_str_offsets.dwo section>")
  537. : _("<no .debug_str_offsets section>"));
  538. if (this_set != NULL)
  539. index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
  540. if (index_offset > index_section->size)
  541. {
  542. warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
  543. dwarf_vmatoa ("x", index_offset));
  544. return _("<index offset is too big>");
  545. }
  546. if (str_section->start == NULL)
  547. return (dwo ? _("<no .debug_str.dwo section>")
  548. : _("<no .debug_str section>"));
  549. str_offset = byte_get (index_section->start + index_offset, offset_size);
  550. str_offset -= str_section->address;
  551. if (str_offset > str_section->size)
  552. {
  553. warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
  554. dwarf_vmatoa ("x", str_offset));
  555. return _("<indirect index offset is too big>");
  556. }
  557. return (const char *) str_section->start + str_offset;
  558. }
  559. static const char *
  560. fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
  561. {
  562. struct dwarf_section *section = &debug_displays [debug_addr].section;
  563. if (section->start == NULL)
  564. return (_("<no .debug_addr section>"));
  565. if (offset + bytes > section->size)
  566. {
  567. warn (_("Offset into section %s too big: %s\n"),
  568. section->name, dwarf_vmatoa ("x", offset));
  569. return "<offset too big>";
  570. }
  571. return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
  572. }
  573. /* FIXME: There are better and more efficient ways to handle
  574. these structures. For now though, I just want something that
  575. is simple to implement. */
  576. typedef struct abbrev_attr
  577. {
  578. unsigned long attribute;
  579. unsigned long form;
  580. struct abbrev_attr *next;
  581. }
  582. abbrev_attr;
  583. typedef struct abbrev_entry
  584. {
  585. unsigned long entry;
  586. unsigned long tag;
  587. int children;
  588. struct abbrev_attr *first_attr;
  589. struct abbrev_attr *last_attr;
  590. struct abbrev_entry *next;
  591. }
  592. abbrev_entry;
  593. static abbrev_entry *first_abbrev = NULL;
  594. static abbrev_entry *last_abbrev = NULL;
  595. static void
  596. free_abbrevs (void)
  597. {
  598. abbrev_entry *abbrv;
  599. for (abbrv = first_abbrev; abbrv;)
  600. {
  601. abbrev_entry *next_abbrev = abbrv->next;
  602. abbrev_attr *attr;
  603. for (attr = abbrv->first_attr; attr;)
  604. {
  605. abbrev_attr *next_attr = attr->next;
  606. free (attr);
  607. attr = next_attr;
  608. }
  609. free (abbrv);
  610. abbrv = next_abbrev;
  611. }
  612. last_abbrev = first_abbrev = NULL;
  613. }
  614. static void
  615. add_abbrev (unsigned long number, unsigned long tag, int children)
  616. {
  617. abbrev_entry *entry;
  618. entry = (abbrev_entry *) malloc (sizeof (*entry));
  619. if (entry == NULL)
  620. /* ugg */
  621. return;
  622. entry->entry = number;
  623. entry->tag = tag;
  624. entry->children = children;
  625. entry->first_attr = NULL;
  626. entry->last_attr = NULL;
  627. entry->next = NULL;
  628. if (first_abbrev == NULL)
  629. first_abbrev = entry;
  630. else
  631. last_abbrev->next = entry;
  632. last_abbrev = entry;
  633. }
  634. static void
  635. add_abbrev_attr (unsigned long attribute, unsigned long form)
  636. {
  637. abbrev_attr *attr;
  638. attr = (abbrev_attr *) malloc (sizeof (*attr));
  639. if (attr == NULL)
  640. /* ugg */
  641. return;
  642. attr->attribute = attribute;
  643. attr->form = form;
  644. attr->next = NULL;
  645. if (last_abbrev->first_attr == NULL)
  646. last_abbrev->first_attr = attr;
  647. else
  648. last_abbrev->last_attr->next = attr;
  649. last_abbrev->last_attr = attr;
  650. }
  651. /* Processes the (partial) contents of a .debug_abbrev section.
  652. Returns NULL if the end of the section was encountered.
  653. Returns the address after the last byte read if the end of
  654. an abbreviation set was found. */
  655. static unsigned char *
  656. process_abbrev_section (unsigned char *start, unsigned char *end)
  657. {
  658. if (first_abbrev != NULL)
  659. return NULL;
  660. while (start < end)
  661. {
  662. unsigned int bytes_read;
  663. unsigned long entry;
  664. unsigned long tag;
  665. unsigned long attribute;
  666. int children;
  667. entry = read_uleb128 (start, & bytes_read, end);
  668. start += bytes_read;
  669. /* A single zero is supposed to end the section according
  670. to the standard. If there's more, then signal that to
  671. the caller. */
  672. if (start == end)
  673. return NULL;
  674. if (entry == 0)
  675. return start;
  676. tag = read_uleb128 (start, & bytes_read, end);
  677. start += bytes_read;
  678. if (start == end)
  679. return NULL;
  680. children = *start++;
  681. add_abbrev (entry, tag, children);
  682. do
  683. {
  684. unsigned long form;
  685. attribute = read_uleb128 (start, & bytes_read, end);
  686. start += bytes_read;
  687. if (start == end)
  688. break;
  689. form = read_uleb128 (start, & bytes_read, end);
  690. start += bytes_read;
  691. if (start == end)
  692. break;
  693. add_abbrev_attr (attribute, form);
  694. }
  695. while (attribute != 0);
  696. }
  697. /* Report the missing single zero which ends the section. */
  698. error (_(".debug_abbrev section not zero terminated\n"));
  699. return NULL;
  700. }
  701. static const char *
  702. get_TAG_name (unsigned long tag)
  703. {
  704. const char *name = get_DW_TAG_name ((unsigned int)tag);
  705. if (name == NULL)
  706. {
  707. static char buffer[100];
  708. snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
  709. return buffer;
  710. }
  711. return name;
  712. }
  713. static const char *
  714. get_FORM_name (unsigned long form)
  715. {
  716. const char *name;
  717. if (form == 0)
  718. return "DW_FORM value: 0";
  719. name = get_DW_FORM_name (form);
  720. if (name == NULL)
  721. {
  722. static char buffer[100];
  723. snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
  724. return buffer;
  725. }
  726. return name;
  727. }
  728. static unsigned char *
  729. display_block (unsigned char *data,
  730. dwarf_vma length,
  731. const unsigned char * const end)
  732. {
  733. dwarf_vma maxlen;
  734. printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
  735. if (data > end)
  736. return (unsigned char *) end;
  737. maxlen = (dwarf_vma) (end - data);
  738. length = length > maxlen ? maxlen : length;
  739. while (length --)
  740. printf ("%lx ", (unsigned long) byte_get (data++, 1));
  741. return data;
  742. }
  743. static int
  744. decode_location_expression (unsigned char * data,
  745. unsigned int pointer_size,
  746. unsigned int offset_size,
  747. int dwarf_version,
  748. dwarf_vma length,
  749. dwarf_vma cu_offset,
  750. struct dwarf_section * section)
  751. {
  752. unsigned op;
  753. unsigned int bytes_read;
  754. dwarf_vma uvalue;
  755. dwarf_signed_vma svalue;
  756. unsigned char *end = data + length;
  757. int need_frame_base = 0;
  758. while (data < end)
  759. {
  760. op = *data++;
  761. switch (op)
  762. {
  763. case DW_OP_addr:
  764. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  765. printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
  766. break;
  767. case DW_OP_deref:
  768. printf ("DW_OP_deref");
  769. break;
  770. case DW_OP_const1u:
  771. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  772. printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
  773. break;
  774. case DW_OP_const1s:
  775. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
  776. printf ("DW_OP_const1s: %ld", (long) svalue);
  777. break;
  778. case DW_OP_const2u:
  779. SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
  780. printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
  781. break;
  782. case DW_OP_const2s:
  783. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
  784. printf ("DW_OP_const2s: %ld", (long) svalue);
  785. break;
  786. case DW_OP_const4u:
  787. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  788. printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
  789. break;
  790. case DW_OP_const4s:
  791. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
  792. printf ("DW_OP_const4s: %ld", (long) svalue);
  793. break;
  794. case DW_OP_const8u:
  795. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  796. printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
  797. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  798. printf ("%lu", (unsigned long) uvalue);
  799. break;
  800. case DW_OP_const8s:
  801. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
  802. printf ("DW_OP_const8s: %ld ", (long) svalue);
  803. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
  804. printf ("%ld", (long) svalue);
  805. break;
  806. case DW_OP_constu:
  807. printf ("DW_OP_constu: %s",
  808. dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
  809. data += bytes_read;
  810. break;
  811. case DW_OP_consts:
  812. printf ("DW_OP_consts: %s",
  813. dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
  814. data += bytes_read;
  815. break;
  816. case DW_OP_dup:
  817. printf ("DW_OP_dup");
  818. break;
  819. case DW_OP_drop:
  820. printf ("DW_OP_drop");
  821. break;
  822. case DW_OP_over:
  823. printf ("DW_OP_over");
  824. break;
  825. case DW_OP_pick:
  826. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  827. printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
  828. break;
  829. case DW_OP_swap:
  830. printf ("DW_OP_swap");
  831. break;
  832. case DW_OP_rot:
  833. printf ("DW_OP_rot");
  834. break;
  835. case DW_OP_xderef:
  836. printf ("DW_OP_xderef");
  837. break;
  838. case DW_OP_abs:
  839. printf ("DW_OP_abs");
  840. break;
  841. case DW_OP_and:
  842. printf ("DW_OP_and");
  843. break;
  844. case DW_OP_div:
  845. printf ("DW_OP_div");
  846. break;
  847. case DW_OP_minus:
  848. printf ("DW_OP_minus");
  849. break;
  850. case DW_OP_mod:
  851. printf ("DW_OP_mod");
  852. break;
  853. case DW_OP_mul:
  854. printf ("DW_OP_mul");
  855. break;
  856. case DW_OP_neg:
  857. printf ("DW_OP_neg");
  858. break;
  859. case DW_OP_not:
  860. printf ("DW_OP_not");
  861. break;
  862. case DW_OP_or:
  863. printf ("DW_OP_or");
  864. break;
  865. case DW_OP_plus:
  866. printf ("DW_OP_plus");
  867. break;
  868. case DW_OP_plus_uconst:
  869. printf ("DW_OP_plus_uconst: %s",
  870. dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
  871. data += bytes_read;
  872. break;
  873. case DW_OP_shl:
  874. printf ("DW_OP_shl");
  875. break;
  876. case DW_OP_shr:
  877. printf ("DW_OP_shr");
  878. break;
  879. case DW_OP_shra:
  880. printf ("DW_OP_shra");
  881. break;
  882. case DW_OP_xor:
  883. printf ("DW_OP_xor");
  884. break;
  885. case DW_OP_bra:
  886. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
  887. printf ("DW_OP_bra: %ld", (long) svalue);
  888. break;
  889. case DW_OP_eq:
  890. printf ("DW_OP_eq");
  891. break;
  892. case DW_OP_ge:
  893. printf ("DW_OP_ge");
  894. break;
  895. case DW_OP_gt:
  896. printf ("DW_OP_gt");
  897. break;
  898. case DW_OP_le:
  899. printf ("DW_OP_le");
  900. break;
  901. case DW_OP_lt:
  902. printf ("DW_OP_lt");
  903. break;
  904. case DW_OP_ne:
  905. printf ("DW_OP_ne");
  906. break;
  907. case DW_OP_skip:
  908. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
  909. printf ("DW_OP_skip: %ld", (long) svalue);
  910. break;
  911. case DW_OP_lit0:
  912. case DW_OP_lit1:
  913. case DW_OP_lit2:
  914. case DW_OP_lit3:
  915. case DW_OP_lit4:
  916. case DW_OP_lit5:
  917. case DW_OP_lit6:
  918. case DW_OP_lit7:
  919. case DW_OP_lit8:
  920. case DW_OP_lit9:
  921. case DW_OP_lit10:
  922. case DW_OP_lit11:
  923. case DW_OP_lit12:
  924. case DW_OP_lit13:
  925. case DW_OP_lit14:
  926. case DW_OP_lit15:
  927. case DW_OP_lit16:
  928. case DW_OP_lit17:
  929. case DW_OP_lit18:
  930. case DW_OP_lit19:
  931. case DW_OP_lit20:
  932. case DW_OP_lit21:
  933. case DW_OP_lit22:
  934. case DW_OP_lit23:
  935. case DW_OP_lit24:
  936. case DW_OP_lit25:
  937. case DW_OP_lit26:
  938. case DW_OP_lit27:
  939. case DW_OP_lit28:
  940. case DW_OP_lit29:
  941. case DW_OP_lit30:
  942. case DW_OP_lit31:
  943. printf ("DW_OP_lit%d", op - DW_OP_lit0);
  944. break;
  945. case DW_OP_reg0:
  946. case DW_OP_reg1:
  947. case DW_OP_reg2:
  948. case DW_OP_reg3:
  949. case DW_OP_reg4:
  950. case DW_OP_reg5:
  951. case DW_OP_reg6:
  952. case DW_OP_reg7:
  953. case DW_OP_reg8:
  954. case DW_OP_reg9:
  955. case DW_OP_reg10:
  956. case DW_OP_reg11:
  957. case DW_OP_reg12:
  958. case DW_OP_reg13:
  959. case DW_OP_reg14:
  960. case DW_OP_reg15:
  961. case DW_OP_reg16:
  962. case DW_OP_reg17:
  963. case DW_OP_reg18:
  964. case DW_OP_reg19:
  965. case DW_OP_reg20:
  966. case DW_OP_reg21:
  967. case DW_OP_reg22:
  968. case DW_OP_reg23:
  969. case DW_OP_reg24:
  970. case DW_OP_reg25:
  971. case DW_OP_reg26:
  972. case DW_OP_reg27:
  973. case DW_OP_reg28:
  974. case DW_OP_reg29:
  975. case DW_OP_reg30:
  976. case DW_OP_reg31:
  977. printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
  978. regname (op - DW_OP_reg0, 1));
  979. break;
  980. case DW_OP_breg0:
  981. case DW_OP_breg1:
  982. case DW_OP_breg2:
  983. case DW_OP_breg3:
  984. case DW_OP_breg4:
  985. case DW_OP_breg5:
  986. case DW_OP_breg6:
  987. case DW_OP_breg7:
  988. case DW_OP_breg8:
  989. case DW_OP_breg9:
  990. case DW_OP_breg10:
  991. case DW_OP_breg11:
  992. case DW_OP_breg12:
  993. case DW_OP_breg13:
  994. case DW_OP_breg14:
  995. case DW_OP_breg15:
  996. case DW_OP_breg16:
  997. case DW_OP_breg17:
  998. case DW_OP_breg18:
  999. case DW_OP_breg19:
  1000. case DW_OP_breg20:
  1001. case DW_OP_breg21:
  1002. case DW_OP_breg22:
  1003. case DW_OP_breg23:
  1004. case DW_OP_breg24:
  1005. case DW_OP_breg25:
  1006. case DW_OP_breg26:
  1007. case DW_OP_breg27:
  1008. case DW_OP_breg28:
  1009. case DW_OP_breg29:
  1010. case DW_OP_breg30:
  1011. case DW_OP_breg31:
  1012. printf ("DW_OP_breg%d (%s): %s",
  1013. op - DW_OP_breg0,
  1014. regname (op - DW_OP_breg0, 1),
  1015. dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
  1016. data += bytes_read;
  1017. break;
  1018. case DW_OP_regx:
  1019. uvalue = read_uleb128 (data, &bytes_read, end);
  1020. data += bytes_read;
  1021. printf ("DW_OP_regx: %s (%s)",
  1022. dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
  1023. break;
  1024. case DW_OP_fbreg:
  1025. need_frame_base = 1;
  1026. printf ("DW_OP_fbreg: %s",
  1027. dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
  1028. data += bytes_read;
  1029. break;
  1030. case DW_OP_bregx:
  1031. uvalue = read_uleb128 (data, &bytes_read, end);
  1032. data += bytes_read;
  1033. printf ("DW_OP_bregx: %s (%s) %s",
  1034. dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
  1035. dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end)));
  1036. data += bytes_read;
  1037. break;
  1038. case DW_OP_piece:
  1039. printf ("DW_OP_piece: %s",
  1040. dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
  1041. data += bytes_read;
  1042. break;
  1043. case DW_OP_deref_size:
  1044. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1045. printf ("DW_OP_deref_size: %ld", (long) uvalue);
  1046. break;
  1047. case DW_OP_xderef_size:
  1048. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1049. printf ("DW_OP_xderef_size: %ld", (long) uvalue);
  1050. break;
  1051. case DW_OP_nop:
  1052. printf ("DW_OP_nop");
  1053. break;
  1054. /* DWARF 3 extensions. */
  1055. case DW_OP_push_object_address:
  1056. printf ("DW_OP_push_object_address");
  1057. break;
  1058. case DW_OP_call2:
  1059. /* XXX: Strictly speaking for 64-bit DWARF3 files
  1060. this ought to be an 8-byte wide computation. */
  1061. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
  1062. printf ("DW_OP_call2: <0x%s>",
  1063. dwarf_vmatoa ("x", svalue + cu_offset));
  1064. break;
  1065. case DW_OP_call4:
  1066. /* XXX: Strictly speaking for 64-bit DWARF3 files
  1067. this ought to be an 8-byte wide computation. */
  1068. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
  1069. printf ("DW_OP_call4: <0x%s>",
  1070. dwarf_vmatoa ("x", svalue + cu_offset));
  1071. break;
  1072. case DW_OP_call_ref:
  1073. /* XXX: Strictly speaking for 64-bit DWARF3 files
  1074. this ought to be an 8-byte wide computation. */
  1075. if (dwarf_version == -1)
  1076. {
  1077. printf (_("(DW_OP_call_ref in frame info)"));
  1078. /* No way to tell where the next op is, so just bail. */
  1079. return need_frame_base;
  1080. }
  1081. if (dwarf_version == 2)
  1082. {
  1083. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1084. }
  1085. else
  1086. {
  1087. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1088. }
  1089. printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
  1090. break;
  1091. case DW_OP_form_tls_address:
  1092. printf ("DW_OP_form_tls_address");
  1093. break;
  1094. case DW_OP_call_frame_cfa:
  1095. printf ("DW_OP_call_frame_cfa");
  1096. break;
  1097. case DW_OP_bit_piece:
  1098. printf ("DW_OP_bit_piece: ");
  1099. printf (_("size: %s "),
  1100. dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
  1101. data += bytes_read;
  1102. printf (_("offset: %s "),
  1103. dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end)));
  1104. data += bytes_read;
  1105. break;
  1106. /* DWARF 4 extensions. */
  1107. case DW_OP_stack_value:
  1108. printf ("DW_OP_stack_value");
  1109. break;
  1110. case DW_OP_implicit_value:
  1111. printf ("DW_OP_implicit_value");
  1112. uvalue = read_uleb128 (data, &bytes_read, end);
  1113. data += bytes_read;
  1114. data = display_block (data, uvalue, end);
  1115. break;
  1116. /* GNU extensions. */
  1117. case DW_OP_GNU_push_tls_address:
  1118. printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
  1119. break;
  1120. case DW_OP_GNU_uninit:
  1121. printf ("DW_OP_GNU_uninit");
  1122. /* FIXME: Is there data associated with this OP ? */
  1123. break;
  1124. case DW_OP_GNU_encoded_addr:
  1125. {
  1126. int encoding = 0;
  1127. dwarf_vma addr;
  1128. if (data < end)
  1129. encoding = *data++;
  1130. addr = get_encoded_value (&data, encoding, section, end);
  1131. printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
  1132. print_dwarf_vma (addr, pointer_size);
  1133. }
  1134. break;
  1135. case DW_OP_GNU_implicit_pointer:
  1136. /* XXX: Strictly speaking for 64-bit DWARF3 files
  1137. this ought to be an 8-byte wide computation. */
  1138. if (dwarf_version == -1)
  1139. {
  1140. printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
  1141. /* No way to tell where the next op is, so just bail. */
  1142. return need_frame_base;
  1143. }
  1144. if (dwarf_version == 2)
  1145. {
  1146. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1147. }
  1148. else
  1149. {
  1150. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1151. }
  1152. printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
  1153. dwarf_vmatoa ("x", uvalue),
  1154. dwarf_vmatoa ("d", read_sleb128 (data,
  1155. &bytes_read, end)));
  1156. data += bytes_read;
  1157. break;
  1158. case DW_OP_GNU_entry_value:
  1159. uvalue = read_uleb128 (data, &bytes_read, end);
  1160. data += bytes_read;
  1161. /* PR 17531: file: 0cc9cd00. */
  1162. if (uvalue > (dwarf_vma) (end - data))
  1163. uvalue = end - data;
  1164. printf ("DW_OP_GNU_entry_value: (");
  1165. if (decode_location_expression (data, pointer_size, offset_size,
  1166. dwarf_version, uvalue,
  1167. cu_offset, section))
  1168. need_frame_base = 1;
  1169. putchar (')');
  1170. data += uvalue;
  1171. if (data > end)
  1172. data = end;
  1173. break;
  1174. case DW_OP_GNU_const_type:
  1175. uvalue = read_uleb128 (data, &bytes_read, end);
  1176. data += bytes_read;
  1177. printf ("DW_OP_GNU_const_type: <0x%s> ",
  1178. dwarf_vmatoa ("x", cu_offset + uvalue));
  1179. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1180. data = display_block (data, uvalue, end);
  1181. break;
  1182. case DW_OP_GNU_regval_type:
  1183. uvalue = read_uleb128 (data, &bytes_read, end);
  1184. data += bytes_read;
  1185. printf ("DW_OP_GNU_regval_type: %s (%s)",
  1186. dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
  1187. uvalue = read_uleb128 (data, &bytes_read, end);
  1188. data += bytes_read;
  1189. printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
  1190. break;
  1191. case DW_OP_GNU_deref_type:
  1192. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1193. printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue);
  1194. uvalue = read_uleb128 (data, &bytes_read, end);
  1195. data += bytes_read;
  1196. printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
  1197. break;
  1198. case DW_OP_GNU_convert:
  1199. uvalue = read_uleb128 (data, &bytes_read, end);
  1200. data += bytes_read;
  1201. printf ("DW_OP_GNU_convert <0x%s>",
  1202. dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
  1203. break;
  1204. case DW_OP_GNU_reinterpret:
  1205. uvalue = read_uleb128 (data, &bytes_read, end);
  1206. data += bytes_read;
  1207. printf ("DW_OP_GNU_reinterpret <0x%s>",
  1208. dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
  1209. break;
  1210. case DW_OP_GNU_parameter_ref:
  1211. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  1212. printf ("DW_OP_GNU_parameter_ref: <0x%s>",
  1213. dwarf_vmatoa ("x", cu_offset + uvalue));
  1214. break;
  1215. case DW_OP_GNU_addr_index:
  1216. uvalue = read_uleb128 (data, &bytes_read, end);
  1217. data += bytes_read;
  1218. printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
  1219. break;
  1220. case DW_OP_GNU_const_index:
  1221. uvalue = read_uleb128 (data, &bytes_read, end);
  1222. data += bytes_read;
  1223. printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
  1224. break;
  1225. /* HP extensions. */
  1226. case DW_OP_HP_is_value:
  1227. printf ("DW_OP_HP_is_value");
  1228. /* FIXME: Is there data associated with this OP ? */
  1229. break;
  1230. case DW_OP_HP_fltconst4:
  1231. printf ("DW_OP_HP_fltconst4");
  1232. /* FIXME: Is there data associated with this OP ? */
  1233. break;
  1234. case DW_OP_HP_fltconst8:
  1235. printf ("DW_OP_HP_fltconst8");
  1236. /* FIXME: Is there data associated with this OP ? */
  1237. break;
  1238. case DW_OP_HP_mod_range:
  1239. printf ("DW_OP_HP_mod_range");
  1240. /* FIXME: Is there data associated with this OP ? */
  1241. break;
  1242. case DW_OP_HP_unmod_range:
  1243. printf ("DW_OP_HP_unmod_range");
  1244. /* FIXME: Is there data associated with this OP ? */
  1245. break;
  1246. case DW_OP_HP_tls:
  1247. printf ("DW_OP_HP_tls");
  1248. /* FIXME: Is there data associated with this OP ? */
  1249. break;
  1250. /* PGI (STMicroelectronics) extensions. */
  1251. case DW_OP_PGI_omp_thread_num:
  1252. /* Pushes the thread number for the current thread as it would be
  1253. returned by the standard OpenMP library function:
  1254. omp_get_thread_num(). The "current thread" is the thread for
  1255. which the expression is being evaluated. */
  1256. printf ("DW_OP_PGI_omp_thread_num");
  1257. break;
  1258. default:
  1259. if (op >= DW_OP_lo_user
  1260. && op <= DW_OP_hi_user)
  1261. printf (_("(User defined location op)"));
  1262. else
  1263. printf (_("(Unknown location op)"));
  1264. /* No way to tell where the next op is, so just bail. */
  1265. return need_frame_base;
  1266. }
  1267. /* Separate the ops. */
  1268. if (data < end)
  1269. printf ("; ");
  1270. }
  1271. return need_frame_base;
  1272. }
  1273. /* Find the CU or TU set corresponding to the given CU_OFFSET.
  1274. This is used for DWARF package files. */
  1275. static struct cu_tu_set *
  1276. find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
  1277. {
  1278. struct cu_tu_set *p;
  1279. unsigned int nsets;
  1280. unsigned int dw_sect;
  1281. if (do_types)
  1282. {
  1283. p = tu_sets;
  1284. nsets = tu_count;
  1285. dw_sect = DW_SECT_TYPES;
  1286. }
  1287. else
  1288. {
  1289. p = cu_sets;
  1290. nsets = cu_count;
  1291. dw_sect = DW_SECT_INFO;
  1292. }
  1293. while (nsets > 0)
  1294. {
  1295. if (p->section_offsets [dw_sect] == cu_offset)
  1296. return p;
  1297. p++;
  1298. nsets--;
  1299. }
  1300. return NULL;
  1301. }
  1302. /* Add INC to HIGH_BITS:LOW_BITS. */
  1303. static void
  1304. add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc)
  1305. {
  1306. dwarf_vma tmp = * low_bits;
  1307. tmp += inc;
  1308. /* FIXME: There is probably a better way of handling this:
  1309. We need to cope with dwarf_vma being a 32-bit or 64-bit
  1310. type. Plus regardless of its size LOW_BITS is meant to
  1311. only hold 32-bits, so if there is overflow or wrap around
  1312. we must propagate into HIGH_BITS. */
  1313. if (tmp < * low_bits)
  1314. {
  1315. ++ * high_bits;
  1316. }
  1317. else if (sizeof (tmp) > 8
  1318. && (tmp >> 31) > 1)
  1319. {
  1320. ++ * high_bits;
  1321. tmp &= 0xFFFFFFFF;
  1322. }
  1323. * low_bits = tmp;
  1324. }
  1325. static unsigned char *
  1326. read_and_display_attr_value (unsigned long attribute,
  1327. unsigned long form,
  1328. unsigned char * data,
  1329. unsigned char * end,
  1330. dwarf_vma cu_offset,
  1331. dwarf_vma pointer_size,
  1332. dwarf_vma offset_size,
  1333. int dwarf_version,
  1334. debug_info * debug_info_p,
  1335. int do_loc,
  1336. struct dwarf_section * section,
  1337. struct cu_tu_set * this_set)
  1338. {
  1339. dwarf_vma uvalue = 0;
  1340. unsigned char *block_start = NULL;
  1341. unsigned char * orig_data = data;
  1342. unsigned int bytes_read;
  1343. if (data > end || (data == end && form != DW_FORM_flag_present))
  1344. {
  1345. warn (_("Corrupt attribute\n"));
  1346. return data;
  1347. }
  1348. switch (form)
  1349. {
  1350. default:
  1351. break;
  1352. case DW_FORM_ref_addr:
  1353. if (dwarf_version == 2)
  1354. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1355. else if (dwarf_version == 3 || dwarf_version == 4)
  1356. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1357. else
  1358. error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
  1359. break;
  1360. case DW_FORM_addr:
  1361. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1362. break;
  1363. case DW_FORM_strp:
  1364. case DW_FORM_sec_offset:
  1365. case DW_FORM_GNU_ref_alt:
  1366. case DW_FORM_GNU_strp_alt:
  1367. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1368. break;
  1369. case DW_FORM_flag_present:
  1370. uvalue = 1;
  1371. break;
  1372. case DW_FORM_ref1:
  1373. case DW_FORM_flag:
  1374. case DW_FORM_data1:
  1375. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1376. break;
  1377. case DW_FORM_ref2:
  1378. case DW_FORM_data2:
  1379. SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
  1380. break;
  1381. case DW_FORM_ref4:
  1382. case DW_FORM_data4:
  1383. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  1384. break;
  1385. case DW_FORM_sdata:
  1386. uvalue = read_sleb128 (data, & bytes_read, end);
  1387. data += bytes_read;
  1388. break;
  1389. case DW_FORM_GNU_str_index:
  1390. uvalue = read_uleb128 (data, & bytes_read, end);
  1391. data += bytes_read;
  1392. break;
  1393. case DW_FORM_ref_udata:
  1394. case DW_FORM_udata:
  1395. uvalue = read_uleb128 (data, & bytes_read, end);
  1396. data += bytes_read;
  1397. break;
  1398. case DW_FORM_indirect:
  1399. form = read_uleb128 (data, & bytes_read, end);
  1400. data += bytes_read;
  1401. if (!do_loc)
  1402. printf (" %s", get_FORM_name (form));
  1403. return read_and_display_attr_value (attribute, form, data, end,
  1404. cu_offset, pointer_size,
  1405. offset_size, dwarf_version,
  1406. debug_info_p, do_loc,
  1407. section, this_set);
  1408. case DW_FORM_GNU_addr_index:
  1409. uvalue = read_uleb128 (data, & bytes_read, end);
  1410. data += bytes_read;
  1411. break;
  1412. }
  1413. switch (form)
  1414. {
  1415. case DW_FORM_ref_addr:
  1416. if (!do_loc)
  1417. printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
  1418. break;
  1419. case DW_FORM_GNU_ref_alt:
  1420. if (!do_loc)
  1421. printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
  1422. break;
  1423. case DW_FORM_ref1:
  1424. case DW_FORM_ref2:
  1425. case DW_FORM_ref4:
  1426. case DW_FORM_ref_udata:
  1427. if (!do_loc)
  1428. printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
  1429. break;
  1430. case DW_FORM_data4:
  1431. case DW_FORM_addr:
  1432. case DW_FORM_sec_offset:
  1433. if (!do_loc)
  1434. printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
  1435. break;
  1436. case DW_FORM_flag_present:
  1437. case DW_FORM_flag:
  1438. case DW_FORM_data1:
  1439. case DW_FORM_data2:
  1440. case DW_FORM_sdata:
  1441. case DW_FORM_udata:
  1442. if (!do_loc)
  1443. printf (" %s", dwarf_vmatoa ("d", uvalue));
  1444. break;
  1445. case DW_FORM_ref8:
  1446. case DW_FORM_data8:
  1447. if (!do_loc)
  1448. {
  1449. dwarf_vma high_bits;
  1450. dwarf_vma utmp;
  1451. char buf[64];
  1452. SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
  1453. utmp = uvalue;
  1454. if (form == DW_FORM_ref8)
  1455. add64 (& high_bits, & utmp, cu_offset);
  1456. printf (" 0x%s",
  1457. dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf)));
  1458. }
  1459. if ((do_loc || do_debug_loc || do_debug_ranges)
  1460. && num_debug_info_entries == 0)
  1461. {
  1462. if (sizeof (uvalue) == 8)
  1463. SAFE_BYTE_GET (uvalue, data, 8, end);
  1464. else
  1465. error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
  1466. }
  1467. data += 8;
  1468. break;
  1469. case DW_FORM_string:
  1470. if (!do_loc)
  1471. printf (" %.*s", (int) (end - data), data);
  1472. data += strnlen ((char *) data, end - data) + 1;
  1473. break;
  1474. case DW_FORM_block:
  1475. case DW_FORM_exprloc:
  1476. uvalue = read_uleb128 (data, & bytes_read, end);
  1477. block_start = data + bytes_read;
  1478. if (block_start >= end)
  1479. {
  1480. warn (_("Block ends prematurely\n"));
  1481. uvalue = 0;
  1482. block_start = end;
  1483. }
  1484. /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
  1485. gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
  1486. block_start + uvalue here. */
  1487. data = block_start + uvalue;
  1488. /* PR 17512: file: 008-103549-0.001:0.1. */
  1489. if (block_start + uvalue > end || data < block_start)
  1490. {
  1491. warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
  1492. uvalue = end - block_start;
  1493. }
  1494. if (do_loc)
  1495. data = block_start + uvalue;
  1496. else
  1497. data = display_block (block_start, uvalue, end);
  1498. break;
  1499. case DW_FORM_block1:
  1500. SAFE_BYTE_GET (uvalue, data, 1, end);
  1501. block_start = data + 1;
  1502. if (block_start >= end)
  1503. {
  1504. warn (_("Block ends prematurely\n"));
  1505. uvalue = 0;
  1506. block_start = end;
  1507. }
  1508. data = block_start + uvalue;
  1509. if (block_start + uvalue > end || data < block_start)
  1510. {
  1511. warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
  1512. uvalue = end - block_start;
  1513. }
  1514. if (do_loc)
  1515. data = block_start + uvalue;
  1516. else
  1517. data = display_block (block_start, uvalue, end);
  1518. break;
  1519. case DW_FORM_block2:
  1520. SAFE_BYTE_GET (uvalue, data, 2, end);
  1521. block_start = data + 2;
  1522. if (block_start >= end)
  1523. {
  1524. warn (_("Block ends prematurely\n"));
  1525. uvalue = 0;
  1526. block_start = end;
  1527. }
  1528. data = block_start + uvalue;
  1529. if (block_start + uvalue > end || data < block_start)
  1530. {
  1531. warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
  1532. uvalue = end - block_start;
  1533. }
  1534. if (do_loc)
  1535. data = block_start + uvalue;
  1536. else
  1537. data = display_block (block_start, uvalue, end);
  1538. break;
  1539. case DW_FORM_block4:
  1540. SAFE_BYTE_GET (uvalue, data, 4, end);
  1541. block_start = data + 4;
  1542. /* PR 17512: file: 3371-3907-0.004. */
  1543. if (block_start >= end)
  1544. {
  1545. warn (_("Block ends prematurely\n"));
  1546. uvalue = 0;
  1547. block_start = end;
  1548. }
  1549. data = block_start + uvalue;
  1550. if (block_start + uvalue > end
  1551. /* PR 17531: file: 5b5f0592. */
  1552. || data < block_start)
  1553. {
  1554. warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
  1555. uvalue = end - block_start;
  1556. }
  1557. if (do_loc)
  1558. data = block_start + uvalue;
  1559. else
  1560. data = display_block (block_start, uvalue, end);
  1561. break;
  1562. case DW_FORM_strp:
  1563. if (!do_loc)
  1564. printf (_(" (indirect string, offset: 0x%s): %s"),
  1565. dwarf_vmatoa ("x", uvalue),
  1566. fetch_indirect_string (uvalue));
  1567. break;
  1568. case DW_FORM_GNU_str_index:
  1569. if (!do_loc)
  1570. {
  1571. const char *suffix = strrchr (section->name, '.');
  1572. int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
  1573. printf (_(" (indexed string: 0x%s): %s"),
  1574. dwarf_vmatoa ("x", uvalue),
  1575. fetch_indexed_string (uvalue, this_set, offset_size, dwo));
  1576. }
  1577. break;
  1578. case DW_FORM_GNU_strp_alt:
  1579. if (!do_loc)
  1580. printf (_(" (alt indirect string, offset: 0x%s)"),
  1581. dwarf_vmatoa ("x", uvalue));
  1582. break;
  1583. case DW_FORM_indirect:
  1584. /* Handled above. */
  1585. break;
  1586. case DW_FORM_ref_sig8:
  1587. if (!do_loc)
  1588. {
  1589. dwarf_vma high_bits;
  1590. char buf[64];
  1591. SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
  1592. printf (" signature: 0x%s",
  1593. dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
  1594. }
  1595. data += 8;
  1596. break;
  1597. case DW_FORM_GNU_addr_index:
  1598. if (!do_loc)
  1599. printf (_(" (addr_index: 0x%s): %s"),
  1600. dwarf_vmatoa ("x", uvalue),
  1601. fetch_indexed_value (uvalue * pointer_size, pointer_size));
  1602. break;
  1603. default:
  1604. warn (_("Unrecognized form: %lu\n"), form);
  1605. break;
  1606. }
  1607. if ((do_loc || do_debug_loc || do_debug_ranges)
  1608. && num_debug_info_entries == 0
  1609. && debug_info_p != NULL)
  1610. {
  1611. switch (attribute)
  1612. {
  1613. case DW_AT_frame_base:
  1614. have_frame_base = 1;
  1615. case DW_AT_location:
  1616. case DW_AT_string_length:
  1617. case DW_AT_return_addr:
  1618. case DW_AT_data_member_location:
  1619. case DW_AT_vtable_elem_location:
  1620. case DW_AT_segment:
  1621. case DW_AT_static_link:
  1622. case DW_AT_use_location:
  1623. case DW_AT_GNU_call_site_value:
  1624. case DW_AT_GNU_call_site_data_value:
  1625. case DW_AT_GNU_call_site_target:
  1626. case DW_AT_GNU_call_site_target_clobbered:
  1627. if ((dwarf_version < 4
  1628. && (form == DW_FORM_data4 || form == DW_FORM_data8))
  1629. || form == DW_FORM_sec_offset)
  1630. {
  1631. /* Process location list. */
  1632. unsigned int lmax = debug_info_p->max_loc_offsets;
  1633. unsigned int num = debug_info_p->num_loc_offsets;
  1634. if (lmax == 0 || num >= lmax)
  1635. {
  1636. lmax += 1024;
  1637. debug_info_p->loc_offsets = (dwarf_vma *)
  1638. xcrealloc (debug_info_p->loc_offsets,
  1639. lmax, sizeof (*debug_info_p->loc_offsets));
  1640. debug_info_p->have_frame_base = (int *)
  1641. xcrealloc (debug_info_p->have_frame_base,
  1642. lmax, sizeof (*debug_info_p->have_frame_base));
  1643. debug_info_p->max_loc_offsets = lmax;
  1644. }
  1645. if (this_set != NULL)
  1646. uvalue += this_set->section_offsets [DW_SECT_LOC];
  1647. debug_info_p->loc_offsets [num] = uvalue;
  1648. debug_info_p->have_frame_base [num] = have_frame_base;
  1649. debug_info_p->num_loc_offsets++;
  1650. }
  1651. break;
  1652. case DW_AT_low_pc:
  1653. if (need_base_address)
  1654. debug_info_p->base_address = uvalue;
  1655. break;
  1656. case DW_AT_GNU_addr_base:
  1657. debug_info_p->addr_base = uvalue;
  1658. break;
  1659. case DW_AT_GNU_ranges_base:
  1660. debug_info_p->ranges_base = uvalue;
  1661. break;
  1662. case DW_AT_ranges:
  1663. if ((dwarf_version < 4
  1664. && (form == DW_FORM_data4 || form == DW_FORM_data8))
  1665. || form == DW_FORM_sec_offset)
  1666. {
  1667. /* Process range list. */
  1668. unsigned int lmax = debug_info_p->max_range_lists;
  1669. unsigned int num = debug_info_p->num_range_lists;
  1670. if (lmax == 0 || num >= lmax)
  1671. {
  1672. lmax += 1024;
  1673. debug_info_p->range_lists = (dwarf_vma *)
  1674. xcrealloc (debug_info_p->range_lists,
  1675. lmax, sizeof (*debug_info_p->range_lists));
  1676. debug_info_p->max_range_lists = lmax;
  1677. }
  1678. debug_info_p->range_lists [num] = uvalue;
  1679. debug_info_p->num_range_lists++;
  1680. }
  1681. break;
  1682. default:
  1683. break;
  1684. }
  1685. }
  1686. if (do_loc || attribute == 0)
  1687. return data;
  1688. /* For some attributes we can display further information. */
  1689. switch (attribute)
  1690. {
  1691. case DW_AT_inline:
  1692. printf ("\t");
  1693. switch (uvalue)
  1694. {
  1695. case DW_INL_not_inlined:
  1696. printf (_("(not inlined)"));
  1697. break;
  1698. case DW_INL_inlined:
  1699. printf (_("(inlined)"));
  1700. break;
  1701. case DW_INL_declared_not_inlined:
  1702. printf (_("(declared as inline but ignored)"));
  1703. break;
  1704. case DW_INL_declared_inlined:
  1705. printf (_("(declared as inline and inlined)"));
  1706. break;
  1707. default:
  1708. printf (_(" (Unknown inline attribute value: %s)"),
  1709. dwarf_vmatoa ("x", uvalue));
  1710. break;
  1711. }
  1712. break;
  1713. case DW_AT_language:
  1714. printf ("\t");
  1715. switch (uvalue)
  1716. {
  1717. /* Ordered by the numeric value of these constants. */
  1718. case DW_LANG_C89: printf ("(ANSI C)"); break;
  1719. case DW_LANG_C: printf ("(non-ANSI C)"); break;
  1720. case DW_LANG_Ada83: printf ("(Ada)"); break;
  1721. case DW_LANG_C_plus_plus: printf ("(C++)"); break;
  1722. case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
  1723. case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
  1724. case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
  1725. case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
  1726. case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
  1727. case DW_LANG_Modula2: printf ("(Modula 2)"); break;
  1728. /* DWARF 2.1 values. */
  1729. case DW_LANG_Java: printf ("(Java)"); break;
  1730. case DW_LANG_C99: printf ("(ANSI C99)"); break;
  1731. case DW_LANG_Ada95: printf ("(ADA 95)"); break;
  1732. case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
  1733. /* DWARF 3 values. */
  1734. case DW_LANG_PLI: printf ("(PLI)"); break;
  1735. case DW_LANG_ObjC: printf ("(Objective C)"); break;
  1736. case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
  1737. case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
  1738. case DW_LANG_D: printf ("(D)"); break;
  1739. /* DWARF 4 values. */
  1740. case DW_LANG_Python: printf ("(Python)"); break;
  1741. /* DWARF 5 values. */
  1742. case DW_LANG_Go: printf ("(Go)"); break;
  1743. case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
  1744. case DW_LANG_C11: printf ("(C11)"); break;
  1745. case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
  1746. case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
  1747. case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
  1748. /* MIPS extension. */
  1749. case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
  1750. /* UPC extension. */
  1751. case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
  1752. default:
  1753. if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
  1754. printf (_("(implementation defined: %s)"),
  1755. dwarf_vmatoa ("x", uvalue));
  1756. else
  1757. printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
  1758. break;
  1759. }
  1760. break;
  1761. case DW_AT_encoding:
  1762. printf ("\t");
  1763. switch (uvalue)
  1764. {
  1765. case DW_ATE_void: printf ("(void)"); break;
  1766. case DW_ATE_address: printf ("(machine address)"); break;
  1767. case DW_ATE_boolean: printf ("(boolean)"); break;
  1768. case DW_ATE_complex_float: printf ("(complex float)"); break;
  1769. case DW_ATE_float: printf ("(float)"); break;
  1770. case DW_ATE_signed: printf ("(signed)"); break;
  1771. case DW_ATE_signed_char: printf ("(signed char)"); break;
  1772. case DW_ATE_unsigned: printf ("(unsigned)"); break;
  1773. case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
  1774. /* DWARF 2.1 values: */
  1775. case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
  1776. case DW_ATE_decimal_float: printf ("(decimal float)"); break;
  1777. /* DWARF 3 values: */
  1778. case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
  1779. case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
  1780. case DW_ATE_edited: printf ("(edited)"); break;
  1781. case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
  1782. case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
  1783. /* HP extensions: */
  1784. case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
  1785. case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
  1786. case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
  1787. case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
  1788. case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
  1789. case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
  1790. case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
  1791. /* DWARF 4 values: */
  1792. case DW_ATE_UTF: printf ("(unicode string)"); break;
  1793. default:
  1794. if (uvalue >= DW_ATE_lo_user
  1795. && uvalue <= DW_ATE_hi_user)
  1796. printf (_("(user defined type)"));
  1797. else
  1798. printf (_("(unknown type)"));
  1799. break;
  1800. }
  1801. break;
  1802. case DW_AT_accessibility:
  1803. printf ("\t");
  1804. switch (uvalue)
  1805. {
  1806. case DW_ACCESS_public: printf ("(public)"); break;
  1807. case DW_ACCESS_protected: printf ("(protected)"); break;
  1808. case DW_ACCESS_private: printf ("(private)"); break;
  1809. default:
  1810. printf (_("(unknown accessibility)"));
  1811. break;
  1812. }
  1813. break;
  1814. case DW_AT_visibility:
  1815. printf ("\t");
  1816. switch (uvalue)
  1817. {
  1818. case DW_VIS_local: printf ("(local)"); break;
  1819. case DW_VIS_exported: printf ("(exported)"); break;
  1820. case DW_VIS_qualified: printf ("(qualified)"); break;
  1821. default: printf (_("(unknown visibility)")); break;
  1822. }
  1823. break;
  1824. case DW_AT_virtuality:
  1825. printf ("\t");
  1826. switch (uvalue)
  1827. {
  1828. case DW_VIRTUALITY_none: printf ("(none)"); break;
  1829. case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
  1830. case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
  1831. default: printf (_("(unknown virtuality)")); break;
  1832. }
  1833. break;
  1834. case DW_AT_identifier_case:
  1835. printf ("\t");
  1836. switch (uvalue)
  1837. {
  1838. case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
  1839. case DW_ID_up_case: printf ("(up_case)"); break;
  1840. case DW_ID_down_case: printf ("(down_case)"); break;
  1841. case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
  1842. default: printf (_("(unknown case)")); break;
  1843. }
  1844. break;
  1845. case DW_AT_calling_convention:
  1846. printf ("\t");
  1847. switch (uvalue)
  1848. {
  1849. case DW_CC_normal: printf ("(normal)"); break;
  1850. case DW_CC_program: printf ("(program)"); break;
  1851. case DW_CC_nocall: printf ("(nocall)"); break;
  1852. default:
  1853. if (uvalue >= DW_CC_lo_user
  1854. && uvalue <= DW_CC_hi_user)
  1855. printf (_("(user defined)"));
  1856. else
  1857. printf (_("(unknown convention)"));
  1858. }
  1859. break;
  1860. case DW_AT_ordering:
  1861. printf ("\t");
  1862. switch (uvalue)
  1863. {
  1864. case -1: printf (_("(undefined)")); break;
  1865. case 0: printf ("(row major)"); break;
  1866. case 1: printf ("(column major)"); break;
  1867. }
  1868. break;
  1869. case DW_AT_frame_base:
  1870. have_frame_base = 1;
  1871. case DW_AT_location:
  1872. case DW_AT_string_length:
  1873. case DW_AT_return_addr:
  1874. case DW_AT_data_member_location:
  1875. case DW_AT_vtable_elem_location:
  1876. case DW_AT_segment:
  1877. case DW_AT_static_link:
  1878. case DW_AT_use_location:
  1879. case DW_AT_GNU_call_site_value:
  1880. case DW_AT_GNU_call_site_data_value:
  1881. case DW_AT_GNU_call_site_target:
  1882. case DW_AT_GNU_call_site_target_clobbered:
  1883. if ((dwarf_version < 4
  1884. && (form == DW_FORM_data4 || form == DW_FORM_data8))
  1885. || form == DW_FORM_sec_offset)
  1886. printf (_(" (location list)"));
  1887. /* Fall through. */
  1888. case DW_AT_allocated:
  1889. case DW_AT_associated:
  1890. case DW_AT_data_location:
  1891. case DW_AT_stride:
  1892. case DW_AT_upper_bound:
  1893. case DW_AT_lower_bound:
  1894. if (block_start)
  1895. {
  1896. int need_frame_base;
  1897. printf ("\t(");
  1898. need_frame_base = decode_location_expression (block_start,
  1899. pointer_size,
  1900. offset_size,
  1901. dwarf_version,
  1902. uvalue,
  1903. cu_offset, section);
  1904. printf (")");
  1905. if (need_frame_base && !have_frame_base)
  1906. printf (_(" [without DW_AT_frame_base]"));
  1907. }
  1908. break;
  1909. case DW_AT_import:
  1910. {
  1911. if (form == DW_FORM_ref_sig8
  1912. || form == DW_FORM_GNU_ref_alt)
  1913. break;
  1914. if (form == DW_FORM_ref1
  1915. || form == DW_FORM_ref2
  1916. || form == DW_FORM_ref4
  1917. || form == DW_FORM_ref_udata)
  1918. uvalue += cu_offset;
  1919. if (uvalue >= section->size)
  1920. warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
  1921. dwarf_vmatoa ("x", uvalue),
  1922. (unsigned long) (orig_data - section->start));
  1923. else
  1924. {
  1925. unsigned long abbrev_number;
  1926. abbrev_entry * entry;
  1927. abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
  1928. printf (_("\t[Abbrev Number: %ld"), abbrev_number);
  1929. /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
  1930. use different abbrev table, and we don't track .debug_info chunks
  1931. yet. */
  1932. if (form != DW_FORM_ref_addr)
  1933. {
  1934. for (entry = first_abbrev; entry != NULL; entry = entry->next)
  1935. if (entry->entry == abbrev_number)
  1936. break;
  1937. if (entry != NULL)
  1938. printf (" (%s)", get_TAG_name (entry->tag));
  1939. }
  1940. printf ("]");
  1941. }
  1942. }
  1943. break;
  1944. default:
  1945. break;
  1946. }
  1947. return data;
  1948. }
  1949. static const char *
  1950. get_AT_name (unsigned long attribute)
  1951. {
  1952. const char *name;
  1953. if (attribute == 0)
  1954. return "DW_AT value: 0";
  1955. /* One value is shared by the MIPS and HP extensions: */
  1956. if (attribute == DW_AT_MIPS_fde)
  1957. return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
  1958. name = get_DW_AT_name (attribute);
  1959. if (name == NULL)
  1960. {
  1961. static char buffer[100];
  1962. snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
  1963. attribute);
  1964. return buffer;
  1965. }
  1966. return name;
  1967. }
  1968. static unsigned char *
  1969. read_and_display_attr (unsigned long attribute,
  1970. unsigned long form,
  1971. unsigned char * data,
  1972. unsigned char * end,
  1973. dwarf_vma cu_offset,
  1974. dwarf_vma pointer_size,
  1975. dwarf_vma offset_size,
  1976. int dwarf_version,
  1977. debug_info * debug_info_p,
  1978. int do_loc,
  1979. struct dwarf_section * section,
  1980. struct cu_tu_set * this_set)
  1981. {
  1982. if (!do_loc)
  1983. printf (" %-18s:", get_AT_name (attribute));
  1984. data = read_and_display_attr_value (attribute, form, data, end,
  1985. cu_offset, pointer_size, offset_size,
  1986. dwarf_version, debug_info_p,
  1987. do_loc, section, this_set);
  1988. if (!do_loc)
  1989. printf ("\n");
  1990. return data;
  1991. }
  1992. /* Process the contents of a .debug_info section. If do_loc is non-zero
  1993. then we are scanning for location lists and we do not want to display
  1994. anything to the user. If do_types is non-zero, we are processing
  1995. a .debug_types section instead of a .debug_info section. */
  1996. static int
  1997. process_debug_info (struct dwarf_section *section,
  1998. void *file,
  1999. enum dwarf_section_display_enum abbrev_sec,
  2000. int do_loc,
  2001. int do_types)
  2002. {
  2003. unsigned char *start = section->start;
  2004. unsigned char *end = start + section->size;
  2005. unsigned char *section_begin;
  2006. unsigned int unit;
  2007. unsigned int num_units = 0;
  2008. if ((do_loc || do_debug_loc || do_debug_ranges)
  2009. && num_debug_info_entries == 0
  2010. && ! do_types)
  2011. {
  2012. dwarf_vma length;
  2013. /* First scan the section to get the number of comp units. */
  2014. for (section_begin = start, num_units = 0; section_begin < end;
  2015. num_units ++)
  2016. {
  2017. /* Read the first 4 bytes. For a 32-bit DWARF section, this
  2018. will be the length. For a 64-bit DWARF section, it'll be
  2019. the escape code 0xffffffff followed by an 8 byte length. */
  2020. SAFE_BYTE_GET (length, section_begin, 4, end);
  2021. if (length == 0xffffffff)
  2022. {
  2023. SAFE_BYTE_GET (length, section_begin + 4, 8, end);
  2024. section_begin += length + 12;
  2025. }
  2026. else if (length >= 0xfffffff0 && length < 0xffffffff)
  2027. {
  2028. warn (_("Reserved length value (0x%s) found in section %s\n"),
  2029. dwarf_vmatoa ("x", length), section->name);
  2030. return 0;
  2031. }
  2032. else
  2033. section_begin += length + 4;
  2034. /* Negative values are illegal, they may even cause infinite
  2035. looping. This can happen if we can't accurately apply
  2036. relocations to an object file, or if the file is corrupt. */
  2037. if ((signed long) length <= 0 || section_begin < start)
  2038. {
  2039. warn (_("Corrupt unit length (0x%s) found in section %s\n"),
  2040. dwarf_vmatoa ("x", length), section->name);
  2041. return 0;
  2042. }
  2043. }
  2044. if (num_units == 0)
  2045. {
  2046. error (_("No comp units in %s section ?\n"), section->name);
  2047. return 0;
  2048. }
  2049. /* Then allocate an array to hold the information. */
  2050. debug_information = (debug_info *) cmalloc (num_units,
  2051. sizeof (* debug_information));
  2052. if (debug_information == NULL)
  2053. {
  2054. error (_("Not enough memory for a debug info array of %u entries\n"),
  2055. num_units);
  2056. alloc_num_debug_info_entries = num_debug_info_entries = 0;
  2057. return 0;
  2058. }
  2059. /* PR 17531: file: 92ca3797.
  2060. We cannot rely upon the debug_information array being initialised
  2061. before it is used. A corrupt file could easily contain references
  2062. to a unit for which information has not been made available. So
  2063. we ensure that the array is zeroed here. */
  2064. memset (debug_information, 0, num_units * sizeof (*debug_information));
  2065. alloc_num_debug_info_entries = num_units;
  2066. }
  2067. if (!do_loc)
  2068. {
  2069. if (dwarf_start_die == 0)
  2070. printf (_("Contents of the %s section:\n\n"), section->name);
  2071. load_debug_section (str, file);
  2072. load_debug_section (str_dwo, file);
  2073. load_debug_section (str_index, file);
  2074. load_debug_section (str_index_dwo, file);
  2075. load_debug_section (debug_addr, file);
  2076. }
  2077. load_debug_section (abbrev_sec, file);
  2078. if (debug_displays [abbrev_sec].section.start == NULL)
  2079. {
  2080. warn (_("Unable to locate %s section!\n"),
  2081. debug_displays [abbrev_sec].section.name);
  2082. return 0;
  2083. }
  2084. for (section_begin = start, unit = 0; start < end; unit++)
  2085. {
  2086. DWARF2_Internal_CompUnit compunit;
  2087. unsigned char *hdrptr;
  2088. unsigned char *tags;
  2089. int level, last_level, saved_level;
  2090. dwarf_vma cu_offset;
  2091. unsigned int offset_size;
  2092. int initial_length_size;
  2093. dwarf_vma signature_high = 0;
  2094. dwarf_vma signature_low = 0;
  2095. dwarf_vma type_offset = 0;
  2096. struct cu_tu_set *this_set;
  2097. dwarf_vma abbrev_base;
  2098. size_t abbrev_size;
  2099. hdrptr = start;
  2100. SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
  2101. if (compunit.cu_length == 0xffffffff)
  2102. {
  2103. SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
  2104. offset_size = 8;
  2105. initial_length_size = 12;
  2106. }
  2107. else
  2108. {
  2109. offset_size = 4;
  2110. initial_length_size = 4;
  2111. }
  2112. SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
  2113. cu_offset = start - section_begin;
  2114. this_set = find_cu_tu_set_v2 (cu_offset, do_types);
  2115. SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
  2116. if (this_set == NULL)
  2117. {
  2118. abbrev_base = 0;
  2119. abbrev_size = debug_displays [abbrev_sec].section.size;
  2120. }
  2121. else
  2122. {
  2123. abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
  2124. abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
  2125. }
  2126. SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
  2127. /* PR 17512: file: 001-108546-0.001:0.1. */
  2128. if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
  2129. {
  2130. warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
  2131. compunit.cu_pointer_size, offset_size);
  2132. compunit.cu_pointer_size = offset_size;
  2133. }
  2134. if (do_types)
  2135. {
  2136. SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
  2137. hdrptr += 8;
  2138. SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
  2139. }
  2140. if ((do_loc || do_debug_loc || do_debug_ranges)
  2141. && num_debug_info_entries == 0
  2142. && ! do_types)
  2143. {
  2144. debug_information [unit].cu_offset = cu_offset;
  2145. debug_information [unit].pointer_size
  2146. = compunit.cu_pointer_size;
  2147. debug_information [unit].offset_size = offset_size;
  2148. debug_information [unit].dwarf_version = compunit.cu_version;
  2149. debug_information [unit].base_address = 0;
  2150. debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
  2151. debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
  2152. debug_information [unit].loc_offsets = NULL;
  2153. debug_information [unit].have_frame_base = NULL;
  2154. debug_information [unit].max_loc_offsets = 0;
  2155. debug_information [unit].num_loc_offsets = 0;
  2156. debug_information [unit].range_lists = NULL;
  2157. debug_information [unit].max_range_lists= 0;
  2158. debug_information [unit].num_range_lists = 0;
  2159. }
  2160. if (!do_loc && dwarf_start_die == 0)
  2161. {
  2162. printf (_(" Compilation Unit @ offset 0x%s:\n"),
  2163. dwarf_vmatoa ("x", cu_offset));
  2164. printf (_(" Length: 0x%s (%s)\n"),
  2165. dwarf_vmatoa ("x", compunit.cu_length),
  2166. offset_size == 8 ? "64-bit" : "32-bit");
  2167. printf (_(" Version: %d\n"), compunit.cu_version);
  2168. printf (_(" Abbrev Offset: 0x%s\n"),
  2169. dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
  2170. printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
  2171. if (do_types)
  2172. {
  2173. char buf[64];
  2174. printf (_(" Signature: 0x%s\n"),
  2175. dwarf_vmatoa64 (signature_high, signature_low,
  2176. buf, sizeof (buf)));
  2177. printf (_(" Type Offset: 0x%s\n"),
  2178. dwarf_vmatoa ("x", type_offset));
  2179. }
  2180. if (this_set != NULL)
  2181. {
  2182. dwarf_vma *offsets = this_set->section_offsets;
  2183. size_t *sizes = this_set->section_sizes;
  2184. printf (_(" Section contributions:\n"));
  2185. printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
  2186. dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
  2187. dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
  2188. printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
  2189. dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
  2190. dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
  2191. printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
  2192. dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
  2193. dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
  2194. printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
  2195. dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
  2196. dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
  2197. }
  2198. }
  2199. if (cu_offset + compunit.cu_length + initial_length_size
  2200. > section->size)
  2201. {
  2202. warn (_("Debug info is corrupted, length of CU at %s"
  2203. " extends beyond end of section (length = %s)\n"),
  2204. dwarf_vmatoa ("x", cu_offset),
  2205. dwarf_vmatoa ("x", compunit.cu_length));
  2206. num_units = unit;
  2207. break;
  2208. }
  2209. tags = hdrptr;
  2210. start += compunit.cu_length + initial_length_size;
  2211. if (start > end)
  2212. {
  2213. warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
  2214. dwarf_vmatoa ("x", cu_offset));
  2215. start = end;
  2216. }
  2217. if (compunit.cu_version != 2
  2218. && compunit.cu_version != 3
  2219. && compunit.cu_version != 4)
  2220. {
  2221. warn (_("CU at offset %s contains corrupt or "
  2222. "unsupported version number: %d.\n"),
  2223. dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
  2224. continue;
  2225. }
  2226. free_abbrevs ();
  2227. /* Process the abbrevs used by this compilation unit. */
  2228. if (compunit.cu_abbrev_offset >= abbrev_size)
  2229. warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
  2230. (unsigned long) compunit.cu_abbrev_offset,
  2231. (unsigned long) abbrev_size);
  2232. /* PR 17531: file:4bcd9ce9. */
  2233. else if ((abbrev_base + abbrev_size)
  2234. > debug_displays [abbrev_sec].section.size)
  2235. warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
  2236. (unsigned long) abbrev_base + abbrev_size,
  2237. (unsigned long) debug_displays [abbrev_sec].section.size);
  2238. else
  2239. process_abbrev_section
  2240. (((unsigned char *) debug_displays [abbrev_sec].section.start
  2241. + abbrev_base + compunit.cu_abbrev_offset),
  2242. ((unsigned char *) debug_displays [abbrev_sec].section.start
  2243. + abbrev_base + abbrev_size));
  2244. level = 0;
  2245. last_level = level;
  2246. saved_level = -1;
  2247. while (tags < start)
  2248. {
  2249. unsigned int bytes_read;
  2250. unsigned long abbrev_number;
  2251. unsigned long die_offset;
  2252. abbrev_entry *entry;
  2253. abbrev_attr *attr;
  2254. int do_printing = 1;
  2255. die_offset = tags - section_begin;
  2256. abbrev_number = read_uleb128 (tags, & bytes_read, start);
  2257. tags += bytes_read;
  2258. /* A null DIE marks the end of a list of siblings or it may also be
  2259. a section padding. */
  2260. if (abbrev_number == 0)
  2261. {
  2262. /* Check if it can be a section padding for the last CU. */
  2263. if (level == 0 && start == end)
  2264. {
  2265. unsigned char *chk;
  2266. for (chk = tags; chk < start; chk++)
  2267. if (*chk != 0)
  2268. break;
  2269. if (chk == start)
  2270. break;
  2271. }
  2272. if (!do_loc && die_offset >= dwarf_start_die
  2273. && (dwarf_cutoff_level == -1
  2274. || level < dwarf_cutoff_level))
  2275. printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
  2276. level, die_offset);
  2277. --level;
  2278. if (level < 0)
  2279. {
  2280. static unsigned num_bogus_warns = 0;
  2281. if (num_bogus_warns < 3)
  2282. {
  2283. warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
  2284. die_offset, section->name);
  2285. num_bogus_warns ++;
  2286. if (num_bogus_warns == 3)
  2287. warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
  2288. }
  2289. }
  2290. if (dwarf_start_die != 0 && level < saved_level)
  2291. return 1;
  2292. continue;
  2293. }
  2294. if (!do_loc)
  2295. {
  2296. if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
  2297. do_printing = 0;
  2298. else
  2299. {
  2300. if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
  2301. saved_level = level;
  2302. do_printing = (dwarf_cutoff_level == -1
  2303. || level < dwarf_cutoff_level);
  2304. if (do_printing)
  2305. printf (_(" <%d><%lx>: Abbrev Number: %lu"),
  2306. level, die_offset, abbrev_number);
  2307. else if (dwarf_cutoff_level == -1
  2308. || last_level < dwarf_cutoff_level)
  2309. printf (_(" <%d><%lx>: ...\n"), level, die_offset);
  2310. last_level = level;
  2311. }
  2312. }
  2313. /* Scan through the abbreviation list until we reach the
  2314. correct entry. */
  2315. for (entry = first_abbrev;
  2316. entry && entry->entry != abbrev_number;
  2317. entry = entry->next)
  2318. continue;
  2319. if (entry == NULL)
  2320. {
  2321. if (!do_loc && do_printing)
  2322. {
  2323. printf ("\n");
  2324. fflush (stdout);
  2325. }
  2326. warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
  2327. die_offset, abbrev_number);
  2328. return 0;
  2329. }
  2330. if (!do_loc && do_printing)
  2331. printf (" (%s)\n", get_TAG_name (entry->tag));
  2332. switch (entry->tag)
  2333. {
  2334. default:
  2335. need_base_address = 0;
  2336. break;
  2337. case DW_TAG_compile_unit:
  2338. need_base_address = 1;
  2339. break;
  2340. case DW_TAG_entry_point:
  2341. case DW_TAG_subprogram:
  2342. need_base_address = 0;
  2343. /* Assuming that there is no DW_AT_frame_base. */
  2344. have_frame_base = 0;
  2345. break;
  2346. }
  2347. for (attr = entry->first_attr;
  2348. attr && attr->attribute;
  2349. attr = attr->next)
  2350. {
  2351. debug_info *arg;
  2352. if (! do_loc && do_printing)
  2353. /* Show the offset from where the tag was extracted. */
  2354. printf (" <%lx>", (unsigned long)(tags - section_begin));
  2355. if (debug_information && unit < alloc_num_debug_info_entries)
  2356. arg = debug_information + unit;
  2357. else
  2358. arg = NULL;
  2359. tags = read_and_display_attr (attr->attribute,
  2360. attr->form,
  2361. tags,
  2362. end,
  2363. cu_offset,
  2364. compunit.cu_pointer_size,
  2365. offset_size,
  2366. compunit.cu_version,
  2367. arg,
  2368. do_loc || ! do_printing,
  2369. section,
  2370. this_set);
  2371. }
  2372. if (entry->children)
  2373. ++level;
  2374. }
  2375. }
  2376. /* Set num_debug_info_entries here so that it can be used to check if
  2377. we need to process .debug_loc and .debug_ranges sections. */
  2378. if ((do_loc || do_debug_loc || do_debug_ranges)
  2379. && num_debug_info_entries == 0
  2380. && ! do_types)
  2381. {
  2382. if (num_units > alloc_num_debug_info_entries)
  2383. num_debug_info_entries = alloc_num_debug_info_entries;
  2384. else
  2385. num_debug_info_entries = num_units;
  2386. }
  2387. if (!do_loc)
  2388. printf ("\n");
  2389. return 1;
  2390. }
  2391. /* Locate and scan the .debug_info section in the file and record the pointer
  2392. sizes and offsets for the compilation units in it. Usually an executable
  2393. will have just one pointer size, but this is not guaranteed, and so we try
  2394. not to make any assumptions. Returns zero upon failure, or the number of
  2395. compilation units upon success. */
  2396. static unsigned int
  2397. load_debug_info (void * file)
  2398. {
  2399. /* Reset the last pointer size so that we can issue correct error
  2400. messages if we are displaying the contents of more than one section. */
  2401. last_pointer_size = 0;
  2402. warned_about_missing_comp_units = FALSE;
  2403. /* If we have already tried and failed to load the .debug_info
  2404. section then do not bother to repeat the task. */
  2405. if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
  2406. return 0;
  2407. /* If we already have the information there is nothing else to do. */
  2408. if (num_debug_info_entries > 0)
  2409. return num_debug_info_entries;
  2410. /* If this is a DWARF package file, load the CU and TU indexes. */
  2411. load_cu_tu_indexes (file);
  2412. if (load_debug_section (info, file)
  2413. && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
  2414. return num_debug_info_entries;
  2415. if (load_debug_section (info_dwo, file)
  2416. && process_debug_info (&debug_displays [info_dwo].section, file,
  2417. abbrev_dwo, 1, 0))
  2418. return num_debug_info_entries;
  2419. num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
  2420. return 0;
  2421. }
  2422. /* Read a DWARF .debug_line section header starting at DATA.
  2423. Upon success returns an updated DATA pointer and the LINFO
  2424. structure and the END_OF_SEQUENCE pointer will be filled in.
  2425. Otherwise returns NULL. */
  2426. static unsigned char *
  2427. read_debug_line_header (struct dwarf_section * section,
  2428. unsigned char * data,
  2429. unsigned char * end,
  2430. DWARF2_Internal_LineInfo * linfo,
  2431. unsigned char ** end_of_sequence)
  2432. {
  2433. unsigned char *hdrptr;
  2434. unsigned int offset_size;
  2435. unsigned int initial_length_size;
  2436. /* Extract information from the Line Number Program Header.
  2437. (section 6.2.4 in the Dwarf3 doc). */
  2438. hdrptr = data;
  2439. /* Get and check the length of the block. */
  2440. SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
  2441. if (linfo->li_length == 0xffffffff)
  2442. {
  2443. /* This section is 64-bit DWARF 3. */
  2444. SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
  2445. offset_size = 8;
  2446. initial_length_size = 12;
  2447. }
  2448. else
  2449. {
  2450. offset_size = 4;
  2451. initial_length_size = 4;
  2452. }
  2453. if (linfo->li_length + initial_length_size > section->size)
  2454. {
  2455. /* If the length field has a relocation against it, then we should
  2456. not complain if it is inaccurate (and probably negative). This
  2457. happens in object files when the .debug_line section is actually
  2458. comprised of several different .debug_line.* sections, (some of
  2459. which may be removed by linker garbage collection), and a relocation
  2460. is used to compute the correct length once that is done. */
  2461. if (reloc_at (section, (hdrptr - section->start) - offset_size))
  2462. {
  2463. linfo->li_length = (end - data) - initial_length_size;
  2464. }
  2465. else
  2466. {
  2467. warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
  2468. (long) linfo->li_length);
  2469. return NULL;
  2470. }
  2471. }
  2472. /* Get and check the version number. */
  2473. SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
  2474. if (linfo->li_version != 2
  2475. && linfo->li_version != 3
  2476. && linfo->li_version != 4)
  2477. {
  2478. warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
  2479. return NULL;
  2480. }
  2481. SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end);
  2482. SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
  2483. if (linfo->li_version >= 4)
  2484. {
  2485. SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
  2486. if (linfo->li_max_ops_per_insn == 0)
  2487. {
  2488. warn (_("Invalid maximum operations per insn.\n"));
  2489. return NULL;
  2490. }
  2491. }
  2492. else
  2493. linfo->li_max_ops_per_insn = 1;
  2494. SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
  2495. SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
  2496. SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
  2497. SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
  2498. * end_of_sequence = data + linfo->li_length + initial_length_size;
  2499. /* PR 17512: file:002-117414-0.004. */
  2500. if (* end_of_sequence > end)
  2501. {
  2502. warn (_("Line length %s extends beyond end of section\n"),
  2503. dwarf_vmatoa ("u", linfo->li_length));
  2504. * end_of_sequence = end;
  2505. return NULL;
  2506. }
  2507. return hdrptr;
  2508. }
  2509. static int
  2510. display_debug_lines_raw (struct dwarf_section *section,
  2511. unsigned char *data,
  2512. unsigned char *end)
  2513. {
  2514. unsigned char *start = section->start;
  2515. printf (_("Raw dump of debug contents of section %s:\n\n"),
  2516. section->name);
  2517. while (data < end)
  2518. {
  2519. static DWARF2_Internal_LineInfo saved_linfo;
  2520. DWARF2_Internal_LineInfo linfo;
  2521. unsigned char *standard_opcodes;
  2522. unsigned char *end_of_sequence;
  2523. unsigned int last_dir_entry = 0;
  2524. int i;
  2525. if (const_strneq (section->name, ".debug_line.")
  2526. /* Note: the following does not apply to .debug_line.dwo sections.
  2527. These are full debug_line sections. */
  2528. && strcmp (section->name, ".debug_line.dwo") != 0)
  2529. {
  2530. /* Sections named .debug_line.<foo> are fragments of a .debug_line
  2531. section containing just the Line Number Statements. They are
  2532. created by the assembler and intended to be used alongside gcc's
  2533. -ffunction-sections command line option. When the linker's
  2534. garbage collection decides to discard a .text.<foo> section it
  2535. can then also discard the line number information in .debug_line.<foo>.
  2536. Since the section is a fragment it does not have the details
  2537. needed to fill out a LineInfo structure, so instead we use the
  2538. details from the last full debug_line section that we processed. */
  2539. end_of_sequence = end;
  2540. standard_opcodes = NULL;
  2541. linfo = saved_linfo;
  2542. /* PR 17531: file: 0522b371. */
  2543. if (linfo.li_line_range == 0)
  2544. {
  2545. warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
  2546. return 0;
  2547. }
  2548. reset_state_machine (linfo.li_default_is_stmt);
  2549. }
  2550. else
  2551. {
  2552. unsigned char * hdrptr;
  2553. if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
  2554. & end_of_sequence)) == NULL)
  2555. return 0;
  2556. printf (_(" Offset: 0x%lx\n"), (long)(data - start));
  2557. printf (_(" Length: %ld\n"), (long) linfo.li_length);
  2558. printf (_(" DWARF Version: %d\n"), linfo.li_version);
  2559. printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
  2560. printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
  2561. if (linfo.li_version >= 4)
  2562. printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
  2563. printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
  2564. printf (_(" Line Base: %d\n"), linfo.li_line_base);
  2565. printf (_(" Line Range: %d\n"), linfo.li_line_range);
  2566. printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
  2567. /* PR 17512: file: 1665-6428-0.004. */
  2568. if (linfo.li_line_range == 0)
  2569. {
  2570. warn (_("Line range of 0 is invalid, using 1 instead\n"));
  2571. linfo.li_line_range = 1;
  2572. }
  2573. reset_state_machine (linfo.li_default_is_stmt);
  2574. /* Display the contents of the Opcodes table. */
  2575. standard_opcodes = hdrptr;
  2576. /* PR 17512: file: 002-417945-0.004. */
  2577. if (standard_opcodes + linfo.li_opcode_base >= end)
  2578. {
  2579. warn (_("Line Base extends beyond end of section\n"));
  2580. return 0;
  2581. }
  2582. printf (_("\n Opcodes:\n"));
  2583. for (i = 1; i < linfo.li_opcode_base; i++)
  2584. printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
  2585. /* Display the contents of the Directory table. */
  2586. data = standard_opcodes + linfo.li_opcode_base - 1;
  2587. if (*data == 0)
  2588. printf (_("\n The Directory Table is empty.\n"));
  2589. else
  2590. {
  2591. printf (_("\n The Directory Table (offset 0x%lx):\n"),
  2592. (long)(data - start));
  2593. while (data < end && *data != 0)
  2594. {
  2595. printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
  2596. data += strnlen ((char *) data, end - data) + 1;
  2597. }
  2598. /* PR 17512: file: 002-132094-0.004. */
  2599. if (data >= end - 1)
  2600. break;
  2601. }
  2602. /* Skip the NUL at the end of the table. */
  2603. data++;
  2604. /* Display the contents of the File Name table. */
  2605. if (*data == 0)
  2606. printf (_("\n The File Name Table is empty.\n"));
  2607. else
  2608. {
  2609. printf (_("\n The File Name Table (offset 0x%lx):\n"),
  2610. (long)(data - start));
  2611. printf (_(" Entry\tDir\tTime\tSize\tName\n"));
  2612. while (data < end && *data != 0)
  2613. {
  2614. unsigned char *name;
  2615. unsigned int bytes_read;
  2616. printf (" %d\t", ++state_machine_regs.last_file_entry);
  2617. name = data;
  2618. data += strnlen ((char *) data, end - data) + 1;
  2619. printf ("%s\t",
  2620. dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
  2621. data += bytes_read;
  2622. printf ("%s\t",
  2623. dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
  2624. data += bytes_read;
  2625. printf ("%s\t",
  2626. dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
  2627. data += bytes_read;
  2628. printf ("%.*s\n", (int)(end - name), name);
  2629. if (data == end)
  2630. {
  2631. warn (_("Corrupt file name table entry\n"));
  2632. break;
  2633. }
  2634. }
  2635. }
  2636. /* Skip the NUL at the end of the table. */
  2637. data++;
  2638. putchar ('\n');
  2639. saved_linfo = linfo;
  2640. }
  2641. /* Now display the statements. */
  2642. if (data >= end_of_sequence)
  2643. printf (_(" No Line Number Statements.\n"));
  2644. else
  2645. {
  2646. printf (_(" Line Number Statements:\n"));
  2647. while (data < end_of_sequence)
  2648. {
  2649. unsigned char op_code;
  2650. dwarf_signed_vma adv;
  2651. dwarf_vma uladv;
  2652. unsigned int bytes_read;
  2653. printf (" [0x%08lx]", (long)(data - start));
  2654. op_code = *data++;
  2655. if (op_code >= linfo.li_opcode_base)
  2656. {
  2657. op_code -= linfo.li_opcode_base;
  2658. uladv = (op_code / linfo.li_line_range);
  2659. if (linfo.li_max_ops_per_insn == 1)
  2660. {
  2661. uladv *= linfo.li_min_insn_length;
  2662. state_machine_regs.address += uladv;
  2663. printf (_(" Special opcode %d: "
  2664. "advance Address by %s to 0x%s"),
  2665. op_code, dwarf_vmatoa ("u", uladv),
  2666. dwarf_vmatoa ("x", state_machine_regs.address));
  2667. }
  2668. else
  2669. {
  2670. state_machine_regs.address
  2671. += ((state_machine_regs.op_index + uladv)
  2672. / linfo.li_max_ops_per_insn)
  2673. * linfo.li_min_insn_length;
  2674. state_machine_regs.op_index
  2675. = (state_machine_regs.op_index + uladv)
  2676. % linfo.li_max_ops_per_insn;
  2677. printf (_(" Special opcode %d: "
  2678. "advance Address by %s to 0x%s[%d]"),
  2679. op_code, dwarf_vmatoa ("u", uladv),
  2680. dwarf_vmatoa ("x", state_machine_regs.address),
  2681. state_machine_regs.op_index);
  2682. }
  2683. adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
  2684. state_machine_regs.line += adv;
  2685. printf (_(" and Line by %s to %d\n"),
  2686. dwarf_vmatoa ("d", adv), state_machine_regs.line);
  2687. }
  2688. else switch (op_code)
  2689. {
  2690. case DW_LNS_extended_op:
  2691. data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
  2692. break;
  2693. case DW_LNS_copy:
  2694. printf (_(" Copy\n"));
  2695. break;
  2696. case DW_LNS_advance_pc:
  2697. uladv = read_uleb128 (data, & bytes_read, end);
  2698. data += bytes_read;
  2699. if (linfo.li_max_ops_per_insn == 1)
  2700. {
  2701. uladv *= linfo.li_min_insn_length;
  2702. state_machine_regs.address += uladv;
  2703. printf (_(" Advance PC by %s to 0x%s\n"),
  2704. dwarf_vmatoa ("u", uladv),
  2705. dwarf_vmatoa ("x", state_machine_regs.address));
  2706. }
  2707. else
  2708. {
  2709. state_machine_regs.address
  2710. += ((state_machine_regs.op_index + uladv)
  2711. / linfo.li_max_ops_per_insn)
  2712. * linfo.li_min_insn_length;
  2713. state_machine_regs.op_index
  2714. = (state_machine_regs.op_index + uladv)
  2715. % linfo.li_max_ops_per_insn;
  2716. printf (_(" Advance PC by %s to 0x%s[%d]\n"),
  2717. dwarf_vmatoa ("u", uladv),
  2718. dwarf_vmatoa ("x", state_machine_regs.address),
  2719. state_machine_regs.op_index);
  2720. }
  2721. break;
  2722. case DW_LNS_advance_line:
  2723. adv = read_sleb128 (data, & bytes_read, end);
  2724. data += bytes_read;
  2725. state_machine_regs.line += adv;
  2726. printf (_(" Advance Line by %s to %d\n"),
  2727. dwarf_vmatoa ("d", adv),
  2728. state_machine_regs.line);
  2729. break;
  2730. case DW_LNS_set_file:
  2731. adv = read_uleb128 (data, & bytes_read, end);
  2732. data += bytes_read;
  2733. printf (_(" Set File Name to entry %s in the File Name Table\n"),
  2734. dwarf_vmatoa ("d", adv));
  2735. state_machine_regs.file = adv;
  2736. break;
  2737. case DW_LNS_set_column:
  2738. uladv = read_uleb128 (data, & bytes_read, end);
  2739. data += bytes_read;
  2740. printf (_(" Set column to %s\n"),
  2741. dwarf_vmatoa ("u", uladv));
  2742. state_machine_regs.column = uladv;
  2743. break;
  2744. case DW_LNS_negate_stmt:
  2745. adv = state_machine_regs.is_stmt;
  2746. adv = ! adv;
  2747. printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
  2748. state_machine_regs.is_stmt = adv;
  2749. break;
  2750. case DW_LNS_set_basic_block:
  2751. printf (_(" Set basic block\n"));
  2752. state_machine_regs.basic_block = 1;
  2753. break;
  2754. case DW_LNS_const_add_pc:
  2755. uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
  2756. if (linfo.li_max_ops_per_insn)
  2757. {
  2758. uladv *= linfo.li_min_insn_length;
  2759. state_machine_regs.address += uladv;
  2760. printf (_(" Advance PC by constant %s to 0x%s\n"),
  2761. dwarf_vmatoa ("u", uladv),
  2762. dwarf_vmatoa ("x", state_machine_regs.address));
  2763. }
  2764. else
  2765. {
  2766. state_machine_regs.address
  2767. += ((state_machine_regs.op_index + uladv)
  2768. / linfo.li_max_ops_per_insn)
  2769. * linfo.li_min_insn_length;
  2770. state_machine_regs.op_index
  2771. = (state_machine_regs.op_index + uladv)
  2772. % linfo.li_max_ops_per_insn;
  2773. printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
  2774. dwarf_vmatoa ("u", uladv),
  2775. dwarf_vmatoa ("x", state_machine_regs.address),
  2776. state_machine_regs.op_index);
  2777. }
  2778. break;
  2779. case DW_LNS_fixed_advance_pc:
  2780. SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
  2781. state_machine_regs.address += uladv;
  2782. state_machine_regs.op_index = 0;
  2783. printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
  2784. dwarf_vmatoa ("u", uladv),
  2785. dwarf_vmatoa ("x", state_machine_regs.address));
  2786. break;
  2787. case DW_LNS_set_prologue_end:
  2788. printf (_(" Set prologue_end to true\n"));
  2789. break;
  2790. case DW_LNS_set_epilogue_begin:
  2791. printf (_(" Set epilogue_begin to true\n"));
  2792. break;
  2793. case DW_LNS_set_isa:
  2794. uladv = read_uleb128 (data, & bytes_read, end);
  2795. data += bytes_read;
  2796. printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
  2797. break;
  2798. default:
  2799. printf (_(" Unknown opcode %d with operands: "), op_code);
  2800. if (standard_opcodes != NULL)
  2801. for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
  2802. {
  2803. printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
  2804. &bytes_read, end)),
  2805. i == 1 ? "" : ", ");
  2806. data += bytes_read;
  2807. }
  2808. putchar ('\n');
  2809. break;
  2810. }
  2811. }
  2812. putchar ('\n');
  2813. }
  2814. }
  2815. return 1;
  2816. }
  2817. typedef struct
  2818. {
  2819. unsigned char *name;
  2820. unsigned int directory_index;
  2821. unsigned int modification_date;
  2822. unsigned int length;
  2823. } File_Entry;
  2824. /* Output a decoded representation of the .debug_line section. */
  2825. static int
  2826. display_debug_lines_decoded (struct dwarf_section *section,
  2827. unsigned char *data,
  2828. unsigned char *end)
  2829. {
  2830. static DWARF2_Internal_LineInfo saved_linfo;
  2831. printf (_("Decoded dump of debug contents of section %s:\n\n"),
  2832. section->name);
  2833. while (data < end)
  2834. {
  2835. /* This loop amounts to one iteration per compilation unit. */
  2836. DWARF2_Internal_LineInfo linfo;
  2837. unsigned char *standard_opcodes;
  2838. unsigned char *end_of_sequence;
  2839. int i;
  2840. File_Entry *file_table = NULL;
  2841. unsigned int n_files = 0;
  2842. unsigned char **directory_table = NULL;
  2843. unsigned int n_directories = 0;
  2844. if (const_strneq (section->name, ".debug_line.")
  2845. /* Note: the following does not apply to .debug_line.dwo sections.
  2846. These are full debug_line sections. */
  2847. && strcmp (section->name, ".debug_line.dwo") != 0)
  2848. {
  2849. /* See comment in display_debug_lines_raw(). */
  2850. end_of_sequence = end;
  2851. standard_opcodes = NULL;
  2852. linfo = saved_linfo;
  2853. /* PR 17531: file: 0522b371. */
  2854. if (linfo.li_line_range == 0)
  2855. {
  2856. warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
  2857. return 0;
  2858. }
  2859. reset_state_machine (linfo.li_default_is_stmt);
  2860. }
  2861. else
  2862. {
  2863. unsigned char *hdrptr;
  2864. if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
  2865. & end_of_sequence)) == NULL)
  2866. return 0;
  2867. /* PR 17531: file: 0522b371. */
  2868. if (linfo.li_line_range == 0)
  2869. {
  2870. warn (_("Line range of 0 is invalid, using 1 instead\n"));
  2871. linfo.li_line_range = 1;
  2872. }
  2873. reset_state_machine (linfo.li_default_is_stmt);
  2874. /* Save a pointer to the contents of the Opcodes table. */
  2875. standard_opcodes = hdrptr;
  2876. /* Traverse the Directory table just to count entries. */
  2877. data = standard_opcodes + linfo.li_opcode_base - 1;
  2878. if (*data != 0)
  2879. {
  2880. unsigned char *ptr_directory_table = data;
  2881. while (*data != 0)
  2882. {
  2883. data += strnlen ((char *) data, end - data) + 1;
  2884. n_directories++;
  2885. }
  2886. /* Go through the directory table again to save the directories. */
  2887. directory_table = (unsigned char **)
  2888. xmalloc (n_directories * sizeof (unsigned char *));
  2889. i = 0;
  2890. while (*ptr_directory_table != 0)
  2891. {
  2892. directory_table[i] = ptr_directory_table;
  2893. ptr_directory_table += strnlen ((char *) ptr_directory_table,
  2894. ptr_directory_table - end) + 1;
  2895. i++;
  2896. }
  2897. }
  2898. /* Skip the NUL at the end of the table. */
  2899. data++;
  2900. /* Traverse the File Name table just to count the entries. */
  2901. if (*data != 0)
  2902. {
  2903. unsigned char *ptr_file_name_table = data;
  2904. while (*data != 0)
  2905. {
  2906. unsigned int bytes_read;
  2907. /* Skip Name, directory index, last modification time and length
  2908. of file. */
  2909. data += strnlen ((char *) data, end - data) + 1;
  2910. read_uleb128 (data, & bytes_read, end);
  2911. data += bytes_read;
  2912. read_uleb128 (data, & bytes_read, end);
  2913. data += bytes_read;
  2914. read_uleb128 (data, & bytes_read, end);
  2915. data += bytes_read;
  2916. n_files++;
  2917. }
  2918. /* Go through the file table again to save the strings. */
  2919. file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
  2920. i = 0;
  2921. while (*ptr_file_name_table != 0)
  2922. {
  2923. unsigned int bytes_read;
  2924. file_table[i].name = ptr_file_name_table;
  2925. ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
  2926. end - ptr_file_name_table) + 1;
  2927. /* We are not interested in directory, time or size. */
  2928. file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
  2929. & bytes_read, end);
  2930. ptr_file_name_table += bytes_read;
  2931. file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
  2932. & bytes_read, end);
  2933. ptr_file_name_table += bytes_read;
  2934. file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
  2935. ptr_file_name_table += bytes_read;
  2936. i++;
  2937. }
  2938. i = 0;
  2939. /* Print the Compilation Unit's name and a header. */
  2940. if (directory_table == NULL)
  2941. {
  2942. printf (_("CU: %s:\n"), file_table[0].name);
  2943. printf (_("File name Line number Starting address\n"));
  2944. }
  2945. else
  2946. {
  2947. unsigned int ix = file_table[0].directory_index;
  2948. const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
  2949. if (do_wide || strlen (directory) < 76)
  2950. printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
  2951. else
  2952. printf ("%s:\n", file_table[0].name);
  2953. printf (_("File name Line number Starting address\n"));
  2954. }
  2955. }
  2956. /* Skip the NUL at the end of the table. */
  2957. data++;
  2958. saved_linfo = linfo;
  2959. }
  2960. /* This loop iterates through the Dwarf Line Number Program. */
  2961. while (data < end_of_sequence)
  2962. {
  2963. unsigned char op_code;
  2964. int adv;
  2965. unsigned long int uladv;
  2966. unsigned int bytes_read;
  2967. int is_special_opcode = 0;
  2968. op_code = *data++;
  2969. if (op_code >= linfo.li_opcode_base)
  2970. {
  2971. op_code -= linfo.li_opcode_base;
  2972. uladv = (op_code / linfo.li_line_range);
  2973. if (linfo.li_max_ops_per_insn == 1)
  2974. {
  2975. uladv *= linfo.li_min_insn_length;
  2976. state_machine_regs.address += uladv;
  2977. }
  2978. else
  2979. {
  2980. state_machine_regs.address
  2981. += ((state_machine_regs.op_index + uladv)
  2982. / linfo.li_max_ops_per_insn)
  2983. * linfo.li_min_insn_length;
  2984. state_machine_regs.op_index
  2985. = (state_machine_regs.op_index + uladv)
  2986. % linfo.li_max_ops_per_insn;
  2987. }
  2988. adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
  2989. state_machine_regs.line += adv;
  2990. is_special_opcode = 1;
  2991. }
  2992. else switch (op_code)
  2993. {
  2994. case DW_LNS_extended_op:
  2995. {
  2996. unsigned int ext_op_code_len;
  2997. unsigned char ext_op_code;
  2998. unsigned char *op_code_data = data;
  2999. ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
  3000. end_of_sequence);
  3001. op_code_data += bytes_read;
  3002. if (ext_op_code_len == 0)
  3003. {
  3004. warn (_("Badly formed extended line op encountered!\n"));
  3005. break;
  3006. }
  3007. ext_op_code_len += bytes_read;
  3008. ext_op_code = *op_code_data++;
  3009. switch (ext_op_code)
  3010. {
  3011. case DW_LNE_end_sequence:
  3012. reset_state_machine (linfo.li_default_is_stmt);
  3013. break;
  3014. case DW_LNE_set_address:
  3015. SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
  3016. op_code_data,
  3017. ext_op_code_len - bytes_read - 1,
  3018. end);
  3019. state_machine_regs.op_index = 0;
  3020. break;
  3021. case DW_LNE_define_file:
  3022. {
  3023. file_table = (File_Entry *) xrealloc
  3024. (file_table, (n_files + 1) * sizeof (File_Entry));
  3025. ++state_machine_regs.last_file_entry;
  3026. /* Source file name. */
  3027. file_table[n_files].name = op_code_data;
  3028. op_code_data += strlen ((char *) op_code_data) + 1;
  3029. /* Directory index. */
  3030. file_table[n_files].directory_index =
  3031. read_uleb128 (op_code_data, & bytes_read,
  3032. end_of_sequence);
  3033. op_code_data += bytes_read;
  3034. /* Last modification time. */
  3035. file_table[n_files].modification_date =
  3036. read_uleb128 (op_code_data, & bytes_read,
  3037. end_of_sequence);
  3038. op_code_data += bytes_read;
  3039. /* File length. */
  3040. file_table[n_files].length =
  3041. read_uleb128 (op_code_data, & bytes_read,
  3042. end_of_sequence);
  3043. n_files++;
  3044. break;
  3045. }
  3046. case DW_LNE_set_discriminator:
  3047. case DW_LNE_HP_set_sequence:
  3048. /* Simply ignored. */
  3049. break;
  3050. default:
  3051. printf (_("UNKNOWN (%u): length %d\n"),
  3052. ext_op_code, ext_op_code_len - bytes_read);
  3053. break;
  3054. }
  3055. data += ext_op_code_len;
  3056. break;
  3057. }
  3058. case DW_LNS_copy:
  3059. break;
  3060. case DW_LNS_advance_pc:
  3061. uladv = read_uleb128 (data, & bytes_read, end);
  3062. data += bytes_read;
  3063. if (linfo.li_max_ops_per_insn == 1)
  3064. {
  3065. uladv *= linfo.li_min_insn_length;
  3066. state_machine_regs.address += uladv;
  3067. }
  3068. else
  3069. {
  3070. state_machine_regs.address
  3071. += ((state_machine_regs.op_index + uladv)
  3072. / linfo.li_max_ops_per_insn)
  3073. * linfo.li_min_insn_length;
  3074. state_machine_regs.op_index
  3075. = (state_machine_regs.op_index + uladv)
  3076. % linfo.li_max_ops_per_insn;
  3077. }
  3078. break;
  3079. case DW_LNS_advance_line:
  3080. adv = read_sleb128 (data, & bytes_read, end);
  3081. data += bytes_read;
  3082. state_machine_regs.line += adv;
  3083. break;
  3084. case DW_LNS_set_file:
  3085. adv = read_uleb128 (data, & bytes_read, end);
  3086. data += bytes_read;
  3087. state_machine_regs.file = adv;
  3088. if (file_table == NULL)
  3089. printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1);
  3090. else if (file_table[state_machine_regs.file - 1].directory_index == 0)
  3091. /* If directory index is 0, that means current directory. */
  3092. printf ("\n./%s:[++]\n",
  3093. file_table[state_machine_regs.file - 1].name);
  3094. else if (directory_table == NULL)
  3095. printf (_("\n [Use directory table entry %d]\n"),
  3096. file_table[state_machine_regs.file - 1].directory_index - 1);
  3097. else
  3098. /* The directory index starts counting at 1. */
  3099. printf ("\n%s/%s:\n",
  3100. directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
  3101. file_table[state_machine_regs.file - 1].name);
  3102. break;
  3103. case DW_LNS_set_column:
  3104. uladv = read_uleb128 (data, & bytes_read, end);
  3105. data += bytes_read;
  3106. state_machine_regs.column = uladv;
  3107. break;
  3108. case DW_LNS_negate_stmt:
  3109. adv = state_machine_regs.is_stmt;
  3110. adv = ! adv;
  3111. state_machine_regs.is_stmt = adv;
  3112. break;
  3113. case DW_LNS_set_basic_block:
  3114. state_machine_regs.basic_block = 1;
  3115. break;
  3116. case DW_LNS_const_add_pc:
  3117. uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
  3118. if (linfo.li_max_ops_per_insn == 1)
  3119. {
  3120. uladv *= linfo.li_min_insn_length;
  3121. state_machine_regs.address += uladv;
  3122. }
  3123. else
  3124. {
  3125. state_machine_regs.address
  3126. += ((state_machine_regs.op_index + uladv)
  3127. / linfo.li_max_ops_per_insn)
  3128. * linfo.li_min_insn_length;
  3129. state_machine_regs.op_index
  3130. = (state_machine_regs.op_index + uladv)
  3131. % linfo.li_max_ops_per_insn;
  3132. }
  3133. break;
  3134. case DW_LNS_fixed_advance_pc:
  3135. SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
  3136. state_machine_regs.address += uladv;
  3137. state_machine_regs.op_index = 0;
  3138. break;
  3139. case DW_LNS_set_prologue_end:
  3140. break;
  3141. case DW_LNS_set_epilogue_begin:
  3142. break;
  3143. case DW_LNS_set_isa:
  3144. uladv = read_uleb128 (data, & bytes_read, end);
  3145. data += bytes_read;
  3146. printf (_(" Set ISA to %lu\n"), uladv);
  3147. break;
  3148. default:
  3149. printf (_(" Unknown opcode %d with operands: "), op_code);
  3150. if (standard_opcodes != NULL)
  3151. for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
  3152. {
  3153. printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
  3154. &bytes_read, end)),
  3155. i == 1 ? "" : ", ");
  3156. data += bytes_read;
  3157. }
  3158. putchar ('\n');
  3159. break;
  3160. }
  3161. /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
  3162. to the DWARF address/line matrix. */
  3163. if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
  3164. || (op_code == DW_LNS_copy))
  3165. {
  3166. const unsigned int MAX_FILENAME_LENGTH = 35;
  3167. char *fileName;
  3168. char *newFileName = NULL;
  3169. size_t fileNameLength;
  3170. if (file_table)
  3171. fileName = (char *) file_table[state_machine_regs.file - 1].name;
  3172. else
  3173. fileName = "<unknown>";
  3174. fileNameLength = strlen (fileName);
  3175. if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
  3176. {
  3177. newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
  3178. /* Truncate file name */
  3179. strncpy (newFileName,
  3180. fileName + fileNameLength - MAX_FILENAME_LENGTH,
  3181. MAX_FILENAME_LENGTH + 1);
  3182. }
  3183. else
  3184. {
  3185. newFileName = (char *) xmalloc (fileNameLength + 1);
  3186. strncpy (newFileName, fileName, fileNameLength + 1);
  3187. }
  3188. if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
  3189. {
  3190. if (linfo.li_max_ops_per_insn == 1)
  3191. printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
  3192. newFileName, state_machine_regs.line,
  3193. state_machine_regs.address);
  3194. else
  3195. printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
  3196. newFileName, state_machine_regs.line,
  3197. state_machine_regs.address,
  3198. state_machine_regs.op_index);
  3199. }
  3200. else
  3201. {
  3202. if (linfo.li_max_ops_per_insn == 1)
  3203. printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
  3204. newFileName, state_machine_regs.line,
  3205. state_machine_regs.address);
  3206. else
  3207. printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
  3208. newFileName, state_machine_regs.line,
  3209. state_machine_regs.address,
  3210. state_machine_regs.op_index);
  3211. }
  3212. if (op_code == DW_LNE_end_sequence)
  3213. printf ("\n");
  3214. free (newFileName);
  3215. }
  3216. }
  3217. if (file_table)
  3218. {
  3219. free (file_table);
  3220. file_table = NULL;
  3221. n_files = 0;
  3222. }
  3223. if (directory_table)
  3224. {
  3225. free (directory_table);
  3226. directory_table = NULL;
  3227. n_directories = 0;
  3228. }
  3229. putchar ('\n');
  3230. }
  3231. return 1;
  3232. }
  3233. static int
  3234. display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
  3235. {
  3236. unsigned char *data = section->start;
  3237. unsigned char *end = data + section->size;
  3238. int retValRaw = 1;
  3239. int retValDecoded = 1;
  3240. if (do_debug_lines == 0)
  3241. do_debug_lines |= FLAG_DEBUG_LINES_RAW;
  3242. if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
  3243. retValRaw = display_debug_lines_raw (section, data, end);
  3244. if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
  3245. retValDecoded = display_debug_lines_decoded (section, data, end);
  3246. if (!retValRaw || !retValDecoded)
  3247. return 0;
  3248. return 1;
  3249. }
  3250. static debug_info *
  3251. find_debug_info_for_offset (unsigned long offset)
  3252. {
  3253. unsigned int i;
  3254. if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
  3255. return NULL;
  3256. for (i = 0; i < num_debug_info_entries; i++)
  3257. if (debug_information[i].cu_offset == offset)
  3258. return debug_information + i;
  3259. return NULL;
  3260. }
  3261. static const char *
  3262. get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
  3263. {
  3264. /* See gdb/gdb-index.h. */
  3265. static const char * const kinds[] =
  3266. {
  3267. N_ ("no info"),
  3268. N_ ("type"),
  3269. N_ ("variable"),
  3270. N_ ("function"),
  3271. N_ ("other"),
  3272. N_ ("unused5"),
  3273. N_ ("unused6"),
  3274. N_ ("unused7")
  3275. };
  3276. return _ (kinds[kind]);
  3277. }
  3278. static int
  3279. display_debug_pubnames_worker (struct dwarf_section *section,
  3280. void *file ATTRIBUTE_UNUSED,
  3281. int is_gnu)
  3282. {
  3283. DWARF2_Internal_PubNames names;
  3284. unsigned char *start = section->start;
  3285. unsigned char *end = start + section->size;
  3286. /* It does not matter if this load fails,
  3287. we test for that later on. */
  3288. load_debug_info (file);
  3289. printf (_("Contents of the %s section:\n\n"), section->name);
  3290. while (start < end)
  3291. {
  3292. unsigned char *data;
  3293. unsigned char *adr;
  3294. dwarf_vma offset;
  3295. unsigned int offset_size, initial_length_size;
  3296. data = start;
  3297. SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
  3298. if (names.pn_length == 0xffffffff)
  3299. {
  3300. SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
  3301. offset_size = 8;
  3302. initial_length_size = 12;
  3303. }
  3304. else
  3305. {
  3306. offset_size = 4;
  3307. initial_length_size = 4;
  3308. }
  3309. SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
  3310. SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
  3311. if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
  3312. && num_debug_info_entries > 0
  3313. && find_debug_info_for_offset (names.pn_offset) == NULL)
  3314. warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
  3315. (unsigned long) names.pn_offset, section->name);
  3316. SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
  3317. adr = start + names.pn_length + initial_length_size;
  3318. /* PR 17531: file: 7615b6b2. */
  3319. if ((dwarf_signed_vma) names.pn_length < 0
  3320. /* PR 17531: file: a5dbeaa7. */
  3321. || adr < start)
  3322. {
  3323. warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
  3324. start = end;
  3325. }
  3326. else
  3327. start = adr;
  3328. printf (_(" Length: %ld\n"),
  3329. (long) names.pn_length);
  3330. printf (_(" Version: %d\n"),
  3331. names.pn_version);
  3332. printf (_(" Offset into .debug_info section: 0x%lx\n"),
  3333. (unsigned long) names.pn_offset);
  3334. printf (_(" Size of area in .debug_info section: %ld\n"),
  3335. (long) names.pn_size);
  3336. if (names.pn_version != 2 && names.pn_version != 3)
  3337. {
  3338. static int warned = 0;
  3339. if (! warned)
  3340. {
  3341. warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
  3342. warned = 1;
  3343. }
  3344. continue;
  3345. }
  3346. if (is_gnu)
  3347. printf (_("\n Offset Kind Name\n"));
  3348. else
  3349. printf (_("\n Offset\tName\n"));
  3350. do
  3351. {
  3352. bfd_size_type maxprint;
  3353. SAFE_BYTE_GET (offset, data, offset_size, end);
  3354. if (offset != 0)
  3355. {
  3356. data += offset_size;
  3357. if (data >= end)
  3358. break;
  3359. maxprint = (end - data) - 1;
  3360. if (is_gnu)
  3361. {
  3362. unsigned int kind_data;
  3363. gdb_index_symbol_kind kind;
  3364. const char *kind_name;
  3365. int is_static;
  3366. SAFE_BYTE_GET (kind_data, data, 1, end);
  3367. data++;
  3368. maxprint --;
  3369. /* GCC computes the kind as the upper byte in the CU index
  3370. word, and then right shifts it by the CU index size.
  3371. Left shift KIND to where the gdb-index.h accessor macros
  3372. can use it. */
  3373. kind_data <<= GDB_INDEX_CU_BITSIZE;
  3374. kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
  3375. kind_name = get_gdb_index_symbol_kind_name (kind);
  3376. is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
  3377. printf (" %-6lx %s,%-10s %.*s\n",
  3378. (unsigned long) offset, is_static ? _("s") : _("g"),
  3379. kind_name, (int) maxprint, data);
  3380. }
  3381. else
  3382. printf (" %-6lx\t%.*s\n",
  3383. (unsigned long) offset, (int) maxprint, data);
  3384. data += strnlen ((char *) data, maxprint) + 1;
  3385. if (data >= end)
  3386. break;
  3387. }
  3388. }
  3389. while (offset != 0);
  3390. }
  3391. printf ("\n");
  3392. return 1;
  3393. }
  3394. static int
  3395. display_debug_pubnames (struct dwarf_section *section, void *file)
  3396. {
  3397. return display_debug_pubnames_worker (section, file, 0);
  3398. }
  3399. static int
  3400. display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
  3401. {
  3402. return display_debug_pubnames_worker (section, file, 1);
  3403. }
  3404. static int
  3405. display_debug_macinfo (struct dwarf_section *section,
  3406. void *file ATTRIBUTE_UNUSED)
  3407. {
  3408. unsigned char *start = section->start;
  3409. unsigned char *end = start + section->size;
  3410. unsigned char *curr = start;
  3411. unsigned int bytes_read;
  3412. enum dwarf_macinfo_record_type op;
  3413. printf (_("Contents of the %s section:\n\n"), section->name);
  3414. while (curr < end)
  3415. {
  3416. unsigned int lineno;
  3417. const unsigned char *string;
  3418. op = (enum dwarf_macinfo_record_type) *curr;
  3419. curr++;
  3420. switch (op)
  3421. {
  3422. case DW_MACINFO_start_file:
  3423. {
  3424. unsigned int filenum;
  3425. lineno = read_uleb128 (curr, & bytes_read, end);
  3426. curr += bytes_read;
  3427. filenum = read_uleb128 (curr, & bytes_read, end);
  3428. curr += bytes_read;
  3429. printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
  3430. lineno, filenum);
  3431. }
  3432. break;
  3433. case DW_MACINFO_end_file:
  3434. printf (_(" DW_MACINFO_end_file\n"));
  3435. break;
  3436. case DW_MACINFO_define:
  3437. lineno = read_uleb128 (curr, & bytes_read, end);
  3438. curr += bytes_read;
  3439. string = curr;
  3440. curr += strnlen ((char *) string, end - string) + 1;
  3441. printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
  3442. lineno, string);
  3443. break;
  3444. case DW_MACINFO_undef:
  3445. lineno = read_uleb128 (curr, & bytes_read, end);
  3446. curr += bytes_read;
  3447. string = curr;
  3448. curr += strnlen ((char *) string, end - string) + 1;
  3449. printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
  3450. lineno, string);
  3451. break;
  3452. case DW_MACINFO_vendor_ext:
  3453. {
  3454. unsigned int constant;
  3455. constant = read_uleb128 (curr, & bytes_read, end);
  3456. curr += bytes_read;
  3457. string = curr;
  3458. curr += strnlen ((char *) string, end - string) + 1;
  3459. printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
  3460. constant, string);
  3461. }
  3462. break;
  3463. }
  3464. }
  3465. return 1;
  3466. }
  3467. /* Given LINE_OFFSET into the .debug_line section, attempt to return
  3468. filename and dirname corresponding to file name table entry with index
  3469. FILEIDX. Return NULL on failure. */
  3470. static unsigned char *
  3471. get_line_filename_and_dirname (dwarf_vma line_offset,
  3472. dwarf_vma fileidx,
  3473. unsigned char **dir_name)
  3474. {
  3475. struct dwarf_section *section = &debug_displays [line].section;
  3476. unsigned char *hdrptr, *dirtable, *file_name;
  3477. unsigned int offset_size, initial_length_size;
  3478. unsigned int version, opcode_base, bytes_read;
  3479. dwarf_vma length, diridx;
  3480. const unsigned char * end;
  3481. *dir_name = NULL;
  3482. if (section->start == NULL
  3483. || line_offset >= section->size
  3484. || fileidx == 0)
  3485. return NULL;
  3486. hdrptr = section->start + line_offset;
  3487. end = section->start + section->size;
  3488. SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
  3489. if (length == 0xffffffff)
  3490. {
  3491. /* This section is 64-bit DWARF 3. */
  3492. SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
  3493. offset_size = 8;
  3494. initial_length_size = 12;
  3495. }
  3496. else
  3497. {
  3498. offset_size = 4;
  3499. initial_length_size = 4;
  3500. }
  3501. if (length + initial_length_size > section->size)
  3502. return NULL;
  3503. SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
  3504. if (version != 2 && version != 3 && version != 4)
  3505. return NULL;
  3506. hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
  3507. if (version >= 4)
  3508. hdrptr++; /* Skip max_ops_per_insn. */
  3509. hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
  3510. SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
  3511. if (opcode_base == 0)
  3512. return NULL;
  3513. hdrptr += opcode_base - 1;
  3514. dirtable = hdrptr;
  3515. /* Skip over dirname table. */
  3516. while (*hdrptr != '\0')
  3517. hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
  3518. hdrptr++; /* Skip the NUL at the end of the table. */
  3519. /* Now skip over preceding filename table entries. */
  3520. for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
  3521. {
  3522. hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
  3523. read_uleb128 (hdrptr, &bytes_read, end);
  3524. hdrptr += bytes_read;
  3525. read_uleb128 (hdrptr, &bytes_read, end);
  3526. hdrptr += bytes_read;
  3527. read_uleb128 (hdrptr, &bytes_read, end);
  3528. hdrptr += bytes_read;
  3529. }
  3530. if (hdrptr == end || *hdrptr == '\0')
  3531. return NULL;
  3532. file_name = hdrptr;
  3533. hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
  3534. diridx = read_uleb128 (hdrptr, &bytes_read, end);
  3535. if (diridx == 0)
  3536. return file_name;
  3537. for (; *dirtable != '\0' && diridx > 1; diridx--)
  3538. dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
  3539. if (*dirtable == '\0')
  3540. return NULL;
  3541. *dir_name = dirtable;
  3542. return file_name;
  3543. }
  3544. static int
  3545. display_debug_macro (struct dwarf_section *section,
  3546. void *file)
  3547. {
  3548. unsigned char *start = section->start;
  3549. unsigned char *end = start + section->size;
  3550. unsigned char *curr = start;
  3551. unsigned char *extended_op_buf[256];
  3552. unsigned int bytes_read;
  3553. load_debug_section (str, file);
  3554. load_debug_section (line, file);
  3555. printf (_("Contents of the %s section:\n\n"), section->name);
  3556. while (curr < end)
  3557. {
  3558. unsigned int lineno, version, flags;
  3559. unsigned int offset_size = 4;
  3560. const unsigned char *string;
  3561. dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
  3562. unsigned char **extended_ops = NULL;
  3563. SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
  3564. if (version != 4)
  3565. {
  3566. error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
  3567. section->name);
  3568. return 0;
  3569. }
  3570. SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
  3571. if (flags & 1)
  3572. offset_size = 8;
  3573. printf (_(" Offset: 0x%lx\n"),
  3574. (unsigned long) sec_offset);
  3575. printf (_(" Version: %d\n"), version);
  3576. printf (_(" Offset size: %d\n"), offset_size);
  3577. if (flags & 2)
  3578. {
  3579. SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
  3580. printf (_(" Offset into .debug_line: 0x%lx\n"),
  3581. (unsigned long) line_offset);
  3582. }
  3583. if (flags & 4)
  3584. {
  3585. unsigned int i, count, op;
  3586. dwarf_vma nargs, n;
  3587. SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
  3588. memset (extended_op_buf, 0, sizeof (extended_op_buf));
  3589. extended_ops = extended_op_buf;
  3590. if (count)
  3591. {
  3592. printf (_(" Extension opcode arguments:\n"));
  3593. for (i = 0; i < count; i++)
  3594. {
  3595. SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
  3596. extended_ops[op] = curr;
  3597. nargs = read_uleb128 (curr, &bytes_read, end);
  3598. curr += bytes_read;
  3599. if (nargs == 0)
  3600. printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
  3601. else
  3602. {
  3603. printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
  3604. for (n = 0; n < nargs; n++)
  3605. {
  3606. unsigned int form;
  3607. SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
  3608. printf ("%s%s", get_FORM_name (form),
  3609. n == nargs - 1 ? "\n" : ", ");
  3610. switch (form)
  3611. {
  3612. case DW_FORM_data1:
  3613. case DW_FORM_data2:
  3614. case DW_FORM_data4:
  3615. case DW_FORM_data8:
  3616. case DW_FORM_sdata:
  3617. case DW_FORM_udata:
  3618. case DW_FORM_block:
  3619. case DW_FORM_block1:
  3620. case DW_FORM_block2:
  3621. case DW_FORM_block4:
  3622. case DW_FORM_flag:
  3623. case DW_FORM_string:
  3624. case DW_FORM_strp:
  3625. case DW_FORM_sec_offset:
  3626. break;
  3627. default:
  3628. error (_("Invalid extension opcode form %s\n"),
  3629. get_FORM_name (form));
  3630. return 0;
  3631. }
  3632. }
  3633. }
  3634. }
  3635. }
  3636. }
  3637. printf ("\n");
  3638. while (1)
  3639. {
  3640. unsigned int op;
  3641. if (curr >= end)
  3642. {
  3643. error (_(".debug_macro section not zero terminated\n"));
  3644. return 0;
  3645. }
  3646. SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
  3647. if (op == 0)
  3648. break;
  3649. switch (op)
  3650. {
  3651. case DW_MACRO_GNU_start_file:
  3652. {
  3653. unsigned int filenum;
  3654. unsigned char *file_name = NULL, *dir_name = NULL;
  3655. lineno = read_uleb128 (curr, &bytes_read, end);
  3656. curr += bytes_read;
  3657. filenum = read_uleb128 (curr, &bytes_read, end);
  3658. curr += bytes_read;
  3659. if ((flags & 2) == 0)
  3660. error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
  3661. else
  3662. file_name
  3663. = get_line_filename_and_dirname (line_offset, filenum,
  3664. &dir_name);
  3665. if (file_name == NULL)
  3666. printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
  3667. lineno, filenum);
  3668. else
  3669. printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
  3670. lineno, filenum,
  3671. dir_name != NULL ? (const char *) dir_name : "",
  3672. dir_name != NULL ? "/" : "", file_name);
  3673. }
  3674. break;
  3675. case DW_MACRO_GNU_end_file:
  3676. printf (_(" DW_MACRO_GNU_end_file\n"));
  3677. break;
  3678. case DW_MACRO_GNU_define:
  3679. lineno = read_uleb128 (curr, &bytes_read, end);
  3680. curr += bytes_read;
  3681. string = curr;
  3682. curr += strnlen ((char *) string, end - string) + 1;
  3683. printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
  3684. lineno, string);
  3685. break;
  3686. case DW_MACRO_GNU_undef:
  3687. lineno = read_uleb128 (curr, &bytes_read, end);
  3688. curr += bytes_read;
  3689. string = curr;
  3690. curr += strnlen ((char *) string, end - string) + 1;
  3691. printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
  3692. lineno, string);
  3693. break;
  3694. case DW_MACRO_GNU_define_indirect:
  3695. lineno = read_uleb128 (curr, &bytes_read, end);
  3696. curr += bytes_read;
  3697. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  3698. string = fetch_indirect_string (offset);
  3699. printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
  3700. lineno, string);
  3701. break;
  3702. case DW_MACRO_GNU_undef_indirect:
  3703. lineno = read_uleb128 (curr, &bytes_read, end);
  3704. curr += bytes_read;
  3705. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  3706. string = fetch_indirect_string (offset);
  3707. printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
  3708. lineno, string);
  3709. break;
  3710. case DW_MACRO_GNU_transparent_include:
  3711. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  3712. printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
  3713. (unsigned long) offset);
  3714. break;
  3715. case DW_MACRO_GNU_define_indirect_alt:
  3716. lineno = read_uleb128 (curr, &bytes_read, end);
  3717. curr += bytes_read;
  3718. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  3719. printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
  3720. lineno, (unsigned long) offset);
  3721. break;
  3722. case DW_MACRO_GNU_undef_indirect_alt:
  3723. lineno = read_uleb128 (curr, &bytes_read, end);
  3724. curr += bytes_read;
  3725. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  3726. printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
  3727. lineno, (unsigned long) offset);
  3728. break;
  3729. case DW_MACRO_GNU_transparent_include_alt:
  3730. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  3731. printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
  3732. (unsigned long) offset);
  3733. break;
  3734. default:
  3735. if (extended_ops == NULL || extended_ops[op] == NULL)
  3736. {
  3737. error (_(" Unknown macro opcode %02x seen\n"), op);
  3738. return 0;
  3739. }
  3740. else
  3741. {
  3742. /* Skip over unhandled opcodes. */
  3743. dwarf_vma nargs, n;
  3744. unsigned char *desc = extended_ops[op];
  3745. nargs = read_uleb128 (desc, &bytes_read, end);
  3746. desc += bytes_read;
  3747. if (nargs == 0)
  3748. {
  3749. printf (_(" DW_MACRO_GNU_%02x\n"), op);
  3750. break;
  3751. }
  3752. printf (_(" DW_MACRO_GNU_%02x -"), op);
  3753. for (n = 0; n < nargs; n++)
  3754. {
  3755. int val;
  3756. SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
  3757. curr
  3758. = read_and_display_attr_value (0, val,
  3759. curr, end, 0, 0, offset_size,
  3760. version, NULL, 0, NULL,
  3761. NULL);
  3762. if (n != nargs - 1)
  3763. printf (",");
  3764. }
  3765. printf ("\n");
  3766. }
  3767. break;
  3768. }
  3769. }
  3770. printf ("\n");
  3771. }
  3772. return 1;
  3773. }
  3774. static int
  3775. display_debug_abbrev (struct dwarf_section *section,
  3776. void *file ATTRIBUTE_UNUSED)
  3777. {
  3778. abbrev_entry *entry;
  3779. unsigned char *start = section->start;
  3780. unsigned char *end = start + section->size;
  3781. printf (_("Contents of the %s section:\n\n"), section->name);
  3782. do
  3783. {
  3784. unsigned char *last;
  3785. free_abbrevs ();
  3786. last = start;
  3787. start = process_abbrev_section (start, end);
  3788. if (first_abbrev == NULL)
  3789. continue;
  3790. printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
  3791. for (entry = first_abbrev; entry; entry = entry->next)
  3792. {
  3793. abbrev_attr *attr;
  3794. printf (" %ld %s [%s]\n",
  3795. entry->entry,
  3796. get_TAG_name (entry->tag),
  3797. entry->children ? _("has children") : _("no children"));
  3798. for (attr = entry->first_attr; attr; attr = attr->next)
  3799. printf (" %-18s %s\n",
  3800. get_AT_name (attr->attribute),
  3801. get_FORM_name (attr->form));
  3802. }
  3803. }
  3804. while (start);
  3805. printf ("\n");
  3806. return 1;
  3807. }
  3808. /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
  3809. static void
  3810. display_loc_list (struct dwarf_section *section,
  3811. unsigned char **start_ptr,
  3812. unsigned int debug_info_entry,
  3813. unsigned long offset,
  3814. unsigned long base_address,
  3815. int has_frame_base)
  3816. {
  3817. unsigned char *start = *start_ptr;
  3818. unsigned char *section_end = section->start + section->size;
  3819. unsigned long cu_offset;
  3820. unsigned int pointer_size;
  3821. unsigned int offset_size;
  3822. int dwarf_version;
  3823. dwarf_vma begin;
  3824. dwarf_vma end;
  3825. unsigned short length;
  3826. int need_frame_base;
  3827. if (debug_info_entry >= num_debug_info_entries)
  3828. {
  3829. warn (_("No debug information available for loc lists of entry: %u\n"),
  3830. debug_info_entry);
  3831. return;
  3832. }
  3833. cu_offset = debug_information [debug_info_entry].cu_offset;
  3834. pointer_size = debug_information [debug_info_entry].pointer_size;
  3835. offset_size = debug_information [debug_info_entry].offset_size;
  3836. dwarf_version = debug_information [debug_info_entry].dwarf_version;
  3837. if (pointer_size < 2 || pointer_size > 8)
  3838. {
  3839. warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
  3840. pointer_size, debug_info_entry);
  3841. return;
  3842. }
  3843. while (1)
  3844. {
  3845. unsigned long off = offset + (start - *start_ptr);
  3846. if (start + 2 * pointer_size > section_end)
  3847. {
  3848. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  3849. offset);
  3850. break;
  3851. }
  3852. printf (" %8.8lx ", off);
  3853. /* Note: we use sign extension here in order to be sure that we can detect
  3854. the -1 escape value. Sign extension into the top 32 bits of a 32-bit
  3855. address will not affect the values that we display since we always show
  3856. hex values, and always the bottom 32-bits. */
  3857. SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
  3858. SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
  3859. if (begin == 0 && end == 0)
  3860. {
  3861. /* PR 18374: In a object file we can have a location list that
  3862. starts with a begin and end of 0 because there are relocations
  3863. that need to be applied to the addresses. Actually applying
  3864. the relocations now does not help as they will probably resolve
  3865. to 0, since the object file has not been fully linked. Real
  3866. end of list markers will not have any relocations against them. */
  3867. if (! reloc_at (section, off)
  3868. && ! reloc_at (section, off + pointer_size))
  3869. {
  3870. printf (_("<End of list>\n"));
  3871. break;
  3872. }
  3873. }
  3874. /* Check base address specifiers. */
  3875. if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
  3876. {
  3877. base_address = end;
  3878. print_dwarf_vma (begin, pointer_size);
  3879. print_dwarf_vma (end, pointer_size);
  3880. printf (_("(base address)\n"));
  3881. continue;
  3882. }
  3883. if (start + 2 > section_end)
  3884. {
  3885. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  3886. offset);
  3887. break;
  3888. }
  3889. SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
  3890. if (start + length > section_end)
  3891. {
  3892. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  3893. offset);
  3894. break;
  3895. }
  3896. print_dwarf_vma (begin + base_address, pointer_size);
  3897. print_dwarf_vma (end + base_address, pointer_size);
  3898. putchar ('(');
  3899. need_frame_base = decode_location_expression (start,
  3900. pointer_size,
  3901. offset_size,
  3902. dwarf_version,
  3903. length,
  3904. cu_offset, section);
  3905. putchar (')');
  3906. if (need_frame_base && !has_frame_base)
  3907. printf (_(" [without DW_AT_frame_base]"));
  3908. if (begin == end)
  3909. fputs (_(" (start == end)"), stdout);
  3910. else if (begin > end)
  3911. fputs (_(" (start > end)"), stdout);
  3912. putchar ('\n');
  3913. start += length;
  3914. }
  3915. *start_ptr = start;
  3916. }
  3917. /* Print a .debug_addr table index in decimal, surrounded by square brackets,
  3918. right-adjusted in a field of length LEN, and followed by a space. */
  3919. static void
  3920. print_addr_index (unsigned int idx, unsigned int len)
  3921. {
  3922. static char buf[15];
  3923. snprintf (buf, sizeof (buf), "[%d]", idx);
  3924. printf ("%*s ", len, buf);
  3925. }
  3926. /* Display a location list from a .dwo section. It uses address indexes rather
  3927. than embedded addresses. This code closely follows display_loc_list, but the
  3928. two are sufficiently different that combining things is very ugly. */
  3929. static void
  3930. display_loc_list_dwo (struct dwarf_section *section,
  3931. unsigned char **start_ptr,
  3932. unsigned int debug_info_entry,
  3933. unsigned long offset,
  3934. int has_frame_base)
  3935. {
  3936. unsigned char *start = *start_ptr;
  3937. unsigned char *section_end = section->start + section->size;
  3938. unsigned long cu_offset;
  3939. unsigned int pointer_size;
  3940. unsigned int offset_size;
  3941. int dwarf_version;
  3942. int entry_type;
  3943. unsigned short length;
  3944. int need_frame_base;
  3945. unsigned int idx;
  3946. unsigned int bytes_read;
  3947. if (debug_info_entry >= num_debug_info_entries)
  3948. {
  3949. warn (_("No debug information for loc lists of entry: %u\n"),
  3950. debug_info_entry);
  3951. return;
  3952. }
  3953. cu_offset = debug_information [debug_info_entry].cu_offset;
  3954. pointer_size = debug_information [debug_info_entry].pointer_size;
  3955. offset_size = debug_information [debug_info_entry].offset_size;
  3956. dwarf_version = debug_information [debug_info_entry].dwarf_version;
  3957. if (pointer_size < 2 || pointer_size > 8)
  3958. {
  3959. warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
  3960. pointer_size, debug_info_entry);
  3961. return;
  3962. }
  3963. while (1)
  3964. {
  3965. printf (" %8.8lx ", offset + (start - *start_ptr));
  3966. if (start >= section_end)
  3967. {
  3968. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  3969. offset);
  3970. break;
  3971. }
  3972. SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
  3973. switch (entry_type)
  3974. {
  3975. case 0: /* A terminating entry. */
  3976. *start_ptr = start;
  3977. printf (_("<End of list>\n"));
  3978. return;
  3979. case 1: /* A base-address entry. */
  3980. idx = read_uleb128 (start, &bytes_read, section_end);
  3981. start += bytes_read;
  3982. print_addr_index (idx, 8);
  3983. printf (" ");
  3984. printf (_("(base address selection entry)\n"));
  3985. continue;
  3986. case 2: /* A start/end entry. */
  3987. idx = read_uleb128 (start, &bytes_read, section_end);
  3988. start += bytes_read;
  3989. print_addr_index (idx, 8);
  3990. idx = read_uleb128 (start, &bytes_read, section_end);
  3991. start += bytes_read;
  3992. print_addr_index (idx, 8);
  3993. break;
  3994. case 3: /* A start/length entry. */
  3995. idx = read_uleb128 (start, &bytes_read, section_end);
  3996. start += bytes_read;
  3997. print_addr_index (idx, 8);
  3998. SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
  3999. printf ("%08x ", idx);
  4000. break;
  4001. case 4: /* An offset pair entry. */
  4002. SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
  4003. printf ("%08x ", idx);
  4004. SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
  4005. printf ("%08x ", idx);
  4006. break;
  4007. default:
  4008. warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
  4009. *start_ptr = start;
  4010. return;
  4011. }
  4012. if (start + 2 > section_end)
  4013. {
  4014. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  4015. offset);
  4016. break;
  4017. }
  4018. SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
  4019. if (start + length > section_end)
  4020. {
  4021. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  4022. offset);
  4023. break;
  4024. }
  4025. putchar ('(');
  4026. need_frame_base = decode_location_expression (start,
  4027. pointer_size,
  4028. offset_size,
  4029. dwarf_version,
  4030. length,
  4031. cu_offset, section);
  4032. putchar (')');
  4033. if (need_frame_base && !has_frame_base)
  4034. printf (_(" [without DW_AT_frame_base]"));
  4035. putchar ('\n');
  4036. start += length;
  4037. }
  4038. *start_ptr = start;
  4039. }
  4040. /* Sort array of indexes in ascending order of loc_offsets[idx]. */
  4041. static dwarf_vma *loc_offsets;
  4042. static int
  4043. loc_offsets_compar (const void *ap, const void *bp)
  4044. {
  4045. dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
  4046. dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
  4047. return (a > b) - (b > a);
  4048. }
  4049. static int
  4050. display_debug_loc (struct dwarf_section *section, void *file)
  4051. {
  4052. unsigned char *start = section->start;
  4053. unsigned long bytes;
  4054. unsigned char *section_begin = start;
  4055. unsigned int num_loc_list = 0;
  4056. unsigned long last_offset = 0;
  4057. unsigned int first = 0;
  4058. unsigned int i;
  4059. unsigned int j;
  4060. int seen_first_offset = 0;
  4061. int locs_sorted = 1;
  4062. unsigned char *next;
  4063. unsigned int *array = NULL;
  4064. const char *suffix = strrchr (section->name, '.');
  4065. int is_dwo = 0;
  4066. if (suffix && strcmp (suffix, ".dwo") == 0)
  4067. is_dwo = 1;
  4068. bytes = section->size;
  4069. if (bytes == 0)
  4070. {
  4071. printf (_("\nThe %s section is empty.\n"), section->name);
  4072. return 0;
  4073. }
  4074. if (load_debug_info (file) == 0)
  4075. {
  4076. warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
  4077. section->name);
  4078. return 0;
  4079. }
  4080. /* Check the order of location list in .debug_info section. If
  4081. offsets of location lists are in the ascending order, we can
  4082. use `debug_information' directly. */
  4083. for (i = 0; i < num_debug_info_entries; i++)
  4084. {
  4085. unsigned int num;
  4086. num = debug_information [i].num_loc_offsets;
  4087. if (num > num_loc_list)
  4088. num_loc_list = num;
  4089. /* Check if we can use `debug_information' directly. */
  4090. if (locs_sorted && num != 0)
  4091. {
  4092. if (!seen_first_offset)
  4093. {
  4094. /* This is the first location list. */
  4095. last_offset = debug_information [i].loc_offsets [0];
  4096. first = i;
  4097. seen_first_offset = 1;
  4098. j = 1;
  4099. }
  4100. else
  4101. j = 0;
  4102. for (; j < num; j++)
  4103. {
  4104. if (last_offset >
  4105. debug_information [i].loc_offsets [j])
  4106. {
  4107. locs_sorted = 0;
  4108. break;
  4109. }
  4110. last_offset = debug_information [i].loc_offsets [j];
  4111. }
  4112. }
  4113. }
  4114. if (!seen_first_offset)
  4115. error (_("No location lists in .debug_info section!\n"));
  4116. if (debug_information [first].num_loc_offsets > 0
  4117. && debug_information [first].loc_offsets [0] != 0)
  4118. warn (_("Location lists in %s section start at 0x%s\n"),
  4119. section->name,
  4120. dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
  4121. if (!locs_sorted)
  4122. array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
  4123. printf (_("Contents of the %s section:\n\n"), section->name);
  4124. if (reloc_at (section, 0))
  4125. printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
  4126. printf (_(" Offset Begin End Expression\n"));
  4127. seen_first_offset = 0;
  4128. for (i = first; i < num_debug_info_entries; i++)
  4129. {
  4130. unsigned long offset;
  4131. unsigned long base_address;
  4132. unsigned int k;
  4133. int has_frame_base;
  4134. if (!locs_sorted)
  4135. {
  4136. for (k = 0; k < debug_information [i].num_loc_offsets; k++)
  4137. array[k] = k;
  4138. loc_offsets = debug_information [i].loc_offsets;
  4139. qsort (array, debug_information [i].num_loc_offsets,
  4140. sizeof (*array), loc_offsets_compar);
  4141. }
  4142. for (k = 0; k < debug_information [i].num_loc_offsets; k++)
  4143. {
  4144. j = locs_sorted ? k : array[k];
  4145. if (k
  4146. && debug_information [i].loc_offsets [locs_sorted
  4147. ? k - 1 : array [k - 1]]
  4148. == debug_information [i].loc_offsets [j])
  4149. continue;
  4150. has_frame_base = debug_information [i].have_frame_base [j];
  4151. offset = debug_information [i].loc_offsets [j];
  4152. next = section_begin + offset;
  4153. base_address = debug_information [i].base_address;
  4154. if (!seen_first_offset)
  4155. seen_first_offset = 1;
  4156. else
  4157. {
  4158. if (start < next)
  4159. warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
  4160. (unsigned long) (start - section_begin),
  4161. (unsigned long) offset);
  4162. else if (start > next)
  4163. warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
  4164. (unsigned long) (start - section_begin),
  4165. (unsigned long) offset);
  4166. }
  4167. start = next;
  4168. if (offset >= bytes)
  4169. {
  4170. warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
  4171. offset);
  4172. continue;
  4173. }
  4174. if (is_dwo)
  4175. display_loc_list_dwo (section, &start, i, offset, has_frame_base);
  4176. else
  4177. display_loc_list (section, &start, i, offset, base_address,
  4178. has_frame_base);
  4179. }
  4180. }
  4181. if (start < section->start + section->size)
  4182. warn (_("There are %ld unused bytes at the end of section %s\n"),
  4183. (long) (section->start + section->size - start), section->name);
  4184. putchar ('\n');
  4185. free (array);
  4186. return 1;
  4187. }
  4188. static int
  4189. display_debug_str (struct dwarf_section *section,
  4190. void *file ATTRIBUTE_UNUSED)
  4191. {
  4192. unsigned char *start = section->start;
  4193. unsigned long bytes = section->size;
  4194. dwarf_vma addr = section->address;
  4195. if (bytes == 0)
  4196. {
  4197. printf (_("\nThe %s section is empty.\n"), section->name);
  4198. return 0;
  4199. }
  4200. printf (_("Contents of the %s section:\n\n"), section->name);
  4201. while (bytes)
  4202. {
  4203. int j;
  4204. int k;
  4205. int lbytes;
  4206. lbytes = (bytes > 16 ? 16 : bytes);
  4207. printf (" 0x%8.8lx ", (unsigned long) addr);
  4208. for (j = 0; j < 16; j++)
  4209. {
  4210. if (j < lbytes)
  4211. printf ("%2.2x", start[j]);
  4212. else
  4213. printf (" ");
  4214. if ((j & 3) == 3)
  4215. printf (" ");
  4216. }
  4217. for (j = 0; j < lbytes; j++)
  4218. {
  4219. k = start[j];
  4220. if (k >= ' ' && k < 0x80)
  4221. printf ("%c", k);
  4222. else
  4223. printf (".");
  4224. }
  4225. putchar ('\n');
  4226. start += lbytes;
  4227. addr += lbytes;
  4228. bytes -= lbytes;
  4229. }
  4230. putchar ('\n');
  4231. return 1;
  4232. }
  4233. static int
  4234. display_debug_info (struct dwarf_section *section, void *file)
  4235. {
  4236. return process_debug_info (section, file, section->abbrev_sec, 0, 0);
  4237. }
  4238. static int
  4239. display_debug_types (struct dwarf_section *section, void *file)
  4240. {
  4241. return process_debug_info (section, file, section->abbrev_sec, 0, 1);
  4242. }
  4243. static int
  4244. display_trace_info (struct dwarf_section *section, void *file)
  4245. {
  4246. return process_debug_info (section, file, section->abbrev_sec, 0, 0);
  4247. }
  4248. static int
  4249. display_debug_aranges (struct dwarf_section *section,
  4250. void *file ATTRIBUTE_UNUSED)
  4251. {
  4252. unsigned char *start = section->start;
  4253. unsigned char *end = start + section->size;
  4254. printf (_("Contents of the %s section:\n\n"), section->name);
  4255. /* It does not matter if this load fails,
  4256. we test for that later on. */
  4257. load_debug_info (file);
  4258. while (start < end)
  4259. {
  4260. unsigned char *hdrptr;
  4261. DWARF2_Internal_ARange arange;
  4262. unsigned char *addr_ranges;
  4263. dwarf_vma length;
  4264. dwarf_vma address;
  4265. unsigned char address_size;
  4266. int excess;
  4267. unsigned int offset_size;
  4268. unsigned int initial_length_size;
  4269. hdrptr = start;
  4270. SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
  4271. if (arange.ar_length == 0xffffffff)
  4272. {
  4273. SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
  4274. offset_size = 8;
  4275. initial_length_size = 12;
  4276. }
  4277. else
  4278. {
  4279. offset_size = 4;
  4280. initial_length_size = 4;
  4281. }
  4282. SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
  4283. SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
  4284. if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
  4285. && num_debug_info_entries > 0
  4286. && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
  4287. warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
  4288. (unsigned long) arange.ar_info_offset, section->name);
  4289. SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
  4290. SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
  4291. if (arange.ar_version != 2 && arange.ar_version != 3)
  4292. {
  4293. warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
  4294. break;
  4295. }
  4296. printf (_(" Length: %ld\n"),
  4297. (long) arange.ar_length);
  4298. printf (_(" Version: %d\n"), arange.ar_version);
  4299. printf (_(" Offset into .debug_info: 0x%lx\n"),
  4300. (unsigned long) arange.ar_info_offset);
  4301. printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
  4302. printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
  4303. address_size = arange.ar_pointer_size + arange.ar_segment_size;
  4304. /* PR 17512: file: 001-108546-0.001:0.1. */
  4305. if (address_size == 0 || address_size > 8)
  4306. {
  4307. error (_("Invalid address size in %s section!\n"),
  4308. section->name);
  4309. break;
  4310. }
  4311. /* The DWARF spec does not require that the address size be a power
  4312. of two, but we do. This will have to change if we ever encounter
  4313. an uneven architecture. */
  4314. if ((address_size & (address_size - 1)) != 0)
  4315. {
  4316. warn (_("Pointer size + Segment size is not a power of two.\n"));
  4317. break;
  4318. }
  4319. if (address_size > 4)
  4320. printf (_("\n Address Length\n"));
  4321. else
  4322. printf (_("\n Address Length\n"));
  4323. addr_ranges = hdrptr;
  4324. /* Must pad to an alignment boundary that is twice the address size. */
  4325. excess = (hdrptr - start) % (2 * address_size);
  4326. if (excess)
  4327. addr_ranges += (2 * address_size) - excess;
  4328. hdrptr = start + arange.ar_length + initial_length_size;
  4329. if (hdrptr < start || hdrptr > end)
  4330. {
  4331. error (_("Excessive header length: %lx\n"), (long) arange.ar_length);
  4332. break;
  4333. }
  4334. start = hdrptr;
  4335. while (addr_ranges + 2 * address_size <= start)
  4336. {
  4337. SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
  4338. SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
  4339. printf (" ");
  4340. print_dwarf_vma (address, address_size);
  4341. print_dwarf_vma (length, address_size);
  4342. putchar ('\n');
  4343. }
  4344. }
  4345. printf ("\n");
  4346. return 1;
  4347. }
  4348. /* Comparison function for qsort. */
  4349. static int
  4350. comp_addr_base (const void * v0, const void * v1)
  4351. {
  4352. debug_info * info0 = (debug_info *) v0;
  4353. debug_info * info1 = (debug_info *) v1;
  4354. return info0->addr_base - info1->addr_base;
  4355. }
  4356. /* Display the debug_addr section. */
  4357. static int
  4358. display_debug_addr (struct dwarf_section *section,
  4359. void *file)
  4360. {
  4361. debug_info **debug_addr_info;
  4362. unsigned char *entry;
  4363. unsigned char *end;
  4364. unsigned int i;
  4365. unsigned int count;
  4366. if (section->size == 0)
  4367. {
  4368. printf (_("\nThe %s section is empty.\n"), section->name);
  4369. return 0;
  4370. }
  4371. if (load_debug_info (file) == 0)
  4372. {
  4373. warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
  4374. section->name);
  4375. return 0;
  4376. }
  4377. printf (_("Contents of the %s section:\n\n"), section->name);
  4378. /* PR 17531: file: cf38d01b.
  4379. We use xcalloc because a corrupt file may not have initialised all of the
  4380. fields in the debug_info structure, which means that the sort below might
  4381. try to move uninitialised data. */
  4382. debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
  4383. sizeof (debug_info *));
  4384. count = 0;
  4385. for (i = 0; i < num_debug_info_entries; i++)
  4386. if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
  4387. {
  4388. /* PR 17531: file: cf38d01b. */
  4389. if (debug_information[i].addr_base >= section->size)
  4390. warn (_("Corrupt address base (%lx) found in debug section %u\n"),
  4391. (unsigned long) debug_information[i].addr_base, i);
  4392. else
  4393. debug_addr_info [count++] = debug_information + i;
  4394. }
  4395. /* Add a sentinel to make iteration convenient. */
  4396. debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
  4397. debug_addr_info [count]->addr_base = section->size;
  4398. qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
  4399. for (i = 0; i < count; i++)
  4400. {
  4401. unsigned int idx;
  4402. unsigned int address_size = debug_addr_info [i]->pointer_size;
  4403. printf (_(" For compilation unit at offset 0x%s:\n"),
  4404. dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
  4405. printf (_("\tIndex\tAddress\n"));
  4406. entry = section->start + debug_addr_info [i]->addr_base;
  4407. end = section->start + debug_addr_info [i + 1]->addr_base;
  4408. idx = 0;
  4409. while (entry < end)
  4410. {
  4411. dwarf_vma base = byte_get (entry, address_size);
  4412. printf (_("\t%d:\t"), idx);
  4413. print_dwarf_vma (base, address_size);
  4414. printf ("\n");
  4415. entry += address_size;
  4416. idx++;
  4417. }
  4418. }
  4419. printf ("\n");
  4420. free (debug_addr_info);
  4421. return 1;
  4422. }
  4423. /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
  4424. static int
  4425. display_debug_str_offsets (struct dwarf_section *section,
  4426. void *file ATTRIBUTE_UNUSED)
  4427. {
  4428. if (section->size == 0)
  4429. {
  4430. printf (_("\nThe %s section is empty.\n"), section->name);
  4431. return 0;
  4432. }
  4433. /* TODO: Dump the contents. This is made somewhat difficult by not knowing
  4434. what the offset size is for this section. */
  4435. return 1;
  4436. }
  4437. /* Each debug_information[x].range_lists[y] gets this representation for
  4438. sorting purposes. */
  4439. struct range_entry
  4440. {
  4441. /* The debug_information[x].range_lists[y] value. */
  4442. unsigned long ranges_offset;
  4443. /* Original debug_information to find parameters of the data. */
  4444. debug_info *debug_info_p;
  4445. };
  4446. /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
  4447. static int
  4448. range_entry_compar (const void *ap, const void *bp)
  4449. {
  4450. const struct range_entry *a_re = (const struct range_entry *) ap;
  4451. const struct range_entry *b_re = (const struct range_entry *) bp;
  4452. const unsigned long a = a_re->ranges_offset;
  4453. const unsigned long b = b_re->ranges_offset;
  4454. return (a > b) - (b > a);
  4455. }
  4456. static int
  4457. display_debug_ranges (struct dwarf_section *section,
  4458. void *file ATTRIBUTE_UNUSED)
  4459. {
  4460. unsigned char *start = section->start;
  4461. unsigned char *last_start = start;
  4462. unsigned long bytes = section->size;
  4463. unsigned char *section_begin = start;
  4464. unsigned char *finish = start + bytes;
  4465. unsigned int num_range_list, i;
  4466. struct range_entry *range_entries, *range_entry_fill;
  4467. if (bytes == 0)
  4468. {
  4469. printf (_("\nThe %s section is empty.\n"), section->name);
  4470. return 0;
  4471. }
  4472. if (load_debug_info (file) == 0)
  4473. {
  4474. warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
  4475. section->name);
  4476. return 0;
  4477. }
  4478. num_range_list = 0;
  4479. for (i = 0; i < num_debug_info_entries; i++)
  4480. num_range_list += debug_information [i].num_range_lists;
  4481. if (num_range_list == 0)
  4482. {
  4483. /* This can happen when the file was compiled with -gsplit-debug
  4484. which removes references to range lists from the primary .o file. */
  4485. printf (_("No range lists in .debug_info section.\n"));
  4486. return 1;
  4487. }
  4488. range_entries = (struct range_entry *)
  4489. xmalloc (sizeof (*range_entries) * num_range_list);
  4490. range_entry_fill = range_entries;
  4491. for (i = 0; i < num_debug_info_entries; i++)
  4492. {
  4493. debug_info *debug_info_p = &debug_information[i];
  4494. unsigned int j;
  4495. for (j = 0; j < debug_info_p->num_range_lists; j++)
  4496. {
  4497. range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
  4498. range_entry_fill->debug_info_p = debug_info_p;
  4499. range_entry_fill++;
  4500. }
  4501. }
  4502. qsort (range_entries, num_range_list, sizeof (*range_entries),
  4503. range_entry_compar);
  4504. if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
  4505. warn (_("Range lists in %s section start at 0x%lx\n"),
  4506. section->name, range_entries[0].ranges_offset);
  4507. printf (_("Contents of the %s section:\n\n"), section->name);
  4508. printf (_(" Offset Begin End\n"));
  4509. for (i = 0; i < num_range_list; i++)
  4510. {
  4511. struct range_entry *range_entry = &range_entries[i];
  4512. debug_info *debug_info_p = range_entry->debug_info_p;
  4513. unsigned int pointer_size;
  4514. unsigned long offset;
  4515. unsigned char *next;
  4516. unsigned long base_address;
  4517. pointer_size = debug_info_p->pointer_size;
  4518. offset = range_entry->ranges_offset;
  4519. next = section_begin + offset;
  4520. base_address = debug_info_p->base_address;
  4521. /* PR 17512: file: 001-101485-0.001:0.1. */
  4522. if (pointer_size < 2 || pointer_size > 8)
  4523. {
  4524. warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
  4525. pointer_size, offset);
  4526. continue;
  4527. }
  4528. if (dwarf_check != 0 && i > 0)
  4529. {
  4530. if (start < next)
  4531. warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
  4532. (unsigned long) (start - section_begin),
  4533. (unsigned long) (next - section_begin), section->name);
  4534. else if (start > next)
  4535. {
  4536. if (next == last_start)
  4537. continue;
  4538. warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
  4539. (unsigned long) (start - section_begin),
  4540. (unsigned long) (next - section_begin), section->name);
  4541. }
  4542. }
  4543. start = next;
  4544. last_start = next;
  4545. while (start < finish)
  4546. {
  4547. dwarf_vma begin;
  4548. dwarf_vma end;
  4549. /* Note: we use sign extension here in order to be sure that
  4550. we can detect the -1 escape value. Sign extension into the
  4551. top 32 bits of a 32-bit address will not affect the values
  4552. that we display since we always show hex values, and always
  4553. the bottom 32-bits. */
  4554. SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
  4555. if (start >= finish)
  4556. break;
  4557. SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
  4558. printf (" %8.8lx ", offset);
  4559. if (begin == 0 && end == 0)
  4560. {
  4561. printf (_("<End of list>\n"));
  4562. break;
  4563. }
  4564. /* Check base address specifiers. */
  4565. if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
  4566. {
  4567. base_address = end;
  4568. print_dwarf_vma (begin, pointer_size);
  4569. print_dwarf_vma (end, pointer_size);
  4570. printf ("(base address)\n");
  4571. continue;
  4572. }
  4573. print_dwarf_vma (begin + base_address, pointer_size);
  4574. print_dwarf_vma (end + base_address, pointer_size);
  4575. if (begin == end)
  4576. fputs (_("(start == end)"), stdout);
  4577. else if (begin > end)
  4578. fputs (_("(start > end)"), stdout);
  4579. putchar ('\n');
  4580. }
  4581. }
  4582. putchar ('\n');
  4583. free (range_entries);
  4584. return 1;
  4585. }
  4586. typedef struct Frame_Chunk
  4587. {
  4588. struct Frame_Chunk *next;
  4589. unsigned char *chunk_start;
  4590. unsigned int ncols;
  4591. /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
  4592. short int *col_type;
  4593. int *col_offset;
  4594. char *augmentation;
  4595. unsigned int code_factor;
  4596. int data_factor;
  4597. dwarf_vma pc_begin;
  4598. dwarf_vma pc_range;
  4599. int cfa_reg;
  4600. dwarf_vma cfa_offset;
  4601. unsigned int ra;
  4602. unsigned char fde_encoding;
  4603. unsigned char cfa_exp;
  4604. unsigned char ptr_size;
  4605. unsigned char segment_size;
  4606. }
  4607. Frame_Chunk;
  4608. static const char *const *dwarf_regnames;
  4609. static unsigned int dwarf_regnames_count;
  4610. /* A marker for a col_type that means this column was never referenced
  4611. in the frame info. */
  4612. #define DW_CFA_unreferenced (-1)
  4613. /* Return 0 if no more space is needed, 1 if more space is needed,
  4614. -1 for invalid reg. */
  4615. static int
  4616. frame_need_space (Frame_Chunk *fc, unsigned int reg)
  4617. {
  4618. unsigned int prev = fc->ncols;
  4619. if (reg < (unsigned int) fc->ncols)
  4620. return 0;
  4621. if (dwarf_regnames_count
  4622. && reg > dwarf_regnames_count)
  4623. return -1;
  4624. fc->ncols = reg + 1;
  4625. /* PR 17512: file: 10450-2643-0.004.
  4626. If reg == -1 then this can happen... */
  4627. if (fc->ncols == 0)
  4628. return -1;
  4629. /* PR 17512: file: 2844a11d. */
  4630. if (fc->ncols > 1024)
  4631. {
  4632. error (_("Unfeasibly large register number: %u\n"), reg);
  4633. fc->ncols = 0;
  4634. /* FIXME: 1024 is an arbitrary limit. Increase it if
  4635. we ever encounter a valid binary that exceeds it. */
  4636. return -1;
  4637. }
  4638. fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
  4639. sizeof (short int));
  4640. fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
  4641. /* PR 17512: file:002-10025-0.005. */
  4642. if (fc->col_type == NULL || fc->col_offset == NULL)
  4643. {
  4644. error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
  4645. fc->ncols);
  4646. fc->ncols = 0;
  4647. return -1;
  4648. }
  4649. while (prev < fc->ncols)
  4650. {
  4651. fc->col_type[prev] = DW_CFA_unreferenced;
  4652. fc->col_offset[prev] = 0;
  4653. prev++;
  4654. }
  4655. return 1;
  4656. }
  4657. static const char *const dwarf_regnames_i386[] =
  4658. {
  4659. "eax", "ecx", "edx", "ebx", /* 0 - 3 */
  4660. "esp", "ebp", "esi", "edi", /* 4 - 7 */
  4661. "eip", "eflags", NULL, /* 8 - 10 */
  4662. "st0", "st1", "st2", "st3", /* 11 - 14 */
  4663. "st4", "st5", "st6", "st7", /* 15 - 18 */
  4664. NULL, NULL, /* 19 - 20 */
  4665. "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
  4666. "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
  4667. "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
  4668. "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
  4669. "fcw", "fsw", "mxcsr", /* 37 - 39 */
  4670. "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
  4671. "tr", "ldtr", /* 48 - 49 */
  4672. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
  4673. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
  4674. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
  4675. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
  4676. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
  4677. NULL, NULL, NULL, /* 90 - 92 */
  4678. "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
  4679. };
  4680. static const char *const dwarf_regnames_iamcu[] =
  4681. {
  4682. "eax", "ecx", "edx", "ebx", /* 0 - 3 */
  4683. "esp", "ebp", "esi", "edi", /* 4 - 7 */
  4684. "eip", "eflags", NULL, /* 8 - 10 */
  4685. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
  4686. NULL, NULL, /* 19 - 20 */
  4687. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
  4688. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
  4689. NULL, NULL, NULL, /* 37 - 39 */
  4690. "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
  4691. "tr", "ldtr", /* 48 - 49 */
  4692. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
  4693. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
  4694. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
  4695. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
  4696. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
  4697. NULL, NULL, NULL, /* 90 - 92 */
  4698. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
  4699. };
  4700. void
  4701. init_dwarf_regnames_i386 (void)
  4702. {
  4703. dwarf_regnames = dwarf_regnames_i386;
  4704. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
  4705. }
  4706. void
  4707. init_dwarf_regnames_iamcu (void)
  4708. {
  4709. dwarf_regnames = dwarf_regnames_iamcu;
  4710. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
  4711. }
  4712. static const char *const dwarf_regnames_x86_64[] =
  4713. {
  4714. "rax", "rdx", "rcx", "rbx",
  4715. "rsi", "rdi", "rbp", "rsp",
  4716. "r8", "r9", "r10", "r11",
  4717. "r12", "r13", "r14", "r15",
  4718. "rip",
  4719. "xmm0", "xmm1", "xmm2", "xmm3",
  4720. "xmm4", "xmm5", "xmm6", "xmm7",
  4721. "xmm8", "xmm9", "xmm10", "xmm11",
  4722. "xmm12", "xmm13", "xmm14", "xmm15",
  4723. "st0", "st1", "st2", "st3",
  4724. "st4", "st5", "st6", "st7",
  4725. "mm0", "mm1", "mm2", "mm3",
  4726. "mm4", "mm5", "mm6", "mm7",
  4727. "rflags",
  4728. "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
  4729. "fs.base", "gs.base", NULL, NULL,
  4730. "tr", "ldtr",
  4731. "mxcsr", "fcw", "fsw",
  4732. "xmm16", "xmm17", "xmm18", "xmm19",
  4733. "xmm20", "xmm21", "xmm22", "xmm23",
  4734. "xmm24", "xmm25", "xmm26", "xmm27",
  4735. "xmm28", "xmm29", "xmm30", "xmm31",
  4736. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
  4737. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
  4738. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
  4739. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
  4740. NULL, NULL, NULL, /* 115 - 117 */
  4741. "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
  4742. };
  4743. void
  4744. init_dwarf_regnames_x86_64 (void)
  4745. {
  4746. dwarf_regnames = dwarf_regnames_x86_64;
  4747. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
  4748. }
  4749. static const char *const dwarf_regnames_aarch64[] =
  4750. {
  4751. "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
  4752. "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
  4753. "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
  4754. "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
  4755. NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
  4756. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  4757. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  4758. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  4759. "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  4760. "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
  4761. "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
  4762. "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
  4763. };
  4764. void
  4765. init_dwarf_regnames_aarch64 (void)
  4766. {
  4767. dwarf_regnames = dwarf_regnames_aarch64;
  4768. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
  4769. }
  4770. void
  4771. init_dwarf_regnames (unsigned int e_machine)
  4772. {
  4773. switch (e_machine)
  4774. {
  4775. case EM_386:
  4776. init_dwarf_regnames_i386 ();
  4777. break;
  4778. case EM_IAMCU:
  4779. init_dwarf_regnames_iamcu ();
  4780. break;
  4781. case EM_X86_64:
  4782. case EM_L1OM:
  4783. case EM_K1OM:
  4784. init_dwarf_regnames_x86_64 ();
  4785. break;
  4786. case EM_AARCH64:
  4787. init_dwarf_regnames_aarch64 ();
  4788. break;
  4789. default:
  4790. break;
  4791. }
  4792. }
  4793. static const char *
  4794. regname (unsigned int regno, int row)
  4795. {
  4796. static char reg[64];
  4797. if (dwarf_regnames
  4798. && regno < dwarf_regnames_count
  4799. && dwarf_regnames [regno] != NULL)
  4800. {
  4801. if (row)
  4802. return dwarf_regnames [regno];
  4803. snprintf (reg, sizeof (reg), "r%d (%s)", regno,
  4804. dwarf_regnames [regno]);
  4805. }
  4806. else
  4807. snprintf (reg, sizeof (reg), "r%d", regno);
  4808. return reg;
  4809. }
  4810. static void
  4811. frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
  4812. {
  4813. unsigned int r;
  4814. char tmp[100];
  4815. if (*max_regs < fc->ncols)
  4816. *max_regs = fc->ncols;
  4817. if (*need_col_headers)
  4818. {
  4819. static const char *sloc = " LOC";
  4820. *need_col_headers = 0;
  4821. printf ("%-*s CFA ", eh_addr_size * 2, sloc);
  4822. for (r = 0; r < *max_regs; r++)
  4823. if (fc->col_type[r] != DW_CFA_unreferenced)
  4824. {
  4825. if (r == fc->ra)
  4826. printf ("ra ");
  4827. else
  4828. printf ("%-5s ", regname (r, 1));
  4829. }
  4830. printf ("\n");
  4831. }
  4832. print_dwarf_vma (fc->pc_begin, eh_addr_size);
  4833. if (fc->cfa_exp)
  4834. strcpy (tmp, "exp");
  4835. else
  4836. sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
  4837. printf ("%-8s ", tmp);
  4838. for (r = 0; r < fc->ncols; r++)
  4839. {
  4840. if (fc->col_type[r] != DW_CFA_unreferenced)
  4841. {
  4842. switch (fc->col_type[r])
  4843. {
  4844. case DW_CFA_undefined:
  4845. strcpy (tmp, "u");
  4846. break;
  4847. case DW_CFA_same_value:
  4848. strcpy (tmp, "s");
  4849. break;
  4850. case DW_CFA_offset:
  4851. sprintf (tmp, "c%+d", fc->col_offset[r]);
  4852. break;
  4853. case DW_CFA_val_offset:
  4854. sprintf (tmp, "v%+d", fc->col_offset[r]);
  4855. break;
  4856. case DW_CFA_register:
  4857. sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
  4858. break;
  4859. case DW_CFA_expression:
  4860. strcpy (tmp, "exp");
  4861. break;
  4862. case DW_CFA_val_expression:
  4863. strcpy (tmp, "vexp");
  4864. break;
  4865. default:
  4866. strcpy (tmp, "n/a");
  4867. break;
  4868. }
  4869. printf ("%-5s ", tmp);
  4870. }
  4871. }
  4872. printf ("\n");
  4873. }
  4874. #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
  4875. #define LEB() read_uleb128 (start, & length_return, end); start += length_return
  4876. #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
  4877. static unsigned char *
  4878. read_cie (unsigned char *start, unsigned char *end,
  4879. Frame_Chunk **p_cie, int *p_version,
  4880. unsigned long *p_aug_len, unsigned char **p_aug)
  4881. {
  4882. int version;
  4883. Frame_Chunk *fc;
  4884. unsigned int length_return;
  4885. unsigned char *augmentation_data = NULL;
  4886. unsigned long augmentation_data_len = 0;
  4887. * p_cie = NULL;
  4888. /* PR 17512: file: 001-228113-0.004. */
  4889. if (start >= end)
  4890. return end;
  4891. fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
  4892. memset (fc, 0, sizeof (Frame_Chunk));
  4893. fc->col_type = (short int *) xmalloc (sizeof (short int));
  4894. fc->col_offset = (int *) xmalloc (sizeof (int));
  4895. version = *start++;
  4896. fc->augmentation = (char *) start;
  4897. /* PR 17512: file: 001-228113-0.004.
  4898. Skip past augmentation name, but avoid running off the end of the data. */
  4899. while (start < end)
  4900. if (* start ++ == '\0')
  4901. break;
  4902. if (start == end)
  4903. {
  4904. warn (_("No terminator for augmentation name\n"));
  4905. return start;
  4906. }
  4907. if (strcmp (fc->augmentation, "eh") == 0)
  4908. start += eh_addr_size;
  4909. if (version >= 4)
  4910. {
  4911. GET (fc->ptr_size, 1);
  4912. if (fc->ptr_size < 1 || fc->ptr_size > 8)
  4913. {
  4914. warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
  4915. return end;
  4916. }
  4917. GET (fc->segment_size, 1);
  4918. /* PR 17512: file: e99d2804. */
  4919. if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
  4920. {
  4921. warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
  4922. return end;
  4923. }
  4924. eh_addr_size = fc->ptr_size;
  4925. }
  4926. else
  4927. {
  4928. fc->ptr_size = eh_addr_size;
  4929. fc->segment_size = 0;
  4930. }
  4931. fc->code_factor = LEB ();
  4932. fc->data_factor = SLEB ();
  4933. if (version == 1)
  4934. {
  4935. GET (fc->ra, 1);
  4936. }
  4937. else
  4938. {
  4939. fc->ra = LEB ();
  4940. }
  4941. if (fc->augmentation[0] == 'z')
  4942. {
  4943. augmentation_data_len = LEB ();
  4944. augmentation_data = start;
  4945. start += augmentation_data_len;
  4946. /* PR 17512: file: 11042-2589-0.004. */
  4947. if (start > end)
  4948. {
  4949. warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len);
  4950. return end;
  4951. }
  4952. }
  4953. if (augmentation_data_len)
  4954. {
  4955. unsigned char *p;
  4956. unsigned char *q;
  4957. unsigned char *qend;
  4958. p = (unsigned char *) fc->augmentation + 1;
  4959. q = augmentation_data;
  4960. qend = q + augmentation_data_len;
  4961. /* PR 17531: file: 015adfaa. */
  4962. if (qend < q)
  4963. {
  4964. warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
  4965. augmentation_data_len = 0;
  4966. }
  4967. while (p < end && q < augmentation_data + augmentation_data_len)
  4968. {
  4969. if (*p == 'L')
  4970. q++;
  4971. else if (*p == 'P')
  4972. q += 1 + size_of_encoded_value (*q);
  4973. else if (*p == 'R')
  4974. fc->fde_encoding = *q++;
  4975. else if (*p == 'S')
  4976. ;
  4977. else
  4978. break;
  4979. p++;
  4980. }
  4981. /* Note - it is OK if this loop terminates with q < qend.
  4982. Padding may have been inserted to align the end of the CIE. */
  4983. }
  4984. *p_cie = fc;
  4985. if (p_version)
  4986. *p_version = version;
  4987. if (p_aug_len)
  4988. {
  4989. *p_aug_len = augmentation_data_len;
  4990. *p_aug = augmentation_data;
  4991. }
  4992. return start;
  4993. }
  4994. static int
  4995. display_debug_frames (struct dwarf_section *section,
  4996. void *file ATTRIBUTE_UNUSED)
  4997. {
  4998. unsigned char *start = section->start;
  4999. unsigned char *end = start + section->size;
  5000. unsigned char *section_start = start;
  5001. Frame_Chunk *chunks = 0, *forward_refs = 0;
  5002. Frame_Chunk *remembered_state = 0;
  5003. Frame_Chunk *rs;
  5004. int is_eh = strcmp (section->name, ".eh_frame") == 0;
  5005. unsigned int length_return;
  5006. unsigned int max_regs = 0;
  5007. const char *bad_reg = _("bad register: ");
  5008. unsigned int saved_eh_addr_size = eh_addr_size;
  5009. printf (_("Contents of the %s section:\n"), section->name);
  5010. while (start < end)
  5011. {
  5012. unsigned char *saved_start;
  5013. unsigned char *block_end;
  5014. dwarf_vma length;
  5015. dwarf_vma cie_id;
  5016. Frame_Chunk *fc;
  5017. Frame_Chunk *cie;
  5018. int need_col_headers = 1;
  5019. unsigned char *augmentation_data = NULL;
  5020. unsigned long augmentation_data_len = 0;
  5021. unsigned int encoded_ptr_size = saved_eh_addr_size;
  5022. unsigned int offset_size;
  5023. unsigned int initial_length_size;
  5024. saved_start = start;
  5025. SAFE_BYTE_GET_AND_INC (length, start, 4, end);
  5026. if (length == 0)
  5027. {
  5028. printf ("\n%08lx ZERO terminator\n\n",
  5029. (unsigned long)(saved_start - section_start));
  5030. /* Skip any zero terminators that directly follow.
  5031. A corrupt section size could have loaded a whole
  5032. slew of zero filled memory bytes. eg
  5033. PR 17512: file: 070-19381-0.004. */
  5034. while (start < end && * start == 0)
  5035. ++ start;
  5036. continue;
  5037. }
  5038. if (length == 0xffffffff)
  5039. {
  5040. SAFE_BYTE_GET_AND_INC (length, start, 8, end);
  5041. offset_size = 8;
  5042. initial_length_size = 12;
  5043. }
  5044. else
  5045. {
  5046. offset_size = 4;
  5047. initial_length_size = 4;
  5048. }
  5049. block_end = saved_start + length + initial_length_size;
  5050. if (block_end > end || block_end < start)
  5051. {
  5052. warn ("Invalid length 0x%s in FDE at %#08lx\n",
  5053. dwarf_vmatoa_1 (NULL, length, offset_size),
  5054. (unsigned long) (saved_start - section_start));
  5055. block_end = end;
  5056. }
  5057. SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
  5058. if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
  5059. || (offset_size == 8 && cie_id == DW64_CIE_ID)))
  5060. {
  5061. int version;
  5062. unsigned int mreg;
  5063. start = read_cie (start, end, &cie, &version,
  5064. &augmentation_data_len, &augmentation_data);
  5065. /* PR 17512: file: 027-135133-0.005. */
  5066. if (cie == NULL)
  5067. break;
  5068. fc = cie;
  5069. fc->next = chunks;
  5070. chunks = fc;
  5071. fc->chunk_start = saved_start;
  5072. mreg = max_regs > 0 ? max_regs - 1 : 0;
  5073. if (mreg < fc->ra)
  5074. mreg = fc->ra;
  5075. if (frame_need_space (fc, mreg) < 0)
  5076. break;
  5077. if (fc->fde_encoding)
  5078. encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
  5079. printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
  5080. print_dwarf_vma (length, fc->ptr_size);
  5081. print_dwarf_vma (cie_id, offset_size);
  5082. if (do_debug_frames_interp)
  5083. {
  5084. printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
  5085. fc->code_factor, fc->data_factor, fc->ra);
  5086. }
  5087. else
  5088. {
  5089. printf ("CIE\n");
  5090. printf (" Version: %d\n", version);
  5091. printf (" Augmentation: \"%s\"\n", fc->augmentation);
  5092. if (version >= 4)
  5093. {
  5094. printf (" Pointer Size: %u\n", fc->ptr_size);
  5095. printf (" Segment Size: %u\n", fc->segment_size);
  5096. }
  5097. printf (" Code alignment factor: %u\n", fc->code_factor);
  5098. printf (" Data alignment factor: %d\n", fc->data_factor);
  5099. printf (" Return address column: %d\n", fc->ra);
  5100. if (augmentation_data_len)
  5101. {
  5102. unsigned long i;
  5103. printf (" Augmentation data: ");
  5104. for (i = 0; i < augmentation_data_len; ++i)
  5105. /* FIXME: If do_wide is FALSE, then we should
  5106. add carriage returns at 80 columns... */
  5107. printf (" %02x", augmentation_data[i]);
  5108. putchar ('\n');
  5109. }
  5110. putchar ('\n');
  5111. }
  5112. }
  5113. else
  5114. {
  5115. unsigned char *look_for;
  5116. static Frame_Chunk fde_fc;
  5117. unsigned long segment_selector;
  5118. if (is_eh)
  5119. {
  5120. dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
  5121. look_for = start - 4 - ((cie_id ^ sign) - sign);
  5122. }
  5123. else
  5124. look_for = section_start + cie_id;
  5125. if (look_for <= saved_start)
  5126. {
  5127. for (cie = chunks; cie ; cie = cie->next)
  5128. if (cie->chunk_start == look_for)
  5129. break;
  5130. }
  5131. else
  5132. {
  5133. for (cie = forward_refs; cie ; cie = cie->next)
  5134. if (cie->chunk_start == look_for)
  5135. break;
  5136. if (!cie)
  5137. {
  5138. unsigned int off_size;
  5139. unsigned char *cie_scan;
  5140. cie_scan = look_for;
  5141. off_size = 4;
  5142. SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
  5143. if (length == 0xffffffff)
  5144. {
  5145. SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
  5146. off_size = 8;
  5147. }
  5148. if (length != 0)
  5149. {
  5150. dwarf_vma c_id;
  5151. SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
  5152. if (is_eh
  5153. ? c_id == 0
  5154. : ((off_size == 4 && c_id == DW_CIE_ID)
  5155. || (off_size == 8 && c_id == DW64_CIE_ID)))
  5156. {
  5157. int version;
  5158. unsigned int mreg;
  5159. read_cie (cie_scan, end, &cie, &version,
  5160. &augmentation_data_len, &augmentation_data);
  5161. /* PR 17512: file: 3450-2098-0.004. */
  5162. if (cie == NULL)
  5163. {
  5164. warn (_("Failed to read CIE information\n"));
  5165. break;
  5166. }
  5167. cie->next = forward_refs;
  5168. forward_refs = cie;
  5169. cie->chunk_start = look_for;
  5170. mreg = max_regs > 0 ? max_regs - 1 : 0;
  5171. if (mreg < cie->ra)
  5172. mreg = cie->ra;
  5173. if (frame_need_space (cie, mreg) < 0)
  5174. {
  5175. warn (_("Invalid max register\n"));
  5176. break;
  5177. }
  5178. if (cie->fde_encoding)
  5179. encoded_ptr_size
  5180. = size_of_encoded_value (cie->fde_encoding);
  5181. }
  5182. }
  5183. }
  5184. }
  5185. fc = &fde_fc;
  5186. memset (fc, 0, sizeof (Frame_Chunk));
  5187. if (!cie)
  5188. {
  5189. warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
  5190. dwarf_vmatoa_1 (NULL, cie_id, offset_size),
  5191. (unsigned long) (saved_start - section_start));
  5192. fc->ncols = 0;
  5193. fc->col_type = (short int *) xmalloc (sizeof (short int));
  5194. fc->col_offset = (int *) xmalloc (sizeof (int));
  5195. if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
  5196. {
  5197. warn (_("Invalid max register\n"));
  5198. break;
  5199. }
  5200. cie = fc;
  5201. fc->augmentation = "";
  5202. fc->fde_encoding = 0;
  5203. fc->ptr_size = eh_addr_size;
  5204. fc->segment_size = 0;
  5205. }
  5206. else
  5207. {
  5208. fc->ncols = cie->ncols;
  5209. fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
  5210. fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
  5211. memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
  5212. memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
  5213. fc->augmentation = cie->augmentation;
  5214. fc->ptr_size = cie->ptr_size;
  5215. eh_addr_size = cie->ptr_size;
  5216. fc->segment_size = cie->segment_size;
  5217. fc->code_factor = cie->code_factor;
  5218. fc->data_factor = cie->data_factor;
  5219. fc->cfa_reg = cie->cfa_reg;
  5220. fc->cfa_offset = cie->cfa_offset;
  5221. fc->ra = cie->ra;
  5222. if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
  5223. {
  5224. warn (_("Invalid max register\n"));
  5225. break;
  5226. }
  5227. fc->fde_encoding = cie->fde_encoding;
  5228. }
  5229. if (fc->fde_encoding)
  5230. encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
  5231. segment_selector = 0;
  5232. if (fc->segment_size)
  5233. {
  5234. if (fc->segment_size > sizeof (segment_selector))
  5235. {
  5236. /* PR 17512: file: 9e196b3e. */
  5237. warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
  5238. fc->segment_size = 4;
  5239. }
  5240. SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
  5241. }
  5242. fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
  5243. /* FIXME: It appears that sometimes the final pc_range value is
  5244. encoded in less than encoded_ptr_size bytes. See the x86_64
  5245. run of the "objcopy on compressed debug sections" test for an
  5246. example of this. */
  5247. SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
  5248. if (cie->augmentation[0] == 'z')
  5249. {
  5250. augmentation_data_len = LEB ();
  5251. augmentation_data = start;
  5252. start += augmentation_data_len;
  5253. /* PR 17512: file: 722-8446-0.004. */
  5254. if (start >= end || ((signed long) augmentation_data_len) < 0)
  5255. {
  5256. warn (_("Corrupt augmentation data length: %lx\n"),
  5257. augmentation_data_len);
  5258. start = end;
  5259. augmentation_data = NULL;
  5260. augmentation_data_len = 0;
  5261. }
  5262. }
  5263. printf ("\n%08lx %s %s FDE cie=%08lx pc=",
  5264. (unsigned long)(saved_start - section_start),
  5265. dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
  5266. dwarf_vmatoa_1 (NULL, cie_id, offset_size),
  5267. (unsigned long)(cie->chunk_start - section_start));
  5268. if (fc->segment_size)
  5269. printf ("%04lx:", segment_selector);
  5270. printf ("%s..%s\n",
  5271. dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
  5272. dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
  5273. if (! do_debug_frames_interp && augmentation_data_len)
  5274. {
  5275. unsigned long i;
  5276. printf (" Augmentation data: ");
  5277. for (i = 0; i < augmentation_data_len; ++i)
  5278. printf (" %02x", augmentation_data[i]);
  5279. putchar ('\n');
  5280. putchar ('\n');
  5281. }
  5282. }
  5283. /* At this point, fc is the current chunk, cie (if any) is set, and
  5284. we're about to interpret instructions for the chunk. */
  5285. /* ??? At present we need to do this always, since this sizes the
  5286. fc->col_type and fc->col_offset arrays, which we write into always.
  5287. We should probably split the interpreted and non-interpreted bits
  5288. into two different routines, since there's so much that doesn't
  5289. really overlap between them. */
  5290. if (1 || do_debug_frames_interp)
  5291. {
  5292. /* Start by making a pass over the chunk, allocating storage
  5293. and taking note of what registers are used. */
  5294. unsigned char *tmp = start;
  5295. while (start < block_end)
  5296. {
  5297. unsigned int reg, op, opa;
  5298. unsigned long temp;
  5299. unsigned char * new_start;
  5300. op = *start++;
  5301. opa = op & 0x3f;
  5302. if (op & 0xc0)
  5303. op &= 0xc0;
  5304. /* Warning: if you add any more cases to this switch, be
  5305. sure to add them to the corresponding switch below. */
  5306. switch (op)
  5307. {
  5308. case DW_CFA_advance_loc:
  5309. break;
  5310. case DW_CFA_offset:
  5311. LEB ();
  5312. if (frame_need_space (fc, opa) >= 0)
  5313. fc->col_type[opa] = DW_CFA_undefined;
  5314. break;
  5315. case DW_CFA_restore:
  5316. if (frame_need_space (fc, opa) >= 0)
  5317. fc->col_type[opa] = DW_CFA_undefined;
  5318. break;
  5319. case DW_CFA_set_loc:
  5320. start += encoded_ptr_size;
  5321. break;
  5322. case DW_CFA_advance_loc1:
  5323. start += 1;
  5324. break;
  5325. case DW_CFA_advance_loc2:
  5326. start += 2;
  5327. break;
  5328. case DW_CFA_advance_loc4:
  5329. start += 4;
  5330. break;
  5331. case DW_CFA_offset_extended:
  5332. case DW_CFA_val_offset:
  5333. reg = LEB (); LEB ();
  5334. if (frame_need_space (fc, reg) >= 0)
  5335. fc->col_type[reg] = DW_CFA_undefined;
  5336. break;
  5337. case DW_CFA_restore_extended:
  5338. reg = LEB ();
  5339. if (frame_need_space (fc, reg) >= 0)
  5340. fc->col_type[reg] = DW_CFA_undefined;
  5341. break;
  5342. case DW_CFA_undefined:
  5343. reg = LEB ();
  5344. if (frame_need_space (fc, reg) >= 0)
  5345. fc->col_type[reg] = DW_CFA_undefined;
  5346. break;
  5347. case DW_CFA_same_value:
  5348. reg = LEB ();
  5349. if (frame_need_space (fc, reg) >= 0)
  5350. fc->col_type[reg] = DW_CFA_undefined;
  5351. break;
  5352. case DW_CFA_register:
  5353. reg = LEB (); LEB ();
  5354. if (frame_need_space (fc, reg) >= 0)
  5355. fc->col_type[reg] = DW_CFA_undefined;
  5356. break;
  5357. case DW_CFA_def_cfa:
  5358. LEB (); LEB ();
  5359. break;
  5360. case DW_CFA_def_cfa_register:
  5361. LEB ();
  5362. break;
  5363. case DW_CFA_def_cfa_offset:
  5364. LEB ();
  5365. break;
  5366. case DW_CFA_def_cfa_expression:
  5367. temp = LEB ();
  5368. new_start = start + temp;
  5369. if (new_start < start)
  5370. {
  5371. warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
  5372. start = block_end;
  5373. }
  5374. else
  5375. start = new_start;
  5376. break;
  5377. case DW_CFA_expression:
  5378. case DW_CFA_val_expression:
  5379. reg = LEB ();
  5380. temp = LEB ();
  5381. new_start = start + temp;
  5382. if (new_start < start)
  5383. {
  5384. /* PR 17512: file:306-192417-0.005. */
  5385. warn (_("Corrupt CFA expression value: %lu\n"), temp);
  5386. start = block_end;
  5387. }
  5388. else
  5389. start = new_start;
  5390. if (frame_need_space (fc, reg) >= 0)
  5391. fc->col_type[reg] = DW_CFA_undefined;
  5392. break;
  5393. case DW_CFA_offset_extended_sf:
  5394. case DW_CFA_val_offset_sf:
  5395. reg = LEB (); SLEB ();
  5396. if (frame_need_space (fc, reg) >= 0)
  5397. fc->col_type[reg] = DW_CFA_undefined;
  5398. break;
  5399. case DW_CFA_def_cfa_sf:
  5400. LEB (); SLEB ();
  5401. break;
  5402. case DW_CFA_def_cfa_offset_sf:
  5403. SLEB ();
  5404. break;
  5405. case DW_CFA_MIPS_advance_loc8:
  5406. start += 8;
  5407. break;
  5408. case DW_CFA_GNU_args_size:
  5409. LEB ();
  5410. break;
  5411. case DW_CFA_GNU_negative_offset_extended:
  5412. reg = LEB (); LEB ();
  5413. if (frame_need_space (fc, reg) >= 0)
  5414. fc->col_type[reg] = DW_CFA_undefined;
  5415. break;
  5416. default:
  5417. break;
  5418. }
  5419. }
  5420. start = tmp;
  5421. }
  5422. /* Now we know what registers are used, make a second pass over
  5423. the chunk, this time actually printing out the info. */
  5424. while (start < block_end)
  5425. {
  5426. unsigned char * tmp;
  5427. unsigned op, opa;
  5428. unsigned long ul, reg, roffs;
  5429. dwarf_vma l;
  5430. dwarf_vma ofs;
  5431. dwarf_vma vma;
  5432. const char *reg_prefix = "";
  5433. op = *start++;
  5434. opa = op & 0x3f;
  5435. if (op & 0xc0)
  5436. op &= 0xc0;
  5437. /* Warning: if you add any more cases to this switch, be
  5438. sure to add them to the corresponding switch above. */
  5439. switch (op)
  5440. {
  5441. case DW_CFA_advance_loc:
  5442. if (do_debug_frames_interp)
  5443. frame_display_row (fc, &need_col_headers, &max_regs);
  5444. else
  5445. printf (" DW_CFA_advance_loc: %d to %s\n",
  5446. opa * fc->code_factor,
  5447. dwarf_vmatoa_1 (NULL,
  5448. fc->pc_begin + opa * fc->code_factor,
  5449. fc->ptr_size));
  5450. fc->pc_begin += opa * fc->code_factor;
  5451. break;
  5452. case DW_CFA_offset:
  5453. roffs = LEB ();
  5454. if (opa >= (unsigned int) fc->ncols)
  5455. reg_prefix = bad_reg;
  5456. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5457. printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
  5458. reg_prefix, regname (opa, 0),
  5459. roffs * fc->data_factor);
  5460. if (*reg_prefix == '\0')
  5461. {
  5462. fc->col_type[opa] = DW_CFA_offset;
  5463. fc->col_offset[opa] = roffs * fc->data_factor;
  5464. }
  5465. break;
  5466. case DW_CFA_restore:
  5467. if (opa >= (unsigned int) cie->ncols
  5468. || opa >= (unsigned int) fc->ncols)
  5469. reg_prefix = bad_reg;
  5470. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5471. printf (" DW_CFA_restore: %s%s\n",
  5472. reg_prefix, regname (opa, 0));
  5473. if (*reg_prefix == '\0')
  5474. {
  5475. fc->col_type[opa] = cie->col_type[opa];
  5476. fc->col_offset[opa] = cie->col_offset[opa];
  5477. if (do_debug_frames_interp
  5478. && fc->col_type[opa] == DW_CFA_unreferenced)
  5479. fc->col_type[opa] = DW_CFA_undefined;
  5480. }
  5481. break;
  5482. case DW_CFA_set_loc:
  5483. vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
  5484. if (do_debug_frames_interp)
  5485. frame_display_row (fc, &need_col_headers, &max_regs);
  5486. else
  5487. printf (" DW_CFA_set_loc: %s\n",
  5488. dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
  5489. fc->pc_begin = vma;
  5490. break;
  5491. case DW_CFA_advance_loc1:
  5492. SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
  5493. if (do_debug_frames_interp)
  5494. frame_display_row (fc, &need_col_headers, &max_regs);
  5495. else
  5496. printf (" DW_CFA_advance_loc1: %ld to %s\n",
  5497. (unsigned long) (ofs * fc->code_factor),
  5498. dwarf_vmatoa_1 (NULL,
  5499. fc->pc_begin + ofs * fc->code_factor,
  5500. fc->ptr_size));
  5501. fc->pc_begin += ofs * fc->code_factor;
  5502. break;
  5503. case DW_CFA_advance_loc2:
  5504. SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
  5505. if (do_debug_frames_interp)
  5506. frame_display_row (fc, &need_col_headers, &max_regs);
  5507. else
  5508. printf (" DW_CFA_advance_loc2: %ld to %s\n",
  5509. (unsigned long) (ofs * fc->code_factor),
  5510. dwarf_vmatoa_1 (NULL,
  5511. fc->pc_begin + ofs * fc->code_factor,
  5512. fc->ptr_size));
  5513. fc->pc_begin += ofs * fc->code_factor;
  5514. break;
  5515. case DW_CFA_advance_loc4:
  5516. SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
  5517. if (do_debug_frames_interp)
  5518. frame_display_row (fc, &need_col_headers, &max_regs);
  5519. else
  5520. printf (" DW_CFA_advance_loc4: %ld to %s\n",
  5521. (unsigned long) (ofs * fc->code_factor),
  5522. dwarf_vmatoa_1 (NULL,
  5523. fc->pc_begin + ofs * fc->code_factor,
  5524. fc->ptr_size));
  5525. fc->pc_begin += ofs * fc->code_factor;
  5526. break;
  5527. case DW_CFA_offset_extended:
  5528. reg = LEB ();
  5529. roffs = LEB ();
  5530. if (reg >= (unsigned int) fc->ncols)
  5531. reg_prefix = bad_reg;
  5532. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5533. printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
  5534. reg_prefix, regname (reg, 0),
  5535. roffs * fc->data_factor);
  5536. if (*reg_prefix == '\0')
  5537. {
  5538. fc->col_type[reg] = DW_CFA_offset;
  5539. fc->col_offset[reg] = roffs * fc->data_factor;
  5540. }
  5541. break;
  5542. case DW_CFA_val_offset:
  5543. reg = LEB ();
  5544. roffs = LEB ();
  5545. if (reg >= (unsigned int) fc->ncols)
  5546. reg_prefix = bad_reg;
  5547. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5548. printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
  5549. reg_prefix, regname (reg, 0),
  5550. roffs * fc->data_factor);
  5551. if (*reg_prefix == '\0')
  5552. {
  5553. fc->col_type[reg] = DW_CFA_val_offset;
  5554. fc->col_offset[reg] = roffs * fc->data_factor;
  5555. }
  5556. break;
  5557. case DW_CFA_restore_extended:
  5558. reg = LEB ();
  5559. if (reg >= (unsigned int) cie->ncols
  5560. || reg >= (unsigned int) fc->ncols)
  5561. reg_prefix = bad_reg;
  5562. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5563. printf (" DW_CFA_restore_extended: %s%s\n",
  5564. reg_prefix, regname (reg, 0));
  5565. if (*reg_prefix == '\0')
  5566. {
  5567. fc->col_type[reg] = cie->col_type[reg];
  5568. fc->col_offset[reg] = cie->col_offset[reg];
  5569. }
  5570. break;
  5571. case DW_CFA_undefined:
  5572. reg = LEB ();
  5573. if (reg >= (unsigned int) fc->ncols)
  5574. reg_prefix = bad_reg;
  5575. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5576. printf (" DW_CFA_undefined: %s%s\n",
  5577. reg_prefix, regname (reg, 0));
  5578. if (*reg_prefix == '\0')
  5579. {
  5580. fc->col_type[reg] = DW_CFA_undefined;
  5581. fc->col_offset[reg] = 0;
  5582. }
  5583. break;
  5584. case DW_CFA_same_value:
  5585. reg = LEB ();
  5586. if (reg >= (unsigned int) fc->ncols)
  5587. reg_prefix = bad_reg;
  5588. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5589. printf (" DW_CFA_same_value: %s%s\n",
  5590. reg_prefix, regname (reg, 0));
  5591. if (*reg_prefix == '\0')
  5592. {
  5593. fc->col_type[reg] = DW_CFA_same_value;
  5594. fc->col_offset[reg] = 0;
  5595. }
  5596. break;
  5597. case DW_CFA_register:
  5598. reg = LEB ();
  5599. roffs = LEB ();
  5600. if (reg >= (unsigned int) fc->ncols)
  5601. reg_prefix = bad_reg;
  5602. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5603. {
  5604. printf (" DW_CFA_register: %s%s in ",
  5605. reg_prefix, regname (reg, 0));
  5606. puts (regname (roffs, 0));
  5607. }
  5608. if (*reg_prefix == '\0')
  5609. {
  5610. fc->col_type[reg] = DW_CFA_register;
  5611. fc->col_offset[reg] = roffs;
  5612. }
  5613. break;
  5614. case DW_CFA_remember_state:
  5615. if (! do_debug_frames_interp)
  5616. printf (" DW_CFA_remember_state\n");
  5617. rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
  5618. rs->cfa_offset = fc->cfa_offset;
  5619. rs->cfa_reg = fc->cfa_reg;
  5620. rs->ra = fc->ra;
  5621. rs->cfa_exp = fc->cfa_exp;
  5622. rs->ncols = fc->ncols;
  5623. rs->col_type = (short int *) xcmalloc (rs->ncols,
  5624. sizeof (* rs->col_type));
  5625. rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
  5626. memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
  5627. memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
  5628. rs->next = remembered_state;
  5629. remembered_state = rs;
  5630. break;
  5631. case DW_CFA_restore_state:
  5632. if (! do_debug_frames_interp)
  5633. printf (" DW_CFA_restore_state\n");
  5634. rs = remembered_state;
  5635. if (rs)
  5636. {
  5637. remembered_state = rs->next;
  5638. fc->cfa_offset = rs->cfa_offset;
  5639. fc->cfa_reg = rs->cfa_reg;
  5640. fc->ra = rs->ra;
  5641. fc->cfa_exp = rs->cfa_exp;
  5642. if (frame_need_space (fc, rs->ncols - 1) < 0)
  5643. {
  5644. warn (_("Invalid column number in saved frame state\n"));
  5645. fc->ncols = 0;
  5646. break;
  5647. }
  5648. memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
  5649. memcpy (fc->col_offset, rs->col_offset,
  5650. rs->ncols * sizeof (* rs->col_offset));
  5651. free (rs->col_type);
  5652. free (rs->col_offset);
  5653. free (rs);
  5654. }
  5655. else if (do_debug_frames_interp)
  5656. printf ("Mismatched DW_CFA_restore_state\n");
  5657. break;
  5658. case DW_CFA_def_cfa:
  5659. fc->cfa_reg = LEB ();
  5660. fc->cfa_offset = LEB ();
  5661. fc->cfa_exp = 0;
  5662. if (! do_debug_frames_interp)
  5663. printf (" DW_CFA_def_cfa: %s ofs %d\n",
  5664. regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
  5665. break;
  5666. case DW_CFA_def_cfa_register:
  5667. fc->cfa_reg = LEB ();
  5668. fc->cfa_exp = 0;
  5669. if (! do_debug_frames_interp)
  5670. printf (" DW_CFA_def_cfa_register: %s\n",
  5671. regname (fc->cfa_reg, 0));
  5672. break;
  5673. case DW_CFA_def_cfa_offset:
  5674. fc->cfa_offset = LEB ();
  5675. if (! do_debug_frames_interp)
  5676. printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
  5677. break;
  5678. case DW_CFA_nop:
  5679. if (! do_debug_frames_interp)
  5680. printf (" DW_CFA_nop\n");
  5681. break;
  5682. case DW_CFA_def_cfa_expression:
  5683. ul = LEB ();
  5684. if (start >= block_end || start + ul > block_end || start + ul < start)
  5685. {
  5686. printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
  5687. break;
  5688. }
  5689. if (! do_debug_frames_interp)
  5690. {
  5691. printf (" DW_CFA_def_cfa_expression (");
  5692. decode_location_expression (start, eh_addr_size, 0, -1,
  5693. ul, 0, section);
  5694. printf (")\n");
  5695. }
  5696. fc->cfa_exp = 1;
  5697. start += ul;
  5698. break;
  5699. case DW_CFA_expression:
  5700. reg = LEB ();
  5701. ul = LEB ();
  5702. if (reg >= (unsigned int) fc->ncols)
  5703. reg_prefix = bad_reg;
  5704. /* PR 17512: file: 069-133014-0.006. */
  5705. /* PR 17512: file: 98c02eb4. */
  5706. tmp = start + ul;
  5707. if (start >= block_end || tmp > block_end || tmp < start)
  5708. {
  5709. printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
  5710. break;
  5711. }
  5712. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5713. {
  5714. printf (" DW_CFA_expression: %s%s (",
  5715. reg_prefix, regname (reg, 0));
  5716. decode_location_expression (start, eh_addr_size, 0, -1,
  5717. ul, 0, section);
  5718. printf (")\n");
  5719. }
  5720. if (*reg_prefix == '\0')
  5721. fc->col_type[reg] = DW_CFA_expression;
  5722. start = tmp;
  5723. break;
  5724. case DW_CFA_val_expression:
  5725. reg = LEB ();
  5726. ul = LEB ();
  5727. if (reg >= (unsigned int) fc->ncols)
  5728. reg_prefix = bad_reg;
  5729. tmp = start + ul;
  5730. if (start >= block_end || tmp > block_end || tmp < start)
  5731. {
  5732. printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
  5733. break;
  5734. }
  5735. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5736. {
  5737. printf (" DW_CFA_val_expression: %s%s (",
  5738. reg_prefix, regname (reg, 0));
  5739. decode_location_expression (start, eh_addr_size, 0, -1,
  5740. ul, 0, section);
  5741. printf (")\n");
  5742. }
  5743. if (*reg_prefix == '\0')
  5744. fc->col_type[reg] = DW_CFA_val_expression;
  5745. start = tmp;
  5746. break;
  5747. case DW_CFA_offset_extended_sf:
  5748. reg = LEB ();
  5749. l = SLEB ();
  5750. if (frame_need_space (fc, reg) < 0)
  5751. reg_prefix = bad_reg;
  5752. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5753. printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
  5754. reg_prefix, regname (reg, 0),
  5755. (long)(l * fc->data_factor));
  5756. if (*reg_prefix == '\0')
  5757. {
  5758. fc->col_type[reg] = DW_CFA_offset;
  5759. fc->col_offset[reg] = l * fc->data_factor;
  5760. }
  5761. break;
  5762. case DW_CFA_val_offset_sf:
  5763. reg = LEB ();
  5764. l = SLEB ();
  5765. if (frame_need_space (fc, reg) < 0)
  5766. reg_prefix = bad_reg;
  5767. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5768. printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
  5769. reg_prefix, regname (reg, 0),
  5770. (long)(l * fc->data_factor));
  5771. if (*reg_prefix == '\0')
  5772. {
  5773. fc->col_type[reg] = DW_CFA_val_offset;
  5774. fc->col_offset[reg] = l * fc->data_factor;
  5775. }
  5776. break;
  5777. case DW_CFA_def_cfa_sf:
  5778. fc->cfa_reg = LEB ();
  5779. fc->cfa_offset = SLEB ();
  5780. fc->cfa_offset = fc->cfa_offset * fc->data_factor;
  5781. fc->cfa_exp = 0;
  5782. if (! do_debug_frames_interp)
  5783. printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
  5784. regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
  5785. break;
  5786. case DW_CFA_def_cfa_offset_sf:
  5787. fc->cfa_offset = SLEB ();
  5788. fc->cfa_offset *= fc->data_factor;
  5789. if (! do_debug_frames_interp)
  5790. printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc->cfa_offset);
  5791. break;
  5792. case DW_CFA_MIPS_advance_loc8:
  5793. SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
  5794. if (do_debug_frames_interp)
  5795. frame_display_row (fc, &need_col_headers, &max_regs);
  5796. else
  5797. printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
  5798. (unsigned long) (ofs * fc->code_factor),
  5799. dwarf_vmatoa_1 (NULL,
  5800. fc->pc_begin + ofs * fc->code_factor,
  5801. fc->ptr_size));
  5802. fc->pc_begin += ofs * fc->code_factor;
  5803. break;
  5804. case DW_CFA_GNU_window_save:
  5805. if (! do_debug_frames_interp)
  5806. printf (" DW_CFA_GNU_window_save\n");
  5807. break;
  5808. case DW_CFA_GNU_args_size:
  5809. ul = LEB ();
  5810. if (! do_debug_frames_interp)
  5811. printf (" DW_CFA_GNU_args_size: %ld\n", ul);
  5812. break;
  5813. case DW_CFA_GNU_negative_offset_extended:
  5814. reg = LEB ();
  5815. l = - LEB ();
  5816. if (frame_need_space (fc, reg) < 0)
  5817. reg_prefix = bad_reg;
  5818. if (! do_debug_frames_interp || *reg_prefix != '\0')
  5819. printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
  5820. reg_prefix, regname (reg, 0),
  5821. (long)(l * fc->data_factor));
  5822. if (*reg_prefix == '\0')
  5823. {
  5824. fc->col_type[reg] = DW_CFA_offset;
  5825. fc->col_offset[reg] = l * fc->data_factor;
  5826. }
  5827. break;
  5828. default:
  5829. if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
  5830. printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
  5831. else
  5832. warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
  5833. start = block_end;
  5834. }
  5835. }
  5836. if (do_debug_frames_interp)
  5837. frame_display_row (fc, &need_col_headers, &max_regs);
  5838. start = block_end;
  5839. eh_addr_size = saved_eh_addr_size;
  5840. }
  5841. printf ("\n");
  5842. return 1;
  5843. }
  5844. #undef GET
  5845. #undef LEB
  5846. #undef SLEB
  5847. static int
  5848. display_gdb_index (struct dwarf_section *section,
  5849. void *file ATTRIBUTE_UNUSED)
  5850. {
  5851. unsigned char *start = section->start;
  5852. uint32_t version;
  5853. uint32_t cu_list_offset, tu_list_offset;
  5854. uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
  5855. unsigned int cu_list_elements, tu_list_elements;
  5856. unsigned int address_table_size, symbol_table_slots;
  5857. unsigned char *cu_list, *tu_list;
  5858. unsigned char *address_table, *symbol_table, *constant_pool;
  5859. unsigned int i;
  5860. /* The documentation for the format of this file is in gdb/dwarf2read.c. */
  5861. printf (_("Contents of the %s section:\n"), section->name);
  5862. if (section->size < 6 * sizeof (uint32_t))
  5863. {
  5864. warn (_("Truncated header in the %s section.\n"), section->name);
  5865. return 0;
  5866. }
  5867. version = byte_get_little_endian (start, 4);
  5868. printf (_("Version %ld\n"), (long) version);
  5869. /* Prior versions are obsolete, and future versions may not be
  5870. backwards compatible. */
  5871. if (version < 3 || version > 8)
  5872. {
  5873. warn (_("Unsupported version %lu.\n"), (unsigned long) version);
  5874. return 0;
  5875. }
  5876. if (version < 4)
  5877. warn (_("The address table data in version 3 may be wrong.\n"));
  5878. if (version < 5)
  5879. warn (_("Version 4 does not support case insensitive lookups.\n"));
  5880. if (version < 6)
  5881. warn (_("Version 5 does not include inlined functions.\n"));
  5882. if (version < 7)
  5883. warn (_("Version 6 does not include symbol attributes.\n"));
  5884. /* Version 7 indices generated by Gold have bad type unit references,
  5885. PR binutils/15021. But we don't know if the index was generated by
  5886. Gold or not, so to avoid worrying users with gdb-generated indices
  5887. we say nothing for version 7 here. */
  5888. cu_list_offset = byte_get_little_endian (start + 4, 4);
  5889. tu_list_offset = byte_get_little_endian (start + 8, 4);
  5890. address_table_offset = byte_get_little_endian (start + 12, 4);
  5891. symbol_table_offset = byte_get_little_endian (start + 16, 4);
  5892. constant_pool_offset = byte_get_little_endian (start + 20, 4);
  5893. if (cu_list_offset > section->size
  5894. || tu_list_offset > section->size
  5895. || address_table_offset > section->size
  5896. || symbol_table_offset > section->size
  5897. || constant_pool_offset > section->size)
  5898. {
  5899. warn (_("Corrupt header in the %s section.\n"), section->name);
  5900. return 0;
  5901. }
  5902. /* PR 17531: file: 418d0a8a. */
  5903. if (tu_list_offset < cu_list_offset)
  5904. {
  5905. warn (_("TU offset (%x) is less than CU offset (%x)\n"),
  5906. tu_list_offset, cu_list_offset);
  5907. return 0;
  5908. }
  5909. cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
  5910. if (address_table_offset < tu_list_offset)
  5911. {
  5912. warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
  5913. address_table_offset, tu_list_offset);
  5914. return 0;
  5915. }
  5916. tu_list_elements = (address_table_offset - tu_list_offset) / 8;
  5917. /* PR 17531: file: 18a47d3d. */
  5918. if (symbol_table_offset < address_table_offset)
  5919. {
  5920. warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
  5921. symbol_table_offset, address_table_offset);
  5922. return 0;
  5923. }
  5924. address_table_size = symbol_table_offset - address_table_offset;
  5925. if (constant_pool_offset < symbol_table_offset)
  5926. {
  5927. warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
  5928. constant_pool_offset, symbol_table_offset);
  5929. return 0;
  5930. }
  5931. symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
  5932. cu_list = start + cu_list_offset;
  5933. tu_list = start + tu_list_offset;
  5934. address_table = start + address_table_offset;
  5935. symbol_table = start + symbol_table_offset;
  5936. constant_pool = start + constant_pool_offset;
  5937. if (address_table + address_table_size * (2 + 8 + 4) > section->start + section->size)
  5938. {
  5939. warn (_("Address table extends beyond end of section.\n"));
  5940. return 0;
  5941. }
  5942. printf (_("\nCU table:\n"));
  5943. for (i = 0; i < cu_list_elements; i += 2)
  5944. {
  5945. uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
  5946. uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
  5947. printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
  5948. (unsigned long) cu_offset,
  5949. (unsigned long) (cu_offset + cu_length - 1));
  5950. }
  5951. printf (_("\nTU table:\n"));
  5952. for (i = 0; i < tu_list_elements; i += 3)
  5953. {
  5954. uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
  5955. uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
  5956. uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
  5957. printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
  5958. (unsigned long) tu_offset,
  5959. (unsigned long) type_offset);
  5960. print_dwarf_vma (signature, 8);
  5961. printf ("\n");
  5962. }
  5963. printf (_("\nAddress table:\n"));
  5964. for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
  5965. i += 2 * 8 + 4)
  5966. {
  5967. uint64_t low = byte_get_little_endian (address_table + i, 8);
  5968. uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
  5969. uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
  5970. print_dwarf_vma (low, 8);
  5971. print_dwarf_vma (high, 8);
  5972. printf (_("%lu\n"), (unsigned long) cu_index);
  5973. }
  5974. printf (_("\nSymbol table:\n"));
  5975. for (i = 0; i < symbol_table_slots; ++i)
  5976. {
  5977. uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
  5978. uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
  5979. uint32_t num_cus, cu;
  5980. if (name_offset != 0
  5981. || cu_vector_offset != 0)
  5982. {
  5983. unsigned int j;
  5984. unsigned char * adr;
  5985. adr = constant_pool + name_offset;
  5986. /* PR 17531: file: 5b7b07ad. */
  5987. if (adr < constant_pool || adr >= section->start + section->size)
  5988. {
  5989. printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
  5990. warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
  5991. name_offset, i);
  5992. }
  5993. else
  5994. printf ("[%3u] %.*s:", i,
  5995. (int) (section->size - (constant_pool_offset + name_offset)),
  5996. constant_pool + name_offset);
  5997. adr = constant_pool + cu_vector_offset;
  5998. if (adr < constant_pool || adr >= section->start + section->size - 3)
  5999. {
  6000. printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
  6001. warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
  6002. cu_vector_offset, i);
  6003. continue;
  6004. }
  6005. num_cus = byte_get_little_endian (adr, 4);
  6006. adr = constant_pool + cu_vector_offset + 4 + num_cus * 4;
  6007. if (num_cus * 4 < num_cus
  6008. || adr >= section->start + section->size
  6009. || adr < constant_pool)
  6010. {
  6011. printf ("<invalid number of CUs: %d>\n", num_cus);
  6012. warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
  6013. num_cus, i);
  6014. continue;
  6015. }
  6016. if (num_cus > 1)
  6017. printf ("\n");
  6018. for (j = 0; j < num_cus; ++j)
  6019. {
  6020. int is_static;
  6021. gdb_index_symbol_kind kind;
  6022. cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
  6023. is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
  6024. kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
  6025. cu = GDB_INDEX_CU_VALUE (cu);
  6026. /* Convert to TU number if it's for a type unit. */
  6027. if (cu >= cu_list_elements / 2)
  6028. printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
  6029. (unsigned long) (cu - cu_list_elements / 2));
  6030. else
  6031. printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
  6032. printf (" [%s, %s]",
  6033. is_static ? _("static") : _("global"),
  6034. get_gdb_index_symbol_kind_name (kind));
  6035. if (num_cus > 1)
  6036. printf ("\n");
  6037. }
  6038. if (num_cus <= 1)
  6039. printf ("\n");
  6040. }
  6041. }
  6042. return 1;
  6043. }
  6044. /* Pre-allocate enough space for the CU/TU sets needed. */
  6045. static void
  6046. prealloc_cu_tu_list (unsigned int nshndx)
  6047. {
  6048. if (shndx_pool == NULL)
  6049. {
  6050. shndx_pool_size = nshndx;
  6051. shndx_pool_used = 0;
  6052. shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
  6053. sizeof (unsigned int));
  6054. }
  6055. else
  6056. {
  6057. shndx_pool_size = shndx_pool_used + nshndx;
  6058. shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
  6059. sizeof (unsigned int));
  6060. }
  6061. }
  6062. static void
  6063. add_shndx_to_cu_tu_entry (unsigned int shndx)
  6064. {
  6065. if (shndx_pool_used >= shndx_pool_size)
  6066. {
  6067. error (_("Internal error: out of space in the shndx pool.\n"));
  6068. return;
  6069. }
  6070. shndx_pool [shndx_pool_used++] = shndx;
  6071. }
  6072. static void
  6073. end_cu_tu_entry (void)
  6074. {
  6075. if (shndx_pool_used >= shndx_pool_size)
  6076. {
  6077. error (_("Internal error: out of space in the shndx pool.\n"));
  6078. return;
  6079. }
  6080. shndx_pool [shndx_pool_used++] = 0;
  6081. }
  6082. /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
  6083. static const char *
  6084. get_DW_SECT_short_name (unsigned int dw_sect)
  6085. {
  6086. static char buf[16];
  6087. switch (dw_sect)
  6088. {
  6089. case DW_SECT_INFO:
  6090. return "info";
  6091. case DW_SECT_TYPES:
  6092. return "types";
  6093. case DW_SECT_ABBREV:
  6094. return "abbrev";
  6095. case DW_SECT_LINE:
  6096. return "line";
  6097. case DW_SECT_LOC:
  6098. return "loc";
  6099. case DW_SECT_STR_OFFSETS:
  6100. return "str_off";
  6101. case DW_SECT_MACINFO:
  6102. return "macinfo";
  6103. case DW_SECT_MACRO:
  6104. return "macro";
  6105. default:
  6106. break;
  6107. }
  6108. snprintf (buf, sizeof (buf), "%d", dw_sect);
  6109. return buf;
  6110. }
  6111. /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
  6112. These sections are extensions for Fission.
  6113. See http://gcc.gnu.org/wiki/DebugFissionDWP. */
  6114. static int
  6115. process_cu_tu_index (struct dwarf_section *section, int do_display)
  6116. {
  6117. unsigned char *phdr = section->start;
  6118. unsigned char *limit = phdr + section->size;
  6119. unsigned char *phash;
  6120. unsigned char *pindex;
  6121. unsigned char *ppool;
  6122. unsigned int version;
  6123. unsigned int ncols = 0;
  6124. unsigned int nused;
  6125. unsigned int nslots;
  6126. unsigned int i;
  6127. unsigned int j;
  6128. dwarf_vma signature_high;
  6129. dwarf_vma signature_low;
  6130. char buf[64];
  6131. /* PR 17512: file: 002-168123-0.004. */
  6132. if (phdr == NULL)
  6133. {
  6134. warn (_("Section %s is empty\n"), section->name);
  6135. return 0;
  6136. }
  6137. /* PR 17512: file: 002-376-0.004. */
  6138. if (section->size < 24)
  6139. {
  6140. warn (_("Section %s is too small to contain a CU/TU header\n"),
  6141. section->name);
  6142. return 0;
  6143. }
  6144. SAFE_BYTE_GET (version, phdr, 4, limit);
  6145. if (version >= 2)
  6146. SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
  6147. SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
  6148. SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
  6149. phash = phdr + 16;
  6150. pindex = phash + nslots * 8;
  6151. ppool = pindex + nslots * 4;
  6152. /* PR 17531: file: 45d69832. */
  6153. if (pindex < phash || ppool < phdr || (pindex == phash && nslots != 0))
  6154. {
  6155. warn (_("Section %s is too small for %d slots\n"),
  6156. section->name, nslots);
  6157. return 0;
  6158. }
  6159. if (do_display)
  6160. {
  6161. printf (_("Contents of the %s section:\n\n"), section->name);
  6162. printf (_(" Version: %d\n"), version);
  6163. if (version >= 2)
  6164. printf (_(" Number of columns: %d\n"), ncols);
  6165. printf (_(" Number of used entries: %d\n"), nused);
  6166. printf (_(" Number of slots: %d\n\n"), nslots);
  6167. }
  6168. if (ppool > limit || ppool < phdr)
  6169. {
  6170. warn (_("Section %s too small for %d hash table entries\n"),
  6171. section->name, nslots);
  6172. return 0;
  6173. }
  6174. if (version == 1)
  6175. {
  6176. if (!do_display)
  6177. prealloc_cu_tu_list ((limit - ppool) / 4);
  6178. for (i = 0; i < nslots; i++)
  6179. {
  6180. unsigned char *shndx_list;
  6181. unsigned int shndx;
  6182. SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
  6183. if (signature_high != 0 || signature_low != 0)
  6184. {
  6185. SAFE_BYTE_GET (j, pindex, 4, limit);
  6186. shndx_list = ppool + j * 4;
  6187. /* PR 17531: file: 705e010d. */
  6188. if (shndx_list < ppool)
  6189. {
  6190. warn (_("Section index pool located before start of section\n"));
  6191. return 0;
  6192. }
  6193. if (do_display)
  6194. printf (_(" [%3d] Signature: 0x%s Sections: "),
  6195. i, dwarf_vmatoa64 (signature_high, signature_low,
  6196. buf, sizeof (buf)));
  6197. for (;;)
  6198. {
  6199. if (shndx_list >= limit)
  6200. {
  6201. warn (_("Section %s too small for shndx pool\n"),
  6202. section->name);
  6203. return 0;
  6204. }
  6205. SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
  6206. if (shndx == 0)
  6207. break;
  6208. if (do_display)
  6209. printf (" %d", shndx);
  6210. else
  6211. add_shndx_to_cu_tu_entry (shndx);
  6212. shndx_list += 4;
  6213. }
  6214. if (do_display)
  6215. printf ("\n");
  6216. else
  6217. end_cu_tu_entry ();
  6218. }
  6219. phash += 8;
  6220. pindex += 4;
  6221. }
  6222. }
  6223. else if (version == 2)
  6224. {
  6225. unsigned int val;
  6226. unsigned int dw_sect;
  6227. unsigned char *ph = phash;
  6228. unsigned char *pi = pindex;
  6229. unsigned char *poffsets = ppool + ncols * 4;
  6230. unsigned char *psizes = poffsets + nused * ncols * 4;
  6231. unsigned char *pend = psizes + nused * ncols * 4;
  6232. bfd_boolean is_tu_index;
  6233. struct cu_tu_set *this_set = NULL;
  6234. unsigned int row;
  6235. unsigned char *prow;
  6236. is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
  6237. /* PR 17531: file: 0dd159bf.
  6238. Check for wraparound with an overlarge ncols value. */
  6239. if (poffsets < ppool || (unsigned int) ((poffsets - ppool) / 4) != ncols)
  6240. {
  6241. warn (_("Overlarge number of columns: %x\n"), ncols);
  6242. return 0;
  6243. }
  6244. if (pend > limit)
  6245. {
  6246. warn (_("Section %s too small for offset and size tables\n"),
  6247. section->name);
  6248. return 0;
  6249. }
  6250. if (do_display)
  6251. {
  6252. printf (_(" Offset table\n"));
  6253. printf (" slot %-16s ",
  6254. is_tu_index ? _("signature") : _("dwo_id"));
  6255. }
  6256. else
  6257. {
  6258. if (is_tu_index)
  6259. {
  6260. tu_count = nused;
  6261. tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
  6262. this_set = tu_sets;
  6263. }
  6264. else
  6265. {
  6266. cu_count = nused;
  6267. cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
  6268. this_set = cu_sets;
  6269. }
  6270. }
  6271. if (do_display)
  6272. {
  6273. for (j = 0; j < ncols; j++)
  6274. {
  6275. SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
  6276. printf (" %8s", get_DW_SECT_short_name (dw_sect));
  6277. }
  6278. printf ("\n");
  6279. }
  6280. for (i = 0; i < nslots; i++)
  6281. {
  6282. SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
  6283. SAFE_BYTE_GET (row, pi, 4, limit);
  6284. if (row != 0)
  6285. {
  6286. /* PR 17531: file: a05f6ab3. */
  6287. if (row > nused)
  6288. {
  6289. warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
  6290. row, nused);
  6291. return 0;
  6292. }
  6293. if (!do_display)
  6294. memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
  6295. prow = poffsets + (row - 1) * ncols * 4;
  6296. /* PR 17531: file: b8ce60a8. */
  6297. if (prow < poffsets || prow > limit)
  6298. {
  6299. warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
  6300. row, ncols);
  6301. return 0;
  6302. }
  6303. if (do_display)
  6304. printf (_(" [%3d] 0x%s"),
  6305. i, dwarf_vmatoa64 (signature_high, signature_low,
  6306. buf, sizeof (buf)));
  6307. for (j = 0; j < ncols; j++)
  6308. {
  6309. SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
  6310. if (do_display)
  6311. printf (" %8d", val);
  6312. else
  6313. {
  6314. SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
  6315. /* PR 17531: file: 10796eb3. */
  6316. if (dw_sect >= DW_SECT_MAX)
  6317. warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
  6318. else
  6319. this_set [row - 1].section_offsets [dw_sect] = val;
  6320. }
  6321. }
  6322. if (do_display)
  6323. printf ("\n");
  6324. }
  6325. ph += 8;
  6326. pi += 4;
  6327. }
  6328. ph = phash;
  6329. pi = pindex;
  6330. if (do_display)
  6331. {
  6332. printf ("\n");
  6333. printf (_(" Size table\n"));
  6334. printf (" slot %-16s ",
  6335. is_tu_index ? _("signature") : _("dwo_id"));
  6336. }
  6337. for (j = 0; j < ncols; j++)
  6338. {
  6339. SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
  6340. if (do_display)
  6341. printf (" %8s", get_DW_SECT_short_name (val));
  6342. }
  6343. if (do_display)
  6344. printf ("\n");
  6345. for (i = 0; i < nslots; i++)
  6346. {
  6347. SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
  6348. SAFE_BYTE_GET (row, pi, 4, limit);
  6349. if (row != 0)
  6350. {
  6351. prow = psizes + (row - 1) * ncols * 4;
  6352. if (do_display)
  6353. printf (_(" [%3d] 0x%s"),
  6354. i, dwarf_vmatoa64 (signature_high, signature_low,
  6355. buf, sizeof (buf)));
  6356. for (j = 0; j < ncols; j++)
  6357. {
  6358. SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
  6359. if (do_display)
  6360. printf (" %8d", val);
  6361. else
  6362. {
  6363. SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
  6364. if (dw_sect >= DW_SECT_MAX)
  6365. warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
  6366. else
  6367. this_set [row - 1].section_sizes [dw_sect] = val;
  6368. }
  6369. }
  6370. if (do_display)
  6371. printf ("\n");
  6372. }
  6373. ph += 8;
  6374. pi += 4;
  6375. }
  6376. }
  6377. else if (do_display)
  6378. printf (_(" Unsupported version (%d)\n"), version);
  6379. if (do_display)
  6380. printf ("\n");
  6381. return 1;
  6382. }
  6383. /* Load the CU and TU indexes if present. This will build a list of
  6384. section sets that we can use to associate a .debug_info.dwo section
  6385. with its associated .debug_abbrev.dwo section in a .dwp file. */
  6386. static void
  6387. load_cu_tu_indexes (void *file)
  6388. {
  6389. /* If we have already loaded (or tried to load) the CU and TU indexes
  6390. then do not bother to repeat the task. */
  6391. if (cu_tu_indexes_read)
  6392. return;
  6393. if (load_debug_section (dwp_cu_index, file))
  6394. process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
  6395. if (load_debug_section (dwp_tu_index, file))
  6396. process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
  6397. cu_tu_indexes_read = 1;
  6398. }
  6399. /* Find the set of sections that includes section SHNDX. */
  6400. unsigned int *
  6401. find_cu_tu_set (void *file, unsigned int shndx)
  6402. {
  6403. unsigned int i;
  6404. load_cu_tu_indexes (file);
  6405. /* Find SHNDX in the shndx pool. */
  6406. for (i = 0; i < shndx_pool_used; i++)
  6407. if (shndx_pool [i] == shndx)
  6408. break;
  6409. if (i >= shndx_pool_used)
  6410. return NULL;
  6411. /* Now backup to find the first entry in the set. */
  6412. while (i > 0 && shndx_pool [i - 1] != 0)
  6413. i--;
  6414. return shndx_pool + i;
  6415. }
  6416. /* Display a .debug_cu_index or .debug_tu_index section. */
  6417. static int
  6418. display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
  6419. {
  6420. return process_cu_tu_index (section, 1);
  6421. }
  6422. static int
  6423. display_debug_not_supported (struct dwarf_section *section,
  6424. void *file ATTRIBUTE_UNUSED)
  6425. {
  6426. printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
  6427. section->name);
  6428. return 1;
  6429. }
  6430. /* Like malloc, but takes two parameters like calloc.
  6431. Verifies that the first parameter is not too large.
  6432. Note: does *not* initialise the allocated memory to zero. */
  6433. void *
  6434. cmalloc (size_t nmemb, size_t size)
  6435. {
  6436. /* Check for overflow. */
  6437. if (nmemb >= ~(size_t) 0 / size)
  6438. return NULL;
  6439. return xmalloc (nmemb * size);
  6440. }
  6441. /* Like xmalloc, but takes two parameters like calloc.
  6442. Verifies that the first parameter is not too large.
  6443. Note: does *not* initialise the allocated memory to zero. */
  6444. void *
  6445. xcmalloc (size_t nmemb, size_t size)
  6446. {
  6447. /* Check for overflow. */
  6448. if (nmemb >= ~(size_t) 0 / size)
  6449. {
  6450. fprintf (stderr,
  6451. _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
  6452. (long) nmemb);
  6453. xexit (1);
  6454. }
  6455. return xmalloc (nmemb * size);
  6456. }
  6457. /* Like xrealloc, but takes three parameters.
  6458. Verifies that the second parameter is not too large.
  6459. Note: does *not* initialise any new memory to zero. */
  6460. void *
  6461. xcrealloc (void *ptr, size_t nmemb, size_t size)
  6462. {
  6463. /* Check for overflow. */
  6464. if (nmemb >= ~(size_t) 0 / size)
  6465. {
  6466. fprintf (stderr,
  6467. _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
  6468. (long) nmemb);
  6469. xexit (1);
  6470. }
  6471. return xrealloc (ptr, nmemb * size);
  6472. }
  6473. /* Like xcalloc, but verifies that the first parameter is not too large. */
  6474. void *
  6475. xcalloc2 (size_t nmemb, size_t size)
  6476. {
  6477. /* Check for overflow. */
  6478. if (nmemb >= ~(size_t) 0 / size)
  6479. {
  6480. fprintf (stderr,
  6481. _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
  6482. (long) nmemb);
  6483. xexit (1);
  6484. }
  6485. return xcalloc (nmemb, size);
  6486. }
  6487. void
  6488. free_debug_memory (void)
  6489. {
  6490. unsigned int i;
  6491. free_abbrevs ();
  6492. for (i = 0; i < max; i++)
  6493. free_debug_section ((enum dwarf_section_display_enum) i);
  6494. if (debug_information != NULL)
  6495. {
  6496. if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
  6497. {
  6498. for (i = 0; i < num_debug_info_entries; i++)
  6499. {
  6500. if (!debug_information [i].max_loc_offsets)
  6501. {
  6502. free (debug_information [i].loc_offsets);
  6503. free (debug_information [i].have_frame_base);
  6504. }
  6505. if (!debug_information [i].max_range_lists)
  6506. free (debug_information [i].range_lists);
  6507. }
  6508. }
  6509. free (debug_information);
  6510. debug_information = NULL;
  6511. alloc_num_debug_info_entries = num_debug_info_entries = 0;
  6512. }
  6513. }
  6514. void
  6515. dwarf_select_sections_by_names (const char *names)
  6516. {
  6517. typedef struct
  6518. {
  6519. const char * option;
  6520. int * variable;
  6521. int val;
  6522. }
  6523. debug_dump_long_opts;
  6524. static const debug_dump_long_opts opts_table [] =
  6525. {
  6526. /* Please keep this table alpha- sorted. */
  6527. { "Ranges", & do_debug_ranges, 1 },
  6528. { "abbrev", & do_debug_abbrevs, 1 },
  6529. { "addr", & do_debug_addr, 1 },
  6530. { "aranges", & do_debug_aranges, 1 },
  6531. { "cu_index", & do_debug_cu_index, 1 },
  6532. { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
  6533. { "frames", & do_debug_frames, 1 },
  6534. { "frames-interp", & do_debug_frames_interp, 1 },
  6535. /* The special .gdb_index section. */
  6536. { "gdb_index", & do_gdb_index, 1 },
  6537. { "info", & do_debug_info, 1 },
  6538. { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
  6539. { "loc", & do_debug_loc, 1 },
  6540. { "macro", & do_debug_macinfo, 1 },
  6541. { "pubnames", & do_debug_pubnames, 1 },
  6542. { "pubtypes", & do_debug_pubtypes, 1 },
  6543. /* This entry is for compatability
  6544. with earlier versions of readelf. */
  6545. { "ranges", & do_debug_aranges, 1 },
  6546. { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
  6547. { "str", & do_debug_str, 1 },
  6548. /* These trace_* sections are used by Itanium VMS. */
  6549. { "trace_abbrev", & do_trace_abbrevs, 1 },
  6550. { "trace_aranges", & do_trace_aranges, 1 },
  6551. { "trace_info", & do_trace_info, 1 },
  6552. { NULL, NULL, 0 }
  6553. };
  6554. const char *p;
  6555. p = names;
  6556. while (*p)
  6557. {
  6558. const debug_dump_long_opts * entry;
  6559. for (entry = opts_table; entry->option; entry++)
  6560. {
  6561. size_t len = strlen (entry->option);
  6562. if (strncmp (p, entry->option, len) == 0
  6563. && (p[len] == ',' || p[len] == '\0'))
  6564. {
  6565. * entry->variable |= entry->val;
  6566. /* The --debug-dump=frames-interp option also
  6567. enables the --debug-dump=frames option. */
  6568. if (do_debug_frames_interp)
  6569. do_debug_frames = 1;
  6570. p += len;
  6571. break;
  6572. }
  6573. }
  6574. if (entry->option == NULL)
  6575. {
  6576. warn (_("Unrecognized debug option '%s'\n"), p);
  6577. p = strchr (p, ',');
  6578. if (p == NULL)
  6579. break;
  6580. }
  6581. if (*p == ',')
  6582. p++;
  6583. }
  6584. }
  6585. void
  6586. dwarf_select_sections_by_letters (const char *letters)
  6587. {
  6588. unsigned int lindex = 0;
  6589. while (letters[lindex])
  6590. switch (letters[lindex++])
  6591. {
  6592. case 'i':
  6593. do_debug_info = 1;
  6594. break;
  6595. case 'a':
  6596. do_debug_abbrevs = 1;
  6597. break;
  6598. case 'l':
  6599. do_debug_lines |= FLAG_DEBUG_LINES_RAW;
  6600. break;
  6601. case 'L':
  6602. do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
  6603. break;
  6604. case 'p':
  6605. do_debug_pubnames = 1;
  6606. break;
  6607. case 't':
  6608. do_debug_pubtypes = 1;
  6609. break;
  6610. case 'r':
  6611. do_debug_aranges = 1;
  6612. break;
  6613. case 'R':
  6614. do_debug_ranges = 1;
  6615. break;
  6616. case 'F':
  6617. do_debug_frames_interp = 1;
  6618. case 'f':
  6619. do_debug_frames = 1;
  6620. break;
  6621. case 'm':
  6622. do_debug_macinfo = 1;
  6623. break;
  6624. case 's':
  6625. do_debug_str = 1;
  6626. break;
  6627. case 'o':
  6628. do_debug_loc = 1;
  6629. break;
  6630. default:
  6631. warn (_("Unrecognized debug option '%s'\n"), letters);
  6632. break;
  6633. }
  6634. }
  6635. void
  6636. dwarf_select_sections_all (void)
  6637. {
  6638. do_debug_info = 1;
  6639. do_debug_abbrevs = 1;
  6640. do_debug_lines = FLAG_DEBUG_LINES_RAW;
  6641. do_debug_pubnames = 1;
  6642. do_debug_pubtypes = 1;
  6643. do_debug_aranges = 1;
  6644. do_debug_ranges = 1;
  6645. do_debug_frames = 1;
  6646. do_debug_macinfo = 1;
  6647. do_debug_str = 1;
  6648. do_debug_loc = 1;
  6649. do_gdb_index = 1;
  6650. do_trace_info = 1;
  6651. do_trace_abbrevs = 1;
  6652. do_trace_aranges = 1;
  6653. do_debug_addr = 1;
  6654. do_debug_cu_index = 1;
  6655. }
  6656. struct dwarf_section_display debug_displays[] =
  6657. {
  6658. { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6659. display_debug_abbrev, &do_debug_abbrevs, FALSE },
  6660. { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6661. display_debug_aranges, &do_debug_aranges, TRUE },
  6662. { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6663. display_debug_frames, &do_debug_frames, TRUE },
  6664. { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
  6665. display_debug_info, &do_debug_info, TRUE },
  6666. { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6667. display_debug_lines, &do_debug_lines, TRUE },
  6668. { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6669. display_debug_pubnames, &do_debug_pubnames, FALSE },
  6670. { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6671. display_debug_gnu_pubnames, &do_debug_pubnames, FALSE },
  6672. { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6673. display_debug_frames, &do_debug_frames, TRUE },
  6674. { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6675. display_debug_macinfo, &do_debug_macinfo, FALSE },
  6676. { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6677. display_debug_macro, &do_debug_macinfo, TRUE },
  6678. { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6679. display_debug_str, &do_debug_str, FALSE },
  6680. { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6681. display_debug_loc, &do_debug_loc, TRUE },
  6682. { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6683. display_debug_pubnames, &do_debug_pubtypes, FALSE },
  6684. { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6685. display_debug_gnu_pubnames, &do_debug_pubtypes, FALSE },
  6686. { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6687. display_debug_ranges, &do_debug_ranges, TRUE },
  6688. { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6689. display_debug_not_supported, NULL, FALSE },
  6690. { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6691. display_debug_not_supported, NULL, FALSE },
  6692. { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL, 0, NULL },
  6693. display_debug_types, &do_debug_info, TRUE },
  6694. { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6695. display_debug_not_supported, NULL, FALSE },
  6696. { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6697. display_gdb_index, &do_gdb_index, FALSE },
  6698. { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL, 0, NULL },
  6699. display_trace_info, &do_trace_info, TRUE },
  6700. { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6701. display_debug_abbrev, &do_trace_abbrevs, FALSE },
  6702. { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6703. display_debug_aranges, &do_trace_aranges, FALSE },
  6704. { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
  6705. display_debug_info, &do_debug_info, TRUE },
  6706. { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6707. display_debug_abbrev, &do_debug_abbrevs, FALSE },
  6708. { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL, 0, NULL },
  6709. display_debug_types, &do_debug_info, TRUE },
  6710. { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6711. display_debug_lines, &do_debug_lines, TRUE },
  6712. { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6713. display_debug_loc, &do_debug_loc, TRUE },
  6714. { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6715. display_debug_macro, &do_debug_macinfo, TRUE },
  6716. { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6717. display_debug_macinfo, &do_debug_macinfo, FALSE },
  6718. { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6719. display_debug_str, &do_debug_str, TRUE },
  6720. { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6721. display_debug_str_offsets, NULL, FALSE },
  6722. { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6723. display_debug_str_offsets, NULL, FALSE },
  6724. { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6725. display_debug_addr, &do_debug_addr, TRUE },
  6726. { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6727. display_cu_index, &do_debug_cu_index, FALSE },
  6728. { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL, 0, NULL },
  6729. display_cu_index, &do_debug_cu_index, FALSE },
  6730. };