1 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* The following need to be defined:
21 SET_NAMESTRING() --Set namestring to name of symbol.
22 CUR_SYMBOL_TYPE --Type code of current symbol.
23 CUR_SYMBOL_VALUE --Value field of current symbol. May be adjusted here.
26 /* End of macro definitions, now let's handle them symbols! */
28 switch (CUR_SYMBOL_TYPE
)
32 * Standard, external, non-debugger, symbols
37 case N_NBTEXT
| N_EXT
:
38 case N_NBDATA
| N_EXT
:
45 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
50 record_misc_function (namestring
, CUR_SYMBOL_VALUE
,
51 CUR_SYMBOL_TYPE
); /* Always */
55 /* Standard, local, non-debugger, symbols */
59 /* We need to be able to deal with both N_FN or N_TEXT,
60 because we have no way of knowing whether the sys-supplied ld
61 or GNU ld was used to make the executable. Sequents throw
62 in another wrinkle -- they renumbered N_FN. */
67 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
69 if ((namestring
[0] == '-' && namestring
[1] == 'l')
70 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
71 && namestring
[nsl
- 2] == '.'))
73 if (entry_point
< CUR_SYMBOL_VALUE
74 && entry_point
>= last_o_file_start
75 && addr
== 0) /* FIXME nogood nomore */
77 startup_file_start
= last_o_file_start
;
78 startup_file_end
= CUR_SYMBOL_VALUE
;
80 if (past_first_source_file
&& pst
81 /* The gould NP1 uses low values for .o and -l symbols
82 which are not the address. */
83 && CUR_SYMBOL_VALUE
> pst
->textlow
)
85 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
86 symnum
* symbol_size
, CUR_SYMBOL_VALUE
,
87 dependency_list
, dependencies_used
);
88 pst
= (struct partial_symtab
*) 0;
90 dependencies_used
= 0;
93 past_first_source_file
= 1;
94 last_o_file_start
= CUR_SYMBOL_VALUE
;
99 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
101 /* Check for __DYNAMIC, which is used by Sun shared libraries.
102 Record it even if it's local, not global, so we can find it.
103 Same with virtual function tables, both global and static. */
104 if ((namestring
[8] == 'C' && (strcmp ("__DYNAMIC", namestring
) == 0))
105 || VTBL_PREFIX_P ((namestring
+HASH_OFFSET
)))
107 /* Not really a function here, but... */
108 record_misc_function (namestring
, CUR_SYMBOL_VALUE
,
109 CUR_SYMBOL_TYPE
); /* Always */
114 if (CUR_SYMBOL_VALUE
!= 0) {
115 /* This is a "Fortran COMMON" symbol. See if the target
116 environment knows where it has been relocated to. */
121 if (target_lookup_symbol (namestring
, &reladdr
)) {
122 continue; /* Error in lookup; ignore symbol for now. */
124 CUR_SYMBOL_TYPE
^= (N_BSS
^N_UNDF
); /* Define it as a bss-symbol */
125 CUR_SYMBOL_VALUE
= reladdr
;
128 continue; /* Just undefined, not COMMON */
131 /* Lots of symbol types we can just ignore. */
140 /* Keep going . . .*/
143 * Special symbol types for GNU
163 unsigned long valu
= CUR_SYMBOL_VALUE
;
164 /* Symbol number of the first symbol of this file (i.e. the N_SO
165 if there is just one, or the first if we have a pair). */
166 int first_symnum
= symnum
;
168 /* End the current partial symtab and start a new one */
172 /* Peek at the next symbol. If it is also an N_SO, the
173 first one just indicates the directory. */
175 valu
+= addr
; /* Relocate */
177 if (pst
&& past_first_source_file
)
179 END_PSYMTAB (pst
, psymtab_include_list
, includes_used
,
180 first_symnum
* symbol_size
, valu
,
181 dependency_list
, dependencies_used
);
182 pst
= (struct partial_symtab
*) 0;
184 dependencies_used
= 0;
187 past_first_source_file
= 1;
189 pst
= START_PSYMTAB (objfile
, addr
,
191 first_symnum
* symbol_size
,
192 global_psymbols
.next
, static_psymbols
.next
);
198 /* Add this bincl to the bincl_list for future EXCLs. No
199 need to save the string; it'll be around until
200 read_dbx_symtab function returns */
204 add_bincl_to_list (pst
, namestring
, CUR_SYMBOL_VALUE
);
206 /* Mark down an include file in the current psymtab */
208 psymtab_include_list
[includes_used
++] = namestring
;
209 if (includes_used
>= includes_allocated
)
211 char **orig
= psymtab_include_list
;
213 psymtab_include_list
= (char **)
214 alloca ((includes_allocated
*= 2) *
216 bcopy (orig
, psymtab_include_list
,
217 includes_used
* sizeof (char *));
224 /* Mark down an include file in the current psymtab */
228 /* In C++, one may expect the same filename to come round many
229 times, when code is coming alternately from the main file
230 and from inline functions in other files. So I check to see
231 if this is a file we've seen before -- either the main
232 source file, or a previously included file.
234 This seems to be a lot of time to be spending on N_SOL, but
235 things like "break c-exp.y:435" need to work (I
236 suppose the psymtab_include_list could be hashed or put
237 in a binary tree, if profiling shows this is a major hog). */
238 if (pst
&& !strcmp (namestring
, pst
->filename
))
242 for (i
= 0; i
< includes_used
; i
++)
243 if (!strcmp (namestring
, psymtab_include_list
[i
]))
252 psymtab_include_list
[includes_used
++] = namestring
;
253 if (includes_used
>= includes_allocated
)
255 char **orig
= psymtab_include_list
;
257 psymtab_include_list
= (char **)
258 alloca ((includes_allocated
*= 2) *
260 bcopy (orig
, psymtab_include_list
,
261 includes_used
* sizeof (char *));
264 case N_LSYM
: /* Typedef or automatic variable. */
265 case N_STSYM
: /* Data seg var -- static */
266 case N_LCSYM
: /* BSS " */
267 case N_NBSTS
: /* Gould nobase. */
268 case N_NBLCS
: /* symbols. */
272 p
= (char *) strchr (namestring
, ':');
274 /* Skip if there is no :. */
280 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
281 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
282 static_psymbols
, CUR_SYMBOL_VALUE
);
285 /* Also a typedef with the same name. */
286 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
287 VAR_NAMESPACE
, LOC_TYPEDEF
,
288 static_psymbols
, CUR_SYMBOL_VALUE
);
293 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
294 VAR_NAMESPACE
, LOC_TYPEDEF
,
295 static_psymbols
, CUR_SYMBOL_VALUE
);
298 /* If this is an enumerated type, we need to
299 add all the enum constants to the partial symbol
300 table. This does not cover enums without names, e.g.
301 "enum {a, b} c;" in C, but fortunately those are
302 rare. There is no way for GDB to find those from the
303 enum type without spending too much time on it. Thus
304 to solve this problem, the compiler needs to put out separate
305 constant symbols ('c' N_LSYMS) for enum constants in
306 enums without names, or put out a dummy type. */
308 /* We are looking for something of the form
309 <name> ":" ("t" | "T") [<number> "="] "e"
310 {<constant> ":" <value> ","} ";". */
312 /* Skip over the colon and the 't' or 'T'. */
314 /* This type may be given a number. Also, numbers can come
315 in pairs like (0,26). Skip over it. */
316 while ((*p
>= '0' && *p
<= '9')
317 || *p
== '(' || *p
== ',' || *p
== ')'
323 /* We have found an enumerated type. */
324 /* According to comments in read_enum_type
325 a comma could end it instead of a semicolon.
326 I don't know where that happens.
328 while (*p
&& *p
!= ';' && *p
!= ',')
332 /* Check for and handle cretinous dbx symbol name
335 p
= next_symbol_text ();
337 /* Point to the character after the name
338 of the enum constant. */
339 for (q
= p
; *q
&& *q
!= ':'; q
++)
341 /* Note that the value doesn't matter for
342 enum constants in psymtabs, just in symtabs. */
343 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
344 VAR_NAMESPACE
, LOC_CONST
,
346 /* Point past the name. */
348 /* Skip over the value. */
349 while (*p
&& *p
!= ',')
351 /* Advance past the comma. */
359 /* Constant, e.g. from "const" in Pascal. */
360 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
361 VAR_NAMESPACE
, LOC_CONST
,
362 static_psymbols
, CUR_SYMBOL_VALUE
);
365 /* Skip if the thing following the : is
366 not a letter (which indicates declaration of a local
367 variable, which we aren't interested in). */
372 case N_GSYM
: /* Global (extern) variable; can be
373 data or bss (sigh). */
375 /* Following may probably be ignored; I'll leave them here
376 for now (until I do Pascal and Modula 2 extensions). */
378 case N_PC
: /* I may or may not need this; I
380 case N_M2C
: /* I suspect that I can ignore this here. */
381 case N_SCOPE
: /* Same. */
385 p
= (char *) strchr (namestring
, ':');
387 continue; /* Not a debugging symbol. */
391 /* Main processing section for debugging symbols which
392 the initial read through the symbol tables needs to worry
393 about. If we reach this point, the symbol which we are
394 considering is definitely one we are interested in.
395 p must also contain the (valid) index into the namestring
396 which indicates the debugging type symbol. */
401 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
402 VAR_NAMESPACE
, LOC_CONST
,
403 static_psymbols
, CUR_SYMBOL_VALUE
);
406 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
407 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
408 VAR_NAMESPACE
, LOC_STATIC
,
409 static_psymbols
, CUR_SYMBOL_VALUE
);
412 CUR_SYMBOL_VALUE
+= addr
; /* Relocate */
413 /* The addresses in these entries are reported to be
414 wrong. See the code that reads 'G's for symtabs. */
415 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
416 VAR_NAMESPACE
, LOC_STATIC
,
417 global_psymbols
, CUR_SYMBOL_VALUE
);
421 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
422 VAR_NAMESPACE
, LOC_TYPEDEF
,
423 static_psymbols
, CUR_SYMBOL_VALUE
);
427 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
428 VAR_NAMESPACE
, LOC_BLOCK
,
429 static_psymbols
, CUR_SYMBOL_VALUE
);
432 /* Global functions were ignored here, but now they
433 are put into the global psymtab like one would expect.
434 They're also in the misc fn vector...
435 FIXME, why did it used to ignore these? That broke
436 "i fun" on these functions. */
438 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
439 VAR_NAMESPACE
, LOC_BLOCK
,
440 global_psymbols
, CUR_SYMBOL_VALUE
);
443 /* Two things show up here (hopefully); static symbols of
444 local scope (static used inside braces) or extensions
445 of structure symbols. We can ignore both. */
461 /* Unexpected symbol. Ignore it; perhaps it is an extension
462 that we don't know about.
464 Someone says sun cc puts out symbols like
465 /foo/baz/maclib::/usr/local/bin/maclib,
466 which would get here with a symbol type of ':'. */
475 /* Find the corresponding bincl and mark that psymtab on the
476 psymtab dependency list */
478 struct partial_symtab
*needed_pst
=
479 find_corresponding_bincl_psymtab (namestring
, CUR_SYMBOL_VALUE
);
481 /* If this include file was defined earlier in this file,
483 if (needed_pst
== pst
) continue;
490 for (i
= 0; i
< dependencies_used
; i
++)
491 if (dependency_list
[i
] == needed_pst
)
497 /* If it's already in the list, skip the rest. */
500 dependency_list
[dependencies_used
++] = needed_pst
;
501 if (dependencies_used
>= dependencies_allocated
)
503 struct partial_symtab
**orig
= dependency_list
;
505 (struct partial_symtab
**)
506 alloca ((dependencies_allocated
*= 2)
507 * sizeof (struct partial_symtab
*));
508 bcopy (orig
, dependency_list
,
510 * sizeof (struct partial_symtab
*)));
512 fprintf (stderr
, "Had to reallocate dependency list.\n");
513 fprintf (stderr
, "New dependencies allocated: %d\n",
514 dependencies_allocated
);
519 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
527 HANDLE_RBRAC(CUR_SYMBOL_VALUE
);
532 case N_SSYM
: /* Claim: Structure or union element.
533 Hopefully, I can ignore this. */
534 case N_ENTRY
: /* Alternate entry point; can ignore. */
535 case N_MAIN
: /* Can definitely ignore this. */
536 case N_CATCH
: /* These are GNU C++ extensions */
537 case N_EHDECL
: /* that can safely be ignored here. */
547 case N_NSYMS
: /* Ultrix 4.0: symbol count */
548 case N_DEFD
: /* GNU Modula-2 */
549 /* These symbols aren't interesting; don't worry about them */
555 /* If we haven't found it yet, ignore it. It's probably some
556 new type we don't know about yet. */
557 complain (&unknown_symtype_complaint
, local_hex_string(CUR_SYMBOL_TYPE
));