dbxread.c 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184
  1. /* Read dbx symbol tables and convert to internal format, for GDB.
  2. Copyright (C) 1986-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. /* This module provides three functions: dbx_symfile_init,
  15. which initializes to read a symbol file; dbx_new_init, which
  16. discards existing cached information when all symbols are being
  17. discarded; and dbx_symfile_read, which reads a symbol table
  18. from a file.
  19. dbx_symfile_read only does the minimum work necessary for letting the
  20. user "name" things symbolically; it does not read the entire symtab.
  21. Instead, it reads the external and static symbols and puts them in partial
  22. symbol tables. When more extensive information is requested of a
  23. file, the corresponding partial symbol table is mutated into a full
  24. fledged symbol table by going back and reading the symbols
  25. for real. dbx_psymtab_to_symtab() is the function that does this */
  26. #include "defs.h"
  27. #include "gdbsupport/gdb_obstack.h"
  28. #include <sys/stat.h>
  29. #include "symtab.h"
  30. #include "breakpoint.h"
  31. #include "target.h"
  32. #include "gdbcore.h" /* for bfd stuff */
  33. #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
  34. #include "filenames.h"
  35. #include "objfiles.h"
  36. #include "buildsym-legacy.h"
  37. #include "stabsread.h"
  38. #include "gdb-stabs.h"
  39. #include "demangle.h"
  40. #include "complaints.h"
  41. #include "cp-abi.h"
  42. #include "cp-support.h"
  43. #include "psympriv.h"
  44. #include "block.h"
  45. #include "aout/aout64.h"
  46. #include "aout/stab_gnu.h" /* We always use GNU stabs, not
  47. native, now. */
  48. /* Key for dbx-associated data. */
  49. objfile_key<dbx_symfile_info> dbx_objfile_data_key;
  50. /* We put a pointer to this structure in the read_symtab_private field
  51. of the psymtab. */
  52. struct symloc
  53. {
  54. /* Offset within the file symbol table of first local symbol for this
  55. file. */
  56. int ldsymoff;
  57. /* Length (in bytes) of the section of the symbol table devoted to
  58. this file's symbols (actually, the section bracketed may contain
  59. more than just this file's symbols). If ldsymlen is 0, the only
  60. reason for this thing's existence is the dependency list. Nothing
  61. else will happen when it is read in. */
  62. int ldsymlen;
  63. /* The size of each symbol in the symbol file (in external form). */
  64. int symbol_size;
  65. /* Further information needed to locate the symbols if they are in
  66. an ELF file. */
  67. int symbol_offset;
  68. int string_offset;
  69. int file_string_offset;
  70. enum language pst_language;
  71. };
  72. #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
  73. #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
  74. #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
  75. #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
  76. #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
  77. #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
  78. #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
  79. #define PST_LANGUAGE(p) (SYMLOC(p)->pst_language)
  80. /* The objfile we are currently reading. */
  81. static struct objfile *dbxread_objfile;
  82. /* Remember what we deduced to be the source language of this psymtab. */
  83. static enum language psymtab_language = language_unknown;
  84. /* The BFD for this file -- implicit parameter to next_symbol_text. */
  85. static bfd *symfile_bfd;
  86. /* The size of each symbol in the symbol file (in external form).
  87. This is set by dbx_symfile_read when building psymtabs, and by
  88. dbx_psymtab_to_symtab when building symtabs. */
  89. static unsigned symbol_size;
  90. /* This is the offset of the symbol table in the executable file. */
  91. static unsigned symbol_table_offset;
  92. /* This is the offset of the string table in the executable file. */
  93. static unsigned string_table_offset;
  94. /* For elf+stab executables, the n_strx field is not a simple index
  95. into the string table. Instead, each .o file has a base offset in
  96. the string table, and the associated symbols contain offsets from
  97. this base. The following two variables contain the base offset for
  98. the current and next .o files. */
  99. static unsigned int file_string_table_offset;
  100. static unsigned int next_file_string_table_offset;
  101. /* .o and NLM files contain unrelocated addresses which are based at
  102. 0. When non-zero, this flag disables some of the special cases for
  103. Solaris elf+stab text addresses at location 0. */
  104. static int symfile_relocatable = 0;
  105. /* When set, we are processing a .o file compiled by sun acc. This is
  106. misnamed; it refers to all stabs-in-elf implementations which use
  107. N_UNDF the way Sun does, including Solaris gcc. Hopefully all
  108. stabs-in-elf implementations ever invented will choose to be
  109. compatible. */
  110. static unsigned char processing_acc_compilation;
  111. /* The lowest text address we have yet encountered. This is needed
  112. because in an a.out file, there is no header field which tells us
  113. what address the program is actually going to be loaded at, so we
  114. need to make guesses based on the symbols (which *are* relocated to
  115. reflect the address it will be loaded at). */
  116. static CORE_ADDR lowest_text_address;
  117. /* Non-zero if there is any line number info in the objfile. Prevents
  118. dbx_end_psymtab from discarding an otherwise empty psymtab. */
  119. static int has_line_numbers;
  120. /* Complaints about the symbols we have encountered. */
  121. static void
  122. unknown_symtype_complaint (const char *arg1)
  123. {
  124. complaint (_("unknown symbol type %s"), arg1);
  125. }
  126. static void
  127. lbrac_mismatch_complaint (int arg1)
  128. {
  129. complaint (_("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
  130. }
  131. static void
  132. repeated_header_complaint (const char *arg1, int arg2)
  133. {
  134. complaint (_("\"repeated\" header file %s not "
  135. "previously seen, at symtab pos %d"),
  136. arg1, arg2);
  137. }
  138. /* find_text_range --- find start and end of loadable code sections
  139. The find_text_range function finds the shortest address range that
  140. encloses all sections containing executable code, and stores it in
  141. objfile's text_addr and text_size members.
  142. dbx_symfile_read will use this to finish off the partial symbol
  143. table, in some cases. */
  144. static void
  145. find_text_range (bfd * sym_bfd, struct objfile *objfile)
  146. {
  147. asection *sec;
  148. int found_any = 0;
  149. CORE_ADDR start = 0;
  150. CORE_ADDR end = 0;
  151. for (sec = sym_bfd->sections; sec; sec = sec->next)
  152. if (bfd_section_flags (sec) & SEC_CODE)
  153. {
  154. CORE_ADDR sec_start = bfd_section_vma (sec);
  155. CORE_ADDR sec_end = sec_start + bfd_section_size (sec);
  156. if (found_any)
  157. {
  158. if (sec_start < start)
  159. start = sec_start;
  160. if (sec_end > end)
  161. end = sec_end;
  162. }
  163. else
  164. {
  165. start = sec_start;
  166. end = sec_end;
  167. }
  168. found_any = 1;
  169. }
  170. if (!found_any)
  171. error (_("Can't find any code sections in symbol file"));
  172. DBX_TEXT_ADDR (objfile) = start;
  173. DBX_TEXT_SIZE (objfile) = end - start;
  174. }
  175. /* During initial symbol readin, we need to have a structure to keep
  176. track of which psymtabs have which bincls in them. This structure
  177. is used during readin to setup the list of dependencies within each
  178. partial symbol table. */
  179. struct header_file_location
  180. {
  181. header_file_location (const char *name_, int instance_,
  182. legacy_psymtab *pst_)
  183. : name (name_),
  184. instance (instance_),
  185. pst (pst_)
  186. {
  187. }
  188. const char *name; /* Name of header file */
  189. int instance; /* See above */
  190. legacy_psymtab *pst; /* Partial symtab that has the
  191. BINCL/EINCL defs for this file. */
  192. };
  193. /* The list of bincls. */
  194. static std::vector<struct header_file_location> *bincl_list;
  195. /* Local function prototypes. */
  196. static void read_ofile_symtab (struct objfile *, legacy_psymtab *);
  197. static void dbx_read_symtab (legacy_psymtab *self,
  198. struct objfile *objfile);
  199. static void dbx_expand_psymtab (legacy_psymtab *, struct objfile *);
  200. static void read_dbx_symtab (minimal_symbol_reader &, psymtab_storage *,
  201. struct objfile *);
  202. static legacy_psymtab *find_corresponding_bincl_psymtab (const char *,
  203. int);
  204. static const char *dbx_next_symbol_text (struct objfile *);
  205. static void fill_symbuf (bfd *);
  206. static void dbx_symfile_init (struct objfile *);
  207. static void dbx_new_init (struct objfile *);
  208. static void dbx_symfile_read (struct objfile *, symfile_add_flags);
  209. static void dbx_symfile_finish (struct objfile *);
  210. static void record_minimal_symbol (minimal_symbol_reader &,
  211. const char *, CORE_ADDR, int,
  212. struct objfile *);
  213. static void add_new_header_file (const char *, int);
  214. static void add_old_header_file (const char *, int);
  215. static void add_this_object_header_file (int);
  216. static legacy_psymtab *start_psymtab (psymtab_storage *, struct objfile *,
  217. const char *, CORE_ADDR, int);
  218. /* Free up old header file tables. */
  219. void
  220. free_header_files (void)
  221. {
  222. if (this_object_header_files)
  223. {
  224. xfree (this_object_header_files);
  225. this_object_header_files = NULL;
  226. }
  227. n_allocated_this_object_header_files = 0;
  228. }
  229. /* Allocate new header file tables. */
  230. void
  231. init_header_files (void)
  232. {
  233. n_allocated_this_object_header_files = 10;
  234. this_object_header_files = XNEWVEC (int, 10);
  235. }
  236. /* Add header file number I for this object file
  237. at the next successive FILENUM. */
  238. static void
  239. add_this_object_header_file (int i)
  240. {
  241. if (n_this_object_header_files == n_allocated_this_object_header_files)
  242. {
  243. n_allocated_this_object_header_files *= 2;
  244. this_object_header_files
  245. = (int *) xrealloc ((char *) this_object_header_files,
  246. n_allocated_this_object_header_files * sizeof (int));
  247. }
  248. this_object_header_files[n_this_object_header_files++] = i;
  249. }
  250. /* Add to this file an "old" header file, one already seen in
  251. a previous object file. NAME is the header file's name.
  252. INSTANCE is its instance code, to select among multiple
  253. symbol tables for the same header file. */
  254. static void
  255. add_old_header_file (const char *name, int instance)
  256. {
  257. struct header_file *p = HEADER_FILES (dbxread_objfile);
  258. int i;
  259. for (i = 0; i < N_HEADER_FILES (dbxread_objfile); i++)
  260. if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
  261. {
  262. add_this_object_header_file (i);
  263. return;
  264. }
  265. repeated_header_complaint (name, symnum);
  266. }
  267. /* Add to this file a "new" header file: definitions for its types follow.
  268. NAME is the header file's name.
  269. Most often this happens only once for each distinct header file,
  270. but not necessarily. If it happens more than once, INSTANCE has
  271. a different value each time, and references to the header file
  272. use INSTANCE values to select among them.
  273. dbx output contains "begin" and "end" markers for each new header file,
  274. but at this level we just need to know which files there have been;
  275. so we record the file when its "begin" is seen and ignore the "end". */
  276. static void
  277. add_new_header_file (const char *name, int instance)
  278. {
  279. int i;
  280. struct header_file *hfile;
  281. /* Make sure there is room for one more header file. */
  282. i = N_ALLOCATED_HEADER_FILES (dbxread_objfile);
  283. if (N_HEADER_FILES (dbxread_objfile) == i)
  284. {
  285. if (i == 0)
  286. {
  287. N_ALLOCATED_HEADER_FILES (dbxread_objfile) = 10;
  288. HEADER_FILES (dbxread_objfile) = (struct header_file *)
  289. xmalloc (10 * sizeof (struct header_file));
  290. }
  291. else
  292. {
  293. i *= 2;
  294. N_ALLOCATED_HEADER_FILES (dbxread_objfile) = i;
  295. HEADER_FILES (dbxread_objfile) = (struct header_file *)
  296. xrealloc ((char *) HEADER_FILES (dbxread_objfile),
  297. (i * sizeof (struct header_file)));
  298. }
  299. }
  300. /* Create an entry for this header file. */
  301. i = N_HEADER_FILES (dbxread_objfile)++;
  302. hfile = HEADER_FILES (dbxread_objfile) + i;
  303. hfile->name = xstrdup (name);
  304. hfile->instance = instance;
  305. hfile->length = 10;
  306. hfile->vector = XCNEWVEC (struct type *, 10);
  307. add_this_object_header_file (i);
  308. }
  309. #if 0
  310. static struct type **
  311. explicit_lookup_type (int real_filenum, int index)
  312. {
  313. struct header_file *f = &HEADER_FILES (dbxread_objfile)[real_filenum];
  314. if (index >= f->length)
  315. {
  316. f->length *= 2;
  317. f->vector = (struct type **)
  318. xrealloc (f->vector, f->length * sizeof (struct type *));
  319. memset (&f->vector[f->length / 2],
  320. '\0', f->length * sizeof (struct type *) / 2);
  321. }
  322. return &f->vector[index];
  323. }
  324. #endif
  325. static void
  326. record_minimal_symbol (minimal_symbol_reader &reader,
  327. const char *name, CORE_ADDR address, int type,
  328. struct objfile *objfile)
  329. {
  330. enum minimal_symbol_type ms_type;
  331. int section;
  332. switch (type)
  333. {
  334. case N_TEXT | N_EXT:
  335. ms_type = mst_text;
  336. section = SECT_OFF_TEXT (objfile);
  337. break;
  338. case N_DATA | N_EXT:
  339. ms_type = mst_data;
  340. section = SECT_OFF_DATA (objfile);
  341. break;
  342. case N_BSS | N_EXT:
  343. ms_type = mst_bss;
  344. section = SECT_OFF_BSS (objfile);
  345. break;
  346. case N_ABS | N_EXT:
  347. ms_type = mst_abs;
  348. section = -1;
  349. break;
  350. #ifdef N_SETV
  351. case N_SETV | N_EXT:
  352. ms_type = mst_data;
  353. section = SECT_OFF_DATA (objfile);
  354. break;
  355. case N_SETV:
  356. /* I don't think this type actually exists; since a N_SETV is the result
  357. of going over many .o files, it doesn't make sense to have one
  358. file local. */
  359. ms_type = mst_file_data;
  360. section = SECT_OFF_DATA (objfile);
  361. break;
  362. #endif
  363. case N_TEXT:
  364. case N_NBTEXT:
  365. case N_FN:
  366. case N_FN_SEQ:
  367. ms_type = mst_file_text;
  368. section = SECT_OFF_TEXT (objfile);
  369. break;
  370. case N_DATA:
  371. ms_type = mst_file_data;
  372. /* Check for __DYNAMIC, which is used by Sun shared libraries.
  373. Record it as global even if it's local, not global, so
  374. lookup_minimal_symbol can find it. We don't check symbol_leading_char
  375. because for SunOS4 it always is '_'. */
  376. if (name[8] == 'C' && strcmp ("__DYNAMIC", name) == 0)
  377. ms_type = mst_data;
  378. /* Same with virtual function tables, both global and static. */
  379. {
  380. const char *tempstring = name;
  381. if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
  382. ++tempstring;
  383. if (is_vtable_name (tempstring))
  384. ms_type = mst_data;
  385. }
  386. section = SECT_OFF_DATA (objfile);
  387. break;
  388. case N_BSS:
  389. ms_type = mst_file_bss;
  390. section = SECT_OFF_BSS (objfile);
  391. break;
  392. default:
  393. ms_type = mst_unknown;
  394. section = -1;
  395. break;
  396. }
  397. if ((ms_type == mst_file_text || ms_type == mst_text)
  398. && address < lowest_text_address)
  399. lowest_text_address = address;
  400. reader.record_with_info (name, address, ms_type, section);
  401. }
  402. /* Scan and build partial symbols for a symbol file.
  403. We have been initialized by a call to dbx_symfile_init, which
  404. put all the relevant info into a "struct dbx_symfile_info",
  405. hung off the objfile structure. */
  406. static void
  407. dbx_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
  408. {
  409. bfd *sym_bfd;
  410. int val;
  411. sym_bfd = objfile->obfd;
  412. /* .o and .nlm files are relocatables with text, data and bss segs based at
  413. 0. This flag disables special (Solaris stabs-in-elf only) fixups for
  414. symbols with a value of 0. */
  415. symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
  416. val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
  417. if (val < 0)
  418. perror_with_name (objfile_name (objfile));
  419. symbol_size = DBX_SYMBOL_SIZE (objfile);
  420. symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
  421. scoped_free_pendings free_pending;
  422. minimal_symbol_reader reader (objfile);
  423. /* Read stabs data from executable file and define symbols. */
  424. psymbol_functions *psf = new psymbol_functions ();
  425. psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
  426. objfile->qf.emplace_front (psf);
  427. read_dbx_symtab (reader, partial_symtabs, objfile);
  428. /* Install any minimal symbols that have been collected as the current
  429. minimal symbols for this objfile. */
  430. reader.install ();
  431. }
  432. /* Initialize anything that needs initializing when a completely new
  433. symbol file is specified (not just adding some symbols from another
  434. file, e.g. a shared library). */
  435. static void
  436. dbx_new_init (struct objfile *ignore)
  437. {
  438. stabsread_new_init ();
  439. init_header_files ();
  440. }
  441. /* dbx_symfile_init ()
  442. is the dbx-specific initialization routine for reading symbols.
  443. It is passed a struct objfile which contains, among other things,
  444. the BFD for the file whose symbols are being read, and a slot for a pointer
  445. to "private data" which we fill with goodies.
  446. We read the string table into malloc'd space and stash a pointer to it.
  447. Since BFD doesn't know how to read debug symbols in a format-independent
  448. way (and may never do so...), we have to do it ourselves. We will never
  449. be called unless this is an a.out (or very similar) file.
  450. FIXME, there should be a cleaner peephole into the BFD environment here. */
  451. #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
  452. static void
  453. dbx_symfile_init (struct objfile *objfile)
  454. {
  455. int val;
  456. bfd *sym_bfd = objfile->obfd;
  457. const char *name = bfd_get_filename (sym_bfd);
  458. asection *text_sect;
  459. unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
  460. /* Allocate struct to keep track of the symfile. */
  461. dbx_objfile_data_key.emplace (objfile);
  462. DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
  463. DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data");
  464. DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss");
  465. /* FIXME POKING INSIDE BFD DATA STRUCTURES. */
  466. #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
  467. #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
  468. /* FIXME POKING INSIDE BFD DATA STRUCTURES. */
  469. text_sect = bfd_get_section_by_name (sym_bfd, ".text");
  470. if (!text_sect)
  471. error (_("Can't find .text section in symbol file"));
  472. DBX_TEXT_ADDR (objfile) = bfd_section_vma (text_sect);
  473. DBX_TEXT_SIZE (objfile) = bfd_section_size (text_sect);
  474. DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);
  475. DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
  476. DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
  477. /* Read the string table and stash it away in the objfile_obstack.
  478. When we blow away the objfile the string table goes away as well.
  479. Note that gdb used to use the results of attempting to malloc the
  480. string table, based on the size it read, as a form of sanity check
  481. for botched byte swapping, on the theory that a byte swapped string
  482. table size would be so totally bogus that the malloc would fail. Now
  483. that we put in on the objfile_obstack, we can't do this since gdb gets
  484. a fatal error (out of virtual memory) if the size is bogus. We can
  485. however at least check to see if the size is less than the size of
  486. the size field itself, or larger than the size of the entire file.
  487. Note that all valid string tables have a size greater than zero, since
  488. the bytes used to hold the size are included in the count. */
  489. if (STRING_TABLE_OFFSET == 0)
  490. {
  491. /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
  492. will never be zero, even when there is no string table. This
  493. would appear to be a bug in bfd. */
  494. DBX_STRINGTAB_SIZE (objfile) = 0;
  495. DBX_STRINGTAB (objfile) = NULL;
  496. }
  497. else
  498. {
  499. val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
  500. if (val < 0)
  501. perror_with_name (name);
  502. memset (size_temp, 0, sizeof (size_temp));
  503. val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd);
  504. if (val < 0)
  505. {
  506. perror_with_name (name);
  507. }
  508. else if (val == 0)
  509. {
  510. /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
  511. EOF if there is no string table, and attempting to read the size
  512. from EOF will read zero bytes. */
  513. DBX_STRINGTAB_SIZE (objfile) = 0;
  514. DBX_STRINGTAB (objfile) = NULL;
  515. }
  516. else
  517. {
  518. /* Read some data that would appear to be the string table size.
  519. If there really is a string table, then it is probably the right
  520. size. Byteswap if necessary and validate the size. Note that
  521. the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
  522. random data that happened to be at STRING_TABLE_OFFSET, because
  523. bfd can't tell us there is no string table, the sanity checks may
  524. or may not catch this. */
  525. DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
  526. if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
  527. || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
  528. error (_("ridiculous string table size (%d bytes)."),
  529. DBX_STRINGTAB_SIZE (objfile));
  530. DBX_STRINGTAB (objfile) =
  531. (char *) obstack_alloc (&objfile->objfile_obstack,
  532. DBX_STRINGTAB_SIZE (objfile));
  533. OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile));
  534. /* Now read in the string table in one big gulp. */
  535. val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
  536. if (val < 0)
  537. perror_with_name (name);
  538. val = bfd_bread (DBX_STRINGTAB (objfile),
  539. DBX_STRINGTAB_SIZE (objfile),
  540. sym_bfd);
  541. if (val != DBX_STRINGTAB_SIZE (objfile))
  542. perror_with_name (name);
  543. }
  544. }
  545. }
  546. /* Perform any local cleanups required when we are done with a particular
  547. objfile. I.E, we are in the process of discarding all symbol information
  548. for an objfile, freeing up all memory held for it, and unlinking the
  549. objfile struct from the global list of known objfiles. */
  550. static void
  551. dbx_symfile_finish (struct objfile *objfile)
  552. {
  553. free_header_files ();
  554. }
  555. dbx_symfile_info::~dbx_symfile_info ()
  556. {
  557. if (header_files != NULL)
  558. {
  559. int i = n_header_files;
  560. struct header_file *hfiles = header_files;
  561. while (--i >= 0)
  562. {
  563. xfree (hfiles[i].name);
  564. xfree (hfiles[i].vector);
  565. }
  566. xfree (hfiles);
  567. }
  568. }
  569. /* Buffer for reading the symbol table entries. */
  570. static struct external_nlist symbuf[4096];
  571. static int symbuf_idx;
  572. static int symbuf_end;
  573. /* Name of last function encountered. Used in Solaris to approximate
  574. object file boundaries. */
  575. static const char *last_function_name;
  576. /* The address in memory of the string table of the object file we are
  577. reading (which might not be the "main" object file, but might be a
  578. shared library or some other dynamically loaded thing). This is
  579. set by read_dbx_symtab when building psymtabs, and by
  580. read_ofile_symtab when building symtabs, and is used only by
  581. next_symbol_text. FIXME: If that is true, we don't need it when
  582. building psymtabs, right? */
  583. static char *stringtab_global;
  584. /* These variables are used to control fill_symbuf when the stabs
  585. symbols are not contiguous (as may be the case when a COFF file is
  586. linked using --split-by-reloc). */
  587. static const std::vector<asection *> *symbuf_sections;
  588. static size_t sect_idx;
  589. static unsigned int symbuf_left;
  590. static unsigned int symbuf_read;
  591. /* This variable stores a global stabs buffer, if we read stabs into
  592. memory in one chunk in order to process relocations. */
  593. static bfd_byte *stabs_data;
  594. /* Refill the symbol table input buffer
  595. and set the variables that control fetching entries from it.
  596. Reports an error if no data available.
  597. This function can read past the end of the symbol table
  598. (into the string table) but this does no harm. */
  599. static void
  600. fill_symbuf (bfd *sym_bfd)
  601. {
  602. unsigned int count;
  603. int nbytes;
  604. if (stabs_data)
  605. {
  606. nbytes = sizeof (symbuf);
  607. if (nbytes > symbuf_left)
  608. nbytes = symbuf_left;
  609. memcpy (symbuf, stabs_data + symbuf_read, nbytes);
  610. }
  611. else if (symbuf_sections == NULL)
  612. {
  613. count = sizeof (symbuf);
  614. nbytes = bfd_bread (symbuf, count, sym_bfd);
  615. }
  616. else
  617. {
  618. if (symbuf_left <= 0)
  619. {
  620. file_ptr filepos = (*symbuf_sections)[sect_idx]->filepos;
  621. if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
  622. perror_with_name (bfd_get_filename (sym_bfd));
  623. symbuf_left = bfd_section_size ((*symbuf_sections)[sect_idx]);
  624. symbol_table_offset = filepos - symbuf_read;
  625. ++sect_idx;
  626. }
  627. count = symbuf_left;
  628. if (count > sizeof (symbuf))
  629. count = sizeof (symbuf);
  630. nbytes = bfd_bread (symbuf, count, sym_bfd);
  631. }
  632. if (nbytes < 0)
  633. perror_with_name (bfd_get_filename (sym_bfd));
  634. else if (nbytes == 0)
  635. error (_("Premature end of file reading symbol table"));
  636. symbuf_end = nbytes / symbol_size;
  637. symbuf_idx = 0;
  638. symbuf_left -= nbytes;
  639. symbuf_read += nbytes;
  640. }
  641. static void
  642. stabs_seek (int sym_offset)
  643. {
  644. if (stabs_data)
  645. {
  646. symbuf_read += sym_offset;
  647. symbuf_left -= sym_offset;
  648. }
  649. else
  650. bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
  651. }
  652. #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
  653. { \
  654. (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
  655. (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
  656. (intern).n_other = 0; \
  657. (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
  658. if (bfd_get_sign_extend_vma (abfd)) \
  659. (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \
  660. else \
  661. (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
  662. }
  663. /* Invariant: The symbol pointed to by symbuf_idx is the first one
  664. that hasn't been swapped. Swap the symbol at the same time
  665. that symbuf_idx is incremented. */
  666. /* dbx allows the text of a symbol name to be continued into the
  667. next symbol name! When such a continuation is encountered
  668. (a \ at the end of the text of a name)
  669. call this function to get the continuation. */
  670. static const char *
  671. dbx_next_symbol_text (struct objfile *objfile)
  672. {
  673. struct internal_nlist nlist;
  674. if (symbuf_idx == symbuf_end)
  675. fill_symbuf (symfile_bfd);
  676. symnum++;
  677. INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd);
  678. OBJSTAT (objfile, n_stabs++);
  679. symbuf_idx++;
  680. return nlist.n_strx + stringtab_global + file_string_table_offset;
  681. }
  682. /* Given a name, value pair, find the corresponding
  683. bincl in the list. Return the partial symtab associated
  684. with that header_file_location. */
  685. static legacy_psymtab *
  686. find_corresponding_bincl_psymtab (const char *name, int instance)
  687. {
  688. for (const header_file_location &bincl : *bincl_list)
  689. if (bincl.instance == instance
  690. && strcmp (name, bincl.name) == 0)
  691. return bincl.pst;
  692. repeated_header_complaint (name, symnum);
  693. return (legacy_psymtab *) 0;
  694. }
  695. /* Set namestring based on nlist. If the string table index is invalid,
  696. give a fake name, and print a single error message per symbol file read,
  697. rather than abort the symbol reading or flood the user with messages. */
  698. static const char *
  699. set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
  700. {
  701. const char *namestring;
  702. if (nlist->n_strx + file_string_table_offset
  703. >= DBX_STRINGTAB_SIZE (objfile)
  704. || nlist->n_strx + file_string_table_offset < nlist->n_strx)
  705. {
  706. complaint (_("bad string table offset in symbol %d"),
  707. symnum);
  708. namestring = "<bad string table offset>";
  709. }
  710. else
  711. namestring = (nlist->n_strx + file_string_table_offset
  712. + DBX_STRINGTAB (objfile));
  713. return namestring;
  714. }
  715. static struct bound_minimal_symbol
  716. find_stab_function (const char *namestring, const char *filename,
  717. struct objfile *objfile)
  718. {
  719. struct bound_minimal_symbol msym;
  720. int n;
  721. const char *colon = strchr (namestring, ':');
  722. if (colon == NULL)
  723. n = 0;
  724. else
  725. n = colon - namestring;
  726. char *p = (char *) alloca (n + 2);
  727. strncpy (p, namestring, n);
  728. p[n] = 0;
  729. msym = lookup_minimal_symbol (p, filename, objfile);
  730. if (msym.minsym == NULL)
  731. {
  732. /* Sun Fortran appends an underscore to the minimal symbol name,
  733. try again with an appended underscore if the minimal symbol
  734. was not found. */
  735. p[n] = '_';
  736. p[n + 1] = 0;
  737. msym = lookup_minimal_symbol (p, filename, objfile);
  738. }
  739. if (msym.minsym == NULL && filename != NULL)
  740. {
  741. /* Try again without the filename. */
  742. p[n] = 0;
  743. msym = lookup_minimal_symbol (p, NULL, objfile);
  744. }
  745. if (msym.minsym == NULL && filename != NULL)
  746. {
  747. /* And try again for Sun Fortran, but without the filename. */
  748. p[n] = '_';
  749. p[n + 1] = 0;
  750. msym = lookup_minimal_symbol (p, NULL, objfile);
  751. }
  752. return msym;
  753. }
  754. static void
  755. function_outside_compilation_unit_complaint (const char *arg1)
  756. {
  757. complaint (_("function `%s' appears to be defined "
  758. "outside of all compilation units"),
  759. arg1);
  760. }
  761. /* Setup partial_symtab's describing each source file for which
  762. debugging information is available. */
  763. static void
  764. read_dbx_symtab (minimal_symbol_reader &reader,
  765. psymtab_storage *partial_symtabs,
  766. struct objfile *objfile)
  767. {
  768. struct gdbarch *gdbarch = objfile->arch ();
  769. struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch. */
  770. struct internal_nlist nlist;
  771. CORE_ADDR text_addr;
  772. int text_size;
  773. const char *sym_name;
  774. int sym_len;
  775. const char *namestring;
  776. int nsl;
  777. int past_first_source_file = 0;
  778. CORE_ADDR last_function_start = 0;
  779. bfd *abfd;
  780. int textlow_not_set;
  781. int data_sect_index;
  782. /* Current partial symtab. */
  783. legacy_psymtab *pst;
  784. /* List of current psymtab's include files. */
  785. const char **psymtab_include_list;
  786. int includes_allocated;
  787. int includes_used;
  788. /* Index within current psymtab dependency list. */
  789. legacy_psymtab **dependency_list;
  790. int dependencies_used, dependencies_allocated;
  791. text_addr = DBX_TEXT_ADDR (objfile);
  792. text_size = DBX_TEXT_SIZE (objfile);
  793. /* FIXME. We probably want to change stringtab_global rather than add this
  794. while processing every symbol entry. FIXME. */
  795. file_string_table_offset = 0;
  796. next_file_string_table_offset = 0;
  797. stringtab_global = DBX_STRINGTAB (objfile);
  798. pst = (legacy_psymtab *) 0;
  799. includes_allocated = 30;
  800. includes_used = 0;
  801. psymtab_include_list = (const char **) alloca (includes_allocated *
  802. sizeof (const char *));
  803. dependencies_allocated = 30;
  804. dependencies_used = 0;
  805. dependency_list =
  806. (legacy_psymtab **) alloca (dependencies_allocated *
  807. sizeof (legacy_psymtab *));
  808. /* Init bincl list */
  809. std::vector<struct header_file_location> bincl_storage;
  810. scoped_restore restore_bincl_global
  811. = make_scoped_restore (&bincl_list, &bincl_storage);
  812. set_last_source_file (NULL);
  813. lowest_text_address = (CORE_ADDR) -1;
  814. symfile_bfd = objfile->obfd; /* For next_text_symbol. */
  815. abfd = objfile->obfd;
  816. symbuf_end = symbuf_idx = 0;
  817. next_symbol_text_func = dbx_next_symbol_text;
  818. textlow_not_set = 1;
  819. has_line_numbers = 0;
  820. /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
  821. to global and static variables. The stab for a global or static
  822. variable doesn't give us any indication of which section it's in,
  823. so we can't tell immediately which offset in
  824. objfile->section_offsets we should apply to the variable's
  825. address.
  826. We could certainly find out which section contains the variable
  827. by looking up the variable's unrelocated address with
  828. find_pc_section, but that would be expensive; this is the
  829. function that constructs the partial symbol tables by examining
  830. every symbol in the entire executable, and it's
  831. performance-critical. So that expense would not be welcome. I'm
  832. not sure what to do about this at the moment.
  833. What we have done for years is to simply assume that the .data
  834. section's offset is appropriate for all global and static
  835. variables. Recently, this was expanded to fall back to the .bss
  836. section's offset if there is no .data section, and then to the
  837. .rodata section's offset. */
  838. data_sect_index = objfile->sect_index_data;
  839. if (data_sect_index == -1)
  840. data_sect_index = SECT_OFF_BSS (objfile);
  841. if (data_sect_index == -1)
  842. data_sect_index = SECT_OFF_RODATA (objfile);
  843. /* If data_sect_index is still -1, that's okay. It's perfectly fine
  844. for the file to have no .data, no .bss, and no .text at all, if
  845. it also has no global or static variables. */
  846. for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
  847. {
  848. /* Get the symbol for this run and pull out some info. */
  849. QUIT; /* Allow this to be interruptable. */
  850. if (symbuf_idx == symbuf_end)
  851. fill_symbuf (abfd);
  852. bufp = &symbuf[symbuf_idx++];
  853. /*
  854. * Special case to speed up readin.
  855. */
  856. if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
  857. {
  858. has_line_numbers = 1;
  859. continue;
  860. }
  861. INTERNALIZE_SYMBOL (nlist, bufp, abfd);
  862. OBJSTAT (objfile, n_stabs++);
  863. /* Ok. There is a lot of code duplicated in the rest of this
  864. switch statement (for efficiency reasons). Since I don't
  865. like duplicating code, I will do my penance here, and
  866. describe the code which is duplicated:
  867. *) The assignment to namestring.
  868. *) The call to strchr.
  869. *) The addition of a partial symbol the two partial
  870. symbol lists. This last is a large section of code, so
  871. I've imbedded it in the following macro. */
  872. switch (nlist.n_type)
  873. {
  874. /*
  875. * Standard, external, non-debugger, symbols
  876. */
  877. case N_TEXT | N_EXT:
  878. case N_NBTEXT | N_EXT:
  879. goto record_it;
  880. case N_DATA | N_EXT:
  881. case N_NBDATA | N_EXT:
  882. goto record_it;
  883. case N_BSS:
  884. case N_BSS | N_EXT:
  885. case N_NBBSS | N_EXT:
  886. case N_SETV | N_EXT: /* FIXME, is this in BSS? */
  887. goto record_it;
  888. case N_ABS | N_EXT:
  889. record_it:
  890. namestring = set_namestring (objfile, &nlist);
  891. record_minimal_symbol (reader, namestring, nlist.n_value,
  892. nlist.n_type, objfile); /* Always */
  893. continue;
  894. /* Standard, local, non-debugger, symbols. */
  895. case N_NBTEXT:
  896. /* We need to be able to deal with both N_FN or N_TEXT,
  897. because we have no way of knowing whether the sys-supplied ld
  898. or GNU ld was used to make the executable. Sequents throw
  899. in another wrinkle -- they renumbered N_FN. */
  900. case N_FN:
  901. case N_FN_SEQ:
  902. case N_TEXT:
  903. namestring = set_namestring (objfile, &nlist);
  904. if ((namestring[0] == '-' && namestring[1] == 'l')
  905. || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
  906. && namestring[nsl - 2] == '.'))
  907. {
  908. if (past_first_source_file && pst
  909. /* The gould NP1 uses low values for .o and -l symbols
  910. which are not the address. */
  911. && nlist.n_value >= pst->raw_text_low ())
  912. {
  913. dbx_end_psymtab (objfile, partial_symtabs,
  914. pst, psymtab_include_list,
  915. includes_used, symnum * symbol_size,
  916. nlist.n_value > pst->raw_text_high ()
  917. ? nlist.n_value : pst->raw_text_high (),
  918. dependency_list, dependencies_used,
  919. textlow_not_set);
  920. pst = (legacy_psymtab *) 0;
  921. includes_used = 0;
  922. dependencies_used = 0;
  923. has_line_numbers = 0;
  924. }
  925. else
  926. past_first_source_file = 1;
  927. }
  928. else
  929. goto record_it;
  930. continue;
  931. case N_DATA:
  932. goto record_it;
  933. case N_UNDF | N_EXT:
  934. /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
  935. We used to rely on the target to tell us whether it knows
  936. where the symbol has been relocated to, but none of the
  937. target implementations actually provided that operation.
  938. So we just ignore the symbol, the same way we would do if
  939. we had a target-side symbol lookup which returned no match.
  940. All other symbols (with nlist.n_value == 0), are really
  941. undefined, and so we ignore them too. */
  942. continue;
  943. case N_UNDF:
  944. if (processing_acc_compilation && nlist.n_strx == 1)
  945. {
  946. /* Deal with relative offsets in the string table
  947. used in ELF+STAB under Solaris. If we want to use the
  948. n_strx field, which contains the name of the file,
  949. we must adjust file_string_table_offset *before* calling
  950. set_namestring(). */
  951. past_first_source_file = 1;
  952. file_string_table_offset = next_file_string_table_offset;
  953. next_file_string_table_offset =
  954. file_string_table_offset + nlist.n_value;
  955. if (next_file_string_table_offset < file_string_table_offset)
  956. error (_("string table offset backs up at %d"), symnum);
  957. /* FIXME -- replace error() with complaint. */
  958. continue;
  959. }
  960. continue;
  961. /* Lots of symbol types we can just ignore. */
  962. case N_ABS:
  963. case N_NBDATA:
  964. case N_NBBSS:
  965. continue;
  966. /* Keep going . . . */
  967. /*
  968. * Special symbol types for GNU
  969. */
  970. case N_INDR:
  971. case N_INDR | N_EXT:
  972. case N_SETA:
  973. case N_SETA | N_EXT:
  974. case N_SETT:
  975. case N_SETT | N_EXT:
  976. case N_SETD:
  977. case N_SETD | N_EXT:
  978. case N_SETB:
  979. case N_SETB | N_EXT:
  980. case N_SETV:
  981. continue;
  982. /*
  983. * Debugger symbols
  984. */
  985. case N_SO:
  986. {
  987. CORE_ADDR valu;
  988. static int prev_so_symnum = -10;
  989. static int first_so_symnum;
  990. const char *p;
  991. static const char *dirname_nso;
  992. int prev_textlow_not_set;
  993. valu = nlist.n_value;
  994. prev_textlow_not_set = textlow_not_set;
  995. /* A zero value is probably an indication for the SunPRO 3.0
  996. compiler. dbx_end_psymtab explicitly tests for zero, so
  997. don't relocate it. */
  998. if (nlist.n_value == 0
  999. && gdbarch_sofun_address_maybe_missing (gdbarch))
  1000. {
  1001. textlow_not_set = 1;
  1002. valu = 0;
  1003. }
  1004. else
  1005. textlow_not_set = 0;
  1006. past_first_source_file = 1;
  1007. if (prev_so_symnum != symnum - 1)
  1008. { /* Here if prev stab wasn't N_SO. */
  1009. first_so_symnum = symnum;
  1010. if (pst)
  1011. {
  1012. dbx_end_psymtab (objfile, partial_symtabs,
  1013. pst, psymtab_include_list,
  1014. includes_used, symnum * symbol_size,
  1015. (valu > pst->raw_text_high ()
  1016. ? valu : pst->raw_text_high ()),
  1017. dependency_list, dependencies_used,
  1018. prev_textlow_not_set);
  1019. pst = (legacy_psymtab *) 0;
  1020. includes_used = 0;
  1021. dependencies_used = 0;
  1022. has_line_numbers = 0;
  1023. }
  1024. }
  1025. prev_so_symnum = symnum;
  1026. /* End the current partial symtab and start a new one. */
  1027. namestring = set_namestring (objfile, &nlist);
  1028. /* Null name means end of .o file. Don't start a new one. */
  1029. if (*namestring == '\000')
  1030. continue;
  1031. /* Some compilers (including gcc) emit a pair of initial N_SOs.
  1032. The first one is a directory name; the second the file name.
  1033. If pst exists, is empty, and has a filename ending in '/',
  1034. we assume the previous N_SO was a directory name. */
  1035. p = lbasename (namestring);
  1036. if (p != namestring && *p == '\000')
  1037. {
  1038. /* Save the directory name SOs locally, then save it into
  1039. the psymtab when it's created below. */
  1040. dirname_nso = namestring;
  1041. continue;
  1042. }
  1043. /* Some other compilers (C++ ones in particular) emit useless
  1044. SOs for non-existant .c files. We ignore all subsequent SOs
  1045. that immediately follow the first. */
  1046. if (!pst)
  1047. {
  1048. pst = start_psymtab (partial_symtabs, objfile,
  1049. namestring, valu,
  1050. first_so_symnum * symbol_size);
  1051. pst->dirname = dirname_nso;
  1052. dirname_nso = NULL;
  1053. }
  1054. continue;
  1055. }
  1056. case N_BINCL:
  1057. {
  1058. enum language tmp_language;
  1059. /* Add this bincl to the bincl_list for future EXCLs. No
  1060. need to save the string; it'll be around until
  1061. read_dbx_symtab function returns. */
  1062. namestring = set_namestring (objfile, &nlist);
  1063. tmp_language = deduce_language_from_filename (namestring);
  1064. /* Only change the psymtab's language if we've learned
  1065. something useful (eg. tmp_language is not language_unknown).
  1066. In addition, to match what start_subfile does, never change
  1067. from C++ to C. */
  1068. if (tmp_language != language_unknown
  1069. && (tmp_language != language_c
  1070. || psymtab_language != language_cplus))
  1071. psymtab_language = tmp_language;
  1072. if (pst == NULL)
  1073. {
  1074. /* FIXME: we should not get here without a PST to work on.
  1075. Attempt to recover. */
  1076. complaint (_("N_BINCL %s not in entries for "
  1077. "any file, at symtab pos %d"),
  1078. namestring, symnum);
  1079. continue;
  1080. }
  1081. bincl_list->emplace_back (namestring, nlist.n_value, pst);
  1082. /* Mark down an include file in the current psymtab. */
  1083. goto record_include_file;
  1084. }
  1085. case N_SOL:
  1086. {
  1087. enum language tmp_language;
  1088. /* Mark down an include file in the current psymtab. */
  1089. namestring = set_namestring (objfile, &nlist);
  1090. tmp_language = deduce_language_from_filename (namestring);
  1091. /* Only change the psymtab's language if we've learned
  1092. something useful (eg. tmp_language is not language_unknown).
  1093. In addition, to match what start_subfile does, never change
  1094. from C++ to C. */
  1095. if (tmp_language != language_unknown
  1096. && (tmp_language != language_c
  1097. || psymtab_language != language_cplus))
  1098. psymtab_language = tmp_language;
  1099. /* In C++, one may expect the same filename to come round many
  1100. times, when code is coming alternately from the main file
  1101. and from inline functions in other files. So I check to see
  1102. if this is a file we've seen before -- either the main
  1103. source file, or a previously included file.
  1104. This seems to be a lot of time to be spending on N_SOL, but
  1105. things like "break c-exp.y:435" need to work (I
  1106. suppose the psymtab_include_list could be hashed or put
  1107. in a binary tree, if profiling shows this is a major hog). */
  1108. if (pst && filename_cmp (namestring, pst->filename) == 0)
  1109. continue;
  1110. {
  1111. int i;
  1112. for (i = 0; i < includes_used; i++)
  1113. if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
  1114. {
  1115. i = -1;
  1116. break;
  1117. }
  1118. if (i == -1)
  1119. continue;
  1120. }
  1121. record_include_file:
  1122. psymtab_include_list[includes_used++] = namestring;
  1123. if (includes_used >= includes_allocated)
  1124. {
  1125. const char **orig = psymtab_include_list;
  1126. psymtab_include_list = (const char **)
  1127. alloca ((includes_allocated *= 2) * sizeof (const char *));
  1128. memcpy (psymtab_include_list, orig,
  1129. includes_used * sizeof (const char *));
  1130. }
  1131. continue;
  1132. }
  1133. case N_LSYM: /* Typedef or automatic variable. */
  1134. case N_STSYM: /* Data seg var -- static. */
  1135. case N_LCSYM: /* BSS " */
  1136. case N_ROSYM: /* Read-only data seg var -- static. */
  1137. case N_NBSTS: /* Gould nobase. */
  1138. case N_NBLCS: /* symbols. */
  1139. case N_FUN:
  1140. case N_GSYM: /* Global (extern) variable; can be
  1141. data or bss (sigh FIXME). */
  1142. /* Following may probably be ignored; I'll leave them here
  1143. for now (until I do Pascal and Modula 2 extensions). */
  1144. case N_PC: /* I may or may not need this; I
  1145. suspect not. */
  1146. case N_M2C: /* I suspect that I can ignore this here. */
  1147. case N_SCOPE: /* Same. */
  1148. {
  1149. const char *p;
  1150. namestring = set_namestring (objfile, &nlist);
  1151. /* See if this is an end of function stab. */
  1152. if (pst && nlist.n_type == N_FUN && *namestring == '\000')
  1153. {
  1154. CORE_ADDR valu;
  1155. /* It's value is the size (in bytes) of the function for
  1156. function relative stabs, or the address of the function's
  1157. end for old style stabs. */
  1158. valu = nlist.n_value + last_function_start;
  1159. if (pst->raw_text_high () == 0 || valu > pst->raw_text_high ())
  1160. pst->set_text_high (valu);
  1161. break;
  1162. }
  1163. p = (char *) strchr (namestring, ':');
  1164. if (!p)
  1165. continue; /* Not a debugging symbol. */
  1166. sym_len = 0;
  1167. sym_name = NULL; /* pacify "gcc -Werror" */
  1168. if (psymtab_language == language_cplus)
  1169. {
  1170. std::string name (namestring, p - namestring);
  1171. gdb::unique_xmalloc_ptr<char> new_name
  1172. = cp_canonicalize_string (name.c_str ());
  1173. if (new_name != nullptr)
  1174. {
  1175. sym_len = strlen (new_name.get ());
  1176. sym_name = obstack_strdup (&objfile->objfile_obstack,
  1177. new_name.get ());
  1178. }
  1179. }
  1180. if (sym_len == 0)
  1181. {
  1182. sym_name = namestring;
  1183. sym_len = p - namestring;
  1184. }
  1185. /* Main processing section for debugging symbols which
  1186. the initial read through the symbol tables needs to worry
  1187. about. If we reach this point, the symbol which we are
  1188. considering is definitely one we are interested in.
  1189. p must also contain the (valid) index into the namestring
  1190. which indicates the debugging type symbol. */
  1191. switch (p[1])
  1192. {
  1193. case 'S':
  1194. if (pst != nullptr)
  1195. pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
  1196. VAR_DOMAIN, LOC_STATIC,
  1197. data_sect_index,
  1198. psymbol_placement::STATIC,
  1199. nlist.n_value, psymtab_language,
  1200. partial_symtabs, objfile);
  1201. else
  1202. complaint (_("static `%*s' appears to be defined "
  1203. "outside of all compilation units"),
  1204. sym_len, sym_name);
  1205. continue;
  1206. case 'G':
  1207. /* The addresses in these entries are reported to be
  1208. wrong. See the code that reads 'G's for symtabs. */
  1209. if (pst != nullptr)
  1210. pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
  1211. VAR_DOMAIN, LOC_STATIC,
  1212. data_sect_index,
  1213. psymbol_placement::GLOBAL,
  1214. nlist.n_value, psymtab_language,
  1215. partial_symtabs, objfile);
  1216. else
  1217. complaint (_("global `%*s' appears to be defined "
  1218. "outside of all compilation units"),
  1219. sym_len, sym_name);
  1220. continue;
  1221. case 'T':
  1222. /* When a 'T' entry is defining an anonymous enum, it
  1223. may have a name which is the empty string, or a
  1224. single space. Since they're not really defining a
  1225. symbol, those shouldn't go in the partial symbol
  1226. table. We do pick up the elements of such enums at
  1227. 'check_enum:', below. */
  1228. if (p >= namestring + 2
  1229. || (p == namestring + 1
  1230. && namestring[0] != ' '))
  1231. {
  1232. if (pst != nullptr)
  1233. pst->add_psymbol (gdb::string_view (sym_name, sym_len),
  1234. true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
  1235. psymbol_placement::STATIC,
  1236. 0, psymtab_language,
  1237. partial_symtabs, objfile);
  1238. else
  1239. complaint (_("enum, struct, or union `%*s' appears "
  1240. "to be defined outside of all "
  1241. "compilation units"),
  1242. sym_len, sym_name);
  1243. if (p[2] == 't')
  1244. {
  1245. /* Also a typedef with the same name. */
  1246. if (pst != nullptr)
  1247. pst->add_psymbol (gdb::string_view (sym_name, sym_len),
  1248. true, VAR_DOMAIN, LOC_TYPEDEF, -1,
  1249. psymbol_placement::STATIC,
  1250. 0, psymtab_language,
  1251. partial_symtabs, objfile);
  1252. else
  1253. complaint (_("typedef `%*s' appears to be defined "
  1254. "outside of all compilation units"),
  1255. sym_len, sym_name);
  1256. p += 1;
  1257. }
  1258. }
  1259. goto check_enum;
  1260. case 't':
  1261. if (p != namestring) /* a name is there, not just :T... */
  1262. {
  1263. if (pst != nullptr)
  1264. pst->add_psymbol (gdb::string_view (sym_name, sym_len),
  1265. true, VAR_DOMAIN, LOC_TYPEDEF, -1,
  1266. psymbol_placement::STATIC,
  1267. 0, psymtab_language,
  1268. partial_symtabs, objfile);
  1269. else
  1270. complaint (_("typename `%*s' appears to be defined "
  1271. "outside of all compilation units"),
  1272. sym_len, sym_name);
  1273. }
  1274. check_enum:
  1275. /* If this is an enumerated type, we need to
  1276. add all the enum constants to the partial symbol
  1277. table. This does not cover enums without names, e.g.
  1278. "enum {a, b} c;" in C, but fortunately those are
  1279. rare. There is no way for GDB to find those from the
  1280. enum type without spending too much time on it. Thus
  1281. to solve this problem, the compiler needs to put out the
  1282. enum in a nameless type. GCC2 does this. */
  1283. /* We are looking for something of the form
  1284. <name> ":" ("t" | "T") [<number> "="] "e"
  1285. {<constant> ":" <value> ","} ";". */
  1286. /* Skip over the colon and the 't' or 'T'. */
  1287. p += 2;
  1288. /* This type may be given a number. Also, numbers can come
  1289. in pairs like (0,26). Skip over it. */
  1290. while ((*p >= '0' && *p <= '9')
  1291. || *p == '(' || *p == ',' || *p == ')'
  1292. || *p == '=')
  1293. p++;
  1294. if (*p++ == 'e')
  1295. {
  1296. /* The aix4 compiler emits extra crud before the members. */
  1297. if (*p == '-')
  1298. {
  1299. /* Skip over the type (?). */
  1300. while (*p != ':')
  1301. p++;
  1302. /* Skip over the colon. */
  1303. p++;
  1304. }
  1305. /* We have found an enumerated type. */
  1306. /* According to comments in read_enum_type
  1307. a comma could end it instead of a semicolon.
  1308. I don't know where that happens.
  1309. Accept either. */
  1310. while (*p && *p != ';' && *p != ',')
  1311. {
  1312. const char *q;
  1313. /* Check for and handle cretinous dbx symbol name
  1314. continuation! */
  1315. if (*p == '\\' || (*p == '?' && p[1] == '\0'))
  1316. p = next_symbol_text (objfile);
  1317. /* Point to the character after the name
  1318. of the enum constant. */
  1319. for (q = p; *q && *q != ':'; q++)
  1320. ;
  1321. /* Note that the value doesn't matter for
  1322. enum constants in psymtabs, just in symtabs. */
  1323. if (pst != nullptr)
  1324. pst->add_psymbol (gdb::string_view (p, q - p), true,
  1325. VAR_DOMAIN, LOC_CONST, -1,
  1326. psymbol_placement::STATIC, 0,
  1327. psymtab_language,
  1328. partial_symtabs, objfile);
  1329. else
  1330. complaint (_("enum constant `%*s' appears to be defined "
  1331. "outside of all compilation units"),
  1332. ((int) (q - p)), p);
  1333. /* Point past the name. */
  1334. p = q;
  1335. /* Skip over the value. */
  1336. while (*p && *p != ',')
  1337. p++;
  1338. /* Advance past the comma. */
  1339. if (*p)
  1340. p++;
  1341. }
  1342. }
  1343. continue;
  1344. case 'c':
  1345. /* Constant, e.g. from "const" in Pascal. */
  1346. if (pst != nullptr)
  1347. pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
  1348. VAR_DOMAIN, LOC_CONST, -1,
  1349. psymbol_placement::STATIC, 0,
  1350. psymtab_language,
  1351. partial_symtabs, objfile);
  1352. else
  1353. complaint (_("constant `%*s' appears to be defined "
  1354. "outside of all compilation units"),
  1355. sym_len, sym_name);
  1356. continue;
  1357. case 'f':
  1358. if (! pst)
  1359. {
  1360. std::string name (namestring, (p - namestring));
  1361. function_outside_compilation_unit_complaint (name.c_str ());
  1362. }
  1363. /* Kludges for ELF/STABS with Sun ACC. */
  1364. last_function_name = namestring;
  1365. /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
  1366. value for the bottom of the text seg in those cases. */
  1367. if (nlist.n_value == 0
  1368. && gdbarch_sofun_address_maybe_missing (gdbarch))
  1369. {
  1370. struct bound_minimal_symbol minsym
  1371. = find_stab_function (namestring,
  1372. pst ? pst->filename : NULL,
  1373. objfile);
  1374. if (minsym.minsym != NULL)
  1375. nlist.n_value = MSYMBOL_VALUE_RAW_ADDRESS (minsym.minsym);
  1376. }
  1377. if (pst && textlow_not_set
  1378. && gdbarch_sofun_address_maybe_missing (gdbarch))
  1379. {
  1380. pst->set_text_low (nlist.n_value);
  1381. textlow_not_set = 0;
  1382. }
  1383. /* End kludge. */
  1384. /* Keep track of the start of the last function so we
  1385. can handle end of function symbols. */
  1386. last_function_start = nlist.n_value;
  1387. /* In reordered executables this function may lie outside
  1388. the bounds created by N_SO symbols. If that's the case
  1389. use the address of this function as the low bound for
  1390. the partial symbol table. */
  1391. if (pst
  1392. && (textlow_not_set
  1393. || (nlist.n_value < pst->raw_text_low ()
  1394. && (nlist.n_value != 0))))
  1395. {
  1396. pst->set_text_low (nlist.n_value);
  1397. textlow_not_set = 0;
  1398. }
  1399. if (pst != nullptr)
  1400. pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
  1401. VAR_DOMAIN, LOC_BLOCK,
  1402. SECT_OFF_TEXT (objfile),
  1403. psymbol_placement::STATIC,
  1404. nlist.n_value, psymtab_language,
  1405. partial_symtabs, objfile);
  1406. continue;
  1407. /* Global functions were ignored here, but now they
  1408. are put into the global psymtab like one would expect.
  1409. They're also in the minimal symbol table. */
  1410. case 'F':
  1411. if (! pst)
  1412. {
  1413. std::string name (namestring, (p - namestring));
  1414. function_outside_compilation_unit_complaint (name.c_str ());
  1415. }
  1416. /* Kludges for ELF/STABS with Sun ACC. */
  1417. last_function_name = namestring;
  1418. /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
  1419. value for the bottom of the text seg in those cases. */
  1420. if (nlist.n_value == 0
  1421. && gdbarch_sofun_address_maybe_missing (gdbarch))
  1422. {
  1423. struct bound_minimal_symbol minsym
  1424. = find_stab_function (namestring,
  1425. pst ? pst->filename : NULL,
  1426. objfile);
  1427. if (minsym.minsym != NULL)
  1428. nlist.n_value = MSYMBOL_VALUE_RAW_ADDRESS (minsym.minsym);
  1429. }
  1430. if (pst && textlow_not_set
  1431. && gdbarch_sofun_address_maybe_missing (gdbarch))
  1432. {
  1433. pst->set_text_low (nlist.n_value);
  1434. textlow_not_set = 0;
  1435. }
  1436. /* End kludge. */
  1437. /* Keep track of the start of the last function so we
  1438. can handle end of function symbols. */
  1439. last_function_start = nlist.n_value;
  1440. /* In reordered executables this function may lie outside
  1441. the bounds created by N_SO symbols. If that's the case
  1442. use the address of this function as the low bound for
  1443. the partial symbol table. */
  1444. if (pst
  1445. && (textlow_not_set
  1446. || (nlist.n_value < pst->raw_text_low ()
  1447. && (nlist.n_value != 0))))
  1448. {
  1449. pst->set_text_low (nlist.n_value);
  1450. textlow_not_set = 0;
  1451. }
  1452. if (pst != nullptr)
  1453. pst->add_psymbol (gdb::string_view (sym_name, sym_len), true,
  1454. VAR_DOMAIN, LOC_BLOCK,
  1455. SECT_OFF_TEXT (objfile),
  1456. psymbol_placement::GLOBAL,
  1457. nlist.n_value, psymtab_language,
  1458. partial_symtabs, objfile);
  1459. continue;
  1460. /* Two things show up here (hopefully); static symbols of
  1461. local scope (static used inside braces) or extensions
  1462. of structure symbols. We can ignore both. */
  1463. case 'V':
  1464. case '(':
  1465. case '0':
  1466. case '1':
  1467. case '2':
  1468. case '3':
  1469. case '4':
  1470. case '5':
  1471. case '6':
  1472. case '7':
  1473. case '8':
  1474. case '9':
  1475. case '-':
  1476. case '#': /* For symbol identification (used in live ranges). */
  1477. continue;
  1478. case ':':
  1479. /* It is a C++ nested symbol. We don't need to record it
  1480. (I don't think); if we try to look up foo::bar::baz,
  1481. then symbols for the symtab containing foo should get
  1482. read in, I think. */
  1483. /* Someone says sun cc puts out symbols like
  1484. /foo/baz/maclib::/usr/local/bin/maclib,
  1485. which would get here with a symbol type of ':'. */
  1486. continue;
  1487. default:
  1488. /* Unexpected symbol descriptor. The second and subsequent stabs
  1489. of a continued stab can show up here. The question is
  1490. whether they ever can mimic a normal stab--it would be
  1491. nice if not, since we certainly don't want to spend the
  1492. time searching to the end of every string looking for
  1493. a backslash. */
  1494. complaint (_("unknown symbol descriptor `%c'"),
  1495. p[1]);
  1496. /* Ignore it; perhaps it is an extension that we don't
  1497. know about. */
  1498. continue;
  1499. }
  1500. }
  1501. case N_EXCL:
  1502. namestring = set_namestring (objfile, &nlist);
  1503. /* Find the corresponding bincl and mark that psymtab on the
  1504. psymtab dependency list. */
  1505. {
  1506. legacy_psymtab *needed_pst =
  1507. find_corresponding_bincl_psymtab (namestring, nlist.n_value);
  1508. /* If this include file was defined earlier in this file,
  1509. leave it alone. */
  1510. if (needed_pst == pst)
  1511. continue;
  1512. if (needed_pst)
  1513. {
  1514. int i;
  1515. int found = 0;
  1516. for (i = 0; i < dependencies_used; i++)
  1517. if (dependency_list[i] == needed_pst)
  1518. {
  1519. found = 1;
  1520. break;
  1521. }
  1522. /* If it's already in the list, skip the rest. */
  1523. if (found)
  1524. continue;
  1525. dependency_list[dependencies_used++] = needed_pst;
  1526. if (dependencies_used >= dependencies_allocated)
  1527. {
  1528. legacy_psymtab **orig = dependency_list;
  1529. dependency_list =
  1530. (legacy_psymtab **)
  1531. alloca ((dependencies_allocated *= 2)
  1532. * sizeof (legacy_psymtab *));
  1533. memcpy (dependency_list, orig,
  1534. (dependencies_used
  1535. * sizeof (legacy_psymtab *)));
  1536. #ifdef DEBUG_INFO
  1537. gdb_printf (gdb_stderr,
  1538. "Had to reallocate "
  1539. "dependency list.\n");
  1540. gdb_printf (gdb_stderr,
  1541. "New dependencies allocated: %d\n",
  1542. dependencies_allocated);
  1543. #endif
  1544. }
  1545. }
  1546. }
  1547. continue;
  1548. case N_ENDM:
  1549. /* Solaris 2 end of module, finish current partial symbol
  1550. table. dbx_end_psymtab will set the high text address of
  1551. PST to the proper value, which is necessary if a module
  1552. compiled without debugging info follows this module. */
  1553. if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
  1554. {
  1555. dbx_end_psymtab (objfile, partial_symtabs, pst,
  1556. psymtab_include_list, includes_used,
  1557. symnum * symbol_size,
  1558. (CORE_ADDR) 0, dependency_list,
  1559. dependencies_used, textlow_not_set);
  1560. pst = (legacy_psymtab *) 0;
  1561. includes_used = 0;
  1562. dependencies_used = 0;
  1563. has_line_numbers = 0;
  1564. }
  1565. continue;
  1566. case N_RBRAC:
  1567. #ifdef HANDLE_RBRAC
  1568. HANDLE_RBRAC (nlist.n_value);
  1569. continue;
  1570. #endif
  1571. case N_EINCL:
  1572. case N_DSLINE:
  1573. case N_BSLINE:
  1574. case N_SSYM: /* Claim: Structure or union element.
  1575. Hopefully, I can ignore this. */
  1576. case N_ENTRY: /* Alternate entry point; can ignore. */
  1577. case N_MAIN: /* Can definitely ignore this. */
  1578. case N_CATCH: /* These are GNU C++ extensions */
  1579. case N_EHDECL: /* that can safely be ignored here. */
  1580. case N_LENG:
  1581. case N_BCOMM:
  1582. case N_ECOMM:
  1583. case N_ECOML:
  1584. case N_FNAME:
  1585. case N_SLINE:
  1586. case N_RSYM:
  1587. case N_PSYM:
  1588. case N_BNSYM:
  1589. case N_ENSYM:
  1590. case N_LBRAC:
  1591. case N_NSYMS: /* Ultrix 4.0: symbol count */
  1592. case N_DEFD: /* GNU Modula-2 */
  1593. case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
  1594. case N_OBJ: /* Useless types from Solaris. */
  1595. case N_OPT:
  1596. case N_PATCH:
  1597. /* These symbols aren't interesting; don't worry about them. */
  1598. continue;
  1599. default:
  1600. /* If we haven't found it yet, ignore it. It's probably some
  1601. new type we don't know about yet. */
  1602. unknown_symtype_complaint (hex_string (nlist.n_type));
  1603. continue;
  1604. }
  1605. }
  1606. /* If there's stuff to be cleaned up, clean it up. */
  1607. if (pst)
  1608. {
  1609. /* Don't set high text address of PST lower than it already
  1610. is. */
  1611. CORE_ADDR text_end =
  1612. (lowest_text_address == (CORE_ADDR) -1
  1613. ? text_addr
  1614. : lowest_text_address)
  1615. + text_size;
  1616. dbx_end_psymtab (objfile, partial_symtabs,
  1617. pst, psymtab_include_list, includes_used,
  1618. symnum * symbol_size,
  1619. (text_end > pst->raw_text_high ()
  1620. ? text_end : pst->raw_text_high ()),
  1621. dependency_list, dependencies_used, textlow_not_set);
  1622. }
  1623. }
  1624. /* Allocate and partially fill a partial symtab. It will be
  1625. completely filled at the end of the symbol list.
  1626. SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
  1627. is the address relative to which its symbols are (incremental) or 0
  1628. (normal). */
  1629. static legacy_psymtab *
  1630. start_psymtab (psymtab_storage *partial_symtabs, struct objfile *objfile,
  1631. const char *filename, CORE_ADDR textlow, int ldsymoff)
  1632. {
  1633. legacy_psymtab *result = new legacy_psymtab (filename, partial_symtabs,
  1634. objfile->per_bfd, textlow);
  1635. result->read_symtab_private =
  1636. XOBNEW (&objfile->objfile_obstack, struct symloc);
  1637. LDSYMOFF (result) = ldsymoff;
  1638. result->legacy_read_symtab = dbx_read_symtab;
  1639. result->legacy_expand_psymtab = dbx_expand_psymtab;
  1640. SYMBOL_SIZE (result) = symbol_size;
  1641. SYMBOL_OFFSET (result) = symbol_table_offset;
  1642. STRING_OFFSET (result) = string_table_offset;
  1643. FILE_STRING_OFFSET (result) = file_string_table_offset;
  1644. /* Deduce the source language from the filename for this psymtab. */
  1645. psymtab_language = deduce_language_from_filename (filename);
  1646. PST_LANGUAGE (result) = psymtab_language;
  1647. return result;
  1648. }
  1649. /* Close off the current usage of PST.
  1650. Returns PST or NULL if the partial symtab was empty and thrown away.
  1651. FIXME: List variables and peculiarities of same. */
  1652. legacy_psymtab *
  1653. dbx_end_psymtab (struct objfile *objfile, psymtab_storage *partial_symtabs,
  1654. legacy_psymtab *pst,
  1655. const char **include_list, int num_includes,
  1656. int capping_symbol_offset, CORE_ADDR capping_text,
  1657. legacy_psymtab **dependency_list,
  1658. int number_dependencies,
  1659. int textlow_not_set)
  1660. {
  1661. int i;
  1662. struct gdbarch *gdbarch = objfile->arch ();
  1663. if (capping_symbol_offset != -1)
  1664. LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
  1665. pst->set_text_high (capping_text);
  1666. /* Under Solaris, the N_SO symbols always have a value of 0,
  1667. instead of the usual address of the .o file. Therefore,
  1668. we have to do some tricks to fill in texthigh and textlow.
  1669. The first trick is: if we see a static
  1670. or global function, and the textlow for the current pst
  1671. is not set (ie: textlow_not_set), then we use that function's
  1672. address for the textlow of the pst. */
  1673. /* Now, to fill in texthigh, we remember the last function seen
  1674. in the .o file. Also, there's a hack in
  1675. bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
  1676. to here via the misc_info field. Therefore, we can fill in
  1677. a reliable texthigh by taking the address plus size of the
  1678. last function in the file. */
  1679. if (!pst->text_high_valid && last_function_name
  1680. && gdbarch_sofun_address_maybe_missing (gdbarch))
  1681. {
  1682. int n;
  1683. struct bound_minimal_symbol minsym;
  1684. const char *colon = strchr (last_function_name, ':');
  1685. if (colon == NULL)
  1686. n = 0;
  1687. else
  1688. n = colon - last_function_name;
  1689. char *p = (char *) alloca (n + 2);
  1690. strncpy (p, last_function_name, n);
  1691. p[n] = 0;
  1692. minsym = lookup_minimal_symbol (p, pst->filename, objfile);
  1693. if (minsym.minsym == NULL)
  1694. {
  1695. /* Sun Fortran appends an underscore to the minimal symbol name,
  1696. try again with an appended underscore if the minimal symbol
  1697. was not found. */
  1698. p[n] = '_';
  1699. p[n + 1] = 0;
  1700. minsym = lookup_minimal_symbol (p, pst->filename, objfile);
  1701. }
  1702. if (minsym.minsym)
  1703. pst->set_text_high (MSYMBOL_VALUE_RAW_ADDRESS (minsym.minsym)
  1704. + MSYMBOL_SIZE (minsym.minsym));
  1705. last_function_name = NULL;
  1706. }
  1707. if (!gdbarch_sofun_address_maybe_missing (gdbarch))
  1708. ;
  1709. /* This test will be true if the last .o file is only data. */
  1710. else if (textlow_not_set)
  1711. pst->set_text_low (pst->raw_text_high ());
  1712. else
  1713. {
  1714. /* If we know our own starting text address, then walk through all other
  1715. psymtabs for this objfile, and if any didn't know their ending text
  1716. address, set it to our starting address. Take care to not set our
  1717. own ending address to our starting address. */
  1718. for (partial_symtab *p1 : partial_symtabs->range ())
  1719. if (!p1->text_high_valid && p1->text_low_valid && p1 != pst)
  1720. p1->set_text_high (pst->raw_text_low ());
  1721. }
  1722. /* End of kludge for patching Solaris textlow and texthigh. */
  1723. pst->end ();
  1724. pst->number_of_dependencies = number_dependencies;
  1725. if (number_dependencies)
  1726. {
  1727. pst->dependencies
  1728. = partial_symtabs->allocate_dependencies (number_dependencies);
  1729. memcpy (pst->dependencies, dependency_list,
  1730. number_dependencies * sizeof (legacy_psymtab *));
  1731. }
  1732. else
  1733. pst->dependencies = 0;
  1734. for (i = 0; i < num_includes; i++)
  1735. {
  1736. legacy_psymtab *subpst =
  1737. new legacy_psymtab (include_list[i], partial_symtabs, objfile->per_bfd);
  1738. subpst->read_symtab_private =
  1739. XOBNEW (&objfile->objfile_obstack, struct symloc);
  1740. LDSYMOFF (subpst) =
  1741. LDSYMLEN (subpst) = 0;
  1742. /* We could save slight bits of space by only making one of these,
  1743. shared by the entire set of include files. FIXME-someday. */
  1744. subpst->dependencies =
  1745. partial_symtabs->allocate_dependencies (1);
  1746. subpst->dependencies[0] = pst;
  1747. subpst->number_of_dependencies = 1;
  1748. subpst->legacy_read_symtab = pst->legacy_read_symtab;
  1749. subpst->legacy_expand_psymtab = pst->legacy_expand_psymtab;
  1750. }
  1751. if (num_includes == 0
  1752. && number_dependencies == 0
  1753. && pst->empty ()
  1754. && has_line_numbers == 0)
  1755. {
  1756. /* Throw away this psymtab, it's empty. */
  1757. /* Empty psymtabs happen as a result of header files which don't have
  1758. any symbols in them. There can be a lot of them. But this check
  1759. is wrong, in that a psymtab with N_SLINE entries but nothing else
  1760. is not empty, but we don't realize that. Fixing that without slowing
  1761. things down might be tricky. */
  1762. partial_symtabs->discard_psymtab (pst);
  1763. /* Indicate that psymtab was thrown away. */
  1764. pst = NULL;
  1765. }
  1766. return pst;
  1767. }
  1768. static void
  1769. dbx_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
  1770. {
  1771. gdb_assert (!pst->readin);
  1772. /* Read in all partial symtabs on which this one is dependent. */
  1773. pst->expand_dependencies (objfile);
  1774. if (LDSYMLEN (pst)) /* Otherwise it's a dummy. */
  1775. {
  1776. /* Init stuff necessary for reading in symbols */
  1777. stabsread_init ();
  1778. scoped_free_pendings free_pending;
  1779. file_string_table_offset = FILE_STRING_OFFSET (pst);
  1780. symbol_size = SYMBOL_SIZE (pst);
  1781. /* Read in this file's symbols. */
  1782. bfd_seek (objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
  1783. read_ofile_symtab (objfile, pst);
  1784. }
  1785. pst->readin = true;
  1786. }
  1787. /* Read in all of the symbols for a given psymtab for real.
  1788. Be verbose about it if the user wants that. SELF is not NULL. */
  1789. static void
  1790. dbx_read_symtab (legacy_psymtab *self, struct objfile *objfile)
  1791. {
  1792. gdb_assert (!self->readin);
  1793. if (LDSYMLEN (self) || self->number_of_dependencies)
  1794. {
  1795. next_symbol_text_func = dbx_next_symbol_text;
  1796. {
  1797. scoped_restore restore_stabs_data = make_scoped_restore (&stabs_data);
  1798. gdb::unique_xmalloc_ptr<gdb_byte> data_holder;
  1799. if (DBX_STAB_SECTION (objfile))
  1800. {
  1801. stabs_data
  1802. = symfile_relocate_debug_section (objfile,
  1803. DBX_STAB_SECTION (objfile),
  1804. NULL);
  1805. data_holder.reset (stabs_data);
  1806. }
  1807. self->expand_psymtab (objfile);
  1808. }
  1809. /* Match with global symbols. This only needs to be done once,
  1810. after all of the symtabs and dependencies have been read in. */
  1811. scan_file_globals (objfile);
  1812. }
  1813. }
  1814. /* Read in a defined section of a specific object file's symbols. */
  1815. static void
  1816. read_ofile_symtab (struct objfile *objfile, legacy_psymtab *pst)
  1817. {
  1818. const char *namestring;
  1819. struct external_nlist *bufp;
  1820. struct internal_nlist nlist;
  1821. unsigned char type;
  1822. unsigned max_symnum;
  1823. bfd *abfd;
  1824. int sym_offset; /* Offset to start of symbols to read */
  1825. int sym_size; /* Size of symbols to read */
  1826. CORE_ADDR text_offset; /* Start of text segment for symbols */
  1827. int text_size; /* Size of text segment for symbols */
  1828. sym_offset = LDSYMOFF (pst);
  1829. sym_size = LDSYMLEN (pst);
  1830. text_offset = pst->text_low (objfile);
  1831. text_size = pst->text_high (objfile) - pst->text_low (objfile);
  1832. const section_offsets &section_offsets = objfile->section_offsets;
  1833. dbxread_objfile = objfile;
  1834. stringtab_global = DBX_STRINGTAB (objfile);
  1835. set_last_source_file (NULL);
  1836. abfd = objfile->obfd;
  1837. symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol. */
  1838. symbuf_end = symbuf_idx = 0;
  1839. symbuf_read = 0;
  1840. symbuf_left = sym_offset + sym_size;
  1841. /* It is necessary to actually read one symbol *before* the start
  1842. of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
  1843. occurs before the N_SO symbol.
  1844. Detecting this in read_dbx_symtab
  1845. would slow down initial readin, so we look for it here instead. */
  1846. if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
  1847. {
  1848. stabs_seek (sym_offset - symbol_size);
  1849. fill_symbuf (abfd);
  1850. bufp = &symbuf[symbuf_idx++];
  1851. INTERNALIZE_SYMBOL (nlist, bufp, abfd);
  1852. OBJSTAT (objfile, n_stabs++);
  1853. namestring = set_namestring (objfile, &nlist);
  1854. processing_gcc_compilation = 0;
  1855. if (nlist.n_type == N_TEXT)
  1856. {
  1857. const char *tempstring = namestring;
  1858. if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
  1859. processing_gcc_compilation = 1;
  1860. else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
  1861. processing_gcc_compilation = 2;
  1862. if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
  1863. ++tempstring;
  1864. if (startswith (tempstring, "__gnu_compiled"))
  1865. processing_gcc_compilation = 2;
  1866. }
  1867. }
  1868. else
  1869. {
  1870. /* The N_SO starting this symtab is the first symbol, so we
  1871. better not check the symbol before it. I'm not this can
  1872. happen, but it doesn't hurt to check for it. */
  1873. stabs_seek (sym_offset);
  1874. processing_gcc_compilation = 0;
  1875. }
  1876. if (symbuf_idx == symbuf_end)
  1877. fill_symbuf (abfd);
  1878. bufp = &symbuf[symbuf_idx];
  1879. if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
  1880. error (_("First symbol in segment of executable not a source symbol"));
  1881. max_symnum = sym_size / symbol_size;
  1882. for (symnum = 0;
  1883. symnum < max_symnum;
  1884. symnum++)
  1885. {
  1886. QUIT; /* Allow this to be interruptable. */
  1887. if (symbuf_idx == symbuf_end)
  1888. fill_symbuf (abfd);
  1889. bufp = &symbuf[symbuf_idx++];
  1890. INTERNALIZE_SYMBOL (nlist, bufp, abfd);
  1891. OBJSTAT (objfile, n_stabs++);
  1892. type = bfd_h_get_8 (abfd, bufp->e_type);
  1893. namestring = set_namestring (objfile, &nlist);
  1894. if (type & N_STAB)
  1895. {
  1896. if (sizeof (nlist.n_value) > 4
  1897. /* We are a 64-bit debugger debugging a 32-bit program. */
  1898. && (type == N_LSYM || type == N_PSYM))
  1899. /* We have to be careful with the n_value in the case of N_LSYM
  1900. and N_PSYM entries, because they are signed offsets from frame
  1901. pointer, but we actually read them as unsigned 32-bit values.
  1902. This is not a problem for 32-bit debuggers, for which negative
  1903. values end up being interpreted correctly (as negative
  1904. offsets) due to integer overflow.
  1905. But we need to sign-extend the value for 64-bit debuggers,
  1906. or we'll end up interpreting negative values as very large
  1907. positive offsets. */
  1908. nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
  1909. process_one_symbol (type, nlist.n_desc, nlist.n_value,
  1910. namestring, section_offsets, objfile,
  1911. PST_LANGUAGE (pst));
  1912. }
  1913. /* We skip checking for a new .o or -l file; that should never
  1914. happen in this routine. */
  1915. else if (type == N_TEXT)
  1916. {
  1917. /* I don't think this code will ever be executed, because
  1918. the GCC_COMPILED_FLAG_SYMBOL usually is right before
  1919. the N_SO symbol which starts this source file.
  1920. However, there is no reason not to accept
  1921. the GCC_COMPILED_FLAG_SYMBOL anywhere. */
  1922. if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
  1923. processing_gcc_compilation = 1;
  1924. else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
  1925. processing_gcc_compilation = 2;
  1926. }
  1927. else if (type & N_EXT || type == (unsigned char) N_TEXT
  1928. || type == (unsigned char) N_NBTEXT)
  1929. {
  1930. /* Global symbol: see if we came across a dbx definition for
  1931. a corresponding symbol. If so, store the value. Remove
  1932. syms from the chain when their values are stored, but
  1933. search the whole chain, as there may be several syms from
  1934. different files with the same name. */
  1935. /* This is probably not true. Since the files will be read
  1936. in one at a time, each reference to a global symbol will
  1937. be satisfied in each file as it appears. So we skip this
  1938. section. */
  1939. ;
  1940. }
  1941. }
  1942. /* In a Solaris elf file, this variable, which comes from the value
  1943. of the N_SO symbol, will still be 0. Luckily, text_offset, which
  1944. comes from low text address of PST, is correct. */
  1945. if (get_last_source_start_addr () == 0)
  1946. set_last_source_start_addr (text_offset);
  1947. /* In reordered executables last_source_start_addr may not be the
  1948. lower bound for this symtab, instead use text_offset which comes
  1949. from the low text address of PST, which is correct. */
  1950. if (get_last_source_start_addr () > text_offset)
  1951. set_last_source_start_addr (text_offset);
  1952. pst->compunit_symtab = end_compunit_symtab (text_offset + text_size,
  1953. SECT_OFF_TEXT (objfile));
  1954. end_stabs ();
  1955. dbxread_objfile = NULL;
  1956. }
  1957. /* Record the namespace that the function defined by SYMBOL was
  1958. defined in, if necessary. BLOCK is the associated block; use
  1959. OBSTACK for allocation. */
  1960. static void
  1961. cp_set_block_scope (const struct symbol *symbol,
  1962. struct block *block,
  1963. struct obstack *obstack)
  1964. {
  1965. if (symbol->demangled_name () != NULL)
  1966. {
  1967. /* Try to figure out the appropriate namespace from the
  1968. demangled name. */
  1969. /* FIXME: carlton/2003-04-15: If the function in question is
  1970. a method of a class, the name will actually include the
  1971. name of the class as well. This should be harmless, but
  1972. is a little unfortunate. */
  1973. const char *name = symbol->demangled_name ();
  1974. unsigned int prefix_len = cp_entire_prefix_len (name);
  1975. block_set_scope (block, obstack_strndup (obstack, name, prefix_len),
  1976. obstack);
  1977. }
  1978. }
  1979. /* This handles a single symbol from the symbol-file, building symbols
  1980. into a GDB symtab. It takes these arguments and an implicit argument.
  1981. TYPE is the type field of the ".stab" symbol entry.
  1982. DESC is the desc field of the ".stab" entry.
  1983. VALU is the value field of the ".stab" entry.
  1984. NAME is the symbol name, in our address space.
  1985. SECTION_OFFSETS is a set of amounts by which the sections of this
  1986. object file were relocated when it was loaded into memory. Note
  1987. that these section_offsets are not the objfile->section_offsets but
  1988. the pst->section_offsets. All symbols that refer to memory
  1989. locations need to be offset by these amounts.
  1990. OBJFILE is the object file from which we are reading symbols. It
  1991. is used in end_compunit_symtab.
  1992. LANGUAGE is the language of the symtab.
  1993. */
  1994. void
  1995. process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
  1996. const section_offsets &section_offsets,
  1997. struct objfile *objfile, enum language language)
  1998. {
  1999. struct gdbarch *gdbarch = objfile->arch ();
  2000. struct context_stack *newobj;
  2001. struct context_stack cstk;
  2002. /* This remembers the address of the start of a function. It is
  2003. used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
  2004. are relative to the current function's start address. On systems
  2005. other than Solaris 2, this just holds the SECT_OFF_TEXT value,
  2006. and is used to relocate these symbol types rather than
  2007. SECTION_OFFSETS. */
  2008. static CORE_ADDR function_start_offset;
  2009. /* This holds the address of the start of a function, without the
  2010. system peculiarities of function_start_offset. */
  2011. static CORE_ADDR last_function_start;
  2012. /* If this is nonzero, we've seen an N_SLINE since the start of the
  2013. current function. We use this to tell us to move the first sline
  2014. to the beginning of the function regardless of what its given
  2015. value is. */
  2016. static int sline_found_in_function = 1;
  2017. /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
  2018. source file. Used to detect the SunPRO solaris compiler. */
  2019. static int n_opt_found;
  2020. /* Something is wrong if we see real data before seeing a source
  2021. file name. */
  2022. if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
  2023. {
  2024. /* Ignore any symbols which appear before an N_SO symbol.
  2025. Currently no one puts symbols there, but we should deal
  2026. gracefully with the case. A complain()t might be in order,
  2027. but this should not be an error (). */
  2028. return;
  2029. }
  2030. switch (type)
  2031. {
  2032. case N_FUN:
  2033. case N_FNAME:
  2034. if (*name == '\000')
  2035. {
  2036. /* This N_FUN marks the end of a function. This closes off
  2037. the current block. */
  2038. struct block *block;
  2039. if (outermost_context_p ())
  2040. {
  2041. lbrac_mismatch_complaint (symnum);
  2042. break;
  2043. }
  2044. /* The following check is added before recording line 0 at
  2045. end of function so as to handle hand-generated stabs
  2046. which may have an N_FUN stabs at the end of the function,
  2047. but no N_SLINE stabs. */
  2048. if (sline_found_in_function)
  2049. {
  2050. CORE_ADDR addr = last_function_start + valu;
  2051. record_line (get_current_subfile (), 0,
  2052. gdbarch_addr_bits_remove (gdbarch, addr));
  2053. }
  2054. within_function = 0;
  2055. cstk = pop_context ();
  2056. /* Make a block for the local symbols within. */
  2057. block = finish_block (cstk.name,
  2058. cstk.old_blocks, NULL,
  2059. cstk.start_addr, cstk.start_addr + valu);
  2060. /* For C++, set the block's scope. */
  2061. if (cstk.name->language () == language_cplus)
  2062. cp_set_block_scope (cstk.name, block, &objfile->objfile_obstack);
  2063. /* May be switching to an assembler file which may not be using
  2064. block relative stabs, so reset the offset. */
  2065. function_start_offset = 0;
  2066. break;
  2067. }
  2068. sline_found_in_function = 0;
  2069. /* Relocate for dynamic loading. */
  2070. valu += section_offsets[SECT_OFF_TEXT (objfile)];
  2071. valu = gdbarch_addr_bits_remove (gdbarch, valu);
  2072. last_function_start = valu;
  2073. goto define_a_symbol;
  2074. case N_LBRAC:
  2075. /* This "symbol" just indicates the start of an inner lexical
  2076. context within a function. */
  2077. /* Ignore extra outermost context from SunPRO cc and acc. */
  2078. if (n_opt_found && desc == 1)
  2079. break;
  2080. valu += function_start_offset;
  2081. push_context (desc, valu);
  2082. break;
  2083. case N_RBRAC:
  2084. /* This "symbol" just indicates the end of an inner lexical
  2085. context that was started with N_LBRAC. */
  2086. /* Ignore extra outermost context from SunPRO cc and acc. */
  2087. if (n_opt_found && desc == 1)
  2088. break;
  2089. valu += function_start_offset;
  2090. if (outermost_context_p ())
  2091. {
  2092. lbrac_mismatch_complaint (symnum);
  2093. break;
  2094. }
  2095. cstk = pop_context ();
  2096. if (desc != cstk.depth)
  2097. lbrac_mismatch_complaint (symnum);
  2098. if (*get_local_symbols () != NULL)
  2099. {
  2100. /* GCC development snapshots from March to December of
  2101. 2000 would output N_LSYM entries after N_LBRAC
  2102. entries. As a consequence, these symbols are simply
  2103. discarded. Complain if this is the case. */
  2104. complaint (_("misplaced N_LBRAC entry; discarding local "
  2105. "symbols which have no enclosing block"));
  2106. }
  2107. *get_local_symbols () = cstk.locals;
  2108. if (get_context_stack_depth () > 1)
  2109. {
  2110. /* This is not the outermost LBRAC...RBRAC pair in the
  2111. function, its local symbols preceded it, and are the ones
  2112. just recovered from the context stack. Define the block
  2113. for them (but don't bother if the block contains no
  2114. symbols. Should we complain on blocks without symbols?
  2115. I can't think of any useful purpose for them). */
  2116. if (*get_local_symbols () != NULL)
  2117. {
  2118. /* Muzzle a compiler bug that makes end < start.
  2119. ??? Which compilers? Is this ever harmful?. */
  2120. if (cstk.start_addr > valu)
  2121. {
  2122. complaint (_("block start larger than block end"));
  2123. cstk.start_addr = valu;
  2124. }
  2125. /* Make a block for the local symbols within. */
  2126. finish_block (0, cstk.old_blocks, NULL,
  2127. cstk.start_addr, valu);
  2128. }
  2129. }
  2130. else
  2131. {
  2132. /* This is the outermost LBRAC...RBRAC pair. There is no
  2133. need to do anything; leave the symbols that preceded it
  2134. to be attached to the function's own block. We need to
  2135. indicate that we just moved outside of the function. */
  2136. within_function = 0;
  2137. }
  2138. break;
  2139. case N_FN:
  2140. case N_FN_SEQ:
  2141. /* This kind of symbol indicates the start of an object file.
  2142. Relocate for dynamic loading. */
  2143. valu += section_offsets[SECT_OFF_TEXT (objfile)];
  2144. break;
  2145. case N_SO:
  2146. /* This type of symbol indicates the start of data for one
  2147. source file. Finish the symbol table of the previous source
  2148. file (if any) and start accumulating a new symbol table.
  2149. Relocate for dynamic loading. */
  2150. valu += section_offsets[SECT_OFF_TEXT (objfile)];
  2151. n_opt_found = 0;
  2152. if (get_last_source_file ())
  2153. {
  2154. /* Check if previous symbol was also an N_SO (with some
  2155. sanity checks). If so, that one was actually the
  2156. directory name, and the current one is the real file
  2157. name. Patch things up. */
  2158. if (previous_stab_code == (unsigned char) N_SO)
  2159. {
  2160. patch_subfile_names (get_current_subfile (), name);
  2161. break; /* Ignore repeated SOs. */
  2162. }
  2163. end_compunit_symtab (valu, SECT_OFF_TEXT (objfile));
  2164. end_stabs ();
  2165. }
  2166. /* Null name means this just marks the end of text for this .o
  2167. file. Don't start a new symtab in this case. */
  2168. if (*name == '\000')
  2169. break;
  2170. function_start_offset = 0;
  2171. start_stabs ();
  2172. start_compunit_symtab (objfile, name, NULL, valu, language);
  2173. record_debugformat ("stabs");
  2174. break;
  2175. case N_SOL:
  2176. /* This type of symbol indicates the start of data for a
  2177. sub-source-file, one whose contents were copied or included
  2178. in the compilation of the main source file (whose name was
  2179. given in the N_SO symbol). Relocate for dynamic loading. */
  2180. valu += section_offsets[SECT_OFF_TEXT (objfile)];
  2181. start_subfile (name);
  2182. break;
  2183. case N_BINCL:
  2184. push_subfile ();
  2185. add_new_header_file (name, valu);
  2186. start_subfile (name);
  2187. break;
  2188. case N_EINCL:
  2189. start_subfile (pop_subfile ());
  2190. break;
  2191. case N_EXCL:
  2192. add_old_header_file (name, valu);
  2193. break;
  2194. case N_SLINE:
  2195. /* This type of "symbol" really just records one line-number --
  2196. core-address correspondence. Enter it in the line list for
  2197. this symbol table. */
  2198. /* Relocate for dynamic loading and for ELF acc
  2199. function-relative symbols. */
  2200. valu += function_start_offset;
  2201. /* GCC 2.95.3 emits the first N_SLINE stab somewhere in the
  2202. middle of the prologue instead of right at the start of the
  2203. function. To deal with this we record the address for the
  2204. first N_SLINE stab to be the start of the function instead of
  2205. the listed location. We really shouldn't to this. When
  2206. compiling with optimization, this first N_SLINE stab might be
  2207. optimized away. Other (non-GCC) compilers don't emit this
  2208. stab at all. There is no real harm in having an extra
  2209. numbered line, although it can be a bit annoying for the
  2210. user. However, it totally screws up our testsuite.
  2211. So for now, keep adjusting the address of the first N_SLINE
  2212. stab, but only for code compiled with GCC. */
  2213. if (within_function && sline_found_in_function == 0)
  2214. {
  2215. CORE_ADDR addr = processing_gcc_compilation == 2 ?
  2216. last_function_start : valu;
  2217. record_line (get_current_subfile (), desc,
  2218. gdbarch_addr_bits_remove (gdbarch, addr));
  2219. sline_found_in_function = 1;
  2220. }
  2221. else
  2222. record_line (get_current_subfile (), desc,
  2223. gdbarch_addr_bits_remove (gdbarch, valu));
  2224. break;
  2225. case N_BCOMM:
  2226. common_block_start (name, objfile);
  2227. break;
  2228. case N_ECOMM:
  2229. common_block_end (objfile);
  2230. break;
  2231. /* The following symbol types need to have the appropriate
  2232. offset added to their value; then we process symbol
  2233. definitions in the name. */
  2234. case N_STSYM: /* Static symbol in data segment. */
  2235. case N_LCSYM: /* Static symbol in BSS segment. */
  2236. case N_ROSYM: /* Static symbol in read-only data segment. */
  2237. /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
  2238. Solaris 2's stabs-in-elf makes *most* symbols relative but
  2239. leaves a few absolute (at least for Solaris 2.1 and version
  2240. 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on
  2241. the fence. .stab "foo:S...",N_STSYM is absolute (ld
  2242. relocates it) .stab "foo:V...",N_STSYM is relative (section
  2243. base subtracted). This leaves us no choice but to search for
  2244. the 'S' or 'V'... (or pass the whole section_offsets stuff
  2245. down ONE MORE function call level, which we really don't want
  2246. to do). */
  2247. {
  2248. const char *p;
  2249. /* Normal object file and NLMs have non-zero text seg offsets,
  2250. but don't need their static syms offset in this fashion.
  2251. XXX - This is really a crock that should be fixed in the
  2252. solib handling code so that I don't have to work around it
  2253. here. */
  2254. if (!symfile_relocatable)
  2255. {
  2256. p = strchr (name, ':');
  2257. if (p != 0 && p[1] == 'S')
  2258. {
  2259. /* The linker relocated it. We don't want to add a
  2260. Sun-stabs Tfoo.foo-like offset, but we *do*
  2261. want to add whatever solib.c passed to
  2262. symbol_file_add as addr (this is known to affect
  2263. SunOS 4, and I suspect ELF too). Since there is no
  2264. Ttext.text symbol, we can get addr from the text offset. */
  2265. valu += section_offsets[SECT_OFF_TEXT (objfile)];
  2266. goto define_a_symbol;
  2267. }
  2268. }
  2269. /* Since it's not the kludge case, re-dispatch to the right
  2270. handler. */
  2271. switch (type)
  2272. {
  2273. case N_STSYM:
  2274. goto case_N_STSYM;
  2275. case N_LCSYM:
  2276. goto case_N_LCSYM;
  2277. case N_ROSYM:
  2278. goto case_N_ROSYM;
  2279. default:
  2280. internal_error (__FILE__, __LINE__,
  2281. _("failed internal consistency check"));
  2282. }
  2283. }
  2284. case_N_STSYM: /* Static symbol in data segment. */
  2285. case N_DSLINE: /* Source line number, data segment. */
  2286. valu += section_offsets[SECT_OFF_DATA (objfile)];
  2287. goto define_a_symbol;
  2288. case_N_LCSYM: /* Static symbol in BSS segment. */
  2289. case N_BSLINE: /* Source line number, BSS segment. */
  2290. /* N_BROWS: overlaps with N_BSLINE. */
  2291. valu += section_offsets[SECT_OFF_BSS (objfile)];
  2292. goto define_a_symbol;
  2293. case_N_ROSYM: /* Static symbol in read-only data segment. */
  2294. valu += section_offsets[SECT_OFF_RODATA (objfile)];
  2295. goto define_a_symbol;
  2296. case N_ENTRY: /* Alternate entry point. */
  2297. /* Relocate for dynamic loading. */
  2298. valu += section_offsets[SECT_OFF_TEXT (objfile)];
  2299. goto define_a_symbol;
  2300. /* The following symbol types we don't know how to process.
  2301. Handle them in a "default" way, but complain to people who
  2302. care. */
  2303. default:
  2304. case N_CATCH: /* Exception handler catcher. */
  2305. case N_EHDECL: /* Exception handler name. */
  2306. case N_PC: /* Global symbol in Pascal. */
  2307. case N_M2C: /* Modula-2 compilation unit. */
  2308. /* N_MOD2: overlaps with N_EHDECL. */
  2309. case N_SCOPE: /* Modula-2 scope information. */
  2310. case N_ECOML: /* End common (local name). */
  2311. case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
  2312. case N_NBDATA:
  2313. case N_NBBSS:
  2314. case N_NBSTS:
  2315. case N_NBLCS:
  2316. unknown_symtype_complaint (hex_string (type));
  2317. /* FALLTHROUGH */
  2318. define_a_symbol:
  2319. /* These symbol types don't need the address field relocated,
  2320. since it is either unused, or is absolute. */
  2321. case N_GSYM: /* Global variable. */
  2322. case N_NSYMS: /* Number of symbols (Ultrix). */
  2323. case N_NOMAP: /* No map? (Ultrix). */
  2324. case N_RSYM: /* Register variable. */
  2325. case N_DEFD: /* Modula-2 GNU module dependency. */
  2326. case N_SSYM: /* Struct or union element. */
  2327. case N_LSYM: /* Local symbol in stack. */
  2328. case N_PSYM: /* Parameter variable. */
  2329. case N_LENG: /* Length of preceding symbol type. */
  2330. if (name)
  2331. {
  2332. int deftype;
  2333. const char *colon_pos = strchr (name, ':');
  2334. if (colon_pos == NULL)
  2335. deftype = '\0';
  2336. else
  2337. deftype = colon_pos[1];
  2338. switch (deftype)
  2339. {
  2340. case 'f':
  2341. case 'F':
  2342. /* Deal with the SunPRO 3.0 compiler which omits the
  2343. address from N_FUN symbols. */
  2344. if (type == N_FUN
  2345. && valu == section_offsets[SECT_OFF_TEXT (objfile)]
  2346. && gdbarch_sofun_address_maybe_missing (gdbarch))
  2347. {
  2348. struct bound_minimal_symbol minsym
  2349. = find_stab_function (name, get_last_source_file (),
  2350. objfile);
  2351. if (minsym.minsym != NULL)
  2352. valu = BMSYMBOL_VALUE_ADDRESS (minsym);
  2353. }
  2354. /* These addresses are absolute. */
  2355. function_start_offset = valu;
  2356. within_function = 1;
  2357. if (get_context_stack_depth () > 1)
  2358. {
  2359. complaint (_("unmatched N_LBRAC before symtab pos %d"),
  2360. symnum);
  2361. break;
  2362. }
  2363. if (!outermost_context_p ())
  2364. {
  2365. struct block *block;
  2366. cstk = pop_context ();
  2367. /* Make a block for the local symbols within. */
  2368. block = finish_block (cstk.name,
  2369. cstk.old_blocks, NULL,
  2370. cstk.start_addr, valu);
  2371. /* For C++, set the block's scope. */
  2372. if (cstk.name->language () == language_cplus)
  2373. cp_set_block_scope (cstk.name, block,
  2374. &objfile->objfile_obstack);
  2375. }
  2376. newobj = push_context (0, valu);
  2377. newobj->name = define_symbol (valu, name, desc, type, objfile);
  2378. break;
  2379. default:
  2380. define_symbol (valu, name, desc, type, objfile);
  2381. break;
  2382. }
  2383. }
  2384. break;
  2385. /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
  2386. for a bunch of other flags, too. Someday we may parse their
  2387. flags; for now we ignore theirs and hope they'll ignore ours. */
  2388. case N_OPT: /* Solaris 2: Compiler options. */
  2389. if (name)
  2390. {
  2391. if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
  2392. {
  2393. processing_gcc_compilation = 2;
  2394. }
  2395. else
  2396. n_opt_found = 1;
  2397. }
  2398. break;
  2399. case N_MAIN: /* Name of main routine. */
  2400. /* FIXME: If one has a symbol file with N_MAIN and then replaces
  2401. it with a symbol file with "main" and without N_MAIN. I'm
  2402. not sure exactly what rule to follow but probably something
  2403. like: N_MAIN takes precedence over "main" no matter what
  2404. objfile it is in; If there is more than one N_MAIN, choose
  2405. the one in the symfile_objfile; If there is more than one
  2406. N_MAIN within a given objfile, complain() and choose
  2407. arbitrarily. (kingdon) */
  2408. if (name != NULL)
  2409. set_objfile_main_name (objfile, name, language_unknown);
  2410. break;
  2411. /* The following symbol types can be ignored. */
  2412. case N_OBJ: /* Solaris 2: Object file dir and name. */
  2413. case N_PATCH: /* Solaris 2: Patch Run Time Checker. */
  2414. /* N_UNDF: Solaris 2: File separator mark. */
  2415. /* N_UNDF: -- we will never encounter it, since we only process
  2416. one file's symbols at once. */
  2417. case N_ENDM: /* Solaris 2: End of module. */
  2418. case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
  2419. break;
  2420. }
  2421. /* '#' is a GNU C extension to allow one symbol to refer to another
  2422. related symbol.
  2423. Generally this is used so that an alias can refer to its main
  2424. symbol. */
  2425. gdb_assert (name);
  2426. if (name[0] == '#')
  2427. {
  2428. /* Initialize symbol reference names and determine if this is a
  2429. definition. If a symbol reference is being defined, go ahead
  2430. and add it. Otherwise, just return. */
  2431. const char *s = name;
  2432. int refnum;
  2433. /* If this stab defines a new reference ID that is not on the
  2434. reference list, then put it on the reference list.
  2435. We go ahead and advance NAME past the reference, even though
  2436. it is not strictly necessary at this time. */
  2437. refnum = symbol_reference_defined (&s);
  2438. if (refnum >= 0)
  2439. if (!ref_search (refnum))
  2440. ref_add (refnum, 0, name, valu);
  2441. name = s;
  2442. }
  2443. previous_stab_code = type;
  2444. }
  2445. /* FIXME: The only difference between this and elfstab_build_psymtabs
  2446. is the call to install_minimal_symbols for elf, and the support for
  2447. split sections. If the differences are really that small, the code
  2448. should be shared. */
  2449. /* Scan and build partial symbols for an coff symbol file.
  2450. The coff file has already been processed to get its minimal symbols.
  2451. This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
  2452. rolled into one.
  2453. OBJFILE is the object file we are reading symbols from.
  2454. ADDR is the address relative to which the symbols are (e.g.
  2455. the base address of the text segment).
  2456. TEXTADDR is the address of the text section.
  2457. TEXTSIZE is the size of the text section.
  2458. STABSECTS is the list of .stab sections in OBJFILE.
  2459. STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
  2460. .stabstr section exists.
  2461. This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
  2462. adjusted for coff details. */
  2463. void
  2464. coffstab_build_psymtabs (struct objfile *objfile,
  2465. CORE_ADDR textaddr, unsigned int textsize,
  2466. const std::vector<asection *> &stabsects,
  2467. file_ptr stabstroffset, unsigned int stabstrsize)
  2468. {
  2469. int val;
  2470. bfd *sym_bfd = objfile->obfd;
  2471. const char *name = bfd_get_filename (sym_bfd);
  2472. unsigned int stabsize;
  2473. /* Allocate struct to keep track of stab reading. */
  2474. dbx_objfile_data_key.emplace (objfile);
  2475. DBX_TEXT_ADDR (objfile) = textaddr;
  2476. DBX_TEXT_SIZE (objfile) = textsize;
  2477. #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
  2478. DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE;
  2479. DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
  2480. if (stabstrsize > bfd_get_size (sym_bfd))
  2481. error (_("ridiculous string table size: %d bytes"), stabstrsize);
  2482. DBX_STRINGTAB (objfile) = (char *)
  2483. obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
  2484. OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
  2485. /* Now read in the string table in one big gulp. */
  2486. val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
  2487. if (val < 0)
  2488. perror_with_name (name);
  2489. val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
  2490. if (val != stabstrsize)
  2491. perror_with_name (name);
  2492. stabsread_new_init ();
  2493. free_header_files ();
  2494. init_header_files ();
  2495. processing_acc_compilation = 1;
  2496. /* In a coff file, we've already installed the minimal symbols that came
  2497. from the coff (non-stab) symbol table, so always act like an
  2498. incremental load here. */
  2499. scoped_restore save_symbuf_sections
  2500. = make_scoped_restore (&symbuf_sections);
  2501. if (stabsects.size () == 1)
  2502. {
  2503. stabsize = bfd_section_size (stabsects[0]);
  2504. DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
  2505. DBX_SYMTAB_OFFSET (objfile) = stabsects[0]->filepos;
  2506. }
  2507. else
  2508. {
  2509. DBX_SYMCOUNT (objfile) = 0;
  2510. for (asection *section : stabsects)
  2511. {
  2512. stabsize = bfd_section_size (section);
  2513. DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
  2514. }
  2515. DBX_SYMTAB_OFFSET (objfile) = stabsects[0]->filepos;
  2516. sect_idx = 1;
  2517. symbuf_sections = &stabsects;
  2518. symbuf_left = bfd_section_size (stabsects[0]);
  2519. symbuf_read = 0;
  2520. }
  2521. dbx_symfile_read (objfile, 0);
  2522. }
  2523. /* Scan and build partial symbols for an ELF symbol file.
  2524. This ELF file has already been processed to get its minimal symbols.
  2525. This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
  2526. rolled into one.
  2527. OBJFILE is the object file we are reading symbols from.
  2528. ADDR is the address relative to which the symbols are (e.g.
  2529. the base address of the text segment).
  2530. STABSECT is the BFD section information for the .stab section.
  2531. STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
  2532. .stabstr section exists.
  2533. This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
  2534. adjusted for elf details. */
  2535. void
  2536. elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
  2537. file_ptr stabstroffset, unsigned int stabstrsize)
  2538. {
  2539. int val;
  2540. bfd *sym_bfd = objfile->obfd;
  2541. const char *name = bfd_get_filename (sym_bfd);
  2542. stabsread_new_init ();
  2543. /* Allocate struct to keep track of stab reading. */
  2544. dbx_objfile_data_key.emplace (objfile);
  2545. /* Find the first and last text address. dbx_symfile_read seems to
  2546. want this. */
  2547. find_text_range (sym_bfd, objfile);
  2548. #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
  2549. DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE;
  2550. DBX_SYMCOUNT (objfile)
  2551. = bfd_section_size (stabsect) / DBX_SYMBOL_SIZE (objfile);
  2552. DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
  2553. DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;
  2554. DBX_STAB_SECTION (objfile) = stabsect;
  2555. if (stabstrsize > bfd_get_size (sym_bfd))
  2556. error (_("ridiculous string table size: %d bytes"), stabstrsize);
  2557. DBX_STRINGTAB (objfile) = (char *)
  2558. obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
  2559. OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
  2560. /* Now read in the string table in one big gulp. */
  2561. val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
  2562. if (val < 0)
  2563. perror_with_name (name);
  2564. val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
  2565. if (val != stabstrsize)
  2566. perror_with_name (name);
  2567. stabsread_new_init ();
  2568. free_header_files ();
  2569. init_header_files ();
  2570. processing_acc_compilation = 1;
  2571. symbuf_read = 0;
  2572. symbuf_left = bfd_section_size (stabsect);
  2573. scoped_restore restore_stabs_data = make_scoped_restore (&stabs_data);
  2574. gdb::unique_xmalloc_ptr<gdb_byte> data_holder;
  2575. stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL);
  2576. if (stabs_data)
  2577. data_holder.reset (stabs_data);
  2578. /* In an elf file, we've already installed the minimal symbols that came
  2579. from the elf (non-stab) symbol table, so always act like an
  2580. incremental load here. dbx_symfile_read should not generate any new
  2581. minimal symbols, since we will have already read the ELF dynamic symbol
  2582. table and normal symbol entries won't be in the ".stab" section; but in
  2583. case it does, it will install them itself. */
  2584. dbx_symfile_read (objfile, 0);
  2585. }
  2586. /* Scan and build partial symbols for a file with special sections for stabs
  2587. and stabstrings. The file has already been processed to get its minimal
  2588. symbols, and any other symbols that might be necessary to resolve GSYMs.
  2589. This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
  2590. rolled into one.
  2591. OBJFILE is the object file we are reading symbols from.
  2592. ADDR is the address relative to which the symbols are (e.g. the base address
  2593. of the text segment).
  2594. STAB_NAME is the name of the section that contains the stabs.
  2595. STABSTR_NAME is the name of the section that contains the stab strings.
  2596. This routine is mostly copied from dbx_symfile_init and
  2597. dbx_symfile_read. */
  2598. void
  2599. stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
  2600. char *stabstr_name, char *text_name)
  2601. {
  2602. int val;
  2603. bfd *sym_bfd = objfile->obfd;
  2604. const char *name = bfd_get_filename (sym_bfd);
  2605. asection *stabsect;
  2606. asection *stabstrsect;
  2607. asection *text_sect;
  2608. stabsect = bfd_get_section_by_name (sym_bfd, stab_name);
  2609. stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name);
  2610. if (!stabsect)
  2611. return;
  2612. if (!stabstrsect)
  2613. error (_("stabsect_build_psymtabs: Found stabs (%s), "
  2614. "but not string section (%s)"),
  2615. stab_name, stabstr_name);
  2616. dbx_objfile_data_key.emplace (objfile);
  2617. text_sect = bfd_get_section_by_name (sym_bfd, text_name);
  2618. if (!text_sect)
  2619. error (_("Can't find %s section in symbol file"), text_name);
  2620. DBX_TEXT_ADDR (objfile) = bfd_section_vma (text_sect);
  2621. DBX_TEXT_SIZE (objfile) = bfd_section_size (text_sect);
  2622. DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist);
  2623. DBX_SYMCOUNT (objfile) = bfd_section_size (stabsect)
  2624. / DBX_SYMBOL_SIZE (objfile);
  2625. DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (stabstrsect);
  2626. DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; /* XXX - FIXME: POKING
  2627. INSIDE BFD DATA
  2628. STRUCTURES */
  2629. if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
  2630. error (_("ridiculous string table size: %d bytes"),
  2631. DBX_STRINGTAB_SIZE (objfile));
  2632. DBX_STRINGTAB (objfile) = (char *)
  2633. obstack_alloc (&objfile->objfile_obstack,
  2634. DBX_STRINGTAB_SIZE (objfile) + 1);
  2635. OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1);
  2636. /* Now read in the string table in one big gulp. */
  2637. val = bfd_get_section_contents (sym_bfd, /* bfd */
  2638. stabstrsect, /* bfd section */
  2639. DBX_STRINGTAB (objfile), /* input buffer */
  2640. 0, /* offset into section */
  2641. DBX_STRINGTAB_SIZE (objfile)); /* amount to
  2642. read */
  2643. if (!val)
  2644. perror_with_name (name);
  2645. stabsread_new_init ();
  2646. free_header_files ();
  2647. init_header_files ();
  2648. /* Now, do an incremental load. */
  2649. processing_acc_compilation = 1;
  2650. dbx_symfile_read (objfile, 0);
  2651. }
  2652. static const struct sym_fns aout_sym_fns =
  2653. {
  2654. dbx_new_init, /* init anything gbl to entire symtab */
  2655. dbx_symfile_init, /* read initial info, setup for sym_read() */
  2656. dbx_symfile_read, /* read a symbol file into symtab */
  2657. dbx_symfile_finish, /* finished with file, cleanup */
  2658. default_symfile_offsets, /* parse user's offsets to internal form */
  2659. default_symfile_segments, /* Get segment information from a file. */
  2660. NULL,
  2661. default_symfile_relocate, /* Relocate a debug section. */
  2662. NULL, /* sym_probe_fns */
  2663. };
  2664. void _initialize_dbxread ();
  2665. void
  2666. _initialize_dbxread ()
  2667. {
  2668. add_symtab_fns (bfd_target_aout_flavour, &aout_sym_fns);
  2669. }