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