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 case N_NBDATA
| N_EXT
:
46 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
51 record_minimal_symbol (namestring
, CUR_SYMBOL_VALUE
,
52 CUR_SYMBOL_TYPE
, objfile
); /* Always */
53 #endif /* DBXREAD_ONLY */
56 /* Standard, local, non-debugger, symbols */
60 /* We need to be able to deal with both N_FN or N_TEXT,
61 because we have no way of knowing whether the sys-supplied ld
62 or GNU ld was used to make the executable. Sequents throw
63 in another wrinkle -- they renumbered N_FN. */
69 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
71 if ((namestring
[0] == '-' && namestring
[1] == 'l')
72 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
73 && namestring
[nsl
- 2] == '.'))
75 if (objfile
-> ei
.entry_point
< CUR_SYMBOL_VALUE
&&
76 objfile
-> ei
.entry_point
>= last_o_file_start
&&
77 addr
== 0) /* FIXME nogood nomore */
79 objfile
-> ei
.entry_file_lowpc
= last_o_file_start
;
80 objfile
-> ei
.entry_file_highpc
= CUR_SYMBOL_VALUE
;
82 if (past_first_source_file
&& pst
83 /* The gould NP1 uses low values for .o and -l symbols
84 which are not the address. */
85 && CUR_SYMBOL_VALUE
> pst
->textlow
)
87 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
88 symnum
* symbol_size
, CUR_SYMBOL_VALUE
,
89 dependency_list
, dependencies_used
);
90 pst
= (struct partial_symtab
*) 0;
92 dependencies_used
= 0;
95 past_first_source_file
= 1;
96 last_o_file_start
= CUR_SYMBOL_VALUE
;
98 #endif /* DBXREAD_ONLY */
103 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
105 /* Check for __DYNAMIC, which is used by Sun shared libraries.
106 Record it even if it's local, not global, so we can find it.
107 Same with virtual function tables, both global and static. */
108 if ((namestring
[8] == 'C' && (strcmp ("__DYNAMIC", namestring
) == 0))
109 || VTBL_PREFIX_P ((namestring
+HASH_OFFSET
)))
111 /* Not really a function here, but... */
112 record_minimal_symbol (namestring
, CUR_SYMBOL_VALUE
,
113 CUR_SYMBOL_TYPE
, objfile
); /* Always */
115 #endif /* DBXREAD_ONLY */
120 if (CUR_SYMBOL_VALUE
!= 0) {
121 /* This is a "Fortran COMMON" symbol. See if the target
122 environment knows where it has been relocated to. */
127 if (target_lookup_symbol (namestring
, &reladdr
)) {
128 continue; /* Error in lookup; ignore symbol for now. */
130 CUR_SYMBOL_TYPE
^= (N_BSS
^N_UNDF
); /* Define it as a bss-symbol */
131 CUR_SYMBOL_VALUE
= reladdr
;
134 #endif /* DBXREAD_ONLY */
135 continue; /* Just undefined, not COMMON */
139 if (processing_acc_compilation
&& bufp
->n_strx
== 1) {
140 /* deal with relative offsets in the string table
141 used in ELF+STAB under Solaris */
142 past_first_source_file
= 1;
143 file_string_table_offset
= next_file_string_table_offset
;
144 next_file_string_table_offset
=
145 file_string_table_offset
+ bufp
->n_value
;
146 if (next_file_string_table_offset
< file_string_table_offset
)
147 error ("string table offset backs up at %d", symnum
);
148 /* FIXME -- replace error() with complaint. */
151 #endif /* DBXREAD_ONLY */
154 /* Lots of symbol types we can just ignore. */
162 /* Keep going . . .*/
165 * Special symbol types for GNU
185 unsigned long valu
= CUR_SYMBOL_VALUE
;
186 /* Symbol number of the first symbol of this file (i.e. the N_SO
187 if there is just one, or the first if we have a pair). */
188 int first_symnum
= symnum
;
190 /* End the current partial symtab and start a new one */
194 valu
+= addr
; /* Relocate */
196 if (pst
&& past_first_source_file
)
198 /* Some compilers (including gcc) emit a pair of initial N_SOs.
199 The first one is a directory name; the second the file name.
200 If pst exists, is empty, and has a filename ending in '/',
201 we assume the previous N_SO was a directory name. */
202 if (pst
-> objfile
-> global_psymbols
.next
203 == (pst
-> objfile
-> global_psymbols
.list
+ pst
->globals_offset
)
204 && pst
-> objfile
-> static_psymbols
.next
205 == (pst
-> objfile
-> static_psymbols
.list
+ pst
->statics_offset
)
206 && pst
->filename
&& pst
->filename
[0]
207 && pst
->filename
[strlen(pst
->filename
)-1] == '/') {
208 /* Just replace the directory name with the real filename. */
210 (char *) obstack_alloc (&pst
->objfile
->psymbol_obstack
,
211 strlen (namestring
) + 1);
212 strcpy (pst
->filename
, namestring
);
215 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
216 first_symnum
* symbol_size
, valu
,
217 dependency_list
, dependencies_used
);
218 pst
= (struct partial_symtab
*) 0;
220 dependencies_used
= 0;
223 past_first_source_file
= 1;
225 pst
= START_PSYMTAB (objfile
, addr
,
227 first_symnum
* symbol_size
,
228 objfile
-> global_psymbols
.next
,
229 objfile
-> static_psymbols
.next
);
235 /* Add this bincl to the bincl_list for future EXCLs. No
236 need to save the string; it'll be around until
237 read_dbx_symtab function returns */
241 add_bincl_to_list (pst
, namestring
, CUR_SYMBOL_VALUE
);
243 /* Mark down an include file in the current psymtab */
245 psymtab_include_list
[includes_used
++] = namestring
;
246 if (includes_used
>= includes_allocated
)
248 char **orig
= psymtab_include_list
;
250 psymtab_include_list
= (char **)
251 alloca ((includes_allocated
*= 2) *
253 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
254 includes_used
* sizeof (char *));
257 #endif /* DBXREAD_ONLY */
261 /* Mark down an include file in the current psymtab */
265 /* In C++, one may expect the same filename to come round many
266 times, when code is coming alternately from the main file
267 and from inline functions in other files. So I check to see
268 if this is a file we've seen before -- either the main
269 source file, or a previously included file.
271 This seems to be a lot of time to be spending on N_SOL, but
272 things like "break c-exp.y:435" need to work (I
273 suppose the psymtab_include_list could be hashed or put
274 in a binary tree, if profiling shows this is a major hog). */
275 if (pst
&& !strcmp (namestring
, pst
->filename
))
279 for (i
= 0; i
< includes_used
; i
++)
280 if (!strcmp (namestring
, psymtab_include_list
[i
]))
289 psymtab_include_list
[includes_used
++] = namestring
;
290 if (includes_used
>= includes_allocated
)
292 char **orig
= psymtab_include_list
;
294 psymtab_include_list
= (char **)
295 alloca ((includes_allocated
*= 2) *
297 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
298 includes_used
* sizeof (char *));
302 case N_LSYM
: /* Typedef or automatic variable. */
303 case N_STSYM
: /* Data seg var -- static */
304 case N_LCSYM
: /* BSS " */
305 case N_NBSTS
: /* Gould nobase. */
306 case N_NBLCS
: /* symbols. */
310 p
= (char *) strchr (namestring
, ':');
312 /* Skip if there is no :. */
318 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
319 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
320 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
323 /* Also a typedef with the same name. */
324 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
325 VAR_NAMESPACE
, LOC_TYPEDEF
,
326 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
331 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
332 VAR_NAMESPACE
, LOC_TYPEDEF
,
333 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
335 /* If this is an enumerated type, we need to
336 add all the enum constants to the partial symbol
337 table. This does not cover enums without names, e.g.
338 "enum {a, b} c;" in C, but fortunately those are
339 rare. There is no way for GDB to find those from the
340 enum type without spending too much time on it. Thus
341 to solve this problem, the compiler needs to put out separate
342 constant symbols ('c' N_LSYMS) for enum constants in
343 enums without names, or put out a dummy type. */
345 /* We are looking for something of the form
346 <name> ":" ("t" | "T") [<number> "="] "e"
347 {<constant> ":" <value> ","} ";". */
349 /* Skip over the colon and the 't' or 'T'. */
351 /* This type may be given a number. Also, numbers can come
352 in pairs like (0,26). Skip over it. */
353 while ((*p
>= '0' && *p
<= '9')
354 || *p
== '(' || *p
== ',' || *p
== ')'
360 /* We have found an enumerated type. */
361 /* According to comments in read_enum_type
362 a comma could end it instead of a semicolon.
363 I don't know where that happens.
365 while (*p
&& *p
!= ';' && *p
!= ',')
369 /* Check for and handle cretinous dbx symbol name
372 p
= next_symbol_text ();
374 /* Point to the character after the name
375 of the enum constant. */
376 for (q
= p
; *q
&& *q
!= ':'; q
++)
378 /* Note that the value doesn't matter for
379 enum constants in psymtabs, just in symtabs. */
380 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
381 VAR_NAMESPACE
, LOC_CONST
,
382 objfile
->static_psymbols
, 0);
383 /* Point past the name. */
385 /* Skip over the value. */
386 while (*p
&& *p
!= ',')
388 /* Advance past the comma. */
395 /* Constant, e.g. from "const" in Pascal. */
396 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
397 VAR_NAMESPACE
, LOC_CONST
,
398 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
401 /* Skip if the thing following the : is
402 not a letter (which indicates declaration of a local
403 variable, which we aren't interested in). */
408 case N_GSYM
: /* Global (extern) variable; can be
409 data or bss (sigh). */
411 /* Following may probably be ignored; I'll leave them here
412 for now (until I do Pascal and Modula 2 extensions). */
414 case N_PC
: /* I may or may not need this; I
416 case N_M2C
: /* I suspect that I can ignore this here. */
417 case N_SCOPE
: /* Same. */
421 p
= (char *) strchr (namestring
, ':');
423 continue; /* Not a debugging symbol. */
427 /* Main processing section for debugging symbols which
428 the initial read through the symbol tables needs to worry
429 about. If we reach this point, the symbol which we are
430 considering is definitely one we are interested in.
431 p must also contain the (valid) index into the namestring
432 which indicates the debugging type symbol. */
437 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
438 VAR_NAMESPACE
, LOC_CONST
,
439 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
442 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
443 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
444 VAR_NAMESPACE
, LOC_STATIC
,
445 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
448 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
449 /* The addresses in these entries are reported to be
450 wrong. See the code that reads 'G's for symtabs. */
451 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
452 VAR_NAMESPACE
, LOC_STATIC
,
453 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
457 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
458 VAR_NAMESPACE
, LOC_TYPEDEF
,
459 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
464 /* Kludges for ELF/STABS with Sun ACC */
465 last_function_name
= namestring
;
466 if (pst
->textlow
== 0)
467 pst
->textlow
= CUR_SYMBOL_VALUE
;
469 if (startup_file_end
== 0)
470 startup_file_end
= CUR_SYMBOL_VALUE
;
473 #endif /* DBXREAD_ONLY */
474 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
475 VAR_NAMESPACE
, LOC_BLOCK
,
476 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
479 /* Global functions were ignored here, but now they
480 are put into the global psymtab like one would expect.
481 They're also in the misc fn vector...
482 FIXME, why did it used to ignore these? That broke
483 "i fun" on these functions. */
486 /* Kludges for ELF/STABS with Sun ACC */
487 last_function_name
= namestring
;
488 if (pst
->textlow
== 0)
489 pst
->textlow
= CUR_SYMBOL_VALUE
;
491 if (startup_file_end
== 0)
492 startup_file_end
= CUR_SYMBOL_VALUE
;
495 #endif /* DBXREAD_ONLY */
496 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
497 VAR_NAMESPACE
, LOC_BLOCK
,
498 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
501 /* Two things show up here (hopefully); static symbols of
502 local scope (static used inside braces) or extensions
503 of structure symbols. We can ignore both. */
519 /* Unexpected symbol. Ignore it; perhaps it is an extension
520 that we don't know about.
522 Someone says sun cc puts out symbols like
523 /foo/baz/maclib::/usr/local/bin/maclib,
524 which would get here with a symbol type of ':'. */
533 /* Find the corresponding bincl and mark that psymtab on the
534 psymtab dependency list */
536 struct partial_symtab
*needed_pst
=
537 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
539 /* If this include file was defined earlier in this file,
541 if (needed_pst
== pst
) continue;
548 for (i
= 0; i
< dependencies_used
; i
++)
549 if (dependency_list
[i
] == needed_pst
)
555 /* If it's already in the list, skip the rest. */
558 dependency_list
[dependencies_used
++] = needed_pst
;
559 if (dependencies_used
>= dependencies_allocated
)
561 struct partial_symtab
**orig
= dependency_list
;
563 (struct partial_symtab
**)
564 alloca ((dependencies_allocated
*= 2)
565 * sizeof (struct partial_symtab
*));
566 memcpy ((PTR
)dependency_list
, (PTR
)orig
,
568 * sizeof (struct partial_symtab
*)));
570 fprintf (stderr
, "Had to reallocate dependency list.\n");
571 fprintf (stderr
, "New dependencies allocated: %d\n",
572 dependencies_allocated
);
577 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
580 #endif /* DBXREAD_ONLY */
585 HANDLE_RBRAC(CUR_SYMBOL_VALUE
);
591 case N_SSYM
: /* Claim: Structure or union element.
592 Hopefully, I can ignore this. */
593 case N_ENTRY
: /* Alternate entry point; can ignore. */
594 case N_MAIN
: /* Can definitely ignore this. */
595 case N_CATCH
: /* These are GNU C++ extensions */
596 case N_EHDECL
: /* that can safely be ignored here. */
606 case N_NSYMS
: /* Ultrix 4.0: symbol count */
607 case N_DEFD
: /* GNU Modula-2 */
609 case N_OBJ
: /* two useless types from Solaris */
611 /* These symbols aren't interesting; don't worry about them */
616 /* If we haven't found it yet, ignore it. It's probably some
617 new type we don't know about yet. */
618 complain (&unknown_symtype_complaint
, local_hex_string(CUR_SYMBOL_TYPE
));