1 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* The following need to be defined:
21 SET_NAMESTRING() --Set namestring to name of symbol.
22 CUR_SYMBOL_TYPE --Type code of current symbol.
23 CUR_SYMBOL_VALUE --Value field of current symbol. May be adjusted here.
26 /* End of macro definitions, now let's handle them symbols! */
28 switch (CUR_SYMBOL_TYPE)
32 * Standard, external, non-debugger, symbols
36 case N_NBTEXT | N_EXT:
37 case N_NBDATA | N_EXT:
45 CUR_SYMBOL_VALUE += addr; /* Relocate */
50 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
51 CUR_SYMBOL_TYPE, objfile); /* Always */
52 #endif /* DBXREAD_ONLY */
55 /* Standard, local, non-debugger, symbols */
59 /* We need to be able to deal with both N_FN or N_TEXT,
60 because we have no way of knowing whether the sys-supplied ld
61 or GNU ld was used to make the executable. Sequents throw
62 in another wrinkle -- they renumbered N_FN. */
68 CUR_SYMBOL_VALUE += addr; /* Relocate */
70 if ((namestring[0] == '-' && namestring[1] == 'l')
71 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
72 && namestring [nsl - 2] == '.'))
74 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
75 objfile -> ei.entry_point >= last_o_file_start &&
76 addr == 0) /* FIXME nogood nomore */
78 objfile -> ei.entry_file_lowpc = last_o_file_start;
79 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
81 if (past_first_source_file && pst
82 /* The gould NP1 uses low values for .o and -l symbols
83 which are not the address. */
84 && CUR_SYMBOL_VALUE > pst->textlow)
86 END_PSYMTAB (pst, psymtab_include_list, includes_used,
87 symnum * symbol_size, CUR_SYMBOL_VALUE,
88 dependency_list, dependencies_used);
89 pst = (struct partial_symtab *) 0;
91 dependencies_used = 0;
94 past_first_source_file = 1;
95 last_o_file_start = CUR_SYMBOL_VALUE;
97 #endif /* DBXREAD_ONLY */
102 CUR_SYMBOL_VALUE += addr; /* Relocate */
104 /* Check for __DYNAMIC, which is used by Sun shared libraries.
105 Record it even if it's local, not global, so we can find it.
106 Same with virtual function tables, both global and static. */
107 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
108 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
110 /* Not really a function here, but... */
111 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
112 CUR_SYMBOL_TYPE, objfile); /* Always */
114 #endif /* DBXREAD_ONLY */
119 if (CUR_SYMBOL_VALUE != 0) {
120 /* This is a "Fortran COMMON" symbol. See if the target
121 environment knows where it has been relocated to. */
126 if (target_lookup_symbol (namestring, &reladdr)) {
127 continue; /* Error in lookup; ignore symbol for now. */
129 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
130 CUR_SYMBOL_VALUE = reladdr;
133 #endif /* DBXREAD_ONLY */
134 continue; /* Just undefined, not COMMON */
136 /* Lots of symbol types we can just ignore. */
145 /* Keep going . . .*/
148 * Special symbol types for GNU
168 unsigned long valu = CUR_SYMBOL_VALUE;
169 /* Symbol number of the first symbol of this file (i.e. the N_SO
170 if there is just one, or the first if we have a pair). */
171 int first_symnum = symnum;
173 /* End the current partial symtab and start a new one */
177 valu += addr; /* Relocate */
179 if (pst && past_first_source_file)
181 /* Some compilers (including gcc) emit a pair of initial N_SOs.
182 The first one is a directory name; the second the file name.
183 If pst exists, is empty, and has a filename ending in '/',
184 we assume the previous N_SO was a directory name. */
185 if (pst -> objfile -> global_psymbols.next
186 == (pst -> objfile -> global_psymbols.list + pst->globals_offset)
187 && pst -> objfile -> static_psymbols.next
188 == (pst -> objfile -> static_psymbols.list + pst->statics_offset)
189 && pst->filename && pst->filename[0]
190 && pst->filename[strlen(pst->filename)-1] == '/') {
191 /* Just replace the directory name with the real filename. */
193 (char *) obstack_alloc (&pst->objfile->psymbol_obstack,
194 strlen (namestring) + 1);
195 strcpy (pst->filename, namestring);
198 END_PSYMTAB (pst, psymtab_include_list, includes_used,
199 first_symnum * symbol_size, valu,
200 dependency_list, dependencies_used);
201 pst = (struct partial_symtab *) 0;
203 dependencies_used = 0;
206 past_first_source_file = 1;
208 pst = START_PSYMTAB (objfile, addr,
210 first_symnum * symbol_size,
211 objfile -> global_psymbols.next,
212 objfile -> static_psymbols.next);
218 /* Add this bincl to the bincl_list for future EXCLs. No
219 need to save the string; it'll be around until
220 read_dbx_symtab function returns */
224 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
226 /* Mark down an include file in the current psymtab */
228 psymtab_include_list[includes_used++] = namestring;
229 if (includes_used >= includes_allocated)
231 char **orig = psymtab_include_list;
233 psymtab_include_list = (char **)
234 alloca ((includes_allocated *= 2) *
236 bcopy (orig, psymtab_include_list,
237 includes_used * sizeof (char *));
240 #endif /* DBXREAD_ONLY */
244 /* Mark down an include file in the current psymtab */
248 /* In C++, one may expect the same filename to come round many
249 times, when code is coming alternately from the main file
250 and from inline functions in other files. So I check to see
251 if this is a file we've seen before -- either the main
252 source file, or a previously included file.
254 This seems to be a lot of time to be spending on N_SOL, but
255 things like "break c-exp.y:435" need to work (I
256 suppose the psymtab_include_list could be hashed or put
257 in a binary tree, if profiling shows this is a major hog). */
258 if (pst && !strcmp (namestring, pst->filename))
262 for (i = 0; i < includes_used; i++)
263 if (!strcmp (namestring, psymtab_include_list[i]))
272 psymtab_include_list[includes_used++] = namestring;
273 if (includes_used >= includes_allocated)
275 char **orig = psymtab_include_list;
277 psymtab_include_list = (char **)
278 alloca ((includes_allocated *= 2) *
280 bcopy (orig, psymtab_include_list,
281 includes_used * sizeof (char *));
285 case N_LSYM: /* Typedef or automatic variable. */
286 case N_STSYM: /* Data seg var -- static */
287 case N_LCSYM: /* BSS " */
288 case N_NBSTS: /* Gould nobase. */
289 case N_NBLCS: /* symbols. */
293 p = (char *) strchr (namestring, ':');
295 /* Skip if there is no :. */
301 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
302 STRUCT_NAMESPACE, LOC_TYPEDEF,
303 objfile->static_psymbols, CUR_SYMBOL_VALUE);
306 /* Also a typedef with the same name. */
307 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
308 VAR_NAMESPACE, LOC_TYPEDEF,
309 objfile->static_psymbols, CUR_SYMBOL_VALUE);
314 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
315 VAR_NAMESPACE, LOC_TYPEDEF,
316 objfile->static_psymbols, CUR_SYMBOL_VALUE);
318 /* If this is an enumerated type, we need to
319 add all the enum constants to the partial symbol
320 table. This does not cover enums without names, e.g.
321 "enum {a, b} c;" in C, but fortunately those are
322 rare. There is no way for GDB to find those from the
323 enum type without spending too much time on it. Thus
324 to solve this problem, the compiler needs to put out separate
325 constant symbols ('c' N_LSYMS) for enum constants in
326 enums without names, or put out a dummy type. */
328 /* We are looking for something of the form
329 <name> ":" ("t" | "T") [<number> "="] "e"
330 {<constant> ":" <value> ","} ";". */
332 /* Skip over the colon and the 't' or 'T'. */
334 /* This type may be given a number. Also, numbers can come
335 in pairs like (0,26). Skip over it. */
336 while ((*p >= '0' && *p <= '9')
337 || *p == '(' || *p == ',' || *p == ')'
343 /* We have found an enumerated type. */
344 /* According to comments in read_enum_type
345 a comma could end it instead of a semicolon.
346 I don't know where that happens.
348 while (*p && *p != ';' && *p != ',')
352 /* Check for and handle cretinous dbx symbol name
355 p = next_symbol_text ();
357 /* Point to the character after the name
358 of the enum constant. */
359 for (q = p; *q && *q != ':'; q++)
361 /* Note that the value doesn't matter for
362 enum constants in psymtabs, just in symtabs. */
363 ADD_PSYMBOL_TO_LIST (p, q - p,
364 VAR_NAMESPACE, LOC_CONST,
365 objfile->static_psymbols, 0);
366 /* Point past the name. */
368 /* Skip over the value. */
369 while (*p && *p != ',')
371 /* Advance past the comma. */
378 /* Constant, e.g. from "const" in Pascal. */
379 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
380 VAR_NAMESPACE, LOC_CONST,
381 objfile->static_psymbols, CUR_SYMBOL_VALUE);
384 /* Skip if the thing following the : is
385 not a letter (which indicates declaration of a local
386 variable, which we aren't interested in). */
391 case N_GSYM: /* Global (extern) variable; can be
392 data or bss (sigh). */
394 /* Following may probably be ignored; I'll leave them here
395 for now (until I do Pascal and Modula 2 extensions). */
397 case N_PC: /* I may or may not need this; I
399 case N_M2C: /* I suspect that I can ignore this here. */
400 case N_SCOPE: /* Same. */
404 p = (char *) strchr (namestring, ':');
406 continue; /* Not a debugging symbol. */
410 /* Main processing section for debugging symbols which
411 the initial read through the symbol tables needs to worry
412 about. If we reach this point, the symbol which we are
413 considering is definitely one we are interested in.
414 p must also contain the (valid) index into the namestring
415 which indicates the debugging type symbol. */
420 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
421 VAR_NAMESPACE, LOC_CONST,
422 objfile->static_psymbols, CUR_SYMBOL_VALUE);
425 CUR_SYMBOL_VALUE += addr; /* Relocate */
426 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
427 VAR_NAMESPACE, LOC_STATIC,
428 objfile->static_psymbols, CUR_SYMBOL_VALUE);
431 CUR_SYMBOL_VALUE += addr; /* Relocate */
432 /* The addresses in these entries are reported to be
433 wrong. See the code that reads 'G's for symtabs. */
434 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
435 VAR_NAMESPACE, LOC_STATIC,
436 objfile->global_psymbols, CUR_SYMBOL_VALUE);
440 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
441 VAR_NAMESPACE, LOC_TYPEDEF,
442 objfile->static_psymbols, CUR_SYMBOL_VALUE);
446 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
447 VAR_NAMESPACE, LOC_BLOCK,
448 objfile->static_psymbols, CUR_SYMBOL_VALUE);
451 /* Global functions were ignored here, but now they
452 are put into the global psymtab like one would expect.
453 They're also in the misc fn vector...
454 FIXME, why did it used to ignore these? That broke
455 "i fun" on these functions. */
457 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
458 VAR_NAMESPACE, LOC_BLOCK,
459 objfile->global_psymbols, CUR_SYMBOL_VALUE);
462 /* Two things show up here (hopefully); static symbols of
463 local scope (static used inside braces) or extensions
464 of structure symbols. We can ignore both. */
480 /* Unexpected symbol. Ignore it; perhaps it is an extension
481 that we don't know about.
483 Someone says sun cc puts out symbols like
484 /foo/baz/maclib::/usr/local/bin/maclib,
485 which would get here with a symbol type of ':'. */
494 /* Find the corresponding bincl and mark that psymtab on the
495 psymtab dependency list */
497 struct partial_symtab *needed_pst =
498 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
500 /* If this include file was defined earlier in this file,
502 if (needed_pst == pst) continue;
509 for (i = 0; i < dependencies_used; i++)
510 if (dependency_list[i] == needed_pst)
516 /* If it's already in the list, skip the rest. */
519 dependency_list[dependencies_used++] = needed_pst;
520 if (dependencies_used >= dependencies_allocated)
522 struct partial_symtab **orig = dependency_list;
524 (struct partial_symtab **)
525 alloca ((dependencies_allocated *= 2)
526 * sizeof (struct partial_symtab *));
527 bcopy (orig, dependency_list,
529 * sizeof (struct partial_symtab *)));
531 fprintf (stderr, "Had to reallocate dependency list.\n");
532 fprintf (stderr, "New dependencies allocated: %d\n",
533 dependencies_allocated);
538 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
541 #endif /* DBXREAD_ONLY */
546 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
552 case N_SSYM: /* Claim: Structure or union element.
553 Hopefully, I can ignore this. */
554 case N_ENTRY: /* Alternate entry point; can ignore. */
555 case N_MAIN: /* Can definitely ignore this. */
556 case N_CATCH: /* These are GNU C++ extensions */
557 case N_EHDECL: /* that can safely be ignored here. */
567 case N_NSYMS: /* Ultrix 4.0: symbol count */
568 case N_DEFD: /* GNU Modula-2 */
569 /* These symbols aren't interesting; don't worry about them */
574 /* If we haven't found it yet, ignore it. It's probably some
575 new type we don't know about yet. */
576 complain (&unknown_symtype_complaint, local_hex_string(CUR_SYMBOL_TYPE));