mdebugread.c 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802
  1. /* Read a symbol table in ECOFF format (Third-Eye).
  2. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  3. Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
  4. CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor
  5. at Cygnus Support.
  6. This file is part of GDB.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  17. /* This module provides the function mdebug_build_psymtabs. It reads
  18. ECOFF debugging information into partial symbol tables. The
  19. debugging information is read from two structures. A struct
  20. ecoff_debug_swap includes the sizes of each ECOFF structure and
  21. swapping routines; these are fixed for a particular target. A
  22. struct ecoff_debug_info points to the debugging information for a
  23. particular object file.
  24. ECOFF symbol tables are mostly written in the byte order of the
  25. target machine. However, one section of the table (the auxiliary
  26. symbol information) is written in the host byte order. There is a
  27. bit in the other symbol info which describes which host byte order
  28. was used. ECOFF thereby takes the trophy from Intel `b.out' for
  29. the most brain-dead adaptation of a file format to byte order.
  30. This module can read all four of the known byte-order combinations,
  31. on any type of host. */
  32. #include "defs.h"
  33. #include "symtab.h"
  34. #include "gdbtypes.h"
  35. #include "gdbcore.h"
  36. #include "filenames.h"
  37. #include "objfiles.h"
  38. #include "gdbsupport/gdb_obstack.h"
  39. #include "buildsym-legacy.h"
  40. #include "stabsread.h"
  41. #include "complaints.h"
  42. #include "demangle.h"
  43. #include "gdb-demangle.h"
  44. #include "block.h"
  45. #include "dictionary.h"
  46. #include "mdebugread.h"
  47. #include <sys/stat.h>
  48. #include "psympriv.h"
  49. #include "source.h"
  50. #include "bfd.h"
  51. #include "coff/ecoff.h" /* COFF-like aspects of ecoff files. */
  52. #include "libaout.h" /* Private BFD a.out information. */
  53. #include "aout/aout64.h"
  54. #include "aout/stab_gnu.h" /* STABS information. */
  55. #include "expression.h"
  56. #include <algorithm>
  57. /* Provide a way to test if we have both ECOFF and ELF symbol tables.
  58. We use this define in order to know whether we should override a
  59. symbol's ECOFF section with its ELF section. This is necessary in
  60. case the symbol's ELF section could not be represented in ECOFF. */
  61. #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
  62. && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
  63. /* The objfile we are currently reading. */
  64. static struct objfile *mdebugread_objfile;
  65. /* We put a pointer to this structure in the read_symtab_private field
  66. of the psymtab. */
  67. struct symloc
  68. {
  69. /* Index of the FDR that this psymtab represents. */
  70. int fdr_idx;
  71. /* The BFD that the psymtab was created from. */
  72. bfd *cur_bfd;
  73. const struct ecoff_debug_swap *debug_swap;
  74. struct ecoff_debug_info *debug_info;
  75. struct mdebug_pending **pending_list;
  76. /* Pointer to external symbols for this file. */
  77. EXTR *extern_tab;
  78. /* Size of extern_tab. */
  79. int extern_count;
  80. enum language pst_language;
  81. };
  82. #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
  83. #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
  84. #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
  85. #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
  86. #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
  87. #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
  88. #define SC_IS_TEXT(sc) ((sc) == scText \
  89. || (sc) == scRConst \
  90. || (sc) == scInit \
  91. || (sc) == scFini)
  92. #define SC_IS_DATA(sc) ((sc) == scData \
  93. || (sc) == scSData \
  94. || (sc) == scRData \
  95. || (sc) == scPData \
  96. || (sc) == scXData)
  97. #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
  98. #define SC_IS_BSS(sc) ((sc) == scBss)
  99. #define SC_IS_SBSS(sc) ((sc) == scSBss)
  100. #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
  101. /* Various complaints about symbol reading that don't abort the process. */
  102. static void
  103. index_complaint (const char *arg1)
  104. {
  105. complaint (_("bad aux index at symbol %s"), arg1);
  106. }
  107. static void
  108. unknown_ext_complaint (const char *arg1)
  109. {
  110. complaint (_("unknown external symbol %s"), arg1);
  111. }
  112. static void
  113. basic_type_complaint (int arg1, const char *arg2)
  114. {
  115. complaint (_("cannot map ECOFF basic type 0x%x for %s"),
  116. arg1, arg2);
  117. }
  118. static void
  119. bad_tag_guess_complaint (const char *arg1)
  120. {
  121. complaint (_("guessed tag type of %s incorrectly"), arg1);
  122. }
  123. static void
  124. bad_rfd_entry_complaint (const char *arg1, int arg2, int arg3)
  125. {
  126. complaint (_("bad rfd entry for %s: file %d, index %d"),
  127. arg1, arg2, arg3);
  128. }
  129. static void
  130. unexpected_type_code_complaint (const char *arg1)
  131. {
  132. complaint (_("unexpected type code for %s"), arg1);
  133. }
  134. /* Macros and extra defs. */
  135. /* Puns: hard to find whether -g was used and how. */
  136. #define MIN_GLEVEL GLEVEL_0
  137. #define compare_glevel(a,b) \
  138. (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
  139. ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
  140. /* Things that really are local to this module. */
  141. /* Remember what we deduced to be the source language of this psymtab. */
  142. static enum language psymtab_language = language_unknown;
  143. /* Current BFD. */
  144. static bfd *cur_bfd;
  145. /* How to parse debugging information for CUR_BFD. */
  146. static const struct ecoff_debug_swap *debug_swap;
  147. /* Pointers to debugging information for CUR_BFD. */
  148. static struct ecoff_debug_info *debug_info;
  149. /* Pointer to current file descriptor record, and its index. */
  150. static FDR *cur_fdr;
  151. static int cur_fd;
  152. /* Index of current symbol. */
  153. static int cur_sdx;
  154. /* Note how much "debuggable" this image is. We would like
  155. to see at least one FDR with full symbols. */
  156. static int max_gdbinfo;
  157. static int max_glevel;
  158. /* When examining .o files, report on undefined symbols. */
  159. static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
  160. /* Pseudo symbol to use when putting stabs into the symbol table. */
  161. static char stabs_symbol[] = STABS_SYMBOL;
  162. /* Nonzero if we have seen ecoff debugging info for a file. */
  163. static int found_ecoff_debugging_info;
  164. /* Forward declarations. */
  165. static int upgrade_type (int, struct type **, int, union aux_ext *,
  166. int, const char *);
  167. static void parse_partial_symbols (minimal_symbol_reader &,
  168. psymtab_storage *,
  169. struct objfile *);
  170. static int has_opaque_xref (FDR *, SYMR *);
  171. static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
  172. const char **, int, const char *);
  173. static struct symbol *new_symbol (const char *);
  174. static struct type *new_type (char *);
  175. enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
  176. static struct block *new_block (enum block_type, enum language);
  177. static struct compunit_symtab *new_symtab (const char *, int, struct objfile *);
  178. static struct linetable *new_linetable (int);
  179. static struct blockvector *new_bvect (int);
  180. static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
  181. int, const char *);
  182. static struct symbol *mylookup_symbol (const char *, const struct block *,
  183. domain_enum, enum address_class);
  184. static void sort_blocks (struct symtab *);
  185. static legacy_psymtab *new_psymtab (const char *, psymtab_storage *,
  186. struct objfile *);
  187. static void mdebug_expand_psymtab (legacy_psymtab *pst,
  188. struct objfile *objfile);
  189. static void add_block (struct block *, struct symtab *);
  190. static void add_symbol (struct symbol *, struct symtab *, struct block *);
  191. static int add_line (struct linetable *, int, CORE_ADDR, int);
  192. static struct linetable *shrink_linetable (struct linetable *);
  193. static void handle_psymbol_enumerators (struct objfile *, psymtab_storage *,
  194. partial_symtab *,
  195. FDR *, int, CORE_ADDR);
  196. static const char *mdebug_next_symbol_text (struct objfile *);
  197. /* Exported procedure: Builds a symtab from the partial symtab SELF.
  198. Restores the environment in effect when SELF was created, delegates
  199. most of the work to an ancillary procedure, and sorts
  200. and reorders the symtab list at the end. SELF is not NULL. */
  201. static void
  202. mdebug_read_symtab (legacy_psymtab *self, struct objfile *objfile)
  203. {
  204. next_symbol_text_func = mdebug_next_symbol_text;
  205. self->expand_psymtab (objfile);
  206. /* Match with global symbols. This only needs to be done once,
  207. after all of the symtabs and dependencies have been read in. */
  208. scan_file_globals (objfile);
  209. }
  210. /* File-level interface functions. */
  211. /* Find a file descriptor given its index RF relative to a file CF. */
  212. static FDR *
  213. get_rfd (int cf, int rf)
  214. {
  215. FDR *fdrs;
  216. FDR *f;
  217. RFDT rfd;
  218. fdrs = debug_info->fdr;
  219. f = fdrs + cf;
  220. /* Object files do not have the RFD table, all refs are absolute. */
  221. if (f->rfdBase == 0)
  222. return fdrs + rf;
  223. (*debug_swap->swap_rfd_in) (cur_bfd,
  224. ((char *) debug_info->external_rfd
  225. + ((f->rfdBase + rf)
  226. * debug_swap->external_rfd_size)),
  227. &rfd);
  228. return fdrs + rfd;
  229. }
  230. /* Return a safer print NAME for a file descriptor. */
  231. static const char *
  232. fdr_name (FDR *f)
  233. {
  234. if (f->rss == -1)
  235. return "<stripped file>";
  236. if (f->rss == 0)
  237. return "<NFY>";
  238. return debug_info->ss + f->issBase + f->rss;
  239. }
  240. /* Read in and parse the symtab of the file OBJFILE. Symbols from
  241. different sections are relocated via the SECTION_OFFSETS. */
  242. void
  243. mdebug_build_psymtabs (minimal_symbol_reader &reader,
  244. struct objfile *objfile,
  245. const struct ecoff_debug_swap *swap,
  246. struct ecoff_debug_info *info)
  247. {
  248. cur_bfd = objfile->obfd;
  249. debug_swap = swap;
  250. debug_info = info;
  251. stabsread_new_init ();
  252. free_header_files ();
  253. init_header_files ();
  254. /* Make sure all the FDR information is swapped in. */
  255. if (info->fdr == NULL)
  256. {
  257. char *fdr_src;
  258. char *fdr_end;
  259. FDR *fdr_ptr;
  260. info->fdr = (FDR *) XOBNEWVEC (&objfile->objfile_obstack, FDR,
  261. info->symbolic_header.ifdMax);
  262. fdr_src = (char *) info->external_fdr;
  263. fdr_end = (fdr_src
  264. + info->symbolic_header.ifdMax * swap->external_fdr_size);
  265. fdr_ptr = info->fdr;
  266. for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
  267. (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
  268. }
  269. psymbol_functions *psf = new psymbol_functions ();
  270. psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
  271. objfile->qf.emplace_front (psf);
  272. parse_partial_symbols (reader, partial_symtabs, objfile);
  273. #if 0
  274. /* Check to make sure file was compiled with -g. If not, warn the
  275. user of this limitation. */
  276. if (compare_glevel (max_glevel, GLEVEL_2) < 0)
  277. {
  278. if (max_gdbinfo == 0)
  279. gdb_printf (_("\n%s not compiled with -g, "
  280. "debugging support is limited.\n"),
  281. objfile->name);
  282. gdb_printf (_("You should compile with -g2 or "
  283. "-g3 for best debugging support.\n"));
  284. }
  285. #endif
  286. }
  287. /* Local utilities */
  288. /* Map of FDR indexes to partial symtabs. */
  289. struct pst_map
  290. {
  291. legacy_psymtab *pst = nullptr; /* the psymtab proper */
  292. long n_globals = 0; /* exported globals (external symbols) */
  293. long globals_offset = 0; /* cumulative */
  294. };
  295. /* Utility stack, used to nest procedures and blocks properly.
  296. It is a doubly linked list, to avoid too many alloc/free.
  297. Since we might need it quite a few times it is NOT deallocated
  298. after use. */
  299. static struct parse_stack
  300. {
  301. struct parse_stack *next, *prev;
  302. struct symtab *cur_st; /* Current symtab. */
  303. struct block *cur_block; /* Block in it. */
  304. /* What are we parsing. stFile, or stBlock are for files and
  305. blocks. stProc or stStaticProc means we have seen the start of a
  306. procedure, but not the start of the block within in. When we see
  307. the start of that block, we change it to stNil, without pushing a
  308. new block, i.e. stNil means both a procedure and a block. */
  309. int blocktype;
  310. struct type *cur_type; /* Type we parse fields for. */
  311. int cur_field; /* Field number in cur_type. */
  312. CORE_ADDR procadr; /* Start addres of this procedure. */
  313. int numargs; /* Its argument count. */
  314. }
  315. *top_stack; /* Top stack ptr */
  316. /* Enter a new lexical context. */
  317. static void
  318. push_parse_stack (void)
  319. {
  320. struct parse_stack *newobj;
  321. /* Reuse frames if possible. */
  322. if (top_stack && top_stack->prev)
  323. newobj = top_stack->prev;
  324. else
  325. newobj = XCNEW (struct parse_stack);
  326. /* Initialize new frame with previous content. */
  327. if (top_stack)
  328. {
  329. struct parse_stack *prev = newobj->prev;
  330. *newobj = *top_stack;
  331. top_stack->prev = newobj;
  332. newobj->prev = prev;
  333. newobj->next = top_stack;
  334. }
  335. top_stack = newobj;
  336. }
  337. /* Exit a lexical context. */
  338. static void
  339. pop_parse_stack (void)
  340. {
  341. if (!top_stack)
  342. return;
  343. if (top_stack->next)
  344. top_stack = top_stack->next;
  345. }
  346. /* Cross-references might be to things we haven't looked at
  347. yet, e.g. type references. To avoid too many type
  348. duplications we keep a quick fixup table, an array
  349. of lists of references indexed by file descriptor. */
  350. struct mdebug_pending
  351. {
  352. struct mdebug_pending *next; /* link */
  353. char *s; /* the unswapped symbol */
  354. struct type *t; /* its partial type descriptor */
  355. };
  356. /* The pending information is kept for an entire object file. We
  357. allocate the pending information table when we create the partial
  358. symbols, and we store a pointer to the single table in each
  359. psymtab. */
  360. static struct mdebug_pending **pending_list;
  361. /* Check whether we already saw symbol SH in file FH. */
  362. static struct mdebug_pending *
  363. is_pending_symbol (FDR *fh, char *sh)
  364. {
  365. int f_idx = fh - debug_info->fdr;
  366. struct mdebug_pending *p;
  367. /* Linear search is ok, list is typically no more than 10 deep. */
  368. for (p = pending_list[f_idx]; p; p = p->next)
  369. if (p->s == sh)
  370. break;
  371. return p;
  372. }
  373. /* Add a new symbol SH of type T. */
  374. static void
  375. add_pending (FDR *fh, char *sh, struct type *t)
  376. {
  377. int f_idx = fh - debug_info->fdr;
  378. struct mdebug_pending *p = is_pending_symbol (fh, sh);
  379. /* Make sure we do not make duplicates. */
  380. if (!p)
  381. {
  382. p = XOBNEW (&mdebugread_objfile->objfile_obstack, mdebug_pending);
  383. p->s = sh;
  384. p->t = t;
  385. p->next = pending_list[f_idx];
  386. pending_list[f_idx] = p;
  387. }
  388. }
  389. /* Parsing Routines proper. */
  390. static void
  391. reg_value_complaint (int regnum, int num_regs, const char *sym)
  392. {
  393. complaint (_("bad register number %d (max %d) in symbol %s"),
  394. regnum, num_regs - 1, sym);
  395. }
  396. /* Parse a single symbol. Mostly just make up a GDB symbol for it.
  397. For blocks, procedures and types we open a new lexical context.
  398. This is basically just a big switch on the symbol's type. Argument
  399. AX is the base pointer of aux symbols for this file (fh->iauxBase).
  400. EXT_SH points to the unswapped symbol, which is needed for struct,
  401. union, etc., types; it is NULL for an EXTR. BIGEND says whether
  402. aux symbols are big-endian or little-endian. Return count of
  403. SYMR's handled (normally one). */
  404. static int
  405. mdebug_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
  406. {
  407. int regno = gdbarch_ecoff_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));
  408. if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch))
  409. {
  410. reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch),
  411. sym->print_name ());
  412. regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless. */
  413. }
  414. return regno;
  415. }
  416. static const struct symbol_register_ops mdebug_register_funcs = {
  417. mdebug_reg_to_regnum
  418. };
  419. /* The "aclass" indices for computed symbols. */
  420. static int mdebug_register_index;
  421. static int mdebug_regparm_index;
  422. /* Common code for symbols describing data. */
  423. static void
  424. add_data_symbol (SYMR *sh, union aux_ext *ax, int bigend,
  425. struct symbol *s, int aclass_index, struct block *b,
  426. struct objfile *objfile, const char *name)
  427. {
  428. s->set_domain (VAR_DOMAIN);
  429. s->set_aclass_index (aclass_index);
  430. add_symbol (s, top_stack->cur_st, b);
  431. /* Type could be missing if file is compiled without debugging info. */
  432. if (SC_IS_UNDEF (sh->sc)
  433. || sh->sc == scNil || sh->index == indexNil)
  434. s->set_type (objfile_type (objfile)->nodebug_data_symbol);
  435. else
  436. s->set_type (parse_type (cur_fd, ax, sh->index, 0, bigend, name));
  437. /* Value of a data symbol is its memory address. */
  438. }
  439. static int
  440. parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
  441. const section_offsets &section_offsets, struct objfile *objfile)
  442. {
  443. struct gdbarch *gdbarch = objfile->arch ();
  444. const bfd_size_type external_sym_size = debug_swap->external_sym_size;
  445. void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
  446. const char *name;
  447. struct symbol *s;
  448. struct block *b;
  449. struct mdebug_pending *pend;
  450. struct type *t;
  451. int count = 1;
  452. TIR tir;
  453. long svalue = sh->value;
  454. int bitsize;
  455. if (ext_sh == NULL)
  456. name = debug_info->ssext + sh->iss;
  457. else
  458. name = debug_info->ss + cur_fdr->issBase + sh->iss;
  459. switch (sh->sc)
  460. {
  461. case scText:
  462. case scRConst:
  463. /* Do not relocate relative values.
  464. The value of a stEnd symbol is the displacement from the
  465. corresponding start symbol value.
  466. The value of a stBlock symbol is the displacement from the
  467. procedure address. */
  468. if (sh->st != stEnd && sh->st != stBlock)
  469. sh->value += section_offsets[SECT_OFF_TEXT (objfile)];
  470. break;
  471. case scData:
  472. case scSData:
  473. case scRData:
  474. case scPData:
  475. case scXData:
  476. sh->value += section_offsets[SECT_OFF_DATA (objfile)];
  477. break;
  478. case scBss:
  479. case scSBss:
  480. sh->value += section_offsets[SECT_OFF_BSS (objfile)];
  481. break;
  482. }
  483. switch (sh->st)
  484. {
  485. case stNil:
  486. break;
  487. case stGlobal: /* External symbol, goes into global block. */
  488. b = BLOCKVECTOR_BLOCK (top_stack->cur_st->compunit ()->blockvector (),
  489. GLOBAL_BLOCK);
  490. s = new_symbol (name);
  491. SET_SYMBOL_VALUE_ADDRESS (s, (CORE_ADDR) sh->value);
  492. add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
  493. break;
  494. case stStatic: /* Static data, goes into current block. */
  495. b = top_stack->cur_block;
  496. s = new_symbol (name);
  497. if (SC_IS_COMMON (sh->sc))
  498. {
  499. /* It is a FORTRAN common block. At least for SGI Fortran the
  500. address is not in the symbol; we need to fix it later in
  501. scan_file_globals. */
  502. int bucket = hashname (s->linkage_name ());
  503. SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
  504. global_sym_chain[bucket] = s;
  505. }
  506. else
  507. SET_SYMBOL_VALUE_ADDRESS (s, (CORE_ADDR) sh->value);
  508. add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
  509. break;
  510. case stLocal: /* Local variable, goes into current block. */
  511. b = top_stack->cur_block;
  512. s = new_symbol (name);
  513. SYMBOL_VALUE (s) = svalue;
  514. if (sh->sc == scRegister)
  515. add_data_symbol (sh, ax, bigend, s, mdebug_register_index,
  516. b, objfile, name);
  517. else
  518. add_data_symbol (sh, ax, bigend, s, LOC_LOCAL,
  519. b, objfile, name);
  520. break;
  521. case stParam: /* Arg to procedure, goes into current
  522. block. */
  523. max_gdbinfo++;
  524. found_ecoff_debugging_info = 1;
  525. top_stack->numargs++;
  526. /* Special GNU C++ name. */
  527. if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
  528. name = "this"; /* FIXME, not alloc'd in obstack. */
  529. s = new_symbol (name);
  530. s->set_domain (VAR_DOMAIN);
  531. s->set_is_argument (1);
  532. switch (sh->sc)
  533. {
  534. case scRegister:
  535. /* Pass by value in register. */
  536. s->set_aclass_index (mdebug_register_index);
  537. break;
  538. case scVar:
  539. /* Pass by reference on stack. */
  540. s->set_aclass_index (LOC_REF_ARG);
  541. break;
  542. case scVarRegister:
  543. /* Pass by reference in register. */
  544. s->set_aclass_index (mdebug_regparm_index);
  545. break;
  546. default:
  547. /* Pass by value on stack. */
  548. s->set_aclass_index (LOC_ARG);
  549. break;
  550. }
  551. SYMBOL_VALUE (s) = svalue;
  552. s->set_type (parse_type (cur_fd, ax, sh->index, 0, bigend, name));
  553. add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  554. break;
  555. case stLabel: /* label, goes into current block. */
  556. s = new_symbol (name);
  557. s->set_domain (VAR_DOMAIN); /* So that it can be used */
  558. s->set_aclass_index (LOC_LABEL); /* but not misused. */
  559. SET_SYMBOL_VALUE_ADDRESS (s, (CORE_ADDR) sh->value);
  560. s->set_type (objfile_type (objfile)->builtin_int);
  561. add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  562. break;
  563. case stProc: /* Procedure, usually goes into global block. */
  564. case stStaticProc: /* Static procedure, goes into current block. */
  565. /* For stProc symbol records, we need to check the storage class
  566. as well, as only (stProc, scText) entries represent "real"
  567. procedures - See the Compaq document titled "Object File /
  568. Symbol Table Format Specification" for more information.
  569. If the storage class is not scText, we discard the whole block
  570. of symbol records for this stProc. */
  571. if (sh->st == stProc && sh->sc != scText)
  572. {
  573. char *ext_tsym = ext_sh;
  574. int keep_counting = 1;
  575. SYMR tsym;
  576. while (keep_counting)
  577. {
  578. ext_tsym += external_sym_size;
  579. (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
  580. count++;
  581. switch (tsym.st)
  582. {
  583. case stParam:
  584. break;
  585. case stEnd:
  586. keep_counting = 0;
  587. break;
  588. default:
  589. complaint (_("unknown symbol type 0x%x"), sh->st);
  590. break;
  591. }
  592. }
  593. break;
  594. }
  595. s = new_symbol (name);
  596. s->set_domain (VAR_DOMAIN);
  597. s->set_aclass_index (LOC_BLOCK);
  598. /* Type of the return value. */
  599. if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
  600. t = objfile_type (objfile)->builtin_int;
  601. else
  602. {
  603. t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
  604. if (strcmp (name, "malloc") == 0
  605. && t->code () == TYPE_CODE_VOID)
  606. {
  607. /* I don't know why, but, at least under Alpha GNU/Linux,
  608. when linking against a malloc without debugging
  609. symbols, its read as a function returning void---this
  610. is bad because it means we cannot call functions with
  611. string arguments interactively; i.e., "call
  612. printf("howdy\n")" would fail with the error message
  613. "program has no memory available". To avoid this, we
  614. patch up the type and make it void*
  615. instead. (davidm@azstarnet.com). */
  616. t = make_pointer_type (t, NULL);
  617. }
  618. }
  619. b = top_stack->cur_block;
  620. if (sh->st == stProc)
  621. {
  622. const struct blockvector *bv
  623. = top_stack->cur_st->compunit ()->blockvector ();
  624. /* The next test should normally be true, but provides a
  625. hook for nested functions (which we don't want to make
  626. global). */
  627. if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
  628. b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  629. /* Irix 5 sometimes has duplicate names for the same
  630. function. We want to add such names up at the global
  631. level, not as a nested function. */
  632. else if (sh->value == top_stack->procadr)
  633. b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  634. }
  635. add_symbol (s, top_stack->cur_st, b);
  636. /* Make a type for the procedure itself. */
  637. s->set_type (lookup_function_type (t));
  638. /* All functions in C++ have prototypes. For C we don't have enough
  639. information in the debug info. */
  640. if (s->language () == language_cplus)
  641. s->type ()->set_is_prototyped (true);
  642. /* Create and enter a new lexical context. */
  643. b = new_block (FUNCTION_BLOCK, s->language ());
  644. SYMBOL_BLOCK_VALUE (s) = b;
  645. BLOCK_FUNCTION (b) = s;
  646. BLOCK_START (b) = BLOCK_END (b) = sh->value;
  647. BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  648. add_block (b, top_stack->cur_st);
  649. /* Not if we only have partial info. */
  650. if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
  651. break;
  652. push_parse_stack ();
  653. top_stack->cur_block = b;
  654. top_stack->blocktype = sh->st;
  655. top_stack->cur_type = s->type ();
  656. top_stack->cur_field = -1;
  657. top_stack->procadr = sh->value;
  658. top_stack->numargs = 0;
  659. break;
  660. /* Beginning of code for structure, union, and enum definitions.
  661. They all share a common set of local variables, defined here. */
  662. {
  663. enum type_code type_code;
  664. char *ext_tsym;
  665. int nfields;
  666. long max_value;
  667. struct field *f;
  668. case stStruct: /* Start a block defining a struct type. */
  669. type_code = TYPE_CODE_STRUCT;
  670. goto structured_common;
  671. case stUnion: /* Start a block defining a union type. */
  672. type_code = TYPE_CODE_UNION;
  673. goto structured_common;
  674. case stEnum: /* Start a block defining an enum type. */
  675. type_code = TYPE_CODE_ENUM;
  676. goto structured_common;
  677. case stBlock: /* Either a lexical block, or some type. */
  678. if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
  679. goto case_stBlock_code; /* Lexical block */
  680. type_code = TYPE_CODE_UNDEF; /* We have a type. */
  681. /* Common code for handling struct, union, enum, and/or as-yet-
  682. unknown-type blocks of info about structured data. `type_code'
  683. has been set to the proper TYPE_CODE, if we know it. */
  684. structured_common:
  685. found_ecoff_debugging_info = 1;
  686. push_parse_stack ();
  687. top_stack->blocktype = stBlock;
  688. /* First count the number of fields and the highest value. */
  689. nfields = 0;
  690. max_value = 0;
  691. for (ext_tsym = ext_sh + external_sym_size;
  692. ;
  693. ext_tsym += external_sym_size)
  694. {
  695. SYMR tsym;
  696. (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
  697. switch (tsym.st)
  698. {
  699. case stEnd:
  700. /* C++ encodes class types as structures where there the
  701. methods are encoded as stProc. The scope of stProc
  702. symbols also ends with stEnd, thus creating a risk of
  703. taking the wrong stEnd symbol record as the end of
  704. the current struct, which would cause GDB to undercount
  705. the real number of fields in this struct. To make sure
  706. we really reached the right stEnd symbol record, we
  707. check the associated name, and match it against the
  708. struct name. Since method names are mangled while
  709. the class name is not, there is no risk of having a
  710. method whose name is identical to the class name
  711. (in particular constructor method names are different
  712. from the class name). There is therefore no risk that
  713. this check stops the count on the StEnd of a method.
  714. Also, assume that we're really at the end when tsym.iss
  715. is 0 (issNull). */
  716. if (tsym.iss == issNull
  717. || strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss,
  718. name) == 0)
  719. goto end_of_fields;
  720. break;
  721. case stMember:
  722. if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
  723. {
  724. /* If the type of the member is Nil (or Void),
  725. without qualifiers, assume the tag is an
  726. enumeration.
  727. Alpha cc -migrate enums are recognized by a zero
  728. index and a zero symbol value.
  729. DU 4.0 cc enums are recognized by a member type of
  730. btEnum without qualifiers and a zero symbol value. */
  731. if (tsym.index == indexNil
  732. || (tsym.index == 0 && sh->value == 0))
  733. type_code = TYPE_CODE_ENUM;
  734. else
  735. {
  736. (*debug_swap->swap_tir_in) (bigend,
  737. &ax[tsym.index].a_ti,
  738. &tir);
  739. if ((tir.bt == btNil || tir.bt == btVoid
  740. || (tir.bt == btEnum && sh->value == 0))
  741. && tir.tq0 == tqNil)
  742. type_code = TYPE_CODE_ENUM;
  743. }
  744. }
  745. nfields++;
  746. if (tsym.value > max_value)
  747. max_value = tsym.value;
  748. break;
  749. case stBlock:
  750. case stUnion:
  751. case stEnum:
  752. case stStruct:
  753. {
  754. #if 0
  755. /* This is a no-op; is it trying to tell us something
  756. we should be checking? */
  757. if (tsym.sc == scVariant); /*UNIMPLEMENTED */
  758. #endif
  759. if (tsym.index != 0)
  760. {
  761. /* This is something like a struct within a
  762. struct. Skip over the fields of the inner
  763. struct. The -1 is because the for loop will
  764. increment ext_tsym. */
  765. ext_tsym = ((char *) debug_info->external_sym
  766. + ((cur_fdr->isymBase + tsym.index - 1)
  767. * external_sym_size));
  768. }
  769. }
  770. break;
  771. case stTypedef:
  772. /* mips cc puts out a typedef for struct x if it is not yet
  773. defined when it encounters
  774. struct y { struct x *xp; };
  775. Just ignore it. */
  776. break;
  777. case stIndirect:
  778. /* Irix5 cc puts out a stIndirect for struct x if it is not
  779. yet defined when it encounters
  780. struct y { struct x *xp; };
  781. Just ignore it. */
  782. break;
  783. default:
  784. complaint (_("declaration block contains "
  785. "unhandled symbol type %d"),
  786. tsym.st);
  787. }
  788. }
  789. end_of_fields:
  790. /* In an stBlock, there is no way to distinguish structs,
  791. unions, and enums at this point. This is a bug in the
  792. original design (that has been fixed with the recent
  793. addition of the stStruct, stUnion, and stEnum symbol
  794. types.) The way you can tell is if/when you see a variable
  795. or field of that type. In that case the variable's type
  796. (in the AUX table) says if the type is struct, union, or
  797. enum, and points back to the stBlock here. So you can
  798. patch the tag kind up later - but only if there actually is
  799. a variable or field of that type.
  800. So until we know for sure, we will guess at this point.
  801. The heuristic is:
  802. If the first member has index==indexNil or a void type,
  803. assume we have an enumeration.
  804. Otherwise, if there is more than one member, and all
  805. the members have offset 0, assume we have a union.
  806. Otherwise, assume we have a struct.
  807. The heuristic could guess wrong in the case of of an
  808. enumeration with no members or a union with one (or zero)
  809. members, or when all except the last field of a struct have
  810. width zero. These are uncommon and/or illegal situations,
  811. and in any case guessing wrong probably doesn't matter
  812. much.
  813. But if we later do find out we were wrong, we fixup the tag
  814. kind. Members of an enumeration must be handled
  815. differently from struct/union fields, and that is harder to
  816. patch up, but luckily we shouldn't need to. (If there are
  817. any enumeration members, we can tell for sure it's an enum
  818. here.) */
  819. if (type_code == TYPE_CODE_UNDEF)
  820. {
  821. if (nfields > 1 && max_value == 0)
  822. type_code = TYPE_CODE_UNION;
  823. else
  824. type_code = TYPE_CODE_STRUCT;
  825. }
  826. /* Create a new type or use the pending type. */
  827. pend = is_pending_symbol (cur_fdr, ext_sh);
  828. if (pend == NULL)
  829. {
  830. t = new_type (NULL);
  831. add_pending (cur_fdr, ext_sh, t);
  832. }
  833. else
  834. t = pend->t;
  835. /* Do not set the tag name if it is a compiler generated tag name
  836. (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
  837. Alpha cc puts out an sh->iss of zero for those. */
  838. if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
  839. t->set_name (NULL);
  840. else
  841. t->set_name (obconcat (&mdebugread_objfile->objfile_obstack,
  842. name, (char *) NULL));
  843. t->set_code (type_code);
  844. TYPE_LENGTH (t) = sh->value;
  845. t->set_num_fields (nfields);
  846. f = ((struct field *) TYPE_ALLOC (t, nfields * sizeof (struct field)));
  847. t->set_fields (f);
  848. if (type_code == TYPE_CODE_ENUM)
  849. {
  850. int unsigned_enum = 1;
  851. /* This is a non-empty enum. */
  852. /* DEC c89 has the number of enumerators in the sh.value field,
  853. not the type length, so we have to compensate for that
  854. incompatibility quirk.
  855. This might do the wrong thing for an enum with one or two
  856. enumerators and gcc -gcoff -fshort-enums, but these cases
  857. are hopefully rare enough.
  858. Alpha cc -migrate has a sh.value field of zero, we adjust
  859. that too. */
  860. if (TYPE_LENGTH (t) == t->num_fields ()
  861. || TYPE_LENGTH (t) == 0)
  862. TYPE_LENGTH (t) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
  863. for (ext_tsym = ext_sh + external_sym_size;
  864. ;
  865. ext_tsym += external_sym_size)
  866. {
  867. SYMR tsym;
  868. struct symbol *enum_sym;
  869. (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
  870. if (tsym.st != stMember)
  871. break;
  872. f->set_loc_enumval (tsym.value);
  873. f->set_type (t);
  874. f->set_name (debug_info->ss + cur_fdr->issBase + tsym.iss);
  875. FIELD_BITSIZE (*f) = 0;
  876. enum_sym = new (&mdebugread_objfile->objfile_obstack) symbol;
  877. enum_sym->set_linkage_name
  878. (obstack_strdup (&mdebugread_objfile->objfile_obstack,
  879. f->name ()));
  880. enum_sym->set_aclass_index (LOC_CONST);
  881. enum_sym->set_type (t);
  882. enum_sym->set_domain (VAR_DOMAIN);
  883. SYMBOL_VALUE (enum_sym) = tsym.value;
  884. if (SYMBOL_VALUE (enum_sym) < 0)
  885. unsigned_enum = 0;
  886. add_symbol (enum_sym, top_stack->cur_st, top_stack->cur_block);
  887. /* Skip the stMembers that we've handled. */
  888. count++;
  889. f++;
  890. }
  891. if (unsigned_enum)
  892. t->set_is_unsigned (true);
  893. }
  894. /* Make this the current type. */
  895. top_stack->cur_type = t;
  896. top_stack->cur_field = 0;
  897. /* Do not create a symbol for alpha cc unnamed structs. */
  898. if (sh->iss == 0)
  899. break;
  900. /* gcc puts out an empty struct for an opaque struct definitions,
  901. do not create a symbol for it either. */
  902. if (t->num_fields () == 0)
  903. {
  904. t->set_is_stub (true);
  905. break;
  906. }
  907. s = new_symbol (name);
  908. s->set_domain (STRUCT_DOMAIN);
  909. s->set_aclass_index (LOC_TYPEDEF);
  910. SYMBOL_VALUE (s) = 0;
  911. s->set_type (t);
  912. add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  913. break;
  914. /* End of local variables shared by struct, union, enum, and
  915. block (as yet unknown struct/union/enum) processing. */
  916. }
  917. case_stBlock_code:
  918. found_ecoff_debugging_info = 1;
  919. /* Beginnning of (code) block. Value of symbol
  920. is the displacement from procedure start. */
  921. push_parse_stack ();
  922. /* Do not start a new block if this is the outermost block of a
  923. procedure. This allows the LOC_BLOCK symbol to point to the
  924. block with the local variables, so funcname::var works. */
  925. if (top_stack->blocktype == stProc
  926. || top_stack->blocktype == stStaticProc)
  927. {
  928. top_stack->blocktype = stNil;
  929. break;
  930. }
  931. top_stack->blocktype = stBlock;
  932. b = new_block (NON_FUNCTION_BLOCK, psymtab_language);
  933. BLOCK_START (b) = sh->value + top_stack->procadr;
  934. BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  935. top_stack->cur_block = b;
  936. add_block (b, top_stack->cur_st);
  937. break;
  938. case stEnd: /* end (of anything) */
  939. if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
  940. {
  941. /* Finished with type */
  942. top_stack->cur_type = 0;
  943. }
  944. else if (sh->sc == scText &&
  945. (top_stack->blocktype == stProc ||
  946. top_stack->blocktype == stStaticProc))
  947. {
  948. /* Finished with procedure */
  949. const struct blockvector *bv
  950. = top_stack->cur_st->compunit ()->blockvector ();
  951. struct mdebug_extra_func_info *e;
  952. struct block *cblock = top_stack->cur_block;
  953. struct type *ftype = top_stack->cur_type;
  954. int i;
  955. BLOCK_END (top_stack->cur_block) += sh->value; /* size */
  956. /* Make up special symbol to contain procedure specific info. */
  957. s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
  958. s->set_domain (LABEL_DOMAIN);
  959. s->set_aclass_index (LOC_CONST);
  960. s->set_type (objfile_type (mdebugread_objfile)->builtin_void);
  961. e = OBSTACK_ZALLOC (&mdebugread_objfile->objfile_obstack,
  962. mdebug_extra_func_info);
  963. SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
  964. e->numargs = top_stack->numargs;
  965. e->pdr.framereg = -1;
  966. add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  967. /* f77 emits proc-level with address bounds==[0,0],
  968. So look for such child blocks, and patch them. */
  969. for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
  970. {
  971. struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
  972. if (BLOCK_SUPERBLOCK (b_bad) == cblock
  973. && BLOCK_START (b_bad) == top_stack->procadr
  974. && BLOCK_END (b_bad) == top_stack->procadr)
  975. {
  976. BLOCK_START (b_bad) = BLOCK_START (cblock);
  977. BLOCK_END (b_bad) = BLOCK_END (cblock);
  978. }
  979. }
  980. if (ftype->num_fields () <= 0)
  981. {
  982. /* No parameter type information is recorded with the function's
  983. type. Set that from the type of the parameter symbols. */
  984. int nparams = top_stack->numargs;
  985. int iparams;
  986. struct symbol *sym;
  987. if (nparams > 0)
  988. {
  989. struct block_iterator iter;
  990. ftype->set_num_fields (nparams);
  991. ftype->set_fields
  992. ((struct field *)
  993. TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
  994. iparams = 0;
  995. ALL_BLOCK_SYMBOLS (cblock, iter, sym)
  996. {
  997. if (iparams == nparams)
  998. break;
  999. if (sym->is_argument ())
  1000. {
  1001. ftype->field (iparams).set_type (sym->type ());
  1002. TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
  1003. iparams++;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. else if (sh->sc == scText && top_stack->blocktype == stBlock)
  1010. {
  1011. /* End of (code) block. The value of the symbol is the
  1012. displacement from the procedure`s start address of the
  1013. end of this block. */
  1014. BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
  1015. }
  1016. else if (sh->sc == scText && top_stack->blocktype == stNil)
  1017. {
  1018. /* End of outermost block. Pop parse stack and ignore. The
  1019. following stEnd of stProc will take care of the block. */
  1020. ;
  1021. }
  1022. else if (sh->sc == scText && top_stack->blocktype == stFile)
  1023. {
  1024. /* End of file. Pop parse stack and ignore. Higher
  1025. level code deals with this. */
  1026. ;
  1027. }
  1028. else
  1029. complaint (_("stEnd with storage class %d not handled"), sh->sc);
  1030. pop_parse_stack (); /* Restore previous lexical context. */
  1031. break;
  1032. case stMember: /* member of struct or union */
  1033. {
  1034. struct field *f = &top_stack->cur_type->field (top_stack->cur_field);
  1035. top_stack->cur_field++;
  1036. f->set_name (name);
  1037. f->set_loc_bitpos (sh->value);
  1038. bitsize = 0;
  1039. f->set_type (parse_type (cur_fd, ax, sh->index, &bitsize, bigend,
  1040. name));
  1041. FIELD_BITSIZE (*f) = bitsize;
  1042. }
  1043. break;
  1044. case stIndirect: /* forward declaration on Irix5 */
  1045. /* Forward declarations from Irix5 cc are handled by cross_ref,
  1046. skip them. */
  1047. break;
  1048. case stTypedef: /* type definition */
  1049. found_ecoff_debugging_info = 1;
  1050. /* Typedefs for forward declarations and opaque structs from alpha cc
  1051. are handled by cross_ref, skip them. */
  1052. if (sh->iss == 0)
  1053. break;
  1054. /* Parse the type or use the pending type. */
  1055. pend = is_pending_symbol (cur_fdr, ext_sh);
  1056. if (pend == NULL)
  1057. {
  1058. t = parse_type (cur_fd, ax, sh->index, NULL, bigend, name);
  1059. add_pending (cur_fdr, ext_sh, t);
  1060. }
  1061. else
  1062. t = pend->t;
  1063. /* Mips cc puts out a typedef with the name of the struct for forward
  1064. declarations. These should not go into the symbol table and
  1065. TYPE_NAME should not be set for them.
  1066. They can't be distinguished from an intentional typedef to
  1067. the same name however:
  1068. x.h:
  1069. struct x { int ix; int jx; };
  1070. struct xx;
  1071. x.c:
  1072. typedef struct x x;
  1073. struct xx {int ixx; int jxx; };
  1074. generates a cross referencing stTypedef for x and xx.
  1075. The user visible effect of this is that the type of a pointer
  1076. to struct foo sometimes is given as `foo *' instead of `struct foo *'.
  1077. The problem is fixed with alpha cc and Irix5 cc. */
  1078. /* However if the typedef cross references to an opaque aggregate, it
  1079. is safe to omit it from the symbol table. */
  1080. if (has_opaque_xref (cur_fdr, sh))
  1081. break;
  1082. s = new_symbol (name);
  1083. s->set_domain (VAR_DOMAIN);
  1084. s->set_aclass_index (LOC_TYPEDEF);
  1085. SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
  1086. s->set_type (t);
  1087. add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  1088. /* Incomplete definitions of structs should not get a name. */
  1089. if (s->type ()->name () == NULL
  1090. && (s->type ()->num_fields () != 0
  1091. || (s->type ()->code () != TYPE_CODE_STRUCT
  1092. && s->type ()->code () != TYPE_CODE_UNION)))
  1093. {
  1094. if (s->type ()->code () == TYPE_CODE_PTR
  1095. || s->type ()->code () == TYPE_CODE_FUNC)
  1096. {
  1097. /* If we are giving a name to a type such as "pointer to
  1098. foo" or "function returning foo", we better not set
  1099. the TYPE_NAME. If the program contains "typedef char
  1100. *caddr_t;", we don't want all variables of type char
  1101. * to print as caddr_t. This is not just a
  1102. consequence of GDB's type management; CC and GCC (at
  1103. least through version 2.4) both output variables of
  1104. either type char * or caddr_t with the type
  1105. refering to the stTypedef symbol for caddr_t. If a future
  1106. compiler cleans this up it GDB is not ready for it
  1107. yet, but if it becomes ready we somehow need to
  1108. disable this check (without breaking the PCC/GCC2.4
  1109. case).
  1110. Sigh.
  1111. Fortunately, this check seems not to be necessary
  1112. for anything except pointers or functions. */
  1113. }
  1114. else
  1115. s->type ()->set_name (s->linkage_name ());
  1116. }
  1117. break;
  1118. case stFile: /* file name */
  1119. push_parse_stack ();
  1120. top_stack->blocktype = sh->st;
  1121. break;
  1122. /* I`ve never seen these for C */
  1123. case stRegReloc:
  1124. break; /* register relocation */
  1125. case stForward:
  1126. break; /* forwarding address */
  1127. case stConstant:
  1128. break; /* constant */
  1129. default:
  1130. complaint (_("unknown symbol type 0x%x"), sh->st);
  1131. break;
  1132. }
  1133. return count;
  1134. }
  1135. /* Basic types. */
  1136. static const struct objfile_key<struct type *,
  1137. gdb::noop_deleter<struct type *>>
  1138. basic_type_data;
  1139. static struct type *
  1140. basic_type (int bt, struct objfile *objfile)
  1141. {
  1142. struct gdbarch *gdbarch = objfile->arch ();
  1143. struct type **map_bt = basic_type_data.get (objfile);
  1144. struct type *tp;
  1145. if (bt >= btMax)
  1146. return NULL;
  1147. if (!map_bt)
  1148. {
  1149. map_bt = OBSTACK_CALLOC (&objfile->objfile_obstack,
  1150. btMax, struct type *);
  1151. basic_type_data.set (objfile, map_bt);
  1152. }
  1153. if (map_bt[bt])
  1154. return map_bt[bt];
  1155. switch (bt)
  1156. {
  1157. case btNil:
  1158. tp = objfile_type (objfile)->builtin_void;
  1159. break;
  1160. case btAdr:
  1161. tp = init_pointer_type (objfile, 32, "adr_32",
  1162. objfile_type (objfile)->builtin_void);
  1163. break;
  1164. case btChar:
  1165. tp = init_integer_type (objfile, 8, 0, "char");
  1166. tp->set_has_no_signedness (true);
  1167. break;
  1168. case btUChar:
  1169. tp = init_integer_type (objfile, 8, 1, "unsigned char");
  1170. break;
  1171. case btShort:
  1172. tp = init_integer_type (objfile, 16, 0, "short");
  1173. break;
  1174. case btUShort:
  1175. tp = init_integer_type (objfile, 16, 1, "unsigned short");
  1176. break;
  1177. case btInt:
  1178. tp = init_integer_type (objfile, 32, 0, "int");
  1179. break;
  1180. case btUInt:
  1181. tp = init_integer_type (objfile, 32, 1, "unsigned int");
  1182. break;
  1183. case btLong:
  1184. tp = init_integer_type (objfile, 32, 0, "long");
  1185. break;
  1186. case btULong:
  1187. tp = init_integer_type (objfile, 32, 1, "unsigned long");
  1188. break;
  1189. case btFloat:
  1190. tp = init_float_type (objfile, gdbarch_float_bit (gdbarch),
  1191. "float", gdbarch_float_format (gdbarch));
  1192. break;
  1193. case btDouble:
  1194. tp = init_float_type (objfile, gdbarch_double_bit (gdbarch),
  1195. "double", gdbarch_double_format (gdbarch));
  1196. break;
  1197. case btComplex:
  1198. tp = init_complex_type ("complex", basic_type (btFloat, objfile));
  1199. break;
  1200. case btDComplex:
  1201. tp = init_complex_type ("double complex", basic_type (btFloat, objfile));
  1202. break;
  1203. case btFixedDec:
  1204. /* We use TYPE_CODE_INT to print these as integers. Does this do any
  1205. good? Would we be better off with TYPE_CODE_ERROR? Should
  1206. TYPE_CODE_ERROR print things in hex if it knows the size? */
  1207. tp = init_integer_type (objfile, gdbarch_int_bit (gdbarch), 0,
  1208. "fixed decimal");
  1209. break;
  1210. case btFloatDec:
  1211. tp = init_type (objfile, TYPE_CODE_ERROR,
  1212. gdbarch_double_bit (gdbarch), "floating decimal");
  1213. break;
  1214. case btString:
  1215. /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
  1216. FIXME. */
  1217. tp = init_type (objfile, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
  1218. break;
  1219. case btVoid:
  1220. tp = objfile_type (objfile)->builtin_void;
  1221. break;
  1222. case btLong64:
  1223. tp = init_integer_type (objfile, 64, 0, "long");
  1224. break;
  1225. case btULong64:
  1226. tp = init_integer_type (objfile, 64, 1, "unsigned long");
  1227. break;
  1228. case btLongLong64:
  1229. tp = init_integer_type (objfile, 64, 0, "long long");
  1230. break;
  1231. case btULongLong64:
  1232. tp = init_integer_type (objfile, 64, 1, "unsigned long long");
  1233. break;
  1234. case btAdr64:
  1235. tp = init_pointer_type (objfile, 64, "adr_64",
  1236. objfile_type (objfile)->builtin_void);
  1237. break;
  1238. case btInt64:
  1239. tp = init_integer_type (objfile, 64, 0, "int");
  1240. break;
  1241. case btUInt64:
  1242. tp = init_integer_type (objfile, 64, 1, "unsigned int");
  1243. break;
  1244. default:
  1245. tp = NULL;
  1246. break;
  1247. }
  1248. map_bt[bt] = tp;
  1249. return tp;
  1250. }
  1251. /* Parse the type information provided in the raw AX entries for
  1252. the symbol SH. Return the bitfield size in BS, in case.
  1253. We must byte-swap the AX entries before we use them; BIGEND says whether
  1254. they are big-endian or little-endian (from fh->fBigendian). */
  1255. static struct type *
  1256. parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
  1257. int bigend, const char *sym_name)
  1258. {
  1259. TIR t[1];
  1260. struct type *tp = 0;
  1261. enum type_code type_code = TYPE_CODE_UNDEF;
  1262. /* Handle undefined types, they have indexNil. */
  1263. if (aux_index == indexNil)
  1264. return basic_type (btInt, mdebugread_objfile);
  1265. /* Handle corrupt aux indices. */
  1266. if (aux_index >= (debug_info->fdr + fd)->caux)
  1267. {
  1268. index_complaint (sym_name);
  1269. return basic_type (btInt, mdebugread_objfile);
  1270. }
  1271. ax += aux_index;
  1272. /* Use aux as a type information record, map its basic type. */
  1273. (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
  1274. tp = basic_type (t->bt, mdebugread_objfile);
  1275. if (tp == NULL)
  1276. {
  1277. /* Cannot use builtin types -- build our own. */
  1278. switch (t->bt)
  1279. {
  1280. case btStruct:
  1281. type_code = TYPE_CODE_STRUCT;
  1282. break;
  1283. case btUnion:
  1284. type_code = TYPE_CODE_UNION;
  1285. break;
  1286. case btEnum:
  1287. type_code = TYPE_CODE_ENUM;
  1288. break;
  1289. case btRange:
  1290. type_code = TYPE_CODE_RANGE;
  1291. break;
  1292. case btSet:
  1293. type_code = TYPE_CODE_SET;
  1294. break;
  1295. case btIndirect:
  1296. /* alpha cc -migrate uses this for typedefs. The true type will
  1297. be obtained by crossreferencing below. */
  1298. type_code = TYPE_CODE_ERROR;
  1299. break;
  1300. case btTypedef:
  1301. /* alpha cc uses this for typedefs. The true type will be
  1302. obtained by crossreferencing below. */
  1303. type_code = TYPE_CODE_ERROR;
  1304. break;
  1305. default:
  1306. basic_type_complaint (t->bt, sym_name);
  1307. return basic_type (btInt, mdebugread_objfile);
  1308. }
  1309. }
  1310. /* Move on to next aux. */
  1311. ax++;
  1312. if (t->fBitfield)
  1313. {
  1314. int width = AUX_GET_WIDTH (bigend, ax);
  1315. /* Inhibit core dumps if TIR is corrupted. */
  1316. if (bs == NULL)
  1317. {
  1318. /* Alpha cc -migrate encodes char and unsigned char types
  1319. as short and unsigned short types with a field width of 8.
  1320. Enum types also have a field width which we ignore for now. */
  1321. if (t->bt == btShort && width == 8)
  1322. tp = basic_type (btChar, mdebugread_objfile);
  1323. else if (t->bt == btUShort && width == 8)
  1324. tp = basic_type (btUChar, mdebugread_objfile);
  1325. else if (t->bt == btEnum)
  1326. ;
  1327. else
  1328. complaint (_("can't handle TIR fBitfield for %s"),
  1329. sym_name);
  1330. }
  1331. else
  1332. *bs = width;
  1333. ax++;
  1334. }
  1335. /* A btIndirect entry cross references to an aux entry containing
  1336. the type. */
  1337. if (t->bt == btIndirect)
  1338. {
  1339. RNDXR rn[1];
  1340. int rf;
  1341. FDR *xref_fh;
  1342. int xref_fd;
  1343. (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
  1344. ax++;
  1345. if (rn->rfd == 0xfff)
  1346. {
  1347. rf = AUX_GET_ISYM (bigend, ax);
  1348. ax++;
  1349. }
  1350. else
  1351. rf = rn->rfd;
  1352. if (rf == -1)
  1353. {
  1354. complaint (_("unable to cross ref btIndirect for %s"), sym_name);
  1355. return basic_type (btInt, mdebugread_objfile);
  1356. }
  1357. xref_fh = get_rfd (fd, rf);
  1358. xref_fd = xref_fh - debug_info->fdr;
  1359. tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
  1360. rn->index, NULL, xref_fh->fBigendian, sym_name);
  1361. }
  1362. /* All these types really point to some (common) MIPS type
  1363. definition, and only the type-qualifiers fully identify
  1364. them. We'll make the same effort at sharing. */
  1365. if (t->bt == btStruct ||
  1366. t->bt == btUnion ||
  1367. t->bt == btEnum ||
  1368. /* btSet (I think) implies that the name is a tag name, not a typedef
  1369. name. This apparently is a MIPS extension for C sets. */
  1370. t->bt == btSet)
  1371. {
  1372. const char *name;
  1373. /* Try to cross reference this type, build new type on failure. */
  1374. ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
  1375. if (tp == NULL)
  1376. tp = init_type (mdebugread_objfile, type_code, 0, NULL);
  1377. /* DEC c89 produces cross references to qualified aggregate types,
  1378. dereference them. */
  1379. while (tp->code () == TYPE_CODE_PTR
  1380. || tp->code () == TYPE_CODE_ARRAY)
  1381. tp = TYPE_TARGET_TYPE (tp);
  1382. /* Make sure that TYPE_CODE(tp) has an expected type code.
  1383. Any type may be returned from cross_ref if file indirect entries
  1384. are corrupted. */
  1385. if (tp->code () != TYPE_CODE_STRUCT
  1386. && tp->code () != TYPE_CODE_UNION
  1387. && tp->code () != TYPE_CODE_ENUM)
  1388. {
  1389. unexpected_type_code_complaint (sym_name);
  1390. }
  1391. else
  1392. {
  1393. /* Usually, TYPE_CODE(tp) is already type_code. The main
  1394. exception is if we guessed wrong re struct/union/enum.
  1395. But for struct vs. union a wrong guess is harmless, so
  1396. don't complain(). */
  1397. if ((tp->code () == TYPE_CODE_ENUM
  1398. && type_code != TYPE_CODE_ENUM)
  1399. || (tp->code () != TYPE_CODE_ENUM
  1400. && type_code == TYPE_CODE_ENUM))
  1401. {
  1402. bad_tag_guess_complaint (sym_name);
  1403. }
  1404. if (tp->code () != type_code)
  1405. {
  1406. tp->set_code (type_code);
  1407. }
  1408. /* Do not set the tag name if it is a compiler generated tag name
  1409. (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
  1410. if (name[0] == '.' || name[0] == '\0')
  1411. tp->set_name (NULL);
  1412. else if (tp->name () == NULL
  1413. || strcmp (tp->name (), name) != 0)
  1414. tp->set_name (obstack_strdup (&mdebugread_objfile->objfile_obstack,
  1415. name));
  1416. }
  1417. }
  1418. /* All these types really point to some (common) MIPS type
  1419. definition, and only the type-qualifiers fully identify
  1420. them. We'll make the same effort at sharing.
  1421. FIXME: We are not doing any guessing on range types. */
  1422. if (t->bt == btRange)
  1423. {
  1424. const char *name;
  1425. /* Try to cross reference this type, build new type on failure. */
  1426. ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
  1427. if (tp == NULL)
  1428. tp = init_type (mdebugread_objfile, type_code, 0, NULL);
  1429. /* Make sure that TYPE_CODE(tp) has an expected type code.
  1430. Any type may be returned from cross_ref if file indirect entries
  1431. are corrupted. */
  1432. if (tp->code () != TYPE_CODE_RANGE)
  1433. {
  1434. unexpected_type_code_complaint (sym_name);
  1435. }
  1436. else
  1437. {
  1438. /* Usually, TYPE_CODE(tp) is already type_code. The main
  1439. exception is if we guessed wrong re struct/union/enum. */
  1440. if (tp->code () != type_code)
  1441. {
  1442. bad_tag_guess_complaint (sym_name);
  1443. tp->set_code (type_code);
  1444. }
  1445. if (tp->name () == NULL
  1446. || strcmp (tp->name (), name) != 0)
  1447. tp->set_name (obstack_strdup (&mdebugread_objfile->objfile_obstack,
  1448. name));
  1449. }
  1450. }
  1451. if (t->bt == btTypedef)
  1452. {
  1453. const char *name;
  1454. /* Try to cross reference this type, it should succeed. */
  1455. ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
  1456. if (tp == NULL)
  1457. {
  1458. complaint (_("unable to cross ref btTypedef for %s"), sym_name);
  1459. tp = basic_type (btInt, mdebugread_objfile);
  1460. }
  1461. }
  1462. /* Deal with range types. */
  1463. if (t->bt == btRange)
  1464. {
  1465. tp->set_num_fields (0);
  1466. tp->set_bounds (((struct range_bounds *)
  1467. TYPE_ZALLOC (tp, sizeof (struct range_bounds))));
  1468. tp->bounds ()->low.set_const_val (AUX_GET_DNLOW (bigend, ax));
  1469. ax++;
  1470. tp->bounds ()->high.set_const_val (AUX_GET_DNHIGH (bigend, ax));
  1471. ax++;
  1472. }
  1473. /* Parse all the type qualifiers now. If there are more
  1474. than 6 the game will continue in the next aux. */
  1475. while (1)
  1476. {
  1477. #define PARSE_TQ(tq) \
  1478. if (t->tq != tqNil) \
  1479. ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
  1480. else \
  1481. break;
  1482. PARSE_TQ (tq0);
  1483. PARSE_TQ (tq1);
  1484. PARSE_TQ (tq2);
  1485. PARSE_TQ (tq3);
  1486. PARSE_TQ (tq4);
  1487. PARSE_TQ (tq5);
  1488. #undef PARSE_TQ
  1489. /* mips cc 2.x and gcc never put out continued aux entries. */
  1490. if (!t->continued)
  1491. break;
  1492. (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
  1493. ax++;
  1494. }
  1495. /* Complain for illegal continuations due to corrupt aux entries. */
  1496. if (t->continued)
  1497. complaint (_("illegal TIR continued for %s"), sym_name);
  1498. return tp;
  1499. }
  1500. /* Make up a complex type from a basic one. Type is passed by
  1501. reference in TPP and side-effected as necessary. The type
  1502. qualifier TQ says how to handle the aux symbols at AX for
  1503. the symbol SX we are currently analyzing. BIGEND says whether
  1504. aux symbols are big-endian or little-endian.
  1505. Returns the number of aux symbols we parsed. */
  1506. static int
  1507. upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
  1508. const char *sym_name)
  1509. {
  1510. int off;
  1511. struct type *t;
  1512. /* Used in array processing. */
  1513. int rf, id;
  1514. FDR *fh;
  1515. struct type *range;
  1516. struct type *indx;
  1517. int lower, upper;
  1518. RNDXR rndx;
  1519. switch (tq)
  1520. {
  1521. case tqPtr:
  1522. t = lookup_pointer_type (*tpp);
  1523. *tpp = t;
  1524. return 0;
  1525. case tqProc:
  1526. t = lookup_function_type (*tpp);
  1527. *tpp = t;
  1528. return 0;
  1529. case tqArray:
  1530. off = 0;
  1531. /* Determine and record the domain type (type of index). */
  1532. (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
  1533. id = rndx.index;
  1534. rf = rndx.rfd;
  1535. if (rf == 0xfff)
  1536. {
  1537. ax++;
  1538. rf = AUX_GET_ISYM (bigend, ax);
  1539. off++;
  1540. }
  1541. fh = get_rfd (fd, rf);
  1542. indx = parse_type (fh - debug_info->fdr,
  1543. debug_info->external_aux + fh->iauxBase,
  1544. id, NULL, bigend, sym_name);
  1545. /* The bounds type should be an integer type, but might be anything
  1546. else due to corrupt aux entries. */
  1547. if (indx->code () != TYPE_CODE_INT)
  1548. {
  1549. complaint (_("illegal array index type for %s, assuming int"),
  1550. sym_name);
  1551. indx = objfile_type (mdebugread_objfile)->builtin_int;
  1552. }
  1553. /* Get the bounds, and create the array type. */
  1554. ax++;
  1555. lower = AUX_GET_DNLOW (bigend, ax);
  1556. ax++;
  1557. upper = AUX_GET_DNHIGH (bigend, ax);
  1558. ax++;
  1559. rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
  1560. range = create_static_range_type (NULL, indx, lower, upper);
  1561. t = create_array_type (NULL, *tpp, range);
  1562. /* We used to fill in the supplied array element bitsize
  1563. here if the TYPE_LENGTH of the target type was zero.
  1564. This happens for a `pointer to an array of anonymous structs',
  1565. but in this case the array element bitsize is also zero,
  1566. so nothing is gained.
  1567. And we used to check the TYPE_LENGTH of the target type against
  1568. the supplied array element bitsize.
  1569. gcc causes a mismatch for `pointer to array of object',
  1570. since the sdb directives it uses do not have a way of
  1571. specifying the bitsize, but it does no harm (the
  1572. TYPE_LENGTH should be correct) and we should be able to
  1573. ignore the erroneous bitsize from the auxiliary entry safely.
  1574. dbx seems to ignore it too. */
  1575. /* TYPE_TARGET_STUB now takes care of the zero TYPE_LENGTH problem. */
  1576. if (TYPE_LENGTH (*tpp) == 0)
  1577. t->set_target_is_stub (true);
  1578. *tpp = t;
  1579. return 4 + off;
  1580. case tqVol:
  1581. /* Volatile -- currently ignored */
  1582. return 0;
  1583. case tqConst:
  1584. /* Const -- currently ignored */
  1585. return 0;
  1586. default:
  1587. complaint (_("unknown type qualifier 0x%x"), tq);
  1588. return 0;
  1589. }
  1590. }
  1591. /* Parse a procedure descriptor record PR. Note that the procedure is
  1592. parsed _after_ the local symbols, now we just insert the extra
  1593. information we need into a MDEBUG_EFI_SYMBOL_NAME symbol that has
  1594. already been placed in the procedure's main block. Note also that
  1595. images that have been partially stripped (ld -x) have been deprived
  1596. of local symbols, and we have to cope with them here. FIRST_OFF is
  1597. the offset of the first procedure for this FDR; we adjust the
  1598. address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
  1599. to look for the function which contains the MDEBUG_EFI_SYMBOL_NAME symbol
  1600. in question, or NULL to use top_stack->cur_block. */
  1601. static void
  1602. parse_procedure (PDR *pr, struct compunit_symtab *search_symtab,
  1603. legacy_psymtab *pst)
  1604. {
  1605. struct symbol *s, *i;
  1606. const struct block *b;
  1607. char *sh_name;
  1608. /* Simple rule to find files linked "-x". */
  1609. if (cur_fdr->rss == -1)
  1610. {
  1611. if (pr->isym == -1)
  1612. {
  1613. /* Static procedure at address pr->adr. Sigh. */
  1614. /* FIXME-32x64. assuming pr->adr fits in long. */
  1615. complaint (_("can't handle PDR for static proc at 0x%lx"),
  1616. (unsigned long) pr->adr);
  1617. return;
  1618. }
  1619. else
  1620. {
  1621. /* external */
  1622. EXTR she;
  1623. (*debug_swap->swap_ext_in) (cur_bfd,
  1624. ((char *) debug_info->external_ext
  1625. + (pr->isym
  1626. * debug_swap->external_ext_size)),
  1627. &she);
  1628. sh_name = debug_info->ssext + she.asym.iss;
  1629. }
  1630. }
  1631. else
  1632. {
  1633. /* Full symbols */
  1634. SYMR sh;
  1635. (*debug_swap->swap_sym_in) (cur_bfd,
  1636. ((char *) debug_info->external_sym
  1637. + ((cur_fdr->isymBase + pr->isym)
  1638. * debug_swap->external_sym_size)),
  1639. &sh);
  1640. sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
  1641. }
  1642. if (search_symtab != NULL)
  1643. {
  1644. #if 0
  1645. /* This loses both in the case mentioned (want a static, find a global),
  1646. but also if we are looking up a non-mangled name which happens to
  1647. match the name of a mangled function. */
  1648. /* We have to save the cur_fdr across the call to lookup_symbol.
  1649. If the pdr is for a static function and if a global function with
  1650. the same name exists, lookup_symbol will eventually read in the symtab
  1651. for the global function and clobber cur_fdr. */
  1652. FDR *save_cur_fdr = cur_fdr;
  1653. s = lookup_symbol (sh_name, NULL, VAR_DOMAIN, 0);
  1654. cur_fdr = save_cur_fdr;
  1655. #else
  1656. s = mylookup_symbol
  1657. (sh_name,
  1658. BLOCKVECTOR_BLOCK (search_symtab->blockvector (),
  1659. STATIC_BLOCK),
  1660. VAR_DOMAIN,
  1661. LOC_BLOCK);
  1662. #endif
  1663. }
  1664. else
  1665. s = mylookup_symbol (sh_name, top_stack->cur_block,
  1666. VAR_DOMAIN, LOC_BLOCK);
  1667. if (s != 0)
  1668. {
  1669. b = SYMBOL_BLOCK_VALUE (s);
  1670. }
  1671. else
  1672. {
  1673. complaint (_("PDR for %s, but no symbol"), sh_name);
  1674. #if 1
  1675. return;
  1676. #else
  1677. /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
  1678. s = new_symbol (sh_name);
  1679. s->set_domain (VAR_DOMAIN);
  1680. SYMBOL_CLASS (s) = LOC_BLOCK;
  1681. /* Don't know its type, hope int is ok. */
  1682. s->type ()
  1683. = lookup_function_type (objfile_type (pst->objfile)->builtin_int);
  1684. add_symbol (s, top_stack->cur_st, top_stack->cur_block);
  1685. /* Won't have symbols for this one. */
  1686. b = new_block (2);
  1687. SYMBOL_BLOCK_VALUE (s) = b;
  1688. BLOCK_FUNCTION (b) = s;
  1689. BLOCK_START (b) = pr->adr;
  1690. /* BOUND used to be the end of procedure's text, but the
  1691. argument is no longer passed in. */
  1692. BLOCK_END (b) = bound;
  1693. BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
  1694. add_block (b, top_stack->cur_st);
  1695. #endif
  1696. }
  1697. i = mylookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, LOC_CONST);
  1698. if (i)
  1699. {
  1700. struct mdebug_extra_func_info *e;
  1701. e = (struct mdebug_extra_func_info *) SYMBOL_VALUE_BYTES (i);
  1702. e->pdr = *pr;
  1703. /* GDB expects the absolute function start address for the
  1704. procedure descriptor in e->pdr.adr.
  1705. As the address in the procedure descriptor is usually relative,
  1706. we would have to relocate e->pdr.adr with cur_fdr->adr.
  1707. Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
  1708. in shared libraries on some systems, and on other systems
  1709. e->pdr.adr is sometimes offset by a bogus value.
  1710. To work around these problems, we replace e->pdr.adr with
  1711. the start address of the function. */
  1712. e->pdr.adr = BLOCK_START (b);
  1713. }
  1714. /* It would be reasonable that functions that have been compiled
  1715. without debugging info have a btNil type for their return value,
  1716. and functions that are void and are compiled with debugging info
  1717. have btVoid.
  1718. gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
  1719. to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
  1720. case right.
  1721. The glevel field in cur_fdr could be used to determine the presence
  1722. of debugging info, but GCC doesn't always pass the -g switch settings
  1723. to the assembler and GAS doesn't set the glevel field from the -g switch
  1724. settings.
  1725. To work around these problems, the return value type of a TYPE_CODE_VOID
  1726. function is adjusted accordingly if no debugging info was found in the
  1727. compilation unit. */
  1728. if (processing_gcc_compilation == 0
  1729. && found_ecoff_debugging_info == 0
  1730. && TYPE_TARGET_TYPE (s->type ())->code () == TYPE_CODE_VOID)
  1731. s->set_type (objfile_type (mdebugread_objfile)->nodebug_text_symbol);
  1732. }
  1733. /* Parse the external symbol ES. Just call parse_symbol() after
  1734. making sure we know where the aux are for it.
  1735. BIGEND says whether aux entries are big-endian or little-endian.
  1736. This routine clobbers top_stack->cur_block and ->cur_st. */
  1737. static void
  1738. parse_external (EXTR *es, int bigend, const section_offsets &section_offsets,
  1739. struct objfile *objfile)
  1740. {
  1741. union aux_ext *ax;
  1742. if (es->ifd != ifdNil)
  1743. {
  1744. cur_fd = es->ifd;
  1745. cur_fdr = debug_info->fdr + cur_fd;
  1746. ax = debug_info->external_aux + cur_fdr->iauxBase;
  1747. }
  1748. else
  1749. {
  1750. cur_fdr = debug_info->fdr;
  1751. ax = 0;
  1752. }
  1753. /* Reading .o files */
  1754. if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
  1755. {
  1756. const char *what;
  1757. switch (es->asym.st)
  1758. {
  1759. case stNil:
  1760. /* These are generated for static symbols in .o files,
  1761. ignore them. */
  1762. return;
  1763. case stStaticProc:
  1764. case stProc:
  1765. what = "procedure";
  1766. n_undef_procs++;
  1767. break;
  1768. case stGlobal:
  1769. what = "variable";
  1770. n_undef_vars++;
  1771. break;
  1772. case stLabel:
  1773. what = "label";
  1774. n_undef_labels++;
  1775. break;
  1776. default:
  1777. what = "symbol";
  1778. break;
  1779. }
  1780. n_undef_symbols++;
  1781. /* FIXME: Turn this into a complaint? */
  1782. if (info_verbose)
  1783. gdb_printf (_("Warning: %s `%s' is undefined (in %s)\n"),
  1784. what, debug_info->ssext + es->asym.iss,
  1785. fdr_name (cur_fdr));
  1786. return;
  1787. }
  1788. switch (es->asym.st)
  1789. {
  1790. case stProc:
  1791. case stStaticProc:
  1792. /* There is no need to parse the external procedure symbols.
  1793. If they are from objects compiled without -g, their index will
  1794. be indexNil, and the symbol definition from the minimal symbol
  1795. is preferrable (yielding a function returning int instead of int).
  1796. If the index points to a local procedure symbol, the local
  1797. symbol already provides the correct type.
  1798. Note that the index of the external procedure symbol points
  1799. to the local procedure symbol in the local symbol table, and
  1800. _not_ to the auxiliary symbol info. */
  1801. break;
  1802. case stGlobal:
  1803. case stLabel:
  1804. /* Global common symbols are resolved by the runtime loader,
  1805. ignore them. */
  1806. if (SC_IS_COMMON (es->asym.sc))
  1807. break;
  1808. /* Note that the case of a symbol with indexNil must be handled
  1809. anyways by parse_symbol(). */
  1810. parse_symbol (&es->asym, ax, NULL,
  1811. bigend, section_offsets, objfile);
  1812. break;
  1813. default:
  1814. break;
  1815. }
  1816. }
  1817. /* Parse the line number info for file descriptor FH into
  1818. GDB's linetable LT. MIPS' encoding requires a little bit
  1819. of magic to get things out. Note also that MIPS' line
  1820. numbers can go back and forth, apparently we can live
  1821. with that and do not need to reorder our linetables. */
  1822. static void
  1823. parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
  1824. CORE_ADDR textlow, CORE_ADDR lowest_pdr_addr)
  1825. {
  1826. unsigned char *base;
  1827. int j, k;
  1828. int delta, count, lineno = 0;
  1829. if (fh->cbLine == 0)
  1830. return;
  1831. /* Scan by procedure descriptors. */
  1832. k = 0;
  1833. for (j = 0; j < fh->cpd; j++, pr++)
  1834. {
  1835. CORE_ADDR l;
  1836. CORE_ADDR adr;
  1837. unsigned char *halt;
  1838. /* No code for this one. */
  1839. if (pr->iline == ilineNil ||
  1840. pr->lnLow == -1 || pr->lnHigh == -1)
  1841. continue;
  1842. /* Determine start and end address of compressed line bytes for
  1843. this procedure. */
  1844. base = debug_info->line + fh->cbLineOffset;
  1845. if (j != (fh->cpd - 1))
  1846. halt = base + pr[1].cbLineOffset;
  1847. else
  1848. halt = base + fh->cbLine;
  1849. base += pr->cbLineOffset;
  1850. adr = textlow + pr->adr - lowest_pdr_addr;
  1851. l = adr >> 2; /* in words */
  1852. for (lineno = pr->lnLow; base < halt;)
  1853. {
  1854. count = *base & 0x0f;
  1855. delta = *base++ >> 4;
  1856. if (delta >= 8)
  1857. delta -= 16;
  1858. if (delta == -8)
  1859. {
  1860. delta = (base[0] << 8) | base[1];
  1861. if (delta >= 0x8000)
  1862. delta -= 0x10000;
  1863. base += 2;
  1864. }
  1865. lineno += delta; /* first delta is 0 */
  1866. /* Complain if the line table overflows. Could happen
  1867. with corrupt binaries. */
  1868. if (lt->nitems >= maxlines)
  1869. {
  1870. complaint (_("guessed size of linetable for %s incorrectly"),
  1871. fdr_name (fh));
  1872. break;
  1873. }
  1874. k = add_line (lt, lineno, l, k);
  1875. l += count + 1;
  1876. }
  1877. }
  1878. }
  1879. static void
  1880. function_outside_compilation_unit_complaint (const char *arg1)
  1881. {
  1882. complaint (_("function `%s' appears to be defined "
  1883. "outside of all compilation units"),
  1884. arg1);
  1885. }
  1886. /* Use the STORAGE_CLASS to compute which section the given symbol
  1887. belongs to, and then records this new minimal symbol. */
  1888. static void
  1889. record_minimal_symbol (minimal_symbol_reader &reader,
  1890. const char *name, const CORE_ADDR address,
  1891. enum minimal_symbol_type ms_type, int storage_class,
  1892. struct objfile *objfile)
  1893. {
  1894. int section;
  1895. switch (storage_class)
  1896. {
  1897. case scText:
  1898. section = SECT_OFF_TEXT (objfile);
  1899. break;
  1900. case scData:
  1901. section = SECT_OFF_DATA (objfile);
  1902. break;
  1903. case scBss:
  1904. section = SECT_OFF_BSS (objfile);
  1905. break;
  1906. case scSData:
  1907. section = get_section_index (objfile, ".sdata");
  1908. break;
  1909. case scSBss:
  1910. section = get_section_index (objfile, ".sbss");
  1911. break;
  1912. case scRData:
  1913. section = get_section_index (objfile, ".rdata");
  1914. break;
  1915. case scInit:
  1916. section = get_section_index (objfile, ".init");
  1917. break;
  1918. case scXData:
  1919. section = get_section_index (objfile, ".xdata");
  1920. break;
  1921. case scPData:
  1922. section = get_section_index (objfile, ".pdata");
  1923. break;
  1924. case scFini:
  1925. section = get_section_index (objfile, ".fini");
  1926. break;
  1927. case scRConst:
  1928. section = get_section_index (objfile, ".rconst");
  1929. break;
  1930. #ifdef scTlsData
  1931. case scTlsData:
  1932. section = get_section_index (objfile, ".tlsdata");
  1933. break;
  1934. #endif
  1935. #ifdef scTlsBss
  1936. case scTlsBss:
  1937. section = get_section_index (objfile, ".tlsbss");
  1938. break;
  1939. #endif
  1940. default:
  1941. /* This kind of symbol is not associated to a section. */
  1942. section = -1;
  1943. }
  1944. reader.record_with_info (name, address, ms_type, section);
  1945. }
  1946. /* Master parsing procedure for first-pass reading of file symbols
  1947. into a partial_symtab. */
  1948. static void
  1949. parse_partial_symbols (minimal_symbol_reader &reader,
  1950. psymtab_storage *partial_symtabs,
  1951. struct objfile *objfile)
  1952. {
  1953. struct gdbarch *gdbarch = objfile->arch ();
  1954. const bfd_size_type external_sym_size = debug_swap->external_sym_size;
  1955. const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
  1956. const bfd_size_type external_ext_size = debug_swap->external_ext_size;
  1957. void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in;
  1958. void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
  1959. void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in;
  1960. int f_idx, s_idx;
  1961. HDRR *hdr = &debug_info->symbolic_header;
  1962. /* Running pointers */
  1963. FDR *fh;
  1964. char *ext_out;
  1965. char *ext_out_end;
  1966. EXTR *ext_in;
  1967. EXTR *ext_in_end;
  1968. SYMR sh;
  1969. legacy_psymtab *pst;
  1970. int textlow_not_set = 1;
  1971. /* List of current psymtab's include files. */
  1972. const char **psymtab_include_list;
  1973. int includes_allocated;
  1974. int includes_used;
  1975. EXTR *extern_tab;
  1976. struct pst_map *fdr_to_pst;
  1977. /* Index within current psymtab dependency list. */
  1978. legacy_psymtab **dependency_list;
  1979. int dependencies_used, dependencies_allocated;
  1980. char *name;
  1981. enum language prev_language;
  1982. asection *text_sect;
  1983. int relocatable = 0;
  1984. /* Irix 5.2 shared libraries have a fh->adr field of zero, but
  1985. the shared libraries are prelinked at a high memory address.
  1986. We have to adjust the start address of the object file for this case,
  1987. by setting it to the start address of the first procedure in the file.
  1988. But we should do no adjustments if we are debugging a .o file, where
  1989. the text section (and fh->adr) really starts at zero. */
  1990. text_sect = bfd_get_section_by_name (cur_bfd, ".text");
  1991. if (text_sect != NULL
  1992. && (bfd_section_flags (text_sect) & SEC_RELOC))
  1993. relocatable = 1;
  1994. extern_tab = XOBNEWVEC (&objfile->objfile_obstack, EXTR, hdr->iextMax);
  1995. includes_allocated = 30;
  1996. includes_used = 0;
  1997. psymtab_include_list = (const char **) alloca (includes_allocated *
  1998. sizeof (const char *));
  1999. next_symbol_text_func = mdebug_next_symbol_text;
  2000. dependencies_allocated = 30;
  2001. dependencies_used = 0;
  2002. dependency_list =
  2003. (legacy_psymtab **) alloca (dependencies_allocated *
  2004. sizeof (legacy_psymtab *));
  2005. set_last_source_file (NULL);
  2006. /*
  2007. * Big plan:
  2008. *
  2009. * Only parse the Local and External symbols, and the Relative FDR.
  2010. * Fixup enough of the loader symtab to be able to use it.
  2011. * Allocate space only for the file's portions we need to
  2012. * look at. (XXX)
  2013. */
  2014. max_gdbinfo = 0;
  2015. max_glevel = MIN_GLEVEL;
  2016. /* Allocate the map FDR -> PST.
  2017. Minor hack: -O3 images might claim some global data belongs
  2018. to FDR -1. We`ll go along with that. */
  2019. std::vector<struct pst_map> fdr_to_pst_holder (hdr->ifdMax + 1);
  2020. fdr_to_pst = fdr_to_pst_holder.data ();
  2021. fdr_to_pst++;
  2022. {
  2023. legacy_psymtab *new_pst = new_psymtab ("", partial_symtabs, objfile);
  2024. fdr_to_pst[-1].pst = new_pst;
  2025. FDR_IDX (new_pst) = -1;
  2026. }
  2027. /* Allocate the global pending list. */
  2028. pending_list = XOBNEWVEC (&objfile->objfile_obstack, mdebug_pending *,
  2029. hdr->ifdMax);
  2030. memset (pending_list, 0,
  2031. hdr->ifdMax * sizeof (struct mdebug_pending *));
  2032. /* Pass 0 over external syms: swap them in. */
  2033. gdb::def_vector<EXTR> ext_block (hdr->iextMax);
  2034. ext_out = (char *) debug_info->external_ext;
  2035. ext_out_end = ext_out + hdr->iextMax * external_ext_size;
  2036. ext_in = ext_block.data ();
  2037. for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
  2038. (*swap_ext_in) (cur_bfd, ext_out, ext_in);
  2039. /* Pass 1 over external syms: Presize and partition the list. */
  2040. ext_in = ext_block.data ();
  2041. ext_in_end = ext_in + hdr->iextMax;
  2042. for (; ext_in < ext_in_end; ext_in++)
  2043. {
  2044. /* See calls to complain below. */
  2045. if (ext_in->ifd >= -1
  2046. && ext_in->ifd < hdr->ifdMax
  2047. && ext_in->asym.iss >= 0
  2048. && ext_in->asym.iss < hdr->issExtMax)
  2049. fdr_to_pst[ext_in->ifd].n_globals++;
  2050. }
  2051. /* Pass 1.5 over files: partition out global symbol space. */
  2052. s_idx = 0;
  2053. for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
  2054. {
  2055. fdr_to_pst[f_idx].globals_offset = s_idx;
  2056. s_idx += fdr_to_pst[f_idx].n_globals;
  2057. fdr_to_pst[f_idx].n_globals = 0;
  2058. }
  2059. /* ECOFF in ELF:
  2060. For ECOFF in ELF, we skip the creation of the minimal symbols.
  2061. The ECOFF symbols should be a subset of the Elf symbols, and the
  2062. section information of the elf symbols will be more accurate.
  2063. FIXME! What about Irix 5's native linker?
  2064. By default, Elf sections which don't exist in ECOFF
  2065. get put in ECOFF's absolute section by the gnu linker.
  2066. Since absolute sections don't get relocated, we
  2067. end up calculating an address different from that of
  2068. the symbol's minimal symbol (created earlier from the
  2069. Elf symtab).
  2070. To fix this, either :
  2071. 1) don't create the duplicate symbol
  2072. (assumes ECOFF symtab is a subset of the ELF symtab;
  2073. assumes no side-effects result from ignoring ECOFF symbol)
  2074. 2) create it, only if lookup for existing symbol in ELF's minimal
  2075. symbols fails
  2076. (inefficient;
  2077. assumes no side-effects result from ignoring ECOFF symbol)
  2078. 3) create it, but lookup ELF's minimal symbol and use it's section
  2079. during relocation, then modify "uniquify" phase to merge and
  2080. eliminate the duplicate symbol
  2081. (highly inefficient)
  2082. I've implemented #1 here...
  2083. Skip the creation of the minimal symbols based on the ECOFF
  2084. symbol table. */
  2085. /* Pass 2 over external syms: fill in external symbols. */
  2086. ext_in = ext_block.data ();
  2087. ext_in_end = ext_in + hdr->iextMax;
  2088. for (; ext_in < ext_in_end; ext_in++)
  2089. {
  2090. enum minimal_symbol_type ms_type = mst_text;
  2091. CORE_ADDR svalue = ext_in->asym.value;
  2092. /* The Irix 5 native tools seem to sometimes generate bogus
  2093. external symbols. */
  2094. if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
  2095. {
  2096. complaint (_("bad ifd for external symbol: %d (max %ld)"),
  2097. ext_in->ifd, hdr->ifdMax);
  2098. continue;
  2099. }
  2100. if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
  2101. {
  2102. complaint (_("bad iss for external symbol: %ld (max %ld)"),
  2103. ext_in->asym.iss, hdr->issExtMax);
  2104. continue;
  2105. }
  2106. extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
  2107. + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
  2108. if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
  2109. continue;
  2110. /* Pass 3 over files, over local syms: fill in static symbols. */
  2111. name = debug_info->ssext + ext_in->asym.iss;
  2112. /* Process ECOFF Symbol Types and Storage Classes. */
  2113. switch (ext_in->asym.st)
  2114. {
  2115. case stProc:
  2116. /* Beginnning of Procedure */
  2117. break;
  2118. case stStaticProc:
  2119. /* Load time only static procs */
  2120. ms_type = mst_file_text;
  2121. break;
  2122. case stGlobal:
  2123. /* External symbol */
  2124. if (SC_IS_COMMON (ext_in->asym.sc))
  2125. {
  2126. /* The value of a common symbol is its size, not its address.
  2127. Ignore it. */
  2128. continue;
  2129. }
  2130. else if (SC_IS_DATA (ext_in->asym.sc))
  2131. {
  2132. ms_type = mst_data;
  2133. }
  2134. else if (SC_IS_BSS (ext_in->asym.sc))
  2135. {
  2136. ms_type = mst_bss;
  2137. }
  2138. else if (SC_IS_SBSS (ext_in->asym.sc))
  2139. {
  2140. ms_type = mst_bss;
  2141. }
  2142. else
  2143. ms_type = mst_abs;
  2144. break;
  2145. case stLabel:
  2146. /* Label */
  2147. /* On certain platforms, some extra label symbols can be
  2148. generated by the linker. One possible usage for this kind
  2149. of symbols is to represent the address of the begining of a
  2150. given section. For instance, on Tru64 5.1, the address of
  2151. the _ftext label is the start address of the .text section.
  2152. The storage class of these symbols is usually directly
  2153. related to the section to which the symbol refers. For
  2154. instance, on Tru64 5.1, the storage class for the _fdata
  2155. label is scData, refering to the .data section.
  2156. It is actually possible that the section associated to the
  2157. storage class of the label does not exist. On True64 5.1
  2158. for instance, the libm.so shared library does not contain
  2159. any .data section, although it contains a _fpdata label
  2160. which storage class is scData... Since these symbols are
  2161. usually useless for the debugger user anyway, we just
  2162. discard these symbols. */
  2163. if (SC_IS_TEXT (ext_in->asym.sc))
  2164. {
  2165. if (objfile->sect_index_text == -1)
  2166. continue;
  2167. ms_type = mst_file_text;
  2168. }
  2169. else if (SC_IS_DATA (ext_in->asym.sc))
  2170. {
  2171. if (objfile->sect_index_data == -1)
  2172. continue;
  2173. ms_type = mst_file_data;
  2174. }
  2175. else if (SC_IS_BSS (ext_in->asym.sc))
  2176. {
  2177. if (objfile->sect_index_bss == -1)
  2178. continue;
  2179. ms_type = mst_file_bss;
  2180. }
  2181. else if (SC_IS_SBSS (ext_in->asym.sc))
  2182. {
  2183. const int sbss_sect_index = get_section_index (objfile, ".sbss");
  2184. if (sbss_sect_index == -1)
  2185. continue;
  2186. ms_type = mst_file_bss;
  2187. }
  2188. else
  2189. ms_type = mst_abs;
  2190. break;
  2191. case stLocal:
  2192. case stNil:
  2193. /* The alpha has the section start addresses in stLocal symbols
  2194. whose name starts with a `.'. Skip those but complain for all
  2195. other stLocal symbols.
  2196. Irix6 puts the section start addresses in stNil symbols, skip
  2197. those too. */
  2198. if (name[0] == '.')
  2199. continue;
  2200. /* Fall through. */
  2201. default:
  2202. ms_type = mst_unknown;
  2203. unknown_ext_complaint (name);
  2204. }
  2205. if (!ECOFF_IN_ELF (cur_bfd))
  2206. record_minimal_symbol (reader, name, svalue, ms_type, ext_in->asym.sc,
  2207. objfile);
  2208. }
  2209. /* Pass 3 over files, over local syms: fill in static symbols. */
  2210. for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
  2211. {
  2212. legacy_psymtab *save_pst;
  2213. EXTR *ext_ptr;
  2214. CORE_ADDR textlow;
  2215. cur_fdr = fh = debug_info->fdr + f_idx;
  2216. if (fh->csym == 0)
  2217. {
  2218. fdr_to_pst[f_idx].pst = NULL;
  2219. continue;
  2220. }
  2221. /* Determine the start address for this object file from the
  2222. file header and relocate it, except for Irix 5.2 zero fh->adr. */
  2223. if (fh->cpd)
  2224. textlow = fh->adr;
  2225. else
  2226. textlow = 0;
  2227. pst = new legacy_psymtab (fdr_name (fh), partial_symtabs,
  2228. objfile->per_bfd, textlow);
  2229. pst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, symloc);
  2230. memset (pst->read_symtab_private, 0, sizeof (struct symloc));
  2231. save_pst = pst;
  2232. FDR_IDX (pst) = f_idx;
  2233. CUR_BFD (pst) = cur_bfd;
  2234. DEBUG_SWAP (pst) = debug_swap;
  2235. DEBUG_INFO (pst) = debug_info;
  2236. PENDING_LIST (pst) = pending_list;
  2237. /* The way to turn this into a symtab is to call... */
  2238. pst->legacy_read_symtab = mdebug_read_symtab;
  2239. pst->legacy_expand_psymtab = mdebug_expand_psymtab;
  2240. /* Set up language for the pst.
  2241. The language from the FDR is used if it is unambigious (e.g. cfront
  2242. with native cc and g++ will set the language to C).
  2243. Otherwise we have to deduce the language from the filename.
  2244. Native ecoff has every header file in a separate FDR, so
  2245. deduce_language_from_filename will return language_unknown for
  2246. a header file, which is not what we want.
  2247. But the FDRs for the header files are after the FDR for the source
  2248. file, so we can assign the language of the source file to the
  2249. following header files. Then we save the language in the private
  2250. pst data so that we can reuse it when building symtabs. */
  2251. prev_language = psymtab_language;
  2252. switch (fh->lang)
  2253. {
  2254. case langCplusplusV2:
  2255. psymtab_language = language_cplus;
  2256. break;
  2257. default:
  2258. psymtab_language = deduce_language_from_filename (fdr_name (fh));
  2259. break;
  2260. }
  2261. if (psymtab_language == language_unknown)
  2262. psymtab_language = prev_language;
  2263. PST_PRIVATE (pst)->pst_language = psymtab_language;
  2264. pst->set_text_high (pst->raw_text_low ());
  2265. /* For stabs-in-ecoff files, the second symbol must be @stab.
  2266. This symbol is emitted by mips-tfile to signal that the
  2267. current object file uses encapsulated stabs instead of mips
  2268. ecoff for local symbols. (It is the second symbol because
  2269. the first symbol is the stFile used to signal the start of a
  2270. file). */
  2271. processing_gcc_compilation = 0;
  2272. if (fh->csym >= 2)
  2273. {
  2274. (*swap_sym_in) (cur_bfd,
  2275. ((char *) debug_info->external_sym
  2276. + (fh->isymBase + 1) * external_sym_size),
  2277. &sh);
  2278. if (strcmp (debug_info->ss + fh->issBase + sh.iss,
  2279. stabs_symbol) == 0)
  2280. processing_gcc_compilation = 2;
  2281. }
  2282. if (processing_gcc_compilation != 0)
  2283. {
  2284. for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
  2285. {
  2286. int type_code;
  2287. const char *namestring;
  2288. (*swap_sym_in) (cur_bfd,
  2289. (((char *) debug_info->external_sym)
  2290. + (fh->isymBase + cur_sdx) * external_sym_size),
  2291. &sh);
  2292. type_code = ECOFF_UNMARK_STAB (sh.index);
  2293. if (!ECOFF_IS_STAB (&sh))
  2294. {
  2295. if (sh.st == stProc || sh.st == stStaticProc)
  2296. {
  2297. CORE_ADDR procaddr;
  2298. long isym;
  2299. if (sh.st == stStaticProc)
  2300. {
  2301. namestring = debug_info->ss + fh->issBase + sh.iss;
  2302. record_minimal_symbol (reader, namestring, sh.value,
  2303. mst_file_text, sh.sc,
  2304. objfile);
  2305. }
  2306. procaddr = sh.value;
  2307. isym = AUX_GET_ISYM (fh->fBigendian,
  2308. (debug_info->external_aux
  2309. + fh->iauxBase
  2310. + sh.index));
  2311. (*swap_sym_in) (cur_bfd,
  2312. ((char *) debug_info->external_sym
  2313. + ((fh->isymBase + isym - 1)
  2314. * external_sym_size)),
  2315. &sh);
  2316. if (sh.st == stEnd)
  2317. {
  2318. CORE_ADDR high = procaddr + sh.value;
  2319. /* Kludge for Irix 5.2 zero fh->adr. */
  2320. if (!relocatable
  2321. && (!pst->text_low_valid
  2322. || procaddr < pst->raw_text_low ()))
  2323. pst->set_text_low (procaddr);
  2324. if (high > pst->raw_text_high ())
  2325. pst->set_text_high (high);
  2326. }
  2327. }
  2328. else if (sh.st == stStatic)
  2329. {
  2330. switch (sh.sc)
  2331. {
  2332. case scUndefined:
  2333. case scSUndefined:
  2334. case scNil:
  2335. case scAbs:
  2336. break;
  2337. case scData:
  2338. case scSData:
  2339. case scRData:
  2340. case scPData:
  2341. case scXData:
  2342. namestring = debug_info->ss + fh->issBase + sh.iss;
  2343. record_minimal_symbol (reader, namestring, sh.value,
  2344. mst_file_data, sh.sc,
  2345. objfile);
  2346. break;
  2347. default:
  2348. /* FIXME! Shouldn't this use cases for bss,
  2349. then have the default be abs? */
  2350. namestring = debug_info->ss + fh->issBase + sh.iss;
  2351. record_minimal_symbol (reader, namestring, sh.value,
  2352. mst_file_bss, sh.sc,
  2353. objfile);
  2354. break;
  2355. }
  2356. }
  2357. continue;
  2358. }
  2359. /* Handle stabs continuation. */
  2360. {
  2361. char *stabstring = debug_info->ss + fh->issBase + sh.iss;
  2362. /* If we need to heap-allocate STABSTRING, this owns
  2363. it. */
  2364. gdb::unique_xmalloc_ptr<char> stabstring_storage;
  2365. int len = strlen (stabstring);
  2366. while (stabstring[len - 1] == '\\')
  2367. {
  2368. SYMR sh2;
  2369. char *stabstring1 = stabstring;
  2370. char *stabstring2;
  2371. int len2;
  2372. /* Ignore continuation char from 1st string. */
  2373. len--;
  2374. /* Read next stabstring. */
  2375. cur_sdx++;
  2376. (*swap_sym_in) (cur_bfd,
  2377. (((char *) debug_info->external_sym)
  2378. + (fh->isymBase + cur_sdx)
  2379. * external_sym_size),
  2380. &sh2);
  2381. stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
  2382. len2 = strlen (stabstring2);
  2383. /* Concatenate stabstring2 with stabstring1. */
  2384. if (stabstring_storage != nullptr)
  2385. {
  2386. stabstring_storage.reset
  2387. ((char *) xrealloc (stabstring_storage.release (),
  2388. len + len2 + 1));
  2389. stabstring = stabstring_storage.get ();
  2390. }
  2391. else
  2392. {
  2393. stabstring_storage.reset
  2394. ((char *) xmalloc (len + len2 + 1));
  2395. stabstring = stabstring_storage.get ();
  2396. strcpy (stabstring, stabstring1);
  2397. }
  2398. strcpy (stabstring + len, stabstring2);
  2399. len += len2;
  2400. }
  2401. switch (type_code)
  2402. {
  2403. const char *p;
  2404. /* Standard, external, non-debugger, symbols. */
  2405. case N_TEXT | N_EXT:
  2406. case N_NBTEXT | N_EXT:
  2407. goto record_it;
  2408. case N_DATA | N_EXT:
  2409. case N_NBDATA | N_EXT:
  2410. goto record_it;
  2411. case N_BSS:
  2412. case N_BSS | N_EXT:
  2413. case N_NBBSS | N_EXT:
  2414. case N_SETV | N_EXT: /* FIXME, is this in BSS? */
  2415. goto record_it;
  2416. case N_ABS | N_EXT:
  2417. record_it:
  2418. continue;
  2419. /* Standard, local, non-debugger, symbols. */
  2420. case N_NBTEXT:
  2421. /* We need to be able to deal with both N_FN or
  2422. N_TEXT, because we have no way of knowing
  2423. whether the sys-supplied ld or GNU ld was used
  2424. to make the executable. Sequents throw in
  2425. another wrinkle -- they renumbered N_FN. */
  2426. case N_FN:
  2427. case N_FN_SEQ:
  2428. case N_TEXT:
  2429. continue;
  2430. case N_DATA:
  2431. goto record_it;
  2432. case N_UNDF | N_EXT:
  2433. continue; /* Just undefined, not COMMON. */
  2434. case N_UNDF:
  2435. continue;
  2436. /* Lots of symbol types we can just ignore. */
  2437. case N_ABS:
  2438. case N_NBDATA:
  2439. case N_NBBSS:
  2440. continue;
  2441. /* Keep going . . . */
  2442. /*
  2443. * Special symbol types for GNU
  2444. */
  2445. case N_INDR:
  2446. case N_INDR | N_EXT:
  2447. case N_SETA:
  2448. case N_SETA | N_EXT:
  2449. case N_SETT:
  2450. case N_SETT | N_EXT:
  2451. case N_SETD:
  2452. case N_SETD | N_EXT:
  2453. case N_SETB:
  2454. case N_SETB | N_EXT:
  2455. case N_SETV:
  2456. continue;
  2457. /*
  2458. * Debugger symbols
  2459. */
  2460. case N_SO:
  2461. {
  2462. static int prev_so_symnum = -10;
  2463. const char *basename;
  2464. /* A zero value is probably an indication for the
  2465. SunPRO 3.0 compiler. dbx_end_psymtab explicitly tests
  2466. for zero, so don't relocate it. */
  2467. if (sh.value == 0
  2468. && gdbarch_sofun_address_maybe_missing (gdbarch))
  2469. textlow_not_set = 1;
  2470. else
  2471. textlow_not_set = 0;
  2472. if (prev_so_symnum != symnum - 1)
  2473. { /* Here if prev stab wasn't N_SO. */
  2474. if (pst)
  2475. {
  2476. pst = (legacy_psymtab *) 0;
  2477. includes_used = 0;
  2478. dependencies_used = 0;
  2479. }
  2480. }
  2481. prev_so_symnum = symnum;
  2482. /* End the current partial symtab and start a
  2483. new one. */
  2484. /* SET_NAMESTRING ();*/
  2485. namestring = stabstring;
  2486. /* Null name means end of .o file. Don't start a new
  2487. one. */
  2488. if (*namestring == '\000')
  2489. continue;
  2490. /* Some compilers (including gcc) emit a pair of
  2491. initial N_SOs. The first one is a directory name;
  2492. the second the file name. If pst exists, is
  2493. empty, and has a filename ending in '/', we assume
  2494. the previous N_SO was a directory name. */
  2495. basename = lbasename (namestring);
  2496. if (basename != namestring && *basename == '\000')
  2497. continue; /* Simply ignore directory
  2498. name SOs. */
  2499. /* Some other compilers (C++ ones in particular) emit
  2500. useless SOs for non-existant .c files. We ignore
  2501. all subsequent SOs that immediately follow the
  2502. first. */
  2503. if (!pst)
  2504. pst = save_pst;
  2505. continue;
  2506. }
  2507. case N_BINCL:
  2508. continue;
  2509. case N_SOL:
  2510. {
  2511. enum language tmp_language;
  2512. /* Mark down an include file in the current psymtab. */
  2513. /* SET_NAMESTRING (); */
  2514. namestring = stabstring;
  2515. tmp_language
  2516. = deduce_language_from_filename (namestring);
  2517. /* Only change the psymtab's language if we've
  2518. learned something useful (eg. tmp_language is not
  2519. language_unknown). In addition, to match what
  2520. start_subfile does, never change from C++ to
  2521. C. */
  2522. if (tmp_language != language_unknown
  2523. && (tmp_language != language_c
  2524. || psymtab_language != language_cplus))
  2525. psymtab_language = tmp_language;
  2526. /* In C++, one may expect the same filename to come
  2527. round many times, when code is coming alternately
  2528. from the main file and from inline functions in
  2529. other files. So I check to see if this is a file
  2530. we've seen before -- either the main source file,
  2531. or a previously included file.
  2532. This seems to be a lot of time to be spending on
  2533. N_SOL, but things like "break c-exp.y:435" need to
  2534. work (I suppose the psymtab_include_list could be
  2535. hashed or put in a binary tree, if profiling shows
  2536. this is a major hog). */
  2537. if (pst && filename_cmp (namestring, pst->filename) == 0)
  2538. continue;
  2539. {
  2540. int i;
  2541. for (i = 0; i < includes_used; i++)
  2542. if (filename_cmp (namestring,
  2543. psymtab_include_list[i]) == 0)
  2544. {
  2545. i = -1;
  2546. break;
  2547. }
  2548. if (i == -1)
  2549. continue;
  2550. }
  2551. psymtab_include_list[includes_used++] = namestring;
  2552. if (includes_used >= includes_allocated)
  2553. {
  2554. const char **orig = psymtab_include_list;
  2555. psymtab_include_list = (const char **)
  2556. alloca ((includes_allocated *= 2) *
  2557. sizeof (const char *));
  2558. memcpy (psymtab_include_list, orig,
  2559. includes_used * sizeof (const char *));
  2560. }
  2561. continue;
  2562. }
  2563. case N_LSYM: /* Typedef or automatic variable. */
  2564. case N_STSYM: /* Data seg var -- static */
  2565. case N_LCSYM: /* BSS " */
  2566. case N_ROSYM: /* Read-only data seg var -- static. */
  2567. case N_NBSTS: /* Gould nobase. */
  2568. case N_NBLCS: /* symbols. */
  2569. case N_FUN:
  2570. case N_GSYM: /* Global (extern) variable; can be
  2571. data or bss (sigh FIXME). */
  2572. /* Following may probably be ignored; I'll leave them here
  2573. for now (until I do Pascal and Modula 2 extensions). */
  2574. case N_PC: /* I may or may not need this; I
  2575. suspect not. */
  2576. case N_M2C: /* I suspect that I can ignore this
  2577. here. */
  2578. case N_SCOPE: /* Same. */
  2579. /* SET_NAMESTRING (); */
  2580. namestring = stabstring;
  2581. p = (char *) strchr (namestring, ':');
  2582. if (!p)
  2583. continue; /* Not a debugging symbol. */
  2584. /* Main processing section for debugging symbols which
  2585. the initial read through the symbol tables needs to
  2586. worry about. If we reach this point, the symbol
  2587. which we are considering is definitely one we are
  2588. interested in. p must also contain the (valid)
  2589. index into the namestring which indicates the
  2590. debugging type symbol. */
  2591. switch (p[1])
  2592. {
  2593. case 'S':
  2594. pst->add_psymbol (gdb::string_view (namestring,
  2595. p - namestring),
  2596. true, VAR_DOMAIN, LOC_STATIC,
  2597. SECT_OFF_DATA (objfile),
  2598. psymbol_placement::STATIC,
  2599. sh.value,
  2600. psymtab_language,
  2601. partial_symtabs, objfile);
  2602. continue;
  2603. case 'G':
  2604. /* The addresses in these entries are reported
  2605. to be wrong. See the code that reads 'G's
  2606. for symtabs. */
  2607. pst->add_psymbol (gdb::string_view (namestring,
  2608. p - namestring),
  2609. true, VAR_DOMAIN, LOC_STATIC,
  2610. SECT_OFF_DATA (objfile),
  2611. psymbol_placement::GLOBAL,
  2612. sh.value,
  2613. psymtab_language,
  2614. partial_symtabs, objfile);
  2615. continue;
  2616. case 'T':
  2617. /* When a 'T' entry is defining an anonymous enum, it
  2618. may have a name which is the empty string, or a
  2619. single space. Since they're not really defining a
  2620. symbol, those shouldn't go in the partial symbol
  2621. table. We do pick up the elements of such enums at
  2622. 'check_enum:', below. */
  2623. if (p >= namestring + 2
  2624. || (p == namestring + 1
  2625. && namestring[0] != ' '))
  2626. {
  2627. pst->add_psymbol
  2628. (gdb::string_view (namestring, p - namestring),
  2629. true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
  2630. psymbol_placement::STATIC, 0, psymtab_language,
  2631. partial_symtabs, objfile);
  2632. if (p[2] == 't')
  2633. {
  2634. /* Also a typedef with the same name. */
  2635. pst->add_psymbol
  2636. (gdb::string_view (namestring,
  2637. p - namestring),
  2638. true, VAR_DOMAIN, LOC_TYPEDEF, -1,
  2639. psymbol_placement::STATIC, 0,
  2640. psymtab_language,
  2641. partial_symtabs, objfile);
  2642. p += 1;
  2643. }
  2644. }
  2645. goto check_enum;
  2646. case 't':
  2647. if (p != namestring) /* a name is there, not
  2648. just :T... */
  2649. {
  2650. pst->add_psymbol
  2651. (gdb::string_view (namestring,
  2652. p - namestring),
  2653. true, VAR_DOMAIN, LOC_TYPEDEF, -1,
  2654. psymbol_placement::STATIC, 0, psymtab_language,
  2655. partial_symtabs, objfile);
  2656. }
  2657. check_enum:
  2658. /* If this is an enumerated type, we need to add
  2659. all the enum constants to the partial symbol
  2660. table. This does not cover enums without names,
  2661. e.g. "enum {a, b} c;" in C, but fortunately
  2662. those are rare. There is no way for GDB to find
  2663. those from the enum type without spending too
  2664. much time on it. Thus to solve this problem,
  2665. the compiler needs to put out the enum in a
  2666. nameless type. GCC2 does this. */
  2667. /* We are looking for something of the form
  2668. <name> ":" ("t" | "T") [<number> "="] "e"
  2669. {<constant> ":" <value> ","} ";". */
  2670. /* Skip over the colon and the 't' or 'T'. */
  2671. p += 2;
  2672. /* This type may be given a number. Also, numbers
  2673. can come in pairs like (0,26). Skip over it. */
  2674. while ((*p >= '0' && *p <= '9')
  2675. || *p == '(' || *p == ',' || *p == ')'
  2676. || *p == '=')
  2677. p++;
  2678. if (*p++ == 'e')
  2679. {
  2680. /* The aix4 compiler emits extra crud before
  2681. the members. */
  2682. if (*p == '-')
  2683. {
  2684. /* Skip over the type (?). */
  2685. while (*p != ':')
  2686. p++;
  2687. /* Skip over the colon. */
  2688. p++;
  2689. }
  2690. /* We have found an enumerated type. */
  2691. /* According to comments in read_enum_type
  2692. a comma could end it instead of a semicolon.
  2693. I don't know where that happens.
  2694. Accept either. */
  2695. while (*p && *p != ';' && *p != ',')
  2696. {
  2697. const char *q;
  2698. /* Check for and handle cretinous dbx
  2699. symbol name continuation! */
  2700. if (*p == '\\' || (*p == '?' && p[1] == '\0'))
  2701. p = next_symbol_text (objfile);
  2702. /* Point to the character after the name
  2703. of the enum constant. */
  2704. for (q = p; *q && *q != ':'; q++)
  2705. ;
  2706. /* Note that the value doesn't matter for
  2707. enum constants in psymtabs, just in
  2708. symtabs. */
  2709. pst->add_psymbol (gdb::string_view (p,
  2710. q - p),
  2711. true, VAR_DOMAIN,
  2712. LOC_CONST, -1,
  2713. psymbol_placement::STATIC,
  2714. 0, psymtab_language,
  2715. partial_symtabs, objfile);
  2716. /* Point past the name. */
  2717. p = q;
  2718. /* Skip over the value. */
  2719. while (*p && *p != ',')
  2720. p++;
  2721. /* Advance past the comma. */
  2722. if (*p)
  2723. p++;
  2724. }
  2725. }
  2726. continue;
  2727. case 'c':
  2728. /* Constant, e.g. from "const" in Pascal. */
  2729. pst->add_psymbol (gdb::string_view (namestring,
  2730. p - namestring),
  2731. true, VAR_DOMAIN, LOC_CONST, -1,
  2732. psymbol_placement::STATIC,
  2733. 0, psymtab_language,
  2734. partial_symtabs, objfile);
  2735. continue;
  2736. case 'f':
  2737. if (! pst)
  2738. {
  2739. std::string copy (namestring, p);
  2740. function_outside_compilation_unit_complaint
  2741. (copy.c_str ());
  2742. }
  2743. pst->add_psymbol (gdb::string_view (namestring,
  2744. p - namestring),
  2745. true, VAR_DOMAIN, LOC_BLOCK,
  2746. SECT_OFF_TEXT (objfile),
  2747. psymbol_placement::STATIC,
  2748. sh.value,
  2749. psymtab_language,
  2750. partial_symtabs, objfile);
  2751. continue;
  2752. /* Global functions were ignored here, but now they
  2753. are put into the global psymtab like one would
  2754. expect. They're also in the minimal symbol
  2755. table. */
  2756. case 'F':
  2757. if (! pst)
  2758. {
  2759. std::string copy (namestring, p);
  2760. function_outside_compilation_unit_complaint
  2761. (copy.c_str ());
  2762. }
  2763. pst->add_psymbol (gdb::string_view (namestring,
  2764. p - namestring),
  2765. true, VAR_DOMAIN, LOC_BLOCK,
  2766. SECT_OFF_TEXT (objfile),
  2767. psymbol_placement::GLOBAL,
  2768. sh.value,
  2769. psymtab_language,
  2770. partial_symtabs, objfile);
  2771. continue;
  2772. /* Two things show up here (hopefully); static
  2773. symbols of local scope (static used inside
  2774. braces) or extensions of structure symbols. We
  2775. can ignore both. */
  2776. case 'V':
  2777. case '(':
  2778. case '0':
  2779. case '1':
  2780. case '2':
  2781. case '3':
  2782. case '4':
  2783. case '5':
  2784. case '6':
  2785. case '7':
  2786. case '8':
  2787. case '9':
  2788. case '-':
  2789. case '#': /* For symbol identification (used
  2790. in live ranges). */
  2791. continue;
  2792. case ':':
  2793. /* It is a C++ nested symbol. We don't need to
  2794. record it (I don't think); if we try to look up
  2795. foo::bar::baz, then symbols for the symtab
  2796. containing foo should get read in, I think. */
  2797. /* Someone says sun cc puts out symbols like
  2798. /foo/baz/maclib::/usr/local/bin/maclib,
  2799. which would get here with a symbol type of ':'. */
  2800. continue;
  2801. default:
  2802. /* Unexpected symbol descriptor. The second and
  2803. subsequent stabs of a continued stab can show up
  2804. here. The question is whether they ever can
  2805. mimic a normal stab--it would be nice if not,
  2806. since we certainly don't want to spend the time
  2807. searching to the end of every string looking for
  2808. a backslash. */
  2809. complaint (_("unknown symbol descriptor `%c'"), p[1]);
  2810. /* Ignore it; perhaps it is an extension that we don't
  2811. know about. */
  2812. continue;
  2813. }
  2814. case N_EXCL:
  2815. continue;
  2816. case N_ENDM:
  2817. /* Solaris 2 end of module, finish current partial
  2818. symbol table. dbx_end_psymtab will set the
  2819. high text address of PST to the proper value,
  2820. which is necessary if a module compiled without
  2821. debugging info follows this module. */
  2822. if (pst
  2823. && gdbarch_sofun_address_maybe_missing (gdbarch))
  2824. {
  2825. pst = (legacy_psymtab *) 0;
  2826. includes_used = 0;
  2827. dependencies_used = 0;
  2828. }
  2829. continue;
  2830. case N_RBRAC:
  2831. if (sh.value > save_pst->raw_text_high ())
  2832. save_pst->set_text_high (sh.value);
  2833. continue;
  2834. case N_EINCL:
  2835. case N_DSLINE:
  2836. case N_BSLINE:
  2837. case N_SSYM: /* Claim: Structure or union
  2838. element. Hopefully, I can
  2839. ignore this. */
  2840. case N_ENTRY: /* Alternate entry point; can
  2841. ignore. */
  2842. case N_MAIN: /* Can definitely ignore this. */
  2843. case N_CATCH: /* These are GNU C++ extensions. */
  2844. case N_EHDECL: /* that can safely be ignored here. */
  2845. case N_LENG:
  2846. case N_BCOMM:
  2847. case N_ECOMM:
  2848. case N_ECOML:
  2849. case N_FNAME:
  2850. case N_SLINE:
  2851. case N_RSYM:
  2852. case N_PSYM:
  2853. case N_LBRAC:
  2854. case N_NSYMS: /* Ultrix 4.0: symbol count */
  2855. case N_DEFD: /* GNU Modula-2 */
  2856. case N_ALIAS: /* SunPro F77: alias name, ignore
  2857. for now. */
  2858. case N_OBJ: /* Useless types from Solaris. */
  2859. case N_OPT:
  2860. /* These symbols aren't interesting; don't worry about
  2861. them. */
  2862. continue;
  2863. default:
  2864. /* If we haven't found it yet, ignore it. It's
  2865. probably some new type we don't know about yet. */
  2866. complaint (_("unknown symbol type %s"),
  2867. hex_string (type_code)); /* CUR_SYMBOL_TYPE */
  2868. continue;
  2869. }
  2870. }
  2871. /* end - Handle continuation */
  2872. }
  2873. }
  2874. else
  2875. {
  2876. for (cur_sdx = 0; cur_sdx < fh->csym;)
  2877. {
  2878. char *sym_name;
  2879. enum address_class theclass;
  2880. CORE_ADDR minsym_value;
  2881. short section = -1;
  2882. (*swap_sym_in) (cur_bfd,
  2883. ((char *) debug_info->external_sym
  2884. + ((fh->isymBase + cur_sdx)
  2885. * external_sym_size)),
  2886. &sh);
  2887. if (ECOFF_IS_STAB (&sh))
  2888. {
  2889. cur_sdx++;
  2890. continue;
  2891. }
  2892. /* Non absolute static symbols go into the minimal table. */
  2893. if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
  2894. || (sh.index == indexNil
  2895. && (sh.st != stStatic || sh.sc == scAbs)))
  2896. {
  2897. /* FIXME, premature? */
  2898. cur_sdx++;
  2899. continue;
  2900. }
  2901. sym_name = debug_info->ss + fh->issBase + sh.iss;
  2902. minsym_value = sh.value;
  2903. switch (sh.sc)
  2904. {
  2905. case scText:
  2906. case scRConst:
  2907. /* The value of a stEnd symbol is the displacement from the
  2908. corresponding start symbol value, do not relocate it. */
  2909. if (sh.st != stEnd)
  2910. section = SECT_OFF_TEXT (objfile);
  2911. break;
  2912. case scData:
  2913. case scSData:
  2914. case scRData:
  2915. case scPData:
  2916. case scXData:
  2917. section = SECT_OFF_DATA (objfile);
  2918. break;
  2919. case scBss:
  2920. case scSBss:
  2921. section = SECT_OFF_BSS (objfile);
  2922. break;
  2923. }
  2924. switch (sh.st)
  2925. {
  2926. CORE_ADDR high;
  2927. CORE_ADDR procaddr;
  2928. int new_sdx;
  2929. case stStaticProc:
  2930. reader.record_with_info (sym_name, minsym_value,
  2931. mst_file_text,
  2932. SECT_OFF_TEXT (objfile));
  2933. /* FALLTHROUGH */
  2934. case stProc:
  2935. /* Ignore all parameter symbol records. */
  2936. if (sh.index >= hdr->iauxMax)
  2937. {
  2938. /* Should not happen, but does when cross-compiling
  2939. with the MIPS compiler. FIXME -- pull later. */
  2940. index_complaint (sym_name);
  2941. new_sdx = cur_sdx + 1; /* Don't skip at all. */
  2942. }
  2943. else
  2944. new_sdx = AUX_GET_ISYM (fh->fBigendian,
  2945. (debug_info->external_aux
  2946. + fh->iauxBase
  2947. + sh.index));
  2948. if (new_sdx <= cur_sdx)
  2949. {
  2950. /* This should not happen either... FIXME. */
  2951. complaint (_("bad proc end in aux found from symbol %s"),
  2952. sym_name);
  2953. new_sdx = cur_sdx + 1; /* Don't skip backward. */
  2954. }
  2955. /* For stProc symbol records, we need to check the
  2956. storage class as well, as only (stProc, scText)
  2957. entries represent "real" procedures - See the
  2958. Compaq document titled "Object File / Symbol Table
  2959. Format Specification" for more information. If the
  2960. storage class is not scText, we discard the whole
  2961. block of symbol records for this stProc. */
  2962. if (sh.st == stProc && sh.sc != scText)
  2963. goto skip;
  2964. /* Usually there is a local and a global stProc symbol
  2965. for a function. This means that the function name
  2966. has already been entered into the minimal symbol table
  2967. while processing the global symbols in pass 2 above.
  2968. One notable exception is the PROGRAM name from
  2969. f77 compiled executables, it is only put out as
  2970. local stProc symbol, and a global MAIN__ stProc symbol
  2971. points to it. It doesn't matter though, as gdb is
  2972. still able to find the PROGRAM name via the partial
  2973. symbol table, and the MAIN__ symbol via the minimal
  2974. symbol table. */
  2975. if (sh.st == stProc)
  2976. pst->add_psymbol (sym_name, true,
  2977. VAR_DOMAIN, LOC_BLOCK,
  2978. section,
  2979. psymbol_placement::GLOBAL,
  2980. sh.value, psymtab_language,
  2981. partial_symtabs, objfile);
  2982. else
  2983. pst->add_psymbol (sym_name, true,
  2984. VAR_DOMAIN, LOC_BLOCK,
  2985. section,
  2986. psymbol_placement::STATIC,
  2987. sh.value, psymtab_language,
  2988. partial_symtabs, objfile);
  2989. procaddr = sh.value;
  2990. cur_sdx = new_sdx;
  2991. (*swap_sym_in) (cur_bfd,
  2992. ((char *) debug_info->external_sym
  2993. + ((fh->isymBase + cur_sdx - 1)
  2994. * external_sym_size)),
  2995. &sh);
  2996. if (sh.st != stEnd)
  2997. continue;
  2998. /* Kludge for Irix 5.2 zero fh->adr. */
  2999. if (!relocatable
  3000. && (!pst->text_low_valid
  3001. || procaddr < pst->raw_text_low ()))
  3002. pst->set_text_low (procaddr);
  3003. high = procaddr + sh.value;
  3004. if (high > pst->raw_text_high ())
  3005. pst->set_text_high (high);
  3006. continue;
  3007. case stStatic: /* Variable */
  3008. if (SC_IS_DATA (sh.sc))
  3009. reader.record_with_info (sym_name, minsym_value,
  3010. mst_file_data,
  3011. SECT_OFF_DATA (objfile));
  3012. else
  3013. reader.record_with_info (sym_name, minsym_value,
  3014. mst_file_bss,
  3015. SECT_OFF_BSS (objfile));
  3016. theclass = LOC_STATIC;
  3017. break;
  3018. case stIndirect: /* Irix5 forward declaration */
  3019. /* Skip forward declarations from Irix5 cc. */
  3020. goto skip;
  3021. case stTypedef: /* Typedef */
  3022. /* Skip typedefs for forward declarations and opaque
  3023. structs from alpha and mips cc. */
  3024. if (sh.iss == 0 || has_opaque_xref (fh, &sh))
  3025. goto skip;
  3026. theclass = LOC_TYPEDEF;
  3027. break;
  3028. case stConstant: /* Constant decl */
  3029. theclass = LOC_CONST;
  3030. break;
  3031. case stUnion:
  3032. case stStruct:
  3033. case stEnum:
  3034. case stBlock: /* { }, str, un, enum */
  3035. /* Do not create a partial symbol for cc unnamed aggregates
  3036. and gcc empty aggregates. */
  3037. if ((sh.sc == scInfo
  3038. || SC_IS_COMMON (sh.sc))
  3039. && sh.iss != 0
  3040. && sh.index != cur_sdx + 2)
  3041. {
  3042. pst->add_psymbol (sym_name, true,
  3043. STRUCT_DOMAIN, LOC_TYPEDEF, -1,
  3044. psymbol_placement::STATIC,
  3045. 0, psymtab_language,
  3046. partial_symtabs, objfile);
  3047. }
  3048. handle_psymbol_enumerators (objfile, partial_symtabs,
  3049. pst, fh, sh.st, sh.value);
  3050. /* Skip over the block. */
  3051. new_sdx = sh.index;
  3052. if (new_sdx <= cur_sdx)
  3053. {
  3054. /* This happens with the Ultrix kernel. */
  3055. complaint (_("bad aux index at block symbol %s"),
  3056. sym_name);
  3057. new_sdx = cur_sdx + 1; /* Don't skip backward. */
  3058. }
  3059. cur_sdx = new_sdx;
  3060. continue;
  3061. case stFile: /* File headers */
  3062. case stLabel: /* Labels */
  3063. case stEnd: /* Ends of files */
  3064. goto skip;
  3065. case stLocal: /* Local variables */
  3066. /* Normally these are skipped because we skip over
  3067. all blocks we see. However, these can occur
  3068. as visible symbols in a .h file that contains code. */
  3069. goto skip;
  3070. default:
  3071. /* Both complaints are valid: one gives symbol sym_name,
  3072. the other the offending symbol type. */
  3073. complaint (_("unknown local symbol %s"),
  3074. sym_name);
  3075. complaint (_("with type %d"), sh.st);
  3076. cur_sdx++;
  3077. continue;
  3078. }
  3079. /* Use this gdb symbol. */
  3080. pst->add_psymbol (sym_name, true,
  3081. VAR_DOMAIN, theclass, section,
  3082. psymbol_placement::STATIC,
  3083. sh.value, psymtab_language,
  3084. partial_symtabs, objfile);
  3085. skip:
  3086. cur_sdx++; /* Go to next file symbol. */
  3087. }
  3088. /* Now do enter the external symbols. */
  3089. ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
  3090. cur_sdx = fdr_to_pst[f_idx].n_globals;
  3091. PST_PRIVATE (save_pst)->extern_count = cur_sdx;
  3092. PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
  3093. for (; --cur_sdx >= 0; ext_ptr++)
  3094. {
  3095. enum address_class theclass;
  3096. SYMR *psh;
  3097. CORE_ADDR svalue;
  3098. short section;
  3099. gdb_assert (ext_ptr->ifd == f_idx);
  3100. psh = &ext_ptr->asym;
  3101. /* Do not add undefined symbols to the partial symbol table. */
  3102. if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
  3103. continue;
  3104. svalue = psh->value;
  3105. switch (psh->sc)
  3106. {
  3107. default:
  3108. case scText:
  3109. case scRConst:
  3110. section = SECT_OFF_TEXT (objfile);
  3111. break;
  3112. case scData:
  3113. case scSData:
  3114. case scRData:
  3115. case scPData:
  3116. case scXData:
  3117. section = SECT_OFF_DATA (objfile);
  3118. break;
  3119. case scBss:
  3120. case scSBss:
  3121. section = SECT_OFF_BSS (objfile);
  3122. break;
  3123. }
  3124. switch (psh->st)
  3125. {
  3126. case stNil:
  3127. /* These are generated for static symbols in .o files,
  3128. ignore them. */
  3129. continue;
  3130. case stProc:
  3131. case stStaticProc:
  3132. /* External procedure symbols have been entered
  3133. into the minimal symbol table in pass 2 above.
  3134. Ignore them, as parse_external will ignore them too. */
  3135. continue;
  3136. case stLabel:
  3137. theclass = LOC_LABEL;
  3138. break;
  3139. default:
  3140. unknown_ext_complaint (debug_info->ssext + psh->iss);
  3141. /* Pretend it's global. */
  3142. /* Fall through. */
  3143. case stGlobal:
  3144. /* Global common symbols are resolved by the runtime loader,
  3145. ignore them. */
  3146. if (SC_IS_COMMON (psh->sc))
  3147. continue;
  3148. theclass = LOC_STATIC;
  3149. break;
  3150. }
  3151. char *sym_name = debug_info->ssext + psh->iss;
  3152. pst->add_psymbol (sym_name, true,
  3153. VAR_DOMAIN, theclass,
  3154. section,
  3155. psymbol_placement::GLOBAL,
  3156. svalue, psymtab_language,
  3157. partial_symtabs, objfile);
  3158. }
  3159. }
  3160. /* Link pst to FDR. dbx_end_psymtab returns NULL if the psymtab was
  3161. empty and put on the free list. */
  3162. fdr_to_pst[f_idx].pst
  3163. = dbx_end_psymtab (objfile, partial_symtabs, save_pst,
  3164. psymtab_include_list, includes_used,
  3165. -1, save_pst->raw_text_high (),
  3166. dependency_list, dependencies_used,
  3167. textlow_not_set);
  3168. includes_used = 0;
  3169. dependencies_used = 0;
  3170. /* The objfile has its functions reordered if this partial symbol
  3171. table overlaps any other partial symbol table.
  3172. We cannot assume a reordered objfile if a partial symbol table
  3173. is contained within another partial symbol table, as partial symbol
  3174. tables for include files with executable code are contained
  3175. within the partial symbol table for the including source file,
  3176. and we do not want to flag the objfile reordered for these cases.
  3177. This strategy works well for Irix-5.2 shared libraries, but we
  3178. might have to use a more elaborate (and slower) algorithm for
  3179. other cases. */
  3180. save_pst = fdr_to_pst[f_idx].pst;
  3181. if (save_pst != NULL
  3182. && save_pst->text_low_valid
  3183. && !(objfile->flags & OBJF_REORDERED))
  3184. {
  3185. for (partial_symtab *iter : partial_symtabs->range ())
  3186. {
  3187. if (save_pst != iter
  3188. && save_pst->raw_text_low () >= iter->raw_text_low ()
  3189. && save_pst->raw_text_low () < iter->raw_text_high ()
  3190. && save_pst->raw_text_high () > iter->raw_text_high ())
  3191. {
  3192. objfile->flags |= OBJF_REORDERED;
  3193. break;
  3194. }
  3195. }
  3196. }
  3197. }
  3198. /* Now scan the FDRs for dependencies. */
  3199. for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
  3200. {
  3201. fh = f_idx + debug_info->fdr;
  3202. pst = fdr_to_pst[f_idx].pst;
  3203. if (pst == NULL)
  3204. continue;
  3205. /* This should catch stabs-in-ecoff. */
  3206. if (fh->crfd <= 1)
  3207. continue;
  3208. /* Skip the first file indirect entry as it is a self dependency for
  3209. source files or a reverse .h -> .c dependency for header files. */
  3210. pst->number_of_dependencies = 0;
  3211. pst->dependencies
  3212. = partial_symtabs->allocate_dependencies (fh->crfd - 1);
  3213. for (s_idx = 1; s_idx < fh->crfd; s_idx++)
  3214. {
  3215. RFDT rh;
  3216. (*swap_rfd_in) (cur_bfd,
  3217. ((char *) debug_info->external_rfd
  3218. + (fh->rfdBase + s_idx) * external_rfd_size),
  3219. &rh);
  3220. if (rh < 0 || rh >= hdr->ifdMax)
  3221. {
  3222. complaint (_("bad file number %ld"), rh);
  3223. continue;
  3224. }
  3225. /* Skip self dependencies of header files. */
  3226. if (rh == f_idx)
  3227. continue;
  3228. /* Do not add to dependency list if psymtab was empty. */
  3229. if (fdr_to_pst[rh].pst == NULL)
  3230. continue;
  3231. pst->dependencies[pst->number_of_dependencies++]
  3232. = fdr_to_pst[rh].pst;
  3233. }
  3234. }
  3235. /* Remove the dummy psymtab created for -O3 images above, if it is
  3236. still empty, to enable the detection of stripped executables. */
  3237. partial_symtab *pst_del = partial_symtabs->psymtabs;
  3238. if (pst_del->next == NULL
  3239. && pst_del->number_of_dependencies == 0
  3240. && pst_del->empty ())
  3241. partial_symtabs->discard_psymtab (pst_del);
  3242. }
  3243. /* If the current psymbol has an enumerated type, we need to add
  3244. all the enum constants to the partial symbol table. */
  3245. static void
  3246. handle_psymbol_enumerators (struct objfile *objfile,
  3247. psymtab_storage *partial_symtabs,
  3248. partial_symtab *pst,
  3249. FDR *fh, int stype, CORE_ADDR svalue)
  3250. {
  3251. const bfd_size_type external_sym_size = debug_swap->external_sym_size;
  3252. void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
  3253. char *ext_sym = ((char *) debug_info->external_sym
  3254. + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
  3255. SYMR sh;
  3256. TIR tir;
  3257. switch (stype)
  3258. {
  3259. case stEnum:
  3260. break;
  3261. case stBlock:
  3262. /* It is an enumerated type if the next symbol entry is a stMember
  3263. and its auxiliary index is indexNil or its auxiliary entry
  3264. is a plain btNil or btVoid.
  3265. Alpha cc -migrate enums are recognized by a zero index and
  3266. a zero symbol value.
  3267. DU 4.0 cc enums are recognized by a member type of btEnum without
  3268. qualifiers and a zero symbol value. */
  3269. (*swap_sym_in) (cur_bfd, ext_sym, &sh);
  3270. if (sh.st != stMember)
  3271. return;
  3272. if (sh.index == indexNil
  3273. || (sh.index == 0 && svalue == 0))
  3274. break;
  3275. (*debug_swap->swap_tir_in) (fh->fBigendian,
  3276. &(debug_info->external_aux
  3277. + fh->iauxBase + sh.index)->a_ti,
  3278. &tir);
  3279. if ((tir.bt != btNil
  3280. && tir.bt != btVoid
  3281. && (tir.bt != btEnum || svalue != 0))
  3282. || tir.tq0 != tqNil)
  3283. return;
  3284. break;
  3285. default:
  3286. return;
  3287. }
  3288. for (;;)
  3289. {
  3290. char *name;
  3291. (*swap_sym_in) (cur_bfd, ext_sym, &sh);
  3292. if (sh.st != stMember)
  3293. break;
  3294. name = debug_info->ss + cur_fdr->issBase + sh.iss;
  3295. /* Note that the value doesn't matter for enum constants
  3296. in psymtabs, just in symtabs. */
  3297. pst->add_psymbol (name, true,
  3298. VAR_DOMAIN, LOC_CONST, -1,
  3299. psymbol_placement::STATIC, 0,
  3300. psymtab_language, partial_symtabs, objfile);
  3301. ext_sym += external_sym_size;
  3302. }
  3303. }
  3304. /* Get the next symbol. OBJFILE is unused. */
  3305. static const char *
  3306. mdebug_next_symbol_text (struct objfile *objfile)
  3307. {
  3308. SYMR sh;
  3309. cur_sdx++;
  3310. (*debug_swap->swap_sym_in) (cur_bfd,
  3311. ((char *) debug_info->external_sym
  3312. + ((cur_fdr->isymBase + cur_sdx)
  3313. * debug_swap->external_sym_size)),
  3314. &sh);
  3315. return debug_info->ss + cur_fdr->issBase + sh.iss;
  3316. }
  3317. /* Ancillary function to psymtab_to_symtab(). Does all the work
  3318. for turning the partial symtab PST into a symtab, recurring
  3319. first on all dependent psymtabs. The argument FILENAME is
  3320. only passed so we can see in debug stack traces what file
  3321. is being read.
  3322. This function has a split personality, based on whether the
  3323. symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
  3324. The flow of control and even the memory allocation differs. FIXME. */
  3325. static void
  3326. mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
  3327. {
  3328. bfd_size_type external_sym_size;
  3329. bfd_size_type external_pdr_size;
  3330. void (*swap_sym_in) (bfd *, void *, SYMR *);
  3331. void (*swap_pdr_in) (bfd *, void *, PDR *);
  3332. int i;
  3333. struct compunit_symtab *cust = NULL;
  3334. FDR *fh;
  3335. struct linetable *lines;
  3336. CORE_ADDR lowest_pdr_addr = 0;
  3337. int last_symtab_ended = 0;
  3338. const section_offsets &section_offsets = objfile->section_offsets;
  3339. if (pst->readin)
  3340. return;
  3341. pst->readin = true;
  3342. /* Read in all partial symtabs on which this one is dependent.
  3343. NOTE that we do have circular dependencies, sigh. We solved
  3344. that by setting pst->readin before this point. */
  3345. pst->expand_dependencies (objfile);
  3346. /* Do nothing if this is a dummy psymtab. */
  3347. if (pst->empty () && !pst->text_low_valid && !pst->text_high_valid)
  3348. return;
  3349. /* Now read the symbols for this symtab. */
  3350. cur_bfd = CUR_BFD (pst);
  3351. debug_swap = DEBUG_SWAP (pst);
  3352. debug_info = DEBUG_INFO (pst);
  3353. pending_list = PENDING_LIST (pst);
  3354. external_sym_size = debug_swap->external_sym_size;
  3355. external_pdr_size = debug_swap->external_pdr_size;
  3356. swap_sym_in = debug_swap->swap_sym_in;
  3357. swap_pdr_in = debug_swap->swap_pdr_in;
  3358. mdebugread_objfile = objfile;
  3359. cur_fd = FDR_IDX (pst);
  3360. fh = ((cur_fd == -1)
  3361. ? NULL
  3362. : debug_info->fdr + cur_fd);
  3363. cur_fdr = fh;
  3364. /* See comment in parse_partial_symbols about the @stabs sentinel. */
  3365. processing_gcc_compilation = 0;
  3366. if (fh != NULL && fh->csym >= 2)
  3367. {
  3368. SYMR sh;
  3369. (*swap_sym_in) (cur_bfd,
  3370. ((char *) debug_info->external_sym
  3371. + (fh->isymBase + 1) * external_sym_size),
  3372. &sh);
  3373. if (strcmp (debug_info->ss + fh->issBase + sh.iss,
  3374. stabs_symbol) == 0)
  3375. {
  3376. /* We indicate that this is a GCC compilation so that certain
  3377. features will be enabled in stabsread/dbxread. */
  3378. processing_gcc_compilation = 2;
  3379. }
  3380. }
  3381. if (processing_gcc_compilation != 0)
  3382. {
  3383. struct gdbarch *gdbarch = objfile->arch ();
  3384. /* This symbol table contains stabs-in-ecoff entries. */
  3385. /* Parse local symbols first. */
  3386. if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr. */
  3387. {
  3388. mdebugread_objfile = NULL;
  3389. return;
  3390. }
  3391. for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
  3392. {
  3393. SYMR sh;
  3394. char *name;
  3395. CORE_ADDR valu;
  3396. (*swap_sym_in) (cur_bfd,
  3397. (((char *) debug_info->external_sym)
  3398. + (fh->isymBase + cur_sdx) * external_sym_size),
  3399. &sh);
  3400. name = debug_info->ss + fh->issBase + sh.iss;
  3401. valu = sh.value;
  3402. /* XXX This is a hack. It will go away! */
  3403. if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
  3404. {
  3405. int type_code = ECOFF_UNMARK_STAB (sh.index);
  3406. enum language language = PST_PRIVATE (pst)->pst_language;
  3407. /* We should never get non N_STAB symbols here, but they
  3408. should be harmless, so keep process_one_symbol from
  3409. complaining about them. */
  3410. if (type_code & N_STAB)
  3411. {
  3412. /* If we found a trailing N_SO with no name, process
  3413. it here instead of in process_one_symbol, so we
  3414. can keep a handle to its symtab. The symtab
  3415. would otherwise be ended twice, once in
  3416. process_one_symbol, and once after this loop. */
  3417. if (type_code == N_SO
  3418. && get_last_source_file ()
  3419. && previous_stab_code != (unsigned char) N_SO
  3420. && *name == '\000')
  3421. {
  3422. valu += section_offsets[SECT_OFF_TEXT (objfile)];
  3423. previous_stab_code = N_SO;
  3424. cust = end_compunit_symtab (valu, SECT_OFF_TEXT (objfile));
  3425. end_stabs ();
  3426. last_symtab_ended = 1;
  3427. }
  3428. else
  3429. {
  3430. last_symtab_ended = 0;
  3431. process_one_symbol (type_code, 0, valu, name,
  3432. section_offsets, objfile, language);
  3433. }
  3434. }
  3435. /* Similarly a hack. */
  3436. else if (name[0] == '#')
  3437. {
  3438. process_one_symbol (N_SLINE, 0, valu, name,
  3439. section_offsets, objfile, language);
  3440. }
  3441. if (type_code == N_FUN)
  3442. {
  3443. /* Make up special symbol to contain
  3444. procedure specific info. */
  3445. mdebug_extra_func_info *e
  3446. = OBSTACK_ZALLOC (&mdebugread_objfile->objfile_obstack,
  3447. mdebug_extra_func_info);
  3448. struct symbol *s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
  3449. s->set_domain (LABEL_DOMAIN);
  3450. s->set_aclass_index (LOC_CONST);
  3451. s->set_type (objfile_type (objfile)->builtin_void);
  3452. SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
  3453. e->pdr.framereg = -1;
  3454. add_symbol_to_list (s, get_local_symbols ());
  3455. }
  3456. }
  3457. else if (sh.st == stLabel)
  3458. {
  3459. if (sh.index == indexNil)
  3460. {
  3461. /* This is what the gcc2_compiled and __gnu_compiled_*
  3462. show up as. So don't complain. */
  3463. ;
  3464. }
  3465. else
  3466. {
  3467. /* Handle encoded stab line number. */
  3468. valu += section_offsets[SECT_OFF_TEXT (objfile)];
  3469. record_line (get_current_subfile (), sh.index,
  3470. gdbarch_addr_bits_remove (gdbarch, valu));
  3471. }
  3472. }
  3473. else if (sh.st == stProc || sh.st == stStaticProc
  3474. || sh.st == stStatic || sh.st == stEnd)
  3475. /* These are generated by gcc-2.x, do not complain. */
  3476. ;
  3477. else
  3478. complaint (_("unknown stabs symbol %s"), name);
  3479. }
  3480. if (! last_symtab_ended)
  3481. {
  3482. cust = end_compunit_symtab (pst->raw_text_high (),
  3483. SECT_OFF_TEXT (objfile));
  3484. end_stabs ();
  3485. }
  3486. /* There used to be a call to sort_blocks here, but this should not
  3487. be necessary for stabs symtabs. And as sort_blocks modifies the
  3488. start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
  3489. it did the wrong thing if the first procedure in a file was
  3490. generated via asm statements. */
  3491. /* Fill in procedure info next. */
  3492. if (fh->cpd > 0)
  3493. {
  3494. char *pdr_ptr;
  3495. char *pdr_end;
  3496. PDR *pdr_in;
  3497. PDR *pdr_in_end;
  3498. gdb::def_vector<PDR> pr_block (fh->cpd);
  3499. pdr_ptr = ((char *) debug_info->external_pdr
  3500. + fh->ipdFirst * external_pdr_size);
  3501. pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
  3502. pdr_in = pr_block.data ();
  3503. for (;
  3504. pdr_ptr < pdr_end;
  3505. pdr_ptr += external_pdr_size, pdr_in++)
  3506. {
  3507. (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
  3508. /* Determine lowest PDR address, the PDRs are not always
  3509. sorted. */
  3510. if (pdr_in == pr_block.data ())
  3511. lowest_pdr_addr = pdr_in->adr;
  3512. else if (pdr_in->adr < lowest_pdr_addr)
  3513. lowest_pdr_addr = pdr_in->adr;
  3514. }
  3515. pdr_in = pr_block.data ();
  3516. pdr_in_end = pdr_in + fh->cpd;
  3517. for (; pdr_in < pdr_in_end; pdr_in++)
  3518. parse_procedure (pdr_in, cust, pst);
  3519. }
  3520. }
  3521. else
  3522. {
  3523. /* This symbol table contains ordinary ecoff entries. */
  3524. int maxlines, size;
  3525. EXTR *ext_ptr;
  3526. if (fh == 0)
  3527. {
  3528. maxlines = 0;
  3529. cust = new_symtab ("unknown", 0, objfile);
  3530. }
  3531. else
  3532. {
  3533. maxlines = 2 * fh->cline;
  3534. cust = new_symtab (pst->filename, maxlines, objfile);
  3535. /* The proper language was already determined when building
  3536. the psymtab, use it. */
  3537. cust->primary_filetab ()->set_language
  3538. (PST_PRIVATE (pst)->pst_language);
  3539. }
  3540. psymtab_language = cust->primary_filetab ()->language ();
  3541. lines = cust->primary_filetab ()->linetable ();
  3542. /* Get a new lexical context. */
  3543. push_parse_stack ();
  3544. top_stack->cur_st = cust->primary_filetab ();
  3545. top_stack->cur_block
  3546. = BLOCKVECTOR_BLOCK (cust->blockvector (), STATIC_BLOCK);
  3547. BLOCK_START (top_stack->cur_block) = pst->text_low (objfile);
  3548. BLOCK_END (top_stack->cur_block) = 0;
  3549. top_stack->blocktype = stFile;
  3550. top_stack->cur_type = 0;
  3551. top_stack->procadr = 0;
  3552. top_stack->numargs = 0;
  3553. found_ecoff_debugging_info = 0;
  3554. if (fh)
  3555. {
  3556. char *sym_ptr;
  3557. char *sym_end;
  3558. /* Parse local symbols first. */
  3559. sym_ptr = ((char *) debug_info->external_sym
  3560. + fh->isymBase * external_sym_size);
  3561. sym_end = sym_ptr + fh->csym * external_sym_size;
  3562. while (sym_ptr < sym_end)
  3563. {
  3564. SYMR sh;
  3565. int c;
  3566. (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
  3567. c = parse_symbol (&sh,
  3568. debug_info->external_aux + fh->iauxBase,
  3569. sym_ptr, fh->fBigendian,
  3570. section_offsets, objfile);
  3571. sym_ptr += c * external_sym_size;
  3572. }
  3573. /* Linenumbers. At the end, check if we can save memory.
  3574. parse_lines has to look ahead an arbitrary number of PDR
  3575. structures, so we swap them all first. */
  3576. if (fh->cpd > 0)
  3577. {
  3578. char *pdr_ptr;
  3579. char *pdr_end;
  3580. PDR *pdr_in;
  3581. PDR *pdr_in_end;
  3582. gdb::def_vector<PDR> pr_block (fh->cpd);
  3583. pdr_ptr = ((char *) debug_info->external_pdr
  3584. + fh->ipdFirst * external_pdr_size);
  3585. pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
  3586. pdr_in = pr_block.data ();
  3587. for (;
  3588. pdr_ptr < pdr_end;
  3589. pdr_ptr += external_pdr_size, pdr_in++)
  3590. {
  3591. (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
  3592. /* Determine lowest PDR address, the PDRs are not always
  3593. sorted. */
  3594. if (pdr_in == pr_block.data ())
  3595. lowest_pdr_addr = pdr_in->adr;
  3596. else if (pdr_in->adr < lowest_pdr_addr)
  3597. lowest_pdr_addr = pdr_in->adr;
  3598. }
  3599. parse_lines (fh, pr_block.data (), lines, maxlines,
  3600. pst->text_low (objfile), lowest_pdr_addr);
  3601. if (lines->nitems < fh->cline)
  3602. lines = shrink_linetable (lines);
  3603. /* Fill in procedure info next. */
  3604. pdr_in = pr_block.data ();
  3605. pdr_in_end = pdr_in + fh->cpd;
  3606. for (; pdr_in < pdr_in_end; pdr_in++)
  3607. parse_procedure (pdr_in, NULL, pst);
  3608. }
  3609. }
  3610. size = lines->nitems;
  3611. if (size > 1)
  3612. --size;
  3613. cust->primary_filetab ()->set_linetable
  3614. ((struct linetable *)
  3615. obstack_copy (&mdebugread_objfile->objfile_obstack,
  3616. lines, (sizeof (struct linetable)
  3617. + size * sizeof (lines->item))));
  3618. xfree (lines);
  3619. /* .. and our share of externals.
  3620. XXX use the global list to speed up things here. How?
  3621. FIXME, Maybe quit once we have found the right number of ext's? */
  3622. top_stack->cur_st = cust->primary_filetab ();
  3623. top_stack->cur_block
  3624. = BLOCKVECTOR_BLOCK (top_stack->cur_st->compunit ()->blockvector (),
  3625. GLOBAL_BLOCK);
  3626. top_stack->blocktype = stFile;
  3627. ext_ptr = PST_PRIVATE (pst)->extern_tab;
  3628. for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
  3629. parse_external (ext_ptr, fh->fBigendian,
  3630. section_offsets, objfile);
  3631. /* If there are undefined symbols, tell the user.
  3632. The alpha has an undefined symbol for every symbol that is
  3633. from a shared library, so tell the user only if verbose is on. */
  3634. if (info_verbose && n_undef_symbols)
  3635. {
  3636. gdb_printf (_("File %s contains %d unresolved references:"),
  3637. symtab_to_filename_for_display
  3638. (cust->primary_filetab ()),
  3639. n_undef_symbols);
  3640. gdb_printf ("\n\t%4d variables\n\t%4d "
  3641. "procedures\n\t%4d labels\n",
  3642. n_undef_vars, n_undef_procs, n_undef_labels);
  3643. n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
  3644. }
  3645. pop_parse_stack ();
  3646. sort_blocks (cust->primary_filetab ());
  3647. }
  3648. /* Now link the psymtab and the symtab. */
  3649. pst->compunit_symtab = cust;
  3650. mdebugread_objfile = NULL;
  3651. }
  3652. /* Ancillary parsing procedures. */
  3653. /* Return 1 if the symbol pointed to by SH has a cross reference
  3654. to an opaque aggregate type, else 0. */
  3655. static int
  3656. has_opaque_xref (FDR *fh, SYMR *sh)
  3657. {
  3658. TIR tir;
  3659. union aux_ext *ax;
  3660. RNDXR rn[1];
  3661. unsigned int rf;
  3662. if (sh->index == indexNil)
  3663. return 0;
  3664. ax = debug_info->external_aux + fh->iauxBase + sh->index;
  3665. (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
  3666. if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
  3667. return 0;
  3668. ax++;
  3669. (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
  3670. if (rn->rfd == 0xfff)
  3671. rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
  3672. else
  3673. rf = rn->rfd;
  3674. if (rf != -1)
  3675. return 0;
  3676. return 1;
  3677. }
  3678. /* Lookup the type at relative index RN. Return it in TPP
  3679. if found and in any event come up with its name PNAME.
  3680. BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
  3681. Return value says how many aux symbols we ate. */
  3682. static int
  3683. cross_ref (int fd, union aux_ext *ax, struct type **tpp,
  3684. enum type_code type_code,
  3685. /* Use to alloc new type if none is found. */
  3686. const char **pname, int bigend, const char *sym_name)
  3687. {
  3688. RNDXR rn[1];
  3689. unsigned int rf;
  3690. int result = 1;
  3691. FDR *fh;
  3692. char *esh;
  3693. SYMR sh;
  3694. int xref_fd;
  3695. struct mdebug_pending *pend;
  3696. *tpp = NULL;
  3697. (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
  3698. /* Escape index means 'the next one'. */
  3699. if (rn->rfd == 0xfff)
  3700. {
  3701. result++;
  3702. rf = AUX_GET_ISYM (bigend, ax + 1);
  3703. }
  3704. else
  3705. {
  3706. rf = rn->rfd;
  3707. }
  3708. /* mips cc uses a rf of -1 for opaque struct definitions.
  3709. Set TYPE_STUB for these types so that check_typedef will
  3710. resolve them if the struct gets defined in another compilation unit. */
  3711. if (rf == -1)
  3712. {
  3713. *pname = "<undefined>";
  3714. *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
  3715. (*tpp)->set_is_stub (true);
  3716. return result;
  3717. }
  3718. /* mips cc uses an escaped rn->index of 0 for struct return types
  3719. of procedures that were compiled without -g. These will always remain
  3720. undefined. */
  3721. if (rn->rfd == 0xfff && rn->index == 0)
  3722. {
  3723. *pname = "<undefined>";
  3724. return result;
  3725. }
  3726. /* Find the relative file descriptor and the symbol in it. */
  3727. fh = get_rfd (fd, rf);
  3728. xref_fd = fh - debug_info->fdr;
  3729. if (rn->index >= fh->csym)
  3730. {
  3731. /* File indirect entry is corrupt. */
  3732. *pname = "<illegal>";
  3733. bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
  3734. return result;
  3735. }
  3736. /* If we have processed this symbol then we left a forwarding
  3737. pointer to the type in the pending list. If not, we`ll put
  3738. it in a list of pending types, to be processed later when
  3739. the file will be. In any event, we collect the name for the
  3740. type here. */
  3741. esh = ((char *) debug_info->external_sym
  3742. + ((fh->isymBase + rn->index)
  3743. * debug_swap->external_sym_size));
  3744. (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
  3745. /* Make sure that this type of cross reference can be handled. */
  3746. if ((sh.sc != scInfo
  3747. || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
  3748. && sh.st != stStruct && sh.st != stUnion
  3749. && sh.st != stEnum))
  3750. && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
  3751. {
  3752. /* File indirect entry is corrupt. */
  3753. *pname = "<illegal>";
  3754. bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
  3755. return result;
  3756. }
  3757. *pname = debug_info->ss + fh->issBase + sh.iss;
  3758. pend = is_pending_symbol (fh, esh);
  3759. if (pend)
  3760. *tpp = pend->t;
  3761. else
  3762. {
  3763. /* We have not yet seen this type. */
  3764. if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
  3765. {
  3766. TIR tir;
  3767. /* alpha cc puts out a stTypedef with a sh.iss of zero for
  3768. two cases:
  3769. a) forward declarations of structs/unions/enums which are not
  3770. defined in this compilation unit.
  3771. For these the type will be void. This is a bad design decision
  3772. as cross referencing across compilation units is impossible
  3773. due to the missing name.
  3774. b) forward declarations of structs/unions/enums/typedefs which
  3775. are defined later in this file or in another file in the same
  3776. compilation unit. Irix5 cc uses a stIndirect symbol for this.
  3777. Simply cross reference those again to get the true type.
  3778. The forward references are not entered in the pending list and
  3779. in the symbol table. */
  3780. (*debug_swap->swap_tir_in) (bigend,
  3781. &(debug_info->external_aux
  3782. + fh->iauxBase + sh.index)->a_ti,
  3783. &tir);
  3784. if (tir.tq0 != tqNil)
  3785. complaint (_("illegal tq0 in forward typedef for %s"), sym_name);
  3786. switch (tir.bt)
  3787. {
  3788. case btVoid:
  3789. *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
  3790. *pname = "<undefined>";
  3791. break;
  3792. case btStruct:
  3793. case btUnion:
  3794. case btEnum:
  3795. cross_ref (xref_fd,
  3796. (debug_info->external_aux
  3797. + fh->iauxBase + sh.index + 1),
  3798. tpp, type_code, pname,
  3799. fh->fBigendian, sym_name);
  3800. break;
  3801. case btTypedef:
  3802. /* Follow a forward typedef. This might recursively
  3803. call cross_ref till we get a non typedef'ed type.
  3804. FIXME: This is not correct behaviour, but gdb currently
  3805. cannot handle typedefs without type copying. Type
  3806. copying is impossible as we might have mutual forward
  3807. references between two files and the copied type would not
  3808. get filled in when we later parse its definition. */
  3809. *tpp = parse_type (xref_fd,
  3810. debug_info->external_aux + fh->iauxBase,
  3811. sh.index,
  3812. NULL,
  3813. fh->fBigendian,
  3814. debug_info->ss + fh->issBase + sh.iss);
  3815. add_pending (fh, esh, *tpp);
  3816. break;
  3817. default:
  3818. complaint (_("illegal bt %d in forward typedef for %s"), tir.bt,
  3819. sym_name);
  3820. *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
  3821. break;
  3822. }
  3823. return result;
  3824. }
  3825. else if (sh.st == stTypedef)
  3826. {
  3827. /* Parse the type for a normal typedef. This might recursively call
  3828. cross_ref till we get a non typedef'ed type.
  3829. FIXME: This is not correct behaviour, but gdb currently
  3830. cannot handle typedefs without type copying. But type copying is
  3831. impossible as we might have mutual forward references between
  3832. two files and the copied type would not get filled in when
  3833. we later parse its definition. */
  3834. *tpp = parse_type (xref_fd,
  3835. debug_info->external_aux + fh->iauxBase,
  3836. sh.index,
  3837. NULL,
  3838. fh->fBigendian,
  3839. debug_info->ss + fh->issBase + sh.iss);
  3840. }
  3841. else
  3842. {
  3843. /* Cross reference to a struct/union/enum which is defined
  3844. in another file in the same compilation unit but that file
  3845. has not been parsed yet.
  3846. Initialize the type only, it will be filled in when
  3847. it's definition is parsed. */
  3848. *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
  3849. }
  3850. add_pending (fh, esh, *tpp);
  3851. }
  3852. /* We used one auxent normally, two if we got a "next one" rf. */
  3853. return result;
  3854. }
  3855. /* Quick&dirty lookup procedure, to avoid the MI ones that require
  3856. keeping the symtab sorted. */
  3857. static struct symbol *
  3858. mylookup_symbol (const char *name, const struct block *block,
  3859. domain_enum domain, enum address_class theclass)
  3860. {
  3861. struct block_iterator iter;
  3862. int inc;
  3863. struct symbol *sym;
  3864. inc = name[0];
  3865. ALL_BLOCK_SYMBOLS (block, iter, sym)
  3866. {
  3867. if (sym->linkage_name ()[0] == inc
  3868. && sym->domain () == domain
  3869. && sym->aclass () == theclass
  3870. && strcmp (sym->linkage_name (), name) == 0)
  3871. return sym;
  3872. }
  3873. block = BLOCK_SUPERBLOCK (block);
  3874. if (block)
  3875. return mylookup_symbol (name, block, domain, theclass);
  3876. return 0;
  3877. }
  3878. /* Add a new symbol S to a block B. */
  3879. static void
  3880. add_symbol (struct symbol *s, struct symtab *symtab, struct block *b)
  3881. {
  3882. symbol_set_symtab (s, symtab);
  3883. mdict_add_symbol (BLOCK_MULTIDICT (b), s);
  3884. }
  3885. /* Add a new block B to a symtab S. */
  3886. static void
  3887. add_block (struct block *b, struct symtab *s)
  3888. {
  3889. /* Cast away "const", but that's ok because we're building the
  3890. symtab and blockvector here. */
  3891. struct blockvector *bv
  3892. = (struct blockvector *) s->compunit ()->blockvector ();
  3893. bv = (struct blockvector *) xrealloc ((void *) bv,
  3894. (sizeof (struct blockvector)
  3895. + BLOCKVECTOR_NBLOCKS (bv)
  3896. * sizeof (bv->block)));
  3897. if (bv != s->compunit ()->blockvector ())
  3898. s->compunit ()->set_blockvector (bv);
  3899. BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
  3900. }
  3901. /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
  3902. MIPS' linenumber encoding might need more than one byte
  3903. to describe it, LAST is used to detect these continuation lines.
  3904. Combining lines with the same line number seems like a bad idea.
  3905. E.g: There could be a line number entry with the same line number after the
  3906. prologue and GDB should not ignore it (this is a better way to find
  3907. a prologue than mips_skip_prologue).
  3908. But due to the compressed line table format there are line number entries
  3909. for the same line which are needed to bridge the gap to the next
  3910. line number entry. These entries have a bogus address info with them
  3911. and we are unable to tell them from intended duplicate line number
  3912. entries.
  3913. This is another reason why -ggdb debugging format is preferable. */
  3914. static int
  3915. add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
  3916. {
  3917. /* DEC c89 sometimes produces zero linenos which confuse gdb.
  3918. Change them to something sensible. */
  3919. if (lineno == 0)
  3920. lineno = 1;
  3921. if (last == 0)
  3922. last = -2; /* Make sure we record first line. */
  3923. if (last == lineno) /* Skip continuation lines. */
  3924. return lineno;
  3925. lt->item[lt->nitems].line = lineno;
  3926. lt->item[lt->nitems++].pc = adr << 2;
  3927. return lineno;
  3928. }
  3929. /* Sorting and reordering procedures. */
  3930. /* Blocks with a smaller low bound should come first. */
  3931. static bool
  3932. block_is_less_than (const struct block *b1, const struct block *b2)
  3933. {
  3934. CORE_ADDR start1 = BLOCK_START (b1);
  3935. CORE_ADDR start2 = BLOCK_START (b2);
  3936. if (start1 != start2)
  3937. return start1 < start2;
  3938. return (BLOCK_END (b2)) < (BLOCK_END (b1));
  3939. }
  3940. /* Sort the blocks of a symtab S.
  3941. Reorder the blocks in the blockvector by code-address,
  3942. as required by some MI search routines. */
  3943. static void
  3944. sort_blocks (struct symtab *s)
  3945. {
  3946. /* We have to cast away const here, but this is ok because we're
  3947. constructing the blockvector in this code. */
  3948. struct blockvector *bv
  3949. = (struct blockvector *) s->compunit ()->blockvector ();
  3950. if (BLOCKVECTOR_NBLOCKS (bv) <= FIRST_LOCAL_BLOCK)
  3951. {
  3952. /* Cosmetic */
  3953. if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
  3954. BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
  3955. if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
  3956. BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
  3957. return;
  3958. }
  3959. /*
  3960. * This is very unfortunate: normally all functions are compiled in
  3961. * the order they are found, but if the file is compiled -O3 things
  3962. * are very different. It would be nice to find a reliable test
  3963. * to detect -O3 images in advance.
  3964. */
  3965. if (BLOCKVECTOR_NBLOCKS (bv) > FIRST_LOCAL_BLOCK + 1)
  3966. std::sort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
  3967. &BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)),
  3968. block_is_less_than);
  3969. {
  3970. CORE_ADDR high = 0;
  3971. int i, j = BLOCKVECTOR_NBLOCKS (bv);
  3972. for (i = FIRST_LOCAL_BLOCK; i < j; i++)
  3973. if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
  3974. high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
  3975. BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
  3976. }
  3977. BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
  3978. BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
  3979. BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
  3980. BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
  3981. BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
  3982. BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
  3983. }
  3984. /* Constructor/restructor/destructor procedures. */
  3985. /* Allocate a new symtab for NAME. Needs an estimate of how many
  3986. linenumbers MAXLINES we'll put in it. */
  3987. static struct compunit_symtab *
  3988. new_symtab (const char *name, int maxlines, struct objfile *objfile)
  3989. {
  3990. struct compunit_symtab *cust = allocate_compunit_symtab (objfile, name);
  3991. struct symtab *symtab;
  3992. struct blockvector *bv;
  3993. enum language lang;
  3994. add_compunit_symtab_to_objfile (cust);
  3995. symtab = allocate_symtab (cust, name);
  3996. symtab->set_linetable (new_linetable (maxlines));
  3997. lang = compunit_language (cust);
  3998. /* All symtabs must have at least two blocks. */
  3999. bv = new_bvect (2);
  4000. BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
  4001. BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
  4002. BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
  4003. BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
  4004. cust->set_blockvector (bv);
  4005. cust->set_debugformat ("ECOFF");
  4006. return cust;
  4007. }
  4008. /* Allocate a new partial_symtab NAME. */
  4009. static legacy_psymtab *
  4010. new_psymtab (const char *name, psymtab_storage *partial_symtabs,
  4011. struct objfile *objfile)
  4012. {
  4013. legacy_psymtab *psymtab;
  4014. psymtab = new legacy_psymtab (name, partial_symtabs, objfile->per_bfd);
  4015. /* Keep a backpointer to the file's symbols. */
  4016. psymtab->read_symtab_private
  4017. = OBSTACK_ZALLOC (&objfile->objfile_obstack, symloc);
  4018. CUR_BFD (psymtab) = cur_bfd;
  4019. DEBUG_SWAP (psymtab) = debug_swap;
  4020. DEBUG_INFO (psymtab) = debug_info;
  4021. PENDING_LIST (psymtab) = pending_list;
  4022. /* The way to turn this into a symtab is to call... */
  4023. psymtab->legacy_read_symtab = mdebug_read_symtab;
  4024. psymtab->legacy_expand_psymtab = mdebug_expand_psymtab;
  4025. return (psymtab);
  4026. }
  4027. /* Allocate a linetable array of the given SIZE. Since the struct
  4028. already includes one item, we subtract one when calculating the
  4029. proper size to allocate. */
  4030. static struct linetable *
  4031. new_linetable (int size)
  4032. {
  4033. struct linetable *l;
  4034. if (size > 1)
  4035. --size;
  4036. size = size * sizeof (l->item) + sizeof (struct linetable);
  4037. l = (struct linetable *) xmalloc (size);
  4038. l->nitems = 0;
  4039. return l;
  4040. }
  4041. /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
  4042. I am not so sure about the 3.4 ones.
  4043. Since the struct linetable already includes one item, we subtract one when
  4044. calculating the proper size to allocate. */
  4045. static struct linetable *
  4046. shrink_linetable (struct linetable *lt)
  4047. {
  4048. return (struct linetable *) xrealloc ((void *) lt,
  4049. (sizeof (struct linetable)
  4050. + ((lt->nitems - 1)
  4051. * sizeof (lt->item))));
  4052. }
  4053. /* Allocate and zero a new blockvector of NBLOCKS blocks. */
  4054. static struct blockvector *
  4055. new_bvect (int nblocks)
  4056. {
  4057. struct blockvector *bv;
  4058. int size;
  4059. size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
  4060. bv = (struct blockvector *) xzalloc (size);
  4061. BLOCKVECTOR_NBLOCKS (bv) = nblocks;
  4062. return bv;
  4063. }
  4064. /* Allocate and zero a new block of language LANGUAGE, and set its
  4065. BLOCK_MULTIDICT. If function is non-zero, assume the block is
  4066. associated to a function, and make sure that the symbols are stored
  4067. linearly; otherwise, store them hashed. */
  4068. static struct block *
  4069. new_block (enum block_type type, enum language language)
  4070. {
  4071. /* FIXME: carlton/2003-09-11: This should use allocate_block to
  4072. allocate the block. Which, in turn, suggests that the block
  4073. should be allocated on an obstack. */
  4074. struct block *retval = XCNEW (struct block);
  4075. if (type == FUNCTION_BLOCK)
  4076. BLOCK_MULTIDICT (retval) = mdict_create_linear_expandable (language);
  4077. else
  4078. BLOCK_MULTIDICT (retval) = mdict_create_hashed_expandable (language);
  4079. return retval;
  4080. }
  4081. /* Create a new symbol with printname NAME. */
  4082. static struct symbol *
  4083. new_symbol (const char *name)
  4084. {
  4085. struct symbol *s = new (&mdebugread_objfile->objfile_obstack) symbol;
  4086. s->set_language (psymtab_language, &mdebugread_objfile->objfile_obstack);
  4087. s->compute_and_set_names (name, true, mdebugread_objfile->per_bfd);
  4088. return s;
  4089. }
  4090. /* Create a new type with printname NAME. */
  4091. static struct type *
  4092. new_type (char *name)
  4093. {
  4094. struct type *t;
  4095. t = alloc_type (mdebugread_objfile);
  4096. t->set_name (name);
  4097. INIT_CPLUS_SPECIFIC (t);
  4098. return t;
  4099. }
  4100. /* Read ECOFF debugging information from a BFD section. This is
  4101. called from elfread.c. It parses the section into a
  4102. ecoff_debug_info struct, and then lets the rest of the file handle
  4103. it as normal. */
  4104. void
  4105. elfmdebug_build_psymtabs (struct objfile *objfile,
  4106. const struct ecoff_debug_swap *swap, asection *sec)
  4107. {
  4108. bfd *abfd = objfile->obfd;
  4109. struct ecoff_debug_info *info;
  4110. /* FIXME: It's not clear whether we should be getting minimal symbol
  4111. information from .mdebug in an ELF file, or whether we will.
  4112. Re-initialize the minimal symbol reader in case we do. */
  4113. minimal_symbol_reader reader (objfile);
  4114. info = XOBNEW (&objfile->objfile_obstack, ecoff_debug_info);
  4115. if (!(*swap->read_debug_info) (abfd, sec, info))
  4116. error (_("Error reading ECOFF debugging information: %s"),
  4117. bfd_errmsg (bfd_get_error ()));
  4118. mdebug_build_psymtabs (reader, objfile, swap, info);
  4119. reader.install ();
  4120. }
  4121. void _initialize_mdebugread ();
  4122. void
  4123. _initialize_mdebugread ()
  4124. {
  4125. mdebug_register_index
  4126. = register_symbol_register_impl (LOC_REGISTER, &mdebug_register_funcs);
  4127. mdebug_regparm_index
  4128. = register_symbol_register_impl (LOC_REGPARM_ADDR, &mdebug_register_funcs);
  4129. }