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