1 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992 Free Software Foundation,
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);
48 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
49 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_BSS);
58 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
59 CUR_SYMBOL_TYPE, objfile); /* Always */
60 #endif /* DBXREAD_ONLY */
63 /* Standard, local, non-debugger, symbols */
67 /* We need to be able to deal with both N_FN or N_TEXT,
68 because we have no way of knowing whether the sys-supplied ld
69 or GNU ld was used to make the executable. Sequents throw
70 in another wrinkle -- they renumbered N_FN. */
76 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
78 if ((namestring[0] == '-' && namestring[1] == 'l')
79 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
80 && namestring [nsl - 2] == '.')
81 #ifdef GDB_TARGET_IS_HPPA
82 /* some cooperation from gcc to get around ld stupidity */
83 || (namestring[0] == 'e' && STREQ (namestring, "end_file."))
87 #ifndef GDB_TARGET_IS_HPPA
88 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
89 objfile -> ei.entry_point >= last_o_file_start)
91 objfile -> ei.entry_file_lowpc = last_o_file_start;
92 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
95 if (past_first_source_file && pst
96 /* The gould NP1 uses low values for .o and -l symbols
97 which are not the address. */
98 && CUR_SYMBOL_VALUE >= pst->textlow)
100 END_PSYMTAB (pst, psymtab_include_list, includes_used,
101 symnum * symbol_size, CUR_SYMBOL_VALUE,
102 dependency_list, dependencies_used);
103 pst = (struct partial_symtab *) 0;
105 dependencies_used = 0;
108 past_first_source_file = 1;
109 last_o_file_start = CUR_SYMBOL_VALUE;
111 #endif /* DBXREAD_ONLY */
116 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
118 /* Check for __DYNAMIC, which is used by Sun shared libraries.
119 Record it even if it's local, not global, so we can find it.
120 FIXME: this might want to check for _DYNAMIC and the current
121 symbol_leading_char. */
122 if (namestring[8] == 'C' && STREQ ("__DYNAMIC", namestring))
125 /* Same with virtual function tables, both global and static. */
127 char *tempstring = namestring;
128 if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
130 if (VTBL_PREFIX_P ((tempstring)))
133 #endif /* DBXREAD_ONLY */
138 if (CUR_SYMBOL_VALUE != 0) {
139 /* This is a "Fortran COMMON" symbol. See if the target
140 environment knows where it has been relocated to. */
145 if (target_lookup_symbol (namestring, &reladdr)) {
146 continue; /* Error in lookup; ignore symbol for now. */
148 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
149 CUR_SYMBOL_VALUE = reladdr;
152 #endif /* DBXREAD_ONLY */
153 continue; /* Just undefined, not COMMON */
157 if (processing_acc_compilation && bufp->n_strx == 1) {
158 /* Deal with relative offsets in the string table
159 used in ELF+STAB under Solaris. If we want to use the
160 n_strx field, which contains the name of the file,
161 we must adjust file_string_table_offset *before* calling
163 past_first_source_file = 1;
164 file_string_table_offset = next_file_string_table_offset;
165 next_file_string_table_offset =
166 file_string_table_offset + bufp->n_value;
167 if (next_file_string_table_offset < file_string_table_offset)
168 error ("string table offset backs up at %d", symnum);
169 /* FIXME -- replace error() with complaint. */
172 #endif /* DBXREAD_ONLY */
175 /* Lots of symbol types we can just ignore. */
183 /* Keep going . . .*/
186 * Special symbol types for GNU
206 unsigned long valu = CUR_SYMBOL_VALUE;
207 static int prev_so_symnum = -10;
208 static int first_so_symnum;
211 past_first_source_file = 1;
213 if (prev_so_symnum != symnum - 1)
214 { /* Here if prev stab wasn't N_SO */
215 first_so_symnum = symnum;
219 END_PSYMTAB (pst, psymtab_include_list, includes_used,
220 symnum * symbol_size, valu,
221 dependency_list, dependencies_used);
222 pst = (struct partial_symtab *) 0;
224 dependencies_used = 0;
228 prev_so_symnum = symnum;
230 /* End the current partial symtab and start a new one */
234 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
236 /* Some compilers (including gcc) emit a pair of initial N_SOs.
237 The first one is a directory name; the second the file name.
238 If pst exists, is empty, and has a filename ending in '/',
239 we assume the previous N_SO was a directory name. */
241 p = strrchr (namestring, '/');
242 if (p && *(p+1) == '\000')
243 continue; /* Simply ignore directory name SOs */
245 /* Some other compilers (C++ ones in particular) emit useless
246 SOs for non-existant .c files. We ignore all subsequent SOs that
247 immediately follow the first. */
250 pst = START_PSYMTAB (objfile, section_offsets,
252 first_so_symnum * symbol_size,
253 objfile -> global_psymbols.next,
254 objfile -> static_psymbols.next);
260 /* Add this bincl to the bincl_list for future EXCLs. No
261 need to save the string; it'll be around until
262 read_dbx_symtab function returns */
266 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
268 /* Mark down an include file in the current psymtab */
270 psymtab_include_list[includes_used++] = namestring;
271 if (includes_used >= includes_allocated)
273 char **orig = psymtab_include_list;
275 psymtab_include_list = (char **)
276 alloca ((includes_allocated *= 2) *
278 memcpy ((PTR)psymtab_include_list, (PTR)orig,
279 includes_used * sizeof (char *));
282 #endif /* DBXREAD_ONLY */
286 /* Mark down an include file in the current psymtab */
290 /* In C++, one may expect the same filename to come round many
291 times, when code is coming alternately from the main file
292 and from inline functions in other files. So I check to see
293 if this is a file we've seen before -- either the main
294 source file, or a previously included file.
296 This seems to be a lot of time to be spending on N_SOL, but
297 things like "break c-exp.y:435" need to work (I
298 suppose the psymtab_include_list could be hashed or put
299 in a binary tree, if profiling shows this is a major hog). */
300 if (pst && STREQ (namestring, pst->filename))
304 for (i = 0; i < includes_used; i++)
305 if (STREQ (namestring, psymtab_include_list[i]))
314 psymtab_include_list[includes_used++] = namestring;
315 if (includes_used >= includes_allocated)
317 char **orig = psymtab_include_list;
319 psymtab_include_list = (char **)
320 alloca ((includes_allocated *= 2) *
322 memcpy ((PTR)psymtab_include_list, (PTR)orig,
323 includes_used * sizeof (char *));
327 case N_LSYM: /* Typedef or automatic variable. */
328 case N_STSYM: /* Data seg var -- static */
329 case N_LCSYM: /* BSS " */
330 case N_ROSYM: /* Read-only data seg var -- static. */
331 case N_NBSTS: /* Gould nobase. */
332 case N_NBLCS: /* symbols. */
336 p = (char *) strchr (namestring, ':');
338 /* Skip if there is no :. */
344 if (p != namestring) /* a name is there, not just :T... */
346 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
347 STRUCT_NAMESPACE, LOC_TYPEDEF,
348 objfile->static_psymbols,
350 psymtab_language, objfile);
353 /* Also a typedef with the same name. */
354 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
355 VAR_NAMESPACE, LOC_TYPEDEF,
356 objfile->static_psymbols,
357 CUR_SYMBOL_VALUE, psymtab_language,
364 if (p != namestring) /* a name is there, not just :T... */
366 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
367 VAR_NAMESPACE, LOC_TYPEDEF,
368 objfile->static_psymbols,
370 psymtab_language, objfile);
373 /* If this is an enumerated type, we need to
374 add all the enum constants to the partial symbol
375 table. This does not cover enums without names, e.g.
376 "enum {a, b} c;" in C, but fortunately those are
377 rare. There is no way for GDB to find those from the
378 enum type without spending too much time on it. Thus
379 to solve this problem, the compiler needs to put out separate
380 constant symbols ('c' N_LSYMS) for enum constants in
381 enums without names, or put out a dummy type. */
383 /* We are looking for something of the form
384 <name> ":" ("t" | "T") [<number> "="] "e"
385 {<constant> ":" <value> ","} ";". */
387 /* Skip over the colon and the 't' or 'T'. */
389 /* This type may be given a number. Also, numbers can come
390 in pairs like (0,26). Skip over it. */
391 while ((*p >= '0' && *p <= '9')
392 || *p == '(' || *p == ',' || *p == ')'
398 /* We have found an enumerated type. */
399 /* According to comments in read_enum_type
400 a comma could end it instead of a semicolon.
401 I don't know where that happens.
403 while (*p && *p != ';' && *p != ',')
407 /* Check for and handle cretinous dbx symbol name
410 p = next_symbol_text ();
412 /* Point to the character after the name
413 of the enum constant. */
414 for (q = p; *q && *q != ':'; q++)
416 /* Note that the value doesn't matter for
417 enum constants in psymtabs, just in symtabs. */
418 ADD_PSYMBOL_TO_LIST (p, q - p,
419 VAR_NAMESPACE, LOC_CONST,
420 objfile->static_psymbols, 0,
421 psymtab_language, objfile);
422 /* Point past the name. */
424 /* Skip over the value. */
425 while (*p && *p != ',')
427 /* Advance past the comma. */
434 /* Constant, e.g. from "const" in Pascal. */
435 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
436 VAR_NAMESPACE, LOC_CONST,
437 objfile->static_psymbols, CUR_SYMBOL_VALUE,
438 psymtab_language, objfile);
441 /* Skip if the thing following the : is
442 not a letter (which indicates declaration of a local
443 variable, which we aren't interested in). */
448 case N_GSYM: /* Global (extern) variable; can be
449 data or bss (sigh FIXME). */
451 /* Following may probably be ignored; I'll leave them here
452 for now (until I do Pascal and Modula 2 extensions). */
454 case N_PC: /* I may or may not need this; I
456 case N_M2C: /* I suspect that I can ignore this here. */
457 case N_SCOPE: /* Same. */
461 p = (char *) strchr (namestring, ':');
463 continue; /* Not a debugging symbol. */
467 /* Main processing section for debugging symbols which
468 the initial read through the symbol tables needs to worry
469 about. If we reach this point, the symbol which we are
470 considering is definitely one we are interested in.
471 p must also contain the (valid) index into the namestring
472 which indicates the debugging type symbol. */
477 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
478 VAR_NAMESPACE, LOC_CONST,
479 objfile->static_psymbols, CUR_SYMBOL_VALUE,
480 psymtab_language, objfile);
483 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
484 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
485 VAR_NAMESPACE, LOC_STATIC,
486 objfile->static_psymbols,
488 psymtab_language, objfile);
491 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
492 /* The addresses in these entries are reported to be
493 wrong. See the code that reads 'G's for symtabs. */
494 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
495 VAR_NAMESPACE, LOC_STATIC,
496 objfile->global_psymbols,
498 psymtab_language, objfile);
502 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
503 VAR_NAMESPACE, LOC_TYPEDEF,
504 objfile->static_psymbols, CUR_SYMBOL_VALUE,
505 psymtab_language, objfile);
510 /* Kludges for ELF/STABS with Sun ACC */
511 last_function_name = namestring;
512 if (pst && pst->textlow == 0)
513 pst->textlow = CUR_SYMBOL_VALUE;
515 if (startup_file_end == 0)
516 startup_file_end = CUR_SYMBOL_VALUE;
519 #endif /* DBXREAD_ONLY */
520 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
521 VAR_NAMESPACE, LOC_BLOCK,
522 objfile->static_psymbols, CUR_SYMBOL_VALUE,
523 psymtab_language, objfile);
526 /* Global functions were ignored here, but now they
527 are put into the global psymtab like one would expect.
528 They're also in the misc fn vector...
529 FIXME, why did it used to ignore these? That broke
530 "i fun" on these functions. */
533 /* Kludges for ELF/STABS with Sun ACC */
534 last_function_name = namestring;
535 if (pst && pst->textlow == 0)
536 pst->textlow = CUR_SYMBOL_VALUE;
538 if (startup_file_end == 0)
539 startup_file_end = CUR_SYMBOL_VALUE;
542 #endif /* DBXREAD_ONLY */
543 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
544 VAR_NAMESPACE, LOC_BLOCK,
545 objfile->global_psymbols, CUR_SYMBOL_VALUE,
546 psymtab_language, objfile);
549 /* Two things show up here (hopefully); static symbols of
550 local scope (static used inside braces) or extensions
551 of structure symbols. We can ignore both. */
567 /* Unexpected symbol. Ignore it; perhaps it is an extension
568 that we don't know about.
570 Someone says sun cc puts out symbols like
571 /foo/baz/maclib::/usr/local/bin/maclib,
572 which would get here with a symbol type of ':'. */
581 /* Find the corresponding bincl and mark that psymtab on the
582 psymtab dependency list */
584 struct partial_symtab *needed_pst =
585 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
587 /* If this include file was defined earlier in this file,
589 if (needed_pst == pst) continue;
596 for (i = 0; i < dependencies_used; i++)
597 if (dependency_list[i] == needed_pst)
603 /* If it's already in the list, skip the rest. */
606 dependency_list[dependencies_used++] = needed_pst;
607 if (dependencies_used >= dependencies_allocated)
609 struct partial_symtab **orig = dependency_list;
611 (struct partial_symtab **)
612 alloca ((dependencies_allocated *= 2)
613 * sizeof (struct partial_symtab *));
614 memcpy ((PTR)dependency_list, (PTR)orig,
616 * sizeof (struct partial_symtab *)));
618 fprintf (stderr, "Had to reallocate dependency list.\n");
619 fprintf (stderr, "New dependencies allocated: %d\n",
620 dependencies_allocated);
625 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
628 #endif /* DBXREAD_ONLY */
633 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
639 case N_SSYM: /* Claim: Structure or union element.
640 Hopefully, I can ignore this. */
641 case N_ENTRY: /* Alternate entry point; can ignore. */
642 case N_MAIN: /* Can definitely ignore this. */
643 case N_CATCH: /* These are GNU C++ extensions */
644 case N_EHDECL: /* that can safely be ignored here. */
654 case N_NSYMS: /* Ultrix 4.0: symbol count */
655 case N_DEFD: /* GNU Modula-2 */
657 case N_OBJ: /* useless types from Solaris */
660 /* These symbols aren't interesting; don't worry about them */
665 /* If we haven't found it yet, ignore it. It's probably some
666 new type we don't know about yet. */
667 complain (&unknown_symtype_complaint,
668 local_hex_string (CUR_SYMBOL_TYPE));