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