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. If we want to use the
142 n_strx field, which contains the name of the file,
143 we must adjust file_string_table_offset *before* calling
145 past_first_source_file
= 1;
146 file_string_table_offset
= next_file_string_table_offset
;
147 next_file_string_table_offset
=
148 file_string_table_offset
+ bufp
->n_value
;
149 if (next_file_string_table_offset
< file_string_table_offset
)
150 error ("string table offset backs up at %d", symnum
);
151 /* FIXME -- replace error() with complaint. */
154 #endif /* DBXREAD_ONLY */
157 /* Lots of symbol types we can just ignore. */
165 /* Keep going . . .*/
168 * Special symbol types for GNU
188 unsigned long valu
= CUR_SYMBOL_VALUE
;
189 static int last_so_symnum
= -10;
190 static int dir_so_symnum
= -1;
194 /* End the current partial symtab and start a new one */
198 valu
+= addr
; /* Relocate */
200 /* Some compilers (including gcc) emit a pair of initial N_SOs.
201 The first one is a directory name; the second the file name.
202 If pst exists, is empty, and has a filename ending in '/',
203 we assume the previous N_SO was a directory name. */
205 p
= strrchr (namestring
, '/');
206 if (p
&& *(p
+1) == '\000')
208 dir_so_symnum
= symnum
;
209 continue; /* Simply ignore directory name SOs */
212 /* Some other compilers (C++ ones in particular) emit useless
213 SOs for non-existant .c files. */
215 if (last_so_symnum
== symnum
- 1)
216 continue; /* Ignore repeated SOs */
217 last_so_symnum
= symnum
;
221 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
222 symnum
* symbol_size
, valu
,
223 dependency_list
, dependencies_used
);
224 pst
= (struct partial_symtab
*) 0;
226 dependencies_used
= 0;
229 past_first_source_file
= 1;
231 if (dir_so_symnum
== symnum
- 1) /* Was prev. SO a directory? */
235 pst
= START_PSYMTAB (objfile
, addr
,
238 objfile
-> global_psymbols
.next
,
239 objfile
-> static_psymbols
.next
);
246 /* Add this bincl to the bincl_list for future EXCLs. No
247 need to save the string; it'll be around until
248 read_dbx_symtab function returns */
252 add_bincl_to_list (pst
, namestring
, CUR_SYMBOL_VALUE
);
254 /* Mark down an include file in the current psymtab */
256 psymtab_include_list
[includes_used
++] = namestring
;
257 if (includes_used
>= includes_allocated
)
259 char **orig
= psymtab_include_list
;
261 psymtab_include_list
= (char **)
262 alloca ((includes_allocated
*= 2) *
264 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
265 includes_used
* sizeof (char *));
268 #endif /* DBXREAD_ONLY */
272 /* Mark down an include file in the current psymtab */
276 /* In C++, one may expect the same filename to come round many
277 times, when code is coming alternately from the main file
278 and from inline functions in other files. So I check to see
279 if this is a file we've seen before -- either the main
280 source file, or a previously included file.
282 This seems to be a lot of time to be spending on N_SOL, but
283 things like "break c-exp.y:435" need to work (I
284 suppose the psymtab_include_list could be hashed or put
285 in a binary tree, if profiling shows this is a major hog). */
286 if (pst
&& !strcmp (namestring
, pst
->filename
))
290 for (i
= 0; i
< includes_used
; i
++)
291 if (!strcmp (namestring
, psymtab_include_list
[i
]))
300 psymtab_include_list
[includes_used
++] = namestring
;
301 if (includes_used
>= includes_allocated
)
303 char **orig
= psymtab_include_list
;
305 psymtab_include_list
= (char **)
306 alloca ((includes_allocated
*= 2) *
308 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
309 includes_used
* sizeof (char *));
313 case N_LSYM
: /* Typedef or automatic variable. */
314 case N_STSYM
: /* Data seg var -- static */
315 case N_LCSYM
: /* BSS " */
316 case N_NBSTS
: /* Gould nobase. */
317 case N_NBLCS
: /* symbols. */
321 p
= (char *) strchr (namestring
, ':');
323 /* Skip if there is no :. */
329 if (p
!= namestring
) /* a name is there, not just :T... */
331 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
332 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
333 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
336 /* Also a typedef with the same name. */
337 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
338 VAR_NAMESPACE
, LOC_TYPEDEF
,
339 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
345 if (p
!= namestring
) /* a name is there, not just :T... */
347 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
348 VAR_NAMESPACE
, LOC_TYPEDEF
,
349 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
352 /* If this is an enumerated type, we need to
353 add all the enum constants to the partial symbol
354 table. This does not cover enums without names, e.g.
355 "enum {a, b} c;" in C, but fortunately those are
356 rare. There is no way for GDB to find those from the
357 enum type without spending too much time on it. Thus
358 to solve this problem, the compiler needs to put out separate
359 constant symbols ('c' N_LSYMS) for enum constants in
360 enums without names, or put out a dummy type. */
362 /* We are looking for something of the form
363 <name> ":" ("t" | "T") [<number> "="] "e"
364 {<constant> ":" <value> ","} ";". */
366 /* Skip over the colon and the 't' or 'T'. */
368 /* This type may be given a number. Also, numbers can come
369 in pairs like (0,26). Skip over it. */
370 while ((*p
>= '0' && *p
<= '9')
371 || *p
== '(' || *p
== ',' || *p
== ')'
377 /* We have found an enumerated type. */
378 /* According to comments in read_enum_type
379 a comma could end it instead of a semicolon.
380 I don't know where that happens.
382 while (*p
&& *p
!= ';' && *p
!= ',')
386 /* Check for and handle cretinous dbx symbol name
389 p
= next_symbol_text ();
391 /* Point to the character after the name
392 of the enum constant. */
393 for (q
= p
; *q
&& *q
!= ':'; q
++)
395 /* Note that the value doesn't matter for
396 enum constants in psymtabs, just in symtabs. */
397 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
398 VAR_NAMESPACE
, LOC_CONST
,
399 objfile
->static_psymbols
, 0);
400 /* Point past the name. */
402 /* Skip over the value. */
403 while (*p
&& *p
!= ',')
405 /* Advance past the comma. */
412 /* Constant, e.g. from "const" in Pascal. */
413 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
414 VAR_NAMESPACE
, LOC_CONST
,
415 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
418 /* Skip if the thing following the : is
419 not a letter (which indicates declaration of a local
420 variable, which we aren't interested in). */
425 case N_GSYM
: /* Global (extern) variable; can be
426 data or bss (sigh). */
428 /* Following may probably be ignored; I'll leave them here
429 for now (until I do Pascal and Modula 2 extensions). */
431 case N_PC
: /* I may or may not need this; I
433 case N_M2C
: /* I suspect that I can ignore this here. */
434 case N_SCOPE
: /* Same. */
438 p
= (char *) strchr (namestring
, ':');
440 continue; /* Not a debugging symbol. */
444 /* Main processing section for debugging symbols which
445 the initial read through the symbol tables needs to worry
446 about. If we reach this point, the symbol which we are
447 considering is definitely one we are interested in.
448 p must also contain the (valid) index into the namestring
449 which indicates the debugging type symbol. */
454 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
455 VAR_NAMESPACE
, LOC_CONST
,
456 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
459 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
460 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
461 VAR_NAMESPACE
, LOC_STATIC
,
462 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
465 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
466 /* The addresses in these entries are reported to be
467 wrong. See the code that reads 'G's for symtabs. */
468 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
469 VAR_NAMESPACE
, LOC_STATIC
,
470 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
474 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
475 VAR_NAMESPACE
, LOC_TYPEDEF
,
476 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
481 /* Kludges for ELF/STABS with Sun ACC */
482 last_function_name
= namestring
;
483 if (pst
->textlow
== 0)
484 pst
->textlow
= CUR_SYMBOL_VALUE
;
486 if (startup_file_end
== 0)
487 startup_file_end
= CUR_SYMBOL_VALUE
;
490 #endif /* DBXREAD_ONLY */
491 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
492 VAR_NAMESPACE
, LOC_BLOCK
,
493 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
496 /* Global functions were ignored here, but now they
497 are put into the global psymtab like one would expect.
498 They're also in the misc fn vector...
499 FIXME, why did it used to ignore these? That broke
500 "i fun" on these functions. */
503 /* Kludges for ELF/STABS with Sun ACC */
504 last_function_name
= namestring
;
505 if (pst
->textlow
== 0)
506 pst
->textlow
= CUR_SYMBOL_VALUE
;
508 if (startup_file_end
== 0)
509 startup_file_end
= CUR_SYMBOL_VALUE
;
512 #endif /* DBXREAD_ONLY */
513 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
514 VAR_NAMESPACE
, LOC_BLOCK
,
515 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
518 /* Two things show up here (hopefully); static symbols of
519 local scope (static used inside braces) or extensions
520 of structure symbols. We can ignore both. */
536 /* Unexpected symbol. Ignore it; perhaps it is an extension
537 that we don't know about.
539 Someone says sun cc puts out symbols like
540 /foo/baz/maclib::/usr/local/bin/maclib,
541 which would get here with a symbol type of ':'. */
550 /* Find the corresponding bincl and mark that psymtab on the
551 psymtab dependency list */
553 struct partial_symtab
*needed_pst
=
554 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
556 /* If this include file was defined earlier in this file,
558 if (needed_pst
== pst
) continue;
565 for (i
= 0; i
< dependencies_used
; i
++)
566 if (dependency_list
[i
] == needed_pst
)
572 /* If it's already in the list, skip the rest. */
575 dependency_list
[dependencies_used
++] = needed_pst
;
576 if (dependencies_used
>= dependencies_allocated
)
578 struct partial_symtab
**orig
= dependency_list
;
580 (struct partial_symtab
**)
581 alloca ((dependencies_allocated
*= 2)
582 * sizeof (struct partial_symtab
*));
583 memcpy ((PTR
)dependency_list
, (PTR
)orig
,
585 * sizeof (struct partial_symtab
*)));
587 fprintf (stderr
, "Had to reallocate dependency list.\n");
588 fprintf (stderr
, "New dependencies allocated: %d\n",
589 dependencies_allocated
);
594 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
597 #endif /* DBXREAD_ONLY */
602 HANDLE_RBRAC(CUR_SYMBOL_VALUE
);
608 case N_SSYM
: /* Claim: Structure or union element.
609 Hopefully, I can ignore this. */
610 case N_ENTRY
: /* Alternate entry point; can ignore. */
611 case N_MAIN
: /* Can definitely ignore this. */
612 case N_CATCH
: /* These are GNU C++ extensions */
613 case N_EHDECL
: /* that can safely be ignored here. */
623 case N_NSYMS
: /* Ultrix 4.0: symbol count */
624 case N_DEFD
: /* GNU Modula-2 */
626 case N_OBJ
: /* two useless types from Solaris */
628 /* These symbols aren't interesting; don't worry about them */
633 /* If we haven't found it yet, ignore it. It's probably some
634 new type we don't know about yet. */
635 complain (&unknown_symtype_complaint
, local_hex_string(CUR_SYMBOL_TYPE
));