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 /* some cooperation from gcc to get around ld stupidity */
76 || (namestring
[0] == 'e' && !strcmp (namestring
, "end_file."))
81 if (objfile
-> ei
.entry_point
< CUR_SYMBOL_VALUE
&&
82 objfile
-> ei
.entry_point
>= last_o_file_start
&&
83 addr
== 0) /* FIXME nogood nomore */
85 objfile
-> ei
.entry_file_lowpc
= last_o_file_start
;
86 objfile
-> ei
.entry_file_highpc
= CUR_SYMBOL_VALUE
;
89 if (past_first_source_file
&& pst
90 /* The gould NP1 uses low values for .o and -l symbols
91 which are not the address. */
92 && CUR_SYMBOL_VALUE
>= pst
->textlow
)
94 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
95 symnum
* symbol_size
, CUR_SYMBOL_VALUE
,
96 dependency_list
, dependencies_used
);
97 pst
= (struct partial_symtab
*) 0;
99 dependencies_used
= 0;
102 past_first_source_file
= 1;
103 last_o_file_start
= CUR_SYMBOL_VALUE
;
105 #endif /* DBXREAD_ONLY */
110 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
112 /* Check for __DYNAMIC, which is used by Sun shared libraries.
113 Record it even if it's local, not global, so we can find it.
114 Same with virtual function tables, both global and static. */
115 if ((namestring
[8] == 'C' && (strcmp ("__DYNAMIC", namestring
) == 0))
116 || VTBL_PREFIX_P ((namestring
+HASH_OFFSET
)))
118 /* Not really a function here, but... */
119 record_minimal_symbol (namestring
, CUR_SYMBOL_VALUE
,
120 CUR_SYMBOL_TYPE
, objfile
); /* Always */
122 #endif /* DBXREAD_ONLY */
127 if (CUR_SYMBOL_VALUE
!= 0) {
128 /* This is a "Fortran COMMON" symbol. See if the target
129 environment knows where it has been relocated to. */
134 if (target_lookup_symbol (namestring
, &reladdr
)) {
135 continue; /* Error in lookup; ignore symbol for now. */
137 CUR_SYMBOL_TYPE
^= (N_BSS
^N_UNDF
); /* Define it as a bss-symbol */
138 CUR_SYMBOL_VALUE
= reladdr
;
141 #endif /* DBXREAD_ONLY */
142 continue; /* Just undefined, not COMMON */
146 if (processing_acc_compilation
&& bufp
->n_strx
== 1) {
147 /* Deal with relative offsets in the string table
148 used in ELF+STAB under Solaris. If we want to use the
149 n_strx field, which contains the name of the file,
150 we must adjust file_string_table_offset *before* calling
152 past_first_source_file
= 1;
153 file_string_table_offset
= next_file_string_table_offset
;
154 next_file_string_table_offset
=
155 file_string_table_offset
+ bufp
->n_value
;
156 if (next_file_string_table_offset
< file_string_table_offset
)
157 error ("string table offset backs up at %d", symnum
);
158 /* FIXME -- replace error() with complaint. */
161 #endif /* DBXREAD_ONLY */
164 /* Lots of symbol types we can just ignore. */
172 /* Keep going . . .*/
175 * Special symbol types for GNU
195 unsigned long valu
= CUR_SYMBOL_VALUE
;
196 static int last_so_symnum
= -10;
197 static int dir_so_symnum
= -1;
201 /* End the current partial symtab and start a new one */
205 valu
+= addr
; /* Relocate */
209 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
210 symnum
* symbol_size
, valu
,
211 dependency_list
, dependencies_used
);
212 pst
= (struct partial_symtab
*) 0;
214 dependencies_used
= 0;
217 /* Some compilers (including gcc) emit a pair of initial N_SOs.
218 The first one is a directory name; the second the file name.
219 If pst exists, is empty, and has a filename ending in '/',
220 we assume the previous N_SO was a directory name. */
222 p
= strrchr (namestring
, '/');
223 if (p
&& *(p
+1) == '\000')
225 dir_so_symnum
= symnum
;
226 continue; /* Simply ignore directory name SOs */
229 /* Some other compilers (C++ ones in particular) emit useless
230 SOs for non-existant .c files. */
232 if (last_so_symnum
== symnum
- 1)
233 continue; /* Ignore repeated SOs */
234 last_so_symnum
= symnum
;
236 past_first_source_file
= 1;
238 if (dir_so_symnum
== symnum
- 1) /* Was prev. SO a directory? */
242 pst
= START_PSYMTAB (objfile
, addr
,
245 objfile
-> global_psymbols
.next
,
246 objfile
-> static_psymbols
.next
);
253 /* Add this bincl to the bincl_list for future EXCLs. No
254 need to save the string; it'll be around until
255 read_dbx_symtab function returns */
259 add_bincl_to_list (pst
, namestring
, CUR_SYMBOL_VALUE
);
261 /* Mark down an include file in the current psymtab */
263 psymtab_include_list
[includes_used
++] = namestring
;
264 if (includes_used
>= includes_allocated
)
266 char **orig
= psymtab_include_list
;
268 psymtab_include_list
= (char **)
269 alloca ((includes_allocated
*= 2) *
271 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
272 includes_used
* sizeof (char *));
275 #endif /* DBXREAD_ONLY */
279 /* Mark down an include file in the current psymtab */
283 /* In C++, one may expect the same filename to come round many
284 times, when code is coming alternately from the main file
285 and from inline functions in other files. So I check to see
286 if this is a file we've seen before -- either the main
287 source file, or a previously included file.
289 This seems to be a lot of time to be spending on N_SOL, but
290 things like "break c-exp.y:435" need to work (I
291 suppose the psymtab_include_list could be hashed or put
292 in a binary tree, if profiling shows this is a major hog). */
293 if (pst
&& !strcmp (namestring
, pst
->filename
))
297 for (i
= 0; i
< includes_used
; i
++)
298 if (!strcmp (namestring
, psymtab_include_list
[i
]))
307 psymtab_include_list
[includes_used
++] = namestring
;
308 if (includes_used
>= includes_allocated
)
310 char **orig
= psymtab_include_list
;
312 psymtab_include_list
= (char **)
313 alloca ((includes_allocated
*= 2) *
315 memcpy ((PTR
)psymtab_include_list
, (PTR
)orig
,
316 includes_used
* sizeof (char *));
320 case N_LSYM
: /* Typedef or automatic variable. */
321 case N_STSYM
: /* Data seg var -- static */
322 case N_LCSYM
: /* BSS " */
323 case N_NBSTS
: /* Gould nobase. */
324 case N_NBLCS
: /* symbols. */
328 p
= (char *) strchr (namestring
, ':');
330 /* Skip if there is no :. */
336 if (p
!= namestring
) /* a name is there, not just :T... */
338 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
339 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
340 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
343 /* Also a typedef with the same name. */
344 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
345 VAR_NAMESPACE
, LOC_TYPEDEF
,
346 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
352 if (p
!= namestring
) /* a name is there, not just :T... */
354 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
355 VAR_NAMESPACE
, LOC_TYPEDEF
,
356 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
359 /* If this is an enumerated type, we need to
360 add all the enum constants to the partial symbol
361 table. This does not cover enums without names, e.g.
362 "enum {a, b} c;" in C, but fortunately those are
363 rare. There is no way for GDB to find those from the
364 enum type without spending too much time on it. Thus
365 to solve this problem, the compiler needs to put out separate
366 constant symbols ('c' N_LSYMS) for enum constants in
367 enums without names, or put out a dummy type. */
369 /* We are looking for something of the form
370 <name> ":" ("t" | "T") [<number> "="] "e"
371 {<constant> ":" <value> ","} ";". */
373 /* Skip over the colon and the 't' or 'T'. */
375 /* This type may be given a number. Also, numbers can come
376 in pairs like (0,26). Skip over it. */
377 while ((*p
>= '0' && *p
<= '9')
378 || *p
== '(' || *p
== ',' || *p
== ')'
384 /* We have found an enumerated type. */
385 /* According to comments in read_enum_type
386 a comma could end it instead of a semicolon.
387 I don't know where that happens.
389 while (*p
&& *p
!= ';' && *p
!= ',')
393 /* Check for and handle cretinous dbx symbol name
396 p
= next_symbol_text ();
398 /* Point to the character after the name
399 of the enum constant. */
400 for (q
= p
; *q
&& *q
!= ':'; q
++)
402 /* Note that the value doesn't matter for
403 enum constants in psymtabs, just in symtabs. */
404 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
405 VAR_NAMESPACE
, LOC_CONST
,
406 objfile
->static_psymbols
, 0);
407 /* Point past the name. */
409 /* Skip over the value. */
410 while (*p
&& *p
!= ',')
412 /* Advance past the comma. */
419 /* Constant, e.g. from "const" in Pascal. */
420 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
421 VAR_NAMESPACE
, LOC_CONST
,
422 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
425 /* Skip if the thing following the : is
426 not a letter (which indicates declaration of a local
427 variable, which we aren't interested in). */
432 case N_GSYM
: /* Global (extern) variable; can be
433 data or bss (sigh). */
435 /* Following may probably be ignored; I'll leave them here
436 for now (until I do Pascal and Modula 2 extensions). */
438 case N_PC
: /* I may or may not need this; I
440 case N_M2C
: /* I suspect that I can ignore this here. */
441 case N_SCOPE
: /* Same. */
445 p
= (char *) strchr (namestring
, ':');
447 continue; /* Not a debugging symbol. */
451 /* Main processing section for debugging symbols which
452 the initial read through the symbol tables needs to worry
453 about. If we reach this point, the symbol which we are
454 considering is definitely one we are interested in.
455 p must also contain the (valid) index into the namestring
456 which indicates the debugging type symbol. */
461 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
462 VAR_NAMESPACE
, LOC_CONST
,
463 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
466 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
467 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
468 VAR_NAMESPACE
, LOC_STATIC
,
469 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
472 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
473 /* The addresses in these entries are reported to be
474 wrong. See the code that reads 'G's for symtabs. */
475 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
476 VAR_NAMESPACE
, LOC_STATIC
,
477 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
481 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
482 VAR_NAMESPACE
, LOC_TYPEDEF
,
483 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
488 /* Kludges for ELF/STABS with Sun ACC */
489 last_function_name
= namestring
;
490 if (pst
->textlow
== 0)
491 pst
->textlow
= CUR_SYMBOL_VALUE
;
493 if (startup_file_end
== 0)
494 startup_file_end
= CUR_SYMBOL_VALUE
;
497 #endif /* DBXREAD_ONLY */
498 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
499 VAR_NAMESPACE
, LOC_BLOCK
,
500 objfile
->static_psymbols
, CUR_SYMBOL_VALUE
);
503 /* Global functions were ignored here, but now they
504 are put into the global psymtab like one would expect.
505 They're also in the misc fn vector...
506 FIXME, why did it used to ignore these? That broke
507 "i fun" on these functions. */
510 /* Kludges for ELF/STABS with Sun ACC */
511 last_function_name
= namestring
;
512 if (pst
->textlow
== 0)
513 pst
->textlow
= CUR_SYMBOL_VALUE
;
515 if (startup_file_end
== 0)
516 startup_file_end
= CUR_SYMBOL_VALUE
;
519 #endif /* DBXREAD_ONLY */
520 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
521 VAR_NAMESPACE
, LOC_BLOCK
,
522 objfile
->global_psymbols
, CUR_SYMBOL_VALUE
);
525 /* Two things show up here (hopefully); static symbols of
526 local scope (static used inside braces) or extensions
527 of structure symbols. We can ignore both. */
543 /* Unexpected symbol. Ignore it; perhaps it is an extension
544 that we don't know about.
546 Someone says sun cc puts out symbols like
547 /foo/baz/maclib::/usr/local/bin/maclib,
548 which would get here with a symbol type of ':'. */
557 /* Find the corresponding bincl and mark that psymtab on the
558 psymtab dependency list */
560 struct partial_symtab
*needed_pst
=
561 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
563 /* If this include file was defined earlier in this file,
565 if (needed_pst
== pst
) continue;
572 for (i
= 0; i
< dependencies_used
; i
++)
573 if (dependency_list
[i
] == needed_pst
)
579 /* If it's already in the list, skip the rest. */
582 dependency_list
[dependencies_used
++] = needed_pst
;
583 if (dependencies_used
>= dependencies_allocated
)
585 struct partial_symtab
**orig
= dependency_list
;
587 (struct partial_symtab
**)
588 alloca ((dependencies_allocated
*= 2)
589 * sizeof (struct partial_symtab
*));
590 memcpy ((PTR
)dependency_list
, (PTR
)orig
,
592 * sizeof (struct partial_symtab
*)));
594 fprintf (stderr
, "Had to reallocate dependency list.\n");
595 fprintf (stderr
, "New dependencies allocated: %d\n",
596 dependencies_allocated
);
601 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
604 #endif /* DBXREAD_ONLY */
609 HANDLE_RBRAC(CUR_SYMBOL_VALUE
);
615 case N_SSYM
: /* Claim: Structure or union element.
616 Hopefully, I can ignore this. */
617 case N_ENTRY
: /* Alternate entry point; can ignore. */
618 case N_MAIN
: /* Can definitely ignore this. */
619 case N_CATCH
: /* These are GNU C++ extensions */
620 case N_EHDECL
: /* that can safely be ignored here. */
630 case N_NSYMS
: /* Ultrix 4.0: symbol count */
631 case N_DEFD
: /* GNU Modula-2 */
633 case N_OBJ
: /* two useless types from Solaris */
635 /* These symbols aren't interesting; don't worry about them */
640 /* If we haven't found it yet, ignore it. It's probably some
641 new type we don't know about yet. */
642 complain (&unknown_symtype_complaint
, local_hex_string(CUR_SYMBOL_TYPE
));