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.
27 /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
28 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
29 add_psymbol_to_plist(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
30 #define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
31 add_psymbol_to_plist(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
33 /* Add a symbol with an integer value to a psymtab. */
34 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
35 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, SYMBOL_VALUE)
37 /* Add a symbol with a CORE_ADDR value to a psymtab. */
38 #define ADD_PSYMBOL_ADDR_TO_LIST(NAME,NAMELENGTH, NAMESPACE,CLASS, LIST,VALUE)\
39 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, SYMBOL_VALUE_ADDRESS)
42 /* End of macro definitions, now let's handle them symbols! */
44 switch (CUR_SYMBOL_TYPE)
48 * Standard, external, non-debugger, symbols
53 case N_NBTEXT | N_EXT:
54 case N_NBDATA | N_EXT:
61 CUR_SYMBOL_VALUE += addr; /* Relocate */
66 record_misc_function (namestring, CUR_SYMBOL_VALUE,
67 CUR_SYMBOL_TYPE); /* Always */
71 /* Standard, local, non-debugger, symbols */
75 /* We need to be able to deal with both N_FN or N_TEXT,
76 because we have no way of knowing whether the sys-supplied ld
77 or GNU ld was used to make the executable. Sequents throw
78 in another wrinkle -- they renumbered N_FN. */
83 CUR_SYMBOL_VALUE += addr; /* Relocate */
85 if ((namestring[0] == '-' && namestring[1] == 'l')
86 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
87 && namestring [nsl - 2] == '.'))
89 if (entry_point < CUR_SYMBOL_VALUE
90 && entry_point >= last_o_file_start
91 && addr == 0) /* FIXME nogood nomore */
93 startup_file_start = last_o_file_start;
94 startup_file_end = CUR_SYMBOL_VALUE;
96 if (past_first_source_file && pst
97 /* The gould NP1 uses low values for .o and -l symbols
98 which are not the address. */
99 && CUR_SYMBOL_VALUE > pst->textlow)
101 END_PSYMTAB (pst, psymtab_include_list, includes_used,
102 symnum * symbol_size, CUR_SYMBOL_VALUE,
103 dependency_list, dependencies_used);
104 pst = (struct partial_symtab *) 0;
106 dependencies_used = 0;
109 past_first_source_file = 1;
110 last_o_file_start = CUR_SYMBOL_VALUE;
115 CUR_SYMBOL_VALUE += addr; /* Relocate */
117 /* Check for __DYNAMIC, which is used by Sun shared libraries.
118 Record it even if it's local, not global, so we can find it.
119 Same with virtual function tables, both global and static. */
120 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
121 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
123 /* Not really a function here, but... */
124 record_misc_function (namestring, CUR_SYMBOL_VALUE,
125 CUR_SYMBOL_TYPE); /* Always */
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 continue; /* Just undefined, not COMMON */
147 /* Lots of symbol types we can just ignore. */
156 /* Keep going . . .*/
159 * Special symbol types for GNU
179 unsigned long valu = CUR_SYMBOL_VALUE;
180 /* Symbol number of the first symbol of this file (i.e. the N_SO
181 if there is just one, or the first if we have a pair). */
182 int first_symnum = symnum;
184 /* End the current partial symtab and start a new one */
188 /* Peek at the next symbol. If it is also an N_SO, the
189 first one just indicates the directory. */
191 valu += addr; /* Relocate */
193 if (pst && past_first_source_file)
195 END_PSYMTAB (pst, psymtab_include_list, includes_used,
196 first_symnum * symbol_size, valu,
197 dependency_list, dependencies_used);
198 pst = (struct partial_symtab *) 0;
200 dependencies_used = 0;
203 past_first_source_file = 1;
205 pst = START_PSYMTAB (objfile, addr,
207 first_symnum * symbol_size,
208 global_psymbols.next, static_psymbols.next);
214 /* Add this bincl to the bincl_list for future EXCLs. No
215 need to save the string; it'll be around until
216 read_dbx_symtab function returns */
220 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
222 /* Mark down an include file in the current psymtab */
224 psymtab_include_list[includes_used++] = namestring;
225 if (includes_used >= includes_allocated)
227 char **orig = psymtab_include_list;
229 psymtab_include_list = (char **)
230 alloca ((includes_allocated *= 2) *
232 bcopy (orig, psymtab_include_list,
233 includes_used * sizeof (char *));
240 /* Mark down an include file in the current psymtab */
244 /* In C++, one may expect the same filename to come round many
245 times, when code is coming alternately from the main file
246 and from inline functions in other files. So I check to see
247 if this is a file we've seen before -- either the main
248 source file, or a previously included file.
250 This seems to be a lot of time to be spending on N_SOL, but
251 things like "break c-exp.y:435" need to work (I
252 suppose the psymtab_include_list could be hashed or put
253 in a binary tree, if profiling shows this is a major hog). */
254 if (pst && !strcmp (namestring, pst->filename))
258 for (i = 0; i < includes_used; i++)
259 if (!strcmp (namestring, psymtab_include_list[i]))
268 psymtab_include_list[includes_used++] = namestring;
269 if (includes_used >= includes_allocated)
271 char **orig = psymtab_include_list;
273 psymtab_include_list = (char **)
274 alloca ((includes_allocated *= 2) *
276 bcopy (orig, psymtab_include_list,
277 includes_used * sizeof (char *));
280 case N_LSYM: /* Typedef or automatic variable. */
281 case N_STSYM: /* Data seg var -- static */
282 case N_LCSYM: /* BSS " */
283 case N_NBSTS: /* Gould nobase. */
284 case N_NBLCS: /* symbols. */
288 p = (char *) strchr (namestring, ':');
290 /* Skip if there is no :. */
296 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
297 STRUCT_NAMESPACE, LOC_TYPEDEF,
298 static_psymbols, CUR_SYMBOL_VALUE);
301 /* Also a typedef with the same name. */
302 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
303 VAR_NAMESPACE, LOC_TYPEDEF,
304 static_psymbols, CUR_SYMBOL_VALUE);
309 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
310 VAR_NAMESPACE, LOC_TYPEDEF,
311 static_psymbols, CUR_SYMBOL_VALUE);
314 /* If this is an enumerated type, we need to
315 add all the enum constants to the partial symbol
316 table. This does not cover enums without names, e.g.
317 "enum {a, b} c;" in C, but fortunately those are
318 rare. There is no way for GDB to find those from the
319 enum type without spending too much time on it. Thus
320 to solve this problem, the compiler needs to put out separate
321 constant symbols ('c' N_LSYMS) for enum constants in
322 enums without names, or put out a dummy type. */
324 /* We are looking for something of the form
325 <name> ":" ("t" | "T") [<number> "="] "e"
326 {<constant> ":" <value> ","} ";". */
328 /* Skip over the colon and the 't' or 'T'. */
330 /* This type may be given a number. Also, numbers can come
331 in pairs like (0,26). Skip over it. */
332 while ((*p >= '0' && *p <= '9')
333 || *p == '(' || *p == ',' || *p == ')'
339 /* We have found an enumerated type. */
340 /* According to comments in read_enum_type
341 a comma could end it instead of a semicolon.
342 I don't know where that happens.
344 while (*p && *p != ';' && *p != ',')
348 /* Check for and handle cretinous dbx symbol name
351 p = next_symbol_text ();
353 /* Point to the character after the name
354 of the enum constant. */
355 for (q = p; *q && *q != ':'; q++)
357 /* Note that the value doesn't matter for
358 enum constants in psymtabs, just in symtabs. */
359 ADD_PSYMBOL_TO_LIST (p, q - p,
360 VAR_NAMESPACE, LOC_CONST,
362 /* Point past the name. */
364 /* Skip over the value. */
365 while (*p && *p != ',')
367 /* Advance past the comma. */
375 /* Constant, e.g. from "const" in Pascal. */
376 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
377 VAR_NAMESPACE, LOC_CONST,
378 static_psymbols, CUR_SYMBOL_VALUE);
381 /* Skip if the thing following the : is
382 not a letter (which indicates declaration of a local
383 variable, which we aren't interested in). */
388 case N_GSYM: /* Global (extern) variable; can be
389 data or bss (sigh). */
391 /* Following may probably be ignored; I'll leave them here
392 for now (until I do Pascal and Modula 2 extensions). */
394 case N_PC: /* I may or may not need this; I
396 case N_M2C: /* I suspect that I can ignore this here. */
397 case N_SCOPE: /* Same. */
401 p = (char *) strchr (namestring, ':');
403 continue; /* Not a debugging symbol. */
407 /* Main processing section for debugging symbols which
408 the initial read through the symbol tables needs to worry
409 about. If we reach this point, the symbol which we are
410 considering is definitely one we are interested in.
411 p must also contain the (valid) index into the namestring
412 which indicates the debugging type symbol. */
417 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
418 VAR_NAMESPACE, LOC_CONST,
419 static_psymbols, CUR_SYMBOL_VALUE);
422 CUR_SYMBOL_VALUE += addr; /* Relocate */
423 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
424 VAR_NAMESPACE, LOC_STATIC,
425 static_psymbols, CUR_SYMBOL_VALUE);
428 CUR_SYMBOL_VALUE += addr; /* Relocate */
429 /* The addresses in these entries are reported to be
430 wrong. See the code that reads 'G's for symtabs. */
431 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
432 VAR_NAMESPACE, LOC_STATIC,
433 global_psymbols, CUR_SYMBOL_VALUE);
437 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
438 VAR_NAMESPACE, LOC_TYPEDEF,
439 static_psymbols, CUR_SYMBOL_VALUE);
443 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
444 VAR_NAMESPACE, LOC_BLOCK,
445 static_psymbols, CUR_SYMBOL_VALUE);
448 /* Global functions were ignored here, but now they
449 are put into the global psymtab like one would expect.
450 They're also in the misc fn vector...
451 FIXME, why did it used to ignore these? That broke
452 "i fun" on these functions. */
454 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
455 VAR_NAMESPACE, LOC_BLOCK,
456 global_psymbols, CUR_SYMBOL_VALUE);
459 /* Two things show up here (hopefully); static symbols of
460 local scope (static used inside braces) or extensions
461 of structure symbols. We can ignore both. */
477 /* Unexpected symbol. Ignore it; perhaps it is an extension
478 that we don't know about.
480 Someone says sun cc puts out symbols like
481 /foo/baz/maclib::/usr/local/bin/maclib,
482 which would get here with a symbol type of ':'. */
491 /* Find the corresponding bincl and mark that psymtab on the
492 psymtab dependency list */
494 struct partial_symtab *needed_pst =
495 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
497 /* If this include file was defined earlier in this file,
499 if (needed_pst == pst) continue;
506 for (i = 0; i < dependencies_used; i++)
507 if (dependency_list[i] == needed_pst)
513 /* If it's already in the list, skip the rest. */
516 dependency_list[dependencies_used++] = needed_pst;
517 if (dependencies_used >= dependencies_allocated)
519 struct partial_symtab **orig = dependency_list;
521 (struct partial_symtab **)
522 alloca ((dependencies_allocated *= 2)
523 * sizeof (struct partial_symtab *));
524 bcopy (orig, dependency_list,
526 * sizeof (struct partial_symtab *)));
528 fprintf (stderr, "Had to reallocate dependency list.\n");
529 fprintf (stderr, "New dependencies allocated: %d\n",
530 dependencies_allocated);
535 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
543 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
548 case N_SSYM: /* Claim: Structure or union element.
549 Hopefully, I can ignore this. */
550 case N_ENTRY: /* Alternate entry point; can ignore. */
551 case N_MAIN: /* Can definitely ignore this. */
552 case N_CATCH: /* These are GNU C++ extensions */
553 case N_EHDECL: /* that can safely be ignored here. */
563 case N_NSYMS: /* Ultrix 4.0: symbol count */
564 case N_DEFD: /* GNU Modula-2 */
565 /* These symbols aren't interesting; don't worry about them */
571 /* If we haven't found it yet, ignore it. It's probably some
572 new type we don't know about yet. */
573 complain (&unknown_symtype_complaint, local_hex_string(CUR_SYMBOL_TYPE));