Oodles of changes. The most important is adding support for stabs
[binutils-gdb.git] / gdb / partial-stab.h
1 /* Shared code to pre-read a stab (dbx-style), when building a psymtab.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* The following need to be defined:
21 SET_NAMESTRING() --Set namestring to name of symbol.
22 CUR_SYMBOL_TYPE --Type code of current symbol.
23 CUR_SYMBOL_VALUE --Value field of current symbol. May be adjusted here.
24 */
25
26 #ifdef DEBUG
27 /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
28 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
29 add_psymbol_to_plist(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
30 #define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
31 add_psymbol_to_plist(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
32 #else
33 /* Add a symbol with an integer value to a psymtab. */
34 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
35 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, SYMBOL_VALUE)
36
37 /* Add a symbol with a CORE_ADDR value to a psymtab. */
38 #define ADD_PSYMBOL_ADDR_TO_LIST(NAME,NAMELENGTH, NAMESPACE,CLASS, LIST,VALUE)\
39 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, SYMBOL_VALUE_ADDRESS)
40 #endif
41
42 /* End of macro definitions, now let's handle them symbols! */
43
44 switch (CUR_SYMBOL_TYPE)
45 {
46 char *p;
47 /*
48 * Standard, external, non-debugger, symbols
49 */
50
51 #ifdef DBXREAD_ONLY
52 case N_TEXT | N_EXT:
53 case N_NBTEXT | N_EXT:
54 case N_NBDATA | N_EXT:
55 case N_NBBSS | N_EXT:
56 case N_SETV | N_EXT:
57 case N_ABS | N_EXT:
58 case N_DATA | N_EXT:
59 case N_BSS | N_EXT:
60
61 CUR_SYMBOL_VALUE += addr; /* Relocate */
62
63 SET_NAMESTRING();
64
65 bss_ext_symbol:
66 record_misc_function (namestring, CUR_SYMBOL_VALUE,
67 CUR_SYMBOL_TYPE); /* Always */
68
69 continue;
70
71 /* Standard, local, non-debugger, symbols */
72
73 case N_NBTEXT:
74
75 /* We need to be able to deal with both N_FN or N_TEXT,
76 because we have no way of knowing whether the sys-supplied ld
77 or GNU ld was used to make the executable. Sequents throw
78 in another wrinkle -- they renumbered N_FN. */
79
80 case N_FN:
81 case N_FN_SEQ:
82 case N_TEXT:
83 CUR_SYMBOL_VALUE += addr; /* Relocate */
84 SET_NAMESTRING();
85 if ((namestring[0] == '-' && namestring[1] == 'l')
86 || (namestring [(nsl = strlen (namestring)) - 1] == 'o'
87 && namestring [nsl - 2] == '.'))
88 {
89 if (entry_point < CUR_SYMBOL_VALUE
90 && entry_point >= last_o_file_start
91 && addr == 0) /* FIXME nogood nomore */
92 {
93 startup_file_start = last_o_file_start;
94 startup_file_end = CUR_SYMBOL_VALUE;
95 }
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 continue;
113
114 case N_DATA:
115 CUR_SYMBOL_VALUE += addr; /* Relocate */
116 SET_NAMESTRING ();
117 /* Check for __DYNAMIC, which is used by Sun shared libraries.
118 Record it even if it's local, not global, so we can find it.
119 Same with virtual function tables, both global and static. */
120 if ((namestring[8] == 'C' && (strcmp ("__DYNAMIC", namestring) == 0))
121 || VTBL_PREFIX_P ((namestring+HASH_OFFSET)))
122 {
123 /* Not really a function here, but... */
124 record_misc_function (namestring, CUR_SYMBOL_VALUE,
125 CUR_SYMBOL_TYPE); /* Always */
126 }
127 continue;
128
129 case N_UNDF | N_EXT:
130 if (CUR_SYMBOL_VALUE != 0) {
131 /* This is a "Fortran COMMON" symbol. See if the target
132 environment knows where it has been relocated to. */
133
134 CORE_ADDR reladdr;
135
136 SET_NAMESTRING();
137 if (target_lookup_symbol (namestring, &reladdr)) {
138 continue; /* Error in lookup; ignore symbol for now. */
139 }
140 CUR_SYMBOL_TYPE ^= (N_BSS^N_UNDF); /* Define it as a bss-symbol */
141 CUR_SYMBOL_VALUE = reladdr;
142 goto bss_ext_symbol;
143 }
144 continue; /* Just undefined, not COMMON */
145 #endif
146
147 /* Lots of symbol types we can just ignore. */
148
149 case N_UNDF:
150 case N_ABS:
151 case N_BSS:
152 case N_NBDATA:
153 case N_NBBSS:
154 continue;
155
156 /* Keep going . . .*/
157
158 /*
159 * Special symbol types for GNU
160 */
161 case N_INDR:
162 case N_INDR | N_EXT:
163 case N_SETA:
164 case N_SETA | N_EXT:
165 case N_SETT:
166 case N_SETT | N_EXT:
167 case N_SETD:
168 case N_SETD | N_EXT:
169 case N_SETB:
170 case N_SETB | N_EXT:
171 case N_SETV:
172 continue;
173
174 /*
175 * Debugger symbols
176 */
177
178 case N_SO: {
179 unsigned long valu = CUR_SYMBOL_VALUE;
180 /* Symbol number of the first symbol of this file (i.e. the N_SO
181 if there is just one, or the first if we have a pair). */
182 int first_symnum = symnum;
183
184 /* End the current partial symtab and start a new one */
185
186 SET_NAMESTRING();
187
188 /* Peek at the next symbol. If it is also an N_SO, the
189 first one just indicates the directory. */
190 CHECK_SECOND_N_SO();
191 valu += addr; /* Relocate */
192
193 if (pst && past_first_source_file)
194 {
195 END_PSYMTAB (pst, psymtab_include_list, includes_used,
196 first_symnum * symbol_size, valu,
197 dependency_list, dependencies_used);
198 pst = (struct partial_symtab *) 0;
199 includes_used = 0;
200 dependencies_used = 0;
201 }
202 else
203 past_first_source_file = 1;
204
205 pst = START_PSYMTAB (objfile, addr,
206 namestring, valu,
207 first_symnum * symbol_size,
208 global_psymbols.next, static_psymbols.next);
209 continue;
210 }
211
212 #ifdef DBXREAD_ONLY
213 case N_BINCL:
214 /* Add this bincl to the bincl_list for future EXCLs. No
215 need to save the string; it'll be around until
216 read_dbx_symtab function returns */
217
218 SET_NAMESTRING();
219
220 add_bincl_to_list (pst, namestring, CUR_SYMBOL_VALUE);
221
222 /* Mark down an include file in the current psymtab */
223
224 psymtab_include_list[includes_used++] = namestring;
225 if (includes_used >= includes_allocated)
226 {
227 char **orig = psymtab_include_list;
228
229 psymtab_include_list = (char **)
230 alloca ((includes_allocated *= 2) *
231 sizeof (char *));
232 bcopy (orig, psymtab_include_list,
233 includes_used * sizeof (char *));
234 }
235
236 continue;
237 #endif
238
239 case N_SOL:
240 /* Mark down an include file in the current psymtab */
241
242 SET_NAMESTRING();
243
244 /* In C++, one may expect the same filename to come round many
245 times, when code is coming alternately from the main file
246 and from inline functions in other files. So I check to see
247 if this is a file we've seen before -- either the main
248 source file, or a previously included file.
249
250 This seems to be a lot of time to be spending on N_SOL, but
251 things like "break c-exp.y:435" need to work (I
252 suppose the psymtab_include_list could be hashed or put
253 in a binary tree, if profiling shows this is a major hog). */
254 if (pst && !strcmp (namestring, pst->filename))
255 continue;
256 {
257 register int i;
258 for (i = 0; i < includes_used; i++)
259 if (!strcmp (namestring, psymtab_include_list[i]))
260 {
261 i = -1;
262 break;
263 }
264 if (i == -1)
265 continue;
266 }
267
268 psymtab_include_list[includes_used++] = namestring;
269 if (includes_used >= includes_allocated)
270 {
271 char **orig = psymtab_include_list;
272
273 psymtab_include_list = (char **)
274 alloca ((includes_allocated *= 2) *
275 sizeof (char *));
276 bcopy (orig, psymtab_include_list,
277 includes_used * sizeof (char *));
278 }
279 continue;
280 case N_LSYM: /* Typedef or automatic variable. */
281 case N_STSYM: /* Data seg var -- static */
282 case N_LCSYM: /* BSS " */
283 case N_NBSTS: /* Gould nobase. */
284 case N_NBLCS: /* symbols. */
285
286 SET_NAMESTRING();
287
288 p = (char *) strchr (namestring, ':');
289
290 /* Skip if there is no :. */
291 if (!p) continue;
292
293 switch (p[1])
294 {
295 case 'T':
296 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
297 STRUCT_NAMESPACE, LOC_TYPEDEF,
298 static_psymbols, CUR_SYMBOL_VALUE);
299 if (p[2] == 't')
300 {
301 /* Also a typedef with the same name. */
302 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
303 VAR_NAMESPACE, LOC_TYPEDEF,
304 static_psymbols, CUR_SYMBOL_VALUE);
305 p += 1;
306 }
307 goto check_enum;
308 case 't':
309 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
310 VAR_NAMESPACE, LOC_TYPEDEF,
311 static_psymbols, CUR_SYMBOL_VALUE);
312 check_enum:
313 #ifdef DBXREAD_ONLY
314 /* If this is an enumerated type, we need to
315 add all the enum constants to the partial symbol
316 table. This does not cover enums without names, e.g.
317 "enum {a, b} c;" in C, but fortunately those are
318 rare. There is no way for GDB to find those from the
319 enum type without spending too much time on it. Thus
320 to solve this problem, the compiler needs to put out separate
321 constant symbols ('c' N_LSYMS) for enum constants in
322 enums without names, or put out a dummy type. */
323
324 /* We are looking for something of the form
325 <name> ":" ("t" | "T") [<number> "="] "e"
326 {<constant> ":" <value> ","} ";". */
327
328 /* Skip over the colon and the 't' or 'T'. */
329 p += 2;
330 /* This type may be given a number. Also, numbers can come
331 in pairs like (0,26). Skip over it. */
332 while ((*p >= '0' && *p <= '9')
333 || *p == '(' || *p == ',' || *p == ')'
334 || *p == '=')
335 p++;
336
337 if (*p++ == 'e')
338 {
339 /* We have found an enumerated type. */
340 /* According to comments in read_enum_type
341 a comma could end it instead of a semicolon.
342 I don't know where that happens.
343 Accept either. */
344 while (*p && *p != ';' && *p != ',')
345 {
346 char *q;
347
348 /* Check for and handle cretinous dbx symbol name
349 continuation! */
350 if (*p == '\\')
351 p = next_symbol_text ();
352
353 /* Point to the character after the name
354 of the enum constant. */
355 for (q = p; *q && *q != ':'; q++)
356 ;
357 /* Note that the value doesn't matter for
358 enum constants in psymtabs, just in symtabs. */
359 ADD_PSYMBOL_TO_LIST (p, q - p,
360 VAR_NAMESPACE, LOC_CONST,
361 static_psymbols, 0);
362 /* Point past the name. */
363 p = q;
364 /* Skip over the value. */
365 while (*p && *p != ',')
366 p++;
367 /* Advance past the comma. */
368 if (*p)
369 p++;
370 }
371 }
372 #endif
373 continue;
374 case 'c':
375 /* Constant, e.g. from "const" in Pascal. */
376 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
377 VAR_NAMESPACE, LOC_CONST,
378 static_psymbols, CUR_SYMBOL_VALUE);
379 continue;
380 default:
381 /* Skip if the thing following the : is
382 not a letter (which indicates declaration of a local
383 variable, which we aren't interested in). */
384 continue;
385 }
386
387 case N_FUN:
388 case N_GSYM: /* Global (extern) variable; can be
389 data or bss (sigh). */
390
391 /* Following may probably be ignored; I'll leave them here
392 for now (until I do Pascal and Modula 2 extensions). */
393
394 case N_PC: /* I may or may not need this; I
395 suspect not. */
396 case N_M2C: /* I suspect that I can ignore this here. */
397 case N_SCOPE: /* Same. */
398
399 SET_NAMESTRING();
400
401 p = (char *) strchr (namestring, ':');
402 if (!p)
403 continue; /* Not a debugging symbol. */
404
405
406
407 /* Main processing section for debugging symbols which
408 the initial read through the symbol tables needs to worry
409 about. If we reach this point, the symbol which we are
410 considering is definitely one we are interested in.
411 p must also contain the (valid) index into the namestring
412 which indicates the debugging type symbol. */
413
414 switch (p[1])
415 {
416 case 'c':
417 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
418 VAR_NAMESPACE, LOC_CONST,
419 static_psymbols, CUR_SYMBOL_VALUE);
420 continue;
421 case 'S':
422 CUR_SYMBOL_VALUE += addr; /* Relocate */
423 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
424 VAR_NAMESPACE, LOC_STATIC,
425 static_psymbols, CUR_SYMBOL_VALUE);
426 continue;
427 case 'G':
428 CUR_SYMBOL_VALUE += addr; /* Relocate */
429 /* The addresses in these entries are reported to be
430 wrong. See the code that reads 'G's for symtabs. */
431 ADD_PSYMBOL_ADDR_TO_LIST (namestring, p - namestring,
432 VAR_NAMESPACE, LOC_STATIC,
433 global_psymbols, CUR_SYMBOL_VALUE);
434 continue;
435
436 case 't':
437 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
438 VAR_NAMESPACE, LOC_TYPEDEF,
439 static_psymbols, CUR_SYMBOL_VALUE);
440 continue;
441
442 case 'f':
443 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
444 VAR_NAMESPACE, LOC_BLOCK,
445 static_psymbols, CUR_SYMBOL_VALUE);
446 continue;
447
448 /* Global functions were ignored here, but now they
449 are put into the global psymtab like one would expect.
450 They're also in the misc fn vector...
451 FIXME, why did it used to ignore these? That broke
452 "i fun" on these functions. */
453 case 'F':
454 ADD_PSYMBOL_TO_LIST (namestring, p - namestring,
455 VAR_NAMESPACE, LOC_BLOCK,
456 global_psymbols, CUR_SYMBOL_VALUE);
457 continue;
458
459 /* Two things show up here (hopefully); static symbols of
460 local scope (static used inside braces) or extensions
461 of structure symbols. We can ignore both. */
462 case 'V':
463 case '(':
464 case '0':
465 case '1':
466 case '2':
467 case '3':
468 case '4':
469 case '5':
470 case '6':
471 case '7':
472 case '8':
473 case '9':
474 continue;
475
476 default:
477 /* Unexpected symbol. Ignore it; perhaps it is an extension
478 that we don't know about.
479
480 Someone says sun cc puts out symbols like
481 /foo/baz/maclib::/usr/local/bin/maclib,
482 which would get here with a symbol type of ':'. */
483 continue;
484 }
485
486 #ifdef DBXREAD_ONLY
487 case N_EXCL:
488
489 SET_NAMESTRING();
490
491 /* Find the corresponding bincl and mark that psymtab on the
492 psymtab dependency list */
493 {
494 struct partial_symtab *needed_pst =
495 find_corresponding_bincl_psymtab (namestring, CUR_SYMBOL_VALUE);
496
497 /* If this include file was defined earlier in this file,
498 leave it alone. */
499 if (needed_pst == pst) continue;
500
501 if (needed_pst)
502 {
503 int i;
504 int found = 0;
505
506 for (i = 0; i < dependencies_used; i++)
507 if (dependency_list[i] == needed_pst)
508 {
509 found = 1;
510 break;
511 }
512
513 /* If it's already in the list, skip the rest. */
514 if (found) continue;
515
516 dependency_list[dependencies_used++] = needed_pst;
517 if (dependencies_used >= dependencies_allocated)
518 {
519 struct partial_symtab **orig = dependency_list;
520 dependency_list =
521 (struct partial_symtab **)
522 alloca ((dependencies_allocated *= 2)
523 * sizeof (struct partial_symtab *));
524 bcopy (orig, dependency_list,
525 (dependencies_used
526 * sizeof (struct partial_symtab *)));
527 #ifdef DEBUG_INFO
528 fprintf (stderr, "Had to reallocate dependency list.\n");
529 fprintf (stderr, "New dependencies allocated: %d\n",
530 dependencies_allocated);
531 #endif
532 }
533 }
534 else
535 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
536 symnum);
537 }
538 continue;
539 #endif
540
541 case N_RBRAC:
542 #ifdef HANDLE_RBRAC
543 HANDLE_RBRAC(CUR_SYMBOL_VALUE);
544 #endif
545 case N_EINCL:
546 case N_DSLINE:
547 case N_BSLINE:
548 case N_SSYM: /* Claim: Structure or union element.
549 Hopefully, I can ignore this. */
550 case N_ENTRY: /* Alternate entry point; can ignore. */
551 case N_MAIN: /* Can definitely ignore this. */
552 case N_CATCH: /* These are GNU C++ extensions */
553 case N_EHDECL: /* that can safely be ignored here. */
554 case N_LENG:
555 case N_BCOMM:
556 case N_ECOMM:
557 case N_ECOML:
558 case N_FNAME:
559 case N_SLINE:
560 case N_RSYM:
561 case N_PSYM:
562 case N_LBRAC:
563 case N_NSYMS: /* Ultrix 4.0: symbol count */
564 case N_DEFD: /* GNU Modula-2 */
565 /* These symbols aren't interesting; don't worry about them */
566
567 continue;
568
569 default:
570 #ifdef DBXREAD_ONLY
571 /* If we haven't found it yet, ignore it. It's probably some
572 new type we don't know about yet. */
573 complain (&unknown_symtype_complaint, local_hex_string(CUR_SYMBOL_TYPE));
574 #endif
575 continue;
576 }