stabs.c 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439
  1. /* stabs.c -- Parse stabs debugging information
  2. Copyright (C) 1995-2015 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 contains code which parses stabs debugging information.
  18. The organization of this code is based on the gdb stabs reading
  19. code. The job it does is somewhat different, because it is not
  20. trying to identify the correct address for anything. */
  21. #include "sysdep.h"
  22. #include "bfd.h"
  23. #include "libiberty.h"
  24. #include "safe-ctype.h"
  25. #include "demangle.h"
  26. #include "debug.h"
  27. #include "budbg.h"
  28. #include "filenames.h"
  29. #include "aout/aout64.h"
  30. #include "aout/stab_gnu.h"
  31. /* The number of predefined XCOFF types. */
  32. #define XCOFF_TYPE_COUNT 34
  33. /* This structure is used as a handle so that the stab parsing doesn't
  34. need to use any static variables. */
  35. struct stab_handle
  36. {
  37. /* The BFD. */
  38. bfd *abfd;
  39. /* TRUE if this is stabs in sections. */
  40. bfd_boolean sections;
  41. /* The symbol table. */
  42. asymbol **syms;
  43. /* The number of symbols. */
  44. long symcount;
  45. /* The accumulated file name string. */
  46. char *so_string;
  47. /* The value of the last N_SO symbol. */
  48. bfd_vma so_value;
  49. /* The value of the start of the file, so that we can handle file
  50. relative N_LBRAC and N_RBRAC symbols. */
  51. bfd_vma file_start_offset;
  52. /* The offset of the start of the function, so that we can handle
  53. function relative N_LBRAC and N_RBRAC symbols. */
  54. bfd_vma function_start_offset;
  55. /* The version number of gcc which compiled the current compilation
  56. unit, 0 if not compiled by gcc. */
  57. int gcc_compiled;
  58. /* Whether an N_OPT symbol was seen that was not generated by gcc,
  59. so that we can detect the SunPRO compiler. */
  60. bfd_boolean n_opt_found;
  61. /* The main file name. */
  62. char *main_filename;
  63. /* A stack of unfinished N_BINCL files. */
  64. struct bincl_file *bincl_stack;
  65. /* A list of finished N_BINCL files. */
  66. struct bincl_file *bincl_list;
  67. /* Whether we are inside a function or not. */
  68. bfd_boolean within_function;
  69. /* The address of the end of the function, used if we have seen an
  70. N_FUN symbol while in a function. This is -1 if we have not seen
  71. an N_FUN (the normal case). */
  72. bfd_vma function_end;
  73. /* The depth of block nesting. */
  74. int block_depth;
  75. /* List of pending variable definitions. */
  76. struct stab_pending_var *pending;
  77. /* Number of files for which we have types. */
  78. unsigned int files;
  79. /* Lists of types per file. */
  80. struct stab_types **file_types;
  81. /* Predefined XCOFF types. */
  82. debug_type xcoff_types[XCOFF_TYPE_COUNT];
  83. /* Undefined tags. */
  84. struct stab_tag *tags;
  85. /* Set by parse_stab_type if it sees a structure defined as a cross
  86. reference to itself. Reset by parse_stab_type otherwise. */
  87. bfd_boolean self_crossref;
  88. };
  89. /* A list of these structures is used to hold pending variable
  90. definitions seen before the N_LBRAC of a block. */
  91. struct stab_pending_var
  92. {
  93. /* Next pending variable definition. */
  94. struct stab_pending_var *next;
  95. /* Name. */
  96. const char *name;
  97. /* Type. */
  98. debug_type type;
  99. /* Kind. */
  100. enum debug_var_kind kind;
  101. /* Value. */
  102. bfd_vma val;
  103. };
  104. /* A list of these structures is used to hold the types for a single
  105. file. */
  106. struct stab_types
  107. {
  108. /* Next set of slots for this file. */
  109. struct stab_types *next;
  110. /* Types indexed by type number. */
  111. #define STAB_TYPES_SLOTS (16)
  112. debug_type types[STAB_TYPES_SLOTS];
  113. };
  114. /* We keep a list of undefined tags that we encounter, so that we can
  115. fill them in if the tag is later defined. */
  116. struct stab_tag
  117. {
  118. /* Next undefined tag. */
  119. struct stab_tag *next;
  120. /* Tag name. */
  121. const char *name;
  122. /* Type kind. */
  123. enum debug_type_kind kind;
  124. /* Slot to hold real type when we discover it. If we don't, we fill
  125. in an undefined tag type. */
  126. debug_type slot;
  127. /* Indirect type we have created to point at slot. */
  128. debug_type type;
  129. };
  130. static char *savestring (const char *, int);
  131. static bfd_vma parse_number (const char **, bfd_boolean *);
  132. static void bad_stab (const char *);
  133. static void warn_stab (const char *, const char *);
  134. static bfd_boolean parse_stab_string
  135. (void *, struct stab_handle *, int, int, bfd_vma, const char *);
  136. static debug_type parse_stab_type
  137. (void *, struct stab_handle *, const char *, const char **, debug_type **);
  138. static bfd_boolean parse_stab_type_number (const char **, int *);
  139. static debug_type parse_stab_range_type
  140. (void *, struct stab_handle *, const char *, const char **, const int *);
  141. static debug_type parse_stab_sun_builtin_type (void *, const char **);
  142. static debug_type parse_stab_sun_floating_type (void *, const char **);
  143. static debug_type parse_stab_enum_type (void *, const char **);
  144. static debug_type parse_stab_struct_type
  145. (void *, struct stab_handle *, const char *, const char **,
  146. bfd_boolean, const int *);
  147. static bfd_boolean parse_stab_baseclasses
  148. (void *, struct stab_handle *, const char **, debug_baseclass **);
  149. static bfd_boolean parse_stab_struct_fields
  150. (void *, struct stab_handle *, const char **, debug_field **, bfd_boolean *);
  151. static bfd_boolean parse_stab_cpp_abbrev
  152. (void *, struct stab_handle *, const char **, debug_field *);
  153. static bfd_boolean parse_stab_one_struct_field
  154. (void *, struct stab_handle *, const char **, const char *,
  155. debug_field *, bfd_boolean *);
  156. static bfd_boolean parse_stab_members
  157. (void *, struct stab_handle *, const char *, const char **, const int *,
  158. debug_method **);
  159. static debug_type parse_stab_argtypes
  160. (void *, struct stab_handle *, debug_type, const char *, const char *,
  161. debug_type, const char *, bfd_boolean, bfd_boolean, const char **);
  162. static bfd_boolean parse_stab_tilde_field
  163. (void *, struct stab_handle *, const char **, const int *, debug_type *,
  164. bfd_boolean *);
  165. static debug_type parse_stab_array_type
  166. (void *, struct stab_handle *, const char **, bfd_boolean);
  167. static void push_bincl (struct stab_handle *, const char *, bfd_vma);
  168. static const char *pop_bincl (struct stab_handle *);
  169. static bfd_boolean find_excl (struct stab_handle *, const char *, bfd_vma);
  170. static bfd_boolean stab_record_variable
  171. (void *, struct stab_handle *, const char *, debug_type,
  172. enum debug_var_kind, bfd_vma);
  173. static bfd_boolean stab_emit_pending_vars (void *, struct stab_handle *);
  174. static debug_type *stab_find_slot (struct stab_handle *, const int *);
  175. static debug_type stab_find_type (void *, struct stab_handle *, const int *);
  176. static bfd_boolean stab_record_type
  177. (void *, struct stab_handle *, const int *, debug_type);
  178. static debug_type stab_xcoff_builtin_type
  179. (void *, struct stab_handle *, int);
  180. static debug_type stab_find_tagged_type
  181. (void *, struct stab_handle *, const char *, int, enum debug_type_kind);
  182. static debug_type *stab_demangle_argtypes
  183. (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int);
  184. static debug_type *stab_demangle_v3_argtypes
  185. (void *, struct stab_handle *, const char *, bfd_boolean *);
  186. static debug_type *stab_demangle_v3_arglist
  187. (void *, struct stab_handle *, struct demangle_component *, bfd_boolean *);
  188. static debug_type stab_demangle_v3_arg
  189. (void *, struct stab_handle *, struct demangle_component *, debug_type,
  190. bfd_boolean *);
  191. /* Save a string in memory. */
  192. static char *
  193. savestring (const char *start, int len)
  194. {
  195. char *ret;
  196. ret = (char *) xmalloc (len + 1);
  197. memcpy (ret, start, len);
  198. ret[len] = '\0';
  199. return ret;
  200. }
  201. /* Read a number from a string. */
  202. static bfd_vma
  203. parse_number (const char **pp, bfd_boolean *poverflow)
  204. {
  205. unsigned long ul;
  206. const char *orig;
  207. if (poverflow != NULL)
  208. *poverflow = FALSE;
  209. orig = *pp;
  210. errno = 0;
  211. ul = strtoul (*pp, (char **) pp, 0);
  212. if (ul + 1 != 0 || errno == 0)
  213. {
  214. /* If bfd_vma is larger than unsigned long, and the number is
  215. meant to be negative, we have to make sure that we sign
  216. extend properly. */
  217. if (*orig == '-')
  218. return (bfd_vma) (bfd_signed_vma) (long) ul;
  219. return (bfd_vma) ul;
  220. }
  221. /* Note that even though strtoul overflowed, it should have set *pp
  222. to the end of the number, which is where we want it. */
  223. if (sizeof (bfd_vma) > sizeof (unsigned long))
  224. {
  225. const char *p;
  226. bfd_boolean neg;
  227. int base;
  228. bfd_vma over, lastdig;
  229. bfd_boolean overflow;
  230. bfd_vma v;
  231. /* Our own version of strtoul, for a bfd_vma. */
  232. p = orig;
  233. neg = FALSE;
  234. if (*p == '+')
  235. ++p;
  236. else if (*p == '-')
  237. {
  238. neg = TRUE;
  239. ++p;
  240. }
  241. base = 10;
  242. if (*p == '0')
  243. {
  244. if (p[1] == 'x' || p[1] == 'X')
  245. {
  246. base = 16;
  247. p += 2;
  248. }
  249. else
  250. {
  251. base = 8;
  252. ++p;
  253. }
  254. }
  255. over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
  256. lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
  257. overflow = FALSE;
  258. v = 0;
  259. while (1)
  260. {
  261. int d;
  262. d = *p++;
  263. if (ISDIGIT (d))
  264. d -= '0';
  265. else if (ISUPPER (d))
  266. d -= 'A';
  267. else if (ISLOWER (d))
  268. d -= 'a';
  269. else
  270. break;
  271. if (d >= base)
  272. break;
  273. if (v > over || (v == over && (bfd_vma) d > lastdig))
  274. {
  275. overflow = TRUE;
  276. break;
  277. }
  278. }
  279. if (! overflow)
  280. {
  281. if (neg)
  282. v = - v;
  283. return v;
  284. }
  285. }
  286. /* If we get here, the number is too large to represent in a
  287. bfd_vma. */
  288. if (poverflow != NULL)
  289. *poverflow = TRUE;
  290. else
  291. warn_stab (orig, _("numeric overflow"));
  292. return 0;
  293. }
  294. /* Give an error for a bad stab string. */
  295. static void
  296. bad_stab (const char *p)
  297. {
  298. fprintf (stderr, _("Bad stab: %s\n"), p);
  299. }
  300. /* Warn about something in a stab string. */
  301. static void
  302. warn_stab (const char *p, const char *err)
  303. {
  304. fprintf (stderr, _("Warning: %s: %s\n"), err, p);
  305. }
  306. /* Create a handle to parse stabs symbols with. */
  307. void *
  308. start_stab (void *dhandle ATTRIBUTE_UNUSED, bfd *abfd, bfd_boolean sections,
  309. asymbol **syms, long symcount)
  310. {
  311. struct stab_handle *ret;
  312. ret = (struct stab_handle *) xmalloc (sizeof *ret);
  313. memset (ret, 0, sizeof *ret);
  314. ret->abfd = abfd;
  315. ret->sections = sections;
  316. ret->syms = syms;
  317. ret->symcount = symcount;
  318. ret->files = 1;
  319. ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
  320. ret->file_types[0] = NULL;
  321. ret->function_end = (bfd_vma) -1;
  322. return (void *) ret;
  323. }
  324. /* When we have processed all the stabs information, we need to go
  325. through and fill in all the undefined tags. */
  326. bfd_boolean
  327. finish_stab (void *dhandle, void *handle)
  328. {
  329. struct stab_handle *info = (struct stab_handle *) handle;
  330. struct stab_tag *st;
  331. if (info->within_function)
  332. {
  333. if (! stab_emit_pending_vars (dhandle, info)
  334. || ! debug_end_function (dhandle, info->function_end))
  335. return FALSE;
  336. info->within_function = FALSE;
  337. info->function_end = (bfd_vma) -1;
  338. }
  339. for (st = info->tags; st != NULL; st = st->next)
  340. {
  341. enum debug_type_kind kind;
  342. kind = st->kind;
  343. if (kind == DEBUG_KIND_ILLEGAL)
  344. kind = DEBUG_KIND_STRUCT;
  345. st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
  346. if (st->slot == DEBUG_TYPE_NULL)
  347. return FALSE;
  348. }
  349. return TRUE;
  350. }
  351. /* Handle a single stabs symbol. */
  352. bfd_boolean
  353. parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
  354. const char *string)
  355. {
  356. struct stab_handle *info = (struct stab_handle *) handle;
  357. /* gcc will emit two N_SO strings per compilation unit, one for the
  358. directory name and one for the file name. We just collect N_SO
  359. strings as we see them, and start the new compilation unit when
  360. we see a non N_SO symbol. */
  361. if (info->so_string != NULL
  362. && (type != N_SO || *string == '\0' || value != info->so_value))
  363. {
  364. if (! debug_set_filename (dhandle, info->so_string))
  365. return FALSE;
  366. info->main_filename = info->so_string;
  367. info->gcc_compiled = 0;
  368. info->n_opt_found = FALSE;
  369. /* Generally, for stabs in the symbol table, the N_LBRAC and
  370. N_RBRAC symbols are relative to the N_SO symbol value. */
  371. if (! info->sections)
  372. info->file_start_offset = info->so_value;
  373. /* We need to reset the mapping from type numbers to types. We
  374. can't free the old mapping, because of the use of
  375. debug_make_indirect_type. */
  376. info->files = 1;
  377. info->file_types = ((struct stab_types **)
  378. xmalloc (sizeof *info->file_types));
  379. info->file_types[0] = NULL;
  380. info->so_string = NULL;
  381. /* Now process whatever type we just got. */
  382. }
  383. switch (type)
  384. {
  385. case N_FN:
  386. case N_FN_SEQ:
  387. break;
  388. case N_LBRAC:
  389. /* Ignore extra outermost context from SunPRO cc and acc. */
  390. if (info->n_opt_found && desc == 1)
  391. break;
  392. if (! info->within_function)
  393. {
  394. fprintf (stderr, _("N_LBRAC not within function\n"));
  395. return FALSE;
  396. }
  397. /* Start an inner lexical block. */
  398. if (! debug_start_block (dhandle,
  399. (value
  400. + info->file_start_offset
  401. + info->function_start_offset)))
  402. return FALSE;
  403. /* Emit any pending variable definitions. */
  404. if (! stab_emit_pending_vars (dhandle, info))
  405. return FALSE;
  406. ++info->block_depth;
  407. break;
  408. case N_RBRAC:
  409. /* Ignore extra outermost context from SunPRO cc and acc. */
  410. if (info->n_opt_found && desc == 1)
  411. break;
  412. /* We shouldn't have any pending variable definitions here, but,
  413. if we do, we probably need to emit them before closing the
  414. block. */
  415. if (! stab_emit_pending_vars (dhandle, info))
  416. return FALSE;
  417. /* End an inner lexical block. */
  418. if (! debug_end_block (dhandle,
  419. (value
  420. + info->file_start_offset
  421. + info->function_start_offset)))
  422. return FALSE;
  423. --info->block_depth;
  424. if (info->block_depth < 0)
  425. {
  426. fprintf (stderr, _("Too many N_RBRACs\n"));
  427. return FALSE;
  428. }
  429. break;
  430. case N_SO:
  431. /* This always ends a function. */
  432. if (info->within_function)
  433. {
  434. bfd_vma endval;
  435. endval = value;
  436. if (*string != '\0'
  437. && info->function_end != (bfd_vma) -1
  438. && info->function_end < endval)
  439. endval = info->function_end;
  440. if (! stab_emit_pending_vars (dhandle, info)
  441. || ! debug_end_function (dhandle, endval))
  442. return FALSE;
  443. info->within_function = FALSE;
  444. info->function_end = (bfd_vma) -1;
  445. }
  446. /* An empty string is emitted by gcc at the end of a compilation
  447. unit. */
  448. if (*string == '\0')
  449. return TRUE;
  450. /* Just accumulate strings until we see a non N_SO symbol. If
  451. the string starts with a directory separator or some other
  452. form of absolute path specification, we discard the previously
  453. accumulated strings. */
  454. if (info->so_string == NULL)
  455. info->so_string = xstrdup (string);
  456. else
  457. {
  458. char *f;
  459. f = info->so_string;
  460. if (IS_ABSOLUTE_PATH (string))
  461. info->so_string = xstrdup (string);
  462. else
  463. info->so_string = concat (info->so_string, string,
  464. (const char *) NULL);
  465. free (f);
  466. }
  467. info->so_value = value;
  468. break;
  469. case N_SOL:
  470. /* Start an include file. */
  471. if (! debug_start_source (dhandle, string))
  472. return FALSE;
  473. break;
  474. case N_BINCL:
  475. /* Start an include file which may be replaced. */
  476. push_bincl (info, string, value);
  477. if (! debug_start_source (dhandle, string))
  478. return FALSE;
  479. break;
  480. case N_EINCL:
  481. /* End an N_BINCL include. */
  482. if (! debug_start_source (dhandle, pop_bincl (info)))
  483. return FALSE;
  484. break;
  485. case N_EXCL:
  486. /* This is a duplicate of a header file named by N_BINCL which
  487. was eliminated by the linker. */
  488. if (! find_excl (info, string, value))
  489. return FALSE;
  490. break;
  491. case N_SLINE:
  492. if (! debug_record_line (dhandle, desc,
  493. value + (info->within_function
  494. ? info->function_start_offset : 0)))
  495. return FALSE;
  496. break;
  497. case N_BCOMM:
  498. if (! debug_start_common_block (dhandle, string))
  499. return FALSE;
  500. break;
  501. case N_ECOMM:
  502. if (! debug_end_common_block (dhandle, string))
  503. return FALSE;
  504. break;
  505. case N_FUN:
  506. if (*string == '\0')
  507. {
  508. if (info->within_function)
  509. {
  510. /* This always marks the end of a function; we don't
  511. need to worry about info->function_end. */
  512. if (info->sections)
  513. value += info->function_start_offset;
  514. if (! stab_emit_pending_vars (dhandle, info)
  515. || ! debug_end_function (dhandle, value))
  516. return FALSE;
  517. info->within_function = FALSE;
  518. info->function_end = (bfd_vma) -1;
  519. }
  520. break;
  521. }
  522. /* A const static symbol in the .text section will have an N_FUN
  523. entry. We need to use these to mark the end of the function,
  524. in case we are looking at gcc output before it was changed to
  525. always emit an empty N_FUN. We can't call debug_end_function
  526. here, because it might be a local static symbol. */
  527. if (info->within_function
  528. && (info->function_end == (bfd_vma) -1
  529. || value < info->function_end))
  530. info->function_end = value;
  531. /* Fall through. */
  532. /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
  533. symbols, and if it does not start with :S, gdb relocates the
  534. value to the start of the section. gcc always seems to use
  535. :S, so we don't worry about this. */
  536. /* Fall through. */
  537. default:
  538. {
  539. const char *colon;
  540. colon = strchr (string, ':');
  541. if (colon != NULL
  542. && (colon[1] == 'f' || colon[1] == 'F'))
  543. {
  544. if (info->within_function)
  545. {
  546. bfd_vma endval;
  547. endval = value;
  548. if (info->function_end != (bfd_vma) -1
  549. && info->function_end < endval)
  550. endval = info->function_end;
  551. if (! stab_emit_pending_vars (dhandle, info)
  552. || ! debug_end_function (dhandle, endval))
  553. return FALSE;
  554. info->function_end = (bfd_vma) -1;
  555. }
  556. /* For stabs in sections, line numbers and block addresses
  557. are offsets from the start of the function. */
  558. if (info->sections)
  559. info->function_start_offset = value;
  560. info->within_function = TRUE;
  561. }
  562. if (! parse_stab_string (dhandle, info, type, desc, value, string))
  563. return FALSE;
  564. }
  565. break;
  566. case N_OPT:
  567. if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
  568. info->gcc_compiled = 2;
  569. else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
  570. info->gcc_compiled = 1;
  571. else
  572. info->n_opt_found = TRUE;
  573. break;
  574. case N_OBJ:
  575. case N_ENDM:
  576. case N_MAIN:
  577. case N_WARNING:
  578. break;
  579. }
  580. return TRUE;
  581. }
  582. /* Parse the stabs string. */
  583. static bfd_boolean
  584. parse_stab_string (void *dhandle, struct stab_handle *info, int stabtype,
  585. int desc ATTRIBUTE_UNUSED, bfd_vma value, const char *string)
  586. {
  587. const char *p;
  588. char *name;
  589. int type;
  590. debug_type dtype;
  591. bfd_boolean synonym;
  592. bfd_boolean self_crossref;
  593. debug_type *slot;
  594. p = strchr (string, ':');
  595. if (p == NULL)
  596. return TRUE;
  597. while (p[1] == ':')
  598. {
  599. p += 2;
  600. p = strchr (p, ':');
  601. if (p == NULL)
  602. {
  603. bad_stab (string);
  604. return FALSE;
  605. }
  606. }
  607. /* FIXME: Sometimes the special C++ names start with '.'. */
  608. name = NULL;
  609. if (string[0] == '$')
  610. {
  611. switch (string[1])
  612. {
  613. case 't':
  614. name = "this";
  615. break;
  616. case 'v':
  617. /* Was: name = "vptr"; */
  618. break;
  619. case 'e':
  620. name = "eh_throw";
  621. break;
  622. case '_':
  623. /* This was an anonymous type that was never fixed up. */
  624. break;
  625. case 'X':
  626. /* SunPRO (3.0 at least) static variable encoding. */
  627. break;
  628. default:
  629. warn_stab (string, _("unknown C++ encoded name"));
  630. break;
  631. }
  632. }
  633. if (name == NULL)
  634. {
  635. if (p == string || (string[0] == ' ' && p == string + 1))
  636. name = NULL;
  637. else
  638. name = savestring (string, p - string);
  639. }
  640. ++p;
  641. if (ISDIGIT (*p) || *p == '(' || *p == '-')
  642. type = 'l';
  643. else
  644. type = *p++;
  645. switch (type)
  646. {
  647. case 'c':
  648. /* c is a special case, not followed by a type-number.
  649. SYMBOL:c=iVALUE for an integer constant symbol.
  650. SYMBOL:c=rVALUE for a floating constant symbol.
  651. SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
  652. e.g. "b:c=e6,0" for "const b = blob1"
  653. (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
  654. if (*p != '=')
  655. {
  656. bad_stab (string);
  657. return FALSE;
  658. }
  659. ++p;
  660. switch (*p++)
  661. {
  662. case 'r':
  663. /* Floating point constant. */
  664. if (! debug_record_float_const (dhandle, name, atof (p)))
  665. return FALSE;
  666. break;
  667. case 'i':
  668. /* Integer constant. */
  669. /* Defining integer constants this way is kind of silly,
  670. since 'e' constants allows the compiler to give not only
  671. the value, but the type as well. C has at least int,
  672. long, unsigned int, and long long as constant types;
  673. other languages probably should have at least unsigned as
  674. well as signed constants. */
  675. if (! debug_record_int_const (dhandle, name, atoi (p)))
  676. return FALSE;
  677. break;
  678. case 'e':
  679. /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
  680. can be represented as integral.
  681. e.g. "b:c=e6,0" for "const b = blob1"
  682. (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
  683. dtype = parse_stab_type (dhandle, info, (const char *) NULL,
  684. &p, (debug_type **) NULL);
  685. if (dtype == DEBUG_TYPE_NULL)
  686. return FALSE;
  687. if (*p != ',')
  688. {
  689. bad_stab (string);
  690. return FALSE;
  691. }
  692. if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
  693. return FALSE;
  694. break;
  695. default:
  696. bad_stab (string);
  697. return FALSE;
  698. }
  699. break;
  700. case 'C':
  701. /* The name of a caught exception. */
  702. dtype = parse_stab_type (dhandle, info, (const char *) NULL,
  703. &p, (debug_type **) NULL);
  704. if (dtype == DEBUG_TYPE_NULL)
  705. return FALSE;
  706. if (! debug_record_label (dhandle, name, dtype, value))
  707. return FALSE;
  708. break;
  709. case 'f':
  710. case 'F':
  711. /* A function definition. */
  712. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  713. (debug_type **) NULL);
  714. if (dtype == DEBUG_TYPE_NULL)
  715. return FALSE;
  716. if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
  717. return FALSE;
  718. /* Sun acc puts declared types of arguments here. We don't care
  719. about their actual types (FIXME -- we should remember the whole
  720. function prototype), but the list may define some new types
  721. that we have to remember, so we must scan it now. */
  722. while (*p == ';')
  723. {
  724. ++p;
  725. if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
  726. (debug_type **) NULL)
  727. == DEBUG_TYPE_NULL)
  728. return FALSE;
  729. }
  730. break;
  731. case 'G':
  732. {
  733. asymbol **ps;
  734. /* A global symbol. The value must be extracted from the
  735. symbol table. */
  736. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  737. (debug_type **) NULL);
  738. if (dtype == DEBUG_TYPE_NULL)
  739. return FALSE;
  740. if (name != NULL)
  741. {
  742. char leading;
  743. long c;
  744. leading = bfd_get_symbol_leading_char (info->abfd);
  745. for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
  746. {
  747. const char *n;
  748. n = bfd_asymbol_name (*ps);
  749. if (leading != '\0' && *n == leading)
  750. ++n;
  751. if (*n == *name && strcmp (n, name) == 0)
  752. break;
  753. }
  754. if (c > 0)
  755. value = bfd_asymbol_value (*ps);
  756. }
  757. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
  758. value))
  759. return FALSE;
  760. }
  761. break;
  762. /* This case is faked by a conditional above, when there is no
  763. code letter in the dbx data. Dbx data never actually
  764. contains 'l'. */
  765. case 'l':
  766. case 's':
  767. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  768. (debug_type **) NULL);
  769. if (dtype == DEBUG_TYPE_NULL)
  770. return FALSE;
  771. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
  772. value))
  773. return FALSE;
  774. break;
  775. case 'p':
  776. /* A function parameter. */
  777. if (*p != 'F')
  778. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  779. (debug_type **) NULL);
  780. else
  781. {
  782. /* pF is a two-letter code that means a function parameter in
  783. Fortran. The type-number specifies the type of the return
  784. value. Translate it into a pointer-to-function type. */
  785. ++p;
  786. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  787. (debug_type **) NULL);
  788. if (dtype != DEBUG_TYPE_NULL)
  789. {
  790. debug_type ftype;
  791. ftype = debug_make_function_type (dhandle, dtype,
  792. (debug_type *) NULL, FALSE);
  793. dtype = debug_make_pointer_type (dhandle, ftype);
  794. }
  795. }
  796. if (dtype == DEBUG_TYPE_NULL)
  797. return FALSE;
  798. if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
  799. value))
  800. return FALSE;
  801. /* FIXME: At this point gdb considers rearranging the parameter
  802. address on a big endian machine if it is smaller than an int.
  803. We have no way to do that, since we don't really know much
  804. about the target. */
  805. break;
  806. case 'P':
  807. if (stabtype == N_FUN)
  808. {
  809. /* Prototype of a function referenced by this file. */
  810. while (*p == ';')
  811. {
  812. ++p;
  813. if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
  814. (debug_type **) NULL)
  815. == DEBUG_TYPE_NULL)
  816. return FALSE;
  817. }
  818. break;
  819. }
  820. /* Fall through. */
  821. case 'R':
  822. /* Parameter which is in a register. */
  823. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  824. (debug_type **) NULL);
  825. if (dtype == DEBUG_TYPE_NULL)
  826. return FALSE;
  827. if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
  828. value))
  829. return FALSE;
  830. break;
  831. case 'r':
  832. /* Register variable (either global or local). */
  833. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  834. (debug_type **) NULL);
  835. if (dtype == DEBUG_TYPE_NULL)
  836. return FALSE;
  837. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
  838. value))
  839. return FALSE;
  840. /* FIXME: At this point gdb checks to combine pairs of 'p' and
  841. 'r' stabs into a single 'P' stab. */
  842. break;
  843. case 'S':
  844. /* Static symbol at top level of file. */
  845. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  846. (debug_type **) NULL);
  847. if (dtype == DEBUG_TYPE_NULL)
  848. return FALSE;
  849. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
  850. value))
  851. return FALSE;
  852. break;
  853. case 't':
  854. /* A typedef. */
  855. dtype = parse_stab_type (dhandle, info, name, &p, &slot);
  856. if (dtype == DEBUG_TYPE_NULL)
  857. return FALSE;
  858. if (name == NULL)
  859. {
  860. /* A nameless type. Nothing to do. */
  861. return TRUE;
  862. }
  863. dtype = debug_name_type (dhandle, name, dtype);
  864. if (dtype == DEBUG_TYPE_NULL)
  865. return FALSE;
  866. if (slot != NULL)
  867. *slot = dtype;
  868. break;
  869. case 'T':
  870. /* Struct, union, or enum tag. For GNU C++, this can be be followed
  871. by 't' which means we are typedef'ing it as well. */
  872. if (*p != 't')
  873. {
  874. synonym = FALSE;
  875. /* FIXME: gdb sets synonym to TRUE if the current language
  876. is C++. */
  877. }
  878. else
  879. {
  880. synonym = TRUE;
  881. ++p;
  882. }
  883. dtype = parse_stab_type (dhandle, info, name, &p, &slot);
  884. if (dtype == DEBUG_TYPE_NULL)
  885. return FALSE;
  886. if (name == NULL)
  887. return TRUE;
  888. /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
  889. a cross reference to itself. These are generated by some
  890. versions of g++. */
  891. self_crossref = info->self_crossref;
  892. dtype = debug_tag_type (dhandle, name, dtype);
  893. if (dtype == DEBUG_TYPE_NULL)
  894. return FALSE;
  895. if (slot != NULL)
  896. *slot = dtype;
  897. /* See if we have a cross reference to this tag which we can now
  898. fill in. Avoid filling in a cross reference to ourselves,
  899. because that would lead to circular debugging information. */
  900. if (! self_crossref)
  901. {
  902. register struct stab_tag **pst;
  903. for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
  904. {
  905. if ((*pst)->name[0] == name[0]
  906. && strcmp ((*pst)->name, name) == 0)
  907. {
  908. (*pst)->slot = dtype;
  909. *pst = (*pst)->next;
  910. break;
  911. }
  912. }
  913. }
  914. if (synonym)
  915. {
  916. dtype = debug_name_type (dhandle, name, dtype);
  917. if (dtype == DEBUG_TYPE_NULL)
  918. return FALSE;
  919. if (slot != NULL)
  920. *slot = dtype;
  921. }
  922. break;
  923. case 'V':
  924. /* Static symbol of local scope */
  925. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  926. (debug_type **) NULL);
  927. if (dtype == DEBUG_TYPE_NULL)
  928. return FALSE;
  929. /* FIXME: gdb checks os9k_stabs here. */
  930. if (! stab_record_variable (dhandle, info, name, dtype,
  931. DEBUG_LOCAL_STATIC, value))
  932. return FALSE;
  933. break;
  934. case 'v':
  935. /* Reference parameter. */
  936. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  937. (debug_type **) NULL);
  938. if (dtype == DEBUG_TYPE_NULL)
  939. return FALSE;
  940. if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
  941. value))
  942. return FALSE;
  943. break;
  944. case 'a':
  945. /* Reference parameter which is in a register. */
  946. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  947. (debug_type **) NULL);
  948. if (dtype == DEBUG_TYPE_NULL)
  949. return FALSE;
  950. if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
  951. value))
  952. return FALSE;
  953. break;
  954. case 'X':
  955. /* This is used by Sun FORTRAN for "function result value".
  956. Sun claims ("dbx and dbxtool interfaces", 2nd ed)
  957. that Pascal uses it too, but when I tried it Pascal used
  958. "x:3" (local symbol) instead. */
  959. dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
  960. (debug_type **) NULL);
  961. if (dtype == DEBUG_TYPE_NULL)
  962. return FALSE;
  963. if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
  964. value))
  965. return FALSE;
  966. break;
  967. case 'Y':
  968. /* SUNPro C++ Namespace =Yn0. */
  969. /* Skip the namespace mapping, as it is not used now. */
  970. if (*(++p) == 'n' && *(++p) == '0')
  971. {
  972. /* =Yn0name; */
  973. while (*p != ';')
  974. ++p;
  975. ++p;
  976. return TRUE;
  977. }
  978. /* TODO SUNPro C++ support:
  979. Support default arguments after F,P parameters
  980. Ya = Anonymous unions
  981. YM,YD = Pointers to class members
  982. YT,YI = Templates
  983. YR = Run-time type information (RTTI) */
  984. /* Fall through. */
  985. default:
  986. bad_stab (string);
  987. return FALSE;
  988. }
  989. /* FIXME: gdb converts structure values to structure pointers in a
  990. couple of cases, depending upon the target. */
  991. return TRUE;
  992. }
  993. /* Parse a stabs type. The typename argument is non-NULL if this is a
  994. typedef or a tag definition. The pp argument points to the stab
  995. string, and is updated. The slotp argument points to a place to
  996. store the slot used if the type is being defined. */
  997. static debug_type
  998. parse_stab_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, debug_type **slotp)
  999. {
  1000. const char *orig;
  1001. int typenums[2];
  1002. int size;
  1003. bfd_boolean stringp;
  1004. int descriptor;
  1005. debug_type dtype;
  1006. if (slotp != NULL)
  1007. *slotp = NULL;
  1008. orig = *pp;
  1009. size = -1;
  1010. stringp = FALSE;
  1011. info->self_crossref = FALSE;
  1012. /* Read type number if present. The type number may be omitted.
  1013. for instance in a two-dimensional array declared with type
  1014. "ar1;1;10;ar1;1;10;4". */
  1015. if (! ISDIGIT (**pp) && **pp != '(' && **pp != '-')
  1016. {
  1017. /* 'typenums=' not present, type is anonymous. Read and return
  1018. the definition, but don't put it in the type vector. */
  1019. typenums[0] = typenums[1] = -1;
  1020. }
  1021. else
  1022. {
  1023. if (! parse_stab_type_number (pp, typenums))
  1024. return DEBUG_TYPE_NULL;
  1025. if (**pp != '=')
  1026. /* Type is not being defined here. Either it already
  1027. exists, or this is a forward reference to it. */
  1028. return stab_find_type (dhandle, info, typenums);
  1029. /* Only set the slot if the type is being defined. This means
  1030. that the mapping from type numbers to types will only record
  1031. the name of the typedef which defines a type. If we don't do
  1032. this, then something like
  1033. typedef int foo;
  1034. int i;
  1035. will record that i is of type foo. Unfortunately, stabs
  1036. information is ambiguous about variable types. For this code,
  1037. typedef int foo;
  1038. int i;
  1039. foo j;
  1040. the stabs information records both i and j as having the same
  1041. type. This could be fixed by patching the compiler. */
  1042. if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
  1043. *slotp = stab_find_slot (info, typenums);
  1044. /* Type is being defined here. */
  1045. /* Skip the '='. */
  1046. ++*pp;
  1047. while (**pp == '@')
  1048. {
  1049. const char *p = *pp + 1;
  1050. const char *attr;
  1051. if (ISDIGIT (*p) || *p == '(' || *p == '-')
  1052. /* Member type. */
  1053. break;
  1054. /* Type attributes. */
  1055. attr = p;
  1056. for (; *p != ';'; ++p)
  1057. {
  1058. if (*p == '\0')
  1059. {
  1060. bad_stab (orig);
  1061. return DEBUG_TYPE_NULL;
  1062. }
  1063. }
  1064. *pp = p + 1;
  1065. switch (*attr)
  1066. {
  1067. case 's':
  1068. size = atoi (attr + 1);
  1069. size /= 8; /* Size is in bits. We store it in bytes. */
  1070. if (size <= 0)
  1071. size = -1;
  1072. break;
  1073. case 'S':
  1074. stringp = TRUE;
  1075. break;
  1076. default:
  1077. /* Ignore unrecognized type attributes, so future
  1078. compilers can invent new ones. */
  1079. break;
  1080. }
  1081. }
  1082. }
  1083. descriptor = **pp;
  1084. ++*pp;
  1085. switch (descriptor)
  1086. {
  1087. case 'x':
  1088. {
  1089. enum debug_type_kind code;
  1090. const char *q1, *q2, *p;
  1091. /* A cross reference to another type. */
  1092. switch (**pp)
  1093. {
  1094. case 's':
  1095. code = DEBUG_KIND_STRUCT;
  1096. break;
  1097. case 'u':
  1098. code = DEBUG_KIND_UNION;
  1099. break;
  1100. case 'e':
  1101. code = DEBUG_KIND_ENUM;
  1102. break;
  1103. default:
  1104. /* Complain and keep going, so compilers can invent new
  1105. cross-reference types. */
  1106. warn_stab (orig, _("unrecognized cross reference type"));
  1107. code = DEBUG_KIND_STRUCT;
  1108. break;
  1109. }
  1110. ++*pp;
  1111. q1 = strchr (*pp, '<');
  1112. p = strchr (*pp, ':');
  1113. if (p == NULL)
  1114. {
  1115. bad_stab (orig);
  1116. return DEBUG_TYPE_NULL;
  1117. }
  1118. if (q1 != NULL && p > q1 && p[1] == ':')
  1119. {
  1120. int nest = 0;
  1121. for (q2 = q1; *q2 != '\0'; ++q2)
  1122. {
  1123. if (*q2 == '<')
  1124. ++nest;
  1125. else if (*q2 == '>')
  1126. --nest;
  1127. else if (*q2 == ':' && nest == 0)
  1128. break;
  1129. }
  1130. p = q2;
  1131. if (*p != ':')
  1132. {
  1133. bad_stab (orig);
  1134. return DEBUG_TYPE_NULL;
  1135. }
  1136. }
  1137. /* Some versions of g++ can emit stabs like
  1138. fleep:T20=xsfleep:
  1139. which define structures in terms of themselves. We need to
  1140. tell the caller to avoid building a circular structure. */
  1141. if (type_name != NULL
  1142. && strncmp (type_name, *pp, p - *pp) == 0
  1143. && type_name[p - *pp] == '\0')
  1144. info->self_crossref = TRUE;
  1145. dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
  1146. *pp = p + 1;
  1147. }
  1148. break;
  1149. case '-':
  1150. case '0':
  1151. case '1':
  1152. case '2':
  1153. case '3':
  1154. case '4':
  1155. case '5':
  1156. case '6':
  1157. case '7':
  1158. case '8':
  1159. case '9':
  1160. case '(':
  1161. {
  1162. const char *hold;
  1163. int xtypenums[2];
  1164. /* This type is defined as another type. */
  1165. (*pp)--;
  1166. hold = *pp;
  1167. /* Peek ahead at the number to detect void. */
  1168. if (! parse_stab_type_number (pp, xtypenums))
  1169. return DEBUG_TYPE_NULL;
  1170. if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
  1171. {
  1172. /* This type is being defined as itself, which means that
  1173. it is void. */
  1174. dtype = debug_make_void_type (dhandle);
  1175. }
  1176. else
  1177. {
  1178. *pp = hold;
  1179. /* Go back to the number and have parse_stab_type get it.
  1180. This means that we can deal with something like
  1181. t(1,2)=(3,4)=... which the Lucid compiler uses. */
  1182. dtype = parse_stab_type (dhandle, info, (const char *) NULL,
  1183. pp, (debug_type **) NULL);
  1184. if (dtype == DEBUG_TYPE_NULL)
  1185. return DEBUG_TYPE_NULL;
  1186. }
  1187. if (typenums[0] != -1)
  1188. {
  1189. if (! stab_record_type (dhandle, info, typenums, dtype))
  1190. return DEBUG_TYPE_NULL;
  1191. }
  1192. break;
  1193. }
  1194. case '*':
  1195. dtype = debug_make_pointer_type (dhandle,
  1196. parse_stab_type (dhandle, info,
  1197. (const char *) NULL,
  1198. pp,
  1199. (debug_type **) NULL));
  1200. break;
  1201. case '&':
  1202. /* Reference to another type. */
  1203. dtype = (debug_make_reference_type
  1204. (dhandle,
  1205. parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1206. (debug_type **) NULL)));
  1207. break;
  1208. case 'f':
  1209. /* Function returning another type. */
  1210. /* FIXME: gdb checks os9k_stabs here. */
  1211. dtype = (debug_make_function_type
  1212. (dhandle,
  1213. parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1214. (debug_type **) NULL),
  1215. (debug_type *) NULL, FALSE));
  1216. break;
  1217. case 'k':
  1218. /* Const qualifier on some type (Sun). */
  1219. /* FIXME: gdb accepts 'c' here if os9k_stabs. */
  1220. dtype = debug_make_const_type (dhandle,
  1221. parse_stab_type (dhandle, info,
  1222. (const char *) NULL,
  1223. pp,
  1224. (debug_type **) NULL));
  1225. break;
  1226. case 'B':
  1227. /* Volatile qual on some type (Sun). */
  1228. /* FIXME: gdb accepts 'i' here if os9k_stabs. */
  1229. dtype = (debug_make_volatile_type
  1230. (dhandle,
  1231. parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1232. (debug_type **) NULL)));
  1233. break;
  1234. case '@':
  1235. /* Offset (class & variable) type. This is used for a pointer
  1236. relative to an object. */
  1237. {
  1238. debug_type domain;
  1239. debug_type memtype;
  1240. /* Member type. */
  1241. domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1242. (debug_type **) NULL);
  1243. if (domain == DEBUG_TYPE_NULL)
  1244. return DEBUG_TYPE_NULL;
  1245. if (**pp != ',')
  1246. {
  1247. bad_stab (orig);
  1248. return DEBUG_TYPE_NULL;
  1249. }
  1250. ++*pp;
  1251. memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1252. (debug_type **) NULL);
  1253. if (memtype == DEBUG_TYPE_NULL)
  1254. return DEBUG_TYPE_NULL;
  1255. dtype = debug_make_offset_type (dhandle, domain, memtype);
  1256. }
  1257. break;
  1258. case '#':
  1259. /* Method (class & fn) type. */
  1260. if (**pp == '#')
  1261. {
  1262. debug_type return_type;
  1263. ++*pp;
  1264. return_type = parse_stab_type (dhandle, info, (const char *) NULL,
  1265. pp, (debug_type **) NULL);
  1266. if (return_type == DEBUG_TYPE_NULL)
  1267. return DEBUG_TYPE_NULL;
  1268. if (**pp != ';')
  1269. {
  1270. bad_stab (orig);
  1271. return DEBUG_TYPE_NULL;
  1272. }
  1273. ++*pp;
  1274. dtype = debug_make_method_type (dhandle, return_type,
  1275. DEBUG_TYPE_NULL,
  1276. (debug_type *) NULL, FALSE);
  1277. }
  1278. else
  1279. {
  1280. debug_type domain;
  1281. debug_type return_type;
  1282. debug_type *args;
  1283. unsigned int n;
  1284. unsigned int alloc;
  1285. bfd_boolean varargs;
  1286. domain = parse_stab_type (dhandle, info, (const char *) NULL,
  1287. pp, (debug_type **) NULL);
  1288. if (domain == DEBUG_TYPE_NULL)
  1289. return DEBUG_TYPE_NULL;
  1290. if (**pp != ',')
  1291. {
  1292. bad_stab (orig);
  1293. return DEBUG_TYPE_NULL;
  1294. }
  1295. ++*pp;
  1296. return_type = parse_stab_type (dhandle, info, (const char *) NULL,
  1297. pp, (debug_type **) NULL);
  1298. if (return_type == DEBUG_TYPE_NULL)
  1299. return DEBUG_TYPE_NULL;
  1300. alloc = 10;
  1301. args = (debug_type *) xmalloc (alloc * sizeof *args);
  1302. n = 0;
  1303. while (**pp != ';')
  1304. {
  1305. if (**pp != ',')
  1306. {
  1307. bad_stab (orig);
  1308. return DEBUG_TYPE_NULL;
  1309. }
  1310. ++*pp;
  1311. if (n + 1 >= alloc)
  1312. {
  1313. alloc += 10;
  1314. args = ((debug_type *)
  1315. xrealloc (args, alloc * sizeof *args));
  1316. }
  1317. args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
  1318. pp, (debug_type **) NULL);
  1319. if (args[n] == DEBUG_TYPE_NULL)
  1320. return DEBUG_TYPE_NULL;
  1321. ++n;
  1322. }
  1323. ++*pp;
  1324. /* If the last type is not void, then this function takes a
  1325. variable number of arguments. Otherwise, we must strip
  1326. the void type. */
  1327. if (n == 0
  1328. || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
  1329. varargs = TRUE;
  1330. else
  1331. {
  1332. --n;
  1333. varargs = FALSE;
  1334. }
  1335. args[n] = DEBUG_TYPE_NULL;
  1336. dtype = debug_make_method_type (dhandle, return_type, domain, args,
  1337. varargs);
  1338. }
  1339. break;
  1340. case 'r':
  1341. /* Range type. */
  1342. dtype = parse_stab_range_type (dhandle, info, type_name, pp, typenums);
  1343. break;
  1344. case 'b':
  1345. /* FIXME: gdb checks os9k_stabs here. */
  1346. /* Sun ACC builtin int type. */
  1347. dtype = parse_stab_sun_builtin_type (dhandle, pp);
  1348. break;
  1349. case 'R':
  1350. /* Sun ACC builtin float type. */
  1351. dtype = parse_stab_sun_floating_type (dhandle, pp);
  1352. break;
  1353. case 'e':
  1354. /* Enumeration type. */
  1355. dtype = parse_stab_enum_type (dhandle, pp);
  1356. break;
  1357. case 's':
  1358. case 'u':
  1359. /* Struct or union type. */
  1360. dtype = parse_stab_struct_type (dhandle, info, type_name, pp,
  1361. descriptor == 's', typenums);
  1362. break;
  1363. case 'a':
  1364. /* Array type. */
  1365. if (**pp != 'r')
  1366. {
  1367. bad_stab (orig);
  1368. return DEBUG_TYPE_NULL;
  1369. }
  1370. ++*pp;
  1371. dtype = parse_stab_array_type (dhandle, info, pp, stringp);
  1372. break;
  1373. case 'S':
  1374. dtype = debug_make_set_type (dhandle,
  1375. parse_stab_type (dhandle, info,
  1376. (const char *) NULL,
  1377. pp,
  1378. (debug_type **) NULL),
  1379. stringp);
  1380. break;
  1381. default:
  1382. bad_stab (orig);
  1383. return DEBUG_TYPE_NULL;
  1384. }
  1385. if (dtype == DEBUG_TYPE_NULL)
  1386. return DEBUG_TYPE_NULL;
  1387. if (typenums[0] != -1)
  1388. {
  1389. if (! stab_record_type (dhandle, info, typenums, dtype))
  1390. return DEBUG_TYPE_NULL;
  1391. }
  1392. if (size != -1)
  1393. {
  1394. if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
  1395. return DEBUG_TYPE_NULL;
  1396. }
  1397. return dtype;
  1398. }
  1399. /* Read a number by which a type is referred to in dbx data, or
  1400. perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
  1401. single number N is equivalent to (0,N). Return the two numbers by
  1402. storing them in the vector TYPENUMS. */
  1403. static bfd_boolean
  1404. parse_stab_type_number (const char **pp, int *typenums)
  1405. {
  1406. const char *orig;
  1407. orig = *pp;
  1408. if (**pp != '(')
  1409. {
  1410. typenums[0] = 0;
  1411. typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL);
  1412. }
  1413. else
  1414. {
  1415. ++*pp;
  1416. typenums[0] = (int) parse_number (pp, (bfd_boolean *) NULL);
  1417. if (**pp != ',')
  1418. {
  1419. bad_stab (orig);
  1420. return FALSE;
  1421. }
  1422. ++*pp;
  1423. typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL);
  1424. if (**pp != ')')
  1425. {
  1426. bad_stab (orig);
  1427. return FALSE;
  1428. }
  1429. ++*pp;
  1430. }
  1431. return TRUE;
  1432. }
  1433. /* Parse a range type. */
  1434. static debug_type
  1435. parse_stab_range_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, const int *typenums)
  1436. {
  1437. const char *orig;
  1438. int rangenums[2];
  1439. bfd_boolean self_subrange;
  1440. debug_type index_type;
  1441. const char *s2, *s3;
  1442. bfd_signed_vma n2, n3;
  1443. bfd_boolean ov2, ov3;
  1444. orig = *pp;
  1445. index_type = DEBUG_TYPE_NULL;
  1446. /* First comes a type we are a subrange of.
  1447. In C it is usually 0, 1 or the type being defined. */
  1448. if (! parse_stab_type_number (pp, rangenums))
  1449. return DEBUG_TYPE_NULL;
  1450. self_subrange = (rangenums[0] == typenums[0]
  1451. && rangenums[1] == typenums[1]);
  1452. if (**pp == '=')
  1453. {
  1454. *pp = orig;
  1455. index_type = parse_stab_type (dhandle, info, (const char *) NULL,
  1456. pp, (debug_type **) NULL);
  1457. if (index_type == DEBUG_TYPE_NULL)
  1458. return DEBUG_TYPE_NULL;
  1459. }
  1460. if (**pp == ';')
  1461. ++*pp;
  1462. /* The remaining two operands are usually lower and upper bounds of
  1463. the range. But in some special cases they mean something else. */
  1464. s2 = *pp;
  1465. n2 = parse_number (pp, &ov2);
  1466. if (**pp != ';')
  1467. {
  1468. bad_stab (orig);
  1469. return DEBUG_TYPE_NULL;
  1470. }
  1471. ++*pp;
  1472. s3 = *pp;
  1473. n3 = parse_number (pp, &ov3);
  1474. if (**pp != ';')
  1475. {
  1476. bad_stab (orig);
  1477. return DEBUG_TYPE_NULL;
  1478. }
  1479. ++*pp;
  1480. if (ov2 || ov3)
  1481. {
  1482. /* gcc will emit range stabs for long long types. Handle this
  1483. as a special case. FIXME: This needs to be more general. */
  1484. #define LLLOW "01000000000000000000000;"
  1485. #define LLHIGH "0777777777777777777777;"
  1486. #define ULLHIGH "01777777777777777777777;"
  1487. if (index_type == DEBUG_TYPE_NULL)
  1488. {
  1489. if (CONST_STRNEQ (s2, LLLOW)
  1490. && CONST_STRNEQ (s3, LLHIGH))
  1491. return debug_make_int_type (dhandle, 8, FALSE);
  1492. if (! ov2
  1493. && n2 == 0
  1494. && CONST_STRNEQ (s3, ULLHIGH))
  1495. return debug_make_int_type (dhandle, 8, TRUE);
  1496. }
  1497. warn_stab (orig, _("numeric overflow"));
  1498. }
  1499. if (index_type == DEBUG_TYPE_NULL)
  1500. {
  1501. /* A type defined as a subrange of itself, with both bounds 0,
  1502. is void. */
  1503. if (self_subrange && n2 == 0 && n3 == 0)
  1504. return debug_make_void_type (dhandle);
  1505. /* A type defined as a subrange of itself, with n2 positive and
  1506. n3 zero, is a complex type, and n2 is the number of bytes. */
  1507. if (self_subrange && n3 == 0 && n2 > 0)
  1508. return debug_make_complex_type (dhandle, n2);
  1509. /* If n3 is zero and n2 is positive, this is a floating point
  1510. type, and n2 is the number of bytes. */
  1511. if (n3 == 0 && n2 > 0)
  1512. return debug_make_float_type (dhandle, n2);
  1513. /* If the upper bound is -1, this is an unsigned int. */
  1514. if (n2 == 0 && n3 == -1)
  1515. {
  1516. /* When gcc is used with -gstabs, but not -gstabs+, it will emit
  1517. long long int:t6=r1;0;-1;
  1518. long long unsigned int:t7=r1;0;-1;
  1519. We hack here to handle this reasonably. */
  1520. if (type_name != NULL)
  1521. {
  1522. if (strcmp (type_name, "long long int") == 0)
  1523. return debug_make_int_type (dhandle, 8, FALSE);
  1524. else if (strcmp (type_name, "long long unsigned int") == 0)
  1525. return debug_make_int_type (dhandle, 8, TRUE);
  1526. }
  1527. /* FIXME: The size here really depends upon the target. */
  1528. return debug_make_int_type (dhandle, 4, TRUE);
  1529. }
  1530. /* A range of 0 to 127 is char. */
  1531. if (self_subrange && n2 == 0 && n3 == 127)
  1532. return debug_make_int_type (dhandle, 1, FALSE);
  1533. /* FIXME: gdb checks for the language CHILL here. */
  1534. if (n2 == 0)
  1535. {
  1536. if (n3 < 0)
  1537. return debug_make_int_type (dhandle, - n3, TRUE);
  1538. else if (n3 == 0xff)
  1539. return debug_make_int_type (dhandle, 1, TRUE);
  1540. else if (n3 == 0xffff)
  1541. return debug_make_int_type (dhandle, 2, TRUE);
  1542. else if (n3 == (bfd_signed_vma) 0xffffffff)
  1543. return debug_make_int_type (dhandle, 4, TRUE);
  1544. #ifdef BFD64
  1545. else if (n3 == (bfd_signed_vma) 0xffffffffffffffffLL)
  1546. return debug_make_int_type (dhandle, 8, TRUE);
  1547. #endif
  1548. }
  1549. else if (n3 == 0
  1550. && n2 < 0
  1551. && (self_subrange || n2 == -8))
  1552. return debug_make_int_type (dhandle, - n2, TRUE);
  1553. else if (n2 == - n3 - 1 || n2 == n3 + 1)
  1554. {
  1555. if (n3 == 0x7f)
  1556. return debug_make_int_type (dhandle, 1, FALSE);
  1557. else if (n3 == 0x7fff)
  1558. return debug_make_int_type (dhandle, 2, FALSE);
  1559. else if (n3 == 0x7fffffff)
  1560. return debug_make_int_type (dhandle, 4, FALSE);
  1561. #ifdef BFD64
  1562. else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff))
  1563. return debug_make_int_type (dhandle, 8, FALSE);
  1564. #endif
  1565. }
  1566. }
  1567. /* At this point I don't have the faintest idea how to deal with a
  1568. self_subrange type; I'm going to assume that this is used as an
  1569. idiom, and that all of them are special cases. So . . . */
  1570. if (self_subrange)
  1571. {
  1572. bad_stab (orig);
  1573. return DEBUG_TYPE_NULL;
  1574. }
  1575. index_type = stab_find_type (dhandle, info, rangenums);
  1576. if (index_type == DEBUG_TYPE_NULL)
  1577. {
  1578. /* Does this actually ever happen? Is that why we are worrying
  1579. about dealing with it rather than just calling error_type? */
  1580. warn_stab (orig, _("missing index type"));
  1581. index_type = debug_make_int_type (dhandle, 4, FALSE);
  1582. }
  1583. return debug_make_range_type (dhandle, index_type, n2, n3);
  1584. }
  1585. /* Sun's ACC uses a somewhat saner method for specifying the builtin
  1586. typedefs in every file (for int, long, etc):
  1587. type = b <signed> <width>; <offset>; <nbits>
  1588. signed = u or s. Possible c in addition to u or s (for char?).
  1589. offset = offset from high order bit to start bit of type.
  1590. width is # bytes in object of this type, nbits is # bits in type.
  1591. The width/offset stuff appears to be for small objects stored in
  1592. larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
  1593. FIXME. */
  1594. static debug_type
  1595. parse_stab_sun_builtin_type (void *dhandle, const char **pp)
  1596. {
  1597. const char *orig;
  1598. bfd_boolean unsignedp;
  1599. bfd_vma bits;
  1600. orig = *pp;
  1601. switch (**pp)
  1602. {
  1603. case 's':
  1604. unsignedp = FALSE;
  1605. break;
  1606. case 'u':
  1607. unsignedp = TRUE;
  1608. break;
  1609. default:
  1610. bad_stab (orig);
  1611. return DEBUG_TYPE_NULL;
  1612. }
  1613. ++*pp;
  1614. /* OpenSolaris source code indicates that one of "cbv" characters
  1615. can come next and specify the intrinsic 'iformat' encoding.
  1616. 'c' is character encoding, 'b' is boolean encoding, and 'v' is
  1617. varargs encoding. This field can be safely ignored because
  1618. the type of the field is determined from the bitwidth extracted
  1619. below. */
  1620. if (**pp == 'c' || **pp == 'b' || **pp == 'v')
  1621. ++*pp;
  1622. /* The first number appears to be the number of bytes occupied
  1623. by this type, except that unsigned short is 4 instead of 2.
  1624. Since this information is redundant with the third number,
  1625. we will ignore it. */
  1626. (void) parse_number (pp, (bfd_boolean *) NULL);
  1627. if (**pp != ';')
  1628. {
  1629. bad_stab (orig);
  1630. return DEBUG_TYPE_NULL;
  1631. }
  1632. ++*pp;
  1633. /* The second number is always 0, so ignore it too. */
  1634. (void) parse_number (pp, (bfd_boolean *) NULL);
  1635. if (**pp != ';')
  1636. {
  1637. bad_stab (orig);
  1638. return DEBUG_TYPE_NULL;
  1639. }
  1640. ++*pp;
  1641. /* The third number is the number of bits for this type. */
  1642. bits = parse_number (pp, (bfd_boolean *) NULL);
  1643. /* The type *should* end with a semicolon. If it are embedded
  1644. in a larger type the semicolon may be the only way to know where
  1645. the type ends. If this type is at the end of the stabstring we
  1646. can deal with the omitted semicolon (but we don't have to like
  1647. it). Don't bother to complain(), Sun's compiler omits the semicolon
  1648. for "void". */
  1649. if (**pp == ';')
  1650. ++*pp;
  1651. if (bits == 0)
  1652. return debug_make_void_type (dhandle);
  1653. return debug_make_int_type (dhandle, bits / 8, unsignedp);
  1654. }
  1655. /* Parse a builtin floating type generated by the Sun compiler. */
  1656. static debug_type
  1657. parse_stab_sun_floating_type (void *dhandle, const char **pp)
  1658. {
  1659. const char *orig;
  1660. bfd_vma details;
  1661. bfd_vma bytes;
  1662. orig = *pp;
  1663. /* The first number has more details about the type, for example
  1664. FN_COMPLEX. */
  1665. details = parse_number (pp, (bfd_boolean *) NULL);
  1666. if (**pp != ';')
  1667. {
  1668. bad_stab (orig);
  1669. return DEBUG_TYPE_NULL;
  1670. }
  1671. /* The second number is the number of bytes occupied by this type */
  1672. bytes = parse_number (pp, (bfd_boolean *) NULL);
  1673. if (**pp != ';')
  1674. {
  1675. bad_stab (orig);
  1676. return DEBUG_TYPE_NULL;
  1677. }
  1678. if (details == NF_COMPLEX
  1679. || details == NF_COMPLEX16
  1680. || details == NF_COMPLEX32)
  1681. return debug_make_complex_type (dhandle, bytes);
  1682. return debug_make_float_type (dhandle, bytes);
  1683. }
  1684. /* Handle an enum type. */
  1685. static debug_type
  1686. parse_stab_enum_type (void *dhandle, const char **pp)
  1687. {
  1688. const char *orig;
  1689. const char **names;
  1690. bfd_signed_vma *values;
  1691. unsigned int n;
  1692. unsigned int alloc;
  1693. orig = *pp;
  1694. /* FIXME: gdb checks os9k_stabs here. */
  1695. /* The aix4 compiler emits an extra field before the enum members;
  1696. my guess is it's a type of some sort. Just ignore it. */
  1697. if (**pp == '-')
  1698. {
  1699. while (**pp != ':')
  1700. ++*pp;
  1701. ++*pp;
  1702. }
  1703. /* Read the value-names and their values.
  1704. The input syntax is NAME:VALUE,NAME:VALUE, and so on.
  1705. A semicolon or comma instead of a NAME means the end. */
  1706. alloc = 10;
  1707. names = (const char **) xmalloc (alloc * sizeof *names);
  1708. values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
  1709. n = 0;
  1710. while (**pp != '\0' && **pp != ';' && **pp != ',')
  1711. {
  1712. const char *p;
  1713. char *name;
  1714. bfd_signed_vma val;
  1715. p = *pp;
  1716. while (*p != ':')
  1717. ++p;
  1718. name = savestring (*pp, p - *pp);
  1719. *pp = p + 1;
  1720. val = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
  1721. if (**pp != ',')
  1722. {
  1723. bad_stab (orig);
  1724. free (name);
  1725. free (names);
  1726. free (values);
  1727. return DEBUG_TYPE_NULL;
  1728. }
  1729. ++*pp;
  1730. if (n + 1 >= alloc)
  1731. {
  1732. alloc += 10;
  1733. names = ((const char **)
  1734. xrealloc (names, alloc * sizeof *names));
  1735. values = ((bfd_signed_vma *)
  1736. xrealloc (values, alloc * sizeof *values));
  1737. }
  1738. names[n] = name;
  1739. values[n] = val;
  1740. ++n;
  1741. }
  1742. names[n] = NULL;
  1743. values[n] = 0;
  1744. if (**pp == ';')
  1745. ++*pp;
  1746. return debug_make_enum_type (dhandle, names, values);
  1747. }
  1748. /* Read the description of a structure (or union type) and return an object
  1749. describing the type.
  1750. PP points to a character pointer that points to the next unconsumed token
  1751. in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
  1752. *PP will point to "4a:1,0,32;;". */
  1753. static debug_type
  1754. parse_stab_struct_type (void *dhandle, struct stab_handle *info,
  1755. const char *tagname, const char **pp,
  1756. bfd_boolean structp, const int *typenums)
  1757. {
  1758. bfd_vma size;
  1759. debug_baseclass *baseclasses;
  1760. debug_field *fields = NULL;
  1761. bfd_boolean statics;
  1762. debug_method *methods;
  1763. debug_type vptrbase;
  1764. bfd_boolean ownvptr;
  1765. /* Get the size. */
  1766. size = parse_number (pp, (bfd_boolean *) NULL);
  1767. /* Get the other information. */
  1768. if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
  1769. || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
  1770. || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
  1771. || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
  1772. &ownvptr))
  1773. {
  1774. if (fields != NULL)
  1775. free (fields);
  1776. return DEBUG_TYPE_NULL;
  1777. }
  1778. if (! statics
  1779. && baseclasses == NULL
  1780. && methods == NULL
  1781. && vptrbase == DEBUG_TYPE_NULL
  1782. && ! ownvptr)
  1783. return debug_make_struct_type (dhandle, structp, size, fields);
  1784. return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
  1785. methods, vptrbase, ownvptr);
  1786. }
  1787. /* The stabs for C++ derived classes contain baseclass information which
  1788. is marked by a '!' character after the total size. This function is
  1789. called when we encounter the baseclass marker, and slurps up all the
  1790. baseclass information.
  1791. Immediately following the '!' marker is the number of base classes that
  1792. the class is derived from, followed by information for each base class.
  1793. For each base class, there are two visibility specifiers, a bit offset
  1794. to the base class information within the derived class, a reference to
  1795. the type for the base class, and a terminating semicolon.
  1796. A typical example, with two base classes, would be "!2,020,19;0264,21;".
  1797. ^^ ^ ^ ^ ^ ^ ^
  1798. Baseclass information marker __________________|| | | | | | |
  1799. Number of baseclasses __________________________| | | | | | |
  1800. Visibility specifiers (2) ________________________| | | | | |
  1801. Offset in bits from start of class _________________| | | | |
  1802. Type number for base class ___________________________| | | |
  1803. Visibility specifiers (2) _______________________________| | |
  1804. Offset in bits from start of class ________________________| |
  1805. Type number of base class ____________________________________|
  1806. Return TRUE for success, FALSE for failure. */
  1807. static bfd_boolean
  1808. parse_stab_baseclasses (void *dhandle, struct stab_handle *info,
  1809. const char **pp, debug_baseclass **retp)
  1810. {
  1811. const char *orig;
  1812. unsigned int c, i;
  1813. debug_baseclass *classes;
  1814. *retp = NULL;
  1815. orig = *pp;
  1816. if (**pp != '!')
  1817. {
  1818. /* No base classes. */
  1819. return TRUE;
  1820. }
  1821. ++*pp;
  1822. c = (unsigned int) parse_number (pp, (bfd_boolean *) NULL);
  1823. if (**pp != ',')
  1824. {
  1825. bad_stab (orig);
  1826. return FALSE;
  1827. }
  1828. ++*pp;
  1829. classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
  1830. for (i = 0; i < c; i++)
  1831. {
  1832. bfd_boolean is_virtual;
  1833. enum debug_visibility visibility;
  1834. bfd_vma bitpos;
  1835. debug_type type;
  1836. switch (**pp)
  1837. {
  1838. case '0':
  1839. is_virtual = FALSE;
  1840. break;
  1841. case '1':
  1842. is_virtual = TRUE;
  1843. break;
  1844. default:
  1845. warn_stab (orig, _("unknown virtual character for baseclass"));
  1846. is_virtual = FALSE;
  1847. break;
  1848. }
  1849. ++*pp;
  1850. switch (**pp)
  1851. {
  1852. case '0':
  1853. visibility = DEBUG_VISIBILITY_PRIVATE;
  1854. break;
  1855. case '1':
  1856. visibility = DEBUG_VISIBILITY_PROTECTED;
  1857. break;
  1858. case '2':
  1859. visibility = DEBUG_VISIBILITY_PUBLIC;
  1860. break;
  1861. default:
  1862. warn_stab (orig, _("unknown visibility character for baseclass"));
  1863. visibility = DEBUG_VISIBILITY_PUBLIC;
  1864. break;
  1865. }
  1866. ++*pp;
  1867. /* The remaining value is the bit offset of the portion of the
  1868. object corresponding to this baseclass. Always zero in the
  1869. absence of multiple inheritance. */
  1870. bitpos = parse_number (pp, (bfd_boolean *) NULL);
  1871. if (**pp != ',')
  1872. {
  1873. bad_stab (orig);
  1874. return FALSE;
  1875. }
  1876. ++*pp;
  1877. type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1878. (debug_type **) NULL);
  1879. if (type == DEBUG_TYPE_NULL)
  1880. return FALSE;
  1881. classes[i] = debug_make_baseclass (dhandle, type, bitpos, is_virtual,
  1882. visibility);
  1883. if (classes[i] == DEBUG_BASECLASS_NULL)
  1884. return FALSE;
  1885. if (**pp != ';')
  1886. return FALSE;
  1887. ++*pp;
  1888. }
  1889. classes[i] = DEBUG_BASECLASS_NULL;
  1890. *retp = classes;
  1891. return TRUE;
  1892. }
  1893. /* Read struct or class data fields. They have the form:
  1894. NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
  1895. At the end, we see a semicolon instead of a field.
  1896. In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
  1897. a static field.
  1898. The optional VISIBILITY is one of:
  1899. '/0' (VISIBILITY_PRIVATE)
  1900. '/1' (VISIBILITY_PROTECTED)
  1901. '/2' (VISIBILITY_PUBLIC)
  1902. '/9' (VISIBILITY_IGNORE)
  1903. or nothing, for C style fields with public visibility.
  1904. Returns 1 for success, 0 for failure. */
  1905. static bfd_boolean
  1906. parse_stab_struct_fields (void *dhandle, struct stab_handle *info,
  1907. const char **pp, debug_field **retp,
  1908. bfd_boolean *staticsp)
  1909. {
  1910. const char *orig;
  1911. const char *p;
  1912. debug_field *fields;
  1913. unsigned int c;
  1914. unsigned int alloc;
  1915. *retp = NULL;
  1916. *staticsp = FALSE;
  1917. orig = *pp;
  1918. c = 0;
  1919. alloc = 10;
  1920. fields = (debug_field *) xmalloc (alloc * sizeof *fields);
  1921. while (**pp != ';')
  1922. {
  1923. /* FIXME: gdb checks os9k_stabs here. */
  1924. p = *pp;
  1925. /* Add 1 to c to leave room for NULL pointer at end. */
  1926. if (c + 1 >= alloc)
  1927. {
  1928. alloc += 10;
  1929. fields = ((debug_field *)
  1930. xrealloc (fields, alloc * sizeof *fields));
  1931. }
  1932. /* If it starts with CPLUS_MARKER it is a special abbreviation,
  1933. unless the CPLUS_MARKER is followed by an underscore, in
  1934. which case it is just the name of an anonymous type, which we
  1935. should handle like any other type name. We accept either '$'
  1936. or '.', because a field name can never contain one of these
  1937. characters except as a CPLUS_MARKER. */
  1938. if ((*p == '$' || *p == '.') && p[1] != '_')
  1939. {
  1940. ++*pp;
  1941. if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
  1942. {
  1943. free (fields);
  1944. return FALSE;
  1945. }
  1946. ++c;
  1947. continue;
  1948. }
  1949. /* Look for the ':' that separates the field name from the field
  1950. values. Data members are delimited by a single ':', while member
  1951. functions are delimited by a pair of ':'s. When we hit the member
  1952. functions (if any), terminate scan loop and return. */
  1953. p = strchr (p, ':');
  1954. if (p == NULL)
  1955. {
  1956. bad_stab (orig);
  1957. free (fields);
  1958. return FALSE;
  1959. }
  1960. if (p[1] == ':')
  1961. break;
  1962. if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
  1963. staticsp))
  1964. return FALSE;
  1965. ++c;
  1966. }
  1967. fields[c] = DEBUG_FIELD_NULL;
  1968. *retp = fields;
  1969. return TRUE;
  1970. }
  1971. /* Special GNU C++ name. */
  1972. static bfd_boolean
  1973. parse_stab_cpp_abbrev (void *dhandle, struct stab_handle *info,
  1974. const char **pp, debug_field *retp)
  1975. {
  1976. const char *orig;
  1977. int cpp_abbrev;
  1978. debug_type context;
  1979. const char *name;
  1980. const char *type_name;
  1981. debug_type type;
  1982. bfd_vma bitpos;
  1983. *retp = DEBUG_FIELD_NULL;
  1984. orig = *pp;
  1985. if (**pp != 'v')
  1986. {
  1987. bad_stab (*pp);
  1988. return FALSE;
  1989. }
  1990. ++*pp;
  1991. cpp_abbrev = **pp;
  1992. ++*pp;
  1993. /* At this point, *pp points to something like "22:23=*22...", where
  1994. the type number before the ':' is the "context" and everything
  1995. after is a regular type definition. Lookup the type, find it's
  1996. name, and construct the field name. */
  1997. context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  1998. (debug_type **) NULL);
  1999. if (context == DEBUG_TYPE_NULL)
  2000. return FALSE;
  2001. switch (cpp_abbrev)
  2002. {
  2003. case 'f':
  2004. /* $vf -- a virtual function table pointer. */
  2005. name = "_vptr$";
  2006. break;
  2007. case 'b':
  2008. /* $vb -- a virtual bsomethingorother */
  2009. type_name = debug_get_type_name (dhandle, context);
  2010. if (type_name == NULL)
  2011. {
  2012. warn_stab (orig, _("unnamed $vb type"));
  2013. type_name = "FOO";
  2014. }
  2015. name = concat ("_vb$", type_name, (const char *) NULL);
  2016. break;
  2017. default:
  2018. warn_stab (orig, _("unrecognized C++ abbreviation"));
  2019. name = "INVALID_CPLUSPLUS_ABBREV";
  2020. break;
  2021. }
  2022. if (**pp != ':')
  2023. {
  2024. bad_stab (orig);
  2025. return FALSE;
  2026. }
  2027. ++*pp;
  2028. type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2029. (debug_type **) NULL);
  2030. if (**pp != ',')
  2031. {
  2032. bad_stab (orig);
  2033. return FALSE;
  2034. }
  2035. ++*pp;
  2036. bitpos = parse_number (pp, (bfd_boolean *) NULL);
  2037. if (**pp != ';')
  2038. {
  2039. bad_stab (orig);
  2040. return FALSE;
  2041. }
  2042. ++*pp;
  2043. *retp = debug_make_field (dhandle, name, type, bitpos, 0,
  2044. DEBUG_VISIBILITY_PRIVATE);
  2045. if (*retp == DEBUG_FIELD_NULL)
  2046. return FALSE;
  2047. return TRUE;
  2048. }
  2049. /* Parse a single field in a struct or union. */
  2050. static bfd_boolean
  2051. parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
  2052. const char **pp, const char *p,
  2053. debug_field *retp, bfd_boolean *staticsp)
  2054. {
  2055. const char *orig;
  2056. char *name;
  2057. enum debug_visibility visibility;
  2058. debug_type type;
  2059. bfd_vma bitpos;
  2060. bfd_vma bitsize;
  2061. orig = *pp;
  2062. /* FIXME: gdb checks ARM_DEMANGLING here. */
  2063. name = savestring (*pp, p - *pp);
  2064. *pp = p + 1;
  2065. if (**pp != '/')
  2066. visibility = DEBUG_VISIBILITY_PUBLIC;
  2067. else
  2068. {
  2069. ++*pp;
  2070. switch (**pp)
  2071. {
  2072. case '0':
  2073. visibility = DEBUG_VISIBILITY_PRIVATE;
  2074. break;
  2075. case '1':
  2076. visibility = DEBUG_VISIBILITY_PROTECTED;
  2077. break;
  2078. case '2':
  2079. visibility = DEBUG_VISIBILITY_PUBLIC;
  2080. break;
  2081. default:
  2082. warn_stab (orig, _("unknown visibility character for field"));
  2083. visibility = DEBUG_VISIBILITY_PUBLIC;
  2084. break;
  2085. }
  2086. ++*pp;
  2087. }
  2088. type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2089. (debug_type **) NULL);
  2090. if (type == DEBUG_TYPE_NULL)
  2091. {
  2092. free (name);
  2093. return FALSE;
  2094. }
  2095. if (**pp == ':')
  2096. {
  2097. char *varname;
  2098. /* This is a static class member. */
  2099. ++*pp;
  2100. p = strchr (*pp, ';');
  2101. if (p == NULL)
  2102. {
  2103. bad_stab (orig);
  2104. free (name);
  2105. return FALSE;
  2106. }
  2107. varname = savestring (*pp, p - *pp);
  2108. *pp = p + 1;
  2109. *retp = debug_make_static_member (dhandle, name, type, varname,
  2110. visibility);
  2111. *staticsp = TRUE;
  2112. return TRUE;
  2113. }
  2114. if (**pp != ',')
  2115. {
  2116. bad_stab (orig);
  2117. free (name);
  2118. return FALSE;
  2119. }
  2120. ++*pp;
  2121. bitpos = parse_number (pp, (bfd_boolean *) NULL);
  2122. if (**pp != ',')
  2123. {
  2124. bad_stab (orig);
  2125. free (name);
  2126. return FALSE;
  2127. }
  2128. ++*pp;
  2129. bitsize = parse_number (pp, (bfd_boolean *) NULL);
  2130. if (**pp != ';')
  2131. {
  2132. bad_stab (orig);
  2133. free (name);
  2134. return FALSE;
  2135. }
  2136. ++*pp;
  2137. if (bitpos == 0 && bitsize == 0)
  2138. {
  2139. /* This can happen in two cases: (1) at least for gcc 2.4.5 or
  2140. so, it is a field which has been optimized out. The correct
  2141. stab for this case is to use VISIBILITY_IGNORE, but that is a
  2142. recent invention. (2) It is a 0-size array. For example
  2143. union { int num; char str[0]; } foo. Printing "<no value>"
  2144. for str in "p foo" is OK, since foo.str (and thus foo.str[3])
  2145. will continue to work, and a 0-size array as a whole doesn't
  2146. have any contents to print.
  2147. I suspect this probably could also happen with gcc -gstabs
  2148. (not -gstabs+) for static fields, and perhaps other C++
  2149. extensions. Hopefully few people use -gstabs with gdb, since
  2150. it is intended for dbx compatibility. */
  2151. visibility = DEBUG_VISIBILITY_IGNORE;
  2152. }
  2153. /* FIXME: gdb does some stuff here to mark fields as unpacked. */
  2154. *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
  2155. return TRUE;
  2156. }
  2157. /* Read member function stabs info for C++ classes. The form of each member
  2158. function data is:
  2159. NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
  2160. An example with two member functions is:
  2161. afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
  2162. For the case of overloaded operators, the format is op$::*.funcs, where
  2163. $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
  2164. name (such as `+=') and `.' marks the end of the operator name. */
  2165. static bfd_boolean
  2166. parse_stab_members (void *dhandle, struct stab_handle *info,
  2167. const char *tagname, const char **pp,
  2168. const int *typenums, debug_method **retp)
  2169. {
  2170. const char *orig;
  2171. debug_method *methods;
  2172. unsigned int c;
  2173. unsigned int alloc;
  2174. char *name = NULL;
  2175. debug_method_variant *variants = NULL;
  2176. char *argtypes = NULL;
  2177. *retp = NULL;
  2178. orig = *pp;
  2179. alloc = 0;
  2180. methods = NULL;
  2181. c = 0;
  2182. while (**pp != ';')
  2183. {
  2184. const char *p;
  2185. unsigned int cvars;
  2186. unsigned int allocvars;
  2187. debug_type look_ahead_type;
  2188. p = strchr (*pp, ':');
  2189. if (p == NULL || p[1] != ':')
  2190. break;
  2191. /* FIXME: Some systems use something other than '$' here. */
  2192. if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
  2193. {
  2194. name = savestring (*pp, p - *pp);
  2195. *pp = p + 2;
  2196. }
  2197. else
  2198. {
  2199. /* This is a completely weird case. In order to stuff in the
  2200. names that might contain colons (the usual name delimiter),
  2201. Mike Tiemann defined a different name format which is
  2202. signalled if the identifier is "op$". In that case, the
  2203. format is "op$::XXXX." where XXXX is the name. This is
  2204. used for names like "+" or "=". YUUUUUUUK! FIXME! */
  2205. *pp = p + 2;
  2206. for (p = *pp; *p != '.' && *p != '\0'; p++)
  2207. ;
  2208. if (*p != '.')
  2209. {
  2210. bad_stab (orig);
  2211. goto fail;
  2212. }
  2213. name = savestring (*pp, p - *pp);
  2214. *pp = p + 1;
  2215. }
  2216. allocvars = 10;
  2217. variants = ((debug_method_variant *)
  2218. xmalloc (allocvars * sizeof *variants));
  2219. cvars = 0;
  2220. look_ahead_type = DEBUG_TYPE_NULL;
  2221. do
  2222. {
  2223. debug_type type;
  2224. bfd_boolean stub;
  2225. enum debug_visibility visibility;
  2226. bfd_boolean constp, volatilep, staticp;
  2227. bfd_vma voffset;
  2228. debug_type context;
  2229. const char *physname;
  2230. bfd_boolean varargs;
  2231. if (look_ahead_type != DEBUG_TYPE_NULL)
  2232. {
  2233. /* g++ version 1 kludge */
  2234. type = look_ahead_type;
  2235. look_ahead_type = DEBUG_TYPE_NULL;
  2236. }
  2237. else
  2238. {
  2239. type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2240. (debug_type **) NULL);
  2241. if (type == DEBUG_TYPE_NULL)
  2242. goto fail;
  2243. if (**pp != ':')
  2244. {
  2245. bad_stab (orig);
  2246. goto fail;
  2247. }
  2248. }
  2249. ++*pp;
  2250. p = strchr (*pp, ';');
  2251. if (p == NULL)
  2252. {
  2253. bad_stab (orig);
  2254. goto fail;
  2255. }
  2256. stub = FALSE;
  2257. if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
  2258. && debug_get_parameter_types (dhandle, type, &varargs) == NULL)
  2259. stub = TRUE;
  2260. argtypes = savestring (*pp, p - *pp);
  2261. *pp = p + 1;
  2262. switch (**pp)
  2263. {
  2264. case '0':
  2265. visibility = DEBUG_VISIBILITY_PRIVATE;
  2266. break;
  2267. case '1':
  2268. visibility = DEBUG_VISIBILITY_PROTECTED;
  2269. break;
  2270. default:
  2271. visibility = DEBUG_VISIBILITY_PUBLIC;
  2272. break;
  2273. }
  2274. ++*pp;
  2275. constp = FALSE;
  2276. volatilep = FALSE;
  2277. switch (**pp)
  2278. {
  2279. case 'A':
  2280. /* Normal function. */
  2281. ++*pp;
  2282. break;
  2283. case 'B':
  2284. /* const member function. */
  2285. constp = TRUE;
  2286. ++*pp;
  2287. break;
  2288. case 'C':
  2289. /* volatile member function. */
  2290. volatilep = TRUE;
  2291. ++*pp;
  2292. break;
  2293. case 'D':
  2294. /* const volatile member function. */
  2295. constp = TRUE;
  2296. volatilep = TRUE;
  2297. ++*pp;
  2298. break;
  2299. case '*':
  2300. case '?':
  2301. case '.':
  2302. /* File compiled with g++ version 1; no information. */
  2303. break;
  2304. default:
  2305. warn_stab (orig, _("const/volatile indicator missing"));
  2306. break;
  2307. }
  2308. staticp = FALSE;
  2309. switch (**pp)
  2310. {
  2311. case '*':
  2312. /* virtual member function, followed by index. The sign
  2313. bit is supposedly set to distinguish
  2314. pointers-to-methods from virtual function indicies. */
  2315. ++*pp;
  2316. voffset = parse_number (pp, (bfd_boolean *) NULL);
  2317. if (**pp != ';')
  2318. {
  2319. bad_stab (orig);
  2320. goto fail;
  2321. }
  2322. ++*pp;
  2323. voffset &= 0x7fffffff;
  2324. if (**pp == ';' || *pp == '\0')
  2325. {
  2326. /* Must be g++ version 1. */
  2327. context = DEBUG_TYPE_NULL;
  2328. }
  2329. else
  2330. {
  2331. /* Figure out from whence this virtual function
  2332. came. It may belong to virtual function table of
  2333. one of its baseclasses. */
  2334. look_ahead_type = parse_stab_type (dhandle, info,
  2335. (const char *) NULL,
  2336. pp,
  2337. (debug_type **) NULL);
  2338. if (**pp == ':')
  2339. {
  2340. /* g++ version 1 overloaded methods. */
  2341. context = DEBUG_TYPE_NULL;
  2342. }
  2343. else
  2344. {
  2345. context = look_ahead_type;
  2346. look_ahead_type = DEBUG_TYPE_NULL;
  2347. if (**pp != ';')
  2348. {
  2349. bad_stab (orig);
  2350. goto fail;
  2351. }
  2352. ++*pp;
  2353. }
  2354. }
  2355. break;
  2356. case '?':
  2357. /* static member function. */
  2358. ++*pp;
  2359. staticp = TRUE;
  2360. voffset = 0;
  2361. context = DEBUG_TYPE_NULL;
  2362. if (strncmp (argtypes, name, strlen (name)) != 0)
  2363. stub = TRUE;
  2364. break;
  2365. default:
  2366. warn_stab (orig, "member function type missing");
  2367. voffset = 0;
  2368. context = DEBUG_TYPE_NULL;
  2369. break;
  2370. case '.':
  2371. ++*pp;
  2372. voffset = 0;
  2373. context = DEBUG_TYPE_NULL;
  2374. break;
  2375. }
  2376. /* If the type is not a stub, then the argtypes string is
  2377. the physical name of the function. Otherwise the
  2378. argtypes string is the mangled form of the argument
  2379. types, and the full type and the physical name must be
  2380. extracted from them. */
  2381. physname = argtypes;
  2382. if (stub)
  2383. {
  2384. debug_type class_type, return_type;
  2385. class_type = stab_find_type (dhandle, info, typenums);
  2386. if (class_type == DEBUG_TYPE_NULL)
  2387. goto fail;
  2388. return_type = debug_get_return_type (dhandle, type);
  2389. if (return_type == DEBUG_TYPE_NULL)
  2390. {
  2391. bad_stab (orig);
  2392. goto fail;
  2393. }
  2394. type = parse_stab_argtypes (dhandle, info, class_type, name,
  2395. tagname, return_type, argtypes,
  2396. constp, volatilep, &physname);
  2397. if (type == DEBUG_TYPE_NULL)
  2398. goto fail;
  2399. }
  2400. if (cvars + 1 >= allocvars)
  2401. {
  2402. allocvars += 10;
  2403. variants = ((debug_method_variant *)
  2404. xrealloc (variants,
  2405. allocvars * sizeof *variants));
  2406. }
  2407. if (! staticp)
  2408. variants[cvars] = debug_make_method_variant (dhandle, physname,
  2409. type, visibility,
  2410. constp, volatilep,
  2411. voffset, context);
  2412. else
  2413. variants[cvars] = debug_make_static_method_variant (dhandle,
  2414. physname,
  2415. type,
  2416. visibility,
  2417. constp,
  2418. volatilep);
  2419. if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
  2420. goto fail;
  2421. ++cvars;
  2422. }
  2423. while (**pp != ';' && **pp != '\0');
  2424. variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
  2425. if (**pp != '\0')
  2426. ++*pp;
  2427. if (c + 1 >= alloc)
  2428. {
  2429. alloc += 10;
  2430. methods = ((debug_method *)
  2431. xrealloc (methods, alloc * sizeof *methods));
  2432. }
  2433. methods[c] = debug_make_method (dhandle, name, variants);
  2434. ++c;
  2435. }
  2436. if (methods != NULL)
  2437. methods[c] = DEBUG_METHOD_NULL;
  2438. *retp = methods;
  2439. return TRUE;
  2440. fail:
  2441. if (name != NULL)
  2442. free (name);
  2443. if (variants != NULL)
  2444. free (variants);
  2445. if (argtypes != NULL)
  2446. free (argtypes);
  2447. return FALSE;
  2448. }
  2449. /* Parse a string representing argument types for a method. Stabs
  2450. tries to save space by packing argument types into a mangled
  2451. string. This string should give us enough information to extract
  2452. both argument types and the physical name of the function, given
  2453. the tag name. */
  2454. static debug_type
  2455. parse_stab_argtypes (void *dhandle, struct stab_handle *info,
  2456. debug_type class_type, const char *fieldname,
  2457. const char *tagname, debug_type return_type,
  2458. const char *argtypes, bfd_boolean constp,
  2459. bfd_boolean volatilep, const char **pphysname)
  2460. {
  2461. bfd_boolean is_full_physname_constructor;
  2462. bfd_boolean is_constructor;
  2463. bfd_boolean is_destructor;
  2464. bfd_boolean is_v3;
  2465. debug_type *args;
  2466. bfd_boolean varargs;
  2467. unsigned int physname_len = 0;
  2468. /* Constructors are sometimes handled specially. */
  2469. is_full_physname_constructor = ((argtypes[0] == '_'
  2470. && argtypes[1] == '_'
  2471. && (ISDIGIT (argtypes[2])
  2472. || argtypes[2] == 'Q'
  2473. || argtypes[2] == 't'))
  2474. || CONST_STRNEQ (argtypes, "__ct"));
  2475. is_constructor = (is_full_physname_constructor
  2476. || (tagname != NULL
  2477. && strcmp (fieldname, tagname) == 0));
  2478. is_destructor = ((argtypes[0] == '_'
  2479. && (argtypes[1] == '$' || argtypes[1] == '.')
  2480. && argtypes[2] == '_')
  2481. || CONST_STRNEQ (argtypes, "__dt"));
  2482. is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z';
  2483. if (!(is_destructor || is_full_physname_constructor || is_v3))
  2484. {
  2485. unsigned int len;
  2486. const char *const_prefix;
  2487. const char *volatile_prefix;
  2488. char buf[20];
  2489. unsigned int mangled_name_len;
  2490. char *physname;
  2491. len = tagname == NULL ? 0 : strlen (tagname);
  2492. const_prefix = constp ? "C" : "";
  2493. volatile_prefix = volatilep ? "V" : "";
  2494. if (len == 0)
  2495. sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
  2496. else if (tagname != NULL && strchr (tagname, '<') != NULL)
  2497. {
  2498. /* Template methods are fully mangled. */
  2499. sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
  2500. tagname = NULL;
  2501. len = 0;
  2502. }
  2503. else
  2504. sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
  2505. mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
  2506. + strlen (buf)
  2507. + len
  2508. + strlen (argtypes)
  2509. + 1);
  2510. if (fieldname[0] == 'o'
  2511. && fieldname[1] == 'p'
  2512. && (fieldname[2] == '$' || fieldname[2] == '.'))
  2513. {
  2514. const char *opname;
  2515. opname = cplus_mangle_opname (fieldname + 3, 0);
  2516. if (opname == NULL)
  2517. {
  2518. fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname);
  2519. return DEBUG_TYPE_NULL;
  2520. }
  2521. mangled_name_len += strlen (opname);
  2522. physname = (char *) xmalloc (mangled_name_len);
  2523. strncpy (physname, fieldname, 3);
  2524. strcpy (physname + 3, opname);
  2525. }
  2526. else
  2527. {
  2528. physname = (char *) xmalloc (mangled_name_len);
  2529. if (is_constructor)
  2530. physname[0] = '\0';
  2531. else
  2532. strcpy (physname, fieldname);
  2533. }
  2534. physname_len = strlen (physname);
  2535. strcat (physname, buf);
  2536. if (tagname != NULL)
  2537. strcat (physname, tagname);
  2538. strcat (physname, argtypes);
  2539. *pphysname = physname;
  2540. }
  2541. if (*argtypes == '\0' || is_destructor)
  2542. {
  2543. args = (debug_type *) xmalloc (sizeof *args);
  2544. *args = NULL;
  2545. return debug_make_method_type (dhandle, return_type, class_type, args,
  2546. FALSE);
  2547. }
  2548. args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs, physname_len);
  2549. if (args == NULL)
  2550. return DEBUG_TYPE_NULL;
  2551. return debug_make_method_type (dhandle, return_type, class_type, args,
  2552. varargs);
  2553. }
  2554. /* The tail end of stabs for C++ classes that contain a virtual function
  2555. pointer contains a tilde, a %, and a type number.
  2556. The type number refers to the base class (possibly this class itself) which
  2557. contains the vtable pointer for the current class.
  2558. This function is called when we have parsed all the method declarations,
  2559. so we can look for the vptr base class info. */
  2560. static bfd_boolean
  2561. parse_stab_tilde_field (void *dhandle, struct stab_handle *info,
  2562. const char **pp, const int *typenums,
  2563. debug_type *retvptrbase, bfd_boolean *retownvptr)
  2564. {
  2565. const char *orig;
  2566. const char *hold;
  2567. int vtypenums[2];
  2568. *retvptrbase = DEBUG_TYPE_NULL;
  2569. *retownvptr = FALSE;
  2570. orig = *pp;
  2571. /* If we are positioned at a ';', then skip it. */
  2572. if (**pp == ';')
  2573. ++*pp;
  2574. if (**pp != '~')
  2575. return TRUE;
  2576. ++*pp;
  2577. if (**pp == '=' || **pp == '+' || **pp == '-')
  2578. {
  2579. /* Obsolete flags that used to indicate the presence of
  2580. constructors and/or destructors. */
  2581. ++*pp;
  2582. }
  2583. if (**pp != '%')
  2584. return TRUE;
  2585. ++*pp;
  2586. hold = *pp;
  2587. /* The next number is the type number of the base class (possibly
  2588. our own class) which supplies the vtable for this class. */
  2589. if (! parse_stab_type_number (pp, vtypenums))
  2590. return FALSE;
  2591. if (vtypenums[0] == typenums[0]
  2592. && vtypenums[1] == typenums[1])
  2593. *retownvptr = TRUE;
  2594. else
  2595. {
  2596. debug_type vtype;
  2597. const char *p;
  2598. *pp = hold;
  2599. vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2600. (debug_type **) NULL);
  2601. for (p = *pp; *p != ';' && *p != '\0'; p++)
  2602. ;
  2603. if (*p != ';')
  2604. {
  2605. bad_stab (orig);
  2606. return FALSE;
  2607. }
  2608. *retvptrbase = vtype;
  2609. *pp = p + 1;
  2610. }
  2611. return TRUE;
  2612. }
  2613. /* Read a definition of an array type. */
  2614. static debug_type
  2615. parse_stab_array_type (void *dhandle, struct stab_handle *info,
  2616. const char **pp, bfd_boolean stringp)
  2617. {
  2618. const char *orig;
  2619. const char *p;
  2620. int typenums[2];
  2621. debug_type index_type;
  2622. bfd_boolean adjustable;
  2623. bfd_signed_vma lower, upper;
  2624. debug_type element_type;
  2625. /* Format of an array type:
  2626. "ar<index type>;lower;upper;<array_contents_type>".
  2627. OS9000: "arlower,upper;<array_contents_type>".
  2628. Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
  2629. for these, produce a type like float[][]. */
  2630. orig = *pp;
  2631. /* FIXME: gdb checks os9k_stabs here. */
  2632. /* If the index type is type 0, we take it as int. */
  2633. p = *pp;
  2634. if (! parse_stab_type_number (&p, typenums))
  2635. return DEBUG_TYPE_NULL;
  2636. if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
  2637. {
  2638. index_type = debug_find_named_type (dhandle, "int");
  2639. if (index_type == DEBUG_TYPE_NULL)
  2640. {
  2641. index_type = debug_make_int_type (dhandle, 4, FALSE);
  2642. if (index_type == DEBUG_TYPE_NULL)
  2643. return DEBUG_TYPE_NULL;
  2644. }
  2645. *pp = p;
  2646. }
  2647. else
  2648. {
  2649. index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2650. (debug_type **) NULL);
  2651. }
  2652. if (**pp != ';')
  2653. {
  2654. bad_stab (orig);
  2655. return DEBUG_TYPE_NULL;
  2656. }
  2657. ++*pp;
  2658. adjustable = FALSE;
  2659. if (! ISDIGIT (**pp) && **pp != '-')
  2660. {
  2661. ++*pp;
  2662. adjustable = TRUE;
  2663. }
  2664. lower = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
  2665. if (**pp != ';')
  2666. {
  2667. bad_stab (orig);
  2668. return DEBUG_TYPE_NULL;
  2669. }
  2670. ++*pp;
  2671. if (! ISDIGIT (**pp) && **pp != '-')
  2672. {
  2673. ++*pp;
  2674. adjustable = TRUE;
  2675. }
  2676. upper = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
  2677. if (**pp != ';')
  2678. {
  2679. bad_stab (orig);
  2680. return DEBUG_TYPE_NULL;
  2681. }
  2682. ++*pp;
  2683. element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
  2684. (debug_type **) NULL);
  2685. if (element_type == DEBUG_TYPE_NULL)
  2686. return DEBUG_TYPE_NULL;
  2687. if (adjustable)
  2688. {
  2689. lower = 0;
  2690. upper = -1;
  2691. }
  2692. return debug_make_array_type (dhandle, element_type, index_type, lower,
  2693. upper, stringp);
  2694. }
  2695. /* This struct holds information about files we have seen using
  2696. N_BINCL. */
  2697. struct bincl_file
  2698. {
  2699. /* The next N_BINCL file. */
  2700. struct bincl_file *next;
  2701. /* The next N_BINCL on the stack. */
  2702. struct bincl_file *next_stack;
  2703. /* The file name. */
  2704. const char *name;
  2705. /* The hash value. */
  2706. bfd_vma hash;
  2707. /* The file index. */
  2708. unsigned int file;
  2709. /* The list of types defined in this file. */
  2710. struct stab_types *file_types;
  2711. };
  2712. /* Start a new N_BINCL file, pushing it onto the stack. */
  2713. static void
  2714. push_bincl (struct stab_handle *info, const char *name, bfd_vma hash)
  2715. {
  2716. struct bincl_file *n;
  2717. n = (struct bincl_file *) xmalloc (sizeof *n);
  2718. n->next = info->bincl_list;
  2719. n->next_stack = info->bincl_stack;
  2720. n->name = name;
  2721. n->hash = hash;
  2722. n->file = info->files;
  2723. n->file_types = NULL;
  2724. info->bincl_list = n;
  2725. info->bincl_stack = n;
  2726. ++info->files;
  2727. info->file_types = ((struct stab_types **)
  2728. xrealloc (info->file_types,
  2729. (info->files
  2730. * sizeof *info->file_types)));
  2731. info->file_types[n->file] = NULL;
  2732. }
  2733. /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
  2734. stack. */
  2735. static const char *
  2736. pop_bincl (struct stab_handle *info)
  2737. {
  2738. struct bincl_file *o;
  2739. o = info->bincl_stack;
  2740. if (o == NULL)
  2741. return info->main_filename;
  2742. info->bincl_stack = o->next_stack;
  2743. o->file_types = info->file_types[o->file];
  2744. if (info->bincl_stack == NULL)
  2745. return info->main_filename;
  2746. return info->bincl_stack->name;
  2747. }
  2748. /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
  2749. static bfd_boolean
  2750. find_excl (struct stab_handle *info, const char *name, bfd_vma hash)
  2751. {
  2752. struct bincl_file *l;
  2753. ++info->files;
  2754. info->file_types = ((struct stab_types **)
  2755. xrealloc (info->file_types,
  2756. (info->files
  2757. * sizeof *info->file_types)));
  2758. for (l = info->bincl_list; l != NULL; l = l->next)
  2759. if (l->hash == hash && strcmp (l->name, name) == 0)
  2760. break;
  2761. if (l == NULL)
  2762. {
  2763. warn_stab (name, _("Undefined N_EXCL"));
  2764. info->file_types[info->files - 1] = NULL;
  2765. return TRUE;
  2766. }
  2767. info->file_types[info->files - 1] = l->file_types;
  2768. return TRUE;
  2769. }
  2770. /* Handle a variable definition. gcc emits variable definitions for a
  2771. block before the N_LBRAC, so we must hold onto them until we see
  2772. it. The SunPRO compiler emits variable definitions after the
  2773. N_LBRAC, so we can call debug_record_variable immediately. */
  2774. static bfd_boolean
  2775. stab_record_variable (void *dhandle, struct stab_handle *info,
  2776. const char *name, debug_type type,
  2777. enum debug_var_kind kind, bfd_vma val)
  2778. {
  2779. struct stab_pending_var *v;
  2780. if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
  2781. || ! info->within_function
  2782. || (info->gcc_compiled == 0 && info->n_opt_found))
  2783. return debug_record_variable (dhandle, name, type, kind, val);
  2784. v = (struct stab_pending_var *) xmalloc (sizeof *v);
  2785. memset (v, 0, sizeof *v);
  2786. v->next = info->pending;
  2787. v->name = name;
  2788. v->type = type;
  2789. v->kind = kind;
  2790. v->val = val;
  2791. info->pending = v;
  2792. return TRUE;
  2793. }
  2794. /* Emit pending variable definitions. This is called after we see the
  2795. N_LBRAC that starts the block. */
  2796. static bfd_boolean
  2797. stab_emit_pending_vars (void *dhandle, struct stab_handle *info)
  2798. {
  2799. struct stab_pending_var *v;
  2800. v = info->pending;
  2801. while (v != NULL)
  2802. {
  2803. struct stab_pending_var *next;
  2804. if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
  2805. return FALSE;
  2806. next = v->next;
  2807. free (v);
  2808. v = next;
  2809. }
  2810. info->pending = NULL;
  2811. return TRUE;
  2812. }
  2813. /* Find the slot for a type in the database. */
  2814. static debug_type *
  2815. stab_find_slot (struct stab_handle *info, const int *typenums)
  2816. {
  2817. int filenum;
  2818. int tindex;
  2819. struct stab_types **ps;
  2820. filenum = typenums[0];
  2821. tindex = typenums[1];
  2822. if (filenum < 0 || (unsigned int) filenum >= info->files)
  2823. {
  2824. fprintf (stderr, _("Type file number %d out of range\n"), filenum);
  2825. return NULL;
  2826. }
  2827. if (tindex < 0)
  2828. {
  2829. fprintf (stderr, _("Type index number %d out of range\n"), tindex);
  2830. return NULL;
  2831. }
  2832. ps = info->file_types + filenum;
  2833. while (tindex >= STAB_TYPES_SLOTS)
  2834. {
  2835. if (*ps == NULL)
  2836. {
  2837. *ps = (struct stab_types *) xmalloc (sizeof **ps);
  2838. memset (*ps, 0, sizeof **ps);
  2839. }
  2840. ps = &(*ps)->next;
  2841. tindex -= STAB_TYPES_SLOTS;
  2842. }
  2843. if (*ps == NULL)
  2844. {
  2845. *ps = (struct stab_types *) xmalloc (sizeof **ps);
  2846. memset (*ps, 0, sizeof **ps);
  2847. }
  2848. return (*ps)->types + tindex;
  2849. }
  2850. /* Find a type given a type number. If the type has not been
  2851. allocated yet, create an indirect type. */
  2852. static debug_type
  2853. stab_find_type (void *dhandle, struct stab_handle *info, const int *typenums)
  2854. {
  2855. debug_type *slot;
  2856. if (typenums[0] == 0 && typenums[1] < 0)
  2857. {
  2858. /* A negative type number indicates an XCOFF builtin type. */
  2859. return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
  2860. }
  2861. slot = stab_find_slot (info, typenums);
  2862. if (slot == NULL)
  2863. return DEBUG_TYPE_NULL;
  2864. if (*slot == DEBUG_TYPE_NULL)
  2865. return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
  2866. return *slot;
  2867. }
  2868. /* Record that a given type number refers to a given type. */
  2869. static bfd_boolean
  2870. stab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info,
  2871. const int *typenums, debug_type type)
  2872. {
  2873. debug_type *slot;
  2874. slot = stab_find_slot (info, typenums);
  2875. if (slot == NULL)
  2876. return FALSE;
  2877. /* gdb appears to ignore type redefinitions, so we do as well. */
  2878. *slot = type;
  2879. return TRUE;
  2880. }
  2881. /* Return an XCOFF builtin type. */
  2882. static debug_type
  2883. stab_xcoff_builtin_type (void *dhandle, struct stab_handle *info,
  2884. int typenum)
  2885. {
  2886. debug_type rettype;
  2887. const char *name;
  2888. if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
  2889. {
  2890. fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum);
  2891. return DEBUG_TYPE_NULL;
  2892. }
  2893. if (info->xcoff_types[-typenum] != NULL)
  2894. return info->xcoff_types[-typenum];
  2895. switch (-typenum)
  2896. {
  2897. case 1:
  2898. /* The size of this and all the other types are fixed, defined
  2899. by the debugging format. */
  2900. name = "int";
  2901. rettype = debug_make_int_type (dhandle, 4, FALSE);
  2902. break;
  2903. case 2:
  2904. name = "char";
  2905. rettype = debug_make_int_type (dhandle, 1, FALSE);
  2906. break;
  2907. case 3:
  2908. name = "short";
  2909. rettype = debug_make_int_type (dhandle, 2, FALSE);
  2910. break;
  2911. case 4:
  2912. name = "long";
  2913. rettype = debug_make_int_type (dhandle, 4, FALSE);
  2914. break;
  2915. case 5:
  2916. name = "unsigned char";
  2917. rettype = debug_make_int_type (dhandle, 1, TRUE);
  2918. break;
  2919. case 6:
  2920. name = "signed char";
  2921. rettype = debug_make_int_type (dhandle, 1, FALSE);
  2922. break;
  2923. case 7:
  2924. name = "unsigned short";
  2925. rettype = debug_make_int_type (dhandle, 2, TRUE);
  2926. break;
  2927. case 8:
  2928. name = "unsigned int";
  2929. rettype = debug_make_int_type (dhandle, 4, TRUE);
  2930. break;
  2931. case 9:
  2932. name = "unsigned";
  2933. rettype = debug_make_int_type (dhandle, 4, TRUE);
  2934. case 10:
  2935. name = "unsigned long";
  2936. rettype = debug_make_int_type (dhandle, 4, TRUE);
  2937. break;
  2938. case 11:
  2939. name = "void";
  2940. rettype = debug_make_void_type (dhandle);
  2941. break;
  2942. case 12:
  2943. /* IEEE single precision (32 bit). */
  2944. name = "float";
  2945. rettype = debug_make_float_type (dhandle, 4);
  2946. break;
  2947. case 13:
  2948. /* IEEE double precision (64 bit). */
  2949. name = "double";
  2950. rettype = debug_make_float_type (dhandle, 8);
  2951. break;
  2952. case 14:
  2953. /* This is an IEEE double on the RS/6000, and different machines
  2954. with different sizes for "long double" should use different
  2955. negative type numbers. See stabs.texinfo. */
  2956. name = "long double";
  2957. rettype = debug_make_float_type (dhandle, 8);
  2958. break;
  2959. case 15:
  2960. name = "integer";
  2961. rettype = debug_make_int_type (dhandle, 4, FALSE);
  2962. break;
  2963. case 16:
  2964. name = "boolean";
  2965. rettype = debug_make_bool_type (dhandle, 4);
  2966. break;
  2967. case 17:
  2968. name = "short real";
  2969. rettype = debug_make_float_type (dhandle, 4);
  2970. break;
  2971. case 18:
  2972. name = "real";
  2973. rettype = debug_make_float_type (dhandle, 8);
  2974. break;
  2975. case 19:
  2976. /* FIXME */
  2977. name = "stringptr";
  2978. rettype = NULL;
  2979. break;
  2980. case 20:
  2981. /* FIXME */
  2982. name = "character";
  2983. rettype = debug_make_int_type (dhandle, 1, TRUE);
  2984. break;
  2985. case 21:
  2986. name = "logical*1";
  2987. rettype = debug_make_bool_type (dhandle, 1);
  2988. break;
  2989. case 22:
  2990. name = "logical*2";
  2991. rettype = debug_make_bool_type (dhandle, 2);
  2992. break;
  2993. case 23:
  2994. name = "logical*4";
  2995. rettype = debug_make_bool_type (dhandle, 4);
  2996. break;
  2997. case 24:
  2998. name = "logical";
  2999. rettype = debug_make_bool_type (dhandle, 4);
  3000. break;
  3001. case 25:
  3002. /* Complex type consisting of two IEEE single precision values. */
  3003. name = "complex";
  3004. rettype = debug_make_complex_type (dhandle, 8);
  3005. break;
  3006. case 26:
  3007. /* Complex type consisting of two IEEE double precision values. */
  3008. name = "double complex";
  3009. rettype = debug_make_complex_type (dhandle, 16);
  3010. break;
  3011. case 27:
  3012. name = "integer*1";
  3013. rettype = debug_make_int_type (dhandle, 1, FALSE);
  3014. break;
  3015. case 28:
  3016. name = "integer*2";
  3017. rettype = debug_make_int_type (dhandle, 2, FALSE);
  3018. break;
  3019. case 29:
  3020. name = "integer*4";
  3021. rettype = debug_make_int_type (dhandle, 4, FALSE);
  3022. break;
  3023. case 30:
  3024. /* FIXME */
  3025. name = "wchar";
  3026. rettype = debug_make_int_type (dhandle, 2, FALSE);
  3027. break;
  3028. case 31:
  3029. name = "long long";
  3030. rettype = debug_make_int_type (dhandle, 8, FALSE);
  3031. break;
  3032. case 32:
  3033. name = "unsigned long long";
  3034. rettype = debug_make_int_type (dhandle, 8, TRUE);
  3035. break;
  3036. case 33:
  3037. name = "logical*8";
  3038. rettype = debug_make_bool_type (dhandle, 8);
  3039. break;
  3040. case 34:
  3041. name = "integer*8";
  3042. rettype = debug_make_int_type (dhandle, 8, FALSE);
  3043. break;
  3044. default:
  3045. abort ();
  3046. }
  3047. rettype = debug_name_type (dhandle, name, rettype);
  3048. info->xcoff_types[-typenum] = rettype;
  3049. return rettype;
  3050. }
  3051. /* Find or create a tagged type. */
  3052. static debug_type
  3053. stab_find_tagged_type (void *dhandle, struct stab_handle *info,
  3054. const char *p, int len, enum debug_type_kind kind)
  3055. {
  3056. char *name;
  3057. debug_type dtype;
  3058. struct stab_tag *st;
  3059. name = savestring (p, len);
  3060. /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
  3061. namespace. This is right for C, and I don't know how to handle
  3062. other languages. FIXME. */
  3063. dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
  3064. if (dtype != DEBUG_TYPE_NULL)
  3065. {
  3066. free (name);
  3067. return dtype;
  3068. }
  3069. /* We need to allocate an entry on the undefined tag list. */
  3070. for (st = info->tags; st != NULL; st = st->next)
  3071. {
  3072. if (st->name[0] == name[0]
  3073. && strcmp (st->name, name) == 0)
  3074. {
  3075. if (st->kind == DEBUG_KIND_ILLEGAL)
  3076. st->kind = kind;
  3077. free (name);
  3078. break;
  3079. }
  3080. }
  3081. if (st == NULL)
  3082. {
  3083. st = (struct stab_tag *) xmalloc (sizeof *st);
  3084. memset (st, 0, sizeof *st);
  3085. st->next = info->tags;
  3086. st->name = name;
  3087. st->kind = kind;
  3088. st->slot = DEBUG_TYPE_NULL;
  3089. st->type = debug_make_indirect_type (dhandle, &st->slot, name);
  3090. info->tags = st;
  3091. }
  3092. return st->type;
  3093. }
  3094. /* In order to get the correct argument types for a stubbed method, we
  3095. need to extract the argument types from a C++ mangled string.
  3096. Since the argument types can refer back to the return type, this
  3097. means that we must demangle the entire physical name. In gdb this
  3098. is done by calling cplus_demangle and running the results back
  3099. through the C++ expression parser. Since we have no expression
  3100. parser, we must duplicate much of the work of cplus_demangle here.
  3101. We assume that GNU style demangling is used, since this is only
  3102. done for method stubs, and only g++ should output that form of
  3103. debugging information. */
  3104. /* This structure is used to hold a pointer to type information which
  3105. demangling a string. */
  3106. struct stab_demangle_typestring
  3107. {
  3108. /* The start of the type. This is not null terminated. */
  3109. const char *typestring;
  3110. /* The length of the type. */
  3111. unsigned int len;
  3112. };
  3113. /* This structure is used to hold information while demangling a
  3114. string. */
  3115. struct stab_demangle_info
  3116. {
  3117. /* The debugging information handle. */
  3118. void *dhandle;
  3119. /* The stab information handle. */
  3120. struct stab_handle *info;
  3121. /* The array of arguments we are building. */
  3122. debug_type *args;
  3123. /* Whether the method takes a variable number of arguments. */
  3124. bfd_boolean varargs;
  3125. /* The array of types we have remembered. */
  3126. struct stab_demangle_typestring *typestrings;
  3127. /* The number of typestrings. */
  3128. unsigned int typestring_count;
  3129. /* The number of typestring slots we have allocated. */
  3130. unsigned int typestring_alloc;
  3131. };
  3132. static void stab_bad_demangle (const char *);
  3133. static unsigned int stab_demangle_count (const char **);
  3134. static bfd_boolean stab_demangle_get_count (const char **, unsigned int *);
  3135. static bfd_boolean stab_demangle_prefix
  3136. (struct stab_demangle_info *, const char **, unsigned int);
  3137. static bfd_boolean stab_demangle_function_name
  3138. (struct stab_demangle_info *, const char **, const char *);
  3139. static bfd_boolean stab_demangle_signature
  3140. (struct stab_demangle_info *, const char **);
  3141. static bfd_boolean stab_demangle_qualified
  3142. (struct stab_demangle_info *, const char **, debug_type *);
  3143. static bfd_boolean stab_demangle_template
  3144. (struct stab_demangle_info *, const char **, char **);
  3145. static bfd_boolean stab_demangle_class
  3146. (struct stab_demangle_info *, const char **, const char **);
  3147. static bfd_boolean stab_demangle_args
  3148. (struct stab_demangle_info *, const char **, debug_type **, bfd_boolean *);
  3149. static bfd_boolean stab_demangle_arg
  3150. (struct stab_demangle_info *, const char **, debug_type **,
  3151. unsigned int *, unsigned int *);
  3152. static bfd_boolean stab_demangle_type
  3153. (struct stab_demangle_info *, const char **, debug_type *);
  3154. static bfd_boolean stab_demangle_fund_type
  3155. (struct stab_demangle_info *, const char **, debug_type *);
  3156. static bfd_boolean stab_demangle_remember_type
  3157. (struct stab_demangle_info *, const char *, int);
  3158. /* Warn about a bad demangling. */
  3159. static void
  3160. stab_bad_demangle (const char *s)
  3161. {
  3162. fprintf (stderr, _("bad mangled name `%s'\n"), s);
  3163. }
  3164. /* Get a count from a stab string. */
  3165. static unsigned int
  3166. stab_demangle_count (const char **pp)
  3167. {
  3168. unsigned int count;
  3169. count = 0;
  3170. while (ISDIGIT (**pp))
  3171. {
  3172. count *= 10;
  3173. count += **pp - '0';
  3174. ++*pp;
  3175. }
  3176. return count;
  3177. }
  3178. /* Require a count in a string. The count may be multiple digits, in
  3179. which case it must end in an underscore. */
  3180. static bfd_boolean
  3181. stab_demangle_get_count (const char **pp, unsigned int *pi)
  3182. {
  3183. if (! ISDIGIT (**pp))
  3184. return FALSE;
  3185. *pi = **pp - '0';
  3186. ++*pp;
  3187. if (ISDIGIT (**pp))
  3188. {
  3189. unsigned int count;
  3190. const char *p;
  3191. count = *pi;
  3192. p = *pp;
  3193. do
  3194. {
  3195. count *= 10;
  3196. count += *p - '0';
  3197. ++p;
  3198. }
  3199. while (ISDIGIT (*p));
  3200. if (*p == '_')
  3201. {
  3202. *pp = p + 1;
  3203. *pi = count;
  3204. }
  3205. }
  3206. return TRUE;
  3207. }
  3208. /* This function demangles a physical name, returning a NULL
  3209. terminated array of argument types. */
  3210. static debug_type *
  3211. stab_demangle_argtypes (void *dhandle, struct stab_handle *info,
  3212. const char *physname, bfd_boolean *pvarargs,
  3213. unsigned int physname_len)
  3214. {
  3215. struct stab_demangle_info minfo;
  3216. /* Check for the g++ V3 ABI. */
  3217. if (physname[0] == '_' && physname[1] == 'Z')
  3218. return stab_demangle_v3_argtypes (dhandle, info, physname, pvarargs);
  3219. minfo.dhandle = dhandle;
  3220. minfo.info = info;
  3221. minfo.args = NULL;
  3222. minfo.varargs = FALSE;
  3223. minfo.typestring_alloc = 10;
  3224. minfo.typestrings = ((struct stab_demangle_typestring *)
  3225. xmalloc (minfo.typestring_alloc
  3226. * sizeof *minfo.typestrings));
  3227. minfo.typestring_count = 0;
  3228. /* cplus_demangle checks for special GNU mangled forms, but we can't
  3229. see any of them in mangled method argument types. */
  3230. if (! stab_demangle_prefix (&minfo, &physname, physname_len))
  3231. goto error_return;
  3232. if (*physname != '\0')
  3233. {
  3234. if (! stab_demangle_signature (&minfo, &physname))
  3235. goto error_return;
  3236. }
  3237. free (minfo.typestrings);
  3238. minfo.typestrings = NULL;
  3239. if (minfo.args == NULL)
  3240. fprintf (stderr, _("no argument types in mangled string\n"));
  3241. *pvarargs = minfo.varargs;
  3242. return minfo.args;
  3243. error_return:
  3244. if (minfo.typestrings != NULL)
  3245. free (minfo.typestrings);
  3246. return NULL;
  3247. }
  3248. /* Demangle the prefix of the mangled name. */
  3249. static bfd_boolean
  3250. stab_demangle_prefix (struct stab_demangle_info *minfo, const char **pp,
  3251. unsigned int physname_len)
  3252. {
  3253. const char *scan;
  3254. unsigned int i;
  3255. /* cplus_demangle checks for global constructors and destructors,
  3256. but we can't see them in mangled argument types. */
  3257. if (physname_len)
  3258. scan = *pp + physname_len;
  3259. else
  3260. {
  3261. /* Look for `__'. */
  3262. scan = *pp;
  3263. do
  3264. scan = strchr (scan, '_');
  3265. while (scan != NULL && *++scan != '_');
  3266. if (scan == NULL)
  3267. {
  3268. stab_bad_demangle (*pp);
  3269. return FALSE;
  3270. }
  3271. --scan;
  3272. /* We found `__'; move ahead to the last contiguous `__' pair. */
  3273. i = strspn (scan, "_");
  3274. if (i > 2)
  3275. scan += i - 2;
  3276. }
  3277. if (scan == *pp
  3278. && (ISDIGIT (scan[2])
  3279. || scan[2] == 'Q'
  3280. || scan[2] == 't'))
  3281. {
  3282. /* This is a GNU style constructor name. */
  3283. *pp = scan + 2;
  3284. return TRUE;
  3285. }
  3286. else if (scan == *pp
  3287. && ! ISDIGIT (scan[2])
  3288. && scan[2] != 't')
  3289. {
  3290. /* Look for the `__' that separates the prefix from the
  3291. signature. */
  3292. while (*scan == '_')
  3293. ++scan;
  3294. scan = strstr (scan, "__");
  3295. if (scan == NULL || scan[2] == '\0')
  3296. {
  3297. stab_bad_demangle (*pp);
  3298. return FALSE;
  3299. }
  3300. return stab_demangle_function_name (minfo, pp, scan);
  3301. }
  3302. else if (scan[2] != '\0')
  3303. {
  3304. /* The name doesn't start with `__', but it does contain `__'. */
  3305. return stab_demangle_function_name (minfo, pp, scan);
  3306. }
  3307. else
  3308. {
  3309. stab_bad_demangle (*pp);
  3310. return FALSE;
  3311. }
  3312. /*NOTREACHED*/
  3313. }
  3314. /* Demangle a function name prefix. The scan argument points to the
  3315. double underscore which separates the function name from the
  3316. signature. */
  3317. static bfd_boolean
  3318. stab_demangle_function_name (struct stab_demangle_info *minfo,
  3319. const char **pp, const char *scan)
  3320. {
  3321. const char *name;
  3322. /* The string from *pp to scan is the name of the function. We
  3323. don't care about the name, since we just looking for argument
  3324. types. However, for conversion operators, the name may include a
  3325. type which we must remember in order to handle backreferences. */
  3326. name = *pp;
  3327. *pp = scan + 2;
  3328. if (*pp - name >= 5
  3329. && CONST_STRNEQ (name, "type")
  3330. && (name[4] == '$' || name[4] == '.'))
  3331. {
  3332. const char *tem;
  3333. /* This is a type conversion operator. */
  3334. tem = name + 5;
  3335. if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
  3336. return FALSE;
  3337. }
  3338. else if (name[0] == '_'
  3339. && name[1] == '_'
  3340. && name[2] == 'o'
  3341. && name[3] == 'p')
  3342. {
  3343. const char *tem;
  3344. /* This is a type conversion operator. */
  3345. tem = name + 4;
  3346. if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
  3347. return FALSE;
  3348. }
  3349. return TRUE;
  3350. }
  3351. /* Demangle the signature. This is where the argument types are
  3352. found. */
  3353. static bfd_boolean
  3354. stab_demangle_signature (struct stab_demangle_info *minfo, const char **pp)
  3355. {
  3356. const char *orig;
  3357. bfd_boolean expect_func, func_done;
  3358. const char *hold;
  3359. orig = *pp;
  3360. expect_func = FALSE;
  3361. func_done = FALSE;
  3362. hold = NULL;
  3363. while (**pp != '\0')
  3364. {
  3365. switch (**pp)
  3366. {
  3367. case 'Q':
  3368. hold = *pp;
  3369. if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
  3370. || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
  3371. return FALSE;
  3372. expect_func = TRUE;
  3373. hold = NULL;
  3374. break;
  3375. case 'S':
  3376. /* Static member function. FIXME: Can this happen? */
  3377. if (hold == NULL)
  3378. hold = *pp;
  3379. ++*pp;
  3380. break;
  3381. case 'C':
  3382. /* Const member function. */
  3383. if (hold == NULL)
  3384. hold = *pp;
  3385. ++*pp;
  3386. break;
  3387. case '0': case '1': case '2': case '3': case '4':
  3388. case '5': case '6': case '7': case '8': case '9':
  3389. if (hold == NULL)
  3390. hold = *pp;
  3391. if (! stab_demangle_class (minfo, pp, (const char **) NULL)
  3392. || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
  3393. return FALSE;
  3394. expect_func = TRUE;
  3395. hold = NULL;
  3396. break;
  3397. case 'F':
  3398. /* Function. I don't know if this actually happens with g++
  3399. output. */
  3400. hold = NULL;
  3401. func_done = TRUE;
  3402. ++*pp;
  3403. if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
  3404. return FALSE;
  3405. break;
  3406. case 't':
  3407. /* Template. */
  3408. if (hold == NULL)
  3409. hold = *pp;
  3410. if (! stab_demangle_template (minfo, pp, (char **) NULL)
  3411. || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
  3412. return FALSE;
  3413. hold = NULL;
  3414. expect_func = TRUE;
  3415. break;
  3416. case '_':
  3417. /* At the outermost level, we cannot have a return type
  3418. specified, so if we run into another '_' at this point we
  3419. are dealing with a mangled name that is either bogus, or
  3420. has been mangled by some algorithm we don't know how to
  3421. deal with. So just reject the entire demangling. */
  3422. stab_bad_demangle (orig);
  3423. return FALSE;
  3424. default:
  3425. /* Assume we have stumbled onto the first outermost function
  3426. argument token, and start processing args. */
  3427. func_done = TRUE;
  3428. if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
  3429. return FALSE;
  3430. break;
  3431. }
  3432. if (expect_func)
  3433. {
  3434. func_done = TRUE;
  3435. if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
  3436. return FALSE;
  3437. }
  3438. }
  3439. if (! func_done)
  3440. {
  3441. /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
  3442. bar__3fooi is 'foo::bar(int)'. We get here when we find the
  3443. first case, and need to ensure that the '(void)' gets added
  3444. to the current declp. */
  3445. if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
  3446. return FALSE;
  3447. }
  3448. return TRUE;
  3449. }
  3450. /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
  3451. mangled form of "Outer::Inner". */
  3452. static bfd_boolean
  3453. stab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp,
  3454. debug_type *ptype)
  3455. {
  3456. const char *orig;
  3457. const char *p;
  3458. unsigned int qualifiers;
  3459. debug_type context;
  3460. orig = *pp;
  3461. switch ((*pp)[1])
  3462. {
  3463. case '_':
  3464. /* GNU mangled name with more than 9 classes. The count is
  3465. preceded by an underscore (to distinguish it from the <= 9
  3466. case) and followed by an underscore. */
  3467. p = *pp + 2;
  3468. if (! ISDIGIT (*p) || *p == '0')
  3469. {
  3470. stab_bad_demangle (orig);
  3471. return FALSE;
  3472. }
  3473. qualifiers = atoi (p);
  3474. while (ISDIGIT (*p))
  3475. ++p;
  3476. if (*p != '_')
  3477. {
  3478. stab_bad_demangle (orig);
  3479. return FALSE;
  3480. }
  3481. *pp = p + 1;
  3482. break;
  3483. case '1': case '2': case '3': case '4': case '5':
  3484. case '6': case '7': case '8': case '9':
  3485. qualifiers = (*pp)[1] - '0';
  3486. /* Skip an optional underscore after the count. */
  3487. if ((*pp)[2] == '_')
  3488. ++*pp;
  3489. *pp += 2;
  3490. break;
  3491. case '0':
  3492. default:
  3493. stab_bad_demangle (orig);
  3494. return FALSE;
  3495. }
  3496. context = DEBUG_TYPE_NULL;
  3497. /* Pick off the names. */
  3498. while (qualifiers-- > 0)
  3499. {
  3500. if (**pp == '_')
  3501. ++*pp;
  3502. if (**pp == 't')
  3503. {
  3504. char *name;
  3505. if (! stab_demangle_template (minfo, pp,
  3506. ptype != NULL ? &name : NULL))
  3507. return FALSE;
  3508. if (ptype != NULL)
  3509. {
  3510. context = stab_find_tagged_type (minfo->dhandle, minfo->info,
  3511. name, strlen (name),
  3512. DEBUG_KIND_CLASS);
  3513. free (name);
  3514. if (context == DEBUG_TYPE_NULL)
  3515. return FALSE;
  3516. }
  3517. }
  3518. else
  3519. {
  3520. unsigned int len;
  3521. len = stab_demangle_count (pp);
  3522. if (strlen (*pp) < len)
  3523. {
  3524. stab_bad_demangle (orig);
  3525. return FALSE;
  3526. }
  3527. if (ptype != NULL)
  3528. {
  3529. const debug_field *fields;
  3530. fields = NULL;
  3531. if (context != DEBUG_TYPE_NULL)
  3532. fields = debug_get_fields (minfo->dhandle, context);
  3533. context = DEBUG_TYPE_NULL;
  3534. if (fields != NULL)
  3535. {
  3536. char *name;
  3537. /* Try to find the type by looking through the
  3538. fields of context until we find a field with the
  3539. same type. This ought to work for a class
  3540. defined within a class, but it won't work for,
  3541. e.g., an enum defined within a class. stabs does
  3542. not give us enough information to figure out the
  3543. latter case. */
  3544. name = savestring (*pp, len);
  3545. for (; *fields != DEBUG_FIELD_NULL; fields++)
  3546. {
  3547. debug_type ft;
  3548. const char *dn;
  3549. ft = debug_get_field_type (minfo->dhandle, *fields);
  3550. if (ft == NULL)
  3551. {
  3552. free (name);
  3553. return FALSE;
  3554. }
  3555. dn = debug_get_type_name (minfo->dhandle, ft);
  3556. if (dn != NULL && strcmp (dn, name) == 0)
  3557. {
  3558. context = ft;
  3559. break;
  3560. }
  3561. }
  3562. free (name);
  3563. }
  3564. if (context == DEBUG_TYPE_NULL)
  3565. {
  3566. /* We have to fall back on finding the type by name.
  3567. If there are more types to come, then this must
  3568. be a class. Otherwise, it could be anything. */
  3569. if (qualifiers == 0)
  3570. {
  3571. char *name;
  3572. name = savestring (*pp, len);
  3573. context = debug_find_named_type (minfo->dhandle,
  3574. name);
  3575. free (name);
  3576. }
  3577. if (context == DEBUG_TYPE_NULL)
  3578. {
  3579. context = stab_find_tagged_type (minfo->dhandle,
  3580. minfo->info,
  3581. *pp, len,
  3582. (qualifiers == 0
  3583. ? DEBUG_KIND_ILLEGAL
  3584. : DEBUG_KIND_CLASS));
  3585. if (context == DEBUG_TYPE_NULL)
  3586. return FALSE;
  3587. }
  3588. }
  3589. }
  3590. *pp += len;
  3591. }
  3592. }
  3593. if (ptype != NULL)
  3594. *ptype = context;
  3595. return TRUE;
  3596. }
  3597. /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
  3598. string representation of the template. */
  3599. static bfd_boolean
  3600. stab_demangle_template (struct stab_demangle_info *minfo, const char **pp,
  3601. char **pname)
  3602. {
  3603. const char *orig;
  3604. unsigned int r, i;
  3605. orig = *pp;
  3606. ++*pp;
  3607. /* Skip the template name. */
  3608. r = stab_demangle_count (pp);
  3609. if (r == 0 || strlen (*pp) < r)
  3610. {
  3611. stab_bad_demangle (orig);
  3612. return FALSE;
  3613. }
  3614. *pp += r;
  3615. /* Get the size of the parameter list. */
  3616. if (stab_demangle_get_count (pp, &r) == 0)
  3617. {
  3618. stab_bad_demangle (orig);
  3619. return FALSE;
  3620. }
  3621. for (i = 0; i < r; i++)
  3622. {
  3623. if (**pp == 'Z')
  3624. {
  3625. /* This is a type parameter. */
  3626. ++*pp;
  3627. if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
  3628. return FALSE;
  3629. }
  3630. else
  3631. {
  3632. const char *old_p;
  3633. bfd_boolean pointerp, realp, integralp, charp, boolp;
  3634. bfd_boolean done;
  3635. old_p = *pp;
  3636. pointerp = FALSE;
  3637. realp = FALSE;
  3638. integralp = FALSE;
  3639. charp = FALSE;
  3640. boolp = FALSE;
  3641. done = FALSE;
  3642. /* This is a value parameter. */
  3643. if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
  3644. return FALSE;
  3645. while (*old_p != '\0' && ! done)
  3646. {
  3647. switch (*old_p)
  3648. {
  3649. case 'P':
  3650. case 'p':
  3651. case 'R':
  3652. pointerp = TRUE;
  3653. done = TRUE;
  3654. break;
  3655. case 'C': /* Const. */
  3656. case 'S': /* Signed. */
  3657. case 'U': /* Unsigned. */
  3658. case 'V': /* Volatile. */
  3659. case 'F': /* Function. */
  3660. case 'M': /* Member function. */
  3661. case 'O': /* ??? */
  3662. ++old_p;
  3663. break;
  3664. case 'Q': /* Qualified name. */
  3665. integralp = TRUE;
  3666. done = TRUE;
  3667. break;
  3668. case 'T': /* Remembered type. */
  3669. abort ();
  3670. case 'v': /* Void. */
  3671. abort ();
  3672. case 'x': /* Long long. */
  3673. case 'l': /* Long. */
  3674. case 'i': /* Int. */
  3675. case 's': /* Short. */
  3676. case 'w': /* Wchar_t. */
  3677. integralp = TRUE;
  3678. done = TRUE;
  3679. break;
  3680. case 'b': /* Bool. */
  3681. boolp = TRUE;
  3682. done = TRUE;
  3683. break;
  3684. case 'c': /* Char. */
  3685. charp = TRUE;
  3686. done = TRUE;
  3687. break;
  3688. case 'r': /* Long double. */
  3689. case 'd': /* Double. */
  3690. case 'f': /* Float. */
  3691. realp = TRUE;
  3692. done = TRUE;
  3693. break;
  3694. default:
  3695. /* Assume it's a user defined integral type. */
  3696. integralp = TRUE;
  3697. done = TRUE;
  3698. break;
  3699. }
  3700. }
  3701. if (integralp)
  3702. {
  3703. if (**pp == 'm')
  3704. ++*pp;
  3705. while (ISDIGIT (**pp))
  3706. ++*pp;
  3707. }
  3708. else if (charp)
  3709. {
  3710. unsigned int val;
  3711. if (**pp == 'm')
  3712. ++*pp;
  3713. val = stab_demangle_count (pp);
  3714. if (val == 0)
  3715. {
  3716. stab_bad_demangle (orig);
  3717. return FALSE;
  3718. }
  3719. }
  3720. else if (boolp)
  3721. {
  3722. unsigned int val;
  3723. val = stab_demangle_count (pp);
  3724. if (val != 0 && val != 1)
  3725. {
  3726. stab_bad_demangle (orig);
  3727. return FALSE;
  3728. }
  3729. }
  3730. else if (realp)
  3731. {
  3732. if (**pp == 'm')
  3733. ++*pp;
  3734. while (ISDIGIT (**pp))
  3735. ++*pp;
  3736. if (**pp == '.')
  3737. {
  3738. ++*pp;
  3739. while (ISDIGIT (**pp))
  3740. ++*pp;
  3741. }
  3742. if (**pp == 'e')
  3743. {
  3744. ++*pp;
  3745. while (ISDIGIT (**pp))
  3746. ++*pp;
  3747. }
  3748. }
  3749. else if (pointerp)
  3750. {
  3751. unsigned int len;
  3752. len = stab_demangle_count (pp);
  3753. if (len == 0)
  3754. {
  3755. stab_bad_demangle (orig);
  3756. return FALSE;
  3757. }
  3758. *pp += len;
  3759. }
  3760. }
  3761. }
  3762. /* We can translate this to a string fairly easily by invoking the
  3763. regular demangling routine. */
  3764. if (pname != NULL)
  3765. {
  3766. char *s1, *s2, *s3, *s4 = NULL;
  3767. char *from, *to;
  3768. s1 = savestring (orig, *pp - orig);
  3769. s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL);
  3770. free (s1);
  3771. s3 = cplus_demangle (s2, DMGL_ANSI);
  3772. free (s2);
  3773. if (s3 != NULL)
  3774. s4 = strstr (s3, "::NoSuchStrinG");
  3775. if (s3 == NULL || s4 == NULL)
  3776. {
  3777. stab_bad_demangle (orig);
  3778. if (s3 != NULL)
  3779. free (s3);
  3780. return FALSE;
  3781. }
  3782. /* Eliminating all spaces, except those between > characters,
  3783. makes it more likely that the demangled name will match the
  3784. name which g++ used as the structure name. */
  3785. for (from = to = s3; from != s4; ++from)
  3786. if (*from != ' '
  3787. || (from[1] == '>' && from > s3 && from[-1] == '>'))
  3788. *to++ = *from;
  3789. *pname = savestring (s3, to - s3);
  3790. free (s3);
  3791. }
  3792. return TRUE;
  3793. }
  3794. /* Demangle a class name. */
  3795. static bfd_boolean
  3796. stab_demangle_class (struct stab_demangle_info *minfo ATTRIBUTE_UNUSED,
  3797. const char **pp, const char **pstart)
  3798. {
  3799. const char *orig;
  3800. unsigned int n;
  3801. orig = *pp;
  3802. n = stab_demangle_count (pp);
  3803. if (strlen (*pp) < n)
  3804. {
  3805. stab_bad_demangle (orig);
  3806. return FALSE;
  3807. }
  3808. if (pstart != NULL)
  3809. *pstart = *pp;
  3810. *pp += n;
  3811. return TRUE;
  3812. }
  3813. /* Demangle function arguments. If the pargs argument is not NULL, it
  3814. is set to a NULL terminated array holding the arguments. */
  3815. static bfd_boolean
  3816. stab_demangle_args (struct stab_demangle_info *minfo, const char **pp,
  3817. debug_type **pargs, bfd_boolean *pvarargs)
  3818. {
  3819. const char *orig;
  3820. unsigned int alloc, count;
  3821. orig = *pp;
  3822. alloc = 10;
  3823. if (pargs != NULL)
  3824. {
  3825. *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
  3826. *pvarargs = FALSE;
  3827. }
  3828. count = 0;
  3829. while (**pp != '_' && **pp != '\0' && **pp != 'e')
  3830. {
  3831. if (**pp == 'N' || **pp == 'T')
  3832. {
  3833. char temptype;
  3834. unsigned int r, t;
  3835. temptype = **pp;
  3836. ++*pp;
  3837. if (temptype == 'T')
  3838. r = 1;
  3839. else
  3840. {
  3841. if (! stab_demangle_get_count (pp, &r))
  3842. {
  3843. stab_bad_demangle (orig);
  3844. return FALSE;
  3845. }
  3846. }
  3847. if (! stab_demangle_get_count (pp, &t))
  3848. {
  3849. stab_bad_demangle (orig);
  3850. return FALSE;
  3851. }
  3852. if (t >= minfo->typestring_count)
  3853. {
  3854. stab_bad_demangle (orig);
  3855. return FALSE;
  3856. }
  3857. while (r-- > 0)
  3858. {
  3859. const char *tem;
  3860. tem = minfo->typestrings[t].typestring;
  3861. if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
  3862. return FALSE;
  3863. }
  3864. }
  3865. else
  3866. {
  3867. if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
  3868. return FALSE;
  3869. }
  3870. }
  3871. if (pargs != NULL)
  3872. (*pargs)[count] = DEBUG_TYPE_NULL;
  3873. if (**pp == 'e')
  3874. {
  3875. if (pargs != NULL)
  3876. *pvarargs = TRUE;
  3877. ++*pp;
  3878. }
  3879. return TRUE;
  3880. }
  3881. /* Demangle a single argument. */
  3882. static bfd_boolean
  3883. stab_demangle_arg (struct stab_demangle_info *minfo, const char **pp,
  3884. debug_type **pargs, unsigned int *pcount,
  3885. unsigned int *palloc)
  3886. {
  3887. const char *start;
  3888. debug_type type;
  3889. start = *pp;
  3890. if (! stab_demangle_type (minfo, pp,
  3891. pargs == NULL ? (debug_type *) NULL : &type)
  3892. || ! stab_demangle_remember_type (minfo, start, *pp - start))
  3893. return FALSE;
  3894. if (pargs != NULL)
  3895. {
  3896. if (type == DEBUG_TYPE_NULL)
  3897. return FALSE;
  3898. if (*pcount + 1 >= *palloc)
  3899. {
  3900. *palloc += 10;
  3901. *pargs = ((debug_type *)
  3902. xrealloc (*pargs, *palloc * sizeof **pargs));
  3903. }
  3904. (*pargs)[*pcount] = type;
  3905. ++*pcount;
  3906. }
  3907. return TRUE;
  3908. }
  3909. /* Demangle a type. If the ptype argument is not NULL, *ptype is set
  3910. to the newly allocated type. */
  3911. static bfd_boolean
  3912. stab_demangle_type (struct stab_demangle_info *minfo, const char **pp,
  3913. debug_type *ptype)
  3914. {
  3915. const char *orig;
  3916. orig = *pp;
  3917. switch (**pp)
  3918. {
  3919. case 'P':
  3920. case 'p':
  3921. /* A pointer type. */
  3922. ++*pp;
  3923. if (! stab_demangle_type (minfo, pp, ptype))
  3924. return FALSE;
  3925. if (ptype != NULL)
  3926. *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
  3927. break;
  3928. case 'R':
  3929. /* A reference type. */
  3930. ++*pp;
  3931. if (! stab_demangle_type (minfo, pp, ptype))
  3932. return FALSE;
  3933. if (ptype != NULL)
  3934. *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
  3935. break;
  3936. case 'A':
  3937. /* An array. */
  3938. {
  3939. unsigned long high;
  3940. ++*pp;
  3941. high = 0;
  3942. while (**pp != '\0' && **pp != '_')
  3943. {
  3944. if (! ISDIGIT (**pp))
  3945. {
  3946. stab_bad_demangle (orig);
  3947. return FALSE;
  3948. }
  3949. high *= 10;
  3950. high += **pp - '0';
  3951. ++*pp;
  3952. }
  3953. if (**pp != '_')
  3954. {
  3955. stab_bad_demangle (orig);
  3956. return FALSE;
  3957. }
  3958. ++*pp;
  3959. if (! stab_demangle_type (minfo, pp, ptype))
  3960. return FALSE;
  3961. if (ptype != NULL)
  3962. {
  3963. debug_type int_type;
  3964. int_type = debug_find_named_type (minfo->dhandle, "int");
  3965. if (int_type == NULL)
  3966. int_type = debug_make_int_type (minfo->dhandle, 4, FALSE);
  3967. *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
  3968. 0, high, FALSE);
  3969. }
  3970. }
  3971. break;
  3972. case 'T':
  3973. /* A back reference to a remembered type. */
  3974. {
  3975. unsigned int i;
  3976. const char *p;
  3977. ++*pp;
  3978. if (! stab_demangle_get_count (pp, &i))
  3979. {
  3980. stab_bad_demangle (orig);
  3981. return FALSE;
  3982. }
  3983. if (i >= minfo->typestring_count)
  3984. {
  3985. stab_bad_demangle (orig);
  3986. return FALSE;
  3987. }
  3988. p = minfo->typestrings[i].typestring;
  3989. if (! stab_demangle_type (minfo, &p, ptype))
  3990. return FALSE;
  3991. }
  3992. break;
  3993. case 'F':
  3994. /* A function. */
  3995. {
  3996. debug_type *args;
  3997. bfd_boolean varargs;
  3998. ++*pp;
  3999. if (! stab_demangle_args (minfo, pp,
  4000. (ptype == NULL
  4001. ? (debug_type **) NULL
  4002. : &args),
  4003. (ptype == NULL
  4004. ? (bfd_boolean *) NULL
  4005. : &varargs)))
  4006. return FALSE;
  4007. if (**pp != '_')
  4008. {
  4009. /* cplus_demangle will accept a function without a return
  4010. type, but I don't know when that will happen, or what
  4011. to do if it does. */
  4012. stab_bad_demangle (orig);
  4013. return FALSE;
  4014. }
  4015. ++*pp;
  4016. if (! stab_demangle_type (minfo, pp, ptype))
  4017. return FALSE;
  4018. if (ptype != NULL)
  4019. *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
  4020. varargs);
  4021. }
  4022. break;
  4023. case 'M':
  4024. case 'O':
  4025. {
  4026. bfd_boolean memberp;
  4027. debug_type class_type = DEBUG_TYPE_NULL;
  4028. debug_type *args;
  4029. bfd_boolean varargs;
  4030. unsigned int n;
  4031. const char *name;
  4032. memberp = **pp == 'M';
  4033. args = NULL;
  4034. varargs = FALSE;
  4035. ++*pp;
  4036. if (ISDIGIT (**pp))
  4037. {
  4038. n = stab_demangle_count (pp);
  4039. if (strlen (*pp) < n)
  4040. {
  4041. stab_bad_demangle (orig);
  4042. return FALSE;
  4043. }
  4044. name = *pp;
  4045. *pp += n;
  4046. if (ptype != NULL)
  4047. {
  4048. class_type = stab_find_tagged_type (minfo->dhandle,
  4049. minfo->info,
  4050. name, (int) n,
  4051. DEBUG_KIND_CLASS);
  4052. if (class_type == DEBUG_TYPE_NULL)
  4053. return FALSE;
  4054. }
  4055. }
  4056. else if (**pp == 'Q')
  4057. {
  4058. if (! stab_demangle_qualified (minfo, pp,
  4059. (ptype == NULL
  4060. ? (debug_type *) NULL
  4061. : &class_type)))
  4062. return FALSE;
  4063. }
  4064. else
  4065. {
  4066. stab_bad_demangle (orig);
  4067. return FALSE;
  4068. }
  4069. if (memberp)
  4070. {
  4071. if (**pp == 'C')
  4072. {
  4073. ++*pp;
  4074. }
  4075. else if (**pp == 'V')
  4076. {
  4077. ++*pp;
  4078. }
  4079. if (**pp != 'F')
  4080. {
  4081. stab_bad_demangle (orig);
  4082. return FALSE;
  4083. }
  4084. ++*pp;
  4085. if (! stab_demangle_args (minfo, pp,
  4086. (ptype == NULL
  4087. ? (debug_type **) NULL
  4088. : &args),
  4089. (ptype == NULL
  4090. ? (bfd_boolean *) NULL
  4091. : &varargs)))
  4092. return FALSE;
  4093. }
  4094. if (**pp != '_')
  4095. {
  4096. stab_bad_demangle (orig);
  4097. return FALSE;
  4098. }
  4099. ++*pp;
  4100. if (! stab_demangle_type (minfo, pp, ptype))
  4101. return FALSE;
  4102. if (ptype != NULL)
  4103. {
  4104. if (! memberp)
  4105. *ptype = debug_make_offset_type (minfo->dhandle, class_type,
  4106. *ptype);
  4107. else
  4108. {
  4109. /* FIXME: We have no way to record constp or
  4110. volatilep. */
  4111. *ptype = debug_make_method_type (minfo->dhandle, *ptype,
  4112. class_type, args, varargs);
  4113. }
  4114. }
  4115. }
  4116. break;
  4117. case 'G':
  4118. ++*pp;
  4119. if (! stab_demangle_type (minfo, pp, ptype))
  4120. return FALSE;
  4121. break;
  4122. case 'C':
  4123. ++*pp;
  4124. if (! stab_demangle_type (minfo, pp, ptype))
  4125. return FALSE;
  4126. if (ptype != NULL)
  4127. *ptype = debug_make_const_type (minfo->dhandle, *ptype);
  4128. break;
  4129. case 'Q':
  4130. {
  4131. if (! stab_demangle_qualified (minfo, pp, ptype))
  4132. return FALSE;
  4133. }
  4134. break;
  4135. default:
  4136. if (! stab_demangle_fund_type (minfo, pp, ptype))
  4137. return FALSE;
  4138. break;
  4139. }
  4140. return TRUE;
  4141. }
  4142. /* Demangle a fundamental type. If the ptype argument is not NULL,
  4143. *ptype is set to the newly allocated type. */
  4144. static bfd_boolean
  4145. stab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp,
  4146. debug_type *ptype)
  4147. {
  4148. const char *orig;
  4149. bfd_boolean constp, volatilep, unsignedp, signedp;
  4150. bfd_boolean done;
  4151. orig = *pp;
  4152. constp = FALSE;
  4153. volatilep = FALSE;
  4154. unsignedp = FALSE;
  4155. signedp = FALSE;
  4156. done = FALSE;
  4157. while (! done)
  4158. {
  4159. switch (**pp)
  4160. {
  4161. case 'C':
  4162. constp = TRUE;
  4163. ++*pp;
  4164. break;
  4165. case 'U':
  4166. unsignedp = TRUE;
  4167. ++*pp;
  4168. break;
  4169. case 'S':
  4170. signedp = TRUE;
  4171. ++*pp;
  4172. break;
  4173. case 'V':
  4174. volatilep = TRUE;
  4175. ++*pp;
  4176. break;
  4177. default:
  4178. done = TRUE;
  4179. break;
  4180. }
  4181. }
  4182. switch (**pp)
  4183. {
  4184. case '\0':
  4185. case '_':
  4186. /* cplus_demangle permits this, but I don't know what it means. */
  4187. stab_bad_demangle (orig);
  4188. break;
  4189. case 'v': /* void */
  4190. if (ptype != NULL)
  4191. {
  4192. *ptype = debug_find_named_type (minfo->dhandle, "void");
  4193. if (*ptype == DEBUG_TYPE_NULL)
  4194. *ptype = debug_make_void_type (minfo->dhandle);
  4195. }
  4196. ++*pp;
  4197. break;
  4198. case 'x': /* long long */
  4199. if (ptype != NULL)
  4200. {
  4201. *ptype = debug_find_named_type (minfo->dhandle,
  4202. (unsignedp
  4203. ? "long long unsigned int"
  4204. : "long long int"));
  4205. if (*ptype == DEBUG_TYPE_NULL)
  4206. *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
  4207. }
  4208. ++*pp;
  4209. break;
  4210. case 'l': /* long */
  4211. if (ptype != NULL)
  4212. {
  4213. *ptype = debug_find_named_type (minfo->dhandle,
  4214. (unsignedp
  4215. ? "long unsigned int"
  4216. : "long int"));
  4217. if (*ptype == DEBUG_TYPE_NULL)
  4218. *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
  4219. }
  4220. ++*pp;
  4221. break;
  4222. case 'i': /* int */
  4223. if (ptype != NULL)
  4224. {
  4225. *ptype = debug_find_named_type (minfo->dhandle,
  4226. (unsignedp
  4227. ? "unsigned int"
  4228. : "int"));
  4229. if (*ptype == DEBUG_TYPE_NULL)
  4230. *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
  4231. }
  4232. ++*pp;
  4233. break;
  4234. case 's': /* short */
  4235. if (ptype != NULL)
  4236. {
  4237. *ptype = debug_find_named_type (minfo->dhandle,
  4238. (unsignedp
  4239. ? "short unsigned int"
  4240. : "short int"));
  4241. if (*ptype == DEBUG_TYPE_NULL)
  4242. *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
  4243. }
  4244. ++*pp;
  4245. break;
  4246. case 'b': /* bool */
  4247. if (ptype != NULL)
  4248. {
  4249. *ptype = debug_find_named_type (minfo->dhandle, "bool");
  4250. if (*ptype == DEBUG_TYPE_NULL)
  4251. *ptype = debug_make_bool_type (minfo->dhandle, 4);
  4252. }
  4253. ++*pp;
  4254. break;
  4255. case 'c': /* char */
  4256. if (ptype != NULL)
  4257. {
  4258. *ptype = debug_find_named_type (minfo->dhandle,
  4259. (unsignedp
  4260. ? "unsigned char"
  4261. : (signedp
  4262. ? "signed char"
  4263. : "char")));
  4264. if (*ptype == DEBUG_TYPE_NULL)
  4265. *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
  4266. }
  4267. ++*pp;
  4268. break;
  4269. case 'w': /* wchar_t */
  4270. if (ptype != NULL)
  4271. {
  4272. *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
  4273. if (*ptype == DEBUG_TYPE_NULL)
  4274. *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE);
  4275. }
  4276. ++*pp;
  4277. break;
  4278. case 'r': /* long double */
  4279. if (ptype != NULL)
  4280. {
  4281. *ptype = debug_find_named_type (minfo->dhandle, "long double");
  4282. if (*ptype == DEBUG_TYPE_NULL)
  4283. *ptype = debug_make_float_type (minfo->dhandle, 8);
  4284. }
  4285. ++*pp;
  4286. break;
  4287. case 'd': /* double */
  4288. if (ptype != NULL)
  4289. {
  4290. *ptype = debug_find_named_type (minfo->dhandle, "double");
  4291. if (*ptype == DEBUG_TYPE_NULL)
  4292. *ptype = debug_make_float_type (minfo->dhandle, 8);
  4293. }
  4294. ++*pp;
  4295. break;
  4296. case 'f': /* float */
  4297. if (ptype != NULL)
  4298. {
  4299. *ptype = debug_find_named_type (minfo->dhandle, "float");
  4300. if (*ptype == DEBUG_TYPE_NULL)
  4301. *ptype = debug_make_float_type (minfo->dhandle, 4);
  4302. }
  4303. ++*pp;
  4304. break;
  4305. case 'G':
  4306. ++*pp;
  4307. if (! ISDIGIT (**pp))
  4308. {
  4309. stab_bad_demangle (orig);
  4310. return FALSE;
  4311. }
  4312. /* Fall through. */
  4313. case '0': case '1': case '2': case '3': case '4':
  4314. case '5': case '6': case '7': case '8': case '9':
  4315. {
  4316. const char *hold;
  4317. if (! stab_demangle_class (minfo, pp, &hold))
  4318. return FALSE;
  4319. if (ptype != NULL)
  4320. {
  4321. char *name;
  4322. name = savestring (hold, *pp - hold);
  4323. *ptype = debug_find_named_type (minfo->dhandle, name);
  4324. free (name);
  4325. if (*ptype == DEBUG_TYPE_NULL)
  4326. {
  4327. /* FIXME: It is probably incorrect to assume that
  4328. undefined types are tagged types. */
  4329. *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
  4330. hold, *pp - hold,
  4331. DEBUG_KIND_ILLEGAL);
  4332. if (*ptype == DEBUG_TYPE_NULL)
  4333. return FALSE;
  4334. }
  4335. }
  4336. }
  4337. break;
  4338. case 't':
  4339. {
  4340. char *name;
  4341. if (! stab_demangle_template (minfo, pp,
  4342. ptype != NULL ? &name : NULL))
  4343. return FALSE;
  4344. if (ptype != NULL)
  4345. {
  4346. *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
  4347. name, strlen (name),
  4348. DEBUG_KIND_CLASS);
  4349. free (name);
  4350. if (*ptype == DEBUG_TYPE_NULL)
  4351. return FALSE;
  4352. }
  4353. }
  4354. break;
  4355. default:
  4356. stab_bad_demangle (orig);
  4357. return FALSE;
  4358. }
  4359. if (ptype != NULL)
  4360. {
  4361. if (constp)
  4362. *ptype = debug_make_const_type (minfo->dhandle, *ptype);
  4363. if (volatilep)
  4364. *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
  4365. }
  4366. return TRUE;
  4367. }
  4368. /* Remember a type string in a demangled string. */
  4369. static bfd_boolean
  4370. stab_demangle_remember_type (struct stab_demangle_info *minfo,
  4371. const char *p, int len)
  4372. {
  4373. if (minfo->typestring_count >= minfo->typestring_alloc)
  4374. {
  4375. minfo->typestring_alloc += 10;
  4376. minfo->typestrings = ((struct stab_demangle_typestring *)
  4377. xrealloc (minfo->typestrings,
  4378. (minfo->typestring_alloc
  4379. * sizeof *minfo->typestrings)));
  4380. }
  4381. minfo->typestrings[minfo->typestring_count].typestring = p;
  4382. minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
  4383. ++minfo->typestring_count;
  4384. return TRUE;
  4385. }
  4386. /* Demangle names encoded using the g++ V3 ABI. The newer versions of
  4387. g++ which use this ABI do not encode ordinary method argument types
  4388. in a mangled name; they simply output the argument types. However,
  4389. for a static method, g++ simply outputs the return type and the
  4390. physical name. So in that case we need to demangle the name here.
  4391. Here PHYSNAME is the physical name of the function, and we set the
  4392. variable pointed at by PVARARGS to indicate whether this function
  4393. is varargs. This returns NULL, or a NULL terminated array of
  4394. argument types. */
  4395. static debug_type *
  4396. stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
  4397. const char *physname, bfd_boolean *pvarargs)
  4398. {
  4399. struct demangle_component *dc;
  4400. void *mem;
  4401. debug_type *pargs;
  4402. dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem);
  4403. if (dc == NULL)
  4404. {
  4405. stab_bad_demangle (physname);
  4406. return NULL;
  4407. }
  4408. /* We expect to see TYPED_NAME, and the right subtree describes the
  4409. function type. */
  4410. if (dc->type != DEMANGLE_COMPONENT_TYPED_NAME
  4411. || dc->u.s_binary.right->type != DEMANGLE_COMPONENT_FUNCTION_TYPE)
  4412. {
  4413. fprintf (stderr, _("Demangled name is not a function\n"));
  4414. free (mem);
  4415. return NULL;
  4416. }
  4417. pargs = stab_demangle_v3_arglist (dhandle, info,
  4418. dc->u.s_binary.right->u.s_binary.right,
  4419. pvarargs);
  4420. free (mem);
  4421. return pargs;
  4422. }
  4423. /* Demangle an argument list in a struct demangle_component tree.
  4424. Returns a DEBUG_TYPE_NULL terminated array of argument types, and
  4425. sets *PVARARGS to indicate whether this is a varargs function. */
  4426. static debug_type *
  4427. stab_demangle_v3_arglist (void *dhandle, struct stab_handle *info,
  4428. struct demangle_component *arglist,
  4429. bfd_boolean *pvarargs)
  4430. {
  4431. struct demangle_component *dc;
  4432. unsigned int alloc, count;
  4433. debug_type *pargs;
  4434. alloc = 10;
  4435. pargs = (debug_type *) xmalloc (alloc * sizeof *pargs);
  4436. *pvarargs = FALSE;
  4437. count = 0;
  4438. for (dc = arglist;
  4439. dc != NULL;
  4440. dc = dc->u.s_binary.right)
  4441. {
  4442. debug_type arg;
  4443. bfd_boolean varargs;
  4444. if (dc->type != DEMANGLE_COMPONENT_ARGLIST)
  4445. {
  4446. fprintf (stderr, _("Unexpected type in v3 arglist demangling\n"));
  4447. free (pargs);
  4448. return NULL;
  4449. }
  4450. /* PR 13925: Cope if the demangler returns an empty
  4451. context for a function with no arguments. */
  4452. if (dc->u.s_binary.left == NULL)
  4453. break;
  4454. arg = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
  4455. NULL, &varargs);
  4456. if (arg == NULL)
  4457. {
  4458. if (varargs)
  4459. {
  4460. *pvarargs = TRUE;
  4461. continue;
  4462. }
  4463. free (pargs);
  4464. return NULL;
  4465. }
  4466. if (count + 1 >= alloc)
  4467. {
  4468. alloc += 10;
  4469. pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs);
  4470. }
  4471. pargs[count] = arg;
  4472. ++count;
  4473. }
  4474. pargs[count] = DEBUG_TYPE_NULL;
  4475. return pargs;
  4476. }
  4477. /* Convert a struct demangle_component tree describing an argument
  4478. type into a debug_type. */
  4479. static debug_type
  4480. stab_demangle_v3_arg (void *dhandle, struct stab_handle *info,
  4481. struct demangle_component *dc, debug_type context,
  4482. bfd_boolean *pvarargs)
  4483. {
  4484. debug_type dt;
  4485. if (pvarargs != NULL)
  4486. *pvarargs = FALSE;
  4487. switch (dc->type)
  4488. {
  4489. /* FIXME: These are demangle component types which we probably
  4490. need to handle one way or another. */
  4491. case DEMANGLE_COMPONENT_LOCAL_NAME:
  4492. case DEMANGLE_COMPONENT_TYPED_NAME:
  4493. case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
  4494. case DEMANGLE_COMPONENT_CTOR:
  4495. case DEMANGLE_COMPONENT_DTOR:
  4496. case DEMANGLE_COMPONENT_JAVA_CLASS:
  4497. case DEMANGLE_COMPONENT_RESTRICT_THIS:
  4498. case DEMANGLE_COMPONENT_VOLATILE_THIS:
  4499. case DEMANGLE_COMPONENT_CONST_THIS:
  4500. case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
  4501. case DEMANGLE_COMPONENT_COMPLEX:
  4502. case DEMANGLE_COMPONENT_IMAGINARY:
  4503. case DEMANGLE_COMPONENT_VENDOR_TYPE:
  4504. case DEMANGLE_COMPONENT_ARRAY_TYPE:
  4505. case DEMANGLE_COMPONENT_PTRMEM_TYPE:
  4506. case DEMANGLE_COMPONENT_ARGLIST:
  4507. default:
  4508. fprintf (stderr, _("Unrecognized demangle component %d\n"),
  4509. (int) dc->type);
  4510. return NULL;
  4511. case DEMANGLE_COMPONENT_NAME:
  4512. if (context != NULL)
  4513. {
  4514. const debug_field *fields;
  4515. fields = debug_get_fields (dhandle, context);
  4516. if (fields != NULL)
  4517. {
  4518. /* Try to find this type by looking through the context
  4519. class. */
  4520. for (; *fields != DEBUG_FIELD_NULL; fields++)
  4521. {
  4522. debug_type ft;
  4523. const char *dn;
  4524. ft = debug_get_field_type (dhandle, *fields);
  4525. if (ft == NULL)
  4526. return NULL;
  4527. dn = debug_get_type_name (dhandle, ft);
  4528. if (dn != NULL
  4529. && (int) strlen (dn) == dc->u.s_name.len
  4530. && strncmp (dn, dc->u.s_name.s, dc->u.s_name.len) == 0)
  4531. return ft;
  4532. }
  4533. }
  4534. }
  4535. return stab_find_tagged_type (dhandle, info, dc->u.s_name.s,
  4536. dc->u.s_name.len, DEBUG_KIND_ILLEGAL);
  4537. case DEMANGLE_COMPONENT_QUAL_NAME:
  4538. context = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
  4539. context, NULL);
  4540. if (context == NULL)
  4541. return NULL;
  4542. return stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.right,
  4543. context, NULL);
  4544. case DEMANGLE_COMPONENT_TEMPLATE:
  4545. {
  4546. char *p;
  4547. size_t alc;
  4548. /* We print this component to get a class name which we can
  4549. use. FIXME: This probably won't work if the template uses
  4550. template parameters which refer to an outer template. */
  4551. p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
  4552. if (p == NULL)
  4553. {
  4554. fprintf (stderr, _("Failed to print demangled template\n"));
  4555. return NULL;
  4556. }
  4557. dt = stab_find_tagged_type (dhandle, info, p, strlen (p),
  4558. DEBUG_KIND_CLASS);
  4559. free (p);
  4560. return dt;
  4561. }
  4562. case DEMANGLE_COMPONENT_SUB_STD:
  4563. return stab_find_tagged_type (dhandle, info, dc->u.s_string.string,
  4564. dc->u.s_string.len, DEBUG_KIND_ILLEGAL);
  4565. case DEMANGLE_COMPONENT_RESTRICT:
  4566. case DEMANGLE_COMPONENT_VOLATILE:
  4567. case DEMANGLE_COMPONENT_CONST:
  4568. case DEMANGLE_COMPONENT_POINTER:
  4569. case DEMANGLE_COMPONENT_REFERENCE:
  4570. dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
  4571. NULL);
  4572. if (dt == NULL)
  4573. return NULL;
  4574. switch (dc->type)
  4575. {
  4576. default:
  4577. abort ();
  4578. case DEMANGLE_COMPONENT_RESTRICT:
  4579. /* FIXME: We have no way to represent restrict. */
  4580. return dt;
  4581. case DEMANGLE_COMPONENT_VOLATILE:
  4582. return debug_make_volatile_type (dhandle, dt);
  4583. case DEMANGLE_COMPONENT_CONST:
  4584. return debug_make_const_type (dhandle, dt);
  4585. case DEMANGLE_COMPONENT_POINTER:
  4586. return debug_make_pointer_type (dhandle, dt);
  4587. case DEMANGLE_COMPONENT_REFERENCE:
  4588. return debug_make_reference_type (dhandle, dt);
  4589. }
  4590. case DEMANGLE_COMPONENT_FUNCTION_TYPE:
  4591. {
  4592. debug_type *pargs;
  4593. bfd_boolean varargs;
  4594. if (dc->u.s_binary.left == NULL)
  4595. {
  4596. /* In this case the return type is actually unknown.
  4597. However, I'm not sure this will ever arise in practice;
  4598. normally an unknown return type would only appear at
  4599. the top level, which is handled above. */
  4600. dt = debug_make_void_type (dhandle);
  4601. }
  4602. else
  4603. dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
  4604. NULL);
  4605. if (dt == NULL)
  4606. return NULL;
  4607. pargs = stab_demangle_v3_arglist (dhandle, info,
  4608. dc->u.s_binary.right,
  4609. &varargs);
  4610. if (pargs == NULL)
  4611. return NULL;
  4612. return debug_make_function_type (dhandle, dt, pargs, varargs);
  4613. }
  4614. case DEMANGLE_COMPONENT_BUILTIN_TYPE:
  4615. {
  4616. char *p;
  4617. size_t alc;
  4618. debug_type ret;
  4619. /* We print this component in order to find out the type name.
  4620. FIXME: Should we instead expose the
  4621. demangle_builtin_type_info structure? */
  4622. p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
  4623. if (p == NULL)
  4624. {
  4625. fprintf (stderr, _("Couldn't get demangled builtin type\n"));
  4626. return NULL;
  4627. }
  4628. /* The mangling is based on the type, but does not itself
  4629. indicate what the sizes are. So we have to guess. */
  4630. if (strcmp (p, "signed char") == 0)
  4631. ret = debug_make_int_type (dhandle, 1, FALSE);
  4632. else if (strcmp (p, "bool") == 0)
  4633. ret = debug_make_bool_type (dhandle, 1);
  4634. else if (strcmp (p, "char") == 0)
  4635. ret = debug_make_int_type (dhandle, 1, FALSE);
  4636. else if (strcmp (p, "double") == 0)
  4637. ret = debug_make_float_type (dhandle, 8);
  4638. else if (strcmp (p, "long double") == 0)
  4639. ret = debug_make_float_type (dhandle, 8);
  4640. else if (strcmp (p, "float") == 0)
  4641. ret = debug_make_float_type (dhandle, 4);
  4642. else if (strcmp (p, "__float128") == 0)
  4643. ret = debug_make_float_type (dhandle, 16);
  4644. else if (strcmp (p, "unsigned char") == 0)
  4645. ret = debug_make_int_type (dhandle, 1, TRUE);
  4646. else if (strcmp (p, "int") == 0)
  4647. ret = debug_make_int_type (dhandle, 4, FALSE);
  4648. else if (strcmp (p, "unsigned int") == 0)
  4649. ret = debug_make_int_type (dhandle, 4, TRUE);
  4650. else if (strcmp (p, "long") == 0)
  4651. ret = debug_make_int_type (dhandle, 4, FALSE);
  4652. else if (strcmp (p, "unsigned long") == 0)
  4653. ret = debug_make_int_type (dhandle, 4, TRUE);
  4654. else if (strcmp (p, "__int128") == 0)
  4655. ret = debug_make_int_type (dhandle, 16, FALSE);
  4656. else if (strcmp (p, "unsigned __int128") == 0)
  4657. ret = debug_make_int_type (dhandle, 16, TRUE);
  4658. else if (strcmp (p, "short") == 0)
  4659. ret = debug_make_int_type (dhandle, 2, FALSE);
  4660. else if (strcmp (p, "unsigned short") == 0)
  4661. ret = debug_make_int_type (dhandle, 2, TRUE);
  4662. else if (strcmp (p, "void") == 0)
  4663. ret = debug_make_void_type (dhandle);
  4664. else if (strcmp (p, "wchar_t") == 0)
  4665. ret = debug_make_int_type (dhandle, 4, TRUE);
  4666. else if (strcmp (p, "long long") == 0)
  4667. ret = debug_make_int_type (dhandle, 8, FALSE);
  4668. else if (strcmp (p, "unsigned long long") == 0)
  4669. ret = debug_make_int_type (dhandle, 8, TRUE);
  4670. else if (strcmp (p, "...") == 0)
  4671. {
  4672. if (pvarargs == NULL)
  4673. fprintf (stderr, _("Unexpected demangled varargs\n"));
  4674. else
  4675. *pvarargs = TRUE;
  4676. ret = NULL;
  4677. }
  4678. else
  4679. {
  4680. fprintf (stderr, _("Unrecognized demangled builtin type\n"));
  4681. ret = NULL;
  4682. }
  4683. free (p);
  4684. return ret;
  4685. }
  4686. }
  4687. }