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] == '.')
82 /* some cooperation from gcc to get around ld stupidity */
83 || (namestring[0] == 'e' && !strcmp (namestring, "end_file."))
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 Same with virtual function tables, both global and static. */
121 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
122 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
124 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
125 CUR_SYMBOL_TYPE, objfile); /* Always */
127 #endif /* DBXREAD_ONLY */
132 if (CUR_SYMBOL_VALUE != 0) {
133 /* This is a "Fortran COMMON" symbol. See if the target
134 environment knows where it has been relocated to. */
139 if (target_lookup_symbol (namestring, &reladdr)) {
140 continue; /* Error in lookup; ignore symbol for now. */
142 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
143 CUR_SYMBOL_VALUE = reladdr;
146 #endif /* DBXREAD_ONLY */
147 continue; /* Just undefined, not COMMON */
151 if (processing_acc_compilation && bufp->n_strx == 1) {
152 /* Deal with relative offsets in the string table
153 used in ELF+STAB under Solaris. If we want to use the
154 n_strx field, which contains the name of the file,
155 we must adjust file_string_table_offset *before* calling
157 past_first_source_file = 1;
158 file_string_table_offset = next_file_string_table_offset;
159 next_file_string_table_offset =
160 file_string_table_offset + bufp->n_value;
161 if (next_file_string_table_offset < file_string_table_offset)
162 error ("string table offset backs up at %d", symnum);
163 /* FIXME -- replace error() with complaint. */
166 #endif /* DBXREAD_ONLY */
169 /* Lots of symbol types we can just ignore. */
177 /* Keep going . . .*/
180 * Special symbol types for GNU
200 unsigned long valu = CUR_SYMBOL_VALUE;
201 static int prev_so_symnum = -10;
202 static int first_so_symnum;
205 past_first_source_file = 1;
207 if (prev_so_symnum != symnum - 1)
208 { /* Here if prev stab wasn't N_SO */
209 first_so_symnum = symnum;
213 END_PSYMTAB (pst, psymtab_include_list, includes_used,
214 symnum * symbol_size, valu,
215 dependency_list, dependencies_used);
216 pst = (struct partial_symtab *) 0;
218 dependencies_used = 0;
222 prev_so_symnum = symnum;
224 /* End the current partial symtab and start a new one */
228 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
230 /* Some compilers (including gcc) emit a pair of initial N_SOs.
231 The first one is a directory name; the second the file name.
232 If pst exists, is empty, and has a filename ending in '/',
233 we assume the previous N_SO was a directory name. */
235 p = strrchr (namestring, '/');
236 if (p && *(p+1) == '\000')
237 continue; /* Simply ignore directory name SOs */
239 /* Some other compilers (C++ ones in particular) emit useless
240 SOs for non-existant .c files. We ignore all subsequent SOs that
241 immediately follow the first. */
244 pst = START_PSYMTAB (objfile, section_offsets,
246 first_so_symnum * symbol_size,
247 objfile -> global_psymbols.next,
248 objfile -> static_psymbols.next);
254 /* Add this bincl to the bincl_list for future EXCLs. No
255 need to save the string; it'll be around until
256 read_dbx_symtab function returns */
260 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
262 /* Mark down an include file in the current psymtab */
264 psymtab_include_list[includes_used++] = namestring;
265 if (includes_used >= includes_allocated)
267 char **orig = psymtab_include_list;
269 psymtab_include_list = (char **)
270 alloca ((includes_allocated *= 2) *
272 memcpy ((PTR)psymtab_include_list, (PTR)orig,
273 includes_used * sizeof (char *));
276 #endif /* DBXREAD_ONLY */
280 /* Mark down an include file in the current psymtab */
284 /* In C++, one may expect the same filename to come round many
285 times, when code is coming alternately from the main file
286 and from inline functions in other files. So I check to see
287 if this is a file we've seen before -- either the main
288 source file, or a previously included file.
290 This seems to be a lot of time to be spending on N_SOL, but
291 things like "break c-exp.y:435" need to work (I
292 suppose the psymtab_include_list could be hashed or put
293 in a binary tree, if profiling shows this is a major hog). */
294 if (pst && !strcmp (namestring, pst->filename))
298 for (i = 0; i < includes_used; i++)
299 if (!strcmp (namestring, psymtab_include_list[i]))
308 psymtab_include_list[includes_used++] = namestring;
309 if (includes_used >= includes_allocated)
311 char **orig = psymtab_include_list;
313 psymtab_include_list = (char **)
314 alloca ((includes_allocated *= 2) *
316 memcpy ((PTR)psymtab_include_list, (PTR)orig,
317 includes_used * sizeof (char *));
321 case N_LSYM: /* Typedef or automatic variable. */
322 case N_STSYM: /* Data seg var -- static */
323 case N_LCSYM: /* BSS " */
324 case N_ROSYM: /* Read-only data seg var -- static. */
325 case N_NBSTS: /* Gould nobase. */
326 case N_NBLCS: /* symbols. */
330 p = (char *) strchr (namestring, ':');
332 /* Skip if there is no :. */
338 if (p != namestring) /* a name is there, not just :T... */
340 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
341 STRUCT_NAMESPACE, LOC_TYPEDEF,
342 objfile->static_psymbols, CUR_SYMBOL_VALUE);
345 /* Also a typedef with the same name. */
346 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
347 VAR_NAMESPACE, LOC_TYPEDEF,
348 objfile->static_psymbols, CUR_SYMBOL_VALUE);
354 if (p != namestring) /* a name is there, not just :T... */
356 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
357 VAR_NAMESPACE, LOC_TYPEDEF,
358 objfile->static_psymbols, CUR_SYMBOL_VALUE);
361 /* If this is an enumerated type, we need to
362 add all the enum constants to the partial symbol
363 table. This does not cover enums without names, e.g.
364 "enum {a, b} c;" in C, but fortunately those are
365 rare. There is no way for GDB to find those from the
366 enum type without spending too much time on it. Thus
367 to solve this problem, the compiler needs to put out separate
368 constant symbols ('c' N_LSYMS) for enum constants in
369 enums without names, or put out a dummy type. */
371 /* We are looking for something of the form
372 <name> ":" ("t" | "T") [<number> "="] "e"
373 {<constant> ":" <value> ","} ";". */
375 /* Skip over the colon and the 't' or 'T'. */
377 /* This type may be given a number. Also, numbers can come
378 in pairs like (0,26). Skip over it. */
379 while ((*p >= '0' && *p <= '9')
380 || *p == '(' || *p == ',' || *p == ')'
386 /* We have found an enumerated type. */
387 /* According to comments in read_enum_type
388 a comma could end it instead of a semicolon.
389 I don't know where that happens.
391 while (*p && *p != ';' && *p != ',')
395 /* Check for and handle cretinous dbx symbol name
398 p = next_symbol_text ();
400 /* Point to the character after the name
401 of the enum constant. */
402 for (q = p; *q && *q != ':'; q++)
404 /* Note that the value doesn't matter for
405 enum constants in psymtabs, just in symtabs. */
406 ADD_PSYMBOL_TO_LIST (p, q - p,
407 VAR_NAMESPACE, LOC_CONST,
408 objfile->static_psymbols, 0);
409 /* Point past the name. */
411 /* Skip over the value. */
412 while (*p && *p != ',')
414 /* Advance past the comma. */
421 /* Constant, e.g. from "const" in Pascal. */
422 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
423 VAR_NAMESPACE, LOC_CONST,
424 objfile->static_psymbols, CUR_SYMBOL_VALUE);
427 /* Skip if the thing following the : is
428 not a letter (which indicates declaration of a local
429 variable, which we aren't interested in). */
434 case N_GSYM: /* Global (extern) variable; can be
435 data or bss (sigh FIXME). */
437 /* Following may probably be ignored; I'll leave them here
438 for now (until I do Pascal and Modula 2 extensions). */
440 case N_PC: /* I may or may not need this; I
442 case N_M2C: /* I suspect that I can ignore this here. */
443 case N_SCOPE: /* Same. */
447 p = (char *) strchr (namestring, ':');
449 continue; /* Not a debugging symbol. */
453 /* Main processing section for debugging symbols which
454 the initial read through the symbol tables needs to worry
455 about. If we reach this point, the symbol which we are
456 considering is definitely one we are interested in.
457 p must also contain the (valid) index into the namestring
458 which indicates the debugging type symbol. */
463 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
464 VAR_NAMESPACE, LOC_CONST,
465 objfile->static_psymbols, CUR_SYMBOL_VALUE);
468 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
469 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
470 VAR_NAMESPACE, LOC_STATIC,
471 objfile->static_psymbols, CUR_SYMBOL_VALUE);
474 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
475 /* The addresses in these entries are reported to be
476 wrong. See the code that reads 'G's for symtabs. */
477 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
478 VAR_NAMESPACE, LOC_STATIC,
479 objfile->global_psymbols, CUR_SYMBOL_VALUE);
483 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
484 VAR_NAMESPACE, LOC_TYPEDEF,
485 objfile->static_psymbols, CUR_SYMBOL_VALUE);
490 /* Kludges for ELF/STABS with Sun ACC */
491 last_function_name = namestring;
492 if (pst->textlow == 0)
493 pst->textlow = CUR_SYMBOL_VALUE;
495 if (startup_file_end == 0)
496 startup_file_end = CUR_SYMBOL_VALUE;
499 #endif /* DBXREAD_ONLY */
500 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
501 VAR_NAMESPACE, LOC_BLOCK,
502 objfile->static_psymbols, CUR_SYMBOL_VALUE);
505 /* Global functions were ignored here, but now they
506 are put into the global psymtab like one would expect.
507 They're also in the misc fn vector...
508 FIXME, why did it used to ignore these? That broke
509 "i fun" on these functions. */
512 /* Kludges for ELF/STABS with Sun ACC */
513 last_function_name = namestring;
514 if (pst->textlow == 0)
515 pst->textlow = CUR_SYMBOL_VALUE;
517 if (startup_file_end == 0)
518 startup_file_end = CUR_SYMBOL_VALUE;
521 #endif /* DBXREAD_ONLY */
522 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
523 VAR_NAMESPACE, LOC_BLOCK,
524 objfile->global_psymbols, CUR_SYMBOL_VALUE);
527 /* Two things show up here (hopefully); static symbols of
528 local scope (static used inside braces) or extensions
529 of structure symbols. We can ignore both. */
545 /* Unexpected symbol. Ignore it; perhaps it is an extension
546 that we don't know about.
548 Someone says sun cc puts out symbols like
549 /foo/baz/maclib::/usr/local/bin/maclib,
550 which would get here with a symbol type of ':'. */
559 /* Find the corresponding bincl and mark that psymtab on the
560 psymtab dependency list */
562 struct partial_symtab *needed_pst =
563 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
565 /* If this include file was defined earlier in this file,
567 if (needed_pst == pst) continue;
574 for (i = 0; i < dependencies_used; i++)
575 if (dependency_list[i] == needed_pst)
581 /* If it's already in the list, skip the rest. */
584 dependency_list[dependencies_used++] = needed_pst;
585 if (dependencies_used >= dependencies_allocated)
587 struct partial_symtab **orig = dependency_list;
589 (struct partial_symtab **)
590 alloca ((dependencies_allocated *= 2)
591 * sizeof (struct partial_symtab *));
592 memcpy ((PTR)dependency_list, (PTR)orig,
594 * sizeof (struct partial_symtab *)));
596 fprintf (stderr, "Had to reallocate dependency list.\n");
597 fprintf (stderr, "New dependencies allocated: %d\n",
598 dependencies_allocated);
603 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
606 #endif /* DBXREAD_ONLY */
611 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
617 case N_SSYM: /* Claim: Structure or union element.
618 Hopefully, I can ignore this. */
619 case N_ENTRY: /* Alternate entry point; can ignore. */
620 case N_MAIN: /* Can definitely ignore this. */
621 case N_CATCH: /* These are GNU C++ extensions */
622 case N_EHDECL: /* that can safely be ignored here. */
632 case N_NSYMS: /* Ultrix 4.0: symbol count */
633 case N_DEFD: /* GNU Modula-2 */
635 case N_OBJ: /* useless types from Solaris */
638 /* These symbols aren't interesting; don't worry about them */
643 /* If we haven't found it yet, ignore it. It's probably some
644 new type we don't know about yet. */
645 complain (&unknown_symtype_complaint, local_hex_string(CUR_SYMBOL_TYPE));