]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/partial-stab.h
* symtab.h (enum minimal_symbol_type): Add mst_file_*.
[thirdparty/binutils-gdb.git] / gdb / partial-stab.h
1 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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. */
20
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.
25 */
26
27 /* End of macro definitions, now let's handle them symbols! */
28
29 switch (CUR_SYMBOL_TYPE)
30 {
31 char *p;
32 /*
33 * Standard, external, non-debugger, symbols
34 */
35
36 case N_TEXT | N_EXT:
37 case N_NBTEXT | N_EXT:
38 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
39 goto record_it;
40
41 case N_DATA | N_EXT:
42 case N_NBDATA | N_EXT:
43 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
44 goto record_it;
45
46 case N_BSS:
47 case N_BSS | N_EXT:
48 case N_NBBSS | N_EXT:
49 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
50 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_BSS);
51 goto record_it;
52
53 case N_ABS | N_EXT:
54 record_it:
55 #ifdef DBXREAD_ONLY
56 SET_NAMESTRING();
57
58 bss_ext_symbol:
59 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
60 CUR_SYMBOL_TYPE, objfile); /* Always */
61 #endif /* DBXREAD_ONLY */
62 continue;
63
64 /* Standard, local, non-debugger, symbols */
65
66 case N_NBTEXT:
67
68 /* We need to be able to deal with both N_FN or N_TEXT,
69 because we have no way of knowing whether the sys-supplied ld
70 or GNU ld was used to make the executable. Sequents throw
71 in another wrinkle -- they renumbered N_FN. */
72
73 case N_FN:
74 case N_FN_SEQ:
75 case N_TEXT:
76 #ifdef DBXREAD_ONLY
77 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
78 SET_NAMESTRING();
79 if ((namestring[0] == '-' && namestring[1] == 'l')
80 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
81 && namestring [nsl - 2] == '.')
82 #ifdef GDB_TARGET_IS_HPPA
83 /* some cooperation from gcc to get around ld stupidity */
84 || (namestring[0] == 'e' && STREQ (namestring, "end_file."))
85 #endif
86 )
87 {
88 #ifndef GDB_TARGET_IS_HPPA
89 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
90 objfile -> ei.entry_point >= last_o_file_start)
91 {
92 objfile -> ei.entry_file_lowpc = last_o_file_start;
93 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
94 }
95 #endif
96 if (past_first_source_file && pst
97 /* The gould NP1 uses low values for .o and -l symbols
98 which are not the address. */
99 && CUR_SYMBOL_VALUE >= pst->textlow)
100 {
101 END_PSYMTAB (pst, psymtab_include_list, includes_used,
102 symnum * symbol_size, CUR_SYMBOL_VALUE,
103 dependency_list, dependencies_used);
104 pst = (struct partial_symtab *) 0;
105 includes_used = 0;
106 dependencies_used = 0;
107 }
108 else
109 past_first_source_file = 1;
110 last_o_file_start = CUR_SYMBOL_VALUE;
111 }
112 else
113 goto record_it;
114 #endif /* DBXREAD_ONLY */
115 continue;
116
117 case N_DATA:
118 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
119 goto record_it;
120
121 case N_UNDF | N_EXT:
122 #ifdef DBXREAD_ONLY
123 if (CUR_SYMBOL_VALUE != 0) {
124 /* This is a "Fortran COMMON" symbol. See if the target
125 environment knows where it has been relocated to. */
126
127 CORE_ADDR reladdr;
128
129 SET_NAMESTRING();
130 if (target_lookup_symbol (namestring, &reladdr)) {
131 continue; /* Error in lookup; ignore symbol for now. */
132 }
133 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
134 CUR_SYMBOL_VALUE = reladdr;
135 goto bss_ext_symbol;
136 }
137 #endif /* DBXREAD_ONLY */
138 continue; /* Just undefined, not COMMON */
139
140 case N_UNDF:
141 #ifdef DBXREAD_ONLY
142 if (processing_acc_compilation && bufp->n_strx == 1) {
143 /* Deal with relative offsets in the string table
144 used in ELF+STAB under Solaris. If we want to use the
145 n_strx field, which contains the name of the file,
146 we must adjust file_string_table_offset *before* calling
147 SET_NAMESTRING(). */
148 past_first_source_file = 1;
149 file_string_table_offset = next_file_string_table_offset;
150 next_file_string_table_offset =
151 file_string_table_offset + bufp->n_value;
152 if (next_file_string_table_offset < file_string_table_offset)
153 error ("string table offset backs up at %d", symnum);
154 /* FIXME -- replace error() with complaint. */
155 continue;
156 }
157 #endif /* DBXREAD_ONLY */
158 continue;
159
160 /* Lots of symbol types we can just ignore. */
161
162 case N_ABS:
163 case N_NBDATA:
164 case N_NBBSS:
165 continue;
166
167 /* Keep going . . .*/
168
169 /*
170 * Special symbol types for GNU
171 */
172 case N_INDR:
173 case N_INDR | N_EXT:
174 case N_SETA:
175 case N_SETA | N_EXT:
176 case N_SETT:
177 case N_SETT | N_EXT:
178 case N_SETD:
179 case N_SETD | N_EXT:
180 case N_SETB:
181 case N_SETB | N_EXT:
182 case N_SETV:
183 continue;
184
185 /*
186 * Debugger symbols
187 */
188
189 case N_SO: {
190 unsigned long valu;
191 static int prev_so_symnum = -10;
192 static int first_so_symnum;
193 char *p;
194
195 valu = CUR_SYMBOL_VALUE + ANOFFSET (section_offsets, SECT_OFF_TEXT);
196
197 past_first_source_file = 1;
198
199 if (prev_so_symnum != symnum - 1)
200 { /* Here if prev stab wasn't N_SO */
201 first_so_symnum = symnum;
202
203 if (pst)
204 {
205 END_PSYMTAB (pst, psymtab_include_list, includes_used,
206 symnum * symbol_size, valu,
207 dependency_list, dependencies_used);
208 pst = (struct partial_symtab *) 0;
209 includes_used = 0;
210 dependencies_used = 0;
211 }
212 }
213
214 prev_so_symnum = symnum;
215
216 /* End the current partial symtab and start a new one */
217
218 SET_NAMESTRING();
219
220 /* Some compilers (including gcc) emit a pair of initial N_SOs.
221 The first one is a directory name; the second the file name.
222 If pst exists, is empty, and has a filename ending in '/',
223 we assume the previous N_SO was a directory name. */
224
225 p = strrchr (namestring, '/');
226 if (p && *(p+1) == '\000')
227 continue; /* Simply ignore directory name SOs */
228
229 /* Some other compilers (C++ ones in particular) emit useless
230 SOs for non-existant .c files. We ignore all subsequent SOs that
231 immediately follow the first. */
232
233 if (!pst)
234 pst = START_PSYMTAB (objfile, section_offsets,
235 namestring, valu,
236 first_so_symnum * symbol_size,
237 objfile -> global_psymbols.next,
238 objfile -> static_psymbols.next);
239 continue;
240 }
241
242 case N_BINCL:
243 #ifdef DBXREAD_ONLY
244 /* Add this bincl to the bincl_list for future EXCLs. No
245 need to save the string; it'll be around until
246 read_dbx_symtab function returns */
247
248 SET_NAMESTRING();
249
250 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
251
252 /* Mark down an include file in the current psymtab */
253
254 goto record_include_file;
255
256 #else /* DBXREAD_ONLY */
257 continue;
258 #endif
259
260 case N_SOL:
261 /* Mark down an include file in the current psymtab */
262
263 SET_NAMESTRING();
264
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.
270
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 && STREQ (namestring, pst->filename))
276 continue;
277 {
278 register int i;
279 for (i = 0; i < includes_used; i++)
280 if (STREQ (namestring, psymtab_include_list[i]))
281 {
282 i = -1;
283 break;
284 }
285 if (i == -1)
286 continue;
287 }
288
289 record_include_file:
290
291 psymtab_include_list[includes_used++] = namestring;
292 if (includes_used >= includes_allocated)
293 {
294 char **orig = psymtab_include_list;
295
296 psymtab_include_list = (char **)
297 alloca ((includes_allocated *= 2) *
298 sizeof (char *));
299 memcpy ((PTR)psymtab_include_list, (PTR)orig,
300 includes_used * sizeof (char *));
301 }
302 continue;
303
304 case N_LSYM: /* Typedef or automatic variable. */
305 case N_STSYM: /* Data seg var -- static */
306 case N_LCSYM: /* BSS " */
307 case N_ROSYM: /* Read-only data seg var -- static. */
308 case N_NBSTS: /* Gould nobase. */
309 case N_NBLCS: /* symbols. */
310 case N_FUN:
311 case N_GSYM: /* Global (extern) variable; can be
312 data or bss (sigh FIXME). */
313
314 /* Following may probably be ignored; I'll leave them here
315 for now (until I do Pascal and Modula 2 extensions). */
316
317 case N_PC: /* I may or may not need this; I
318 suspect not. */
319 case N_M2C: /* I suspect that I can ignore this here. */
320 case N_SCOPE: /* Same. */
321
322 SET_NAMESTRING();
323
324 p = (char *) strchr (namestring, ':');
325 if (!p)
326 continue; /* Not a debugging symbol. */
327
328
329
330 /* Main processing section for debugging symbols which
331 the initial read through the symbol tables needs to worry
332 about. If we reach this point, the symbol which we are
333 considering is definitely one we are interested in.
334 p must also contain the (valid) index into the namestring
335 which indicates the debugging type symbol. */
336
337 switch (p[1])
338 {
339 case 'S':
340 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
341 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
342 VAR_NAMESPACE, LOC_STATIC,
343 objfile->static_psymbols,
344 CUR_SYMBOL_VALUE,
345 psymtab_language, objfile);
346 continue;
347 case 'G':
348 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
349 /* The addresses in these entries are reported to be
350 wrong. See the code that reads 'G's for symtabs. */
351 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
352 VAR_NAMESPACE, LOC_STATIC,
353 objfile->global_psymbols,
354 CUR_SYMBOL_VALUE,
355 psymtab_language, objfile);
356 continue;
357
358 case 'T':
359 if (p != namestring) /* a name is there, not just :T... */
360 {
361 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
362 STRUCT_NAMESPACE, LOC_TYPEDEF,
363 objfile->static_psymbols,
364 CUR_SYMBOL_VALUE,
365 psymtab_language, objfile);
366 if (p[2] == 't')
367 {
368 /* Also a typedef with the same name. */
369 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
370 VAR_NAMESPACE, LOC_TYPEDEF,
371 objfile->static_psymbols,
372 CUR_SYMBOL_VALUE, psymtab_language,
373 objfile);
374 p += 1;
375 }
376 }
377 goto check_enum;
378 case 't':
379 if (p != namestring) /* a name is there, not just :T... */
380 {
381 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
382 VAR_NAMESPACE, LOC_TYPEDEF,
383 objfile->static_psymbols,
384 CUR_SYMBOL_VALUE,
385 psymtab_language, objfile);
386 }
387 check_enum:
388 /* If this is an enumerated type, we need to
389 add all the enum constants to the partial symbol
390 table. This does not cover enums without names, e.g.
391 "enum {a, b} c;" in C, but fortunately those are
392 rare. There is no way for GDB to find those from the
393 enum type without spending too much time on it. Thus
394 to solve this problem, the compiler needs to put out the
395 enum in a nameless type. GCC2 does this. */
396
397 /* We are looking for something of the form
398 <name> ":" ("t" | "T") [<number> "="] "e"
399 {<constant> ":" <value> ","} ";". */
400
401 /* Skip over the colon and the 't' or 'T'. */
402 p += 2;
403 /* This type may be given a number. Also, numbers can come
404 in pairs like (0,26). Skip over it. */
405 while ((*p >= '0' && *p <= '9')
406 || *p == '(' || *p == ',' || *p == ')'
407 || *p == '=')
408 p++;
409
410 if (*p++ == 'e')
411 {
412 /* We have found an enumerated type. */
413 /* According to comments in read_enum_type
414 a comma could end it instead of a semicolon.
415 I don't know where that happens.
416 Accept either. */
417 while (*p && *p != ';' && *p != ',')
418 {
419 char *q;
420
421 /* Check for and handle cretinous dbx symbol name
422 continuation! */
423 if (*p == '\\')
424 p = next_symbol_text ();
425
426 /* Point to the character after the name
427 of the enum constant. */
428 for (q = p; *q && *q != ':'; q++)
429 ;
430 /* Note that the value doesn't matter for
431 enum constants in psymtabs, just in symtabs. */
432 ADD_PSYMBOL_TO_LIST (p, q - p,
433 VAR_NAMESPACE, LOC_CONST,
434 objfile->static_psymbols, 0,
435 psymtab_language, objfile);
436 /* Point past the name. */
437 p = q;
438 /* Skip over the value. */
439 while (*p && *p != ',')
440 p++;
441 /* Advance past the comma. */
442 if (*p)
443 p++;
444 }
445 }
446 continue;
447 case 'c':
448 /* Constant, e.g. from "const" in Pascal. */
449 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
450 VAR_NAMESPACE, LOC_CONST,
451 objfile->static_psymbols, CUR_SYMBOL_VALUE,
452 psymtab_language, objfile);
453 continue;
454
455 case 'f':
456 #ifdef DBXREAD_ONLY
457 /* Kludges for ELF/STABS with Sun ACC */
458 last_function_name = namestring;
459 if (pst && pst->textlow == 0)
460 pst->textlow = CUR_SYMBOL_VALUE;
461 #if 0
462 if (startup_file_end == 0)
463 startup_file_end = CUR_SYMBOL_VALUE;
464 #endif
465 /* End kludge. */
466 #endif /* DBXREAD_ONLY */
467 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
468 VAR_NAMESPACE, LOC_BLOCK,
469 objfile->static_psymbols, CUR_SYMBOL_VALUE,
470 psymtab_language, objfile);
471 continue;
472
473 /* Global functions were ignored here, but now they
474 are put into the global psymtab like one would expect.
475 They're also in the minimal symbol table. */
476 case 'F':
477 #ifdef DBXREAD_ONLY
478 /* Kludges for ELF/STABS with Sun ACC */
479 last_function_name = namestring;
480 if (pst && pst->textlow == 0)
481 pst->textlow = CUR_SYMBOL_VALUE;
482 #if 0
483 if (startup_file_end == 0)
484 startup_file_end = CUR_SYMBOL_VALUE;
485 #endif
486 /* End kludge. */
487 #endif /* DBXREAD_ONLY */
488 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
489 VAR_NAMESPACE, LOC_BLOCK,
490 objfile->global_psymbols, CUR_SYMBOL_VALUE,
491 psymtab_language, objfile);
492 continue;
493
494 /* Two things show up here (hopefully); static symbols of
495 local scope (static used inside braces) or extensions
496 of structure symbols. We can ignore both. */
497 case 'V':
498 case '(':
499 case '0':
500 case '1':
501 case '2':
502 case '3':
503 case '4':
504 case '5':
505 case '6':
506 case '7':
507 case '8':
508 case '9':
509 continue;
510
511 default:
512 /* Unexpected symbol. Ignore it; perhaps it is an extension
513 that we don't know about.
514
515 Someone says sun cc puts out symbols like
516 /foo/baz/maclib::/usr/local/bin/maclib,
517 which would get here with a symbol type of ':'. */
518 complain (&unknown_symchar_complaint, p[1]);
519 continue;
520 }
521
522 case N_EXCL:
523 #ifdef DBXREAD_ONLY
524
525 SET_NAMESTRING();
526
527 /* Find the corresponding bincl and mark that psymtab on the
528 psymtab dependency list */
529 {
530 struct partial_symtab *needed_pst =
531 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
532
533 /* If this include file was defined earlier in this file,
534 leave it alone. */
535 if (needed_pst == pst) continue;
536
537 if (needed_pst)
538 {
539 int i;
540 int found = 0;
541
542 for (i = 0; i < dependencies_used; i++)
543 if (dependency_list[i] == needed_pst)
544 {
545 found = 1;
546 break;
547 }
548
549 /* If it's already in the list, skip the rest. */
550 if (found) continue;
551
552 dependency_list[dependencies_used++] = needed_pst;
553 if (dependencies_used >= dependencies_allocated)
554 {
555 struct partial_symtab **orig = dependency_list;
556 dependency_list =
557 (struct partial_symtab **)
558 alloca ((dependencies_allocated *= 2)
559 * sizeof (struct partial_symtab *));
560 memcpy ((PTR)dependency_list, (PTR)orig,
561 (dependencies_used
562 * sizeof (struct partial_symtab *)));
563 #ifdef DEBUG_INFO
564 fprintf (stderr, "Had to reallocate dependency list.\n");
565 fprintf (stderr, "New dependencies allocated: %d\n",
566 dependencies_allocated);
567 #endif
568 }
569 }
570 else
571 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
572 symnum);
573 }
574 #endif /* DBXREAD_ONLY */
575 continue;
576
577 case N_RBRAC:
578 #ifdef HANDLE_RBRAC
579 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
580 continue;
581 #endif
582 case N_EINCL:
583 case N_DSLINE:
584 case N_BSLINE:
585 case N_SSYM: /* Claim: Structure or union element.
586 Hopefully, I can ignore this. */
587 case N_ENTRY: /* Alternate entry point; can ignore. */
588 case N_MAIN: /* Can definitely ignore this. */
589 case N_CATCH: /* These are GNU C++ extensions */
590 case N_EHDECL: /* that can safely be ignored here. */
591 case N_LENG:
592 case N_BCOMM:
593 case N_ECOMM:
594 case N_ECOML:
595 case N_FNAME:
596 case N_SLINE:
597 case N_RSYM:
598 case N_PSYM:
599 case N_LBRAC:
600 case N_NSYMS: /* Ultrix 4.0: symbol count */
601 case N_DEFD: /* GNU Modula-2 */
602
603 case N_OBJ: /* useless types from Solaris */
604 case N_OPT:
605 case N_ENDM:
606 /* These symbols aren't interesting; don't worry about them */
607
608 continue;
609
610 default:
611 /* If we haven't found it yet, ignore it. It's probably some
612 new type we don't know about yet. */
613 complain (&unknown_symtype_complaint,
614 local_hex_string (CUR_SYMBOL_TYPE));
615 continue;
616 }