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