dwarf.c 337 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281
  1. /* dwarf.c -- display DWARF contents of a BFD binary file
  2. Copyright (C) 2005-2022 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 <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. #include "filenames.h"
  27. #include "safe-ctype.h"
  28. #include <assert.h>
  29. #ifdef HAVE_LIBDEBUGINFOD
  30. #include <elfutils/debuginfod.h>
  31. #endif
  32. #include <limits.h>
  33. #ifndef CHAR_BIT
  34. #define CHAR_BIT 8
  35. #endif
  36. #ifndef ENABLE_CHECKING
  37. #define ENABLE_CHECKING 0
  38. #endif
  39. #undef MAX
  40. #undef MIN
  41. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  42. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  43. static const char *regname (unsigned int regno, int row);
  44. static const char *regname_internal_by_table_only (unsigned int regno);
  45. static int have_frame_base;
  46. static int need_base_address;
  47. static unsigned int num_debug_info_entries = 0;
  48. static unsigned int alloc_num_debug_info_entries = 0;
  49. static debug_info *debug_information = NULL;
  50. /* Special value for num_debug_info_entries to indicate
  51. that the .debug_info section could not be loaded/parsed. */
  52. #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
  53. /* A .debug_info section can contain multiple links to separate
  54. DWO object files. We use these structures to record these links. */
  55. typedef enum dwo_type
  56. {
  57. DWO_NAME,
  58. DWO_DIR,
  59. DWO_ID
  60. } dwo_type;
  61. typedef struct dwo_info
  62. {
  63. dwo_type type;
  64. const char * value;
  65. dwarf_vma cu_offset;
  66. struct dwo_info * next;
  67. } dwo_info;
  68. static dwo_info *first_dwo_info = NULL;
  69. static bool need_dwo_info;
  70. separate_info * first_separate_info = NULL;
  71. unsigned int eh_addr_size;
  72. int do_debug_info;
  73. int do_debug_abbrevs;
  74. int do_debug_lines;
  75. int do_debug_pubnames;
  76. int do_debug_pubtypes;
  77. int do_debug_aranges;
  78. int do_debug_ranges;
  79. int do_debug_frames;
  80. int do_debug_frames_interp;
  81. int do_debug_macinfo;
  82. int do_debug_str;
  83. int do_debug_str_offsets;
  84. int do_debug_loc;
  85. int do_gdb_index;
  86. int do_trace_info;
  87. int do_trace_abbrevs;
  88. int do_trace_aranges;
  89. int do_debug_addr;
  90. int do_debug_cu_index;
  91. int do_wide;
  92. int do_debug_links;
  93. int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS;
  94. #ifdef HAVE_LIBDEBUGINFOD
  95. int use_debuginfod = 1;
  96. #endif
  97. bool do_checks;
  98. int dwarf_cutoff_level = -1;
  99. unsigned long dwarf_start_die;
  100. int dwarf_check = 0;
  101. /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
  102. testing whether e.g. a locview list is present. */
  103. static const dwarf_vma vm1 = -1;
  104. /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
  105. sections. For version 1 package files, each set is stored in SHNDX_POOL
  106. as a zero-terminated list of section indexes comprising one set of debug
  107. sections from a .dwo file. */
  108. static unsigned int *shndx_pool = NULL;
  109. static unsigned int shndx_pool_size = 0;
  110. static unsigned int shndx_pool_used = 0;
  111. /* For version 2 package files, each set contains an array of section offsets
  112. and an array of section sizes, giving the offset and size of the
  113. contribution from a CU or TU within one of the debug sections.
  114. When displaying debug info from a package file, we need to use these
  115. tables to locate the corresponding contributions to each section. */
  116. struct cu_tu_set
  117. {
  118. uint64_t signature;
  119. dwarf_vma section_offsets[DW_SECT_MAX];
  120. size_t section_sizes[DW_SECT_MAX];
  121. };
  122. static int cu_count = 0;
  123. static int tu_count = 0;
  124. static struct cu_tu_set *cu_sets = NULL;
  125. static struct cu_tu_set *tu_sets = NULL;
  126. static bool load_cu_tu_indexes (void *);
  127. /* An array that indicates for a given level of CU nesting whether
  128. the latest DW_AT_type seen for that level was a signed type or
  129. an unsigned type. */
  130. #define MAX_CU_NESTING (1 << 8)
  131. static bool level_type_signed[MAX_CU_NESTING];
  132. /* Values for do_debug_lines. */
  133. #define FLAG_DEBUG_LINES_RAW 1
  134. #define FLAG_DEBUG_LINES_DECODED 2
  135. static unsigned int
  136. size_of_encoded_value (int encoding)
  137. {
  138. switch (encoding & 0x7)
  139. {
  140. default: /* ??? */
  141. case 0: return eh_addr_size;
  142. case 2: return 2;
  143. case 3: return 4;
  144. case 4: return 8;
  145. }
  146. }
  147. static dwarf_vma
  148. get_encoded_value (unsigned char **pdata,
  149. int encoding,
  150. struct dwarf_section *section,
  151. unsigned char * end)
  152. {
  153. unsigned char * data = * pdata;
  154. unsigned int size = size_of_encoded_value (encoding);
  155. dwarf_vma val;
  156. if (data >= end || size > (size_t) (end - data))
  157. {
  158. warn (_("Encoded value extends past end of section\n"));
  159. * pdata = end;
  160. return 0;
  161. }
  162. /* PR 17512: file: 002-829853-0.004. */
  163. if (size > 8)
  164. {
  165. warn (_("Encoded size of %d is too large to read\n"), size);
  166. * pdata = end;
  167. return 0;
  168. }
  169. /* PR 17512: file: 1085-5603-0.004. */
  170. if (size == 0)
  171. {
  172. warn (_("Encoded size of 0 is too small to read\n"));
  173. * pdata = end;
  174. return 0;
  175. }
  176. if (encoding & DW_EH_PE_signed)
  177. val = byte_get_signed (data, size);
  178. else
  179. val = byte_get (data, size);
  180. if ((encoding & 0x70) == DW_EH_PE_pcrel)
  181. val += section->address + (data - section->start);
  182. * pdata = data + size;
  183. return val;
  184. }
  185. #if SIZEOF_LONG_LONG > SIZEOF_LONG
  186. # ifndef __MINGW32__
  187. # define DWARF_VMA_FMT "ll"
  188. # define DWARF_VMA_FMT_LONG "%16.16llx"
  189. # else
  190. # define DWARF_VMA_FMT "I64"
  191. # define DWARF_VMA_FMT_LONG "%016I64x"
  192. # endif
  193. #else
  194. # define DWARF_VMA_FMT "l"
  195. # define DWARF_VMA_FMT_LONG "%16.16lx"
  196. #endif
  197. /* Convert a dwarf vma value into a string. Returns a pointer to a static
  198. buffer containing the converted VALUE. The value is converted according
  199. to the printf formating character FMTCH. If NUM_BYTES is non-zero then
  200. it specifies the maximum number of bytes to be displayed in the converted
  201. value and FMTCH is ignored - hex is always used. */
  202. static const char *
  203. dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes)
  204. {
  205. /* As dwarf_vmatoa is used more then once in a printf call
  206. for output, we are cycling through a fixed array of pointers
  207. for return address. */
  208. static int buf_pos = 0;
  209. static struct dwarf_vmatoa_buf
  210. {
  211. char place[64];
  212. } buf[16];
  213. char *ret;
  214. ret = buf[buf_pos++].place;
  215. buf_pos %= ARRAY_SIZE (buf);
  216. if (num_bytes)
  217. {
  218. /* Printf does not have a way of specifying a maximum field width for an
  219. integer value, so we print the full value into a buffer and then select
  220. the precision we need. */
  221. snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value);
  222. if (num_bytes > 8)
  223. num_bytes = 8;
  224. return ret + (16 - 2 * num_bytes);
  225. }
  226. else
  227. {
  228. char fmt[32];
  229. if (fmtch)
  230. sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
  231. else
  232. sprintf (fmt, "%%%s", DWARF_VMA_FMT);
  233. snprintf (ret, sizeof (buf[0].place), fmt, value);
  234. return ret;
  235. }
  236. }
  237. static inline const char *
  238. dwarf_vmatoa (const char * fmtch, dwarf_vma value)
  239. {
  240. return dwarf_vmatoa_1 (fmtch, value, 0);
  241. }
  242. /* Print a dwarf_vma value (typically an address, offset or length) in
  243. hexadecimal format, followed by a space. The length of the VALUE (and
  244. hence the precision displayed) is determined by the NUM_BYTES parameter. */
  245. static void
  246. print_dwarf_vma (dwarf_vma value, unsigned num_bytes)
  247. {
  248. printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes));
  249. }
  250. /* Print a view number in hexadecimal value, with the same width
  251. print_dwarf_vma would have printed it with the same num_bytes.
  252. Print blanks for zero view, unless force is nonzero. */
  253. static void
  254. print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
  255. {
  256. int len;
  257. if (!num_bytes)
  258. len = 4;
  259. else
  260. len = num_bytes * 2;
  261. assert (value == (unsigned long) value);
  262. if (value || force)
  263. printf ("v%0*lx ", len - 1, (unsigned long) value);
  264. else
  265. printf ("%*s", len + 1, "");
  266. }
  267. /* Read in a LEB128 encoded value starting at address DATA.
  268. If SIGN is true, return a signed LEB128 value.
  269. If LENGTH_RETURN is not NULL, return in it the number of bytes read.
  270. If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
  271. terminating byte was not found and with bit 1 set if the value
  272. overflows a dwarf_vma.
  273. No bytes will be read at address END or beyond. */
  274. dwarf_vma
  275. read_leb128 (unsigned char *data,
  276. const unsigned char *const end,
  277. bool sign,
  278. unsigned int *length_return,
  279. int *status_return)
  280. {
  281. dwarf_vma result = 0;
  282. unsigned int num_read = 0;
  283. unsigned int shift = 0;
  284. int status = 1;
  285. while (data < end)
  286. {
  287. unsigned char byte = *data++;
  288. unsigned char lost, mask;
  289. num_read++;
  290. if (shift < CHAR_BIT * sizeof (result))
  291. {
  292. result |= ((dwarf_vma) (byte & 0x7f)) << shift;
  293. /* These bits overflowed. */
  294. lost = byte ^ (result >> shift);
  295. /* And this is the mask of possible overflow bits. */
  296. mask = 0x7f ^ ((dwarf_vma) 0x7f << shift >> shift);
  297. shift += 7;
  298. }
  299. else
  300. {
  301. lost = byte;
  302. mask = 0x7f;
  303. }
  304. if ((lost & mask) != (sign && (dwarf_signed_vma) result < 0 ? mask : 0))
  305. status |= 2;
  306. if ((byte & 0x80) == 0)
  307. {
  308. status &= ~1;
  309. if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40))
  310. result |= -((dwarf_vma) 1 << shift);
  311. break;
  312. }
  313. }
  314. if (length_return != NULL)
  315. *length_return = num_read;
  316. if (status_return != NULL)
  317. *status_return = status;
  318. return result;
  319. }
  320. /* Read AMOUNT bytes from PTR and store them in VAL.
  321. Checks to make sure that the read will not reach or pass END.
  322. FUNC chooses whether the value read is unsigned or signed, and may
  323. be either byte_get or byte_get_signed. If INC is true, PTR is
  324. incremented after reading the value.
  325. This macro cannot protect against PTR values derived from user input.
  326. The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
  327. pointers is undefined behaviour. */
  328. #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
  329. do \
  330. { \
  331. size_t amount = (AMOUNT); \
  332. if (sizeof (VAL) < amount) \
  333. { \
  334. error (ngettext ("internal error: attempt to read %d byte " \
  335. "of data in to %d sized variable", \
  336. "internal error: attempt to read %d bytes " \
  337. "of data in to %d sized variable", \
  338. amount), \
  339. (int) amount, (int) sizeof (VAL)); \
  340. amount = sizeof (VAL); \
  341. } \
  342. if (ENABLE_CHECKING) \
  343. assert ((PTR) <= (END)); \
  344. size_t avail = (END) - (PTR); \
  345. if ((PTR) > (END)) \
  346. avail = 0; \
  347. if (amount > avail) \
  348. amount = avail; \
  349. if (amount == 0) \
  350. (VAL) = 0; \
  351. else \
  352. (VAL) = (FUNC) ((PTR), amount); \
  353. if (INC) \
  354. (PTR) += amount; \
  355. } \
  356. while (0)
  357. #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
  358. SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
  359. #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
  360. SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
  361. #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
  362. SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
  363. #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
  364. SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
  365. typedef struct State_Machine_Registers
  366. {
  367. dwarf_vma address;
  368. unsigned int view;
  369. unsigned int file;
  370. unsigned int line;
  371. unsigned int column;
  372. int is_stmt;
  373. int basic_block;
  374. unsigned char op_index;
  375. unsigned char end_sequence;
  376. /* This variable hold the number of the last entry seen
  377. in the File Table. */
  378. unsigned int last_file_entry;
  379. } SMR;
  380. static SMR state_machine_regs;
  381. static void
  382. reset_state_machine (int is_stmt)
  383. {
  384. state_machine_regs.address = 0;
  385. state_machine_regs.view = 0;
  386. state_machine_regs.op_index = 0;
  387. state_machine_regs.file = 1;
  388. state_machine_regs.line = 1;
  389. state_machine_regs.column = 0;
  390. state_machine_regs.is_stmt = is_stmt;
  391. state_machine_regs.basic_block = 0;
  392. state_machine_regs.end_sequence = 0;
  393. state_machine_regs.last_file_entry = 0;
  394. }
  395. /* Handled an extend line op.
  396. Returns the number of bytes read. */
  397. static size_t
  398. process_extended_line_op (unsigned char * data,
  399. int is_stmt,
  400. unsigned char * end)
  401. {
  402. unsigned char op_code;
  403. size_t len, header_len;
  404. unsigned char *name;
  405. unsigned char *orig_data = data;
  406. dwarf_vma adr, val;
  407. READ_ULEB (len, data, end);
  408. header_len = data - orig_data;
  409. if (len == 0 || data >= end || len > (size_t) (end - data))
  410. {
  411. warn (_("Badly formed extended line op encountered!\n"));
  412. return header_len;
  413. }
  414. op_code = *data++;
  415. printf (_(" Extended opcode %d: "), op_code);
  416. switch (op_code)
  417. {
  418. case DW_LNE_end_sequence:
  419. printf (_("End of Sequence\n\n"));
  420. reset_state_machine (is_stmt);
  421. break;
  422. case DW_LNE_set_address:
  423. /* PR 17512: file: 002-100480-0.004. */
  424. if (len - 1 > 8)
  425. {
  426. warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
  427. (unsigned long) len - 1);
  428. adr = 0;
  429. }
  430. else
  431. SAFE_BYTE_GET (adr, data, len - 1, end);
  432. printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
  433. state_machine_regs.address = adr;
  434. state_machine_regs.view = 0;
  435. state_machine_regs.op_index = 0;
  436. break;
  437. case DW_LNE_define_file:
  438. printf (_("define new File Table entry\n"));
  439. printf (_(" Entry\tDir\tTime\tSize\tName\n"));
  440. printf (" %d\t", ++state_machine_regs.last_file_entry);
  441. {
  442. size_t l;
  443. name = data;
  444. l = strnlen ((char *) data, end - data);
  445. data += l;
  446. if (data < end)
  447. data++;
  448. READ_ULEB (val, data, end);
  449. printf ("%s\t", dwarf_vmatoa ("u", val));
  450. READ_ULEB (val, data, end);
  451. printf ("%s\t", dwarf_vmatoa ("u", val));
  452. READ_ULEB (val, data, end);
  453. printf ("%s\t", dwarf_vmatoa ("u", val));
  454. printf ("%.*s\n\n", (int) l, name);
  455. }
  456. if (((size_t) (data - orig_data) != len + header_len) || data >= end)
  457. warn (_("DW_LNE_define_file: Bad opcode length\n"));
  458. break;
  459. case DW_LNE_set_discriminator:
  460. READ_ULEB (val, data, end);
  461. printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val));
  462. break;
  463. /* HP extensions. */
  464. case DW_LNE_HP_negate_is_UV_update:
  465. printf ("DW_LNE_HP_negate_is_UV_update\n");
  466. break;
  467. case DW_LNE_HP_push_context:
  468. printf ("DW_LNE_HP_push_context\n");
  469. break;
  470. case DW_LNE_HP_pop_context:
  471. printf ("DW_LNE_HP_pop_context\n");
  472. break;
  473. case DW_LNE_HP_set_file_line_column:
  474. printf ("DW_LNE_HP_set_file_line_column\n");
  475. break;
  476. case DW_LNE_HP_set_routine_name:
  477. printf ("DW_LNE_HP_set_routine_name\n");
  478. break;
  479. case DW_LNE_HP_set_sequence:
  480. printf ("DW_LNE_HP_set_sequence\n");
  481. break;
  482. case DW_LNE_HP_negate_post_semantics:
  483. printf ("DW_LNE_HP_negate_post_semantics\n");
  484. break;
  485. case DW_LNE_HP_negate_function_exit:
  486. printf ("DW_LNE_HP_negate_function_exit\n");
  487. break;
  488. case DW_LNE_HP_negate_front_end_logical:
  489. printf ("DW_LNE_HP_negate_front_end_logical\n");
  490. break;
  491. case DW_LNE_HP_define_proc:
  492. printf ("DW_LNE_HP_define_proc\n");
  493. break;
  494. case DW_LNE_HP_source_file_correlation:
  495. {
  496. unsigned char *edata = data + len - 1;
  497. printf ("DW_LNE_HP_source_file_correlation\n");
  498. while (data < edata)
  499. {
  500. unsigned int opc;
  501. READ_ULEB (opc, data, edata);
  502. switch (opc)
  503. {
  504. case DW_LNE_HP_SFC_formfeed:
  505. printf (" DW_LNE_HP_SFC_formfeed\n");
  506. break;
  507. case DW_LNE_HP_SFC_set_listing_line:
  508. READ_ULEB (val, data, edata);
  509. printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
  510. dwarf_vmatoa ("u", val));
  511. break;
  512. case DW_LNE_HP_SFC_associate:
  513. printf (" DW_LNE_HP_SFC_associate ");
  514. READ_ULEB (val, data, edata);
  515. printf ("(%s", dwarf_vmatoa ("u", val));
  516. READ_ULEB (val, data, edata);
  517. printf (",%s", dwarf_vmatoa ("u", val));
  518. READ_ULEB (val, data, edata);
  519. printf (",%s)\n", dwarf_vmatoa ("u", val));
  520. break;
  521. default:
  522. printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
  523. data = edata;
  524. break;
  525. }
  526. }
  527. }
  528. break;
  529. default:
  530. {
  531. unsigned int rlen = len - 1;
  532. if (op_code >= DW_LNE_lo_user
  533. /* The test against DW_LNW_hi_user is redundant due to
  534. the limited range of the unsigned char data type used
  535. for op_code. */
  536. /*&& op_code <= DW_LNE_hi_user*/)
  537. printf (_("user defined: "));
  538. else
  539. printf (_("UNKNOWN: "));
  540. printf (_("length %d ["), rlen);
  541. for (; rlen; rlen--)
  542. printf (" %02x", *data++);
  543. printf ("]\n");
  544. }
  545. break;
  546. }
  547. return len + header_len;
  548. }
  549. static const unsigned char *
  550. fetch_indirect_string (dwarf_vma offset)
  551. {
  552. struct dwarf_section *section = &debug_displays [str].section;
  553. const unsigned char * ret;
  554. if (section->start == NULL)
  555. return (const unsigned char *) _("<no .debug_str section>");
  556. if (offset >= section->size)
  557. {
  558. warn (_("DW_FORM_strp offset too big: 0x%s\n"),
  559. dwarf_vmatoa ("x", offset));
  560. return (const unsigned char *) _("<offset is too big>");
  561. }
  562. ret = section->start + offset;
  563. /* Unfortunately we cannot rely upon the .debug_str section ending with a
  564. NUL byte. Since our caller is expecting to receive a well formed C
  565. string we test for the lack of a terminating byte here. */
  566. if (strnlen ((const char *) ret, section->size - offset)
  567. == section->size - offset)
  568. ret = (const unsigned char *)
  569. _("<no NUL byte at end of .debug_str section>");
  570. return ret;
  571. }
  572. static const unsigned char *
  573. fetch_indirect_line_string (dwarf_vma offset)
  574. {
  575. struct dwarf_section *section = &debug_displays [line_str].section;
  576. const unsigned char * ret;
  577. if (section->start == NULL)
  578. return (const unsigned char *) _("<no .debug_line_str section>");
  579. if (offset >= section->size)
  580. {
  581. warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
  582. dwarf_vmatoa ("x", offset));
  583. return (const unsigned char *) _("<offset is too big>");
  584. }
  585. ret = section->start + offset;
  586. /* Unfortunately we cannot rely upon the .debug_line_str section ending
  587. with a NUL byte. Since our caller is expecting to receive a well formed
  588. C string we test for the lack of a terminating byte here. */
  589. if (strnlen ((const char *) ret, section->size - offset)
  590. == section->size - offset)
  591. ret = (const unsigned char *)
  592. _("<no NUL byte at end of .debug_line_str section>");
  593. return ret;
  594. }
  595. static const char *
  596. fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
  597. dwarf_vma offset_size, bool dwo)
  598. {
  599. enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
  600. enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
  601. struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
  602. struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
  603. dwarf_vma index_offset;
  604. dwarf_vma str_offset;
  605. const char * ret;
  606. unsigned char *curr = index_section->start;
  607. unsigned char *end = curr + index_section->size;
  608. dwarf_vma length;
  609. if (index_section->start == NULL)
  610. return (dwo ? _("<no .debug_str_offsets.dwo section>")
  611. : _("<no .debug_str_offsets section>"));
  612. if (str_section->start == NULL)
  613. return (dwo ? _("<no .debug_str.dwo section>")
  614. : _("<no .debug_str section>"));
  615. /* FIXME: We should cache the length... */
  616. SAFE_BYTE_GET_AND_INC (length, curr, 4, end);
  617. if (length == 0xffffffff)
  618. {
  619. if (offset_size != 8)
  620. warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size));
  621. SAFE_BYTE_GET_AND_INC (length, curr, 8, end);
  622. }
  623. else if (offset_size != 4)
  624. {
  625. warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size));
  626. }
  627. if (length == 0)
  628. {
  629. /* This is probably an old style .debug_str_offset section which
  630. just contains offsets and no header (and the first offset is 0). */
  631. curr = index_section->start;
  632. length = index_section->size;
  633. }
  634. else
  635. {
  636. /* Skip the version and padding bytes.
  637. We assume that they are correct. */
  638. if (end - curr >= 4)
  639. curr += 4;
  640. else
  641. curr = end;
  642. if (length >= 4)
  643. length -= 4;
  644. else
  645. length = 0;
  646. if (this_set != NULL
  647. && this_set->section_sizes[DW_SECT_STR_OFFSETS] < length)
  648. length = this_set->section_sizes[DW_SECT_STR_OFFSETS];
  649. if (length > (dwarf_vma) (end - curr))
  650. {
  651. warn (_("index table size too large for section %s vs %s\n"),
  652. dwarf_vmatoa ("x", length),
  653. dwarf_vmatoa ("x", index_section->size));
  654. length = end - curr;
  655. }
  656. if (length < offset_size)
  657. {
  658. warn (_("index table size %s is too small\n"),
  659. dwarf_vmatoa ("x", length));
  660. return _("<table too small>");
  661. }
  662. }
  663. index_offset = idx * offset_size;
  664. if (this_set != NULL)
  665. index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
  666. if (index_offset >= length
  667. || length - index_offset < offset_size)
  668. {
  669. warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
  670. dwarf_vmatoa ("x", index_offset),
  671. dwarf_vmatoa ("x", length));
  672. return _("<index offset is too big>");
  673. }
  674. str_offset = byte_get (curr + index_offset, offset_size);
  675. str_offset -= str_section->address;
  676. if (str_offset >= str_section->size)
  677. {
  678. warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
  679. dwarf_vmatoa ("x", str_offset));
  680. return _("<indirect index offset is too big>");
  681. }
  682. ret = (const char *) str_section->start + str_offset;
  683. /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
  684. Since our caller is expecting to receive a well formed C string we test
  685. for the lack of a terminating byte here. */
  686. if (strnlen (ret, str_section->size - str_offset)
  687. == str_section->size - str_offset)
  688. ret = (const char *) _("<no NUL byte at end of section>");
  689. return ret;
  690. }
  691. static dwarf_vma
  692. fetch_indexed_addr (dwarf_vma offset, uint32_t num_bytes)
  693. {
  694. struct dwarf_section *section = &debug_displays [debug_addr].section;
  695. if (section->start == NULL)
  696. {
  697. warn (_("<no .debug_addr section>"));
  698. return 0;
  699. }
  700. if (offset + num_bytes > section->size)
  701. {
  702. warn (_("Offset into section %s too big: 0x%s\n"),
  703. section->name, dwarf_vmatoa ("x", offset));
  704. return 0;
  705. }
  706. return byte_get (section->start + offset, num_bytes);
  707. }
  708. /* Fetch a value from a debug section that has been indexed by
  709. something in another section (eg DW_FORM_loclistx).
  710. Returns 0 if the value could not be found. */
  711. static dwarf_vma
  712. fetch_indexed_value (dwarf_vma index,
  713. enum dwarf_section_display_enum sec_enum)
  714. {
  715. struct dwarf_section *section = &debug_displays [sec_enum].section;
  716. if (section->start == NULL)
  717. {
  718. warn (_("Unable to locate %s section\n"), section->uncompressed_name);
  719. return 0;
  720. }
  721. uint32_t pointer_size, bias;
  722. if (byte_get (section->start, 4) == 0xffffffff)
  723. {
  724. pointer_size = 8;
  725. bias = 20;
  726. }
  727. else
  728. {
  729. pointer_size = 4;
  730. bias = 12;
  731. }
  732. dwarf_vma offset = index * pointer_size;
  733. /* Offsets are biased by the size of the section header. */
  734. offset += bias;
  735. if (offset + pointer_size > section->size)
  736. {
  737. warn (_("Offset into section %s too big: 0x%s\n"),
  738. section->name, dwarf_vmatoa ("x", offset));
  739. return 0;
  740. }
  741. return byte_get (section->start + offset, pointer_size);
  742. }
  743. /* FIXME: There are better and more efficient ways to handle
  744. these structures. For now though, I just want something that
  745. is simple to implement. */
  746. /* Records a single attribute in an abbrev. */
  747. typedef struct abbrev_attr
  748. {
  749. unsigned long attribute;
  750. unsigned long form;
  751. dwarf_signed_vma implicit_const;
  752. struct abbrev_attr * next;
  753. }
  754. abbrev_attr;
  755. /* Records a single abbrev. */
  756. typedef struct abbrev_entry
  757. {
  758. unsigned long number;
  759. unsigned long tag;
  760. int children;
  761. struct abbrev_attr * first_attr;
  762. struct abbrev_attr * last_attr;
  763. struct abbrev_entry * next;
  764. }
  765. abbrev_entry;
  766. /* Records a set of abbreviations. */
  767. typedef struct abbrev_list
  768. {
  769. abbrev_entry * first_abbrev;
  770. abbrev_entry * last_abbrev;
  771. dwarf_vma abbrev_base;
  772. dwarf_vma abbrev_offset;
  773. struct abbrev_list * next;
  774. unsigned char * start_of_next_abbrevs;
  775. }
  776. abbrev_list;
  777. /* Records all the abbrevs found so far. */
  778. static struct abbrev_list * abbrev_lists = NULL;
  779. typedef struct abbrev_map
  780. {
  781. dwarf_vma start;
  782. dwarf_vma end;
  783. abbrev_list * list;
  784. } abbrev_map;
  785. /* Maps between CU offsets and abbrev sets. */
  786. static abbrev_map * cu_abbrev_map = NULL;
  787. static unsigned long num_abbrev_map_entries = 0;
  788. static unsigned long next_free_abbrev_map_entry = 0;
  789. #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
  790. #define ABBREV_MAP_ENTRIES_INCREMENT 8
  791. static void
  792. record_abbrev_list_for_cu (dwarf_vma start, dwarf_vma end, abbrev_list * list)
  793. {
  794. if (cu_abbrev_map == NULL)
  795. {
  796. num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES;
  797. cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map));
  798. }
  799. else if (next_free_abbrev_map_entry == num_abbrev_map_entries)
  800. {
  801. num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT;
  802. cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map));
  803. }
  804. cu_abbrev_map[next_free_abbrev_map_entry].start = start;
  805. cu_abbrev_map[next_free_abbrev_map_entry].end = end;
  806. cu_abbrev_map[next_free_abbrev_map_entry].list = list;
  807. next_free_abbrev_map_entry ++;
  808. }
  809. static void
  810. free_all_abbrevs (void)
  811. {
  812. abbrev_list * list;
  813. for (list = abbrev_lists; list != NULL;)
  814. {
  815. abbrev_list * next = list->next;
  816. abbrev_entry * abbrv;
  817. for (abbrv = list->first_abbrev; abbrv != NULL;)
  818. {
  819. abbrev_entry * next_abbrev = abbrv->next;
  820. abbrev_attr * attr;
  821. for (attr = abbrv->first_attr; attr;)
  822. {
  823. abbrev_attr *next_attr = attr->next;
  824. free (attr);
  825. attr = next_attr;
  826. }
  827. free (abbrv);
  828. abbrv = next_abbrev;
  829. }
  830. free (list);
  831. list = next;
  832. }
  833. abbrev_lists = NULL;
  834. }
  835. static abbrev_list *
  836. new_abbrev_list (dwarf_vma abbrev_base, dwarf_vma abbrev_offset)
  837. {
  838. abbrev_list * list = (abbrev_list *) xcalloc (sizeof * list, 1);
  839. list->abbrev_base = abbrev_base;
  840. list->abbrev_offset = abbrev_offset;
  841. list->next = abbrev_lists;
  842. abbrev_lists = list;
  843. return list;
  844. }
  845. static abbrev_list *
  846. find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base,
  847. dwarf_vma abbrev_offset)
  848. {
  849. abbrev_list * list;
  850. for (list = abbrev_lists; list != NULL; list = list->next)
  851. if (list->abbrev_base == abbrev_base
  852. && list->abbrev_offset == abbrev_offset)
  853. return list;
  854. return NULL;
  855. }
  856. /* Find the abbreviation map for the CU that includes OFFSET.
  857. OFFSET is an absolute offset from the start of the .debug_info section. */
  858. /* FIXME: This function is going to slow down readelf & objdump.
  859. Consider using a better algorithm to mitigate this effect. */
  860. static abbrev_map *
  861. find_abbrev_map_by_offset (dwarf_vma offset)
  862. {
  863. unsigned long i;
  864. for (i = 0; i < next_free_abbrev_map_entry; i++)
  865. if (cu_abbrev_map[i].start <= offset
  866. && cu_abbrev_map[i].end > offset)
  867. return cu_abbrev_map + i;
  868. return NULL;
  869. }
  870. static void
  871. add_abbrev (unsigned long number,
  872. unsigned long tag,
  873. int children,
  874. abbrev_list * list)
  875. {
  876. abbrev_entry * entry;
  877. entry = (abbrev_entry *) xmalloc (sizeof (*entry));
  878. entry->number = number;
  879. entry->tag = tag;
  880. entry->children = children;
  881. entry->first_attr = NULL;
  882. entry->last_attr = NULL;
  883. entry->next = NULL;
  884. assert (list != NULL);
  885. if (list->first_abbrev == NULL)
  886. list->first_abbrev = entry;
  887. else
  888. list->last_abbrev->next = entry;
  889. list->last_abbrev = entry;
  890. }
  891. static void
  892. add_abbrev_attr (unsigned long attribute,
  893. unsigned long form,
  894. dwarf_signed_vma implicit_const,
  895. abbrev_list * list)
  896. {
  897. abbrev_attr *attr;
  898. attr = (abbrev_attr *) xmalloc (sizeof (*attr));
  899. attr->attribute = attribute;
  900. attr->form = form;
  901. attr->implicit_const = implicit_const;
  902. attr->next = NULL;
  903. assert (list != NULL && list->last_abbrev != NULL);
  904. if (list->last_abbrev->first_attr == NULL)
  905. list->last_abbrev->first_attr = attr;
  906. else
  907. list->last_abbrev->last_attr->next = attr;
  908. list->last_abbrev->last_attr = attr;
  909. }
  910. /* Processes the (partial) contents of a .debug_abbrev section.
  911. Returns NULL if the end of the section was encountered.
  912. Returns the address after the last byte read if the end of
  913. an abbreviation set was found. */
  914. static unsigned char *
  915. process_abbrev_set (struct dwarf_section *section,
  916. dwarf_vma abbrev_base,
  917. dwarf_vma abbrev_size,
  918. dwarf_vma abbrev_offset,
  919. abbrev_list *list)
  920. {
  921. if (abbrev_base >= section->size
  922. || abbrev_size > section->size - abbrev_base)
  923. {
  924. /* PR 17531: file:4bcd9ce9. */
  925. warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
  926. "abbrev section size (%lx)\n"),
  927. (unsigned long) (abbrev_base + abbrev_size),
  928. (unsigned long) section->size);
  929. return NULL;
  930. }
  931. if (abbrev_offset >= abbrev_size)
  932. {
  933. warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
  934. "abbrev section size (%lx)\n"),
  935. (unsigned long) abbrev_offset,
  936. (unsigned long) abbrev_size);
  937. return NULL;
  938. }
  939. unsigned char *start = section->start + abbrev_base;
  940. unsigned char *end = start + abbrev_size;
  941. start += abbrev_offset;
  942. while (start < end)
  943. {
  944. unsigned long entry;
  945. unsigned long tag;
  946. unsigned long attribute;
  947. int children;
  948. READ_ULEB (entry, start, end);
  949. /* A single zero is supposed to end the set according
  950. to the standard. If there's more, then signal that to
  951. the caller. */
  952. if (start == end)
  953. return NULL;
  954. if (entry == 0)
  955. return start;
  956. READ_ULEB (tag, start, end);
  957. if (start == end)
  958. return NULL;
  959. children = *start++;
  960. add_abbrev (entry, tag, children, list);
  961. do
  962. {
  963. unsigned long form;
  964. /* Initialize it due to a false compiler warning. */
  965. dwarf_signed_vma implicit_const = -1;
  966. READ_ULEB (attribute, start, end);
  967. if (start == end)
  968. break;
  969. READ_ULEB (form, start, end);
  970. if (start == end)
  971. break;
  972. if (form == DW_FORM_implicit_const)
  973. {
  974. READ_SLEB (implicit_const, start, end);
  975. if (start == end)
  976. break;
  977. }
  978. add_abbrev_attr (attribute, form, implicit_const, list);
  979. }
  980. while (attribute != 0);
  981. }
  982. /* Report the missing single zero which ends the section. */
  983. error (_(".debug_abbrev section not zero terminated\n"));
  984. return NULL;
  985. }
  986. static const char *
  987. get_TAG_name (unsigned long tag)
  988. {
  989. const char *name = get_DW_TAG_name ((unsigned int) tag);
  990. if (name == NULL)
  991. {
  992. static char buffer[100];
  993. if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user)
  994. snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag);
  995. else
  996. snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %#lx"), tag);
  997. return buffer;
  998. }
  999. return name;
  1000. }
  1001. static const char *
  1002. get_FORM_name (unsigned long form)
  1003. {
  1004. const char *name;
  1005. if (form == 0)
  1006. return "DW_FORM value: 0";
  1007. name = get_DW_FORM_name (form);
  1008. if (name == NULL)
  1009. {
  1010. static char buffer[100];
  1011. snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
  1012. return buffer;
  1013. }
  1014. return name;
  1015. }
  1016. static const char *
  1017. get_IDX_name (unsigned long idx)
  1018. {
  1019. const char *name = get_DW_IDX_name ((unsigned int) idx);
  1020. if (name == NULL)
  1021. {
  1022. static char buffer[100];
  1023. snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx);
  1024. return buffer;
  1025. }
  1026. return name;
  1027. }
  1028. static unsigned char *
  1029. display_block (unsigned char *data,
  1030. dwarf_vma length,
  1031. const unsigned char * const end, char delimiter)
  1032. {
  1033. dwarf_vma maxlen;
  1034. printf (_("%c%s byte block: "), delimiter, dwarf_vmatoa ("u", length));
  1035. if (data > end)
  1036. return (unsigned char *) end;
  1037. maxlen = (dwarf_vma) (end - data);
  1038. length = length > maxlen ? maxlen : length;
  1039. while (length --)
  1040. printf ("%lx ", (unsigned long) byte_get (data++, 1));
  1041. return data;
  1042. }
  1043. static int
  1044. decode_location_expression (unsigned char * data,
  1045. unsigned int pointer_size,
  1046. unsigned int offset_size,
  1047. int dwarf_version,
  1048. dwarf_vma length,
  1049. dwarf_vma cu_offset,
  1050. struct dwarf_section * section)
  1051. {
  1052. unsigned op;
  1053. dwarf_vma uvalue;
  1054. dwarf_signed_vma svalue;
  1055. unsigned char *end = data + length;
  1056. int need_frame_base = 0;
  1057. while (data < end)
  1058. {
  1059. op = *data++;
  1060. switch (op)
  1061. {
  1062. case DW_OP_addr:
  1063. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1064. printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue));
  1065. break;
  1066. case DW_OP_deref:
  1067. printf ("DW_OP_deref");
  1068. break;
  1069. case DW_OP_const1u:
  1070. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1071. printf ("DW_OP_const1u: %lu", (unsigned long) uvalue);
  1072. break;
  1073. case DW_OP_const1s:
  1074. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end);
  1075. printf ("DW_OP_const1s: %ld", (long) svalue);
  1076. break;
  1077. case DW_OP_const2u:
  1078. SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
  1079. printf ("DW_OP_const2u: %lu", (unsigned long) uvalue);
  1080. break;
  1081. case DW_OP_const2s:
  1082. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
  1083. printf ("DW_OP_const2s: %ld", (long) svalue);
  1084. break;
  1085. case DW_OP_const4u:
  1086. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  1087. printf ("DW_OP_const4u: %lu", (unsigned long) uvalue);
  1088. break;
  1089. case DW_OP_const4s:
  1090. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
  1091. printf ("DW_OP_const4s: %ld", (long) svalue);
  1092. break;
  1093. case DW_OP_const8u:
  1094. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  1095. printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue);
  1096. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  1097. printf ("%lu", (unsigned long) uvalue);
  1098. break;
  1099. case DW_OP_const8s:
  1100. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
  1101. printf ("DW_OP_const8s: %ld ", (long) svalue);
  1102. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
  1103. printf ("%ld", (long) svalue);
  1104. break;
  1105. case DW_OP_constu:
  1106. READ_ULEB (uvalue, data, end);
  1107. printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue));
  1108. break;
  1109. case DW_OP_consts:
  1110. READ_SLEB (svalue, data, end);
  1111. printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue));
  1112. break;
  1113. case DW_OP_dup:
  1114. printf ("DW_OP_dup");
  1115. break;
  1116. case DW_OP_drop:
  1117. printf ("DW_OP_drop");
  1118. break;
  1119. case DW_OP_over:
  1120. printf ("DW_OP_over");
  1121. break;
  1122. case DW_OP_pick:
  1123. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1124. printf ("DW_OP_pick: %ld", (unsigned long) uvalue);
  1125. break;
  1126. case DW_OP_swap:
  1127. printf ("DW_OP_swap");
  1128. break;
  1129. case DW_OP_rot:
  1130. printf ("DW_OP_rot");
  1131. break;
  1132. case DW_OP_xderef:
  1133. printf ("DW_OP_xderef");
  1134. break;
  1135. case DW_OP_abs:
  1136. printf ("DW_OP_abs");
  1137. break;
  1138. case DW_OP_and:
  1139. printf ("DW_OP_and");
  1140. break;
  1141. case DW_OP_div:
  1142. printf ("DW_OP_div");
  1143. break;
  1144. case DW_OP_minus:
  1145. printf ("DW_OP_minus");
  1146. break;
  1147. case DW_OP_mod:
  1148. printf ("DW_OP_mod");
  1149. break;
  1150. case DW_OP_mul:
  1151. printf ("DW_OP_mul");
  1152. break;
  1153. case DW_OP_neg:
  1154. printf ("DW_OP_neg");
  1155. break;
  1156. case DW_OP_not:
  1157. printf ("DW_OP_not");
  1158. break;
  1159. case DW_OP_or:
  1160. printf ("DW_OP_or");
  1161. break;
  1162. case DW_OP_plus:
  1163. printf ("DW_OP_plus");
  1164. break;
  1165. case DW_OP_plus_uconst:
  1166. READ_ULEB (uvalue, data, end);
  1167. printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue));
  1168. break;
  1169. case DW_OP_shl:
  1170. printf ("DW_OP_shl");
  1171. break;
  1172. case DW_OP_shr:
  1173. printf ("DW_OP_shr");
  1174. break;
  1175. case DW_OP_shra:
  1176. printf ("DW_OP_shra");
  1177. break;
  1178. case DW_OP_xor:
  1179. printf ("DW_OP_xor");
  1180. break;
  1181. case DW_OP_bra:
  1182. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
  1183. printf ("DW_OP_bra: %ld", (long) svalue);
  1184. break;
  1185. case DW_OP_eq:
  1186. printf ("DW_OP_eq");
  1187. break;
  1188. case DW_OP_ge:
  1189. printf ("DW_OP_ge");
  1190. break;
  1191. case DW_OP_gt:
  1192. printf ("DW_OP_gt");
  1193. break;
  1194. case DW_OP_le:
  1195. printf ("DW_OP_le");
  1196. break;
  1197. case DW_OP_lt:
  1198. printf ("DW_OP_lt");
  1199. break;
  1200. case DW_OP_ne:
  1201. printf ("DW_OP_ne");
  1202. break;
  1203. case DW_OP_skip:
  1204. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
  1205. printf ("DW_OP_skip: %ld", (long) svalue);
  1206. break;
  1207. case DW_OP_lit0:
  1208. case DW_OP_lit1:
  1209. case DW_OP_lit2:
  1210. case DW_OP_lit3:
  1211. case DW_OP_lit4:
  1212. case DW_OP_lit5:
  1213. case DW_OP_lit6:
  1214. case DW_OP_lit7:
  1215. case DW_OP_lit8:
  1216. case DW_OP_lit9:
  1217. case DW_OP_lit10:
  1218. case DW_OP_lit11:
  1219. case DW_OP_lit12:
  1220. case DW_OP_lit13:
  1221. case DW_OP_lit14:
  1222. case DW_OP_lit15:
  1223. case DW_OP_lit16:
  1224. case DW_OP_lit17:
  1225. case DW_OP_lit18:
  1226. case DW_OP_lit19:
  1227. case DW_OP_lit20:
  1228. case DW_OP_lit21:
  1229. case DW_OP_lit22:
  1230. case DW_OP_lit23:
  1231. case DW_OP_lit24:
  1232. case DW_OP_lit25:
  1233. case DW_OP_lit26:
  1234. case DW_OP_lit27:
  1235. case DW_OP_lit28:
  1236. case DW_OP_lit29:
  1237. case DW_OP_lit30:
  1238. case DW_OP_lit31:
  1239. printf ("DW_OP_lit%d", op - DW_OP_lit0);
  1240. break;
  1241. case DW_OP_reg0:
  1242. case DW_OP_reg1:
  1243. case DW_OP_reg2:
  1244. case DW_OP_reg3:
  1245. case DW_OP_reg4:
  1246. case DW_OP_reg5:
  1247. case DW_OP_reg6:
  1248. case DW_OP_reg7:
  1249. case DW_OP_reg8:
  1250. case DW_OP_reg9:
  1251. case DW_OP_reg10:
  1252. case DW_OP_reg11:
  1253. case DW_OP_reg12:
  1254. case DW_OP_reg13:
  1255. case DW_OP_reg14:
  1256. case DW_OP_reg15:
  1257. case DW_OP_reg16:
  1258. case DW_OP_reg17:
  1259. case DW_OP_reg18:
  1260. case DW_OP_reg19:
  1261. case DW_OP_reg20:
  1262. case DW_OP_reg21:
  1263. case DW_OP_reg22:
  1264. case DW_OP_reg23:
  1265. case DW_OP_reg24:
  1266. case DW_OP_reg25:
  1267. case DW_OP_reg26:
  1268. case DW_OP_reg27:
  1269. case DW_OP_reg28:
  1270. case DW_OP_reg29:
  1271. case DW_OP_reg30:
  1272. case DW_OP_reg31:
  1273. printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
  1274. regname (op - DW_OP_reg0, 1));
  1275. break;
  1276. case DW_OP_breg0:
  1277. case DW_OP_breg1:
  1278. case DW_OP_breg2:
  1279. case DW_OP_breg3:
  1280. case DW_OP_breg4:
  1281. case DW_OP_breg5:
  1282. case DW_OP_breg6:
  1283. case DW_OP_breg7:
  1284. case DW_OP_breg8:
  1285. case DW_OP_breg9:
  1286. case DW_OP_breg10:
  1287. case DW_OP_breg11:
  1288. case DW_OP_breg12:
  1289. case DW_OP_breg13:
  1290. case DW_OP_breg14:
  1291. case DW_OP_breg15:
  1292. case DW_OP_breg16:
  1293. case DW_OP_breg17:
  1294. case DW_OP_breg18:
  1295. case DW_OP_breg19:
  1296. case DW_OP_breg20:
  1297. case DW_OP_breg21:
  1298. case DW_OP_breg22:
  1299. case DW_OP_breg23:
  1300. case DW_OP_breg24:
  1301. case DW_OP_breg25:
  1302. case DW_OP_breg26:
  1303. case DW_OP_breg27:
  1304. case DW_OP_breg28:
  1305. case DW_OP_breg29:
  1306. case DW_OP_breg30:
  1307. case DW_OP_breg31:
  1308. READ_SLEB (svalue, data, end);
  1309. printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0,
  1310. regname (op - DW_OP_breg0, 1), dwarf_vmatoa ("d", svalue));
  1311. break;
  1312. case DW_OP_regx:
  1313. READ_ULEB (uvalue, data, end);
  1314. printf ("DW_OP_regx: %s (%s)",
  1315. dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
  1316. break;
  1317. case DW_OP_fbreg:
  1318. need_frame_base = 1;
  1319. READ_SLEB (svalue, data, end);
  1320. printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue));
  1321. break;
  1322. case DW_OP_bregx:
  1323. READ_ULEB (uvalue, data, end);
  1324. READ_SLEB (svalue, data, end);
  1325. printf ("DW_OP_bregx: %s (%s) %s",
  1326. dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
  1327. dwarf_vmatoa ("d", svalue));
  1328. break;
  1329. case DW_OP_piece:
  1330. READ_ULEB (uvalue, data, end);
  1331. printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue));
  1332. break;
  1333. case DW_OP_deref_size:
  1334. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1335. printf ("DW_OP_deref_size: %ld", (long) uvalue);
  1336. break;
  1337. case DW_OP_xderef_size:
  1338. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1339. printf ("DW_OP_xderef_size: %ld", (long) uvalue);
  1340. break;
  1341. case DW_OP_nop:
  1342. printf ("DW_OP_nop");
  1343. break;
  1344. /* DWARF 3 extensions. */
  1345. case DW_OP_push_object_address:
  1346. printf ("DW_OP_push_object_address");
  1347. break;
  1348. case DW_OP_call2:
  1349. /* FIXME: Strictly speaking for 64-bit DWARF3 files
  1350. this ought to be an 8-byte wide computation. */
  1351. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end);
  1352. printf ("DW_OP_call2: <0x%s>",
  1353. dwarf_vmatoa ("x", svalue + cu_offset));
  1354. break;
  1355. case DW_OP_call4:
  1356. /* FIXME: Strictly speaking for 64-bit DWARF3 files
  1357. this ought to be an 8-byte wide computation. */
  1358. SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end);
  1359. printf ("DW_OP_call4: <0x%s>",
  1360. dwarf_vmatoa ("x", svalue + cu_offset));
  1361. break;
  1362. case DW_OP_call_ref:
  1363. /* FIXME: Strictly speaking for 64-bit DWARF3 files
  1364. this ought to be an 8-byte wide computation. */
  1365. if (dwarf_version == -1)
  1366. {
  1367. printf (_("(DW_OP_call_ref in frame info)"));
  1368. /* No way to tell where the next op is, so just bail. */
  1369. return need_frame_base;
  1370. }
  1371. if (dwarf_version == 2)
  1372. {
  1373. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1374. }
  1375. else
  1376. {
  1377. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1378. }
  1379. printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue));
  1380. break;
  1381. case DW_OP_form_tls_address:
  1382. printf ("DW_OP_form_tls_address");
  1383. break;
  1384. case DW_OP_call_frame_cfa:
  1385. printf ("DW_OP_call_frame_cfa");
  1386. break;
  1387. case DW_OP_bit_piece:
  1388. printf ("DW_OP_bit_piece: ");
  1389. READ_ULEB (uvalue, data, end);
  1390. printf (_("size: %s "), dwarf_vmatoa ("u", uvalue));
  1391. READ_ULEB (uvalue, data, end);
  1392. printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue));
  1393. break;
  1394. /* DWARF 4 extensions. */
  1395. case DW_OP_stack_value:
  1396. printf ("DW_OP_stack_value");
  1397. break;
  1398. case DW_OP_implicit_value:
  1399. printf ("DW_OP_implicit_value");
  1400. READ_ULEB (uvalue, data, end);
  1401. data = display_block (data, uvalue, end, ' ');
  1402. break;
  1403. /* GNU extensions. */
  1404. case DW_OP_GNU_push_tls_address:
  1405. printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
  1406. break;
  1407. case DW_OP_GNU_uninit:
  1408. printf ("DW_OP_GNU_uninit");
  1409. /* FIXME: Is there data associated with this OP ? */
  1410. break;
  1411. case DW_OP_GNU_encoded_addr:
  1412. {
  1413. int encoding = 0;
  1414. dwarf_vma addr;
  1415. if (data < end)
  1416. encoding = *data++;
  1417. addr = get_encoded_value (&data, encoding, section, end);
  1418. printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
  1419. print_dwarf_vma (addr, pointer_size);
  1420. }
  1421. break;
  1422. case DW_OP_implicit_pointer:
  1423. case DW_OP_GNU_implicit_pointer:
  1424. /* FIXME: Strictly speaking for 64-bit DWARF3 files
  1425. this ought to be an 8-byte wide computation. */
  1426. if (dwarf_version == -1)
  1427. {
  1428. printf (_("(%s in frame info)"),
  1429. (op == DW_OP_implicit_pointer
  1430. ? "DW_OP_implicit_pointer"
  1431. : "DW_OP_GNU_implicit_pointer"));
  1432. /* No way to tell where the next op is, so just bail. */
  1433. return need_frame_base;
  1434. }
  1435. if (dwarf_version == 2)
  1436. {
  1437. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1438. }
  1439. else
  1440. {
  1441. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1442. }
  1443. READ_SLEB (svalue, data, end);
  1444. printf ("%s: <0x%s> %s",
  1445. (op == DW_OP_implicit_pointer
  1446. ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
  1447. dwarf_vmatoa ("x", uvalue),
  1448. dwarf_vmatoa ("d", svalue));
  1449. break;
  1450. case DW_OP_entry_value:
  1451. case DW_OP_GNU_entry_value:
  1452. READ_ULEB (uvalue, data, end);
  1453. /* PR 17531: file: 0cc9cd00. */
  1454. if (uvalue > (dwarf_vma) (end - data))
  1455. uvalue = end - data;
  1456. printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value"
  1457. : "DW_OP_GNU_entry_value"));
  1458. if (decode_location_expression (data, pointer_size, offset_size,
  1459. dwarf_version, uvalue,
  1460. cu_offset, section))
  1461. need_frame_base = 1;
  1462. putchar (')');
  1463. data += uvalue;
  1464. break;
  1465. case DW_OP_const_type:
  1466. case DW_OP_GNU_const_type:
  1467. READ_ULEB (uvalue, data, end);
  1468. printf ("%s: <0x%s> ",
  1469. (op == DW_OP_const_type ? "DW_OP_const_type"
  1470. : "DW_OP_GNU_const_type"),
  1471. dwarf_vmatoa ("x", cu_offset + uvalue));
  1472. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1473. data = display_block (data, uvalue, end, ' ');
  1474. break;
  1475. case DW_OP_regval_type:
  1476. case DW_OP_GNU_regval_type:
  1477. READ_ULEB (uvalue, data, end);
  1478. printf ("%s: %s (%s)",
  1479. (op == DW_OP_regval_type ? "DW_OP_regval_type"
  1480. : "DW_OP_GNU_regval_type"),
  1481. dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
  1482. READ_ULEB (uvalue, data, end);
  1483. printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
  1484. break;
  1485. case DW_OP_deref_type:
  1486. case DW_OP_GNU_deref_type:
  1487. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1488. printf ("%s: %ld",
  1489. (op == DW_OP_deref_type ? "DW_OP_deref_type"
  1490. : "DW_OP_GNU_deref_type"),
  1491. (long) uvalue);
  1492. READ_ULEB (uvalue, data, end);
  1493. printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
  1494. break;
  1495. case DW_OP_convert:
  1496. case DW_OP_GNU_convert:
  1497. READ_ULEB (uvalue, data, end);
  1498. printf ("%s <0x%s>",
  1499. (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
  1500. dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
  1501. break;
  1502. case DW_OP_reinterpret:
  1503. case DW_OP_GNU_reinterpret:
  1504. READ_ULEB (uvalue, data, end);
  1505. printf ("%s <0x%s>",
  1506. (op == DW_OP_reinterpret ? "DW_OP_reinterpret"
  1507. : "DW_OP_GNU_reinterpret"),
  1508. dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
  1509. break;
  1510. case DW_OP_GNU_parameter_ref:
  1511. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  1512. printf ("DW_OP_GNU_parameter_ref: <0x%s>",
  1513. dwarf_vmatoa ("x", cu_offset + uvalue));
  1514. break;
  1515. case DW_OP_GNU_addr_index:
  1516. READ_ULEB (uvalue, data, end);
  1517. printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
  1518. break;
  1519. case DW_OP_GNU_const_index:
  1520. READ_ULEB (uvalue, data, end);
  1521. printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
  1522. break;
  1523. case DW_OP_GNU_variable_value:
  1524. /* FIXME: Strictly speaking for 64-bit DWARF3 files
  1525. this ought to be an 8-byte wide computation. */
  1526. if (dwarf_version == -1)
  1527. {
  1528. printf (_("(DW_OP_GNU_variable_value in frame info)"));
  1529. /* No way to tell where the next op is, so just bail. */
  1530. return need_frame_base;
  1531. }
  1532. if (dwarf_version == 2)
  1533. {
  1534. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1535. }
  1536. else
  1537. {
  1538. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1539. }
  1540. printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue));
  1541. break;
  1542. /* HP extensions. */
  1543. case DW_OP_HP_is_value:
  1544. printf ("DW_OP_HP_is_value");
  1545. /* FIXME: Is there data associated with this OP ? */
  1546. break;
  1547. case DW_OP_HP_fltconst4:
  1548. printf ("DW_OP_HP_fltconst4");
  1549. /* FIXME: Is there data associated with this OP ? */
  1550. break;
  1551. case DW_OP_HP_fltconst8:
  1552. printf ("DW_OP_HP_fltconst8");
  1553. /* FIXME: Is there data associated with this OP ? */
  1554. break;
  1555. case DW_OP_HP_mod_range:
  1556. printf ("DW_OP_HP_mod_range");
  1557. /* FIXME: Is there data associated with this OP ? */
  1558. break;
  1559. case DW_OP_HP_unmod_range:
  1560. printf ("DW_OP_HP_unmod_range");
  1561. /* FIXME: Is there data associated with this OP ? */
  1562. break;
  1563. case DW_OP_HP_tls:
  1564. printf ("DW_OP_HP_tls");
  1565. /* FIXME: Is there data associated with this OP ? */
  1566. break;
  1567. /* PGI (STMicroelectronics) extensions. */
  1568. case DW_OP_PGI_omp_thread_num:
  1569. /* Pushes the thread number for the current thread as it would be
  1570. returned by the standard OpenMP library function:
  1571. omp_get_thread_num(). The "current thread" is the thread for
  1572. which the expression is being evaluated. */
  1573. printf ("DW_OP_PGI_omp_thread_num");
  1574. break;
  1575. default:
  1576. if (op >= DW_OP_lo_user
  1577. && op <= DW_OP_hi_user)
  1578. printf (_("(User defined location op 0x%x)"), op);
  1579. else
  1580. printf (_("(Unknown location op 0x%x)"), op);
  1581. /* No way to tell where the next op is, so just bail. */
  1582. return need_frame_base;
  1583. }
  1584. /* Separate the ops. */
  1585. if (data < end)
  1586. printf ("; ");
  1587. }
  1588. return need_frame_base;
  1589. }
  1590. /* Find the CU or TU set corresponding to the given CU_OFFSET.
  1591. This is used for DWARF package files. */
  1592. static struct cu_tu_set *
  1593. find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
  1594. {
  1595. struct cu_tu_set *p;
  1596. unsigned int nsets;
  1597. unsigned int dw_sect;
  1598. if (do_types)
  1599. {
  1600. p = tu_sets;
  1601. nsets = tu_count;
  1602. dw_sect = DW_SECT_TYPES;
  1603. }
  1604. else
  1605. {
  1606. p = cu_sets;
  1607. nsets = cu_count;
  1608. dw_sect = DW_SECT_INFO;
  1609. }
  1610. while (nsets > 0)
  1611. {
  1612. if (p->section_offsets [dw_sect] == cu_offset)
  1613. return p;
  1614. p++;
  1615. nsets--;
  1616. }
  1617. return NULL;
  1618. }
  1619. static const char *
  1620. fetch_alt_indirect_string (dwarf_vma offset)
  1621. {
  1622. separate_info * i;
  1623. if (! do_follow_links)
  1624. return "";
  1625. if (first_separate_info == NULL)
  1626. return _("<no links available>");
  1627. for (i = first_separate_info; i != NULL; i = i->next)
  1628. {
  1629. struct dwarf_section * section;
  1630. const char * ret;
  1631. if (! load_debug_section (separate_debug_str, i->handle))
  1632. continue;
  1633. section = &debug_displays [separate_debug_str].section;
  1634. if (section->start == NULL)
  1635. continue;
  1636. if (offset >= section->size)
  1637. continue;
  1638. ret = (const char *) (section->start + offset);
  1639. /* Unfortunately we cannot rely upon the .debug_str section ending with a
  1640. NUL byte. Since our caller is expecting to receive a well formed C
  1641. string we test for the lack of a terminating byte here. */
  1642. if (strnlen ((const char *) ret, section->size - offset)
  1643. == section->size - offset)
  1644. return _("<no NUL byte at end of alt .debug_str section>");
  1645. return ret;
  1646. }
  1647. warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
  1648. dwarf_vmatoa ("x", offset));
  1649. return _("<offset is too big>");
  1650. }
  1651. static const char *
  1652. get_AT_name (unsigned long attribute)
  1653. {
  1654. const char *name;
  1655. if (attribute == 0)
  1656. return "DW_AT value: 0";
  1657. /* One value is shared by the MIPS and HP extensions: */
  1658. if (attribute == DW_AT_MIPS_fde)
  1659. return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
  1660. name = get_DW_AT_name (attribute);
  1661. if (name == NULL)
  1662. {
  1663. static char buffer[100];
  1664. snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
  1665. attribute);
  1666. return buffer;
  1667. }
  1668. return name;
  1669. }
  1670. static void
  1671. add_dwo_info (const char * value, dwarf_vma cu_offset, dwo_type type)
  1672. {
  1673. dwo_info * dwinfo = xmalloc (sizeof * dwinfo);
  1674. dwinfo->type = type;
  1675. dwinfo->value = value;
  1676. dwinfo->cu_offset = cu_offset;
  1677. dwinfo->next = first_dwo_info;
  1678. first_dwo_info = dwinfo;
  1679. }
  1680. static void
  1681. add_dwo_name (const char * name, dwarf_vma cu_offset)
  1682. {
  1683. add_dwo_info (name, cu_offset, DWO_NAME);
  1684. }
  1685. static void
  1686. add_dwo_dir (const char * dir, dwarf_vma cu_offset)
  1687. {
  1688. add_dwo_info (dir, cu_offset, DWO_DIR);
  1689. }
  1690. static void
  1691. add_dwo_id (const char * id, dwarf_vma cu_offset)
  1692. {
  1693. add_dwo_info (id, cu_offset, DWO_ID);
  1694. }
  1695. static void
  1696. free_dwo_info (void)
  1697. {
  1698. dwo_info * dwinfo;
  1699. dwo_info * next;
  1700. for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next)
  1701. {
  1702. next = dwinfo->next;
  1703. free (dwinfo);
  1704. }
  1705. first_dwo_info = NULL;
  1706. }
  1707. /* Ensure that START + UVALUE is less than END.
  1708. Return an adjusted UVALUE if necessary to ensure this relationship. */
  1709. static inline dwarf_vma
  1710. check_uvalue (const unsigned char * start,
  1711. dwarf_vma uvalue,
  1712. const unsigned char * end)
  1713. {
  1714. dwarf_vma max_uvalue = end - start;
  1715. /* See PR 17512: file: 008-103549-0.001:0.1.
  1716. and PR 24829 for examples of where these tests are triggered. */
  1717. if (uvalue > max_uvalue)
  1718. {
  1719. warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue);
  1720. uvalue = max_uvalue;
  1721. }
  1722. return uvalue;
  1723. }
  1724. static unsigned char *
  1725. skip_attr_bytes (unsigned long form,
  1726. unsigned char *data,
  1727. unsigned char *end,
  1728. dwarf_vma pointer_size,
  1729. dwarf_vma offset_size,
  1730. int dwarf_version,
  1731. dwarf_vma *value_return)
  1732. {
  1733. dwarf_signed_vma svalue;
  1734. dwarf_vma uvalue = 0;
  1735. dwarf_vma inc = 0;
  1736. * value_return = 0;
  1737. switch (form)
  1738. {
  1739. case DW_FORM_ref_addr:
  1740. if (dwarf_version == 2)
  1741. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1742. else if (dwarf_version > 2)
  1743. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1744. else
  1745. return NULL;
  1746. break;
  1747. case DW_FORM_addr:
  1748. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  1749. break;
  1750. case DW_FORM_strp:
  1751. case DW_FORM_line_strp:
  1752. case DW_FORM_sec_offset:
  1753. case DW_FORM_GNU_ref_alt:
  1754. case DW_FORM_GNU_strp_alt:
  1755. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  1756. break;
  1757. case DW_FORM_flag_present:
  1758. uvalue = 1;
  1759. break;
  1760. case DW_FORM_ref1:
  1761. case DW_FORM_flag:
  1762. case DW_FORM_data1:
  1763. case DW_FORM_strx1:
  1764. case DW_FORM_addrx1:
  1765. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1766. break;
  1767. case DW_FORM_strx3:
  1768. case DW_FORM_addrx3:
  1769. SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end);
  1770. break;
  1771. case DW_FORM_ref2:
  1772. case DW_FORM_data2:
  1773. case DW_FORM_strx2:
  1774. case DW_FORM_addrx2:
  1775. SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
  1776. break;
  1777. case DW_FORM_ref4:
  1778. case DW_FORM_data4:
  1779. case DW_FORM_strx4:
  1780. case DW_FORM_addrx4:
  1781. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  1782. break;
  1783. case DW_FORM_sdata:
  1784. READ_SLEB (svalue, data, end);
  1785. uvalue = svalue;
  1786. break;
  1787. case DW_FORM_ref_udata:
  1788. case DW_FORM_udata:
  1789. case DW_FORM_GNU_str_index:
  1790. case DW_FORM_strx:
  1791. case DW_FORM_GNU_addr_index:
  1792. case DW_FORM_addrx:
  1793. case DW_FORM_loclistx:
  1794. case DW_FORM_rnglistx:
  1795. READ_ULEB (uvalue, data, end);
  1796. break;
  1797. case DW_FORM_ref8:
  1798. SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end);
  1799. break;
  1800. case DW_FORM_data8:
  1801. case DW_FORM_ref_sig8:
  1802. inc = 8;
  1803. break;
  1804. case DW_FORM_data16:
  1805. inc = 16;
  1806. break;
  1807. case DW_FORM_string:
  1808. inc = strnlen ((char *) data, end - data) + 1;
  1809. break;
  1810. case DW_FORM_block:
  1811. case DW_FORM_exprloc:
  1812. READ_ULEB (uvalue, data, end);
  1813. inc = uvalue;
  1814. break;
  1815. case DW_FORM_block1:
  1816. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  1817. inc = uvalue;
  1818. break;
  1819. case DW_FORM_block2:
  1820. SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
  1821. inc = uvalue;
  1822. break;
  1823. case DW_FORM_block4:
  1824. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  1825. inc = uvalue;
  1826. break;
  1827. case DW_FORM_indirect:
  1828. READ_ULEB (form, data, end);
  1829. if (form == DW_FORM_implicit_const)
  1830. SKIP_ULEB (data, end);
  1831. return skip_attr_bytes (form, data, end, pointer_size, offset_size,
  1832. dwarf_version, value_return);
  1833. default:
  1834. return NULL;
  1835. }
  1836. * value_return = uvalue;
  1837. if (inc <= (dwarf_vma) (end - data))
  1838. data += inc;
  1839. else
  1840. data = end;
  1841. return data;
  1842. }
  1843. /* Given form FORM with value UVALUE, locate and return the abbreviation
  1844. associated with it. */
  1845. static abbrev_entry *
  1846. get_type_abbrev_from_form (unsigned long form,
  1847. unsigned long uvalue,
  1848. dwarf_vma cu_offset,
  1849. unsigned char *cu_end,
  1850. const struct dwarf_section *section,
  1851. unsigned long *abbrev_num_return,
  1852. unsigned char **data_return,
  1853. abbrev_map **map_return)
  1854. {
  1855. unsigned long abbrev_number;
  1856. abbrev_map * map;
  1857. abbrev_entry * entry;
  1858. unsigned char * data;
  1859. if (abbrev_num_return != NULL)
  1860. * abbrev_num_return = 0;
  1861. if (data_return != NULL)
  1862. * data_return = NULL;
  1863. switch (form)
  1864. {
  1865. case DW_FORM_GNU_ref_alt:
  1866. case DW_FORM_ref_sig8:
  1867. /* FIXME: We are unable to handle this form at the moment. */
  1868. return NULL;
  1869. case DW_FORM_ref_addr:
  1870. if (uvalue >= section->size)
  1871. {
  1872. warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
  1873. uvalue, (long) section->size, section->name);
  1874. return NULL;
  1875. }
  1876. break;
  1877. case DW_FORM_ref_sup4:
  1878. case DW_FORM_ref_sup8:
  1879. break;
  1880. case DW_FORM_ref1:
  1881. case DW_FORM_ref2:
  1882. case DW_FORM_ref4:
  1883. case DW_FORM_ref8:
  1884. case DW_FORM_ref_udata:
  1885. if (uvalue + cu_offset > (size_t) (cu_end - section->start))
  1886. {
  1887. warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
  1888. uvalue, (long) cu_offset, (long) (cu_end - section->start));
  1889. return NULL;
  1890. }
  1891. uvalue += cu_offset;
  1892. break;
  1893. /* FIXME: Are there other DW_FORMs that can be used by types ? */
  1894. default:
  1895. warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form);
  1896. return NULL;
  1897. }
  1898. data = (unsigned char *) section->start + uvalue;
  1899. map = find_abbrev_map_by_offset (uvalue);
  1900. if (map == NULL)
  1901. {
  1902. warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue);
  1903. return NULL;
  1904. }
  1905. if (map->list == NULL)
  1906. {
  1907. warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue);
  1908. return NULL;
  1909. }
  1910. if (map_return != NULL)
  1911. {
  1912. if (form == DW_FORM_ref_addr)
  1913. *map_return = map;
  1914. else
  1915. *map_return = NULL;
  1916. }
  1917. READ_ULEB (abbrev_number, data, section->start + section->size);
  1918. for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next)
  1919. if (entry->number == abbrev_number)
  1920. break;
  1921. if (abbrev_num_return != NULL)
  1922. * abbrev_num_return = abbrev_number;
  1923. if (data_return != NULL)
  1924. * data_return = data;
  1925. if (entry == NULL)
  1926. warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number);
  1927. return entry;
  1928. }
  1929. /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
  1930. can be determined to be a signed type. The data for ENTRY can be
  1931. found starting at DATA. */
  1932. static void
  1933. get_type_signedness (abbrev_entry *entry,
  1934. const struct dwarf_section *section,
  1935. unsigned char *data,
  1936. unsigned char *end,
  1937. dwarf_vma cu_offset,
  1938. dwarf_vma pointer_size,
  1939. dwarf_vma offset_size,
  1940. int dwarf_version,
  1941. bool *is_signed,
  1942. unsigned int nesting)
  1943. {
  1944. abbrev_attr * attr;
  1945. * is_signed = false;
  1946. #define MAX_NESTING 20
  1947. if (nesting > MAX_NESTING)
  1948. {
  1949. /* FIXME: Warn - or is this expected ?
  1950. NB/ We need to avoid infinite recursion. */
  1951. return;
  1952. }
  1953. for (attr = entry->first_attr;
  1954. attr != NULL && attr->attribute;
  1955. attr = attr->next)
  1956. {
  1957. unsigned char * orig_data = data;
  1958. dwarf_vma uvalue = 0;
  1959. data = skip_attr_bytes (attr->form, data, end, pointer_size,
  1960. offset_size, dwarf_version, & uvalue);
  1961. if (data == NULL)
  1962. return;
  1963. switch (attr->attribute)
  1964. {
  1965. case DW_AT_linkage_name:
  1966. case DW_AT_name:
  1967. if (do_wide)
  1968. {
  1969. if (attr->form == DW_FORM_strp)
  1970. printf (", %s", fetch_indirect_string (uvalue));
  1971. else if (attr->form == DW_FORM_string)
  1972. printf (", %.*s", (int) (end - orig_data), orig_data);
  1973. }
  1974. break;
  1975. case DW_AT_type:
  1976. /* Recurse. */
  1977. {
  1978. abbrev_entry *type_abbrev;
  1979. unsigned char *type_data;
  1980. abbrev_map *map;
  1981. type_abbrev = get_type_abbrev_from_form (attr->form,
  1982. uvalue,
  1983. cu_offset,
  1984. end,
  1985. section,
  1986. NULL /* abbrev num return */,
  1987. &type_data,
  1988. &map);
  1989. if (type_abbrev == NULL)
  1990. break;
  1991. get_type_signedness (type_abbrev, section, type_data,
  1992. map ? section->start + map->end : end,
  1993. map ? map->start : cu_offset,
  1994. pointer_size, offset_size, dwarf_version,
  1995. is_signed, nesting + 1);
  1996. }
  1997. break;
  1998. case DW_AT_encoding:
  1999. /* Determine signness. */
  2000. switch (uvalue)
  2001. {
  2002. case DW_ATE_address:
  2003. /* FIXME - some architectures have signed addresses. */
  2004. case DW_ATE_boolean:
  2005. case DW_ATE_unsigned:
  2006. case DW_ATE_unsigned_char:
  2007. case DW_ATE_unsigned_fixed:
  2008. * is_signed = false;
  2009. break;
  2010. default:
  2011. case DW_ATE_complex_float:
  2012. case DW_ATE_float:
  2013. case DW_ATE_signed:
  2014. case DW_ATE_signed_char:
  2015. case DW_ATE_imaginary_float:
  2016. case DW_ATE_decimal_float:
  2017. case DW_ATE_signed_fixed:
  2018. * is_signed = true;
  2019. break;
  2020. }
  2021. break;
  2022. }
  2023. }
  2024. }
  2025. static void
  2026. read_and_print_leb128 (unsigned char *data,
  2027. unsigned int *bytes_read,
  2028. unsigned const char *end,
  2029. bool is_signed)
  2030. {
  2031. int status;
  2032. dwarf_vma val = read_leb128 (data, end, is_signed, bytes_read, &status);
  2033. if (status != 0)
  2034. report_leb_status (status);
  2035. else
  2036. printf ("%s", dwarf_vmatoa (is_signed ? "d" : "u", val));
  2037. }
  2038. static void
  2039. display_discr_list (unsigned long form,
  2040. dwarf_vma uvalue,
  2041. unsigned char * data,
  2042. int level)
  2043. {
  2044. unsigned char *end = data;
  2045. if (uvalue == 0)
  2046. {
  2047. printf ("[default]");
  2048. return;
  2049. }
  2050. switch (form)
  2051. {
  2052. case DW_FORM_block:
  2053. case DW_FORM_block1:
  2054. case DW_FORM_block2:
  2055. case DW_FORM_block4:
  2056. /* Move data pointer back to the start of the byte array. */
  2057. data -= uvalue;
  2058. break;
  2059. default:
  2060. printf ("<corrupt>\n");
  2061. warn (_("corrupt discr_list - not using a block form\n"));
  2062. return;
  2063. }
  2064. if (uvalue < 2)
  2065. {
  2066. printf ("<corrupt>\n");
  2067. warn (_("corrupt discr_list - block not long enough\n"));
  2068. return;
  2069. }
  2070. bool is_signed = (level > 0 && level <= MAX_CU_NESTING
  2071. ? level_type_signed [level - 1] : false);
  2072. printf ("(");
  2073. while (data < end)
  2074. {
  2075. unsigned char discriminant;
  2076. unsigned int bytes_read;
  2077. SAFE_BYTE_GET_AND_INC (discriminant, data, 1, end);
  2078. switch (discriminant)
  2079. {
  2080. case DW_DSC_label:
  2081. printf ("label ");
  2082. read_and_print_leb128 (data, & bytes_read, end, is_signed);
  2083. data += bytes_read;
  2084. break;
  2085. case DW_DSC_range:
  2086. printf ("range ");
  2087. read_and_print_leb128 (data, & bytes_read, end, is_signed);
  2088. data += bytes_read;
  2089. printf ("..");
  2090. read_and_print_leb128 (data, & bytes_read, end, is_signed);
  2091. data += bytes_read;
  2092. break;
  2093. default:
  2094. printf ("<corrupt>\n");
  2095. warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
  2096. discriminant);
  2097. return;
  2098. }
  2099. if (data < end)
  2100. printf (", ");
  2101. }
  2102. if (is_signed)
  2103. printf (")(signed)");
  2104. else
  2105. printf (")(unsigned)");
  2106. }
  2107. static unsigned char *
  2108. read_and_display_attr_value (unsigned long attribute,
  2109. unsigned long form,
  2110. dwarf_signed_vma implicit_const,
  2111. unsigned char * start,
  2112. unsigned char * data,
  2113. unsigned char * end,
  2114. dwarf_vma cu_offset,
  2115. dwarf_vma pointer_size,
  2116. dwarf_vma offset_size,
  2117. int dwarf_version,
  2118. debug_info * debug_info_p,
  2119. int do_loc,
  2120. struct dwarf_section * section,
  2121. struct cu_tu_set * this_set,
  2122. char delimiter,
  2123. int level)
  2124. {
  2125. dwarf_signed_vma svalue;
  2126. dwarf_vma uvalue = 0;
  2127. dwarf_vma uvalue_hi = 0;
  2128. unsigned char *block_start = NULL;
  2129. unsigned char *orig_data = data;
  2130. if (data > end || (data == end && form != DW_FORM_flag_present))
  2131. {
  2132. warn (_("Corrupt attribute\n"));
  2133. return data;
  2134. }
  2135. if (do_wide && ! do_loc)
  2136. {
  2137. /* PR 26847: Display the name of the form. */
  2138. const char * name = get_FORM_name (form);
  2139. /* For convenience we skip the DW_FORM_ prefix to the name. */
  2140. if (name[0] == 'D')
  2141. name += 8; /* strlen ("DW_FORM_") */
  2142. printf ("%c(%s)", delimiter, name);
  2143. }
  2144. switch (form)
  2145. {
  2146. case DW_FORM_ref_addr:
  2147. if (dwarf_version == 2)
  2148. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  2149. else if (dwarf_version > 2)
  2150. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  2151. else
  2152. error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
  2153. break;
  2154. case DW_FORM_addr:
  2155. SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end);
  2156. break;
  2157. case DW_FORM_strp_sup:
  2158. case DW_FORM_strp:
  2159. case DW_FORM_line_strp:
  2160. case DW_FORM_sec_offset:
  2161. case DW_FORM_GNU_ref_alt:
  2162. case DW_FORM_GNU_strp_alt:
  2163. SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end);
  2164. break;
  2165. case DW_FORM_flag_present:
  2166. uvalue = 1;
  2167. break;
  2168. case DW_FORM_ref1:
  2169. case DW_FORM_flag:
  2170. case DW_FORM_data1:
  2171. case DW_FORM_strx1:
  2172. case DW_FORM_addrx1:
  2173. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  2174. break;
  2175. case DW_FORM_ref2:
  2176. case DW_FORM_data2:
  2177. case DW_FORM_strx2:
  2178. case DW_FORM_addrx2:
  2179. SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
  2180. break;
  2181. case DW_FORM_strx3:
  2182. case DW_FORM_addrx3:
  2183. SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end);
  2184. break;
  2185. case DW_FORM_ref_sup4:
  2186. case DW_FORM_ref4:
  2187. case DW_FORM_data4:
  2188. case DW_FORM_strx4:
  2189. case DW_FORM_addrx4:
  2190. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  2191. break;
  2192. case DW_FORM_ref_sup8:
  2193. case DW_FORM_ref8:
  2194. case DW_FORM_data8:
  2195. case DW_FORM_ref_sig8:
  2196. SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end);
  2197. break;
  2198. case DW_FORM_data16:
  2199. SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end);
  2200. SAFE_BYTE_GET_AND_INC (uvalue_hi, data, 8, end);
  2201. if (byte_get != byte_get_little_endian)
  2202. {
  2203. dwarf_vma utmp = uvalue;
  2204. uvalue = uvalue_hi;
  2205. uvalue_hi = utmp;
  2206. }
  2207. break;
  2208. case DW_FORM_sdata:
  2209. READ_SLEB (svalue, data, end);
  2210. uvalue = svalue;
  2211. break;
  2212. case DW_FORM_GNU_str_index:
  2213. case DW_FORM_strx:
  2214. case DW_FORM_ref_udata:
  2215. case DW_FORM_udata:
  2216. case DW_FORM_GNU_addr_index:
  2217. case DW_FORM_addrx:
  2218. case DW_FORM_loclistx:
  2219. case DW_FORM_rnglistx:
  2220. READ_ULEB (uvalue, data, end);
  2221. break;
  2222. case DW_FORM_indirect:
  2223. READ_ULEB (form, data, end);
  2224. if (!do_loc)
  2225. printf ("%c%s", delimiter, get_FORM_name (form));
  2226. if (form == DW_FORM_implicit_const)
  2227. READ_SLEB (implicit_const, data, end);
  2228. return read_and_display_attr_value (attribute, form, implicit_const,
  2229. start, data, end,
  2230. cu_offset, pointer_size,
  2231. offset_size, dwarf_version,
  2232. debug_info_p, do_loc,
  2233. section, this_set, delimiter, level);
  2234. case DW_FORM_implicit_const:
  2235. uvalue = implicit_const;
  2236. break;
  2237. default:
  2238. break;
  2239. }
  2240. switch (form)
  2241. {
  2242. case DW_FORM_ref_addr:
  2243. if (!do_loc)
  2244. printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
  2245. break;
  2246. case DW_FORM_GNU_ref_alt:
  2247. if (!do_loc)
  2248. {
  2249. if (do_wide)
  2250. /* We have already printed the form name. */
  2251. printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
  2252. else
  2253. printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x", uvalue));
  2254. }
  2255. /* FIXME: Follow the reference... */
  2256. break;
  2257. case DW_FORM_ref1:
  2258. case DW_FORM_ref2:
  2259. case DW_FORM_ref4:
  2260. case DW_FORM_ref_sup4:
  2261. case DW_FORM_ref_udata:
  2262. if (!do_loc)
  2263. printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
  2264. break;
  2265. case DW_FORM_data4:
  2266. case DW_FORM_addr:
  2267. case DW_FORM_sec_offset:
  2268. if (!do_loc)
  2269. printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", uvalue));
  2270. break;
  2271. case DW_FORM_flag_present:
  2272. case DW_FORM_flag:
  2273. case DW_FORM_data1:
  2274. case DW_FORM_data2:
  2275. case DW_FORM_sdata:
  2276. case DW_FORM_udata:
  2277. if (!do_loc)
  2278. printf ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
  2279. break;
  2280. case DW_FORM_implicit_const:
  2281. if (!do_loc)
  2282. printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
  2283. break;
  2284. case DW_FORM_ref_sup8:
  2285. case DW_FORM_ref8:
  2286. case DW_FORM_data8:
  2287. if (!do_loc)
  2288. {
  2289. dwarf_vma utmp = uvalue;
  2290. if (form == DW_FORM_ref8)
  2291. utmp += cu_offset;
  2292. printf ("%c0x%s", delimiter, dwarf_vmatoa ("x", utmp));
  2293. }
  2294. break;
  2295. case DW_FORM_data16:
  2296. if (!do_loc)
  2297. printf (" 0x%s%s",
  2298. uvalue_hi == 0 ? "" : dwarf_vmatoa ("x", uvalue_hi),
  2299. dwarf_vmatoa_1 ("x", uvalue, uvalue_hi == 0 ? 0 : 8));
  2300. break;
  2301. case DW_FORM_string:
  2302. if (!do_loc)
  2303. printf ("%c%.*s", delimiter, (int) (end - data), data);
  2304. data += strnlen ((char *) data, end - data);
  2305. if (data < end)
  2306. data++;
  2307. break;
  2308. case DW_FORM_block:
  2309. case DW_FORM_exprloc:
  2310. READ_ULEB (uvalue, data, end);
  2311. do_block:
  2312. block_start = data;
  2313. if (block_start >= end)
  2314. {
  2315. warn (_("Block ends prematurely\n"));
  2316. uvalue = 0;
  2317. block_start = end;
  2318. }
  2319. uvalue = check_uvalue (block_start, uvalue, end);
  2320. if (do_loc)
  2321. data = block_start + uvalue;
  2322. else
  2323. data = display_block (block_start, uvalue, end, delimiter);
  2324. break;
  2325. case DW_FORM_block1:
  2326. SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
  2327. goto do_block;
  2328. case DW_FORM_block2:
  2329. SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end);
  2330. goto do_block;
  2331. case DW_FORM_block4:
  2332. SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end);
  2333. goto do_block;
  2334. case DW_FORM_strp:
  2335. if (!do_loc)
  2336. {
  2337. if (do_wide)
  2338. /* We have already displayed the form name. */
  2339. printf (_("%c(offset: 0x%s): %s"), delimiter,
  2340. dwarf_vmatoa ("x", uvalue),
  2341. fetch_indirect_string (uvalue));
  2342. else
  2343. printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
  2344. dwarf_vmatoa ("x", uvalue),
  2345. fetch_indirect_string (uvalue));
  2346. }
  2347. break;
  2348. case DW_FORM_line_strp:
  2349. if (!do_loc)
  2350. {
  2351. if (do_wide)
  2352. /* We have already displayed the form name. */
  2353. printf (_("%c(offset: 0x%s): %s"), delimiter,
  2354. dwarf_vmatoa ("x", uvalue),
  2355. fetch_indirect_line_string (uvalue));
  2356. else
  2357. printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
  2358. dwarf_vmatoa ("x", uvalue),
  2359. fetch_indirect_line_string (uvalue));
  2360. }
  2361. break;
  2362. case DW_FORM_GNU_str_index:
  2363. case DW_FORM_strx:
  2364. case DW_FORM_strx1:
  2365. case DW_FORM_strx2:
  2366. case DW_FORM_strx3:
  2367. case DW_FORM_strx4:
  2368. if (!do_loc)
  2369. {
  2370. const char *suffix = strrchr (section->name, '.');
  2371. bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
  2372. if (do_wide)
  2373. /* We have already displayed the form name. */
  2374. printf (_("%c(offset: 0x%s): %s"), delimiter,
  2375. dwarf_vmatoa ("x", uvalue),
  2376. fetch_indexed_string (uvalue, this_set, offset_size, dwo));
  2377. else
  2378. printf (_("%c(indexed string: 0x%s): %s"), delimiter,
  2379. dwarf_vmatoa ("x", uvalue),
  2380. fetch_indexed_string (uvalue, this_set, offset_size, dwo));
  2381. }
  2382. break;
  2383. case DW_FORM_GNU_strp_alt:
  2384. if (!do_loc)
  2385. {
  2386. if (do_wide)
  2387. /* We have already displayed the form name. */
  2388. printf (_("%c(offset: 0x%s) %s"), delimiter,
  2389. dwarf_vmatoa ("x", uvalue),
  2390. fetch_alt_indirect_string (uvalue));
  2391. else
  2392. printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter,
  2393. dwarf_vmatoa ("x", uvalue),
  2394. fetch_alt_indirect_string (uvalue));
  2395. }
  2396. break;
  2397. case DW_FORM_indirect:
  2398. /* Handled above. */
  2399. break;
  2400. case DW_FORM_ref_sig8:
  2401. if (!do_loc)
  2402. printf ("%c%s: 0x%s", delimiter, do_wide ? "" : "signature",
  2403. dwarf_vmatoa ("x", uvalue));
  2404. break;
  2405. case DW_FORM_GNU_addr_index:
  2406. case DW_FORM_addrx:
  2407. case DW_FORM_addrx1:
  2408. case DW_FORM_addrx2:
  2409. case DW_FORM_addrx3:
  2410. case DW_FORM_addrx4:
  2411. case DW_FORM_loclistx:
  2412. case DW_FORM_rnglistx:
  2413. if (!do_loc)
  2414. {
  2415. dwarf_vma base;
  2416. dwarf_vma offset;
  2417. if (debug_info_p == NULL)
  2418. base = 0;
  2419. else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE)
  2420. base = 0;
  2421. else
  2422. base = debug_info_p->addr_base;
  2423. offset = base + uvalue * pointer_size;
  2424. if (do_wide)
  2425. /* We have already displayed the form name. */
  2426. printf (_("%c(index: 0x%s): %s"), delimiter,
  2427. dwarf_vmatoa ("x", uvalue),
  2428. dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
  2429. else
  2430. printf (_("%c(addr_index: 0x%s): %s"), delimiter,
  2431. dwarf_vmatoa ("x", uvalue),
  2432. dwarf_vmatoa ("x", fetch_indexed_addr (offset, pointer_size)));
  2433. }
  2434. break;
  2435. case DW_FORM_strp_sup:
  2436. if (!do_loc)
  2437. printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
  2438. break;
  2439. default:
  2440. warn (_("Unrecognized form: 0x%lx\n"), form);
  2441. /* What to do? Consume a byte maybe? */
  2442. ++data;
  2443. break;
  2444. }
  2445. if ((do_loc || do_debug_loc || do_debug_ranges)
  2446. && num_debug_info_entries == 0
  2447. && debug_info_p != NULL)
  2448. {
  2449. switch (attribute)
  2450. {
  2451. case DW_AT_loclists_base:
  2452. if (debug_info_p->loclists_base)
  2453. warn (_("CU @ 0x%s has multiple loclists_base values"),
  2454. dwarf_vmatoa ("x", debug_info_p->cu_offset));
  2455. debug_info_p->loclists_base = uvalue;
  2456. break;
  2457. case DW_AT_frame_base:
  2458. have_frame_base = 1;
  2459. /* Fall through. */
  2460. case DW_AT_location:
  2461. case DW_AT_GNU_locviews:
  2462. case DW_AT_string_length:
  2463. case DW_AT_return_addr:
  2464. case DW_AT_data_member_location:
  2465. case DW_AT_vtable_elem_location:
  2466. case DW_AT_segment:
  2467. case DW_AT_static_link:
  2468. case DW_AT_use_location:
  2469. case DW_AT_call_value:
  2470. case DW_AT_GNU_call_site_value:
  2471. case DW_AT_call_data_value:
  2472. case DW_AT_GNU_call_site_data_value:
  2473. case DW_AT_call_target:
  2474. case DW_AT_GNU_call_site_target:
  2475. case DW_AT_call_target_clobbered:
  2476. case DW_AT_GNU_call_site_target_clobbered:
  2477. if ((dwarf_version < 4
  2478. && (form == DW_FORM_data4 || form == DW_FORM_data8))
  2479. || form == DW_FORM_sec_offset
  2480. || form == DW_FORM_loclistx)
  2481. {
  2482. /* Process location list. */
  2483. unsigned int lmax = debug_info_p->max_loc_offsets;
  2484. unsigned int num = debug_info_p->num_loc_offsets;
  2485. if (lmax == 0 || num >= lmax)
  2486. {
  2487. lmax += 1024;
  2488. debug_info_p->loc_offsets = (dwarf_vma *)
  2489. xcrealloc (debug_info_p->loc_offsets,
  2490. lmax, sizeof (*debug_info_p->loc_offsets));
  2491. debug_info_p->loc_views = (dwarf_vma *)
  2492. xcrealloc (debug_info_p->loc_views,
  2493. lmax, sizeof (*debug_info_p->loc_views));
  2494. debug_info_p->have_frame_base = (int *)
  2495. xcrealloc (debug_info_p->have_frame_base,
  2496. lmax, sizeof (*debug_info_p->have_frame_base));
  2497. debug_info_p->max_loc_offsets = lmax;
  2498. }
  2499. if (form == DW_FORM_loclistx)
  2500. uvalue = fetch_indexed_value (uvalue, loclists);
  2501. else if (this_set != NULL)
  2502. uvalue += this_set->section_offsets [DW_SECT_LOC];
  2503. debug_info_p->have_frame_base [num] = have_frame_base;
  2504. if (attribute != DW_AT_GNU_locviews)
  2505. {
  2506. uvalue += debug_info_p->loclists_base;
  2507. /* Corrupt DWARF info can produce more offsets than views.
  2508. See PR 23062 for an example. */
  2509. if (debug_info_p->num_loc_offsets
  2510. > debug_info_p->num_loc_views)
  2511. warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
  2512. else
  2513. {
  2514. debug_info_p->loc_offsets [num] = uvalue;
  2515. debug_info_p->num_loc_offsets++;
  2516. }
  2517. }
  2518. else
  2519. {
  2520. assert (debug_info_p->num_loc_views <= num);
  2521. num = debug_info_p->num_loc_views;
  2522. if (num > debug_info_p->num_loc_offsets)
  2523. warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
  2524. else
  2525. {
  2526. debug_info_p->loc_views [num] = uvalue;
  2527. debug_info_p->num_loc_views++;
  2528. }
  2529. }
  2530. }
  2531. break;
  2532. case DW_AT_low_pc:
  2533. if (need_base_address)
  2534. debug_info_p->base_address = uvalue;
  2535. break;
  2536. case DW_AT_GNU_addr_base:
  2537. case DW_AT_addr_base:
  2538. debug_info_p->addr_base = uvalue;
  2539. break;
  2540. case DW_AT_GNU_ranges_base:
  2541. debug_info_p->ranges_base = uvalue;
  2542. break;
  2543. case DW_AT_ranges:
  2544. if ((dwarf_version < 4
  2545. && (form == DW_FORM_data4 || form == DW_FORM_data8))
  2546. || form == DW_FORM_sec_offset
  2547. || form == DW_FORM_rnglistx)
  2548. {
  2549. /* Process range list. */
  2550. unsigned int lmax = debug_info_p->max_range_lists;
  2551. unsigned int num = debug_info_p->num_range_lists;
  2552. if (lmax == 0 || num >= lmax)
  2553. {
  2554. lmax += 1024;
  2555. debug_info_p->range_lists = (dwarf_vma *)
  2556. xcrealloc (debug_info_p->range_lists,
  2557. lmax, sizeof (*debug_info_p->range_lists));
  2558. debug_info_p->max_range_lists = lmax;
  2559. }
  2560. if (form == DW_FORM_rnglistx)
  2561. uvalue = fetch_indexed_value (uvalue, rnglists);
  2562. debug_info_p->range_lists [num] = uvalue;
  2563. debug_info_p->num_range_lists++;
  2564. }
  2565. break;
  2566. case DW_AT_GNU_dwo_name:
  2567. case DW_AT_dwo_name:
  2568. if (need_dwo_info)
  2569. switch (form)
  2570. {
  2571. case DW_FORM_strp:
  2572. add_dwo_name ((const char *) fetch_indirect_string (uvalue), cu_offset);
  2573. break;
  2574. case DW_FORM_GNU_strp_alt:
  2575. add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset);
  2576. break;
  2577. case DW_FORM_GNU_str_index:
  2578. case DW_FORM_strx:
  2579. case DW_FORM_strx1:
  2580. case DW_FORM_strx2:
  2581. case DW_FORM_strx3:
  2582. case DW_FORM_strx4:
  2583. add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset);
  2584. break;
  2585. case DW_FORM_string:
  2586. add_dwo_name ((const char *) orig_data, cu_offset);
  2587. break;
  2588. default:
  2589. warn (_("Unsupported form (%s) for attribute %s\n"),
  2590. get_FORM_name (form), get_AT_name (attribute));
  2591. break;
  2592. }
  2593. break;
  2594. case DW_AT_comp_dir:
  2595. /* FIXME: Also extract a build-id in a CU/TU. */
  2596. if (need_dwo_info)
  2597. switch (form)
  2598. {
  2599. case DW_FORM_strp:
  2600. add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset);
  2601. break;
  2602. case DW_FORM_GNU_strp_alt:
  2603. add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset);
  2604. break;
  2605. case DW_FORM_line_strp:
  2606. add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset);
  2607. break;
  2608. case DW_FORM_GNU_str_index:
  2609. case DW_FORM_strx:
  2610. case DW_FORM_strx1:
  2611. case DW_FORM_strx2:
  2612. case DW_FORM_strx3:
  2613. case DW_FORM_strx4:
  2614. add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false), cu_offset);
  2615. break;
  2616. case DW_FORM_string:
  2617. add_dwo_dir ((const char *) orig_data, cu_offset);
  2618. break;
  2619. default:
  2620. warn (_("Unsupported form (%s) for attribute %s\n"),
  2621. get_FORM_name (form), get_AT_name (attribute));
  2622. break;
  2623. }
  2624. break;
  2625. case DW_AT_GNU_dwo_id:
  2626. if (need_dwo_info)
  2627. switch (form)
  2628. {
  2629. case DW_FORM_data8:
  2630. /* FIXME: Record the length of the ID as well ? */
  2631. add_dwo_id ((const char *) (data - 8), cu_offset);
  2632. break;
  2633. default:
  2634. warn (_("Unsupported form (%s) for attribute %s\n"),
  2635. get_FORM_name (form), get_AT_name (attribute));
  2636. break;
  2637. }
  2638. break;
  2639. default:
  2640. break;
  2641. }
  2642. }
  2643. if (do_loc || attribute == 0)
  2644. return data;
  2645. /* For some attributes we can display further information. */
  2646. switch (attribute)
  2647. {
  2648. case DW_AT_type:
  2649. if (level >= 0 && level < MAX_CU_NESTING
  2650. && uvalue < (size_t) (end - start))
  2651. {
  2652. bool is_signed = false;
  2653. abbrev_entry *type_abbrev;
  2654. unsigned char *type_data;
  2655. abbrev_map *map;
  2656. type_abbrev = get_type_abbrev_from_form (form, uvalue,
  2657. cu_offset, end,
  2658. section, NULL,
  2659. &type_data, &map);
  2660. if (type_abbrev != NULL)
  2661. {
  2662. get_type_signedness (type_abbrev, section, type_data,
  2663. map ? section->start + map->end : end,
  2664. map ? map->start : cu_offset,
  2665. pointer_size, offset_size, dwarf_version,
  2666. & is_signed, 0);
  2667. }
  2668. level_type_signed[level] = is_signed;
  2669. }
  2670. break;
  2671. case DW_AT_inline:
  2672. printf ("\t");
  2673. switch (uvalue)
  2674. {
  2675. case DW_INL_not_inlined:
  2676. printf (_("(not inlined)"));
  2677. break;
  2678. case DW_INL_inlined:
  2679. printf (_("(inlined)"));
  2680. break;
  2681. case DW_INL_declared_not_inlined:
  2682. printf (_("(declared as inline but ignored)"));
  2683. break;
  2684. case DW_INL_declared_inlined:
  2685. printf (_("(declared as inline and inlined)"));
  2686. break;
  2687. default:
  2688. printf (_(" (Unknown inline attribute value: %s)"),
  2689. dwarf_vmatoa ("x", uvalue));
  2690. break;
  2691. }
  2692. break;
  2693. case DW_AT_language:
  2694. printf ("\t");
  2695. switch (uvalue)
  2696. {
  2697. /* Ordered by the numeric value of these constants. */
  2698. case DW_LANG_C89: printf ("(ANSI C)"); break;
  2699. case DW_LANG_C: printf ("(non-ANSI C)"); break;
  2700. case DW_LANG_Ada83: printf ("(Ada)"); break;
  2701. case DW_LANG_C_plus_plus: printf ("(C++)"); break;
  2702. case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
  2703. case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
  2704. case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
  2705. case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
  2706. case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
  2707. case DW_LANG_Modula2: printf ("(Modula 2)"); break;
  2708. /* DWARF 2.1 values. */
  2709. case DW_LANG_Java: printf ("(Java)"); break;
  2710. case DW_LANG_C99: printf ("(ANSI C99)"); break;
  2711. case DW_LANG_Ada95: printf ("(ADA 95)"); break;
  2712. case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
  2713. /* DWARF 3 values. */
  2714. case DW_LANG_PLI: printf ("(PLI)"); break;
  2715. case DW_LANG_ObjC: printf ("(Objective C)"); break;
  2716. case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
  2717. case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
  2718. case DW_LANG_D: printf ("(D)"); break;
  2719. /* DWARF 4 values. */
  2720. case DW_LANG_Python: printf ("(Python)"); break;
  2721. /* DWARF 5 values. */
  2722. case DW_LANG_OpenCL: printf ("(OpenCL)"); break;
  2723. case DW_LANG_Go: printf ("(Go)"); break;
  2724. case DW_LANG_Modula3: printf ("(Modula 3)"); break;
  2725. case DW_LANG_Haskell: printf ("(Haskell)"); break;
  2726. case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break;
  2727. case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break;
  2728. case DW_LANG_OCaml: printf ("(OCaml)"); break;
  2729. case DW_LANG_Rust: printf ("(Rust)"); break;
  2730. case DW_LANG_C11: printf ("(C11)"); break;
  2731. case DW_LANG_Swift: printf ("(Swift)"); break;
  2732. case DW_LANG_Julia: printf ("(Julia)"); break;
  2733. case DW_LANG_Dylan: printf ("(Dylan)"); break;
  2734. case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break;
  2735. case DW_LANG_Fortran03: printf ("(Fortran 03)"); break;
  2736. case DW_LANG_Fortran08: printf ("(Fortran 08)"); break;
  2737. case DW_LANG_RenderScript: printf ("(RenderScript)"); break;
  2738. /* MIPS extension. */
  2739. case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
  2740. /* UPC extension. */
  2741. case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
  2742. default:
  2743. if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
  2744. printf (_("(implementation defined: %s)"),
  2745. dwarf_vmatoa ("x", uvalue));
  2746. else
  2747. printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
  2748. break;
  2749. }
  2750. break;
  2751. case DW_AT_encoding:
  2752. printf ("\t");
  2753. switch (uvalue)
  2754. {
  2755. case DW_ATE_void: printf ("(void)"); break;
  2756. case DW_ATE_address: printf ("(machine address)"); break;
  2757. case DW_ATE_boolean: printf ("(boolean)"); break;
  2758. case DW_ATE_complex_float: printf ("(complex float)"); break;
  2759. case DW_ATE_float: printf ("(float)"); break;
  2760. case DW_ATE_signed: printf ("(signed)"); break;
  2761. case DW_ATE_signed_char: printf ("(signed char)"); break;
  2762. case DW_ATE_unsigned: printf ("(unsigned)"); break;
  2763. case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
  2764. /* DWARF 2.1 values: */
  2765. case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
  2766. case DW_ATE_decimal_float: printf ("(decimal float)"); break;
  2767. /* DWARF 3 values: */
  2768. case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
  2769. case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
  2770. case DW_ATE_edited: printf ("(edited)"); break;
  2771. case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
  2772. case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
  2773. /* DWARF 4 values: */
  2774. case DW_ATE_UTF: printf ("(unicode string)"); break;
  2775. /* DWARF 5 values: */
  2776. case DW_ATE_UCS: printf ("(UCS)"); break;
  2777. case DW_ATE_ASCII: printf ("(ASCII)"); break;
  2778. /* HP extensions: */
  2779. case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
  2780. case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
  2781. case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
  2782. case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
  2783. case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
  2784. case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
  2785. case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
  2786. default:
  2787. if (uvalue >= DW_ATE_lo_user
  2788. && uvalue <= DW_ATE_hi_user)
  2789. printf (_("(user defined type)"));
  2790. else
  2791. printf (_("(unknown type)"));
  2792. break;
  2793. }
  2794. break;
  2795. case DW_AT_accessibility:
  2796. printf ("\t");
  2797. switch (uvalue)
  2798. {
  2799. case DW_ACCESS_public: printf ("(public)"); break;
  2800. case DW_ACCESS_protected: printf ("(protected)"); break;
  2801. case DW_ACCESS_private: printf ("(private)"); break;
  2802. default:
  2803. printf (_("(unknown accessibility)"));
  2804. break;
  2805. }
  2806. break;
  2807. case DW_AT_visibility:
  2808. printf ("\t");
  2809. switch (uvalue)
  2810. {
  2811. case DW_VIS_local: printf ("(local)"); break;
  2812. case DW_VIS_exported: printf ("(exported)"); break;
  2813. case DW_VIS_qualified: printf ("(qualified)"); break;
  2814. default: printf (_("(unknown visibility)")); break;
  2815. }
  2816. break;
  2817. case DW_AT_endianity:
  2818. printf ("\t");
  2819. switch (uvalue)
  2820. {
  2821. case DW_END_default: printf ("(default)"); break;
  2822. case DW_END_big: printf ("(big)"); break;
  2823. case DW_END_little: printf ("(little)"); break;
  2824. default:
  2825. if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user)
  2826. printf (_("(user specified)"));
  2827. else
  2828. printf (_("(unknown endianity)"));
  2829. break;
  2830. }
  2831. break;
  2832. case DW_AT_virtuality:
  2833. printf ("\t");
  2834. switch (uvalue)
  2835. {
  2836. case DW_VIRTUALITY_none: printf ("(none)"); break;
  2837. case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
  2838. case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
  2839. default: printf (_("(unknown virtuality)")); break;
  2840. }
  2841. break;
  2842. case DW_AT_identifier_case:
  2843. printf ("\t");
  2844. switch (uvalue)
  2845. {
  2846. case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
  2847. case DW_ID_up_case: printf ("(up_case)"); break;
  2848. case DW_ID_down_case: printf ("(down_case)"); break;
  2849. case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
  2850. default: printf (_("(unknown case)")); break;
  2851. }
  2852. break;
  2853. case DW_AT_calling_convention:
  2854. printf ("\t");
  2855. switch (uvalue)
  2856. {
  2857. case DW_CC_normal: printf ("(normal)"); break;
  2858. case DW_CC_program: printf ("(program)"); break;
  2859. case DW_CC_nocall: printf ("(nocall)"); break;
  2860. case DW_CC_pass_by_reference: printf ("(pass by ref)"); break;
  2861. case DW_CC_pass_by_value: printf ("(pass by value)"); break;
  2862. case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break;
  2863. case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); break;
  2864. default:
  2865. if (uvalue >= DW_CC_lo_user
  2866. && uvalue <= DW_CC_hi_user)
  2867. printf (_("(user defined)"));
  2868. else
  2869. printf (_("(unknown convention)"));
  2870. }
  2871. break;
  2872. case DW_AT_ordering:
  2873. printf ("\t");
  2874. switch (uvalue)
  2875. {
  2876. case 255:
  2877. case -1: printf (_("(undefined)")); break;
  2878. case 0: printf ("(row major)"); break;
  2879. case 1: printf ("(column major)"); break;
  2880. }
  2881. break;
  2882. case DW_AT_decimal_sign:
  2883. printf ("\t");
  2884. switch (uvalue)
  2885. {
  2886. case DW_DS_unsigned: printf (_("(unsigned)")); break;
  2887. case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break;
  2888. case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break;
  2889. case DW_DS_leading_separate: printf (_("(leading separate)")); break;
  2890. case DW_DS_trailing_separate: printf (_("(trailing separate)")); break;
  2891. default: printf (_("(unrecognised)")); break;
  2892. }
  2893. break;
  2894. case DW_AT_defaulted:
  2895. printf ("\t");
  2896. switch (uvalue)
  2897. {
  2898. case DW_DEFAULTED_no: printf (_("(no)")); break;
  2899. case DW_DEFAULTED_in_class: printf (_("(in class)")); break;
  2900. case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break;
  2901. default: printf (_("(unrecognised)")); break;
  2902. }
  2903. break;
  2904. case DW_AT_discr_list:
  2905. printf ("\t");
  2906. display_discr_list (form, uvalue, data, level);
  2907. break;
  2908. case DW_AT_frame_base:
  2909. have_frame_base = 1;
  2910. /* Fall through. */
  2911. case DW_AT_location:
  2912. case DW_AT_loclists_base:
  2913. case DW_AT_string_length:
  2914. case DW_AT_return_addr:
  2915. case DW_AT_data_member_location:
  2916. case DW_AT_vtable_elem_location:
  2917. case DW_AT_segment:
  2918. case DW_AT_static_link:
  2919. case DW_AT_use_location:
  2920. case DW_AT_call_value:
  2921. case DW_AT_GNU_call_site_value:
  2922. case DW_AT_call_data_value:
  2923. case DW_AT_GNU_call_site_data_value:
  2924. case DW_AT_call_target:
  2925. case DW_AT_GNU_call_site_target:
  2926. case DW_AT_call_target_clobbered:
  2927. case DW_AT_GNU_call_site_target_clobbered:
  2928. if ((dwarf_version < 4
  2929. && (form == DW_FORM_data4 || form == DW_FORM_data8))
  2930. || form == DW_FORM_sec_offset
  2931. || form == DW_FORM_loclistx)
  2932. printf (_(" (location list)"));
  2933. /* Fall through. */
  2934. case DW_AT_allocated:
  2935. case DW_AT_associated:
  2936. case DW_AT_data_location:
  2937. case DW_AT_stride:
  2938. case DW_AT_upper_bound:
  2939. case DW_AT_lower_bound:
  2940. if (block_start)
  2941. {
  2942. int need_frame_base;
  2943. printf ("\t(");
  2944. need_frame_base = decode_location_expression (block_start,
  2945. pointer_size,
  2946. offset_size,
  2947. dwarf_version,
  2948. uvalue,
  2949. cu_offset, section);
  2950. printf (")");
  2951. if (need_frame_base && !have_frame_base)
  2952. printf (_(" [without DW_AT_frame_base]"));
  2953. }
  2954. break;
  2955. case DW_AT_data_bit_offset:
  2956. case DW_AT_byte_size:
  2957. case DW_AT_bit_size:
  2958. case DW_AT_string_length_byte_size:
  2959. case DW_AT_string_length_bit_size:
  2960. case DW_AT_bit_stride:
  2961. if (form == DW_FORM_exprloc)
  2962. {
  2963. printf ("\t(");
  2964. (void) decode_location_expression (block_start, pointer_size,
  2965. offset_size, dwarf_version,
  2966. uvalue, cu_offset, section);
  2967. printf (")");
  2968. }
  2969. break;
  2970. case DW_AT_import:
  2971. {
  2972. unsigned long abbrev_number;
  2973. abbrev_entry *entry;
  2974. entry = get_type_abbrev_from_form (form, uvalue, cu_offset, end,
  2975. section, & abbrev_number, NULL, NULL);
  2976. if (entry == NULL)
  2977. {
  2978. if (form != DW_FORM_GNU_ref_alt)
  2979. warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
  2980. dwarf_vmatoa ("x", uvalue),
  2981. (unsigned long) (orig_data - section->start));
  2982. }
  2983. else
  2984. {
  2985. printf (_("\t[Abbrev Number: %ld"), abbrev_number);
  2986. printf (" (%s)", get_TAG_name (entry->tag));
  2987. printf ("]");
  2988. }
  2989. }
  2990. break;
  2991. default:
  2992. break;
  2993. }
  2994. return data;
  2995. }
  2996. static unsigned char *
  2997. read_and_display_attr (unsigned long attribute,
  2998. unsigned long form,
  2999. dwarf_signed_vma implicit_const,
  3000. unsigned char * start,
  3001. unsigned char * data,
  3002. unsigned char * end,
  3003. dwarf_vma cu_offset,
  3004. dwarf_vma pointer_size,
  3005. dwarf_vma offset_size,
  3006. int dwarf_version,
  3007. debug_info * debug_info_p,
  3008. int do_loc,
  3009. struct dwarf_section * section,
  3010. struct cu_tu_set * this_set,
  3011. int level)
  3012. {
  3013. if (!do_loc)
  3014. printf (" %-18s:", get_AT_name (attribute));
  3015. data = read_and_display_attr_value (attribute, form, implicit_const,
  3016. start, data, end,
  3017. cu_offset, pointer_size, offset_size,
  3018. dwarf_version, debug_info_p,
  3019. do_loc, section, this_set, ' ', level);
  3020. if (!do_loc)
  3021. printf ("\n");
  3022. return data;
  3023. }
  3024. /* Like load_debug_section, but if the ordinary call fails, and we are
  3025. following debug links, then attempt to load the requested section
  3026. from one of the separate debug info files. */
  3027. static bool
  3028. load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum,
  3029. void * handle)
  3030. {
  3031. if (load_debug_section (sec_enum, handle))
  3032. {
  3033. if (debug_displays[sec_enum].section.filename == NULL)
  3034. {
  3035. /* See if we can associate a filename with this section. */
  3036. separate_info * i;
  3037. for (i = first_separate_info; i != NULL; i = i->next)
  3038. if (i->handle == handle)
  3039. {
  3040. debug_displays[sec_enum].section.filename = i->filename;
  3041. break;
  3042. }
  3043. }
  3044. return true;
  3045. }
  3046. if (do_follow_links)
  3047. {
  3048. separate_info * i;
  3049. for (i = first_separate_info; i != NULL; i = i->next)
  3050. {
  3051. if (load_debug_section (sec_enum, i->handle))
  3052. {
  3053. debug_displays[sec_enum].section.filename = i->filename;
  3054. /* FIXME: We should check to see if any of the remaining debug info
  3055. files also contain this section, and, umm, do something about it. */
  3056. return true;
  3057. }
  3058. }
  3059. }
  3060. return false;
  3061. }
  3062. static void
  3063. introduce (struct dwarf_section * section, bool raw)
  3064. {
  3065. if (raw)
  3066. {
  3067. if (do_follow_links && section->filename)
  3068. printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
  3069. section->name, section->filename);
  3070. else
  3071. printf (_("Raw dump of debug contents of section %s:\n\n"), section->name);
  3072. }
  3073. else
  3074. {
  3075. if (do_follow_links && section->filename)
  3076. printf (_("Contents of the %s section (loaded from %s):\n\n"),
  3077. section->name, section->filename);
  3078. else
  3079. printf (_("Contents of the %s section:\n\n"), section->name);
  3080. }
  3081. }
  3082. /* Process the contents of a .debug_info section.
  3083. If do_loc is TRUE then we are scanning for location lists and dwo tags
  3084. and we do not want to display anything to the user.
  3085. If do_types is TRUE, we are processing a .debug_types section instead of
  3086. a .debug_info section.
  3087. The information displayed is restricted by the values in DWARF_START_DIE
  3088. and DWARF_CUTOFF_LEVEL.
  3089. Returns TRUE upon success. Otherwise an error or warning message is
  3090. printed and FALSE is returned. */
  3091. static bool
  3092. process_debug_info (struct dwarf_section * section,
  3093. void *file,
  3094. enum dwarf_section_display_enum abbrev_sec,
  3095. bool do_loc,
  3096. bool do_types)
  3097. {
  3098. unsigned char *start = section->start;
  3099. unsigned char *end = start + section->size;
  3100. unsigned char *section_begin;
  3101. unsigned int unit;
  3102. unsigned int num_units = 0;
  3103. /* First scan the section to get the number of comp units.
  3104. Length sanity checks are done here. */
  3105. for (section_begin = start, num_units = 0; section_begin < end;
  3106. num_units ++)
  3107. {
  3108. dwarf_vma length;
  3109. /* Read the first 4 bytes. For a 32-bit DWARF section, this
  3110. will be the length. For a 64-bit DWARF section, it'll be
  3111. the escape code 0xffffffff followed by an 8 byte length. */
  3112. SAFE_BYTE_GET_AND_INC (length, section_begin, 4, end);
  3113. if (length == 0xffffffff)
  3114. SAFE_BYTE_GET_AND_INC (length, section_begin, 8, end);
  3115. else if (length >= 0xfffffff0 && length < 0xffffffff)
  3116. {
  3117. warn (_("Reserved length value (0x%s) found in section %s\n"),
  3118. dwarf_vmatoa ("x", length), section->name);
  3119. return false;
  3120. }
  3121. /* Negative values are illegal, they may even cause infinite
  3122. looping. This can happen if we can't accurately apply
  3123. relocations to an object file, or if the file is corrupt. */
  3124. if (length > (size_t) (end - section_begin))
  3125. {
  3126. warn (_("Corrupt unit length (got 0x%s expected at most 0x%s) in section %s\n"),
  3127. dwarf_vmatoa ("x", length),
  3128. dwarf_vmatoa ("x", end - section_begin),
  3129. section->name);
  3130. return false;
  3131. }
  3132. section_begin += length;
  3133. }
  3134. if (num_units == 0)
  3135. {
  3136. error (_("No comp units in %s section ?\n"), section->name);
  3137. return false;
  3138. }
  3139. if ((do_loc || do_debug_loc || do_debug_ranges)
  3140. && num_debug_info_entries == 0
  3141. && ! do_types)
  3142. {
  3143. /* Then allocate an array to hold the information. */
  3144. debug_information = (debug_info *) cmalloc (num_units,
  3145. sizeof (* debug_information));
  3146. if (debug_information == NULL)
  3147. {
  3148. error (_("Not enough memory for a debug info array of %u entries\n"),
  3149. num_units);
  3150. alloc_num_debug_info_entries = num_debug_info_entries = 0;
  3151. return false;
  3152. }
  3153. /* PR 17531: file: 92ca3797.
  3154. We cannot rely upon the debug_information array being initialised
  3155. before it is used. A corrupt file could easily contain references
  3156. to a unit for which information has not been made available. So
  3157. we ensure that the array is zeroed here. */
  3158. memset (debug_information, 0, num_units * sizeof (*debug_information));
  3159. alloc_num_debug_info_entries = num_units;
  3160. }
  3161. if (!do_loc)
  3162. {
  3163. load_debug_section_with_follow (str, file);
  3164. load_debug_section_with_follow (line_str, file);
  3165. load_debug_section_with_follow (str_dwo, file);
  3166. load_debug_section_with_follow (str_index, file);
  3167. load_debug_section_with_follow (str_index_dwo, file);
  3168. load_debug_section_with_follow (debug_addr, file);
  3169. }
  3170. load_debug_section_with_follow (abbrev_sec, file);
  3171. load_debug_section_with_follow (loclists, file);
  3172. load_debug_section_with_follow (rnglists, file);
  3173. if (debug_displays [abbrev_sec].section.start == NULL)
  3174. {
  3175. warn (_("Unable to locate %s section!\n"),
  3176. debug_displays [abbrev_sec].section.uncompressed_name);
  3177. return false;
  3178. }
  3179. if (!do_loc && dwarf_start_die == 0)
  3180. introduce (section, false);
  3181. free_all_abbrevs ();
  3182. free (cu_abbrev_map);
  3183. cu_abbrev_map = NULL;
  3184. next_free_abbrev_map_entry = 0;
  3185. /* In order to be able to resolve DW_FORM_ref_attr forms we need
  3186. to load *all* of the abbrevs for all CUs in this .debug_info
  3187. section. This does effectively mean that we (partially) read
  3188. every CU header twice. */
  3189. for (section_begin = start; start < end;)
  3190. {
  3191. DWARF2_Internal_CompUnit compunit;
  3192. unsigned char * hdrptr;
  3193. dwarf_vma abbrev_base;
  3194. size_t abbrev_size;
  3195. dwarf_vma cu_offset;
  3196. unsigned int offset_size;
  3197. struct cu_tu_set * this_set;
  3198. abbrev_list * list;
  3199. unsigned char *end_cu;
  3200. hdrptr = start;
  3201. cu_offset = start - section_begin;
  3202. SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
  3203. if (compunit.cu_length == 0xffffffff)
  3204. {
  3205. SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
  3206. offset_size = 8;
  3207. }
  3208. else
  3209. offset_size = 4;
  3210. end_cu = hdrptr + compunit.cu_length;
  3211. SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu);
  3212. this_set = find_cu_tu_set_v2 (cu_offset, do_types);
  3213. if (compunit.cu_version < 5)
  3214. {
  3215. compunit.cu_unit_type = DW_UT_compile;
  3216. /* Initialize it due to a false compiler warning. */
  3217. compunit.cu_pointer_size = -1;
  3218. }
  3219. else
  3220. {
  3221. SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu);
  3222. do_types = (compunit.cu_unit_type == DW_UT_type);
  3223. SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu);
  3224. }
  3225. SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size,
  3226. end_cu);
  3227. if (compunit.cu_unit_type == DW_UT_split_compile
  3228. || compunit.cu_unit_type == DW_UT_skeleton)
  3229. {
  3230. uint64_t dwo_id;
  3231. SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu);
  3232. }
  3233. if (this_set == NULL)
  3234. {
  3235. abbrev_base = 0;
  3236. abbrev_size = debug_displays [abbrev_sec].section.size;
  3237. }
  3238. else
  3239. {
  3240. abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
  3241. abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
  3242. }
  3243. list = find_abbrev_list_by_abbrev_offset (abbrev_base,
  3244. compunit.cu_abbrev_offset);
  3245. if (list == NULL)
  3246. {
  3247. unsigned char * next;
  3248. list = new_abbrev_list (abbrev_base,
  3249. compunit.cu_abbrev_offset);
  3250. next = process_abbrev_set (&debug_displays[abbrev_sec].section,
  3251. abbrev_base, abbrev_size,
  3252. compunit.cu_abbrev_offset, list);
  3253. list->start_of_next_abbrevs = next;
  3254. }
  3255. start = end_cu;
  3256. record_abbrev_list_for_cu (cu_offset, start - section_begin, list);
  3257. }
  3258. for (start = section_begin, unit = 0; start < end; unit++)
  3259. {
  3260. DWARF2_Internal_CompUnit compunit;
  3261. unsigned char *hdrptr;
  3262. unsigned char *tags;
  3263. int level, last_level, saved_level;
  3264. dwarf_vma cu_offset;
  3265. unsigned int offset_size;
  3266. dwarf_vma signature = 0;
  3267. dwarf_vma type_offset = 0;
  3268. struct cu_tu_set *this_set;
  3269. dwarf_vma abbrev_base;
  3270. size_t abbrev_size;
  3271. abbrev_list * list = NULL;
  3272. unsigned char *end_cu;
  3273. hdrptr = start;
  3274. cu_offset = start - section_begin;
  3275. SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
  3276. if (compunit.cu_length == 0xffffffff)
  3277. {
  3278. SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
  3279. offset_size = 8;
  3280. }
  3281. else
  3282. offset_size = 4;
  3283. end_cu = hdrptr + compunit.cu_length;
  3284. SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu);
  3285. this_set = find_cu_tu_set_v2 (cu_offset, do_types);
  3286. if (compunit.cu_version < 5)
  3287. {
  3288. compunit.cu_unit_type = DW_UT_compile;
  3289. /* Initialize it due to a false compiler warning. */
  3290. compunit.cu_pointer_size = -1;
  3291. }
  3292. else
  3293. {
  3294. SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu);
  3295. do_types = (compunit.cu_unit_type == DW_UT_type);
  3296. SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu);
  3297. }
  3298. SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end_cu);
  3299. if (this_set == NULL)
  3300. {
  3301. abbrev_base = 0;
  3302. abbrev_size = debug_displays [abbrev_sec].section.size;
  3303. }
  3304. else
  3305. {
  3306. abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
  3307. abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
  3308. }
  3309. if (compunit.cu_version < 5)
  3310. SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu);
  3311. bool do_dwo_id = false;
  3312. uint64_t dwo_id = 0;
  3313. if (compunit.cu_unit_type == DW_UT_split_compile
  3314. || compunit.cu_unit_type == DW_UT_skeleton)
  3315. {
  3316. SAFE_BYTE_GET_AND_INC (dwo_id, hdrptr, 8, end_cu);
  3317. do_dwo_id = true;
  3318. }
  3319. /* PR 17512: file: 001-108546-0.001:0.1. */
  3320. if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
  3321. {
  3322. warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
  3323. compunit.cu_pointer_size, offset_size);
  3324. compunit.cu_pointer_size = offset_size;
  3325. }
  3326. if (do_types)
  3327. {
  3328. SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, end_cu);
  3329. SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end_cu);
  3330. }
  3331. if (dwarf_start_die >= (size_t) (end_cu - section_begin))
  3332. {
  3333. start = end_cu;
  3334. continue;
  3335. }
  3336. if ((do_loc || do_debug_loc || do_debug_ranges)
  3337. && num_debug_info_entries == 0
  3338. && alloc_num_debug_info_entries > unit
  3339. && ! do_types)
  3340. {
  3341. debug_information [unit].cu_offset = cu_offset;
  3342. debug_information [unit].pointer_size
  3343. = compunit.cu_pointer_size;
  3344. debug_information [unit].offset_size = offset_size;
  3345. debug_information [unit].dwarf_version = compunit.cu_version;
  3346. debug_information [unit].base_address = 0;
  3347. debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
  3348. debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
  3349. debug_information [unit].loc_offsets = NULL;
  3350. debug_information [unit].have_frame_base = NULL;
  3351. debug_information [unit].max_loc_offsets = 0;
  3352. debug_information [unit].num_loc_offsets = 0;
  3353. debug_information [unit].loclists_base = 0;
  3354. debug_information [unit].range_lists = NULL;
  3355. debug_information [unit].max_range_lists= 0;
  3356. debug_information [unit].num_range_lists = 0;
  3357. }
  3358. if (!do_loc && dwarf_start_die == 0)
  3359. {
  3360. printf (_(" Compilation Unit @ offset 0x%s:\n"),
  3361. dwarf_vmatoa ("x", cu_offset));
  3362. printf (_(" Length: 0x%s (%s)\n"),
  3363. dwarf_vmatoa ("x", compunit.cu_length),
  3364. offset_size == 8 ? "64-bit" : "32-bit");
  3365. printf (_(" Version: %d\n"), compunit.cu_version);
  3366. if (compunit.cu_version >= 5)
  3367. {
  3368. const char *name = get_DW_UT_name (compunit.cu_unit_type);
  3369. printf (_(" Unit Type: %s (%x)\n"),
  3370. name ? name : "???",
  3371. compunit.cu_unit_type);
  3372. }
  3373. printf (_(" Abbrev Offset: 0x%s\n"),
  3374. dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
  3375. printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
  3376. if (do_types)
  3377. {
  3378. printf (_(" Signature: 0x%s\n"),
  3379. dwarf_vmatoa ("x", signature));
  3380. printf (_(" Type Offset: 0x%s\n"),
  3381. dwarf_vmatoa ("x", type_offset));
  3382. }
  3383. if (do_dwo_id)
  3384. printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id));
  3385. if (this_set != NULL)
  3386. {
  3387. dwarf_vma *offsets = this_set->section_offsets;
  3388. size_t *sizes = this_set->section_sizes;
  3389. printf (_(" Section contributions:\n"));
  3390. printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
  3391. dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
  3392. dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
  3393. printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
  3394. dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
  3395. dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
  3396. printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
  3397. dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
  3398. dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
  3399. printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
  3400. dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
  3401. dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
  3402. }
  3403. }
  3404. tags = hdrptr;
  3405. start = end_cu;
  3406. if (compunit.cu_version < 2 || compunit.cu_version > 5)
  3407. {
  3408. warn (_("CU at offset %s contains corrupt or "
  3409. "unsupported version number: %d.\n"),
  3410. dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
  3411. continue;
  3412. }
  3413. if (compunit.cu_unit_type != DW_UT_compile
  3414. && compunit.cu_unit_type != DW_UT_partial
  3415. && compunit.cu_unit_type != DW_UT_type
  3416. && compunit.cu_unit_type != DW_UT_split_compile
  3417. && compunit.cu_unit_type != DW_UT_skeleton)
  3418. {
  3419. warn (_("CU at offset %s contains corrupt or "
  3420. "unsupported unit type: %d.\n"),
  3421. dwarf_vmatoa ("x", cu_offset), compunit.cu_unit_type);
  3422. continue;
  3423. }
  3424. /* Process the abbrevs used by this compilation unit. */
  3425. list = find_abbrev_list_by_abbrev_offset (abbrev_base,
  3426. compunit.cu_abbrev_offset);
  3427. if (list == NULL)
  3428. {
  3429. unsigned char *next;
  3430. list = new_abbrev_list (abbrev_base,
  3431. compunit.cu_abbrev_offset);
  3432. next = process_abbrev_set (&debug_displays[abbrev_sec].section,
  3433. abbrev_base, abbrev_size,
  3434. compunit.cu_abbrev_offset, list);
  3435. list->start_of_next_abbrevs = next;
  3436. }
  3437. level = 0;
  3438. last_level = level;
  3439. saved_level = -1;
  3440. while (tags < start)
  3441. {
  3442. unsigned long abbrev_number;
  3443. unsigned long die_offset;
  3444. abbrev_entry *entry;
  3445. abbrev_attr *attr;
  3446. int do_printing = 1;
  3447. die_offset = tags - section_begin;
  3448. READ_ULEB (abbrev_number, tags, start);
  3449. /* A null DIE marks the end of a list of siblings or it may also be
  3450. a section padding. */
  3451. if (abbrev_number == 0)
  3452. {
  3453. /* Check if it can be a section padding for the last CU. */
  3454. if (level == 0 && start == end)
  3455. {
  3456. unsigned char *chk;
  3457. for (chk = tags; chk < start; chk++)
  3458. if (*chk != 0)
  3459. break;
  3460. if (chk == start)
  3461. break;
  3462. }
  3463. if (!do_loc && die_offset >= dwarf_start_die
  3464. && (dwarf_cutoff_level == -1
  3465. || level < dwarf_cutoff_level))
  3466. printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
  3467. level, die_offset);
  3468. --level;
  3469. if (level < 0)
  3470. {
  3471. static unsigned num_bogus_warns = 0;
  3472. if (num_bogus_warns < 3)
  3473. {
  3474. warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
  3475. die_offset, section->name);
  3476. num_bogus_warns ++;
  3477. if (num_bogus_warns == 3)
  3478. warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
  3479. }
  3480. }
  3481. if (dwarf_start_die != 0 && level < saved_level)
  3482. return true;
  3483. continue;
  3484. }
  3485. if (!do_loc)
  3486. {
  3487. if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
  3488. do_printing = 0;
  3489. else
  3490. {
  3491. if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
  3492. saved_level = level;
  3493. do_printing = (dwarf_cutoff_level == -1
  3494. || level < dwarf_cutoff_level);
  3495. if (do_printing)
  3496. printf (_(" <%d><%lx>: Abbrev Number: %lu"),
  3497. level, die_offset, abbrev_number);
  3498. else if (dwarf_cutoff_level == -1
  3499. || last_level < dwarf_cutoff_level)
  3500. printf (_(" <%d><%lx>: ...\n"), level, die_offset);
  3501. last_level = level;
  3502. }
  3503. }
  3504. /* Scan through the abbreviation list until we reach the
  3505. correct entry. */
  3506. if (list == NULL)
  3507. continue;
  3508. for (entry = list->first_abbrev; entry != NULL; entry = entry->next)
  3509. if (entry->number == abbrev_number)
  3510. break;
  3511. if (entry == NULL)
  3512. {
  3513. if (!do_loc && do_printing)
  3514. {
  3515. printf ("\n");
  3516. fflush (stdout);
  3517. }
  3518. warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
  3519. die_offset, abbrev_number);
  3520. return false;
  3521. }
  3522. if (!do_loc && do_printing)
  3523. printf (" (%s)\n", get_TAG_name (entry->tag));
  3524. switch (entry->tag)
  3525. {
  3526. default:
  3527. need_base_address = 0;
  3528. break;
  3529. case DW_TAG_compile_unit:
  3530. need_base_address = 1;
  3531. need_dwo_info = do_loc;
  3532. break;
  3533. case DW_TAG_entry_point:
  3534. case DW_TAG_subprogram:
  3535. need_base_address = 0;
  3536. /* Assuming that there is no DW_AT_frame_base. */
  3537. have_frame_base = 0;
  3538. break;
  3539. }
  3540. debug_info *debug_info_p =
  3541. (debug_information && unit < alloc_num_debug_info_entries)
  3542. ? debug_information + unit : NULL;
  3543. assert (!debug_info_p
  3544. || (debug_info_p->num_loc_offsets
  3545. == debug_info_p->num_loc_views));
  3546. for (attr = entry->first_attr;
  3547. attr && attr->attribute;
  3548. attr = attr->next)
  3549. {
  3550. if (! do_loc && do_printing)
  3551. /* Show the offset from where the tag was extracted. */
  3552. printf (" <%lx>", (unsigned long)(tags - section_begin));
  3553. tags = read_and_display_attr (attr->attribute,
  3554. attr->form,
  3555. attr->implicit_const,
  3556. section_begin,
  3557. tags,
  3558. start,
  3559. cu_offset,
  3560. compunit.cu_pointer_size,
  3561. offset_size,
  3562. compunit.cu_version,
  3563. debug_info_p,
  3564. do_loc || ! do_printing,
  3565. section,
  3566. this_set,
  3567. level);
  3568. }
  3569. /* If a locview attribute appears before a location one,
  3570. make sure we don't associate it with an earlier
  3571. loclist. */
  3572. if (debug_info_p)
  3573. switch (debug_info_p->num_loc_offsets - debug_info_p->num_loc_views)
  3574. {
  3575. case 1:
  3576. debug_info_p->loc_views [debug_info_p->num_loc_views] = vm1;
  3577. debug_info_p->num_loc_views++;
  3578. assert (debug_info_p->num_loc_views
  3579. == debug_info_p->num_loc_offsets);
  3580. break;
  3581. case 0:
  3582. break;
  3583. case -1:
  3584. warn(_("DIE has locviews without loclist\n"));
  3585. debug_info_p->num_loc_views--;
  3586. break;
  3587. default:
  3588. assert (0);
  3589. }
  3590. if (entry->children)
  3591. ++level;
  3592. }
  3593. }
  3594. /* Set num_debug_info_entries here so that it can be used to check if
  3595. we need to process .debug_loc and .debug_ranges sections. */
  3596. if ((do_loc || do_debug_loc || do_debug_ranges)
  3597. && num_debug_info_entries == 0
  3598. && ! do_types)
  3599. {
  3600. if (num_units > alloc_num_debug_info_entries)
  3601. num_debug_info_entries = alloc_num_debug_info_entries;
  3602. else
  3603. num_debug_info_entries = num_units;
  3604. }
  3605. if (!do_loc)
  3606. printf ("\n");
  3607. return true;
  3608. }
  3609. /* Locate and scan the .debug_info section in the file and record the pointer
  3610. sizes and offsets for the compilation units in it. Usually an executable
  3611. will have just one pointer size, but this is not guaranteed, and so we try
  3612. not to make any assumptions. Returns zero upon failure, or the number of
  3613. compilation units upon success. */
  3614. static unsigned int
  3615. load_debug_info (void * file)
  3616. {
  3617. /* If we have already tried and failed to load the .debug_info
  3618. section then do not bother to repeat the task. */
  3619. if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
  3620. return 0;
  3621. /* If we already have the information there is nothing else to do. */
  3622. if (num_debug_info_entries > 0)
  3623. return num_debug_info_entries;
  3624. /* If this is a DWARF package file, load the CU and TU indexes. */
  3625. (void) load_cu_tu_indexes (file);
  3626. if (load_debug_section_with_follow (info, file)
  3627. && process_debug_info (&debug_displays [info].section, file, abbrev, true, false))
  3628. return num_debug_info_entries;
  3629. if (load_debug_section_with_follow (info_dwo, file)
  3630. && process_debug_info (&debug_displays [info_dwo].section, file,
  3631. abbrev_dwo, true, false))
  3632. return num_debug_info_entries;
  3633. num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
  3634. return 0;
  3635. }
  3636. /* Read a DWARF .debug_line section header starting at DATA.
  3637. Upon success returns an updated DATA pointer and the LINFO
  3638. structure and the END_OF_SEQUENCE pointer will be filled in.
  3639. Otherwise returns NULL. */
  3640. static unsigned char *
  3641. read_debug_line_header (struct dwarf_section * section,
  3642. unsigned char * data,
  3643. unsigned char * end,
  3644. DWARF2_Internal_LineInfo * linfo,
  3645. unsigned char ** end_of_sequence)
  3646. {
  3647. unsigned char *hdrptr;
  3648. /* Extract information from the Line Number Program Header.
  3649. (section 6.2.4 in the Dwarf3 doc). */
  3650. hdrptr = data;
  3651. /* Get and check the length of the block. */
  3652. SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
  3653. if (linfo->li_length == 0xffffffff)
  3654. {
  3655. /* This section is 64-bit DWARF 3. */
  3656. SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
  3657. linfo->li_offset_size = 8;
  3658. }
  3659. else
  3660. linfo->li_offset_size = 4;
  3661. if (linfo->li_length > (size_t) (end - hdrptr))
  3662. {
  3663. /* If the length field has a relocation against it, then we should
  3664. not complain if it is inaccurate (and probably negative). This
  3665. happens in object files when the .debug_line section is actually
  3666. comprised of several different .debug_line.* sections, (some of
  3667. which may be removed by linker garbage collection), and a relocation
  3668. is used to compute the correct length once that is done. */
  3669. if (reloc_at (section, (hdrptr - section->start) - linfo->li_offset_size))
  3670. {
  3671. linfo->li_length = end - hdrptr;
  3672. }
  3673. else
  3674. {
  3675. warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
  3676. (long) linfo->li_length);
  3677. return NULL;
  3678. }
  3679. }
  3680. end = hdrptr + linfo->li_length;
  3681. /* Get and check the version number. */
  3682. SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
  3683. if (linfo->li_version != 2
  3684. && linfo->li_version != 3
  3685. && linfo->li_version != 4
  3686. && linfo->li_version != 5)
  3687. {
  3688. warn (_("Only DWARF version 2, 3, 4 and 5 line info "
  3689. "is currently supported.\n"));
  3690. return NULL;
  3691. }
  3692. if (linfo->li_version >= 5)
  3693. {
  3694. SAFE_BYTE_GET_AND_INC (linfo->li_address_size, hdrptr, 1, end);
  3695. SAFE_BYTE_GET_AND_INC (linfo->li_segment_size, hdrptr, 1, end);
  3696. if (linfo->li_segment_size != 0)
  3697. {
  3698. warn (_("The %s section contains "
  3699. "unsupported segment selector size: %d.\n"),
  3700. section->name, linfo->li_segment_size);
  3701. return NULL;
  3702. }
  3703. }
  3704. SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr,
  3705. linfo->li_offset_size, end);
  3706. SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
  3707. if (linfo->li_version >= 4)
  3708. {
  3709. SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
  3710. if (linfo->li_max_ops_per_insn == 0)
  3711. {
  3712. warn (_("Invalid maximum operations per insn.\n"));
  3713. return NULL;
  3714. }
  3715. }
  3716. else
  3717. linfo->li_max_ops_per_insn = 1;
  3718. SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
  3719. SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
  3720. SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
  3721. SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
  3722. *end_of_sequence = end;
  3723. return hdrptr;
  3724. }
  3725. static unsigned char *
  3726. display_formatted_table (unsigned char *data,
  3727. unsigned char *start,
  3728. unsigned char *end,
  3729. const DWARF2_Internal_LineInfo *linfo,
  3730. struct dwarf_section *section,
  3731. bool is_dir)
  3732. {
  3733. unsigned char *format_start, format_count, *format, formati;
  3734. dwarf_vma data_count, datai;
  3735. unsigned int namepass, last_entry = 0;
  3736. const char * table_name = is_dir ? N_("Directory Table") : N_("File Name Table");
  3737. SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
  3738. if (do_checks && format_count > 5)
  3739. warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
  3740. table_name, format_count);
  3741. format_start = data;
  3742. for (formati = 0; formati < format_count; formati++)
  3743. {
  3744. SKIP_ULEB (data, end);
  3745. SKIP_ULEB (data, end);
  3746. if (data >= end)
  3747. {
  3748. warn (_("%s: Corrupt format description entry\n"), table_name);
  3749. return data;
  3750. }
  3751. }
  3752. READ_ULEB (data_count, data, end);
  3753. if (data_count == 0)
  3754. {
  3755. printf (_("\n The %s is empty.\n"), table_name);
  3756. return data;
  3757. }
  3758. else if (data >= end)
  3759. {
  3760. warn (_("%s: Corrupt entry count - expected %s but none found\n"),
  3761. table_name, dwarf_vmatoa ("x", data_count));
  3762. return data;
  3763. }
  3764. else if (format_count == 0)
  3765. {
  3766. warn (_("%s: format count is zero, but the table is not empty\n"),
  3767. table_name);
  3768. return end;
  3769. }
  3770. printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
  3771. table_name, (long) (data - start), dwarf_vmatoa ("u", data_count),
  3772. format_count);
  3773. printf (_(" Entry"));
  3774. /* Delay displaying name as the last entry for better screen layout. */
  3775. for (namepass = 0; namepass < 2; namepass++)
  3776. {
  3777. format = format_start;
  3778. for (formati = 0; formati < format_count; formati++)
  3779. {
  3780. dwarf_vma content_type;
  3781. READ_ULEB (content_type, format, end);
  3782. if ((content_type == DW_LNCT_path) == (namepass == 1))
  3783. switch (content_type)
  3784. {
  3785. case DW_LNCT_path:
  3786. printf (_("\tName"));
  3787. break;
  3788. case DW_LNCT_directory_index:
  3789. printf (_("\tDir"));
  3790. break;
  3791. case DW_LNCT_timestamp:
  3792. printf (_("\tTime"));
  3793. break;
  3794. case DW_LNCT_size:
  3795. printf (_("\tSize"));
  3796. break;
  3797. case DW_LNCT_MD5:
  3798. printf (_("\tMD5\t\t\t"));
  3799. break;
  3800. default:
  3801. printf (_("\t(Unknown format content type %s)"),
  3802. dwarf_vmatoa ("u", content_type));
  3803. }
  3804. SKIP_ULEB (format, end);
  3805. }
  3806. }
  3807. putchar ('\n');
  3808. for (datai = 0; datai < data_count; datai++)
  3809. {
  3810. unsigned char *datapass = data;
  3811. printf (" %d", last_entry++);
  3812. /* Delay displaying name as the last entry for better screen layout. */
  3813. for (namepass = 0; namepass < 2; namepass++)
  3814. {
  3815. format = format_start;
  3816. data = datapass;
  3817. for (formati = 0; formati < format_count; formati++)
  3818. {
  3819. dwarf_vma content_type, form;
  3820. READ_ULEB (content_type, format, end);
  3821. READ_ULEB (form, format, end);
  3822. data = read_and_display_attr_value (0, form, 0, start, data, end,
  3823. 0, 0, linfo->li_offset_size,
  3824. linfo->li_version, NULL,
  3825. ((content_type == DW_LNCT_path) != (namepass == 1)),
  3826. section, NULL, '\t', -1);
  3827. }
  3828. }
  3829. if (data >= end && (datai < data_count - 1))
  3830. {
  3831. warn (_("\n%s: Corrupt entries list\n"), table_name);
  3832. return data;
  3833. }
  3834. putchar ('\n');
  3835. }
  3836. return data;
  3837. }
  3838. static int
  3839. display_debug_sup (struct dwarf_section * section,
  3840. void * file ATTRIBUTE_UNUSED)
  3841. {
  3842. unsigned char * start = section->start;
  3843. unsigned char * end = section->start + section->size;
  3844. unsigned int version;
  3845. char is_supplementary;
  3846. const unsigned char * sup_filename;
  3847. size_t sup_filename_len;
  3848. unsigned int num_read;
  3849. int status;
  3850. dwarf_vma checksum_len;
  3851. introduce (section, true);
  3852. if (section->size < 4)
  3853. {
  3854. error (_("corrupt .debug_sup section: size is too small\n"));
  3855. return 0;
  3856. }
  3857. /* Read the data. */
  3858. SAFE_BYTE_GET_AND_INC (version, start, 2, end);
  3859. if (version < 5)
  3860. warn (_("corrupt .debug_sup section: version < 5"));
  3861. SAFE_BYTE_GET_AND_INC (is_supplementary, start, 1, end);
  3862. if (is_supplementary != 0 && is_supplementary != 1)
  3863. warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
  3864. sup_filename = start;
  3865. if (is_supplementary && sup_filename[0] != 0)
  3866. warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
  3867. sup_filename_len = strnlen ((const char *) start, end - start);
  3868. if (sup_filename_len == (size_t) (end - start))
  3869. {
  3870. error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
  3871. return 0;
  3872. }
  3873. start += sup_filename_len + 1;
  3874. checksum_len = read_leb128 (start, end, false /* unsigned */, & num_read, & status);
  3875. if (status)
  3876. {
  3877. error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
  3878. checksum_len = 0;
  3879. }
  3880. start += num_read;
  3881. if (checksum_len > (dwarf_vma) (end - start))
  3882. {
  3883. error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
  3884. checksum_len = end - start;
  3885. }
  3886. else if (checksum_len < (dwarf_vma) (end - start))
  3887. {
  3888. warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
  3889. (long) ((end - start) - checksum_len));
  3890. }
  3891. printf (_(" Version: %u\n"), version);
  3892. printf (_(" Is Supp: %u\n"), is_supplementary);
  3893. printf (_(" Filename: %s\n"), sup_filename);
  3894. printf (_(" Checksum Len: %lu\n"), (long) checksum_len);
  3895. if (checksum_len > 0)
  3896. {
  3897. printf (_(" Checksum: "));
  3898. while (checksum_len--)
  3899. printf ("0x%x ", * start++ );
  3900. printf ("\n");
  3901. }
  3902. return 1;
  3903. }
  3904. static int
  3905. display_debug_lines_raw (struct dwarf_section * section,
  3906. unsigned char * data,
  3907. unsigned char * end,
  3908. void * file)
  3909. {
  3910. unsigned char *start = section->start;
  3911. int verbose_view = 0;
  3912. introduce (section, true);
  3913. while (data < end)
  3914. {
  3915. static DWARF2_Internal_LineInfo saved_linfo;
  3916. DWARF2_Internal_LineInfo linfo;
  3917. unsigned char *standard_opcodes;
  3918. unsigned char *end_of_sequence;
  3919. int i;
  3920. if (startswith (section->name, ".debug_line.")
  3921. /* Note: the following does not apply to .debug_line.dwo sections.
  3922. These are full debug_line sections. */
  3923. && strcmp (section->name, ".debug_line.dwo") != 0)
  3924. {
  3925. /* Sections named .debug_line.<foo> are fragments of a .debug_line
  3926. section containing just the Line Number Statements. They are
  3927. created by the assembler and intended to be used alongside gcc's
  3928. -ffunction-sections command line option. When the linker's
  3929. garbage collection decides to discard a .text.<foo> section it
  3930. can then also discard the line number information in .debug_line.<foo>.
  3931. Since the section is a fragment it does not have the details
  3932. needed to fill out a LineInfo structure, so instead we use the
  3933. details from the last full debug_line section that we processed. */
  3934. end_of_sequence = end;
  3935. standard_opcodes = NULL;
  3936. linfo = saved_linfo;
  3937. /* PR 17531: file: 0522b371. */
  3938. if (linfo.li_line_range == 0)
  3939. {
  3940. warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
  3941. return 0;
  3942. }
  3943. reset_state_machine (linfo.li_default_is_stmt);
  3944. }
  3945. else
  3946. {
  3947. unsigned char * hdrptr;
  3948. if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
  3949. & end_of_sequence)) == NULL)
  3950. return 0;
  3951. printf (_(" Offset: 0x%lx\n"), (long)(data - start));
  3952. printf (_(" Length: %ld\n"), (long) linfo.li_length);
  3953. printf (_(" DWARF Version: %d\n"), linfo.li_version);
  3954. if (linfo.li_version >= 5)
  3955. {
  3956. printf (_(" Address size (bytes): %d\n"), linfo.li_address_size);
  3957. printf (_(" Segment selector (bytes): %d\n"), linfo.li_segment_size);
  3958. }
  3959. printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
  3960. printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
  3961. if (linfo.li_version >= 4)
  3962. printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
  3963. printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
  3964. printf (_(" Line Base: %d\n"), linfo.li_line_base);
  3965. printf (_(" Line Range: %d\n"), linfo.li_line_range);
  3966. printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
  3967. /* PR 17512: file: 1665-6428-0.004. */
  3968. if (linfo.li_line_range == 0)
  3969. {
  3970. warn (_("Line range of 0 is invalid, using 1 instead\n"));
  3971. linfo.li_line_range = 1;
  3972. }
  3973. reset_state_machine (linfo.li_default_is_stmt);
  3974. /* Display the contents of the Opcodes table. */
  3975. standard_opcodes = hdrptr;
  3976. /* PR 17512: file: 002-417945-0.004. */
  3977. if (standard_opcodes + linfo.li_opcode_base >= end)
  3978. {
  3979. warn (_("Line Base extends beyond end of section\n"));
  3980. return 0;
  3981. }
  3982. printf (_("\n Opcodes:\n"));
  3983. for (i = 1; i < linfo.li_opcode_base; i++)
  3984. printf (ngettext (" Opcode %d has %d arg\n",
  3985. " Opcode %d has %d args\n",
  3986. standard_opcodes[i - 1]),
  3987. i, standard_opcodes[i - 1]);
  3988. /* Display the contents of the Directory table. */
  3989. data = standard_opcodes + linfo.li_opcode_base - 1;
  3990. if (linfo.li_version >= 5)
  3991. {
  3992. load_debug_section_with_follow (line_str, file);
  3993. data = display_formatted_table (data, start, end, &linfo, section,
  3994. true);
  3995. data = display_formatted_table (data, start, end, &linfo, section,
  3996. false);
  3997. }
  3998. else
  3999. {
  4000. if (*data == 0)
  4001. printf (_("\n The Directory Table is empty.\n"));
  4002. else
  4003. {
  4004. unsigned int last_dir_entry = 0;
  4005. printf (_("\n The Directory Table (offset 0x%lx):\n"),
  4006. (long)(data - start));
  4007. while (data < end && *data != 0)
  4008. {
  4009. printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
  4010. data += strnlen ((char *) data, end - data);
  4011. if (data < end)
  4012. data++;
  4013. }
  4014. /* PR 17512: file: 002-132094-0.004. */
  4015. if (data >= end - 1)
  4016. break;
  4017. }
  4018. /* Skip the NUL at the end of the table. */
  4019. if (data < end)
  4020. data++;
  4021. /* Display the contents of the File Name table. */
  4022. if (data >= end || *data == 0)
  4023. printf (_("\n The File Name Table is empty.\n"));
  4024. else
  4025. {
  4026. printf (_("\n The File Name Table (offset 0x%lx):\n"),
  4027. (long)(data - start));
  4028. printf (_(" Entry\tDir\tTime\tSize\tName\n"));
  4029. while (data < end && *data != 0)
  4030. {
  4031. unsigned char *name;
  4032. dwarf_vma val;
  4033. printf (" %d\t", ++state_machine_regs.last_file_entry);
  4034. name = data;
  4035. data += strnlen ((char *) data, end - data);
  4036. if (data < end)
  4037. data++;
  4038. READ_ULEB (val, data, end);
  4039. printf ("%s\t", dwarf_vmatoa ("u", val));
  4040. READ_ULEB (val, data, end);
  4041. printf ("%s\t", dwarf_vmatoa ("u", val));
  4042. READ_ULEB (val, data, end);
  4043. printf ("%s\t", dwarf_vmatoa ("u", val));
  4044. printf ("%.*s\n", (int)(end - name), name);
  4045. if (data >= end)
  4046. {
  4047. warn (_("Corrupt file name table entry\n"));
  4048. break;
  4049. }
  4050. }
  4051. }
  4052. /* Skip the NUL at the end of the table. */
  4053. if (data < end)
  4054. data++;
  4055. }
  4056. putchar ('\n');
  4057. saved_linfo = linfo;
  4058. }
  4059. /* Now display the statements. */
  4060. if (data >= end_of_sequence)
  4061. printf (_(" No Line Number Statements.\n"));
  4062. else
  4063. {
  4064. printf (_(" Line Number Statements:\n"));
  4065. while (data < end_of_sequence)
  4066. {
  4067. unsigned char op_code;
  4068. dwarf_signed_vma adv;
  4069. dwarf_vma uladv;
  4070. printf (" [0x%08lx]", (long)(data - start));
  4071. op_code = *data++;
  4072. if (op_code >= linfo.li_opcode_base)
  4073. {
  4074. op_code -= linfo.li_opcode_base;
  4075. uladv = (op_code / linfo.li_line_range);
  4076. if (linfo.li_max_ops_per_insn == 1)
  4077. {
  4078. uladv *= linfo.li_min_insn_length;
  4079. state_machine_regs.address += uladv;
  4080. if (uladv)
  4081. state_machine_regs.view = 0;
  4082. printf (_(" Special opcode %d: "
  4083. "advance Address by %s to 0x%s%s"),
  4084. op_code, dwarf_vmatoa ("u", uladv),
  4085. dwarf_vmatoa ("x", state_machine_regs.address),
  4086. verbose_view && uladv
  4087. ? _(" (reset view)") : "");
  4088. }
  4089. else
  4090. {
  4091. unsigned addrdelta
  4092. = ((state_machine_regs.op_index + uladv)
  4093. / linfo.li_max_ops_per_insn)
  4094. * linfo.li_min_insn_length;
  4095. state_machine_regs.address += addrdelta;
  4096. state_machine_regs.op_index
  4097. = (state_machine_regs.op_index + uladv)
  4098. % linfo.li_max_ops_per_insn;
  4099. if (addrdelta)
  4100. state_machine_regs.view = 0;
  4101. printf (_(" Special opcode %d: "
  4102. "advance Address by %s to 0x%s[%d]%s"),
  4103. op_code, dwarf_vmatoa ("u", uladv),
  4104. dwarf_vmatoa ("x", state_machine_regs.address),
  4105. state_machine_regs.op_index,
  4106. verbose_view && addrdelta
  4107. ? _(" (reset view)") : "");
  4108. }
  4109. adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
  4110. state_machine_regs.line += adv;
  4111. printf (_(" and Line by %s to %d"),
  4112. dwarf_vmatoa ("d", adv), state_machine_regs.line);
  4113. if (verbose_view || state_machine_regs.view)
  4114. printf (_(" (view %u)\n"), state_machine_regs.view);
  4115. else
  4116. putchar ('\n');
  4117. state_machine_regs.view++;
  4118. }
  4119. else
  4120. switch (op_code)
  4121. {
  4122. case DW_LNS_extended_op:
  4123. data += process_extended_line_op (data,
  4124. linfo.li_default_is_stmt,
  4125. end);
  4126. break;
  4127. case DW_LNS_copy:
  4128. printf (_(" Copy"));
  4129. if (verbose_view || state_machine_regs.view)
  4130. printf (_(" (view %u)\n"), state_machine_regs.view);
  4131. else
  4132. putchar ('\n');
  4133. state_machine_regs.view++;
  4134. break;
  4135. case DW_LNS_advance_pc:
  4136. READ_ULEB (uladv, data, end);
  4137. if (linfo.li_max_ops_per_insn == 1)
  4138. {
  4139. uladv *= linfo.li_min_insn_length;
  4140. state_machine_regs.address += uladv;
  4141. if (uladv)
  4142. state_machine_regs.view = 0;
  4143. printf (_(" Advance PC by %s to 0x%s%s\n"),
  4144. dwarf_vmatoa ("u", uladv),
  4145. dwarf_vmatoa ("x", state_machine_regs.address),
  4146. verbose_view && uladv
  4147. ? _(" (reset view)") : "");
  4148. }
  4149. else
  4150. {
  4151. unsigned addrdelta
  4152. = ((state_machine_regs.op_index + uladv)
  4153. / linfo.li_max_ops_per_insn)
  4154. * linfo.li_min_insn_length;
  4155. state_machine_regs.address
  4156. += addrdelta;
  4157. state_machine_regs.op_index
  4158. = (state_machine_regs.op_index + uladv)
  4159. % linfo.li_max_ops_per_insn;
  4160. if (addrdelta)
  4161. state_machine_regs.view = 0;
  4162. printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
  4163. dwarf_vmatoa ("u", uladv),
  4164. dwarf_vmatoa ("x", state_machine_regs.address),
  4165. state_machine_regs.op_index,
  4166. verbose_view && addrdelta
  4167. ? _(" (reset view)") : "");
  4168. }
  4169. break;
  4170. case DW_LNS_advance_line:
  4171. READ_SLEB (adv, data, end);
  4172. state_machine_regs.line += adv;
  4173. printf (_(" Advance Line by %s to %d\n"),
  4174. dwarf_vmatoa ("d", adv),
  4175. state_machine_regs.line);
  4176. break;
  4177. case DW_LNS_set_file:
  4178. READ_ULEB (uladv, data, end);
  4179. printf (_(" Set File Name to entry %s in the File Name Table\n"),
  4180. dwarf_vmatoa ("u", uladv));
  4181. state_machine_regs.file = uladv;
  4182. break;
  4183. case DW_LNS_set_column:
  4184. READ_ULEB (uladv, data, end);
  4185. printf (_(" Set column to %s\n"),
  4186. dwarf_vmatoa ("u", uladv));
  4187. state_machine_regs.column = uladv;
  4188. break;
  4189. case DW_LNS_negate_stmt:
  4190. adv = state_machine_regs.is_stmt;
  4191. adv = ! adv;
  4192. printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
  4193. state_machine_regs.is_stmt = adv;
  4194. break;
  4195. case DW_LNS_set_basic_block:
  4196. printf (_(" Set basic block\n"));
  4197. state_machine_regs.basic_block = 1;
  4198. break;
  4199. case DW_LNS_const_add_pc:
  4200. uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
  4201. if (linfo.li_max_ops_per_insn)
  4202. {
  4203. uladv *= linfo.li_min_insn_length;
  4204. state_machine_regs.address += uladv;
  4205. if (uladv)
  4206. state_machine_regs.view = 0;
  4207. printf (_(" Advance PC by constant %s to 0x%s%s\n"),
  4208. dwarf_vmatoa ("u", uladv),
  4209. dwarf_vmatoa ("x", state_machine_regs.address),
  4210. verbose_view && uladv
  4211. ? _(" (reset view)") : "");
  4212. }
  4213. else
  4214. {
  4215. unsigned addrdelta
  4216. = ((state_machine_regs.op_index + uladv)
  4217. / linfo.li_max_ops_per_insn)
  4218. * linfo.li_min_insn_length;
  4219. state_machine_regs.address
  4220. += addrdelta;
  4221. state_machine_regs.op_index
  4222. = (state_machine_regs.op_index + uladv)
  4223. % linfo.li_max_ops_per_insn;
  4224. if (addrdelta)
  4225. state_machine_regs.view = 0;
  4226. printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
  4227. dwarf_vmatoa ("u", uladv),
  4228. dwarf_vmatoa ("x", state_machine_regs.address),
  4229. state_machine_regs.op_index,
  4230. verbose_view && addrdelta
  4231. ? _(" (reset view)") : "");
  4232. }
  4233. break;
  4234. case DW_LNS_fixed_advance_pc:
  4235. SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
  4236. state_machine_regs.address += uladv;
  4237. state_machine_regs.op_index = 0;
  4238. printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
  4239. dwarf_vmatoa ("u", uladv),
  4240. dwarf_vmatoa ("x", state_machine_regs.address));
  4241. /* Do NOT reset view. */
  4242. break;
  4243. case DW_LNS_set_prologue_end:
  4244. printf (_(" Set prologue_end to true\n"));
  4245. break;
  4246. case DW_LNS_set_epilogue_begin:
  4247. printf (_(" Set epilogue_begin to true\n"));
  4248. break;
  4249. case DW_LNS_set_isa:
  4250. READ_ULEB (uladv, data, end);
  4251. printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
  4252. break;
  4253. default:
  4254. printf (_(" Unknown opcode %d with operands: "), op_code);
  4255. if (standard_opcodes != NULL)
  4256. for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
  4257. {
  4258. READ_ULEB (uladv, data, end);
  4259. printf ("0x%s%s", dwarf_vmatoa ("x", uladv),
  4260. i == 1 ? "" : ", ");
  4261. }
  4262. putchar ('\n');
  4263. break;
  4264. }
  4265. }
  4266. putchar ('\n');
  4267. }
  4268. }
  4269. return 1;
  4270. }
  4271. typedef struct
  4272. {
  4273. unsigned char *name;
  4274. unsigned int directory_index;
  4275. unsigned int modification_date;
  4276. unsigned int length;
  4277. } File_Entry;
  4278. /* Output a decoded representation of the .debug_line section. */
  4279. static int
  4280. display_debug_lines_decoded (struct dwarf_section * section,
  4281. unsigned char * start,
  4282. unsigned char * data,
  4283. unsigned char * end,
  4284. void * fileptr)
  4285. {
  4286. static DWARF2_Internal_LineInfo saved_linfo;
  4287. introduce (section, false);
  4288. while (data < end)
  4289. {
  4290. /* This loop amounts to one iteration per compilation unit. */
  4291. DWARF2_Internal_LineInfo linfo;
  4292. unsigned char *standard_opcodes;
  4293. unsigned char *end_of_sequence;
  4294. int i;
  4295. File_Entry *file_table = NULL;
  4296. unsigned int n_files = 0;
  4297. unsigned char **directory_table = NULL;
  4298. dwarf_vma n_directories = 0;
  4299. if (startswith (section->name, ".debug_line.")
  4300. /* Note: the following does not apply to .debug_line.dwo sections.
  4301. These are full debug_line sections. */
  4302. && strcmp (section->name, ".debug_line.dwo") != 0)
  4303. {
  4304. /* See comment in display_debug_lines_raw(). */
  4305. end_of_sequence = end;
  4306. standard_opcodes = NULL;
  4307. linfo = saved_linfo;
  4308. /* PR 17531: file: 0522b371. */
  4309. if (linfo.li_line_range == 0)
  4310. {
  4311. warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
  4312. return 0;
  4313. }
  4314. reset_state_machine (linfo.li_default_is_stmt);
  4315. }
  4316. else
  4317. {
  4318. unsigned char *hdrptr;
  4319. if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
  4320. & end_of_sequence)) == NULL)
  4321. return 0;
  4322. /* PR 17531: file: 0522b371. */
  4323. if (linfo.li_line_range == 0)
  4324. {
  4325. warn (_("Line range of 0 is invalid, using 1 instead\n"));
  4326. linfo.li_line_range = 1;
  4327. }
  4328. reset_state_machine (linfo.li_default_is_stmt);
  4329. /* Save a pointer to the contents of the Opcodes table. */
  4330. standard_opcodes = hdrptr;
  4331. /* Traverse the Directory table just to count entries. */
  4332. data = standard_opcodes + linfo.li_opcode_base - 1;
  4333. /* PR 20440 */
  4334. if (data >= end)
  4335. {
  4336. warn (_("opcode base of %d extends beyond end of section\n"),
  4337. linfo.li_opcode_base);
  4338. return 0;
  4339. }
  4340. if (linfo.li_version >= 5)
  4341. {
  4342. unsigned char *format_start, format_count, *format;
  4343. dwarf_vma formati, entryi;
  4344. load_debug_section_with_follow (line_str, fileptr);
  4345. /* Skip directories format. */
  4346. SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
  4347. if (do_checks && format_count > 1)
  4348. warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
  4349. format_count);
  4350. format_start = data;
  4351. for (formati = 0; formati < format_count; formati++)
  4352. {
  4353. SKIP_ULEB (data, end);
  4354. SKIP_ULEB (data, end);
  4355. }
  4356. READ_ULEB (n_directories, data, end);
  4357. if (data >= end)
  4358. {
  4359. warn (_("Corrupt directories list\n"));
  4360. break;
  4361. }
  4362. if (n_directories == 0)
  4363. directory_table = NULL;
  4364. else
  4365. directory_table = (unsigned char **)
  4366. xmalloc (n_directories * sizeof (unsigned char *));
  4367. for (entryi = 0; entryi < n_directories; entryi++)
  4368. {
  4369. unsigned char **pathp = &directory_table[entryi];
  4370. format = format_start;
  4371. for (formati = 0; formati < format_count; formati++)
  4372. {
  4373. dwarf_vma content_type, form;
  4374. dwarf_vma uvalue;
  4375. READ_ULEB (content_type, format, end);
  4376. READ_ULEB (form, format, end);
  4377. if (data >= end)
  4378. {
  4379. warn (_("Corrupt directories list\n"));
  4380. break;
  4381. }
  4382. switch (content_type)
  4383. {
  4384. case DW_LNCT_path:
  4385. switch (form)
  4386. {
  4387. case DW_FORM_string:
  4388. *pathp = data;
  4389. break;
  4390. case DW_FORM_line_strp:
  4391. SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
  4392. end);
  4393. /* Remove const by the cast. */
  4394. *pathp = (unsigned char *)
  4395. fetch_indirect_line_string (uvalue);
  4396. break;
  4397. }
  4398. break;
  4399. }
  4400. data = read_and_display_attr_value (0, form, 0, start,
  4401. data, end, 0, 0,
  4402. linfo.li_offset_size,
  4403. linfo.li_version,
  4404. NULL, 1, section,
  4405. NULL, '\t', -1);
  4406. }
  4407. if (data >= end)
  4408. {
  4409. warn (_("Corrupt directories list\n"));
  4410. break;
  4411. }
  4412. }
  4413. /* Skip files format. */
  4414. SAFE_BYTE_GET_AND_INC (format_count, data, 1, end);
  4415. if (do_checks && format_count > 5)
  4416. warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
  4417. format_count);
  4418. format_start = data;
  4419. for (formati = 0; formati < format_count; formati++)
  4420. {
  4421. SKIP_ULEB (data, end);
  4422. SKIP_ULEB (data, end);
  4423. }
  4424. READ_ULEB (n_files, data, end);
  4425. if (data >= end && n_files > 0)
  4426. {
  4427. warn (_("Corrupt file name list\n"));
  4428. break;
  4429. }
  4430. if (n_files == 0)
  4431. file_table = NULL;
  4432. else
  4433. file_table = (File_Entry *) xcalloc (1, n_files
  4434. * sizeof (File_Entry));
  4435. for (entryi = 0; entryi < n_files; entryi++)
  4436. {
  4437. File_Entry *file = &file_table[entryi];
  4438. format = format_start;
  4439. for (formati = 0; formati < format_count; formati++)
  4440. {
  4441. dwarf_vma content_type, form;
  4442. dwarf_vma uvalue;
  4443. unsigned char *tmp;
  4444. READ_ULEB (content_type, format, end);
  4445. READ_ULEB (form, format, end);
  4446. if (data >= end)
  4447. {
  4448. warn (_("Corrupt file name list\n"));
  4449. break;
  4450. }
  4451. switch (content_type)
  4452. {
  4453. case DW_LNCT_path:
  4454. switch (form)
  4455. {
  4456. case DW_FORM_string:
  4457. file->name = data;
  4458. break;
  4459. case DW_FORM_line_strp:
  4460. SAFE_BYTE_GET (uvalue, data, linfo.li_offset_size,
  4461. end);
  4462. /* Remove const by the cast. */
  4463. file->name = (unsigned char *)
  4464. fetch_indirect_line_string (uvalue);
  4465. break;
  4466. }
  4467. break;
  4468. case DW_LNCT_directory_index:
  4469. switch (form)
  4470. {
  4471. case DW_FORM_data1:
  4472. SAFE_BYTE_GET (file->directory_index, data, 1,
  4473. end);
  4474. break;
  4475. case DW_FORM_data2:
  4476. SAFE_BYTE_GET (file->directory_index, data, 2,
  4477. end);
  4478. break;
  4479. case DW_FORM_udata:
  4480. tmp = data;
  4481. READ_ULEB (file->directory_index, tmp, end);
  4482. break;
  4483. }
  4484. break;
  4485. }
  4486. data = read_and_display_attr_value (0, form, 0, start,
  4487. data, end, 0, 0,
  4488. linfo.li_offset_size,
  4489. linfo.li_version,
  4490. NULL, 1, section,
  4491. NULL, '\t', -1);
  4492. }
  4493. if (data >= end)
  4494. {
  4495. warn (_("Corrupt file name list\n"));
  4496. break;
  4497. }
  4498. }
  4499. }
  4500. else
  4501. {
  4502. if (*data != 0)
  4503. {
  4504. unsigned char *ptr_directory_table = data;
  4505. while (data < end && *data != 0)
  4506. {
  4507. data += strnlen ((char *) data, end - data);
  4508. if (data < end)
  4509. data++;
  4510. n_directories++;
  4511. }
  4512. /* PR 20440 */
  4513. if (data >= end)
  4514. {
  4515. warn (_("directory table ends unexpectedly\n"));
  4516. n_directories = 0;
  4517. break;
  4518. }
  4519. /* Go through the directory table again to save the directories. */
  4520. directory_table = (unsigned char **)
  4521. xmalloc (n_directories * sizeof (unsigned char *));
  4522. i = 0;
  4523. while (*ptr_directory_table != 0)
  4524. {
  4525. directory_table[i] = ptr_directory_table;
  4526. ptr_directory_table
  4527. += strlen ((char *) ptr_directory_table) + 1;
  4528. i++;
  4529. }
  4530. }
  4531. /* Skip the NUL at the end of the table. */
  4532. data++;
  4533. /* Traverse the File Name table just to count the entries. */
  4534. if (data < end && *data != 0)
  4535. {
  4536. unsigned char *ptr_file_name_table = data;
  4537. while (data < end && *data != 0)
  4538. {
  4539. /* Skip Name, directory index, last modification
  4540. time and length of file. */
  4541. data += strnlen ((char *) data, end - data);
  4542. if (data < end)
  4543. data++;
  4544. SKIP_ULEB (data, end);
  4545. SKIP_ULEB (data, end);
  4546. SKIP_ULEB (data, end);
  4547. n_files++;
  4548. }
  4549. if (data >= end)
  4550. {
  4551. warn (_("file table ends unexpectedly\n"));
  4552. n_files = 0;
  4553. break;
  4554. }
  4555. /* Go through the file table again to save the strings. */
  4556. file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
  4557. i = 0;
  4558. while (*ptr_file_name_table != 0)
  4559. {
  4560. file_table[i].name = ptr_file_name_table;
  4561. ptr_file_name_table
  4562. += strlen ((char *) ptr_file_name_table) + 1;
  4563. /* We are not interested in directory, time or size. */
  4564. READ_ULEB (file_table[i].directory_index,
  4565. ptr_file_name_table, end);
  4566. READ_ULEB (file_table[i].modification_date,
  4567. ptr_file_name_table, end);
  4568. READ_ULEB (file_table[i].length,
  4569. ptr_file_name_table, end);
  4570. i++;
  4571. }
  4572. i = 0;
  4573. }
  4574. /* Skip the NUL at the end of the table. */
  4575. data++;
  4576. }
  4577. /* Print the Compilation Unit's name and a header. */
  4578. if (file_table == NULL)
  4579. printf (_("CU: No directory table\n"));
  4580. else if (directory_table == NULL)
  4581. printf (_("CU: %s:\n"), file_table[0].name);
  4582. else
  4583. {
  4584. unsigned int ix = file_table[0].directory_index;
  4585. const char *directory;
  4586. if (ix == 0)
  4587. directory = ".";
  4588. /* PR 20439 */
  4589. else if (n_directories == 0)
  4590. directory = _("<unknown>");
  4591. else if (ix > n_directories)
  4592. {
  4593. warn (_("directory index %u > number of directories %s\n"),
  4594. ix, dwarf_vmatoa ("u", n_directories));
  4595. directory = _("<corrupt>");
  4596. }
  4597. else
  4598. directory = (char *) directory_table[ix - 1];
  4599. if (do_wide)
  4600. printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
  4601. else
  4602. printf ("%s:\n", file_table[0].name);
  4603. }
  4604. if (n_files > 0)
  4605. printf (_("File name Line number Starting address View Stmt\n"));
  4606. else
  4607. printf (_("CU: Empty file name table\n"));
  4608. saved_linfo = linfo;
  4609. }
  4610. /* This loop iterates through the Dwarf Line Number Program. */
  4611. while (data < end_of_sequence)
  4612. {
  4613. unsigned char op_code;
  4614. int xop;
  4615. int adv;
  4616. unsigned long int uladv;
  4617. int is_special_opcode = 0;
  4618. op_code = *data++;
  4619. xop = op_code;
  4620. if (op_code >= linfo.li_opcode_base)
  4621. {
  4622. op_code -= linfo.li_opcode_base;
  4623. uladv = (op_code / linfo.li_line_range);
  4624. if (linfo.li_max_ops_per_insn == 1)
  4625. {
  4626. uladv *= linfo.li_min_insn_length;
  4627. state_machine_regs.address += uladv;
  4628. if (uladv)
  4629. state_machine_regs.view = 0;
  4630. }
  4631. else
  4632. {
  4633. unsigned addrdelta
  4634. = ((state_machine_regs.op_index + uladv)
  4635. / linfo.li_max_ops_per_insn)
  4636. * linfo.li_min_insn_length;
  4637. state_machine_regs.address
  4638. += addrdelta;
  4639. state_machine_regs.op_index
  4640. = (state_machine_regs.op_index + uladv)
  4641. % linfo.li_max_ops_per_insn;
  4642. if (addrdelta)
  4643. state_machine_regs.view = 0;
  4644. }
  4645. adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
  4646. state_machine_regs.line += adv;
  4647. is_special_opcode = 1;
  4648. /* Increment view after printing this row. */
  4649. }
  4650. else
  4651. switch (op_code)
  4652. {
  4653. case DW_LNS_extended_op:
  4654. {
  4655. unsigned int ext_op_code_len;
  4656. unsigned char ext_op_code;
  4657. unsigned char *op_code_end;
  4658. unsigned char *op_code_data = data;
  4659. READ_ULEB (ext_op_code_len, op_code_data, end_of_sequence);
  4660. op_code_end = op_code_data + ext_op_code_len;
  4661. if (ext_op_code_len == 0 || op_code_end > end_of_sequence)
  4662. {
  4663. warn (_("Badly formed extended line op encountered!\n"));
  4664. break;
  4665. }
  4666. ext_op_code = *op_code_data++;
  4667. xop = ext_op_code;
  4668. xop = -xop;
  4669. switch (ext_op_code)
  4670. {
  4671. case DW_LNE_end_sequence:
  4672. /* Reset stuff after printing this row. */
  4673. break;
  4674. case DW_LNE_set_address:
  4675. SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
  4676. op_code_data,
  4677. op_code_end - op_code_data,
  4678. op_code_end);
  4679. state_machine_regs.op_index = 0;
  4680. state_machine_regs.view = 0;
  4681. break;
  4682. case DW_LNE_define_file:
  4683. file_table = (File_Entry *) xrealloc
  4684. (file_table, (n_files + 1) * sizeof (File_Entry));
  4685. ++state_machine_regs.last_file_entry;
  4686. /* Source file name. */
  4687. file_table[n_files].name = op_code_data;
  4688. op_code_data += strlen ((char *) op_code_data) + 1;
  4689. /* Directory index. */
  4690. READ_ULEB (file_table[n_files].directory_index,
  4691. op_code_data, op_code_end);
  4692. /* Last modification time. */
  4693. READ_ULEB (file_table[n_files].modification_date,
  4694. op_code_data, op_code_end);
  4695. /* File length. */
  4696. READ_ULEB (file_table[n_files].length,
  4697. op_code_data, op_code_end);
  4698. n_files++;
  4699. break;
  4700. case DW_LNE_set_discriminator:
  4701. case DW_LNE_HP_set_sequence:
  4702. /* Simply ignored. */
  4703. break;
  4704. default:
  4705. printf (_("UNKNOWN (%u): length %ld\n"),
  4706. ext_op_code, (long int) (op_code_data - data));
  4707. break;
  4708. }
  4709. data = op_code_end;
  4710. break;
  4711. }
  4712. case DW_LNS_copy:
  4713. /* Increment view after printing this row. */
  4714. break;
  4715. case DW_LNS_advance_pc:
  4716. READ_ULEB (uladv, data, end);
  4717. if (linfo.li_max_ops_per_insn == 1)
  4718. {
  4719. uladv *= linfo.li_min_insn_length;
  4720. state_machine_regs.address += uladv;
  4721. if (uladv)
  4722. state_machine_regs.view = 0;
  4723. }
  4724. else
  4725. {
  4726. unsigned addrdelta
  4727. = ((state_machine_regs.op_index + uladv)
  4728. / linfo.li_max_ops_per_insn)
  4729. * linfo.li_min_insn_length;
  4730. state_machine_regs.address
  4731. += addrdelta;
  4732. state_machine_regs.op_index
  4733. = (state_machine_regs.op_index + uladv)
  4734. % linfo.li_max_ops_per_insn;
  4735. if (addrdelta)
  4736. state_machine_regs.view = 0;
  4737. }
  4738. break;
  4739. case DW_LNS_advance_line:
  4740. READ_SLEB (adv, data, end);
  4741. state_machine_regs.line += adv;
  4742. break;
  4743. case DW_LNS_set_file:
  4744. READ_ULEB (uladv, data, end);
  4745. state_machine_regs.file = uladv;
  4746. {
  4747. unsigned file = state_machine_regs.file;
  4748. unsigned dir;
  4749. if (linfo.li_version < 5)
  4750. --file;
  4751. if (file_table == NULL || n_files == 0)
  4752. printf (_("\n [Use file table entry %d]\n"), file);
  4753. /* PR 20439 */
  4754. else if (file >= n_files)
  4755. {
  4756. warn (_("file index %u > number of files %u\n"), file, n_files);
  4757. printf (_("\n <over large file table index %u>"), file);
  4758. }
  4759. else if ((dir = file_table[file].directory_index) == 0)
  4760. /* If directory index is 0, that means current directory. */
  4761. printf ("\n./%s:[++]\n", file_table[file].name);
  4762. else if (directory_table == NULL || n_directories == 0)
  4763. printf (_("\n [Use file %s in directory table entry %d]\n"),
  4764. file_table[file].name, dir);
  4765. /* PR 20439 */
  4766. else if (dir > n_directories)
  4767. {
  4768. warn (_("directory index %u > number of directories %s\n"),
  4769. dir, dwarf_vmatoa ("u", n_directories));
  4770. printf (_("\n <over large directory table entry %u>\n"), dir);
  4771. }
  4772. else
  4773. printf ("\n%s/%s:\n",
  4774. /* The directory index starts counting at 1. */
  4775. directory_table[dir - 1], file_table[file].name);
  4776. }
  4777. break;
  4778. case DW_LNS_set_column:
  4779. READ_ULEB (uladv, data, end);
  4780. state_machine_regs.column = uladv;
  4781. break;
  4782. case DW_LNS_negate_stmt:
  4783. adv = state_machine_regs.is_stmt;
  4784. adv = ! adv;
  4785. state_machine_regs.is_stmt = adv;
  4786. break;
  4787. case DW_LNS_set_basic_block:
  4788. state_machine_regs.basic_block = 1;
  4789. break;
  4790. case DW_LNS_const_add_pc:
  4791. uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
  4792. if (linfo.li_max_ops_per_insn == 1)
  4793. {
  4794. uladv *= linfo.li_min_insn_length;
  4795. state_machine_regs.address += uladv;
  4796. if (uladv)
  4797. state_machine_regs.view = 0;
  4798. }
  4799. else
  4800. {
  4801. unsigned addrdelta
  4802. = ((state_machine_regs.op_index + uladv)
  4803. / linfo.li_max_ops_per_insn)
  4804. * linfo.li_min_insn_length;
  4805. state_machine_regs.address
  4806. += addrdelta;
  4807. state_machine_regs.op_index
  4808. = (state_machine_regs.op_index + uladv)
  4809. % linfo.li_max_ops_per_insn;
  4810. if (addrdelta)
  4811. state_machine_regs.view = 0;
  4812. }
  4813. break;
  4814. case DW_LNS_fixed_advance_pc:
  4815. SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
  4816. state_machine_regs.address += uladv;
  4817. state_machine_regs.op_index = 0;
  4818. /* Do NOT reset view. */
  4819. break;
  4820. case DW_LNS_set_prologue_end:
  4821. break;
  4822. case DW_LNS_set_epilogue_begin:
  4823. break;
  4824. case DW_LNS_set_isa:
  4825. READ_ULEB (uladv, data, end);
  4826. printf (_(" Set ISA to %lu\n"), uladv);
  4827. break;
  4828. default:
  4829. printf (_(" Unknown opcode %d with operands: "), op_code);
  4830. if (standard_opcodes != NULL)
  4831. for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
  4832. {
  4833. dwarf_vma val;
  4834. READ_ULEB (val, data, end);
  4835. printf ("0x%s%s", dwarf_vmatoa ("x", val),
  4836. i == 1 ? "" : ", ");
  4837. }
  4838. putchar ('\n');
  4839. break;
  4840. }
  4841. /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
  4842. to the DWARF address/line matrix. */
  4843. if ((is_special_opcode) || (xop == -DW_LNE_end_sequence)
  4844. || (xop == DW_LNS_copy))
  4845. {
  4846. const unsigned int MAX_FILENAME_LENGTH = 35;
  4847. char *fileName;
  4848. char *newFileName = NULL;
  4849. size_t fileNameLength;
  4850. if (file_table)
  4851. {
  4852. unsigned indx = state_machine_regs.file;
  4853. if (linfo.li_version < 5)
  4854. --indx;
  4855. /* PR 20439 */
  4856. if (indx >= n_files)
  4857. {
  4858. warn (_("corrupt file index %u encountered\n"), indx);
  4859. fileName = _("<corrupt>");
  4860. }
  4861. else
  4862. fileName = (char *) file_table[indx].name;
  4863. }
  4864. else
  4865. fileName = _("<unknown>");
  4866. fileNameLength = strlen (fileName);
  4867. newFileName = fileName;
  4868. if (fileNameLength > MAX_FILENAME_LENGTH && !do_wide)
  4869. {
  4870. newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
  4871. /* Truncate file name */
  4872. memcpy (newFileName,
  4873. fileName + fileNameLength - MAX_FILENAME_LENGTH,
  4874. MAX_FILENAME_LENGTH);
  4875. newFileName[MAX_FILENAME_LENGTH] = 0;
  4876. }
  4877. /* A row with end_seq set to true has a meaningful address, but
  4878. the other information in the same row is not significant.
  4879. In such a row, print line as "-", and don't print
  4880. view/is_stmt. */
  4881. if (!do_wide || fileNameLength <= MAX_FILENAME_LENGTH)
  4882. {
  4883. if (linfo.li_max_ops_per_insn == 1)
  4884. {
  4885. if (xop == -DW_LNE_end_sequence)
  4886. printf ("%-35s %11s %#18" DWARF_VMA_FMT "x",
  4887. newFileName, "-",
  4888. state_machine_regs.address);
  4889. else
  4890. printf ("%-35s %11d %#18" DWARF_VMA_FMT "x",
  4891. newFileName, state_machine_regs.line,
  4892. state_machine_regs.address);
  4893. }
  4894. else
  4895. {
  4896. if (xop == -DW_LNE_end_sequence)
  4897. printf ("%-35s %11s %#18" DWARF_VMA_FMT "x[%d]",
  4898. newFileName, "-",
  4899. state_machine_regs.address,
  4900. state_machine_regs.op_index);
  4901. else
  4902. printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]",
  4903. newFileName, state_machine_regs.line,
  4904. state_machine_regs.address,
  4905. state_machine_regs.op_index);
  4906. }
  4907. }
  4908. else
  4909. {
  4910. if (linfo.li_max_ops_per_insn == 1)
  4911. {
  4912. if (xop == -DW_LNE_end_sequence)
  4913. printf ("%s %11s %#18" DWARF_VMA_FMT "x",
  4914. newFileName, "-",
  4915. state_machine_regs.address);
  4916. else
  4917. printf ("%s %11d %#18" DWARF_VMA_FMT "x",
  4918. newFileName, state_machine_regs.line,
  4919. state_machine_regs.address);
  4920. }
  4921. else
  4922. {
  4923. if (xop == -DW_LNE_end_sequence)
  4924. printf ("%s %11s %#18" DWARF_VMA_FMT "x[%d]",
  4925. newFileName, "-",
  4926. state_machine_regs.address,
  4927. state_machine_regs.op_index);
  4928. else
  4929. printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]",
  4930. newFileName, state_machine_regs.line,
  4931. state_machine_regs.address,
  4932. state_machine_regs.op_index);
  4933. }
  4934. }
  4935. if (xop != -DW_LNE_end_sequence)
  4936. {
  4937. if (state_machine_regs.view)
  4938. printf (" %6u", state_machine_regs.view);
  4939. else
  4940. printf (" ");
  4941. if (state_machine_regs.is_stmt)
  4942. printf (" x");
  4943. }
  4944. putchar ('\n');
  4945. state_machine_regs.view++;
  4946. if (xop == -DW_LNE_end_sequence)
  4947. {
  4948. reset_state_machine (linfo.li_default_is_stmt);
  4949. putchar ('\n');
  4950. }
  4951. if (newFileName != fileName)
  4952. free (newFileName);
  4953. }
  4954. }
  4955. if (file_table)
  4956. {
  4957. free (file_table);
  4958. file_table = NULL;
  4959. n_files = 0;
  4960. }
  4961. if (directory_table)
  4962. {
  4963. free (directory_table);
  4964. directory_table = NULL;
  4965. n_directories = 0;
  4966. }
  4967. putchar ('\n');
  4968. }
  4969. return 1;
  4970. }
  4971. static int
  4972. display_debug_lines (struct dwarf_section *section, void *file)
  4973. {
  4974. unsigned char *data = section->start;
  4975. unsigned char *end = data + section->size;
  4976. int retValRaw = 1;
  4977. int retValDecoded = 1;
  4978. if (do_debug_lines == 0)
  4979. do_debug_lines |= FLAG_DEBUG_LINES_RAW;
  4980. if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
  4981. retValRaw = display_debug_lines_raw (section, data, end, file);
  4982. if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
  4983. retValDecoded = display_debug_lines_decoded (section, data, data, end, file);
  4984. if (!retValRaw || !retValDecoded)
  4985. return 0;
  4986. return 1;
  4987. }
  4988. static debug_info *
  4989. find_debug_info_for_offset (dwarf_vma offset)
  4990. {
  4991. unsigned int i;
  4992. if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
  4993. return NULL;
  4994. for (i = 0; i < num_debug_info_entries; i++)
  4995. if (debug_information[i].cu_offset == offset)
  4996. return debug_information + i;
  4997. return NULL;
  4998. }
  4999. static const char *
  5000. get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
  5001. {
  5002. /* See gdb/gdb-index.h. */
  5003. static const char * const kinds[] =
  5004. {
  5005. N_ ("no info"),
  5006. N_ ("type"),
  5007. N_ ("variable"),
  5008. N_ ("function"),
  5009. N_ ("other"),
  5010. N_ ("unused5"),
  5011. N_ ("unused6"),
  5012. N_ ("unused7")
  5013. };
  5014. return _ (kinds[kind]);
  5015. }
  5016. static int
  5017. display_debug_pubnames_worker (struct dwarf_section *section,
  5018. void *file ATTRIBUTE_UNUSED,
  5019. int is_gnu)
  5020. {
  5021. DWARF2_Internal_PubNames names;
  5022. unsigned char *start = section->start;
  5023. unsigned char *end = start + section->size;
  5024. /* It does not matter if this load fails,
  5025. we test for that later on. */
  5026. load_debug_info (file);
  5027. introduce (section, false);
  5028. while (start < end)
  5029. {
  5030. unsigned char *data;
  5031. unsigned long sec_off = start - section->start;
  5032. unsigned int offset_size;
  5033. SAFE_BYTE_GET_AND_INC (names.pn_length, start, 4, end);
  5034. if (names.pn_length == 0xffffffff)
  5035. {
  5036. SAFE_BYTE_GET_AND_INC (names.pn_length, start, 8, end);
  5037. offset_size = 8;
  5038. }
  5039. else
  5040. offset_size = 4;
  5041. if (names.pn_length > (size_t) (end - start))
  5042. {
  5043. warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
  5044. section->name,
  5045. sec_off,
  5046. dwarf_vmatoa ("x", names.pn_length));
  5047. break;
  5048. }
  5049. data = start;
  5050. start += names.pn_length;
  5051. SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, start);
  5052. SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, start);
  5053. if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
  5054. && num_debug_info_entries > 0
  5055. && find_debug_info_for_offset (names.pn_offset) == NULL)
  5056. warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
  5057. (unsigned long) names.pn_offset, section->name);
  5058. SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, start);
  5059. printf (_(" Length: %ld\n"),
  5060. (long) names.pn_length);
  5061. printf (_(" Version: %d\n"),
  5062. names.pn_version);
  5063. printf (_(" Offset into .debug_info section: 0x%lx\n"),
  5064. (unsigned long) names.pn_offset);
  5065. printf (_(" Size of area in .debug_info section: %ld\n"),
  5066. (long) names.pn_size);
  5067. if (names.pn_version != 2 && names.pn_version != 3)
  5068. {
  5069. static int warned = 0;
  5070. if (! warned)
  5071. {
  5072. warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
  5073. warned = 1;
  5074. }
  5075. continue;
  5076. }
  5077. if (is_gnu)
  5078. printf (_("\n Offset Kind Name\n"));
  5079. else
  5080. printf (_("\n Offset\tName\n"));
  5081. while (1)
  5082. {
  5083. bfd_size_type maxprint;
  5084. dwarf_vma offset;
  5085. SAFE_BYTE_GET_AND_INC (offset, data, offset_size, start);
  5086. if (offset == 0)
  5087. break;
  5088. if (data >= start)
  5089. break;
  5090. maxprint = (start - data) - 1;
  5091. if (is_gnu)
  5092. {
  5093. unsigned int kind_data;
  5094. gdb_index_symbol_kind kind;
  5095. const char *kind_name;
  5096. int is_static;
  5097. SAFE_BYTE_GET_AND_INC (kind_data, data, 1, start);
  5098. maxprint --;
  5099. /* GCC computes the kind as the upper byte in the CU index
  5100. word, and then right shifts it by the CU index size.
  5101. Left shift KIND to where the gdb-index.h accessor macros
  5102. can use it. */
  5103. kind_data <<= GDB_INDEX_CU_BITSIZE;
  5104. kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
  5105. kind_name = get_gdb_index_symbol_kind_name (kind);
  5106. is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
  5107. printf (" %-6lx %s,%-10s %.*s\n",
  5108. (unsigned long) offset, is_static ? _("s") : _("g"),
  5109. kind_name, (int) maxprint, data);
  5110. }
  5111. else
  5112. printf (" %-6lx\t%.*s\n",
  5113. (unsigned long) offset, (int) maxprint, data);
  5114. data += strnlen ((char *) data, maxprint);
  5115. if (data < start)
  5116. data++;
  5117. if (data >= start)
  5118. break;
  5119. }
  5120. }
  5121. printf ("\n");
  5122. return 1;
  5123. }
  5124. static int
  5125. display_debug_pubnames (struct dwarf_section *section, void *file)
  5126. {
  5127. return display_debug_pubnames_worker (section, file, 0);
  5128. }
  5129. static int
  5130. display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
  5131. {
  5132. return display_debug_pubnames_worker (section, file, 1);
  5133. }
  5134. static int
  5135. display_debug_macinfo (struct dwarf_section *section,
  5136. void *file ATTRIBUTE_UNUSED)
  5137. {
  5138. unsigned char *start = section->start;
  5139. unsigned char *end = start + section->size;
  5140. unsigned char *curr = start;
  5141. enum dwarf_macinfo_record_type op;
  5142. introduce (section, false);
  5143. while (curr < end)
  5144. {
  5145. unsigned int lineno;
  5146. const unsigned char *string;
  5147. op = (enum dwarf_macinfo_record_type) *curr;
  5148. curr++;
  5149. switch (op)
  5150. {
  5151. case DW_MACINFO_start_file:
  5152. {
  5153. unsigned int filenum;
  5154. READ_ULEB (lineno, curr, end);
  5155. READ_ULEB (filenum, curr, end);
  5156. printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
  5157. lineno, filenum);
  5158. }
  5159. break;
  5160. case DW_MACINFO_end_file:
  5161. printf (_(" DW_MACINFO_end_file\n"));
  5162. break;
  5163. case DW_MACINFO_define:
  5164. READ_ULEB (lineno, curr, end);
  5165. string = curr;
  5166. curr += strnlen ((char *) string, end - string);
  5167. printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
  5168. lineno, (int) (curr - string), string);
  5169. if (curr < end)
  5170. curr++;
  5171. break;
  5172. case DW_MACINFO_undef:
  5173. READ_ULEB (lineno, curr, end);
  5174. string = curr;
  5175. curr += strnlen ((char *) string, end - string);
  5176. printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
  5177. lineno, (int) (curr - string), string);
  5178. if (curr < end)
  5179. curr++;
  5180. break;
  5181. case DW_MACINFO_vendor_ext:
  5182. {
  5183. unsigned int constant;
  5184. READ_ULEB (constant, curr, end);
  5185. string = curr;
  5186. curr += strnlen ((char *) string, end - string);
  5187. printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
  5188. constant, (int) (curr - string), string);
  5189. if (curr < end)
  5190. curr++;
  5191. }
  5192. break;
  5193. }
  5194. }
  5195. return 1;
  5196. }
  5197. /* Given LINE_OFFSET into the .debug_line section, attempt to return
  5198. filename and dirname corresponding to file name table entry with index
  5199. FILEIDX. Return NULL on failure. */
  5200. static unsigned char *
  5201. get_line_filename_and_dirname (dwarf_vma line_offset,
  5202. dwarf_vma fileidx,
  5203. unsigned char **dir_name)
  5204. {
  5205. struct dwarf_section *section = &debug_displays [line].section;
  5206. unsigned char *hdrptr, *dirtable, *file_name;
  5207. unsigned int offset_size;
  5208. unsigned int version, opcode_base;
  5209. dwarf_vma length, diridx;
  5210. const unsigned char * end;
  5211. *dir_name = NULL;
  5212. if (section->start == NULL
  5213. || line_offset >= section->size
  5214. || fileidx == 0)
  5215. return NULL;
  5216. hdrptr = section->start + line_offset;
  5217. end = section->start + section->size;
  5218. SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
  5219. if (length == 0xffffffff)
  5220. {
  5221. /* This section is 64-bit DWARF 3. */
  5222. SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
  5223. offset_size = 8;
  5224. }
  5225. else
  5226. offset_size = 4;
  5227. if (length > (size_t) (end - hdrptr)
  5228. || length < 2 + offset_size + 1 + 3 + 1)
  5229. return NULL;
  5230. end = hdrptr + length;
  5231. SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
  5232. if (version != 2 && version != 3 && version != 4)
  5233. return NULL;
  5234. hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
  5235. if (version >= 4)
  5236. hdrptr++; /* Skip max_ops_per_insn. */
  5237. hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
  5238. SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
  5239. if (opcode_base == 0
  5240. || opcode_base - 1 >= (size_t) (end - hdrptr))
  5241. return NULL;
  5242. hdrptr += opcode_base - 1;
  5243. dirtable = hdrptr;
  5244. /* Skip over dirname table. */
  5245. while (*hdrptr != '\0')
  5246. {
  5247. hdrptr += strnlen ((char *) hdrptr, end - hdrptr);
  5248. if (hdrptr < end)
  5249. hdrptr++;
  5250. if (hdrptr >= end)
  5251. return NULL;
  5252. }
  5253. hdrptr++; /* Skip the NUL at the end of the table. */
  5254. /* Now skip over preceding filename table entries. */
  5255. for (; hdrptr < end && *hdrptr != '\0' && fileidx > 1; fileidx--)
  5256. {
  5257. hdrptr += strnlen ((char *) hdrptr, end - hdrptr);
  5258. if (hdrptr < end)
  5259. hdrptr++;
  5260. SKIP_ULEB (hdrptr, end);
  5261. SKIP_ULEB (hdrptr, end);
  5262. SKIP_ULEB (hdrptr, end);
  5263. }
  5264. if (hdrptr >= end || *hdrptr == '\0')
  5265. return NULL;
  5266. file_name = hdrptr;
  5267. hdrptr += strnlen ((char *) hdrptr, end - hdrptr);
  5268. if (hdrptr < end)
  5269. hdrptr++;
  5270. if (hdrptr >= end)
  5271. return NULL;
  5272. READ_ULEB (diridx, hdrptr, end);
  5273. if (diridx == 0)
  5274. return file_name;
  5275. for (; dirtable < end && *dirtable != '\0' && diridx > 1; diridx--)
  5276. {
  5277. dirtable += strnlen ((char *) dirtable, end - dirtable);
  5278. if (dirtable < end)
  5279. dirtable++;
  5280. }
  5281. if (dirtable >= end || *dirtable == '\0')
  5282. return NULL;
  5283. *dir_name = dirtable;
  5284. return file_name;
  5285. }
  5286. static int
  5287. display_debug_macro (struct dwarf_section *section,
  5288. void *file)
  5289. {
  5290. unsigned char *start = section->start;
  5291. unsigned char *end = start + section->size;
  5292. unsigned char *curr = start;
  5293. unsigned char *extended_op_buf[256];
  5294. bool is_dwo = false;
  5295. const char *suffix = strrchr (section->name, '.');
  5296. if (suffix && strcmp (suffix, ".dwo") == 0)
  5297. is_dwo = true;
  5298. load_debug_section_with_follow (str, file);
  5299. load_debug_section_with_follow (line, file);
  5300. load_debug_section_with_follow (str_index, file);
  5301. introduce (section, false);
  5302. while (curr < end)
  5303. {
  5304. unsigned int lineno, version, flags;
  5305. unsigned int offset_size;
  5306. const unsigned char *string;
  5307. dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
  5308. unsigned char **extended_ops = NULL;
  5309. SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
  5310. if (version != 4 && version != 5)
  5311. {
  5312. error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
  5313. section->name, version);
  5314. return 0;
  5315. }
  5316. SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
  5317. offset_size = (flags & 1) ? 8 : 4;
  5318. printf (_(" Offset: 0x%lx\n"),
  5319. (unsigned long) sec_offset);
  5320. printf (_(" Version: %d\n"), version);
  5321. printf (_(" Offset size: %d\n"), offset_size);
  5322. if (flags & 2)
  5323. {
  5324. SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
  5325. printf (_(" Offset into .debug_line: 0x%lx\n"),
  5326. (unsigned long) line_offset);
  5327. }
  5328. if (flags & 4)
  5329. {
  5330. unsigned int i, count, op;
  5331. dwarf_vma nargs, n;
  5332. SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
  5333. memset (extended_op_buf, 0, sizeof (extended_op_buf));
  5334. extended_ops = extended_op_buf;
  5335. if (count)
  5336. {
  5337. printf (_(" Extension opcode arguments:\n"));
  5338. for (i = 0; i < count; i++)
  5339. {
  5340. SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
  5341. extended_ops[op] = curr;
  5342. READ_ULEB (nargs, curr, end);
  5343. if (nargs == 0)
  5344. printf (_(" DW_MACRO_%02x has no arguments\n"), op);
  5345. else
  5346. {
  5347. printf (_(" DW_MACRO_%02x arguments: "), op);
  5348. for (n = 0; n < nargs; n++)
  5349. {
  5350. unsigned int form;
  5351. SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
  5352. printf ("%s%s", get_FORM_name (form),
  5353. n == nargs - 1 ? "\n" : ", ");
  5354. switch (form)
  5355. {
  5356. case DW_FORM_data1:
  5357. case DW_FORM_data2:
  5358. case DW_FORM_data4:
  5359. case DW_FORM_data8:
  5360. case DW_FORM_sdata:
  5361. case DW_FORM_udata:
  5362. case DW_FORM_block:
  5363. case DW_FORM_block1:
  5364. case DW_FORM_block2:
  5365. case DW_FORM_block4:
  5366. case DW_FORM_flag:
  5367. case DW_FORM_string:
  5368. case DW_FORM_strp:
  5369. case DW_FORM_sec_offset:
  5370. break;
  5371. default:
  5372. error (_("Invalid extension opcode form %s\n"),
  5373. get_FORM_name (form));
  5374. return 0;
  5375. }
  5376. }
  5377. }
  5378. }
  5379. }
  5380. }
  5381. printf ("\n");
  5382. while (1)
  5383. {
  5384. unsigned int op;
  5385. if (curr >= end)
  5386. {
  5387. error (_(".debug_macro section not zero terminated\n"));
  5388. return 0;
  5389. }
  5390. SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
  5391. if (op == 0)
  5392. break;
  5393. switch (op)
  5394. {
  5395. case DW_MACRO_define:
  5396. READ_ULEB (lineno, curr, end);
  5397. string = curr;
  5398. curr += strnlen ((char *) string, end - string);
  5399. printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
  5400. lineno, (int) (curr - string), string);
  5401. if (curr < end)
  5402. curr++;
  5403. break;
  5404. case DW_MACRO_undef:
  5405. READ_ULEB (lineno, curr, end);
  5406. string = curr;
  5407. curr += strnlen ((char *) string, end - string);
  5408. printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
  5409. lineno, (int) (curr - string), string);
  5410. if (curr < end)
  5411. curr++;
  5412. break;
  5413. case DW_MACRO_start_file:
  5414. {
  5415. unsigned int filenum;
  5416. unsigned char *file_name = NULL, *dir_name = NULL;
  5417. READ_ULEB (lineno, curr, end);
  5418. READ_ULEB (filenum, curr, end);
  5419. if ((flags & 2) == 0)
  5420. error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
  5421. else
  5422. file_name
  5423. = get_line_filename_and_dirname (line_offset, filenum,
  5424. &dir_name);
  5425. if (file_name == NULL)
  5426. printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
  5427. lineno, filenum);
  5428. else
  5429. printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
  5430. lineno, filenum,
  5431. dir_name != NULL ? (const char *) dir_name : "",
  5432. dir_name != NULL ? "/" : "", file_name);
  5433. }
  5434. break;
  5435. case DW_MACRO_end_file:
  5436. printf (_(" DW_MACRO_end_file\n"));
  5437. break;
  5438. case DW_MACRO_define_strp:
  5439. READ_ULEB (lineno, curr, end);
  5440. if (version == 4 && is_dwo)
  5441. READ_ULEB (offset, curr, end);
  5442. else
  5443. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  5444. string = fetch_indirect_string (offset);
  5445. printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
  5446. lineno, string);
  5447. break;
  5448. case DW_MACRO_undef_strp:
  5449. READ_ULEB (lineno, curr, end);
  5450. if (version == 4 && is_dwo)
  5451. READ_ULEB (offset, curr, end);
  5452. else
  5453. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  5454. string = fetch_indirect_string (offset);
  5455. printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
  5456. lineno, string);
  5457. break;
  5458. case DW_MACRO_import:
  5459. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  5460. printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
  5461. (unsigned long) offset);
  5462. break;
  5463. case DW_MACRO_define_sup:
  5464. READ_ULEB (lineno, curr, end);
  5465. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  5466. printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
  5467. lineno, (unsigned long) offset);
  5468. break;
  5469. case DW_MACRO_undef_sup:
  5470. READ_ULEB (lineno, curr, end);
  5471. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  5472. printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
  5473. lineno, (unsigned long) offset);
  5474. break;
  5475. case DW_MACRO_import_sup:
  5476. SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
  5477. printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
  5478. (unsigned long) offset);
  5479. break;
  5480. case DW_MACRO_define_strx:
  5481. case DW_MACRO_undef_strx:
  5482. READ_ULEB (lineno, curr, end);
  5483. READ_ULEB (offset, curr, end);
  5484. string = (const unsigned char *)
  5485. fetch_indexed_string (offset, NULL, offset_size, false);
  5486. if (op == DW_MACRO_define_strx)
  5487. printf (" DW_MACRO_define_strx ");
  5488. else
  5489. printf (" DW_MACRO_undef_strx ");
  5490. if (do_wide)
  5491. printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset));
  5492. printf (_("lineno : %d macro : %s\n"),
  5493. lineno, string);
  5494. break;
  5495. default:
  5496. if (op >= DW_MACRO_lo_user && op <= DW_MACRO_hi_user)
  5497. {
  5498. printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op);
  5499. break;
  5500. }
  5501. if (extended_ops == NULL || extended_ops[op] == NULL)
  5502. {
  5503. error (_(" Unknown macro opcode %02x seen\n"), op);
  5504. return 0;
  5505. }
  5506. else
  5507. {
  5508. /* Skip over unhandled opcodes. */
  5509. dwarf_vma nargs, n;
  5510. unsigned char *desc = extended_ops[op];
  5511. READ_ULEB (nargs, desc, end);
  5512. if (nargs == 0)
  5513. {
  5514. printf (_(" DW_MACRO_%02x\n"), op);
  5515. break;
  5516. }
  5517. printf (_(" DW_MACRO_%02x -"), op);
  5518. for (n = 0; n < nargs; n++)
  5519. {
  5520. int val;
  5521. /* DW_FORM_implicit_const is not expected here. */
  5522. SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
  5523. curr
  5524. = read_and_display_attr_value (0, val, 0,
  5525. start, curr, end, 0, 0, offset_size,
  5526. version, NULL, 0, NULL,
  5527. NULL, ' ', -1);
  5528. if (n != nargs - 1)
  5529. printf (",");
  5530. }
  5531. printf ("\n");
  5532. }
  5533. break;
  5534. }
  5535. }
  5536. printf ("\n");
  5537. }
  5538. return 1;
  5539. }
  5540. static int
  5541. display_debug_abbrev (struct dwarf_section *section,
  5542. void *file ATTRIBUTE_UNUSED)
  5543. {
  5544. abbrev_entry *entry;
  5545. unsigned char *start = section->start;
  5546. introduce (section, false);
  5547. do
  5548. {
  5549. abbrev_list * list;
  5550. dwarf_vma offset;
  5551. offset = start - section->start;
  5552. list = find_abbrev_list_by_abbrev_offset (0, offset);
  5553. if (list == NULL)
  5554. {
  5555. list = new_abbrev_list (0, offset);
  5556. start = process_abbrev_set (section, 0, section->size, offset, list);
  5557. list->start_of_next_abbrevs = start;
  5558. }
  5559. else
  5560. start = list->start_of_next_abbrevs;
  5561. if (list->first_abbrev == NULL)
  5562. continue;
  5563. printf (_(" Number TAG (0x%lx)\n"), (long) offset);
  5564. for (entry = list->first_abbrev; entry; entry = entry->next)
  5565. {
  5566. abbrev_attr *attr;
  5567. printf (" %ld %s [%s]\n",
  5568. entry->number,
  5569. get_TAG_name (entry->tag),
  5570. entry->children ? _("has children") : _("no children"));
  5571. for (attr = entry->first_attr; attr; attr = attr->next)
  5572. {
  5573. printf (" %-18s %s",
  5574. get_AT_name (attr->attribute),
  5575. get_FORM_name (attr->form));
  5576. if (attr->form == DW_FORM_implicit_const)
  5577. printf (": %s", dwarf_vmatoa ("d", attr->implicit_const));
  5578. putchar ('\n');
  5579. }
  5580. }
  5581. }
  5582. while (start);
  5583. printf ("\n");
  5584. return 1;
  5585. }
  5586. /* Return true when ADDR is the maximum address, when addresses are
  5587. POINTER_SIZE bytes long. */
  5588. static bool
  5589. is_max_address (dwarf_vma addr, unsigned int pointer_size)
  5590. {
  5591. dwarf_vma mask = ~(~(dwarf_vma) 1 << (pointer_size * 8 - 1));
  5592. return ((addr & mask) == mask);
  5593. }
  5594. /* Display a view pair list starting at *VSTART_PTR and ending at
  5595. VLISTEND within SECTION. */
  5596. static void
  5597. display_view_pair_list (struct dwarf_section *section,
  5598. unsigned char **vstart_ptr,
  5599. unsigned int debug_info_entry,
  5600. unsigned char *vlistend)
  5601. {
  5602. unsigned char *vstart = *vstart_ptr;
  5603. unsigned char *section_end = section->start + section->size;
  5604. unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
  5605. if (vlistend < section_end)
  5606. section_end = vlistend;
  5607. putchar ('\n');
  5608. while (vstart < section_end)
  5609. {
  5610. dwarf_vma off = vstart - section->start;
  5611. dwarf_vma vbegin, vend;
  5612. READ_ULEB (vbegin, vstart, section_end);
  5613. if (vstart == section_end)
  5614. break;
  5615. READ_ULEB (vend, vstart, section_end);
  5616. printf (" %8.8lx ", (unsigned long) off);
  5617. print_dwarf_view (vbegin, pointer_size, 1);
  5618. print_dwarf_view (vend, pointer_size, 1);
  5619. printf (_("location view pair\n"));
  5620. }
  5621. putchar ('\n');
  5622. *vstart_ptr = vstart;
  5623. }
  5624. /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
  5625. static void
  5626. display_loc_list (struct dwarf_section *section,
  5627. unsigned char **start_ptr,
  5628. unsigned int debug_info_entry,
  5629. dwarf_vma offset,
  5630. dwarf_vma base_address,
  5631. unsigned char **vstart_ptr,
  5632. int has_frame_base)
  5633. {
  5634. unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
  5635. unsigned char *section_end = section->start + section->size;
  5636. dwarf_vma cu_offset;
  5637. unsigned int pointer_size;
  5638. unsigned int offset_size;
  5639. int dwarf_version;
  5640. dwarf_vma begin;
  5641. dwarf_vma end;
  5642. unsigned short length;
  5643. int need_frame_base;
  5644. if (debug_info_entry >= num_debug_info_entries)
  5645. {
  5646. warn (_("No debug information available for loc lists of entry: %u\n"),
  5647. debug_info_entry);
  5648. return;
  5649. }
  5650. cu_offset = debug_information [debug_info_entry].cu_offset;
  5651. pointer_size = debug_information [debug_info_entry].pointer_size;
  5652. offset_size = debug_information [debug_info_entry].offset_size;
  5653. dwarf_version = debug_information [debug_info_entry].dwarf_version;
  5654. if (pointer_size < 2 || pointer_size > 8)
  5655. {
  5656. warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
  5657. pointer_size, debug_info_entry);
  5658. return;
  5659. }
  5660. while (1)
  5661. {
  5662. dwarf_vma off = offset + (start - *start_ptr);
  5663. dwarf_vma vbegin = vm1, vend = vm1;
  5664. if (2 * pointer_size > (size_t) (section_end - start))
  5665. {
  5666. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  5667. (unsigned long) offset);
  5668. break;
  5669. }
  5670. printf (" ");
  5671. print_dwarf_vma (off, 4);
  5672. SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
  5673. SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
  5674. if (begin == 0 && end == 0)
  5675. {
  5676. /* PR 18374: In a object file we can have a location list that
  5677. starts with a begin and end of 0 because there are relocations
  5678. that need to be applied to the addresses. Actually applying
  5679. the relocations now does not help as they will probably resolve
  5680. to 0, since the object file has not been fully linked. Real
  5681. end of list markers will not have any relocations against them. */
  5682. if (! reloc_at (section, off)
  5683. && ! reloc_at (section, off + pointer_size))
  5684. {
  5685. printf (_("<End of list>\n"));
  5686. break;
  5687. }
  5688. }
  5689. /* Check base address specifiers. */
  5690. if (is_max_address (begin, pointer_size)
  5691. && !is_max_address (end, pointer_size))
  5692. {
  5693. base_address = end;
  5694. print_dwarf_vma (begin, pointer_size);
  5695. print_dwarf_vma (end, pointer_size);
  5696. printf (_("(base address)\n"));
  5697. continue;
  5698. }
  5699. if (vstart)
  5700. {
  5701. off = offset + (vstart - *start_ptr);
  5702. READ_ULEB (vbegin, vstart, section_end);
  5703. print_dwarf_view (vbegin, pointer_size, 1);
  5704. READ_ULEB (vend, vstart, section_end);
  5705. print_dwarf_view (vend, pointer_size, 1);
  5706. printf (_("views at %8.8lx for:\n %*s "),
  5707. (unsigned long) off, 8, "");
  5708. }
  5709. if (2 > (size_t) (section_end - start))
  5710. {
  5711. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  5712. (unsigned long) offset);
  5713. break;
  5714. }
  5715. SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
  5716. if (length > (size_t) (section_end - start))
  5717. {
  5718. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  5719. (unsigned long) offset);
  5720. break;
  5721. }
  5722. print_dwarf_vma (begin + base_address, pointer_size);
  5723. print_dwarf_vma (end + base_address, pointer_size);
  5724. putchar ('(');
  5725. need_frame_base = decode_location_expression (start,
  5726. pointer_size,
  5727. offset_size,
  5728. dwarf_version,
  5729. length,
  5730. cu_offset, section);
  5731. putchar (')');
  5732. if (need_frame_base && !has_frame_base)
  5733. printf (_(" [without DW_AT_frame_base]"));
  5734. if (begin == end && vbegin == vend)
  5735. fputs (_(" (start == end)"), stdout);
  5736. else if (begin > end || (begin == end && vbegin > vend))
  5737. fputs (_(" (start > end)"), stdout);
  5738. putchar ('\n');
  5739. start += length;
  5740. }
  5741. *start_ptr = start;
  5742. *vstart_ptr = vstart;
  5743. }
  5744. /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
  5745. static void
  5746. display_loclists_list (struct dwarf_section * section,
  5747. unsigned char ** start_ptr,
  5748. unsigned int debug_info_entry,
  5749. dwarf_vma offset,
  5750. dwarf_vma base_address,
  5751. unsigned char ** vstart_ptr,
  5752. int has_frame_base)
  5753. {
  5754. unsigned char * start = *start_ptr;
  5755. unsigned char * vstart = *vstart_ptr;
  5756. unsigned char * section_end = section->start + section->size;
  5757. dwarf_vma cu_offset;
  5758. unsigned int pointer_size;
  5759. unsigned int offset_size;
  5760. unsigned int dwarf_version;
  5761. /* Initialize it due to a false compiler warning. */
  5762. dwarf_vma begin = -1, vbegin = -1;
  5763. dwarf_vma end = -1, vend = -1;
  5764. dwarf_vma length;
  5765. int need_frame_base;
  5766. if (debug_info_entry >= num_debug_info_entries)
  5767. {
  5768. warn (_("No debug information available for "
  5769. "loclists lists of entry: %u\n"),
  5770. debug_info_entry);
  5771. return;
  5772. }
  5773. cu_offset = debug_information [debug_info_entry].cu_offset;
  5774. pointer_size = debug_information [debug_info_entry].pointer_size;
  5775. offset_size = debug_information [debug_info_entry].offset_size;
  5776. dwarf_version = debug_information [debug_info_entry].dwarf_version;
  5777. if (pointer_size < 2 || pointer_size > 8)
  5778. {
  5779. warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
  5780. pointer_size, debug_info_entry);
  5781. return;
  5782. }
  5783. while (1)
  5784. {
  5785. dwarf_vma off = offset + (start - *start_ptr);
  5786. enum dwarf_location_list_entry_type llet;
  5787. if (start + 1 > section_end)
  5788. {
  5789. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  5790. (unsigned long) offset);
  5791. break;
  5792. }
  5793. printf (" ");
  5794. print_dwarf_vma (off, 4);
  5795. SAFE_BYTE_GET_AND_INC (llet, start, 1, section_end);
  5796. if (vstart && (llet == DW_LLE_offset_pair
  5797. || llet == DW_LLE_start_end
  5798. || llet == DW_LLE_start_length))
  5799. {
  5800. off = offset + (vstart - *start_ptr);
  5801. READ_ULEB (vbegin, vstart, section_end);
  5802. print_dwarf_view (vbegin, pointer_size, 1);
  5803. READ_ULEB (vend, vstart, section_end);
  5804. print_dwarf_view (vend, pointer_size, 1);
  5805. printf (_("views at %8.8lx for:\n %*s "),
  5806. (unsigned long) off, 8, "");
  5807. }
  5808. switch (llet)
  5809. {
  5810. case DW_LLE_end_of_list:
  5811. printf (_("<End of list>\n"));
  5812. break;
  5813. case DW_LLE_base_addressx:
  5814. READ_ULEB (base_address, start, section_end);
  5815. print_dwarf_vma (base_address, pointer_size);
  5816. printf (_("(index into .debug_addr) "));
  5817. base_address = fetch_indexed_addr (base_address, pointer_size);
  5818. print_dwarf_vma (base_address, pointer_size);
  5819. printf (_("(base address)\n"));
  5820. break;
  5821. case DW_LLE_startx_endx:
  5822. READ_ULEB (begin, start, section_end);
  5823. begin = fetch_indexed_addr (begin, pointer_size);
  5824. READ_ULEB (end, start, section_end);
  5825. end = fetch_indexed_addr (end, pointer_size);
  5826. break;
  5827. case DW_LLE_startx_length:
  5828. READ_ULEB (begin, start, section_end);
  5829. begin = fetch_indexed_addr (begin, pointer_size);
  5830. READ_ULEB (end, start, section_end);
  5831. end += begin;
  5832. break;
  5833. case DW_LLE_default_location:
  5834. begin = end = 0;
  5835. break;
  5836. case DW_LLE_offset_pair:
  5837. READ_ULEB (begin, start, section_end);
  5838. begin += base_address;
  5839. READ_ULEB (end, start, section_end);
  5840. end += base_address;
  5841. break;
  5842. case DW_LLE_base_address:
  5843. SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size,
  5844. section_end);
  5845. print_dwarf_vma (base_address, pointer_size);
  5846. printf (_("(base address)\n"));
  5847. break;
  5848. case DW_LLE_start_end:
  5849. SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
  5850. SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
  5851. break;
  5852. case DW_LLE_start_length:
  5853. SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
  5854. READ_ULEB (end, start, section_end);
  5855. end += begin;
  5856. break;
  5857. #ifdef DW_LLE_view_pair
  5858. case DW_LLE_view_pair:
  5859. if (vstart)
  5860. printf (_("View pair entry in loclist with locviews attribute\n"));
  5861. READ_ULEB (vbegin, start, section_end);
  5862. print_dwarf_view (vbegin, pointer_size, 1);
  5863. READ_ULEB (vend, start, section_end);
  5864. print_dwarf_view (vend, pointer_size, 1);
  5865. printf (_("views for:\n"));
  5866. continue;
  5867. #endif
  5868. default:
  5869. error (_("Invalid location list entry type %d\n"), llet);
  5870. return;
  5871. }
  5872. if (llet == DW_LLE_end_of_list)
  5873. break;
  5874. if (llet == DW_LLE_base_address
  5875. || llet == DW_LLE_base_addressx)
  5876. continue;
  5877. if (start == section_end)
  5878. {
  5879. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  5880. (unsigned long) offset);
  5881. break;
  5882. }
  5883. READ_ULEB (length, start, section_end);
  5884. if (length > (size_t) (section_end - start))
  5885. {
  5886. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  5887. (unsigned long) offset);
  5888. break;
  5889. }
  5890. print_dwarf_vma (begin, pointer_size);
  5891. print_dwarf_vma (end, pointer_size);
  5892. putchar ('(');
  5893. need_frame_base = decode_location_expression (start,
  5894. pointer_size,
  5895. offset_size,
  5896. dwarf_version,
  5897. length,
  5898. cu_offset, section);
  5899. putchar (')');
  5900. if (need_frame_base && !has_frame_base)
  5901. printf (_(" [without DW_AT_frame_base]"));
  5902. if (begin == end && vbegin == vend)
  5903. fputs (_(" (start == end)"), stdout);
  5904. else if (begin > end || (begin == end && vbegin > vend))
  5905. fputs (_(" (start > end)"), stdout);
  5906. putchar ('\n');
  5907. start += length;
  5908. vbegin = vend = -1;
  5909. }
  5910. if (vbegin != vm1 || vend != vm1)
  5911. printf (_("Trailing view pair not used in a range"));
  5912. *start_ptr = start;
  5913. *vstart_ptr = vstart;
  5914. }
  5915. /* Print a .debug_addr table index in decimal, surrounded by square brackets,
  5916. right-adjusted in a field of length LEN, and followed by a space. */
  5917. static void
  5918. print_addr_index (unsigned int idx, unsigned int len)
  5919. {
  5920. static char buf[15];
  5921. snprintf (buf, sizeof (buf), "[%d]", idx);
  5922. printf ("%*s ", len, buf);
  5923. }
  5924. /* Display a location list from a .dwo section. It uses address indexes rather
  5925. than embedded addresses. This code closely follows display_loc_list, but the
  5926. two are sufficiently different that combining things is very ugly. */
  5927. static void
  5928. display_loc_list_dwo (struct dwarf_section *section,
  5929. unsigned char **start_ptr,
  5930. unsigned int debug_info_entry,
  5931. dwarf_vma offset,
  5932. unsigned char **vstart_ptr,
  5933. int has_frame_base)
  5934. {
  5935. unsigned char *start = *start_ptr, *vstart = *vstart_ptr;
  5936. unsigned char *section_end = section->start + section->size;
  5937. dwarf_vma cu_offset;
  5938. unsigned int pointer_size;
  5939. unsigned int offset_size;
  5940. int dwarf_version;
  5941. int entry_type;
  5942. unsigned short length;
  5943. int need_frame_base;
  5944. unsigned int idx;
  5945. if (debug_info_entry >= num_debug_info_entries)
  5946. {
  5947. warn (_("No debug information for loc lists of entry: %u\n"),
  5948. debug_info_entry);
  5949. return;
  5950. }
  5951. cu_offset = debug_information [debug_info_entry].cu_offset;
  5952. pointer_size = debug_information [debug_info_entry].pointer_size;
  5953. offset_size = debug_information [debug_info_entry].offset_size;
  5954. dwarf_version = debug_information [debug_info_entry].dwarf_version;
  5955. if (pointer_size < 2 || pointer_size > 8)
  5956. {
  5957. warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
  5958. pointer_size, debug_info_entry);
  5959. return;
  5960. }
  5961. while (1)
  5962. {
  5963. printf (" ");
  5964. print_dwarf_vma (offset + (start - *start_ptr), 4);
  5965. if (start >= section_end)
  5966. {
  5967. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  5968. (unsigned long) offset);
  5969. break;
  5970. }
  5971. SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
  5972. if (vstart)
  5973. switch (entry_type)
  5974. {
  5975. default:
  5976. break;
  5977. case 2:
  5978. case 3:
  5979. case 4:
  5980. {
  5981. dwarf_vma view;
  5982. dwarf_vma off = offset + (vstart - *start_ptr);
  5983. READ_ULEB (view, vstart, section_end);
  5984. print_dwarf_view (view, 8, 1);
  5985. READ_ULEB (view, vstart, section_end);
  5986. print_dwarf_view (view, 8, 1);
  5987. printf (_("views at %8.8lx for:\n %*s "),
  5988. (unsigned long) off, 8, "");
  5989. }
  5990. break;
  5991. }
  5992. switch (entry_type)
  5993. {
  5994. case 0: /* A terminating entry. */
  5995. *start_ptr = start;
  5996. *vstart_ptr = vstart;
  5997. printf (_("<End of list>\n"));
  5998. return;
  5999. case 1: /* A base-address entry. */
  6000. READ_ULEB (idx, start, section_end);
  6001. print_addr_index (idx, 8);
  6002. printf ("%*s", 9 + (vstart ? 2 * 6 : 0), "");
  6003. printf (_("(base address selection entry)\n"));
  6004. continue;
  6005. case 2: /* A start/end entry. */
  6006. READ_ULEB (idx, start, section_end);
  6007. print_addr_index (idx, 8);
  6008. READ_ULEB (idx, start, section_end);
  6009. print_addr_index (idx, 8);
  6010. break;
  6011. case 3: /* A start/length entry. */
  6012. READ_ULEB (idx, start, section_end);
  6013. print_addr_index (idx, 8);
  6014. SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
  6015. printf ("%08x ", idx);
  6016. break;
  6017. case 4: /* An offset pair entry. */
  6018. SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
  6019. printf ("%08x ", idx);
  6020. SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
  6021. printf ("%08x ", idx);
  6022. break;
  6023. default:
  6024. warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
  6025. *start_ptr = start;
  6026. *vstart_ptr = vstart;
  6027. return;
  6028. }
  6029. if (2 > (size_t) (section_end - start))
  6030. {
  6031. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  6032. (unsigned long) offset);
  6033. break;
  6034. }
  6035. SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
  6036. if (length > (size_t) (section_end - start))
  6037. {
  6038. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  6039. (unsigned long) offset);
  6040. break;
  6041. }
  6042. putchar ('(');
  6043. need_frame_base = decode_location_expression (start,
  6044. pointer_size,
  6045. offset_size,
  6046. dwarf_version,
  6047. length,
  6048. cu_offset, section);
  6049. putchar (')');
  6050. if (need_frame_base && !has_frame_base)
  6051. printf (_(" [without DW_AT_frame_base]"));
  6052. putchar ('\n');
  6053. start += length;
  6054. }
  6055. *start_ptr = start;
  6056. *vstart_ptr = vstart;
  6057. }
  6058. /* Sort array of indexes in ascending order of loc_offsets[idx] and
  6059. loc_views. */
  6060. static dwarf_vma *loc_offsets, *loc_views;
  6061. static int
  6062. loc_offsets_compar (const void *ap, const void *bp)
  6063. {
  6064. dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
  6065. dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
  6066. int ret = (a > b) - (b > a);
  6067. if (ret)
  6068. return ret;
  6069. a = loc_views[*(const unsigned int *) ap];
  6070. b = loc_views[*(const unsigned int *) bp];
  6071. ret = (a > b) - (b > a);
  6072. return ret;
  6073. }
  6074. static int
  6075. display_offset_entry_loclists (struct dwarf_section *section)
  6076. {
  6077. unsigned char * start = section->start;
  6078. unsigned char * const end = start + section->size;
  6079. introduce (section, false);
  6080. do
  6081. {
  6082. dwarf_vma length;
  6083. unsigned short version;
  6084. unsigned char address_size;
  6085. unsigned char segment_selector_size;
  6086. uint32_t offset_entry_count;
  6087. uint32_t i;
  6088. bool is_64bit;
  6089. printf (_("Table at Offset 0x%lx\n"), (long)(start - section->start));
  6090. SAFE_BYTE_GET_AND_INC (length, start, 4, end);
  6091. if (length == 0xffffffff)
  6092. {
  6093. is_64bit = true;
  6094. SAFE_BYTE_GET_AND_INC (length, start, 8, end);
  6095. }
  6096. else
  6097. is_64bit = false;
  6098. SAFE_BYTE_GET_AND_INC (version, start, 2, end);
  6099. SAFE_BYTE_GET_AND_INC (address_size, start, 1, end);
  6100. SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, end);
  6101. SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, end);
  6102. printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", length));
  6103. printf (_(" DWARF version: %u\n"), version);
  6104. printf (_(" Address size: %u\n"), address_size);
  6105. printf (_(" Segment size: %u\n"), segment_selector_size);
  6106. printf (_(" Offset entries: %u\n"), offset_entry_count);
  6107. if (version < 5)
  6108. {
  6109. warn (_("The %s section contains a corrupt or "
  6110. "unsupported version number: %d.\n"),
  6111. section->name, version);
  6112. return 0;
  6113. }
  6114. if (segment_selector_size != 0)
  6115. {
  6116. warn (_("The %s section contains an "
  6117. "unsupported segment selector size: %d.\n"),
  6118. section->name, segment_selector_size);
  6119. return 0;
  6120. }
  6121. if (offset_entry_count == 0)
  6122. {
  6123. warn (_("The %s section contains a table without offset\n"),
  6124. section->name);
  6125. return 0;
  6126. }
  6127. printf (_("\n Offset Entries starting at 0x%lx:\n"),
  6128. (long)(start - section->start));
  6129. if (is_64bit)
  6130. {
  6131. for (i = 0; i < offset_entry_count; i++)
  6132. {
  6133. dwarf_vma entry;
  6134. SAFE_BYTE_GET_AND_INC (entry, start, 8, end);
  6135. printf (_(" [%6u] 0x%s\n"), i, dwarf_vmatoa ("x", entry));
  6136. }
  6137. }
  6138. else
  6139. {
  6140. for (i = 0; i < offset_entry_count; i++)
  6141. {
  6142. uint32_t entry;
  6143. SAFE_BYTE_GET_AND_INC (entry, start, 4, end);
  6144. printf (_(" [%6u] 0x%x\n"), i, entry);
  6145. }
  6146. }
  6147. putchar ('\n');
  6148. uint32_t j;
  6149. for (j = 1, i = 0; i < offset_entry_count;)
  6150. {
  6151. unsigned char lle;
  6152. dwarf_vma base_address = 0;
  6153. dwarf_vma begin;
  6154. dwarf_vma finish;
  6155. dwarf_vma off = start - section->start;
  6156. if (j != i)
  6157. {
  6158. printf (_(" Offset Entry %u\n"), i);
  6159. j = i;
  6160. }
  6161. printf (" ");
  6162. print_dwarf_vma (off, 4);
  6163. SAFE_BYTE_GET_AND_INC (lle, start, 1, end);
  6164. switch (lle)
  6165. {
  6166. case DW_LLE_end_of_list:
  6167. printf (_("<End of list>\n\n"));
  6168. i ++;
  6169. continue;
  6170. case DW_LLE_base_addressx:
  6171. READ_ULEB (base_address, start, end);
  6172. print_dwarf_vma (base_address, address_size);
  6173. printf (_("(index into .debug_addr) "));
  6174. base_address = fetch_indexed_addr (base_address, address_size);
  6175. print_dwarf_vma (base_address, address_size);
  6176. printf (_("(base address)\n"));
  6177. continue;
  6178. case DW_LLE_startx_endx:
  6179. READ_ULEB (begin, start, end);
  6180. begin = fetch_indexed_addr (begin, address_size);
  6181. READ_ULEB (finish, start, end);
  6182. finish = fetch_indexed_addr (finish, address_size);
  6183. break;
  6184. case DW_LLE_startx_length:
  6185. READ_ULEB (begin, start, end);
  6186. begin = fetch_indexed_addr (begin, address_size);
  6187. READ_ULEB (finish, start, end);
  6188. finish += begin;
  6189. break;
  6190. case DW_LLE_offset_pair:
  6191. READ_ULEB (begin, start, end);
  6192. begin += base_address;
  6193. READ_ULEB (finish, start, end);
  6194. finish += base_address;
  6195. break;
  6196. case DW_LLE_default_location:
  6197. begin = finish = 0;
  6198. break;
  6199. case DW_LLE_base_address:
  6200. SAFE_BYTE_GET_AND_INC (base_address, start, address_size, end);
  6201. print_dwarf_vma (base_address, address_size);
  6202. printf (_("(base address)\n"));
  6203. continue;
  6204. case DW_LLE_start_end:
  6205. SAFE_BYTE_GET_AND_INC (begin, start, address_size, end);
  6206. SAFE_BYTE_GET_AND_INC (finish, start, address_size, end);
  6207. break;
  6208. case DW_LLE_start_length:
  6209. SAFE_BYTE_GET_AND_INC (begin, start, address_size, end);
  6210. READ_ULEB (finish, start, end);
  6211. finish += begin;
  6212. break;
  6213. default:
  6214. error (_("Invalid location list entry type %d\n"), lle);
  6215. return 0;
  6216. }
  6217. if (start == end)
  6218. {
  6219. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  6220. (unsigned long) off);
  6221. break;
  6222. }
  6223. print_dwarf_vma (begin, address_size);
  6224. print_dwarf_vma (finish, address_size);
  6225. if (begin == finish)
  6226. fputs (_(" (start == end)"), stdout);
  6227. else if (begin > finish)
  6228. fputs (_(" (start > end)"), stdout);
  6229. /* Read the counted location descriptions. */
  6230. READ_ULEB (length, start, end);
  6231. if (length > (size_t) (end - start))
  6232. {
  6233. warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
  6234. (unsigned long) off);
  6235. break;
  6236. }
  6237. putchar (' ');
  6238. (void) decode_location_expression (start, address_size, address_size,
  6239. version, length, 0, section);
  6240. start += length;
  6241. putchar ('\n');
  6242. }
  6243. putchar ('\n');
  6244. }
  6245. while (start < end);
  6246. return 1;
  6247. }
  6248. static int
  6249. display_debug_loc (struct dwarf_section *section, void *file)
  6250. {
  6251. unsigned char *start = section->start, *vstart = NULL;
  6252. dwarf_vma bytes;
  6253. unsigned char *section_begin = start;
  6254. unsigned int num_loc_list = 0;
  6255. dwarf_vma last_offset = 0;
  6256. dwarf_vma last_view = 0;
  6257. unsigned int first = 0;
  6258. unsigned int i;
  6259. unsigned int j;
  6260. int seen_first_offset = 0;
  6261. int locs_sorted = 1;
  6262. unsigned char *next = start, *vnext = vstart;
  6263. unsigned int *array = NULL;
  6264. const char *suffix = strrchr (section->name, '.');
  6265. bool is_dwo = false;
  6266. int is_loclists = strstr (section->name, "debug_loclists") != NULL;
  6267. dwarf_vma expected_start = 0;
  6268. if (suffix && strcmp (suffix, ".dwo") == 0)
  6269. is_dwo = true;
  6270. bytes = section->size;
  6271. if (bytes == 0)
  6272. {
  6273. printf (_("\nThe %s section is empty.\n"), section->name);
  6274. return 0;
  6275. }
  6276. if (is_loclists)
  6277. {
  6278. unsigned char *hdrptr = section_begin;
  6279. dwarf_vma ll_length;
  6280. unsigned short ll_version;
  6281. unsigned char *end = section_begin + section->size;
  6282. unsigned char address_size, segment_selector_size;
  6283. uint32_t offset_entry_count;
  6284. SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 4, end);
  6285. if (ll_length == 0xffffffff)
  6286. SAFE_BYTE_GET_AND_INC (ll_length, hdrptr, 8, end);
  6287. SAFE_BYTE_GET_AND_INC (ll_version, hdrptr, 2, end);
  6288. if (ll_version != 5)
  6289. {
  6290. warn (_("The %s section contains corrupt or "
  6291. "unsupported version number: %d.\n"),
  6292. section->name, ll_version);
  6293. return 0;
  6294. }
  6295. SAFE_BYTE_GET_AND_INC (address_size, hdrptr, 1, end);
  6296. SAFE_BYTE_GET_AND_INC (segment_selector_size, hdrptr, 1, end);
  6297. if (segment_selector_size != 0)
  6298. {
  6299. warn (_("The %s section contains "
  6300. "unsupported segment selector size: %d.\n"),
  6301. section->name, segment_selector_size);
  6302. return 0;
  6303. }
  6304. SAFE_BYTE_GET_AND_INC (offset_entry_count, hdrptr, 4, end);
  6305. if (offset_entry_count != 0)
  6306. return display_offset_entry_loclists (section);
  6307. expected_start = hdrptr - section_begin;
  6308. }
  6309. if (load_debug_info (file) == 0)
  6310. {
  6311. warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
  6312. section->name);
  6313. return 0;
  6314. }
  6315. /* Check the order of location list in .debug_info section. If
  6316. offsets of location lists are in the ascending order, we can
  6317. use `debug_information' directly. */
  6318. for (i = 0; i < num_debug_info_entries; i++)
  6319. {
  6320. unsigned int num;
  6321. num = debug_information [i].num_loc_offsets;
  6322. if (num > num_loc_list)
  6323. num_loc_list = num;
  6324. /* Check if we can use `debug_information' directly. */
  6325. if (locs_sorted && num != 0)
  6326. {
  6327. if (!seen_first_offset)
  6328. {
  6329. /* This is the first location list. */
  6330. last_offset = debug_information [i].loc_offsets [0];
  6331. last_view = debug_information [i].loc_views [0];
  6332. first = i;
  6333. seen_first_offset = 1;
  6334. j = 1;
  6335. }
  6336. else
  6337. j = 0;
  6338. for (; j < num; j++)
  6339. {
  6340. if (last_offset >
  6341. debug_information [i].loc_offsets [j]
  6342. || (last_offset == debug_information [i].loc_offsets [j]
  6343. && last_view > debug_information [i].loc_views [j]))
  6344. {
  6345. locs_sorted = 0;
  6346. break;
  6347. }
  6348. last_offset = debug_information [i].loc_offsets [j];
  6349. last_view = debug_information [i].loc_views [j];
  6350. }
  6351. }
  6352. }
  6353. if (!seen_first_offset)
  6354. error (_("No location lists in .debug_info section!\n"));
  6355. if (debug_information [first].num_loc_offsets > 0
  6356. && debug_information [first].loc_offsets [0] != expected_start
  6357. && debug_information [first].loc_views [0] != expected_start)
  6358. warn (_("Location lists in %s section start at 0x%s rather than 0x%s\n"),
  6359. section->name,
  6360. dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]),
  6361. dwarf_vmatoa ("x", expected_start));
  6362. if (!locs_sorted)
  6363. array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
  6364. introduce (section, false);
  6365. if (reloc_at (section, 0))
  6366. printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
  6367. printf (_(" Offset Begin End Expression\n"));
  6368. seen_first_offset = 0;
  6369. for (i = first; i < num_debug_info_entries; i++)
  6370. {
  6371. dwarf_vma offset, voffset;
  6372. dwarf_vma base_address;
  6373. unsigned int k;
  6374. int has_frame_base;
  6375. if (!locs_sorted)
  6376. {
  6377. for (k = 0; k < debug_information [i].num_loc_offsets; k++)
  6378. array[k] = k;
  6379. loc_offsets = debug_information [i].loc_offsets;
  6380. loc_views = debug_information [i].loc_views;
  6381. qsort (array, debug_information [i].num_loc_offsets,
  6382. sizeof (*array), loc_offsets_compar);
  6383. }
  6384. int adjacent_view_loclists = 1;
  6385. for (k = 0; k < debug_information [i].num_loc_offsets; k++)
  6386. {
  6387. j = locs_sorted ? k : array[k];
  6388. if (k
  6389. && (debug_information [i].loc_offsets [locs_sorted
  6390. ? k - 1 : array [k - 1]]
  6391. == debug_information [i].loc_offsets [j])
  6392. && (debug_information [i].loc_views [locs_sorted
  6393. ? k - 1 : array [k - 1]]
  6394. == debug_information [i].loc_views [j]))
  6395. continue;
  6396. has_frame_base = debug_information [i].have_frame_base [j];
  6397. offset = debug_information [i].loc_offsets [j];
  6398. next = section_begin + offset;
  6399. voffset = debug_information [i].loc_views [j];
  6400. if (voffset != vm1)
  6401. vnext = section_begin + voffset;
  6402. else
  6403. vnext = NULL;
  6404. base_address = debug_information [i].base_address;
  6405. if (vnext && vnext < next)
  6406. {
  6407. vstart = vnext;
  6408. display_view_pair_list (section, &vstart, i, next);
  6409. if (start == vnext)
  6410. start = vstart;
  6411. }
  6412. if (!seen_first_offset || !adjacent_view_loclists)
  6413. seen_first_offset = 1;
  6414. else
  6415. {
  6416. if (start < next)
  6417. warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
  6418. (unsigned long) (start - section_begin),
  6419. (unsigned long) offset,
  6420. section->name);
  6421. else if (start > next)
  6422. warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
  6423. (unsigned long) (start - section_begin),
  6424. (unsigned long) offset,
  6425. section->name);
  6426. }
  6427. start = next;
  6428. vstart = vnext;
  6429. if (offset >= bytes)
  6430. {
  6431. warn (_("Offset 0x%lx is bigger than %s section size.\n"),
  6432. (unsigned long) offset,
  6433. section->name);
  6434. continue;
  6435. }
  6436. if (vnext && voffset >= bytes)
  6437. {
  6438. warn (_("View Offset 0x%lx is bigger than %s section size.\n"),
  6439. (unsigned long) voffset,
  6440. section->name);
  6441. continue;
  6442. }
  6443. if (!is_loclists)
  6444. {
  6445. if (is_dwo)
  6446. display_loc_list_dwo (section, &start, i, offset,
  6447. &vstart, has_frame_base);
  6448. else
  6449. display_loc_list (section, &start, i, offset, base_address,
  6450. &vstart, has_frame_base);
  6451. }
  6452. else
  6453. {
  6454. if (is_dwo)
  6455. warn (_("DWO is not yet supported.\n"));
  6456. else
  6457. display_loclists_list (section, &start, i, offset, base_address,
  6458. &vstart, has_frame_base);
  6459. }
  6460. /* FIXME: this arrangement is quite simplistic. Nothing
  6461. requires locview lists to be adjacent to corresponding
  6462. loclists, and a single loclist could be augmented by
  6463. different locview lists, and vice-versa, unlikely as it
  6464. is that it would make sense to do so. Hopefully we'll
  6465. have view pair support built into loclists before we ever
  6466. need to address all these possibilities. */
  6467. if (adjacent_view_loclists && vnext
  6468. && vnext != start && vstart != next)
  6469. {
  6470. adjacent_view_loclists = 0;
  6471. warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
  6472. }
  6473. if (vnext && vnext == start)
  6474. display_view_pair_list (section, &start, i, vstart);
  6475. }
  6476. }
  6477. if (start < section->start + section->size)
  6478. warn (ngettext ("There is %ld unused byte at the end of section %s\n",
  6479. "There are %ld unused bytes at the end of section %s\n",
  6480. (long) (section->start + section->size - start)),
  6481. (long) (section->start + section->size - start), section->name);
  6482. putchar ('\n');
  6483. free (array);
  6484. return 1;
  6485. }
  6486. static int
  6487. display_debug_str (struct dwarf_section *section,
  6488. void *file ATTRIBUTE_UNUSED)
  6489. {
  6490. unsigned char *start = section->start;
  6491. dwarf_vma bytes = section->size;
  6492. dwarf_vma addr = section->address;
  6493. if (bytes == 0)
  6494. {
  6495. printf (_("\nThe %s section is empty.\n"), section->name);
  6496. return 0;
  6497. }
  6498. introduce (section, false);
  6499. while (bytes)
  6500. {
  6501. int j;
  6502. int k;
  6503. int lbytes;
  6504. lbytes = (bytes > 16 ? 16 : bytes);
  6505. printf (" 0x%8.8lx ", (unsigned long) addr);
  6506. for (j = 0; j < 16; j++)
  6507. {
  6508. if (j < lbytes)
  6509. printf ("%2.2x", start[j]);
  6510. else
  6511. printf (" ");
  6512. if ((j & 3) == 3)
  6513. printf (" ");
  6514. }
  6515. for (j = 0; j < lbytes; j++)
  6516. {
  6517. k = start[j];
  6518. if (k >= ' ' && k < 0x80)
  6519. printf ("%c", k);
  6520. else
  6521. printf (".");
  6522. }
  6523. putchar ('\n');
  6524. start += lbytes;
  6525. addr += lbytes;
  6526. bytes -= lbytes;
  6527. }
  6528. putchar ('\n');
  6529. return 1;
  6530. }
  6531. static int
  6532. display_debug_info (struct dwarf_section *section, void *file)
  6533. {
  6534. return process_debug_info (section, file, section->abbrev_sec, false, false);
  6535. }
  6536. static int
  6537. display_debug_types (struct dwarf_section *section, void *file)
  6538. {
  6539. return process_debug_info (section, file, section->abbrev_sec, false, true);
  6540. }
  6541. static int
  6542. display_trace_info (struct dwarf_section *section, void *file)
  6543. {
  6544. return process_debug_info (section, file, section->abbrev_sec, false, true);
  6545. }
  6546. static int
  6547. display_debug_aranges (struct dwarf_section *section,
  6548. void *file ATTRIBUTE_UNUSED)
  6549. {
  6550. unsigned char *start = section->start;
  6551. unsigned char *end = start + section->size;
  6552. introduce (section, false);
  6553. /* It does not matter if this load fails,
  6554. we test for that later on. */
  6555. load_debug_info (file);
  6556. while (start < end)
  6557. {
  6558. unsigned char *hdrptr;
  6559. DWARF2_Internal_ARange arange;
  6560. unsigned char *addr_ranges;
  6561. dwarf_vma length;
  6562. dwarf_vma address;
  6563. dwarf_vma sec_off;
  6564. unsigned char address_size;
  6565. unsigned int offset_size;
  6566. unsigned char *end_ranges;
  6567. hdrptr = start;
  6568. sec_off = hdrptr - section->start;
  6569. SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
  6570. if (arange.ar_length == 0xffffffff)
  6571. {
  6572. SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
  6573. offset_size = 8;
  6574. }
  6575. else
  6576. offset_size = 4;
  6577. if (arange.ar_length > (size_t) (end - hdrptr))
  6578. {
  6579. warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
  6580. section->name,
  6581. (unsigned long) sec_off,
  6582. dwarf_vmatoa ("x", arange.ar_length));
  6583. break;
  6584. }
  6585. end_ranges = hdrptr + arange.ar_length;
  6586. SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end_ranges);
  6587. SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size,
  6588. end_ranges);
  6589. if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
  6590. && num_debug_info_entries > 0
  6591. && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
  6592. warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
  6593. (unsigned long) arange.ar_info_offset, section->name);
  6594. SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end_ranges);
  6595. SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end_ranges);
  6596. if (arange.ar_version != 2 && arange.ar_version != 3)
  6597. {
  6598. /* PR 19872: A version number of 0 probably means that there is
  6599. padding at the end of the .debug_aranges section. Gold puts
  6600. it there when performing an incremental link, for example.
  6601. So do not generate a warning in this case. */
  6602. if (arange.ar_version)
  6603. warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
  6604. break;
  6605. }
  6606. printf (_(" Length: %ld\n"),
  6607. (long) arange.ar_length);
  6608. printf (_(" Version: %d\n"), arange.ar_version);
  6609. printf (_(" Offset into .debug_info: 0x%lx\n"),
  6610. (unsigned long) arange.ar_info_offset);
  6611. printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
  6612. printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
  6613. address_size = arange.ar_pointer_size + arange.ar_segment_size;
  6614. /* PR 17512: file: 001-108546-0.001:0.1. */
  6615. if (address_size == 0 || address_size > 8)
  6616. {
  6617. error (_("Invalid address size in %s section!\n"),
  6618. section->name);
  6619. break;
  6620. }
  6621. /* The DWARF spec does not require that the address size be a power
  6622. of two, but we do. This will have to change if we ever encounter
  6623. an uneven architecture. */
  6624. if ((address_size & (address_size - 1)) != 0)
  6625. {
  6626. warn (_("Pointer size + Segment size is not a power of two.\n"));
  6627. break;
  6628. }
  6629. if (address_size > 4)
  6630. printf (_("\n Address Length\n"));
  6631. else
  6632. printf (_("\n Address Length\n"));
  6633. addr_ranges = hdrptr;
  6634. /* Must pad to an alignment boundary that is twice the address size. */
  6635. addr_ranges += (2 * address_size - 1
  6636. - (hdrptr - start - 1) % (2 * address_size));
  6637. while (2 * address_size <= end_ranges - addr_ranges)
  6638. {
  6639. SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size,
  6640. end_ranges);
  6641. SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size,
  6642. end_ranges);
  6643. printf (" ");
  6644. print_dwarf_vma (address, address_size);
  6645. print_dwarf_vma (length, address_size);
  6646. putchar ('\n');
  6647. }
  6648. start = end_ranges;
  6649. }
  6650. printf ("\n");
  6651. return 1;
  6652. }
  6653. /* Comparison function for qsort. */
  6654. static int
  6655. comp_addr_base (const void * v0, const void * v1)
  6656. {
  6657. debug_info *info0 = *(debug_info **) v0;
  6658. debug_info *info1 = *(debug_info **) v1;
  6659. return info0->addr_base - info1->addr_base;
  6660. }
  6661. /* Display the debug_addr section. */
  6662. static int
  6663. display_debug_addr (struct dwarf_section *section,
  6664. void *file)
  6665. {
  6666. debug_info **debug_addr_info;
  6667. unsigned char *entry;
  6668. unsigned char *end;
  6669. unsigned int i;
  6670. unsigned int count;
  6671. unsigned char * header;
  6672. if (section->size == 0)
  6673. {
  6674. printf (_("\nThe %s section is empty.\n"), section->name);
  6675. return 0;
  6676. }
  6677. if (load_debug_info (file) == 0)
  6678. {
  6679. warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
  6680. section->name);
  6681. return 0;
  6682. }
  6683. introduce (section, false);
  6684. /* PR 17531: file: cf38d01b.
  6685. We use xcalloc because a corrupt file may not have initialised all of the
  6686. fields in the debug_info structure, which means that the sort below might
  6687. try to move uninitialised data. */
  6688. debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
  6689. sizeof (debug_info *));
  6690. count = 0;
  6691. for (i = 0; i < num_debug_info_entries; i++)
  6692. if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
  6693. {
  6694. /* PR 17531: file: cf38d01b. */
  6695. if (debug_information[i].addr_base >= section->size)
  6696. warn (_("Corrupt address base (%lx) found in debug section %u\n"),
  6697. (unsigned long) debug_information[i].addr_base, i);
  6698. else
  6699. debug_addr_info [count++] = debug_information + i;
  6700. }
  6701. /* Add a sentinel to make iteration convenient. */
  6702. debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
  6703. debug_addr_info [count]->addr_base = section->size;
  6704. qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
  6705. header = section->start;
  6706. for (i = 0; i < count; i++)
  6707. {
  6708. unsigned int idx;
  6709. unsigned int address_size = debug_addr_info [i]->pointer_size;
  6710. printf (_(" For compilation unit at offset 0x%s:\n"),
  6711. dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
  6712. printf (_("\tIndex\tAddress\n"));
  6713. entry = section->start + debug_addr_info [i]->addr_base;
  6714. if (debug_addr_info [i]->dwarf_version >= 5)
  6715. {
  6716. size_t header_size = entry - header;
  6717. unsigned char * curr_header = header;
  6718. dwarf_vma length;
  6719. int version;
  6720. int segment_selector_size;
  6721. if (header_size != 8 && header_size != 16)
  6722. {
  6723. warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
  6724. section->name, (long) header_size);
  6725. return 0;
  6726. }
  6727. SAFE_BYTE_GET_AND_INC (length, curr_header, 4, entry);
  6728. if (length == 0xffffffff)
  6729. SAFE_BYTE_GET_AND_INC (length, curr_header, 8, entry);
  6730. end = curr_header + length;
  6731. SAFE_BYTE_GET_AND_INC (version, curr_header, 2, entry);
  6732. if (version != 5)
  6733. warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
  6734. section->name, version);
  6735. SAFE_BYTE_GET_AND_INC (address_size, curr_header, 1, entry);
  6736. SAFE_BYTE_GET_AND_INC (segment_selector_size, curr_header, 1, entry);
  6737. address_size += segment_selector_size;
  6738. }
  6739. else
  6740. end = section->start + debug_addr_info [i + 1]->addr_base;
  6741. header = end;
  6742. idx = 0;
  6743. while (entry < end)
  6744. {
  6745. dwarf_vma base = byte_get (entry, address_size);
  6746. printf (_("\t%d:\t"), idx);
  6747. print_dwarf_vma (base, address_size);
  6748. printf ("\n");
  6749. entry += address_size;
  6750. idx++;
  6751. }
  6752. }
  6753. printf ("\n");
  6754. free (debug_addr_info);
  6755. return 1;
  6756. }
  6757. /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
  6758. static int
  6759. display_debug_str_offsets (struct dwarf_section *section,
  6760. void *file ATTRIBUTE_UNUSED)
  6761. {
  6762. unsigned long idx;
  6763. if (section->size == 0)
  6764. {
  6765. printf (_("\nThe %s section is empty.\n"), section->name);
  6766. return 0;
  6767. }
  6768. unsigned char *start = section->start;
  6769. unsigned char *end = start + section->size;
  6770. unsigned char *curr = start;
  6771. const char *suffix = strrchr (section->name, '.');
  6772. bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
  6773. if (dwo)
  6774. load_debug_section_with_follow (str_dwo, file);
  6775. else
  6776. load_debug_section_with_follow (str, file);
  6777. introduce (section, false);
  6778. while (curr < end)
  6779. {
  6780. dwarf_vma length;
  6781. dwarf_vma entry_length;
  6782. SAFE_BYTE_GET_AND_INC (length, curr, 4, end);
  6783. /* FIXME: We assume that this means 64-bit DWARF is being used. */
  6784. if (length == 0xffffffff)
  6785. {
  6786. SAFE_BYTE_GET_AND_INC (length, curr, 8, end);
  6787. entry_length = 8;
  6788. }
  6789. else
  6790. entry_length = 4;
  6791. unsigned char *entries_end;
  6792. if (length == 0)
  6793. {
  6794. /* This is probably an old style .debug_str_offset section which
  6795. just contains offsets and no header (and the first offset is 0). */
  6796. length = section->size;
  6797. curr = section->start;
  6798. entries_end = end;
  6799. printf (_(" Length: %#lx\n"), (unsigned long) length);
  6800. printf (_(" Index Offset [String]\n"));
  6801. }
  6802. else
  6803. {
  6804. if (length <= (dwarf_vma) (end - curr))
  6805. entries_end = curr + length;
  6806. else
  6807. {
  6808. warn (_("Section %s is too small %#lx\n"),
  6809. section->name, (unsigned long) section->size);
  6810. entries_end = end;
  6811. }
  6812. int version;
  6813. SAFE_BYTE_GET_AND_INC (version, curr, 2, entries_end);
  6814. if (version != 5)
  6815. warn (_("Unexpected version number in str_offset header: %#x\n"), version);
  6816. int padding;
  6817. SAFE_BYTE_GET_AND_INC (padding, curr, 2, entries_end);
  6818. if (padding != 0)
  6819. warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding);
  6820. printf (_(" Length: %#lx\n"), (unsigned long) length);
  6821. printf (_(" Version: %#lx\n"), (unsigned long) version);
  6822. printf (_(" Index Offset [String]\n"));
  6823. }
  6824. for (idx = 0; curr < entries_end; idx++)
  6825. {
  6826. dwarf_vma offset;
  6827. const unsigned char * string;
  6828. if ((dwarf_vma) (entries_end - curr) < entry_length)
  6829. /* Not enough space to read one entry_length, give up. */
  6830. return 0;
  6831. SAFE_BYTE_GET_AND_INC (offset, curr, entry_length, entries_end);
  6832. if (dwo)
  6833. string = (const unsigned char *)
  6834. fetch_indexed_string (idx, NULL, entry_length, dwo);
  6835. else
  6836. string = fetch_indirect_string (offset);
  6837. printf (" %8lu %8s %s\n", idx, dwarf_vmatoa ("x", offset),
  6838. string);
  6839. }
  6840. }
  6841. return 1;
  6842. }
  6843. /* Each debug_information[x].range_lists[y] gets this representation for
  6844. sorting purposes. */
  6845. struct range_entry
  6846. {
  6847. /* The debug_information[x].range_lists[y] value. */
  6848. dwarf_vma ranges_offset;
  6849. /* Original debug_information to find parameters of the data. */
  6850. debug_info *debug_info_p;
  6851. };
  6852. /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
  6853. static int
  6854. range_entry_compar (const void *ap, const void *bp)
  6855. {
  6856. const struct range_entry *a_re = (const struct range_entry *) ap;
  6857. const struct range_entry *b_re = (const struct range_entry *) bp;
  6858. const dwarf_vma a = a_re->ranges_offset;
  6859. const dwarf_vma b = b_re->ranges_offset;
  6860. return (a > b) - (b > a);
  6861. }
  6862. static void
  6863. display_debug_ranges_list (unsigned char * start,
  6864. unsigned char * finish,
  6865. unsigned int pointer_size,
  6866. dwarf_vma offset,
  6867. dwarf_vma base_address)
  6868. {
  6869. while (start < finish)
  6870. {
  6871. dwarf_vma begin;
  6872. dwarf_vma end;
  6873. SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
  6874. if (start >= finish)
  6875. break;
  6876. SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
  6877. printf (" ");
  6878. print_dwarf_vma (offset, 4);
  6879. if (begin == 0 && end == 0)
  6880. {
  6881. printf (_("<End of list>\n"));
  6882. break;
  6883. }
  6884. /* Check base address specifiers. */
  6885. if (is_max_address (begin, pointer_size)
  6886. && !is_max_address (end, pointer_size))
  6887. {
  6888. base_address = end;
  6889. print_dwarf_vma (begin, pointer_size);
  6890. print_dwarf_vma (end, pointer_size);
  6891. printf ("(base address)\n");
  6892. continue;
  6893. }
  6894. print_dwarf_vma (begin + base_address, pointer_size);
  6895. print_dwarf_vma (end + base_address, pointer_size);
  6896. if (begin == end)
  6897. fputs (_("(start == end)"), stdout);
  6898. else if (begin > end)
  6899. fputs (_("(start > end)"), stdout);
  6900. putchar ('\n');
  6901. }
  6902. }
  6903. static void
  6904. display_debug_rnglists_list (unsigned char * start,
  6905. unsigned char * finish,
  6906. unsigned int pointer_size,
  6907. dwarf_vma offset,
  6908. dwarf_vma base_address)
  6909. {
  6910. unsigned char *next = start;
  6911. while (1)
  6912. {
  6913. dwarf_vma off = offset + (start - next);
  6914. enum dwarf_range_list_entry rlet;
  6915. /* Initialize it due to a false compiler warning. */
  6916. dwarf_vma begin = -1, length, end = -1;
  6917. if (start >= finish)
  6918. {
  6919. warn (_("Range list starting at offset 0x%s is not terminated.\n"),
  6920. dwarf_vmatoa ("x", offset));
  6921. break;
  6922. }
  6923. printf (" ");
  6924. print_dwarf_vma (off, 4);
  6925. SAFE_BYTE_GET_AND_INC (rlet, start, 1, finish);
  6926. switch (rlet)
  6927. {
  6928. case DW_RLE_end_of_list:
  6929. printf (_("<End of list>\n"));
  6930. break;
  6931. case DW_RLE_base_addressx:
  6932. READ_ULEB (base_address, start, finish);
  6933. print_dwarf_vma (base_address, pointer_size);
  6934. printf (_("(base address index) "));
  6935. base_address = fetch_indexed_addr (base_address, pointer_size);
  6936. print_dwarf_vma (base_address, pointer_size);
  6937. printf (_("(base address)\n"));
  6938. break;
  6939. case DW_RLE_startx_endx:
  6940. READ_ULEB (begin, start, finish);
  6941. READ_ULEB (end, start, finish);
  6942. begin = fetch_indexed_addr (begin, pointer_size);
  6943. end = fetch_indexed_addr (begin, pointer_size);
  6944. break;
  6945. case DW_RLE_startx_length:
  6946. READ_ULEB (begin, start, finish);
  6947. READ_ULEB (length, start, finish);
  6948. begin = fetch_indexed_addr (begin, pointer_size);
  6949. end = begin + length;
  6950. break;
  6951. case DW_RLE_offset_pair:
  6952. READ_ULEB (begin, start, finish);
  6953. READ_ULEB (end, start, finish);
  6954. break;
  6955. case DW_RLE_base_address:
  6956. SAFE_BYTE_GET_AND_INC (base_address, start, pointer_size, finish);
  6957. print_dwarf_vma (base_address, pointer_size);
  6958. printf (_("(base address)\n"));
  6959. break;
  6960. case DW_RLE_start_end:
  6961. SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
  6962. SAFE_BYTE_GET_AND_INC (end, start, pointer_size, finish);
  6963. break;
  6964. case DW_RLE_start_length:
  6965. SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
  6966. READ_ULEB (length, start, finish);
  6967. end = begin + length;
  6968. break;
  6969. default:
  6970. error (_("Invalid range list entry type %d\n"), rlet);
  6971. rlet = DW_RLE_end_of_list;
  6972. break;
  6973. }
  6974. if (rlet == DW_RLE_end_of_list)
  6975. break;
  6976. if (rlet == DW_RLE_base_address || rlet == DW_RLE_base_addressx)
  6977. continue;
  6978. /* Only a DW_RLE_offset_pair needs the base address added. */
  6979. if (rlet == DW_RLE_offset_pair)
  6980. {
  6981. begin += base_address;
  6982. end += base_address;
  6983. }
  6984. print_dwarf_vma (begin, pointer_size);
  6985. print_dwarf_vma (end, pointer_size);
  6986. if (begin == end)
  6987. fputs (_("(start == end)"), stdout);
  6988. else if (begin > end)
  6989. fputs (_("(start > end)"), stdout);
  6990. putchar ('\n');
  6991. }
  6992. }
  6993. static int
  6994. display_debug_ranges (struct dwarf_section *section,
  6995. void *file ATTRIBUTE_UNUSED)
  6996. {
  6997. unsigned char * start = section->start;
  6998. unsigned char * last_start = start;
  6999. dwarf_vma bytes = section->size;
  7000. unsigned char * section_begin = start;
  7001. unsigned char * finish = start + bytes;
  7002. unsigned int num_range_list, i;
  7003. struct range_entry * range_entries;
  7004. struct range_entry * range_entry_fill;
  7005. int is_rnglists = strstr (section->name, "debug_rnglists") != NULL;
  7006. /* Initialize it due to a false compiler warning. */
  7007. unsigned char address_size = 0;
  7008. dwarf_vma last_offset = 0;
  7009. if (bytes == 0)
  7010. {
  7011. printf (_("\nThe %s section is empty.\n"), section->name);
  7012. return 0;
  7013. }
  7014. introduce (section, false);
  7015. if (is_rnglists)
  7016. {
  7017. dwarf_vma initial_length;
  7018. unsigned char segment_selector_size;
  7019. unsigned int offset_size, offset_entry_count;
  7020. unsigned short version;
  7021. /* Get and check the length of the block. */
  7022. SAFE_BYTE_GET_AND_INC (initial_length, start, 4, finish);
  7023. if (initial_length == 0xffffffff)
  7024. {
  7025. /* This section is 64-bit DWARF 3. */
  7026. SAFE_BYTE_GET_AND_INC (initial_length, start, 8, finish);
  7027. offset_size = 8;
  7028. }
  7029. else
  7030. offset_size = 4;
  7031. if (initial_length > (size_t) (finish - start))
  7032. {
  7033. /* If the length field has a relocation against it, then we should
  7034. not complain if it is inaccurate (and probably negative).
  7035. It is copied from .debug_line handling code. */
  7036. if (reloc_at (section, (start - section->start) - offset_size))
  7037. {
  7038. initial_length = finish - start;
  7039. }
  7040. else
  7041. {
  7042. warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
  7043. (long) initial_length);
  7044. return 0;
  7045. }
  7046. }
  7047. /* Get the other fields in the header. */
  7048. SAFE_BYTE_GET_AND_INC (version, start, 2, finish);
  7049. SAFE_BYTE_GET_AND_INC (address_size, start, 1, finish);
  7050. SAFE_BYTE_GET_AND_INC (segment_selector_size, start, 1, finish);
  7051. SAFE_BYTE_GET_AND_INC (offset_entry_count, start, 4, finish);
  7052. printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", initial_length));
  7053. printf (_(" DWARF version: %u\n"), version);
  7054. printf (_(" Address size: %u\n"), address_size);
  7055. printf (_(" Segment size: %u\n"), segment_selector_size);
  7056. printf (_(" Offset entries: %u\n"), offset_entry_count);
  7057. /* Check the fields. */
  7058. if (segment_selector_size != 0)
  7059. {
  7060. warn (_("The %s section contains "
  7061. "unsupported segment selector size: %d.\n"),
  7062. section->name, segment_selector_size);
  7063. return 0;
  7064. }
  7065. if (version < 5)
  7066. {
  7067. warn (_("Only DWARF version 5+ debug_rnglists info "
  7068. "is currently supported.\n"));
  7069. return 0;
  7070. }
  7071. if (offset_entry_count != 0)
  7072. {
  7073. printf (_("\n Offsets starting at 0x%lx:\n"), (long)(start - section->start));
  7074. if (offset_size == 8)
  7075. {
  7076. for (i = 0; i < offset_entry_count; i++)
  7077. {
  7078. dwarf_vma entry;
  7079. SAFE_BYTE_GET_AND_INC (entry, start, 8, finish);
  7080. printf (_(" [%6u] 0x%s\n"), i, dwarf_vmatoa ("x", entry));
  7081. }
  7082. }
  7083. else
  7084. {
  7085. for (i = 0; i < offset_entry_count; i++)
  7086. {
  7087. uint32_t entry;
  7088. SAFE_BYTE_GET_AND_INC (entry, start, 4, finish);
  7089. printf (_(" [%6u] 0x%x\n"), i, entry);
  7090. }
  7091. }
  7092. }
  7093. }
  7094. if (load_debug_info (file) == 0)
  7095. {
  7096. warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
  7097. section->name);
  7098. return 0;
  7099. }
  7100. num_range_list = 0;
  7101. for (i = 0; i < num_debug_info_entries; i++)
  7102. {
  7103. if (debug_information [i].dwarf_version < 5 && is_rnglists)
  7104. /* Skip .debug_rnglists reference. */
  7105. continue;
  7106. if (debug_information [i].dwarf_version >= 5 && !is_rnglists)
  7107. /* Skip .debug_range reference. */
  7108. continue;
  7109. num_range_list += debug_information [i].num_range_lists;
  7110. }
  7111. if (num_range_list == 0)
  7112. {
  7113. /* This can happen when the file was compiled with -gsplit-debug
  7114. which removes references to range lists from the primary .o file. */
  7115. printf (_("No range lists in .debug_info section.\n"));
  7116. return 1;
  7117. }
  7118. range_entries = (struct range_entry *)
  7119. xmalloc (sizeof (*range_entries) * num_range_list);
  7120. range_entry_fill = range_entries;
  7121. for (i = 0; i < num_debug_info_entries; i++)
  7122. {
  7123. debug_info *debug_info_p = &debug_information[i];
  7124. unsigned int j;
  7125. if (debug_information [i].dwarf_version < 5 && is_rnglists)
  7126. /* Skip .debug_rnglists reference. */
  7127. continue;
  7128. if (debug_information [i].dwarf_version >= 5 && !is_rnglists)
  7129. /* Skip .debug_range reference. */
  7130. continue;
  7131. for (j = 0; j < debug_info_p->num_range_lists; j++)
  7132. {
  7133. range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
  7134. range_entry_fill->debug_info_p = debug_info_p;
  7135. range_entry_fill++;
  7136. }
  7137. }
  7138. qsort (range_entries, num_range_list, sizeof (*range_entries),
  7139. range_entry_compar);
  7140. if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
  7141. warn (_("Range lists in %s section start at 0x%lx\n"),
  7142. section->name, (unsigned long) range_entries[0].ranges_offset);
  7143. putchar ('\n');
  7144. printf (_(" Offset Begin End\n"));
  7145. for (i = 0; i < num_range_list; i++)
  7146. {
  7147. struct range_entry *range_entry = &range_entries[i];
  7148. debug_info *debug_info_p = range_entry->debug_info_p;
  7149. unsigned int pointer_size;
  7150. dwarf_vma offset;
  7151. unsigned char *next;
  7152. dwarf_vma base_address;
  7153. pointer_size = (is_rnglists ? address_size : debug_info_p->pointer_size);
  7154. offset = range_entry->ranges_offset;
  7155. base_address = debug_info_p->base_address;
  7156. /* PR 17512: file: 001-101485-0.001:0.1. */
  7157. if (pointer_size < 2 || pointer_size > 8)
  7158. {
  7159. warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
  7160. pointer_size, (unsigned long) offset);
  7161. continue;
  7162. }
  7163. if (offset > (size_t) (finish - section_begin))
  7164. {
  7165. warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
  7166. (unsigned long) offset, i);
  7167. continue;
  7168. }
  7169. next = section_begin + offset;
  7170. /* If multiple DWARF entities reference the same range then we will
  7171. have multiple entries in the `range_entries' list for the same
  7172. offset. Thanks to the sort above these will all be consecutive in
  7173. the `range_entries' list, so we can easily ignore duplicates
  7174. here. */
  7175. if (i > 0 && last_offset == offset)
  7176. continue;
  7177. last_offset = offset;
  7178. if (dwarf_check != 0 && i > 0)
  7179. {
  7180. if (start < next)
  7181. warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
  7182. (unsigned long) (start - section_begin),
  7183. (unsigned long) (next - section_begin), section->name);
  7184. else if (start > next)
  7185. {
  7186. if (next == last_start)
  7187. continue;
  7188. warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
  7189. (unsigned long) (start - section_begin),
  7190. (unsigned long) (next - section_begin), section->name);
  7191. }
  7192. }
  7193. start = next;
  7194. last_start = next;
  7195. if (is_rnglists)
  7196. display_debug_rnglists_list
  7197. (start, finish, pointer_size, offset, base_address);
  7198. else
  7199. display_debug_ranges_list
  7200. (start, finish, pointer_size, offset, base_address);
  7201. }
  7202. putchar ('\n');
  7203. free (range_entries);
  7204. return 1;
  7205. }
  7206. typedef struct Frame_Chunk
  7207. {
  7208. struct Frame_Chunk *next;
  7209. unsigned char *chunk_start;
  7210. unsigned int ncols;
  7211. /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
  7212. short int *col_type;
  7213. int *col_offset;
  7214. char *augmentation;
  7215. unsigned int code_factor;
  7216. int data_factor;
  7217. dwarf_vma pc_begin;
  7218. dwarf_vma pc_range;
  7219. unsigned int cfa_reg;
  7220. dwarf_vma cfa_offset;
  7221. unsigned int ra;
  7222. unsigned char fde_encoding;
  7223. unsigned char cfa_exp;
  7224. unsigned char ptr_size;
  7225. unsigned char segment_size;
  7226. }
  7227. Frame_Chunk;
  7228. typedef const char *(*dwarf_regname_lookup_ftype) (unsigned int);
  7229. static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func;
  7230. static const char *const *dwarf_regnames;
  7231. static unsigned int dwarf_regnames_count;
  7232. /* A marker for a col_type that means this column was never referenced
  7233. in the frame info. */
  7234. #define DW_CFA_unreferenced (-1)
  7235. /* Return 0 if no more space is needed, 1 if more space is needed,
  7236. -1 for invalid reg. */
  7237. static int
  7238. frame_need_space (Frame_Chunk *fc, unsigned int reg)
  7239. {
  7240. unsigned int prev = fc->ncols;
  7241. if (reg < (unsigned int) fc->ncols)
  7242. return 0;
  7243. if (dwarf_regnames_count > 0
  7244. && reg > dwarf_regnames_count)
  7245. return -1;
  7246. fc->ncols = reg + 1;
  7247. /* PR 17512: file: 10450-2643-0.004.
  7248. If reg == -1 then this can happen... */
  7249. if (fc->ncols == 0)
  7250. return -1;
  7251. /* PR 17512: file: 2844a11d. */
  7252. if (fc->ncols > 1024 && dwarf_regnames_count == 0)
  7253. {
  7254. error (_("Unfeasibly large register number: %u\n"), reg);
  7255. fc->ncols = 0;
  7256. /* FIXME: 1024 is an arbitrary limit. Increase it if
  7257. we ever encounter a valid binary that exceeds it. */
  7258. return -1;
  7259. }
  7260. fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
  7261. sizeof (short int));
  7262. fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
  7263. /* PR 17512: file:002-10025-0.005. */
  7264. if (fc->col_type == NULL || fc->col_offset == NULL)
  7265. {
  7266. error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
  7267. fc->ncols);
  7268. fc->ncols = 0;
  7269. return -1;
  7270. }
  7271. while (prev < fc->ncols)
  7272. {
  7273. fc->col_type[prev] = DW_CFA_unreferenced;
  7274. fc->col_offset[prev] = 0;
  7275. prev++;
  7276. }
  7277. return 1;
  7278. }
  7279. static const char *const dwarf_regnames_i386[] =
  7280. {
  7281. "eax", "ecx", "edx", "ebx", /* 0 - 3 */
  7282. "esp", "ebp", "esi", "edi", /* 4 - 7 */
  7283. "eip", "eflags", NULL, /* 8 - 10 */
  7284. "st0", "st1", "st2", "st3", /* 11 - 14 */
  7285. "st4", "st5", "st6", "st7", /* 15 - 18 */
  7286. NULL, NULL, /* 19 - 20 */
  7287. "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
  7288. "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
  7289. "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
  7290. "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
  7291. "fcw", "fsw", "mxcsr", /* 37 - 39 */
  7292. "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
  7293. "tr", "ldtr", /* 48 - 49 */
  7294. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
  7295. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
  7296. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
  7297. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
  7298. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
  7299. NULL, NULL, NULL, /* 90 - 92 */
  7300. "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
  7301. };
  7302. static const char *const dwarf_regnames_iamcu[] =
  7303. {
  7304. "eax", "ecx", "edx", "ebx", /* 0 - 3 */
  7305. "esp", "ebp", "esi", "edi", /* 4 - 7 */
  7306. "eip", "eflags", NULL, /* 8 - 10 */
  7307. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 11 - 18 */
  7308. NULL, NULL, /* 19 - 20 */
  7309. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 21 - 28 */
  7310. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 29 - 36 */
  7311. NULL, NULL, NULL, /* 37 - 39 */
  7312. "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
  7313. "tr", "ldtr", /* 48 - 49 */
  7314. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
  7315. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
  7316. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
  7317. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
  7318. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
  7319. NULL, NULL, NULL, /* 90 - 92 */
  7320. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* 93 - 100 */
  7321. };
  7322. static void
  7323. init_dwarf_regnames_i386 (void)
  7324. {
  7325. dwarf_regnames = dwarf_regnames_i386;
  7326. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
  7327. dwarf_regnames_lookup_func = regname_internal_by_table_only;
  7328. }
  7329. static void
  7330. init_dwarf_regnames_iamcu (void)
  7331. {
  7332. dwarf_regnames = dwarf_regnames_iamcu;
  7333. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_iamcu);
  7334. dwarf_regnames_lookup_func = regname_internal_by_table_only;
  7335. }
  7336. static const char *const dwarf_regnames_x86_64[] =
  7337. {
  7338. "rax", "rdx", "rcx", "rbx",
  7339. "rsi", "rdi", "rbp", "rsp",
  7340. "r8", "r9", "r10", "r11",
  7341. "r12", "r13", "r14", "r15",
  7342. "rip",
  7343. "xmm0", "xmm1", "xmm2", "xmm3",
  7344. "xmm4", "xmm5", "xmm6", "xmm7",
  7345. "xmm8", "xmm9", "xmm10", "xmm11",
  7346. "xmm12", "xmm13", "xmm14", "xmm15",
  7347. "st0", "st1", "st2", "st3",
  7348. "st4", "st5", "st6", "st7",
  7349. "mm0", "mm1", "mm2", "mm3",
  7350. "mm4", "mm5", "mm6", "mm7",
  7351. "rflags",
  7352. "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
  7353. "fs.base", "gs.base", NULL, NULL,
  7354. "tr", "ldtr",
  7355. "mxcsr", "fcw", "fsw",
  7356. "xmm16", "xmm17", "xmm18", "xmm19",
  7357. "xmm20", "xmm21", "xmm22", "xmm23",
  7358. "xmm24", "xmm25", "xmm26", "xmm27",
  7359. "xmm28", "xmm29", "xmm30", "xmm31",
  7360. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
  7361. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
  7362. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
  7363. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
  7364. NULL, NULL, NULL, /* 115 - 117 */
  7365. "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
  7366. };
  7367. static void
  7368. init_dwarf_regnames_x86_64 (void)
  7369. {
  7370. dwarf_regnames = dwarf_regnames_x86_64;
  7371. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
  7372. dwarf_regnames_lookup_func = regname_internal_by_table_only;
  7373. }
  7374. static const char *const dwarf_regnames_aarch64[] =
  7375. {
  7376. "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
  7377. "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
  7378. "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
  7379. "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
  7380. NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
  7381. NULL, NULL, NULL, NULL, NULL, NULL, "vg", "ffr",
  7382. "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
  7383. "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
  7384. "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  7385. "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
  7386. "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
  7387. "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
  7388. "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
  7389. "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
  7390. "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
  7391. "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
  7392. };
  7393. static void
  7394. init_dwarf_regnames_aarch64 (void)
  7395. {
  7396. dwarf_regnames = dwarf_regnames_aarch64;
  7397. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
  7398. dwarf_regnames_lookup_func = regname_internal_by_table_only;
  7399. }
  7400. static const char *const dwarf_regnames_s390[] =
  7401. {
  7402. /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
  7403. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  7404. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  7405. "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
  7406. "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
  7407. "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
  7408. "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
  7409. "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
  7410. "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
  7411. "pswm", "pswa",
  7412. NULL, NULL,
  7413. "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
  7414. "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
  7415. };
  7416. static void
  7417. init_dwarf_regnames_s390 (void)
  7418. {
  7419. dwarf_regnames = dwarf_regnames_s390;
  7420. dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_s390);
  7421. dwarf_regnames_lookup_func = regname_internal_by_table_only;
  7422. }
  7423. static const char *const dwarf_regnames_riscv[] =
  7424. {
  7425. "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
  7426. "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
  7427. "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
  7428. "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
  7429. "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
  7430. "fs0", "fs1", /* 40 - 41 */
  7431. "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
  7432. "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
  7433. "fs10", "fs11", /* 58 - 59 */
  7434. "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
  7435. };
  7436. /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
  7437. the large number of CSRs. */
  7438. static const char *
  7439. regname_internal_riscv (unsigned int regno)
  7440. {
  7441. const char *name = NULL;
  7442. /* Lookup in the table first, this covers GPR and FPR. */
  7443. if (regno < ARRAY_SIZE (dwarf_regnames_riscv))
  7444. name = dwarf_regnames_riscv [regno];
  7445. else if (regno >= 4096 && regno <= 8191)
  7446. {
  7447. /* This might be a CSR, these live in a sparse number space from 4096
  7448. to 8191 These numbers are defined in the RISC-V ELF ABI
  7449. document. */
  7450. switch (regno)
  7451. {
  7452. #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
  7453. case VALUE + 4096: name = #NAME; break;
  7454. #include "opcode/riscv-opc.h"
  7455. #undef DECLARE_CSR
  7456. default:
  7457. {
  7458. static char csr_name[10];
  7459. snprintf (csr_name, sizeof (csr_name), "csr%d", (regno - 4096));
  7460. name = csr_name;
  7461. }
  7462. break;
  7463. }
  7464. }
  7465. return name;
  7466. }
  7467. static void
  7468. init_dwarf_regnames_riscv (void)
  7469. {
  7470. dwarf_regnames = NULL;
  7471. dwarf_regnames_count = 8192;
  7472. dwarf_regnames_lookup_func = regname_internal_riscv;
  7473. }
  7474. void
  7475. init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine)
  7476. {
  7477. dwarf_regnames_lookup_func = NULL;
  7478. switch (e_machine)
  7479. {
  7480. case EM_386:
  7481. init_dwarf_regnames_i386 ();
  7482. break;
  7483. case EM_IAMCU:
  7484. init_dwarf_regnames_iamcu ();
  7485. break;
  7486. case EM_X86_64:
  7487. case EM_L1OM:
  7488. case EM_K1OM:
  7489. init_dwarf_regnames_x86_64 ();
  7490. break;
  7491. case EM_AARCH64:
  7492. init_dwarf_regnames_aarch64 ();
  7493. break;
  7494. case EM_S390:
  7495. init_dwarf_regnames_s390 ();
  7496. break;
  7497. case EM_RISCV:
  7498. init_dwarf_regnames_riscv ();
  7499. break;
  7500. default:
  7501. break;
  7502. }
  7503. }
  7504. /* Initialize the DWARF register name lookup state based on the
  7505. architecture and specific machine type of a BFD. */
  7506. void
  7507. init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
  7508. unsigned long mach)
  7509. {
  7510. dwarf_regnames_lookup_func = NULL;
  7511. switch (arch)
  7512. {
  7513. case bfd_arch_i386:
  7514. switch (mach)
  7515. {
  7516. case bfd_mach_x86_64:
  7517. case bfd_mach_x86_64_intel_syntax:
  7518. case bfd_mach_x64_32:
  7519. case bfd_mach_x64_32_intel_syntax:
  7520. init_dwarf_regnames_x86_64 ();
  7521. break;
  7522. default:
  7523. init_dwarf_regnames_i386 ();
  7524. break;
  7525. }
  7526. break;
  7527. case bfd_arch_iamcu:
  7528. init_dwarf_regnames_iamcu ();
  7529. break;
  7530. case bfd_arch_aarch64:
  7531. init_dwarf_regnames_aarch64();
  7532. break;
  7533. case bfd_arch_s390:
  7534. init_dwarf_regnames_s390 ();
  7535. break;
  7536. case bfd_arch_riscv:
  7537. init_dwarf_regnames_riscv ();
  7538. break;
  7539. default:
  7540. break;
  7541. }
  7542. }
  7543. static const char *
  7544. regname_internal_by_table_only (unsigned int regno)
  7545. {
  7546. if (dwarf_regnames != NULL
  7547. && regno < dwarf_regnames_count
  7548. && dwarf_regnames [regno] != NULL)
  7549. return dwarf_regnames [regno];
  7550. return NULL;
  7551. }
  7552. static const char *
  7553. regname (unsigned int regno, int name_only_p)
  7554. {
  7555. static char reg[64];
  7556. const char *name = NULL;
  7557. if (dwarf_regnames_lookup_func != NULL)
  7558. name = dwarf_regnames_lookup_func (regno);
  7559. if (name != NULL)
  7560. {
  7561. if (name_only_p)
  7562. return name;
  7563. snprintf (reg, sizeof (reg), "r%d (%s)", regno, name);
  7564. }
  7565. else
  7566. snprintf (reg, sizeof (reg), "r%d", regno);
  7567. return reg;
  7568. }
  7569. static void
  7570. frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
  7571. {
  7572. unsigned int r;
  7573. char tmp[100];
  7574. if (*max_regs != fc->ncols)
  7575. *max_regs = fc->ncols;
  7576. if (*need_col_headers)
  7577. {
  7578. *need_col_headers = 0;
  7579. printf ("%-*s CFA ", eh_addr_size * 2, " LOC");
  7580. for (r = 0; r < *max_regs; r++)
  7581. if (fc->col_type[r] != DW_CFA_unreferenced)
  7582. {
  7583. if (r == fc->ra)
  7584. printf ("ra ");
  7585. else
  7586. printf ("%-5s ", regname (r, 1));
  7587. }
  7588. printf ("\n");
  7589. }
  7590. print_dwarf_vma (fc->pc_begin, eh_addr_size);
  7591. if (fc->cfa_exp)
  7592. strcpy (tmp, "exp");
  7593. else
  7594. sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), (int) fc->cfa_offset);
  7595. printf ("%-8s ", tmp);
  7596. for (r = 0; r < fc->ncols; r++)
  7597. {
  7598. if (fc->col_type[r] != DW_CFA_unreferenced)
  7599. {
  7600. switch (fc->col_type[r])
  7601. {
  7602. case DW_CFA_undefined:
  7603. strcpy (tmp, "u");
  7604. break;
  7605. case DW_CFA_same_value:
  7606. strcpy (tmp, "s");
  7607. break;
  7608. case DW_CFA_offset:
  7609. sprintf (tmp, "c%+d", fc->col_offset[r]);
  7610. break;
  7611. case DW_CFA_val_offset:
  7612. sprintf (tmp, "v%+d", fc->col_offset[r]);
  7613. break;
  7614. case DW_CFA_register:
  7615. sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
  7616. break;
  7617. case DW_CFA_expression:
  7618. strcpy (tmp, "exp");
  7619. break;
  7620. case DW_CFA_val_expression:
  7621. strcpy (tmp, "vexp");
  7622. break;
  7623. default:
  7624. strcpy (tmp, "n/a");
  7625. break;
  7626. }
  7627. printf ("%-5s ", tmp);
  7628. }
  7629. }
  7630. printf ("\n");
  7631. }
  7632. #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
  7633. static unsigned char *
  7634. read_cie (unsigned char *start, unsigned char *end,
  7635. Frame_Chunk **p_cie, int *p_version,
  7636. bfd_size_type *p_aug_len, unsigned char **p_aug)
  7637. {
  7638. int version;
  7639. Frame_Chunk *fc;
  7640. unsigned char *augmentation_data = NULL;
  7641. bfd_size_type augmentation_data_len = 0;
  7642. * p_cie = NULL;
  7643. /* PR 17512: file: 001-228113-0.004. */
  7644. if (start >= end)
  7645. return end;
  7646. fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
  7647. memset (fc, 0, sizeof (Frame_Chunk));
  7648. fc->col_type = (short int *) xmalloc (sizeof (short int));
  7649. fc->col_offset = (int *) xmalloc (sizeof (int));
  7650. version = *start++;
  7651. fc->augmentation = (char *) start;
  7652. /* PR 17512: file: 001-228113-0.004.
  7653. Skip past augmentation name, but avoid running off the end of the data. */
  7654. while (start < end)
  7655. if (* start ++ == '\0')
  7656. break;
  7657. if (start == end)
  7658. {
  7659. warn (_("No terminator for augmentation name\n"));
  7660. goto fail;
  7661. }
  7662. if (strcmp (fc->augmentation, "eh") == 0)
  7663. {
  7664. if (eh_addr_size > (size_t) (end - start))
  7665. goto fail;
  7666. start += eh_addr_size;
  7667. }
  7668. if (version >= 4)
  7669. {
  7670. if (2 > (size_t) (end - start))
  7671. goto fail;
  7672. GET (fc->ptr_size, 1);
  7673. if (fc->ptr_size < 1 || fc->ptr_size > 8)
  7674. {
  7675. warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
  7676. goto fail;
  7677. }
  7678. GET (fc->segment_size, 1);
  7679. /* PR 17512: file: e99d2804. */
  7680. if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
  7681. {
  7682. warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
  7683. goto fail;
  7684. }
  7685. eh_addr_size = fc->ptr_size;
  7686. }
  7687. else
  7688. {
  7689. fc->ptr_size = eh_addr_size;
  7690. fc->segment_size = 0;
  7691. }
  7692. READ_ULEB (fc->code_factor, start, end);
  7693. READ_SLEB (fc->data_factor, start, end);
  7694. if (start >= end)
  7695. goto fail;
  7696. if (version == 1)
  7697. {
  7698. GET (fc->ra, 1);
  7699. }
  7700. else
  7701. {
  7702. READ_ULEB (fc->ra, start, end);
  7703. }
  7704. if (fc->augmentation[0] == 'z')
  7705. {
  7706. if (start >= end)
  7707. goto fail;
  7708. READ_ULEB (augmentation_data_len, start, end);
  7709. augmentation_data = start;
  7710. /* PR 17512: file: 11042-2589-0.004. */
  7711. if (augmentation_data_len > (bfd_size_type) (end - start))
  7712. {
  7713. warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
  7714. dwarf_vmatoa ("x", augmentation_data_len),
  7715. (unsigned long) (end - start));
  7716. goto fail;
  7717. }
  7718. start += augmentation_data_len;
  7719. }
  7720. if (augmentation_data_len)
  7721. {
  7722. unsigned char *p;
  7723. unsigned char *q;
  7724. unsigned char *qend;
  7725. p = (unsigned char *) fc->augmentation + 1;
  7726. q = augmentation_data;
  7727. qend = q + augmentation_data_len;
  7728. while (p < end && q < qend)
  7729. {
  7730. if (*p == 'L')
  7731. q++;
  7732. else if (*p == 'P')
  7733. q += 1 + size_of_encoded_value (*q);
  7734. else if (*p == 'R')
  7735. fc->fde_encoding = *q++;
  7736. else if (*p == 'S')
  7737. ;
  7738. else if (*p == 'B')
  7739. ;
  7740. else
  7741. break;
  7742. p++;
  7743. }
  7744. /* Note - it is OK if this loop terminates with q < qend.
  7745. Padding may have been inserted to align the end of the CIE. */
  7746. }
  7747. *p_cie = fc;
  7748. if (p_version)
  7749. *p_version = version;
  7750. if (p_aug_len)
  7751. {
  7752. *p_aug_len = augmentation_data_len;
  7753. *p_aug = augmentation_data;
  7754. }
  7755. return start;
  7756. fail:
  7757. free (fc->col_offset);
  7758. free (fc->col_type);
  7759. free (fc);
  7760. return end;
  7761. }
  7762. /* Prints out the contents on the DATA array formatted as unsigned bytes.
  7763. If do_wide is not enabled, then formats the output to fit into 80 columns.
  7764. PRINTED contains the number of characters already written to the current
  7765. output line. */
  7766. static void
  7767. display_data (bfd_size_type printed,
  7768. const unsigned char * data,
  7769. const bfd_size_type len)
  7770. {
  7771. if (do_wide || len < ((80 - printed) / 3))
  7772. for (printed = 0; printed < len; ++printed)
  7773. printf (" %02x", data[printed]);
  7774. else
  7775. {
  7776. for (printed = 0; printed < len; ++printed)
  7777. {
  7778. if (printed % (80 / 3) == 0)
  7779. putchar ('\n');
  7780. printf (" %02x", data[printed]);
  7781. }
  7782. }
  7783. }
  7784. /* Prints out the contents on the augmentation data array.
  7785. If do_wide is not enabled, then formats the output to fit into 80 columns. */
  7786. static void
  7787. display_augmentation_data (const unsigned char * data, const bfd_size_type len)
  7788. {
  7789. bfd_size_type i;
  7790. i = printf (_(" Augmentation data: "));
  7791. display_data (i, data, len);
  7792. }
  7793. static int
  7794. display_debug_frames (struct dwarf_section *section,
  7795. void *file ATTRIBUTE_UNUSED)
  7796. {
  7797. unsigned char *start = section->start;
  7798. unsigned char *end = start + section->size;
  7799. unsigned char *section_start = start;
  7800. Frame_Chunk *chunks = NULL, *forward_refs = NULL;
  7801. Frame_Chunk *remembered_state = NULL;
  7802. Frame_Chunk *rs;
  7803. bool is_eh = strcmp (section->name, ".eh_frame") == 0;
  7804. unsigned int max_regs = 0;
  7805. const char *bad_reg = _("bad register: ");
  7806. unsigned int saved_eh_addr_size = eh_addr_size;
  7807. introduce (section, false);
  7808. while (start < end)
  7809. {
  7810. unsigned char *saved_start;
  7811. unsigned char *block_end;
  7812. dwarf_vma length;
  7813. dwarf_vma cie_id;
  7814. Frame_Chunk *fc;
  7815. Frame_Chunk *cie;
  7816. int need_col_headers = 1;
  7817. unsigned char *augmentation_data = NULL;
  7818. bfd_size_type augmentation_data_len = 0;
  7819. unsigned int encoded_ptr_size = saved_eh_addr_size;
  7820. unsigned int offset_size;
  7821. bool all_nops;
  7822. static Frame_Chunk fde_fc;
  7823. saved_start = start;
  7824. SAFE_BYTE_GET_AND_INC (length, start, 4, end);
  7825. if (length == 0)
  7826. {
  7827. printf ("\n%08lx ZERO terminator\n\n",
  7828. (unsigned long)(saved_start - section_start));
  7829. /* Skip any zero terminators that directly follow.
  7830. A corrupt section size could have loaded a whole
  7831. slew of zero filled memory bytes. eg
  7832. PR 17512: file: 070-19381-0.004. */
  7833. while (start < end && * start == 0)
  7834. ++ start;
  7835. continue;
  7836. }
  7837. if (length == 0xffffffff)
  7838. {
  7839. SAFE_BYTE_GET_AND_INC (length, start, 8, end);
  7840. offset_size = 8;
  7841. }
  7842. else
  7843. offset_size = 4;
  7844. if (length > (size_t) (end - start))
  7845. {
  7846. warn ("Invalid length 0x%s in FDE at %#08lx\n",
  7847. dwarf_vmatoa_1 (NULL, length, offset_size),
  7848. (unsigned long) (saved_start - section_start));
  7849. block_end = end;
  7850. }
  7851. else
  7852. block_end = start + length;
  7853. SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, block_end);
  7854. if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
  7855. || (offset_size == 8 && cie_id == DW64_CIE_ID)))
  7856. {
  7857. int version;
  7858. unsigned int mreg;
  7859. start = read_cie (start, block_end, &cie, &version,
  7860. &augmentation_data_len, &augmentation_data);
  7861. /* PR 17512: file: 027-135133-0.005. */
  7862. if (cie == NULL)
  7863. break;
  7864. fc = cie;
  7865. fc->next = chunks;
  7866. chunks = fc;
  7867. fc->chunk_start = saved_start;
  7868. mreg = max_regs > 0 ? max_regs - 1 : 0;
  7869. if (mreg < fc->ra)
  7870. mreg = fc->ra;
  7871. if (frame_need_space (fc, mreg) < 0)
  7872. break;
  7873. if (fc->fde_encoding)
  7874. encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
  7875. printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
  7876. print_dwarf_vma (length, fc->ptr_size);
  7877. print_dwarf_vma (cie_id, offset_size);
  7878. if (do_debug_frames_interp)
  7879. {
  7880. printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
  7881. fc->code_factor, fc->data_factor, fc->ra);
  7882. }
  7883. else
  7884. {
  7885. printf ("CIE\n");
  7886. printf (" Version: %d\n", version);
  7887. printf (" Augmentation: \"%s\"\n", fc->augmentation);
  7888. if (version >= 4)
  7889. {
  7890. printf (" Pointer Size: %u\n", fc->ptr_size);
  7891. printf (" Segment Size: %u\n", fc->segment_size);
  7892. }
  7893. printf (" Code alignment factor: %u\n", fc->code_factor);
  7894. printf (" Data alignment factor: %d\n", fc->data_factor);
  7895. printf (" Return address column: %d\n", fc->ra);
  7896. if (augmentation_data_len)
  7897. display_augmentation_data (augmentation_data, augmentation_data_len);
  7898. putchar ('\n');
  7899. }
  7900. }
  7901. else
  7902. {
  7903. unsigned char *look_for;
  7904. unsigned long segment_selector;
  7905. dwarf_vma cie_off;
  7906. cie_off = cie_id;
  7907. if (is_eh)
  7908. {
  7909. dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
  7910. cie_off = (cie_off ^ sign) - sign;
  7911. cie_off = start - 4 - section_start - cie_off;
  7912. }
  7913. look_for = section_start + cie_off;
  7914. if (cie_off <= (dwarf_vma) (saved_start - section_start))
  7915. {
  7916. for (cie = chunks; cie ; cie = cie->next)
  7917. if (cie->chunk_start == look_for)
  7918. break;
  7919. }
  7920. else if (cie_off >= section->size)
  7921. cie = NULL;
  7922. else
  7923. {
  7924. for (cie = forward_refs; cie ; cie = cie->next)
  7925. if (cie->chunk_start == look_for)
  7926. break;
  7927. if (!cie)
  7928. {
  7929. unsigned int off_size;
  7930. unsigned char *cie_scan;
  7931. cie_scan = look_for;
  7932. off_size = 4;
  7933. SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
  7934. if (length == 0xffffffff)
  7935. {
  7936. SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
  7937. off_size = 8;
  7938. }
  7939. if (length != 0 && length <= (size_t) (end - cie_scan))
  7940. {
  7941. dwarf_vma c_id;
  7942. unsigned char *cie_end = cie_scan + length;
  7943. SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size,
  7944. cie_end);
  7945. if (is_eh
  7946. ? c_id == 0
  7947. : ((off_size == 4 && c_id == DW_CIE_ID)
  7948. || (off_size == 8 && c_id == DW64_CIE_ID)))
  7949. {
  7950. int version;
  7951. unsigned int mreg;
  7952. read_cie (cie_scan, cie_end, &cie, &version,
  7953. &augmentation_data_len, &augmentation_data);
  7954. /* PR 17512: file: 3450-2098-0.004. */
  7955. if (cie == NULL)
  7956. {
  7957. warn (_("Failed to read CIE information\n"));
  7958. break;
  7959. }
  7960. cie->next = forward_refs;
  7961. forward_refs = cie;
  7962. cie->chunk_start = look_for;
  7963. mreg = max_regs > 0 ? max_regs - 1 : 0;
  7964. if (mreg < cie->ra)
  7965. mreg = cie->ra;
  7966. if (frame_need_space (cie, mreg) < 0)
  7967. {
  7968. warn (_("Invalid max register\n"));
  7969. break;
  7970. }
  7971. if (cie->fde_encoding)
  7972. encoded_ptr_size
  7973. = size_of_encoded_value (cie->fde_encoding);
  7974. }
  7975. }
  7976. }
  7977. }
  7978. fc = &fde_fc;
  7979. memset (fc, 0, sizeof (Frame_Chunk));
  7980. if (!cie)
  7981. {
  7982. fc->ncols = 0;
  7983. fc->col_type = (short int *) xmalloc (sizeof (short int));
  7984. fc->col_offset = (int *) xmalloc (sizeof (int));
  7985. if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
  7986. {
  7987. warn (_("Invalid max register\n"));
  7988. break;
  7989. }
  7990. cie = fc;
  7991. fc->augmentation = "";
  7992. fc->fde_encoding = 0;
  7993. fc->ptr_size = eh_addr_size;
  7994. fc->segment_size = 0;
  7995. }
  7996. else
  7997. {
  7998. fc->ncols = cie->ncols;
  7999. fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
  8000. fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
  8001. memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
  8002. memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
  8003. fc->augmentation = cie->augmentation;
  8004. fc->ptr_size = cie->ptr_size;
  8005. eh_addr_size = cie->ptr_size;
  8006. fc->segment_size = cie->segment_size;
  8007. fc->code_factor = cie->code_factor;
  8008. fc->data_factor = cie->data_factor;
  8009. fc->cfa_reg = cie->cfa_reg;
  8010. fc->cfa_offset = cie->cfa_offset;
  8011. fc->ra = cie->ra;
  8012. if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
  8013. {
  8014. warn (_("Invalid max register\n"));
  8015. break;
  8016. }
  8017. fc->fde_encoding = cie->fde_encoding;
  8018. }
  8019. if (fc->fde_encoding)
  8020. encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
  8021. segment_selector = 0;
  8022. if (fc->segment_size)
  8023. {
  8024. if (fc->segment_size > sizeof (segment_selector))
  8025. {
  8026. /* PR 17512: file: 9e196b3e. */
  8027. warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc->segment_size);
  8028. fc->segment_size = 4;
  8029. }
  8030. SAFE_BYTE_GET_AND_INC (segment_selector, start,
  8031. fc->segment_size, block_end);
  8032. }
  8033. fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section,
  8034. block_end);
  8035. /* FIXME: It appears that sometimes the final pc_range value is
  8036. encoded in less than encoded_ptr_size bytes. See the x86_64
  8037. run of the "objcopy on compressed debug sections" test for an
  8038. example of this. */
  8039. SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size,
  8040. block_end);
  8041. if (cie->augmentation[0] == 'z')
  8042. {
  8043. READ_ULEB (augmentation_data_len, start, block_end);
  8044. augmentation_data = start;
  8045. /* PR 17512 file: 722-8446-0.004 and PR 22386. */
  8046. if (augmentation_data_len > (bfd_size_type) (block_end - start))
  8047. {
  8048. warn (_("Augmentation data too long: 0x%s, "
  8049. "expected at most %#lx\n"),
  8050. dwarf_vmatoa ("x", augmentation_data_len),
  8051. (unsigned long) (block_end - start));
  8052. start = block_end;
  8053. augmentation_data = NULL;
  8054. augmentation_data_len = 0;
  8055. }
  8056. start += augmentation_data_len;
  8057. }
  8058. printf ("\n%08lx %s %s FDE ",
  8059. (unsigned long)(saved_start - section_start),
  8060. dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
  8061. dwarf_vmatoa_1 (NULL, cie_id, offset_size));
  8062. if (cie->chunk_start)
  8063. printf ("cie=%08lx",
  8064. (unsigned long) (cie->chunk_start - section_start));
  8065. else
  8066. /* Ideally translate "invalid " to 8 chars, trailing space
  8067. is optional. */
  8068. printf (_("cie=invalid "));
  8069. printf (" pc=");
  8070. if (fc->segment_size)
  8071. printf ("%04lx:", segment_selector);
  8072. printf ("%s..%s\n",
  8073. dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
  8074. dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
  8075. if (! do_debug_frames_interp && augmentation_data_len)
  8076. {
  8077. display_augmentation_data (augmentation_data, augmentation_data_len);
  8078. putchar ('\n');
  8079. }
  8080. }
  8081. /* At this point, fc is the current chunk, cie (if any) is set, and
  8082. we're about to interpret instructions for the chunk. */
  8083. /* ??? At present we need to do this always, since this sizes the
  8084. fc->col_type and fc->col_offset arrays, which we write into always.
  8085. We should probably split the interpreted and non-interpreted bits
  8086. into two different routines, since there's so much that doesn't
  8087. really overlap between them. */
  8088. if (1 || do_debug_frames_interp)
  8089. {
  8090. /* Start by making a pass over the chunk, allocating storage
  8091. and taking note of what registers are used. */
  8092. unsigned char *tmp = start;
  8093. while (start < block_end)
  8094. {
  8095. unsigned int reg, op, opa;
  8096. unsigned long temp;
  8097. op = *start++;
  8098. opa = op & 0x3f;
  8099. if (op & 0xc0)
  8100. op &= 0xc0;
  8101. /* Warning: if you add any more cases to this switch, be
  8102. sure to add them to the corresponding switch below. */
  8103. switch (op)
  8104. {
  8105. case DW_CFA_advance_loc:
  8106. break;
  8107. case DW_CFA_offset:
  8108. SKIP_ULEB (start, block_end);
  8109. if (frame_need_space (fc, opa) >= 0)
  8110. fc->col_type[opa] = DW_CFA_undefined;
  8111. break;
  8112. case DW_CFA_restore:
  8113. if (frame_need_space (fc, opa) >= 0)
  8114. fc->col_type[opa] = DW_CFA_undefined;
  8115. break;
  8116. case DW_CFA_set_loc:
  8117. if ((size_t) (block_end - start) < encoded_ptr_size)
  8118. start = block_end;
  8119. else
  8120. start += encoded_ptr_size;
  8121. break;
  8122. case DW_CFA_advance_loc1:
  8123. if ((size_t) (block_end - start) < 1)
  8124. start = block_end;
  8125. else
  8126. start += 1;
  8127. break;
  8128. case DW_CFA_advance_loc2:
  8129. if ((size_t) (block_end - start) < 2)
  8130. start = block_end;
  8131. else
  8132. start += 2;
  8133. break;
  8134. case DW_CFA_advance_loc4:
  8135. if ((size_t) (block_end - start) < 4)
  8136. start = block_end;
  8137. else
  8138. start += 4;
  8139. break;
  8140. case DW_CFA_offset_extended:
  8141. case DW_CFA_val_offset:
  8142. READ_ULEB (reg, start, block_end);
  8143. SKIP_ULEB (start, block_end);
  8144. if (frame_need_space (fc, reg) >= 0)
  8145. fc->col_type[reg] = DW_CFA_undefined;
  8146. break;
  8147. case DW_CFA_restore_extended:
  8148. READ_ULEB (reg, start, block_end);
  8149. if (frame_need_space (fc, reg) >= 0)
  8150. fc->col_type[reg] = DW_CFA_undefined;
  8151. break;
  8152. case DW_CFA_undefined:
  8153. READ_ULEB (reg, start, block_end);
  8154. if (frame_need_space (fc, reg) >= 0)
  8155. fc->col_type[reg] = DW_CFA_undefined;
  8156. break;
  8157. case DW_CFA_same_value:
  8158. READ_ULEB (reg, start, block_end);
  8159. if (frame_need_space (fc, reg) >= 0)
  8160. fc->col_type[reg] = DW_CFA_undefined;
  8161. break;
  8162. case DW_CFA_register:
  8163. READ_ULEB (reg, start, block_end);
  8164. SKIP_ULEB (start, block_end);
  8165. if (frame_need_space (fc, reg) >= 0)
  8166. fc->col_type[reg] = DW_CFA_undefined;
  8167. break;
  8168. case DW_CFA_def_cfa:
  8169. SKIP_ULEB (start, block_end);
  8170. SKIP_ULEB (start, block_end);
  8171. break;
  8172. case DW_CFA_def_cfa_register:
  8173. SKIP_ULEB (start, block_end);
  8174. break;
  8175. case DW_CFA_def_cfa_offset:
  8176. SKIP_ULEB (start, block_end);
  8177. break;
  8178. case DW_CFA_def_cfa_expression:
  8179. READ_ULEB (temp, start, block_end);
  8180. if ((size_t) (block_end - start) < temp)
  8181. start = block_end;
  8182. else
  8183. start += temp;
  8184. break;
  8185. case DW_CFA_expression:
  8186. case DW_CFA_val_expression:
  8187. READ_ULEB (reg, start, block_end);
  8188. READ_ULEB (temp, start, block_end);
  8189. if ((size_t) (block_end - start) < temp)
  8190. start = block_end;
  8191. else
  8192. start += temp;
  8193. if (frame_need_space (fc, reg) >= 0)
  8194. fc->col_type[reg] = DW_CFA_undefined;
  8195. break;
  8196. case DW_CFA_offset_extended_sf:
  8197. case DW_CFA_val_offset_sf:
  8198. READ_ULEB (reg, start, block_end);
  8199. SKIP_SLEB (start, block_end);
  8200. if (frame_need_space (fc, reg) >= 0)
  8201. fc->col_type[reg] = DW_CFA_undefined;
  8202. break;
  8203. case DW_CFA_def_cfa_sf:
  8204. SKIP_ULEB (start, block_end);
  8205. SKIP_SLEB (start, block_end);
  8206. break;
  8207. case DW_CFA_def_cfa_offset_sf:
  8208. SKIP_SLEB (start, block_end);
  8209. break;
  8210. case DW_CFA_MIPS_advance_loc8:
  8211. if ((size_t) (block_end - start) < 8)
  8212. start = block_end;
  8213. else
  8214. start += 8;
  8215. break;
  8216. case DW_CFA_GNU_args_size:
  8217. SKIP_ULEB (start, block_end);
  8218. break;
  8219. case DW_CFA_GNU_negative_offset_extended:
  8220. READ_ULEB (reg, start, block_end);
  8221. SKIP_ULEB (start, block_end);
  8222. if (frame_need_space (fc, reg) >= 0)
  8223. fc->col_type[reg] = DW_CFA_undefined;
  8224. break;
  8225. default:
  8226. break;
  8227. }
  8228. }
  8229. start = tmp;
  8230. }
  8231. all_nops = true;
  8232. /* Now we know what registers are used, make a second pass over
  8233. the chunk, this time actually printing out the info. */
  8234. while (start < block_end)
  8235. {
  8236. unsigned op, opa;
  8237. unsigned long ul, roffs;
  8238. /* Note: It is tempting to use an unsigned long for 'reg' but there
  8239. are various functions, notably frame_space_needed() that assume that
  8240. reg is an unsigned int. */
  8241. unsigned int reg;
  8242. dwarf_signed_vma l;
  8243. dwarf_vma ofs;
  8244. dwarf_vma vma;
  8245. const char *reg_prefix = "";
  8246. op = *start++;
  8247. opa = op & 0x3f;
  8248. if (op & 0xc0)
  8249. op &= 0xc0;
  8250. /* Make a note if something other than DW_CFA_nop happens. */
  8251. if (op != DW_CFA_nop)
  8252. all_nops = false;
  8253. /* Warning: if you add any more cases to this switch, be
  8254. sure to add them to the corresponding switch above. */
  8255. switch (op)
  8256. {
  8257. case DW_CFA_advance_loc:
  8258. if (do_debug_frames_interp)
  8259. frame_display_row (fc, &need_col_headers, &max_regs);
  8260. else
  8261. printf (" DW_CFA_advance_loc: %d to %s\n",
  8262. opa * fc->code_factor,
  8263. dwarf_vmatoa_1 (NULL,
  8264. fc->pc_begin + opa * fc->code_factor,
  8265. fc->ptr_size));
  8266. fc->pc_begin += opa * fc->code_factor;
  8267. break;
  8268. case DW_CFA_offset:
  8269. READ_ULEB (roffs, start, block_end);
  8270. if (opa >= (unsigned int) fc->ncols)
  8271. reg_prefix = bad_reg;
  8272. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8273. printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
  8274. reg_prefix, regname (opa, 0),
  8275. roffs * fc->data_factor);
  8276. if (*reg_prefix == '\0')
  8277. {
  8278. fc->col_type[opa] = DW_CFA_offset;
  8279. fc->col_offset[opa] = roffs * fc->data_factor;
  8280. }
  8281. break;
  8282. case DW_CFA_restore:
  8283. if (opa >= (unsigned int) fc->ncols)
  8284. reg_prefix = bad_reg;
  8285. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8286. printf (" DW_CFA_restore: %s%s\n",
  8287. reg_prefix, regname (opa, 0));
  8288. if (*reg_prefix != '\0')
  8289. break;
  8290. if (opa >= (unsigned int) cie->ncols
  8291. || (do_debug_frames_interp
  8292. && cie->col_type[opa] == DW_CFA_unreferenced))
  8293. {
  8294. fc->col_type[opa] = DW_CFA_undefined;
  8295. fc->col_offset[opa] = 0;
  8296. }
  8297. else
  8298. {
  8299. fc->col_type[opa] = cie->col_type[opa];
  8300. fc->col_offset[opa] = cie->col_offset[opa];
  8301. }
  8302. break;
  8303. case DW_CFA_set_loc:
  8304. vma = get_encoded_value (&start, fc->fde_encoding, section,
  8305. block_end);
  8306. if (do_debug_frames_interp)
  8307. frame_display_row (fc, &need_col_headers, &max_regs);
  8308. else
  8309. printf (" DW_CFA_set_loc: %s\n",
  8310. dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
  8311. fc->pc_begin = vma;
  8312. break;
  8313. case DW_CFA_advance_loc1:
  8314. SAFE_BYTE_GET_AND_INC (ofs, start, 1, block_end);
  8315. if (do_debug_frames_interp)
  8316. frame_display_row (fc, &need_col_headers, &max_regs);
  8317. else
  8318. printf (" DW_CFA_advance_loc1: %ld to %s\n",
  8319. (unsigned long) (ofs * fc->code_factor),
  8320. dwarf_vmatoa_1 (NULL,
  8321. fc->pc_begin + ofs * fc->code_factor,
  8322. fc->ptr_size));
  8323. fc->pc_begin += ofs * fc->code_factor;
  8324. break;
  8325. case DW_CFA_advance_loc2:
  8326. SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
  8327. if (do_debug_frames_interp)
  8328. frame_display_row (fc, &need_col_headers, &max_regs);
  8329. else
  8330. printf (" DW_CFA_advance_loc2: %ld to %s\n",
  8331. (unsigned long) (ofs * fc->code_factor),
  8332. dwarf_vmatoa_1 (NULL,
  8333. fc->pc_begin + ofs * fc->code_factor,
  8334. fc->ptr_size));
  8335. fc->pc_begin += ofs * fc->code_factor;
  8336. break;
  8337. case DW_CFA_advance_loc4:
  8338. SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
  8339. if (do_debug_frames_interp)
  8340. frame_display_row (fc, &need_col_headers, &max_regs);
  8341. else
  8342. printf (" DW_CFA_advance_loc4: %ld to %s\n",
  8343. (unsigned long) (ofs * fc->code_factor),
  8344. dwarf_vmatoa_1 (NULL,
  8345. fc->pc_begin + ofs * fc->code_factor,
  8346. fc->ptr_size));
  8347. fc->pc_begin += ofs * fc->code_factor;
  8348. break;
  8349. case DW_CFA_offset_extended:
  8350. READ_ULEB (reg, start, block_end);
  8351. READ_ULEB (roffs, start, block_end);
  8352. if (reg >= (unsigned int) fc->ncols)
  8353. reg_prefix = bad_reg;
  8354. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8355. printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
  8356. reg_prefix, regname (reg, 0),
  8357. roffs * fc->data_factor);
  8358. if (*reg_prefix == '\0')
  8359. {
  8360. fc->col_type[reg] = DW_CFA_offset;
  8361. fc->col_offset[reg] = roffs * fc->data_factor;
  8362. }
  8363. break;
  8364. case DW_CFA_val_offset:
  8365. READ_ULEB (reg, start, block_end);
  8366. READ_ULEB (roffs, start, block_end);
  8367. if (reg >= (unsigned int) fc->ncols)
  8368. reg_prefix = bad_reg;
  8369. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8370. printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
  8371. reg_prefix, regname (reg, 0),
  8372. roffs * fc->data_factor);
  8373. if (*reg_prefix == '\0')
  8374. {
  8375. fc->col_type[reg] = DW_CFA_val_offset;
  8376. fc->col_offset[reg] = roffs * fc->data_factor;
  8377. }
  8378. break;
  8379. case DW_CFA_restore_extended:
  8380. READ_ULEB (reg, start, block_end);
  8381. if (reg >= (unsigned int) fc->ncols)
  8382. reg_prefix = bad_reg;
  8383. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8384. printf (" DW_CFA_restore_extended: %s%s\n",
  8385. reg_prefix, regname (reg, 0));
  8386. if (*reg_prefix != '\0')
  8387. break;
  8388. if (reg >= (unsigned int) cie->ncols)
  8389. {
  8390. fc->col_type[reg] = DW_CFA_undefined;
  8391. fc->col_offset[reg] = 0;
  8392. }
  8393. else
  8394. {
  8395. fc->col_type[reg] = cie->col_type[reg];
  8396. fc->col_offset[reg] = cie->col_offset[reg];
  8397. }
  8398. break;
  8399. case DW_CFA_undefined:
  8400. READ_ULEB (reg, start, block_end);
  8401. if (reg >= (unsigned int) fc->ncols)
  8402. reg_prefix = bad_reg;
  8403. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8404. printf (" DW_CFA_undefined: %s%s\n",
  8405. reg_prefix, regname (reg, 0));
  8406. if (*reg_prefix == '\0')
  8407. {
  8408. fc->col_type[reg] = DW_CFA_undefined;
  8409. fc->col_offset[reg] = 0;
  8410. }
  8411. break;
  8412. case DW_CFA_same_value:
  8413. READ_ULEB (reg, start, block_end);
  8414. if (reg >= (unsigned int) fc->ncols)
  8415. reg_prefix = bad_reg;
  8416. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8417. printf (" DW_CFA_same_value: %s%s\n",
  8418. reg_prefix, regname (reg, 0));
  8419. if (*reg_prefix == '\0')
  8420. {
  8421. fc->col_type[reg] = DW_CFA_same_value;
  8422. fc->col_offset[reg] = 0;
  8423. }
  8424. break;
  8425. case DW_CFA_register:
  8426. READ_ULEB (reg, start, block_end);
  8427. READ_ULEB (roffs, start, block_end);
  8428. if (reg >= (unsigned int) fc->ncols)
  8429. reg_prefix = bad_reg;
  8430. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8431. {
  8432. printf (" DW_CFA_register: %s%s in ",
  8433. reg_prefix, regname (reg, 0));
  8434. puts (regname (roffs, 0));
  8435. }
  8436. if (*reg_prefix == '\0')
  8437. {
  8438. fc->col_type[reg] = DW_CFA_register;
  8439. fc->col_offset[reg] = roffs;
  8440. }
  8441. break;
  8442. case DW_CFA_remember_state:
  8443. if (! do_debug_frames_interp)
  8444. printf (" DW_CFA_remember_state\n");
  8445. rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
  8446. rs->cfa_offset = fc->cfa_offset;
  8447. rs->cfa_reg = fc->cfa_reg;
  8448. rs->ra = fc->ra;
  8449. rs->cfa_exp = fc->cfa_exp;
  8450. rs->ncols = fc->ncols;
  8451. rs->col_type = (short int *) xcmalloc (rs->ncols,
  8452. sizeof (* rs->col_type));
  8453. rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
  8454. memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
  8455. memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
  8456. rs->next = remembered_state;
  8457. remembered_state = rs;
  8458. break;
  8459. case DW_CFA_restore_state:
  8460. if (! do_debug_frames_interp)
  8461. printf (" DW_CFA_restore_state\n");
  8462. rs = remembered_state;
  8463. if (rs)
  8464. {
  8465. remembered_state = rs->next;
  8466. fc->cfa_offset = rs->cfa_offset;
  8467. fc->cfa_reg = rs->cfa_reg;
  8468. fc->ra = rs->ra;
  8469. fc->cfa_exp = rs->cfa_exp;
  8470. if (frame_need_space (fc, rs->ncols - 1) < 0)
  8471. {
  8472. warn (_("Invalid column number in saved frame state\n"));
  8473. fc->ncols = 0;
  8474. break;
  8475. }
  8476. memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
  8477. memcpy (fc->col_offset, rs->col_offset,
  8478. rs->ncols * sizeof (* rs->col_offset));
  8479. free (rs->col_type);
  8480. free (rs->col_offset);
  8481. free (rs);
  8482. }
  8483. else if (do_debug_frames_interp)
  8484. printf ("Mismatched DW_CFA_restore_state\n");
  8485. break;
  8486. case DW_CFA_def_cfa:
  8487. READ_ULEB (fc->cfa_reg, start, block_end);
  8488. READ_ULEB (fc->cfa_offset, start, block_end);
  8489. fc->cfa_exp = 0;
  8490. if (! do_debug_frames_interp)
  8491. printf (" DW_CFA_def_cfa: %s ofs %d\n",
  8492. regname (fc->cfa_reg, 0), (int) fc->cfa_offset);
  8493. break;
  8494. case DW_CFA_def_cfa_register:
  8495. READ_ULEB (fc->cfa_reg, start, block_end);
  8496. fc->cfa_exp = 0;
  8497. if (! do_debug_frames_interp)
  8498. printf (" DW_CFA_def_cfa_register: %s\n",
  8499. regname (fc->cfa_reg, 0));
  8500. break;
  8501. case DW_CFA_def_cfa_offset:
  8502. READ_ULEB (fc->cfa_offset, start, block_end);
  8503. if (! do_debug_frames_interp)
  8504. printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc->cfa_offset);
  8505. break;
  8506. case DW_CFA_nop:
  8507. if (! do_debug_frames_interp)
  8508. printf (" DW_CFA_nop\n");
  8509. break;
  8510. case DW_CFA_def_cfa_expression:
  8511. READ_ULEB (ul, start, block_end);
  8512. if (ul > (size_t) (block_end - start))
  8513. {
  8514. printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
  8515. break;
  8516. }
  8517. if (! do_debug_frames_interp)
  8518. {
  8519. printf (" DW_CFA_def_cfa_expression (");
  8520. decode_location_expression (start, eh_addr_size, 0, -1,
  8521. ul, 0, section);
  8522. printf (")\n");
  8523. }
  8524. fc->cfa_exp = 1;
  8525. start += ul;
  8526. break;
  8527. case DW_CFA_expression:
  8528. READ_ULEB (reg, start, block_end);
  8529. READ_ULEB (ul, start, block_end);
  8530. if (reg >= (unsigned int) fc->ncols)
  8531. reg_prefix = bad_reg;
  8532. /* PR 17512: file: 069-133014-0.006. */
  8533. /* PR 17512: file: 98c02eb4. */
  8534. if (ul > (size_t) (block_end - start))
  8535. {
  8536. printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
  8537. break;
  8538. }
  8539. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8540. {
  8541. printf (" DW_CFA_expression: %s%s (",
  8542. reg_prefix, regname (reg, 0));
  8543. decode_location_expression (start, eh_addr_size, 0, -1,
  8544. ul, 0, section);
  8545. printf (")\n");
  8546. }
  8547. if (*reg_prefix == '\0')
  8548. fc->col_type[reg] = DW_CFA_expression;
  8549. start += ul;
  8550. break;
  8551. case DW_CFA_val_expression:
  8552. READ_ULEB (reg, start, block_end);
  8553. READ_ULEB (ul, start, block_end);
  8554. if (reg >= (unsigned int) fc->ncols)
  8555. reg_prefix = bad_reg;
  8556. if (ul > (size_t) (block_end - start))
  8557. {
  8558. printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
  8559. break;
  8560. }
  8561. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8562. {
  8563. printf (" DW_CFA_val_expression: %s%s (",
  8564. reg_prefix, regname (reg, 0));
  8565. decode_location_expression (start, eh_addr_size, 0, -1,
  8566. ul, 0, section);
  8567. printf (")\n");
  8568. }
  8569. if (*reg_prefix == '\0')
  8570. fc->col_type[reg] = DW_CFA_val_expression;
  8571. start += ul;
  8572. break;
  8573. case DW_CFA_offset_extended_sf:
  8574. READ_ULEB (reg, start, block_end);
  8575. READ_SLEB (l, start, block_end);
  8576. if (frame_need_space (fc, reg) < 0)
  8577. reg_prefix = bad_reg;
  8578. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8579. printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
  8580. reg_prefix, regname (reg, 0),
  8581. (long)(l * fc->data_factor));
  8582. if (*reg_prefix == '\0')
  8583. {
  8584. fc->col_type[reg] = DW_CFA_offset;
  8585. fc->col_offset[reg] = l * fc->data_factor;
  8586. }
  8587. break;
  8588. case DW_CFA_val_offset_sf:
  8589. READ_ULEB (reg, start, block_end);
  8590. READ_SLEB (l, start, block_end);
  8591. if (frame_need_space (fc, reg) < 0)
  8592. reg_prefix = bad_reg;
  8593. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8594. printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
  8595. reg_prefix, regname (reg, 0),
  8596. (long)(l * fc->data_factor));
  8597. if (*reg_prefix == '\0')
  8598. {
  8599. fc->col_type[reg] = DW_CFA_val_offset;
  8600. fc->col_offset[reg] = l * fc->data_factor;
  8601. }
  8602. break;
  8603. case DW_CFA_def_cfa_sf:
  8604. READ_ULEB (fc->cfa_reg, start, block_end);
  8605. READ_SLEB (l, start, block_end);
  8606. l *= fc->data_factor;
  8607. fc->cfa_offset = l;
  8608. fc->cfa_exp = 0;
  8609. if (! do_debug_frames_interp)
  8610. printf (" DW_CFA_def_cfa_sf: %s ofs %ld\n",
  8611. regname (fc->cfa_reg, 0), (long) l);
  8612. break;
  8613. case DW_CFA_def_cfa_offset_sf:
  8614. READ_SLEB (l, start, block_end);
  8615. l *= fc->data_factor;
  8616. fc->cfa_offset = l;
  8617. if (! do_debug_frames_interp)
  8618. printf (" DW_CFA_def_cfa_offset_sf: %ld\n", (long) l);
  8619. break;
  8620. case DW_CFA_MIPS_advance_loc8:
  8621. SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
  8622. if (do_debug_frames_interp)
  8623. frame_display_row (fc, &need_col_headers, &max_regs);
  8624. else
  8625. printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
  8626. (unsigned long) (ofs * fc->code_factor),
  8627. dwarf_vmatoa_1 (NULL,
  8628. fc->pc_begin + ofs * fc->code_factor,
  8629. fc->ptr_size));
  8630. fc->pc_begin += ofs * fc->code_factor;
  8631. break;
  8632. case DW_CFA_GNU_window_save:
  8633. if (! do_debug_frames_interp)
  8634. printf (" DW_CFA_GNU_window_save\n");
  8635. break;
  8636. case DW_CFA_GNU_args_size:
  8637. READ_ULEB (ul, start, block_end);
  8638. if (! do_debug_frames_interp)
  8639. printf (" DW_CFA_GNU_args_size: %ld\n", ul);
  8640. break;
  8641. case DW_CFA_GNU_negative_offset_extended:
  8642. READ_ULEB (reg, start, block_end);
  8643. READ_SLEB (l, start, block_end);
  8644. l = - l;
  8645. if (frame_need_space (fc, reg) < 0)
  8646. reg_prefix = bad_reg;
  8647. if (! do_debug_frames_interp || *reg_prefix != '\0')
  8648. printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
  8649. reg_prefix, regname (reg, 0),
  8650. (long)(l * fc->data_factor));
  8651. if (*reg_prefix == '\0')
  8652. {
  8653. fc->col_type[reg] = DW_CFA_offset;
  8654. fc->col_offset[reg] = l * fc->data_factor;
  8655. }
  8656. break;
  8657. default:
  8658. if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
  8659. printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
  8660. else
  8661. warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
  8662. start = block_end;
  8663. }
  8664. }
  8665. /* Interpret the CFA - as long as it is not completely full of NOPs. */
  8666. if (do_debug_frames_interp && ! all_nops)
  8667. frame_display_row (fc, &need_col_headers, &max_regs);
  8668. if (fde_fc.col_type != NULL)
  8669. {
  8670. free (fde_fc.col_type);
  8671. fde_fc.col_type = NULL;
  8672. }
  8673. if (fde_fc.col_offset != NULL)
  8674. {
  8675. free (fde_fc.col_offset);
  8676. fde_fc.col_offset = NULL;
  8677. }
  8678. start = block_end;
  8679. eh_addr_size = saved_eh_addr_size;
  8680. }
  8681. printf ("\n");
  8682. while (remembered_state != NULL)
  8683. {
  8684. rs = remembered_state;
  8685. remembered_state = rs->next;
  8686. free (rs->col_type);
  8687. free (rs->col_offset);
  8688. rs->next = NULL; /* Paranoia. */
  8689. free (rs);
  8690. }
  8691. while (chunks != NULL)
  8692. {
  8693. rs = chunks;
  8694. chunks = rs->next;
  8695. free (rs->col_type);
  8696. free (rs->col_offset);
  8697. rs->next = NULL; /* Paranoia. */
  8698. free (rs);
  8699. }
  8700. while (forward_refs != NULL)
  8701. {
  8702. rs = forward_refs;
  8703. forward_refs = rs->next;
  8704. free (rs->col_type);
  8705. free (rs->col_offset);
  8706. rs->next = NULL; /* Paranoia. */
  8707. free (rs);
  8708. }
  8709. return 1;
  8710. }
  8711. #undef GET
  8712. static int
  8713. display_debug_names (struct dwarf_section *section, void *file)
  8714. {
  8715. unsigned char *hdrptr = section->start;
  8716. dwarf_vma unit_length;
  8717. unsigned char *unit_start;
  8718. const unsigned char *const section_end = section->start + section->size;
  8719. unsigned char *unit_end;
  8720. introduce (section, false);
  8721. load_debug_section_with_follow (str, file);
  8722. for (; hdrptr < section_end; hdrptr = unit_end)
  8723. {
  8724. unsigned int offset_size;
  8725. uint16_t dwarf_version, padding;
  8726. uint32_t comp_unit_count, local_type_unit_count, foreign_type_unit_count;
  8727. uint64_t bucket_count, name_count, abbrev_table_size;
  8728. uint32_t augmentation_string_size;
  8729. unsigned int i;
  8730. bool augmentation_printable;
  8731. const char *augmentation_string;
  8732. size_t total;
  8733. unit_start = hdrptr;
  8734. /* Get and check the length of the block. */
  8735. SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 4, section_end);
  8736. if (unit_length == 0xffffffff)
  8737. {
  8738. /* This section is 64-bit DWARF. */
  8739. SAFE_BYTE_GET_AND_INC (unit_length, hdrptr, 8, section_end);
  8740. offset_size = 8;
  8741. }
  8742. else
  8743. offset_size = 4;
  8744. if (unit_length > (size_t) (section_end - hdrptr)
  8745. || unit_length < 2 + 2 + 4 * 7)
  8746. {
  8747. too_short:
  8748. warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
  8749. section->name,
  8750. (unsigned long) (unit_start - section->start),
  8751. dwarf_vmatoa ("x", unit_length));
  8752. return 0;
  8753. }
  8754. unit_end = hdrptr + unit_length;
  8755. /* Get and check the version number. */
  8756. SAFE_BYTE_GET_AND_INC (dwarf_version, hdrptr, 2, unit_end);
  8757. printf (_("Version %ld\n"), (long) dwarf_version);
  8758. /* Prior versions did not exist, and future versions may not be
  8759. backwards compatible. */
  8760. if (dwarf_version != 5)
  8761. {
  8762. warn (_("Only DWARF version 5 .debug_names "
  8763. "is currently supported.\n"));
  8764. return 0;
  8765. }
  8766. SAFE_BYTE_GET_AND_INC (padding, hdrptr, 2, unit_end);
  8767. if (padding != 0)
  8768. warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
  8769. padding);
  8770. SAFE_BYTE_GET_AND_INC (comp_unit_count, hdrptr, 4, unit_end);
  8771. if (comp_unit_count == 0)
  8772. warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
  8773. SAFE_BYTE_GET_AND_INC (local_type_unit_count, hdrptr, 4, unit_end);
  8774. SAFE_BYTE_GET_AND_INC (foreign_type_unit_count, hdrptr, 4, unit_end);
  8775. SAFE_BYTE_GET_AND_INC (bucket_count, hdrptr, 4, unit_end);
  8776. SAFE_BYTE_GET_AND_INC (name_count, hdrptr, 4, unit_end);
  8777. SAFE_BYTE_GET_AND_INC (abbrev_table_size, hdrptr, 4, unit_end);
  8778. SAFE_BYTE_GET_AND_INC (augmentation_string_size, hdrptr, 4, unit_end);
  8779. if (augmentation_string_size % 4 != 0)
  8780. {
  8781. warn (_("Augmentation string length %u must be rounded up "
  8782. "to a multiple of 4 in .debug_names.\n"),
  8783. augmentation_string_size);
  8784. augmentation_string_size += (-augmentation_string_size) & 3;
  8785. }
  8786. if (augmentation_string_size > (size_t) (unit_end - hdrptr))
  8787. goto too_short;
  8788. printf (_("Augmentation string:"));
  8789. augmentation_printable = true;
  8790. augmentation_string = (const char *) hdrptr;
  8791. for (i = 0; i < augmentation_string_size; i++)
  8792. {
  8793. unsigned char uc;
  8794. SAFE_BYTE_GET_AND_INC (uc, hdrptr, 1, unit_end);
  8795. printf (" %02x", uc);
  8796. if (uc != 0 && !ISPRINT (uc))
  8797. augmentation_printable = false;
  8798. }
  8799. if (augmentation_printable)
  8800. {
  8801. printf (" (\"");
  8802. for (i = 0;
  8803. i < augmentation_string_size && augmentation_string[i];
  8804. ++i)
  8805. putchar (augmentation_string[i]);
  8806. printf ("\")");
  8807. }
  8808. putchar ('\n');
  8809. printf (_("CU table:\n"));
  8810. if (_mul_overflow (comp_unit_count, offset_size, &total)
  8811. || total > (size_t) (unit_end - hdrptr))
  8812. goto too_short;
  8813. for (i = 0; i < comp_unit_count; i++)
  8814. {
  8815. uint64_t cu_offset;
  8816. SAFE_BYTE_GET_AND_INC (cu_offset, hdrptr, offset_size, unit_end);
  8817. printf (_("[%3u] 0x%lx\n"), i, (unsigned long) cu_offset);
  8818. }
  8819. putchar ('\n');
  8820. printf (_("TU table:\n"));
  8821. if (_mul_overflow (local_type_unit_count, offset_size, &total)
  8822. || total > (size_t) (unit_end - hdrptr))
  8823. goto too_short;
  8824. for (i = 0; i < local_type_unit_count; i++)
  8825. {
  8826. uint64_t tu_offset;
  8827. SAFE_BYTE_GET_AND_INC (tu_offset, hdrptr, offset_size, unit_end);
  8828. printf (_("[%3u] 0x%lx\n"), i, (unsigned long) tu_offset);
  8829. }
  8830. putchar ('\n');
  8831. printf (_("Foreign TU table:\n"));
  8832. if (_mul_overflow (foreign_type_unit_count, 8, &total)
  8833. || total > (size_t) (unit_end - hdrptr))
  8834. goto too_short;
  8835. for (i = 0; i < foreign_type_unit_count; i++)
  8836. {
  8837. uint64_t signature;
  8838. SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, unit_end);
  8839. printf (_("[%3u] "), i);
  8840. print_dwarf_vma (signature, 8);
  8841. putchar ('\n');
  8842. }
  8843. putchar ('\n');
  8844. uint64_t xtra = (bucket_count * sizeof (uint32_t)
  8845. + name_count * (sizeof (uint32_t) + 2 * offset_size)
  8846. + abbrev_table_size);
  8847. if (xtra > (size_t) (unit_end - hdrptr))
  8848. {
  8849. warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
  8850. "for unit 0x%lx in the debug_names\n"),
  8851. (long) xtra,
  8852. (long) (unit_end - unit_start),
  8853. (long) (unit_start - section->start));
  8854. return 0;
  8855. }
  8856. const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr;
  8857. hdrptr += bucket_count * sizeof (uint32_t);
  8858. const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr;
  8859. hdrptr += name_count * sizeof (uint32_t);
  8860. unsigned char *const name_table_string_offsets = hdrptr;
  8861. hdrptr += name_count * offset_size;
  8862. unsigned char *const name_table_entry_offsets = hdrptr;
  8863. hdrptr += name_count * offset_size;
  8864. unsigned char *const abbrev_table = hdrptr;
  8865. hdrptr += abbrev_table_size;
  8866. const unsigned char *const abbrev_table_end = hdrptr;
  8867. unsigned char *const entry_pool = hdrptr;
  8868. size_t buckets_filled = 0;
  8869. size_t bucketi;
  8870. for (bucketi = 0; bucketi < bucket_count; bucketi++)
  8871. {
  8872. const uint32_t bucket = hash_table_buckets[bucketi];
  8873. if (bucket != 0)
  8874. ++buckets_filled;
  8875. }
  8876. printf (ngettext ("Used %zu of %lu bucket.\n",
  8877. "Used %zu of %lu buckets.\n",
  8878. bucket_count),
  8879. buckets_filled, (unsigned long) bucket_count);
  8880. uint32_t hash_prev = 0;
  8881. size_t hash_clash_count = 0;
  8882. size_t longest_clash = 0;
  8883. size_t this_length = 0;
  8884. size_t hashi;
  8885. for (hashi = 0; hashi < name_count; hashi++)
  8886. {
  8887. const uint32_t hash_this = hash_table_hashes[hashi];
  8888. if (hashi > 0)
  8889. {
  8890. if (hash_prev % bucket_count == hash_this % bucket_count)
  8891. {
  8892. ++hash_clash_count;
  8893. ++this_length;
  8894. longest_clash = MAX (longest_clash, this_length);
  8895. }
  8896. else
  8897. this_length = 0;
  8898. }
  8899. hash_prev = hash_this;
  8900. }
  8901. printf (_("Out of %lu items there are %zu bucket clashes"
  8902. " (longest of %zu entries).\n"),
  8903. (unsigned long) name_count, hash_clash_count, longest_clash);
  8904. assert (name_count == buckets_filled + hash_clash_count);
  8905. struct abbrev_lookup_entry
  8906. {
  8907. dwarf_vma abbrev_tag;
  8908. unsigned char *abbrev_lookup_ptr;
  8909. };
  8910. struct abbrev_lookup_entry *abbrev_lookup = NULL;
  8911. size_t abbrev_lookup_used = 0;
  8912. size_t abbrev_lookup_allocated = 0;
  8913. unsigned char *abbrevptr = abbrev_table;
  8914. for (;;)
  8915. {
  8916. dwarf_vma abbrev_tag;
  8917. READ_ULEB (abbrev_tag, abbrevptr, abbrev_table_end);
  8918. if (abbrev_tag == 0)
  8919. break;
  8920. if (abbrev_lookup_used == abbrev_lookup_allocated)
  8921. {
  8922. abbrev_lookup_allocated = MAX (0x100,
  8923. abbrev_lookup_allocated * 2);
  8924. abbrev_lookup = xrealloc (abbrev_lookup,
  8925. (abbrev_lookup_allocated
  8926. * sizeof (*abbrev_lookup)));
  8927. }
  8928. assert (abbrev_lookup_used < abbrev_lookup_allocated);
  8929. struct abbrev_lookup_entry *entry;
  8930. for (entry = abbrev_lookup;
  8931. entry < abbrev_lookup + abbrev_lookup_used;
  8932. entry++)
  8933. if (entry->abbrev_tag == abbrev_tag)
  8934. {
  8935. warn (_("Duplicate abbreviation tag %lu "
  8936. "in unit 0x%lx in the debug_names\n"),
  8937. (long) abbrev_tag, (long) (unit_start - section->start));
  8938. break;
  8939. }
  8940. entry = &abbrev_lookup[abbrev_lookup_used++];
  8941. entry->abbrev_tag = abbrev_tag;
  8942. entry->abbrev_lookup_ptr = abbrevptr;
  8943. /* Skip DWARF tag. */
  8944. SKIP_ULEB (abbrevptr, abbrev_table_end);
  8945. for (;;)
  8946. {
  8947. dwarf_vma xindex, form;
  8948. READ_ULEB (xindex, abbrevptr, abbrev_table_end);
  8949. READ_ULEB (form, abbrevptr, abbrev_table_end);
  8950. if (xindex == 0 && form == 0)
  8951. break;
  8952. }
  8953. }
  8954. printf (_("\nSymbol table:\n"));
  8955. uint32_t namei;
  8956. for (namei = 0; namei < name_count; ++namei)
  8957. {
  8958. uint64_t string_offset, entry_offset;
  8959. unsigned char *p;
  8960. p = name_table_string_offsets + namei * offset_size;
  8961. SAFE_BYTE_GET (string_offset, p, offset_size, unit_end);
  8962. p = name_table_entry_offsets + namei * offset_size;
  8963. SAFE_BYTE_GET (entry_offset, p, offset_size, unit_end);
  8964. printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei],
  8965. fetch_indirect_string (string_offset));
  8966. unsigned char *entryptr = entry_pool + entry_offset;
  8967. /* We need to scan first whether there is a single or multiple
  8968. entries. TAGNO is -2 for the first entry, it is -1 for the
  8969. initial tag read of the second entry, then it becomes 0 for the
  8970. first entry for real printing etc. */
  8971. int tagno = -2;
  8972. /* Initialize it due to a false compiler warning. */
  8973. dwarf_vma second_abbrev_tag = -1;
  8974. for (;;)
  8975. {
  8976. dwarf_vma abbrev_tag;
  8977. dwarf_vma dwarf_tag;
  8978. const struct abbrev_lookup_entry *entry;
  8979. READ_ULEB (abbrev_tag, entryptr, unit_end);
  8980. if (tagno == -1)
  8981. {
  8982. second_abbrev_tag = abbrev_tag;
  8983. tagno = 0;
  8984. entryptr = entry_pool + entry_offset;
  8985. continue;
  8986. }
  8987. if (abbrev_tag == 0)
  8988. break;
  8989. if (tagno >= 0)
  8990. printf ("%s<%lu>",
  8991. (tagno == 0 && second_abbrev_tag == 0 ? " " : "\n\t"),
  8992. (unsigned long) abbrev_tag);
  8993. for (entry = abbrev_lookup;
  8994. entry < abbrev_lookup + abbrev_lookup_used;
  8995. entry++)
  8996. if (entry->abbrev_tag == abbrev_tag)
  8997. break;
  8998. if (entry >= abbrev_lookup + abbrev_lookup_used)
  8999. {
  9000. warn (_("Undefined abbreviation tag %lu "
  9001. "in unit 0x%lx in the debug_names\n"),
  9002. (long) abbrev_tag,
  9003. (long) (unit_start - section->start));
  9004. break;
  9005. }
  9006. abbrevptr = entry->abbrev_lookup_ptr;
  9007. READ_ULEB (dwarf_tag, abbrevptr, abbrev_table_end);
  9008. if (tagno >= 0)
  9009. printf (" %s", get_TAG_name (dwarf_tag));
  9010. for (;;)
  9011. {
  9012. dwarf_vma xindex, form;
  9013. READ_ULEB (xindex, abbrevptr, abbrev_table_end);
  9014. READ_ULEB (form, abbrevptr, abbrev_table_end);
  9015. if (xindex == 0 && form == 0)
  9016. break;
  9017. if (tagno >= 0)
  9018. printf (" %s", get_IDX_name (xindex));
  9019. entryptr = read_and_display_attr_value (0, form, 0,
  9020. unit_start, entryptr, unit_end,
  9021. 0, 0, offset_size,
  9022. dwarf_version, NULL,
  9023. (tagno < 0), NULL,
  9024. NULL, '=', -1);
  9025. }
  9026. ++tagno;
  9027. }
  9028. if (tagno <= 0)
  9029. printf (_(" <no entries>"));
  9030. putchar ('\n');
  9031. }
  9032. free (abbrev_lookup);
  9033. }
  9034. return 1;
  9035. }
  9036. static int
  9037. display_debug_links (struct dwarf_section * section,
  9038. void * file ATTRIBUTE_UNUSED)
  9039. {
  9040. const unsigned char * filename;
  9041. unsigned int filelen;
  9042. introduce (section, false);
  9043. /* The .gnu_debuglink section is formatted as:
  9044. (c-string) Filename.
  9045. (padding) If needed to reach a 4 byte boundary.
  9046. (uint32_t) CRC32 value.
  9047. The .gun_debugaltlink section is formatted as:
  9048. (c-string) Filename.
  9049. (binary) Build-ID. */
  9050. filename = section->start;
  9051. filelen = strnlen ((const char *) filename, section->size);
  9052. if (filelen == section->size)
  9053. {
  9054. warn (_("The debuglink filename is corrupt/missing\n"));
  9055. return 0;
  9056. }
  9057. printf (_(" Separate debug info file: %s\n"), filename);
  9058. if (startswith (section->name, ".gnu_debuglink"))
  9059. {
  9060. unsigned int crc32;
  9061. unsigned int crc_offset;
  9062. crc_offset = filelen + 1;
  9063. crc_offset = (crc_offset + 3) & ~3;
  9064. if (crc_offset + 4 > section->size)
  9065. {
  9066. warn (_("CRC offset missing/truncated\n"));
  9067. return 0;
  9068. }
  9069. crc32 = byte_get (filename + crc_offset, 4);
  9070. printf (_(" CRC value: %#x\n"), crc32);
  9071. if (crc_offset + 4 < section->size)
  9072. {
  9073. warn (_("There are %#lx extraneous bytes at the end of the section\n"),
  9074. (long)(section->size - (crc_offset + 4)));
  9075. return 0;
  9076. }
  9077. }
  9078. else /* startswith (section->name, ".gnu_debugaltlink") */
  9079. {
  9080. const unsigned char * build_id = section->start + filelen + 1;
  9081. bfd_size_type build_id_len = section->size - (filelen + 1);
  9082. bfd_size_type printed;
  9083. /* FIXME: Should we support smaller build-id notes ? */
  9084. if (build_id_len < 0x14)
  9085. {
  9086. warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len);
  9087. return 0;
  9088. }
  9089. printed = printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len);
  9090. display_data (printed, build_id, build_id_len);
  9091. putchar ('\n');
  9092. }
  9093. putchar ('\n');
  9094. return 1;
  9095. }
  9096. static int
  9097. display_gdb_index (struct dwarf_section *section,
  9098. void *file ATTRIBUTE_UNUSED)
  9099. {
  9100. unsigned char *start = section->start;
  9101. uint32_t version;
  9102. uint32_t cu_list_offset, tu_list_offset;
  9103. uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
  9104. unsigned int cu_list_elements, tu_list_elements;
  9105. unsigned int address_table_size, symbol_table_slots;
  9106. unsigned char *cu_list, *tu_list;
  9107. unsigned char *address_table, *symbol_table, *constant_pool;
  9108. unsigned int i;
  9109. /* The documentation for the format of this file is in gdb/dwarf2read.c. */
  9110. introduce (section, false);
  9111. if (section->size < 6 * sizeof (uint32_t))
  9112. {
  9113. warn (_("Truncated header in the %s section.\n"), section->name);
  9114. return 0;
  9115. }
  9116. version = byte_get_little_endian (start, 4);
  9117. printf (_("Version %ld\n"), (long) version);
  9118. /* Prior versions are obsolete, and future versions may not be
  9119. backwards compatible. */
  9120. if (version < 3 || version > 8)
  9121. {
  9122. warn (_("Unsupported version %lu.\n"), (unsigned long) version);
  9123. return 0;
  9124. }
  9125. if (version < 4)
  9126. warn (_("The address table data in version 3 may be wrong.\n"));
  9127. if (version < 5)
  9128. warn (_("Version 4 does not support case insensitive lookups.\n"));
  9129. if (version < 6)
  9130. warn (_("Version 5 does not include inlined functions.\n"));
  9131. if (version < 7)
  9132. warn (_("Version 6 does not include symbol attributes.\n"));
  9133. /* Version 7 indices generated by Gold have bad type unit references,
  9134. PR binutils/15021. But we don't know if the index was generated by
  9135. Gold or not, so to avoid worrying users with gdb-generated indices
  9136. we say nothing for version 7 here. */
  9137. cu_list_offset = byte_get_little_endian (start + 4, 4);
  9138. tu_list_offset = byte_get_little_endian (start + 8, 4);
  9139. address_table_offset = byte_get_little_endian (start + 12, 4);
  9140. symbol_table_offset = byte_get_little_endian (start + 16, 4);
  9141. constant_pool_offset = byte_get_little_endian (start + 20, 4);
  9142. if (cu_list_offset > section->size
  9143. || tu_list_offset > section->size
  9144. || address_table_offset > section->size
  9145. || symbol_table_offset > section->size
  9146. || constant_pool_offset > section->size)
  9147. {
  9148. warn (_("Corrupt header in the %s section.\n"), section->name);
  9149. return 0;
  9150. }
  9151. /* PR 17531: file: 418d0a8a. */
  9152. if (tu_list_offset < cu_list_offset)
  9153. {
  9154. warn (_("TU offset (%x) is less than CU offset (%x)\n"),
  9155. tu_list_offset, cu_list_offset);
  9156. return 0;
  9157. }
  9158. cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
  9159. if (address_table_offset < tu_list_offset)
  9160. {
  9161. warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
  9162. address_table_offset, tu_list_offset);
  9163. return 0;
  9164. }
  9165. tu_list_elements = (address_table_offset - tu_list_offset) / 8;
  9166. /* PR 17531: file: 18a47d3d. */
  9167. if (symbol_table_offset < address_table_offset)
  9168. {
  9169. warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
  9170. symbol_table_offset, address_table_offset);
  9171. return 0;
  9172. }
  9173. address_table_size = symbol_table_offset - address_table_offset;
  9174. if (constant_pool_offset < symbol_table_offset)
  9175. {
  9176. warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
  9177. constant_pool_offset, symbol_table_offset);
  9178. return 0;
  9179. }
  9180. symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
  9181. cu_list = start + cu_list_offset;
  9182. tu_list = start + tu_list_offset;
  9183. address_table = start + address_table_offset;
  9184. symbol_table = start + symbol_table_offset;
  9185. constant_pool = start + constant_pool_offset;
  9186. if (address_table_offset + address_table_size > section->size)
  9187. {
  9188. warn (_("Address table extends beyond end of section.\n"));
  9189. return 0;
  9190. }
  9191. printf (_("\nCU table:\n"));
  9192. for (i = 0; i < cu_list_elements; i += 2)
  9193. {
  9194. uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
  9195. uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
  9196. printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
  9197. (unsigned long) cu_offset,
  9198. (unsigned long) (cu_offset + cu_length - 1));
  9199. }
  9200. printf (_("\nTU table:\n"));
  9201. for (i = 0; i < tu_list_elements; i += 3)
  9202. {
  9203. uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
  9204. uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
  9205. uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
  9206. printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
  9207. (unsigned long) tu_offset,
  9208. (unsigned long) type_offset);
  9209. print_dwarf_vma (signature, 8);
  9210. printf ("\n");
  9211. }
  9212. printf (_("\nAddress table:\n"));
  9213. for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
  9214. i += 2 * 8 + 4)
  9215. {
  9216. uint64_t low = byte_get_little_endian (address_table + i, 8);
  9217. uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
  9218. uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
  9219. print_dwarf_vma (low, 8);
  9220. print_dwarf_vma (high, 8);
  9221. printf (_("%lu\n"), (unsigned long) cu_index);
  9222. }
  9223. printf (_("\nSymbol table:\n"));
  9224. for (i = 0; i < symbol_table_slots; ++i)
  9225. {
  9226. uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
  9227. uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
  9228. uint32_t num_cus, cu;
  9229. if (name_offset != 0
  9230. || cu_vector_offset != 0)
  9231. {
  9232. unsigned int j;
  9233. /* PR 17531: file: 5b7b07ad. */
  9234. if (name_offset >= section->size - constant_pool_offset)
  9235. {
  9236. printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
  9237. warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
  9238. name_offset, i);
  9239. }
  9240. else
  9241. printf ("[%3u] %.*s:", i,
  9242. (int) (section->size - (constant_pool_offset + name_offset)),
  9243. constant_pool + name_offset);
  9244. if (section->size - constant_pool_offset < 4
  9245. || cu_vector_offset > section->size - constant_pool_offset - 4)
  9246. {
  9247. printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
  9248. warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
  9249. cu_vector_offset, i);
  9250. continue;
  9251. }
  9252. num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
  9253. if ((uint64_t) num_cus * 4 > section->size - (constant_pool_offset
  9254. + cu_vector_offset + 4))
  9255. {
  9256. printf ("<invalid number of CUs: %d>\n", num_cus);
  9257. warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
  9258. num_cus, i);
  9259. continue;
  9260. }
  9261. if (num_cus > 1)
  9262. printf ("\n");
  9263. for (j = 0; j < num_cus; ++j)
  9264. {
  9265. int is_static;
  9266. gdb_index_symbol_kind kind;
  9267. cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
  9268. is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
  9269. kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
  9270. cu = GDB_INDEX_CU_VALUE (cu);
  9271. /* Convert to TU number if it's for a type unit. */
  9272. if (cu >= cu_list_elements / 2)
  9273. printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
  9274. (unsigned long) (cu - cu_list_elements / 2));
  9275. else
  9276. printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
  9277. printf (" [%s, %s]",
  9278. is_static ? _("static") : _("global"),
  9279. get_gdb_index_symbol_kind_name (kind));
  9280. if (num_cus > 1)
  9281. printf ("\n");
  9282. }
  9283. if (num_cus <= 1)
  9284. printf ("\n");
  9285. }
  9286. }
  9287. return 1;
  9288. }
  9289. /* Pre-allocate enough space for the CU/TU sets needed. */
  9290. static void
  9291. prealloc_cu_tu_list (unsigned int nshndx)
  9292. {
  9293. if (shndx_pool == NULL)
  9294. {
  9295. shndx_pool_size = nshndx;
  9296. shndx_pool_used = 0;
  9297. shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
  9298. sizeof (unsigned int));
  9299. }
  9300. else
  9301. {
  9302. shndx_pool_size = shndx_pool_used + nshndx;
  9303. shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
  9304. sizeof (unsigned int));
  9305. }
  9306. }
  9307. static void
  9308. add_shndx_to_cu_tu_entry (unsigned int shndx)
  9309. {
  9310. if (shndx_pool_used >= shndx_pool_size)
  9311. {
  9312. error (_("Internal error: out of space in the shndx pool.\n"));
  9313. return;
  9314. }
  9315. shndx_pool [shndx_pool_used++] = shndx;
  9316. }
  9317. static void
  9318. end_cu_tu_entry (void)
  9319. {
  9320. if (shndx_pool_used >= shndx_pool_size)
  9321. {
  9322. error (_("Internal error: out of space in the shndx pool.\n"));
  9323. return;
  9324. }
  9325. shndx_pool [shndx_pool_used++] = 0;
  9326. }
  9327. /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
  9328. static const char *
  9329. get_DW_SECT_short_name (unsigned int dw_sect)
  9330. {
  9331. static char buf[16];
  9332. switch (dw_sect)
  9333. {
  9334. case DW_SECT_INFO:
  9335. return "info";
  9336. case DW_SECT_TYPES:
  9337. return "types";
  9338. case DW_SECT_ABBREV:
  9339. return "abbrev";
  9340. case DW_SECT_LINE:
  9341. return "line";
  9342. case DW_SECT_LOC:
  9343. return "loc";
  9344. case DW_SECT_STR_OFFSETS:
  9345. return "str_off";
  9346. case DW_SECT_MACINFO:
  9347. return "macinfo";
  9348. case DW_SECT_MACRO:
  9349. return "macro";
  9350. default:
  9351. break;
  9352. }
  9353. snprintf (buf, sizeof (buf), "%d", dw_sect);
  9354. return buf;
  9355. }
  9356. /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
  9357. These sections are extensions for Fission.
  9358. See http://gcc.gnu.org/wiki/DebugFissionDWP. */
  9359. static int
  9360. process_cu_tu_index (struct dwarf_section *section, int do_display)
  9361. {
  9362. unsigned char *phdr = section->start;
  9363. unsigned char *limit = phdr + section->size;
  9364. unsigned char *phash;
  9365. unsigned char *pindex;
  9366. unsigned char *ppool;
  9367. unsigned int version;
  9368. unsigned int ncols = 0;
  9369. unsigned int nused;
  9370. unsigned int nslots;
  9371. unsigned int i;
  9372. unsigned int j;
  9373. dwarf_vma signature;
  9374. size_t total;
  9375. /* PR 17512: file: 002-168123-0.004. */
  9376. if (phdr == NULL)
  9377. {
  9378. warn (_("Section %s is empty\n"), section->name);
  9379. return 0;
  9380. }
  9381. /* PR 17512: file: 002-376-0.004. */
  9382. if (section->size < 24)
  9383. {
  9384. warn (_("Section %s is too small to contain a CU/TU header\n"),
  9385. section->name);
  9386. return 0;
  9387. }
  9388. phash = phdr;
  9389. SAFE_BYTE_GET_AND_INC (version, phash, 4, limit);
  9390. if (version >= 2)
  9391. SAFE_BYTE_GET_AND_INC (ncols, phash, 4, limit);
  9392. SAFE_BYTE_GET_AND_INC (nused, phash, 4, limit);
  9393. SAFE_BYTE_GET_AND_INC (nslots, phash, 4, limit);
  9394. pindex = phash + (size_t) nslots * 8;
  9395. ppool = pindex + (size_t) nslots * 4;
  9396. if (do_display)
  9397. {
  9398. introduce (section, false);
  9399. printf (_(" Version: %u\n"), version);
  9400. if (version >= 2)
  9401. printf (_(" Number of columns: %u\n"), ncols);
  9402. printf (_(" Number of used entries: %u\n"), nused);
  9403. printf (_(" Number of slots: %u\n\n"), nslots);
  9404. }
  9405. /* PR 17531: file: 45d69832. */
  9406. if (_mul_overflow ((size_t) nslots, 12, &total)
  9407. || total > (size_t) (limit - phash))
  9408. {
  9409. warn (ngettext ("Section %s is too small for %u slot\n",
  9410. "Section %s is too small for %u slots\n",
  9411. nslots),
  9412. section->name, nslots);
  9413. return 0;
  9414. }
  9415. if (version == 1)
  9416. {
  9417. if (!do_display)
  9418. prealloc_cu_tu_list ((limit - ppool) / 4);
  9419. for (i = 0; i < nslots; i++)
  9420. {
  9421. unsigned char *shndx_list;
  9422. unsigned int shndx;
  9423. SAFE_BYTE_GET (signature, phash, 8, limit);
  9424. if (signature != 0)
  9425. {
  9426. SAFE_BYTE_GET (j, pindex, 4, limit);
  9427. shndx_list = ppool + j * 4;
  9428. /* PR 17531: file: 705e010d. */
  9429. if (shndx_list < ppool)
  9430. {
  9431. warn (_("Section index pool located before start of section\n"));
  9432. return 0;
  9433. }
  9434. if (do_display)
  9435. printf (_(" [%3d] Signature: 0x%s Sections: "),
  9436. i, dwarf_vmatoa ("x", signature));
  9437. for (;;)
  9438. {
  9439. if (shndx_list >= limit)
  9440. {
  9441. warn (_("Section %s too small for shndx pool\n"),
  9442. section->name);
  9443. return 0;
  9444. }
  9445. SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
  9446. if (shndx == 0)
  9447. break;
  9448. if (do_display)
  9449. printf (" %d", shndx);
  9450. else
  9451. add_shndx_to_cu_tu_entry (shndx);
  9452. shndx_list += 4;
  9453. }
  9454. if (do_display)
  9455. printf ("\n");
  9456. else
  9457. end_cu_tu_entry ();
  9458. }
  9459. phash += 8;
  9460. pindex += 4;
  9461. }
  9462. }
  9463. else if (version == 2)
  9464. {
  9465. unsigned int val;
  9466. unsigned int dw_sect;
  9467. unsigned char *ph = phash;
  9468. unsigned char *pi = pindex;
  9469. unsigned char *poffsets = ppool + (size_t) ncols * 4;
  9470. unsigned char *psizes = poffsets + (size_t) nused * ncols * 4;
  9471. bool is_tu_index;
  9472. struct cu_tu_set *this_set = NULL;
  9473. unsigned int row;
  9474. unsigned char *prow;
  9475. size_t temp;
  9476. is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
  9477. /* PR 17531: file: 0dd159bf.
  9478. Check for integer overflow (can occur when size_t is 32-bit)
  9479. with overlarge ncols or nused values. */
  9480. if (nused == -1u
  9481. || _mul_overflow ((size_t) ncols, 4, &temp)
  9482. || _mul_overflow ((size_t) nused + 1, temp, &total)
  9483. || total > (size_t) (limit - ppool))
  9484. {
  9485. warn (_("Section %s too small for offset and size tables\n"),
  9486. section->name);
  9487. return 0;
  9488. }
  9489. if (do_display)
  9490. {
  9491. printf (_(" Offset table\n"));
  9492. printf (" slot %-16s ",
  9493. is_tu_index ? _("signature") : _("dwo_id"));
  9494. }
  9495. else
  9496. {
  9497. if (is_tu_index)
  9498. {
  9499. tu_count = nused;
  9500. tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
  9501. this_set = tu_sets;
  9502. }
  9503. else
  9504. {
  9505. cu_count = nused;
  9506. cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
  9507. this_set = cu_sets;
  9508. }
  9509. }
  9510. if (do_display)
  9511. {
  9512. for (j = 0; j < ncols; j++)
  9513. {
  9514. unsigned char *p = ppool + j * 4;
  9515. SAFE_BYTE_GET (dw_sect, p, 4, limit);
  9516. printf (" %8s", get_DW_SECT_short_name (dw_sect));
  9517. }
  9518. printf ("\n");
  9519. }
  9520. for (i = 0; i < nslots; i++)
  9521. {
  9522. SAFE_BYTE_GET (signature, ph, 8, limit);
  9523. SAFE_BYTE_GET (row, pi, 4, limit);
  9524. if (row != 0)
  9525. {
  9526. /* PR 17531: file: a05f6ab3. */
  9527. if (row > nused)
  9528. {
  9529. warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
  9530. row, nused);
  9531. return 0;
  9532. }
  9533. if (!do_display)
  9534. {
  9535. size_t num_copy = sizeof (uint64_t);
  9536. memcpy (&this_set[row - 1].signature, ph, num_copy);
  9537. }
  9538. prow = poffsets + (row - 1) * ncols * 4;
  9539. if (do_display)
  9540. printf (_(" [%3d] 0x%s"),
  9541. i, dwarf_vmatoa ("x", signature));
  9542. for (j = 0; j < ncols; j++)
  9543. {
  9544. unsigned char *p = prow + j * 4;
  9545. SAFE_BYTE_GET (val, p, 4, limit);
  9546. if (do_display)
  9547. printf (" %8d", val);
  9548. else
  9549. {
  9550. p = ppool + j * 4;
  9551. SAFE_BYTE_GET (dw_sect, p, 4, limit);
  9552. /* PR 17531: file: 10796eb3. */
  9553. if (dw_sect >= DW_SECT_MAX)
  9554. warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
  9555. else
  9556. this_set [row - 1].section_offsets [dw_sect] = val;
  9557. }
  9558. }
  9559. if (do_display)
  9560. printf ("\n");
  9561. }
  9562. ph += 8;
  9563. pi += 4;
  9564. }
  9565. ph = phash;
  9566. pi = pindex;
  9567. if (do_display)
  9568. {
  9569. printf ("\n");
  9570. printf (_(" Size table\n"));
  9571. printf (" slot %-16s ",
  9572. is_tu_index ? _("signature") : _("dwo_id"));
  9573. }
  9574. for (j = 0; j < ncols; j++)
  9575. {
  9576. unsigned char *p = ppool + j * 4;
  9577. SAFE_BYTE_GET (val, p, 4, limit);
  9578. if (do_display)
  9579. printf (" %8s", get_DW_SECT_short_name (val));
  9580. }
  9581. if (do_display)
  9582. printf ("\n");
  9583. for (i = 0; i < nslots; i++)
  9584. {
  9585. SAFE_BYTE_GET (signature, ph, 8, limit);
  9586. SAFE_BYTE_GET (row, pi, 4, limit);
  9587. if (row != 0)
  9588. {
  9589. prow = psizes + (row - 1) * ncols * 4;
  9590. if (do_display)
  9591. printf (_(" [%3d] 0x%s"),
  9592. i, dwarf_vmatoa ("x", signature));
  9593. for (j = 0; j < ncols; j++)
  9594. {
  9595. unsigned char *p = prow + j * 4;
  9596. /* PR 28645: Check for overflow. Since we do not know how
  9597. many populated rows there will be, we cannot just
  9598. perform a single check at the start of this function. */
  9599. if (p > (limit - 4))
  9600. {
  9601. if (do_display)
  9602. printf ("\n");
  9603. warn (_("Too many rows/columns in DWARF index section %s\n"),
  9604. section->name);
  9605. return 0;
  9606. }
  9607. SAFE_BYTE_GET (val, p, 4, limit);
  9608. if (do_display)
  9609. printf (" %8d", val);
  9610. else
  9611. {
  9612. p = ppool + j * 4;
  9613. SAFE_BYTE_GET (dw_sect, p, 4, limit);
  9614. if (dw_sect >= DW_SECT_MAX)
  9615. warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
  9616. else
  9617. this_set [row - 1].section_sizes [dw_sect] = val;
  9618. }
  9619. }
  9620. if (do_display)
  9621. printf ("\n");
  9622. }
  9623. ph += 8;
  9624. pi += 4;
  9625. }
  9626. }
  9627. else if (do_display)
  9628. printf (_(" Unsupported version (%d)\n"), version);
  9629. if (do_display)
  9630. printf ("\n");
  9631. return 1;
  9632. }
  9633. static int cu_tu_indexes_read = -1; /* Tri-state variable. */
  9634. /* Load the CU and TU indexes if present. This will build a list of
  9635. section sets that we can use to associate a .debug_info.dwo section
  9636. with its associated .debug_abbrev.dwo section in a .dwp file. */
  9637. static bool
  9638. load_cu_tu_indexes (void *file)
  9639. {
  9640. /* If we have already loaded (or tried to load) the CU and TU indexes
  9641. then do not bother to repeat the task. */
  9642. if (cu_tu_indexes_read == -1)
  9643. {
  9644. cu_tu_indexes_read = true;
  9645. if (load_debug_section_with_follow (dwp_cu_index, file))
  9646. if (! process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0))
  9647. cu_tu_indexes_read = false;
  9648. if (load_debug_section_with_follow (dwp_tu_index, file))
  9649. if (! process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0))
  9650. cu_tu_indexes_read = false;
  9651. }
  9652. return (bool) cu_tu_indexes_read;
  9653. }
  9654. /* Find the set of sections that includes section SHNDX. */
  9655. unsigned int *
  9656. find_cu_tu_set (void *file, unsigned int shndx)
  9657. {
  9658. unsigned int i;
  9659. if (! load_cu_tu_indexes (file))
  9660. return NULL;
  9661. /* Find SHNDX in the shndx pool. */
  9662. for (i = 0; i < shndx_pool_used; i++)
  9663. if (shndx_pool [i] == shndx)
  9664. break;
  9665. if (i >= shndx_pool_used)
  9666. return NULL;
  9667. /* Now backup to find the first entry in the set. */
  9668. while (i > 0 && shndx_pool [i - 1] != 0)
  9669. i--;
  9670. return shndx_pool + i;
  9671. }
  9672. /* Display a .debug_cu_index or .debug_tu_index section. */
  9673. static int
  9674. display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
  9675. {
  9676. return process_cu_tu_index (section, 1);
  9677. }
  9678. static int
  9679. display_debug_not_supported (struct dwarf_section *section,
  9680. void *file ATTRIBUTE_UNUSED)
  9681. {
  9682. printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
  9683. section->name);
  9684. return 1;
  9685. }
  9686. /* Like malloc, but takes two parameters like calloc.
  9687. Verifies that the first parameter is not too large.
  9688. Note: does *not* initialise the allocated memory to zero. */
  9689. void *
  9690. cmalloc (size_t nmemb, size_t size)
  9691. {
  9692. /* Check for overflow. */
  9693. if (nmemb >= ~(size_t) 0 / size)
  9694. return NULL;
  9695. return xmalloc (nmemb * size);
  9696. }
  9697. /* Like xmalloc, but takes two parameters like calloc.
  9698. Verifies that the first parameter is not too large.
  9699. Note: does *not* initialise the allocated memory to zero. */
  9700. void *
  9701. xcmalloc (size_t nmemb, size_t size)
  9702. {
  9703. /* Check for overflow. */
  9704. if (nmemb >= ~(size_t) 0 / size)
  9705. {
  9706. fprintf (stderr,
  9707. _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
  9708. (long) nmemb);
  9709. xexit (1);
  9710. }
  9711. return xmalloc (nmemb * size);
  9712. }
  9713. /* Like xrealloc, but takes three parameters.
  9714. Verifies that the second parameter is not too large.
  9715. Note: does *not* initialise any new memory to zero. */
  9716. void *
  9717. xcrealloc (void *ptr, size_t nmemb, size_t size)
  9718. {
  9719. /* Check for overflow. */
  9720. if (nmemb >= ~(size_t) 0 / size)
  9721. {
  9722. error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
  9723. (long) nmemb);
  9724. xexit (1);
  9725. }
  9726. return xrealloc (ptr, nmemb * size);
  9727. }
  9728. /* Like xcalloc, but verifies that the first parameter is not too large. */
  9729. void *
  9730. xcalloc2 (size_t nmemb, size_t size)
  9731. {
  9732. /* Check for overflow. */
  9733. if (nmemb >= ~(size_t) 0 / size)
  9734. {
  9735. error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
  9736. (long) nmemb);
  9737. xexit (1);
  9738. }
  9739. return xcalloc (nmemb, size);
  9740. }
  9741. static unsigned long
  9742. calc_gnu_debuglink_crc32 (unsigned long crc,
  9743. const unsigned char * buf,
  9744. bfd_size_type len)
  9745. {
  9746. static const unsigned long crc32_table[256] =
  9747. {
  9748. 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
  9749. 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
  9750. 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
  9751. 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
  9752. 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
  9753. 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
  9754. 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
  9755. 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
  9756. 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
  9757. 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
  9758. 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
  9759. 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
  9760. 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
  9761. 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
  9762. 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
  9763. 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
  9764. 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
  9765. 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
  9766. 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
  9767. 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
  9768. 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
  9769. 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
  9770. 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
  9771. 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
  9772. 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
  9773. 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
  9774. 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
  9775. 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
  9776. 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
  9777. 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
  9778. 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
  9779. 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
  9780. 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
  9781. 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
  9782. 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
  9783. 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
  9784. 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
  9785. 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
  9786. 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
  9787. 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
  9788. 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
  9789. 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
  9790. 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
  9791. 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
  9792. 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
  9793. 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
  9794. 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
  9795. 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
  9796. 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
  9797. 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
  9798. 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
  9799. 0x2d02ef8d
  9800. };
  9801. const unsigned char *end;
  9802. crc = ~crc & 0xffffffff;
  9803. for (end = buf + len; buf < end; ++ buf)
  9804. crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
  9805. return ~crc & 0xffffffff;
  9806. }
  9807. typedef bool (*check_func_type) (const char *, void *);
  9808. typedef const char *(* parse_func_type) (struct dwarf_section *, void *);
  9809. static bool
  9810. check_gnu_debuglink (const char * pathname, void * crc_pointer)
  9811. {
  9812. static unsigned char buffer [8 * 1024];
  9813. FILE * f;
  9814. bfd_size_type count;
  9815. unsigned long crc = 0;
  9816. void * sep_data;
  9817. sep_data = open_debug_file (pathname);
  9818. if (sep_data == NULL)
  9819. return false;
  9820. /* Yes - we are opening the file twice... */
  9821. f = fopen (pathname, "rb");
  9822. if (f == NULL)
  9823. {
  9824. /* Paranoia: This should never happen. */
  9825. close_debug_file (sep_data);
  9826. warn (_("Unable to reopen separate debug info file: %s\n"), pathname);
  9827. return false;
  9828. }
  9829. while ((count = fread (buffer, 1, sizeof (buffer), f)) > 0)
  9830. crc = calc_gnu_debuglink_crc32 (crc, buffer, count);
  9831. fclose (f);
  9832. if (crc != * (unsigned long *) crc_pointer)
  9833. {
  9834. close_debug_file (sep_data);
  9835. warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
  9836. pathname);
  9837. return false;
  9838. }
  9839. return true;
  9840. }
  9841. static const char *
  9842. parse_gnu_debuglink (struct dwarf_section * section, void * data)
  9843. {
  9844. const char * name;
  9845. unsigned int crc_offset;
  9846. unsigned long * crc32 = (unsigned long *) data;
  9847. /* The name is first.
  9848. The CRC value is stored after the filename, aligned up to 4 bytes. */
  9849. name = (const char *) section->start;
  9850. crc_offset = strnlen (name, section->size) + 1;
  9851. if (crc_offset == 1)
  9852. return NULL;
  9853. crc_offset = (crc_offset + 3) & ~3;
  9854. if (crc_offset + 4 > section->size)
  9855. return NULL;
  9856. * crc32 = byte_get (section->start + crc_offset, 4);
  9857. return name;
  9858. }
  9859. static bool
  9860. check_gnu_debugaltlink (const char * filename, void * data ATTRIBUTE_UNUSED)
  9861. {
  9862. void * sep_data = open_debug_file (filename);
  9863. if (sep_data == NULL)
  9864. return false;
  9865. /* FIXME: We should now extract the build-id in the separate file
  9866. and check it... */
  9867. return true;
  9868. }
  9869. typedef struct build_id_data
  9870. {
  9871. bfd_size_type len;
  9872. const unsigned char * data;
  9873. } Build_id_data;
  9874. static const char *
  9875. parse_gnu_debugaltlink (struct dwarf_section * section, void * data)
  9876. {
  9877. const char * name;
  9878. bfd_size_type namelen;
  9879. bfd_size_type id_len;
  9880. Build_id_data * build_id_data;
  9881. /* The name is first.
  9882. The build-id follows immediately, with no padding, up to the section's end. */
  9883. name = (const char *) section->start;
  9884. namelen = strnlen (name, section->size) + 1;
  9885. if (namelen == 1)
  9886. return NULL;
  9887. if (namelen >= section->size)
  9888. return NULL;
  9889. id_len = section->size - namelen;
  9890. if (id_len < 0x14)
  9891. return NULL;
  9892. build_id_data = (Build_id_data *) data;
  9893. build_id_data->len = id_len;
  9894. build_id_data->data = section->start + namelen;
  9895. return name;
  9896. }
  9897. static void
  9898. add_separate_debug_file (const char * filename, void * handle)
  9899. {
  9900. separate_info * i = xmalloc (sizeof * i);
  9901. i->filename = filename;
  9902. i->handle = handle;
  9903. i->next = first_separate_info;
  9904. first_separate_info = i;
  9905. }
  9906. #if HAVE_LIBDEBUGINFOD
  9907. /* Query debuginfod servers for the target debuglink or debugaltlink
  9908. file. If successful, store the path of the file in filename and
  9909. return TRUE, otherwise return FALSE. */
  9910. static bool
  9911. debuginfod_fetch_separate_debug_info (struct dwarf_section * section,
  9912. char ** filename,
  9913. void * file)
  9914. {
  9915. size_t build_id_len;
  9916. unsigned char * build_id;
  9917. if (strcmp (section->uncompressed_name, ".gnu_debuglink") == 0)
  9918. {
  9919. /* Get the build-id of file. */
  9920. build_id = get_build_id (file);
  9921. build_id_len = 0;
  9922. }
  9923. else if (strcmp (section->uncompressed_name, ".gnu_debugaltlink") == 0)
  9924. {
  9925. /* Get the build-id of the debugaltlink file. */
  9926. unsigned int filelen;
  9927. filelen = strnlen ((const char *)section->start, section->size);
  9928. if (filelen == section->size)
  9929. /* Corrupt debugaltlink. */
  9930. return false;
  9931. build_id = section->start + filelen + 1;
  9932. build_id_len = section->size - (filelen + 1);
  9933. if (build_id_len == 0)
  9934. return false;
  9935. }
  9936. else
  9937. return false;
  9938. if (build_id)
  9939. {
  9940. int fd;
  9941. debuginfod_client * client;
  9942. client = debuginfod_begin ();
  9943. if (client == NULL)
  9944. return false;
  9945. /* Query debuginfod servers for the target file. If found its path
  9946. will be stored in filename. */
  9947. fd = debuginfod_find_debuginfo (client, build_id, build_id_len, filename);
  9948. debuginfod_end (client);
  9949. /* Only free build_id if we allocated space for a hex string
  9950. in get_build_id (). */
  9951. if (build_id_len == 0)
  9952. free (build_id);
  9953. if (fd >= 0)
  9954. {
  9955. /* File successfully retrieved. Close fd since we want to
  9956. use open_debug_file () on filename instead. */
  9957. close (fd);
  9958. return true;
  9959. }
  9960. }
  9961. return false;
  9962. }
  9963. #endif /* HAVE_LIBDEBUGINFOD */
  9964. static void *
  9965. load_separate_debug_info (const char * main_filename,
  9966. struct dwarf_section * xlink,
  9967. parse_func_type parse_func,
  9968. check_func_type check_func,
  9969. void * func_data,
  9970. void * file ATTRIBUTE_UNUSED)
  9971. {
  9972. const char * separate_filename;
  9973. char * debug_filename;
  9974. char * canon_dir;
  9975. size_t canon_dirlen;
  9976. size_t dirlen;
  9977. char * canon_filename;
  9978. char * canon_debug_filename;
  9979. bool self;
  9980. if ((separate_filename = parse_func (xlink, func_data)) == NULL)
  9981. {
  9982. warn (_("Corrupt debuglink section: %s\n"),
  9983. xlink->name ? xlink->name : xlink->uncompressed_name);
  9984. return NULL;
  9985. }
  9986. /* Attempt to locate the separate file.
  9987. This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
  9988. canon_filename = lrealpath (main_filename);
  9989. canon_dir = xstrdup (canon_filename);
  9990. for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--)
  9991. if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1]))
  9992. break;
  9993. canon_dir[canon_dirlen] = '\0';
  9994. #ifndef DEBUGDIR
  9995. #define DEBUGDIR "/lib/debug"
  9996. #endif
  9997. #ifndef EXTRA_DEBUG_ROOT1
  9998. #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
  9999. #endif
  10000. #ifndef EXTRA_DEBUG_ROOT2
  10001. #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
  10002. #endif
  10003. debug_filename = (char *) malloc (strlen (DEBUGDIR) + 1
  10004. + canon_dirlen
  10005. + strlen (".debug/")
  10006. #ifdef EXTRA_DEBUG_ROOT1
  10007. + strlen (EXTRA_DEBUG_ROOT1)
  10008. #endif
  10009. #ifdef EXTRA_DEBUG_ROOT2
  10010. + strlen (EXTRA_DEBUG_ROOT2)
  10011. #endif
  10012. + strlen (separate_filename)
  10013. + 1);
  10014. if (debug_filename == NULL)
  10015. {
  10016. warn (_("Out of memory"));
  10017. free (canon_dir);
  10018. free (canon_filename);
  10019. return NULL;
  10020. }
  10021. /* First try in the current directory. */
  10022. sprintf (debug_filename, "%s", separate_filename);
  10023. if (check_func (debug_filename, func_data))
  10024. goto found;
  10025. /* Then try in a subdirectory called .debug. */
  10026. sprintf (debug_filename, ".debug/%s", separate_filename);
  10027. if (check_func (debug_filename, func_data))
  10028. goto found;
  10029. /* Then try in the same directory as the original file. */
  10030. sprintf (debug_filename, "%s%s", canon_dir, separate_filename);
  10031. if (check_func (debug_filename, func_data))
  10032. goto found;
  10033. /* And the .debug subdirectory of that directory. */
  10034. sprintf (debug_filename, "%s.debug/%s", canon_dir, separate_filename);
  10035. if (check_func (debug_filename, func_data))
  10036. goto found;
  10037. #ifdef EXTRA_DEBUG_ROOT1
  10038. /* Try the first extra debug file root. */
  10039. sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1, separate_filename);
  10040. if (check_func (debug_filename, func_data))
  10041. goto found;
  10042. /* Try the first extra debug file root. */
  10043. sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1, canon_dir, separate_filename);
  10044. if (check_func (debug_filename, func_data))
  10045. goto found;
  10046. #endif
  10047. #ifdef EXTRA_DEBUG_ROOT2
  10048. /* Try the second extra debug file root. */
  10049. sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2, separate_filename);
  10050. if (check_func (debug_filename, func_data))
  10051. goto found;
  10052. #endif
  10053. /* Then try in the global debug_filename directory. */
  10054. strcpy (debug_filename, DEBUGDIR);
  10055. dirlen = strlen (DEBUGDIR) - 1;
  10056. if (dirlen > 0 && DEBUGDIR[dirlen] != '/')
  10057. strcat (debug_filename, "/");
  10058. strcat (debug_filename, (const char *) separate_filename);
  10059. if (check_func (debug_filename, func_data))
  10060. goto found;
  10061. #if HAVE_LIBDEBUGINFOD
  10062. {
  10063. char * tmp_filename;
  10064. if (use_debuginfod
  10065. && debuginfod_fetch_separate_debug_info (xlink,
  10066. & tmp_filename,
  10067. file))
  10068. {
  10069. /* File successfully downloaded from server, replace
  10070. debug_filename with the file's path. */
  10071. free (debug_filename);
  10072. debug_filename = tmp_filename;
  10073. goto found;
  10074. }
  10075. }
  10076. #endif
  10077. if (do_debug_links)
  10078. {
  10079. /* Failed to find the file. */
  10080. warn (_("could not find separate debug file '%s'\n"),
  10081. separate_filename);
  10082. warn (_("tried: %s\n"), debug_filename);
  10083. #ifdef EXTRA_DEBUG_ROOT2
  10084. sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT2,
  10085. separate_filename);
  10086. warn (_("tried: %s\n"), debug_filename);
  10087. #endif
  10088. #ifdef EXTRA_DEBUG_ROOT1
  10089. sprintf (debug_filename, "%s/%s/%s", EXTRA_DEBUG_ROOT1,
  10090. canon_dir, separate_filename);
  10091. warn (_("tried: %s\n"), debug_filename);
  10092. sprintf (debug_filename, "%s/%s", EXTRA_DEBUG_ROOT1,
  10093. separate_filename);
  10094. warn (_("tried: %s\n"), debug_filename);
  10095. #endif
  10096. sprintf (debug_filename, "%s.debug/%s", canon_dir,
  10097. separate_filename);
  10098. warn (_("tried: %s\n"), debug_filename);
  10099. sprintf (debug_filename, "%s%s", canon_dir, separate_filename);
  10100. warn (_("tried: %s\n"), debug_filename);
  10101. sprintf (debug_filename, ".debug/%s", separate_filename);
  10102. warn (_("tried: %s\n"), debug_filename);
  10103. sprintf (debug_filename, "%s", separate_filename);
  10104. warn (_("tried: %s\n"), debug_filename);
  10105. #if HAVE_LIBDEBUGINFOD
  10106. if (use_debuginfod)
  10107. {
  10108. char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR);
  10109. if (urls == NULL)
  10110. urls = "";
  10111. warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls);
  10112. }
  10113. #endif
  10114. }
  10115. free (canon_dir);
  10116. free (debug_filename);
  10117. free (canon_filename);
  10118. return NULL;
  10119. found:
  10120. free (canon_dir);
  10121. canon_debug_filename = lrealpath (debug_filename);
  10122. self = strcmp (canon_debug_filename, canon_filename) == 0;
  10123. free (canon_filename);
  10124. free (canon_debug_filename);
  10125. if (self)
  10126. {
  10127. free (debug_filename);
  10128. return NULL;
  10129. }
  10130. void * debug_handle;
  10131. /* Now open the file.... */
  10132. if ((debug_handle = open_debug_file (debug_filename)) == NULL)
  10133. {
  10134. warn (_("failed to open separate debug file: %s\n"), debug_filename);
  10135. free (debug_filename);
  10136. return NULL;
  10137. }
  10138. /* FIXME: We do not check to see if there are any other separate debug info
  10139. files that would also match. */
  10140. if (do_debug_links)
  10141. printf (_("\n%s: Found separate debug info file: %s\n"), main_filename, debug_filename);
  10142. add_separate_debug_file (debug_filename, debug_handle);
  10143. /* Do not free debug_filename - it might be referenced inside
  10144. the structure returned by open_debug_file(). */
  10145. return debug_handle;
  10146. }
  10147. /* Attempt to load a separate dwarf object file. */
  10148. static void *
  10149. load_dwo_file (const char * main_filename, const char * name, const char * dir, const char * id ATTRIBUTE_UNUSED)
  10150. {
  10151. char * separate_filename;
  10152. void * separate_handle;
  10153. if (IS_ABSOLUTE_PATH (name))
  10154. separate_filename = strdup (name);
  10155. else
  10156. /* FIXME: Skip adding / if dwo_dir ends in /. */
  10157. separate_filename = concat (dir, "/", name, NULL);
  10158. if (separate_filename == NULL)
  10159. {
  10160. warn (_("Out of memory allocating dwo filename\n"));
  10161. return NULL;
  10162. }
  10163. if ((separate_handle = open_debug_file (separate_filename)) == NULL)
  10164. {
  10165. warn (_("Unable to load dwo file: %s\n"), separate_filename);
  10166. free (separate_filename);
  10167. return NULL;
  10168. }
  10169. /* FIXME: We should check the dwo_id. */
  10170. printf (_("%s: Found separate debug object file: %s\n\n"), main_filename, separate_filename);
  10171. add_separate_debug_file (separate_filename, separate_handle);
  10172. /* Note - separate_filename will be freed in free_debug_memory(). */
  10173. return separate_handle;
  10174. }
  10175. static void *
  10176. try_build_id_prefix (const char * prefix, char * filename, const unsigned char * data, unsigned long id_len)
  10177. {
  10178. char * f = filename;
  10179. f += sprintf (f, "%s.build-id/%02x/", prefix, (unsigned) *data++);
  10180. id_len --;
  10181. while (id_len --)
  10182. f += sprintf (f, "%02x", (unsigned) *data++);
  10183. strcpy (f, ".debug");
  10184. return open_debug_file (filename);
  10185. }
  10186. /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
  10187. static void
  10188. load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED, void * main_file)
  10189. {
  10190. if (! load_debug_section (note_gnu_build_id, main_file))
  10191. return; /* No .note.gnu.build-id section. */
  10192. struct dwarf_section * section = & debug_displays [note_gnu_build_id].section;
  10193. if (section == NULL)
  10194. {
  10195. warn (_("Unable to load the .note.gnu.build-id section\n"));
  10196. return;
  10197. }
  10198. if (section->start == NULL || section->size < 0x18)
  10199. {
  10200. warn (_(".note.gnu.build-id section is corrupt/empty\n"));
  10201. return;
  10202. }
  10203. /* In theory we should extract the contents of the section into
  10204. a note structure and then check the fields. For now though
  10205. just use hard coded offsets instead:
  10206. Field Bytes Contents
  10207. NSize 0...3 4
  10208. DSize 4...7 8+
  10209. Type 8..11 3 (NT_GNU_BUILD_ID)
  10210. Name 12.15 GNU\0
  10211. Data 16.... */
  10212. /* FIXME: Check the name size, name and type fields. */
  10213. unsigned long build_id_size;
  10214. build_id_size = byte_get (section->start + 4, 4);
  10215. if (build_id_size < 8)
  10216. {
  10217. warn (_(".note.gnu.build-id data size is too small\n"));
  10218. return;
  10219. }
  10220. if (build_id_size > (section->size - 16))
  10221. {
  10222. warn (_(".note.gnu.build-id data size is too bug\n"));
  10223. return;
  10224. }
  10225. char * filename;
  10226. filename = xmalloc (strlen (".build-id/")
  10227. + build_id_size * 2 + 2
  10228. + strlen (".debug")
  10229. /* The next string should be the same as the longest
  10230. name found in the prefixes[] array below. */
  10231. + strlen ("/usrlib64/debug/usr")
  10232. + 1);
  10233. void * handle;
  10234. static const char * prefixes[] =
  10235. {
  10236. "",
  10237. ".debug/",
  10238. "/usr/lib/debug/",
  10239. "/usr/lib/debug/usr/",
  10240. "/usr/lib64/debug/",
  10241. "/usr/lib64/debug/usr"
  10242. };
  10243. long unsigned int i;
  10244. for (i = 0; i < ARRAY_SIZE (prefixes); i++)
  10245. {
  10246. handle = try_build_id_prefix (prefixes[i], filename,
  10247. section->start + 16, build_id_size);
  10248. if (handle != NULL)
  10249. break;
  10250. }
  10251. /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
  10252. if (handle == NULL)
  10253. {
  10254. /* Failed to find a debug file associated with the build-id.
  10255. This is not an error however, rather it just means that
  10256. the debug info has probably not been loaded on the system,
  10257. or that another method is being used to link to the debug
  10258. info. */
  10259. free (filename);
  10260. return;
  10261. }
  10262. add_separate_debug_file (filename, handle);
  10263. }
  10264. /* Try to load a debug file pointed to by the .debug_sup section. */
  10265. static void
  10266. load_debug_sup_file (const char * main_filename, void * file)
  10267. {
  10268. if (! load_debug_section (debug_sup, file))
  10269. return; /* No .debug_sup section. */
  10270. struct dwarf_section * section;
  10271. section = & debug_displays [debug_sup].section;
  10272. assert (section != NULL);
  10273. if (section->start == NULL || section->size < 5)
  10274. {
  10275. warn (_(".debug_sup section is corrupt/empty\n"));
  10276. return;
  10277. }
  10278. if (section->start[2] != 0)
  10279. return; /* This is a supplementary file. */
  10280. const char * filename = (const char *) section->start + 3;
  10281. if (strnlen (filename, section->size - 3) == section->size - 3)
  10282. {
  10283. warn (_("filename in .debug_sup section is corrupt\n"));
  10284. return;
  10285. }
  10286. if (filename[0] != '/' && strchr (main_filename, '/'))
  10287. {
  10288. char * new_name;
  10289. int new_len;
  10290. new_len = asprintf (& new_name, "%.*s/%s",
  10291. (int) (strrchr (main_filename, '/') - main_filename),
  10292. main_filename,
  10293. filename);
  10294. if (new_len < 3)
  10295. {
  10296. warn (_("unable to construct path for supplementary debug file"));
  10297. if (new_len > -1)
  10298. free (new_name);
  10299. return;
  10300. }
  10301. filename = new_name;
  10302. }
  10303. else
  10304. {
  10305. /* PR 27796: Make sure that we pass a filename that can be free'd to
  10306. add_separate_debug_file(). */
  10307. filename = strdup (filename);
  10308. if (filename == NULL)
  10309. {
  10310. warn (_("out of memory constructing filename for .debug_sup link\n"));
  10311. return;
  10312. }
  10313. }
  10314. void * handle = open_debug_file (filename);
  10315. if (handle == NULL)
  10316. {
  10317. warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename);
  10318. free ((void *) filename);
  10319. return;
  10320. }
  10321. printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename, filename);
  10322. /* FIXME: Compare the checksums, if present. */
  10323. add_separate_debug_file (filename, handle);
  10324. }
  10325. /* Load a debuglink section and/or a debugaltlink section, if either are present.
  10326. Recursively check the loaded files for more of these sections.
  10327. Also follow any links in .debug_sup sections.
  10328. FIXME: Should also check for DWO_* entries in the newly loaded files. */
  10329. static void
  10330. check_for_and_load_links (void * file, const char * filename)
  10331. {
  10332. void * handle = NULL;
  10333. if (load_debug_section (gnu_debugaltlink, file))
  10334. {
  10335. Build_id_data build_id_data;
  10336. handle = load_separate_debug_info (filename,
  10337. & debug_displays[gnu_debugaltlink].section,
  10338. parse_gnu_debugaltlink,
  10339. check_gnu_debugaltlink,
  10340. & build_id_data,
  10341. file);
  10342. if (handle)
  10343. {
  10344. assert (handle == first_separate_info->handle);
  10345. check_for_and_load_links (first_separate_info->handle,
  10346. first_separate_info->filename);
  10347. }
  10348. }
  10349. if (load_debug_section (gnu_debuglink, file))
  10350. {
  10351. unsigned long crc32;
  10352. handle = load_separate_debug_info (filename,
  10353. & debug_displays[gnu_debuglink].section,
  10354. parse_gnu_debuglink,
  10355. check_gnu_debuglink,
  10356. & crc32,
  10357. file);
  10358. if (handle)
  10359. {
  10360. assert (handle == first_separate_info->handle);
  10361. check_for_and_load_links (first_separate_info->handle,
  10362. first_separate_info->filename);
  10363. }
  10364. }
  10365. load_debug_sup_file (filename, file);
  10366. load_build_id_debug_file (filename, file);
  10367. }
  10368. /* Load the separate debug info file(s) attached to FILE, if any exist.
  10369. Returns TRUE if any were found, FALSE otherwise.
  10370. If TRUE is returned then the linked list starting at first_separate_info
  10371. will be populated with open file handles. */
  10372. bool
  10373. load_separate_debug_files (void * file, const char * filename)
  10374. {
  10375. /* Skip this operation if we are not interested in debug links. */
  10376. if (! do_follow_links && ! do_debug_links)
  10377. return false;
  10378. /* See if there are any dwo links. */
  10379. if (load_debug_section (str, file)
  10380. && load_debug_section (abbrev, file)
  10381. && load_debug_section (info, file))
  10382. {
  10383. free_dwo_info ();
  10384. if (process_debug_info (& debug_displays[info].section, file, abbrev,
  10385. true, false))
  10386. {
  10387. bool introduced = false;
  10388. dwo_info *dwinfo;
  10389. const char *dir = NULL;
  10390. const char *id = NULL;
  10391. const char *name = NULL;
  10392. for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = dwinfo->next)
  10393. {
  10394. /* Accumulate NAME, DIR and ID fields. */
  10395. switch (dwinfo->type)
  10396. {
  10397. case DWO_NAME:
  10398. if (name != NULL)
  10399. warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
  10400. name = dwinfo->value;
  10401. break;
  10402. case DWO_DIR:
  10403. /* There can be multiple DW_AT_comp_dir entries in a CU,
  10404. so do not complain. */
  10405. dir = dwinfo->value;
  10406. break;
  10407. case DWO_ID:
  10408. if (id != NULL)
  10409. warn (_("multiple DWO_IDs encountered for the same CU\n"));
  10410. id = dwinfo->value;
  10411. break;
  10412. default:
  10413. error (_("Unexpected DWO INFO type"));
  10414. break;
  10415. }
  10416. /* If we have reached the end of our list, or we are changing
  10417. CUs, then display the information that we have accumulated
  10418. so far. */
  10419. if (name != NULL
  10420. && (dwinfo->next == NULL
  10421. || dwinfo->next->cu_offset != dwinfo->cu_offset))
  10422. {
  10423. if (do_debug_links)
  10424. {
  10425. if (! introduced)
  10426. {
  10427. printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
  10428. debug_displays [info].section.uncompressed_name);
  10429. introduced = true;
  10430. }
  10431. printf (_(" Name: %s\n"), name);
  10432. printf (_(" Directory: %s\n"), dir ? dir : _("<not-found>"));
  10433. if (id != NULL)
  10434. display_data (printf (_(" ID: ")), (unsigned char *) id, 8);
  10435. else
  10436. printf (_(" ID: <not specified>\n"));
  10437. printf ("\n\n");
  10438. }
  10439. if (do_follow_links)
  10440. load_dwo_file (filename, name, dir, id);
  10441. name = dir = id = NULL;
  10442. }
  10443. }
  10444. }
  10445. }
  10446. if (! do_follow_links)
  10447. /* The other debug links will be displayed by display_debug_links()
  10448. so we do not need to do any further processing here. */
  10449. return false;
  10450. /* FIXME: We do not check for the presence of both link sections in the same file. */
  10451. /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
  10452. /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
  10453. check_for_and_load_links (file, filename);
  10454. if (first_separate_info != NULL)
  10455. return true;
  10456. do_follow_links = 0;
  10457. return false;
  10458. }
  10459. void
  10460. free_debug_memory (void)
  10461. {
  10462. unsigned int i;
  10463. free_all_abbrevs ();
  10464. free (cu_abbrev_map);
  10465. cu_abbrev_map = NULL;
  10466. next_free_abbrev_map_entry = 0;
  10467. free (shndx_pool);
  10468. shndx_pool = NULL;
  10469. shndx_pool_size = 0;
  10470. shndx_pool_used = 0;
  10471. free (cu_sets);
  10472. cu_sets = NULL;
  10473. cu_count = 0;
  10474. free (tu_sets);
  10475. tu_sets = NULL;
  10476. tu_count = 0;
  10477. memset (level_type_signed, 0, sizeof level_type_signed);
  10478. cu_tu_indexes_read = -1;
  10479. for (i = 0; i < max; i++)
  10480. free_debug_section ((enum dwarf_section_display_enum) i);
  10481. if (debug_information != NULL)
  10482. {
  10483. for (i = 0; i < alloc_num_debug_info_entries; i++)
  10484. {
  10485. if (debug_information [i].max_loc_offsets)
  10486. {
  10487. free (debug_information [i].loc_offsets);
  10488. free (debug_information [i].have_frame_base);
  10489. }
  10490. if (debug_information [i].max_range_lists)
  10491. free (debug_information [i].range_lists);
  10492. }
  10493. free (debug_information);
  10494. debug_information = NULL;
  10495. alloc_num_debug_info_entries = num_debug_info_entries = 0;
  10496. }
  10497. separate_info * d;
  10498. separate_info * next;
  10499. for (d = first_separate_info; d != NULL; d = next)
  10500. {
  10501. close_debug_file (d->handle);
  10502. free ((void *) d->filename);
  10503. next = d->next;
  10504. free ((void *) d);
  10505. }
  10506. first_separate_info = NULL;
  10507. free_dwo_info ();
  10508. }
  10509. void
  10510. dwarf_select_sections_by_names (const char *names)
  10511. {
  10512. typedef struct
  10513. {
  10514. const char * option;
  10515. int * variable;
  10516. int val;
  10517. }
  10518. debug_dump_long_opts;
  10519. static const debug_dump_long_opts opts_table [] =
  10520. {
  10521. /* Please keep this table alpha- sorted. */
  10522. { "Ranges", & do_debug_ranges, 1 },
  10523. { "abbrev", & do_debug_abbrevs, 1 },
  10524. { "addr", & do_debug_addr, 1 },
  10525. { "aranges", & do_debug_aranges, 1 },
  10526. { "cu_index", & do_debug_cu_index, 1 },
  10527. { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
  10528. #ifdef HAVE_LIBDEBUGINFOD
  10529. { "do-not-use-debuginfod", & use_debuginfod, 0 },
  10530. #endif
  10531. { "follow-links", & do_follow_links, 1 },
  10532. { "frames", & do_debug_frames, 1 },
  10533. { "frames-interp", & do_debug_frames_interp, 1 },
  10534. /* The special .gdb_index section. */
  10535. { "gdb_index", & do_gdb_index, 1 },
  10536. { "info", & do_debug_info, 1 },
  10537. { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
  10538. { "links", & do_debug_links, 1 },
  10539. { "loc", & do_debug_loc, 1 },
  10540. { "macro", & do_debug_macinfo, 1 },
  10541. { "no-follow-links", & do_follow_links, 0 },
  10542. { "pubnames", & do_debug_pubnames, 1 },
  10543. { "pubtypes", & do_debug_pubtypes, 1 },
  10544. /* This entry is for compatibility
  10545. with earlier versions of readelf. */
  10546. { "ranges", & do_debug_aranges, 1 },
  10547. { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
  10548. { "str", & do_debug_str, 1 },
  10549. { "str-offsets", & do_debug_str_offsets, 1 },
  10550. /* These trace_* sections are used by Itanium VMS. */
  10551. { "trace_abbrev", & do_trace_abbrevs, 1 },
  10552. { "trace_aranges", & do_trace_aranges, 1 },
  10553. { "trace_info", & do_trace_info, 1 },
  10554. #ifdef HAVE_LIBDEBUGINFOD
  10555. { "use-debuginfod", & use_debuginfod, 1 },
  10556. #endif
  10557. { NULL, NULL, 0 }
  10558. };
  10559. const char *p;
  10560. p = names;
  10561. while (*p)
  10562. {
  10563. const debug_dump_long_opts * entry;
  10564. for (entry = opts_table; entry->option; entry++)
  10565. {
  10566. size_t len = strlen (entry->option);
  10567. if (strncmp (p, entry->option, len) == 0
  10568. && (p[len] == ',' || p[len] == '\0'))
  10569. {
  10570. * entry->variable = entry->val;
  10571. /* The --debug-dump=frames-interp option also
  10572. enables the --debug-dump=frames option. */
  10573. if (do_debug_frames_interp)
  10574. do_debug_frames = 1;
  10575. p += len;
  10576. break;
  10577. }
  10578. }
  10579. if (entry->option == NULL)
  10580. {
  10581. warn (_("Unrecognized debug option '%s'\n"), p);
  10582. p = strchr (p, ',');
  10583. if (p == NULL)
  10584. break;
  10585. }
  10586. if (*p == ',')
  10587. p++;
  10588. }
  10589. }
  10590. void
  10591. dwarf_select_sections_by_letters (const char *letters)
  10592. {
  10593. unsigned int lindex = 0;
  10594. while (letters[lindex])
  10595. switch (letters[lindex++])
  10596. {
  10597. case 'A': do_debug_addr = 1; break;
  10598. case 'a': do_debug_abbrevs = 1; break;
  10599. case 'c': do_debug_cu_index = 1; break;
  10600. #ifdef HAVE_LIBDEBUGINFOD
  10601. case 'D': use_debuginfod = 1; break;
  10602. case 'E': use_debuginfod = 0; break;
  10603. #endif
  10604. case 'F': do_debug_frames_interp = 1; /* Fall through. */
  10605. case 'f': do_debug_frames = 1; break;
  10606. case 'g': do_gdb_index = 1; break;
  10607. case 'i': do_debug_info = 1; break;
  10608. case 'K': do_follow_links = 1; break;
  10609. case 'N': do_follow_links = 0; break;
  10610. case 'k': do_debug_links = 1; break;
  10611. case 'l': do_debug_lines |= FLAG_DEBUG_LINES_RAW; break;
  10612. case 'L': do_debug_lines |= FLAG_DEBUG_LINES_DECODED; break;
  10613. case 'm': do_debug_macinfo = 1; break;
  10614. case 'O': do_debug_str_offsets = 1; break;
  10615. case 'o': do_debug_loc = 1; break;
  10616. case 'p': do_debug_pubnames = 1; break;
  10617. case 'R': do_debug_ranges = 1; break;
  10618. case 'r': do_debug_aranges = 1; break;
  10619. case 's': do_debug_str = 1; break;
  10620. case 'T': do_trace_aranges = 1; break;
  10621. case 't': do_debug_pubtypes = 1; break;
  10622. case 'U': do_trace_info = 1; break;
  10623. case 'u': do_trace_abbrevs = 1; break;
  10624. default:
  10625. warn (_("Unrecognized debug option '%s'\n"), letters);
  10626. break;
  10627. }
  10628. }
  10629. void
  10630. dwarf_select_sections_all (void)
  10631. {
  10632. do_debug_info = 1;
  10633. do_debug_abbrevs = 1;
  10634. do_debug_lines = FLAG_DEBUG_LINES_RAW;
  10635. do_debug_pubnames = 1;
  10636. do_debug_pubtypes = 1;
  10637. do_debug_aranges = 1;
  10638. do_debug_ranges = 1;
  10639. do_debug_frames = 1;
  10640. do_debug_macinfo = 1;
  10641. do_debug_str = 1;
  10642. do_debug_loc = 1;
  10643. do_gdb_index = 1;
  10644. do_trace_info = 1;
  10645. do_trace_abbrevs = 1;
  10646. do_trace_aranges = 1;
  10647. do_debug_addr = 1;
  10648. do_debug_cu_index = 1;
  10649. do_follow_links = 1;
  10650. do_debug_links = 1;
  10651. do_debug_str_offsets = 1;
  10652. }
  10653. #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
  10654. #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
  10655. /* N.B. The order here must match the order in section_display_enum. */
  10656. struct dwarf_section_display debug_displays[] =
  10657. {
  10658. { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false },
  10659. { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS }, display_debug_aranges, &do_debug_aranges, true },
  10660. { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true },
  10661. { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev)}, display_debug_info, &do_debug_info, true },
  10662. { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true },
  10663. { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubnames, false },
  10664. { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubnames, false },
  10665. { { ".eh_frame", "", "", NO_ABBREVS }, display_debug_frames, &do_debug_frames, true },
  10666. { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false },
  10667. { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true },
  10668. { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS }, display_debug_str, &do_debug_str, false },
  10669. { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false },
  10670. { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true },
  10671. { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true },
  10672. { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS }, display_debug_pubnames, &do_debug_pubtypes, false },
  10673. { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS }, display_debug_gnu_pubnames, &do_debug_pubtypes, false },
  10674. { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true },
  10675. { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS }, display_debug_ranges, &do_debug_ranges, true },
  10676. { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS }, display_debug_not_supported, NULL, false },
  10677. { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS }, display_debug_not_supported, NULL, false },
  10678. { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev) }, display_debug_types, &do_debug_info, true },
  10679. { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS }, display_debug_not_supported, NULL, false },
  10680. { { ".gdb_index", "", "", NO_ABBREVS }, display_gdb_index, &do_gdb_index, false },
  10681. { { ".debug_names", "", "", NO_ABBREVS }, display_debug_names, &do_gdb_index, false },
  10682. { { ".trace_info", "", "", ABBREV (trace_abbrev) }, display_trace_info, &do_trace_info, true },
  10683. { { ".trace_abbrev", "", "", NO_ABBREVS }, display_debug_abbrev, &do_trace_abbrevs, false },
  10684. { { ".trace_aranges", "", "", NO_ABBREVS }, display_debug_aranges, &do_trace_aranges, false },
  10685. { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo) }, display_debug_info, &do_debug_info, true },
  10686. { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS }, display_debug_abbrev, &do_debug_abbrevs, false },
  10687. { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo) }, display_debug_types, &do_debug_info, true },
  10688. { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS }, display_debug_lines, &do_debug_lines, true },
  10689. { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS }, display_debug_loc, &do_debug_loc, true },
  10690. { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS }, display_debug_macro, &do_debug_macinfo, true },
  10691. { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS }, display_debug_macinfo, &do_debug_macinfo, false },
  10692. { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS }, display_debug_str, &do_debug_str, true },
  10693. { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true },
  10694. { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS }, display_debug_str_offsets, &do_debug_str_offsets, true },
  10695. { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS }, display_debug_addr, &do_debug_addr, true },
  10696. { { ".debug_cu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false },
  10697. { { ".debug_tu_index", "", "", NO_ABBREVS }, display_cu_index, &do_debug_cu_index, false },
  10698. { { ".gnu_debuglink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false },
  10699. { { ".gnu_debugaltlink", "", "", NO_ABBREVS }, display_debug_links, &do_debug_links, false },
  10700. { { ".debug_sup", "", "", NO_ABBREVS }, display_debug_sup, &do_debug_links, false },
  10701. /* Separate debug info files can containt their own .debug_str section,
  10702. and this might be in *addition* to a .debug_str section already present
  10703. in the main file. Hence we need to have two entries for .debug_str. */
  10704. { { ".debug_str", ".zdebug_str", "", NO_ABBREVS }, display_debug_str, &do_debug_str, false },
  10705. { { ".note.gnu.build-id", "", "", NO_ABBREVS }, display_debug_not_supported, NULL, false },
  10706. };
  10707. /* A static assertion. */
  10708. extern int debug_displays_assert[ARRAY_SIZE (debug_displays) == max ? 1 : -1];