1 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* The following need to be defined:
23 SET_NAMESTRING() --Set namestring to name of symbol.
24 CUR_SYMBOL_TYPE --Type code of current symbol.
25 CUR_SYMBOL_VALUE --Value field of current symbol. May be adjusted here.
26 namestring - variable pointing to the name of the stab.
27 section_offsets - variable pointing to the section offsets.
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
);
54 case N_NBDATA
| N_EXT
:
55 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA
);
61 case N_SETV
| N_EXT
: /* FIXME, is this in BSS? */
62 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS
);
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
);
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
);
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
);
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
, objfile
->section_offsets
,
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 (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
);
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
);
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
);
581 /* Keep track of the start of the last function so we
582 can handle end of function symbols. */
583 last_function_start
= CUR_SYMBOL_VALUE
;
584 /* Kludges for ELF/STABS with Sun ACC */
585 last_function_name
= namestring
;
586 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
587 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
588 value for the bottom of the text seg in those cases. */
589 if (pst
&& textlow_not_set
)
592 find_stab_function_addr (namestring
, pst
, objfile
);
598 /* In reordered executables this function may lie outside
599 the bounds created by N_SO symbols. If that's the case
600 use the address of this function as the low bound for
601 the partial symbol table. */
603 || (CUR_SYMBOL_VALUE
< pst
->textlow
605 != ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT
)))
607 pst
->textlow
= CUR_SYMBOL_VALUE
;
610 #endif /* DBXREAD_ONLY */
611 add_psymbol_to_list (namestring
, p
- namestring
,
612 VAR_NAMESPACE
, LOC_BLOCK
,
613 &objfile
->static_psymbols
,
615 psymtab_language
, objfile
);
618 /* Global functions were ignored here, but now they
619 are put into the global psymtab like one would expect.
620 They're also in the minimal symbol table. */
622 CUR_SYMBOL_VALUE
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT
);
624 /* Keep track of the start of the last function so we
625 can handle end of function symbols. */
626 last_function_start
= CUR_SYMBOL_VALUE
;
627 /* Kludges for ELF/STABS with Sun ACC */
628 last_function_name
= namestring
;
629 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
630 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
631 value for the bottom of the text seg in those cases. */
632 if (pst
&& textlow_not_set
)
635 find_stab_function_addr (namestring
, pst
, objfile
);
640 /* In reordered executables this function may lie outside
641 the bounds created by N_SO symbols. If that's the case
642 use the address of this function as the low bound for
643 the partial symbol table. */
645 || (CUR_SYMBOL_VALUE
< pst
->textlow
647 != ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT
)))
649 pst
->textlow
= CUR_SYMBOL_VALUE
;
652 #endif /* DBXREAD_ONLY */
653 add_psymbol_to_list (namestring
, p
- namestring
,
654 VAR_NAMESPACE
, LOC_BLOCK
,
655 &objfile
->global_psymbols
,
657 psymtab_language
, objfile
);
660 /* Two things show up here (hopefully); static symbols of
661 local scope (static used inside braces) or extensions
662 of structure symbols. We can ignore both. */
676 case '#': /* for symbol identification (used in live ranges) */
677 /* added to support cfront stabs strings */
678 case 'Z': /* for definition continuations */
679 case 'P': /* for prototypes */
683 /* It is a C++ nested symbol. We don't need to record it
684 (I don't think); if we try to look up foo::bar::baz,
685 then symbols for the symtab containing foo should get
687 /* Someone says sun cc puts out symbols like
688 /foo/baz/maclib::/usr/local/bin/maclib,
689 which would get here with a symbol type of ':'. */
693 /* Unexpected symbol descriptor. The second and subsequent stabs
694 of a continued stab can show up here. The question is
695 whether they ever can mimic a normal stab--it would be
696 nice if not, since we certainly don't want to spend the
697 time searching to the end of every string looking for
700 complain (&unknown_symchar_complaint
, p
[1]);
702 /* Ignore it; perhaps it is an extension that we don't
712 /* Find the corresponding bincl and mark that psymtab on the
713 psymtab dependency list */
715 struct partial_symtab
*needed_pst
=
716 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
718 /* If this include file was defined earlier in this file,
720 if (needed_pst
== pst
)
728 for (i
= 0; i
< dependencies_used
; i
++)
729 if (dependency_list
[i
] == needed_pst
)
735 /* If it's already in the list, skip the rest. */
739 dependency_list
[dependencies_used
++] = needed_pst
;
740 if (dependencies_used
>= dependencies_allocated
)
742 struct partial_symtab
**orig
= dependency_list
;
744 (struct partial_symtab
**)
745 alloca ((dependencies_allocated
*= 2)
746 * sizeof (struct partial_symtab
*));
747 memcpy ((PTR
) dependency_list
, (PTR
) orig
,
749 * sizeof (struct partial_symtab
*)));
751 fprintf_unfiltered (gdb_stderr
, "Had to reallocate dependency list.\n");
752 fprintf_unfiltered (gdb_stderr
, "New dependencies allocated: %d\n",
753 dependencies_allocated
);
758 #endif /* DBXREAD_ONLY */
762 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
763 /* Solaris 2 end of module, finish current partial symbol table.
764 END_PSYMTAB will set pst->texthigh to the proper value, which
765 is necessary if a module compiled without debugging info
766 follows this module. */
769 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
770 symnum
* symbol_size
,
772 dependency_list
, dependencies_used
, textlow_not_set
);
773 pst
= (struct partial_symtab
*) 0;
775 dependencies_used
= 0;
782 HANDLE_RBRAC (CUR_SYMBOL_VALUE
);
788 case N_SSYM
: /* Claim: Structure or union element.
789 Hopefully, I can ignore this. */
790 case N_ENTRY
: /* Alternate entry point; can ignore. */
791 case N_MAIN
: /* Can definitely ignore this. */
792 case N_CATCH
: /* These are GNU C++ extensions */
793 case N_EHDECL
: /* that can safely be ignored here. */
803 case N_NSYMS
: /* Ultrix 4.0: symbol count */
804 case N_DEFD
: /* GNU Modula-2 */
805 case N_ALIAS
: /* SunPro F77: alias name, ignore for now. */
807 case N_OBJ
: /* useless types from Solaris */
809 /* These symbols aren't interesting; don't worry about them */
814 /* If we haven't found it yet, ignore it. It's probably some
815 new type we don't know about yet. */
816 complain (&unknown_symtype_complaint
,
817 local_hex_string (CUR_SYMBOL_TYPE
));