Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Read dbx symbol tables and convert to internal format, for GDB. |
b6ba6518 | 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
25caa7a8 | 3 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003. |
c906108c SS |
4 | Free Software Foundation, Inc. |
5 | ||
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | /* This module provides three functions: dbx_symfile_init, | |
24 | which initializes to read a symbol file; dbx_new_init, which | |
25 | discards existing cached information when all symbols are being | |
26 | discarded; and dbx_symfile_read, which reads a symbol table | |
27 | from a file. | |
28 | ||
29 | dbx_symfile_read only does the minimum work necessary for letting the | |
30 | user "name" things symbolically; it does not read the entire symtab. | |
31 | Instead, it reads the external and static symbols and puts them in partial | |
32 | symbol tables. When more extensive information is requested of a | |
33 | file, the corresponding partial symbol table is mutated into a full | |
34 | fledged symbol table by going back and reading the symbols | |
35 | for real. dbx_psymtab_to_symtab() is the function that does this */ | |
36 | ||
37 | #include "defs.h" | |
38 | #include "gdb_string.h" | |
39 | ||
40 | #if defined(USG) || defined(__CYGNUSCLIB__) | |
41 | #include <sys/types.h> | |
42 | #include <fcntl.h> | |
43 | #endif | |
44 | ||
04ea0df1 | 45 | #include "gdb_obstack.h" |
c906108c | 46 | #include "gdb_stat.h" |
c906108c SS |
47 | #include "symtab.h" |
48 | #include "breakpoint.h" | |
c906108c SS |
49 | #include "target.h" |
50 | #include "gdbcore.h" /* for bfd stuff */ | |
c5aa993b | 51 | #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */ |
c906108c SS |
52 | #include "symfile.h" |
53 | #include "objfiles.h" | |
54 | #include "buildsym.h" | |
55 | #include "stabsread.h" | |
56 | #include "gdb-stabs.h" | |
57 | #include "demangle.h" | |
6a34fd2f | 58 | #include "language.h" /* Needed for local_hex_string */ |
c906108c | 59 | #include "complaints.h" |
015a42b4 | 60 | #include "cp-abi.h" |
c906108c SS |
61 | |
62 | #include "aout/aout64.h" | |
63 | #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */ | |
c906108c | 64 | \f |
c5aa993b | 65 | |
c906108c SS |
66 | /* This macro returns the size field of a minimal symbol, which is normally |
67 | stored in the "info" field. The macro can be overridden for specific | |
68 | targets (e.g. MIPS16) that use the info field for other purposes. */ | |
69 | #ifndef MSYMBOL_SIZE | |
70 | #define MSYMBOL_SIZE(msym) ((long) MSYMBOL_INFO (msym)) | |
71 | #endif | |
72 | ||
73 | ||
74 | /* We put a pointer to this structure in the read_symtab_private field | |
75 | of the psymtab. */ | |
76 | ||
c5aa993b JM |
77 | struct symloc |
78 | { | |
c5aa993b JM |
79 | /* Offset within the file symbol table of first local symbol for this |
80 | file. */ | |
c906108c | 81 | |
c5aa993b | 82 | int ldsymoff; |
c906108c | 83 | |
c5aa993b JM |
84 | /* Length (in bytes) of the section of the symbol table devoted to |
85 | this file's symbols (actually, the section bracketed may contain | |
86 | more than just this file's symbols). If ldsymlen is 0, the only | |
87 | reason for this thing's existence is the dependency list. Nothing | |
88 | else will happen when it is read in. */ | |
c906108c | 89 | |
c5aa993b | 90 | int ldsymlen; |
c906108c | 91 | |
c5aa993b | 92 | /* The size of each symbol in the symbol file (in external form). */ |
c906108c | 93 | |
c5aa993b | 94 | int symbol_size; |
c906108c | 95 | |
c5aa993b JM |
96 | /* Further information needed to locate the symbols if they are in |
97 | an ELF file. */ | |
c906108c | 98 | |
c5aa993b JM |
99 | int symbol_offset; |
100 | int string_offset; | |
101 | int file_string_offset; | |
102 | }; | |
c906108c SS |
103 | |
104 | #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff) | |
105 | #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen) | |
106 | #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private)) | |
107 | #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size) | |
108 | #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset) | |
109 | #define STRING_OFFSET(p) (SYMLOC(p)->string_offset) | |
110 | #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset) | |
c906108c | 111 | \f |
c5aa993b | 112 | |
c906108c SS |
113 | /* Remember what we deduced to be the source language of this psymtab. */ |
114 | ||
115 | static enum language psymtab_language = language_unknown; | |
116 | ||
c906108c SS |
117 | /* The BFD for this file -- implicit parameter to next_symbol_text. */ |
118 | ||
119 | static bfd *symfile_bfd; | |
120 | ||
121 | /* The size of each symbol in the symbol file (in external form). | |
122 | This is set by dbx_symfile_read when building psymtabs, and by | |
123 | dbx_psymtab_to_symtab when building symtabs. */ | |
124 | ||
125 | static unsigned symbol_size; | |
126 | ||
127 | /* This is the offset of the symbol table in the executable file. */ | |
128 | ||
129 | static unsigned symbol_table_offset; | |
130 | ||
131 | /* This is the offset of the string table in the executable file. */ | |
132 | ||
133 | static unsigned string_table_offset; | |
134 | ||
135 | /* For elf+stab executables, the n_strx field is not a simple index | |
136 | into the string table. Instead, each .o file has a base offset in | |
137 | the string table, and the associated symbols contain offsets from | |
138 | this base. The following two variables contain the base offset for | |
139 | the current and next .o files. */ | |
140 | ||
141 | static unsigned int file_string_table_offset; | |
142 | static unsigned int next_file_string_table_offset; | |
143 | ||
144 | /* .o and NLM files contain unrelocated addresses which are based at | |
145 | 0. When non-zero, this flag disables some of the special cases for | |
146 | Solaris elf+stab text addresses at location 0. */ | |
147 | ||
148 | static int symfile_relocatable = 0; | |
149 | ||
150 | /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are | |
151 | relative to the function start address. */ | |
152 | ||
153 | static int block_address_function_relative = 0; | |
154 | \f | |
155 | /* The lowest text address we have yet encountered. This is needed | |
156 | because in an a.out file, there is no header field which tells us | |
157 | what address the program is actually going to be loaded at, so we | |
158 | need to make guesses based on the symbols (which *are* relocated to | |
159 | reflect the address it will be loaded at). */ | |
160 | ||
161 | static CORE_ADDR lowest_text_address; | |
162 | ||
163 | /* Non-zero if there is any line number info in the objfile. Prevents | |
164 | end_psymtab from discarding an otherwise empty psymtab. */ | |
165 | ||
166 | static int has_line_numbers; | |
167 | ||
168 | /* Complaints about the symbols we have encountered. */ | |
169 | ||
23136709 KB |
170 | static void |
171 | unknown_symtype_complaint (const char *arg1) | |
172 | { | |
173 | complaint (&symfile_complaints, "unknown symbol type %s", arg1); | |
174 | } | |
c906108c | 175 | |
23136709 KB |
176 | static void |
177 | lbrac_mismatch_complaint (int arg1) | |
178 | { | |
179 | complaint (&symfile_complaints, | |
180 | "N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", arg1); | |
181 | } | |
c906108c | 182 | |
23136709 KB |
183 | static void |
184 | repeated_header_complaint (const char *arg1, int arg2) | |
185 | { | |
186 | complaint (&symfile_complaints, | |
187 | "\"repeated\" header file %s not previously seen, at symtab pos %d", | |
188 | arg1, arg2); | |
189 | } | |
1f077a3e | 190 | |
7a292a7a SS |
191 | /* find_text_range --- find start and end of loadable code sections |
192 | ||
193 | The find_text_range function finds the shortest address range that | |
194 | encloses all sections containing executable code, and stores it in | |
195 | objfile's text_addr and text_size members. | |
196 | ||
197 | dbx_symfile_read will use this to finish off the partial symbol | |
198 | table, in some cases. */ | |
199 | ||
200 | static void | |
c5aa993b | 201 | find_text_range (bfd * sym_bfd, struct objfile *objfile) |
7a292a7a SS |
202 | { |
203 | asection *sec; | |
204 | int found_any = 0; | |
b9179dbc EZ |
205 | CORE_ADDR start = 0; |
206 | CORE_ADDR end = 0; | |
c5aa993b | 207 | |
7a292a7a SS |
208 | for (sec = sym_bfd->sections; sec; sec = sec->next) |
209 | if (bfd_get_section_flags (sym_bfd, sec) & SEC_CODE) | |
210 | { | |
211 | CORE_ADDR sec_start = bfd_section_vma (sym_bfd, sec); | |
212 | CORE_ADDR sec_end = sec_start + bfd_section_size (sym_bfd, sec); | |
213 | ||
214 | if (found_any) | |
215 | { | |
c5aa993b JM |
216 | if (sec_start < start) |
217 | start = sec_start; | |
218 | if (sec_end > end) | |
219 | end = sec_end; | |
7a292a7a SS |
220 | } |
221 | else | |
222 | { | |
223 | start = sec_start; | |
224 | end = sec_end; | |
225 | } | |
226 | ||
227 | found_any = 1; | |
228 | } | |
229 | ||
c5aa993b | 230 | if (!found_any) |
7a292a7a SS |
231 | error ("Can't find any code sections in symbol file"); |
232 | ||
233 | DBX_TEXT_ADDR (objfile) = start; | |
234 | DBX_TEXT_SIZE (objfile) = end - start; | |
235 | } | |
c5aa993b | 236 | \f |
7a292a7a SS |
237 | |
238 | ||
c906108c SS |
239 | /* During initial symbol readin, we need to have a structure to keep |
240 | track of which psymtabs have which bincls in them. This structure | |
241 | is used during readin to setup the list of dependencies within each | |
242 | partial symbol table. */ | |
243 | ||
244 | struct header_file_location | |
245 | { | |
246 | char *name; /* Name of header file */ | |
247 | int instance; /* See above */ | |
248 | struct partial_symtab *pst; /* Partial symtab that has the | |
249 | BINCL/EINCL defs for this file */ | |
250 | }; | |
251 | ||
252 | /* The actual list and controling variables */ | |
253 | static struct header_file_location *bincl_list, *next_bincl; | |
254 | static int bincls_allocated; | |
255 | ||
256 | /* Local function prototypes */ | |
257 | ||
a14ed312 | 258 | extern void _initialize_dbxread (void); |
392a587b | 259 | |
25caa7a8 EZ |
260 | #if 0 /* OBSOLETE CFront */ |
261 | // OBSOLETE static void process_now (struct objfile *); | |
262 | #endif /* OBSOLETE CFront */ | |
c906108c | 263 | |
a14ed312 | 264 | static void read_ofile_symtab (struct partial_symtab *); |
c906108c | 265 | |
a14ed312 | 266 | static void dbx_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 267 | |
a14ed312 | 268 | static void dbx_psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 269 | |
a14ed312 | 270 | static void read_dbx_dynamic_symtab (struct objfile *objfile); |
c906108c | 271 | |
a14ed312 | 272 | static void read_dbx_symtab (struct objfile *); |
c906108c | 273 | |
a14ed312 | 274 | static void free_bincl_list (struct objfile *); |
c906108c | 275 | |
a14ed312 | 276 | static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int); |
c906108c | 277 | |
a14ed312 | 278 | static void add_bincl_to_list (struct partial_symtab *, char *, int); |
c906108c | 279 | |
a14ed312 | 280 | static void init_bincl_list (int, struct objfile *); |
c906108c | 281 | |
a14ed312 | 282 | static char *dbx_next_symbol_text (struct objfile *); |
c906108c | 283 | |
a14ed312 | 284 | static void fill_symbuf (bfd *); |
c906108c | 285 | |
a14ed312 | 286 | static void dbx_symfile_init (struct objfile *); |
c906108c | 287 | |
a14ed312 | 288 | static void dbx_new_init (struct objfile *); |
c906108c | 289 | |
a14ed312 | 290 | static void dbx_symfile_read (struct objfile *, int); |
c906108c | 291 | |
a14ed312 | 292 | static void dbx_symfile_finish (struct objfile *); |
c906108c | 293 | |
a14ed312 | 294 | static void record_minimal_symbol (char *, CORE_ADDR, int, struct objfile *); |
c906108c | 295 | |
a14ed312 | 296 | static void add_new_header_file (char *, int); |
c906108c | 297 | |
a14ed312 | 298 | static void add_old_header_file (char *, int); |
c906108c | 299 | |
a14ed312 | 300 | static void add_this_object_header_file (int); |
c906108c | 301 | |
a14ed312 KB |
302 | static struct partial_symtab *start_psymtab (struct objfile *, char *, |
303 | CORE_ADDR, int, | |
304 | struct partial_symbol **, | |
305 | struct partial_symbol **); | |
d4f3574e | 306 | |
c906108c SS |
307 | /* Free up old header file tables */ |
308 | ||
d3d55eeb | 309 | void |
fba45db2 | 310 | free_header_files (void) |
c906108c SS |
311 | { |
312 | if (this_object_header_files) | |
313 | { | |
b8c9b27d | 314 | xfree (this_object_header_files); |
c906108c SS |
315 | this_object_header_files = NULL; |
316 | } | |
317 | n_allocated_this_object_header_files = 0; | |
318 | } | |
319 | ||
320 | /* Allocate new header file tables */ | |
321 | ||
d3d55eeb | 322 | void |
fba45db2 | 323 | init_header_files (void) |
c906108c SS |
324 | { |
325 | n_allocated_this_object_header_files = 10; | |
326 | this_object_header_files = (int *) xmalloc (10 * sizeof (int)); | |
327 | } | |
328 | ||
329 | /* Add header file number I for this object file | |
330 | at the next successive FILENUM. */ | |
331 | ||
332 | static void | |
fba45db2 | 333 | add_this_object_header_file (int i) |
c906108c SS |
334 | { |
335 | if (n_this_object_header_files == n_allocated_this_object_header_files) | |
336 | { | |
337 | n_allocated_this_object_header_files *= 2; | |
338 | this_object_header_files | |
339 | = (int *) xrealloc ((char *) this_object_header_files, | |
c5aa993b | 340 | n_allocated_this_object_header_files * sizeof (int)); |
c906108c SS |
341 | } |
342 | ||
343 | this_object_header_files[n_this_object_header_files++] = i; | |
344 | } | |
345 | ||
346 | /* Add to this file an "old" header file, one already seen in | |
347 | a previous object file. NAME is the header file's name. | |
348 | INSTANCE is its instance code, to select among multiple | |
349 | symbol tables for the same header file. */ | |
350 | ||
351 | static void | |
fba45db2 | 352 | add_old_header_file (char *name, int instance) |
c906108c SS |
353 | { |
354 | register struct header_file *p = HEADER_FILES (current_objfile); | |
355 | register int i; | |
356 | ||
357 | for (i = 0; i < N_HEADER_FILES (current_objfile); i++) | |
358 | if (STREQ (p[i].name, name) && instance == p[i].instance) | |
359 | { | |
360 | add_this_object_header_file (i); | |
361 | return; | |
362 | } | |
23136709 | 363 | repeated_header_complaint (name, symnum); |
c906108c SS |
364 | } |
365 | ||
366 | /* Add to this file a "new" header file: definitions for its types follow. | |
367 | NAME is the header file's name. | |
368 | Most often this happens only once for each distinct header file, | |
369 | but not necessarily. If it happens more than once, INSTANCE has | |
370 | a different value each time, and references to the header file | |
371 | use INSTANCE values to select among them. | |
372 | ||
373 | dbx output contains "begin" and "end" markers for each new header file, | |
374 | but at this level we just need to know which files there have been; | |
375 | so we record the file when its "begin" is seen and ignore the "end". */ | |
376 | ||
377 | static void | |
fba45db2 | 378 | add_new_header_file (char *name, int instance) |
c906108c SS |
379 | { |
380 | register int i; | |
381 | register struct header_file *hfile; | |
382 | ||
383 | /* Make sure there is room for one more header file. */ | |
384 | ||
385 | i = N_ALLOCATED_HEADER_FILES (current_objfile); | |
386 | ||
387 | if (N_HEADER_FILES (current_objfile) == i) | |
388 | { | |
389 | if (i == 0) | |
390 | { | |
391 | N_ALLOCATED_HEADER_FILES (current_objfile) = 10; | |
392 | HEADER_FILES (current_objfile) = (struct header_file *) | |
393 | xmalloc (10 * sizeof (struct header_file)); | |
394 | } | |
395 | else | |
396 | { | |
397 | i *= 2; | |
398 | N_ALLOCATED_HEADER_FILES (current_objfile) = i; | |
399 | HEADER_FILES (current_objfile) = (struct header_file *) | |
400 | xrealloc ((char *) HEADER_FILES (current_objfile), | |
401 | (i * sizeof (struct header_file))); | |
402 | } | |
403 | } | |
404 | ||
405 | /* Create an entry for this header file. */ | |
406 | ||
407 | i = N_HEADER_FILES (current_objfile)++; | |
408 | hfile = HEADER_FILES (current_objfile) + i; | |
c5aa993b | 409 | hfile->name = savestring (name, strlen (name)); |
c906108c SS |
410 | hfile->instance = instance; |
411 | hfile->length = 10; | |
412 | hfile->vector | |
413 | = (struct type **) xmalloc (10 * sizeof (struct type *)); | |
414 | memset (hfile->vector, 0, 10 * sizeof (struct type *)); | |
415 | ||
416 | add_this_object_header_file (i); | |
417 | } | |
418 | ||
419 | #if 0 | |
420 | static struct type ** | |
fba45db2 | 421 | explicit_lookup_type (int real_filenum, int index) |
c906108c SS |
422 | { |
423 | register struct header_file *f = &HEADER_FILES (current_objfile)[real_filenum]; | |
424 | ||
425 | if (index >= f->length) | |
426 | { | |
427 | f->length *= 2; | |
428 | f->vector = (struct type **) | |
429 | xrealloc (f->vector, f->length * sizeof (struct type *)); | |
430 | memset (&f->vector[f->length / 2], | |
c5aa993b | 431 | '\0', f->length * sizeof (struct type *) / 2); |
c906108c SS |
432 | } |
433 | return &f->vector[index]; | |
434 | } | |
435 | #endif | |
436 | \f | |
437 | static void | |
fba45db2 KB |
438 | record_minimal_symbol (char *name, CORE_ADDR address, int type, |
439 | struct objfile *objfile) | |
c906108c SS |
440 | { |
441 | enum minimal_symbol_type ms_type; | |
442 | int section; | |
443 | asection *bfd_section; | |
444 | ||
445 | switch (type) | |
446 | { | |
447 | case N_TEXT | N_EXT: | |
448 | ms_type = mst_text; | |
b8fbeb18 | 449 | section = SECT_OFF_TEXT (objfile); |
c906108c SS |
450 | bfd_section = DBX_TEXT_SECTION (objfile); |
451 | break; | |
452 | case N_DATA | N_EXT: | |
453 | ms_type = mst_data; | |
b8fbeb18 | 454 | section = SECT_OFF_DATA (objfile); |
c906108c SS |
455 | bfd_section = DBX_DATA_SECTION (objfile); |
456 | break; | |
457 | case N_BSS | N_EXT: | |
458 | ms_type = mst_bss; | |
b8fbeb18 | 459 | section = SECT_OFF_BSS (objfile); |
c906108c SS |
460 | bfd_section = DBX_BSS_SECTION (objfile); |
461 | break; | |
462 | case N_ABS | N_EXT: | |
463 | ms_type = mst_abs; | |
464 | section = -1; | |
465 | bfd_section = NULL; | |
466 | break; | |
467 | #ifdef N_SETV | |
468 | case N_SETV | N_EXT: | |
469 | ms_type = mst_data; | |
b8fbeb18 | 470 | section = SECT_OFF_DATA (objfile); |
c906108c SS |
471 | bfd_section = DBX_DATA_SECTION (objfile); |
472 | break; | |
473 | case N_SETV: | |
474 | /* I don't think this type actually exists; since a N_SETV is the result | |
c5aa993b JM |
475 | of going over many .o files, it doesn't make sense to have one |
476 | file local. */ | |
c906108c | 477 | ms_type = mst_file_data; |
b8fbeb18 | 478 | section = SECT_OFF_DATA (objfile); |
c906108c SS |
479 | bfd_section = DBX_DATA_SECTION (objfile); |
480 | break; | |
481 | #endif | |
482 | case N_TEXT: | |
483 | case N_NBTEXT: | |
484 | case N_FN: | |
485 | case N_FN_SEQ: | |
486 | ms_type = mst_file_text; | |
b8fbeb18 | 487 | section = SECT_OFF_TEXT (objfile); |
c906108c SS |
488 | bfd_section = DBX_TEXT_SECTION (objfile); |
489 | break; | |
490 | case N_DATA: | |
491 | ms_type = mst_file_data; | |
492 | ||
493 | /* Check for __DYNAMIC, which is used by Sun shared libraries. | |
c5aa993b JM |
494 | Record it as global even if it's local, not global, so |
495 | lookup_minimal_symbol can find it. We don't check symbol_leading_char | |
496 | because for SunOS4 it always is '_'. */ | |
c906108c SS |
497 | if (name[8] == 'C' && STREQ ("__DYNAMIC", name)) |
498 | ms_type = mst_data; | |
499 | ||
500 | /* Same with virtual function tables, both global and static. */ | |
501 | { | |
502 | char *tempstring = name; | |
503 | if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd)) | |
504 | ++tempstring; | |
015a42b4 | 505 | if (is_vtable_name (tempstring)) |
c906108c SS |
506 | ms_type = mst_data; |
507 | } | |
b8fbeb18 | 508 | section = SECT_OFF_DATA (objfile); |
c906108c SS |
509 | bfd_section = DBX_DATA_SECTION (objfile); |
510 | break; | |
511 | case N_BSS: | |
512 | ms_type = mst_file_bss; | |
b8fbeb18 | 513 | section = SECT_OFF_BSS (objfile); |
c906108c SS |
514 | bfd_section = DBX_BSS_SECTION (objfile); |
515 | break; | |
516 | default: | |
517 | ms_type = mst_unknown; | |
518 | section = -1; | |
519 | bfd_section = NULL; | |
520 | break; | |
c5aa993b | 521 | } |
c906108c SS |
522 | |
523 | if ((ms_type == mst_file_text || ms_type == mst_text) | |
524 | && address < lowest_text_address) | |
525 | lowest_text_address = address; | |
526 | ||
527 | prim_record_minimal_symbol_and_info | |
528 | (name, address, ms_type, NULL, section, bfd_section, objfile); | |
529 | } | |
530 | \f | |
531 | /* Scan and build partial symbols for a symbol file. | |
532 | We have been initialized by a call to dbx_symfile_init, which | |
533 | put all the relevant info into a "struct dbx_symfile_info", | |
534 | hung off the objfile structure. | |
535 | ||
c906108c SS |
536 | MAINLINE is true if we are reading the main symbol |
537 | table (as opposed to a shared lib or dynamically loaded file). */ | |
538 | ||
539 | static void | |
9df3df99 | 540 | dbx_symfile_read (struct objfile *objfile, int mainline) |
c906108c SS |
541 | { |
542 | bfd *sym_bfd; | |
543 | int val; | |
544 | struct cleanup *back_to; | |
545 | ||
c906108c SS |
546 | sym_bfd = objfile->obfd; |
547 | ||
548 | /* .o and .nlm files are relocatables with text, data and bss segs based at | |
549 | 0. This flag disables special (Solaris stabs-in-elf only) fixups for | |
550 | symbols with a value of 0. */ | |
551 | ||
552 | symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC; | |
553 | ||
554 | /* This is true for Solaris (and all other systems which put stabs | |
555 | in sections, hopefully, since it would be silly to do things | |
556 | differently from Solaris), and false for SunOS4 and other a.out | |
557 | file formats. */ | |
558 | block_address_function_relative = | |
559 | ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3)) | |
560 | || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3)) | |
561 | || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4)) | |
562 | || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2)) | |
c2d11a7d | 563 | || (0 == strncmp (bfd_get_target (sym_bfd), "epoc-pe", 7)) |
c906108c SS |
564 | || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3))); |
565 | ||
566 | val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET); | |
567 | if (val < 0) | |
568 | perror_with_name (objfile->name); | |
569 | ||
570 | /* If we are reinitializing, or if we have never loaded syms yet, init */ | |
571 | if (mainline | |
ef96bde8 EZ |
572 | || (objfile->global_psymbols.size == 0 |
573 | && objfile->static_psymbols.size == 0)) | |
c906108c SS |
574 | init_psymbol_list (objfile, DBX_SYMCOUNT (objfile)); |
575 | ||
576 | symbol_size = DBX_SYMBOL_SIZE (objfile); | |
577 | symbol_table_offset = DBX_SYMTAB_OFFSET (objfile); | |
578 | ||
579 | free_pending_blocks (); | |
a0b3c4fd | 580 | back_to = make_cleanup (really_free_pendings, 0); |
c906108c SS |
581 | |
582 | init_minimal_symbol_collection (); | |
56e290f4 | 583 | make_cleanup_discard_minimal_symbols (); |
c906108c | 584 | |
d4f3574e | 585 | /* Read stabs data from executable file and define symbols. */ |
c906108c | 586 | |
d4f3574e | 587 | read_dbx_symtab (objfile); |
c906108c SS |
588 | |
589 | /* Add the dynamic symbols. */ | |
590 | ||
96baa820 | 591 | read_dbx_dynamic_symtab (objfile); |
c906108c SS |
592 | |
593 | /* Install any minimal symbols that have been collected as the current | |
594 | minimal symbols for this objfile. */ | |
595 | ||
596 | install_minimal_symbols (objfile); | |
597 | ||
598 | do_cleanups (back_to); | |
599 | } | |
600 | ||
601 | /* Initialize anything that needs initializing when a completely new | |
602 | symbol file is specified (not just adding some symbols from another | |
603 | file, e.g. a shared library). */ | |
604 | ||
605 | static void | |
fba45db2 | 606 | dbx_new_init (struct objfile *ignore) |
c906108c SS |
607 | { |
608 | stabsread_new_init (); | |
609 | buildsym_new_init (); | |
610 | init_header_files (); | |
611 | } | |
612 | ||
613 | ||
614 | /* dbx_symfile_init () | |
615 | is the dbx-specific initialization routine for reading symbols. | |
616 | It is passed a struct objfile which contains, among other things, | |
617 | the BFD for the file whose symbols are being read, and a slot for a pointer | |
618 | to "private data" which we fill with goodies. | |
619 | ||
620 | We read the string table into malloc'd space and stash a pointer to it. | |
621 | ||
622 | Since BFD doesn't know how to read debug symbols in a format-independent | |
623 | way (and may never do so...), we have to do it ourselves. We will never | |
624 | be called unless this is an a.out (or very similar) file. | |
625 | FIXME, there should be a cleaner peephole into the BFD environment here. */ | |
626 | ||
c5aa993b | 627 | #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */ |
c906108c SS |
628 | |
629 | static void | |
fba45db2 | 630 | dbx_symfile_init (struct objfile *objfile) |
c906108c SS |
631 | { |
632 | int val; | |
633 | bfd *sym_bfd = objfile->obfd; | |
634 | char *name = bfd_get_filename (sym_bfd); | |
635 | asection *text_sect; | |
636 | unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE]; | |
637 | ||
638 | /* Allocate struct to keep track of the symfile */ | |
639 | objfile->sym_stab_info = (struct dbx_symfile_info *) | |
c5aa993b | 640 | xmmalloc (objfile->md, sizeof (struct dbx_symfile_info)); |
4efb68b1 | 641 | memset (objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info)); |
c906108c SS |
642 | |
643 | DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text"); | |
644 | DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data"); | |
645 | DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss"); | |
646 | ||
647 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ | |
648 | #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd)) | |
649 | #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd)) | |
650 | ||
651 | /* FIXME POKING INSIDE BFD DATA STRUCTURES */ | |
652 | ||
653 | DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL; | |
c5aa993b | 654 | |
c906108c SS |
655 | text_sect = bfd_get_section_by_name (sym_bfd, ".text"); |
656 | if (!text_sect) | |
657 | error ("Can't find .text section in symbol file"); | |
658 | DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect); | |
659 | DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect); | |
660 | ||
661 | DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd); | |
662 | DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd); | |
663 | DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET; | |
664 | ||
665 | /* Read the string table and stash it away in the psymbol_obstack. It is | |
666 | only needed as long as we need to expand psymbols into full symbols, | |
667 | so when we blow away the psymbol the string table goes away as well. | |
668 | Note that gdb used to use the results of attempting to malloc the | |
669 | string table, based on the size it read, as a form of sanity check | |
670 | for botched byte swapping, on the theory that a byte swapped string | |
671 | table size would be so totally bogus that the malloc would fail. Now | |
672 | that we put in on the psymbol_obstack, we can't do this since gdb gets | |
673 | a fatal error (out of virtual memory) if the size is bogus. We can | |
674 | however at least check to see if the size is less than the size of | |
675 | the size field itself, or larger than the size of the entire file. | |
676 | Note that all valid string tables have a size greater than zero, since | |
677 | the bytes used to hold the size are included in the count. */ | |
678 | ||
679 | if (STRING_TABLE_OFFSET == 0) | |
680 | { | |
681 | /* It appears that with the existing bfd code, STRING_TABLE_OFFSET | |
c5aa993b JM |
682 | will never be zero, even when there is no string table. This |
683 | would appear to be a bug in bfd. */ | |
c906108c SS |
684 | DBX_STRINGTAB_SIZE (objfile) = 0; |
685 | DBX_STRINGTAB (objfile) = NULL; | |
686 | } | |
687 | else | |
688 | { | |
689 | val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET); | |
690 | if (val < 0) | |
691 | perror_with_name (name); | |
c5aa993b | 692 | |
4efb68b1 AC |
693 | memset (size_temp, 0, sizeof (size_temp)); |
694 | val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd); | |
c906108c SS |
695 | if (val < 0) |
696 | { | |
697 | perror_with_name (name); | |
698 | } | |
699 | else if (val == 0) | |
700 | { | |
701 | /* With the existing bfd code, STRING_TABLE_OFFSET will be set to | |
702 | EOF if there is no string table, and attempting to read the size | |
703 | from EOF will read zero bytes. */ | |
704 | DBX_STRINGTAB_SIZE (objfile) = 0; | |
705 | DBX_STRINGTAB (objfile) = NULL; | |
706 | } | |
707 | else | |
708 | { | |
709 | /* Read some data that would appear to be the string table size. | |
710 | If there really is a string table, then it is probably the right | |
711 | size. Byteswap if necessary and validate the size. Note that | |
712 | the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some | |
713 | random data that happened to be at STRING_TABLE_OFFSET, because | |
714 | bfd can't tell us there is no string table, the sanity checks may | |
715 | or may not catch this. */ | |
716 | DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp); | |
c5aa993b | 717 | |
c906108c SS |
718 | if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp) |
719 | || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd)) | |
720 | error ("ridiculous string table size (%d bytes).", | |
721 | DBX_STRINGTAB_SIZE (objfile)); | |
c5aa993b | 722 | |
c906108c | 723 | DBX_STRINGTAB (objfile) = |
c5aa993b | 724 | (char *) obstack_alloc (&objfile->psymbol_obstack, |
c906108c SS |
725 | DBX_STRINGTAB_SIZE (objfile)); |
726 | OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile)); | |
c5aa993b | 727 | |
c906108c | 728 | /* Now read in the string table in one big gulp. */ |
c5aa993b | 729 | |
c906108c SS |
730 | val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET); |
731 | if (val < 0) | |
732 | perror_with_name (name); | |
3a42e9d0 AM |
733 | val = bfd_bread (DBX_STRINGTAB (objfile), |
734 | DBX_STRINGTAB_SIZE (objfile), | |
735 | sym_bfd); | |
c906108c SS |
736 | if (val != DBX_STRINGTAB_SIZE (objfile)) |
737 | perror_with_name (name); | |
738 | } | |
739 | } | |
740 | } | |
741 | ||
742 | /* Perform any local cleanups required when we are done with a particular | |
743 | objfile. I.E, we are in the process of discarding all symbol information | |
744 | for an objfile, freeing up all memory held for it, and unlinking the | |
745 | objfile struct from the global list of known objfiles. */ | |
746 | ||
747 | static void | |
fba45db2 | 748 | dbx_symfile_finish (struct objfile *objfile) |
c906108c SS |
749 | { |
750 | if (objfile->sym_stab_info != NULL) | |
751 | { | |
752 | if (HEADER_FILES (objfile) != NULL) | |
753 | { | |
754 | register int i = N_HEADER_FILES (objfile); | |
755 | register struct header_file *hfiles = HEADER_FILES (objfile); | |
756 | ||
757 | while (--i >= 0) | |
758 | { | |
b8c9b27d KB |
759 | xfree (hfiles[i].name); |
760 | xfree (hfiles[i].vector); | |
c906108c | 761 | } |
b8c9b27d | 762 | xfree (hfiles); |
c906108c | 763 | } |
aac7f4ea | 764 | xmfree (objfile->md, objfile->sym_stab_info); |
c906108c SS |
765 | } |
766 | free_header_files (); | |
767 | } | |
c906108c | 768 | \f |
c5aa993b | 769 | |
c906108c SS |
770 | /* Buffer for reading the symbol table entries. */ |
771 | static struct external_nlist symbuf[4096]; | |
772 | static int symbuf_idx; | |
773 | static int symbuf_end; | |
774 | ||
25caa7a8 EZ |
775 | #if 0 /* OBSOLETE CFront */ |
776 | // OBSOLETE /* cont_elem is used for continuing information in cfront. | |
777 | // OBSOLETE It saves information about which types need to be fixed up and | |
778 | // OBSOLETE completed after all the stabs are read. */ | |
779 | // OBSOLETE struct cont_elem | |
780 | // OBSOLETE { | |
781 | // OBSOLETE /* sym and stabstring for continuing information in cfront */ | |
782 | // OBSOLETE struct symbol *sym; | |
783 | // OBSOLETE char *stabs; | |
784 | // OBSOLETE /* state dependencies (statics that must be preserved) */ | |
785 | // OBSOLETE int sym_idx; | |
786 | // OBSOLETE int sym_end; | |
787 | // OBSOLETE int symnum; | |
788 | // OBSOLETE int (*func) (struct objfile *, struct symbol *, char *); | |
789 | // OBSOLETE /* other state dependencies include: | |
790 | // OBSOLETE (assumption is that these will not change since process_now FIXME!!) | |
791 | // OBSOLETE stringtab_global | |
792 | // OBSOLETE n_stabs | |
793 | // OBSOLETE objfile | |
794 | // OBSOLETE symfile_bfd */ | |
795 | // OBSOLETE }; | |
796 | ||
797 | // OBSOLETE static struct cont_elem *cont_list = 0; | |
798 | // OBSOLETE static int cont_limit = 0; | |
799 | // OBSOLETE static int cont_count = 0; | |
800 | ||
801 | // OBSOLETE /* Arrange for function F to be called with arguments SYM and P later | |
802 | // OBSOLETE in the stabs reading process. */ | |
803 | // OBSOLETE void | |
804 | // OBSOLETE process_later (struct symbol *sym, char *p, | |
805 | // OBSOLETE int (*f) (struct objfile *, struct symbol *, char *)) | |
806 | // OBSOLETE { | |
807 | ||
808 | // OBSOLETE /* Allocate more space for the deferred list. */ | |
809 | // OBSOLETE if (cont_count >= cont_limit - 1) | |
810 | // OBSOLETE { | |
811 | // OBSOLETE cont_limit += 32; /* chunk size */ | |
812 | ||
813 | // OBSOLETE cont_list | |
814 | // OBSOLETE = (struct cont_elem *) xrealloc (cont_list, | |
815 | // OBSOLETE (cont_limit | |
816 | // OBSOLETE * sizeof (struct cont_elem))); | |
817 | // OBSOLETE if (!cont_list) | |
818 | // OBSOLETE error ("Virtual memory exhausted\n"); | |
819 | // OBSOLETE } | |
820 | ||
821 | // OBSOLETE /* Save state variables so we can process these stabs later. */ | |
822 | // OBSOLETE cont_list[cont_count].sym_idx = symbuf_idx; | |
823 | // OBSOLETE cont_list[cont_count].sym_end = symbuf_end; | |
824 | // OBSOLETE cont_list[cont_count].symnum = symnum; | |
825 | // OBSOLETE cont_list[cont_count].sym = sym; | |
826 | // OBSOLETE cont_list[cont_count].stabs = p; | |
827 | // OBSOLETE cont_list[cont_count].func = f; | |
828 | // OBSOLETE cont_count++; | |
829 | // OBSOLETE } | |
830 | ||
831 | // OBSOLETE /* Call deferred funtions in CONT_LIST. */ | |
832 | ||
833 | // OBSOLETE static void | |
834 | // OBSOLETE process_now (struct objfile *objfile) | |
835 | // OBSOLETE { | |
836 | // OBSOLETE int i; | |
837 | // OBSOLETE int save_symbuf_idx; | |
838 | // OBSOLETE int save_symbuf_end; | |
839 | // OBSOLETE int save_symnum; | |
840 | // OBSOLETE struct symbol *sym; | |
841 | // OBSOLETE char *stabs; | |
842 | // OBSOLETE int err; | |
843 | // OBSOLETE int (*func) (struct objfile *, struct symbol *, char *); | |
844 | ||
845 | // OBSOLETE /* Save the state of our caller, we'll want to restore it before | |
846 | // OBSOLETE returning. */ | |
847 | // OBSOLETE save_symbuf_idx = symbuf_idx; | |
848 | // OBSOLETE save_symbuf_end = symbuf_end; | |
849 | // OBSOLETE save_symnum = symnum; | |
850 | ||
851 | // OBSOLETE /* Iterate over all the deferred stabs. */ | |
852 | // OBSOLETE for (i = 0; i < cont_count; i++) | |
853 | // OBSOLETE { | |
854 | // OBSOLETE /* Restore the state for this deferred stab. */ | |
855 | // OBSOLETE symbuf_idx = cont_list[i].sym_idx; | |
856 | // OBSOLETE symbuf_end = cont_list[i].sym_end; | |
857 | // OBSOLETE symnum = cont_list[i].symnum; | |
858 | // OBSOLETE sym = cont_list[i].sym; | |
859 | // OBSOLETE stabs = cont_list[i].stabs; | |
860 | // OBSOLETE func = cont_list[i].func; | |
861 | ||
862 | // OBSOLETE /* Call the function to handle this deferrd stab. */ | |
863 | // OBSOLETE err = (*func) (objfile, sym, stabs); | |
864 | // OBSOLETE if (err) | |
865 | // OBSOLETE error ("Internal error: unable to resolve stab.\n"); | |
866 | // OBSOLETE } | |
867 | ||
868 | // OBSOLETE /* Restore our caller's state. */ | |
869 | // OBSOLETE symbuf_idx = save_symbuf_idx; | |
870 | // OBSOLETE symbuf_end = save_symbuf_end; | |
871 | // OBSOLETE symnum = save_symnum; | |
872 | // OBSOLETE cont_count = 0; | |
873 | // OBSOLETE } | |
874 | #endif /* OBSOLETE CFront */ | |
c906108c SS |
875 | |
876 | /* Name of last function encountered. Used in Solaris to approximate | |
877 | object file boundaries. */ | |
878 | static char *last_function_name; | |
879 | ||
880 | /* The address in memory of the string table of the object file we are | |
881 | reading (which might not be the "main" object file, but might be a | |
882 | shared library or some other dynamically loaded thing). This is | |
883 | set by read_dbx_symtab when building psymtabs, and by | |
884 | read_ofile_symtab when building symtabs, and is used only by | |
885 | next_symbol_text. FIXME: If that is true, we don't need it when | |
886 | building psymtabs, right? */ | |
887 | static char *stringtab_global; | |
888 | ||
889 | /* These variables are used to control fill_symbuf when the stabs | |
890 | symbols are not contiguous (as may be the case when a COFF file is | |
891 | linked using --split-by-reloc). */ | |
892 | static struct stab_section_list *symbuf_sections; | |
893 | static unsigned int symbuf_left; | |
894 | static unsigned int symbuf_read; | |
895 | ||
086df311 DJ |
896 | /* This variable stores a global stabs buffer, if we read stabs into |
897 | memory in one chunk in order to process relocations. */ | |
898 | static bfd_byte *stabs_data; | |
899 | ||
c906108c SS |
900 | /* Refill the symbol table input buffer |
901 | and set the variables that control fetching entries from it. | |
902 | Reports an error if no data available. | |
903 | This function can read past the end of the symbol table | |
904 | (into the string table) but this does no harm. */ | |
905 | ||
906 | static void | |
fba45db2 | 907 | fill_symbuf (bfd *sym_bfd) |
c906108c SS |
908 | { |
909 | unsigned int count; | |
910 | int nbytes; | |
911 | ||
086df311 DJ |
912 | if (stabs_data) |
913 | { | |
914 | nbytes = sizeof (symbuf); | |
915 | if (nbytes > symbuf_left) | |
916 | nbytes = symbuf_left; | |
917 | memcpy (symbuf, stabs_data + symbuf_read, nbytes); | |
918 | } | |
919 | else if (symbuf_sections == NULL) | |
920 | { | |
921 | count = sizeof (symbuf); | |
922 | nbytes = bfd_bread (symbuf, count, sym_bfd); | |
923 | } | |
c906108c SS |
924 | else |
925 | { | |
926 | if (symbuf_left <= 0) | |
927 | { | |
928 | file_ptr filepos = symbuf_sections->section->filepos; | |
929 | if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0) | |
930 | perror_with_name (bfd_get_filename (sym_bfd)); | |
931 | symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section); | |
932 | symbol_table_offset = filepos - symbuf_read; | |
933 | symbuf_sections = symbuf_sections->next; | |
934 | } | |
935 | ||
936 | count = symbuf_left; | |
937 | if (count > sizeof (symbuf)) | |
938 | count = sizeof (symbuf); | |
086df311 | 939 | nbytes = bfd_bread (symbuf, count, sym_bfd); |
c906108c SS |
940 | } |
941 | ||
c906108c SS |
942 | if (nbytes < 0) |
943 | perror_with_name (bfd_get_filename (sym_bfd)); | |
944 | else if (nbytes == 0) | |
945 | error ("Premature end of file reading symbol table"); | |
946 | symbuf_end = nbytes / symbol_size; | |
947 | symbuf_idx = 0; | |
948 | symbuf_left -= nbytes; | |
949 | symbuf_read += nbytes; | |
950 | } | |
951 | ||
086df311 DJ |
952 | static void |
953 | stabs_seek (int sym_offset) | |
954 | { | |
955 | if (stabs_data) | |
956 | { | |
957 | symbuf_read += sym_offset; | |
958 | symbuf_left -= sym_offset; | |
959 | } | |
960 | else | |
961 | bfd_seek (symfile_bfd, sym_offset, SEEK_CUR); | |
962 | } | |
963 | ||
c906108c SS |
964 | #define INTERNALIZE_SYMBOL(intern, extern, abfd) \ |
965 | { \ | |
966 | (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \ | |
967 | (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \ | |
968 | (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \ | |
40b3352b L |
969 | if (bfd_get_sign_extend_vma (abfd)) \ |
970 | (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \ | |
971 | else \ | |
972 | (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \ | |
c906108c SS |
973 | } |
974 | ||
975 | /* Invariant: The symbol pointed to by symbuf_idx is the first one | |
976 | that hasn't been swapped. Swap the symbol at the same time | |
977 | that symbuf_idx is incremented. */ | |
978 | ||
979 | /* dbx allows the text of a symbol name to be continued into the | |
980 | next symbol name! When such a continuation is encountered | |
981 | (a \ at the end of the text of a name) | |
982 | call this function to get the continuation. */ | |
983 | ||
984 | static char * | |
fba45db2 | 985 | dbx_next_symbol_text (struct objfile *objfile) |
c906108c SS |
986 | { |
987 | struct internal_nlist nlist; | |
988 | ||
989 | if (symbuf_idx == symbuf_end) | |
990 | fill_symbuf (symfile_bfd); | |
991 | ||
992 | symnum++; | |
c5aa993b | 993 | INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd); |
c906108c SS |
994 | OBJSTAT (objfile, n_stabs++); |
995 | ||
996 | symbuf_idx++; | |
997 | ||
998 | return nlist.n_strx + stringtab_global + file_string_table_offset; | |
999 | } | |
1000 | \f | |
1001 | /* Initialize the list of bincls to contain none and have some | |
1002 | allocated. */ | |
1003 | ||
1004 | static void | |
fba45db2 | 1005 | init_bincl_list (int number, struct objfile *objfile) |
c906108c SS |
1006 | { |
1007 | bincls_allocated = number; | |
1008 | next_bincl = bincl_list = (struct header_file_location *) | |
c5aa993b | 1009 | xmmalloc (objfile->md, bincls_allocated * sizeof (struct header_file_location)); |
c906108c SS |
1010 | } |
1011 | ||
1012 | /* Add a bincl to the list. */ | |
1013 | ||
1014 | static void | |
fba45db2 | 1015 | add_bincl_to_list (struct partial_symtab *pst, char *name, int instance) |
c906108c SS |
1016 | { |
1017 | if (next_bincl >= bincl_list + bincls_allocated) | |
1018 | { | |
1019 | int offset = next_bincl - bincl_list; | |
1020 | bincls_allocated *= 2; | |
1021 | bincl_list = (struct header_file_location *) | |
c5aa993b JM |
1022 | xmrealloc (pst->objfile->md, (char *) bincl_list, |
1023 | bincls_allocated * sizeof (struct header_file_location)); | |
c906108c SS |
1024 | next_bincl = bincl_list + offset; |
1025 | } | |
1026 | next_bincl->pst = pst; | |
1027 | next_bincl->instance = instance; | |
1028 | next_bincl++->name = name; | |
1029 | } | |
1030 | ||
1031 | /* Given a name, value pair, find the corresponding | |
1032 | bincl in the list. Return the partial symtab associated | |
1033 | with that header_file_location. */ | |
1034 | ||
1035 | static struct partial_symtab * | |
fba45db2 | 1036 | find_corresponding_bincl_psymtab (char *name, int instance) |
c906108c SS |
1037 | { |
1038 | struct header_file_location *bincl; | |
1039 | ||
1040 | for (bincl = bincl_list; bincl < next_bincl; bincl++) | |
1041 | if (bincl->instance == instance | |
1042 | && STREQ (name, bincl->name)) | |
1043 | return bincl->pst; | |
1044 | ||
23136709 | 1045 | repeated_header_complaint (name, symnum); |
c906108c SS |
1046 | return (struct partial_symtab *) 0; |
1047 | } | |
1048 | ||
1049 | /* Free the storage allocated for the bincl list. */ | |
1050 | ||
1051 | static void | |
fba45db2 | 1052 | free_bincl_list (struct objfile *objfile) |
c906108c | 1053 | { |
4efb68b1 | 1054 | xmfree (objfile->md, bincl_list); |
c906108c SS |
1055 | bincls_allocated = 0; |
1056 | } | |
1057 | ||
74b7792f AC |
1058 | static void |
1059 | do_free_bincl_list_cleanup (void *objfile) | |
1060 | { | |
1061 | free_bincl_list (objfile); | |
1062 | } | |
1063 | ||
1064 | static struct cleanup * | |
1065 | make_cleanup_free_bincl_list (struct objfile *objfile) | |
1066 | { | |
1067 | return make_cleanup (do_free_bincl_list_cleanup, objfile); | |
1068 | } | |
1069 | ||
6a34fd2f EZ |
1070 | /* Set namestring based on nlist. If the string table index is invalid, |
1071 | give a fake name, and print a single error message per symbol file read, | |
1072 | rather than abort the symbol reading or flood the user with messages. */ | |
1073 | ||
1074 | static char * | |
1075 | set_namestring (struct objfile *objfile, struct internal_nlist nlist) | |
1076 | { | |
1077 | char *namestring; | |
1078 | ||
1079 | if (((unsigned) nlist.n_strx + file_string_table_offset) >= | |
1080 | DBX_STRINGTAB_SIZE (objfile)) | |
1081 | { | |
23136709 KB |
1082 | complaint (&symfile_complaints, "bad string table offset in symbol %d", |
1083 | symnum); | |
6a34fd2f EZ |
1084 | namestring = "<bad string table offset>"; |
1085 | } | |
1086 | else | |
1087 | namestring = nlist.n_strx + file_string_table_offset + | |
1088 | DBX_STRINGTAB (objfile); | |
1089 | return namestring; | |
1090 | } | |
1091 | ||
c906108c SS |
1092 | /* Scan a SunOs dynamic symbol table for symbols of interest and |
1093 | add them to the minimal symbol table. */ | |
1094 | ||
1095 | static void | |
fba45db2 | 1096 | read_dbx_dynamic_symtab (struct objfile *objfile) |
c906108c SS |
1097 | { |
1098 | bfd *abfd = objfile->obfd; | |
1099 | struct cleanup *back_to; | |
1100 | int counter; | |
1101 | long dynsym_size; | |
1102 | long dynsym_count; | |
1103 | asymbol **dynsyms; | |
1104 | asymbol **symptr; | |
1105 | arelent **relptr; | |
1106 | long dynrel_size; | |
1107 | long dynrel_count; | |
1108 | arelent **dynrels; | |
1109 | CORE_ADDR sym_value; | |
1110 | char *name; | |
1111 | ||
1112 | /* Check that the symbol file has dynamic symbols that we know about. | |
1113 | bfd_arch_unknown can happen if we are reading a sun3 symbol file | |
1114 | on a sun4 host (and vice versa) and bfd is not configured | |
1115 | --with-target=all. This would trigger an assertion in bfd/sunos.c, | |
1116 | so we ignore the dynamic symbols in this case. */ | |
1117 | if (bfd_get_flavour (abfd) != bfd_target_aout_flavour | |
1118 | || (bfd_get_file_flags (abfd) & DYNAMIC) == 0 | |
1119 | || bfd_get_arch (abfd) == bfd_arch_unknown) | |
1120 | return; | |
1121 | ||
1122 | dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd); | |
1123 | if (dynsym_size < 0) | |
1124 | return; | |
1125 | ||
1126 | dynsyms = (asymbol **) xmalloc (dynsym_size); | |
b8c9b27d | 1127 | back_to = make_cleanup (xfree, dynsyms); |
c906108c SS |
1128 | |
1129 | dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms); | |
1130 | if (dynsym_count < 0) | |
1131 | { | |
1132 | do_cleanups (back_to); | |
1133 | return; | |
1134 | } | |
1135 | ||
1136 | /* Enter dynamic symbols into the minimal symbol table | |
1137 | if this is a stripped executable. */ | |
1138 | if (bfd_get_symcount (abfd) <= 0) | |
1139 | { | |
1140 | symptr = dynsyms; | |
1141 | for (counter = 0; counter < dynsym_count; counter++, symptr++) | |
1142 | { | |
1143 | asymbol *sym = *symptr; | |
1144 | asection *sec; | |
1145 | int type; | |
1146 | ||
1147 | sec = bfd_get_section (sym); | |
1148 | ||
1149 | /* BFD symbols are section relative. */ | |
1150 | sym_value = sym->value + sec->vma; | |
1151 | ||
1152 | if (bfd_get_section_flags (abfd, sec) & SEC_CODE) | |
1153 | { | |
b8fbeb18 | 1154 | sym_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1155 | type = N_TEXT; |
1156 | } | |
1157 | else if (bfd_get_section_flags (abfd, sec) & SEC_DATA) | |
1158 | { | |
b8fbeb18 | 1159 | sym_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); |
c906108c SS |
1160 | type = N_DATA; |
1161 | } | |
1162 | else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) | |
1163 | { | |
b8fbeb18 | 1164 | sym_value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); |
c906108c SS |
1165 | type = N_BSS; |
1166 | } | |
1167 | else | |
1168 | continue; | |
1169 | ||
1170 | if (sym->flags & BSF_GLOBAL) | |
1171 | type |= N_EXT; | |
1172 | ||
1173 | record_minimal_symbol ((char *) bfd_asymbol_name (sym), sym_value, | |
1174 | type, objfile); | |
1175 | } | |
1176 | } | |
1177 | ||
1178 | /* Symbols from shared libraries have a dynamic relocation entry | |
1179 | that points to the associated slot in the procedure linkage table. | |
1180 | We make a mininal symbol table entry with type mst_solib_trampoline | |
1181 | at the address in the procedure linkage table. */ | |
1182 | dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd); | |
1183 | if (dynrel_size < 0) | |
1184 | { | |
1185 | do_cleanups (back_to); | |
1186 | return; | |
1187 | } | |
c5aa993b | 1188 | |
c906108c | 1189 | dynrels = (arelent **) xmalloc (dynrel_size); |
b8c9b27d | 1190 | make_cleanup (xfree, dynrels); |
c906108c SS |
1191 | |
1192 | dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms); | |
1193 | if (dynrel_count < 0) | |
1194 | { | |
1195 | do_cleanups (back_to); | |
1196 | return; | |
1197 | } | |
1198 | ||
1199 | for (counter = 0, relptr = dynrels; | |
1200 | counter < dynrel_count; | |
1201 | counter++, relptr++) | |
1202 | { | |
1203 | arelent *rel = *relptr; | |
1204 | CORE_ADDR address = | |
b8fbeb18 | 1205 | rel->address + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); |
c906108c SS |
1206 | |
1207 | switch (bfd_get_arch (abfd)) | |
1208 | { | |
1209 | case bfd_arch_sparc: | |
1210 | if (rel->howto->type != RELOC_JMP_SLOT) | |
1211 | continue; | |
1212 | break; | |
1213 | case bfd_arch_m68k: | |
1214 | /* `16' is the type BFD produces for a jump table relocation. */ | |
1215 | if (rel->howto->type != 16) | |
1216 | continue; | |
1217 | ||
1218 | /* Adjust address in the jump table to point to | |
1219 | the start of the bsr instruction. */ | |
1220 | address -= 2; | |
1221 | break; | |
1222 | default: | |
1223 | continue; | |
1224 | } | |
1225 | ||
1226 | name = (char *) bfd_asymbol_name (*rel->sym_ptr_ptr); | |
1227 | prim_record_minimal_symbol (name, address, mst_solib_trampoline, | |
1228 | objfile); | |
1229 | } | |
1230 | ||
1231 | do_cleanups (back_to); | |
1232 | } | |
1233 | ||
4867e41e DM |
1234 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING |
1235 | CORE_ADDR | |
1236 | find_stab_function_addr (char *namestring, char *filename, | |
1237 | struct objfile *objfile) | |
1238 | { | |
1239 | struct minimal_symbol *msym; | |
1240 | char *p; | |
1241 | int n; | |
1242 | ||
1243 | p = strchr (namestring, ':'); | |
1244 | if (p == NULL) | |
1245 | p = namestring; | |
1246 | n = p - namestring; | |
1247 | p = alloca (n + 2); | |
1248 | strncpy (p, namestring, n); | |
1249 | p[n] = 0; | |
1250 | ||
1251 | msym = lookup_minimal_symbol (p, filename, objfile); | |
1252 | if (msym == NULL) | |
1253 | { | |
1254 | /* Sun Fortran appends an underscore to the minimal symbol name, | |
1255 | try again with an appended underscore if the minimal symbol | |
1256 | was not found. */ | |
1257 | p[n] = '_'; | |
1258 | p[n + 1] = 0; | |
1259 | msym = lookup_minimal_symbol (p, filename, objfile); | |
1260 | } | |
1261 | ||
1262 | if (msym == NULL && filename != NULL) | |
1263 | { | |
1264 | /* Try again without the filename. */ | |
1265 | p[n] = 0; | |
1266 | msym = lookup_minimal_symbol (p, NULL, objfile); | |
1267 | } | |
1268 | if (msym == NULL && filename != NULL) | |
1269 | { | |
1270 | /* And try again for Sun Fortran, but without the filename. */ | |
1271 | p[n] = '_'; | |
1272 | p[n + 1] = 0; | |
1273 | msym = lookup_minimal_symbol (p, NULL, objfile); | |
1274 | } | |
1275 | ||
1276 | return msym == NULL ? 0 : SYMBOL_VALUE_ADDRESS (msym); | |
1277 | } | |
1278 | #endif /* SOFUN_ADDRESS_MAYBE_MISSING */ | |
1279 | ||
23136709 KB |
1280 | static void |
1281 | function_outside_compilation_unit_complaint (const char *arg1) | |
1282 | { | |
1283 | complaint (&symfile_complaints, | |
1284 | "function `%s' appears to be defined outside of all compilation units", | |
1285 | arg1); | |
1286 | } | |
1287 | ||
d4f3574e SS |
1288 | /* Setup partial_symtab's describing each source file for which |
1289 | debugging information is available. */ | |
c906108c SS |
1290 | |
1291 | static void | |
fba45db2 | 1292 | read_dbx_symtab (struct objfile *objfile) |
c906108c SS |
1293 | { |
1294 | register struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch */ | |
1295 | struct internal_nlist nlist; | |
d4f3574e SS |
1296 | CORE_ADDR text_addr; |
1297 | int text_size; | |
c906108c SS |
1298 | |
1299 | register char *namestring; | |
1300 | int nsl; | |
1301 | int past_first_source_file = 0; | |
1302 | CORE_ADDR last_o_file_start = 0; | |
1303 | CORE_ADDR last_function_start = 0; | |
1304 | struct cleanup *back_to; | |
1305 | bfd *abfd; | |
1306 | int textlow_not_set; | |
1307 | ||
1308 | /* Current partial symtab */ | |
1309 | struct partial_symtab *pst; | |
1310 | ||
1311 | /* List of current psymtab's include files */ | |
1312 | char **psymtab_include_list; | |
1313 | int includes_allocated; | |
1314 | int includes_used; | |
1315 | ||
1316 | /* Index within current psymtab dependency list */ | |
1317 | struct partial_symtab **dependency_list; | |
1318 | int dependencies_used, dependencies_allocated; | |
1319 | ||
d4f3574e SS |
1320 | text_addr = DBX_TEXT_ADDR (objfile); |
1321 | text_size = DBX_TEXT_SIZE (objfile); | |
1322 | ||
c906108c SS |
1323 | /* FIXME. We probably want to change stringtab_global rather than add this |
1324 | while processing every symbol entry. FIXME. */ | |
1325 | file_string_table_offset = 0; | |
1326 | next_file_string_table_offset = 0; | |
1327 | ||
1328 | stringtab_global = DBX_STRINGTAB (objfile); | |
c5aa993b | 1329 | |
c906108c SS |
1330 | pst = (struct partial_symtab *) 0; |
1331 | ||
1332 | includes_allocated = 30; | |
1333 | includes_used = 0; | |
1334 | psymtab_include_list = (char **) alloca (includes_allocated * | |
1335 | sizeof (char *)); | |
1336 | ||
1337 | dependencies_allocated = 30; | |
1338 | dependencies_used = 0; | |
1339 | dependency_list = | |
1340 | (struct partial_symtab **) alloca (dependencies_allocated * | |
1341 | sizeof (struct partial_symtab *)); | |
1342 | ||
1343 | /* Init bincl list */ | |
1344 | init_bincl_list (20, objfile); | |
74b7792f | 1345 | back_to = make_cleanup_free_bincl_list (objfile); |
c906108c SS |
1346 | |
1347 | last_source_file = NULL; | |
1348 | ||
96baa820 | 1349 | lowest_text_address = (CORE_ADDR) -1; |
c906108c SS |
1350 | |
1351 | symfile_bfd = objfile->obfd; /* For next_text_symbol */ | |
1352 | abfd = objfile->obfd; | |
1353 | symbuf_end = symbuf_idx = 0; | |
1354 | next_symbol_text_func = dbx_next_symbol_text; | |
1355 | textlow_not_set = 1; | |
1356 | has_line_numbers = 0; | |
1357 | ||
1358 | for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++) | |
1359 | { | |
1360 | /* Get the symbol for this run and pull out some info */ | |
c5aa993b | 1361 | QUIT; /* allow this to be interruptable */ |
c906108c SS |
1362 | if (symbuf_idx == symbuf_end) |
1363 | fill_symbuf (abfd); | |
1364 | bufp = &symbuf[symbuf_idx++]; | |
1365 | ||
1366 | /* | |
1367 | * Special case to speed up readin. | |
1368 | */ | |
1369 | if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE) | |
1370 | { | |
1371 | has_line_numbers = 1; | |
1372 | continue; | |
1373 | } | |
1374 | ||
1375 | INTERNALIZE_SYMBOL (nlist, bufp, abfd); | |
1376 | OBJSTAT (objfile, n_stabs++); | |
1377 | ||
1378 | /* Ok. There is a lot of code duplicated in the rest of this | |
1379 | switch statement (for efficiency reasons). Since I don't | |
1380 | like duplicating code, I will do my penance here, and | |
1381 | describe the code which is duplicated: | |
1382 | ||
c5aa993b JM |
1383 | *) The assignment to namestring. |
1384 | *) The call to strchr. | |
1385 | *) The addition of a partial symbol the the two partial | |
1386 | symbol lists. This last is a large section of code, so | |
1387 | I've imbedded it in the following macro. | |
6a34fd2f | 1388 | */ |
c5aa993b | 1389 | |
6a34fd2f EZ |
1390 | switch (nlist.n_type) |
1391 | { | |
6a34fd2f EZ |
1392 | char *p; |
1393 | /* | |
1394 | * Standard, external, non-debugger, symbols | |
1395 | */ | |
1396 | ||
1397 | case N_TEXT | N_EXT: | |
1398 | case N_NBTEXT | N_EXT: | |
1399 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1400 | goto record_it; | |
1401 | ||
1402 | case N_DATA | N_EXT: | |
1403 | case N_NBDATA | N_EXT: | |
1404 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); | |
1405 | goto record_it; | |
1406 | ||
1407 | case N_BSS: | |
1408 | case N_BSS | N_EXT: | |
1409 | case N_NBBSS | N_EXT: | |
1410 | case N_SETV | N_EXT: /* FIXME, is this in BSS? */ | |
1411 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); | |
1412 | goto record_it; | |
1413 | ||
1414 | case N_ABS | N_EXT: | |
1415 | record_it: | |
1416 | namestring = set_namestring (objfile, nlist); | |
1417 | ||
1418 | bss_ext_symbol: | |
1419 | record_minimal_symbol (namestring, nlist.n_value, | |
1420 | nlist.n_type, objfile); /* Always */ | |
1421 | continue; | |
1422 | ||
1423 | /* Standard, local, non-debugger, symbols */ | |
1424 | ||
1425 | case N_NBTEXT: | |
1426 | ||
1427 | /* We need to be able to deal with both N_FN or N_TEXT, | |
1428 | because we have no way of knowing whether the sys-supplied ld | |
1429 | or GNU ld was used to make the executable. Sequents throw | |
1430 | in another wrinkle -- they renumbered N_FN. */ | |
1431 | ||
1432 | case N_FN: | |
1433 | case N_FN_SEQ: | |
1434 | case N_TEXT: | |
1435 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1436 | namestring = set_namestring (objfile, nlist); | |
1437 | ||
1438 | if ((namestring[0] == '-' && namestring[1] == 'l') | |
1439 | || (namestring[(nsl = strlen (namestring)) - 1] == 'o' | |
1440 | && namestring[nsl - 2] == '.')) | |
1441 | { | |
1442 | if (objfile->ei.entry_point < nlist.n_value && | |
1443 | objfile->ei.entry_point >= last_o_file_start) | |
1444 | { | |
1445 | objfile->ei.entry_file_lowpc = last_o_file_start; | |
1446 | objfile->ei.entry_file_highpc = nlist.n_value; | |
1447 | } | |
1448 | if (past_first_source_file && pst | |
1449 | /* The gould NP1 uses low values for .o and -l symbols | |
1450 | which are not the address. */ | |
5afc051b | 1451 | && nlist.n_value >= pst->textlow) |
6a34fd2f EZ |
1452 | { |
1453 | end_psymtab (pst, psymtab_include_list, includes_used, | |
1454 | symnum * symbol_size, | |
5afc051b JB |
1455 | nlist.n_value > pst->texthigh |
1456 | ? nlist.n_value : pst->texthigh, | |
6a34fd2f EZ |
1457 | dependency_list, dependencies_used, textlow_not_set); |
1458 | pst = (struct partial_symtab *) 0; | |
1459 | includes_used = 0; | |
1460 | dependencies_used = 0; | |
1461 | } | |
1462 | else | |
1463 | past_first_source_file = 1; | |
1464 | last_o_file_start = nlist.n_value; | |
1465 | } | |
1466 | else | |
1467 | goto record_it; | |
1468 | continue; | |
1469 | ||
1470 | case N_DATA: | |
1471 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); | |
1472 | goto record_it; | |
1473 | ||
1474 | case N_UNDF | N_EXT: | |
1475 | if (nlist.n_value != 0) | |
1476 | { | |
1477 | /* This is a "Fortran COMMON" symbol. See if the target | |
1478 | environment knows where it has been relocated to. */ | |
1479 | ||
1480 | CORE_ADDR reladdr; | |
1481 | ||
1482 | namestring = set_namestring (objfile, nlist); | |
1483 | if (target_lookup_symbol (namestring, &reladdr)) | |
1484 | { | |
1485 | continue; /* Error in lookup; ignore symbol for now. */ | |
1486 | } | |
1487 | nlist.n_type ^= (N_BSS ^ N_UNDF); /* Define it as a bss-symbol */ | |
1488 | nlist.n_value = reladdr; | |
1489 | goto bss_ext_symbol; | |
1490 | } | |
1491 | continue; /* Just undefined, not COMMON */ | |
1492 | ||
1493 | case N_UNDF: | |
1494 | if (processing_acc_compilation && nlist.n_strx == 1) | |
1495 | { | |
1496 | /* Deal with relative offsets in the string table | |
1497 | used in ELF+STAB under Solaris. If we want to use the | |
1498 | n_strx field, which contains the name of the file, | |
1499 | we must adjust file_string_table_offset *before* calling | |
1500 | set_namestring(). */ | |
1501 | past_first_source_file = 1; | |
1502 | file_string_table_offset = next_file_string_table_offset; | |
1503 | next_file_string_table_offset = | |
1504 | file_string_table_offset + nlist.n_value; | |
1505 | if (next_file_string_table_offset < file_string_table_offset) | |
1506 | error ("string table offset backs up at %d", symnum); | |
1507 | /* FIXME -- replace error() with complaint. */ | |
1508 | continue; | |
1509 | } | |
1510 | continue; | |
1511 | ||
1512 | /* Lots of symbol types we can just ignore. */ | |
1513 | ||
1514 | case N_ABS: | |
1515 | case N_NBDATA: | |
1516 | case N_NBBSS: | |
1517 | continue; | |
1518 | ||
1519 | /* Keep going . . . */ | |
1520 | ||
1521 | /* | |
1522 | * Special symbol types for GNU | |
1523 | */ | |
1524 | case N_INDR: | |
1525 | case N_INDR | N_EXT: | |
1526 | case N_SETA: | |
1527 | case N_SETA | N_EXT: | |
1528 | case N_SETT: | |
1529 | case N_SETT | N_EXT: | |
1530 | case N_SETD: | |
1531 | case N_SETD | N_EXT: | |
1532 | case N_SETB: | |
1533 | case N_SETB | N_EXT: | |
1534 | case N_SETV: | |
1535 | continue; | |
1536 | ||
1537 | /* | |
1538 | * Debugger symbols | |
1539 | */ | |
1540 | ||
1541 | case N_SO: | |
1542 | { | |
1543 | CORE_ADDR valu; | |
1544 | static int prev_so_symnum = -10; | |
1545 | static int first_so_symnum; | |
1546 | char *p; | |
1547 | int prev_textlow_not_set; | |
1548 | ||
1549 | valu = nlist.n_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1550 | ||
1551 | prev_textlow_not_set = textlow_not_set; | |
1552 | ||
1553 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
1554 | /* A zero value is probably an indication for the SunPRO 3.0 | |
1555 | compiler. end_psymtab explicitly tests for zero, so | |
1556 | don't relocate it. */ | |
1557 | ||
1558 | if (nlist.n_value == 0) | |
1559 | { | |
1560 | textlow_not_set = 1; | |
1561 | valu = 0; | |
1562 | } | |
1563 | else | |
1564 | textlow_not_set = 0; | |
1565 | #else | |
1566 | textlow_not_set = 0; | |
1567 | #endif | |
1568 | past_first_source_file = 1; | |
1569 | ||
1570 | if (prev_so_symnum != symnum - 1) | |
1571 | { /* Here if prev stab wasn't N_SO */ | |
1572 | first_so_symnum = symnum; | |
1573 | ||
1574 | if (pst) | |
1575 | { | |
1576 | end_psymtab (pst, psymtab_include_list, includes_used, | |
1577 | symnum * symbol_size, | |
5afc051b | 1578 | valu > pst->texthigh ? valu : pst->texthigh, |
6a34fd2f EZ |
1579 | dependency_list, dependencies_used, |
1580 | prev_textlow_not_set); | |
1581 | pst = (struct partial_symtab *) 0; | |
1582 | includes_used = 0; | |
1583 | dependencies_used = 0; | |
1584 | } | |
1585 | } | |
1586 | ||
1587 | prev_so_symnum = symnum; | |
1588 | ||
1589 | /* End the current partial symtab and start a new one */ | |
1590 | ||
1591 | namestring = set_namestring (objfile, nlist); | |
1592 | ||
1593 | /* Null name means end of .o file. Don't start a new one. */ | |
1594 | if (*namestring == '\000') | |
1595 | continue; | |
1596 | ||
1597 | /* Some compilers (including gcc) emit a pair of initial N_SOs. | |
1598 | The first one is a directory name; the second the file name. | |
1599 | If pst exists, is empty, and has a filename ending in '/', | |
1600 | we assume the previous N_SO was a directory name. */ | |
1601 | ||
1602 | p = strrchr (namestring, '/'); | |
1603 | if (p && *(p + 1) == '\000') | |
1604 | continue; /* Simply ignore directory name SOs */ | |
1605 | ||
1606 | /* Some other compilers (C++ ones in particular) emit useless | |
1607 | SOs for non-existant .c files. We ignore all subsequent SOs that | |
1608 | immediately follow the first. */ | |
1609 | ||
1610 | if (!pst) | |
1611 | pst = start_psymtab (objfile, | |
1612 | namestring, valu, | |
1613 | first_so_symnum * symbol_size, | |
1614 | objfile->global_psymbols.next, | |
1615 | objfile->static_psymbols.next); | |
1616 | continue; | |
1617 | } | |
1618 | ||
1619 | case N_BINCL: | |
1620 | { | |
1621 | enum language tmp_language; | |
1622 | /* Add this bincl to the bincl_list for future EXCLs. No | |
1623 | need to save the string; it'll be around until | |
1624 | read_dbx_symtab function returns */ | |
1625 | ||
1626 | namestring = set_namestring (objfile, nlist); | |
1627 | tmp_language = deduce_language_from_filename (namestring); | |
1628 | ||
1629 | /* Only change the psymtab's language if we've learned | |
1630 | something useful (eg. tmp_language is not language_unknown). | |
1631 | In addition, to match what start_subfile does, never change | |
1632 | from C++ to C. */ | |
1633 | if (tmp_language != language_unknown | |
1634 | && (tmp_language != language_c | |
1635 | || psymtab_language != language_cplus)) | |
1636 | psymtab_language = tmp_language; | |
1637 | ||
1638 | if (pst == NULL) | |
1639 | { | |
1640 | /* FIXME: we should not get here without a PST to work on. | |
1641 | Attempt to recover. */ | |
23136709 KB |
1642 | complaint (&symfile_complaints, |
1643 | "N_BINCL %s not in entries for any file, at symtab pos %d", | |
1644 | namestring, symnum); | |
6a34fd2f EZ |
1645 | continue; |
1646 | } | |
1647 | add_bincl_to_list (pst, namestring, nlist.n_value); | |
1648 | ||
1649 | /* Mark down an include file in the current psymtab */ | |
1650 | ||
1651 | goto record_include_file; | |
1652 | } | |
1653 | ||
1654 | case N_SOL: | |
1655 | { | |
1656 | enum language tmp_language; | |
1657 | /* Mark down an include file in the current psymtab */ | |
1658 | ||
1659 | namestring = set_namestring (objfile, nlist); | |
1660 | tmp_language = deduce_language_from_filename (namestring); | |
1661 | ||
1662 | /* Only change the psymtab's language if we've learned | |
1663 | something useful (eg. tmp_language is not language_unknown). | |
1664 | In addition, to match what start_subfile does, never change | |
1665 | from C++ to C. */ | |
1666 | if (tmp_language != language_unknown | |
1667 | && (tmp_language != language_c | |
1668 | || psymtab_language != language_cplus)) | |
1669 | psymtab_language = tmp_language; | |
1670 | ||
1671 | /* In C++, one may expect the same filename to come round many | |
1672 | times, when code is coming alternately from the main file | |
1673 | and from inline functions in other files. So I check to see | |
1674 | if this is a file we've seen before -- either the main | |
1675 | source file, or a previously included file. | |
1676 | ||
1677 | This seems to be a lot of time to be spending on N_SOL, but | |
1678 | things like "break c-exp.y:435" need to work (I | |
1679 | suppose the psymtab_include_list could be hashed or put | |
1680 | in a binary tree, if profiling shows this is a major hog). */ | |
1681 | if (pst && STREQ (namestring, pst->filename)) | |
1682 | continue; | |
1683 | { | |
1684 | register int i; | |
1685 | for (i = 0; i < includes_used; i++) | |
1686 | if (STREQ (namestring, psymtab_include_list[i])) | |
1687 | { | |
1688 | i = -1; | |
1689 | break; | |
1690 | } | |
1691 | if (i == -1) | |
1692 | continue; | |
1693 | } | |
1694 | ||
1695 | record_include_file: | |
1696 | ||
1697 | psymtab_include_list[includes_used++] = namestring; | |
1698 | if (includes_used >= includes_allocated) | |
1699 | { | |
1700 | char **orig = psymtab_include_list; | |
1701 | ||
1702 | psymtab_include_list = (char **) | |
1703 | alloca ((includes_allocated *= 2) * | |
1704 | sizeof (char *)); | |
4efb68b1 | 1705 | memcpy (psymtab_include_list, orig, |
6a34fd2f EZ |
1706 | includes_used * sizeof (char *)); |
1707 | } | |
1708 | continue; | |
1709 | } | |
1710 | case N_LSYM: /* Typedef or automatic variable. */ | |
1711 | case N_STSYM: /* Data seg var -- static */ | |
1712 | case N_LCSYM: /* BSS " */ | |
1713 | case N_ROSYM: /* Read-only data seg var -- static. */ | |
1714 | case N_NBSTS: /* Gould nobase. */ | |
1715 | case N_NBLCS: /* symbols. */ | |
1716 | case N_FUN: | |
1717 | case N_GSYM: /* Global (extern) variable; can be | |
1718 | data or bss (sigh FIXME). */ | |
1719 | ||
1720 | /* Following may probably be ignored; I'll leave them here | |
1721 | for now (until I do Pascal and Modula 2 extensions). */ | |
1722 | ||
1723 | case N_PC: /* I may or may not need this; I | |
1724 | suspect not. */ | |
1725 | case N_M2C: /* I suspect that I can ignore this here. */ | |
1726 | case N_SCOPE: /* Same. */ | |
1727 | ||
1728 | namestring = set_namestring (objfile, nlist); | |
1729 | ||
1730 | /* See if this is an end of function stab. */ | |
1731 | if (pst && nlist.n_type == N_FUN && *namestring == '\000') | |
1732 | { | |
1733 | CORE_ADDR valu; | |
1734 | ||
1735 | /* It's value is the size (in bytes) of the function for | |
1736 | function relative stabs, or the address of the function's | |
1737 | end for old style stabs. */ | |
1738 | valu = nlist.n_value + last_function_start; | |
5afc051b JB |
1739 | if (pst->texthigh == 0 || valu > pst->texthigh) |
1740 | pst->texthigh = valu; | |
6a34fd2f EZ |
1741 | break; |
1742 | } | |
1743 | ||
1744 | p = (char *) strchr (namestring, ':'); | |
1745 | if (!p) | |
1746 | continue; /* Not a debugging symbol. */ | |
1747 | ||
1748 | ||
1749 | ||
1750 | /* Main processing section for debugging symbols which | |
1751 | the initial read through the symbol tables needs to worry | |
1752 | about. If we reach this point, the symbol which we are | |
1753 | considering is definitely one we are interested in. | |
1754 | p must also contain the (valid) index into the namestring | |
1755 | which indicates the debugging type symbol. */ | |
1756 | ||
1757 | switch (p[1]) | |
1758 | { | |
1759 | case 'S': | |
1760 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); | |
1761 | #ifdef STATIC_TRANSFORM_NAME | |
1762 | namestring = STATIC_TRANSFORM_NAME (namestring); | |
1763 | #endif | |
1764 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 1765 | VAR_DOMAIN, LOC_STATIC, |
6a34fd2f EZ |
1766 | &objfile->static_psymbols, |
1767 | 0, nlist.n_value, | |
1768 | psymtab_language, objfile); | |
1769 | continue; | |
1770 | case 'G': | |
1771 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); | |
1772 | /* The addresses in these entries are reported to be | |
1773 | wrong. See the code that reads 'G's for symtabs. */ | |
1774 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 1775 | VAR_DOMAIN, LOC_STATIC, |
6a34fd2f EZ |
1776 | &objfile->global_psymbols, |
1777 | 0, nlist.n_value, | |
1778 | psymtab_language, objfile); | |
1779 | continue; | |
1780 | ||
1781 | case 'T': | |
1782 | /* When a 'T' entry is defining an anonymous enum, it | |
1783 | may have a name which is the empty string, or a | |
1784 | single space. Since they're not really defining a | |
1785 | symbol, those shouldn't go in the partial symbol | |
1786 | table. We do pick up the elements of such enums at | |
1787 | 'check_enum:', below. */ | |
1788 | if (p >= namestring + 2 | |
1789 | || (p == namestring + 1 | |
1790 | && namestring[0] != ' ')) | |
1791 | { | |
1792 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 1793 | STRUCT_DOMAIN, LOC_TYPEDEF, |
6a34fd2f EZ |
1794 | &objfile->static_psymbols, |
1795 | nlist.n_value, 0, | |
1796 | psymtab_language, objfile); | |
1797 | if (p[2] == 't') | |
1798 | { | |
1799 | /* Also a typedef with the same name. */ | |
1800 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 1801 | VAR_DOMAIN, LOC_TYPEDEF, |
6a34fd2f EZ |
1802 | &objfile->static_psymbols, |
1803 | nlist.n_value, 0, | |
1804 | psymtab_language, objfile); | |
1805 | p += 1; | |
1806 | } | |
25caa7a8 EZ |
1807 | #if 0 /* OBSOLETE CFront */ |
1808 | // OBSOLETE /* The semantics of C++ state that "struct foo { ... }" | |
1809 | // OBSOLETE also defines a typedef for "foo". Unfortuantely, cfront | |
1810 | // OBSOLETE never makes the typedef when translating from C++ to C. | |
1811 | // OBSOLETE We make the typedef here so that "ptype foo" works as | |
1812 | // OBSOLETE expected for cfront translated code. */ | |
1813 | // OBSOLETE else if (psymtab_language == language_cplus) | |
1814 | // OBSOLETE { | |
1815 | // OBSOLETE /* Also a typedef with the same name. */ | |
1816 | // OBSOLETE add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 1817 | // OBSOLETE VAR_DOMAIN, LOC_TYPEDEF, |
25caa7a8 EZ |
1818 | // OBSOLETE &objfile->static_psymbols, |
1819 | // OBSOLETE nlist.n_value, 0, | |
1820 | // OBSOLETE psymtab_language, objfile); | |
1821 | // OBSOLETE } | |
1822 | #endif /* OBSOLETE CFront */ | |
6a34fd2f EZ |
1823 | } |
1824 | goto check_enum; | |
1825 | case 't': | |
1826 | if (p != namestring) /* a name is there, not just :T... */ | |
1827 | { | |
1828 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 1829 | VAR_DOMAIN, LOC_TYPEDEF, |
6a34fd2f EZ |
1830 | &objfile->static_psymbols, |
1831 | nlist.n_value, 0, | |
1832 | psymtab_language, objfile); | |
1833 | } | |
1834 | check_enum: | |
1835 | /* If this is an enumerated type, we need to | |
1836 | add all the enum constants to the partial symbol | |
1837 | table. This does not cover enums without names, e.g. | |
1838 | "enum {a, b} c;" in C, but fortunately those are | |
1839 | rare. There is no way for GDB to find those from the | |
1840 | enum type without spending too much time on it. Thus | |
1841 | to solve this problem, the compiler needs to put out the | |
1842 | enum in a nameless type. GCC2 does this. */ | |
1843 | ||
1844 | /* We are looking for something of the form | |
1845 | <name> ":" ("t" | "T") [<number> "="] "e" | |
1846 | {<constant> ":" <value> ","} ";". */ | |
1847 | ||
1848 | /* Skip over the colon and the 't' or 'T'. */ | |
1849 | p += 2; | |
1850 | /* This type may be given a number. Also, numbers can come | |
1851 | in pairs like (0,26). Skip over it. */ | |
1852 | while ((*p >= '0' && *p <= '9') | |
1853 | || *p == '(' || *p == ',' || *p == ')' | |
1854 | || *p == '=') | |
1855 | p++; | |
1856 | ||
1857 | if (*p++ == 'e') | |
1858 | { | |
1859 | /* The aix4 compiler emits extra crud before the members. */ | |
1860 | if (*p == '-') | |
1861 | { | |
1862 | /* Skip over the type (?). */ | |
1863 | while (*p != ':') | |
1864 | p++; | |
1865 | ||
1866 | /* Skip over the colon. */ | |
1867 | p++; | |
1868 | } | |
1869 | ||
1870 | /* We have found an enumerated type. */ | |
1871 | /* According to comments in read_enum_type | |
1872 | a comma could end it instead of a semicolon. | |
1873 | I don't know where that happens. | |
1874 | Accept either. */ | |
1875 | while (*p && *p != ';' && *p != ',') | |
1876 | { | |
1877 | char *q; | |
1878 | ||
1879 | /* Check for and handle cretinous dbx symbol name | |
1880 | continuation! */ | |
1881 | if (*p == '\\' || (*p == '?' && p[1] == '\0')) | |
1882 | p = next_symbol_text (objfile); | |
1883 | ||
1884 | /* Point to the character after the name | |
1885 | of the enum constant. */ | |
1886 | for (q = p; *q && *q != ':'; q++) | |
1887 | ; | |
1888 | /* Note that the value doesn't matter for | |
1889 | enum constants in psymtabs, just in symtabs. */ | |
1890 | add_psymbol_to_list (p, q - p, | |
176620f1 | 1891 | VAR_DOMAIN, LOC_CONST, |
6a34fd2f EZ |
1892 | &objfile->static_psymbols, 0, |
1893 | 0, psymtab_language, objfile); | |
1894 | /* Point past the name. */ | |
1895 | p = q; | |
1896 | /* Skip over the value. */ | |
1897 | while (*p && *p != ',') | |
1898 | p++; | |
1899 | /* Advance past the comma. */ | |
1900 | if (*p) | |
1901 | p++; | |
1902 | } | |
1903 | } | |
1904 | continue; | |
1905 | case 'c': | |
1906 | /* Constant, e.g. from "const" in Pascal. */ | |
1907 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 1908 | VAR_DOMAIN, LOC_CONST, |
6a34fd2f EZ |
1909 | &objfile->static_psymbols, nlist.n_value, |
1910 | 0, psymtab_language, objfile); | |
1911 | continue; | |
1912 | ||
1913 | case 'f': | |
1914 | if (! pst) | |
1915 | { | |
1916 | int name_len = p - namestring; | |
1917 | char *name = xmalloc (name_len + 1); | |
1918 | memcpy (name, namestring, name_len); | |
1919 | name[name_len] = '\0'; | |
23136709 | 1920 | function_outside_compilation_unit_complaint (name); |
6a34fd2f EZ |
1921 | xfree (name); |
1922 | } | |
1923 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1924 | /* Kludges for ELF/STABS with Sun ACC */ | |
1925 | last_function_name = namestring; | |
1926 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
1927 | /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit | |
1928 | value for the bottom of the text seg in those cases. */ | |
1929 | if (nlist.n_value == ANOFFSET (objfile->section_offsets, | |
1930 | SECT_OFF_TEXT (objfile))) | |
1931 | { | |
1932 | CORE_ADDR minsym_valu = | |
1933 | find_stab_function_addr (namestring, pst->filename, objfile); | |
1934 | /* find_stab_function_addr will return 0 if the minimal | |
1935 | symbol wasn't found. (Unfortunately, this might also | |
1936 | be a valid address.) Anyway, if it *does* return 0, | |
1937 | it is likely that the value was set correctly to begin | |
1938 | with... */ | |
1939 | if (minsym_valu != 0) | |
1940 | nlist.n_value = minsym_valu; | |
1941 | } | |
1942 | if (pst && textlow_not_set) | |
1943 | { | |
5afc051b | 1944 | pst->textlow = nlist.n_value; |
6a34fd2f EZ |
1945 | textlow_not_set = 0; |
1946 | } | |
1947 | #endif | |
1948 | /* End kludge. */ | |
1949 | ||
1950 | /* Keep track of the start of the last function so we | |
1951 | can handle end of function symbols. */ | |
1952 | last_function_start = nlist.n_value; | |
1953 | ||
1954 | /* In reordered executables this function may lie outside | |
1955 | the bounds created by N_SO symbols. If that's the case | |
1956 | use the address of this function as the low bound for | |
1957 | the partial symbol table. */ | |
1958 | if (pst | |
1959 | && (textlow_not_set | |
5afc051b | 1960 | || (nlist.n_value < pst->textlow |
6a34fd2f EZ |
1961 | && (nlist.n_value |
1962 | != ANOFFSET (objfile->section_offsets, | |
1963 | SECT_OFF_TEXT (objfile)))))) | |
1964 | { | |
5afc051b | 1965 | pst->textlow = nlist.n_value; |
6a34fd2f EZ |
1966 | textlow_not_set = 0; |
1967 | } | |
1968 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 1969 | VAR_DOMAIN, LOC_BLOCK, |
6a34fd2f EZ |
1970 | &objfile->static_psymbols, |
1971 | 0, nlist.n_value, | |
1972 | psymtab_language, objfile); | |
1973 | continue; | |
1974 | ||
1975 | /* Global functions were ignored here, but now they | |
1976 | are put into the global psymtab like one would expect. | |
1977 | They're also in the minimal symbol table. */ | |
1978 | case 'F': | |
1979 | if (! pst) | |
1980 | { | |
1981 | int name_len = p - namestring; | |
1982 | char *name = xmalloc (name_len + 1); | |
1983 | memcpy (name, namestring, name_len); | |
1984 | name[name_len] = '\0'; | |
23136709 | 1985 | function_outside_compilation_unit_complaint (name); |
6a34fd2f EZ |
1986 | xfree (name); |
1987 | } | |
1988 | nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1989 | /* Kludges for ELF/STABS with Sun ACC */ | |
1990 | last_function_name = namestring; | |
1991 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
1992 | /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit | |
1993 | value for the bottom of the text seg in those cases. */ | |
1994 | if (nlist.n_value == ANOFFSET (objfile->section_offsets, | |
1995 | SECT_OFF_TEXT (objfile))) | |
1996 | { | |
1997 | CORE_ADDR minsym_valu = | |
1998 | find_stab_function_addr (namestring, pst->filename, objfile); | |
1999 | /* find_stab_function_addr will return 0 if the minimal | |
2000 | symbol wasn't found. (Unfortunately, this might also | |
2001 | be a valid address.) Anyway, if it *does* return 0, | |
2002 | it is likely that the value was set correctly to begin | |
2003 | with... */ | |
2004 | if (minsym_valu != 0) | |
2005 | nlist.n_value = minsym_valu; | |
2006 | } | |
2007 | if (pst && textlow_not_set) | |
2008 | { | |
5afc051b | 2009 | pst->textlow = nlist.n_value; |
6a34fd2f EZ |
2010 | textlow_not_set = 0; |
2011 | } | |
2012 | #endif | |
2013 | /* End kludge. */ | |
2014 | ||
2015 | /* Keep track of the start of the last function so we | |
2016 | can handle end of function symbols. */ | |
2017 | last_function_start = nlist.n_value; | |
2018 | ||
2019 | /* In reordered executables this function may lie outside | |
2020 | the bounds created by N_SO symbols. If that's the case | |
2021 | use the address of this function as the low bound for | |
2022 | the partial symbol table. */ | |
2023 | if (pst | |
2024 | && (textlow_not_set | |
5afc051b | 2025 | || (nlist.n_value < pst->textlow |
6a34fd2f EZ |
2026 | && (nlist.n_value |
2027 | != ANOFFSET (objfile->section_offsets, | |
2028 | SECT_OFF_TEXT (objfile)))))) | |
2029 | { | |
5afc051b | 2030 | pst->textlow = nlist.n_value; |
6a34fd2f EZ |
2031 | textlow_not_set = 0; |
2032 | } | |
2033 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 2034 | VAR_DOMAIN, LOC_BLOCK, |
6a34fd2f EZ |
2035 | &objfile->global_psymbols, |
2036 | 0, nlist.n_value, | |
2037 | psymtab_language, objfile); | |
2038 | continue; | |
2039 | ||
2040 | /* Two things show up here (hopefully); static symbols of | |
2041 | local scope (static used inside braces) or extensions | |
2042 | of structure symbols. We can ignore both. */ | |
2043 | case 'V': | |
2044 | case '(': | |
2045 | case '0': | |
2046 | case '1': | |
2047 | case '2': | |
2048 | case '3': | |
2049 | case '4': | |
2050 | case '5': | |
2051 | case '6': | |
2052 | case '7': | |
2053 | case '8': | |
2054 | case '9': | |
2055 | case '-': | |
2056 | case '#': /* for symbol identification (used in live ranges) */ | |
25caa7a8 EZ |
2057 | #if 0 /* OBSOLETE CFront */ |
2058 | // OBSOLETE /* added to support cfront stabs strings */ | |
2059 | // OBSOLETE case 'Z': /* for definition continuations */ | |
2060 | // OBSOLETE case 'P': /* for prototypes */ | |
2061 | #endif /* OBSOLETE CFront */ | |
6a34fd2f EZ |
2062 | continue; |
2063 | ||
2064 | case ':': | |
2065 | /* It is a C++ nested symbol. We don't need to record it | |
2066 | (I don't think); if we try to look up foo::bar::baz, | |
2067 | then symbols for the symtab containing foo should get | |
2068 | read in, I think. */ | |
2069 | /* Someone says sun cc puts out symbols like | |
2070 | /foo/baz/maclib::/usr/local/bin/maclib, | |
2071 | which would get here with a symbol type of ':'. */ | |
2072 | continue; | |
2073 | ||
2074 | default: | |
2075 | /* Unexpected symbol descriptor. The second and subsequent stabs | |
2076 | of a continued stab can show up here. The question is | |
2077 | whether they ever can mimic a normal stab--it would be | |
2078 | nice if not, since we certainly don't want to spend the | |
2079 | time searching to the end of every string looking for | |
2080 | a backslash. */ | |
2081 | ||
23136709 KB |
2082 | complaint (&symfile_complaints, "unknown symbol descriptor `%c'", |
2083 | p[1]); | |
6a34fd2f EZ |
2084 | |
2085 | /* Ignore it; perhaps it is an extension that we don't | |
2086 | know about. */ | |
2087 | continue; | |
2088 | } | |
2089 | ||
2090 | case N_EXCL: | |
2091 | ||
2092 | namestring = set_namestring (objfile, nlist); | |
2093 | ||
2094 | /* Find the corresponding bincl and mark that psymtab on the | |
2095 | psymtab dependency list */ | |
2096 | { | |
2097 | struct partial_symtab *needed_pst = | |
2098 | find_corresponding_bincl_psymtab (namestring, nlist.n_value); | |
2099 | ||
2100 | /* If this include file was defined earlier in this file, | |
2101 | leave it alone. */ | |
2102 | if (needed_pst == pst) | |
2103 | continue; | |
2104 | ||
2105 | if (needed_pst) | |
2106 | { | |
2107 | int i; | |
2108 | int found = 0; | |
2109 | ||
2110 | for (i = 0; i < dependencies_used; i++) | |
2111 | if (dependency_list[i] == needed_pst) | |
2112 | { | |
2113 | found = 1; | |
2114 | break; | |
2115 | } | |
2116 | ||
2117 | /* If it's already in the list, skip the rest. */ | |
2118 | if (found) | |
2119 | continue; | |
2120 | ||
2121 | dependency_list[dependencies_used++] = needed_pst; | |
2122 | if (dependencies_used >= dependencies_allocated) | |
2123 | { | |
2124 | struct partial_symtab **orig = dependency_list; | |
2125 | dependency_list = | |
2126 | (struct partial_symtab **) | |
2127 | alloca ((dependencies_allocated *= 2) | |
2128 | * sizeof (struct partial_symtab *)); | |
4efb68b1 | 2129 | memcpy (dependency_list, orig, |
6a34fd2f EZ |
2130 | (dependencies_used |
2131 | * sizeof (struct partial_symtab *))); | |
2132 | #ifdef DEBUG_INFO | |
2133 | fprintf_unfiltered (gdb_stderr, "Had to reallocate dependency list.\n"); | |
2134 | fprintf_unfiltered (gdb_stderr, "New dependencies allocated: %d\n", | |
2135 | dependencies_allocated); | |
2136 | #endif | |
2137 | } | |
2138 | } | |
2139 | } | |
2140 | continue; | |
2141 | ||
2142 | case N_ENDM: | |
2143 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
2144 | /* Solaris 2 end of module, finish current partial symbol table. | |
5afc051b | 2145 | end_psymtab will set pst->texthigh to the proper value, which |
6a34fd2f EZ |
2146 | is necessary if a module compiled without debugging info |
2147 | follows this module. */ | |
2148 | if (pst) | |
2149 | { | |
2150 | end_psymtab (pst, psymtab_include_list, includes_used, | |
2151 | symnum * symbol_size, | |
2152 | (CORE_ADDR) 0, | |
2153 | dependency_list, dependencies_used, textlow_not_set); | |
2154 | pst = (struct partial_symtab *) 0; | |
2155 | includes_used = 0; | |
2156 | dependencies_used = 0; | |
2157 | } | |
2158 | #endif | |
2159 | continue; | |
c906108c | 2160 | |
6a34fd2f EZ |
2161 | case N_RBRAC: |
2162 | #ifdef HANDLE_RBRAC | |
2163 | HANDLE_RBRAC (nlist.n_value); | |
2164 | continue; | |
2165 | #endif | |
2166 | case N_EINCL: | |
2167 | case N_DSLINE: | |
2168 | case N_BSLINE: | |
2169 | case N_SSYM: /* Claim: Structure or union element. | |
2170 | Hopefully, I can ignore this. */ | |
2171 | case N_ENTRY: /* Alternate entry point; can ignore. */ | |
2172 | case N_MAIN: /* Can definitely ignore this. */ | |
2173 | case N_CATCH: /* These are GNU C++ extensions */ | |
2174 | case N_EHDECL: /* that can safely be ignored here. */ | |
2175 | case N_LENG: | |
2176 | case N_BCOMM: | |
2177 | case N_ECOMM: | |
2178 | case N_ECOML: | |
2179 | case N_FNAME: | |
2180 | case N_SLINE: | |
2181 | case N_RSYM: | |
2182 | case N_PSYM: | |
2183 | case N_LBRAC: | |
2184 | case N_NSYMS: /* Ultrix 4.0: symbol count */ | |
2185 | case N_DEFD: /* GNU Modula-2 */ | |
2186 | case N_ALIAS: /* SunPro F77: alias name, ignore for now. */ | |
2187 | ||
2188 | case N_OBJ: /* useless types from Solaris */ | |
2189 | case N_OPT: | |
2190 | /* These symbols aren't interesting; don't worry about them */ | |
2191 | ||
2192 | continue; | |
2193 | ||
2194 | default: | |
2195 | /* If we haven't found it yet, ignore it. It's probably some | |
2196 | new type we don't know about yet. */ | |
23136709 | 2197 | unknown_symtype_complaint (local_hex_string (nlist.n_type)); |
6a34fd2f EZ |
2198 | continue; |
2199 | } | |
c906108c SS |
2200 | } |
2201 | ||
2202 | /* If there's stuff to be cleaned up, clean it up. */ | |
c5aa993b | 2203 | if (DBX_SYMCOUNT (objfile) > 0 /* We have some syms */ |
6a34fd2f | 2204 | /*FIXME, does this have a bug at start address 0? */ |
c906108c | 2205 | && last_o_file_start |
c5aa993b JM |
2206 | && objfile->ei.entry_point < nlist.n_value |
2207 | && objfile->ei.entry_point >= last_o_file_start) | |
c906108c | 2208 | { |
c5aa993b JM |
2209 | objfile->ei.entry_file_lowpc = last_o_file_start; |
2210 | objfile->ei.entry_file_highpc = nlist.n_value; | |
c906108c SS |
2211 | } |
2212 | ||
2213 | if (pst) | |
2214 | { | |
2215 | /* Don't set pst->texthigh lower than it already is. */ | |
2216 | CORE_ADDR text_end = | |
6a34fd2f EZ |
2217 | (lowest_text_address == (CORE_ADDR) -1 |
2218 | ? (text_addr + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))) | |
2219 | : lowest_text_address) | |
2220 | + text_size; | |
c906108c SS |
2221 | |
2222 | end_psymtab (pst, psymtab_include_list, includes_used, | |
2223 | symnum * symbol_size, | |
5afc051b | 2224 | text_end > pst->texthigh ? text_end : pst->texthigh, |
c906108c SS |
2225 | dependency_list, dependencies_used, textlow_not_set); |
2226 | } | |
2227 | ||
2228 | do_cleanups (back_to); | |
2229 | } | |
2230 | ||
2231 | /* Allocate and partially fill a partial symtab. It will be | |
2232 | completely filled at the end of the symbol list. | |
2233 | ||
2234 | SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR | |
2235 | is the address relative to which its symbols are (incremental) or 0 | |
2236 | (normal). */ | |
2237 | ||
2238 | ||
d4f3574e | 2239 | static struct partial_symtab * |
fba45db2 KB |
2240 | start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow, |
2241 | int ldsymoff, struct partial_symbol **global_syms, | |
2242 | struct partial_symbol **static_syms) | |
c906108c SS |
2243 | { |
2244 | struct partial_symtab *result = | |
d4f3574e | 2245 | start_psymtab_common (objfile, objfile->section_offsets, |
c5aa993b | 2246 | filename, textlow, global_syms, static_syms); |
c906108c SS |
2247 | |
2248 | result->read_symtab_private = (char *) | |
c5aa993b JM |
2249 | obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc)); |
2250 | LDSYMOFF (result) = ldsymoff; | |
c906108c | 2251 | result->read_symtab = dbx_psymtab_to_symtab; |
c5aa993b JM |
2252 | SYMBOL_SIZE (result) = symbol_size; |
2253 | SYMBOL_OFFSET (result) = symbol_table_offset; | |
2254 | STRING_OFFSET (result) = string_table_offset; | |
2255 | FILE_STRING_OFFSET (result) = file_string_table_offset; | |
c906108c SS |
2256 | |
2257 | /* If we're handling an ELF file, drag some section-relocation info | |
2258 | for this source file out of the ELF symbol table, to compensate for | |
2259 | Sun brain death. This replaces the section_offsets in this psymtab, | |
2260 | if successful. */ | |
2261 | elfstab_offset_sections (objfile, result); | |
2262 | ||
2263 | /* Deduce the source language from the filename for this psymtab. */ | |
2264 | psymtab_language = deduce_language_from_filename (filename); | |
2265 | ||
2266 | return result; | |
2267 | } | |
2268 | ||
2269 | /* Close off the current usage of PST. | |
2270 | Returns PST or NULL if the partial symtab was empty and thrown away. | |
2271 | ||
2272 | FIXME: List variables and peculiarities of same. */ | |
2273 | ||
2274 | struct partial_symtab * | |
fba45db2 KB |
2275 | end_psymtab (struct partial_symtab *pst, char **include_list, int num_includes, |
2276 | int capping_symbol_offset, CORE_ADDR capping_text, | |
2277 | struct partial_symtab **dependency_list, int number_dependencies, | |
2278 | int textlow_not_set) | |
c906108c SS |
2279 | { |
2280 | int i; | |
c5aa993b | 2281 | struct objfile *objfile = pst->objfile; |
c906108c SS |
2282 | |
2283 | if (capping_symbol_offset != -1) | |
c5aa993b | 2284 | LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst); |
5afc051b | 2285 | pst->texthigh = capping_text; |
c906108c SS |
2286 | |
2287 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
2288 | /* Under Solaris, the N_SO symbols always have a value of 0, | |
2289 | instead of the usual address of the .o file. Therefore, | |
2290 | we have to do some tricks to fill in texthigh and textlow. | |
6a34fd2f | 2291 | The first trick is: if we see a static |
c906108c SS |
2292 | or global function, and the textlow for the current pst |
2293 | is not set (ie: textlow_not_set), then we use that function's | |
2294 | address for the textlow of the pst. */ | |
2295 | ||
2296 | /* Now, to fill in texthigh, we remember the last function seen | |
6a34fd2f | 2297 | in the .o file. Also, there's a hack in |
c906108c SS |
2298 | bfd/elf.c and gdb/elfread.c to pass the ELF st_size field |
2299 | to here via the misc_info field. Therefore, we can fill in | |
2300 | a reliable texthigh by taking the address plus size of the | |
2301 | last function in the file. */ | |
2302 | ||
5afc051b | 2303 | if (pst->texthigh == 0 && last_function_name) |
c906108c SS |
2304 | { |
2305 | char *p; | |
2306 | int n; | |
2307 | struct minimal_symbol *minsym; | |
2308 | ||
2309 | p = strchr (last_function_name, ':'); | |
2310 | if (p == NULL) | |
2311 | p = last_function_name; | |
2312 | n = p - last_function_name; | |
2313 | p = alloca (n + 2); | |
2314 | strncpy (p, last_function_name, n); | |
2315 | p[n] = 0; | |
c5aa993b | 2316 | |
c906108c SS |
2317 | minsym = lookup_minimal_symbol (p, pst->filename, objfile); |
2318 | if (minsym == NULL) | |
2319 | { | |
2320 | /* Sun Fortran appends an underscore to the minimal symbol name, | |
2321 | try again with an appended underscore if the minimal symbol | |
2322 | was not found. */ | |
2323 | p[n] = '_'; | |
2324 | p[n + 1] = 0; | |
2325 | minsym = lookup_minimal_symbol (p, pst->filename, objfile); | |
2326 | } | |
2327 | ||
2328 | if (minsym) | |
5afc051b | 2329 | pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + MSYMBOL_SIZE (minsym); |
c906108c SS |
2330 | |
2331 | last_function_name = NULL; | |
2332 | } | |
2333 | ||
2334 | /* this test will be true if the last .o file is only data */ | |
2335 | if (textlow_not_set) | |
5afc051b | 2336 | pst->textlow = pst->texthigh; |
c906108c SS |
2337 | else |
2338 | { | |
2339 | struct partial_symtab *p1; | |
2340 | ||
2341 | /* If we know our own starting text address, then walk through all other | |
c5aa993b JM |
2342 | psymtabs for this objfile, and if any didn't know their ending text |
2343 | address, set it to our starting address. Take care to not set our | |
2344 | own ending address to our starting address, nor to set addresses on | |
2345 | `dependency' files that have both textlow and texthigh zero. */ | |
c906108c SS |
2346 | |
2347 | ALL_OBJFILE_PSYMTABS (objfile, p1) | |
c5aa993b | 2348 | { |
5afc051b | 2349 | if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst) |
c5aa993b | 2350 | { |
5afc051b | 2351 | p1->texthigh = pst->textlow; |
c5aa993b | 2352 | /* if this file has only data, then make textlow match texthigh */ |
5afc051b JB |
2353 | if (p1->textlow == 0) |
2354 | p1->textlow = p1->texthigh; | |
c5aa993b JM |
2355 | } |
2356 | } | |
c906108c SS |
2357 | } |
2358 | ||
2359 | /* End of kludge for patching Solaris textlow and texthigh. */ | |
2360 | #endif /* SOFUN_ADDRESS_MAYBE_MISSING. */ | |
2361 | ||
2362 | pst->n_global_syms = | |
2363 | objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset); | |
2364 | pst->n_static_syms = | |
2365 | objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset); | |
2366 | ||
2367 | pst->number_of_dependencies = number_dependencies; | |
2368 | if (number_dependencies) | |
2369 | { | |
2370 | pst->dependencies = (struct partial_symtab **) | |
2371 | obstack_alloc (&objfile->psymbol_obstack, | |
c5aa993b | 2372 | number_dependencies * sizeof (struct partial_symtab *)); |
c906108c | 2373 | memcpy (pst->dependencies, dependency_list, |
c5aa993b | 2374 | number_dependencies * sizeof (struct partial_symtab *)); |
c906108c SS |
2375 | } |
2376 | else | |
2377 | pst->dependencies = 0; | |
2378 | ||
2379 | for (i = 0; i < num_includes; i++) | |
2380 | { | |
2381 | struct partial_symtab *subpst = | |
c5aa993b | 2382 | allocate_psymtab (include_list[i], objfile); |
c906108c | 2383 | |
b8fbeb18 | 2384 | /* Copy the sesction_offsets array from the main psymtab. */ |
c906108c SS |
2385 | subpst->section_offsets = pst->section_offsets; |
2386 | subpst->read_symtab_private = | |
c5aa993b JM |
2387 | (char *) obstack_alloc (&objfile->psymbol_obstack, |
2388 | sizeof (struct symloc)); | |
2389 | LDSYMOFF (subpst) = | |
2390 | LDSYMLEN (subpst) = | |
5afc051b JB |
2391 | subpst->textlow = |
2392 | subpst->texthigh = 0; | |
c906108c SS |
2393 | |
2394 | /* We could save slight bits of space by only making one of these, | |
c5aa993b | 2395 | shared by the entire set of include files. FIXME-someday. */ |
c906108c SS |
2396 | subpst->dependencies = (struct partial_symtab **) |
2397 | obstack_alloc (&objfile->psymbol_obstack, | |
2398 | sizeof (struct partial_symtab *)); | |
2399 | subpst->dependencies[0] = pst; | |
2400 | subpst->number_of_dependencies = 1; | |
2401 | ||
2402 | subpst->globals_offset = | |
2403 | subpst->n_global_syms = | |
c5aa993b JM |
2404 | subpst->statics_offset = |
2405 | subpst->n_static_syms = 0; | |
c906108c SS |
2406 | |
2407 | subpst->readin = 0; | |
2408 | subpst->symtab = 0; | |
2409 | subpst->read_symtab = pst->read_symtab; | |
2410 | } | |
2411 | ||
2412 | sort_pst_symbols (pst); | |
2413 | ||
2414 | /* If there is already a psymtab or symtab for a file of this name, remove it. | |
2415 | (If there is a symtab, more drastic things also happen.) | |
2416 | This happens in VxWorks. */ | |
2417 | free_named_symtabs (pst->filename); | |
2418 | ||
2419 | if (num_includes == 0 | |
2420 | && number_dependencies == 0 | |
2421 | && pst->n_global_syms == 0 | |
2422 | && pst->n_static_syms == 0 | |
2423 | && has_line_numbers == 0) | |
2424 | { | |
2425 | /* Throw away this psymtab, it's empty. We can't deallocate it, since | |
c5aa993b | 2426 | it is on the obstack, but we can forget to chain it on the list. */ |
c906108c | 2427 | /* Empty psymtabs happen as a result of header files which don't have |
c5aa993b JM |
2428 | any symbols in them. There can be a lot of them. But this check |
2429 | is wrong, in that a psymtab with N_SLINE entries but nothing else | |
2430 | is not empty, but we don't realize that. Fixing that without slowing | |
2431 | things down might be tricky. */ | |
c906108c SS |
2432 | |
2433 | discard_psymtab (pst); | |
2434 | ||
2435 | /* Indicate that psymtab was thrown away. */ | |
c5aa993b | 2436 | pst = (struct partial_symtab *) NULL; |
c906108c SS |
2437 | } |
2438 | return pst; | |
2439 | } | |
2440 | \f | |
2441 | static void | |
fba45db2 | 2442 | dbx_psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c SS |
2443 | { |
2444 | struct cleanup *old_chain; | |
2445 | int i; | |
c5aa993b | 2446 | |
c906108c SS |
2447 | if (!pst) |
2448 | return; | |
2449 | ||
2450 | if (pst->readin) | |
2451 | { | |
2452 | fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
c5aa993b | 2453 | pst->filename); |
c906108c SS |
2454 | return; |
2455 | } | |
2456 | ||
2457 | /* Read in all partial symtabs on which this one is dependent */ | |
2458 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2459 | if (!pst->dependencies[i]->readin) | |
2460 | { | |
2461 | /* Inform about additional files that need to be read in. */ | |
2462 | if (info_verbose) | |
2463 | { | |
2464 | fputs_filtered (" ", gdb_stdout); | |
2465 | wrap_here (""); | |
2466 | fputs_filtered ("and ", gdb_stdout); | |
2467 | wrap_here (""); | |
2468 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
c5aa993b | 2469 | wrap_here (""); /* Flush output */ |
c906108c SS |
2470 | gdb_flush (gdb_stdout); |
2471 | } | |
2472 | dbx_psymtab_to_symtab_1 (pst->dependencies[i]); | |
2473 | } | |
2474 | ||
c5aa993b | 2475 | if (LDSYMLEN (pst)) /* Otherwise it's a dummy */ |
c906108c SS |
2476 | { |
2477 | /* Init stuff necessary for reading in symbols */ | |
2478 | stabsread_init (); | |
2479 | buildsym_init (); | |
a0b3c4fd | 2480 | old_chain = make_cleanup (really_free_pendings, 0); |
c906108c SS |
2481 | file_string_table_offset = FILE_STRING_OFFSET (pst); |
2482 | symbol_size = SYMBOL_SIZE (pst); | |
2483 | ||
2484 | /* Read in this file's symbols */ | |
2485 | bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET); | |
2486 | read_ofile_symtab (pst); | |
2487 | sort_symtab_syms (pst->symtab); | |
2488 | ||
2489 | do_cleanups (old_chain); | |
2490 | } | |
2491 | ||
2492 | pst->readin = 1; | |
2493 | } | |
2494 | ||
2495 | /* Read in all of the symbols for a given psymtab for real. | |
2496 | Be verbose about it if the user wants that. */ | |
2497 | ||
2498 | static void | |
fba45db2 | 2499 | dbx_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2500 | { |
2501 | bfd *sym_bfd; | |
086df311 | 2502 | struct cleanup *back_to = NULL; |
c906108c SS |
2503 | |
2504 | if (!pst) | |
2505 | return; | |
2506 | ||
2507 | if (pst->readin) | |
2508 | { | |
2509 | fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n", | |
c5aa993b | 2510 | pst->filename); |
c906108c SS |
2511 | return; |
2512 | } | |
2513 | ||
c5aa993b | 2514 | if (LDSYMLEN (pst) || pst->number_of_dependencies) |
c906108c SS |
2515 | { |
2516 | /* Print the message now, before reading the string table, | |
c5aa993b | 2517 | to avoid disconcerting pauses. */ |
c906108c SS |
2518 | if (info_verbose) |
2519 | { | |
2520 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
2521 | gdb_flush (gdb_stdout); | |
2522 | } | |
2523 | ||
2524 | sym_bfd = pst->objfile->obfd; | |
2525 | ||
2526 | next_symbol_text_func = dbx_next_symbol_text; | |
2527 | ||
086df311 DJ |
2528 | if (DBX_STAB_SECTION (pst->objfile)) |
2529 | { | |
2530 | stabs_data | |
2531 | = symfile_relocate_debug_section (pst->objfile->obfd, | |
2532 | DBX_STAB_SECTION (pst->objfile), | |
2533 | NULL); | |
2534 | if (stabs_data) | |
2535 | back_to = make_cleanup (free_current_contents, (void *) &stabs_data); | |
2536 | } | |
2537 | ||
c906108c SS |
2538 | dbx_psymtab_to_symtab_1 (pst); |
2539 | ||
086df311 DJ |
2540 | if (back_to) |
2541 | do_cleanups (back_to); | |
2542 | ||
c906108c SS |
2543 | /* Match with global symbols. This only needs to be done once, |
2544 | after all of the symtabs and dependencies have been read in. */ | |
2545 | scan_file_globals (pst->objfile); | |
2546 | ||
2547 | /* Finish up the debug error message. */ | |
2548 | if (info_verbose) | |
2549 | printf_filtered ("done.\n"); | |
2550 | } | |
2551 | } | |
2552 | ||
2553 | /* Read in a defined section of a specific object file's symbols. */ | |
c5aa993b | 2554 | |
c906108c | 2555 | static void |
fba45db2 | 2556 | read_ofile_symtab (struct partial_symtab *pst) |
c906108c SS |
2557 | { |
2558 | register char *namestring; | |
2559 | register struct external_nlist *bufp; | |
2560 | struct internal_nlist nlist; | |
2561 | unsigned char type; | |
2562 | unsigned max_symnum; | |
2563 | register bfd *abfd; | |
2564 | struct objfile *objfile; | |
2565 | int sym_offset; /* Offset to start of symbols to read */ | |
2566 | int sym_size; /* Size of symbols to read */ | |
2567 | CORE_ADDR text_offset; /* Start of text segment for symbols */ | |
2568 | int text_size; /* Size of text segment for symbols */ | |
2569 | struct section_offsets *section_offsets; | |
2570 | ||
2571 | objfile = pst->objfile; | |
c5aa993b JM |
2572 | sym_offset = LDSYMOFF (pst); |
2573 | sym_size = LDSYMLEN (pst); | |
5afc051b JB |
2574 | text_offset = pst->textlow; |
2575 | text_size = pst->texthigh - pst->textlow; | |
b8fbeb18 EZ |
2576 | /* This cannot be simply objfile->section_offsets because of |
2577 | elfstab_offset_sections() which initializes the psymtab section | |
2578 | offsets information in a special way, and that is different from | |
2579 | objfile->section_offsets. */ | |
c906108c SS |
2580 | section_offsets = pst->section_offsets; |
2581 | ||
2582 | current_objfile = objfile; | |
2583 | subfile_stack = NULL; | |
2584 | ||
2585 | stringtab_global = DBX_STRINGTAB (objfile); | |
2586 | last_source_file = NULL; | |
2587 | ||
2588 | abfd = objfile->obfd; | |
2589 | symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol */ | |
2590 | symbuf_end = symbuf_idx = 0; | |
086df311 DJ |
2591 | symbuf_read = 0; |
2592 | symbuf_left = sym_offset + sym_size; | |
c906108c SS |
2593 | |
2594 | /* It is necessary to actually read one symbol *before* the start | |
2595 | of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL | |
2596 | occurs before the N_SO symbol. | |
2597 | ||
2598 | Detecting this in read_dbx_symtab | |
2599 | would slow down initial readin, so we look for it here instead. */ | |
c5aa993b | 2600 | if (!processing_acc_compilation && sym_offset >= (int) symbol_size) |
c906108c | 2601 | { |
086df311 | 2602 | stabs_seek (sym_offset - symbol_size); |
c906108c SS |
2603 | fill_symbuf (abfd); |
2604 | bufp = &symbuf[symbuf_idx++]; | |
2605 | INTERNALIZE_SYMBOL (nlist, bufp, abfd); | |
2606 | OBJSTAT (objfile, n_stabs++); | |
2607 | ||
6a34fd2f | 2608 | namestring = set_namestring (objfile, nlist); |
c906108c SS |
2609 | |
2610 | processing_gcc_compilation = 0; | |
2611 | if (nlist.n_type == N_TEXT) | |
2612 | { | |
2613 | const char *tempstring = namestring; | |
2614 | ||
2615 | if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL)) | |
2616 | processing_gcc_compilation = 1; | |
2617 | else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL)) | |
2618 | processing_gcc_compilation = 2; | |
2619 | if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd)) | |
2620 | ++tempstring; | |
2621 | if (STREQN (tempstring, "__gnu_compiled", 14)) | |
2622 | processing_gcc_compilation = 2; | |
2623 | } | |
2624 | ||
2625 | /* Try to select a C++ demangling based on the compilation unit | |
c5aa993b | 2626 | producer. */ |
c906108c | 2627 | |
8052a17a JM |
2628 | #if 0 |
2629 | /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't | |
2630 | know whether it will use the old style or v3 mangling. */ | |
c906108c SS |
2631 | if (processing_gcc_compilation) |
2632 | { | |
2633 | if (AUTO_DEMANGLING) | |
2634 | { | |
2635 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
2636 | } | |
2637 | } | |
8052a17a | 2638 | #endif |
c906108c SS |
2639 | } |
2640 | else | |
2641 | { | |
2642 | /* The N_SO starting this symtab is the first symbol, so we | |
c5aa993b JM |
2643 | better not check the symbol before it. I'm not this can |
2644 | happen, but it doesn't hurt to check for it. */ | |
086df311 | 2645 | stabs_seek (sym_offset); |
c906108c SS |
2646 | processing_gcc_compilation = 0; |
2647 | } | |
2648 | ||
2649 | if (symbuf_idx == symbuf_end) | |
2650 | fill_symbuf (abfd); | |
2651 | bufp = &symbuf[symbuf_idx]; | |
2652 | if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO) | |
c5aa993b | 2653 | error ("First symbol in segment of executable not a source symbol"); |
c906108c SS |
2654 | |
2655 | max_symnum = sym_size / symbol_size; | |
2656 | ||
2657 | for (symnum = 0; | |
2658 | symnum < max_symnum; | |
2659 | symnum++) | |
2660 | { | |
2661 | QUIT; /* Allow this to be interruptable */ | |
2662 | if (symbuf_idx == symbuf_end) | |
c5aa993b | 2663 | fill_symbuf (abfd); |
c906108c SS |
2664 | bufp = &symbuf[symbuf_idx++]; |
2665 | INTERNALIZE_SYMBOL (nlist, bufp, abfd); | |
2666 | OBJSTAT (objfile, n_stabs++); | |
2667 | ||
2668 | type = bfd_h_get_8 (abfd, bufp->e_type); | |
2669 | ||
6a34fd2f | 2670 | namestring = set_namestring (objfile, nlist); |
c906108c | 2671 | |
c5aa993b JM |
2672 | if (type & N_STAB) |
2673 | { | |
c906108c SS |
2674 | process_one_symbol (type, nlist.n_desc, nlist.n_value, |
2675 | namestring, section_offsets, objfile); | |
c5aa993b | 2676 | } |
c906108c SS |
2677 | /* We skip checking for a new .o or -l file; that should never |
2678 | happen in this routine. */ | |
2679 | else if (type == N_TEXT) | |
2680 | { | |
2681 | /* I don't think this code will ever be executed, because | |
2682 | the GCC_COMPILED_FLAG_SYMBOL usually is right before | |
2683 | the N_SO symbol which starts this source file. | |
2684 | However, there is no reason not to accept | |
2685 | the GCC_COMPILED_FLAG_SYMBOL anywhere. */ | |
2686 | ||
2687 | if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL)) | |
2688 | processing_gcc_compilation = 1; | |
2689 | else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL)) | |
2690 | processing_gcc_compilation = 2; | |
2691 | ||
8052a17a JM |
2692 | #if 0 |
2693 | /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't | |
2694 | know whether it will use the old style or v3 mangling. */ | |
c906108c SS |
2695 | if (AUTO_DEMANGLING) |
2696 | { | |
2697 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
2698 | } | |
8052a17a | 2699 | #endif |
c906108c | 2700 | } |
c5aa993b JM |
2701 | else if (type & N_EXT || type == (unsigned char) N_TEXT |
2702 | || type == (unsigned char) N_NBTEXT | |
2703 | ) | |
2704 | { | |
c906108c SS |
2705 | /* Global symbol: see if we came across a dbx defintion for |
2706 | a corresponding symbol. If so, store the value. Remove | |
2707 | syms from the chain when their values are stored, but | |
2708 | search the whole chain, as there may be several syms from | |
2709 | different files with the same name. */ | |
2710 | /* This is probably not true. Since the files will be read | |
2711 | in one at a time, each reference to a global symbol will | |
2712 | be satisfied in each file as it appears. So we skip this | |
2713 | section. */ | |
2714 | ; | |
c5aa993b | 2715 | } |
c906108c SS |
2716 | } |
2717 | ||
2718 | current_objfile = NULL; | |
2719 | ||
2720 | /* In a Solaris elf file, this variable, which comes from the | |
2721 | value of the N_SO symbol, will still be 0. Luckily, text_offset, | |
5afc051b | 2722 | which comes from pst->textlow is correct. */ |
c906108c SS |
2723 | if (last_source_start_addr == 0) |
2724 | last_source_start_addr = text_offset; | |
2725 | ||
2726 | /* In reordered executables last_source_start_addr may not be the | |
2727 | lower bound for this symtab, instead use text_offset which comes | |
5afc051b | 2728 | from pst->textlow which is correct. */ |
c906108c SS |
2729 | if (last_source_start_addr > text_offset) |
2730 | last_source_start_addr = text_offset; | |
2731 | ||
b8fbeb18 | 2732 | pst->symtab = end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 2733 | |
25caa7a8 EZ |
2734 | #if 0 /* OBSOLETE CFront */ |
2735 | // OBSOLETE /* Process items which we had to "process_later" due to dependencies | |
2736 | // OBSOLETE on other stabs. */ | |
2737 | // OBSOLETE process_now (objfile); | |
2738 | #endif /* OBSOLETE CFront */ | |
c906108c SS |
2739 | end_stabs (); |
2740 | } | |
c906108c | 2741 | \f |
c5aa993b | 2742 | |
c906108c SS |
2743 | /* This handles a single symbol from the symbol-file, building symbols |
2744 | into a GDB symtab. It takes these arguments and an implicit argument. | |
2745 | ||
2746 | TYPE is the type field of the ".stab" symbol entry. | |
2747 | DESC is the desc field of the ".stab" entry. | |
2748 | VALU is the value field of the ".stab" entry. | |
2749 | NAME is the symbol name, in our address space. | |
2750 | SECTION_OFFSETS is a set of amounts by which the sections of this object | |
c5aa993b | 2751 | file were relocated when it was loaded into memory. |
b8fbeb18 EZ |
2752 | Note that these section_offsets are not the |
2753 | objfile->section_offsets but the pst->section_offsets. | |
c5aa993b JM |
2754 | All symbols that refer |
2755 | to memory locations need to be offset by these amounts. | |
c906108c | 2756 | OBJFILE is the object file from which we are reading symbols. |
c5aa993b | 2757 | It is used in end_symtab. */ |
c906108c SS |
2758 | |
2759 | void | |
fba45db2 KB |
2760 | process_one_symbol (int type, int desc, CORE_ADDR valu, char *name, |
2761 | struct section_offsets *section_offsets, | |
2762 | struct objfile *objfile) | |
c906108c SS |
2763 | { |
2764 | #ifdef SUN_FIXED_LBRAC_BUG | |
2765 | /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need | |
2766 | to correct the address of N_LBRAC's. If it is not defined, then | |
2767 | we never need to correct the addresses. */ | |
2768 | ||
2769 | /* This records the last pc address we've seen. We depend on there being | |
2770 | an SLINE or FUN or SO before the first LBRAC, since the variable does | |
2771 | not get reset in between reads of different symbol files. */ | |
2772 | static CORE_ADDR last_pc_address; | |
2773 | #endif | |
2774 | ||
2775 | register struct context_stack *new; | |
2776 | /* This remembers the address of the start of a function. It is used | |
2777 | because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are | |
2778 | relative to the current function's start address. On systems | |
2779 | other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is | |
2780 | used to relocate these symbol types rather than SECTION_OFFSETS. */ | |
2781 | static CORE_ADDR function_start_offset; | |
2782 | ||
a1b9830c DJ |
2783 | /* This holds the address of the start of a function, without the system |
2784 | peculiarities of function_start_offset. */ | |
2785 | static CORE_ADDR last_function_start; | |
2786 | ||
54c7009d EZ |
2787 | /* If this is nonzero, we've seen an N_SLINE since the start of the |
2788 | current function. We use this to tell us to move the first sline | |
2789 | to the beginning of the function regardless of what its given | |
2790 | value is. */ | |
a1b9830c DJ |
2791 | static int sline_found_in_function = 1; |
2792 | ||
c906108c SS |
2793 | /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source |
2794 | file. Used to detect the SunPRO solaris compiler. */ | |
2795 | static int n_opt_found; | |
2796 | ||
2797 | /* The stab type used for the definition of the last function. | |
2798 | N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */ | |
2799 | static int function_stab_type = 0; | |
2800 | ||
2801 | if (!block_address_function_relative) | |
2802 | /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the | |
2803 | function start address, so just use the text offset. */ | |
b8fbeb18 | 2804 | function_start_offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2805 | |
2806 | /* Something is wrong if we see real data before | |
2807 | seeing a source file name. */ | |
2808 | ||
c5aa993b | 2809 | if (last_source_file == NULL && type != (unsigned char) N_SO) |
c906108c SS |
2810 | { |
2811 | /* Ignore any symbols which appear before an N_SO symbol. | |
c5aa993b JM |
2812 | Currently no one puts symbols there, but we should deal |
2813 | gracefully with the case. A complain()t might be in order, | |
2814 | but this should not be an error (). */ | |
c906108c SS |
2815 | return; |
2816 | } | |
2817 | ||
2818 | switch (type) | |
2819 | { | |
2820 | case N_FUN: | |
2821 | case N_FNAME: | |
2822 | ||
2823 | if (*name == '\000') | |
2824 | { | |
2825 | /* This N_FUN marks the end of a function. This closes off the | |
2826 | current block. */ | |
0c5e171a KD |
2827 | |
2828 | if (context_stack_depth <= 0) | |
2829 | { | |
23136709 | 2830 | lbrac_mismatch_complaint (symnum); |
0c5e171a KD |
2831 | break; |
2832 | } | |
2833 | ||
6b37567a JJ |
2834 | /* The following check is added before recording line 0 at |
2835 | end of function so as to handle hand-generated stabs | |
2836 | which may have an N_FUN stabs at the end of the function, but | |
2837 | no N_SLINE stabs. */ | |
2838 | if (sline_found_in_function) | |
2839 | record_line (current_subfile, 0, last_function_start + valu); | |
2840 | ||
c906108c SS |
2841 | within_function = 0; |
2842 | new = pop_context (); | |
2843 | ||
2844 | /* Make a block for the local symbols within. */ | |
2845 | finish_block (new->name, &local_symbols, new->old_blocks, | |
2846 | new->start_addr, new->start_addr + valu, | |
2847 | objfile); | |
2848 | ||
2849 | /* May be switching to an assembler file which may not be using | |
2850 | block relative stabs, so reset the offset. */ | |
2851 | if (block_address_function_relative) | |
2852 | function_start_offset = 0; | |
2853 | ||
2854 | break; | |
2855 | } | |
2856 | ||
a1b9830c DJ |
2857 | sline_found_in_function = 0; |
2858 | ||
c906108c | 2859 | /* Relocate for dynamic loading */ |
b8fbeb18 | 2860 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
181c1381 | 2861 | valu = SMASH_TEXT_ADDRESS (valu); |
a1b9830c DJ |
2862 | last_function_start = valu; |
2863 | ||
c906108c SS |
2864 | goto define_a_symbol; |
2865 | ||
2866 | case N_LBRAC: | |
2867 | /* This "symbol" just indicates the start of an inner lexical | |
c5aa993b | 2868 | context within a function. */ |
c906108c SS |
2869 | |
2870 | /* Ignore extra outermost context from SunPRO cc and acc. */ | |
2871 | if (n_opt_found && desc == 1) | |
2872 | break; | |
2873 | ||
2874 | if (block_address_function_relative) | |
2875 | /* Relocate for Sun ELF acc fn-relative syms. */ | |
2876 | valu += function_start_offset; | |
2877 | else | |
2878 | /* On most machines, the block addresses are relative to the | |
2879 | N_SO, the linker did not relocate them (sigh). */ | |
2880 | valu += last_source_start_addr; | |
2881 | ||
2882 | #ifdef SUN_FIXED_LBRAC_BUG | |
c5aa993b JM |
2883 | if (!SUN_FIXED_LBRAC_BUG && valu < last_pc_address) |
2884 | { | |
2885 | /* Patch current LBRAC pc value to match last handy pc value */ | |
23136709 | 2886 | complaint (&symfile_complaints, "bad block start address patched"); |
c5aa993b JM |
2887 | valu = last_pc_address; |
2888 | } | |
c906108c SS |
2889 | #endif |
2890 | new = push_context (desc, valu); | |
2891 | break; | |
2892 | ||
2893 | case N_RBRAC: | |
2894 | /* This "symbol" just indicates the end of an inner lexical | |
c5aa993b | 2895 | context that was started with N_LBRAC. */ |
c906108c SS |
2896 | |
2897 | /* Ignore extra outermost context from SunPRO cc and acc. */ | |
2898 | if (n_opt_found && desc == 1) | |
2899 | break; | |
2900 | ||
2901 | if (block_address_function_relative) | |
2902 | /* Relocate for Sun ELF acc fn-relative syms. */ | |
2903 | valu += function_start_offset; | |
2904 | else | |
2905 | /* On most machines, the block addresses are relative to the | |
2906 | N_SO, the linker did not relocate them (sigh). */ | |
2907 | valu += last_source_start_addr; | |
2908 | ||
0c5e171a KD |
2909 | if (context_stack_depth <= 0) |
2910 | { | |
23136709 | 2911 | lbrac_mismatch_complaint (symnum); |
0c5e171a KD |
2912 | break; |
2913 | } | |
2914 | ||
c5aa993b | 2915 | new = pop_context (); |
c906108c | 2916 | if (desc != new->depth) |
23136709 | 2917 | lbrac_mismatch_complaint (symnum); |
c906108c SS |
2918 | |
2919 | /* Some compilers put the variable decls inside of an | |
2920 | LBRAC/RBRAC block. This macro should be nonzero if this | |
c5aa993b JM |
2921 | is true. DESC is N_DESC from the N_RBRAC symbol. |
2922 | GCC_P is true if we've detected the GCC_COMPILED_SYMBOL | |
2923 | or the GCC2_COMPILED_SYMBOL. */ | |
c906108c SS |
2924 | #if !defined (VARIABLES_INSIDE_BLOCK) |
2925 | #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0 | |
2926 | #endif | |
2927 | ||
2928 | /* Can only use new->locals as local symbols here if we're in | |
2929 | gcc or on a machine that puts them before the lbrack. */ | |
c5aa993b | 2930 | if (!VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation)) |
1f077a3e KB |
2931 | { |
2932 | if (local_symbols != NULL) | |
2933 | { | |
2934 | /* GCC development snapshots from March to December of | |
2935 | 2000 would output N_LSYM entries after N_LBRAC | |
2936 | entries. As a consequence, these symbols are simply | |
2937 | discarded. Complain if this is the case. Note that | |
2938 | there are some compilers which legitimately put local | |
2939 | symbols within an LBRAC/RBRAC block; this complaint | |
2940 | might also help sort out problems in which | |
2941 | VARIABLES_INSIDE_BLOCK is incorrectly defined. */ | |
23136709 KB |
2942 | complaint (&symfile_complaints, |
2943 | "misplaced N_LBRAC entry; discarding local symbols which have no enclosing block"); | |
1f077a3e KB |
2944 | } |
2945 | local_symbols = new->locals; | |
2946 | } | |
c906108c SS |
2947 | |
2948 | if (context_stack_depth | |
c5aa993b | 2949 | > !VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation)) |
c906108c SS |
2950 | { |
2951 | /* This is not the outermost LBRAC...RBRAC pair in the function, | |
2952 | its local symbols preceded it, and are the ones just recovered | |
2953 | from the context stack. Define the block for them (but don't | |
2954 | bother if the block contains no symbols. Should we complain | |
2955 | on blocks without symbols? I can't think of any useful purpose | |
2956 | for them). */ | |
2957 | if (local_symbols != NULL) | |
2958 | { | |
2959 | /* Muzzle a compiler bug that makes end < start. (which | |
c5aa993b | 2960 | compilers? Is this ever harmful?). */ |
c906108c SS |
2961 | if (new->start_addr > valu) |
2962 | { | |
23136709 KB |
2963 | complaint (&symfile_complaints, |
2964 | "block start larger than block end"); | |
c906108c SS |
2965 | new->start_addr = valu; |
2966 | } | |
2967 | /* Make a block for the local symbols within. */ | |
2968 | finish_block (0, &local_symbols, new->old_blocks, | |
2969 | new->start_addr, valu, objfile); | |
2970 | } | |
2971 | } | |
2972 | else | |
2973 | { | |
2974 | /* This is the outermost LBRAC...RBRAC pair. There is no | |
2975 | need to do anything; leave the symbols that preceded it | |
2976 | to be attached to the function's own block. We need to | |
2977 | indicate that we just moved outside of the function. */ | |
2978 | within_function = 0; | |
2979 | } | |
2980 | ||
c5aa993b | 2981 | if (VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation)) |
c906108c SS |
2982 | /* Now pop locals of block just finished. */ |
2983 | local_symbols = new->locals; | |
2984 | break; | |
2985 | ||
2986 | case N_FN: | |
2987 | case N_FN_SEQ: | |
2988 | /* This kind of symbol indicates the start of an object file. */ | |
2989 | /* Relocate for dynamic loading */ | |
b8fbeb18 | 2990 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2991 | break; |
2992 | ||
2993 | case N_SO: | |
2994 | /* This type of symbol indicates the start of data | |
c5aa993b JM |
2995 | for one source file. |
2996 | Finish the symbol table of the previous source file | |
2997 | (if any) and start accumulating a new symbol table. */ | |
c906108c | 2998 | /* Relocate for dynamic loading */ |
b8fbeb18 | 2999 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3000 | |
3001 | n_opt_found = 0; | |
3002 | ||
3003 | #ifdef SUN_FIXED_LBRAC_BUG | |
3004 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
3005 | #endif | |
3006 | ||
3007 | #ifdef PCC_SOL_BROKEN | |
3008 | /* pcc bug, occasionally puts out SO for SOL. */ | |
3009 | if (context_stack_depth > 0) | |
3010 | { | |
3011 | start_subfile (name, NULL); | |
3012 | break; | |
3013 | } | |
3014 | #endif | |
3015 | if (last_source_file) | |
3016 | { | |
3017 | /* Check if previous symbol was also an N_SO (with some | |
3018 | sanity checks). If so, that one was actually the directory | |
3019 | name, and the current one is the real file name. | |
c5aa993b | 3020 | Patch things up. */ |
c906108c SS |
3021 | if (previous_stab_code == (unsigned char) N_SO) |
3022 | { | |
3023 | patch_subfile_names (current_subfile, name); | |
3024 | break; /* Ignore repeated SOs */ | |
3025 | } | |
b8fbeb18 | 3026 | end_symtab (valu, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3027 | end_stabs (); |
3028 | } | |
3029 | ||
3030 | /* Null name means this just marks the end of text for this .o file. | |
c5aa993b | 3031 | Don't start a new symtab in this case. */ |
c906108c SS |
3032 | if (*name == '\000') |
3033 | break; | |
3034 | ||
3035 | if (block_address_function_relative) | |
c5aa993b | 3036 | function_start_offset = 0; |
c906108c SS |
3037 | |
3038 | start_stabs (); | |
3039 | start_symtab (name, NULL, valu); | |
3040 | record_debugformat ("stabs"); | |
3041 | break; | |
3042 | ||
3043 | case N_SOL: | |
3044 | /* This type of symbol indicates the start of data for | |
c5aa993b JM |
3045 | a sub-source-file, one whose contents were copied or |
3046 | included in the compilation of the main source file | |
3047 | (whose name was given in the N_SO symbol.) */ | |
c906108c | 3048 | /* Relocate for dynamic loading */ |
b8fbeb18 | 3049 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3050 | start_subfile (name, current_subfile->dirname); |
3051 | break; | |
3052 | ||
3053 | case N_BINCL: | |
3054 | push_subfile (); | |
3055 | add_new_header_file (name, valu); | |
3056 | start_subfile (name, current_subfile->dirname); | |
3057 | break; | |
3058 | ||
3059 | case N_EINCL: | |
3060 | start_subfile (pop_subfile (), current_subfile->dirname); | |
3061 | break; | |
3062 | ||
3063 | case N_EXCL: | |
3064 | add_old_header_file (name, valu); | |
3065 | break; | |
3066 | ||
3067 | case N_SLINE: | |
3068 | /* This type of "symbol" really just records | |
c5aa993b JM |
3069 | one line-number -- core-address correspondence. |
3070 | Enter it in the line list for this symbol table. */ | |
c906108c SS |
3071 | |
3072 | /* Relocate for dynamic loading and for ELF acc fn-relative syms. */ | |
3073 | valu += function_start_offset; | |
3074 | ||
3075 | #ifdef SUN_FIXED_LBRAC_BUG | |
3076 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
3077 | #endif | |
a1b9830c DJ |
3078 | /* If this is the first SLINE note in the function, record it at |
3079 | the start of the function instead of at the listed location. */ | |
3080 | if (within_function && sline_found_in_function == 0) | |
3081 | { | |
3082 | record_line (current_subfile, desc, last_function_start); | |
3083 | sline_found_in_function = 1; | |
3084 | } | |
3085 | else | |
3086 | record_line (current_subfile, desc, valu); | |
c906108c SS |
3087 | break; |
3088 | ||
3089 | case N_BCOMM: | |
3090 | common_block_start (name, objfile); | |
3091 | break; | |
3092 | ||
3093 | case N_ECOMM: | |
3094 | common_block_end (objfile); | |
3095 | break; | |
3096 | ||
c5aa993b JM |
3097 | /* The following symbol types need to have the appropriate offset added |
3098 | to their value; then we process symbol definitions in the name. */ | |
c906108c SS |
3099 | |
3100 | case N_STSYM: /* Static symbol in data seg */ | |
3101 | case N_LCSYM: /* Static symbol in BSS seg */ | |
3102 | case N_ROSYM: /* Static symbol in Read-only data seg */ | |
c5aa993b JM |
3103 | /* HORRID HACK DEPT. However, it's Sun's furgin' fault. |
3104 | Solaris2's stabs-in-elf makes *most* symbols relative | |
3105 | but leaves a few absolute (at least for Solaris 2.1 and version | |
3106 | 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on the fence. | |
3107 | .stab "foo:S...",N_STSYM is absolute (ld relocates it) | |
3108 | .stab "foo:V...",N_STSYM is relative (section base subtracted). | |
3109 | This leaves us no choice but to search for the 'S' or 'V'... | |
3110 | (or pass the whole section_offsets stuff down ONE MORE function | |
3111 | call level, which we really don't want to do). */ | |
c906108c SS |
3112 | { |
3113 | char *p; | |
3114 | ||
3115 | /* .o files and NLMs have non-zero text seg offsets, but don't need | |
3116 | their static syms offset in this fashion. XXX - This is really a | |
3117 | crock that should be fixed in the solib handling code so that I | |
3118 | don't have to work around it here. */ | |
3119 | ||
3120 | if (!symfile_relocatable) | |
3121 | { | |
3122 | p = strchr (name, ':'); | |
3123 | if (p != 0 && p[1] == 'S') | |
3124 | { | |
3125 | /* The linker relocated it. We don't want to add an | |
3126 | elfstab_offset_sections-type offset, but we *do* want | |
3127 | to add whatever solib.c passed to symbol_file_add as | |
3128 | addr (this is known to affect SunOS4, and I suspect ELF | |
3129 | too). Since elfstab_offset_sections currently does not | |
3130 | muck with the text offset (there is no Ttext.text | |
3131 | symbol), we can get addr from the text offset. If | |
3132 | elfstab_offset_sections ever starts dealing with the | |
3133 | text offset, and we still need to do this, we need to | |
3134 | invent a SECT_OFF_ADDR_KLUDGE or something. */ | |
b8fbeb18 | 3135 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3136 | goto define_a_symbol; |
3137 | } | |
3138 | } | |
3139 | /* Since it's not the kludge case, re-dispatch to the right handler. */ | |
c5aa993b JM |
3140 | switch (type) |
3141 | { | |
3142 | case N_STSYM: | |
3143 | goto case_N_STSYM; | |
3144 | case N_LCSYM: | |
3145 | goto case_N_LCSYM; | |
3146 | case N_ROSYM: | |
3147 | goto case_N_ROSYM; | |
3148 | default: | |
e1e9e218 | 3149 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
c5aa993b | 3150 | } |
c906108c SS |
3151 | } |
3152 | ||
3153 | case_N_STSYM: /* Static symbol in data seg */ | |
3154 | case N_DSLINE: /* Source line number, data seg */ | |
b8fbeb18 | 3155 | valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); |
c906108c SS |
3156 | goto define_a_symbol; |
3157 | ||
3158 | case_N_LCSYM: /* Static symbol in BSS seg */ | |
3159 | case N_BSLINE: /* Source line number, bss seg */ | |
c5aa993b | 3160 | /* N_BROWS: overlaps with N_BSLINE */ |
b8fbeb18 | 3161 | valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile)); |
c906108c SS |
3162 | goto define_a_symbol; |
3163 | ||
3164 | case_N_ROSYM: /* Static symbol in Read-only data seg */ | |
b8fbeb18 | 3165 | valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile)); |
c906108c SS |
3166 | goto define_a_symbol; |
3167 | ||
3168 | case N_ENTRY: /* Alternate entry point */ | |
3169 | /* Relocate for dynamic loading */ | |
b8fbeb18 | 3170 | valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3171 | goto define_a_symbol; |
3172 | ||
c5aa993b JM |
3173 | /* The following symbol types we don't know how to process. Handle |
3174 | them in a "default" way, but complain to people who care. */ | |
c906108c SS |
3175 | default: |
3176 | case N_CATCH: /* Exception handler catcher */ | |
3177 | case N_EHDECL: /* Exception handler name */ | |
3178 | case N_PC: /* Global symbol in Pascal */ | |
c5aa993b JM |
3179 | case N_M2C: /* Modula-2 compilation unit */ |
3180 | /* N_MOD2: overlaps with N_EHDECL */ | |
c906108c SS |
3181 | case N_SCOPE: /* Modula-2 scope information */ |
3182 | case N_ECOML: /* End common (local name) */ | |
3183 | case N_NBTEXT: /* Gould Non-Base-Register symbols??? */ | |
3184 | case N_NBDATA: | |
3185 | case N_NBBSS: | |
3186 | case N_NBSTS: | |
3187 | case N_NBLCS: | |
23136709 | 3188 | unknown_symtype_complaint (local_hex_string (type)); |
c906108c SS |
3189 | /* FALLTHROUGH */ |
3190 | ||
c5aa993b JM |
3191 | /* The following symbol types don't need the address field relocated, |
3192 | since it is either unused, or is absolute. */ | |
c906108c SS |
3193 | define_a_symbol: |
3194 | case N_GSYM: /* Global variable */ | |
3195 | case N_NSYMS: /* Number of symbols (ultrix) */ | |
3196 | case N_NOMAP: /* No map? (ultrix) */ | |
3197 | case N_RSYM: /* Register variable */ | |
3198 | case N_DEFD: /* Modula-2 GNU module dependency */ | |
3199 | case N_SSYM: /* Struct or union element */ | |
3200 | case N_LSYM: /* Local symbol in stack */ | |
3201 | case N_PSYM: /* Parameter variable */ | |
3202 | case N_LENG: /* Length of preceding symbol type */ | |
3203 | if (name) | |
3204 | { | |
3205 | int deftype; | |
3206 | char *colon_pos = strchr (name, ':'); | |
3207 | if (colon_pos == NULL) | |
3208 | deftype = '\0'; | |
3209 | else | |
3210 | deftype = colon_pos[1]; | |
3211 | ||
3212 | switch (deftype) | |
3213 | { | |
3214 | case 'f': | |
3215 | case 'F': | |
3216 | function_stab_type = type; | |
3217 | ||
3218 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
3219 | /* Deal with the SunPRO 3.0 compiler which omits the address | |
c5aa993b | 3220 | from N_FUN symbols. */ |
c906108c | 3221 | if (type == N_FUN |
b8fbeb18 | 3222 | && valu == ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile))) |
9a058a09 KB |
3223 | { |
3224 | CORE_ADDR minsym_valu = | |
3225 | find_stab_function_addr (name, last_source_file, objfile); | |
3226 | ||
3227 | /* find_stab_function_addr will return 0 if the minimal | |
3228 | symbol wasn't found. (Unfortunately, this might also | |
3229 | be a valid address.) Anyway, if it *does* return 0, | |
3230 | it is likely that the value was set correctly to begin | |
3231 | with... */ | |
3232 | if (minsym_valu != 0) | |
3233 | valu = minsym_valu; | |
3234 | } | |
c906108c SS |
3235 | #endif |
3236 | ||
3237 | #ifdef SUN_FIXED_LBRAC_BUG | |
3238 | /* The Sun acc compiler, under SunOS4, puts out | |
c5aa993b JM |
3239 | functions with N_GSYM or N_STSYM. The problem is |
3240 | that the address of the symbol is no good (for N_GSYM | |
3241 | it doesn't even attept an address; for N_STSYM it | |
3242 | puts out an address but then it gets relocated | |
3243 | relative to the data segment, not the text segment). | |
3244 | Currently we can't fix this up later as we do for | |
3245 | some types of symbol in scan_file_globals. | |
3246 | Fortunately we do have a way of finding the address - | |
3247 | we know that the value in last_pc_address is either | |
3248 | the one we want (if we're dealing with the first | |
3249 | function in an object file), or somewhere in the | |
3250 | previous function. This means that we can use the | |
3251 | minimal symbol table to get the address. */ | |
c906108c SS |
3252 | |
3253 | /* Starting with release 3.0, the Sun acc compiler, | |
c5aa993b JM |
3254 | under SunOS4, puts out functions with N_FUN and a value |
3255 | of zero. This gets relocated to the start of the text | |
3256 | segment of the module, which is no good either. | |
3257 | Under SunOS4 we can deal with this as N_SLINE and N_SO | |
3258 | entries contain valid absolute addresses. | |
3259 | Release 3.0 acc also puts out N_OPT entries, which makes | |
3260 | it possible to discern acc from cc or gcc. */ | |
c906108c SS |
3261 | |
3262 | if (type == N_GSYM || type == N_STSYM | |
3263 | || (type == N_FUN | |
3264 | && n_opt_found && !block_address_function_relative)) | |
3265 | { | |
3266 | struct minimal_symbol *m; | |
3267 | int l = colon_pos - name; | |
3268 | ||
3269 | m = lookup_minimal_symbol_by_pc (last_pc_address); | |
22abf04a DC |
3270 | if (m && STREQN (DEPRECATED_SYMBOL_NAME (m), name, l) |
3271 | && DEPRECATED_SYMBOL_NAME (m)[l] == '\0') | |
c906108c SS |
3272 | /* last_pc_address was in this function */ |
3273 | valu = SYMBOL_VALUE (m); | |
22abf04a DC |
3274 | else if (m && DEPRECATED_SYMBOL_NAME (m + 1) |
3275 | && STREQN (DEPRECATED_SYMBOL_NAME (m + 1), name, l) | |
3276 | && DEPRECATED_SYMBOL_NAME (m + 1)[l] == '\0') | |
c906108c | 3277 | /* last_pc_address was in last function */ |
c5aa993b | 3278 | valu = SYMBOL_VALUE (m + 1); |
c906108c SS |
3279 | else |
3280 | /* Not found - use last_pc_address (for finish_block) */ | |
3281 | valu = last_pc_address; | |
3282 | } | |
3283 | ||
3284 | last_pc_address = valu; /* Save for SunOS bug circumcision */ | |
3285 | #endif | |
3286 | ||
3287 | if (block_address_function_relative) | |
3288 | /* For Solaris 2.0 compilers, the block addresses and | |
3289 | N_SLINE's are relative to the start of the | |
3290 | function. On normal systems, and when using gcc on | |
3291 | Solaris 2.0, these addresses are just absolute, or | |
3292 | relative to the N_SO, depending on | |
3293 | BLOCK_ADDRESS_ABSOLUTE. */ | |
c5aa993b | 3294 | function_start_offset = valu; |
c906108c SS |
3295 | |
3296 | within_function = 1; | |
c3f6f71d JM |
3297 | |
3298 | if (context_stack_depth > 1) | |
3299 | { | |
23136709 KB |
3300 | complaint (&symfile_complaints, |
3301 | "unmatched N_LBRAC before symtab pos %d", symnum); | |
c3f6f71d JM |
3302 | break; |
3303 | } | |
3304 | ||
c906108c SS |
3305 | if (context_stack_depth > 0) |
3306 | { | |
3307 | new = pop_context (); | |
3308 | /* Make a block for the local symbols within. */ | |
3309 | finish_block (new->name, &local_symbols, new->old_blocks, | |
3310 | new->start_addr, valu, objfile); | |
3311 | } | |
c906108c SS |
3312 | |
3313 | new = push_context (0, valu); | |
3314 | new->name = define_symbol (valu, name, desc, type, objfile); | |
3315 | break; | |
3316 | ||
3317 | default: | |
3318 | define_symbol (valu, name, desc, type, objfile); | |
3319 | break; | |
3320 | } | |
3321 | } | |
3322 | break; | |
3323 | ||
c5aa993b JM |
3324 | /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it |
3325 | for a bunch of other flags, too. Someday we may parse their | |
3326 | flags; for now we ignore theirs and hope they'll ignore ours. */ | |
3327 | case N_OPT: /* Solaris 2: Compiler options */ | |
c906108c SS |
3328 | if (name) |
3329 | { | |
3330 | if (STREQ (name, GCC2_COMPILED_FLAG_SYMBOL)) | |
3331 | { | |
3332 | processing_gcc_compilation = 2; | |
8052a17a JM |
3333 | #if 0 /* Works, but is experimental. -fnf */ |
3334 | /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't | |
3335 | know whether it will use the old style or v3 mangling. */ | |
c906108c SS |
3336 | if (AUTO_DEMANGLING) |
3337 | { | |
3338 | set_demangling_style (GNU_DEMANGLING_STYLE_STRING); | |
3339 | } | |
3340 | #endif | |
3341 | } | |
3342 | else | |
3343 | n_opt_found = 1; | |
3344 | } | |
3345 | break; | |
3346 | ||
51cc5b07 AC |
3347 | case N_MAIN: /* Name of main routine. */ |
3348 | /* FIXME: If one has a symbol file with N_MAIN and then replaces | |
3349 | it with a symbol file with "main" and without N_MAIN. I'm | |
3350 | not sure exactly what rule to follow but probably something | |
3351 | like: N_MAIN takes precedence over "main" no matter what | |
3352 | objfile it is in; If there is more than one N_MAIN, choose | |
3353 | the one in the symfile_objfile; If there is more than one | |
3354 | N_MAIN within a given objfile, complain() and choose | |
3355 | arbitrarily. (kingdon) */ | |
3356 | if (name != NULL) | |
3357 | set_main_name (name); | |
3358 | break; | |
3359 | ||
c5aa993b JM |
3360 | /* The following symbol types can be ignored. */ |
3361 | case N_OBJ: /* Solaris 2: Object file dir and name */ | |
3362 | /* N_UNDF: Solaris 2: file separator mark */ | |
3363 | /* N_UNDF: -- we will never encounter it, since we only process one | |
3364 | file's symbols at once. */ | |
c906108c | 3365 | case N_ENDM: /* Solaris 2: End of module */ |
c906108c SS |
3366 | case N_ALIAS: /* SunPro F77: alias name, ignore for now. */ |
3367 | break; | |
3368 | } | |
3369 | ||
3370 | /* '#' is a GNU C extension to allow one symbol to refer to another | |
3371 | related symbol. | |
3372 | ||
3373 | Generally this is used so that an alias can refer to its main | |
c5aa993b | 3374 | symbol. */ |
c906108c SS |
3375 | if (name[0] == '#') |
3376 | { | |
3377 | /* Initialize symbol reference names and determine if this is | |
3378 | a definition. If symbol reference is being defined, go | |
3379 | ahead and add it. Otherwise, just return sym. */ | |
3380 | ||
3381 | char *s = name; | |
3382 | int refnum; | |
3383 | ||
3384 | /* If this stab defines a new reference ID that is not on the | |
c5aa993b | 3385 | reference list, then put it on the reference list. |
c906108c | 3386 | |
c5aa993b JM |
3387 | We go ahead and advance NAME past the reference, even though |
3388 | it is not strictly necessary at this time. */ | |
c906108c SS |
3389 | refnum = symbol_reference_defined (&s); |
3390 | if (refnum >= 0) | |
3391 | if (!ref_search (refnum)) | |
3392 | ref_add (refnum, 0, name, valu); | |
3393 | name = s; | |
3394 | } | |
3395 | ||
3396 | ||
3397 | previous_stab_code = type; | |
3398 | } | |
3399 | \f | |
3400 | /* FIXME: The only difference between this and elfstab_build_psymtabs | |
3401 | is the call to install_minimal_symbols for elf, and the support for | |
3402 | split sections. If the differences are really that small, the code | |
3403 | should be shared. */ | |
3404 | ||
3405 | /* Scan and build partial symbols for an coff symbol file. | |
3406 | The coff file has already been processed to get its minimal symbols. | |
3407 | ||
3408 | This routine is the equivalent of dbx_symfile_init and dbx_symfile_read | |
3409 | rolled into one. | |
3410 | ||
3411 | OBJFILE is the object file we are reading symbols from. | |
3412 | ADDR is the address relative to which the symbols are (e.g. | |
3413 | the base address of the text segment). | |
3414 | MAINLINE is true if we are reading the main symbol | |
3415 | table (as opposed to a shared lib or dynamically loaded file). | |
3416 | TEXTADDR is the address of the text section. | |
3417 | TEXTSIZE is the size of the text section. | |
3418 | STABSECTS is the list of .stab sections in OBJFILE. | |
3419 | STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the | |
3420 | .stabstr section exists. | |
3421 | ||
3422 | This routine is mostly copied from dbx_symfile_init and dbx_symfile_read, | |
3423 | adjusted for coff details. */ | |
3424 | ||
3425 | void | |
fba45db2 KB |
3426 | coffstab_build_psymtabs (struct objfile *objfile, int mainline, |
3427 | CORE_ADDR textaddr, unsigned int textsize, | |
3428 | struct stab_section_list *stabsects, | |
3429 | file_ptr stabstroffset, unsigned int stabstrsize) | |
c906108c SS |
3430 | { |
3431 | int val; | |
3432 | bfd *sym_bfd = objfile->obfd; | |
3433 | char *name = bfd_get_filename (sym_bfd); | |
3434 | struct dbx_symfile_info *info; | |
3435 | unsigned int stabsize; | |
3436 | ||
3437 | /* There is already a dbx_symfile_info allocated by our caller. | |
3438 | It might even contain some info from the coff symtab to help us. */ | |
3439 | info = objfile->sym_stab_info; | |
3440 | ||
3441 | DBX_TEXT_ADDR (objfile) = textaddr; | |
3442 | DBX_TEXT_SIZE (objfile) = textsize; | |
3443 | ||
3444 | #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ | |
c5aa993b | 3445 | DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE; |
c906108c | 3446 | DBX_STRINGTAB_SIZE (objfile) = stabstrsize; |
c5aa993b | 3447 | |
c906108c SS |
3448 | if (stabstrsize > bfd_get_size (sym_bfd)) |
3449 | error ("ridiculous string table size: %d bytes", stabstrsize); | |
3450 | DBX_STRINGTAB (objfile) = (char *) | |
c5aa993b JM |
3451 | obstack_alloc (&objfile->psymbol_obstack, stabstrsize + 1); |
3452 | OBJSTAT (objfile, sz_strtab += stabstrsize + 1); | |
c906108c SS |
3453 | |
3454 | /* Now read in the string table in one big gulp. */ | |
3455 | ||
3456 | val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET); | |
3457 | if (val < 0) | |
3458 | perror_with_name (name); | |
3a42e9d0 | 3459 | val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd); |
c906108c SS |
3460 | if (val != stabstrsize) |
3461 | perror_with_name (name); | |
3462 | ||
3463 | stabsread_new_init (); | |
3464 | buildsym_new_init (); | |
3465 | free_header_files (); | |
3466 | init_header_files (); | |
3467 | ||
3468 | processing_acc_compilation = 1; | |
3469 | ||
3470 | /* In a coff file, we've already installed the minimal symbols that came | |
3471 | from the coff (non-stab) symbol table, so always act like an | |
3472 | incremental load here. */ | |
3473 | if (stabsects->next == NULL) | |
3474 | { | |
3475 | stabsize = bfd_section_size (sym_bfd, stabsects->section); | |
3476 | DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile); | |
3477 | DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos; | |
3478 | } | |
3479 | else | |
3480 | { | |
3481 | struct stab_section_list *stabsect; | |
3482 | ||
3483 | DBX_SYMCOUNT (objfile) = 0; | |
3484 | for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next) | |
3485 | { | |
3486 | stabsize = bfd_section_size (sym_bfd, stabsect->section); | |
3487 | DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile); | |
3488 | } | |
3489 | ||
3490 | DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos; | |
3491 | ||
3492 | symbuf_sections = stabsects->next; | |
3493 | symbuf_left = bfd_section_size (sym_bfd, stabsects->section); | |
3494 | symbuf_read = 0; | |
3495 | } | |
3496 | ||
96baa820 | 3497 | dbx_symfile_read (objfile, 0); |
c906108c SS |
3498 | } |
3499 | \f | |
3500 | /* Scan and build partial symbols for an ELF symbol file. | |
3501 | This ELF file has already been processed to get its minimal symbols, | |
3502 | and any DWARF symbols that were in it. | |
3503 | ||
3504 | This routine is the equivalent of dbx_symfile_init and dbx_symfile_read | |
3505 | rolled into one. | |
3506 | ||
3507 | OBJFILE is the object file we are reading symbols from. | |
3508 | ADDR is the address relative to which the symbols are (e.g. | |
3509 | the base address of the text segment). | |
3510 | MAINLINE is true if we are reading the main symbol | |
3511 | table (as opposed to a shared lib or dynamically loaded file). | |
086df311 | 3512 | STABSECT is the BFD section information for the .stab section. |
c906108c SS |
3513 | STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the |
3514 | .stabstr section exists. | |
3515 | ||
3516 | This routine is mostly copied from dbx_symfile_init and dbx_symfile_read, | |
3517 | adjusted for elf details. */ | |
3518 | ||
3519 | void | |
fba45db2 | 3520 | elfstab_build_psymtabs (struct objfile *objfile, int mainline, |
086df311 | 3521 | asection *stabsect, |
fba45db2 | 3522 | file_ptr stabstroffset, unsigned int stabstrsize) |
c906108c SS |
3523 | { |
3524 | int val; | |
3525 | bfd *sym_bfd = objfile->obfd; | |
3526 | char *name = bfd_get_filename (sym_bfd); | |
3527 | struct dbx_symfile_info *info; | |
086df311 | 3528 | struct cleanup *back_to = NULL; |
c906108c SS |
3529 | |
3530 | /* There is already a dbx_symfile_info allocated by our caller. | |
3531 | It might even contain some info from the ELF symtab to help us. */ | |
3532 | info = objfile->sym_stab_info; | |
3533 | ||
7a292a7a SS |
3534 | /* Find the first and last text address. dbx_symfile_read seems to |
3535 | want this. */ | |
3536 | find_text_range (sym_bfd, objfile); | |
c906108c SS |
3537 | |
3538 | #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */ | |
c5aa993b | 3539 | DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE; |
086df311 DJ |
3540 | DBX_SYMCOUNT (objfile) |
3541 | = bfd_section_size (objfile->obfd, stabsect) / DBX_SYMBOL_SIZE (objfile); | |
c906108c | 3542 | DBX_STRINGTAB_SIZE (objfile) = stabstrsize; |
086df311 DJ |
3543 | DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; |
3544 | DBX_STAB_SECTION (objfile) = stabsect; | |
c5aa993b | 3545 | |
c906108c SS |
3546 | if (stabstrsize > bfd_get_size (sym_bfd)) |
3547 | error ("ridiculous string table size: %d bytes", stabstrsize); | |
3548 | DBX_STRINGTAB (objfile) = (char *) | |
c5aa993b JM |
3549 | obstack_alloc (&objfile->psymbol_obstack, stabstrsize + 1); |
3550 | OBJSTAT (objfile, sz_strtab += stabstrsize + 1); | |
c906108c SS |
3551 | |
3552 | /* Now read in the string table in one big gulp. */ | |
3553 | ||
3554 | val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET); | |
3555 | if (val < 0) | |
3556 | perror_with_name (name); | |
3a42e9d0 | 3557 | val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd); |
c906108c SS |
3558 | if (val != stabstrsize) |
3559 | perror_with_name (name); | |
3560 | ||
3561 | stabsread_new_init (); | |
3562 | buildsym_new_init (); | |
3563 | free_header_files (); | |
3564 | init_header_files (); | |
c906108c SS |
3565 | |
3566 | processing_acc_compilation = 1; | |
3567 | ||
086df311 DJ |
3568 | symbuf_read = 0; |
3569 | symbuf_left = bfd_section_size (objfile->obfd, stabsect); | |
3570 | stabs_data = symfile_relocate_debug_section (objfile->obfd, stabsect, NULL); | |
3571 | if (stabs_data) | |
3572 | back_to = make_cleanup (free_current_contents, (void *) &stabs_data); | |
3573 | ||
c906108c SS |
3574 | /* In an elf file, we've already installed the minimal symbols that came |
3575 | from the elf (non-stab) symbol table, so always act like an | |
7134143f DJ |
3576 | incremental load here. dbx_symfile_read should not generate any new |
3577 | minimal symbols, since we will have already read the ELF dynamic symbol | |
3578 | table and normal symbol entries won't be in the ".stab" section; but in | |
3579 | case it does, it will install them itself. */ | |
96baa820 | 3580 | dbx_symfile_read (objfile, 0); |
086df311 DJ |
3581 | |
3582 | if (back_to) | |
3583 | do_cleanups (back_to); | |
c906108c SS |
3584 | } |
3585 | \f | |
3586 | /* Scan and build partial symbols for a file with special sections for stabs | |
3587 | and stabstrings. The file has already been processed to get its minimal | |
3588 | symbols, and any other symbols that might be necessary to resolve GSYMs. | |
3589 | ||
3590 | This routine is the equivalent of dbx_symfile_init and dbx_symfile_read | |
3591 | rolled into one. | |
3592 | ||
3593 | OBJFILE is the object file we are reading symbols from. | |
3594 | ADDR is the address relative to which the symbols are (e.g. the base address | |
c5aa993b | 3595 | of the text segment). |
c906108c | 3596 | MAINLINE is true if we are reading the main symbol table (as opposed to a |
c5aa993b | 3597 | shared lib or dynamically loaded file). |
c906108c SS |
3598 | STAB_NAME is the name of the section that contains the stabs. |
3599 | STABSTR_NAME is the name of the section that contains the stab strings. | |
3600 | ||
3601 | This routine is mostly copied from dbx_symfile_init and dbx_symfile_read. */ | |
3602 | ||
3603 | void | |
fba45db2 KB |
3604 | stabsect_build_psymtabs (struct objfile *objfile, int mainline, char *stab_name, |
3605 | char *stabstr_name, char *text_name) | |
c906108c SS |
3606 | { |
3607 | int val; | |
3608 | bfd *sym_bfd = objfile->obfd; | |
3609 | char *name = bfd_get_filename (sym_bfd); | |
3610 | asection *stabsect; | |
3611 | asection *stabstrsect; | |
3612 | asection *text_sect; | |
3613 | ||
3614 | stabsect = bfd_get_section_by_name (sym_bfd, stab_name); | |
3615 | stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name); | |
3616 | ||
3617 | if (!stabsect) | |
3618 | return; | |
3619 | ||
3620 | if (!stabstrsect) | |
3621 | error ("stabsect_build_psymtabs: Found stabs (%s), but not string section (%s)", | |
3622 | stab_name, stabstr_name); | |
3623 | ||
3624 | objfile->sym_stab_info = (struct dbx_symfile_info *) | |
3625 | xmalloc (sizeof (struct dbx_symfile_info)); | |
3626 | memset (objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info)); | |
3627 | ||
3628 | text_sect = bfd_get_section_by_name (sym_bfd, text_name); | |
3629 | if (!text_sect) | |
3630 | error ("Can't find %s section in symbol file", text_name); | |
3631 | DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect); | |
3632 | DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect); | |
3633 | ||
c5aa993b JM |
3634 | DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist); |
3635 | DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect) | |
c906108c SS |
3636 | / DBX_SYMBOL_SIZE (objfile); |
3637 | DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect); | |
c5aa993b JM |
3638 | DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; /* XXX - FIXME: POKING INSIDE BFD DATA STRUCTURES */ |
3639 | ||
c906108c SS |
3640 | if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd)) |
3641 | error ("ridiculous string table size: %d bytes", DBX_STRINGTAB_SIZE (objfile)); | |
3642 | DBX_STRINGTAB (objfile) = (char *) | |
3643 | obstack_alloc (&objfile->psymbol_obstack, DBX_STRINGTAB_SIZE (objfile) + 1); | |
3644 | OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1); | |
3645 | ||
3646 | /* Now read in the string table in one big gulp. */ | |
3647 | ||
c5aa993b JM |
3648 | val = bfd_get_section_contents (sym_bfd, /* bfd */ |
3649 | stabstrsect, /* bfd section */ | |
3650 | DBX_STRINGTAB (objfile), /* input buffer */ | |
3651 | 0, /* offset into section */ | |
3652 | DBX_STRINGTAB_SIZE (objfile)); /* amount to read */ | |
c906108c SS |
3653 | |
3654 | if (!val) | |
3655 | perror_with_name (name); | |
3656 | ||
3657 | stabsread_new_init (); | |
3658 | buildsym_new_init (); | |
3659 | free_header_files (); | |
3660 | init_header_files (); | |
c906108c SS |
3661 | |
3662 | /* Now, do an incremental load */ | |
3663 | ||
3664 | processing_acc_compilation = 1; | |
96baa820 | 3665 | dbx_symfile_read (objfile, 0); |
c906108c SS |
3666 | } |
3667 | \f | |
3668 | static struct sym_fns aout_sym_fns = | |
3669 | { | |
3670 | bfd_target_aout_flavour, | |
c5aa993b JM |
3671 | dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */ |
3672 | dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */ | |
3673 | dbx_symfile_read, /* sym_read: read a symbol file into symtab */ | |
3674 | dbx_symfile_finish, /* sym_finish: finished with file, cleanup */ | |
96baa820 | 3675 | default_symfile_offsets, /* sym_offsets: parse user's offsets to internal form */ |
c5aa993b | 3676 | NULL /* next: pointer to next struct sym_fns */ |
c906108c SS |
3677 | }; |
3678 | ||
3679 | void | |
fba45db2 | 3680 | _initialize_dbxread (void) |
c906108c | 3681 | { |
c5aa993b | 3682 | add_symtab_fns (&aout_sym_fns); |
c906108c | 3683 | } |