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 */
137 /* Lots of symbol types we can just ignore. */
146 /* Keep going . . .*/
149 * Special symbol types for GNU
169 unsigned long valu
= CUR_SYMBOL_VALUE
;
170 /* Symbol number of the first symbol of this file (i.e. the N_SO
171 if there is just one, or the first if we have a pair). */
172 int first_symnum
= symnum
;
174 /* End the current partial symtab and start a new one */
178 valu
+= addr
; /* Relocate */
180 if (pst
&& past_first_source_file
)
182 /* Some compilers (including gcc) emit a pair of initial N_SOs.
183 The first one is a directory name; the second the file name.
184 If pst exists, is empty, and has a filename ending in '/',
185 we assume the previous N_SO was a directory name. */
186 if (pst
-> objfile
-> global_psymbols
.next
187 == (pst
-> objfile
-> global_psymbols
.list
+ pst
->globals_offset
)
188 && pst
-> objfile
-> static_psymbols
.next
189 == (pst
-> objfile
-> static_psymbols
.list
+ pst
->statics_offset
)
190 && pst
->filename
&& pst
->filename
[0]
191 && pst
->filename
[strlen(pst
->filename
)-1] == '/') {
192 /* Just replace the directory name with the real filename. */
194 (char *) obstack_alloc (&pst
->objfile
->psymbol_obstack
,
195 strlen (namestring
) + 1);
196 strcpy (pst
->filename
, namestring
);
199 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
200 first_symnum
* symbol_size
, valu
,
201 dependency_list
, dependencies_used
);
202 pst
= (struct partial_symtab
*) 0;
204 dependencies_used
= 0;
207 past_first_source_file
= 1;
209 pst
= START_PSYMTAB (objfile
, addr
,
211 first_symnum
* symbol_size
,
212 objfile
-> global_psymbols
.next
,
213 objfile
-> static_psymbols
.next
);
219 /* Add this bincl to the bincl_list for future EXCLs. No
220 need to save the string; it'll be around until
221 read_dbx_symtab function returns */
225 add_bincl_to_list (pst
, namestring
, CUR_SYMBOL_VALUE
);
227 /* Mark down an include file in the current psymtab */
229 psymtab_include_list
[includes_used
++] = namestring
;
230 if (includes_used
>= includes_allocated
)
232 char **orig
= psymtab_include_list
;
234 psymtab_include_list
= (char **)
235 alloca ((includes_allocated
*= 2) *
237 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
238 includes_used
* sizeof (char *));
241 #endif /* DBXREAD_ONLY */
245 /* Mark down an include file in the current psymtab */
249 /* In C++, one may expect the same filename to come round many
250 times, when code is coming alternately from the main file
251 and from inline functions in other files. So I check to see
252 if this is a file we've seen before -- either the main
253 source file, or a previously included file.
255 This seems to be a lot of time to be spending on N_SOL, but
256 things like "break c-exp.y:435" need to work (I
257 suppose the psymtab_include_list could be hashed or put
258 in a binary tree, if profiling shows this is a major hog). */
259 if (pst
&& !strcmp (namestring
, pst
->filename
))
263 for (i
= 0; i
< includes_used
; i
++)
264 if (!strcmp (namestring
, psymtab_include_list
[i
]))
273 psymtab_include_list
[includes_used
++] = namestring
;
274 if (includes_used
>= includes_allocated
)
276 char **orig
= psymtab_include_list
;
278 psymtab_include_list
= (char **)
279 alloca ((includes_allocated
*= 2) *
281 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
282 includes_used
* sizeof (char *));
286 case N_LSYM
: /* Typedef or automatic variable. */
287 case N_STSYM
: /* Data seg var -- static */
288 case N_LCSYM
: /* BSS " */
289 case N_NBSTS
: /* Gould nobase. */
290 case N_NBLCS
: /* symbols. */
294 p
= (char *) strchr (namestring
, ':');
296 /* Skip if there is no :. */
302 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
303 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
304 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
307 /* Also a typedef with the same name. */
308 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
309 VAR_NAMESPACE
, LOC_TYPEDEF
,
310 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
315 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
316 VAR_NAMESPACE
, LOC_TYPEDEF
,
317 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
319 /* If this is an enumerated type, we need to
320 add all the enum constants to the partial symbol
321 table. This does not cover enums without names, e.g.
322 "enum {a, b} c;" in C, but fortunately those are
323 rare. There is no way for GDB to find those from the
324 enum type without spending too much time on it. Thus
325 to solve this problem, the compiler needs to put out separate
326 constant symbols ('c' N_LSYMS) for enum constants in
327 enums without names, or put out a dummy type. */
329 /* We are looking for something of the form
330 <name> ":" ("t" | "T") [<number> "="] "e"
331 {<constant> ":" <value> ","} ";". */
333 /* Skip over the colon and the 't' or 'T'. */
335 /* This type may be given a number. Also, numbers can come
336 in pairs like (0,26). Skip over it. */
337 while ((*p
>= '0' && *p
<= '9')
338 || *p
== '(' || *p
== ',' || *p
== ')'
344 /* We have found an enumerated type. */
345 /* According to comments in read_enum_type
346 a comma could end it instead of a semicolon.
347 I don't know where that happens.
349 while (*p
&& *p
!= ';' && *p
!= ',')
353 /* Check for and handle cretinous dbx symbol name
356 p
= next_symbol_text ();
358 /* Point to the character after the name
359 of the enum constant. */
360 for (q
= p
; *q
&& *q
!= ':'; q
++)
362 /* Note that the value doesn't matter for
363 enum constants in psymtabs, just in symtabs. */
364 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
365 VAR_NAMESPACE
, LOC_CONST
,
366 objfile
->static_psymbols
, 0);
367 /* Point past the name. */
369 /* Skip over the value. */
370 while (*p
&& *p
!= ',')
372 /* Advance past the comma. */
379 /* Constant, e.g. from "const" in Pascal. */
380 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
381 VAR_NAMESPACE
, LOC_CONST
,
382 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
385 /* Skip if the thing following the : is
386 not a letter (which indicates declaration of a local
387 variable, which we aren't interested in). */
392 case N_GSYM
: /* Global (extern) variable; can be
393 data or bss (sigh). */
395 /* Following may probably be ignored; I'll leave them here
396 for now (until I do Pascal and Modula 2 extensions). */
398 case N_PC
: /* I may or may not need this; I
400 case N_M2C
: /* I suspect that I can ignore this here. */
401 case N_SCOPE
: /* Same. */
405 p
= (char *) strchr (namestring
, ':');
407 continue; /* Not a debugging symbol. */
411 /* Main processing section for debugging symbols which
412 the initial read through the symbol tables needs to worry
413 about. If we reach this point, the symbol which we are
414 considering is definitely one we are interested in.
415 p must also contain the (valid) index into the namestring
416 which indicates the debugging type symbol. */
421 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
422 VAR_NAMESPACE
, LOC_CONST
,
423 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
426 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
427 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
428 VAR_NAMESPACE
, LOC_STATIC
,
429 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
432 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
433 /* The addresses in these entries are reported to be
434 wrong. See the code that reads 'G's for symtabs. */
435 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
436 VAR_NAMESPACE
, LOC_STATIC
,
437 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
441 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
442 VAR_NAMESPACE
, LOC_TYPEDEF
,
443 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
447 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
448 VAR_NAMESPACE
, LOC_BLOCK
,
449 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
452 /* Global functions were ignored here, but now they
453 are put into the global psymtab like one would expect.
454 They're also in the misc fn vector...
455 FIXME, why did it used to ignore these? That broke
456 "i fun" on these functions. */
458 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
459 VAR_NAMESPACE
, LOC_BLOCK
,
460 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
463 /* Two things show up here (hopefully); static symbols of
464 local scope (static used inside braces) or extensions
465 of structure symbols. We can ignore both. */
481 /* Unexpected symbol. Ignore it; perhaps it is an extension
482 that we don't know about.
484 Someone says sun cc puts out symbols like
485 /foo/baz/maclib::/usr/local/bin/maclib,
486 which would get here with a symbol type of ':'. */
495 /* Find the corresponding bincl and mark that psymtab on the
496 psymtab dependency list */
498 struct partial_symtab
*needed_pst
=
499 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
501 /* If this include file was defined earlier in this file,
503 if (needed_pst
== pst
) continue;
510 for (i
= 0; i
< dependencies_used
; i
++)
511 if (dependency_list
[i
] == needed_pst
)
517 /* If it's already in the list, skip the rest. */
520 dependency_list
[dependencies_used
++] = needed_pst
;
521 if (dependencies_used
>= dependencies_allocated
)
523 struct partial_symtab
**orig
= dependency_list
;
525 (struct partial_symtab
**)
526 alloca ((dependencies_allocated
*= 2)
527 * sizeof (struct partial_symtab
*));
528 memcpy ((PTR
)dependency_list
, (PTR
)orig
,
530 * sizeof (struct partial_symtab
*)));
532 fprintf (stderr
, "Had to reallocate dependency list.\n");
533 fprintf (stderr
, "New dependencies allocated: %d\n",
534 dependencies_allocated
);
539 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
542 #endif /* DBXREAD_ONLY */
547 HANDLE_RBRAC(CUR_SYMBOL_VALUE
);
553 case N_SSYM
: /* Claim: Structure or union element.
554 Hopefully, I can ignore this. */
555 case N_ENTRY
: /* Alternate entry point; can ignore. */
556 case N_MAIN
: /* Can definitely ignore this. */
557 case N_CATCH
: /* These are GNU C++ extensions */
558 case N_EHDECL
: /* that can safely be ignored here. */
568 case N_NSYMS
: /* Ultrix 4.0: symbol count */
569 case N_DEFD
: /* GNU Modula-2 */
570 /* These symbols aren't interesting; don't worry about them */
575 /* If we haven't found it yet, ignore it. It's probably some
576 new type we don't know about yet. */
577 complain (&unknown_symtype_complaint
, local_hex_string(CUR_SYMBOL_TYPE
));