stabs.c 134 KB

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