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 case N_NBDATA | N_EXT:
46 CUR_SYMBOL_VALUE += addr; /* Relocate */
51 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
52 CUR_SYMBOL_TYPE, objfile); /* Always */
53 #endif /* DBXREAD_ONLY */
56 /* Standard, local, non-debugger, symbols */
60 /* We need to be able to deal with both N_FN or N_TEXT,
61 because we have no way of knowing whether the sys-supplied ld
62 or GNU ld was used to make the executable. Sequents throw
63 in another wrinkle -- they renumbered N_FN. */
69 CUR_SYMBOL_VALUE += addr; /* Relocate */
71 if ((namestring[0] == '-' && namestring[1] == 'l')
72 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
73 && namestring [nsl - 2] == '.'))
75 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
76 objfile -> ei.entry_point >= last_o_file_start &&
77 addr == 0) /* FIXME nogood nomore */
79 objfile -> ei.entry_file_lowpc = last_o_file_start;
80 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
82 if (past_first_source_file && pst
83 /* The gould NP1 uses low values for .o and -l symbols
84 which are not the address. */
85 && CUR_SYMBOL_VALUE > pst->textlow)
87 END_PSYMTAB (pst, psymtab_include_list, includes_used,
88 symnum * symbol_size, CUR_SYMBOL_VALUE,
89 dependency_list, dependencies_used);
90 pst = (struct partial_symtab *) 0;
92 dependencies_used = 0;
95 past_first_source_file = 1;
96 last_o_file_start = CUR_SYMBOL_VALUE;
98 #endif /* DBXREAD_ONLY */
103 CUR_SYMBOL_VALUE += addr; /* Relocate */
105 /* Check for __DYNAMIC, which is used by Sun shared libraries.
106 Record it even if it's local, not global, so we can find it.
107 Same with virtual function tables, both global and static. */
108 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
109 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
111 /* Not really a function here, but... */
112 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
113 CUR_SYMBOL_TYPE, objfile); /* Always */
115 #endif /* DBXREAD_ONLY */
120 if (CUR_SYMBOL_VALUE != 0) {
121 /* This is a "Fortran COMMON" symbol. See if the target
122 environment knows where it has been relocated to. */
127 if (target_lookup_symbol (namestring, &reladdr)) {
128 continue; /* Error in lookup; ignore symbol for now. */
130 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
131 CUR_SYMBOL_VALUE = reladdr;
134 #endif /* DBXREAD_ONLY */
135 continue; /* Just undefined, not COMMON */
139 if (processing_acc_compilation && bufp->n_strx == 1) {
140 /* Deal with relative offsets in the string table
141 used in ELF+STAB under Solaris. If we want to use the
142 n_strx field, which contains the name of the file,
143 we must adjust file_string_table_offset *before* calling
145 past_first_source_file = 1;
146 file_string_table_offset = next_file_string_table_offset;
147 next_file_string_table_offset =
148 file_string_table_offset + bufp->n_value;
149 if (next_file_string_table_offset < file_string_table_offset)
150 error ("string table offset backs up at %d", symnum);
151 /* FIXME -- replace error() with complaint. */
154 #endif /* DBXREAD_ONLY */
157 /* Lots of symbol types we can just ignore. */
165 /* Keep going . . .*/
168 * Special symbol types for GNU
188 unsigned long valu = CUR_SYMBOL_VALUE;
189 /* Symbol number of the first symbol of this file (i.e. the N_SO
190 if there is just one, or the first if we have a pair). */
191 int first_symnum = symnum;
193 /* End the current partial symtab and start a new one */
197 valu += addr; /* Relocate */
199 if (pst && past_first_source_file)
201 /* Some compilers (including gcc) emit a pair of initial N_SOs.
202 The first one is a directory name; the second the file name.
203 If pst exists, is empty, and has a filename ending in '/',
204 we assume the previous N_SO was a directory name. */
205 if (pst -> objfile -> global_psymbols.next
206 == (pst -> objfile -> global_psymbols.list + pst->globals_offset)
207 && pst -> objfile -> static_psymbols.next
208 == (pst -> objfile -> static_psymbols.list + pst->statics_offset)
209 && pst->filename && pst->filename[0]
210 && pst->filename[strlen(pst->filename)-1] == '/') {
211 /* Just replace the directory name with the real filename. */
213 (char *) obstack_alloc (&pst->objfile->psymbol_obstack,
214 strlen (namestring) + 1);
215 strcpy (pst->filename, namestring);
218 END_PSYMTAB (pst, psymtab_include_list, includes_used,
219 first_symnum * symbol_size, valu,
220 dependency_list, dependencies_used);
221 pst = (struct partial_symtab *) 0;
223 dependencies_used = 0;
226 past_first_source_file = 1;
228 pst = START_PSYMTAB (objfile, addr,
230 first_symnum * symbol_size,
231 objfile -> global_psymbols.next,
232 objfile -> static_psymbols.next);
238 /* Add this bincl to the bincl_list for future EXCLs. No
239 need to save the string; it'll be around until
240 read_dbx_symtab function returns */
244 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
246 /* Mark down an include file in the current psymtab */
248 psymtab_include_list[includes_used++] = namestring;
249 if (includes_used >= includes_allocated)
251 char **orig = psymtab_include_list;
253 psymtab_include_list = (char **)
254 alloca ((includes_allocated *= 2) *
256 memcpy ((PTR)psymtab_include_list, (PTR)orig,
257 includes_used * sizeof (char *));
260 #endif /* DBXREAD_ONLY */
264 /* Mark down an include file in the current psymtab */
268 /* In C++, one may expect the same filename to come round many
269 times, when code is coming alternately from the main file
270 and from inline functions in other files. So I check to see
271 if this is a file we've seen before -- either the main
272 source file, or a previously included file.
274 This seems to be a lot of time to be spending on N_SOL, but
275 things like "break c-exp.y:435" need to work (I
276 suppose the psymtab_include_list could be hashed or put
277 in a binary tree, if profiling shows this is a major hog). */
278 if (pst && !strcmp (namestring, pst->filename))
282 for (i = 0; i < includes_used; i++)
283 if (!strcmp (namestring, psymtab_include_list[i]))
292 psymtab_include_list[includes_used++] = namestring;
293 if (includes_used >= includes_allocated)
295 char **orig = psymtab_include_list;
297 psymtab_include_list = (char **)
298 alloca ((includes_allocated *= 2) *
300 memcpy ((PTR)psymtab_include_list, (PTR)orig,
301 includes_used * sizeof (char *));
305 case N_LSYM: /* Typedef or automatic variable. */
306 case N_STSYM: /* Data seg var -- static */
307 case N_LCSYM: /* BSS " */
308 case N_NBSTS: /* Gould nobase. */
309 case N_NBLCS: /* symbols. */
313 p = (char *) strchr (namestring, ':');
315 /* Skip if there is no :. */
321 if (p != namestring) /* a name is there, not just :T... */
323 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
324 STRUCT_NAMESPACE, LOC_TYPEDEF,
325 objfile->static_psymbols, CUR_SYMBOL_VALUE);
328 /* Also a typedef with the same name. */
329 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
330 VAR_NAMESPACE, LOC_TYPEDEF,
331 objfile->static_psymbols, CUR_SYMBOL_VALUE);
337 if (p != namestring) /* a name is there, not just :T... */
339 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
340 VAR_NAMESPACE, LOC_TYPEDEF,
341 objfile->static_psymbols, CUR_SYMBOL_VALUE);
344 /* If this is an enumerated type, we need to
345 add all the enum constants to the partial symbol
346 table. This does not cover enums without names, e.g.
347 "enum {a, b} c;" in C, but fortunately those are
348 rare. There is no way for GDB to find those from the
349 enum type without spending too much time on it. Thus
350 to solve this problem, the compiler needs to put out separate
351 constant symbols ('c' N_LSYMS) for enum constants in
352 enums without names, or put out a dummy type. */
354 /* We are looking for something of the form
355 <name> ":" ("t" | "T") [<number> "="] "e"
356 {<constant> ":" <value> ","} ";". */
358 /* Skip over the colon and the 't' or 'T'. */
360 /* This type may be given a number. Also, numbers can come
361 in pairs like (0,26). Skip over it. */
362 while ((*p >= '0' && *p <= '9')
363 || *p == '(' || *p == ',' || *p == ')'
369 /* We have found an enumerated type. */
370 /* According to comments in read_enum_type
371 a comma could end it instead of a semicolon.
372 I don't know where that happens.
374 while (*p && *p != ';' && *p != ',')
378 /* Check for and handle cretinous dbx symbol name
381 p = next_symbol_text ();
383 /* Point to the character after the name
384 of the enum constant. */
385 for (q = p; *q && *q != ':'; q++)
387 /* Note that the value doesn't matter for
388 enum constants in psymtabs, just in symtabs. */
389 ADD_PSYMBOL_TO_LIST (p, q - p,
390 VAR_NAMESPACE, LOC_CONST,
391 objfile->static_psymbols, 0);
392 /* Point past the name. */
394 /* Skip over the value. */
395 while (*p && *p != ',')
397 /* Advance past the comma. */
404 /* Constant, e.g. from "const" in Pascal. */
405 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
406 VAR_NAMESPACE, LOC_CONST,
407 objfile->static_psymbols, CUR_SYMBOL_VALUE);
410 /* Skip if the thing following the : is
411 not a letter (which indicates declaration of a local
412 variable, which we aren't interested in). */
417 case N_GSYM: /* Global (extern) variable; can be
418 data or bss (sigh). */
420 /* Following may probably be ignored; I'll leave them here
421 for now (until I do Pascal and Modula 2 extensions). */
423 case N_PC: /* I may or may not need this; I
425 case N_M2C: /* I suspect that I can ignore this here. */
426 case N_SCOPE: /* Same. */
430 p = (char *) strchr (namestring, ':');
432 continue; /* Not a debugging symbol. */
436 /* Main processing section for debugging symbols which
437 the initial read through the symbol tables needs to worry
438 about. If we reach this point, the symbol which we are
439 considering is definitely one we are interested in.
440 p must also contain the (valid) index into the namestring
441 which indicates the debugging type symbol. */
446 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
447 VAR_NAMESPACE, LOC_CONST,
448 objfile->static_psymbols, CUR_SYMBOL_VALUE);
451 CUR_SYMBOL_VALUE += addr; /* Relocate */
452 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
453 VAR_NAMESPACE, LOC_STATIC,
454 objfile->static_psymbols, CUR_SYMBOL_VALUE);
457 CUR_SYMBOL_VALUE += addr; /* Relocate */
458 /* The addresses in these entries are reported to be
459 wrong. See the code that reads 'G's for symtabs. */
460 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
461 VAR_NAMESPACE, LOC_STATIC,
462 objfile->global_psymbols, CUR_SYMBOL_VALUE);
466 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
467 VAR_NAMESPACE, LOC_TYPEDEF,
468 objfile->static_psymbols, CUR_SYMBOL_VALUE);
473 /* Kludges for ELF/STABS with Sun ACC */
474 last_function_name = namestring;
475 if (pst->textlow == 0)
476 pst->textlow = CUR_SYMBOL_VALUE;
478 if (startup_file_end == 0)
479 startup_file_end = CUR_SYMBOL_VALUE;
482 #endif /* DBXREAD_ONLY */
483 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
484 VAR_NAMESPACE, LOC_BLOCK,
485 objfile->static_psymbols, CUR_SYMBOL_VALUE);
488 /* Global functions were ignored here, but now they
489 are put into the global psymtab like one would expect.
490 They're also in the misc fn vector...
491 FIXME, why did it used to ignore these? That broke
492 "i fun" on these functions. */
495 /* Kludges for ELF/STABS with Sun ACC */
496 last_function_name = namestring;
497 if (pst->textlow == 0)
498 pst->textlow = CUR_SYMBOL_VALUE;
500 if (startup_file_end == 0)
501 startup_file_end = CUR_SYMBOL_VALUE;
504 #endif /* DBXREAD_ONLY */
505 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
506 VAR_NAMESPACE, LOC_BLOCK,
507 objfile->global_psymbols, CUR_SYMBOL_VALUE);
510 /* Two things show up here (hopefully); static symbols of
511 local scope (static used inside braces) or extensions
512 of structure symbols. We can ignore both. */
528 /* Unexpected symbol. Ignore it; perhaps it is an extension
529 that we don't know about.
531 Someone says sun cc puts out symbols like
532 /foo/baz/maclib::/usr/local/bin/maclib,
533 which would get here with a symbol type of ':'. */
542 /* Find the corresponding bincl and mark that psymtab on the
543 psymtab dependency list */
545 struct partial_symtab *needed_pst =
546 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
548 /* If this include file was defined earlier in this file,
550 if (needed_pst == pst) continue;
557 for (i = 0; i < dependencies_used; i++)
558 if (dependency_list[i] == needed_pst)
564 /* If it's already in the list, skip the rest. */
567 dependency_list[dependencies_used++] = needed_pst;
568 if (dependencies_used >= dependencies_allocated)
570 struct partial_symtab **orig = dependency_list;
572 (struct partial_symtab **)
573 alloca ((dependencies_allocated *= 2)
574 * sizeof (struct partial_symtab *));
575 memcpy ((PTR)dependency_list, (PTR)orig,
577 * sizeof (struct partial_symtab *)));
579 fprintf (stderr, "Had to reallocate dependency list.\n");
580 fprintf (stderr, "New dependencies allocated: %d\n",
581 dependencies_allocated);
586 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
589 #endif /* DBXREAD_ONLY */
594 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
600 case N_SSYM: /* Claim: Structure or union element.
601 Hopefully, I can ignore this. */
602 case N_ENTRY: /* Alternate entry point; can ignore. */
603 case N_MAIN: /* Can definitely ignore this. */
604 case N_CATCH: /* These are GNU C++ extensions */
605 case N_EHDECL: /* that can safely be ignored here. */
615 case N_NSYMS: /* Ultrix 4.0: symbol count */
616 case N_DEFD: /* GNU Modula-2 */
618 case N_OBJ: /* two useless types from Solaris */
620 /* These symbols aren't interesting; don't worry about them */
625 /* If we haven't found it yet, ignore it. It's probably some
626 new type we don't know about yet. */
627 complain (&unknown_symtype_complaint, local_hex_string(CUR_SYMBOL_TYPE));