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] == '.'))
94 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
95 objfile -> ei.entry_point >= last_o_file_start)
97 objfile -> ei.entry_file_lowpc = last_o_file_start;
98 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
100 if (past_first_source_file && pst
101 /* The gould NP1 uses low values for .o and -l symbols
102 which are not the address. */
103 && CUR_SYMBOL_VALUE >= pst->textlow)
105 END_PSYMTAB (pst, psymtab_include_list, includes_used,
106 symnum * symbol_size, CUR_SYMBOL_VALUE,
107 dependency_list, dependencies_used);
108 pst = (struct partial_symtab *) 0;
110 dependencies_used = 0;
113 past_first_source_file = 1;
114 last_o_file_start = CUR_SYMBOL_VALUE;
118 #endif /* DBXREAD_ONLY */
122 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
127 if (CUR_SYMBOL_VALUE != 0) {
128 /* This is a "Fortran COMMON" symbol. See if the target
129 environment knows where it has been relocated to. */
134 if (target_lookup_symbol (namestring, &reladdr)) {
135 continue; /* Error in lookup; ignore symbol for now. */
137 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
138 CUR_SYMBOL_VALUE = reladdr;
141 #endif /* DBXREAD_ONLY */
142 continue; /* Just undefined, not COMMON */
146 if (processing_acc_compilation && bufp->n_strx == 1) {
147 /* Deal with relative offsets in the string table
148 used in ELF+STAB under Solaris. If we want to use the
149 n_strx field, which contains the name of the file,
150 we must adjust file_string_table_offset *before* calling
152 past_first_source_file = 1;
153 file_string_table_offset = next_file_string_table_offset;
154 next_file_string_table_offset =
155 file_string_table_offset + bufp->n_value;
156 if (next_file_string_table_offset < file_string_table_offset)
157 error ("string table offset backs up at %d", symnum);
158 /* FIXME -- replace error() with complaint. */
161 #endif /* DBXREAD_ONLY */
164 /* Lots of symbol types we can just ignore. */
171 /* Keep going . . .*/
174 * Special symbol types for GNU
195 static int prev_so_symnum = -10;
196 static int first_so_symnum;
199 valu = CUR_SYMBOL_VALUE + ANOFFSET (section_offsets, SECT_OFF_TEXT);
200 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
201 /* A zero value is probably an indication for the SunPRO 3.0
202 compiler. end_psymtab explicitly tests for zero, so
203 don't relocate it. */
204 if (CUR_SYMBOL_VALUE == 0)
208 past_first_source_file = 1;
210 if (prev_so_symnum != symnum - 1)
211 { /* Here if prev stab wasn't N_SO */
212 first_so_symnum = symnum;
216 END_PSYMTAB (pst, psymtab_include_list, includes_used,
217 symnum * symbol_size, valu,
218 dependency_list, dependencies_used);
219 pst = (struct partial_symtab *) 0;
221 dependencies_used = 0;
225 prev_so_symnum = symnum;
227 /* End the current partial symtab and start a new one */
231 /* Null name means end of .o file. Don't start a new one. */
232 if (*namestring == '\000')
235 /* Some compilers (including gcc) emit a pair of initial N_SOs.
236 The first one is a directory name; the second the file name.
237 If pst exists, is empty, and has a filename ending in '/',
238 we assume the previous N_SO was a directory name. */
240 p = strrchr (namestring, '/');
241 if (p && *(p+1) == '\000')
242 continue; /* Simply ignore directory name SOs */
244 /* Some other compilers (C++ ones in particular) emit useless
245 SOs for non-existant .c files. We ignore all subsequent SOs that
246 immediately follow the first. */
249 pst = START_PSYMTAB (objfile, section_offsets,
251 first_so_symnum * symbol_size,
252 objfile -> global_psymbols.next,
253 objfile -> static_psymbols.next);
260 enum language tmp_language;
261 /* Add this bincl to the bincl_list for future EXCLs. No
262 need to save the string; it'll be around until
263 read_dbx_symtab function returns */
267 tmp_language = deduce_language_from_filename (namestring);
269 /* Only change the psymtab's language if we've learned
270 something useful (eg. tmp_language is not language_unknown).
271 In addition, to match what start_subfile does, never change
273 if (tmp_language != language_unknown
274 && (tmp_language != language_c
275 || psymtab_language != language_cplus))
276 psymtab_language = tmp_language;
278 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
280 /* Mark down an include file in the current psymtab */
282 goto record_include_file;
284 #else /* DBXREAD_ONLY */
291 enum language tmp_language;
292 /* Mark down an include file in the current psymtab */
296 tmp_language = deduce_language_from_filename (namestring);
298 /* Only change the psymtab's language if we've learned
299 something useful (eg. tmp_language is not language_unknown).
300 In addition, to match what start_subfile does, never change
302 if (tmp_language != language_unknown
303 && (tmp_language != language_c
304 || psymtab_language != language_cplus))
305 psymtab_language = tmp_language;
307 /* In C++, one may expect the same filename to come round many
308 times, when code is coming alternately from the main file
309 and from inline functions in other files. So I check to see
310 if this is a file we've seen before -- either the main
311 source file, or a previously included file.
313 This seems to be a lot of time to be spending on N_SOL, but
314 things like "break c-exp.y:435" need to work (I
315 suppose the psymtab_include_list could be hashed or put
316 in a binary tree, if profiling shows this is a major hog). */
317 if (pst && STREQ (namestring, pst->filename))
321 for (i = 0; i < includes_used; i++)
322 if (STREQ (namestring, psymtab_include_list[i]))
335 psymtab_include_list[includes_used++] = namestring;
336 if (includes_used >= includes_allocated)
338 char **orig = psymtab_include_list;
340 psymtab_include_list = (char **)
341 alloca ((includes_allocated *= 2) *
343 memcpy ((PTR)psymtab_include_list, (PTR)orig,
344 includes_used * sizeof (char *));
348 case N_LSYM: /* Typedef or automatic variable. */
349 case N_STSYM: /* Data seg var -- static */
350 case N_LCSYM: /* BSS " */
351 case N_ROSYM: /* Read-only data seg var -- static. */
352 case N_NBSTS: /* Gould nobase. */
353 case N_NBLCS: /* symbols. */
355 case N_GSYM: /* Global (extern) variable; can be
356 data or bss (sigh FIXME). */
358 /* Following may probably be ignored; I'll leave them here
359 for now (until I do Pascal and Modula 2 extensions). */
361 case N_PC: /* I may or may not need this; I
363 case N_M2C: /* I suspect that I can ignore this here. */
364 case N_SCOPE: /* Same. */
368 p = (char *) strchr (namestring, ':');
370 continue; /* Not a debugging symbol. */
374 /* Main processing section for debugging symbols which
375 the initial read through the symbol tables needs to worry
376 about. If we reach this point, the symbol which we are
377 considering is definitely one we are interested in.
378 p must also contain the (valid) index into the namestring
379 which indicates the debugging type symbol. */
384 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
385 #ifdef STATIC_TRANSFORM_NAME
386 namestring = STATIC_TRANSFORM_NAME (namestring);
388 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
389 VAR_NAMESPACE, LOC_STATIC,
390 objfile->static_psymbols,
392 psymtab_language, objfile);
395 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
396 /* The addresses in these entries are reported to be
397 wrong. See the code that reads 'G's for symtabs. */
398 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
399 VAR_NAMESPACE, LOC_STATIC,
400 objfile->global_psymbols,
402 psymtab_language, objfile);
406 if (p != namestring) /* a name is there, not just :T... */
408 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
409 STRUCT_NAMESPACE, LOC_TYPEDEF,
410 objfile->static_psymbols,
412 psymtab_language, objfile);
415 /* Also a typedef with the same name. */
416 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
417 VAR_NAMESPACE, LOC_TYPEDEF,
418 objfile->static_psymbols,
419 CUR_SYMBOL_VALUE, psymtab_language,
423 /* The semantics of C++ state that "struct foo { ... }"
424 also defines a typedef for "foo". Unfortuantely, cfront
425 never makes the typedef when translating from C++ to C.
426 We make the typedef here so that "ptype foo" works as
427 expected for cfront translated code. */
428 else if (psymtab_language == language_cplus)
430 /* Also a typedef with the same name. */
431 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
432 VAR_NAMESPACE, LOC_TYPEDEF,
433 objfile->static_psymbols,
434 CUR_SYMBOL_VALUE, psymtab_language,
440 if (p != namestring) /* a name is there, not just :T... */
442 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
443 VAR_NAMESPACE, LOC_TYPEDEF,
444 objfile->static_psymbols,
446 psymtab_language, objfile);
449 /* If this is an enumerated type, we need to
450 add all the enum constants to the partial symbol
451 table. This does not cover enums without names, e.g.
452 "enum {a, b} c;" in C, but fortunately those are
453 rare. There is no way for GDB to find those from the
454 enum type without spending too much time on it. Thus
455 to solve this problem, the compiler needs to put out the
456 enum in a nameless type. GCC2 does this. */
458 /* We are looking for something of the form
459 <name> ":" ("t" | "T") [<number> "="] "e"
460 {<constant> ":" <value> ","} ";". */
462 /* Skip over the colon and the 't' or 'T'. */
464 /* This type may be given a number. Also, numbers can come
465 in pairs like (0,26). Skip over it. */
466 while ((*p >= '0' && *p <= '9')
467 || *p == '(' || *p == ',' || *p == ')'
473 /* The aix4 compiler emits extra crud before the members. */
476 /* Skip over the type (?). */
480 /* Skip over the colon. */
484 /* We have found an enumerated type. */
485 /* According to comments in read_enum_type
486 a comma could end it instead of a semicolon.
487 I don't know where that happens.
489 while (*p && *p != ';' && *p != ',')
493 /* Check for and handle cretinous dbx symbol name
495 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
496 p = next_symbol_text (objfile);
498 /* Point to the character after the name
499 of the enum constant. */
500 for (q = p; *q && *q != ':'; q++)
502 /* Note that the value doesn't matter for
503 enum constants in psymtabs, just in symtabs. */
504 ADD_PSYMBOL_TO_LIST (p, q - p,
505 VAR_NAMESPACE, LOC_CONST,
506 objfile->static_psymbols, 0,
507 psymtab_language, objfile);
508 /* Point past the name. */
510 /* Skip over the value. */
511 while (*p && *p != ',')
513 /* Advance past the comma. */
520 /* Constant, e.g. from "const" in Pascal. */
521 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
522 VAR_NAMESPACE, LOC_CONST,
523 objfile->static_psymbols, CUR_SYMBOL_VALUE,
524 psymtab_language, objfile);
528 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
530 /* Kludges for ELF/STABS with Sun ACC */
531 last_function_name = namestring;
532 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
533 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
534 value for the bottom of the text seg in those cases. */
535 if (pst && pst->textlow == 0 && !symfile_relocatable)
537 find_stab_function_addr (namestring, pst, objfile);
540 if (startup_file_end == 0)
541 startup_file_end = CUR_SYMBOL_VALUE;
544 #endif /* DBXREAD_ONLY */
545 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
546 VAR_NAMESPACE, LOC_BLOCK,
547 objfile->static_psymbols, CUR_SYMBOL_VALUE,
548 psymtab_language, objfile);
551 /* Global functions were ignored here, but now they
552 are put into the global psymtab like one would expect.
553 They're also in the minimal symbol table. */
555 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
557 /* Kludges for ELF/STABS with Sun ACC */
558 last_function_name = namestring;
559 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
560 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
561 value for the bottom of the text seg in those cases. */
562 if (pst && pst->textlow == 0 && !symfile_relocatable)
564 find_stab_function_addr (namestring, pst, objfile);
567 if (startup_file_end == 0)
568 startup_file_end = CUR_SYMBOL_VALUE;
571 #endif /* DBXREAD_ONLY */
572 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
573 VAR_NAMESPACE, LOC_BLOCK,
574 objfile->global_psymbols, CUR_SYMBOL_VALUE,
575 psymtab_language, objfile);
578 /* Two things show up here (hopefully); static symbols of
579 local scope (static used inside braces) or extensions
580 of structure symbols. We can ignore both. */
597 /* It is a C++ nested symbol. We don't need to record it
598 (I don't think); if we try to look up foo::bar::baz,
599 then symbols for the symtab containing foo should get
601 /* Someone says sun cc puts out symbols like
602 /foo/baz/maclib::/usr/local/bin/maclib,
603 which would get here with a symbol type of ':'. */
607 /* Unexpected symbol descriptor. The second and subsequent stabs
608 of a continued stab can show up here. The question is
609 whether they ever can mimic a normal stab--it would be
610 nice if not, since we certainly don't want to spend the
611 time searching to the end of every string looking for
614 complain (&unknown_symchar_complaint, p[1]);
616 /* Ignore it; perhaps it is an extension that we don't
626 /* Find the corresponding bincl and mark that psymtab on the
627 psymtab dependency list */
629 struct partial_symtab *needed_pst =
630 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
632 /* If this include file was defined earlier in this file,
634 if (needed_pst == pst) continue;
641 for (i = 0; i < dependencies_used; i++)
642 if (dependency_list[i] == needed_pst)
648 /* If it's already in the list, skip the rest. */
651 dependency_list[dependencies_used++] = needed_pst;
652 if (dependencies_used >= dependencies_allocated)
654 struct partial_symtab **orig = dependency_list;
656 (struct partial_symtab **)
657 alloca ((dependencies_allocated *= 2)
658 * sizeof (struct partial_symtab *));
659 memcpy ((PTR)dependency_list, (PTR)orig,
661 * sizeof (struct partial_symtab *)));
663 fprintf_unfiltered (gdb_stderr, "Had to reallocate dependency list.\n");
664 fprintf_unfiltered (gdb_stderr, "New dependencies allocated: %d\n",
665 dependencies_allocated);
670 #endif /* DBXREAD_ONLY */
675 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
681 case N_SSYM: /* Claim: Structure or union element.
682 Hopefully, I can ignore this. */
683 case N_ENTRY: /* Alternate entry point; can ignore. */
684 case N_MAIN: /* Can definitely ignore this. */
685 case N_CATCH: /* These are GNU C++ extensions */
686 case N_EHDECL: /* that can safely be ignored here. */
696 case N_NSYMS: /* Ultrix 4.0: symbol count */
697 case N_DEFD: /* GNU Modula-2 */
699 case N_OBJ: /* useless types from Solaris */
702 /* These symbols aren't interesting; don't worry about them */
707 /* If we haven't found it yet, ignore it. It's probably some
708 new type we don't know about yet. */
709 complain (&unknown_symtype_complaint,
710 local_hex_string (CUR_SYMBOL_TYPE));