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