ieee.c 187 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410
  1. /* ieee.c -- Read and write IEEE-695 debugging information.
  2. Copyright (C) 1996-2017 Free Software Foundation, Inc.
  3. Written by Ian Lance Taylor <ian@cygnus.com>.
  4. This file is part of GNU Binutils.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  16. 02110-1301, USA. */
  17. /* This file reads and writes IEEE-695 debugging information. */
  18. #include "sysdep.h"
  19. #include <assert.h>
  20. #include "bfd.h"
  21. #include "ieee.h"
  22. #include "libiberty.h"
  23. #include "debug.h"
  24. #include "budbg.h"
  25. #include "filenames.h"
  26. /* This structure holds an entry on the block stack. */
  27. struct ieee_block
  28. {
  29. /* The kind of block. */
  30. int kind;
  31. /* The source file name, for a BB5 block. */
  32. const char *filename;
  33. /* The index of the function type, for a BB4 or BB6 block. */
  34. unsigned int fnindx;
  35. /* TRUE if this function is being skipped. */
  36. bfd_boolean skip;
  37. };
  38. /* This structure is the block stack. */
  39. #define BLOCKSTACK_SIZE (16)
  40. struct ieee_blockstack
  41. {
  42. /* The stack pointer. */
  43. struct ieee_block *bsp;
  44. /* The stack. */
  45. struct ieee_block stack[BLOCKSTACK_SIZE];
  46. };
  47. /* This structure holds information for a variable. */
  48. enum ieee_var_kind
  49. {
  50. IEEE_UNKNOWN,
  51. IEEE_EXTERNAL,
  52. IEEE_GLOBAL,
  53. IEEE_STATIC,
  54. IEEE_LOCAL,
  55. IEEE_FUNCTION
  56. };
  57. struct ieee_var
  58. {
  59. /* Start of name. */
  60. const char *name;
  61. /* Length of name. */
  62. unsigned long namlen;
  63. /* Type. */
  64. debug_type type;
  65. /* Slot if we make an indirect type. */
  66. debug_type *pslot;
  67. /* Kind of variable or function. */
  68. enum ieee_var_kind kind;
  69. };
  70. /* This structure holds all the variables. */
  71. struct ieee_vars
  72. {
  73. /* Number of slots allocated. */
  74. unsigned int alloc;
  75. /* Variables. */
  76. struct ieee_var *vars;
  77. };
  78. /* This structure holds information for a type. We need this because
  79. we don't want to represent bitfields as real types. */
  80. struct ieee_type
  81. {
  82. /* Type. */
  83. debug_type type;
  84. /* Slot if this is type is referenced before it is defined. */
  85. debug_type *pslot;
  86. /* Slots for arguments if we make indirect types for them. */
  87. debug_type *arg_slots;
  88. /* If this is a bitfield, this is the size in bits. If this is not
  89. a bitfield, this is zero. */
  90. unsigned long bitsize;
  91. };
  92. /* This structure holds all the type information. */
  93. struct ieee_types
  94. {
  95. /* Number of slots allocated. */
  96. unsigned int alloc;
  97. /* Types. */
  98. struct ieee_type *types;
  99. /* Builtin types. */
  100. #define BUILTIN_TYPE_COUNT (60)
  101. debug_type builtins[BUILTIN_TYPE_COUNT];
  102. };
  103. /* This structure holds a linked last of structs with their tag names,
  104. so that we can convert them to C++ classes if necessary. */
  105. struct ieee_tag
  106. {
  107. /* Next tag. */
  108. struct ieee_tag *next;
  109. /* This tag name. */
  110. const char *name;
  111. /* The type of the tag. */
  112. debug_type type;
  113. /* The tagged type is an indirect type pointing at this slot. */
  114. debug_type slot;
  115. /* This is an array of slots used when a field type is converted
  116. into a indirect type, in case it needs to be later converted into
  117. a reference type. */
  118. debug_type *fslots;
  119. };
  120. /* This structure holds the information we pass around to the parsing
  121. functions. */
  122. struct ieee_info
  123. {
  124. /* The debugging handle. */
  125. void *dhandle;
  126. /* The BFD. */
  127. bfd *abfd;
  128. /* The start of the bytes to be parsed. */
  129. const bfd_byte *bytes;
  130. /* The end of the bytes to be parsed. */
  131. const bfd_byte *pend;
  132. /* The block stack. */
  133. struct ieee_blockstack blockstack;
  134. /* Whether we have seen a BB1 or BB2. */
  135. bfd_boolean saw_filename;
  136. /* The variables. */
  137. struct ieee_vars vars;
  138. /* The global variables, after a global typedef block. */
  139. struct ieee_vars *global_vars;
  140. /* The types. */
  141. struct ieee_types types;
  142. /* The global types, after a global typedef block. */
  143. struct ieee_types *global_types;
  144. /* The list of tagged structs. */
  145. struct ieee_tag *tags;
  146. };
  147. /* Basic builtin types, not including the pointers. */
  148. enum builtin_types
  149. {
  150. builtin_unknown = 0,
  151. builtin_void = 1,
  152. builtin_signed_char = 2,
  153. builtin_unsigned_char = 3,
  154. builtin_signed_short_int = 4,
  155. builtin_unsigned_short_int = 5,
  156. builtin_signed_long = 6,
  157. builtin_unsigned_long = 7,
  158. builtin_signed_long_long = 8,
  159. builtin_unsigned_long_long = 9,
  160. builtin_float = 10,
  161. builtin_double = 11,
  162. builtin_long_double = 12,
  163. builtin_long_long_double = 13,
  164. builtin_quoted_string = 14,
  165. builtin_instruction_address = 15,
  166. builtin_int = 16,
  167. builtin_unsigned = 17,
  168. builtin_unsigned_int = 18,
  169. builtin_char = 19,
  170. builtin_long = 20,
  171. builtin_short = 21,
  172. builtin_unsigned_short = 22,
  173. builtin_short_int = 23,
  174. builtin_signed_short = 24,
  175. builtin_bcd_float = 25
  176. };
  177. /* These are the values found in the derivation flags of a 'b'
  178. component record of a 'T' type extension record in a C++ pmisc
  179. record. These are bitmasks. */
  180. /* Set for a private base class, clear for a public base class.
  181. Protected base classes are not supported. */
  182. #define BASEFLAGS_PRIVATE (0x1)
  183. /* Set for a virtual base class. */
  184. #define BASEFLAGS_VIRTUAL (0x2)
  185. /* Set for a friend class, clear for a base class. */
  186. #define BASEFLAGS_FRIEND (0x10)
  187. /* These are the values found in the specs flags of a 'd', 'm', or 'v'
  188. component record of a 'T' type extension record in a C++ pmisc
  189. record. The same flags are used for a 'M' record in a C++ pmisc
  190. record. */
  191. /* The lower two bits hold visibility information. */
  192. #define CXXFLAGS_VISIBILITY (0x3)
  193. /* This value in the lower two bits indicates a public member. */
  194. #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
  195. /* This value in the lower two bits indicates a private member. */
  196. #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
  197. /* This value in the lower two bits indicates a protected member. */
  198. #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
  199. /* Set for a static member. */
  200. #define CXXFLAGS_STATIC (0x4)
  201. /* Set for a virtual override. */
  202. #define CXXFLAGS_OVERRIDE (0x8)
  203. /* Set for a friend function. */
  204. #define CXXFLAGS_FRIEND (0x10)
  205. /* Set for a const function. */
  206. #define CXXFLAGS_CONST (0x20)
  207. /* Set for a volatile function. */
  208. #define CXXFLAGS_VOLATILE (0x40)
  209. /* Set for an overloaded function. */
  210. #define CXXFLAGS_OVERLOADED (0x80)
  211. /* Set for an operator function. */
  212. #define CXXFLAGS_OPERATOR (0x100)
  213. /* Set for a constructor or destructor. */
  214. #define CXXFLAGS_CTORDTOR (0x400)
  215. /* Set for a constructor. */
  216. #define CXXFLAGS_CTOR (0x200)
  217. /* Set for an inline function. */
  218. #define CXXFLAGS_INLINE (0x800)
  219. /* Local functions. */
  220. static void ieee_error (struct ieee_info *, const bfd_byte *, const char *);
  221. static void ieee_eof (struct ieee_info *);
  222. static char *savestring (const char *, unsigned long);
  223. static bfd_boolean ieee_read_number
  224. (struct ieee_info *, const bfd_byte **, bfd_vma *);
  225. static bfd_boolean ieee_read_optional_number
  226. (struct ieee_info *, const bfd_byte **, bfd_vma *, bfd_boolean *);
  227. static bfd_boolean ieee_read_id
  228. (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
  229. static bfd_boolean ieee_read_optional_id
  230. (struct ieee_info *, const bfd_byte **, const char **, unsigned long *,
  231. bfd_boolean *);
  232. static bfd_boolean ieee_read_expression
  233. (struct ieee_info *, const bfd_byte **, bfd_vma *);
  234. static debug_type ieee_builtin_type
  235. (struct ieee_info *, const bfd_byte *, unsigned int);
  236. static bfd_boolean ieee_alloc_type
  237. (struct ieee_info *, unsigned int, bfd_boolean);
  238. static bfd_boolean ieee_read_type_index
  239. (struct ieee_info *, const bfd_byte **, debug_type *);
  240. static int ieee_regno_to_genreg (bfd *, int);
  241. static int ieee_genreg_to_regno (bfd *, int);
  242. static bfd_boolean parse_ieee_bb (struct ieee_info *, const bfd_byte **);
  243. static bfd_boolean parse_ieee_be (struct ieee_info *, const bfd_byte **);
  244. static bfd_boolean parse_ieee_nn (struct ieee_info *, const bfd_byte **);
  245. static bfd_boolean parse_ieee_ty (struct ieee_info *, const bfd_byte **);
  246. static bfd_boolean parse_ieee_atn (struct ieee_info *, const bfd_byte **);
  247. static bfd_boolean ieee_read_cxx_misc
  248. (struct ieee_info *, const bfd_byte **, unsigned long);
  249. static bfd_boolean ieee_read_cxx_class
  250. (struct ieee_info *, const bfd_byte **, unsigned long);
  251. static bfd_boolean ieee_read_cxx_defaults
  252. (struct ieee_info *, const bfd_byte **, unsigned long);
  253. static bfd_boolean ieee_read_reference
  254. (struct ieee_info *, const bfd_byte **);
  255. static bfd_boolean ieee_require_asn
  256. (struct ieee_info *, const bfd_byte **, bfd_vma *);
  257. static bfd_boolean ieee_require_atn65
  258. (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
  259. /* Report an error in the IEEE debugging information. */
  260. static void
  261. ieee_error (struct ieee_info *info, const bfd_byte *p, const char *s)
  262. {
  263. if (p != NULL)
  264. fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
  265. (unsigned long) (p - info->bytes), s, *p);
  266. else
  267. fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
  268. }
  269. /* Report an unexpected EOF in the IEEE debugging information. */
  270. static void
  271. ieee_eof (struct ieee_info *info)
  272. {
  273. ieee_error (info, (const bfd_byte *) NULL,
  274. _("unexpected end of debugging information"));
  275. }
  276. /* Save a string in memory. */
  277. static char *
  278. savestring (const char *start, unsigned long len)
  279. {
  280. char *ret;
  281. ret = (char *) xmalloc (len + 1);
  282. memcpy (ret, start, len);
  283. ret[len] = '\0';
  284. return ret;
  285. }
  286. /* Read a number which must be present in an IEEE file. */
  287. static bfd_boolean
  288. ieee_read_number (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
  289. {
  290. return ieee_read_optional_number (info, pp, pv, (bfd_boolean *) NULL);
  291. }
  292. /* Read a number in an IEEE file. If ppresent is not NULL, the number
  293. need not be there. */
  294. static bfd_boolean
  295. ieee_read_optional_number (struct ieee_info *info, const bfd_byte **pp,
  296. bfd_vma *pv, bfd_boolean *ppresent)
  297. {
  298. ieee_record_enum_type b;
  299. if (*pp >= info->pend)
  300. {
  301. if (ppresent != NULL)
  302. {
  303. *ppresent = FALSE;
  304. return TRUE;
  305. }
  306. ieee_eof (info);
  307. return FALSE;
  308. }
  309. b = (ieee_record_enum_type) **pp;
  310. ++*pp;
  311. if (b <= ieee_number_end_enum)
  312. {
  313. *pv = (bfd_vma) b;
  314. if (ppresent != NULL)
  315. *ppresent = TRUE;
  316. return TRUE;
  317. }
  318. if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
  319. {
  320. unsigned int i;
  321. i = (int) b - (int) ieee_number_repeat_start_enum;
  322. if (*pp + i - 1 >= info->pend)
  323. {
  324. ieee_eof (info);
  325. return FALSE;
  326. }
  327. *pv = 0;
  328. for (; i > 0; i--)
  329. {
  330. *pv <<= 8;
  331. *pv += **pp;
  332. ++*pp;
  333. }
  334. if (ppresent != NULL)
  335. *ppresent = TRUE;
  336. return TRUE;
  337. }
  338. if (ppresent != NULL)
  339. {
  340. --*pp;
  341. *ppresent = FALSE;
  342. return TRUE;
  343. }
  344. ieee_error (info, *pp - 1, _("invalid number"));
  345. return FALSE;
  346. }
  347. /* Read a required string from an IEEE file. */
  348. static bfd_boolean
  349. ieee_read_id (struct ieee_info *info, const bfd_byte **pp,
  350. const char **pname, unsigned long *pnamlen)
  351. {
  352. return ieee_read_optional_id (info, pp, pname, pnamlen, (bfd_boolean *) NULL);
  353. }
  354. /* Read a string from an IEEE file. If ppresent is not NULL, the
  355. string is optional. */
  356. static bfd_boolean
  357. ieee_read_optional_id (struct ieee_info *info, const bfd_byte **pp,
  358. const char **pname, unsigned long *pnamlen,
  359. bfd_boolean *ppresent)
  360. {
  361. bfd_byte b;
  362. unsigned long len;
  363. if (*pp >= info->pend)
  364. {
  365. ieee_eof (info);
  366. return FALSE;
  367. }
  368. b = **pp;
  369. ++*pp;
  370. if (b <= 0x7f)
  371. len = b;
  372. else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
  373. {
  374. len = **pp;
  375. ++*pp;
  376. }
  377. else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
  378. {
  379. len = (**pp << 8) + (*pp)[1];
  380. *pp += 2;
  381. }
  382. else
  383. {
  384. if (ppresent != NULL)
  385. {
  386. --*pp;
  387. *ppresent = FALSE;
  388. return TRUE;
  389. }
  390. ieee_error (info, *pp - 1, _("invalid string length"));
  391. return FALSE;
  392. }
  393. if ((unsigned long) (info->pend - *pp) < len)
  394. {
  395. ieee_eof (info);
  396. return FALSE;
  397. }
  398. *pname = (const char *) *pp;
  399. *pnamlen = len;
  400. *pp += len;
  401. if (ppresent != NULL)
  402. *ppresent = TRUE;
  403. return TRUE;
  404. }
  405. /* Read an expression from an IEEE file. Since this code is only used
  406. to parse debugging information, I haven't bothered to write a full
  407. blown IEEE expression parser. I've only thrown in the things I've
  408. seen in debugging information. This can be easily extended if
  409. necessary. */
  410. static bfd_boolean
  411. ieee_read_expression (struct ieee_info *info, const bfd_byte **pp,
  412. bfd_vma *pv)
  413. {
  414. const bfd_byte *expr_start;
  415. #define EXPR_STACK_SIZE (10)
  416. bfd_vma expr_stack[EXPR_STACK_SIZE];
  417. bfd_vma *esp;
  418. expr_start = *pp;
  419. esp = expr_stack;
  420. while (1)
  421. {
  422. const bfd_byte *start;
  423. bfd_vma val;
  424. bfd_boolean present;
  425. ieee_record_enum_type c;
  426. start = *pp;
  427. if (! ieee_read_optional_number (info, pp, &val, &present))
  428. return FALSE;
  429. if (present)
  430. {
  431. if (esp - expr_stack >= EXPR_STACK_SIZE)
  432. {
  433. ieee_error (info, start, _("expression stack overflow"));
  434. return FALSE;
  435. }
  436. *esp++ = val;
  437. continue;
  438. }
  439. c = (ieee_record_enum_type) **pp;
  440. if (c >= ieee_module_beginning_enum)
  441. break;
  442. ++*pp;
  443. if (c == ieee_comma)
  444. break;
  445. switch (c)
  446. {
  447. default:
  448. ieee_error (info, start, _("unsupported IEEE expression operator"));
  449. break;
  450. case ieee_variable_R_enum:
  451. {
  452. bfd_vma indx;
  453. asection *s;
  454. if (! ieee_read_number (info, pp, &indx))
  455. return FALSE;
  456. for (s = info->abfd->sections; s != NULL; s = s->next)
  457. if ((bfd_vma) s->target_index == indx)
  458. break;
  459. if (s == NULL)
  460. {
  461. ieee_error (info, start, _("unknown section"));
  462. return FALSE;
  463. }
  464. if (esp - expr_stack >= EXPR_STACK_SIZE)
  465. {
  466. ieee_error (info, start, _("expression stack overflow"));
  467. return FALSE;
  468. }
  469. *esp++ = bfd_get_section_vma (info->abfd, s);
  470. }
  471. break;
  472. case ieee_function_plus_enum:
  473. case ieee_function_minus_enum:
  474. {
  475. bfd_vma v1, v2;
  476. if (esp - expr_stack < 2)
  477. {
  478. ieee_error (info, start, _("expression stack underflow"));
  479. return FALSE;
  480. }
  481. v1 = *--esp;
  482. v2 = *--esp;
  483. *esp++ = v1 + v2;
  484. }
  485. break;
  486. }
  487. }
  488. if (esp - 1 != expr_stack)
  489. {
  490. ieee_error (info, expr_start, _("expression stack mismatch"));
  491. return FALSE;
  492. }
  493. *pv = *--esp;
  494. return TRUE;
  495. }
  496. /* Return an IEEE builtin type. */
  497. static debug_type
  498. ieee_builtin_type (struct ieee_info *info, const bfd_byte *p,
  499. unsigned int indx)
  500. {
  501. void *dhandle;
  502. debug_type type;
  503. const char *name;
  504. if (indx < BUILTIN_TYPE_COUNT
  505. && info->types.builtins[indx] != DEBUG_TYPE_NULL)
  506. return info->types.builtins[indx];
  507. dhandle = info->dhandle;
  508. if (indx >= 32 && indx < 64)
  509. {
  510. type = debug_make_pointer_type (dhandle,
  511. ieee_builtin_type (info, p, indx - 32));
  512. assert (indx < BUILTIN_TYPE_COUNT);
  513. info->types.builtins[indx] = type;
  514. return type;
  515. }
  516. switch ((enum builtin_types) indx)
  517. {
  518. default:
  519. ieee_error (info, p, _("unknown builtin type"));
  520. return NULL;
  521. case builtin_unknown:
  522. type = debug_make_void_type (dhandle);
  523. name = NULL;
  524. break;
  525. case builtin_void:
  526. type = debug_make_void_type (dhandle);
  527. name = "void";
  528. break;
  529. case builtin_signed_char:
  530. type = debug_make_int_type (dhandle, 1, FALSE);
  531. name = "signed char";
  532. break;
  533. case builtin_unsigned_char:
  534. type = debug_make_int_type (dhandle, 1, TRUE);
  535. name = "unsigned char";
  536. break;
  537. case builtin_signed_short_int:
  538. type = debug_make_int_type (dhandle, 2, FALSE);
  539. name = "signed short int";
  540. break;
  541. case builtin_unsigned_short_int:
  542. type = debug_make_int_type (dhandle, 2, TRUE);
  543. name = "unsigned short int";
  544. break;
  545. case builtin_signed_long:
  546. type = debug_make_int_type (dhandle, 4, FALSE);
  547. name = "signed long";
  548. break;
  549. case builtin_unsigned_long:
  550. type = debug_make_int_type (dhandle, 4, TRUE);
  551. name = "unsigned long";
  552. break;
  553. case builtin_signed_long_long:
  554. type = debug_make_int_type (dhandle, 8, FALSE);
  555. name = "signed long long";
  556. break;
  557. case builtin_unsigned_long_long:
  558. type = debug_make_int_type (dhandle, 8, TRUE);
  559. name = "unsigned long long";
  560. break;
  561. case builtin_float:
  562. type = debug_make_float_type (dhandle, 4);
  563. name = "float";
  564. break;
  565. case builtin_double:
  566. type = debug_make_float_type (dhandle, 8);
  567. name = "double";
  568. break;
  569. case builtin_long_double:
  570. /* FIXME: The size for this type should depend upon the
  571. processor. */
  572. type = debug_make_float_type (dhandle, 12);
  573. name = "long double";
  574. break;
  575. case builtin_long_long_double:
  576. type = debug_make_float_type (dhandle, 16);
  577. name = "long long double";
  578. break;
  579. case builtin_quoted_string:
  580. type = debug_make_array_type (dhandle,
  581. ieee_builtin_type (info, p,
  582. ((unsigned int)
  583. builtin_char)),
  584. ieee_builtin_type (info, p,
  585. ((unsigned int)
  586. builtin_int)),
  587. 0, -1, TRUE);
  588. name = "QUOTED STRING";
  589. break;
  590. case builtin_instruction_address:
  591. /* FIXME: This should be a code address. */
  592. type = debug_make_int_type (dhandle, 4, TRUE);
  593. name = "instruction address";
  594. break;
  595. case builtin_int:
  596. /* FIXME: The size for this type should depend upon the
  597. processor. */
  598. type = debug_make_int_type (dhandle, 4, FALSE);
  599. name = "int";
  600. break;
  601. case builtin_unsigned:
  602. /* FIXME: The size for this type should depend upon the
  603. processor. */
  604. type = debug_make_int_type (dhandle, 4, TRUE);
  605. name = "unsigned";
  606. break;
  607. case builtin_unsigned_int:
  608. /* FIXME: The size for this type should depend upon the
  609. processor. */
  610. type = debug_make_int_type (dhandle, 4, TRUE);
  611. name = "unsigned int";
  612. break;
  613. case builtin_char:
  614. type = debug_make_int_type (dhandle, 1, FALSE);
  615. name = "char";
  616. break;
  617. case builtin_long:
  618. type = debug_make_int_type (dhandle, 4, FALSE);
  619. name = "long";
  620. break;
  621. case builtin_short:
  622. type = debug_make_int_type (dhandle, 2, FALSE);
  623. name = "short";
  624. break;
  625. case builtin_unsigned_short:
  626. type = debug_make_int_type (dhandle, 2, TRUE);
  627. name = "unsigned short";
  628. break;
  629. case builtin_short_int:
  630. type = debug_make_int_type (dhandle, 2, FALSE);
  631. name = "short int";
  632. break;
  633. case builtin_signed_short:
  634. type = debug_make_int_type (dhandle, 2, FALSE);
  635. name = "signed short";
  636. break;
  637. case builtin_bcd_float:
  638. ieee_error (info, p, _("BCD float type not supported"));
  639. return DEBUG_TYPE_NULL;
  640. }
  641. if (name != NULL)
  642. type = debug_name_type (dhandle, name, type);
  643. assert (indx < BUILTIN_TYPE_COUNT);
  644. info->types.builtins[indx] = type;
  645. return type;
  646. }
  647. /* Allocate more space in the type table. If ref is TRUE, this is a
  648. reference to the type; if it is not already defined, we should set
  649. up an indirect type. */
  650. static bfd_boolean
  651. ieee_alloc_type (struct ieee_info *info, unsigned int indx, bfd_boolean ref)
  652. {
  653. unsigned int nalloc;
  654. register struct ieee_type *t;
  655. struct ieee_type *tend;
  656. if (indx >= info->types.alloc)
  657. {
  658. nalloc = info->types.alloc;
  659. if (nalloc == 0)
  660. nalloc = 4;
  661. while (indx >= nalloc)
  662. nalloc *= 2;
  663. info->types.types = ((struct ieee_type *)
  664. xrealloc (info->types.types,
  665. nalloc * sizeof *info->types.types));
  666. memset (info->types.types + info->types.alloc, 0,
  667. (nalloc - info->types.alloc) * sizeof *info->types.types);
  668. tend = info->types.types + nalloc;
  669. for (t = info->types.types + info->types.alloc; t < tend; t++)
  670. t->type = DEBUG_TYPE_NULL;
  671. info->types.alloc = nalloc;
  672. }
  673. if (ref)
  674. {
  675. t = info->types.types + indx;
  676. if (t->type == NULL)
  677. {
  678. t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
  679. *t->pslot = DEBUG_TYPE_NULL;
  680. t->type = debug_make_indirect_type (info->dhandle, t->pslot,
  681. (const char *) NULL);
  682. if (t->type == NULL)
  683. return FALSE;
  684. }
  685. }
  686. return TRUE;
  687. }
  688. /* Read a type index and return the corresponding type. */
  689. static bfd_boolean
  690. ieee_read_type_index (struct ieee_info *info, const bfd_byte **pp,
  691. debug_type *ptype)
  692. {
  693. const bfd_byte *start;
  694. bfd_vma indx;
  695. start = *pp;
  696. if (! ieee_read_number (info, pp, &indx))
  697. return FALSE;
  698. if (indx < 256)
  699. {
  700. *ptype = ieee_builtin_type (info, start, indx);
  701. if (*ptype == NULL)
  702. return FALSE;
  703. return TRUE;
  704. }
  705. indx -= 256;
  706. if (! ieee_alloc_type (info, indx, TRUE))
  707. return FALSE;
  708. *ptype = info->types.types[indx].type;
  709. return TRUE;
  710. }
  711. /* Parse IEEE debugging information for a file. This is passed the
  712. bytes which compose the Debug Information Part of an IEEE file. */
  713. bfd_boolean
  714. parse_ieee (void *dhandle, bfd *abfd, const bfd_byte *bytes, bfd_size_type len)
  715. {
  716. struct ieee_info info;
  717. unsigned int i;
  718. const bfd_byte *p, *pend;
  719. info.dhandle = dhandle;
  720. info.abfd = abfd;
  721. info.bytes = bytes;
  722. info.pend = bytes + len;
  723. info.blockstack.bsp = info.blockstack.stack;
  724. info.saw_filename = FALSE;
  725. info.vars.alloc = 0;
  726. info.vars.vars = NULL;
  727. info.global_vars = NULL;
  728. info.types.alloc = 0;
  729. info.types.types = NULL;
  730. info.global_types = NULL;
  731. info.tags = NULL;
  732. for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
  733. info.types.builtins[i] = DEBUG_TYPE_NULL;
  734. p = bytes;
  735. pend = info.pend;
  736. while (p < pend)
  737. {
  738. const bfd_byte *record_start;
  739. ieee_record_enum_type c;
  740. record_start = p;
  741. c = (ieee_record_enum_type) *p++;
  742. if (c == ieee_at_record_enum)
  743. c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
  744. if (c <= ieee_number_repeat_end_enum)
  745. {
  746. ieee_error (&info, record_start, _("unexpected number"));
  747. return FALSE;
  748. }
  749. switch (c)
  750. {
  751. default:
  752. ieee_error (&info, record_start, _("unexpected record type"));
  753. return FALSE;
  754. case ieee_bb_record_enum:
  755. if (! parse_ieee_bb (&info, &p))
  756. return FALSE;
  757. break;
  758. case ieee_be_record_enum:
  759. if (! parse_ieee_be (&info, &p))
  760. return FALSE;
  761. break;
  762. case ieee_nn_record:
  763. if (! parse_ieee_nn (&info, &p))
  764. return FALSE;
  765. break;
  766. case ieee_ty_record_enum:
  767. if (! parse_ieee_ty (&info, &p))
  768. return FALSE;
  769. break;
  770. case ieee_atn_record_enum:
  771. if (! parse_ieee_atn (&info, &p))
  772. return FALSE;
  773. break;
  774. }
  775. }
  776. if (info.blockstack.bsp != info.blockstack.stack)
  777. {
  778. ieee_error (&info, (const bfd_byte *) NULL,
  779. _("blocks left on stack at end"));
  780. return FALSE;
  781. }
  782. return TRUE;
  783. }
  784. /* Handle an IEEE BB record. */
  785. static bfd_boolean
  786. parse_ieee_bb (struct ieee_info *info, const bfd_byte **pp)
  787. {
  788. const bfd_byte *block_start;
  789. bfd_byte b;
  790. bfd_vma size;
  791. const char *name;
  792. unsigned long namlen;
  793. char *namcopy = NULL;
  794. unsigned int fnindx;
  795. bfd_boolean skip;
  796. block_start = *pp;
  797. b = **pp;
  798. ++*pp;
  799. if (! ieee_read_number (info, pp, &size)
  800. || ! ieee_read_id (info, pp, &name, &namlen))
  801. return FALSE;
  802. fnindx = (unsigned int) -1;
  803. skip = FALSE;
  804. switch (b)
  805. {
  806. case 1:
  807. /* BB1: Type definitions local to a module. */
  808. namcopy = savestring (name, namlen);
  809. if (namcopy == NULL)
  810. return FALSE;
  811. if (! debug_set_filename (info->dhandle, namcopy))
  812. return FALSE;
  813. info->saw_filename = TRUE;
  814. /* Discard any variables or types we may have seen before. */
  815. if (info->vars.vars != NULL)
  816. free (info->vars.vars);
  817. info->vars.vars = NULL;
  818. info->vars.alloc = 0;
  819. if (info->types.types != NULL)
  820. free (info->types.types);
  821. info->types.types = NULL;
  822. info->types.alloc = 0;
  823. /* Initialize the types to the global types. */
  824. if (info->global_types != NULL)
  825. {
  826. info->types.alloc = info->global_types->alloc;
  827. info->types.types = ((struct ieee_type *)
  828. xmalloc (info->types.alloc
  829. * sizeof (*info->types.types)));
  830. memcpy (info->types.types, info->global_types->types,
  831. info->types.alloc * sizeof (*info->types.types));
  832. }
  833. break;
  834. case 2:
  835. /* BB2: Global type definitions. The name is supposed to be
  836. empty, but we don't check. */
  837. if (! debug_set_filename (info->dhandle, "*global*"))
  838. return FALSE;
  839. info->saw_filename = TRUE;
  840. break;
  841. case 3:
  842. /* BB3: High level module block begin. We don't have to do
  843. anything here. The name is supposed to be the same as for
  844. the BB1, but we don't check. */
  845. break;
  846. case 4:
  847. /* BB4: Global function. */
  848. {
  849. bfd_vma stackspace, typindx, offset;
  850. debug_type return_type;
  851. if (! ieee_read_number (info, pp, &stackspace)
  852. || ! ieee_read_number (info, pp, &typindx)
  853. || ! ieee_read_expression (info, pp, &offset))
  854. return FALSE;
  855. /* We have no way to record the stack space. FIXME. */
  856. if (typindx < 256)
  857. {
  858. return_type = ieee_builtin_type (info, block_start, typindx);
  859. if (return_type == DEBUG_TYPE_NULL)
  860. return FALSE;
  861. }
  862. else
  863. {
  864. typindx -= 256;
  865. if (! ieee_alloc_type (info, typindx, TRUE))
  866. return FALSE;
  867. fnindx = typindx;
  868. return_type = info->types.types[typindx].type;
  869. if (debug_get_type_kind (info->dhandle, return_type)
  870. == DEBUG_KIND_FUNCTION)
  871. return_type = debug_get_return_type (info->dhandle,
  872. return_type);
  873. }
  874. namcopy = savestring (name, namlen);
  875. if (namcopy == NULL)
  876. return FALSE;
  877. if (! debug_record_function (info->dhandle, namcopy, return_type,
  878. TRUE, offset))
  879. return FALSE;
  880. }
  881. break;
  882. case 5:
  883. /* BB5: File name for source line numbers. */
  884. {
  885. unsigned int i;
  886. /* We ignore the date and time. FIXME. */
  887. for (i = 0; i < 6; i++)
  888. {
  889. bfd_vma ignore;
  890. bfd_boolean present;
  891. if (! ieee_read_optional_number (info, pp, &ignore, &present))
  892. return FALSE;
  893. if (! present)
  894. break;
  895. }
  896. if (! info->saw_filename)
  897. {
  898. namcopy = savestring (name, namlen);
  899. if (namcopy == NULL)
  900. return FALSE;
  901. if (! debug_set_filename (info->dhandle, namcopy))
  902. return FALSE;
  903. info->saw_filename = TRUE;
  904. }
  905. namcopy = savestring (name, namlen);
  906. if (namcopy == NULL)
  907. return FALSE;
  908. if (! debug_start_source (info->dhandle, namcopy))
  909. return FALSE;
  910. }
  911. break;
  912. case 6:
  913. /* BB6: Local function or block. */
  914. {
  915. bfd_vma stackspace, typindx, offset;
  916. if (! ieee_read_number (info, pp, &stackspace)
  917. || ! ieee_read_number (info, pp, &typindx)
  918. || ! ieee_read_expression (info, pp, &offset))
  919. return FALSE;
  920. /* We have no way to record the stack space. FIXME. */
  921. if (namlen == 0)
  922. {
  923. if (! debug_start_block (info->dhandle, offset))
  924. return FALSE;
  925. /* Change b to indicate that this is a block
  926. rather than a function. */
  927. b = 0x86;
  928. }
  929. else
  930. {
  931. /* The MRI C++ compiler will output a fake function named
  932. __XRYCPP to hold C++ debugging information. We skip
  933. that function. This is not crucial, but it makes
  934. converting from IEEE to other debug formats work
  935. better. */
  936. if (strncmp (name, "__XRYCPP", namlen) == 0)
  937. skip = TRUE;
  938. else
  939. {
  940. debug_type return_type;
  941. if (typindx < 256)
  942. {
  943. return_type = ieee_builtin_type (info, block_start,
  944. typindx);
  945. if (return_type == NULL)
  946. return FALSE;
  947. }
  948. else
  949. {
  950. typindx -= 256;
  951. if (! ieee_alloc_type (info, typindx, TRUE))
  952. return FALSE;
  953. fnindx = typindx;
  954. return_type = info->types.types[typindx].type;
  955. if (debug_get_type_kind (info->dhandle, return_type)
  956. == DEBUG_KIND_FUNCTION)
  957. return_type = debug_get_return_type (info->dhandle,
  958. return_type);
  959. }
  960. namcopy = savestring (name, namlen);
  961. if (namcopy == NULL)
  962. return FALSE;
  963. if (! debug_record_function (info->dhandle, namcopy,
  964. return_type, FALSE, offset))
  965. return FALSE;
  966. }
  967. }
  968. }
  969. break;
  970. case 10:
  971. /* BB10: Assembler module scope. In the normal case, we
  972. completely ignore all this information. FIXME. */
  973. {
  974. const char *inam, *vstr;
  975. unsigned long inamlen, vstrlen;
  976. bfd_vma tool_type;
  977. bfd_boolean present;
  978. unsigned int i;
  979. if (! info->saw_filename)
  980. {
  981. namcopy = savestring (name, namlen);
  982. if (namcopy == NULL)
  983. return FALSE;
  984. if (! debug_set_filename (info->dhandle, namcopy))
  985. return FALSE;
  986. info->saw_filename = TRUE;
  987. }
  988. if (! ieee_read_id (info, pp, &inam, &inamlen)
  989. || ! ieee_read_number (info, pp, &tool_type)
  990. || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
  991. return FALSE;
  992. for (i = 0; i < 6; i++)
  993. {
  994. bfd_vma ignore;
  995. if (! ieee_read_optional_number (info, pp, &ignore, &present))
  996. return FALSE;
  997. if (! present)
  998. break;
  999. }
  1000. }
  1001. break;
  1002. case 11:
  1003. /* BB11: Module section. We completely ignore all this
  1004. information. FIXME. */
  1005. {
  1006. bfd_vma sectype, secindx, offset, map;
  1007. bfd_boolean present;
  1008. if (! ieee_read_number (info, pp, &sectype)
  1009. || ! ieee_read_number (info, pp, &secindx)
  1010. || ! ieee_read_expression (info, pp, &offset)
  1011. || ! ieee_read_optional_number (info, pp, &map, &present))
  1012. return FALSE;
  1013. }
  1014. break;
  1015. default:
  1016. ieee_error (info, block_start, _("unknown BB type"));
  1017. return FALSE;
  1018. }
  1019. /* Push this block on the block stack. */
  1020. if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
  1021. {
  1022. ieee_error (info, (const bfd_byte *) NULL, _("stack overflow"));
  1023. return FALSE;
  1024. }
  1025. info->blockstack.bsp->kind = b;
  1026. if (b == 5)
  1027. info->blockstack.bsp->filename = namcopy;
  1028. info->blockstack.bsp->fnindx = fnindx;
  1029. info->blockstack.bsp->skip = skip;
  1030. ++info->blockstack.bsp;
  1031. return TRUE;
  1032. }
  1033. /* Handle an IEEE BE record. */
  1034. static bfd_boolean
  1035. parse_ieee_be (struct ieee_info *info, const bfd_byte **pp)
  1036. {
  1037. bfd_vma offset;
  1038. if (info->blockstack.bsp <= info->blockstack.stack)
  1039. {
  1040. ieee_error (info, *pp, _("stack underflow"));
  1041. return FALSE;
  1042. }
  1043. --info->blockstack.bsp;
  1044. switch (info->blockstack.bsp->kind)
  1045. {
  1046. case 2:
  1047. /* When we end the global typedefs block, we copy out the
  1048. contents of info->vars. This is because the variable indices
  1049. may be reused in the local blocks. However, we need to
  1050. preserve them so that we can locate a function returning a
  1051. reference variable whose type is named in the global typedef
  1052. block. */
  1053. info->global_vars = ((struct ieee_vars *)
  1054. xmalloc (sizeof *info->global_vars));
  1055. info->global_vars->alloc = info->vars.alloc;
  1056. info->global_vars->vars = ((struct ieee_var *)
  1057. xmalloc (info->vars.alloc
  1058. * sizeof (*info->vars.vars)));
  1059. memcpy (info->global_vars->vars, info->vars.vars,
  1060. info->vars.alloc * sizeof (*info->vars.vars));
  1061. /* We also copy out the non builtin parts of info->types, since
  1062. the types are discarded when we start a new block. */
  1063. info->global_types = ((struct ieee_types *)
  1064. xmalloc (sizeof *info->global_types));
  1065. info->global_types->alloc = info->types.alloc;
  1066. info->global_types->types = ((struct ieee_type *)
  1067. xmalloc (info->types.alloc
  1068. * sizeof (*info->types.types)));
  1069. memcpy (info->global_types->types, info->types.types,
  1070. info->types.alloc * sizeof (*info->types.types));
  1071. memset (info->global_types->builtins, 0,
  1072. sizeof (info->global_types->builtins));
  1073. break;
  1074. case 4:
  1075. case 6:
  1076. if (! ieee_read_expression (info, pp, &offset))
  1077. return FALSE;
  1078. if (! info->blockstack.bsp->skip)
  1079. {
  1080. if (! debug_end_function (info->dhandle, offset + 1))
  1081. return FALSE;
  1082. }
  1083. break;
  1084. case 0x86:
  1085. /* This is BE6 when BB6 started a block rather than a local
  1086. function. */
  1087. if (! ieee_read_expression (info, pp, &offset))
  1088. return FALSE;
  1089. if (! debug_end_block (info->dhandle, offset + 1))
  1090. return FALSE;
  1091. break;
  1092. case 5:
  1093. /* When we end a BB5, we look up the stack for the last BB5, if
  1094. there is one, so that we can call debug_start_source. */
  1095. if (info->blockstack.bsp > info->blockstack.stack)
  1096. {
  1097. struct ieee_block *bl;
  1098. bl = info->blockstack.bsp;
  1099. do
  1100. {
  1101. --bl;
  1102. if (bl->kind == 5)
  1103. {
  1104. if (! debug_start_source (info->dhandle, bl->filename))
  1105. return FALSE;
  1106. break;
  1107. }
  1108. }
  1109. while (bl != info->blockstack.stack);
  1110. }
  1111. break;
  1112. case 11:
  1113. if (! ieee_read_expression (info, pp, &offset))
  1114. return FALSE;
  1115. /* We just ignore the module size. FIXME. */
  1116. break;
  1117. default:
  1118. /* Other block types do not have any trailing information. */
  1119. break;
  1120. }
  1121. return TRUE;
  1122. }
  1123. /* Parse an NN record. */
  1124. static bfd_boolean
  1125. parse_ieee_nn (struct ieee_info *info, const bfd_byte **pp)
  1126. {
  1127. const bfd_byte *nn_start;
  1128. bfd_vma varindx;
  1129. const char *name;
  1130. unsigned long namlen;
  1131. nn_start = *pp;
  1132. if (! ieee_read_number (info, pp, &varindx)
  1133. || ! ieee_read_id (info, pp, &name, &namlen))
  1134. return FALSE;
  1135. if (varindx < 32)
  1136. {
  1137. ieee_error (info, nn_start, _("illegal variable index"));
  1138. return FALSE;
  1139. }
  1140. varindx -= 32;
  1141. if (varindx >= info->vars.alloc)
  1142. {
  1143. unsigned int alloc;
  1144. alloc = info->vars.alloc;
  1145. if (alloc == 0)
  1146. alloc = 4;
  1147. while (varindx >= alloc)
  1148. alloc *= 2;
  1149. info->vars.vars = ((struct ieee_var *)
  1150. xrealloc (info->vars.vars,
  1151. alloc * sizeof *info->vars.vars));
  1152. memset (info->vars.vars + info->vars.alloc, 0,
  1153. (alloc - info->vars.alloc) * sizeof *info->vars.vars);
  1154. info->vars.alloc = alloc;
  1155. }
  1156. info->vars.vars[varindx].name = name;
  1157. info->vars.vars[varindx].namlen = namlen;
  1158. return TRUE;
  1159. }
  1160. /* Parse a TY record. */
  1161. static bfd_boolean
  1162. parse_ieee_ty (struct ieee_info *info, const bfd_byte **pp)
  1163. {
  1164. const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
  1165. bfd_vma typeindx, varindx, tc;
  1166. void *dhandle;
  1167. bfd_boolean tag, typdef;
  1168. debug_type *arg_slots;
  1169. unsigned long type_bitsize;
  1170. debug_type type;
  1171. ty_start = *pp;
  1172. if (! ieee_read_number (info, pp, &typeindx))
  1173. return FALSE;
  1174. if (typeindx < 256)
  1175. {
  1176. ieee_error (info, ty_start, _("illegal type index"));
  1177. return FALSE;
  1178. }
  1179. typeindx -= 256;
  1180. if (! ieee_alloc_type (info, typeindx, FALSE))
  1181. return FALSE;
  1182. if (**pp != 0xce)
  1183. {
  1184. ieee_error (info, *pp, _("unknown TY code"));
  1185. return FALSE;
  1186. }
  1187. ++*pp;
  1188. ty_var_start = *pp;
  1189. if (! ieee_read_number (info, pp, &varindx))
  1190. return FALSE;
  1191. if (varindx < 32)
  1192. {
  1193. ieee_error (info, ty_var_start, _("illegal variable index"));
  1194. return FALSE;
  1195. }
  1196. varindx -= 32;
  1197. if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
  1198. {
  1199. ieee_error (info, ty_var_start, _("undefined variable in TY"));
  1200. return FALSE;
  1201. }
  1202. ty_code_start = *pp;
  1203. if (! ieee_read_number (info, pp, &tc))
  1204. return FALSE;
  1205. dhandle = info->dhandle;
  1206. tag = FALSE;
  1207. typdef = FALSE;
  1208. arg_slots = NULL;
  1209. type_bitsize = 0;
  1210. switch (tc)
  1211. {
  1212. default:
  1213. ieee_error (info, ty_code_start, _("unknown TY code"));
  1214. return FALSE;
  1215. case '!':
  1216. /* Unknown type, with size. We treat it as int. FIXME. */
  1217. {
  1218. bfd_vma size;
  1219. if (! ieee_read_number (info, pp, &size))
  1220. return FALSE;
  1221. type = debug_make_int_type (dhandle, size, FALSE);
  1222. }
  1223. break;
  1224. case 'A': /* Array. */
  1225. case 'a': /* FORTRAN array in column/row order. FIXME: Not
  1226. distinguished from normal array. */
  1227. {
  1228. debug_type ele_type;
  1229. bfd_vma lower, upper;
  1230. if (! ieee_read_type_index (info, pp, &ele_type)
  1231. || ! ieee_read_number (info, pp, &lower)
  1232. || ! ieee_read_number (info, pp, &upper))
  1233. return FALSE;
  1234. type = debug_make_array_type (dhandle, ele_type,
  1235. ieee_builtin_type (info, ty_code_start,
  1236. ((unsigned int)
  1237. builtin_int)),
  1238. (bfd_signed_vma) lower,
  1239. (bfd_signed_vma) upper,
  1240. FALSE);
  1241. }
  1242. break;
  1243. case 'E':
  1244. /* Simple enumeration. */
  1245. {
  1246. bfd_vma size;
  1247. unsigned int alloc;
  1248. const char **names;
  1249. unsigned int c;
  1250. bfd_signed_vma *vals;
  1251. unsigned int i;
  1252. if (! ieee_read_number (info, pp, &size))
  1253. return FALSE;
  1254. /* FIXME: we ignore the enumeration size. */
  1255. alloc = 10;
  1256. names = (const char **) xmalloc (alloc * sizeof *names);
  1257. memset (names, 0, alloc * sizeof *names);
  1258. c = 0;
  1259. while (1)
  1260. {
  1261. const char *name;
  1262. unsigned long namlen;
  1263. bfd_boolean present;
  1264. if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
  1265. return FALSE;
  1266. if (! present)
  1267. break;
  1268. if (c + 1 >= alloc)
  1269. {
  1270. alloc += 10;
  1271. names = ((const char **)
  1272. xrealloc (names, alloc * sizeof *names));
  1273. }
  1274. names[c] = savestring (name, namlen);
  1275. if (names[c] == NULL)
  1276. return FALSE;
  1277. ++c;
  1278. }
  1279. names[c] = NULL;
  1280. vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
  1281. for (i = 0; i < c; i++)
  1282. vals[i] = i;
  1283. type = debug_make_enum_type (dhandle, names, vals);
  1284. tag = TRUE;
  1285. }
  1286. break;
  1287. case 'G':
  1288. /* Struct with bit fields. */
  1289. {
  1290. bfd_vma size;
  1291. unsigned int alloc;
  1292. debug_field *fields;
  1293. unsigned int c;
  1294. if (! ieee_read_number (info, pp, &size))
  1295. return FALSE;
  1296. alloc = 10;
  1297. fields = (debug_field *) xmalloc (alloc * sizeof *fields);
  1298. c = 0;
  1299. while (1)
  1300. {
  1301. const char *name;
  1302. unsigned long namlen;
  1303. bfd_boolean present;
  1304. debug_type ftype;
  1305. bfd_vma bitpos, bitsize;
  1306. if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
  1307. return FALSE;
  1308. if (! present)
  1309. break;
  1310. if (! ieee_read_type_index (info, pp, &ftype)
  1311. || ! ieee_read_number (info, pp, &bitpos)
  1312. || ! ieee_read_number (info, pp, &bitsize))
  1313. return FALSE;
  1314. if (c + 1 >= alloc)
  1315. {
  1316. alloc += 10;
  1317. fields = ((debug_field *)
  1318. xrealloc (fields, alloc * sizeof *fields));
  1319. }
  1320. fields[c] = debug_make_field (dhandle, savestring (name, namlen),
  1321. ftype, bitpos, bitsize,
  1322. DEBUG_VISIBILITY_PUBLIC);
  1323. if (fields[c] == NULL)
  1324. return FALSE;
  1325. ++c;
  1326. }
  1327. fields[c] = NULL;
  1328. type = debug_make_struct_type (dhandle, TRUE, size, fields);
  1329. tag = TRUE;
  1330. }
  1331. break;
  1332. case 'N':
  1333. /* Enumeration. */
  1334. {
  1335. unsigned int alloc;
  1336. const char **names;
  1337. bfd_signed_vma *vals;
  1338. unsigned int c;
  1339. alloc = 10;
  1340. names = (const char **) xmalloc (alloc * sizeof *names);
  1341. vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
  1342. c = 0;
  1343. while (1)
  1344. {
  1345. const char *name;
  1346. unsigned long namlen;
  1347. bfd_boolean present;
  1348. bfd_vma val;
  1349. if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
  1350. return FALSE;
  1351. if (! present)
  1352. break;
  1353. if (! ieee_read_number (info, pp, &val))
  1354. return FALSE;
  1355. /* If the length of the name is zero, then the value is
  1356. actually the size of the enum. We ignore this
  1357. information. FIXME. */
  1358. if (namlen == 0)
  1359. continue;
  1360. if (c + 1 >= alloc)
  1361. {
  1362. alloc += 10;
  1363. names = ((const char **)
  1364. xrealloc (names, alloc * sizeof *names));
  1365. vals = ((bfd_signed_vma *)
  1366. xrealloc (vals, alloc * sizeof *vals));
  1367. }
  1368. names[c] = savestring (name, namlen);
  1369. if (names[c] == NULL)
  1370. return FALSE;
  1371. vals[c] = (bfd_signed_vma) val;
  1372. ++c;
  1373. }
  1374. names[c] = NULL;
  1375. type = debug_make_enum_type (dhandle, names, vals);
  1376. tag = TRUE;
  1377. }
  1378. break;
  1379. case 'O': /* Small pointer. We don't distinguish small and large
  1380. pointers. FIXME. */
  1381. case 'P': /* Large pointer. */
  1382. {
  1383. debug_type t;
  1384. if (! ieee_read_type_index (info, pp, &t))
  1385. return FALSE;
  1386. type = debug_make_pointer_type (dhandle, t);
  1387. }
  1388. break;
  1389. case 'R':
  1390. /* Range. */
  1391. {
  1392. bfd_vma low, high, signedp, size;
  1393. if (! ieee_read_number (info, pp, &low)
  1394. || ! ieee_read_number (info, pp, &high)
  1395. || ! ieee_read_number (info, pp, &signedp)
  1396. || ! ieee_read_number (info, pp, &size))
  1397. return FALSE;
  1398. type = debug_make_range_type (dhandle,
  1399. debug_make_int_type (dhandle, size,
  1400. ! signedp),
  1401. (bfd_signed_vma) low,
  1402. (bfd_signed_vma) high);
  1403. }
  1404. break;
  1405. case 'S': /* Struct. */
  1406. case 'U': /* Union. */
  1407. {
  1408. bfd_vma size;
  1409. unsigned int alloc;
  1410. debug_field *fields;
  1411. unsigned int c;
  1412. if (! ieee_read_number (info, pp, &size))
  1413. return FALSE;
  1414. alloc = 10;
  1415. fields = (debug_field *) xmalloc (alloc * sizeof *fields);
  1416. c = 0;
  1417. while (1)
  1418. {
  1419. const char *name;
  1420. unsigned long namlen;
  1421. bfd_boolean present;
  1422. bfd_vma tindx;
  1423. bfd_vma offset;
  1424. debug_type ftype;
  1425. bfd_vma bitsize;
  1426. if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
  1427. return FALSE;
  1428. if (! present)
  1429. break;
  1430. if (! ieee_read_number (info, pp, &tindx)
  1431. || ! ieee_read_number (info, pp, &offset))
  1432. return FALSE;
  1433. if (tindx < 256)
  1434. {
  1435. ftype = ieee_builtin_type (info, ty_code_start, tindx);
  1436. bitsize = 0;
  1437. offset *= 8;
  1438. }
  1439. else
  1440. {
  1441. struct ieee_type *t;
  1442. tindx -= 256;
  1443. if (! ieee_alloc_type (info, tindx, TRUE))
  1444. return FALSE;
  1445. t = info->types.types + tindx;
  1446. ftype = t->type;
  1447. bitsize = t->bitsize;
  1448. if (bitsize == 0)
  1449. offset *= 8;
  1450. }
  1451. if (c + 1 >= alloc)
  1452. {
  1453. alloc += 10;
  1454. fields = ((debug_field *)
  1455. xrealloc (fields, alloc * sizeof *fields));
  1456. }
  1457. fields[c] = debug_make_field (dhandle, savestring (name, namlen),
  1458. ftype, offset, bitsize,
  1459. DEBUG_VISIBILITY_PUBLIC);
  1460. if (fields[c] == NULL)
  1461. return FALSE;
  1462. ++c;
  1463. }
  1464. fields[c] = NULL;
  1465. type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
  1466. tag = TRUE;
  1467. }
  1468. break;
  1469. case 'T':
  1470. /* Typedef. */
  1471. if (! ieee_read_type_index (info, pp, &type))
  1472. return FALSE;
  1473. typdef = TRUE;
  1474. break;
  1475. case 'X':
  1476. /* Procedure. FIXME: This is an extern declaration, which we
  1477. have no way of representing. */
  1478. {
  1479. bfd_vma attr;
  1480. debug_type rtype;
  1481. bfd_vma nargs;
  1482. bfd_boolean present;
  1483. struct ieee_var *pv;
  1484. /* FIXME: We ignore the attribute and the argument names. */
  1485. if (! ieee_read_number (info, pp, &attr)
  1486. || ! ieee_read_type_index (info, pp, &rtype)
  1487. || ! ieee_read_number (info, pp, &nargs))
  1488. return FALSE;
  1489. do
  1490. {
  1491. const char *name;
  1492. unsigned long namlen;
  1493. if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
  1494. return FALSE;
  1495. }
  1496. while (present);
  1497. pv = info->vars.vars + varindx;
  1498. pv->kind = IEEE_EXTERNAL;
  1499. if (pv->namlen > 0
  1500. && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
  1501. {
  1502. /* Set up the return type as an indirect type pointing to
  1503. the variable slot, so that we can change it to a
  1504. reference later if appropriate. */
  1505. pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
  1506. *pv->pslot = rtype;
  1507. rtype = debug_make_indirect_type (dhandle, pv->pslot,
  1508. (const char *) NULL);
  1509. }
  1510. type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
  1511. FALSE);
  1512. }
  1513. break;
  1514. case 'V':
  1515. case 'v':
  1516. /* Void. This is not documented, but the MRI compiler emits it. */
  1517. type = debug_make_void_type (dhandle);
  1518. break;
  1519. case 'Z':
  1520. /* Array with 0 lower bound. */
  1521. {
  1522. debug_type etype;
  1523. bfd_vma high;
  1524. if (! ieee_read_type_index (info, pp, &etype)
  1525. || ! ieee_read_number (info, pp, &high))
  1526. return FALSE;
  1527. type = debug_make_array_type (dhandle, etype,
  1528. ieee_builtin_type (info, ty_code_start,
  1529. ((unsigned int)
  1530. builtin_int)),
  1531. 0, (bfd_signed_vma) high, FALSE);
  1532. }
  1533. break;
  1534. case 'c': /* Complex. */
  1535. case 'd': /* Double complex. */
  1536. {
  1537. const char *name;
  1538. unsigned long namlen;
  1539. /* FIXME: I don't know what the name means. */
  1540. if (! ieee_read_id (info, pp, &name, &namlen))
  1541. return FALSE;
  1542. type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
  1543. }
  1544. break;
  1545. case 'f':
  1546. /* Pascal file name. FIXME. */
  1547. ieee_error (info, ty_code_start, _("Pascal file name not supported"));
  1548. return FALSE;
  1549. case 'g':
  1550. /* Bitfield type. */
  1551. {
  1552. bfd_vma signedp, bitsize, dummy;
  1553. const bfd_byte *hold;
  1554. bfd_boolean present;
  1555. if (! ieee_read_number (info, pp, &signedp)
  1556. || ! ieee_read_number (info, pp, &bitsize))
  1557. return FALSE;
  1558. /* I think the documentation says that there is a type index,
  1559. but some actual files do not have one. */
  1560. hold = *pp;
  1561. if (! ieee_read_optional_number (info, pp, &dummy, &present))
  1562. return FALSE;
  1563. if (! present)
  1564. {
  1565. /* FIXME: This is just a guess. */
  1566. type = debug_make_int_type (dhandle, 4,
  1567. signedp ? FALSE : TRUE);
  1568. }
  1569. else
  1570. {
  1571. *pp = hold;
  1572. if (! ieee_read_type_index (info, pp, &type))
  1573. return FALSE;
  1574. }
  1575. type_bitsize = bitsize;
  1576. }
  1577. break;
  1578. case 'n':
  1579. /* Qualifier. */
  1580. {
  1581. bfd_vma kind;
  1582. debug_type t;
  1583. if (! ieee_read_number (info, pp, &kind)
  1584. || ! ieee_read_type_index (info, pp, &t))
  1585. return FALSE;
  1586. switch (kind)
  1587. {
  1588. default:
  1589. ieee_error (info, ty_start, _("unsupported qualifier"));
  1590. return FALSE;
  1591. case 1:
  1592. type = debug_make_const_type (dhandle, t);
  1593. break;
  1594. case 2:
  1595. type = debug_make_volatile_type (dhandle, t);
  1596. break;
  1597. }
  1598. }
  1599. break;
  1600. case 's':
  1601. /* Set. */
  1602. {
  1603. bfd_vma size;
  1604. debug_type etype;
  1605. if (! ieee_read_number (info, pp, &size)
  1606. || ! ieee_read_type_index (info, pp, &etype))
  1607. return FALSE;
  1608. /* FIXME: We ignore the size. */
  1609. type = debug_make_set_type (dhandle, etype, FALSE);
  1610. }
  1611. break;
  1612. case 'x':
  1613. /* Procedure with compiler dependencies. */
  1614. {
  1615. struct ieee_var *pv;
  1616. bfd_vma attr, frame_type, push_mask, nargs, level, father;
  1617. debug_type rtype;
  1618. debug_type *arg_types;
  1619. bfd_boolean varargs;
  1620. bfd_boolean present;
  1621. /* FIXME: We ignore some of this information. */
  1622. pv = info->vars.vars + varindx;
  1623. if (! ieee_read_number (info, pp, &attr)
  1624. || ! ieee_read_number (info, pp, &frame_type)
  1625. || ! ieee_read_number (info, pp, &push_mask)
  1626. || ! ieee_read_type_index (info, pp, &rtype)
  1627. || ! ieee_read_number (info, pp, &nargs))
  1628. return FALSE;
  1629. if (nargs == (bfd_vma) -1)
  1630. {
  1631. arg_types = NULL;
  1632. varargs = FALSE;
  1633. }
  1634. else
  1635. {
  1636. unsigned int i;
  1637. arg_types = ((debug_type *)
  1638. xmalloc ((nargs + 1) * sizeof *arg_types));
  1639. for (i = 0; i < nargs; i++)
  1640. if (! ieee_read_type_index (info, pp, arg_types + i))
  1641. return FALSE;
  1642. /* If the last type is pointer to void, this is really a
  1643. varargs function. */
  1644. varargs = FALSE;
  1645. if (nargs > 0)
  1646. {
  1647. debug_type last;
  1648. last = arg_types[nargs - 1];
  1649. if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
  1650. && (debug_get_type_kind (dhandle,
  1651. debug_get_target_type (dhandle,
  1652. last))
  1653. == DEBUG_KIND_VOID))
  1654. {
  1655. --nargs;
  1656. varargs = TRUE;
  1657. }
  1658. }
  1659. /* If there are any pointer arguments, turn them into
  1660. indirect types in case we later need to convert them to
  1661. reference types. */
  1662. for (i = 0; i < nargs; i++)
  1663. {
  1664. if (debug_get_type_kind (dhandle, arg_types[i])
  1665. == DEBUG_KIND_POINTER)
  1666. {
  1667. if (arg_slots == NULL)
  1668. {
  1669. arg_slots = ((debug_type *)
  1670. xmalloc (nargs * sizeof *arg_slots));
  1671. memset (arg_slots, 0, nargs * sizeof *arg_slots);
  1672. }
  1673. arg_slots[i] = arg_types[i];
  1674. arg_types[i] =
  1675. debug_make_indirect_type (dhandle,
  1676. arg_slots + i,
  1677. (const char *) NULL);
  1678. }
  1679. }
  1680. arg_types[nargs] = DEBUG_TYPE_NULL;
  1681. }
  1682. if (! ieee_read_number (info, pp, &level)
  1683. || ! ieee_read_optional_number (info, pp, &father, &present))
  1684. return FALSE;
  1685. /* We can't distinguish between a global function and a static
  1686. function. */
  1687. pv->kind = IEEE_FUNCTION;
  1688. if (pv->namlen > 0
  1689. && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
  1690. {
  1691. /* Set up the return type as an indirect type pointing to
  1692. the variable slot, so that we can change it to a
  1693. reference later if appropriate. */
  1694. pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
  1695. *pv->pslot = rtype;
  1696. rtype = debug_make_indirect_type (dhandle, pv->pslot,
  1697. (const char *) NULL);
  1698. }
  1699. type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
  1700. }
  1701. break;
  1702. }
  1703. /* Record the type in the table. */
  1704. if (type == DEBUG_TYPE_NULL)
  1705. return FALSE;
  1706. info->vars.vars[varindx].type = type;
  1707. if ((tag || typdef)
  1708. && info->vars.vars[varindx].namlen > 0)
  1709. {
  1710. const char *name;
  1711. name = savestring (info->vars.vars[varindx].name,
  1712. info->vars.vars[varindx].namlen);
  1713. if (typdef)
  1714. type = debug_name_type (dhandle, name, type);
  1715. else if (tc == 'E' || tc == 'N')
  1716. type = debug_tag_type (dhandle, name, type);
  1717. else
  1718. {
  1719. struct ieee_tag *it;
  1720. /* We must allocate all struct tags as indirect types, so
  1721. that if we later see a definition of the tag as a C++
  1722. record we can update the indirect slot and automatically
  1723. change all the existing references. */
  1724. it = (struct ieee_tag *) xmalloc (sizeof *it);
  1725. memset (it, 0, sizeof *it);
  1726. it->next = info->tags;
  1727. info->tags = it;
  1728. it->name = name;
  1729. it->slot = type;
  1730. type = debug_make_indirect_type (dhandle, &it->slot, name);
  1731. type = debug_tag_type (dhandle, name, type);
  1732. it->type = type;
  1733. }
  1734. if (type == NULL)
  1735. return FALSE;
  1736. }
  1737. info->types.types[typeindx].type = type;
  1738. info->types.types[typeindx].arg_slots = arg_slots;
  1739. info->types.types[typeindx].bitsize = type_bitsize;
  1740. /* We may have already allocated type as an indirect type pointing
  1741. to slot. It does no harm to replace the indirect type with the
  1742. real type. Filling in slot as well handles the indirect types
  1743. which are already hanging around. */
  1744. if (info->types.types[typeindx].pslot != NULL)
  1745. *info->types.types[typeindx].pslot = type;
  1746. return TRUE;
  1747. }
  1748. /* Parse an ATN record. */
  1749. static bfd_boolean
  1750. parse_ieee_atn (struct ieee_info *info, const bfd_byte **pp)
  1751. {
  1752. const bfd_byte *atn_start, *atn_code_start;
  1753. bfd_vma varindx;
  1754. struct ieee_var *pvar;
  1755. debug_type type;
  1756. bfd_vma atn_code;
  1757. void *dhandle;
  1758. bfd_vma v, v2, v3, v4, v5;
  1759. const char *name;
  1760. unsigned long namlen;
  1761. char *namcopy;
  1762. bfd_boolean present;
  1763. int blocktype;
  1764. atn_start = *pp;
  1765. if (! ieee_read_number (info, pp, &varindx)
  1766. || ! ieee_read_type_index (info, pp, &type))
  1767. return FALSE;
  1768. atn_code_start = *pp;
  1769. if (! ieee_read_number (info, pp, &atn_code))
  1770. return FALSE;
  1771. if (varindx == 0)
  1772. {
  1773. pvar = NULL;
  1774. name = "";
  1775. namlen = 0;
  1776. }
  1777. else if (varindx < 32)
  1778. {
  1779. /* The MRI compiler reportedly sometimes emits variable lifetime
  1780. information for a register. We just ignore it. */
  1781. if (atn_code == 9)
  1782. return ieee_read_number (info, pp, &v);
  1783. ieee_error (info, atn_start, _("illegal variable index"));
  1784. return FALSE;
  1785. }
  1786. else
  1787. {
  1788. varindx -= 32;
  1789. if (varindx >= info->vars.alloc
  1790. || info->vars.vars[varindx].name == NULL)
  1791. {
  1792. /* The MRI compiler or linker sometimes omits the NN record
  1793. for a pmisc record. */
  1794. if (atn_code == 62)
  1795. {
  1796. if (varindx >= info->vars.alloc)
  1797. {
  1798. unsigned int alloc;
  1799. alloc = info->vars.alloc;
  1800. if (alloc == 0)
  1801. alloc = 4;
  1802. while (varindx >= alloc)
  1803. alloc *= 2;
  1804. info->vars.vars = ((struct ieee_var *)
  1805. xrealloc (info->vars.vars,
  1806. (alloc
  1807. * sizeof *info->vars.vars)));
  1808. memset (info->vars.vars + info->vars.alloc, 0,
  1809. ((alloc - info->vars.alloc)
  1810. * sizeof *info->vars.vars));
  1811. info->vars.alloc = alloc;
  1812. }
  1813. pvar = info->vars.vars + varindx;
  1814. pvar->name = "";
  1815. pvar->namlen = 0;
  1816. }
  1817. else
  1818. {
  1819. ieee_error (info, atn_start, _("undefined variable in ATN"));
  1820. return FALSE;
  1821. }
  1822. }
  1823. pvar = info->vars.vars + varindx;
  1824. pvar->type = type;
  1825. name = pvar->name;
  1826. namlen = pvar->namlen;
  1827. }
  1828. dhandle = info->dhandle;
  1829. /* If we are going to call debug_record_variable with a pointer
  1830. type, change the type to an indirect type so that we can later
  1831. change it to a reference type if we encounter a C++ pmisc 'R'
  1832. record. */
  1833. if (pvar != NULL
  1834. && type != DEBUG_TYPE_NULL
  1835. && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
  1836. {
  1837. switch (atn_code)
  1838. {
  1839. case 1:
  1840. case 2:
  1841. case 3:
  1842. case 5:
  1843. case 8:
  1844. case 10:
  1845. pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
  1846. *pvar->pslot = type;
  1847. type = debug_make_indirect_type (dhandle, pvar->pslot,
  1848. (const char *) NULL);
  1849. pvar->type = type;
  1850. break;
  1851. }
  1852. }
  1853. switch (atn_code)
  1854. {
  1855. default:
  1856. ieee_error (info, atn_code_start, _("unknown ATN type"));
  1857. return FALSE;
  1858. case 1:
  1859. /* Automatic variable. */
  1860. if (! ieee_read_number (info, pp, &v))
  1861. return FALSE;
  1862. namcopy = savestring (name, namlen);
  1863. if (type == NULL)
  1864. type = debug_make_void_type (dhandle);
  1865. if (pvar != NULL)
  1866. pvar->kind = IEEE_LOCAL;
  1867. return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
  1868. case 2:
  1869. /* Register variable. */
  1870. if (! ieee_read_number (info, pp, &v))
  1871. return FALSE;
  1872. namcopy = savestring (name, namlen);
  1873. if (type == NULL)
  1874. type = debug_make_void_type (dhandle);
  1875. if (pvar != NULL)
  1876. pvar->kind = IEEE_LOCAL;
  1877. return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
  1878. ieee_regno_to_genreg (info->abfd, v));
  1879. case 3:
  1880. /* Static variable. */
  1881. if (! ieee_require_asn (info, pp, &v))
  1882. return FALSE;
  1883. namcopy = savestring (name, namlen);
  1884. if (type == NULL)
  1885. type = debug_make_void_type (dhandle);
  1886. if (info->blockstack.bsp <= info->blockstack.stack)
  1887. blocktype = 0;
  1888. else
  1889. blocktype = info->blockstack.bsp[-1].kind;
  1890. if (pvar != NULL)
  1891. {
  1892. if (blocktype == 4 || blocktype == 6)
  1893. pvar->kind = IEEE_LOCAL;
  1894. else
  1895. pvar->kind = IEEE_STATIC;
  1896. }
  1897. return debug_record_variable (dhandle, namcopy, type,
  1898. (blocktype == 4 || blocktype == 6
  1899. ? DEBUG_LOCAL_STATIC
  1900. : DEBUG_STATIC),
  1901. v);
  1902. case 4:
  1903. /* External function. We don't currently record these. FIXME. */
  1904. if (pvar != NULL)
  1905. pvar->kind = IEEE_EXTERNAL;
  1906. return TRUE;
  1907. case 5:
  1908. /* External variable. We don't currently record these. FIXME. */
  1909. if (pvar != NULL)
  1910. pvar->kind = IEEE_EXTERNAL;
  1911. return TRUE;
  1912. case 7:
  1913. if (! ieee_read_number (info, pp, &v)
  1914. || ! ieee_read_number (info, pp, &v2)
  1915. || ! ieee_read_optional_number (info, pp, &v3, &present))
  1916. return FALSE;
  1917. if (present)
  1918. {
  1919. if (! ieee_read_optional_number (info, pp, &v4, &present))
  1920. return FALSE;
  1921. }
  1922. /* We just ignore the two optional fields in v3 and v4, since
  1923. they are not defined. */
  1924. if (! ieee_require_asn (info, pp, &v3))
  1925. return FALSE;
  1926. /* We have no way to record the column number. FIXME. */
  1927. return debug_record_line (dhandle, v, v3);
  1928. case 8:
  1929. /* Global variable. */
  1930. if (! ieee_require_asn (info, pp, &v))
  1931. return FALSE;
  1932. namcopy = savestring (name, namlen);
  1933. if (type == NULL)
  1934. type = debug_make_void_type (dhandle);
  1935. if (pvar != NULL)
  1936. pvar->kind = IEEE_GLOBAL;
  1937. return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
  1938. case 9:
  1939. /* Variable lifetime information. */
  1940. if (! ieee_read_number (info, pp, &v))
  1941. return FALSE;
  1942. /* We have no way to record this information. FIXME. */
  1943. return TRUE;
  1944. case 10:
  1945. /* Locked register. The spec says that there are two required
  1946. fields, but at least on occasion the MRI compiler only emits
  1947. one. */
  1948. if (! ieee_read_number (info, pp, &v)
  1949. || ! ieee_read_optional_number (info, pp, &v2, &present))
  1950. return FALSE;
  1951. /* I think this means a variable that is both in a register and
  1952. a frame slot. We ignore the frame slot. FIXME. */
  1953. namcopy = savestring (name, namlen);
  1954. if (type == NULL)
  1955. type = debug_make_void_type (dhandle);
  1956. if (pvar != NULL)
  1957. pvar->kind = IEEE_LOCAL;
  1958. return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
  1959. case 11:
  1960. /* Reserved for FORTRAN common. */
  1961. ieee_error (info, atn_code_start, _("unsupported ATN11"));
  1962. /* Return TRUE to keep going. */
  1963. return TRUE;
  1964. case 12:
  1965. /* Based variable. */
  1966. v3 = 0;
  1967. v4 = 0x80;
  1968. v5 = 0;
  1969. if (! ieee_read_number (info, pp, &v)
  1970. || ! ieee_read_number (info, pp, &v2)
  1971. || ! ieee_read_optional_number (info, pp, &v3, &present))
  1972. return FALSE;
  1973. if (present)
  1974. {
  1975. if (! ieee_read_optional_number (info, pp, &v4, &present))
  1976. return FALSE;
  1977. if (present)
  1978. {
  1979. if (! ieee_read_optional_number (info, pp, &v5, &present))
  1980. return FALSE;
  1981. }
  1982. }
  1983. /* We have no way to record this information. FIXME. */
  1984. ieee_error (info, atn_code_start, _("unsupported ATN12"));
  1985. /* Return TRUE to keep going. */
  1986. return TRUE;
  1987. case 16:
  1988. /* Constant. The description of this that I have is ambiguous,
  1989. so I'm not going to try to implement it. */
  1990. if (! ieee_read_number (info, pp, &v)
  1991. || ! ieee_read_optional_number (info, pp, &v2, &present))
  1992. return FALSE;
  1993. if (present)
  1994. {
  1995. if (! ieee_read_optional_number (info, pp, &v2, &present))
  1996. return FALSE;
  1997. if (present)
  1998. {
  1999. if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
  2000. return FALSE;
  2001. }
  2002. }
  2003. if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
  2004. {
  2005. if (! ieee_require_asn (info, pp, &v3))
  2006. return FALSE;
  2007. }
  2008. return TRUE;
  2009. case 19:
  2010. /* Static variable from assembler. */
  2011. v2 = 0;
  2012. if (! ieee_read_number (info, pp, &v)
  2013. || ! ieee_read_optional_number (info, pp, &v2, &present)
  2014. || ! ieee_require_asn (info, pp, &v3))
  2015. return FALSE;
  2016. namcopy = savestring (name, namlen);
  2017. /* We don't really handle this correctly. FIXME. */
  2018. return debug_record_variable (dhandle, namcopy,
  2019. debug_make_void_type (dhandle),
  2020. v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
  2021. v3);
  2022. case 62:
  2023. /* Procedure miscellaneous information. */
  2024. case 63:
  2025. /* Variable miscellaneous information. */
  2026. case 64:
  2027. /* Module miscellaneous information. */
  2028. if (! ieee_read_number (info, pp, &v)
  2029. || ! ieee_read_number (info, pp, &v2)
  2030. || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
  2031. return FALSE;
  2032. if (atn_code == 62 && v == 80)
  2033. {
  2034. if (present)
  2035. {
  2036. ieee_error (info, atn_code_start,
  2037. _("unexpected string in C++ misc"));
  2038. return FALSE;
  2039. }
  2040. return ieee_read_cxx_misc (info, pp, v2);
  2041. }
  2042. /* We just ignore all of this stuff. FIXME. */
  2043. for (; v2 > 0; --v2)
  2044. {
  2045. switch ((ieee_record_enum_type) **pp)
  2046. {
  2047. default:
  2048. ieee_error (info, *pp, _("bad misc record"));
  2049. return FALSE;
  2050. case ieee_at_record_enum:
  2051. if (! ieee_require_atn65 (info, pp, &name, &namlen))
  2052. return FALSE;
  2053. break;
  2054. case ieee_e2_first_byte_enum:
  2055. if (! ieee_require_asn (info, pp, &v3))
  2056. return FALSE;
  2057. break;
  2058. }
  2059. }
  2060. return TRUE;
  2061. }
  2062. /*NOTREACHED*/
  2063. }
  2064. /* Handle C++ debugging miscellaneous records. This is called for
  2065. procedure miscellaneous records of type 80. */
  2066. static bfd_boolean
  2067. ieee_read_cxx_misc (struct ieee_info *info, const bfd_byte **pp,
  2068. unsigned long count)
  2069. {
  2070. const bfd_byte *start;
  2071. bfd_vma category;
  2072. start = *pp;
  2073. /* Get the category of C++ misc record. */
  2074. if (! ieee_require_asn (info, pp, &category))
  2075. return FALSE;
  2076. --count;
  2077. switch (category)
  2078. {
  2079. default:
  2080. ieee_error (info, start, _("unrecognized C++ misc record"));
  2081. return FALSE;
  2082. case 'T':
  2083. if (! ieee_read_cxx_class (info, pp, count))
  2084. return FALSE;
  2085. break;
  2086. case 'M':
  2087. {
  2088. bfd_vma flags;
  2089. const char *name;
  2090. unsigned long namlen;
  2091. /* The IEEE spec indicates that the 'M' record only has a
  2092. flags field. The MRI compiler also emits the name of the
  2093. function. */
  2094. if (! ieee_require_asn (info, pp, &flags))
  2095. return FALSE;
  2096. if (*pp < info->pend
  2097. && (ieee_record_enum_type) **pp == ieee_at_record_enum)
  2098. {
  2099. if (! ieee_require_atn65 (info, pp, &name, &namlen))
  2100. return FALSE;
  2101. }
  2102. /* This is emitted for method functions, but I don't think we
  2103. care very much. It might help if it told us useful
  2104. information like the class with which this function is
  2105. associated, but it doesn't, so it isn't helpful. */
  2106. }
  2107. break;
  2108. case 'B':
  2109. if (! ieee_read_cxx_defaults (info, pp, count))
  2110. return FALSE;
  2111. break;
  2112. case 'z':
  2113. {
  2114. const char *name, *mangled, *cxx_class;
  2115. unsigned long namlen, mangledlen, classlen;
  2116. bfd_vma control;
  2117. /* Pointer to member. */
  2118. if (! ieee_require_atn65 (info, pp, &name, &namlen)
  2119. || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
  2120. || ! ieee_require_atn65 (info, pp, &cxx_class, &classlen)
  2121. || ! ieee_require_asn (info, pp, &control))
  2122. return FALSE;
  2123. /* FIXME: We should now track down name and change its type. */
  2124. }
  2125. break;
  2126. case 'R':
  2127. if (! ieee_read_reference (info, pp))
  2128. return FALSE;
  2129. break;
  2130. }
  2131. return TRUE;
  2132. }
  2133. /* Read a C++ class definition. This is a pmisc type 80 record of
  2134. category 'T'. */
  2135. static bfd_boolean
  2136. ieee_read_cxx_class (struct ieee_info *info, const bfd_byte **pp,
  2137. unsigned long count)
  2138. {
  2139. const bfd_byte *start;
  2140. bfd_vma cxx_class;
  2141. const char *tag;
  2142. unsigned long taglen;
  2143. struct ieee_tag *it;
  2144. void *dhandle;
  2145. debug_field *fields;
  2146. unsigned int field_count, field_alloc;
  2147. debug_baseclass *baseclasses;
  2148. unsigned int baseclasses_count, baseclasses_alloc;
  2149. const debug_field *structfields;
  2150. struct ieee_method
  2151. {
  2152. const char *name;
  2153. unsigned long namlen;
  2154. debug_method_variant *variants;
  2155. unsigned count;
  2156. unsigned int alloc;
  2157. } *methods;
  2158. unsigned int methods_count, methods_alloc;
  2159. debug_type vptrbase;
  2160. bfd_boolean ownvptr;
  2161. debug_method *dmethods;
  2162. start = *pp;
  2163. if (! ieee_require_asn (info, pp, &cxx_class))
  2164. return FALSE;
  2165. --count;
  2166. if (! ieee_require_atn65 (info, pp, &tag, &taglen))
  2167. return FALSE;
  2168. --count;
  2169. /* Find the C struct with this name. */
  2170. for (it = info->tags; it != NULL; it = it->next)
  2171. if (it->name[0] == tag[0]
  2172. && strncmp (it->name, tag, taglen) == 0
  2173. && strlen (it->name) == taglen)
  2174. break;
  2175. if (it == NULL)
  2176. {
  2177. ieee_error (info, start, _("undefined C++ object"));
  2178. return FALSE;
  2179. }
  2180. dhandle = info->dhandle;
  2181. fields = NULL;
  2182. field_count = 0;
  2183. field_alloc = 0;
  2184. baseclasses = NULL;
  2185. baseclasses_count = 0;
  2186. baseclasses_alloc = 0;
  2187. methods = NULL;
  2188. methods_count = 0;
  2189. methods_alloc = 0;
  2190. vptrbase = DEBUG_TYPE_NULL;
  2191. ownvptr = FALSE;
  2192. structfields = debug_get_fields (dhandle, it->type);
  2193. while (count > 0)
  2194. {
  2195. bfd_vma id;
  2196. const bfd_byte *spec_start;
  2197. spec_start = *pp;
  2198. if (! ieee_require_asn (info, pp, &id))
  2199. return FALSE;
  2200. --count;
  2201. switch (id)
  2202. {
  2203. default:
  2204. ieee_error (info, spec_start, _("unrecognized C++ object spec"));
  2205. return FALSE;
  2206. case 'b':
  2207. {
  2208. bfd_vma flags, cinline;
  2209. const char *base, *fieldname;
  2210. unsigned long baselen, fieldlen;
  2211. char *basecopy;
  2212. debug_type basetype;
  2213. bfd_vma bitpos;
  2214. bfd_boolean virtualp;
  2215. enum debug_visibility visibility;
  2216. debug_baseclass baseclass;
  2217. /* This represents a base or friend class. */
  2218. if (! ieee_require_asn (info, pp, &flags)
  2219. || ! ieee_require_atn65 (info, pp, &base, &baselen)
  2220. || ! ieee_require_asn (info, pp, &cinline)
  2221. || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
  2222. return FALSE;
  2223. count -= 4;
  2224. /* We have no way of recording friend information, so we
  2225. just ignore it. */
  2226. if ((flags & BASEFLAGS_FRIEND) != 0)
  2227. break;
  2228. /* I assume that either all of the members of the
  2229. baseclass are included in the object, starting at the
  2230. beginning of the object, or that none of them are
  2231. included. */
  2232. if ((fieldlen == 0) == (cinline == 0))
  2233. {
  2234. ieee_error (info, start, _("unsupported C++ object type"));
  2235. return FALSE;
  2236. }
  2237. basecopy = savestring (base, baselen);
  2238. basetype = debug_find_tagged_type (dhandle, basecopy,
  2239. DEBUG_KIND_ILLEGAL);
  2240. free (basecopy);
  2241. if (basetype == DEBUG_TYPE_NULL)
  2242. {
  2243. ieee_error (info, start, _("C++ base class not defined"));
  2244. return FALSE;
  2245. }
  2246. if (fieldlen == 0)
  2247. bitpos = 0;
  2248. else
  2249. {
  2250. const debug_field *pf;
  2251. if (structfields == NULL)
  2252. {
  2253. ieee_error (info, start, _("C++ object has no fields"));
  2254. return FALSE;
  2255. }
  2256. for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
  2257. {
  2258. const char *fname;
  2259. fname = debug_get_field_name (dhandle, *pf);
  2260. if (fname == NULL)
  2261. return FALSE;
  2262. if (fname[0] == fieldname[0]
  2263. && strncmp (fname, fieldname, fieldlen) == 0
  2264. && strlen (fname) == fieldlen)
  2265. break;
  2266. }
  2267. if (*pf == DEBUG_FIELD_NULL)
  2268. {
  2269. ieee_error (info, start,
  2270. _("C++ base class not found in container"));
  2271. return FALSE;
  2272. }
  2273. bitpos = debug_get_field_bitpos (dhandle, *pf);
  2274. }
  2275. if ((flags & BASEFLAGS_VIRTUAL) != 0)
  2276. virtualp = TRUE;
  2277. else
  2278. virtualp = FALSE;
  2279. if ((flags & BASEFLAGS_PRIVATE) != 0)
  2280. visibility = DEBUG_VISIBILITY_PRIVATE;
  2281. else
  2282. visibility = DEBUG_VISIBILITY_PUBLIC;
  2283. baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
  2284. virtualp, visibility);
  2285. if (baseclass == DEBUG_BASECLASS_NULL)
  2286. return FALSE;
  2287. if (baseclasses_count + 1 >= baseclasses_alloc)
  2288. {
  2289. baseclasses_alloc += 10;
  2290. baseclasses = ((debug_baseclass *)
  2291. xrealloc (baseclasses,
  2292. (baseclasses_alloc
  2293. * sizeof *baseclasses)));
  2294. }
  2295. baseclasses[baseclasses_count] = baseclass;
  2296. ++baseclasses_count;
  2297. baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
  2298. }
  2299. break;
  2300. case 'd':
  2301. {
  2302. bfd_vma flags;
  2303. const char *fieldname, *mangledname;
  2304. unsigned long fieldlen, mangledlen;
  2305. char *fieldcopy;
  2306. bfd_boolean staticp;
  2307. debug_type ftype;
  2308. const debug_field *pf = NULL;
  2309. enum debug_visibility visibility;
  2310. debug_field field;
  2311. /* This represents a data member. */
  2312. if (! ieee_require_asn (info, pp, &flags)
  2313. || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
  2314. || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
  2315. return FALSE;
  2316. count -= 3;
  2317. fieldcopy = savestring (fieldname, fieldlen);
  2318. staticp = (flags & CXXFLAGS_STATIC) != 0 ? TRUE : FALSE;
  2319. if (staticp)
  2320. {
  2321. struct ieee_var *pv, *pvend;
  2322. /* See if we can find a definition for this variable. */
  2323. pv = info->vars.vars;
  2324. pvend = pv + info->vars.alloc;
  2325. for (; pv < pvend; pv++)
  2326. if (pv->namlen == mangledlen
  2327. && strncmp (pv->name, mangledname, mangledlen) == 0)
  2328. break;
  2329. if (pv < pvend)
  2330. ftype = pv->type;
  2331. else
  2332. {
  2333. /* This can happen if the variable is never used. */
  2334. ftype = ieee_builtin_type (info, start,
  2335. (unsigned int) builtin_void);
  2336. }
  2337. }
  2338. else
  2339. {
  2340. unsigned int findx;
  2341. if (structfields == NULL)
  2342. {
  2343. ieee_error (info, start, _("C++ object has no fields"));
  2344. return FALSE;
  2345. }
  2346. for (pf = structfields, findx = 0;
  2347. *pf != DEBUG_FIELD_NULL;
  2348. pf++, findx++)
  2349. {
  2350. const char *fname;
  2351. fname = debug_get_field_name (dhandle, *pf);
  2352. if (fname == NULL)
  2353. return FALSE;
  2354. if (fname[0] == mangledname[0]
  2355. && strncmp (fname, mangledname, mangledlen) == 0
  2356. && strlen (fname) == mangledlen)
  2357. break;
  2358. }
  2359. if (*pf == DEBUG_FIELD_NULL)
  2360. {
  2361. ieee_error (info, start,
  2362. _("C++ data member not found in container"));
  2363. return FALSE;
  2364. }
  2365. ftype = debug_get_field_type (dhandle, *pf);
  2366. if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
  2367. {
  2368. /* We might need to convert this field into a
  2369. reference type later on, so make it an indirect
  2370. type. */
  2371. if (it->fslots == NULL)
  2372. {
  2373. unsigned int fcnt;
  2374. const debug_field *pfcnt;
  2375. fcnt = 0;
  2376. for (pfcnt = structfields;
  2377. *pfcnt != DEBUG_FIELD_NULL;
  2378. pfcnt++)
  2379. ++fcnt;
  2380. it->fslots = ((debug_type *)
  2381. xmalloc (fcnt * sizeof *it->fslots));
  2382. memset (it->fslots, 0,
  2383. fcnt * sizeof *it->fslots);
  2384. }
  2385. if (ftype == DEBUG_TYPE_NULL)
  2386. return FALSE;
  2387. it->fslots[findx] = ftype;
  2388. ftype = debug_make_indirect_type (dhandle,
  2389. it->fslots + findx,
  2390. (const char *) NULL);
  2391. }
  2392. }
  2393. if (ftype == DEBUG_TYPE_NULL)
  2394. return FALSE;
  2395. switch (flags & CXXFLAGS_VISIBILITY)
  2396. {
  2397. default:
  2398. ieee_error (info, start, _("unknown C++ visibility"));
  2399. return FALSE;
  2400. case CXXFLAGS_VISIBILITY_PUBLIC:
  2401. visibility = DEBUG_VISIBILITY_PUBLIC;
  2402. break;
  2403. case CXXFLAGS_VISIBILITY_PRIVATE:
  2404. visibility = DEBUG_VISIBILITY_PRIVATE;
  2405. break;
  2406. case CXXFLAGS_VISIBILITY_PROTECTED:
  2407. visibility = DEBUG_VISIBILITY_PROTECTED;
  2408. break;
  2409. }
  2410. if (staticp)
  2411. {
  2412. char *mangledcopy;
  2413. mangledcopy = savestring (mangledname, mangledlen);
  2414. field = debug_make_static_member (dhandle, fieldcopy,
  2415. ftype, mangledcopy,
  2416. visibility);
  2417. }
  2418. else
  2419. {
  2420. bfd_vma bitpos, bitsize;
  2421. bitpos = debug_get_field_bitpos (dhandle, *pf);
  2422. bitsize = debug_get_field_bitsize (dhandle, *pf);
  2423. if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
  2424. {
  2425. ieee_error (info, start, _("bad C++ field bit pos or size"));
  2426. return FALSE;
  2427. }
  2428. field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
  2429. bitsize, visibility);
  2430. }
  2431. if (field == DEBUG_FIELD_NULL)
  2432. return FALSE;
  2433. if (field_count + 1 >= field_alloc)
  2434. {
  2435. field_alloc += 10;
  2436. fields = ((debug_field *)
  2437. xrealloc (fields, field_alloc * sizeof *fields));
  2438. }
  2439. fields[field_count] = field;
  2440. ++field_count;
  2441. fields[field_count] = DEBUG_FIELD_NULL;
  2442. }
  2443. break;
  2444. case 'm':
  2445. case 'v':
  2446. {
  2447. bfd_vma flags, voffset, control;
  2448. const char *name, *mangled;
  2449. unsigned long namlen, mangledlen;
  2450. struct ieee_var *pv, *pvend;
  2451. debug_type type;
  2452. enum debug_visibility visibility;
  2453. bfd_boolean constp, volatilep;
  2454. char *mangledcopy;
  2455. debug_method_variant mv;
  2456. struct ieee_method *meth;
  2457. unsigned int im;
  2458. if (! ieee_require_asn (info, pp, &flags)
  2459. || ! ieee_require_atn65 (info, pp, &name, &namlen)
  2460. || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
  2461. return FALSE;
  2462. count -= 3;
  2463. if (id != 'v')
  2464. voffset = 0;
  2465. else
  2466. {
  2467. if (! ieee_require_asn (info, pp, &voffset))
  2468. return FALSE;
  2469. --count;
  2470. }
  2471. if (! ieee_require_asn (info, pp, &control))
  2472. return FALSE;
  2473. --count;
  2474. /* We just ignore the control information. */
  2475. /* We have no way to represent friend information, so we
  2476. just ignore it. */
  2477. if ((flags & CXXFLAGS_FRIEND) != 0)
  2478. break;
  2479. /* We should already have seen a type for the function. */
  2480. pv = info->vars.vars;
  2481. pvend = pv + info->vars.alloc;
  2482. for (; pv < pvend; pv++)
  2483. if (pv->namlen == mangledlen
  2484. && strncmp (pv->name, mangled, mangledlen) == 0)
  2485. break;
  2486. if (pv >= pvend)
  2487. {
  2488. /* We won't have type information for this function if
  2489. it is not included in this file. We don't try to
  2490. handle this case. FIXME. */
  2491. type = (debug_make_function_type
  2492. (dhandle,
  2493. ieee_builtin_type (info, start,
  2494. (unsigned int) builtin_void),
  2495. (debug_type *) NULL,
  2496. FALSE));
  2497. }
  2498. else
  2499. {
  2500. debug_type return_type;
  2501. const debug_type *arg_types;
  2502. bfd_boolean varargs = FALSE;
  2503. if (debug_get_type_kind (dhandle, pv->type)
  2504. != DEBUG_KIND_FUNCTION)
  2505. {
  2506. ieee_error (info, start,
  2507. _("bad type for C++ method function"));
  2508. return FALSE;
  2509. }
  2510. return_type = debug_get_return_type (dhandle, pv->type);
  2511. arg_types = debug_get_parameter_types (dhandle, pv->type,
  2512. &varargs);
  2513. if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
  2514. {
  2515. ieee_error (info, start,
  2516. _("no type information for C++ method function"));
  2517. return FALSE;
  2518. }
  2519. type = debug_make_method_type (dhandle, return_type, it->type,
  2520. (debug_type *) arg_types,
  2521. varargs);
  2522. }
  2523. if (type == DEBUG_TYPE_NULL)
  2524. return FALSE;
  2525. switch (flags & CXXFLAGS_VISIBILITY)
  2526. {
  2527. default:
  2528. ieee_error (info, start, _("unknown C++ visibility"));
  2529. return FALSE;
  2530. case CXXFLAGS_VISIBILITY_PUBLIC:
  2531. visibility = DEBUG_VISIBILITY_PUBLIC;
  2532. break;
  2533. case CXXFLAGS_VISIBILITY_PRIVATE:
  2534. visibility = DEBUG_VISIBILITY_PRIVATE;
  2535. break;
  2536. case CXXFLAGS_VISIBILITY_PROTECTED:
  2537. visibility = DEBUG_VISIBILITY_PROTECTED;
  2538. break;
  2539. }
  2540. constp = (flags & CXXFLAGS_CONST) != 0 ? TRUE : FALSE;
  2541. volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? TRUE : FALSE;
  2542. mangledcopy = savestring (mangled, mangledlen);
  2543. if ((flags & CXXFLAGS_STATIC) != 0)
  2544. {
  2545. if (id == 'v')
  2546. {
  2547. ieee_error (info, start, _("C++ static virtual method"));
  2548. return FALSE;
  2549. }
  2550. mv = debug_make_static_method_variant (dhandle, mangledcopy,
  2551. type, visibility,
  2552. constp, volatilep);
  2553. }
  2554. else
  2555. {
  2556. debug_type vcontext;
  2557. if (id != 'v')
  2558. vcontext = DEBUG_TYPE_NULL;
  2559. else
  2560. {
  2561. /* FIXME: How can we calculate this correctly? */
  2562. vcontext = it->type;
  2563. }
  2564. mv = debug_make_method_variant (dhandle, mangledcopy, type,
  2565. visibility, constp,
  2566. volatilep, voffset,
  2567. vcontext);
  2568. }
  2569. if (mv == DEBUG_METHOD_VARIANT_NULL)
  2570. return FALSE;
  2571. for (meth = methods, im = 0; im < methods_count; meth++, im++)
  2572. if (meth->namlen == namlen
  2573. && strncmp (meth->name, name, namlen) == 0)
  2574. break;
  2575. if (im >= methods_count)
  2576. {
  2577. if (methods_count >= methods_alloc)
  2578. {
  2579. methods_alloc += 10;
  2580. methods = ((struct ieee_method *)
  2581. xrealloc (methods,
  2582. methods_alloc * sizeof *methods));
  2583. }
  2584. methods[methods_count].name = name;
  2585. methods[methods_count].namlen = namlen;
  2586. methods[methods_count].variants = NULL;
  2587. methods[methods_count].count = 0;
  2588. methods[methods_count].alloc = 0;
  2589. meth = methods + methods_count;
  2590. ++methods_count;
  2591. }
  2592. if (meth->count + 1 >= meth->alloc)
  2593. {
  2594. meth->alloc += 10;
  2595. meth->variants = ((debug_method_variant *)
  2596. xrealloc (meth->variants,
  2597. (meth->alloc
  2598. * sizeof *meth->variants)));
  2599. }
  2600. meth->variants[meth->count] = mv;
  2601. ++meth->count;
  2602. meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
  2603. }
  2604. break;
  2605. case 'o':
  2606. {
  2607. bfd_vma spec;
  2608. /* We have no way to store this information, so we just
  2609. ignore it. */
  2610. if (! ieee_require_asn (info, pp, &spec))
  2611. return FALSE;
  2612. --count;
  2613. if ((spec & 4) != 0)
  2614. {
  2615. const char *filename;
  2616. unsigned long filenamlen;
  2617. bfd_vma lineno;
  2618. if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
  2619. || ! ieee_require_asn (info, pp, &lineno))
  2620. return FALSE;
  2621. count -= 2;
  2622. }
  2623. else if ((spec & 8) != 0)
  2624. {
  2625. const char *mangled;
  2626. unsigned long mangledlen;
  2627. if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
  2628. return FALSE;
  2629. --count;
  2630. }
  2631. else
  2632. {
  2633. ieee_error (info, start,
  2634. _("unrecognized C++ object overhead spec"));
  2635. return FALSE;
  2636. }
  2637. }
  2638. break;
  2639. case 'z':
  2640. {
  2641. const char *vname, *base;
  2642. unsigned long vnamelen, baselen;
  2643. bfd_vma vsize, control;
  2644. /* A virtual table pointer. */
  2645. if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
  2646. || ! ieee_require_asn (info, pp, &vsize)
  2647. || ! ieee_require_atn65 (info, pp, &base, &baselen)
  2648. || ! ieee_require_asn (info, pp, &control))
  2649. return FALSE;
  2650. count -= 4;
  2651. /* We just ignore the control number. We don't care what
  2652. the virtual table name is. We have no way to store the
  2653. virtual table size, and I don't think we care anyhow. */
  2654. /* FIXME: We can't handle multiple virtual table pointers. */
  2655. if (baselen == 0)
  2656. ownvptr = TRUE;
  2657. else
  2658. {
  2659. char *basecopy;
  2660. basecopy = savestring (base, baselen);
  2661. vptrbase = debug_find_tagged_type (dhandle, basecopy,
  2662. DEBUG_KIND_ILLEGAL);
  2663. free (basecopy);
  2664. if (vptrbase == DEBUG_TYPE_NULL)
  2665. {
  2666. ieee_error (info, start, _("undefined C++ vtable"));
  2667. return FALSE;
  2668. }
  2669. }
  2670. }
  2671. break;
  2672. }
  2673. }
  2674. /* Now that we have seen all the method variants, we can call
  2675. debug_make_method for each one. */
  2676. if (methods_count == 0)
  2677. dmethods = NULL;
  2678. else
  2679. {
  2680. unsigned int i;
  2681. dmethods = ((debug_method *)
  2682. xmalloc ((methods_count + 1) * sizeof *dmethods));
  2683. for (i = 0; i < methods_count; i++)
  2684. {
  2685. char *namcopy;
  2686. namcopy = savestring (methods[i].name, methods[i].namlen);
  2687. dmethods[i] = debug_make_method (dhandle, namcopy,
  2688. methods[i].variants);
  2689. if (dmethods[i] == DEBUG_METHOD_NULL)
  2690. return FALSE;
  2691. }
  2692. dmethods[i] = DEBUG_METHOD_NULL;
  2693. free (methods);
  2694. }
  2695. /* The struct type was created as an indirect type pointing at
  2696. it->slot. We update it->slot to automatically update all
  2697. references to this struct. */
  2698. it->slot = debug_make_object_type (dhandle,
  2699. cxx_class != 'u',
  2700. debug_get_type_size (dhandle,
  2701. it->slot),
  2702. fields, baseclasses, dmethods,
  2703. vptrbase, ownvptr);
  2704. if (it->slot == DEBUG_TYPE_NULL)
  2705. return FALSE;
  2706. return TRUE;
  2707. }
  2708. /* Read C++ default argument value and reference type information. */
  2709. static bfd_boolean
  2710. ieee_read_cxx_defaults (struct ieee_info *info, const bfd_byte **pp,
  2711. unsigned long count)
  2712. {
  2713. const bfd_byte *start;
  2714. const char *fnname;
  2715. unsigned long fnlen;
  2716. bfd_vma defcount;
  2717. start = *pp;
  2718. /* Giving the function name before the argument count is an addendum
  2719. to the spec. The function name is demangled, though, so this
  2720. record must always refer to the current function. */
  2721. if (info->blockstack.bsp <= info->blockstack.stack
  2722. || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
  2723. {
  2724. ieee_error (info, start, _("C++ default values not in a function"));
  2725. return FALSE;
  2726. }
  2727. if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
  2728. || ! ieee_require_asn (info, pp, &defcount))
  2729. return FALSE;
  2730. count -= 2;
  2731. while (defcount-- > 0)
  2732. {
  2733. bfd_vma type, val;
  2734. const char *strval;
  2735. unsigned long strvallen;
  2736. if (! ieee_require_asn (info, pp, &type))
  2737. return FALSE;
  2738. --count;
  2739. switch (type)
  2740. {
  2741. case 0:
  2742. case 4:
  2743. break;
  2744. case 1:
  2745. case 2:
  2746. if (! ieee_require_asn (info, pp, &val))
  2747. return FALSE;
  2748. --count;
  2749. break;
  2750. case 3:
  2751. case 7:
  2752. if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
  2753. return FALSE;
  2754. --count;
  2755. break;
  2756. default:
  2757. ieee_error (info, start, _("unrecognized C++ default type"));
  2758. return FALSE;
  2759. }
  2760. /* We have no way to record the default argument values, so we
  2761. just ignore them. FIXME. */
  2762. }
  2763. /* Any remaining arguments are indices of parameters that are really
  2764. reference type. */
  2765. if (count > 0)
  2766. {
  2767. void *dhandle;
  2768. debug_type *arg_slots;
  2769. dhandle = info->dhandle;
  2770. arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
  2771. while (count-- > 0)
  2772. {
  2773. bfd_vma indx;
  2774. debug_type target;
  2775. if (! ieee_require_asn (info, pp, &indx))
  2776. return FALSE;
  2777. /* The index is 1 based. */
  2778. --indx;
  2779. if (arg_slots == NULL
  2780. || arg_slots[indx] == DEBUG_TYPE_NULL
  2781. || (debug_get_type_kind (dhandle, arg_slots[indx])
  2782. != DEBUG_KIND_POINTER))
  2783. {
  2784. ieee_error (info, start, _("reference parameter is not a pointer"));
  2785. return FALSE;
  2786. }
  2787. target = debug_get_target_type (dhandle, arg_slots[indx]);
  2788. arg_slots[indx] = debug_make_reference_type (dhandle, target);
  2789. if (arg_slots[indx] == DEBUG_TYPE_NULL)
  2790. return FALSE;
  2791. }
  2792. }
  2793. return TRUE;
  2794. }
  2795. /* Read a C++ reference definition. */
  2796. static bfd_boolean
  2797. ieee_read_reference (struct ieee_info *info, const bfd_byte **pp)
  2798. {
  2799. const bfd_byte *start;
  2800. bfd_vma flags;
  2801. const char *cxx_class, *name;
  2802. unsigned long classlen, namlen;
  2803. debug_type *pslot;
  2804. debug_type target;
  2805. start = *pp;
  2806. if (! ieee_require_asn (info, pp, &flags))
  2807. return FALSE;
  2808. /* Giving the class name before the member name is in an addendum to
  2809. the spec. */
  2810. if (flags == 3)
  2811. {
  2812. if (! ieee_require_atn65 (info, pp, &cxx_class, &classlen))
  2813. return FALSE;
  2814. }
  2815. if (! ieee_require_atn65 (info, pp, &name, &namlen))
  2816. return FALSE;
  2817. pslot = NULL;
  2818. if (flags != 3)
  2819. {
  2820. int pass;
  2821. /* We search from the last variable indices to the first in
  2822. hopes of finding local variables correctly. We search the
  2823. local variables on the first pass, and the global variables
  2824. on the second. FIXME: This probably won't work in all cases.
  2825. On the other hand, I don't know what will. */
  2826. for (pass = 0; pass < 2; pass++)
  2827. {
  2828. struct ieee_vars *vars;
  2829. int i;
  2830. struct ieee_var *pv = NULL;
  2831. if (pass == 0)
  2832. vars = &info->vars;
  2833. else
  2834. {
  2835. vars = info->global_vars;
  2836. if (vars == NULL)
  2837. break;
  2838. }
  2839. for (i = (int) vars->alloc - 1; i >= 0; i--)
  2840. {
  2841. bfd_boolean found;
  2842. pv = vars->vars + i;
  2843. if (pv->pslot == NULL
  2844. || pv->namlen != namlen
  2845. || strncmp (pv->name, name, namlen) != 0)
  2846. continue;
  2847. found = FALSE;
  2848. switch (flags)
  2849. {
  2850. default:
  2851. ieee_error (info, start,
  2852. _("unrecognized C++ reference type"));
  2853. return FALSE;
  2854. case 0:
  2855. /* Global variable or function. */
  2856. if (pv->kind == IEEE_GLOBAL
  2857. || pv->kind == IEEE_EXTERNAL
  2858. || pv->kind == IEEE_FUNCTION)
  2859. found = TRUE;
  2860. break;
  2861. case 1:
  2862. /* Global static variable or function. */
  2863. if (pv->kind == IEEE_STATIC
  2864. || pv->kind == IEEE_FUNCTION)
  2865. found = TRUE;
  2866. break;
  2867. case 2:
  2868. /* Local variable. */
  2869. if (pv->kind == IEEE_LOCAL)
  2870. found = TRUE;
  2871. break;
  2872. }
  2873. if (found)
  2874. break;
  2875. }
  2876. if (i >= 0)
  2877. {
  2878. pslot = pv->pslot;
  2879. break;
  2880. }
  2881. }
  2882. }
  2883. else
  2884. {
  2885. struct ieee_tag *it;
  2886. for (it = info->tags; it != NULL; it = it->next)
  2887. {
  2888. if (it->name[0] == cxx_class[0]
  2889. && strncmp (it->name, cxx_class, classlen) == 0
  2890. && strlen (it->name) == classlen)
  2891. {
  2892. if (it->fslots != NULL)
  2893. {
  2894. const debug_field *pf;
  2895. unsigned int findx;
  2896. pf = debug_get_fields (info->dhandle, it->type);
  2897. if (pf == NULL)
  2898. {
  2899. ieee_error (info, start,
  2900. "C++ reference in class with no fields");
  2901. return FALSE;
  2902. }
  2903. for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
  2904. {
  2905. const char *fname;
  2906. fname = debug_get_field_name (info->dhandle, *pf);
  2907. if (fname == NULL)
  2908. return FALSE;
  2909. if (strncmp (fname, name, namlen) == 0
  2910. && strlen (fname) == namlen)
  2911. {
  2912. pslot = it->fslots + findx;
  2913. break;
  2914. }
  2915. }
  2916. }
  2917. break;
  2918. }
  2919. }
  2920. }
  2921. if (pslot == NULL)
  2922. {
  2923. ieee_error (info, start, _("C++ reference not found"));
  2924. return FALSE;
  2925. }
  2926. /* We allocated the type of the object as an indirect type pointing
  2927. to *pslot, which we can now update to be a reference type. */
  2928. if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
  2929. {
  2930. ieee_error (info, start, _("C++ reference is not pointer"));
  2931. return FALSE;
  2932. }
  2933. target = debug_get_target_type (info->dhandle, *pslot);
  2934. *pslot = debug_make_reference_type (info->dhandle, target);
  2935. if (*pslot == DEBUG_TYPE_NULL)
  2936. return FALSE;
  2937. return TRUE;
  2938. }
  2939. /* Require an ASN record. */
  2940. static bfd_boolean
  2941. ieee_require_asn (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
  2942. {
  2943. const bfd_byte *start;
  2944. ieee_record_enum_type c;
  2945. bfd_vma varindx;
  2946. start = *pp;
  2947. c = (ieee_record_enum_type) **pp;
  2948. if (c != ieee_e2_first_byte_enum)
  2949. {
  2950. ieee_error (info, start, _("missing required ASN"));
  2951. return FALSE;
  2952. }
  2953. ++*pp;
  2954. c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
  2955. if (c != ieee_asn_record_enum)
  2956. {
  2957. ieee_error (info, start, _("missing required ASN"));
  2958. return FALSE;
  2959. }
  2960. ++*pp;
  2961. /* Just ignore the variable index. */
  2962. if (! ieee_read_number (info, pp, &varindx))
  2963. return FALSE;
  2964. return ieee_read_expression (info, pp, pv);
  2965. }
  2966. /* Require an ATN65 record. */
  2967. static bfd_boolean
  2968. ieee_require_atn65 (struct ieee_info *info, const bfd_byte **pp,
  2969. const char **pname, unsigned long *pnamlen)
  2970. {
  2971. const bfd_byte *start;
  2972. ieee_record_enum_type c;
  2973. bfd_vma name_indx, type_indx, atn_code;
  2974. start = *pp;
  2975. c = (ieee_record_enum_type) **pp;
  2976. if (c != ieee_at_record_enum)
  2977. {
  2978. ieee_error (info, start, _("missing required ATN65"));
  2979. return FALSE;
  2980. }
  2981. ++*pp;
  2982. c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
  2983. if (c != ieee_atn_record_enum)
  2984. {
  2985. ieee_error (info, start, _("missing required ATN65"));
  2986. return FALSE;
  2987. }
  2988. ++*pp;
  2989. if (! ieee_read_number (info, pp, &name_indx)
  2990. || ! ieee_read_number (info, pp, &type_indx)
  2991. || ! ieee_read_number (info, pp, &atn_code))
  2992. return FALSE;
  2993. /* Just ignore name_indx. */
  2994. if (type_indx != 0 || atn_code != 65)
  2995. {
  2996. ieee_error (info, start, _("bad ATN65 record"));
  2997. return FALSE;
  2998. }
  2999. return ieee_read_id (info, pp, pname, pnamlen);
  3000. }
  3001. /* Convert a register number in IEEE debugging information into a
  3002. generic register number. */
  3003. static int
  3004. ieee_regno_to_genreg (bfd *abfd, int r)
  3005. {
  3006. switch (bfd_get_arch (abfd))
  3007. {
  3008. case bfd_arch_m68k:
  3009. /* For some reasons stabs adds 2 to the floating point register
  3010. numbers. */
  3011. if (r >= 16)
  3012. r += 2;
  3013. break;
  3014. case bfd_arch_i960:
  3015. /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
  3016. 32 to 35 for fp0 to fp3. */
  3017. --r;
  3018. break;
  3019. default:
  3020. break;
  3021. }
  3022. return r;
  3023. }
  3024. /* Convert a generic register number to an IEEE specific one. */
  3025. static int
  3026. ieee_genreg_to_regno (bfd *abfd, int r)
  3027. {
  3028. switch (bfd_get_arch (abfd))
  3029. {
  3030. case bfd_arch_m68k:
  3031. /* For some reason stabs add 2 to the floating point register
  3032. numbers. */
  3033. if (r >= 18)
  3034. r -= 2;
  3035. break;
  3036. case bfd_arch_i960:
  3037. /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
  3038. 32 to 35 for fp0 to fp3. */
  3039. ++r;
  3040. break;
  3041. default:
  3042. break;
  3043. }
  3044. return r;
  3045. }
  3046. /* These routines build IEEE debugging information out of the generic
  3047. debugging information. */
  3048. /* We build the IEEE debugging information byte by byte. Rather than
  3049. waste time copying data around, we use a linked list of buffers to
  3050. hold the data. */
  3051. #define IEEE_BUFSIZE (490)
  3052. struct ieee_buf
  3053. {
  3054. /* Next buffer. */
  3055. struct ieee_buf *next;
  3056. /* Number of data bytes in this buffer. */
  3057. unsigned int c;
  3058. /* Bytes. */
  3059. bfd_byte buf[IEEE_BUFSIZE];
  3060. };
  3061. /* A list of buffers. */
  3062. struct ieee_buflist
  3063. {
  3064. /* Head of list. */
  3065. struct ieee_buf *head;
  3066. /* Tail--last buffer on list. */
  3067. struct ieee_buf *tail;
  3068. };
  3069. /* In order to generate the BB11 blocks required by the HP emulator,
  3070. we keep track of ranges of addresses which correspond to a given
  3071. compilation unit. */
  3072. struct ieee_range
  3073. {
  3074. /* Next range. */
  3075. struct ieee_range *next;
  3076. /* Low address. */
  3077. bfd_vma low;
  3078. /* High address. */
  3079. bfd_vma high;
  3080. };
  3081. /* This structure holds information for a class on the type stack. */
  3082. struct ieee_type_class
  3083. {
  3084. /* The name index in the debugging information. */
  3085. unsigned int indx;
  3086. /* The pmisc records for the class. */
  3087. struct ieee_buflist pmiscbuf;
  3088. /* The number of pmisc records. */
  3089. unsigned int pmisccount;
  3090. /* The name of the class holding the virtual table, if not this
  3091. class. */
  3092. const char *vclass;
  3093. /* Whether this class holds its own virtual table. */
  3094. bfd_boolean ownvptr;
  3095. /* The largest virtual table offset seen so far. */
  3096. bfd_vma voffset;
  3097. /* The current method. */
  3098. const char *method;
  3099. /* Additional pmisc records used to record fields of reference type. */
  3100. struct ieee_buflist refs;
  3101. };
  3102. /* This is how we store types for the writing routines. Most types
  3103. are simply represented by a type index. */
  3104. struct ieee_write_type
  3105. {
  3106. /* Type index. */
  3107. unsigned int indx;
  3108. /* The size of the type, if known. */
  3109. unsigned int size;
  3110. /* The name of the type, if any. */
  3111. const char *name;
  3112. /* If this is a function or method type, we build the type here, and
  3113. only add it to the output buffers if we need it. */
  3114. struct ieee_buflist fndef;
  3115. /* If this is a struct, this is where the struct definition is
  3116. built. */
  3117. struct ieee_buflist strdef;
  3118. /* If this is a class, this is where the class information is built. */
  3119. struct ieee_type_class *classdef;
  3120. /* Whether the type is unsigned. */
  3121. unsigned int unsignedp : 1;
  3122. /* Whether this is a reference type. */
  3123. unsigned int referencep : 1;
  3124. /* Whether this is in the local type block. */
  3125. unsigned int localp : 1;
  3126. /* Whether this is a duplicate struct definition which we are
  3127. ignoring. */
  3128. unsigned int ignorep : 1;
  3129. };
  3130. /* This is the type stack used by the debug writing routines. FIXME:
  3131. We could generate more efficient output if we remembered when we
  3132. have output a particular type before. */
  3133. struct ieee_type_stack
  3134. {
  3135. /* Next entry on stack. */
  3136. struct ieee_type_stack *next;
  3137. /* Type information. */
  3138. struct ieee_write_type type;
  3139. };
  3140. /* This is a list of associations between a name and some types.
  3141. These are used for typedefs and tags. */
  3142. struct ieee_name_type
  3143. {
  3144. /* Next type for this name. */
  3145. struct ieee_name_type *next;
  3146. /* ID number. For a typedef, this is the index of the type to which
  3147. this name is typedefed. */
  3148. unsigned int id;
  3149. /* Type. */
  3150. struct ieee_write_type type;
  3151. /* If this is a tag which has not yet been defined, this is the
  3152. kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
  3153. enum debug_type_kind kind;
  3154. };
  3155. /* We use a hash table to associate names and types. */
  3156. struct ieee_name_type_hash_table
  3157. {
  3158. struct bfd_hash_table root;
  3159. };
  3160. struct ieee_name_type_hash_entry
  3161. {
  3162. struct bfd_hash_entry root;
  3163. /* Information for this name. */
  3164. struct ieee_name_type *types;
  3165. };
  3166. /* This is a list of enums. */
  3167. struct ieee_defined_enum
  3168. {
  3169. /* Next enum. */
  3170. struct ieee_defined_enum *next;
  3171. /* Type index. */
  3172. unsigned int indx;
  3173. /* Whether this enum has been defined. */
  3174. bfd_boolean defined;
  3175. /* Tag. */
  3176. const char *tag;
  3177. /* Names. */
  3178. const char **names;
  3179. /* Values. */
  3180. bfd_signed_vma *vals;
  3181. };
  3182. /* We keep a list of modified versions of types, so that we don't
  3183. output them more than once. */
  3184. struct ieee_modified_type
  3185. {
  3186. /* Pointer to this type. */
  3187. unsigned int pointer;
  3188. /* Function with unknown arguments returning this type. */
  3189. unsigned int function;
  3190. /* Const version of this type. */
  3191. unsigned int const_qualified;
  3192. /* Volatile version of this type. */
  3193. unsigned int volatile_qualified;
  3194. /* List of arrays of this type of various bounds. */
  3195. struct ieee_modified_array_type *arrays;
  3196. };
  3197. /* A list of arrays bounds. */
  3198. struct ieee_modified_array_type
  3199. {
  3200. /* Next array bounds. */
  3201. struct ieee_modified_array_type *next;
  3202. /* Type index with these bounds. */
  3203. unsigned int indx;
  3204. /* Low bound. */
  3205. bfd_signed_vma low;
  3206. /* High bound. */
  3207. bfd_signed_vma high;
  3208. };
  3209. /* This is a list of pending function parameter information. We don't
  3210. output them until we see the first block. */
  3211. struct ieee_pending_parm
  3212. {
  3213. /* Next pending parameter. */
  3214. struct ieee_pending_parm *next;
  3215. /* Name. */
  3216. const char *name;
  3217. /* Type index. */
  3218. unsigned int type;
  3219. /* Whether the type is a reference. */
  3220. bfd_boolean referencep;
  3221. /* Kind. */
  3222. enum debug_parm_kind kind;
  3223. /* Value. */
  3224. bfd_vma val;
  3225. };
  3226. /* This is the handle passed down by debug_write. */
  3227. struct ieee_handle
  3228. {
  3229. /* BFD we are writing to. */
  3230. bfd *abfd;
  3231. /* Whether we got an error in a subroutine called via traverse or
  3232. map_over_sections. */
  3233. bfd_boolean error;
  3234. /* Current data buffer list. */
  3235. struct ieee_buflist *current;
  3236. /* Current data buffer. */
  3237. struct ieee_buf *curbuf;
  3238. /* Filename of current compilation unit. */
  3239. const char *filename;
  3240. /* Module name of current compilation unit. */
  3241. const char *modname;
  3242. /* List of buffer for global types. */
  3243. struct ieee_buflist global_types;
  3244. /* List of finished data buffers. */
  3245. struct ieee_buflist data;
  3246. /* List of buffers for typedefs in the current compilation unit. */
  3247. struct ieee_buflist types;
  3248. /* List of buffers for variables and functions in the current
  3249. compilation unit. */
  3250. struct ieee_buflist vars;
  3251. /* List of buffers for C++ class definitions in the current
  3252. compilation unit. */
  3253. struct ieee_buflist cxx;
  3254. /* List of buffers for line numbers in the current compilation unit. */
  3255. struct ieee_buflist linenos;
  3256. /* Ranges for the current compilation unit. */
  3257. struct ieee_range *ranges;
  3258. /* Ranges for all debugging information. */
  3259. struct ieee_range *global_ranges;
  3260. /* Nested pending ranges. */
  3261. struct ieee_range *pending_ranges;
  3262. /* Type stack. */
  3263. struct ieee_type_stack *type_stack;
  3264. /* Next unallocated type index. */
  3265. unsigned int type_indx;
  3266. /* Next unallocated name index. */
  3267. unsigned int name_indx;
  3268. /* Typedefs. */
  3269. struct ieee_name_type_hash_table typedefs;
  3270. /* Tags. */
  3271. struct ieee_name_type_hash_table tags;
  3272. /* Enums. */
  3273. struct ieee_defined_enum *enums;
  3274. /* Modified versions of types. */
  3275. struct ieee_modified_type *modified;
  3276. /* Number of entries allocated in modified. */
  3277. unsigned int modified_alloc;
  3278. /* 4 byte complex type. */
  3279. unsigned int complex_float_index;
  3280. /* 8 byte complex type. */
  3281. unsigned int complex_double_index;
  3282. /* The depth of block nesting. This is 0 outside a function, and 1
  3283. just after start_function is called. */
  3284. unsigned int block_depth;
  3285. /* The name of the current function. */
  3286. const char *fnname;
  3287. /* List of buffers for the type of the function we are currently
  3288. writing out. */
  3289. struct ieee_buflist fntype;
  3290. /* List of buffers for the parameters of the function we are
  3291. currently writing out. */
  3292. struct ieee_buflist fnargs;
  3293. /* Number of arguments written to fnargs. */
  3294. unsigned int fnargcount;
  3295. /* Pending function parameters. */
  3296. struct ieee_pending_parm *pending_parms;
  3297. /* Current line number filename. */
  3298. const char *lineno_filename;
  3299. /* Line number name index. */
  3300. unsigned int lineno_name_indx;
  3301. /* Filename of pending line number. */
  3302. const char *pending_lineno_filename;
  3303. /* Pending line number. */
  3304. unsigned long pending_lineno;
  3305. /* Address of pending line number. */
  3306. bfd_vma pending_lineno_addr;
  3307. /* Highest address seen at end of procedure. */
  3308. bfd_vma highaddr;
  3309. };
  3310. static bfd_boolean ieee_init_buffer
  3311. (struct ieee_handle *, struct ieee_buflist *);
  3312. static bfd_boolean ieee_change_buffer
  3313. (struct ieee_handle *, struct ieee_buflist *);
  3314. static bfd_boolean ieee_append_buffer
  3315. (struct ieee_handle *, struct ieee_buflist *, struct ieee_buflist *);
  3316. static bfd_boolean ieee_real_write_byte (struct ieee_handle *, int);
  3317. static bfd_boolean ieee_write_2bytes (struct ieee_handle *, int);
  3318. static bfd_boolean ieee_write_number (struct ieee_handle *, bfd_vma);
  3319. static bfd_boolean ieee_write_id (struct ieee_handle *, const char *);
  3320. static bfd_boolean ieee_write_asn
  3321. (struct ieee_handle *, unsigned int, bfd_vma);
  3322. static bfd_boolean ieee_write_atn65
  3323. (struct ieee_handle *, unsigned int, const char *);
  3324. static bfd_boolean ieee_push_type
  3325. (struct ieee_handle *, unsigned int, unsigned int, bfd_boolean,
  3326. bfd_boolean);
  3327. static unsigned int ieee_pop_type (struct ieee_handle *);
  3328. static void ieee_pop_unused_type (struct ieee_handle *);
  3329. static unsigned int ieee_pop_type_used (struct ieee_handle *, bfd_boolean);
  3330. static bfd_boolean ieee_add_range
  3331. (struct ieee_handle *, bfd_boolean, bfd_vma, bfd_vma);
  3332. static bfd_boolean ieee_start_range (struct ieee_handle *, bfd_vma);
  3333. static bfd_boolean ieee_end_range (struct ieee_handle *, bfd_vma);
  3334. static bfd_boolean ieee_define_type
  3335. (struct ieee_handle *, unsigned int, bfd_boolean, bfd_boolean);
  3336. static bfd_boolean ieee_define_named_type
  3337. (struct ieee_handle *, const char *, unsigned int, unsigned int,
  3338. bfd_boolean, bfd_boolean, struct ieee_buflist *);
  3339. static struct ieee_modified_type *ieee_get_modified_info
  3340. (struct ieee_handle *, unsigned int);
  3341. static struct bfd_hash_entry *ieee_name_type_newfunc
  3342. (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
  3343. static bfd_boolean ieee_write_undefined_tag
  3344. (struct ieee_name_type_hash_entry *, void *);
  3345. static bfd_boolean ieee_finish_compilation_unit (struct ieee_handle *);
  3346. static void ieee_add_bb11_blocks (bfd *, asection *, void *);
  3347. static bfd_boolean ieee_add_bb11
  3348. (struct ieee_handle *, asection *, bfd_vma, bfd_vma);
  3349. static bfd_boolean ieee_output_pending_parms (struct ieee_handle *);
  3350. static unsigned int ieee_vis_to_flags (enum debug_visibility);
  3351. static bfd_boolean ieee_class_method_var
  3352. (struct ieee_handle *, const char *, enum debug_visibility, bfd_boolean,
  3353. bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
  3354. static bfd_boolean ieee_start_compilation_unit (void *, const char *);
  3355. static bfd_boolean ieee_start_source (void *, const char *);
  3356. static bfd_boolean ieee_empty_type (void *);
  3357. static bfd_boolean ieee_void_type (void *);
  3358. static bfd_boolean ieee_int_type (void *, unsigned int, bfd_boolean);
  3359. static bfd_boolean ieee_float_type (void *, unsigned int);
  3360. static bfd_boolean ieee_complex_type (void *, unsigned int);
  3361. static bfd_boolean ieee_bool_type (void *, unsigned int);
  3362. static bfd_boolean ieee_enum_type
  3363. (void *, const char *, const char **, bfd_signed_vma *);
  3364. static bfd_boolean ieee_pointer_type (void *);
  3365. static bfd_boolean ieee_function_type (void *, int, bfd_boolean);
  3366. static bfd_boolean ieee_reference_type (void *);
  3367. static bfd_boolean ieee_range_type (void *, bfd_signed_vma, bfd_signed_vma);
  3368. static bfd_boolean ieee_array_type
  3369. (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
  3370. static bfd_boolean ieee_set_type (void *, bfd_boolean);
  3371. static bfd_boolean ieee_offset_type (void *);
  3372. static bfd_boolean ieee_method_type (void *, bfd_boolean, int, bfd_boolean);
  3373. static bfd_boolean ieee_const_type (void *);
  3374. static bfd_boolean ieee_volatile_type (void *);
  3375. static bfd_boolean ieee_start_struct_type
  3376. (void *, const char *, unsigned int, bfd_boolean, unsigned int);
  3377. static bfd_boolean ieee_struct_field
  3378. (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
  3379. static bfd_boolean ieee_end_struct_type (void *);
  3380. static bfd_boolean ieee_start_class_type
  3381. (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean,
  3382. bfd_boolean);
  3383. static bfd_boolean ieee_class_static_member
  3384. (void *, const char *, const char *, enum debug_visibility);
  3385. static bfd_boolean ieee_class_baseclass
  3386. (void *, bfd_vma, bfd_boolean, enum debug_visibility);
  3387. static bfd_boolean ieee_class_start_method (void *, const char *);
  3388. static bfd_boolean ieee_class_method_variant
  3389. (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
  3390. bfd_vma, bfd_boolean);
  3391. static bfd_boolean ieee_class_static_method_variant
  3392. (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
  3393. static bfd_boolean ieee_class_end_method (void *);
  3394. static bfd_boolean ieee_end_class_type (void *);
  3395. static bfd_boolean ieee_typedef_type (void *, const char *);
  3396. static bfd_boolean ieee_tag_type
  3397. (void *, const char *, unsigned int, enum debug_type_kind);
  3398. static bfd_boolean ieee_typdef (void *, const char *);
  3399. static bfd_boolean ieee_tag (void *, const char *);
  3400. static bfd_boolean ieee_int_constant (void *, const char *, bfd_vma);
  3401. static bfd_boolean ieee_float_constant (void *, const char *, double);
  3402. static bfd_boolean ieee_typed_constant (void *, const char *, bfd_vma);
  3403. static bfd_boolean ieee_variable
  3404. (void *, const char *, enum debug_var_kind, bfd_vma);
  3405. static bfd_boolean ieee_start_function (void *, const char *, bfd_boolean);
  3406. static bfd_boolean ieee_function_parameter
  3407. (void *, const char *, enum debug_parm_kind, bfd_vma);
  3408. static bfd_boolean ieee_start_block (void *, bfd_vma);
  3409. static bfd_boolean ieee_end_block (void *, bfd_vma);
  3410. static bfd_boolean ieee_end_function (void *);
  3411. static bfd_boolean ieee_lineno (void *, const char *, unsigned long, bfd_vma);
  3412. static const struct debug_write_fns ieee_fns =
  3413. {
  3414. ieee_start_compilation_unit,
  3415. ieee_start_source,
  3416. ieee_empty_type,
  3417. ieee_void_type,
  3418. ieee_int_type,
  3419. ieee_float_type,
  3420. ieee_complex_type,
  3421. ieee_bool_type,
  3422. ieee_enum_type,
  3423. ieee_pointer_type,
  3424. ieee_function_type,
  3425. ieee_reference_type,
  3426. ieee_range_type,
  3427. ieee_array_type,
  3428. ieee_set_type,
  3429. ieee_offset_type,
  3430. ieee_method_type,
  3431. ieee_const_type,
  3432. ieee_volatile_type,
  3433. ieee_start_struct_type,
  3434. ieee_struct_field,
  3435. ieee_end_struct_type,
  3436. ieee_start_class_type,
  3437. ieee_class_static_member,
  3438. ieee_class_baseclass,
  3439. ieee_class_start_method,
  3440. ieee_class_method_variant,
  3441. ieee_class_static_method_variant,
  3442. ieee_class_end_method,
  3443. ieee_end_class_type,
  3444. ieee_typedef_type,
  3445. ieee_tag_type,
  3446. ieee_typdef,
  3447. ieee_tag,
  3448. ieee_int_constant,
  3449. ieee_float_constant,
  3450. ieee_typed_constant,
  3451. ieee_variable,
  3452. ieee_start_function,
  3453. ieee_function_parameter,
  3454. ieee_start_block,
  3455. ieee_end_block,
  3456. ieee_end_function,
  3457. ieee_lineno
  3458. };
  3459. /* Initialize a buffer to be empty. */
  3460. static bfd_boolean
  3461. ieee_init_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
  3462. struct ieee_buflist *buflist)
  3463. {
  3464. buflist->head = NULL;
  3465. buflist->tail = NULL;
  3466. return TRUE;
  3467. }
  3468. /* See whether a buffer list has any data. */
  3469. #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
  3470. /* Change the current buffer to a specified buffer chain. */
  3471. static bfd_boolean
  3472. ieee_change_buffer (struct ieee_handle *info, struct ieee_buflist *buflist)
  3473. {
  3474. if (buflist->head == NULL)
  3475. {
  3476. struct ieee_buf *buf;
  3477. buf = (struct ieee_buf *) xmalloc (sizeof *buf);
  3478. buf->next = NULL;
  3479. buf->c = 0;
  3480. buflist->head = buf;
  3481. buflist->tail = buf;
  3482. }
  3483. info->current = buflist;
  3484. info->curbuf = buflist->tail;
  3485. return TRUE;
  3486. }
  3487. /* Append a buffer chain. */
  3488. static bfd_boolean
  3489. ieee_append_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
  3490. struct ieee_buflist *mainbuf,
  3491. struct ieee_buflist *newbuf)
  3492. {
  3493. if (newbuf->head != NULL)
  3494. {
  3495. if (mainbuf->head == NULL)
  3496. mainbuf->head = newbuf->head;
  3497. else
  3498. mainbuf->tail->next = newbuf->head;
  3499. mainbuf->tail = newbuf->tail;
  3500. }
  3501. return TRUE;
  3502. }
  3503. /* Write a byte into the buffer. We use a macro for speed and a
  3504. function for the complex cases. */
  3505. #define ieee_write_byte(info, b) \
  3506. ((info)->curbuf->c < IEEE_BUFSIZE \
  3507. ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE) \
  3508. : ieee_real_write_byte ((info), (b)))
  3509. static bfd_boolean
  3510. ieee_real_write_byte (struct ieee_handle *info, int b)
  3511. {
  3512. if (info->curbuf->c >= IEEE_BUFSIZE)
  3513. {
  3514. struct ieee_buf *n;
  3515. n = (struct ieee_buf *) xmalloc (sizeof *n);
  3516. n->next = NULL;
  3517. n->c = 0;
  3518. if (info->current->head == NULL)
  3519. info->current->head = n;
  3520. else
  3521. info->current->tail->next = n;
  3522. info->current->tail = n;
  3523. info->curbuf = n;
  3524. }
  3525. info->curbuf->buf[info->curbuf->c] = b;
  3526. ++info->curbuf->c;
  3527. return TRUE;
  3528. }
  3529. /* Write out two bytes. */
  3530. static bfd_boolean
  3531. ieee_write_2bytes (struct ieee_handle *info, int i)
  3532. {
  3533. return (ieee_write_byte (info, i >> 8)
  3534. && ieee_write_byte (info, i & 0xff));
  3535. }
  3536. /* Write out an integer. */
  3537. static bfd_boolean
  3538. ieee_write_number (struct ieee_handle *info, bfd_vma v)
  3539. {
  3540. bfd_vma t;
  3541. bfd_byte ab[20];
  3542. bfd_byte *p;
  3543. unsigned int c;
  3544. if (v <= (bfd_vma) ieee_number_end_enum)
  3545. return ieee_write_byte (info, (int) v);
  3546. t = v;
  3547. p = ab + sizeof ab;
  3548. while (t != 0)
  3549. {
  3550. *--p = t & 0xff;
  3551. t >>= 8;
  3552. }
  3553. c = (ab + 20) - p;
  3554. if (c > (unsigned int) (ieee_number_repeat_end_enum
  3555. - ieee_number_repeat_start_enum))
  3556. {
  3557. fprintf (stderr, _("IEEE numeric overflow: 0x"));
  3558. fprintf_vma (stderr, v);
  3559. fprintf (stderr, "\n");
  3560. return FALSE;
  3561. }
  3562. if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
  3563. return FALSE;
  3564. for (; c > 0; --c, ++p)
  3565. {
  3566. if (! ieee_write_byte (info, *p))
  3567. return FALSE;
  3568. }
  3569. return TRUE;
  3570. }
  3571. /* Write out a string. */
  3572. static bfd_boolean
  3573. ieee_write_id (struct ieee_handle *info, const char *s)
  3574. {
  3575. unsigned int len;
  3576. len = strlen (s);
  3577. if (len <= 0x7f)
  3578. {
  3579. if (! ieee_write_byte (info, len))
  3580. return FALSE;
  3581. }
  3582. else if (len <= 0xff)
  3583. {
  3584. if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
  3585. || ! ieee_write_byte (info, len))
  3586. return FALSE;
  3587. }
  3588. else if (len <= 0xffff)
  3589. {
  3590. if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
  3591. || ! ieee_write_2bytes (info, len))
  3592. return FALSE;
  3593. }
  3594. else
  3595. {
  3596. fprintf (stderr, _("IEEE string length overflow: %u\n"), len);
  3597. return FALSE;
  3598. }
  3599. for (; *s != '\0'; s++)
  3600. if (! ieee_write_byte (info, *s))
  3601. return FALSE;
  3602. return TRUE;
  3603. }
  3604. /* Write out an ASN record. */
  3605. static bfd_boolean
  3606. ieee_write_asn (struct ieee_handle *info, unsigned int indx, bfd_vma val)
  3607. {
  3608. return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
  3609. && ieee_write_number (info, indx)
  3610. && ieee_write_number (info, val));
  3611. }
  3612. /* Write out an ATN65 record. */
  3613. static bfd_boolean
  3614. ieee_write_atn65 (struct ieee_handle *info, unsigned int indx, const char *s)
  3615. {
  3616. return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
  3617. && ieee_write_number (info, indx)
  3618. && ieee_write_number (info, 0)
  3619. && ieee_write_number (info, 65)
  3620. && ieee_write_id (info, s));
  3621. }
  3622. /* Push a type index onto the type stack. */
  3623. static bfd_boolean
  3624. ieee_push_type (struct ieee_handle *info, unsigned int indx,
  3625. unsigned int size, bfd_boolean unsignedp, bfd_boolean localp)
  3626. {
  3627. struct ieee_type_stack *ts;
  3628. ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
  3629. memset (ts, 0, sizeof *ts);
  3630. ts->type.indx = indx;
  3631. ts->type.size = size;
  3632. ts->type.unsignedp = unsignedp;
  3633. ts->type.localp = localp;
  3634. ts->next = info->type_stack;
  3635. info->type_stack = ts;
  3636. return TRUE;
  3637. }
  3638. /* Pop a type index off the type stack. */
  3639. static unsigned int
  3640. ieee_pop_type (struct ieee_handle *info)
  3641. {
  3642. return ieee_pop_type_used (info, TRUE);
  3643. }
  3644. /* Pop an unused type index off the type stack. */
  3645. static void
  3646. ieee_pop_unused_type (struct ieee_handle *info)
  3647. {
  3648. (void) ieee_pop_type_used (info, FALSE);
  3649. }
  3650. /* Pop a used or unused type index off the type stack. */
  3651. static unsigned int
  3652. ieee_pop_type_used (struct ieee_handle *info, bfd_boolean used)
  3653. {
  3654. struct ieee_type_stack *ts;
  3655. unsigned int ret;
  3656. ts = info->type_stack;
  3657. assert (ts != NULL);
  3658. /* If this is a function type, and we need it, we need to append the
  3659. actual definition to the typedef block now. */
  3660. if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
  3661. {
  3662. struct ieee_buflist *buflist;
  3663. if (ts->type.localp)
  3664. {
  3665. /* Make sure we have started the types block. */
  3666. if (ieee_buffer_emptyp (&info->types))
  3667. {
  3668. if (! ieee_change_buffer (info, &info->types)
  3669. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  3670. || ! ieee_write_byte (info, 1)
  3671. || ! ieee_write_number (info, 0)
  3672. || ! ieee_write_id (info, info->modname))
  3673. return FALSE;
  3674. }
  3675. buflist = &info->types;
  3676. }
  3677. else
  3678. {
  3679. /* Make sure we started the global type block. */
  3680. if (ieee_buffer_emptyp (&info->global_types))
  3681. {
  3682. if (! ieee_change_buffer (info, &info->global_types)
  3683. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  3684. || ! ieee_write_byte (info, 2)
  3685. || ! ieee_write_number (info, 0)
  3686. || ! ieee_write_id (info, ""))
  3687. return FALSE;
  3688. }
  3689. buflist = &info->global_types;
  3690. }
  3691. if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
  3692. return FALSE;
  3693. }
  3694. ret = ts->type.indx;
  3695. info->type_stack = ts->next;
  3696. free (ts);
  3697. return ret;
  3698. }
  3699. /* Add a range of bytes included in the current compilation unit. */
  3700. static bfd_boolean
  3701. ieee_add_range (struct ieee_handle *info, bfd_boolean global, bfd_vma low,
  3702. bfd_vma high)
  3703. {
  3704. struct ieee_range **plist, *r, **pr;
  3705. if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
  3706. return TRUE;
  3707. if (global)
  3708. plist = &info->global_ranges;
  3709. else
  3710. plist = &info->ranges;
  3711. for (r = *plist; r != NULL; r = r->next)
  3712. {
  3713. if (high >= r->low && low <= r->high)
  3714. {
  3715. /* The new range overlaps r. */
  3716. if (low < r->low)
  3717. r->low = low;
  3718. if (high > r->high)
  3719. r->high = high;
  3720. pr = &r->next;
  3721. while (*pr != NULL && (*pr)->low <= r->high)
  3722. {
  3723. struct ieee_range *n;
  3724. if ((*pr)->high > r->high)
  3725. r->high = (*pr)->high;
  3726. n = (*pr)->next;
  3727. free (*pr);
  3728. *pr = n;
  3729. }
  3730. return TRUE;
  3731. }
  3732. }
  3733. r = (struct ieee_range *) xmalloc (sizeof *r);
  3734. memset (r, 0, sizeof *r);
  3735. r->low = low;
  3736. r->high = high;
  3737. /* Store the ranges sorted by address. */
  3738. for (pr = plist; *pr != NULL; pr = &(*pr)->next)
  3739. if ((*pr)->low > high)
  3740. break;
  3741. r->next = *pr;
  3742. *pr = r;
  3743. return TRUE;
  3744. }
  3745. /* Start a new range for which we only have the low address. */
  3746. static bfd_boolean
  3747. ieee_start_range (struct ieee_handle *info, bfd_vma low)
  3748. {
  3749. struct ieee_range *r;
  3750. r = (struct ieee_range *) xmalloc (sizeof *r);
  3751. memset (r, 0, sizeof *r);
  3752. r->low = low;
  3753. r->next = info->pending_ranges;
  3754. info->pending_ranges = r;
  3755. return TRUE;
  3756. }
  3757. /* Finish a range started by ieee_start_range. */
  3758. static bfd_boolean
  3759. ieee_end_range (struct ieee_handle *info, bfd_vma high)
  3760. {
  3761. struct ieee_range *r;
  3762. bfd_vma low;
  3763. assert (info->pending_ranges != NULL);
  3764. r = info->pending_ranges;
  3765. low = r->low;
  3766. info->pending_ranges = r->next;
  3767. free (r);
  3768. return ieee_add_range (info, FALSE, low, high);
  3769. }
  3770. /* Start defining a type. */
  3771. static bfd_boolean
  3772. ieee_define_type (struct ieee_handle *info, unsigned int size,
  3773. bfd_boolean unsignedp, bfd_boolean localp)
  3774. {
  3775. return ieee_define_named_type (info, (const char *) NULL,
  3776. (unsigned int) -1, size, unsignedp,
  3777. localp, (struct ieee_buflist *) NULL);
  3778. }
  3779. /* Start defining a named type. */
  3780. static bfd_boolean
  3781. ieee_define_named_type (struct ieee_handle *info, const char *name,
  3782. unsigned int indx, unsigned int size,
  3783. bfd_boolean unsignedp, bfd_boolean localp,
  3784. struct ieee_buflist *buflist)
  3785. {
  3786. unsigned int type_indx;
  3787. unsigned int name_indx;
  3788. if (indx != (unsigned int) -1)
  3789. type_indx = indx;
  3790. else
  3791. {
  3792. type_indx = info->type_indx;
  3793. ++info->type_indx;
  3794. }
  3795. name_indx = info->name_indx;
  3796. ++info->name_indx;
  3797. if (name == NULL)
  3798. name = "";
  3799. /* If we were given a buffer, use it; otherwise, use either the
  3800. local or the global type information, and make sure that the type
  3801. block is started. */
  3802. if (buflist != NULL)
  3803. {
  3804. if (! ieee_change_buffer (info, buflist))
  3805. return FALSE;
  3806. }
  3807. else if (localp)
  3808. {
  3809. if (! ieee_buffer_emptyp (&info->types))
  3810. {
  3811. if (! ieee_change_buffer (info, &info->types))
  3812. return FALSE;
  3813. }
  3814. else
  3815. {
  3816. if (! ieee_change_buffer (info, &info->types)
  3817. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  3818. || ! ieee_write_byte (info, 1)
  3819. || ! ieee_write_number (info, 0)
  3820. || ! ieee_write_id (info, info->modname))
  3821. return FALSE;
  3822. }
  3823. }
  3824. else
  3825. {
  3826. if (! ieee_buffer_emptyp (&info->global_types))
  3827. {
  3828. if (! ieee_change_buffer (info, &info->global_types))
  3829. return FALSE;
  3830. }
  3831. else
  3832. {
  3833. if (! ieee_change_buffer (info, &info->global_types)
  3834. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  3835. || ! ieee_write_byte (info, 2)
  3836. || ! ieee_write_number (info, 0)
  3837. || ! ieee_write_id (info, ""))
  3838. return FALSE;
  3839. }
  3840. }
  3841. /* Push the new type on the type stack, write out an NN record, and
  3842. write out the start of a TY record. The caller will then finish
  3843. the TY record. */
  3844. if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
  3845. return FALSE;
  3846. return (ieee_write_byte (info, (int) ieee_nn_record)
  3847. && ieee_write_number (info, name_indx)
  3848. && ieee_write_id (info, name)
  3849. && ieee_write_byte (info, (int) ieee_ty_record_enum)
  3850. && ieee_write_number (info, type_indx)
  3851. && ieee_write_byte (info, 0xce)
  3852. && ieee_write_number (info, name_indx));
  3853. }
  3854. /* Get an entry to the list of modified versions of a type. */
  3855. static struct ieee_modified_type *
  3856. ieee_get_modified_info (struct ieee_handle *info, unsigned int indx)
  3857. {
  3858. if (indx >= info->modified_alloc)
  3859. {
  3860. unsigned int nalloc;
  3861. nalloc = info->modified_alloc;
  3862. if (nalloc == 0)
  3863. nalloc = 16;
  3864. while (indx >= nalloc)
  3865. nalloc *= 2;
  3866. info->modified = ((struct ieee_modified_type *)
  3867. xrealloc (info->modified,
  3868. nalloc * sizeof *info->modified));
  3869. memset (info->modified + info->modified_alloc, 0,
  3870. (nalloc - info->modified_alloc) * sizeof *info->modified);
  3871. info->modified_alloc = nalloc;
  3872. }
  3873. return info->modified + indx;
  3874. }
  3875. /* Routines for the hash table mapping names to types. */
  3876. /* Initialize an entry in the hash table. */
  3877. static struct bfd_hash_entry *
  3878. ieee_name_type_newfunc (struct bfd_hash_entry *entry,
  3879. struct bfd_hash_table *table, const char *string)
  3880. {
  3881. struct ieee_name_type_hash_entry *ret =
  3882. (struct ieee_name_type_hash_entry *) entry;
  3883. /* Allocate the structure if it has not already been allocated by a
  3884. subclass. */
  3885. if (ret == NULL)
  3886. ret = ((struct ieee_name_type_hash_entry *)
  3887. bfd_hash_allocate (table, sizeof *ret));
  3888. if (ret == NULL)
  3889. return NULL;
  3890. /* Call the allocation method of the superclass. */
  3891. ret = ((struct ieee_name_type_hash_entry *)
  3892. bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
  3893. if (ret)
  3894. {
  3895. /* Set local fields. */
  3896. ret->types = NULL;
  3897. }
  3898. return (struct bfd_hash_entry *) ret;
  3899. }
  3900. /* Look up an entry in the hash table. */
  3901. #define ieee_name_type_hash_lookup(table, string, create, copy) \
  3902. ((struct ieee_name_type_hash_entry *) \
  3903. bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
  3904. /* Traverse the hash table. */
  3905. #define ieee_name_type_hash_traverse(table, func, info) \
  3906. (bfd_hash_traverse \
  3907. (&(table)->root, \
  3908. (bfd_boolean (*) (struct bfd_hash_entry *, void *)) (func), \
  3909. (info)))
  3910. /* The general routine to write out IEEE debugging information. */
  3911. bfd_boolean
  3912. write_ieee_debugging_info (bfd *abfd, void *dhandle)
  3913. {
  3914. struct ieee_handle info;
  3915. asection *s;
  3916. const char *err;
  3917. struct ieee_buf *b;
  3918. memset (&info, 0, sizeof info);
  3919. info.abfd = abfd;
  3920. info.type_indx = 256;
  3921. info.name_indx = 32;
  3922. if (!bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc,
  3923. sizeof (struct ieee_name_type_hash_entry))
  3924. || !bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc,
  3925. sizeof (struct ieee_name_type_hash_entry)))
  3926. return FALSE;
  3927. if (! ieee_init_buffer (&info, &info.global_types)
  3928. || ! ieee_init_buffer (&info, &info.data)
  3929. || ! ieee_init_buffer (&info, &info.types)
  3930. || ! ieee_init_buffer (&info, &info.vars)
  3931. || ! ieee_init_buffer (&info, &info.cxx)
  3932. || ! ieee_init_buffer (&info, &info.linenos)
  3933. || ! ieee_init_buffer (&info, &info.fntype)
  3934. || ! ieee_init_buffer (&info, &info.fnargs))
  3935. return FALSE;
  3936. if (! debug_write (dhandle, &ieee_fns, (void *) &info))
  3937. return FALSE;
  3938. if (info.filename != NULL)
  3939. {
  3940. if (! ieee_finish_compilation_unit (&info))
  3941. return FALSE;
  3942. }
  3943. /* Put any undefined tags in the global typedef information. */
  3944. info.error = FALSE;
  3945. ieee_name_type_hash_traverse (&info.tags,
  3946. ieee_write_undefined_tag,
  3947. (void *) &info);
  3948. if (info.error)
  3949. return FALSE;
  3950. /* Prepend the global typedef information to the other data. */
  3951. if (! ieee_buffer_emptyp (&info.global_types))
  3952. {
  3953. /* The HP debugger seems to have a bug in which it ignores the
  3954. last entry in the global types, so we add a dummy entry. */
  3955. if (! ieee_change_buffer (&info, &info.global_types)
  3956. || ! ieee_write_byte (&info, (int) ieee_nn_record)
  3957. || ! ieee_write_number (&info, info.name_indx)
  3958. || ! ieee_write_id (&info, "")
  3959. || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
  3960. || ! ieee_write_number (&info, info.type_indx)
  3961. || ! ieee_write_byte (&info, 0xce)
  3962. || ! ieee_write_number (&info, info.name_indx)
  3963. || ! ieee_write_number (&info, 'P')
  3964. || ! ieee_write_number (&info, (int) builtin_void + 32)
  3965. || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
  3966. return FALSE;
  3967. if (! ieee_append_buffer (&info, &info.global_types, &info.data))
  3968. return FALSE;
  3969. info.data = info.global_types;
  3970. }
  3971. /* Make sure that we have declare BB11 blocks for each range in the
  3972. file. They are added to info->vars. */
  3973. info.error = FALSE;
  3974. if (! ieee_init_buffer (&info, &info.vars))
  3975. return FALSE;
  3976. bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (void *) &info);
  3977. if (info.error)
  3978. return FALSE;
  3979. if (! ieee_buffer_emptyp (&info.vars))
  3980. {
  3981. if (! ieee_change_buffer (&info, &info.vars)
  3982. || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
  3983. return FALSE;
  3984. if (! ieee_append_buffer (&info, &info.data, &info.vars))
  3985. return FALSE;
  3986. }
  3987. /* Now all the data is in info.data. Write it out to the BFD. We
  3988. normally would need to worry about whether all the other sections
  3989. are set up yet, but the IEEE backend will handle this particular
  3990. case correctly regardless. */
  3991. if (ieee_buffer_emptyp (&info.data))
  3992. {
  3993. /* There is no debugging information. */
  3994. return TRUE;
  3995. }
  3996. err = NULL;
  3997. s = bfd_make_section_with_flags (abfd, ".debug",
  3998. SEC_DEBUGGING | SEC_HAS_CONTENTS);
  3999. if (s == NULL)
  4000. err = "bfd_make_section";
  4001. if (err == NULL)
  4002. {
  4003. bfd_size_type size;
  4004. size = 0;
  4005. for (b = info.data.head; b != NULL; b = b->next)
  4006. size += b->c;
  4007. if (! bfd_set_section_size (abfd, s, size))
  4008. err = "bfd_set_section_size";
  4009. }
  4010. if (err == NULL)
  4011. {
  4012. file_ptr offset;
  4013. offset = 0;
  4014. for (b = info.data.head; b != NULL; b = b->next)
  4015. {
  4016. if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
  4017. {
  4018. err = "bfd_set_section_contents";
  4019. break;
  4020. }
  4021. offset += b->c;
  4022. }
  4023. }
  4024. if (err != NULL)
  4025. {
  4026. fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
  4027. bfd_errmsg (bfd_get_error ()));
  4028. return FALSE;
  4029. }
  4030. bfd_hash_table_free (&info.typedefs.root);
  4031. bfd_hash_table_free (&info.tags.root);
  4032. return TRUE;
  4033. }
  4034. /* Write out information for an undefined tag. This is called via
  4035. ieee_name_type_hash_traverse. */
  4036. static bfd_boolean
  4037. ieee_write_undefined_tag (struct ieee_name_type_hash_entry *h, void *p)
  4038. {
  4039. struct ieee_handle *info = (struct ieee_handle *) p;
  4040. struct ieee_name_type *nt;
  4041. for (nt = h->types; nt != NULL; nt = nt->next)
  4042. {
  4043. unsigned int name_indx;
  4044. char code;
  4045. if (nt->kind == DEBUG_KIND_ILLEGAL)
  4046. continue;
  4047. if (ieee_buffer_emptyp (&info->global_types))
  4048. {
  4049. if (! ieee_change_buffer (info, &info->global_types)
  4050. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  4051. || ! ieee_write_byte (info, 2)
  4052. || ! ieee_write_number (info, 0)
  4053. || ! ieee_write_id (info, ""))
  4054. {
  4055. info->error = TRUE;
  4056. return FALSE;
  4057. }
  4058. }
  4059. else
  4060. {
  4061. if (! ieee_change_buffer (info, &info->global_types))
  4062. {
  4063. info->error = TRUE;
  4064. return FALSE;
  4065. }
  4066. }
  4067. name_indx = info->name_indx;
  4068. ++info->name_indx;
  4069. if (! ieee_write_byte (info, (int) ieee_nn_record)
  4070. || ! ieee_write_number (info, name_indx)
  4071. || ! ieee_write_id (info, nt->type.name)
  4072. || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
  4073. || ! ieee_write_number (info, nt->type.indx)
  4074. || ! ieee_write_byte (info, 0xce)
  4075. || ! ieee_write_number (info, name_indx))
  4076. {
  4077. info->error = TRUE;
  4078. return FALSE;
  4079. }
  4080. switch (nt->kind)
  4081. {
  4082. default:
  4083. abort ();
  4084. info->error = TRUE;
  4085. return FALSE;
  4086. case DEBUG_KIND_STRUCT:
  4087. case DEBUG_KIND_CLASS:
  4088. code = 'S';
  4089. break;
  4090. case DEBUG_KIND_UNION:
  4091. case DEBUG_KIND_UNION_CLASS:
  4092. code = 'U';
  4093. break;
  4094. case DEBUG_KIND_ENUM:
  4095. code = 'E';
  4096. break;
  4097. }
  4098. if (! ieee_write_number (info, code)
  4099. || ! ieee_write_number (info, 0))
  4100. {
  4101. info->error = TRUE;
  4102. return FALSE;
  4103. }
  4104. }
  4105. return TRUE;
  4106. }
  4107. /* Start writing out information for a compilation unit. */
  4108. static bfd_boolean
  4109. ieee_start_compilation_unit (void *p, const char *filename)
  4110. {
  4111. struct ieee_handle *info = (struct ieee_handle *) p;
  4112. const char *modname;
  4113. #ifdef HAVE_DOS_BASED_FILE_SYSTEM
  4114. const char *backslash;
  4115. #endif
  4116. char *c, *s;
  4117. if (info->filename != NULL)
  4118. {
  4119. if (! ieee_finish_compilation_unit (info))
  4120. return FALSE;
  4121. }
  4122. info->filename = filename;
  4123. modname = strrchr (filename, '/');
  4124. #ifdef HAVE_DOS_BASED_FILE_SYSTEM
  4125. /* We could have a mixed forward/back slash case. */
  4126. backslash = strrchr (filename, '\\');
  4127. if (modname == NULL || (backslash != NULL && backslash > modname))
  4128. modname = backslash;
  4129. #endif
  4130. if (modname != NULL)
  4131. ++modname;
  4132. #ifdef HAVE_DOS_BASED_FILE_SYSTEM
  4133. else if (filename[0] && filename[1] == ':')
  4134. modname = filename + 2;
  4135. #endif
  4136. else
  4137. modname = filename;
  4138. c = xstrdup (modname);
  4139. s = strrchr (c, '.');
  4140. if (s != NULL)
  4141. *s = '\0';
  4142. info->modname = c;
  4143. if (! ieee_init_buffer (info, &info->types)
  4144. || ! ieee_init_buffer (info, &info->vars)
  4145. || ! ieee_init_buffer (info, &info->cxx)
  4146. || ! ieee_init_buffer (info, &info->linenos))
  4147. return FALSE;
  4148. info->ranges = NULL;
  4149. /* Always include a BB1 and a BB3 block. That is what the output of
  4150. the MRI linker seems to look like. */
  4151. if (! ieee_change_buffer (info, &info->types)
  4152. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  4153. || ! ieee_write_byte (info, 1)
  4154. || ! ieee_write_number (info, 0)
  4155. || ! ieee_write_id (info, info->modname))
  4156. return FALSE;
  4157. ++info->name_indx;
  4158. if (! ieee_change_buffer (info, &info->vars)
  4159. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  4160. || ! ieee_write_byte (info, 3)
  4161. || ! ieee_write_number (info, 0)
  4162. || ! ieee_write_id (info, info->modname))
  4163. return FALSE;
  4164. return TRUE;
  4165. }
  4166. /* Finish up a compilation unit. */
  4167. static bfd_boolean
  4168. ieee_finish_compilation_unit (struct ieee_handle *info)
  4169. {
  4170. struct ieee_range *r;
  4171. if (! ieee_buffer_emptyp (&info->types))
  4172. {
  4173. if (! ieee_change_buffer (info, &info->types)
  4174. || ! ieee_write_byte (info, (int) ieee_be_record_enum))
  4175. return FALSE;
  4176. }
  4177. if (! ieee_buffer_emptyp (&info->cxx))
  4178. {
  4179. /* Append any C++ information to the global function and
  4180. variable information. */
  4181. assert (! ieee_buffer_emptyp (&info->vars));
  4182. if (! ieee_change_buffer (info, &info->vars))
  4183. return FALSE;
  4184. /* We put the pmisc records in a dummy procedure, just as the
  4185. MRI compiler does. */
  4186. if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
  4187. || ! ieee_write_byte (info, 6)
  4188. || ! ieee_write_number (info, 0)
  4189. || ! ieee_write_id (info, "__XRYCPP")
  4190. || ! ieee_write_number (info, 0)
  4191. || ! ieee_write_number (info, 0)
  4192. || ! ieee_write_number (info, info->highaddr - 1)
  4193. || ! ieee_append_buffer (info, &info->vars, &info->cxx)
  4194. || ! ieee_change_buffer (info, &info->vars)
  4195. || ! ieee_write_byte (info, (int) ieee_be_record_enum)
  4196. || ! ieee_write_number (info, info->highaddr - 1))
  4197. return FALSE;
  4198. }
  4199. if (! ieee_buffer_emptyp (&info->vars))
  4200. {
  4201. if (! ieee_change_buffer (info, &info->vars)
  4202. || ! ieee_write_byte (info, (int) ieee_be_record_enum))
  4203. return FALSE;
  4204. }
  4205. if (info->pending_lineno_filename != NULL)
  4206. {
  4207. /* Force out the pending line number. */
  4208. if (! ieee_lineno ((void *) info, (const char *) NULL, 0, (bfd_vma) -1))
  4209. return FALSE;
  4210. }
  4211. if (! ieee_buffer_emptyp (&info->linenos))
  4212. {
  4213. if (! ieee_change_buffer (info, &info->linenos)
  4214. || ! ieee_write_byte (info, (int) ieee_be_record_enum))
  4215. return FALSE;
  4216. if (filename_cmp (info->filename, info->lineno_filename) != 0)
  4217. {
  4218. /* We were not in the main file. We just closed the
  4219. included line number block, and now we must close the
  4220. main line number block. */
  4221. if (! ieee_write_byte (info, (int) ieee_be_record_enum))
  4222. return FALSE;
  4223. }
  4224. }
  4225. if (! ieee_append_buffer (info, &info->data, &info->types)
  4226. || ! ieee_append_buffer (info, &info->data, &info->vars)
  4227. || ! ieee_append_buffer (info, &info->data, &info->linenos))
  4228. return FALSE;
  4229. /* Build BB10/BB11 blocks based on the ranges we recorded. */
  4230. if (! ieee_change_buffer (info, &info->data))
  4231. return FALSE;
  4232. if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
  4233. || ! ieee_write_byte (info, 10)
  4234. || ! ieee_write_number (info, 0)
  4235. || ! ieee_write_id (info, info->modname)
  4236. || ! ieee_write_id (info, "")
  4237. || ! ieee_write_number (info, 0)
  4238. || ! ieee_write_id (info, "GNU objcopy"))
  4239. return FALSE;
  4240. for (r = info->ranges; r != NULL; r = r->next)
  4241. {
  4242. bfd_vma low, high;
  4243. asection *s;
  4244. int kind;
  4245. low = r->low;
  4246. high = r->high;
  4247. /* Find the section corresponding to this range. */
  4248. for (s = info->abfd->sections; s != NULL; s = s->next)
  4249. {
  4250. if (bfd_get_section_vma (info->abfd, s) <= low
  4251. && high <= (bfd_get_section_vma (info->abfd, s)
  4252. + bfd_section_size (info->abfd, s)))
  4253. break;
  4254. }
  4255. if (s == NULL)
  4256. {
  4257. /* Just ignore this range. */
  4258. continue;
  4259. }
  4260. /* Coalesce ranges if it seems reasonable. */
  4261. while (r->next != NULL
  4262. && high + 0x1000 >= r->next->low
  4263. && (r->next->high
  4264. <= (bfd_get_section_vma (info->abfd, s)
  4265. + bfd_section_size (info->abfd, s))))
  4266. {
  4267. r = r->next;
  4268. high = r->high;
  4269. }
  4270. if ((s->flags & SEC_CODE) != 0)
  4271. kind = 1;
  4272. else if ((s->flags & SEC_READONLY) != 0)
  4273. kind = 3;
  4274. else
  4275. kind = 2;
  4276. if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
  4277. || ! ieee_write_byte (info, 11)
  4278. || ! ieee_write_number (info, 0)
  4279. || ! ieee_write_id (info, "")
  4280. || ! ieee_write_number (info, kind)
  4281. || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
  4282. || ! ieee_write_number (info, low)
  4283. || ! ieee_write_byte (info, (int) ieee_be_record_enum)
  4284. || ! ieee_write_number (info, high - low))
  4285. return FALSE;
  4286. /* Add this range to the list of global ranges. */
  4287. if (! ieee_add_range (info, TRUE, low, high))
  4288. return FALSE;
  4289. }
  4290. if (! ieee_write_byte (info, (int) ieee_be_record_enum))
  4291. return FALSE;
  4292. return TRUE;
  4293. }
  4294. /* Add BB11 blocks describing each range that we have not already
  4295. described. */
  4296. static void
  4297. ieee_add_bb11_blocks (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *data)
  4298. {
  4299. struct ieee_handle *info = (struct ieee_handle *) data;
  4300. bfd_vma low, high;
  4301. struct ieee_range *r;
  4302. low = bfd_get_section_vma (abfd, sec);
  4303. high = low + bfd_section_size (abfd, sec);
  4304. /* Find the first range at or after this section. The ranges are
  4305. sorted by address. */
  4306. for (r = info->global_ranges; r != NULL; r = r->next)
  4307. if (r->high > low)
  4308. break;
  4309. while (low < high)
  4310. {
  4311. if (r == NULL || r->low >= high)
  4312. {
  4313. if (! ieee_add_bb11 (info, sec, low, high))
  4314. info->error = TRUE;
  4315. return;
  4316. }
  4317. if (low < r->low
  4318. && r->low - low > 0x100)
  4319. {
  4320. if (! ieee_add_bb11 (info, sec, low, r->low))
  4321. {
  4322. info->error = TRUE;
  4323. return;
  4324. }
  4325. }
  4326. low = r->high;
  4327. r = r->next;
  4328. }
  4329. }
  4330. /* Add a single BB11 block for a range. We add it to info->vars. */
  4331. static bfd_boolean
  4332. ieee_add_bb11 (struct ieee_handle *info, asection *sec, bfd_vma low,
  4333. bfd_vma high)
  4334. {
  4335. int kind;
  4336. if (! ieee_buffer_emptyp (&info->vars))
  4337. {
  4338. if (! ieee_change_buffer (info, &info->vars))
  4339. return FALSE;
  4340. }
  4341. else
  4342. {
  4343. const char *filename, *modname;
  4344. #ifdef HAVE_DOS_BASED_FILE_SYSTEM
  4345. const char *backslash;
  4346. #endif
  4347. char *c, *s;
  4348. /* Start the enclosing BB10 block. */
  4349. filename = bfd_get_filename (info->abfd);
  4350. modname = strrchr (filename, '/');
  4351. #ifdef HAVE_DOS_BASED_FILE_SYSTEM
  4352. backslash = strrchr (filename, '\\');
  4353. if (modname == NULL || (backslash != NULL && backslash > modname))
  4354. modname = backslash;
  4355. #endif
  4356. if (modname != NULL)
  4357. ++modname;
  4358. #ifdef HAVE_DOS_BASED_FILE_SYSTEM
  4359. else if (filename[0] && filename[1] == ':')
  4360. modname = filename + 2;
  4361. #endif
  4362. else
  4363. modname = filename;
  4364. c = xstrdup (modname);
  4365. s = strrchr (c, '.');
  4366. if (s != NULL)
  4367. *s = '\0';
  4368. if (! ieee_change_buffer (info, &info->vars)
  4369. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  4370. || ! ieee_write_byte (info, 10)
  4371. || ! ieee_write_number (info, 0)
  4372. || ! ieee_write_id (info, c)
  4373. || ! ieee_write_id (info, "")
  4374. || ! ieee_write_number (info, 0)
  4375. || ! ieee_write_id (info, "GNU objcopy"))
  4376. {
  4377. free (c);
  4378. return FALSE;
  4379. }
  4380. free (c);
  4381. }
  4382. if ((sec->flags & SEC_CODE) != 0)
  4383. kind = 1;
  4384. else if ((sec->flags & SEC_READONLY) != 0)
  4385. kind = 3;
  4386. else
  4387. kind = 2;
  4388. if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
  4389. || ! ieee_write_byte (info, 11)
  4390. || ! ieee_write_number (info, 0)
  4391. || ! ieee_write_id (info, "")
  4392. || ! ieee_write_number (info, kind)
  4393. || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
  4394. || ! ieee_write_number (info, low)
  4395. || ! ieee_write_byte (info, (int) ieee_be_record_enum)
  4396. || ! ieee_write_number (info, high - low))
  4397. return FALSE;
  4398. return TRUE;
  4399. }
  4400. /* Start recording information from a particular source file. This is
  4401. used to record which file defined which types, variables, etc. It
  4402. is not used for line numbers, since the lineno entry point passes
  4403. down the file name anyhow. IEEE debugging information doesn't seem
  4404. to store this information anywhere. */
  4405. static bfd_boolean
  4406. ieee_start_source (void *p ATTRIBUTE_UNUSED,
  4407. const char *filename ATTRIBUTE_UNUSED)
  4408. {
  4409. return TRUE;
  4410. }
  4411. /* Make an empty type. */
  4412. static bfd_boolean
  4413. ieee_empty_type (void *p)
  4414. {
  4415. struct ieee_handle *info = (struct ieee_handle *) p;
  4416. return ieee_push_type (info, (int) builtin_unknown, 0, FALSE, FALSE);
  4417. }
  4418. /* Make a void type. */
  4419. static bfd_boolean
  4420. ieee_void_type (void *p)
  4421. {
  4422. struct ieee_handle *info = (struct ieee_handle *) p;
  4423. return ieee_push_type (info, (int) builtin_void, 0, FALSE, FALSE);
  4424. }
  4425. /* Make an integer type. */
  4426. static bfd_boolean
  4427. ieee_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
  4428. {
  4429. struct ieee_handle *info = (struct ieee_handle *) p;
  4430. unsigned int indx;
  4431. switch (size)
  4432. {
  4433. case 1:
  4434. indx = (int) builtin_signed_char;
  4435. break;
  4436. case 2:
  4437. indx = (int) builtin_signed_short_int;
  4438. break;
  4439. case 4:
  4440. indx = (int) builtin_signed_long;
  4441. break;
  4442. case 8:
  4443. indx = (int) builtin_signed_long_long;
  4444. break;
  4445. default:
  4446. fprintf (stderr, _("IEEE unsupported integer type size %u\n"), size);
  4447. return FALSE;
  4448. }
  4449. if (unsignedp)
  4450. ++indx;
  4451. return ieee_push_type (info, indx, size, unsignedp, FALSE);
  4452. }
  4453. /* Make a floating point type. */
  4454. static bfd_boolean
  4455. ieee_float_type (void *p, unsigned int size)
  4456. {
  4457. struct ieee_handle *info = (struct ieee_handle *) p;
  4458. unsigned int indx;
  4459. switch (size)
  4460. {
  4461. case 4:
  4462. indx = (int) builtin_float;
  4463. break;
  4464. case 8:
  4465. indx = (int) builtin_double;
  4466. break;
  4467. case 12:
  4468. /* FIXME: This size really depends upon the processor. */
  4469. indx = (int) builtin_long_double;
  4470. break;
  4471. case 16:
  4472. indx = (int) builtin_long_long_double;
  4473. break;
  4474. default:
  4475. fprintf (stderr, _("IEEE unsupported float type size %u\n"), size);
  4476. return FALSE;
  4477. }
  4478. return ieee_push_type (info, indx, size, FALSE, FALSE);
  4479. }
  4480. /* Make a complex type. */
  4481. static bfd_boolean
  4482. ieee_complex_type (void *p, unsigned int size)
  4483. {
  4484. struct ieee_handle *info = (struct ieee_handle *) p;
  4485. char code;
  4486. switch (size)
  4487. {
  4488. case 4:
  4489. if (info->complex_float_index != 0)
  4490. return ieee_push_type (info, info->complex_float_index, size * 2,
  4491. FALSE, FALSE);
  4492. code = 'c';
  4493. break;
  4494. case 12:
  4495. case 16:
  4496. /* These cases can be output by gcc -gstabs. Outputting the
  4497. wrong type is better than crashing. */
  4498. case 8:
  4499. if (info->complex_double_index != 0)
  4500. return ieee_push_type (info, info->complex_double_index, size * 2,
  4501. FALSE, FALSE);
  4502. code = 'd';
  4503. break;
  4504. default:
  4505. fprintf (stderr, _("IEEE unsupported complex type size %u\n"), size);
  4506. return FALSE;
  4507. }
  4508. /* FIXME: I don't know what the string is for. */
  4509. if (! ieee_define_type (info, size * 2, FALSE, FALSE)
  4510. || ! ieee_write_number (info, code)
  4511. || ! ieee_write_id (info, ""))
  4512. return FALSE;
  4513. if (size == 4)
  4514. info->complex_float_index = info->type_stack->type.indx;
  4515. else
  4516. info->complex_double_index = info->type_stack->type.indx;
  4517. return TRUE;
  4518. }
  4519. /* Make a boolean type. IEEE doesn't support these, so we just make
  4520. an integer type instead. */
  4521. static bfd_boolean
  4522. ieee_bool_type (void *p, unsigned int size)
  4523. {
  4524. return ieee_int_type (p, size, TRUE);
  4525. }
  4526. /* Make an enumeration. */
  4527. static bfd_boolean
  4528. ieee_enum_type (void *p, const char *tag, const char **names,
  4529. bfd_signed_vma *vals)
  4530. {
  4531. struct ieee_handle *info = (struct ieee_handle *) p;
  4532. struct ieee_defined_enum *e;
  4533. bfd_boolean localp, simple;
  4534. unsigned int indx;
  4535. int i = 0;
  4536. localp = FALSE;
  4537. indx = (unsigned int) -1;
  4538. for (e = info->enums; e != NULL; e = e->next)
  4539. {
  4540. if (tag == NULL)
  4541. {
  4542. if (e->tag != NULL)
  4543. continue;
  4544. }
  4545. else
  4546. {
  4547. if (e->tag == NULL
  4548. || tag[0] != e->tag[0]
  4549. || strcmp (tag, e->tag) != 0)
  4550. continue;
  4551. }
  4552. if (! e->defined)
  4553. {
  4554. /* This enum tag has been seen but not defined. */
  4555. indx = e->indx;
  4556. break;
  4557. }
  4558. if (names != NULL && e->names != NULL)
  4559. {
  4560. for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
  4561. {
  4562. if (names[i][0] != e->names[i][0]
  4563. || vals[i] != e->vals[i]
  4564. || strcmp (names[i], e->names[i]) != 0)
  4565. break;
  4566. }
  4567. }
  4568. if ((names == NULL && e->names == NULL)
  4569. || (names != NULL
  4570. && e->names != NULL
  4571. && names[i] == NULL
  4572. && e->names[i] == NULL))
  4573. {
  4574. /* We've seen this enum before. */
  4575. return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
  4576. }
  4577. if (tag != NULL)
  4578. {
  4579. /* We've already seen an enum of the same name, so we must make
  4580. sure to output this one locally. */
  4581. localp = TRUE;
  4582. break;
  4583. }
  4584. }
  4585. /* If this is a simple enumeration, in which the values start at 0
  4586. and always increment by 1, we can use type E. Otherwise we must
  4587. use type N. */
  4588. simple = TRUE;
  4589. if (names != NULL)
  4590. {
  4591. for (i = 0; names[i] != NULL; i++)
  4592. {
  4593. if (vals[i] != i)
  4594. {
  4595. simple = FALSE;
  4596. break;
  4597. }
  4598. }
  4599. }
  4600. if (! ieee_define_named_type (info, tag, indx, 0, TRUE, localp,
  4601. (struct ieee_buflist *) NULL)
  4602. || ! ieee_write_number (info, simple ? 'E' : 'N'))
  4603. return FALSE;
  4604. if (simple)
  4605. {
  4606. /* FIXME: This is supposed to be the enumeration size, but we
  4607. don't store that. */
  4608. if (! ieee_write_number (info, 4))
  4609. return FALSE;
  4610. }
  4611. if (names != NULL)
  4612. {
  4613. for (i = 0; names[i] != NULL; i++)
  4614. {
  4615. if (! ieee_write_id (info, names[i]))
  4616. return FALSE;
  4617. if (! simple)
  4618. {
  4619. if (! ieee_write_number (info, vals[i]))
  4620. return FALSE;
  4621. }
  4622. }
  4623. }
  4624. if (! localp)
  4625. {
  4626. if (indx == (unsigned int) -1)
  4627. {
  4628. e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
  4629. memset (e, 0, sizeof *e);
  4630. e->indx = info->type_stack->type.indx;
  4631. e->tag = tag;
  4632. e->next = info->enums;
  4633. info->enums = e;
  4634. }
  4635. e->names = names;
  4636. e->vals = vals;
  4637. e->defined = TRUE;
  4638. }
  4639. return TRUE;
  4640. }
  4641. /* Make a pointer type. */
  4642. static bfd_boolean
  4643. ieee_pointer_type (void *p)
  4644. {
  4645. struct ieee_handle *info = (struct ieee_handle *) p;
  4646. bfd_boolean localp;
  4647. unsigned int indx;
  4648. struct ieee_modified_type *m = NULL;
  4649. localp = info->type_stack->type.localp;
  4650. indx = ieee_pop_type (info);
  4651. /* A pointer to a simple builtin type can be obtained by adding 32.
  4652. FIXME: Will this be a short pointer, and will that matter? */
  4653. if (indx < 32)
  4654. return ieee_push_type (info, indx + 32, 0, TRUE, FALSE);
  4655. if (! localp)
  4656. {
  4657. m = ieee_get_modified_info ((struct ieee_handle *) p, indx);
  4658. if (m == NULL)
  4659. return FALSE;
  4660. /* FIXME: The size should depend upon the architecture. */
  4661. if (m->pointer > 0)
  4662. return ieee_push_type (info, m->pointer, 4, TRUE, FALSE);
  4663. }
  4664. if (! ieee_define_type (info, 4, TRUE, localp)
  4665. || ! ieee_write_number (info, 'P')
  4666. || ! ieee_write_number (info, indx))
  4667. return FALSE;
  4668. if (! localp)
  4669. m->pointer = info->type_stack->type.indx;
  4670. return TRUE;
  4671. }
  4672. /* Make a function type. This will be called for a method, but we
  4673. don't want to actually add it to the type table in that case. We
  4674. handle this by defining the type in a private buffer, and only
  4675. adding that buffer to the typedef block if we are going to use it. */
  4676. static bfd_boolean
  4677. ieee_function_type (void *p, int argcount, bfd_boolean varargs)
  4678. {
  4679. struct ieee_handle *info = (struct ieee_handle *) p;
  4680. bfd_boolean localp;
  4681. unsigned int *args = NULL;
  4682. int i;
  4683. unsigned int retindx;
  4684. struct ieee_buflist fndef;
  4685. struct ieee_modified_type *m;
  4686. localp = FALSE;
  4687. if (argcount > 0)
  4688. {
  4689. args = (unsigned int *) xmalloc (argcount * sizeof *args);
  4690. for (i = argcount - 1; i >= 0; i--)
  4691. {
  4692. if (info->type_stack->type.localp)
  4693. localp = TRUE;
  4694. args[i] = ieee_pop_type (info);
  4695. }
  4696. }
  4697. else if (argcount < 0)
  4698. varargs = FALSE;
  4699. if (info->type_stack->type.localp)
  4700. localp = TRUE;
  4701. retindx = ieee_pop_type (info);
  4702. m = NULL;
  4703. if (argcount < 0 && ! localp)
  4704. {
  4705. m = ieee_get_modified_info ((struct ieee_handle *) p, retindx);
  4706. if (m == NULL)
  4707. return FALSE;
  4708. if (m->function > 0)
  4709. return ieee_push_type (info, m->function, 0, TRUE, FALSE);
  4710. }
  4711. /* An attribute of 0x41 means that the frame and push mask are
  4712. unknown. */
  4713. if (! ieee_init_buffer (info, &fndef)
  4714. || ! ieee_define_named_type (info, (const char *) NULL,
  4715. (unsigned int) -1, 0, TRUE, localp,
  4716. &fndef)
  4717. || ! ieee_write_number (info, 'x')
  4718. || ! ieee_write_number (info, 0x41)
  4719. || ! ieee_write_number (info, 0)
  4720. || ! ieee_write_number (info, 0)
  4721. || ! ieee_write_number (info, retindx)
  4722. || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
  4723. {
  4724. free (args);
  4725. return FALSE;
  4726. }
  4727. if (argcount > 0)
  4728. {
  4729. for (i = 0; i < argcount; i++)
  4730. if (! ieee_write_number (info, args[i]))
  4731. return FALSE;
  4732. free (args);
  4733. }
  4734. if (varargs)
  4735. {
  4736. /* A varargs function is represented by writing out the last
  4737. argument as type void *, although this makes little sense. */
  4738. if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
  4739. return FALSE;
  4740. }
  4741. if (! ieee_write_number (info, 0))
  4742. return FALSE;
  4743. /* We wrote the information into fndef, in case we don't need it.
  4744. It will be appended to info->types by ieee_pop_type. */
  4745. info->type_stack->type.fndef = fndef;
  4746. if (m != NULL)
  4747. m->function = info->type_stack->type.indx;
  4748. return TRUE;
  4749. }
  4750. /* Make a reference type. */
  4751. static bfd_boolean
  4752. ieee_reference_type (void *p)
  4753. {
  4754. struct ieee_handle *info = (struct ieee_handle *) p;
  4755. /* IEEE appears to record a normal pointer type, and then use a
  4756. pmisc record to indicate that it is really a reference. */
  4757. if (! ieee_pointer_type (p))
  4758. return FALSE;
  4759. info->type_stack->type.referencep = TRUE;
  4760. return TRUE;
  4761. }
  4762. /* Make a range type. */
  4763. static bfd_boolean
  4764. ieee_range_type (void *p, bfd_signed_vma low, bfd_signed_vma high)
  4765. {
  4766. struct ieee_handle *info = (struct ieee_handle *) p;
  4767. unsigned int size;
  4768. bfd_boolean unsignedp, localp;
  4769. size = info->type_stack->type.size;
  4770. unsignedp = info->type_stack->type.unsignedp;
  4771. localp = info->type_stack->type.localp;
  4772. ieee_pop_unused_type (info);
  4773. return (ieee_define_type (info, size, unsignedp, localp)
  4774. && ieee_write_number (info, 'R')
  4775. && ieee_write_number (info, (bfd_vma) low)
  4776. && ieee_write_number (info, (bfd_vma) high)
  4777. && ieee_write_number (info, unsignedp ? 0 : 1)
  4778. && ieee_write_number (info, size));
  4779. }
  4780. /* Make an array type. */
  4781. static bfd_boolean
  4782. ieee_array_type (void *p, bfd_signed_vma low, bfd_signed_vma high,
  4783. bfd_boolean stringp ATTRIBUTE_UNUSED)
  4784. {
  4785. struct ieee_handle *info = (struct ieee_handle *) p;
  4786. unsigned int eleindx;
  4787. bfd_boolean localp;
  4788. unsigned int size;
  4789. struct ieee_modified_type *m = NULL;
  4790. struct ieee_modified_array_type *a;
  4791. /* IEEE does not store the range, so we just ignore it. */
  4792. ieee_pop_unused_type (info);
  4793. localp = info->type_stack->type.localp;
  4794. size = info->type_stack->type.size;
  4795. eleindx = ieee_pop_type (info);
  4796. /* If we don't know the range, treat the size as exactly one
  4797. element. */
  4798. if (low < high)
  4799. size *= (high - low) + 1;
  4800. if (! localp)
  4801. {
  4802. m = ieee_get_modified_info (info, eleindx);
  4803. if (m == NULL)
  4804. return FALSE;
  4805. for (a = m->arrays; a != NULL; a = a->next)
  4806. {
  4807. if (a->low == low && a->high == high)
  4808. return ieee_push_type (info, a->indx, size, FALSE, FALSE);
  4809. }
  4810. }
  4811. if (! ieee_define_type (info, size, FALSE, localp)
  4812. || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
  4813. || ! ieee_write_number (info, eleindx))
  4814. return FALSE;
  4815. if (low != 0)
  4816. {
  4817. if (! ieee_write_number (info, low))
  4818. return FALSE;
  4819. }
  4820. if (! ieee_write_number (info, high + 1))
  4821. return FALSE;
  4822. if (! localp)
  4823. {
  4824. a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
  4825. memset (a, 0, sizeof *a);
  4826. a->indx = info->type_stack->type.indx;
  4827. a->low = low;
  4828. a->high = high;
  4829. a->next = m->arrays;
  4830. m->arrays = a;
  4831. }
  4832. return TRUE;
  4833. }
  4834. /* Make a set type. */
  4835. static bfd_boolean
  4836. ieee_set_type (void *p, bfd_boolean bitstringp ATTRIBUTE_UNUSED)
  4837. {
  4838. struct ieee_handle *info = (struct ieee_handle *) p;
  4839. bfd_boolean localp;
  4840. unsigned int eleindx;
  4841. localp = info->type_stack->type.localp;
  4842. eleindx = ieee_pop_type (info);
  4843. /* FIXME: We don't know the size, so we just use 4. */
  4844. return (ieee_define_type (info, 0, TRUE, localp)
  4845. && ieee_write_number (info, 's')
  4846. && ieee_write_number (info, 4)
  4847. && ieee_write_number (info, eleindx));
  4848. }
  4849. /* Make an offset type. */
  4850. static bfd_boolean
  4851. ieee_offset_type (void *p)
  4852. {
  4853. /* FIXME: The MRI C++ compiler does not appear to generate any
  4854. useful type information about an offset type. It just records a
  4855. pointer to member as an integer. The MRI/HP IEEE spec does
  4856. describe a pmisc record which can be used for a pointer to
  4857. member. Unfortunately, it does not describe the target type,
  4858. which seems pretty important. I'm going to punt this for now. */
  4859. return ieee_int_type (p, 4, TRUE);
  4860. }
  4861. /* Make a method type. */
  4862. static bfd_boolean
  4863. ieee_method_type (void *p, bfd_boolean domain, int argcount,
  4864. bfd_boolean varargs)
  4865. {
  4866. struct ieee_handle *info = (struct ieee_handle *) p;
  4867. /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
  4868. method, but the definition is incomplete. We just output an 'x'
  4869. type. */
  4870. if (domain)
  4871. ieee_pop_unused_type (info);
  4872. return ieee_function_type (p, argcount, varargs);
  4873. }
  4874. /* Make a const qualified type. */
  4875. static bfd_boolean
  4876. ieee_const_type (void *p)
  4877. {
  4878. struct ieee_handle *info = (struct ieee_handle *) p;
  4879. unsigned int size;
  4880. bfd_boolean unsignedp, localp;
  4881. unsigned int indx;
  4882. struct ieee_modified_type *m = NULL;
  4883. size = info->type_stack->type.size;
  4884. unsignedp = info->type_stack->type.unsignedp;
  4885. localp = info->type_stack->type.localp;
  4886. indx = ieee_pop_type (info);
  4887. if (! localp)
  4888. {
  4889. m = ieee_get_modified_info (info, indx);
  4890. if (m == NULL)
  4891. return FALSE;
  4892. if (m->const_qualified > 0)
  4893. return ieee_push_type (info, m->const_qualified, size, unsignedp,
  4894. FALSE);
  4895. }
  4896. if (! ieee_define_type (info, size, unsignedp, localp)
  4897. || ! ieee_write_number (info, 'n')
  4898. || ! ieee_write_number (info, 1)
  4899. || ! ieee_write_number (info, indx))
  4900. return FALSE;
  4901. if (! localp)
  4902. m->const_qualified = info->type_stack->type.indx;
  4903. return TRUE;
  4904. }
  4905. /* Make a volatile qualified type. */
  4906. static bfd_boolean
  4907. ieee_volatile_type (void *p)
  4908. {
  4909. struct ieee_handle *info = (struct ieee_handle *) p;
  4910. unsigned int size;
  4911. bfd_boolean unsignedp, localp;
  4912. unsigned int indx;
  4913. struct ieee_modified_type *m = NULL;
  4914. size = info->type_stack->type.size;
  4915. unsignedp = info->type_stack->type.unsignedp;
  4916. localp = info->type_stack->type.localp;
  4917. indx = ieee_pop_type (info);
  4918. if (! localp)
  4919. {
  4920. m = ieee_get_modified_info (info, indx);
  4921. if (m == NULL)
  4922. return FALSE;
  4923. if (m->volatile_qualified > 0)
  4924. return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
  4925. FALSE);
  4926. }
  4927. if (! ieee_define_type (info, size, unsignedp, localp)
  4928. || ! ieee_write_number (info, 'n')
  4929. || ! ieee_write_number (info, 2)
  4930. || ! ieee_write_number (info, indx))
  4931. return FALSE;
  4932. if (! localp)
  4933. m->volatile_qualified = info->type_stack->type.indx;
  4934. return TRUE;
  4935. }
  4936. /* Convert an enum debug_visibility into a CXXFLAGS value. */
  4937. static unsigned int
  4938. ieee_vis_to_flags (enum debug_visibility visibility)
  4939. {
  4940. switch (visibility)
  4941. {
  4942. default:
  4943. abort ();
  4944. case DEBUG_VISIBILITY_PUBLIC:
  4945. return CXXFLAGS_VISIBILITY_PUBLIC;
  4946. case DEBUG_VISIBILITY_PRIVATE:
  4947. return CXXFLAGS_VISIBILITY_PRIVATE;
  4948. case DEBUG_VISIBILITY_PROTECTED:
  4949. return CXXFLAGS_VISIBILITY_PROTECTED;
  4950. }
  4951. /*NOTREACHED*/
  4952. }
  4953. /* Start defining a struct type. We build it in the strdef field on
  4954. the stack, to avoid confusing type definitions required by the
  4955. fields with the struct type itself. */
  4956. static bfd_boolean
  4957. ieee_start_struct_type (void *p, const char *tag, unsigned int id,
  4958. bfd_boolean structp, unsigned int size)
  4959. {
  4960. struct ieee_handle *info = (struct ieee_handle *) p;
  4961. bfd_boolean localp, ignorep;
  4962. bfd_boolean copy;
  4963. char ab[20];
  4964. const char *look;
  4965. struct ieee_name_type_hash_entry *h;
  4966. struct ieee_name_type *nt, *ntlook;
  4967. struct ieee_buflist strdef;
  4968. localp = FALSE;
  4969. ignorep = FALSE;
  4970. /* We need to create a tag for internal use even if we don't want
  4971. one for external use. This will let us refer to an anonymous
  4972. struct. */
  4973. if (tag != NULL)
  4974. {
  4975. look = tag;
  4976. copy = FALSE;
  4977. }
  4978. else
  4979. {
  4980. sprintf (ab, "__anon%u", id);
  4981. look = ab;
  4982. copy = TRUE;
  4983. }
  4984. /* If we already have references to the tag, we must use the
  4985. existing type index. */
  4986. h = ieee_name_type_hash_lookup (&info->tags, look, TRUE, copy);
  4987. if (h == NULL)
  4988. return FALSE;
  4989. nt = NULL;
  4990. for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
  4991. {
  4992. if (ntlook->id == id)
  4993. nt = ntlook;
  4994. else if (! ntlook->type.localp)
  4995. {
  4996. /* We are creating a duplicate definition of a globally
  4997. defined tag. Force it to be local to avoid
  4998. confusion. */
  4999. localp = TRUE;
  5000. }
  5001. }
  5002. if (nt != NULL)
  5003. {
  5004. assert (localp == nt->type.localp);
  5005. if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
  5006. {
  5007. /* We've already seen a global definition of the type.
  5008. Ignore this new definition. */
  5009. ignorep = TRUE;
  5010. }
  5011. }
  5012. else
  5013. {
  5014. nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
  5015. memset (nt, 0, sizeof *nt);
  5016. nt->id = id;
  5017. nt->type.name = h->root.string;
  5018. nt->next = h->types;
  5019. h->types = nt;
  5020. nt->type.indx = info->type_indx;
  5021. ++info->type_indx;
  5022. }
  5023. nt->kind = DEBUG_KIND_ILLEGAL;
  5024. if (! ieee_init_buffer (info, &strdef)
  5025. || ! ieee_define_named_type (info, tag, nt->type.indx, size, TRUE,
  5026. localp, &strdef)
  5027. || ! ieee_write_number (info, structp ? 'S' : 'U')
  5028. || ! ieee_write_number (info, size))
  5029. return FALSE;
  5030. if (! ignorep)
  5031. {
  5032. const char *hold;
  5033. /* We never want nt->type.name to be NULL. We want the rest of
  5034. the type to be the object set up on the type stack; it will
  5035. have a NULL name if tag is NULL. */
  5036. hold = nt->type.name;
  5037. nt->type = info->type_stack->type;
  5038. nt->type.name = hold;
  5039. }
  5040. info->type_stack->type.name = tag;
  5041. info->type_stack->type.strdef = strdef;
  5042. info->type_stack->type.ignorep = ignorep;
  5043. return TRUE;
  5044. }
  5045. /* Add a field to a struct. */
  5046. static bfd_boolean
  5047. ieee_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
  5048. enum debug_visibility visibility)
  5049. {
  5050. struct ieee_handle *info = (struct ieee_handle *) p;
  5051. unsigned int size;
  5052. bfd_boolean unsignedp;
  5053. bfd_boolean referencep;
  5054. bfd_boolean localp;
  5055. unsigned int indx;
  5056. bfd_vma offset;
  5057. assert (info->type_stack != NULL
  5058. && info->type_stack->next != NULL
  5059. && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
  5060. /* If we are ignoring this struct definition, just pop and ignore
  5061. the type. */
  5062. if (info->type_stack->next->type.ignorep)
  5063. {
  5064. ieee_pop_unused_type (info);
  5065. return TRUE;
  5066. }
  5067. size = info->type_stack->type.size;
  5068. unsignedp = info->type_stack->type.unsignedp;
  5069. referencep = info->type_stack->type.referencep;
  5070. localp = info->type_stack->type.localp;
  5071. indx = ieee_pop_type (info);
  5072. if (localp)
  5073. info->type_stack->type.localp = TRUE;
  5074. if (info->type_stack->type.classdef != NULL)
  5075. {
  5076. unsigned int flags;
  5077. unsigned int nindx;
  5078. /* This is a class. We must add a description of this field to
  5079. the class records we are building. */
  5080. flags = ieee_vis_to_flags (visibility);
  5081. nindx = info->type_stack->type.classdef->indx;
  5082. if (! ieee_change_buffer (info,
  5083. &info->type_stack->type.classdef->pmiscbuf)
  5084. || ! ieee_write_asn (info, nindx, 'd')
  5085. || ! ieee_write_asn (info, nindx, flags)
  5086. || ! ieee_write_atn65 (info, nindx, name)
  5087. || ! ieee_write_atn65 (info, nindx, name))
  5088. return FALSE;
  5089. info->type_stack->type.classdef->pmisccount += 4;
  5090. if (referencep)
  5091. {
  5092. /* We need to output a record recording that this field is
  5093. really of reference type. We put this on the refs field
  5094. of classdef, so that it can be appended to the C++
  5095. records after the class is defined. */
  5096. nindx = info->name_indx;
  5097. ++info->name_indx;
  5098. if (! ieee_change_buffer (info,
  5099. &info->type_stack->type.classdef->refs)
  5100. || ! ieee_write_byte (info, (int) ieee_nn_record)
  5101. || ! ieee_write_number (info, nindx)
  5102. || ! ieee_write_id (info, "")
  5103. || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
  5104. || ! ieee_write_number (info, nindx)
  5105. || ! ieee_write_number (info, 0)
  5106. || ! ieee_write_number (info, 62)
  5107. || ! ieee_write_number (info, 80)
  5108. || ! ieee_write_number (info, 4)
  5109. || ! ieee_write_asn (info, nindx, 'R')
  5110. || ! ieee_write_asn (info, nindx, 3)
  5111. || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
  5112. || ! ieee_write_atn65 (info, nindx, name))
  5113. return FALSE;
  5114. }
  5115. }
  5116. /* If the bitsize doesn't match the expected size, we need to output
  5117. a bitfield type. */
  5118. if (size == 0 || bitsize == 0 || bitsize == size * 8)
  5119. offset = bitpos / 8;
  5120. else
  5121. {
  5122. if (! ieee_define_type (info, 0, unsignedp,
  5123. info->type_stack->type.localp)
  5124. || ! ieee_write_number (info, 'g')
  5125. || ! ieee_write_number (info, unsignedp ? 0 : 1)
  5126. || ! ieee_write_number (info, bitsize)
  5127. || ! ieee_write_number (info, indx))
  5128. return FALSE;
  5129. indx = ieee_pop_type (info);
  5130. offset = bitpos;
  5131. }
  5132. /* Switch to the struct we are building in order to output this
  5133. field definition. */
  5134. return (ieee_change_buffer (info, &info->type_stack->type.strdef)
  5135. && ieee_write_id (info, name)
  5136. && ieee_write_number (info, indx)
  5137. && ieee_write_number (info, offset));
  5138. }
  5139. /* Finish up a struct type. */
  5140. static bfd_boolean
  5141. ieee_end_struct_type (void *p)
  5142. {
  5143. struct ieee_handle *info = (struct ieee_handle *) p;
  5144. struct ieee_buflist *pb;
  5145. assert (info->type_stack != NULL
  5146. && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
  5147. /* If we were ignoring this struct definition because it was a
  5148. duplicate definition, just through away whatever bytes we have
  5149. accumulated. Leave the type on the stack. */
  5150. if (info->type_stack->type.ignorep)
  5151. return TRUE;
  5152. /* If this is not a duplicate definition of this tag, then localp
  5153. will be FALSE, and we can put it in the global type block.
  5154. FIXME: We should avoid outputting duplicate definitions which are
  5155. the same. */
  5156. if (! info->type_stack->type.localp)
  5157. {
  5158. /* Make sure we have started the global type block. */
  5159. if (ieee_buffer_emptyp (&info->global_types))
  5160. {
  5161. if (! ieee_change_buffer (info, &info->global_types)
  5162. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  5163. || ! ieee_write_byte (info, 2)
  5164. || ! ieee_write_number (info, 0)
  5165. || ! ieee_write_id (info, ""))
  5166. return FALSE;
  5167. }
  5168. pb = &info->global_types;
  5169. }
  5170. else
  5171. {
  5172. /* Make sure we have started the types block. */
  5173. if (ieee_buffer_emptyp (&info->types))
  5174. {
  5175. if (! ieee_change_buffer (info, &info->types)
  5176. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  5177. || ! ieee_write_byte (info, 1)
  5178. || ! ieee_write_number (info, 0)
  5179. || ! ieee_write_id (info, info->modname))
  5180. return FALSE;
  5181. }
  5182. pb = &info->types;
  5183. }
  5184. /* Append the struct definition to the types. */
  5185. if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
  5186. || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
  5187. return FALSE;
  5188. /* Leave the struct on the type stack. */
  5189. return TRUE;
  5190. }
  5191. /* Start a class type. */
  5192. static bfd_boolean
  5193. ieee_start_class_type (void *p, const char *tag, unsigned int id,
  5194. bfd_boolean structp, unsigned int size,
  5195. bfd_boolean vptr, bfd_boolean ownvptr)
  5196. {
  5197. struct ieee_handle *info = (struct ieee_handle *) p;
  5198. const char *vclass;
  5199. struct ieee_buflist pmiscbuf;
  5200. unsigned int indx;
  5201. struct ieee_type_class *classdef;
  5202. /* A C++ class is output as a C++ struct along with a set of pmisc
  5203. records describing the class. */
  5204. /* We need to have a name so that we can associate the struct and
  5205. the class. */
  5206. if (tag == NULL)
  5207. {
  5208. char *t;
  5209. t = (char *) xmalloc (20);
  5210. sprintf (t, "__anon%u", id);
  5211. tag = t;
  5212. }
  5213. /* We can't write out the virtual table information until we have
  5214. finished the class, because we don't know the virtual table size.
  5215. We get the size from the largest voffset we see. */
  5216. vclass = NULL;
  5217. if (vptr && ! ownvptr)
  5218. {
  5219. vclass = info->type_stack->type.name;
  5220. assert (vclass != NULL);
  5221. /* We don't call ieee_pop_unused_type, since the class should
  5222. get defined. */
  5223. (void) ieee_pop_type (info);
  5224. }
  5225. if (! ieee_start_struct_type (p, tag, id, structp, size))
  5226. return FALSE;
  5227. indx = info->name_indx;
  5228. ++info->name_indx;
  5229. /* We write out pmisc records into the classdef field. We will
  5230. write out the pmisc start after we know the number of records we
  5231. need. */
  5232. if (! ieee_init_buffer (info, &pmiscbuf)
  5233. || ! ieee_change_buffer (info, &pmiscbuf)
  5234. || ! ieee_write_asn (info, indx, 'T')
  5235. || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
  5236. || ! ieee_write_atn65 (info, indx, tag))
  5237. return FALSE;
  5238. classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
  5239. memset (classdef, 0, sizeof *classdef);
  5240. classdef->indx = indx;
  5241. classdef->pmiscbuf = pmiscbuf;
  5242. classdef->pmisccount = 3;
  5243. classdef->vclass = vclass;
  5244. classdef->ownvptr = ownvptr;
  5245. info->type_stack->type.classdef = classdef;
  5246. return TRUE;
  5247. }
  5248. /* Add a static member to a class. */
  5249. static bfd_boolean
  5250. ieee_class_static_member (void *p, const char *name, const char *physname,
  5251. enum debug_visibility visibility)
  5252. {
  5253. struct ieee_handle *info = (struct ieee_handle *) p;
  5254. unsigned int flags;
  5255. unsigned int nindx;
  5256. /* We don't care about the type. Hopefully there will be a call to
  5257. ieee_variable declaring the physical name and the type, since
  5258. that is where an IEEE consumer must get the type. */
  5259. ieee_pop_unused_type (info);
  5260. assert (info->type_stack != NULL
  5261. && info->type_stack->type.classdef != NULL);
  5262. flags = ieee_vis_to_flags (visibility);
  5263. flags |= CXXFLAGS_STATIC;
  5264. nindx = info->type_stack->type.classdef->indx;
  5265. if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
  5266. || ! ieee_write_asn (info, nindx, 'd')
  5267. || ! ieee_write_asn (info, nindx, flags)
  5268. || ! ieee_write_atn65 (info, nindx, name)
  5269. || ! ieee_write_atn65 (info, nindx, physname))
  5270. return FALSE;
  5271. info->type_stack->type.classdef->pmisccount += 4;
  5272. return TRUE;
  5273. }
  5274. /* Add a base class to a class. */
  5275. static bfd_boolean
  5276. ieee_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean is_virtual,
  5277. enum debug_visibility visibility)
  5278. {
  5279. struct ieee_handle *info = (struct ieee_handle *) p;
  5280. const char *bname;
  5281. bfd_boolean localp;
  5282. unsigned int bindx;
  5283. char *fname;
  5284. unsigned int flags;
  5285. unsigned int nindx;
  5286. assert (info->type_stack != NULL
  5287. && info->type_stack->type.name != NULL
  5288. && info->type_stack->next != NULL
  5289. && info->type_stack->next->type.classdef != NULL
  5290. && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
  5291. bname = info->type_stack->type.name;
  5292. localp = info->type_stack->type.localp;
  5293. bindx = ieee_pop_type (info);
  5294. /* We are currently defining both a struct and a class. We must
  5295. write out a field definition in the struct which holds the base
  5296. class. The stabs debugging reader will create a field named
  5297. _vb$CLASS for a virtual base class, so we just use that. FIXME:
  5298. we should not depend upon a detail of stabs debugging. */
  5299. if (is_virtual)
  5300. {
  5301. fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
  5302. sprintf (fname, "_vb$%s", bname);
  5303. flags = BASEFLAGS_VIRTUAL;
  5304. }
  5305. else
  5306. {
  5307. if (localp)
  5308. info->type_stack->type.localp = TRUE;
  5309. fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
  5310. sprintf (fname, "_b$%s", bname);
  5311. if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
  5312. || ! ieee_write_id (info, fname)
  5313. || ! ieee_write_number (info, bindx)
  5314. || ! ieee_write_number (info, bitpos / 8))
  5315. {
  5316. free (fname);
  5317. return FALSE;
  5318. }
  5319. flags = 0;
  5320. }
  5321. if (visibility == DEBUG_VISIBILITY_PRIVATE)
  5322. flags |= BASEFLAGS_PRIVATE;
  5323. nindx = info->type_stack->type.classdef->indx;
  5324. if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
  5325. || ! ieee_write_asn (info, nindx, 'b')
  5326. || ! ieee_write_asn (info, nindx, flags)
  5327. || ! ieee_write_atn65 (info, nindx, bname)
  5328. || ! ieee_write_asn (info, nindx, 0)
  5329. || ! ieee_write_atn65 (info, nindx, fname))
  5330. {
  5331. free (fname);
  5332. return FALSE;
  5333. }
  5334. info->type_stack->type.classdef->pmisccount += 5;
  5335. free (fname);
  5336. return TRUE;
  5337. }
  5338. /* Start building a method for a class. */
  5339. static bfd_boolean
  5340. ieee_class_start_method (void *p, const char *name)
  5341. {
  5342. struct ieee_handle *info = (struct ieee_handle *) p;
  5343. assert (info->type_stack != NULL
  5344. && info->type_stack->type.classdef != NULL
  5345. && info->type_stack->type.classdef->method == NULL);
  5346. info->type_stack->type.classdef->method = name;
  5347. return TRUE;
  5348. }
  5349. /* Define a new method variant, either static or not. */
  5350. static bfd_boolean
  5351. ieee_class_method_var (struct ieee_handle *info, const char *physname,
  5352. enum debug_visibility visibility,
  5353. bfd_boolean staticp, bfd_boolean constp,
  5354. bfd_boolean volatilep, bfd_vma voffset,
  5355. bfd_boolean context)
  5356. {
  5357. unsigned int flags;
  5358. unsigned int nindx;
  5359. bfd_boolean is_virtual;
  5360. /* We don't need the type of the method. An IEEE consumer which
  5361. wants the type must track down the function by the physical name
  5362. and get the type from that. */
  5363. ieee_pop_unused_type (info);
  5364. /* We don't use the context. FIXME: We probably ought to use it to
  5365. adjust the voffset somehow, but I don't really know how. */
  5366. if (context)
  5367. ieee_pop_unused_type (info);
  5368. assert (info->type_stack != NULL
  5369. && info->type_stack->type.classdef != NULL
  5370. && info->type_stack->type.classdef->method != NULL);
  5371. flags = ieee_vis_to_flags (visibility);
  5372. /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
  5373. CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
  5374. if (staticp)
  5375. flags |= CXXFLAGS_STATIC;
  5376. if (constp)
  5377. flags |= CXXFLAGS_CONST;
  5378. if (volatilep)
  5379. flags |= CXXFLAGS_VOLATILE;
  5380. nindx = info->type_stack->type.classdef->indx;
  5381. is_virtual = context || voffset > 0;
  5382. if (! ieee_change_buffer (info,
  5383. &info->type_stack->type.classdef->pmiscbuf)
  5384. || ! ieee_write_asn (info, nindx, is_virtual ? 'v' : 'm')
  5385. || ! ieee_write_asn (info, nindx, flags)
  5386. || ! ieee_write_atn65 (info, nindx,
  5387. info->type_stack->type.classdef->method)
  5388. || ! ieee_write_atn65 (info, nindx, physname))
  5389. return FALSE;
  5390. if (is_virtual)
  5391. {
  5392. if (voffset > info->type_stack->type.classdef->voffset)
  5393. info->type_stack->type.classdef->voffset = voffset;
  5394. if (! ieee_write_asn (info, nindx, voffset))
  5395. return FALSE;
  5396. ++info->type_stack->type.classdef->pmisccount;
  5397. }
  5398. if (! ieee_write_asn (info, nindx, 0))
  5399. return FALSE;
  5400. info->type_stack->type.classdef->pmisccount += 5;
  5401. return TRUE;
  5402. }
  5403. /* Define a new method variant. */
  5404. static bfd_boolean
  5405. ieee_class_method_variant (void *p, const char *physname,
  5406. enum debug_visibility visibility,
  5407. bfd_boolean constp, bfd_boolean volatilep,
  5408. bfd_vma voffset, bfd_boolean context)
  5409. {
  5410. struct ieee_handle *info = (struct ieee_handle *) p;
  5411. return ieee_class_method_var (info, physname, visibility, FALSE, constp,
  5412. volatilep, voffset, context);
  5413. }
  5414. /* Define a new static method variant. */
  5415. static bfd_boolean
  5416. ieee_class_static_method_variant (void *p, const char *physname,
  5417. enum debug_visibility visibility,
  5418. bfd_boolean constp, bfd_boolean volatilep)
  5419. {
  5420. struct ieee_handle *info = (struct ieee_handle *) p;
  5421. return ieee_class_method_var (info, physname, visibility, TRUE, constp,
  5422. volatilep, 0, FALSE);
  5423. }
  5424. /* Finish up a method. */
  5425. static bfd_boolean
  5426. ieee_class_end_method (void *p)
  5427. {
  5428. struct ieee_handle *info = (struct ieee_handle *) p;
  5429. assert (info->type_stack != NULL
  5430. && info->type_stack->type.classdef != NULL
  5431. && info->type_stack->type.classdef->method != NULL);
  5432. info->type_stack->type.classdef->method = NULL;
  5433. return TRUE;
  5434. }
  5435. /* Finish up a class. */
  5436. static bfd_boolean
  5437. ieee_end_class_type (void *p)
  5438. {
  5439. struct ieee_handle *info = (struct ieee_handle *) p;
  5440. unsigned int nindx;
  5441. assert (info->type_stack != NULL
  5442. && info->type_stack->type.classdef != NULL);
  5443. /* If we were ignoring this class definition because it was a
  5444. duplicate definition, just through away whatever bytes we have
  5445. accumulated. Leave the type on the stack. */
  5446. if (info->type_stack->type.ignorep)
  5447. return TRUE;
  5448. nindx = info->type_stack->type.classdef->indx;
  5449. /* If we have a virtual table, we can write out the information now. */
  5450. if (info->type_stack->type.classdef->vclass != NULL
  5451. || info->type_stack->type.classdef->ownvptr)
  5452. {
  5453. if (! ieee_change_buffer (info,
  5454. &info->type_stack->type.classdef->pmiscbuf)
  5455. || ! ieee_write_asn (info, nindx, 'z')
  5456. || ! ieee_write_atn65 (info, nindx, "")
  5457. || ! ieee_write_asn (info, nindx,
  5458. info->type_stack->type.classdef->voffset))
  5459. return FALSE;
  5460. if (info->type_stack->type.classdef->ownvptr)
  5461. {
  5462. if (! ieee_write_atn65 (info, nindx, ""))
  5463. return FALSE;
  5464. }
  5465. else
  5466. {
  5467. if (! ieee_write_atn65 (info, nindx,
  5468. info->type_stack->type.classdef->vclass))
  5469. return FALSE;
  5470. }
  5471. if (! ieee_write_asn (info, nindx, 0))
  5472. return FALSE;
  5473. info->type_stack->type.classdef->pmisccount += 5;
  5474. }
  5475. /* Now that we know the number of pmisc records, we can write out
  5476. the atn62 which starts the pmisc records, and append them to the
  5477. C++ buffers. */
  5478. if (! ieee_change_buffer (info, &info->cxx)
  5479. || ! ieee_write_byte (info, (int) ieee_nn_record)
  5480. || ! ieee_write_number (info, nindx)
  5481. || ! ieee_write_id (info, "")
  5482. || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
  5483. || ! ieee_write_number (info, nindx)
  5484. || ! ieee_write_number (info, 0)
  5485. || ! ieee_write_number (info, 62)
  5486. || ! ieee_write_number (info, 80)
  5487. || ! ieee_write_number (info,
  5488. info->type_stack->type.classdef->pmisccount))
  5489. return FALSE;
  5490. if (! ieee_append_buffer (info, &info->cxx,
  5491. &info->type_stack->type.classdef->pmiscbuf))
  5492. return FALSE;
  5493. if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
  5494. {
  5495. if (! ieee_append_buffer (info, &info->cxx,
  5496. &info->type_stack->type.classdef->refs))
  5497. return FALSE;
  5498. }
  5499. return ieee_end_struct_type (p);
  5500. }
  5501. /* Push a previously seen typedef onto the type stack. */
  5502. static bfd_boolean
  5503. ieee_typedef_type (void *p, const char *name)
  5504. {
  5505. struct ieee_handle *info = (struct ieee_handle *) p;
  5506. struct ieee_name_type_hash_entry *h;
  5507. struct ieee_name_type *nt;
  5508. h = ieee_name_type_hash_lookup (&info->typedefs, name, FALSE, FALSE);
  5509. /* h should never be NULL, since that would imply that the generic
  5510. debugging code has asked for a typedef which it has not yet
  5511. defined. */
  5512. assert (h != NULL);
  5513. /* We always use the most recently defined type for this name, which
  5514. will be the first one on the list. */
  5515. nt = h->types;
  5516. if (! ieee_push_type (info, nt->type.indx, nt->type.size,
  5517. nt->type.unsignedp, nt->type.localp))
  5518. return FALSE;
  5519. /* Copy over any other type information we may have. */
  5520. info->type_stack->type = nt->type;
  5521. return TRUE;
  5522. }
  5523. /* Push a tagged type onto the type stack. */
  5524. static bfd_boolean
  5525. ieee_tag_type (void *p, const char *name, unsigned int id,
  5526. enum debug_type_kind kind)
  5527. {
  5528. struct ieee_handle *info = (struct ieee_handle *) p;
  5529. bfd_boolean localp;
  5530. bfd_boolean copy;
  5531. char ab[20];
  5532. struct ieee_name_type_hash_entry *h;
  5533. struct ieee_name_type *nt;
  5534. if (kind == DEBUG_KIND_ENUM)
  5535. {
  5536. struct ieee_defined_enum *e;
  5537. if (name == NULL)
  5538. abort ();
  5539. for (e = info->enums; e != NULL; e = e->next)
  5540. if (e->tag != NULL && strcmp (e->tag, name) == 0)
  5541. return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
  5542. e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
  5543. memset (e, 0, sizeof *e);
  5544. e->indx = info->type_indx;
  5545. ++info->type_indx;
  5546. e->tag = name;
  5547. e->defined = FALSE;
  5548. e->next = info->enums;
  5549. info->enums = e;
  5550. return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
  5551. }
  5552. localp = FALSE;
  5553. copy = FALSE;
  5554. if (name == NULL)
  5555. {
  5556. sprintf (ab, "__anon%u", id);
  5557. name = ab;
  5558. copy = TRUE;
  5559. }
  5560. h = ieee_name_type_hash_lookup (&info->tags, name, TRUE, copy);
  5561. if (h == NULL)
  5562. return FALSE;
  5563. for (nt = h->types; nt != NULL; nt = nt->next)
  5564. {
  5565. if (nt->id == id)
  5566. {
  5567. if (! ieee_push_type (info, nt->type.indx, nt->type.size,
  5568. nt->type.unsignedp, nt->type.localp))
  5569. return FALSE;
  5570. /* Copy over any other type information we may have. */
  5571. info->type_stack->type = nt->type;
  5572. return TRUE;
  5573. }
  5574. if (! nt->type.localp)
  5575. {
  5576. /* This is a duplicate of a global type, so it must be
  5577. local. */
  5578. localp = TRUE;
  5579. }
  5580. }
  5581. nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
  5582. memset (nt, 0, sizeof *nt);
  5583. nt->id = id;
  5584. nt->type.name = h->root.string;
  5585. nt->type.indx = info->type_indx;
  5586. nt->type.localp = localp;
  5587. ++info->type_indx;
  5588. nt->kind = kind;
  5589. nt->next = h->types;
  5590. h->types = nt;
  5591. if (! ieee_push_type (info, nt->type.indx, 0, FALSE, localp))
  5592. return FALSE;
  5593. info->type_stack->type.name = h->root.string;
  5594. return TRUE;
  5595. }
  5596. /* Output a typedef. */
  5597. static bfd_boolean
  5598. ieee_typdef (void *p, const char *name)
  5599. {
  5600. struct ieee_handle *info = (struct ieee_handle *) p;
  5601. struct ieee_write_type type;
  5602. unsigned int indx;
  5603. bfd_boolean found;
  5604. bfd_boolean localp;
  5605. struct ieee_name_type_hash_entry *h;
  5606. struct ieee_name_type *nt;
  5607. type = info->type_stack->type;
  5608. indx = type.indx;
  5609. /* If this is a simple builtin type using a builtin name, we don't
  5610. want to output the typedef itself. We also want to change the
  5611. type index to correspond to the name being used. We recognize
  5612. names used in stabs debugging output even if they don't exactly
  5613. correspond to the names used for the IEEE builtin types. */
  5614. found = FALSE;
  5615. if (indx <= (unsigned int) builtin_bcd_float)
  5616. {
  5617. switch ((enum builtin_types) indx)
  5618. {
  5619. default:
  5620. break;
  5621. case builtin_void:
  5622. if (strcmp (name, "void") == 0)
  5623. found = TRUE;
  5624. break;
  5625. case builtin_signed_char:
  5626. case builtin_char:
  5627. if (strcmp (name, "signed char") == 0)
  5628. {
  5629. indx = (unsigned int) builtin_signed_char;
  5630. found = TRUE;
  5631. }
  5632. else if (strcmp (name, "char") == 0)
  5633. {
  5634. indx = (unsigned int) builtin_char;
  5635. found = TRUE;
  5636. }
  5637. break;
  5638. case builtin_unsigned_char:
  5639. if (strcmp (name, "unsigned char") == 0)
  5640. found = TRUE;
  5641. break;
  5642. case builtin_signed_short_int:
  5643. case builtin_short:
  5644. case builtin_short_int:
  5645. case builtin_signed_short:
  5646. if (strcmp (name, "signed short int") == 0)
  5647. {
  5648. indx = (unsigned int) builtin_signed_short_int;
  5649. found = TRUE;
  5650. }
  5651. else if (strcmp (name, "short") == 0)
  5652. {
  5653. indx = (unsigned int) builtin_short;
  5654. found = TRUE;
  5655. }
  5656. else if (strcmp (name, "short int") == 0)
  5657. {
  5658. indx = (unsigned int) builtin_short_int;
  5659. found = TRUE;
  5660. }
  5661. else if (strcmp (name, "signed short") == 0)
  5662. {
  5663. indx = (unsigned int) builtin_signed_short;
  5664. found = TRUE;
  5665. }
  5666. break;
  5667. case builtin_unsigned_short_int:
  5668. case builtin_unsigned_short:
  5669. if (strcmp (name, "unsigned short int") == 0
  5670. || strcmp (name, "short unsigned int") == 0)
  5671. {
  5672. indx = builtin_unsigned_short_int;
  5673. found = TRUE;
  5674. }
  5675. else if (strcmp (name, "unsigned short") == 0)
  5676. {
  5677. indx = builtin_unsigned_short;
  5678. found = TRUE;
  5679. }
  5680. break;
  5681. case builtin_signed_long:
  5682. case builtin_int: /* FIXME: Size depends upon architecture. */
  5683. case builtin_long:
  5684. if (strcmp (name, "signed long") == 0)
  5685. {
  5686. indx = builtin_signed_long;
  5687. found = TRUE;
  5688. }
  5689. else if (strcmp (name, "int") == 0)
  5690. {
  5691. indx = builtin_int;
  5692. found = TRUE;
  5693. }
  5694. else if (strcmp (name, "long") == 0
  5695. || strcmp (name, "long int") == 0)
  5696. {
  5697. indx = builtin_long;
  5698. found = TRUE;
  5699. }
  5700. break;
  5701. case builtin_unsigned_long:
  5702. case builtin_unsigned: /* FIXME: Size depends upon architecture. */
  5703. case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
  5704. if (strcmp (name, "unsigned long") == 0
  5705. || strcmp (name, "long unsigned int") == 0)
  5706. {
  5707. indx = builtin_unsigned_long;
  5708. found = TRUE;
  5709. }
  5710. else if (strcmp (name, "unsigned") == 0)
  5711. {
  5712. indx = builtin_unsigned;
  5713. found = TRUE;
  5714. }
  5715. else if (strcmp (name, "unsigned int") == 0)
  5716. {
  5717. indx = builtin_unsigned_int;
  5718. found = TRUE;
  5719. }
  5720. break;
  5721. case builtin_signed_long_long:
  5722. if (strcmp (name, "signed long long") == 0
  5723. || strcmp (name, "long long int") == 0)
  5724. found = TRUE;
  5725. break;
  5726. case builtin_unsigned_long_long:
  5727. if (strcmp (name, "unsigned long long") == 0
  5728. || strcmp (name, "long long unsigned int") == 0)
  5729. found = TRUE;
  5730. break;
  5731. case builtin_float:
  5732. if (strcmp (name, "float") == 0)
  5733. found = TRUE;
  5734. break;
  5735. case builtin_double:
  5736. if (strcmp (name, "double") == 0)
  5737. found = TRUE;
  5738. break;
  5739. case builtin_long_double:
  5740. if (strcmp (name, "long double") == 0)
  5741. found = TRUE;
  5742. break;
  5743. case builtin_long_long_double:
  5744. if (strcmp (name, "long long double") == 0)
  5745. found = TRUE;
  5746. break;
  5747. }
  5748. if (found)
  5749. type.indx = indx;
  5750. }
  5751. h = ieee_name_type_hash_lookup (&info->typedefs, name, TRUE, FALSE);
  5752. if (h == NULL)
  5753. return FALSE;
  5754. /* See if we have already defined this type with this name. */
  5755. localp = type.localp;
  5756. for (nt = h->types; nt != NULL; nt = nt->next)
  5757. {
  5758. if (nt->id == indx)
  5759. {
  5760. /* If this is a global definition, then we don't need to
  5761. do anything here. */
  5762. if (! nt->type.localp)
  5763. {
  5764. ieee_pop_unused_type (info);
  5765. return TRUE;
  5766. }
  5767. }
  5768. else
  5769. {
  5770. /* This is a duplicate definition, so make this one local. */
  5771. localp = TRUE;
  5772. }
  5773. }
  5774. /* We need to add a new typedef for this type. */
  5775. nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
  5776. memset (nt, 0, sizeof *nt);
  5777. nt->id = indx;
  5778. nt->type = type;
  5779. nt->type.name = name;
  5780. nt->type.localp = localp;
  5781. nt->kind = DEBUG_KIND_ILLEGAL;
  5782. nt->next = h->types;
  5783. h->types = nt;
  5784. if (found)
  5785. {
  5786. /* This is one of the builtin typedefs, so we don't need to
  5787. actually define it. */
  5788. ieee_pop_unused_type (info);
  5789. return TRUE;
  5790. }
  5791. indx = ieee_pop_type (info);
  5792. if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
  5793. type.unsignedp, localp,
  5794. (struct ieee_buflist *) NULL)
  5795. || ! ieee_write_number (info, 'T')
  5796. || ! ieee_write_number (info, indx))
  5797. return FALSE;
  5798. /* Remove the type we just added to the type stack. This should not
  5799. be ieee_pop_unused_type, since the type is used, we just don't
  5800. need it now. */
  5801. (void) ieee_pop_type (info);
  5802. return TRUE;
  5803. }
  5804. /* Output a tag for a type. We don't have to do anything here. */
  5805. static bfd_boolean
  5806. ieee_tag (void *p, const char *name ATTRIBUTE_UNUSED)
  5807. {
  5808. struct ieee_handle *info = (struct ieee_handle *) p;
  5809. /* This should not be ieee_pop_unused_type, since we want the type
  5810. to be defined. */
  5811. (void) ieee_pop_type (info);
  5812. return TRUE;
  5813. }
  5814. /* Output an integer constant. */
  5815. static bfd_boolean
  5816. ieee_int_constant (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED,
  5817. bfd_vma val ATTRIBUTE_UNUSED)
  5818. {
  5819. /* FIXME. */
  5820. return TRUE;
  5821. }
  5822. /* Output a floating point constant. */
  5823. static bfd_boolean
  5824. ieee_float_constant (void *p ATTRIBUTE_UNUSED,
  5825. const char *name ATTRIBUTE_UNUSED,
  5826. double val ATTRIBUTE_UNUSED)
  5827. {
  5828. /* FIXME. */
  5829. return TRUE;
  5830. }
  5831. /* Output a typed constant. */
  5832. static bfd_boolean
  5833. ieee_typed_constant (void *p, const char *name ATTRIBUTE_UNUSED,
  5834. bfd_vma val ATTRIBUTE_UNUSED)
  5835. {
  5836. struct ieee_handle *info = (struct ieee_handle *) p;
  5837. /* FIXME. */
  5838. ieee_pop_unused_type (info);
  5839. return TRUE;
  5840. }
  5841. /* Output a variable. */
  5842. static bfd_boolean
  5843. ieee_variable (void *p, const char *name, enum debug_var_kind kind,
  5844. bfd_vma val)
  5845. {
  5846. struct ieee_handle *info = (struct ieee_handle *) p;
  5847. unsigned int name_indx;
  5848. unsigned int size;
  5849. bfd_boolean referencep;
  5850. unsigned int type_indx;
  5851. bfd_boolean asn;
  5852. int refflag;
  5853. size = info->type_stack->type.size;
  5854. referencep = info->type_stack->type.referencep;
  5855. type_indx = ieee_pop_type (info);
  5856. assert (! ieee_buffer_emptyp (&info->vars));
  5857. if (! ieee_change_buffer (info, &info->vars))
  5858. return FALSE;
  5859. name_indx = info->name_indx;
  5860. ++info->name_indx;
  5861. /* Write out an NN and an ATN record for this variable. */
  5862. if (! ieee_write_byte (info, (int) ieee_nn_record)
  5863. || ! ieee_write_number (info, name_indx)
  5864. || ! ieee_write_id (info, name)
  5865. || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
  5866. || ! ieee_write_number (info, name_indx)
  5867. || ! ieee_write_number (info, type_indx))
  5868. return FALSE;
  5869. switch (kind)
  5870. {
  5871. default:
  5872. abort ();
  5873. return FALSE;
  5874. case DEBUG_GLOBAL:
  5875. if (! ieee_write_number (info, 8)
  5876. || ! ieee_add_range (info, FALSE, val, val + size))
  5877. return FALSE;
  5878. refflag = 0;
  5879. asn = TRUE;
  5880. break;
  5881. case DEBUG_STATIC:
  5882. if (! ieee_write_number (info, 3)
  5883. || ! ieee_add_range (info, FALSE, val, val + size))
  5884. return FALSE;
  5885. refflag = 1;
  5886. asn = TRUE;
  5887. break;
  5888. case DEBUG_LOCAL_STATIC:
  5889. if (! ieee_write_number (info, 3)
  5890. || ! ieee_add_range (info, FALSE, val, val + size))
  5891. return FALSE;
  5892. refflag = 2;
  5893. asn = TRUE;
  5894. break;
  5895. case DEBUG_LOCAL:
  5896. if (! ieee_write_number (info, 1)
  5897. || ! ieee_write_number (info, val))
  5898. return FALSE;
  5899. refflag = 2;
  5900. asn = FALSE;
  5901. break;
  5902. case DEBUG_REGISTER:
  5903. if (! ieee_write_number (info, 2)
  5904. || ! ieee_write_number (info,
  5905. ieee_genreg_to_regno (info->abfd, val)))
  5906. return FALSE;
  5907. refflag = 2;
  5908. asn = FALSE;
  5909. break;
  5910. }
  5911. if (asn)
  5912. {
  5913. if (! ieee_write_asn (info, name_indx, val))
  5914. return FALSE;
  5915. }
  5916. /* If this is really a reference type, then we just output it with
  5917. pointer type, and must now output a C++ record indicating that it
  5918. is really reference type. */
  5919. if (referencep)
  5920. {
  5921. unsigned int nindx;
  5922. nindx = info->name_indx;
  5923. ++info->name_indx;
  5924. /* If this is a global variable, we want to output the misc
  5925. record in the C++ misc record block. Otherwise, we want to
  5926. output it just after the variable definition, which is where
  5927. the current buffer is. */
  5928. if (refflag != 2)
  5929. {
  5930. if (! ieee_change_buffer (info, &info->cxx))
  5931. return FALSE;
  5932. }
  5933. if (! ieee_write_byte (info, (int) ieee_nn_record)
  5934. || ! ieee_write_number (info, nindx)
  5935. || ! ieee_write_id (info, "")
  5936. || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
  5937. || ! ieee_write_number (info, nindx)
  5938. || ! ieee_write_number (info, 0)
  5939. || ! ieee_write_number (info, 62)
  5940. || ! ieee_write_number (info, 80)
  5941. || ! ieee_write_number (info, 3)
  5942. || ! ieee_write_asn (info, nindx, 'R')
  5943. || ! ieee_write_asn (info, nindx, refflag)
  5944. || ! ieee_write_atn65 (info, nindx, name))
  5945. return FALSE;
  5946. }
  5947. return TRUE;
  5948. }
  5949. /* Start outputting information for a function. */
  5950. static bfd_boolean
  5951. ieee_start_function (void *p, const char *name, bfd_boolean global)
  5952. {
  5953. struct ieee_handle *info = (struct ieee_handle *) p;
  5954. bfd_boolean referencep;
  5955. unsigned int retindx, typeindx;
  5956. referencep = info->type_stack->type.referencep;
  5957. retindx = ieee_pop_type (info);
  5958. /* Besides recording a BB4 or BB6 block, we record the type of the
  5959. function in the BB1 typedef block. We can't write out the full
  5960. type until we have seen all the parameters, so we accumulate it
  5961. in info->fntype and info->fnargs. */
  5962. if (! ieee_buffer_emptyp (&info->fntype))
  5963. {
  5964. /* FIXME: This might happen someday if we support nested
  5965. functions. */
  5966. abort ();
  5967. }
  5968. info->fnname = name;
  5969. /* An attribute of 0x40 means that the push mask is unknown. */
  5970. if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, FALSE, TRUE,
  5971. &info->fntype)
  5972. || ! ieee_write_number (info, 'x')
  5973. || ! ieee_write_number (info, 0x40)
  5974. || ! ieee_write_number (info, 0)
  5975. || ! ieee_write_number (info, 0)
  5976. || ! ieee_write_number (info, retindx))
  5977. return FALSE;
  5978. typeindx = ieee_pop_type (info);
  5979. if (! ieee_init_buffer (info, &info->fnargs))
  5980. return FALSE;
  5981. info->fnargcount = 0;
  5982. /* If the function return value is actually a reference type, we
  5983. must add a record indicating that. */
  5984. if (referencep)
  5985. {
  5986. unsigned int nindx;
  5987. nindx = info->name_indx;
  5988. ++info->name_indx;
  5989. if (! ieee_change_buffer (info, &info->cxx)
  5990. || ! ieee_write_byte (info, (int) ieee_nn_record)
  5991. || ! ieee_write_number (info, nindx)
  5992. || ! ieee_write_id (info, "")
  5993. || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
  5994. || ! ieee_write_number (info, nindx)
  5995. || ! ieee_write_number (info, 0)
  5996. || ! ieee_write_number (info, 62)
  5997. || ! ieee_write_number (info, 80)
  5998. || ! ieee_write_number (info, 3)
  5999. || ! ieee_write_asn (info, nindx, 'R')
  6000. || ! ieee_write_asn (info, nindx, global ? 0 : 1)
  6001. || ! ieee_write_atn65 (info, nindx, name))
  6002. return FALSE;
  6003. }
  6004. assert (! ieee_buffer_emptyp (&info->vars));
  6005. if (! ieee_change_buffer (info, &info->vars))
  6006. return FALSE;
  6007. /* The address is written out as the first block. */
  6008. ++info->block_depth;
  6009. return (ieee_write_byte (info, (int) ieee_bb_record_enum)
  6010. && ieee_write_byte (info, global ? 4 : 6)
  6011. && ieee_write_number (info, 0)
  6012. && ieee_write_id (info, name)
  6013. && ieee_write_number (info, 0)
  6014. && ieee_write_number (info, typeindx));
  6015. }
  6016. /* Add a function parameter. This will normally be called before the
  6017. first block, so we postpone them until we see the block. */
  6018. static bfd_boolean
  6019. ieee_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
  6020. bfd_vma val)
  6021. {
  6022. struct ieee_handle *info = (struct ieee_handle *) p;
  6023. struct ieee_pending_parm *m, **pm;
  6024. assert (info->block_depth == 1);
  6025. m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
  6026. memset (m, 0, sizeof *m);
  6027. m->next = NULL;
  6028. m->name = name;
  6029. m->referencep = info->type_stack->type.referencep;
  6030. m->type = ieee_pop_type (info);
  6031. m->kind = kind;
  6032. m->val = val;
  6033. for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
  6034. ;
  6035. *pm = m;
  6036. /* Add the type to the fnargs list. */
  6037. if (! ieee_change_buffer (info, &info->fnargs)
  6038. || ! ieee_write_number (info, m->type))
  6039. return FALSE;
  6040. ++info->fnargcount;
  6041. return TRUE;
  6042. }
  6043. /* Output pending function parameters. */
  6044. static bfd_boolean
  6045. ieee_output_pending_parms (struct ieee_handle *info)
  6046. {
  6047. struct ieee_pending_parm *m;
  6048. unsigned int refcount;
  6049. refcount = 0;
  6050. for (m = info->pending_parms; m != NULL; m = m->next)
  6051. {
  6052. enum debug_var_kind vkind;
  6053. switch (m->kind)
  6054. {
  6055. default:
  6056. abort ();
  6057. return FALSE;
  6058. case DEBUG_PARM_STACK:
  6059. case DEBUG_PARM_REFERENCE:
  6060. vkind = DEBUG_LOCAL;
  6061. break;
  6062. case DEBUG_PARM_REG:
  6063. case DEBUG_PARM_REF_REG:
  6064. vkind = DEBUG_REGISTER;
  6065. break;
  6066. }
  6067. if (! ieee_push_type (info, m->type, 0, FALSE, FALSE))
  6068. return FALSE;
  6069. info->type_stack->type.referencep = m->referencep;
  6070. if (m->referencep)
  6071. ++refcount;
  6072. if (! ieee_variable ((void *) info, m->name, vkind, m->val))
  6073. return FALSE;
  6074. }
  6075. /* If there are any reference parameters, we need to output a
  6076. miscellaneous record indicating them. */
  6077. if (refcount > 0)
  6078. {
  6079. unsigned int nindx, varindx;
  6080. /* FIXME: The MRI compiler outputs the demangled function name
  6081. here, but we are outputting the mangled name. */
  6082. nindx = info->name_indx;
  6083. ++info->name_indx;
  6084. if (! ieee_change_buffer (info, &info->vars)
  6085. || ! ieee_write_byte (info, (int) ieee_nn_record)
  6086. || ! ieee_write_number (info, nindx)
  6087. || ! ieee_write_id (info, "")
  6088. || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
  6089. || ! ieee_write_number (info, nindx)
  6090. || ! ieee_write_number (info, 0)
  6091. || ! ieee_write_number (info, 62)
  6092. || ! ieee_write_number (info, 80)
  6093. || ! ieee_write_number (info, refcount + 3)
  6094. || ! ieee_write_asn (info, nindx, 'B')
  6095. || ! ieee_write_atn65 (info, nindx, info->fnname)
  6096. || ! ieee_write_asn (info, nindx, 0))
  6097. return FALSE;
  6098. for (m = info->pending_parms, varindx = 1;
  6099. m != NULL;
  6100. m = m->next, varindx++)
  6101. {
  6102. if (m->referencep)
  6103. {
  6104. if (! ieee_write_asn (info, nindx, varindx))
  6105. return FALSE;
  6106. }
  6107. }
  6108. }
  6109. m = info->pending_parms;
  6110. while (m != NULL)
  6111. {
  6112. struct ieee_pending_parm *next;
  6113. next = m->next;
  6114. free (m);
  6115. m = next;
  6116. }
  6117. info->pending_parms = NULL;
  6118. return TRUE;
  6119. }
  6120. /* Start a block. If this is the first block, we output the address
  6121. to finish the BB4 or BB6, and then output the function parameters. */
  6122. static bfd_boolean
  6123. ieee_start_block (void *p, bfd_vma addr)
  6124. {
  6125. struct ieee_handle *info = (struct ieee_handle *) p;
  6126. if (! ieee_change_buffer (info, &info->vars))
  6127. return FALSE;
  6128. if (info->block_depth == 1)
  6129. {
  6130. if (! ieee_write_number (info, addr)
  6131. || ! ieee_output_pending_parms (info))
  6132. return FALSE;
  6133. }
  6134. else
  6135. {
  6136. if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
  6137. || ! ieee_write_byte (info, 6)
  6138. || ! ieee_write_number (info, 0)
  6139. || ! ieee_write_id (info, "")
  6140. || ! ieee_write_number (info, 0)
  6141. || ! ieee_write_number (info, 0)
  6142. || ! ieee_write_number (info, addr))
  6143. return FALSE;
  6144. }
  6145. if (! ieee_start_range (info, addr))
  6146. return FALSE;
  6147. ++info->block_depth;
  6148. return TRUE;
  6149. }
  6150. /* End a block. */
  6151. static bfd_boolean
  6152. ieee_end_block (void *p, bfd_vma addr)
  6153. {
  6154. struct ieee_handle *info = (struct ieee_handle *) p;
  6155. /* The address we are given is the end of the block, but IEEE seems
  6156. to want to the address of the last byte in the block, so we
  6157. subtract one. */
  6158. if (! ieee_change_buffer (info, &info->vars)
  6159. || ! ieee_write_byte (info, (int) ieee_be_record_enum)
  6160. || ! ieee_write_number (info, addr - 1))
  6161. return FALSE;
  6162. if (! ieee_end_range (info, addr))
  6163. return FALSE;
  6164. --info->block_depth;
  6165. if (addr > info->highaddr)
  6166. info->highaddr = addr;
  6167. return TRUE;
  6168. }
  6169. /* End a function. */
  6170. static bfd_boolean
  6171. ieee_end_function (void *p)
  6172. {
  6173. struct ieee_handle *info = (struct ieee_handle *) p;
  6174. assert (info->block_depth == 1);
  6175. --info->block_depth;
  6176. /* Now we can finish up fntype, and add it to the typdef section.
  6177. At this point, fntype is the 'x' type up to the argument count,
  6178. and fnargs is the argument types. We must add the argument
  6179. count, and we must add the level. FIXME: We don't record varargs
  6180. functions correctly. In fact, stabs debugging does not give us
  6181. enough information to do so. */
  6182. if (! ieee_change_buffer (info, &info->fntype)
  6183. || ! ieee_write_number (info, info->fnargcount)
  6184. || ! ieee_change_buffer (info, &info->fnargs)
  6185. || ! ieee_write_number (info, 0))
  6186. return FALSE;
  6187. /* Make sure the typdef block has been started. */
  6188. if (ieee_buffer_emptyp (&info->types))
  6189. {
  6190. if (! ieee_change_buffer (info, &info->types)
  6191. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  6192. || ! ieee_write_byte (info, 1)
  6193. || ! ieee_write_number (info, 0)
  6194. || ! ieee_write_id (info, info->modname))
  6195. return FALSE;
  6196. }
  6197. if (! ieee_append_buffer (info, &info->types, &info->fntype)
  6198. || ! ieee_append_buffer (info, &info->types, &info->fnargs))
  6199. return FALSE;
  6200. info->fnname = NULL;
  6201. if (! ieee_init_buffer (info, &info->fntype)
  6202. || ! ieee_init_buffer (info, &info->fnargs))
  6203. return FALSE;
  6204. info->fnargcount = 0;
  6205. return TRUE;
  6206. }
  6207. /* Record line number information. */
  6208. static bfd_boolean
  6209. ieee_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
  6210. {
  6211. struct ieee_handle *info = (struct ieee_handle *) p;
  6212. assert (info->filename != NULL);
  6213. /* The HP simulator seems to get confused when more than one line is
  6214. listed for the same address, at least if they are in different
  6215. files. We handle this by always listing the last line for a
  6216. given address, since that seems to be the one that gdb uses. */
  6217. if (info->pending_lineno_filename != NULL
  6218. && addr != info->pending_lineno_addr)
  6219. {
  6220. /* Make sure we have a line number block. */
  6221. if (! ieee_buffer_emptyp (&info->linenos))
  6222. {
  6223. if (! ieee_change_buffer (info, &info->linenos))
  6224. return FALSE;
  6225. }
  6226. else
  6227. {
  6228. info->lineno_name_indx = info->name_indx;
  6229. ++info->name_indx;
  6230. if (! ieee_change_buffer (info, &info->linenos)
  6231. || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
  6232. || ! ieee_write_byte (info, 5)
  6233. || ! ieee_write_number (info, 0)
  6234. || ! ieee_write_id (info, info->filename)
  6235. || ! ieee_write_byte (info, (int) ieee_nn_record)
  6236. || ! ieee_write_number (info, info->lineno_name_indx)
  6237. || ! ieee_write_id (info, ""))
  6238. return FALSE;
  6239. info->lineno_filename = info->filename;
  6240. }
  6241. if (filename_cmp (info->pending_lineno_filename,
  6242. info->lineno_filename) != 0)
  6243. {
  6244. if (filename_cmp (info->filename, info->lineno_filename) != 0)
  6245. {
  6246. /* We were not in the main file. Close the block for the
  6247. included file. */
  6248. if (! ieee_write_byte (info, (int) ieee_be_record_enum))
  6249. return FALSE;
  6250. if (filename_cmp (info->filename,
  6251. info->pending_lineno_filename) == 0)
  6252. {
  6253. /* We need a new NN record, and we aren't about to
  6254. output one. */
  6255. info->lineno_name_indx = info->name_indx;
  6256. ++info->name_indx;
  6257. if (! ieee_write_byte (info, (int) ieee_nn_record)
  6258. || ! ieee_write_number (info, info->lineno_name_indx)
  6259. || ! ieee_write_id (info, ""))
  6260. return FALSE;
  6261. }
  6262. }
  6263. if (filename_cmp (info->filename,
  6264. info->pending_lineno_filename) != 0)
  6265. {
  6266. /* We are not changing to the main file. Open a block for
  6267. the new included file. */
  6268. info->lineno_name_indx = info->name_indx;
  6269. ++info->name_indx;
  6270. if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
  6271. || ! ieee_write_byte (info, 5)
  6272. || ! ieee_write_number (info, 0)
  6273. || ! ieee_write_id (info, info->pending_lineno_filename)
  6274. || ! ieee_write_byte (info, (int) ieee_nn_record)
  6275. || ! ieee_write_number (info, info->lineno_name_indx)
  6276. || ! ieee_write_id (info, ""))
  6277. return FALSE;
  6278. }
  6279. info->lineno_filename = info->pending_lineno_filename;
  6280. }
  6281. if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
  6282. || ! ieee_write_number (info, info->lineno_name_indx)
  6283. || ! ieee_write_number (info, 0)
  6284. || ! ieee_write_number (info, 7)
  6285. || ! ieee_write_number (info, info->pending_lineno)
  6286. || ! ieee_write_number (info, 0)
  6287. || ! ieee_write_asn (info, info->lineno_name_indx,
  6288. info->pending_lineno_addr))
  6289. return FALSE;
  6290. }
  6291. info->pending_lineno_filename = filename;
  6292. info->pending_lineno = lineno;
  6293. info->pending_lineno_addr = addr;
  6294. return TRUE;
  6295. }