* cadillac.c (kernel_dispatch): Make return type void.
[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 Free Software Foundation,
3 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 case N_NBDATA | N_EXT:
39 case N_NBBSS | N_EXT:
40 case N_SETV | N_EXT:
41 case N_ABS | N_EXT:
42 case N_DATA | N_EXT:
43 case N_BSS | N_EXT:
44 #ifdef DBXREAD_ONLY
45
46 CUR_SYMBOL_VALUE += addr; /* Relocate */
47
48 SET_NAMESTRING();
49
50 bss_ext_symbol:
51 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
52 CUR_SYMBOL_TYPE, objfile); /* Always */
53 #endif /* DBXREAD_ONLY */
54 continue;
55
56 /* Standard, local, non-debugger, symbols */
57
58 case N_NBTEXT:
59
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. */
64
65 case N_FN:
66 case N_FN_SEQ:
67 case N_TEXT:
68 #ifdef DBXREAD_ONLY
69 CUR_SYMBOL_VALUE += addr; /* Relocate */
70 SET_NAMESTRING();
71 if ((namestring[0] == '-' && namestring[1] == 'l')
72 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
73 && namestring [nsl - 2] == '.')
74 #ifdef hp9000s800
75 /* some cooperation from gcc to get around ld stupidity */
76 || (namestring[0] == 'e' && !strcmp (namestring, "end_file."))
77 #endif
78 )
79 {
80 #ifndef hp9000s800
81 if (objfile -> ei.entry_point < CUR_SYMBOL_VALUE &&
82 objfile -> ei.entry_point >= last_o_file_start &&
83 addr == 0) /* FIXME nogood nomore */
84 {
85 objfile -> ei.entry_file_lowpc = last_o_file_start;
86 objfile -> ei.entry_file_highpc = CUR_SYMBOL_VALUE;
87 }
88 #endif
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)
93 {
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;
98 includes_used = 0;
99 dependencies_used = 0;
100 }
101 else
102 past_first_source_file = 1;
103 last_o_file_start = CUR_SYMBOL_VALUE;
104 }
105 #endif /* DBXREAD_ONLY */
106 continue;
107
108 case N_DATA:
109 #ifdef DBXREAD_ONLY
110 CUR_SYMBOL_VALUE += addr; /* Relocate */
111 SET_NAMESTRING ();
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)))
117 {
118 /* Not really a function here, but... */
119 record_minimal_symbol (namestring, CUR_SYMBOL_VALUE,
120 CUR_SYMBOL_TYPE, objfile); /* Always */
121 }
122 #endif /* DBXREAD_ONLY */
123 continue;
124
125 case N_UNDF | N_EXT:
126 #ifdef 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. */
130
131 CORE_ADDR reladdr;
132
133 SET_NAMESTRING();
134 if (target_lookup_symbol (namestring, &reladdr)) {
135 continue; /* Error in lookup; ignore symbol for now. */
136 }
137 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
138 CUR_SYMBOL_VALUE = reladdr;
139 goto bss_ext_symbol;
140 }
141 #endif /* DBXREAD_ONLY */
142 continue; /* Just undefined, not COMMON */
143
144 case N_UNDF:
145 #ifdef DBXREAD_ONLY
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
151 SET_NAMESTRING(). */
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. */
159 continue;
160 }
161 #endif /* DBXREAD_ONLY */
162 continue;
163
164 /* Lots of symbol types we can just ignore. */
165
166 case N_ABS:
167 case N_BSS:
168 case N_NBDATA:
169 case N_NBBSS:
170 continue;
171
172 /* Keep going . . .*/
173
174 /*
175 * Special symbol types for GNU
176 */
177 case N_INDR:
178 case N_INDR | N_EXT:
179 case N_SETA:
180 case N_SETA | N_EXT:
181 case N_SETT:
182 case N_SETT | N_EXT:
183 case N_SETD:
184 case N_SETD | N_EXT:
185 case N_SETB:
186 case N_SETB | N_EXT:
187 case N_SETV:
188 continue;
189
190 /*
191 * Debugger symbols
192 */
193
194 case N_SO: {
195 unsigned long valu = CUR_SYMBOL_VALUE;
196 static int last_so_symnum = -10;
197 static int dir_so_symnum = -1;
198 int tmp;
199 char *p;
200
201 /* End the current partial symtab and start a new one */
202
203 SET_NAMESTRING();
204
205 valu += addr; /* Relocate */
206
207 /* Some compilers (including gcc) emit a pair of initial N_SOs.
208 The first one is a directory name; the second the file name.
209 If pst exists, is empty, and has a filename ending in '/',
210 we assume the previous N_SO was a directory name. */
211
212 p = strrchr (namestring, '/');
213 if (p && *(p+1) == '\000')
214 {
215 dir_so_symnum = symnum;
216 continue; /* Simply ignore directory name SOs */
217 }
218
219 /* Some other compilers (C++ ones in particular) emit useless
220 SOs for non-existant .c files. */
221
222 if (last_so_symnum == symnum - 1)
223 continue; /* Ignore repeated SOs */
224 last_so_symnum = symnum;
225
226 if (pst)
227 {
228 END_PSYMTAB (pst, psymtab_include_list, includes_used,
229 symnum * symbol_size, valu,
230 dependency_list, dependencies_used);
231 pst = (struct partial_symtab *) 0;
232 includes_used = 0;
233 dependencies_used = 0;
234 }
235
236 past_first_source_file = 1;
237
238 if (dir_so_symnum == symnum - 1) /* Was prev. SO a directory? */
239 tmp = dir_so_symnum;
240 else
241 tmp = symnum;
242 pst = START_PSYMTAB (objfile, addr,
243 namestring, valu,
244 tmp * symbol_size,
245 objfile -> global_psymbols.next,
246 objfile -> static_psymbols.next);
247 dir_so_symnum = -1;
248 continue;
249 }
250
251 case N_BINCL:
252 #ifdef DBXREAD_ONLY
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 */
256
257 SET_NAMESTRING();
258
259 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
260
261 /* Mark down an include file in the current psymtab */
262
263 psymtab_include_list[includes_used++] = namestring;
264 if (includes_used >= includes_allocated)
265 {
266 char **orig = psymtab_include_list;
267
268 psymtab_include_list = (char **)
269 alloca ((includes_allocated *= 2) *
270 sizeof (char *));
271 memcpy ((PTR)psymtab_include_list, (PTR)orig,
272 includes_used * sizeof (char *));
273 }
274
275 #endif /* DBXREAD_ONLY */
276 continue;
277
278 case N_SOL:
279 /* Mark down an include file in the current psymtab */
280
281 SET_NAMESTRING();
282
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.
288
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))
294 continue;
295 {
296 register int i;
297 for (i = 0; i < includes_used; i++)
298 if (!strcmp (namestring, psymtab_include_list[i]))
299 {
300 i = -1;
301 break;
302 }
303 if (i == -1)
304 continue;
305 }
306
307 psymtab_include_list[includes_used++] = namestring;
308 if (includes_used >= includes_allocated)
309 {
310 char **orig = psymtab_include_list;
311
312 psymtab_include_list = (char **)
313 alloca ((includes_allocated *= 2) *
314 sizeof (char *));
315 memcpy ((PTR)psymtab_include_list, (PTR)orig,
316 includes_used * sizeof (char *));
317 }
318 continue;
319
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. */
325
326 SET_NAMESTRING();
327
328 p = (char *) strchr (namestring, ':');
329
330 /* Skip if there is no :. */
331 if (!p) continue;
332
333 switch (p[1])
334 {
335 case 'T':
336 if (p != namestring) /* a name is there, not just :T... */
337 {
338 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
339 STRUCT_NAMESPACE, LOC_TYPEDEF,
340 objfile->static_psymbols, CUR_SYMBOL_VALUE);
341 if (p[2] == 't')
342 {
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);
347 p += 1;
348 }
349 }
350 goto check_enum;
351 case 't':
352 if (p != namestring) /* a name is there, not just :T... */
353 {
354 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
355 VAR_NAMESPACE, LOC_TYPEDEF,
356 objfile->static_psymbols, CUR_SYMBOL_VALUE);
357 }
358 check_enum:
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. */
368
369 /* We are looking for something of the form
370 <name> ":" ("t" | "T") [<number> "="] "e"
371 {<constant> ":" <value> ","} ";". */
372
373 /* Skip over the colon and the 't' or 'T'. */
374 p += 2;
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 == ')'
379 || *p == '=')
380 p++;
381
382 if (*p++ == 'e')
383 {
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.
388 Accept either. */
389 while (*p && *p != ';' && *p != ',')
390 {
391 char *q;
392
393 /* Check for and handle cretinous dbx symbol name
394 continuation! */
395 if (*p == '\\')
396 p = next_symbol_text ();
397
398 /* Point to the character after the name
399 of the enum constant. */
400 for (q = p; *q && *q != ':'; q++)
401 ;
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. */
408 p = q;
409 /* Skip over the value. */
410 while (*p && *p != ',')
411 p++;
412 /* Advance past the comma. */
413 if (*p)
414 p++;
415 }
416 }
417 continue;
418 case 'c':
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);
423 continue;
424 default:
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). */
428 continue;
429 }
430
431 case N_FUN:
432 case N_GSYM: /* Global (extern) variable; can be
433 data or bss (sigh). */
434
435 /* Following may probably be ignored; I'll leave them here
436 for now (until I do Pascal and Modula 2 extensions). */
437
438 case N_PC: /* I may or may not need this; I
439 suspect not. */
440 case N_M2C: /* I suspect that I can ignore this here. */
441 case N_SCOPE: /* Same. */
442
443 SET_NAMESTRING();
444
445 p = (char *) strchr (namestring, ':');
446 if (!p)
447 continue; /* Not a debugging symbol. */
448
449
450
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. */
457
458 switch (p[1])
459 {
460 case 'c':
461 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
462 VAR_NAMESPACE, LOC_CONST,
463 objfile->static_psymbols, CUR_SYMBOL_VALUE);
464 continue;
465 case 'S':
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);
470 continue;
471 case 'G':
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);
478 continue;
479
480 case 't':
481 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
482 VAR_NAMESPACE, LOC_TYPEDEF,
483 objfile->static_psymbols, CUR_SYMBOL_VALUE);
484 continue;
485
486 case 'f':
487 #ifdef DBXREAD_ONLY
488 /* Kludges for ELF/STABS with Sun ACC */
489 last_function_name = namestring;
490 if (pst->textlow == 0)
491 pst->textlow = CUR_SYMBOL_VALUE;
492 #if 0
493 if (startup_file_end == 0)
494 startup_file_end = CUR_SYMBOL_VALUE;
495 #endif
496 /* End kludge. */
497 #endif /* DBXREAD_ONLY */
498 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
499 VAR_NAMESPACE, LOC_BLOCK,
500 objfile->static_psymbols, CUR_SYMBOL_VALUE);
501 continue;
502
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. */
508 case 'F':
509 #ifdef DBXREAD_ONLY
510 /* Kludges for ELF/STABS with Sun ACC */
511 last_function_name = namestring;
512 if (pst->textlow == 0)
513 pst->textlow = CUR_SYMBOL_VALUE;
514 #if 0
515 if (startup_file_end == 0)
516 startup_file_end = CUR_SYMBOL_VALUE;
517 #endif
518 /* End kludge. */
519 #endif /* DBXREAD_ONLY */
520 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
521 VAR_NAMESPACE, LOC_BLOCK,
522 objfile->global_psymbols, CUR_SYMBOL_VALUE);
523 continue;
524
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. */
528 case 'V':
529 case '(':
530 case '0':
531 case '1':
532 case '2':
533 case '3':
534 case '4':
535 case '5':
536 case '6':
537 case '7':
538 case '8':
539 case '9':
540 continue;
541
542 default:
543 /* Unexpected symbol. Ignore it; perhaps it is an extension
544 that we don't know about.
545
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 ':'. */
549 continue;
550 }
551
552 case N_EXCL:
553 #ifdef DBXREAD_ONLY
554
555 SET_NAMESTRING();
556
557 /* Find the corresponding bincl and mark that psymtab on the
558 psymtab dependency list */
559 {
560 struct partial_symtab *needed_pst =
561 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
562
563 /* If this include file was defined earlier in this file,
564 leave it alone. */
565 if (needed_pst == pst) continue;
566
567 if (needed_pst)
568 {
569 int i;
570 int found = 0;
571
572 for (i = 0; i < dependencies_used; i++)
573 if (dependency_list[i] == needed_pst)
574 {
575 found = 1;
576 break;
577 }
578
579 /* If it's already in the list, skip the rest. */
580 if (found) continue;
581
582 dependency_list[dependencies_used++] = needed_pst;
583 if (dependencies_used >= dependencies_allocated)
584 {
585 struct partial_symtab **orig = dependency_list;
586 dependency_list =
587 (struct partial_symtab **)
588 alloca ((dependencies_allocated *= 2)
589 * sizeof (struct partial_symtab *));
590 memcpy ((PTR)dependency_list, (PTR)orig,
591 (dependencies_used
592 * sizeof (struct partial_symtab *)));
593 #ifdef DEBUG_INFO
594 fprintf (stderr, "Had to reallocate dependency list.\n");
595 fprintf (stderr, "New dependencies allocated: %d\n",
596 dependencies_allocated);
597 #endif
598 }
599 }
600 else
601 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
602 symnum);
603 }
604 #endif /* DBXREAD_ONLY */
605 continue;
606
607 case N_RBRAC:
608 #ifdef HANDLE_RBRAC
609 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
610 continue;
611 #endif
612 case N_EINCL:
613 case N_DSLINE:
614 case N_BSLINE:
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. */
621 case N_LENG:
622 case N_BCOMM:
623 case N_ECOMM:
624 case N_ECOML:
625 case N_FNAME:
626 case N_SLINE:
627 case N_RSYM:
628 case N_PSYM:
629 case N_LBRAC:
630 case N_NSYMS: /* Ultrix 4.0: symbol count */
631 case N_DEFD: /* GNU Modula-2 */
632
633 case N_OBJ: /* two useless types from Solaris */
634 case N_OPT:
635 /* These symbols aren't interesting; don't worry about them */
636
637 continue;
638
639 default:
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));
643 continue;
644 }
This page took 0.057975 seconds and 4 git commands to generate.