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 last_so_symnum
= -10;
202 static int dir_so_symnum
= -10;
206 /* End the current partial symtab and start a new one */
210 valu
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
214 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
215 symnum
* symbol_size
, valu
,
216 dependency_list
, dependencies_used
);
217 pst
= (struct partial_symtab
*) 0;
219 dependencies_used
= 0;
222 /* Some compilers (including gcc) emit a pair of initial N_SOs.
223 The first one is a directory name; the second the file name.
224 If pst exists, is empty, and has a filename ending in '/',
225 we assume the previous N_SO was a directory name. */
227 p
= strrchr (namestring
, '/');
228 if (p
&& *(p
+1) == '\000')
230 dir_so_symnum
= symnum
;
231 continue; /* Simply ignore directory name SOs */
234 /* Some other compilers (C++ ones in particular) emit useless
235 SOs for non-existant .c files. */
237 if (last_so_symnum
== symnum
- 1)
238 continue; /* Ignore repeated SOs */
239 last_so_symnum
= symnum
;
241 past_first_source_file
= 1;
243 if (dir_so_symnum
== symnum
- 1) /* Was prev. SO a directory? */
247 pst
= START_PSYMTAB (objfile
, section_offsets
,
250 objfile
-> global_psymbols
.next
,
251 objfile
-> static_psymbols
.next
);
258 /* Add this bincl to the bincl_list for future EXCLs. No
259 need to save the string; it'll be around until
260 read_dbx_symtab function returns */
264 add_bincl_to_list (pst
, namestring
, CUR_SYMBOL_VALUE
);
266 /* Mark down an include file in the current psymtab */
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 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
277 includes_used
* sizeof (char *));
280 #endif /* DBXREAD_ONLY */
284 /* Mark down an include file in the current psymtab */
288 /* In C++, one may expect the same filename to come round many
289 times, when code is coming alternately from the main file
290 and from inline functions in other files. So I check to see
291 if this is a file we've seen before -- either the main
292 source file, or a previously included file.
294 This seems to be a lot of time to be spending on N_SOL, but
295 things like "break c-exp.y:435" need to work (I
296 suppose the psymtab_include_list could be hashed or put
297 in a binary tree, if profiling shows this is a major hog). */
298 if (pst
&& !strcmp (namestring
, pst
->filename
))
302 for (i
= 0; i
< includes_used
; i
++)
303 if (!strcmp (namestring
, psymtab_include_list
[i
]))
312 psymtab_include_list
[includes_used
++] = namestring
;
313 if (includes_used
>= includes_allocated
)
315 char **orig
= psymtab_include_list
;
317 psymtab_include_list
= (char **)
318 alloca ((includes_allocated
*= 2) *
320 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
321 includes_used
* sizeof (char *));
325 case N_LSYM
: /* Typedef or automatic variable. */
326 case N_STSYM
: /* Data seg var -- static */
327 case N_LCSYM
: /* BSS " */
328 case N_ROSYM
: /* Read-only data seg var -- static. */
329 case N_NBSTS
: /* Gould nobase. */
330 case N_NBLCS
: /* symbols. */
334 p
= (char *) strchr (namestring
, ':');
336 /* Skip if there is no :. */
342 if (p
!= namestring
) /* a name is there, not just :T... */
344 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
345 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
346 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
349 /* Also a typedef with the same name. */
350 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
351 VAR_NAMESPACE
, LOC_TYPEDEF
,
352 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
358 if (p
!= namestring
) /* a name is there, not just :T... */
360 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
361 VAR_NAMESPACE
, LOC_TYPEDEF
,
362 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
365 /* If this is an enumerated type, we need to
366 add all the enum constants to the partial symbol
367 table. This does not cover enums without names, e.g.
368 "enum {a, b} c;" in C, but fortunately those are
369 rare. There is no way for GDB to find those from the
370 enum type without spending too much time on it. Thus
371 to solve this problem, the compiler needs to put out separate
372 constant symbols ('c' N_LSYMS) for enum constants in
373 enums without names, or put out a dummy type. */
375 /* We are looking for something of the form
376 <name> ":" ("t" | "T") [<number> "="] "e"
377 {<constant> ":" <value> ","} ";". */
379 /* Skip over the colon and the 't' or 'T'. */
381 /* This type may be given a number. Also, numbers can come
382 in pairs like (0,26). Skip over it. */
383 while ((*p
>= '0' && *p
<= '9')
384 || *p
== '(' || *p
== ',' || *p
== ')'
390 /* We have found an enumerated type. */
391 /* According to comments in read_enum_type
392 a comma could end it instead of a semicolon.
393 I don't know where that happens.
395 while (*p
&& *p
!= ';' && *p
!= ',')
399 /* Check for and handle cretinous dbx symbol name
402 p
= next_symbol_text ();
404 /* Point to the character after the name
405 of the enum constant. */
406 for (q
= p
; *q
&& *q
!= ':'; q
++)
408 /* Note that the value doesn't matter for
409 enum constants in psymtabs, just in symtabs. */
410 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
411 VAR_NAMESPACE
, LOC_CONST
,
412 objfile
->static_psymbols
, 0);
413 /* Point past the name. */
415 /* Skip over the value. */
416 while (*p
&& *p
!= ',')
418 /* Advance past the comma. */
425 /* Constant, e.g. from "const" in Pascal. */
426 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
427 VAR_NAMESPACE
, LOC_CONST
,
428 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
431 /* Skip if the thing following the : is
432 not a letter (which indicates declaration of a local
433 variable, which we aren't interested in). */
438 case N_GSYM
: /* Global (extern) variable; can be
439 data or bss (sigh FIXME). */
441 /* Following may probably be ignored; I'll leave them here
442 for now (until I do Pascal and Modula 2 extensions). */
444 case N_PC
: /* I may or may not need this; I
446 case N_M2C
: /* I suspect that I can ignore this here. */
447 case N_SCOPE
: /* Same. */
451 p
= (char *) strchr (namestring
, ':');
453 continue; /* Not a debugging symbol. */
457 /* Main processing section for debugging symbols which
458 the initial read through the symbol tables needs to worry
459 about. If we reach this point, the symbol which we are
460 considering is definitely one we are interested in.
461 p must also contain the (valid) index into the namestring
462 which indicates the debugging type symbol. */
467 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
468 VAR_NAMESPACE
, LOC_CONST
,
469 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
472 CUR_SYMBOL_VALUE
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
473 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
474 VAR_NAMESPACE
, LOC_STATIC
,
475 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
478 CUR_SYMBOL_VALUE
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
479 /* The addresses in these entries are reported to be
480 wrong. See the code that reads 'G's for symtabs. */
481 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
482 VAR_NAMESPACE
, LOC_STATIC
,
483 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
487 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
488 VAR_NAMESPACE
, LOC_TYPEDEF
,
489 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
494 /* Kludges for ELF/STABS with Sun ACC */
495 last_function_name
= namestring
;
496 if (pst
->textlow
== 0)
497 pst
->textlow
= CUR_SYMBOL_VALUE
;
499 if (startup_file_end
== 0)
500 startup_file_end
= CUR_SYMBOL_VALUE
;
503 #endif /* DBXREAD_ONLY */
504 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
505 VAR_NAMESPACE
, LOC_BLOCK
,
506 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
509 /* Global functions were ignored here, but now they
510 are put into the global psymtab like one would expect.
511 They're also in the misc fn vector...
512 FIXME, why did it used to ignore these? That broke
513 "i fun" on these functions. */
516 /* Kludges for ELF/STABS with Sun ACC */
517 last_function_name
= namestring
;
518 if (pst
->textlow
== 0)
519 pst
->textlow
= CUR_SYMBOL_VALUE
;
521 if (startup_file_end
== 0)
522 startup_file_end
= CUR_SYMBOL_VALUE
;
525 #endif /* DBXREAD_ONLY */
526 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
527 VAR_NAMESPACE
, LOC_BLOCK
,
528 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
531 /* Two things show up here (hopefully); static symbols of
532 local scope (static used inside braces) or extensions
533 of structure symbols. We can ignore both. */
549 /* Unexpected symbol. Ignore it; perhaps it is an extension
550 that we don't know about.
552 Someone says sun cc puts out symbols like
553 /foo/baz/maclib::/usr/local/bin/maclib,
554 which would get here with a symbol type of ':'. */
563 /* Find the corresponding bincl and mark that psymtab on the
564 psymtab dependency list */
566 struct partial_symtab
*needed_pst
=
567 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
569 /* If this include file was defined earlier in this file,
571 if (needed_pst
== pst
) continue;
578 for (i
= 0; i
< dependencies_used
; i
++)
579 if (dependency_list
[i
] == needed_pst
)
585 /* If it's already in the list, skip the rest. */
588 dependency_list
[dependencies_used
++] = needed_pst
;
589 if (dependencies_used
>= dependencies_allocated
)
591 struct partial_symtab
**orig
= dependency_list
;
593 (struct partial_symtab
**)
594 alloca ((dependencies_allocated
*= 2)
595 * sizeof (struct partial_symtab
*));
596 memcpy ((PTR
)dependency_list
, (PTR
)orig
,
598 * sizeof (struct partial_symtab
*)));
600 fprintf (stderr
, "Had to reallocate dependency list.\n");
601 fprintf (stderr
, "New dependencies allocated: %d\n",
602 dependencies_allocated
);
607 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
610 #endif /* DBXREAD_ONLY */
615 HANDLE_RBRAC(CUR_SYMBOL_VALUE
);
621 case N_SSYM
: /* Claim: Structure or union element.
622 Hopefully, I can ignore this. */
623 case N_ENTRY
: /* Alternate entry point; can ignore. */
624 case N_MAIN
: /* Can definitely ignore this. */
625 case N_CATCH
: /* These are GNU C++ extensions */
626 case N_EHDECL
: /* that can safely be ignored here. */
636 case N_NSYMS
: /* Ultrix 4.0: symbol count */
637 case N_DEFD
: /* GNU Modula-2 */
639 case N_OBJ
: /* useless types from Solaris */
642 /* These symbols aren't interesting; don't worry about them */
647 /* If we haven't found it yet, ignore it. It's probably some
648 new type we don't know about yet. */
649 complain (&unknown_symtype_complaint
, local_hex_string(CUR_SYMBOL_TYPE
));