* Makefile.in: Add stuff to build nlmstub.
[deliverable/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, 1994
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 /* Null name means end of .o file. Don't start a new one. */
221 if (*namestring == '\000')
222 continue;
223
224 /* Some compilers (including gcc) emit a pair of initial N_SOs.
225 The first one is a directory name; the second the file name.
226 If pst exists, is empty, and has a filename ending in '/',
227 we assume the previous N_SO was a directory name. */
228
229 p = strrchr (namestring, '/');
230 if (p && *(p+1) == '\000')
231 continue; /* Simply ignore directory name SOs */
232
233 /* Some other compilers (C++ ones in particular) emit useless
234 SOs for non-existant .c files. We ignore all subsequent SOs that
235 immediately follow the first. */
236
237 if (!pst)
238 pst = START_PSYMTAB (objfile, section_offsets,
239 namestring, valu,
240 first_so_symnum * symbol_size,
241 objfile -> global_psymbols.next,
242 objfile -> static_psymbols.next);
243 continue;
244 }
245
246 case N_BINCL:
247 {
248 #ifdef DBXREAD_ONLY
249 enum language tmp_language;
250 /* Add this bincl to the bincl_list for future EXCLs. No
251 need to save the string; it'll be around until
252 read_dbx_symtab function returns */
253
254 SET_NAMESTRING();
255
256 tmp_language = deduce_language_from_filename (namestring);
257
258 /* Only change the psymtab's language if we've learned
259 something useful (eg. tmp_language is not language_unknown).
260 In addition, to match what start_subfile does, never change
261 from C++ to C. */
262 if (tmp_language != language_unknown
263 && (tmp_language != language_c
264 || psymtab_language != language_cplus))
265 psymtab_language = tmp_language;
266
267 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
268
269 /* Mark down an include file in the current psymtab */
270
271 goto record_include_file;
272
273 #else /* DBXREAD_ONLY */
274 continue;
275 #endif
276 }
277
278 case N_SOL:
279 {
280 enum language tmp_language;
281 /* Mark down an include file in the current psymtab */
282
283 SET_NAMESTRING();
284
285 tmp_language = deduce_language_from_filename (namestring);
286
287 /* Only change the psymtab's language if we've learned
288 something useful (eg. tmp_language is not language_unknown).
289 In addition, to match what start_subfile does, never change
290 from C++ to C. */
291 if (tmp_language != language_unknown
292 && (tmp_language != language_c
293 || psymtab_language != language_cplus))
294 psymtab_language = tmp_language;
295
296 /* In C++, one may expect the same filename to come round many
297 times, when code is coming alternately from the main file
298 and from inline functions in other files. So I check to see
299 if this is a file we've seen before -- either the main
300 source file, or a previously included file.
301
302 This seems to be a lot of time to be spending on N_SOL, but
303 things like "break c-exp.y:435" need to work (I
304 suppose the psymtab_include_list could be hashed or put
305 in a binary tree, if profiling shows this is a major hog). */
306 if (pst && STREQ (namestring, pst->filename))
307 continue;
308 {
309 register int i;
310 for (i = 0; i < includes_used; i++)
311 if (STREQ (namestring, psymtab_include_list[i]))
312 {
313 i = -1;
314 break;
315 }
316 if (i == -1)
317 continue;
318 }
319
320 #ifdef DBXREAD_ONLY
321 record_include_file:
322 #endif
323
324 psymtab_include_list[includes_used++] = namestring;
325 if (includes_used >= includes_allocated)
326 {
327 char **orig = psymtab_include_list;
328
329 psymtab_include_list = (char **)
330 alloca ((includes_allocated *= 2) *
331 sizeof (char *));
332 memcpy ((PTR)psymtab_include_list, (PTR)orig,
333 includes_used * sizeof (char *));
334 }
335 continue;
336 }
337 case N_LSYM: /* Typedef or automatic variable. */
338 case N_STSYM: /* Data seg var -- static */
339 case N_LCSYM: /* BSS " */
340 case N_ROSYM: /* Read-only data seg var -- static. */
341 case N_NBSTS: /* Gould nobase. */
342 case N_NBLCS: /* symbols. */
343 case N_FUN:
344 case N_GSYM: /* Global (extern) variable; can be
345 data or bss (sigh FIXME). */
346
347 /* Following may probably be ignored; I'll leave them here
348 for now (until I do Pascal and Modula 2 extensions). */
349
350 case N_PC: /* I may or may not need this; I
351 suspect not. */
352 case N_M2C: /* I suspect that I can ignore this here. */
353 case N_SCOPE: /* Same. */
354
355 SET_NAMESTRING();
356
357 p = (char *) strchr (namestring, ':');
358 if (!p)
359 continue; /* Not a debugging symbol. */
360
361
362
363 /* Main processing section for debugging symbols which
364 the initial read through the symbol tables needs to worry
365 about. If we reach this point, the symbol which we are
366 considering is definitely one we are interested in.
367 p must also contain the (valid) index into the namestring
368 which indicates the debugging type symbol. */
369
370 switch (p[1])
371 {
372 case 'S':
373 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
374 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
375 VAR_NAMESPACE, LOC_STATIC,
376 objfile->static_psymbols,
377 CUR_SYMBOL_VALUE,
378 psymtab_language, objfile);
379 continue;
380 case 'G':
381 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
382 /* The addresses in these entries are reported to be
383 wrong. See the code that reads 'G's for symtabs. */
384 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
385 VAR_NAMESPACE, LOC_STATIC,
386 objfile->global_psymbols,
387 CUR_SYMBOL_VALUE,
388 psymtab_language, objfile);
389 continue;
390
391 case 'T':
392 if (p != namestring) /* a name is there, not just :T... */
393 {
394 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
395 STRUCT_NAMESPACE, LOC_TYPEDEF,
396 objfile->static_psymbols,
397 CUR_SYMBOL_VALUE,
398 psymtab_language, objfile);
399 if (p[2] == 't')
400 {
401 /* Also a typedef with the same name. */
402 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
403 VAR_NAMESPACE, LOC_TYPEDEF,
404 objfile->static_psymbols,
405 CUR_SYMBOL_VALUE, psymtab_language,
406 objfile);
407 p += 1;
408 }
409 /* The semantics of C++ state that "struct foo { ... }"
410 also defines a typedef for "foo". Unfortuantely, cfront
411 never makes the typedef when translating from C++ to C.
412 We make the typedef here so that "ptype foo" works as
413 expected for cfront translated code. */
414 else if (psymtab_language == language_cplus)
415 {
416 /* Also a typedef with the same name. */
417 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
418 VAR_NAMESPACE, LOC_TYPEDEF,
419 objfile->static_psymbols,
420 CUR_SYMBOL_VALUE, psymtab_language,
421 objfile);
422 }
423 }
424 goto check_enum;
425 case 't':
426 if (p != namestring) /* a name is there, not just :T... */
427 {
428 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
429 VAR_NAMESPACE, LOC_TYPEDEF,
430 objfile->static_psymbols,
431 CUR_SYMBOL_VALUE,
432 psymtab_language, objfile);
433 }
434 check_enum:
435 /* If this is an enumerated type, we need to
436 add all the enum constants to the partial symbol
437 table. This does not cover enums without names, e.g.
438 "enum {a, b} c;" in C, but fortunately those are
439 rare. There is no way for GDB to find those from the
440 enum type without spending too much time on it. Thus
441 to solve this problem, the compiler needs to put out the
442 enum in a nameless type. GCC2 does this. */
443
444 /* We are looking for something of the form
445 <name> ":" ("t" | "T") [<number> "="] "e"
446 {<constant> ":" <value> ","} ";". */
447
448 /* Skip over the colon and the 't' or 'T'. */
449 p += 2;
450 /* This type may be given a number. Also, numbers can come
451 in pairs like (0,26). Skip over it. */
452 while ((*p >= '0' && *p <= '9')
453 || *p == '(' || *p == ',' || *p == ')'
454 || *p == '=')
455 p++;
456
457 if (*p++ == 'e')
458 {
459 /* We have found an enumerated type. */
460 /* According to comments in read_enum_type
461 a comma could end it instead of a semicolon.
462 I don't know where that happens.
463 Accept either. */
464 while (*p && *p != ';' && *p != ',')
465 {
466 char *q;
467
468 /* Check for and handle cretinous dbx symbol name
469 continuation! */
470 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
471 p = next_symbol_text ();
472
473 /* Point to the character after the name
474 of the enum constant. */
475 for (q = p; *q && *q != ':'; q++)
476 ;
477 /* Note that the value doesn't matter for
478 enum constants in psymtabs, just in symtabs. */
479 ADD_PSYMBOL_TO_LIST (p, q - p,
480 VAR_NAMESPACE, LOC_CONST,
481 objfile->static_psymbols, 0,
482 psymtab_language, objfile);
483 /* Point past the name. */
484 p = q;
485 /* Skip over the value. */
486 while (*p && *p != ',')
487 p++;
488 /* Advance past the comma. */
489 if (*p)
490 p++;
491 }
492 }
493 continue;
494 case 'c':
495 /* Constant, e.g. from "const" in Pascal. */
496 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
497 VAR_NAMESPACE, LOC_CONST,
498 objfile->static_psymbols, CUR_SYMBOL_VALUE,
499 psymtab_language, objfile);
500 continue;
501
502 case 'f':
503 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
504 #ifdef DBXREAD_ONLY
505 /* Kludges for ELF/STABS with Sun ACC */
506 last_function_name = namestring;
507 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
508 value for the bottom of the text seg in those cases. */
509 if (pst && pst->textlow == 0 && !symfile_relocatable)
510 pst->textlow = CUR_SYMBOL_VALUE;
511 #if 0
512 if (startup_file_end == 0)
513 startup_file_end = CUR_SYMBOL_VALUE;
514 #endif
515 /* End kludge. */
516 #endif /* DBXREAD_ONLY */
517 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
518 VAR_NAMESPACE, LOC_BLOCK,
519 objfile->static_psymbols, CUR_SYMBOL_VALUE,
520 psymtab_language, objfile);
521 continue;
522
523 /* Global functions were ignored here, but now they
524 are put into the global psymtab like one would expect.
525 They're also in the minimal symbol table. */
526 case 'F':
527 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
528 #ifdef DBXREAD_ONLY
529 /* Kludges for ELF/STABS with Sun ACC */
530 last_function_name = namestring;
531 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
532 value for the bottom of the text seg in those cases. */
533 if (pst && pst->textlow == 0 && !symfile_relocatable)
534 pst->textlow = CUR_SYMBOL_VALUE;
535 #if 0
536 if (startup_file_end == 0)
537 startup_file_end = CUR_SYMBOL_VALUE;
538 #endif
539 /* End kludge. */
540 #endif /* DBXREAD_ONLY */
541 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
542 VAR_NAMESPACE, LOC_BLOCK,
543 objfile->global_psymbols, CUR_SYMBOL_VALUE,
544 psymtab_language, objfile);
545 continue;
546
547 /* Two things show up here (hopefully); static symbols of
548 local scope (static used inside braces) or extensions
549 of structure symbols. We can ignore both. */
550 case 'V':
551 case '(':
552 case '0':
553 case '1':
554 case '2':
555 case '3':
556 case '4':
557 case '5':
558 case '6':
559 case '7':
560 case '8':
561 case '9':
562 continue;
563
564 case ':':
565 /* It is a C++ nested symbol. We don't need to record it
566 (I don't think); if we try to look up foo::bar::baz,
567 then symbols for the symtab containing foo should get
568 read in, I think. */
569 /* Someone says sun cc puts out symbols like
570 /foo/baz/maclib::/usr/local/bin/maclib,
571 which would get here with a symbol type of ':'. */
572 continue;
573
574 default:
575 /* Unexpected symbol descriptor. The second and subsequent stabs
576 of a continued stab can show up here. The question is
577 whether they ever can mimic a normal stab--it would be
578 nice if not, since we certainly don't want to spend the
579 time searching to the end of every string looking for
580 a backslash. */
581
582 complain (&unknown_symchar_complaint, p[1]);
583
584 /* Ignore it; perhaps it is an extension that we don't
585 know about. */
586 continue;
587 }
588
589 case N_EXCL:
590 #ifdef DBXREAD_ONLY
591
592 SET_NAMESTRING();
593
594 /* Find the corresponding bincl and mark that psymtab on the
595 psymtab dependency list */
596 {
597 struct partial_symtab *needed_pst =
598 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
599
600 /* If this include file was defined earlier in this file,
601 leave it alone. */
602 if (needed_pst == pst) continue;
603
604 if (needed_pst)
605 {
606 int i;
607 int found = 0;
608
609 for (i = 0; i < dependencies_used; i++)
610 if (dependency_list[i] == needed_pst)
611 {
612 found = 1;
613 break;
614 }
615
616 /* If it's already in the list, skip the rest. */
617 if (found) continue;
618
619 dependency_list[dependencies_used++] = needed_pst;
620 if (dependencies_used >= dependencies_allocated)
621 {
622 struct partial_symtab **orig = dependency_list;
623 dependency_list =
624 (struct partial_symtab **)
625 alloca ((dependencies_allocated *= 2)
626 * sizeof (struct partial_symtab *));
627 memcpy ((PTR)dependency_list, (PTR)orig,
628 (dependencies_used
629 * sizeof (struct partial_symtab *)));
630 #ifdef DEBUG_INFO
631 fprintf_unfiltered (gdb_stderr, "Had to reallocate dependency list.\n");
632 fprintf_unfiltered (gdb_stderr, "New dependencies allocated: %d\n",
633 dependencies_allocated);
634 #endif
635 }
636 }
637 else
638 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
639 symnum);
640 }
641 #endif /* DBXREAD_ONLY */
642 continue;
643
644 case N_RBRAC:
645 #ifdef HANDLE_RBRAC
646 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
647 continue;
648 #endif
649 case N_EINCL:
650 case N_DSLINE:
651 case N_BSLINE:
652 case N_SSYM: /* Claim: Structure or union element.
653 Hopefully, I can ignore this. */
654 case N_ENTRY: /* Alternate entry point; can ignore. */
655 case N_MAIN: /* Can definitely ignore this. */
656 case N_CATCH: /* These are GNU C++ extensions */
657 case N_EHDECL: /* that can safely be ignored here. */
658 case N_LENG:
659 case N_BCOMM:
660 case N_ECOMM:
661 case N_ECOML:
662 case N_FNAME:
663 case N_SLINE:
664 case N_RSYM:
665 case N_PSYM:
666 case N_LBRAC:
667 case N_NSYMS: /* Ultrix 4.0: symbol count */
668 case N_DEFD: /* GNU Modula-2 */
669
670 case N_OBJ: /* useless types from Solaris */
671 case N_OPT:
672 case N_ENDM:
673 /* These symbols aren't interesting; don't worry about them */
674
675 continue;
676
677 default:
678 /* If we haven't found it yet, ignore it. It's probably some
679 new type we don't know about yet. */
680 complain (&unknown_symtype_complaint,
681 local_hex_string (CUR_SYMBOL_TYPE));
682 continue;
683 }
This page took 0.04549 seconds and 5 git commands to generate.