1 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* The following need to be defined:
22 SET_NAMESTRING() --Set namestring to name of symbol.
23 CUR_SYMBOL_TYPE --Type code of current symbol.
24 CUR_SYMBOL_VALUE --Value field of current symbol. May be adjusted here.
25 namestring - variable pointing to the name of the stab.
26 section_offsets - variable pointing to the section offsets.
27 pst - the partial symbol table being built.
29 psymtab_include_list, includes_used, includes_allocated - list of include
30 file names (N_SOL) seen so far.
31 dependency_list, dependencies_used, dependencies_allocated - list of
32 N_EXCL stabs seen so far.
34 END_PSYMTAB -- end a partial symbol table.
35 START_PSYMTAB -- start a partial symbol table.
38 /* End of macro definitions, now let's handle them symbols! */
40 switch (CUR_SYMBOL_TYPE)
44 * Standard, external, non-debugger, symbols
48 case N_NBTEXT | N_EXT:
49 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
53 case N_NBDATA | N_EXT:
54 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
60 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
61 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_BSS);
70 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
71 CUR_SYMBOL_TYPE, objfile); /* Always */
72 #endif /* DBXREAD_ONLY */
75 /* Standard, local, non-debugger, symbols */
79 /* We need to be able to deal with both N_FN or N_TEXT,
80 because we have no way of knowing whether the sys-supplied ld
81 or GNU ld was used to make the executable. Sequents throw
82 in another wrinkle -- they renumbered N_FN. */
88 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
90 if ((namestring[0] == '-' && namestring[1] == 'l')
91 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
92 && namestring [nsl - 2] == '.')
93 #ifdef GDB_TARGET_IS_HPPA
94 /* This braindamage is necessary for versions of GCC 2.6 and
95 earlier; it will not be necessary for GCC 2.7.
97 In a nutshell, we need a way to determine when we've hit
98 the end of a file with debug symbols. Most ports do this
99 with a N_SO record with a NULL symbol name (as will GCC 2.7
100 on the PA). GCC 2.6 (and earlier) on the PA instead creates
101 an N_TEXT symbol with the name "end_file." */
102 || (namestring[0] == 'e' && STREQ (namestring, "end_file."))
106 #ifndef GDB_TARGET_IS_HPPA
107 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
108 objfile -> ei.entry_point >= last_o_file_start)
110 objfile -> ei.entry_file_lowpc = last_o_file_start;
111 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
114 if (past_first_source_file && pst
115 /* The gould NP1 uses low values for .o and -l symbols
116 which are not the address. */
117 && CUR_SYMBOL_VALUE >= pst->textlow)
119 END_PSYMTAB (pst, psymtab_include_list, includes_used,
120 symnum * symbol_size, CUR_SYMBOL_VALUE,
121 dependency_list, dependencies_used);
122 pst = (struct partial_symtab *) 0;
124 dependencies_used = 0;
127 past_first_source_file = 1;
128 last_o_file_start = CUR_SYMBOL_VALUE;
132 #endif /* DBXREAD_ONLY */
136 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
141 if (CUR_SYMBOL_VALUE != 0) {
142 /* This is a "Fortran COMMON" symbol. See if the target
143 environment knows where it has been relocated to. */
148 if (target_lookup_symbol (namestring, &reladdr)) {
149 continue; /* Error in lookup; ignore symbol for now. */
151 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
152 CUR_SYMBOL_VALUE = reladdr;
155 #endif /* DBXREAD_ONLY */
156 continue; /* Just undefined, not COMMON */
160 if (processing_acc_compilation && bufp->n_strx == 1) {
161 /* Deal with relative offsets in the string table
162 used in ELF+STAB under Solaris. If we want to use the
163 n_strx field, which contains the name of the file,
164 we must adjust file_string_table_offset *before* calling
166 past_first_source_file = 1;
167 file_string_table_offset = next_file_string_table_offset;
168 next_file_string_table_offset =
169 file_string_table_offset + bufp->n_value;
170 if (next_file_string_table_offset < file_string_table_offset)
171 error ("string table offset backs up at %d", symnum);
172 /* FIXME -- replace error() with complaint. */
175 #endif /* DBXREAD_ONLY */
178 /* Lots of symbol types we can just ignore. */
185 /* Keep going . . .*/
188 * Special symbol types for GNU
209 static int prev_so_symnum = -10;
210 static int first_so_symnum;
213 valu = CUR_SYMBOL_VALUE + ANOFFSET (section_offsets, SECT_OFF_TEXT);
214 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
215 /* A zero value is probably an indication for the SunPRO 3.0
216 compiler. end_psymtab explicitly tests for zero, so
217 don't relocate it. */
218 if (CUR_SYMBOL_VALUE == 0)
222 past_first_source_file = 1;
224 if (prev_so_symnum != symnum - 1)
225 { /* Here if prev stab wasn't N_SO */
226 first_so_symnum = symnum;
230 END_PSYMTAB (pst, psymtab_include_list, includes_used,
231 symnum * symbol_size, valu,
232 dependency_list, dependencies_used);
233 pst = (struct partial_symtab *) 0;
235 dependencies_used = 0;
239 prev_so_symnum = symnum;
241 /* End the current partial symtab and start a new one */
245 /* Null name means end of .o file. Don't start a new one. */
246 if (*namestring == '\000')
249 /* Some compilers (including gcc) emit a pair of initial N_SOs.
250 The first one is a directory name; the second the file name.
251 If pst exists, is empty, and has a filename ending in '/',
252 we assume the previous N_SO was a directory name. */
254 p = strrchr (namestring, '/');
255 if (p && *(p+1) == '\000')
256 continue; /* Simply ignore directory name SOs */
258 /* Some other compilers (C++ ones in particular) emit useless
259 SOs for non-existant .c files. We ignore all subsequent SOs that
260 immediately follow the first. */
263 pst = START_PSYMTAB (objfile, section_offsets,
265 first_so_symnum * symbol_size,
266 objfile -> global_psymbols.next,
267 objfile -> static_psymbols.next);
274 enum language tmp_language;
275 /* Add this bincl to the bincl_list for future EXCLs. No
276 need to save the string; it'll be around until
277 read_dbx_symtab function returns */
281 tmp_language = deduce_language_from_filename (namestring);
283 /* Only change the psymtab's language if we've learned
284 something useful (eg. tmp_language is not language_unknown).
285 In addition, to match what start_subfile does, never change
287 if (tmp_language != language_unknown
288 && (tmp_language != language_c
289 || psymtab_language != language_cplus))
290 psymtab_language = tmp_language;
292 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
294 /* Mark down an include file in the current psymtab */
296 goto record_include_file;
298 #else /* DBXREAD_ONLY */
305 enum language tmp_language;
306 /* Mark down an include file in the current psymtab */
310 tmp_language = deduce_language_from_filename (namestring);
312 /* Only change the psymtab's language if we've learned
313 something useful (eg. tmp_language is not language_unknown).
314 In addition, to match what start_subfile does, never change
316 if (tmp_language != language_unknown
317 && (tmp_language != language_c
318 || psymtab_language != language_cplus))
319 psymtab_language = tmp_language;
321 /* In C++, one may expect the same filename to come round many
322 times, when code is coming alternately from the main file
323 and from inline functions in other files. So I check to see
324 if this is a file we've seen before -- either the main
325 source file, or a previously included file.
327 This seems to be a lot of time to be spending on N_SOL, but
328 things like "break c-exp.y:435" need to work (I
329 suppose the psymtab_include_list could be hashed or put
330 in a binary tree, if profiling shows this is a major hog). */
331 if (pst && STREQ (namestring, pst->filename))
335 for (i = 0; i < includes_used; i++)
336 if (STREQ (namestring, psymtab_include_list[i]))
349 psymtab_include_list[includes_used++] = namestring;
350 if (includes_used >= includes_allocated)
352 char **orig = psymtab_include_list;
354 psymtab_include_list = (char **)
355 alloca ((includes_allocated *= 2) *
357 memcpy ((PTR)psymtab_include_list, (PTR)orig,
358 includes_used * sizeof (char *));
362 case N_LSYM: /* Typedef or automatic variable. */
363 case N_STSYM: /* Data seg var -- static */
364 case N_LCSYM: /* BSS " */
365 case N_ROSYM: /* Read-only data seg var -- static. */
366 case N_NBSTS: /* Gould nobase. */
367 case N_NBLCS: /* symbols. */
369 case N_GSYM: /* Global (extern) variable; can be
370 data or bss (sigh FIXME). */
372 /* Following may probably be ignored; I'll leave them here
373 for now (until I do Pascal and Modula 2 extensions). */
375 case N_PC: /* I may or may not need this; I
377 case N_M2C: /* I suspect that I can ignore this here. */
378 case N_SCOPE: /* Same. */
382 p = (char *) strchr (namestring, ':');
384 continue; /* Not a debugging symbol. */
388 /* Main processing section for debugging symbols which
389 the initial read through the symbol tables needs to worry
390 about. If we reach this point, the symbol which we are
391 considering is definitely one we are interested in.
392 p must also contain the (valid) index into the namestring
393 which indicates the debugging type symbol. */
398 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
399 #ifdef STATIC_TRANSFORM_NAME
400 namestring = STATIC_TRANSFORM_NAME (namestring);
402 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
403 VAR_NAMESPACE, LOC_STATIC,
404 objfile->static_psymbols,
406 psymtab_language, objfile);
409 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
410 /* The addresses in these entries are reported to be
411 wrong. See the code that reads 'G's for symtabs. */
412 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
413 VAR_NAMESPACE, LOC_STATIC,
414 objfile->global_psymbols,
416 psymtab_language, objfile);
420 if (p != namestring) /* a name is there, not just :T... */
422 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
423 STRUCT_NAMESPACE, LOC_TYPEDEF,
424 objfile->static_psymbols,
426 psymtab_language, objfile);
429 /* Also a typedef with the same name. */
430 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
431 VAR_NAMESPACE, LOC_TYPEDEF,
432 objfile->static_psymbols,
433 CUR_SYMBOL_VALUE, psymtab_language,
437 /* The semantics of C++ state that "struct foo { ... }"
438 also defines a typedef for "foo". Unfortuantely, cfront
439 never makes the typedef when translating from C++ to C.
440 We make the typedef here so that "ptype foo" works as
441 expected for cfront translated code. */
442 else if (psymtab_language == language_cplus)
444 /* Also a typedef with the same name. */
445 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
446 VAR_NAMESPACE, LOC_TYPEDEF,
447 objfile->static_psymbols,
448 CUR_SYMBOL_VALUE, psymtab_language,
454 if (p != namestring) /* a name is there, not just :T... */
456 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
457 VAR_NAMESPACE, LOC_TYPEDEF,
458 objfile->static_psymbols,
460 psymtab_language, objfile);
463 /* If this is an enumerated type, we need to
464 add all the enum constants to the partial symbol
465 table. This does not cover enums without names, e.g.
466 "enum {a, b} c;" in C, but fortunately those are
467 rare. There is no way for GDB to find those from the
468 enum type without spending too much time on it. Thus
469 to solve this problem, the compiler needs to put out the
470 enum in a nameless type. GCC2 does this. */
472 /* We are looking for something of the form
473 <name> ":" ("t" | "T") [<number> "="] "e"
474 {<constant> ":" <value> ","} ";". */
476 /* Skip over the colon and the 't' or 'T'. */
478 /* This type may be given a number. Also, numbers can come
479 in pairs like (0,26). Skip over it. */
480 while ((*p >= '0' && *p <= '9')
481 || *p == '(' || *p == ',' || *p == ')'
487 /* We have found an enumerated type. */
488 /* According to comments in read_enum_type
489 a comma could end it instead of a semicolon.
490 I don't know where that happens.
492 while (*p && *p != ';' && *p != ',')
496 /* Check for and handle cretinous dbx symbol name
498 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
499 p = next_symbol_text ();
501 /* Point to the character after the name
502 of the enum constant. */
503 for (q = p; *q && *q != ':'; q++)
505 /* Note that the value doesn't matter for
506 enum constants in psymtabs, just in symtabs. */
507 ADD_PSYMBOL_TO_LIST (p, q - p,
508 VAR_NAMESPACE, LOC_CONST,
509 objfile->static_psymbols, 0,
510 psymtab_language, objfile);
511 /* Point past the name. */
513 /* Skip over the value. */
514 while (*p && *p != ',')
516 /* Advance past the comma. */
523 /* Constant, e.g. from "const" in Pascal. */
524 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
525 VAR_NAMESPACE, LOC_CONST,
526 objfile->static_psymbols, CUR_SYMBOL_VALUE,
527 psymtab_language, objfile);
531 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
533 /* Kludges for ELF/STABS with Sun ACC */
534 last_function_name = namestring;
535 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
536 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
537 value for the bottom of the text seg in those cases. */
538 if (pst && pst->textlow == 0 && !symfile_relocatable)
540 find_stab_function_addr (namestring, pst, objfile);
543 if (startup_file_end == 0)
544 startup_file_end = CUR_SYMBOL_VALUE;
547 #endif /* DBXREAD_ONLY */
548 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
549 VAR_NAMESPACE, LOC_BLOCK,
550 objfile->static_psymbols, CUR_SYMBOL_VALUE,
551 psymtab_language, objfile);
554 /* Global functions were ignored here, but now they
555 are put into the global psymtab like one would expect.
556 They're also in the minimal symbol table. */
558 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
560 /* Kludges for ELF/STABS with Sun ACC */
561 last_function_name = namestring;
562 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
563 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
564 value for the bottom of the text seg in those cases. */
565 if (pst && pst->textlow == 0 && !symfile_relocatable)
567 find_stab_function_addr (namestring, pst, objfile);
570 if (startup_file_end == 0)
571 startup_file_end = CUR_SYMBOL_VALUE;
574 #endif /* DBXREAD_ONLY */
575 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
576 VAR_NAMESPACE, LOC_BLOCK,
577 objfile->global_psymbols, CUR_SYMBOL_VALUE,
578 psymtab_language, objfile);
581 /* Two things show up here (hopefully); static symbols of
582 local scope (static used inside braces) or extensions
583 of structure symbols. We can ignore both. */
600 /* It is a C++ nested symbol. We don't need to record it
601 (I don't think); if we try to look up foo::bar::baz,
602 then symbols for the symtab containing foo should get
604 /* Someone says sun cc puts out symbols like
605 /foo/baz/maclib::/usr/local/bin/maclib,
606 which would get here with a symbol type of ':'. */
610 /* Unexpected symbol descriptor. The second and subsequent stabs
611 of a continued stab can show up here. The question is
612 whether they ever can mimic a normal stab--it would be
613 nice if not, since we certainly don't want to spend the
614 time searching to the end of every string looking for
617 complain (&unknown_symchar_complaint, p[1]);
619 /* Ignore it; perhaps it is an extension that we don't
629 /* Find the corresponding bincl and mark that psymtab on the
630 psymtab dependency list */
632 struct partial_symtab *needed_pst =
633 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
635 /* If this include file was defined earlier in this file,
637 if (needed_pst == pst) continue;
644 for (i = 0; i < dependencies_used; i++)
645 if (dependency_list[i] == needed_pst)
651 /* If it's already in the list, skip the rest. */
654 dependency_list[dependencies_used++] = needed_pst;
655 if (dependencies_used >= dependencies_allocated)
657 struct partial_symtab **orig = dependency_list;
659 (struct partial_symtab **)
660 alloca ((dependencies_allocated *= 2)
661 * sizeof (struct partial_symtab *));
662 memcpy ((PTR)dependency_list, (PTR)orig,
664 * sizeof (struct partial_symtab *)));
666 fprintf_unfiltered (gdb_stderr, "Had to reallocate dependency list.\n");
667 fprintf_unfiltered (gdb_stderr, "New dependencies allocated: %d\n",
668 dependencies_allocated);
673 #endif /* DBXREAD_ONLY */
678 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
684 case N_SSYM: /* Claim: Structure or union element.
685 Hopefully, I can ignore this. */
686 case N_ENTRY: /* Alternate entry point; can ignore. */
687 case N_MAIN: /* Can definitely ignore this. */
688 case N_CATCH: /* These are GNU C++ extensions */
689 case N_EHDECL: /* that can safely be ignored here. */
699 case N_NSYMS: /* Ultrix 4.0: symbol count */
700 case N_DEFD: /* GNU Modula-2 */
702 case N_OBJ: /* useless types from Solaris */
705 /* These symbols aren't interesting; don't worry about them */
710 /* If we haven't found it yet, ignore it. It's probably some
711 new type we don't know about yet. */
712 complain (&unknown_symtype_complaint,
713 local_hex_string (CUR_SYMBOL_TYPE));