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
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., 675 Mass Ave, Cambridge, MA 02139, 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.
27 /* End of macro definitions, now let's handle them symbols! */
29 switch (CUR_SYMBOL_TYPE)
33 * Standard, external, non-debugger, symbols
37 case N_NBTEXT | N_EXT:
38 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
42 case N_NBDATA | N_EXT:
43 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
49 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
50 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_BSS);
59 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
60 CUR_SYMBOL_TYPE, objfile); /* Always */
61 #endif /* DBXREAD_ONLY */
64 /* Standard, local, non-debugger, symbols */
68 /* We need to be able to deal with both N_FN or N_TEXT,
69 because we have no way of knowing whether the sys-supplied ld
70 or GNU ld was used to make the executable. Sequents throw
71 in another wrinkle -- they renumbered N_FN. */
77 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
79 if ((namestring[0] == '-' && namestring[1] == 'l')
80 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
81 && namestring [nsl - 2] == '.')
82 #ifdef GDB_TARGET_IS_HPPA
83 /* This braindamage is necessary for versions of GCC 2.6 and
84 earlier; it will not be necessary for GCC 2.7.
86 In a nutshell, we need a way to determine when we've hit
87 the end of a file with debug symbols. Most ports do this
88 with a N_SO record with a NULL symbol name (as will GCC 2.7
89 on the PA). GCC 2.6 (and earlier) on the PA instead creates
90 an N_TEXT symbol with the name "end_file." */
91 || (namestring[0] == 'e' && STREQ (namestring, "end_file."))
95 #ifndef GDB_TARGET_IS_HPPA
96 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
97 objfile -> ei.entry_point >= last_o_file_start)
99 objfile -> ei.entry_file_lowpc = last_o_file_start;
100 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
103 if (past_first_source_file && pst
104 /* The gould NP1 uses low values for .o and -l symbols
105 which are not the address. */
106 && CUR_SYMBOL_VALUE >= pst->textlow)
108 END_PSYMTAB (pst, psymtab_include_list, includes_used,
109 symnum * symbol_size, CUR_SYMBOL_VALUE,
110 dependency_list, dependencies_used);
111 pst = (struct partial_symtab *) 0;
113 dependencies_used = 0;
116 past_first_source_file = 1;
117 last_o_file_start = CUR_SYMBOL_VALUE;
121 #endif /* DBXREAD_ONLY */
125 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
130 if (CUR_SYMBOL_VALUE != 0) {
131 /* This is a "Fortran COMMON" symbol. See if the target
132 environment knows where it has been relocated to. */
137 if (target_lookup_symbol (namestring, &reladdr)) {
138 continue; /* Error in lookup; ignore symbol for now. */
140 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
141 CUR_SYMBOL_VALUE = reladdr;
144 #endif /* DBXREAD_ONLY */
145 continue; /* Just undefined, not COMMON */
149 if (processing_acc_compilation && bufp->n_strx == 1) {
150 /* Deal with relative offsets in the string table
151 used in ELF+STAB under Solaris. If we want to use the
152 n_strx field, which contains the name of the file,
153 we must adjust file_string_table_offset *before* calling
155 past_first_source_file = 1;
156 file_string_table_offset = next_file_string_table_offset;
157 next_file_string_table_offset =
158 file_string_table_offset + bufp->n_value;
159 if (next_file_string_table_offset < file_string_table_offset)
160 error ("string table offset backs up at %d", symnum);
161 /* FIXME -- replace error() with complaint. */
164 #endif /* DBXREAD_ONLY */
167 /* Lots of symbol types we can just ignore. */
174 /* Keep going . . .*/
177 * Special symbol types for GNU
198 static int prev_so_symnum = -10;
199 static int first_so_symnum;
202 valu = CUR_SYMBOL_VALUE + ANOFFSET (section_offsets, SECT_OFF_TEXT);
204 past_first_source_file = 1;
206 if (prev_so_symnum != symnum - 1)
207 { /* Here if prev stab wasn't N_SO */
208 first_so_symnum = symnum;
212 END_PSYMTAB (pst, psymtab_include_list, includes_used,
213 symnum * symbol_size, valu,
214 dependency_list, dependencies_used);
215 pst = (struct partial_symtab *) 0;
217 dependencies_used = 0;
221 prev_so_symnum = symnum;
223 /* End the current partial symtab and start a new one */
227 /* Null name means end of .o file. Don't start a new one. */
228 if (*namestring == '\000')
231 /* Some compilers (including gcc) emit a pair of initial N_SOs.
232 The first one is a directory name; the second the file name.
233 If pst exists, is empty, and has a filename ending in '/',
234 we assume the previous N_SO was a directory name. */
236 p = strrchr (namestring, '/');
237 if (p && *(p+1) == '\000')
238 continue; /* Simply ignore directory name SOs */
240 /* Some other compilers (C++ ones in particular) emit useless
241 SOs for non-existant .c files. We ignore all subsequent SOs that
242 immediately follow the first. */
245 pst = START_PSYMTAB (objfile, section_offsets,
247 first_so_symnum * symbol_size,
248 objfile -> global_psymbols.next,
249 objfile -> static_psymbols.next);
256 enum language tmp_language;
257 /* Add this bincl to the bincl_list for future EXCLs. No
258 need to save the string; it'll be around until
259 read_dbx_symtab function returns */
263 tmp_language = deduce_language_from_filename (namestring);
265 /* Only change the psymtab's language if we've learned
266 something useful (eg. tmp_language is not language_unknown).
267 In addition, to match what start_subfile does, never change
269 if (tmp_language != language_unknown
270 && (tmp_language != language_c
271 || psymtab_language != language_cplus))
272 psymtab_language = tmp_language;
274 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
276 /* Mark down an include file in the current psymtab */
278 goto record_include_file;
280 #else /* DBXREAD_ONLY */
287 enum language tmp_language;
288 /* Mark down an include file in the current psymtab */
292 tmp_language = deduce_language_from_filename (namestring);
294 /* Only change the psymtab's language if we've learned
295 something useful (eg. tmp_language is not language_unknown).
296 In addition, to match what start_subfile does, never change
298 if (tmp_language != language_unknown
299 && (tmp_language != language_c
300 || psymtab_language != language_cplus))
301 psymtab_language = tmp_language;
303 /* In C++, one may expect the same filename to come round many
304 times, when code is coming alternately from the main file
305 and from inline functions in other files. So I check to see
306 if this is a file we've seen before -- either the main
307 source file, or a previously included file.
309 This seems to be a lot of time to be spending on N_SOL, but
310 things like "break c-exp.y:435" need to work (I
311 suppose the psymtab_include_list could be hashed or put
312 in a binary tree, if profiling shows this is a major hog). */
313 if (pst && STREQ (namestring, pst->filename))
317 for (i = 0; i < includes_used; i++)
318 if (STREQ (namestring, psymtab_include_list[i]))
331 psymtab_include_list[includes_used++] = namestring;
332 if (includes_used >= includes_allocated)
334 char **orig = psymtab_include_list;
336 psymtab_include_list = (char **)
337 alloca ((includes_allocated *= 2) *
339 memcpy ((PTR)psymtab_include_list, (PTR)orig,
340 includes_used * sizeof (char *));
344 case N_LSYM: /* Typedef or automatic variable. */
345 case N_STSYM: /* Data seg var -- static */
346 case N_LCSYM: /* BSS " */
347 case N_ROSYM: /* Read-only data seg var -- static. */
348 case N_NBSTS: /* Gould nobase. */
349 case N_NBLCS: /* symbols. */
351 case N_GSYM: /* Global (extern) variable; can be
352 data or bss (sigh FIXME). */
354 /* Following may probably be ignored; I'll leave them here
355 for now (until I do Pascal and Modula 2 extensions). */
357 case N_PC: /* I may or may not need this; I
359 case N_M2C: /* I suspect that I can ignore this here. */
360 case N_SCOPE: /* Same. */
364 p = (char *) strchr (namestring, ':');
366 continue; /* Not a debugging symbol. */
370 /* Main processing section for debugging symbols which
371 the initial read through the symbol tables needs to worry
372 about. If we reach this point, the symbol which we are
373 considering is definitely one we are interested in.
374 p must also contain the (valid) index into the namestring
375 which indicates the debugging type symbol. */
380 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
381 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
382 VAR_NAMESPACE, LOC_STATIC,
383 objfile->static_psymbols,
385 psymtab_language, objfile);
388 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
389 /* The addresses in these entries are reported to be
390 wrong. See the code that reads 'G's for symtabs. */
391 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
392 VAR_NAMESPACE, LOC_STATIC,
393 objfile->global_psymbols,
395 psymtab_language, objfile);
399 if (p != namestring) /* a name is there, not just :T... */
401 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
402 STRUCT_NAMESPACE, LOC_TYPEDEF,
403 objfile->static_psymbols,
405 psymtab_language, objfile);
408 /* Also a typedef with the same name. */
409 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
410 VAR_NAMESPACE, LOC_TYPEDEF,
411 objfile->static_psymbols,
412 CUR_SYMBOL_VALUE, psymtab_language,
416 /* The semantics of C++ state that "struct foo { ... }"
417 also defines a typedef for "foo". Unfortuantely, cfront
418 never makes the typedef when translating from C++ to C.
419 We make the typedef here so that "ptype foo" works as
420 expected for cfront translated code. */
421 else if (psymtab_language == language_cplus)
423 /* Also a typedef with the same name. */
424 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
425 VAR_NAMESPACE, LOC_TYPEDEF,
426 objfile->static_psymbols,
427 CUR_SYMBOL_VALUE, psymtab_language,
433 if (p != namestring) /* a name is there, not just :T... */
435 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
436 VAR_NAMESPACE, LOC_TYPEDEF,
437 objfile->static_psymbols,
439 psymtab_language, objfile);
442 /* If this is an enumerated type, we need to
443 add all the enum constants to the partial symbol
444 table. This does not cover enums without names, e.g.
445 "enum {a, b} c;" in C, but fortunately those are
446 rare. There is no way for GDB to find those from the
447 enum type without spending too much time on it. Thus
448 to solve this problem, the compiler needs to put out the
449 enum in a nameless type. GCC2 does this. */
451 /* We are looking for something of the form
452 <name> ":" ("t" | "T") [<number> "="] "e"
453 {<constant> ":" <value> ","} ";". */
455 /* Skip over the colon and the 't' or 'T'. */
457 /* This type may be given a number. Also, numbers can come
458 in pairs like (0,26). Skip over it. */
459 while ((*p >= '0' && *p <= '9')
460 || *p == '(' || *p == ',' || *p == ')'
466 /* We have found an enumerated type. */
467 /* According to comments in read_enum_type
468 a comma could end it instead of a semicolon.
469 I don't know where that happens.
471 while (*p && *p != ';' && *p != ',')
475 /* Check for and handle cretinous dbx symbol name
477 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
478 p = next_symbol_text ();
480 /* Point to the character after the name
481 of the enum constant. */
482 for (q = p; *q && *q != ':'; q++)
484 /* Note that the value doesn't matter for
485 enum constants in psymtabs, just in symtabs. */
486 ADD_PSYMBOL_TO_LIST (p, q - p,
487 VAR_NAMESPACE, LOC_CONST,
488 objfile->static_psymbols, 0,
489 psymtab_language, objfile);
490 /* Point past the name. */
492 /* Skip over the value. */
493 while (*p && *p != ',')
495 /* Advance past the comma. */
502 /* Constant, e.g. from "const" in Pascal. */
503 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
504 VAR_NAMESPACE, LOC_CONST,
505 objfile->static_psymbols, CUR_SYMBOL_VALUE,
506 psymtab_language, objfile);
510 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
512 /* Kludges for ELF/STABS with Sun ACC */
513 last_function_name = namestring;
514 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
515 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
516 value for the bottom of the text seg in those cases. */
517 if (pst && pst->textlow == 0 && !symfile_relocatable)
519 find_stab_function_addr (namestring, pst, objfile);
522 if (startup_file_end == 0)
523 startup_file_end = CUR_SYMBOL_VALUE;
526 #endif /* DBXREAD_ONLY */
527 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
528 VAR_NAMESPACE, LOC_BLOCK,
529 objfile->static_psymbols, CUR_SYMBOL_VALUE,
530 psymtab_language, objfile);
533 /* Global functions were ignored here, but now they
534 are put into the global psymtab like one would expect.
535 They're also in the minimal symbol table. */
537 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
539 /* Kludges for ELF/STABS with Sun ACC */
540 last_function_name = namestring;
541 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
542 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
543 value for the bottom of the text seg in those cases. */
544 if (pst && pst->textlow == 0 && !symfile_relocatable)
546 find_stab_function_addr (namestring, pst, objfile);
549 if (startup_file_end == 0)
550 startup_file_end = CUR_SYMBOL_VALUE;
553 #endif /* DBXREAD_ONLY */
554 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
555 VAR_NAMESPACE, LOC_BLOCK,
556 objfile->global_psymbols, CUR_SYMBOL_VALUE,
557 psymtab_language, objfile);
560 /* Two things show up here (hopefully); static symbols of
561 local scope (static used inside braces) or extensions
562 of structure symbols. We can ignore both. */
578 /* It is a C++ nested symbol. We don't need to record it
579 (I don't think); if we try to look up foo::bar::baz,
580 then symbols for the symtab containing foo should get
582 /* Someone says sun cc puts out symbols like
583 /foo/baz/maclib::/usr/local/bin/maclib,
584 which would get here with a symbol type of ':'. */
588 /* Unexpected symbol descriptor. The second and subsequent stabs
589 of a continued stab can show up here. The question is
590 whether they ever can mimic a normal stab--it would be
591 nice if not, since we certainly don't want to spend the
592 time searching to the end of every string looking for
595 complain (&unknown_symchar_complaint, p[1]);
597 /* Ignore it; perhaps it is an extension that we don't
607 /* Find the corresponding bincl and mark that psymtab on the
608 psymtab dependency list */
610 struct partial_symtab *needed_pst =
611 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
613 /* If this include file was defined earlier in this file,
615 if (needed_pst == pst) continue;
622 for (i = 0; i < dependencies_used; i++)
623 if (dependency_list[i] == needed_pst)
629 /* If it's already in the list, skip the rest. */
632 dependency_list[dependencies_used++] = needed_pst;
633 if (dependencies_used >= dependencies_allocated)
635 struct partial_symtab **orig = dependency_list;
637 (struct partial_symtab **)
638 alloca ((dependencies_allocated *= 2)
639 * sizeof (struct partial_symtab *));
640 memcpy ((PTR)dependency_list, (PTR)orig,
642 * sizeof (struct partial_symtab *)));
644 fprintf_unfiltered (gdb_stderr, "Had to reallocate dependency list.\n");
645 fprintf_unfiltered (gdb_stderr, "New dependencies allocated: %d\n",
646 dependencies_allocated);
651 #endif /* DBXREAD_ONLY */
656 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
662 case N_SSYM: /* Claim: Structure or union element.
663 Hopefully, I can ignore this. */
664 case N_ENTRY: /* Alternate entry point; can ignore. */
665 case N_MAIN: /* Can definitely ignore this. */
666 case N_CATCH: /* These are GNU C++ extensions */
667 case N_EHDECL: /* that can safely be ignored here. */
677 case N_NSYMS: /* Ultrix 4.0: symbol count */
678 case N_DEFD: /* GNU Modula-2 */
680 case N_OBJ: /* useless types from Solaris */
683 /* These symbols aren't interesting; don't worry about them */
688 /* If we haven't found it yet, ignore it. It's probably some
689 new type we don't know about yet. */
690 complain (&unknown_symtype_complaint,
691 local_hex_string (CUR_SYMBOL_TYPE));