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 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., 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
);
49 case N_SETV
| N_EXT
: /* FIXME, is this in BSS? */
50 CUR_SYMBOL_VALUE
+= ANOFFSET (section_offsets
, SECT_OFF_BSS
);
59 record_minimal_symbol (namestring
, CUR_SYMBOL_VALUE
,
60 CUR_SYMBOL_TYPE
, objfile
); /* Always */
61 #endif /* DBXREAD_ONLY */
64 /* Standard, local, non-debugger, symbols */
68 /* We need to be able to deal with both N_FN or N_TEXT,
69 because we have no way of knowing whether the sys-supplied ld
70 or GNU ld was used to make the executable. Sequents throw
71 in another wrinkle -- they renumbered N_FN. */
77 CUR_SYMBOL_VALUE
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
79 if ((namestring
[0] == '-' && namestring
[1] == 'l')
80 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
81 && namestring
[nsl
- 2] == '.')
82 #ifdef GDB_TARGET_IS_HPPA
83 /* This braindamage is necessary for versions of GCC 2.6 and
84 earlier; it will not be necessary for GCC 2.7.
86 In a nutshell, we need a way to determine when we've hit
87 the end of a file with debug symbols. Most ports do this
88 with a N_SO record with a NULL symbol name (as will GCC 2.7
89 on the PA). GCC 2.6 (and earlier) on the PA instead creates
90 an N_TEXT symbol with the name "end_file." */
91 || (namestring
[0] == 'e' && STREQ (namestring
, "end_file."))
95 #ifndef GDB_TARGET_IS_HPPA
96 if (objfile
-> ei
.entry_point
< CUR_SYMBOL_VALUE
&&
97 objfile
-> ei
.entry_point
>= last_o_file_start
)
99 objfile
-> ei
.entry_file_lowpc
= last_o_file_start
;
100 objfile
-> ei
.entry_file_highpc
= CUR_SYMBOL_VALUE
;
103 if (past_first_source_file
&& pst
104 /* The gould NP1 uses low values for .o and -l symbols
105 which are not the address. */
106 && CUR_SYMBOL_VALUE
>= pst
->textlow
)
108 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
109 symnum
* symbol_size
, CUR_SYMBOL_VALUE
,
110 dependency_list
, dependencies_used
);
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 (section_offsets
, SECT_OFF_DATA
);
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 #endif /* DBXREAD_ONLY */
145 continue; /* Just undefined, not COMMON */
149 if (processing_acc_compilation
&& bufp
->n_strx
== 1) {
150 /* Deal with relative offsets in the string table
151 used in ELF+STAB under Solaris. If we want to use the
152 n_strx field, which contains the name of the file,
153 we must adjust file_string_table_offset *before* calling
155 past_first_source_file
= 1;
156 file_string_table_offset
= next_file_string_table_offset
;
157 next_file_string_table_offset
=
158 file_string_table_offset
+ bufp
->n_value
;
159 if (next_file_string_table_offset
< file_string_table_offset
)
160 error ("string table offset backs up at %d", symnum
);
161 /* FIXME -- replace error() with complaint. */
164 #endif /* DBXREAD_ONLY */
167 /* Lots of symbol types we can just ignore. */
174 /* Keep going . . .*/
177 * Special symbol types for GNU
198 static int prev_so_symnum
= -10;
199 static int first_so_symnum
;
202 valu
= CUR_SYMBOL_VALUE
+ ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
203 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
204 /* A zero value is probably an indication for the SunPRO 3.0
205 compiler. end_psymtab explicitly tests for zero, so
206 don't relocate it. */
207 if (CUR_SYMBOL_VALUE
== 0)
211 past_first_source_file
= 1;
213 if (prev_so_symnum
!= symnum
- 1)
214 { /* Here if prev stab wasn't N_SO */
215 first_so_symnum
= symnum
;
219 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
220 symnum
* symbol_size
, valu
,
221 dependency_list
, dependencies_used
);
222 pst
= (struct partial_symtab
*) 0;
224 dependencies_used
= 0;
228 prev_so_symnum
= symnum
;
230 /* End the current partial symtab and start a new one */
234 /* Null name means end of .o file. Don't start a new one. */
235 if (*namestring
== '\000')
238 /* Some compilers (including gcc) emit a pair of initial N_SOs.
239 The first one is a directory name; the second the file name.
240 If pst exists, is empty, and has a filename ending in '/',
241 we assume the previous N_SO was a directory name. */
243 p
= strrchr (namestring
, '/');
244 if (p
&& *(p
+1) == '\000')
245 continue; /* Simply ignore directory name SOs */
247 /* Some other compilers (C++ ones in particular) emit useless
248 SOs for non-existant .c files. We ignore all subsequent SOs that
249 immediately follow the first. */
252 pst
= START_PSYMTAB (objfile
, section_offsets
,
254 first_so_symnum
* symbol_size
,
255 objfile
-> global_psymbols
.next
,
256 objfile
-> static_psymbols
.next
);
263 enum language tmp_language
;
264 /* Add this bincl to the bincl_list for future EXCLs. No
265 need to save the string; it'll be around until
266 read_dbx_symtab function returns */
270 tmp_language
= deduce_language_from_filename (namestring
);
272 /* Only change the psymtab's language if we've learned
273 something useful (eg. tmp_language is not language_unknown).
274 In addition, to match what start_subfile does, never change
276 if (tmp_language
!= language_unknown
277 && (tmp_language
!= language_c
278 || psymtab_language
!= language_cplus
))
279 psymtab_language
= tmp_language
;
281 add_bincl_to_list (pst
, namestring
, CUR_SYMBOL_VALUE
);
283 /* Mark down an include file in the current psymtab */
285 goto record_include_file
;
287 #else /* DBXREAD_ONLY */
294 enum language tmp_language
;
295 /* Mark down an include file in the current psymtab */
299 tmp_language
= deduce_language_from_filename (namestring
);
301 /* Only change the psymtab's language if we've learned
302 something useful (eg. tmp_language is not language_unknown).
303 In addition, to match what start_subfile does, never change
305 if (tmp_language
!= language_unknown
306 && (tmp_language
!= language_c
307 || psymtab_language
!= language_cplus
))
308 psymtab_language
= tmp_language
;
310 /* In C++, one may expect the same filename to come round many
311 times, when code is coming alternately from the main file
312 and from inline functions in other files. So I check to see
313 if this is a file we've seen before -- either the main
314 source file, or a previously included file.
316 This seems to be a lot of time to be spending on N_SOL, but
317 things like "break c-exp.y:435" need to work (I
318 suppose the psymtab_include_list could be hashed or put
319 in a binary tree, if profiling shows this is a major hog). */
320 if (pst
&& STREQ (namestring
, pst
->filename
))
324 for (i
= 0; i
< includes_used
; i
++)
325 if (STREQ (namestring
, psymtab_include_list
[i
]))
338 psymtab_include_list
[includes_used
++] = namestring
;
339 if (includes_used
>= includes_allocated
)
341 char **orig
= psymtab_include_list
;
343 psymtab_include_list
= (char **)
344 alloca ((includes_allocated
*= 2) *
346 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
347 includes_used
* sizeof (char *));
351 case N_LSYM
: /* Typedef or automatic variable. */
352 case N_STSYM
: /* Data seg var -- static */
353 case N_LCSYM
: /* BSS " */
354 case N_ROSYM
: /* Read-only data seg var -- static. */
355 case N_NBSTS
: /* Gould nobase. */
356 case N_NBLCS
: /* symbols. */
358 case N_GSYM
: /* Global (extern) variable; can be
359 data or bss (sigh FIXME). */
361 /* Following may probably be ignored; I'll leave them here
362 for now (until I do Pascal and Modula 2 extensions). */
364 case N_PC
: /* I may or may not need this; I
366 case N_M2C
: /* I suspect that I can ignore this here. */
367 case N_SCOPE
: /* Same. */
371 p
= (char *) strchr (namestring
, ':');
373 continue; /* Not a debugging symbol. */
377 /* Main processing section for debugging symbols which
378 the initial read through the symbol tables needs to worry
379 about. If we reach this point, the symbol which we are
380 considering is definitely one we are interested in.
381 p must also contain the (valid) index into the namestring
382 which indicates the debugging type symbol. */
387 CUR_SYMBOL_VALUE
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
388 #ifdef STATIC_TRANSFORM_NAME
389 namestring
= STATIC_TRANSFORM_NAME (namestring
);
391 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
392 VAR_NAMESPACE
, LOC_STATIC
,
393 objfile
->static_psymbols
,
395 psymtab_language
, objfile
);
398 CUR_SYMBOL_VALUE
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
399 /* The addresses in these entries are reported to be
400 wrong. See the code that reads 'G's for symtabs. */
401 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
402 VAR_NAMESPACE
, LOC_STATIC
,
403 objfile
->global_psymbols
,
405 psymtab_language
, objfile
);
409 if (p
!= namestring
) /* a name is there, not just :T... */
411 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
412 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
413 objfile
->static_psymbols
,
415 psymtab_language
, objfile
);
418 /* Also a typedef with the same name. */
419 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
420 VAR_NAMESPACE
, LOC_TYPEDEF
,
421 objfile
->static_psymbols
,
422 CUR_SYMBOL_VALUE
, psymtab_language
,
426 /* The semantics of C++ state that "struct foo { ... }"
427 also defines a typedef for "foo". Unfortuantely, cfront
428 never makes the typedef when translating from C++ to C.
429 We make the typedef here so that "ptype foo" works as
430 expected for cfront translated code. */
431 else if (psymtab_language
== language_cplus
)
433 /* Also a typedef with the same name. */
434 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
435 VAR_NAMESPACE
, LOC_TYPEDEF
,
436 objfile
->static_psymbols
,
437 CUR_SYMBOL_VALUE
, psymtab_language
,
443 if (p
!= namestring
) /* a name is there, not just :T... */
445 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
446 VAR_NAMESPACE
, LOC_TYPEDEF
,
447 objfile
->static_psymbols
,
449 psymtab_language
, objfile
);
452 /* If this is an enumerated type, we need to
453 add all the enum constants to the partial symbol
454 table. This does not cover enums without names, e.g.
455 "enum {a, b} c;" in C, but fortunately those are
456 rare. There is no way for GDB to find those from the
457 enum type without spending too much time on it. Thus
458 to solve this problem, the compiler needs to put out the
459 enum in a nameless type. GCC2 does this. */
461 /* We are looking for something of the form
462 <name> ":" ("t" | "T") [<number> "="] "e"
463 {<constant> ":" <value> ","} ";". */
465 /* Skip over the colon and the 't' or 'T'. */
467 /* This type may be given a number. Also, numbers can come
468 in pairs like (0,26). Skip over it. */
469 while ((*p
>= '0' && *p
<= '9')
470 || *p
== '(' || *p
== ',' || *p
== ')'
476 /* We have found an enumerated type. */
477 /* According to comments in read_enum_type
478 a comma could end it instead of a semicolon.
479 I don't know where that happens.
481 while (*p
&& *p
!= ';' && *p
!= ',')
485 /* Check for and handle cretinous dbx symbol name
487 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
488 p
= next_symbol_text ();
490 /* Point to the character after the name
491 of the enum constant. */
492 for (q
= p
; *q
&& *q
!= ':'; q
++)
494 /* Note that the value doesn't matter for
495 enum constants in psymtabs, just in symtabs. */
496 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
497 VAR_NAMESPACE
, LOC_CONST
,
498 objfile
->static_psymbols
, 0,
499 psymtab_language
, objfile
);
500 /* Point past the name. */
502 /* Skip over the value. */
503 while (*p
&& *p
!= ',')
505 /* Advance past the comma. */
512 /* Constant, e.g. from "const" in Pascal. */
513 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
514 VAR_NAMESPACE
, LOC_CONST
,
515 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
,
516 psymtab_language
, objfile
);
520 CUR_SYMBOL_VALUE
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
522 /* Kludges for ELF/STABS with Sun ACC */
523 last_function_name
= namestring
;
524 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
525 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
526 value for the bottom of the text seg in those cases. */
527 if (pst
&& pst
->textlow
== 0 && !symfile_relocatable
)
529 find_stab_function_addr (namestring
, pst
, objfile
);
532 if (startup_file_end
== 0)
533 startup_file_end
= CUR_SYMBOL_VALUE
;
536 #endif /* DBXREAD_ONLY */
537 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
538 VAR_NAMESPACE
, LOC_BLOCK
,
539 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
,
540 psymtab_language
, objfile
);
543 /* Global functions were ignored here, but now they
544 are put into the global psymtab like one would expect.
545 They're also in the minimal symbol table. */
547 CUR_SYMBOL_VALUE
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
549 /* Kludges for ELF/STABS with Sun ACC */
550 last_function_name
= namestring
;
551 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
552 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
553 value for the bottom of the text seg in those cases. */
554 if (pst
&& pst
->textlow
== 0 && !symfile_relocatable
)
556 find_stab_function_addr (namestring
, pst
, objfile
);
559 if (startup_file_end
== 0)
560 startup_file_end
= CUR_SYMBOL_VALUE
;
563 #endif /* DBXREAD_ONLY */
564 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
565 VAR_NAMESPACE
, LOC_BLOCK
,
566 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
,
567 psymtab_language
, objfile
);
570 /* Two things show up here (hopefully); static symbols of
571 local scope (static used inside braces) or extensions
572 of structure symbols. We can ignore both. */
588 /* It is a C++ nested symbol. We don't need to record it
589 (I don't think); if we try to look up foo::bar::baz,
590 then symbols for the symtab containing foo should get
592 /* Someone says sun cc puts out symbols like
593 /foo/baz/maclib::/usr/local/bin/maclib,
594 which would get here with a symbol type of ':'. */
598 /* Unexpected symbol descriptor. The second and subsequent stabs
599 of a continued stab can show up here. The question is
600 whether they ever can mimic a normal stab--it would be
601 nice if not, since we certainly don't want to spend the
602 time searching to the end of every string looking for
605 complain (&unknown_symchar_complaint
, p
[1]);
607 /* Ignore it; perhaps it is an extension that we don't
617 /* Find the corresponding bincl and mark that psymtab on the
618 psymtab dependency list */
620 struct partial_symtab
*needed_pst
=
621 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
623 /* If this include file was defined earlier in this file,
625 if (needed_pst
== pst
) continue;
632 for (i
= 0; i
< dependencies_used
; i
++)
633 if (dependency_list
[i
] == needed_pst
)
639 /* If it's already in the list, skip the rest. */
642 dependency_list
[dependencies_used
++] = needed_pst
;
643 if (dependencies_used
>= dependencies_allocated
)
645 struct partial_symtab
**orig
= dependency_list
;
647 (struct partial_symtab
**)
648 alloca ((dependencies_allocated
*= 2)
649 * sizeof (struct partial_symtab
*));
650 memcpy ((PTR
)dependency_list
, (PTR
)orig
,
652 * sizeof (struct partial_symtab
*)));
654 fprintf_unfiltered (gdb_stderr
, "Had to reallocate dependency list.\n");
655 fprintf_unfiltered (gdb_stderr
, "New dependencies allocated: %d\n",
656 dependencies_allocated
);
661 #endif /* DBXREAD_ONLY */
666 HANDLE_RBRAC(CUR_SYMBOL_VALUE
);
672 case N_SSYM
: /* Claim: Structure or union element.
673 Hopefully, I can ignore this. */
674 case N_ENTRY
: /* Alternate entry point; can ignore. */
675 case N_MAIN
: /* Can definitely ignore this. */
676 case N_CATCH
: /* These are GNU C++ extensions */
677 case N_EHDECL
: /* that can safely be ignored here. */
687 case N_NSYMS
: /* Ultrix 4.0: symbol count */
688 case N_DEFD
: /* GNU Modula-2 */
690 case N_OBJ
: /* useless types from Solaris */
693 /* These symbols aren't interesting; don't worry about them */
698 /* If we haven't found it yet, ignore it. It's probably some
699 new type we don't know about yet. */
700 complain (&unknown_symtype_complaint
,
701 local_hex_string (CUR_SYMBOL_TYPE
));