1 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* The following need to be defined:
24 SET_NAMESTRING() --Set namestring to name of symbol.
25 CUR_SYMBOL_TYPE --Type code of current symbol.
26 CUR_SYMBOL_VALUE --Value field of current symbol. May be adjusted here.
27 namestring - variable pointing to the name of the stab.
28 pst - the partial symbol table being built.
30 psymtab_include_list, includes_used, includes_allocated - list of include
31 file names (N_SOL) seen so far.
32 dependency_list, dependencies_used, dependencies_allocated - list of
33 N_EXCL stabs seen so far.
35 END_PSYMTAB -- end a partial symbol table.
36 START_PSYMTAB -- start a partial symbol table.
39 /* End of macro definitions, now let's handle them symbols! */
41 switch (CUR_SYMBOL_TYPE
)
45 * Standard, external, non-debugger, symbols
49 case N_NBTEXT
| N_EXT
:
50 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
54 case N_NBDATA
| N_EXT
:
55 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
61 case N_SETV
| N_EXT
: /* FIXME, is this in BSS? */
62 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
71 record_minimal_symbol (namestring
, CUR_SYMBOL_VALUE
,
72 CUR_SYMBOL_TYPE
, objfile
); /* Always */
73 #endif /* DBXREAD_ONLY */
76 /* Standard, local, non-debugger, symbols */
80 /* We need to be able to deal with both N_FN or N_TEXT,
81 because we have no way of knowing whether the sys-supplied ld
82 or GNU ld was used to make the executable. Sequents throw
83 in another wrinkle -- they renumbered N_FN. */
89 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
91 if ((namestring
[0] == '-' && namestring
[1] == 'l')
92 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
93 && namestring
[nsl
- 2] == '.'))
95 if (objfile
->ei
.entry_point
< CUR_SYMBOL_VALUE
&&
96 objfile
->ei
.entry_point
>= last_o_file_start
)
98 objfile
->ei
.entry_file_lowpc
= last_o_file_start
;
99 objfile
->ei
.entry_file_highpc
= CUR_SYMBOL_VALUE
;
101 if (past_first_source_file
&& pst
102 /* The gould NP1 uses low values for .o and -l symbols
103 which are not the address. */
104 && CUR_SYMBOL_VALUE
>= pst
->textlow
)
106 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
107 symnum
* symbol_size
,
108 CUR_SYMBOL_VALUE
> pst
->texthigh
109 ? CUR_SYMBOL_VALUE
: pst
->texthigh
,
110 dependency_list
, dependencies_used
, textlow_not_set
);
111 pst
= (struct partial_symtab
*) 0;
113 dependencies_used
= 0;
116 past_first_source_file
= 1;
117 last_o_file_start
= CUR_SYMBOL_VALUE
;
121 #endif /* DBXREAD_ONLY */
125 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
130 if (CUR_SYMBOL_VALUE
!= 0)
132 /* This is a "Fortran COMMON" symbol. See if the target
133 environment knows where it has been relocated to. */
138 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
&& CUR_SYMBOL_STRX
== 1)
153 /* Deal with relative offsets in the string table
154 used in ELF+STAB under Solaris. If we want to use the
155 n_strx field, which contains the name of the file,
156 we must adjust file_string_table_offset *before* calling
158 past_first_source_file
= 1;
159 file_string_table_offset
= next_file_string_table_offset
;
160 next_file_string_table_offset
=
161 file_string_table_offset
+ CUR_SYMBOL_VALUE
;
162 if (next_file_string_table_offset
< file_string_table_offset
)
163 error ("string table offset backs up at %d", symnum
);
164 /* FIXME -- replace error() with complaint. */
167 #endif /* DBXREAD_ONLY */
170 /* Lots of symbol types we can just ignore. */
177 /* Keep going . . . */
180 * Special symbol types for GNU
202 static int prev_so_symnum
= -10;
203 static int first_so_symnum
;
205 int prev_textlow_not_set
;
207 valu
= CUR_SYMBOL_VALUE
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
209 prev_textlow_not_set
= textlow_not_set
;
211 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
212 /* A zero value is probably an indication for the SunPRO 3.0
213 compiler. end_psymtab explicitly tests for zero, so
214 don't relocate it. */
216 if (CUR_SYMBOL_VALUE
== 0)
226 past_first_source_file
= 1;
228 if (prev_so_symnum
!= symnum
- 1)
229 { /* Here if prev stab wasn't N_SO */
230 first_so_symnum
= symnum
;
234 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
235 symnum
* symbol_size
,
236 valu
> pst
->texthigh
? valu
: pst
->texthigh
,
237 dependency_list
, dependencies_used
,
238 prev_textlow_not_set
);
239 pst
= (struct partial_symtab
*) 0;
241 dependencies_used
= 0;
245 prev_so_symnum
= symnum
;
247 /* End the current partial symtab and start a new one */
251 /* Null name means end of .o file. Don't start a new one. */
252 if (*namestring
== '\000')
255 /* Some compilers (including gcc) emit a pair of initial N_SOs.
256 The first one is a directory name; the second the file name.
257 If pst exists, is empty, and has a filename ending in '/',
258 we assume the previous N_SO was a directory name. */
260 p
= strrchr (namestring
, '/');
261 if (p
&& *(p
+ 1) == '\000')
262 continue; /* Simply ignore directory name SOs */
264 /* Some other compilers (C++ ones in particular) emit useless
265 SOs for non-existant .c files. We ignore all subsequent SOs that
266 immediately follow the first. */
269 pst
= START_PSYMTAB (objfile
,
271 first_so_symnum
* symbol_size
,
272 objfile
->global_psymbols
.next
,
273 objfile
->static_psymbols
.next
);
280 enum language tmp_language
;
281 /* Add this bincl to the bincl_list for future EXCLs. No
282 need to save the string; it'll be around until
283 read_dbx_symtab function returns */
287 tmp_language
= deduce_language_from_filename (namestring
);
289 /* Only change the psymtab's language if we've learned
290 something useful (eg. tmp_language is not language_unknown).
291 In addition, to match what start_subfile does, never change
293 if (tmp_language
!= language_unknown
294 && (tmp_language
!= language_c
295 || psymtab_language
!= language_cplus
))
296 psymtab_language
= tmp_language
;
300 /* FIXME: we should not get here without a PST to work on.
301 Attempt to recover. */
302 complain (&unclaimed_bincl_complaint
, namestring
, symnum
);
305 add_bincl_to_list (pst
, namestring
, CUR_SYMBOL_VALUE
);
307 /* Mark down an include file in the current psymtab */
309 goto record_include_file
;
311 #else /* DBXREAD_ONLY */
318 enum language tmp_language
;
319 /* Mark down an include file in the current psymtab */
323 tmp_language
= deduce_language_from_filename (namestring
);
325 /* Only change the psymtab's language if we've learned
326 something useful (eg. tmp_language is not language_unknown).
327 In addition, to match what start_subfile does, never change
329 if (tmp_language
!= language_unknown
330 && (tmp_language
!= language_c
331 || psymtab_language
!= language_cplus
))
332 psymtab_language
= tmp_language
;
334 /* In C++, one may expect the same filename to come round many
335 times, when code is coming alternately from the main file
336 and from inline functions in other files. So I check to see
337 if this is a file we've seen before -- either the main
338 source file, or a previously included file.
340 This seems to be a lot of time to be spending on N_SOL, but
341 things like "break c-exp.y:435" need to work (I
342 suppose the psymtab_include_list could be hashed or put
343 in a binary tree, if profiling shows this is a major hog). */
344 if (pst
&& STREQ (namestring
, pst
->filename
))
348 for (i
= 0; i
< includes_used
; i
++)
349 if (STREQ (namestring
, psymtab_include_list
[i
]))
362 psymtab_include_list
[includes_used
++] = namestring
;
363 if (includes_used
>= includes_allocated
)
365 char **orig
= psymtab_include_list
;
367 psymtab_include_list
= (char **)
368 alloca ((includes_allocated
*= 2) *
370 memcpy ((PTR
) psymtab_include_list
, (PTR
) orig
,
371 includes_used
* sizeof (char *));
375 case N_LSYM
: /* Typedef or automatic variable. */
376 case N_STSYM
: /* Data seg var -- static */
377 case N_LCSYM
: /* BSS " */
378 case N_ROSYM
: /* Read-only data seg var -- static. */
379 case N_NBSTS
: /* Gould nobase. */
380 case N_NBLCS
: /* symbols. */
382 case N_GSYM
: /* Global (extern) variable; can be
383 data or bss (sigh FIXME). */
385 /* Following may probably be ignored; I'll leave them here
386 for now (until I do Pascal and Modula 2 extensions). */
388 case N_PC
: /* I may or may not need this; I
390 case N_M2C
: /* I suspect that I can ignore this here. */
391 case N_SCOPE
: /* Same. */
396 /* See if this is an end of function stab. */
397 if (pst
&& CUR_SYMBOL_TYPE
== N_FUN
&& *namestring
== '\000')
401 /* It's value is the size (in bytes) of the function for
402 function relative stabs, or the address of the function's
403 end for old style stabs. */
404 valu
= CUR_SYMBOL_VALUE
+ last_function_start
;
405 if (pst
->texthigh
== 0 || valu
> pst
->texthigh
)
406 pst
->texthigh
= valu
;
411 p
= (char *) strchr (namestring
, ':');
413 continue; /* Not a debugging symbol. */
417 /* Main processing section for debugging symbols which
418 the initial read through the symbol tables needs to worry
419 about. If we reach this point, the symbol which we are
420 considering is definitely one we are interested in.
421 p must also contain the (valid) index into the namestring
422 which indicates the debugging type symbol. */
427 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
428 #ifdef STATIC_TRANSFORM_NAME
429 namestring
= STATIC_TRANSFORM_NAME (namestring
);
431 add_psymbol_to_list (namestring
, p
- namestring
,
432 VAR_NAMESPACE
, LOC_STATIC
,
433 &objfile
->static_psymbols
,
435 psymtab_language
, objfile
);
438 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
439 /* The addresses in these entries are reported to be
440 wrong. See the code that reads 'G's for symtabs. */
441 add_psymbol_to_list (namestring
, p
- namestring
,
442 VAR_NAMESPACE
, LOC_STATIC
,
443 &objfile
->global_psymbols
,
445 psymtab_language
, objfile
);
449 /* When a 'T' entry is defining an anonymous enum, it
450 may have a name which is the empty string, or a
451 single space. Since they're not really defining a
452 symbol, those shouldn't go in the partial symbol
453 table. We do pick up the elements of such enums at
454 'check_enum:', below. */
455 if (p
>= namestring
+ 2
456 || (p
== namestring
+ 1
457 && namestring
[0] != ' '))
459 add_psymbol_to_list (namestring
, p
- namestring
,
460 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
461 &objfile
->static_psymbols
,
463 psymtab_language
, objfile
);
466 /* Also a typedef with the same name. */
467 add_psymbol_to_list (namestring
, p
- namestring
,
468 VAR_NAMESPACE
, LOC_TYPEDEF
,
469 &objfile
->static_psymbols
,
471 psymtab_language
, objfile
);
474 /* The semantics of C++ state that "struct foo { ... }"
475 also defines a typedef for "foo". Unfortuantely, cfront
476 never makes the typedef when translating from C++ to C.
477 We make the typedef here so that "ptype foo" works as
478 expected for cfront translated code. */
479 else if (psymtab_language
== language_cplus
)
481 /* Also a typedef with the same name. */
482 add_psymbol_to_list (namestring
, p
- namestring
,
483 VAR_NAMESPACE
, LOC_TYPEDEF
,
484 &objfile
->static_psymbols
,
486 psymtab_language
, objfile
);
491 if (p
!= namestring
) /* a name is there, not just :T... */
493 add_psymbol_to_list (namestring
, p
- namestring
,
494 VAR_NAMESPACE
, LOC_TYPEDEF
,
495 &objfile
->static_psymbols
,
497 psymtab_language
, objfile
);
500 /* If this is an enumerated type, we need to
501 add all the enum constants to the partial symbol
502 table. This does not cover enums without names, e.g.
503 "enum {a, b} c;" in C, but fortunately those are
504 rare. There is no way for GDB to find those from the
505 enum type without spending too much time on it. Thus
506 to solve this problem, the compiler needs to put out the
507 enum in a nameless type. GCC2 does this. */
509 /* We are looking for something of the form
510 <name> ":" ("t" | "T") [<number> "="] "e"
511 {<constant> ":" <value> ","} ";". */
513 /* Skip over the colon and the 't' or 'T'. */
515 /* This type may be given a number. Also, numbers can come
516 in pairs like (0,26). Skip over it. */
517 while ((*p
>= '0' && *p
<= '9')
518 || *p
== '(' || *p
== ',' || *p
== ')'
524 /* The aix4 compiler emits extra crud before the members. */
527 /* Skip over the type (?). */
531 /* Skip over the colon. */
535 /* We have found an enumerated type. */
536 /* According to comments in read_enum_type
537 a comma could end it instead of a semicolon.
538 I don't know where that happens.
540 while (*p
&& *p
!= ';' && *p
!= ',')
544 /* Check for and handle cretinous dbx symbol name
546 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
547 p
= next_symbol_text (objfile
);
549 /* Point to the character after the name
550 of the enum constant. */
551 for (q
= p
; *q
&& *q
!= ':'; q
++)
553 /* Note that the value doesn't matter for
554 enum constants in psymtabs, just in symtabs. */
555 add_psymbol_to_list (p
, q
- p
,
556 VAR_NAMESPACE
, LOC_CONST
,
557 &objfile
->static_psymbols
, 0,
558 0, psymtab_language
, objfile
);
559 /* Point past the name. */
561 /* Skip over the value. */
562 while (*p
&& *p
!= ',')
564 /* Advance past the comma. */
571 /* Constant, e.g. from "const" in Pascal. */
572 add_psymbol_to_list (namestring
, p
- namestring
,
573 VAR_NAMESPACE
, LOC_CONST
,
574 &objfile
->static_psymbols
, CUR_SYMBOL_VALUE
,
575 0, psymtab_language
, objfile
);
579 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
581 /* Kludges for ELF/STABS with Sun ACC */
582 last_function_name
= namestring
;
583 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
584 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
585 value for the bottom of the text seg in those cases. */
586 if (pst
&& textlow_not_set
)
589 find_stab_function_addr (namestring
, pst
->filename
, objfile
);
595 /* Keep track of the start of the last function so we
596 can handle end of function symbols. */
597 last_function_start
= CUR_SYMBOL_VALUE
;
599 /* In reordered executables this function may lie outside
600 the bounds created by N_SO symbols. If that's the case
601 use the address of this function as the low bound for
602 the partial symbol table. */
604 || (pst
&& CUR_SYMBOL_VALUE
< pst
->textlow
606 != ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
))))
608 pst
->textlow
= CUR_SYMBOL_VALUE
;
611 #endif /* DBXREAD_ONLY */
612 add_psymbol_to_list (namestring
, p
- namestring
,
613 VAR_NAMESPACE
, LOC_BLOCK
,
614 &objfile
->static_psymbols
,
616 psymtab_language
, objfile
);
619 /* Global functions were ignored here, but now they
620 are put into the global psymtab like one would expect.
621 They're also in the minimal symbol table. */
623 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
625 /* Kludges for ELF/STABS with Sun ACC */
626 last_function_name
= namestring
;
627 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
628 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
629 value for the bottom of the text seg in those cases. */
630 if (CUR_SYMBOL_VALUE
== ANOFFSET (objfile
->section_offsets
,
631 SECT_OFF_TEXT (objfile
)))
633 find_stab_function_addr (namestring
, pst
->filename
, objfile
);
634 if (pst
&& textlow_not_set
)
636 pst
->textlow
= CUR_SYMBOL_VALUE
;
642 /* Keep track of the start of the last function so we
643 can handle end of function symbols. */
644 last_function_start
= CUR_SYMBOL_VALUE
;
646 /* In reordered executables this function may lie outside
647 the bounds created by N_SO symbols. If that's the case
648 use the address of this function as the low bound for
649 the partial symbol table. */
651 || (pst
&& CUR_SYMBOL_VALUE
< pst
->textlow
653 != ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
))))
655 pst
->textlow
= CUR_SYMBOL_VALUE
;
658 #endif /* DBXREAD_ONLY */
659 add_psymbol_to_list (namestring
, p
- namestring
,
660 VAR_NAMESPACE
, LOC_BLOCK
,
661 &objfile
->global_psymbols
,
663 psymtab_language
, objfile
);
666 /* Two things show up here (hopefully); static symbols of
667 local scope (static used inside braces) or extensions
668 of structure symbols. We can ignore both. */
682 case '#': /* for symbol identification (used in live ranges) */
683 /* added to support cfront stabs strings */
684 case 'Z': /* for definition continuations */
685 case 'P': /* for prototypes */
689 /* It is a C++ nested symbol. We don't need to record it
690 (I don't think); if we try to look up foo::bar::baz,
691 then symbols for the symtab containing foo should get
693 /* Someone says sun cc puts out symbols like
694 /foo/baz/maclib::/usr/local/bin/maclib,
695 which would get here with a symbol type of ':'. */
699 /* Unexpected symbol descriptor. The second and subsequent stabs
700 of a continued stab can show up here. The question is
701 whether they ever can mimic a normal stab--it would be
702 nice if not, since we certainly don't want to spend the
703 time searching to the end of every string looking for
706 complain (&unknown_symchar_complaint
, p
[1]);
708 /* Ignore it; perhaps it is an extension that we don't
718 /* Find the corresponding bincl and mark that psymtab on the
719 psymtab dependency list */
721 struct partial_symtab
*needed_pst
=
722 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
724 /* If this include file was defined earlier in this file,
726 if (needed_pst
== pst
)
734 for (i
= 0; i
< dependencies_used
; i
++)
735 if (dependency_list
[i
] == needed_pst
)
741 /* If it's already in the list, skip the rest. */
745 dependency_list
[dependencies_used
++] = needed_pst
;
746 if (dependencies_used
>= dependencies_allocated
)
748 struct partial_symtab
**orig
= dependency_list
;
750 (struct partial_symtab
**)
751 alloca ((dependencies_allocated
*= 2)
752 * sizeof (struct partial_symtab
*));
753 memcpy ((PTR
) dependency_list
, (PTR
) orig
,
755 * sizeof (struct partial_symtab
*)));
757 fprintf_unfiltered (gdb_stderr
, "Had to reallocate dependency list.\n");
758 fprintf_unfiltered (gdb_stderr
, "New dependencies allocated: %d\n",
759 dependencies_allocated
);
764 #endif /* DBXREAD_ONLY */
768 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
769 /* Solaris 2 end of module, finish current partial symbol table.
770 END_PSYMTAB will set pst->texthigh to the proper value, which
771 is necessary if a module compiled without debugging info
772 follows this module. */
775 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
776 symnum
* symbol_size
,
778 dependency_list
, dependencies_used
, textlow_not_set
);
779 pst
= (struct partial_symtab
*) 0;
781 dependencies_used
= 0;
788 HANDLE_RBRAC (CUR_SYMBOL_VALUE
);
794 case N_SSYM
: /* Claim: Structure or union element.
795 Hopefully, I can ignore this. */
796 case N_ENTRY
: /* Alternate entry point; can ignore. */
797 case N_MAIN
: /* Can definitely ignore this. */
798 case N_CATCH
: /* These are GNU C++ extensions */
799 case N_EHDECL
: /* that can safely be ignored here. */
809 case N_NSYMS
: /* Ultrix 4.0: symbol count */
810 case N_DEFD
: /* GNU Modula-2 */
811 case N_ALIAS
: /* SunPro F77: alias name, ignore for now. */
813 case N_OBJ
: /* useless types from Solaris */
815 /* These symbols aren't interesting; don't worry about them */
820 /* If we haven't found it yet, ignore it. It's probably some
821 new type we don't know about yet. */
822 complain (&unknown_symtype_complaint
,
823 local_hex_string (CUR_SYMBOL_TYPE
));