* corelow.c, exec.c, inftarg.c, m3-nat.c, op50-rom.c, procfs.c,
[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 )
83 {
84 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
85 objfile -> ei.entry_point >= last_o_file_start)
86 {
87 objfile -> ei.entry_file_lowpc = last_o_file_start;
88 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
89 }
90 if (past_first_source_file && pst
91 /* The gould NP1 uses low values for .o and -l symbols
92 which are not the address. */
93 && CUR_SYMBOL_VALUE >= pst->textlow)
94 {
95 END_PSYMTAB (pst, psymtab_include_list, includes_used,
96 symnum * symbol_size, CUR_SYMBOL_VALUE,
97 dependency_list, dependencies_used);
98 pst = (struct partial_symtab *) 0;
99 includes_used = 0;
100 dependencies_used = 0;
101 }
102 else
103 past_first_source_file = 1;
104 last_o_file_start = CUR_SYMBOL_VALUE;
105 }
106 else
107 goto record_it;
108 #endif /* DBXREAD_ONLY */
109 continue;
110
111 case N_DATA:
112 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
113 goto record_it;
114
115 case N_UNDF | N_EXT:
116 #ifdef DBXREAD_ONLY
117 if (CUR_SYMBOL_VALUE != 0) {
118 /* This is a "Fortran COMMON" symbol. See if the target
119 environment knows where it has been relocated to. */
120
121 CORE_ADDR reladdr;
122
123 SET_NAMESTRING();
124 if (target_lookup_symbol (namestring, &reladdr)) {
125 continue; /* Error in lookup; ignore symbol for now. */
126 }
127 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
128 CUR_SYMBOL_VALUE = reladdr;
129 goto bss_ext_symbol;
130 }
131 #endif /* DBXREAD_ONLY */
132 continue; /* Just undefined, not COMMON */
133
134 case N_UNDF:
135 #ifdef DBXREAD_ONLY
136 if (processing_acc_compilation && bufp->n_strx == 1) {
137 /* Deal with relative offsets in the string table
138 used in ELF+STAB under Solaris. If we want to use the
139 n_strx field, which contains the name of the file,
140 we must adjust file_string_table_offset *before* calling
141 SET_NAMESTRING(). */
142 past_first_source_file = 1;
143 file_string_table_offset = next_file_string_table_offset;
144 next_file_string_table_offset =
145 file_string_table_offset + bufp->n_value;
146 if (next_file_string_table_offset < file_string_table_offset)
147 error ("string table offset backs up at %d", symnum);
148 /* FIXME -- replace error() with complaint. */
149 continue;
150 }
151 #endif /* DBXREAD_ONLY */
152 continue;
153
154 /* Lots of symbol types we can just ignore. */
155
156 case N_ABS:
157 case N_NBDATA:
158 case N_NBBSS:
159 continue;
160
161 /* Keep going . . .*/
162
163 /*
164 * Special symbol types for GNU
165 */
166 case N_INDR:
167 case N_INDR | N_EXT:
168 case N_SETA:
169 case N_SETA | N_EXT:
170 case N_SETT:
171 case N_SETT | N_EXT:
172 case N_SETD:
173 case N_SETD | N_EXT:
174 case N_SETB:
175 case N_SETB | N_EXT:
176 case N_SETV:
177 continue;
178
179 /*
180 * Debugger symbols
181 */
182
183 case N_SO: {
184 unsigned long valu;
185 static int prev_so_symnum = -10;
186 static int first_so_symnum;
187 char *p;
188
189 valu = CUR_SYMBOL_VALUE + ANOFFSET (section_offsets, SECT_OFF_TEXT);
190
191 past_first_source_file = 1;
192
193 if (prev_so_symnum != symnum - 1)
194 { /* Here if prev stab wasn't N_SO */
195 first_so_symnum = symnum;
196
197 if (pst)
198 {
199 END_PSYMTAB (pst, psymtab_include_list, includes_used,
200 symnum * symbol_size, valu,
201 dependency_list, dependencies_used);
202 pst = (struct partial_symtab *) 0;
203 includes_used = 0;
204 dependencies_used = 0;
205 }
206 }
207
208 prev_so_symnum = symnum;
209
210 /* End the current partial symtab and start a new one */
211
212 SET_NAMESTRING();
213
214 /* Null name means end of .o file. Don't start a new one. */
215 if (*namestring == '\000')
216 continue;
217
218 /* Some compilers (including gcc) emit a pair of initial N_SOs.
219 The first one is a directory name; the second the file name.
220 If pst exists, is empty, and has a filename ending in '/',
221 we assume the previous N_SO was a directory name. */
222
223 p = strrchr (namestring, '/');
224 if (p && *(p+1) == '\000')
225 continue; /* Simply ignore directory name SOs */
226
227 /* Some other compilers (C++ ones in particular) emit useless
228 SOs for non-existant .c files. We ignore all subsequent SOs that
229 immediately follow the first. */
230
231 if (!pst)
232 pst = START_PSYMTAB (objfile, section_offsets,
233 namestring, valu,
234 first_so_symnum * symbol_size,
235 objfile -> global_psymbols.next,
236 objfile -> static_psymbols.next);
237 continue;
238 }
239
240 case N_BINCL:
241 {
242 #ifdef DBXREAD_ONLY
243 enum language tmp_language;
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 tmp_language = deduce_language_from_filename (namestring);
251
252 /* Only change the psymtab's language if we've learned
253 something useful (eg. tmp_language is not language_unknown).
254 In addition, to match what start_subfile does, never change
255 from C++ to C. */
256 if (tmp_language != language_unknown
257 && (tmp_language != language_c
258 || psymtab_language != language_cplus))
259 psymtab_language = tmp_language;
260
261 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
262
263 /* Mark down an include file in the current psymtab */
264
265 goto record_include_file;
266
267 #else /* DBXREAD_ONLY */
268 continue;
269 #endif
270 }
271
272 case N_SOL:
273 {
274 enum language tmp_language;
275 /* Mark down an include file in the current psymtab */
276
277 SET_NAMESTRING();
278
279 tmp_language = deduce_language_from_filename (namestring);
280
281 /* Only change the psymtab's language if we've learned
282 something useful (eg. tmp_language is not language_unknown).
283 In addition, to match what start_subfile does, never change
284 from C++ to C. */
285 if (tmp_language != language_unknown
286 && (tmp_language != language_c
287 || psymtab_language != language_cplus))
288 psymtab_language = tmp_language;
289
290 /* In C++, one may expect the same filename to come round many
291 times, when code is coming alternately from the main file
292 and from inline functions in other files. So I check to see
293 if this is a file we've seen before -- either the main
294 source file, or a previously included file.
295
296 This seems to be a lot of time to be spending on N_SOL, but
297 things like "break c-exp.y:435" need to work (I
298 suppose the psymtab_include_list could be hashed or put
299 in a binary tree, if profiling shows this is a major hog). */
300 if (pst && STREQ (namestring, pst->filename))
301 continue;
302 {
303 register int i;
304 for (i = 0; i < includes_used; i++)
305 if (STREQ (namestring, psymtab_include_list[i]))
306 {
307 i = -1;
308 break;
309 }
310 if (i == -1)
311 continue;
312 }
313
314 #ifdef DBXREAD_ONLY
315 record_include_file:
316 #endif
317
318 psymtab_include_list[includes_used++] = namestring;
319 if (includes_used >= includes_allocated)
320 {
321 char **orig = psymtab_include_list;
322
323 psymtab_include_list = (char **)
324 alloca ((includes_allocated *= 2) *
325 sizeof (char *));
326 memcpy ((PTR)psymtab_include_list, (PTR)orig,
327 includes_used * sizeof (char *));
328 }
329 continue;
330 }
331 case N_LSYM: /* Typedef or automatic variable. */
332 case N_STSYM: /* Data seg var -- static */
333 case N_LCSYM: /* BSS " */
334 case N_ROSYM: /* Read-only data seg var -- static. */
335 case N_NBSTS: /* Gould nobase. */
336 case N_NBLCS: /* symbols. */
337 case N_FUN:
338 case N_GSYM: /* Global (extern) variable; can be
339 data or bss (sigh FIXME). */
340
341 /* Following may probably be ignored; I'll leave them here
342 for now (until I do Pascal and Modula 2 extensions). */
343
344 case N_PC: /* I may or may not need this; I
345 suspect not. */
346 case N_M2C: /* I suspect that I can ignore this here. */
347 case N_SCOPE: /* Same. */
348
349 SET_NAMESTRING();
350
351 p = (char *) strchr (namestring, ':');
352 if (!p)
353 continue; /* Not a debugging symbol. */
354
355
356
357 /* Main processing section for debugging symbols which
358 the initial read through the symbol tables needs to worry
359 about. If we reach this point, the symbol which we are
360 considering is definitely one we are interested in.
361 p must also contain the (valid) index into the namestring
362 which indicates the debugging type symbol. */
363
364 switch (p[1])
365 {
366 case 'S':
367 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
368 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
369 VAR_NAMESPACE, LOC_STATIC,
370 objfile->static_psymbols,
371 CUR_SYMBOL_VALUE,
372 psymtab_language, objfile);
373 continue;
374 case 'G':
375 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_DATA);
376 /* The addresses in these entries are reported to be
377 wrong. See the code that reads 'G's for symtabs. */
378 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
379 VAR_NAMESPACE, LOC_STATIC,
380 objfile->global_psymbols,
381 CUR_SYMBOL_VALUE,
382 psymtab_language, objfile);
383 continue;
384
385 case 'T':
386 if (p != namestring) /* a name is there, not just :T... */
387 {
388 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
389 STRUCT_NAMESPACE, LOC_TYPEDEF,
390 objfile->static_psymbols,
391 CUR_SYMBOL_VALUE,
392 psymtab_language, objfile);
393 if (p[2] == 't')
394 {
395 /* Also a typedef with the same name. */
396 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
397 VAR_NAMESPACE, LOC_TYPEDEF,
398 objfile->static_psymbols,
399 CUR_SYMBOL_VALUE, psymtab_language,
400 objfile);
401 p += 1;
402 }
403 /* The semantics of C++ state that "struct foo { ... }"
404 also defines a typedef for "foo". Unfortuantely, cfront
405 never makes the typedef when translating from C++ to C.
406 We make the typedef here so that "ptype foo" works as
407 expected for cfront translated code. */
408 else if (psymtab_language == language_cplus)
409 {
410 /* Also a typedef with the same name. */
411 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
412 VAR_NAMESPACE, LOC_TYPEDEF,
413 objfile->static_psymbols,
414 CUR_SYMBOL_VALUE, psymtab_language,
415 objfile);
416 }
417 }
418 goto check_enum;
419 case 't':
420 if (p != namestring) /* a name is there, not just :T... */
421 {
422 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
423 VAR_NAMESPACE, LOC_TYPEDEF,
424 objfile->static_psymbols,
425 CUR_SYMBOL_VALUE,
426 psymtab_language, objfile);
427 }
428 check_enum:
429 /* If this is an enumerated type, we need to
430 add all the enum constants to the partial symbol
431 table. This does not cover enums without names, e.g.
432 "enum {a, b} c;" in C, but fortunately those are
433 rare. There is no way for GDB to find those from the
434 enum type without spending too much time on it. Thus
435 to solve this problem, the compiler needs to put out the
436 enum in a nameless type. GCC2 does this. */
437
438 /* We are looking for something of the form
439 <name> ":" ("t" | "T") [<number> "="] "e"
440 {<constant> ":" <value> ","} ";". */
441
442 /* Skip over the colon and the 't' or 'T'. */
443 p += 2;
444 /* This type may be given a number. Also, numbers can come
445 in pairs like (0,26). Skip over it. */
446 while ((*p >= '0' && *p <= '9')
447 || *p == '(' || *p == ',' || *p == ')'
448 || *p == '=')
449 p++;
450
451 if (*p++ == 'e')
452 {
453 /* We have found an enumerated type. */
454 /* According to comments in read_enum_type
455 a comma could end it instead of a semicolon.
456 I don't know where that happens.
457 Accept either. */
458 while (*p && *p != ';' && *p != ',')
459 {
460 char *q;
461
462 /* Check for and handle cretinous dbx symbol name
463 continuation! */
464 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
465 p = next_symbol_text ();
466
467 /* Point to the character after the name
468 of the enum constant. */
469 for (q = p; *q && *q != ':'; q++)
470 ;
471 /* Note that the value doesn't matter for
472 enum constants in psymtabs, just in symtabs. */
473 ADD_PSYMBOL_TO_LIST (p, q - p,
474 VAR_NAMESPACE, LOC_CONST,
475 objfile->static_psymbols, 0,
476 psymtab_language, objfile);
477 /* Point past the name. */
478 p = q;
479 /* Skip over the value. */
480 while (*p && *p != ',')
481 p++;
482 /* Advance past the comma. */
483 if (*p)
484 p++;
485 }
486 }
487 continue;
488 case 'c':
489 /* Constant, e.g. from "const" in Pascal. */
490 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
491 VAR_NAMESPACE, LOC_CONST,
492 objfile->static_psymbols, CUR_SYMBOL_VALUE,
493 psymtab_language, objfile);
494 continue;
495
496 case 'f':
497 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
498 #ifdef DBXREAD_ONLY
499 /* Kludges for ELF/STABS with Sun ACC */
500 last_function_name = namestring;
501 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
502 value for the bottom of the text seg in those cases. */
503 if (pst && pst->textlow == 0 && !symfile_relocatable)
504 pst->textlow = CUR_SYMBOL_VALUE;
505 #if 0
506 if (startup_file_end == 0)
507 startup_file_end = CUR_SYMBOL_VALUE;
508 #endif
509 /* End kludge. */
510 #endif /* DBXREAD_ONLY */
511 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
512 VAR_NAMESPACE, LOC_BLOCK,
513 objfile->static_psymbols, CUR_SYMBOL_VALUE,
514 psymtab_language, objfile);
515 continue;
516
517 /* Global functions were ignored here, but now they
518 are put into the global psymtab like one would expect.
519 They're also in the minimal symbol table. */
520 case 'F':
521 CUR_SYMBOL_VALUE += ANOFFSET (section_offsets, SECT_OFF_TEXT);
522 #ifdef DBXREAD_ONLY
523 /* Kludges for ELF/STABS with Sun ACC */
524 last_function_name = namestring;
525 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
526 value for the bottom of the text seg in those cases. */
527 if (pst && pst->textlow == 0 && !symfile_relocatable)
528 pst->textlow = CUR_SYMBOL_VALUE;
529 #if 0
530 if (startup_file_end == 0)
531 startup_file_end = CUR_SYMBOL_VALUE;
532 #endif
533 /* End kludge. */
534 #endif /* DBXREAD_ONLY */
535 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
536 VAR_NAMESPACE, LOC_BLOCK,
537 objfile->global_psymbols, CUR_SYMBOL_VALUE,
538 psymtab_language, objfile);
539 continue;
540
541 /* Two things show up here (hopefully); static symbols of
542 local scope (static used inside braces) or extensions
543 of structure symbols. We can ignore both. */
544 case 'V':
545 case '(':
546 case '0':
547 case '1':
548 case '2':
549 case '3':
550 case '4':
551 case '5':
552 case '6':
553 case '7':
554 case '8':
555 case '9':
556 continue;
557
558 case ':':
559 /* It is a C++ nested symbol. We don't need to record it
560 (I don't think); if we try to look up foo::bar::baz,
561 then symbols for the symtab containing foo should get
562 read in, I think. */
563 /* Someone says sun cc puts out symbols like
564 /foo/baz/maclib::/usr/local/bin/maclib,
565 which would get here with a symbol type of ':'. */
566 continue;
567
568 default:
569 /* Unexpected symbol descriptor. The second and subsequent stabs
570 of a continued stab can show up here. The question is
571 whether they ever can mimic a normal stab--it would be
572 nice if not, since we certainly don't want to spend the
573 time searching to the end of every string looking for
574 a backslash. */
575
576 complain (&unknown_symchar_complaint, p[1]);
577
578 /* Ignore it; perhaps it is an extension that we don't
579 know about. */
580 continue;
581 }
582
583 case N_EXCL:
584 #ifdef DBXREAD_ONLY
585
586 SET_NAMESTRING();
587
588 /* Find the corresponding bincl and mark that psymtab on the
589 psymtab dependency list */
590 {
591 struct partial_symtab *needed_pst =
592 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
593
594 /* If this include file was defined earlier in this file,
595 leave it alone. */
596 if (needed_pst == pst) continue;
597
598 if (needed_pst)
599 {
600 int i;
601 int found = 0;
602
603 for (i = 0; i < dependencies_used; i++)
604 if (dependency_list[i] == needed_pst)
605 {
606 found = 1;
607 break;
608 }
609
610 /* If it's already in the list, skip the rest. */
611 if (found) continue;
612
613 dependency_list[dependencies_used++] = needed_pst;
614 if (dependencies_used >= dependencies_allocated)
615 {
616 struct partial_symtab **orig = dependency_list;
617 dependency_list =
618 (struct partial_symtab **)
619 alloca ((dependencies_allocated *= 2)
620 * sizeof (struct partial_symtab *));
621 memcpy ((PTR)dependency_list, (PTR)orig,
622 (dependencies_used
623 * sizeof (struct partial_symtab *)));
624 #ifdef DEBUG_INFO
625 fprintf_unfiltered (gdb_stderr, "Had to reallocate dependency list.\n");
626 fprintf_unfiltered (gdb_stderr, "New dependencies allocated: %d\n",
627 dependencies_allocated);
628 #endif
629 }
630 }
631 }
632 #endif /* DBXREAD_ONLY */
633 continue;
634
635 case N_RBRAC:
636 #ifdef HANDLE_RBRAC
637 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
638 continue;
639 #endif
640 case N_EINCL:
641 case N_DSLINE:
642 case N_BSLINE:
643 case N_SSYM: /* Claim: Structure or union element.
644 Hopefully, I can ignore this. */
645 case N_ENTRY: /* Alternate entry point; can ignore. */
646 case N_MAIN: /* Can definitely ignore this. */
647 case N_CATCH: /* These are GNU C++ extensions */
648 case N_EHDECL: /* that can safely be ignored here. */
649 case N_LENG:
650 case N_BCOMM:
651 case N_ECOMM:
652 case N_ECOML:
653 case N_FNAME:
654 case N_SLINE:
655 case N_RSYM:
656 case N_PSYM:
657 case N_LBRAC:
658 case N_NSYMS: /* Ultrix 4.0: symbol count */
659 case N_DEFD: /* GNU Modula-2 */
660
661 case N_OBJ: /* useless types from Solaris */
662 case N_OPT:
663 case N_ENDM:
664 /* These symbols aren't interesting; don't worry about them */
665
666 continue;
667
668 default:
669 /* If we haven't found it yet, ignore it. It's probably some
670 new type we don't know about yet. */
671 complain (&unknown_symtype_complaint,
672 local_hex_string (CUR_SYMBOL_TYPE));
673 continue;
674 }
This page took 0.0446 seconds and 4 git commands to generate.