Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Read a symbol table in ECOFF format (Third-Eye). |
ee300cd4 AC |
2 | |
3 | Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, | |
4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software | |
5 | Foundation, Inc. | |
6 | ||
c906108c SS |
7 | Original version contributed by Alessandro Forin (af@cs.cmu.edu) at |
8 | CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor | |
9 | at Cygnus Support. | |
10 | ||
c5aa993b | 11 | This file is part of GDB. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is free software; you can redistribute it and/or modify |
14 | it under the terms of the GNU General Public License as published by | |
15 | the Free Software Foundation; either version 2 of the License, or | |
16 | (at your option) any later version. | |
c906108c | 17 | |
c5aa993b JM |
18 | This program is distributed in the hope that it will be useful, |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | GNU General Public License for more details. | |
c906108c | 22 | |
c5aa993b JM |
23 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software | |
25 | Foundation, Inc., 59 Temple Place - Suite 330, | |
26 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
27 | |
28 | /* This module provides the function mdebug_build_psymtabs. It reads | |
29 | ECOFF debugging information into partial symbol tables. The | |
30 | debugging information is read from two structures. A struct | |
31 | ecoff_debug_swap includes the sizes of each ECOFF structure and | |
32 | swapping routines; these are fixed for a particular target. A | |
33 | struct ecoff_debug_info points to the debugging information for a | |
34 | particular object file. | |
35 | ||
36 | ECOFF symbol tables are mostly written in the byte order of the | |
37 | target machine. However, one section of the table (the auxiliary | |
38 | symbol information) is written in the host byte order. There is a | |
39 | bit in the other symbol info which describes which host byte order | |
40 | was used. ECOFF thereby takes the trophy from Intel `b.out' for | |
41 | the most brain-dead adaptation of a file format to byte order. | |
42 | ||
43 | This module can read all four of the known byte-order combinations, | |
44 | on any type of host. */ | |
45 | ||
46 | #include "defs.h" | |
47 | #include "symtab.h" | |
48 | #include "gdbtypes.h" | |
49 | #include "gdbcore.h" | |
c906108c | 50 | #include "objfiles.h" |
04ea0df1 | 51 | #include "gdb_obstack.h" |
c906108c SS |
52 | #include "buildsym.h" |
53 | #include "stabsread.h" | |
54 | #include "complaints.h" | |
55 | #include "demangle.h" | |
261397f8 | 56 | #include "gdb_assert.h" |
fe898f56 | 57 | #include "block.h" |
de4f826b | 58 | #include "dictionary.h" |
5b123146 | 59 | #include "mdebugread.h" |
c906108c SS |
60 | #include "gdb_stat.h" |
61 | #include "gdb_string.h" | |
62 | ||
c906108c SS |
63 | #include "bfd.h" |
64 | ||
65 | #include "coff/ecoff.h" /* COFF-like aspects of ecoff files */ | |
66 | ||
67 | #include "libaout.h" /* Private BFD a.out information. */ | |
68 | #include "aout/aout64.h" | |
69 | #include "aout/stab_gnu.h" /* STABS information */ | |
70 | ||
71 | #include "expression.h" | |
c906108c | 72 | |
a14ed312 | 73 | extern void _initialize_mdebugread (void); |
c906108c | 74 | |
c906108c SS |
75 | /* Provide a way to test if we have both ECOFF and ELF symbol tables. |
76 | We use this define in order to know whether we should override a | |
77 | symbol's ECOFF section with its ELF section. This is necessary in | |
78 | case the symbol's ELF section could not be represented in ECOFF. */ | |
79 | #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | |
80 | && bfd_get_section_by_name (bfd, ".mdebug") != NULL) | |
c906108c | 81 | \f |
c5aa993b | 82 | |
c906108c SS |
83 | /* We put a pointer to this structure in the read_symtab_private field |
84 | of the psymtab. */ | |
85 | ||
86 | struct symloc | |
c5aa993b JM |
87 | { |
88 | /* Index of the FDR that this psymtab represents. */ | |
89 | int fdr_idx; | |
90 | /* The BFD that the psymtab was created from. */ | |
91 | bfd *cur_bfd; | |
92 | const struct ecoff_debug_swap *debug_swap; | |
93 | struct ecoff_debug_info *debug_info; | |
94 | struct mdebug_pending **pending_list; | |
95 | /* Pointer to external symbols for this file. */ | |
96 | EXTR *extern_tab; | |
97 | /* Size of extern_tab. */ | |
98 | int extern_count; | |
99 | enum language pst_language; | |
100 | }; | |
c906108c SS |
101 | |
102 | #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private) | |
103 | #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx) | |
104 | #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd) | |
105 | #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap) | |
106 | #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info) | |
107 | #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list) | |
108 | ||
109 | #define SC_IS_TEXT(sc) ((sc) == scText \ | |
110 | || (sc) == scRConst \ | |
111 | || (sc) == scInit \ | |
112 | || (sc) == scFini) | |
113 | #define SC_IS_DATA(sc) ((sc) == scData \ | |
114 | || (sc) == scSData \ | |
115 | || (sc) == scRData \ | |
116 | || (sc) == scPData \ | |
117 | || (sc) == scXData) | |
118 | #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon) | |
0e931cf0 JB |
119 | #define SC_IS_BSS(sc) ((sc) == scBss) |
120 | #define SC_IS_SBSS(sc) ((sc) == scSBss) | |
c906108c | 121 | #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined) |
c906108c | 122 | \f |
c906108c | 123 | /* Various complaints about symbol reading that don't abort the process */ |
23136709 KB |
124 | static void |
125 | index_complaint (const char *arg1) | |
126 | { | |
127 | complaint (&symfile_complaints, "bad aux index at symbol %s", arg1); | |
128 | } | |
c906108c | 129 | |
23136709 KB |
130 | static void |
131 | unknown_ext_complaint (const char *arg1) | |
132 | { | |
133 | complaint (&symfile_complaints, "unknown external symbol %s", arg1); | |
134 | } | |
c906108c | 135 | |
23136709 KB |
136 | static void |
137 | basic_type_complaint (int arg1, const char *arg2) | |
138 | { | |
139 | complaint (&symfile_complaints, "cannot map ECOFF basic type 0x%x for %s", | |
140 | arg1, arg2); | |
141 | } | |
c906108c | 142 | |
23136709 KB |
143 | static void |
144 | bad_tag_guess_complaint (const char *arg1) | |
145 | { | |
146 | complaint (&symfile_complaints, "guessed tag type of %s incorrectly", arg1); | |
147 | } | |
c906108c | 148 | |
23136709 KB |
149 | static void |
150 | bad_rfd_entry_complaint (const char *arg1, int arg2, int arg3) | |
151 | { | |
152 | complaint (&symfile_complaints, "bad rfd entry for %s: file %d, index %d", | |
153 | arg1, arg2, arg3); | |
154 | } | |
c906108c | 155 | |
23136709 KB |
156 | static void |
157 | unexpected_type_code_complaint (const char *arg1) | |
158 | { | |
159 | complaint (&symfile_complaints, "unexpected type code for %s", arg1); | |
160 | } | |
c906108c SS |
161 | |
162 | /* Macros and extra defs */ | |
163 | ||
164 | /* Puns: hard to find whether -g was used and how */ | |
165 | ||
166 | #define MIN_GLEVEL GLEVEL_0 | |
167 | #define compare_glevel(a,b) \ | |
168 | (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \ | |
169 | ((b) == GLEVEL_3) ? -1 : (int)((b) - (a))) | |
170 | \f | |
171 | /* Things that really are local to this module */ | |
172 | ||
173 | /* Remember what we deduced to be the source language of this psymtab. */ | |
174 | ||
175 | static enum language psymtab_language = language_unknown; | |
176 | ||
177 | /* Current BFD. */ | |
178 | ||
179 | static bfd *cur_bfd; | |
180 | ||
181 | /* How to parse debugging information for CUR_BFD. */ | |
182 | ||
183 | static const struct ecoff_debug_swap *debug_swap; | |
184 | ||
185 | /* Pointers to debugging information for CUR_BFD. */ | |
186 | ||
187 | static struct ecoff_debug_info *debug_info; | |
188 | ||
189 | /* Pointer to current file decriptor record, and its index */ | |
190 | ||
191 | static FDR *cur_fdr; | |
192 | static int cur_fd; | |
193 | ||
194 | /* Index of current symbol */ | |
195 | ||
196 | static int cur_sdx; | |
197 | ||
198 | /* Note how much "debuggable" this image is. We would like | |
199 | to see at least one FDR with full symbols */ | |
200 | ||
201 | static int max_gdbinfo; | |
202 | static int max_glevel; | |
203 | ||
204 | /* When examining .o files, report on undefined symbols */ | |
205 | ||
206 | static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs; | |
207 | ||
208 | /* Pseudo symbol to use when putting stabs into the symbol table. */ | |
209 | ||
210 | static char stabs_symbol[] = STABS_SYMBOL; | |
211 | ||
212 | /* Types corresponding to mdebug format bt* basic types. */ | |
213 | ||
214 | static struct type *mdebug_type_void; | |
215 | static struct type *mdebug_type_char; | |
216 | static struct type *mdebug_type_short; | |
217 | static struct type *mdebug_type_int_32; | |
218 | #define mdebug_type_int mdebug_type_int_32 | |
219 | static struct type *mdebug_type_int_64; | |
220 | static struct type *mdebug_type_long_32; | |
221 | static struct type *mdebug_type_long_64; | |
222 | static struct type *mdebug_type_long_long_64; | |
223 | static struct type *mdebug_type_unsigned_char; | |
224 | static struct type *mdebug_type_unsigned_short; | |
225 | static struct type *mdebug_type_unsigned_int_32; | |
226 | static struct type *mdebug_type_unsigned_int_64; | |
227 | static struct type *mdebug_type_unsigned_long_32; | |
228 | static struct type *mdebug_type_unsigned_long_64; | |
229 | static struct type *mdebug_type_unsigned_long_long_64; | |
230 | static struct type *mdebug_type_adr_32; | |
231 | static struct type *mdebug_type_adr_64; | |
232 | static struct type *mdebug_type_float; | |
233 | static struct type *mdebug_type_double; | |
234 | static struct type *mdebug_type_complex; | |
235 | static struct type *mdebug_type_double_complex; | |
236 | static struct type *mdebug_type_fixed_dec; | |
237 | static struct type *mdebug_type_float_dec; | |
238 | static struct type *mdebug_type_string; | |
239 | ||
240 | /* Types for symbols from files compiled without debugging info. */ | |
241 | ||
242 | static struct type *nodebug_func_symbol_type; | |
243 | static struct type *nodebug_var_symbol_type; | |
244 | ||
245 | /* Nonzero if we have seen ecoff debugging info for a file. */ | |
246 | ||
247 | static int found_ecoff_debugging_info; | |
248 | ||
249 | /* Forward declarations */ | |
250 | ||
12b9c64f AO |
251 | static int upgrade_type (int, struct type **, int, union aux_ext *, |
252 | int, char *); | |
c906108c | 253 | |
a14ed312 | 254 | static void parse_partial_symbols (struct objfile *); |
c906108c | 255 | |
a14ed312 | 256 | static int has_opaque_xref (FDR *, SYMR *); |
c906108c | 257 | |
12b9c64f AO |
258 | static int cross_ref (int, union aux_ext *, struct type **, enum type_code, |
259 | char **, int, char *); | |
c906108c | 260 | |
a14ed312 | 261 | static struct symbol *new_symbol (char *); |
c906108c | 262 | |
a14ed312 | 263 | static struct type *new_type (char *); |
c906108c | 264 | |
de4f826b | 265 | enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK }; |
c906108c | 266 | |
de4f826b DC |
267 | static struct block *new_block (enum block_type); |
268 | ||
269 | static struct symtab *new_symtab (char *, int, struct objfile *); | |
c906108c | 270 | |
a14ed312 | 271 | static struct linetable *new_linetable (int); |
c906108c | 272 | |
a14ed312 | 273 | static struct blockvector *new_bvect (int); |
c906108c | 274 | |
a14ed312 KB |
275 | static struct type *parse_type (int, union aux_ext *, unsigned int, int *, |
276 | int, char *); | |
c906108c | 277 | |
176620f1 | 278 | static struct symbol *mylookup_symbol (char *, struct block *, domain_enum, |
a14ed312 | 279 | enum address_class); |
c906108c | 280 | |
a14ed312 | 281 | static void sort_blocks (struct symtab *); |
c906108c | 282 | |
a14ed312 | 283 | static struct partial_symtab *new_psymtab (char *, struct objfile *); |
c906108c | 284 | |
a14ed312 | 285 | static void psymtab_to_symtab_1 (struct partial_symtab *, char *); |
c906108c | 286 | |
a14ed312 | 287 | static void add_block (struct block *, struct symtab *); |
c906108c | 288 | |
a14ed312 | 289 | static void add_symbol (struct symbol *, struct block *); |
c906108c | 290 | |
a14ed312 | 291 | static int add_line (struct linetable *, int, CORE_ADDR, int); |
c906108c | 292 | |
a14ed312 | 293 | static struct linetable *shrink_linetable (struct linetable *); |
c906108c | 294 | |
12b9c64f AO |
295 | static void handle_psymbol_enumerators (struct objfile *, FDR *, int, |
296 | CORE_ADDR); | |
c906108c | 297 | |
a14ed312 | 298 | static char *mdebug_next_symbol_text (struct objfile *); |
c906108c | 299 | \f |
c906108c SS |
300 | /* Allocate zeroed memory */ |
301 | ||
12b9c64f | 302 | static void * |
fba45db2 | 303 | xzalloc (unsigned int size) |
c906108c | 304 | { |
12b9c64f | 305 | void *p = xmalloc (size); |
c906108c SS |
306 | |
307 | memset (p, 0, size); | |
308 | return p; | |
309 | } | |
310 | ||
311 | /* Exported procedure: Builds a symtab from the PST partial one. | |
312 | Restores the environment in effect when PST was created, delegates | |
313 | most of the work to an ancillary procedure, and sorts | |
314 | and reorders the symtab list at the end */ | |
315 | ||
316 | static void | |
fba45db2 | 317 | mdebug_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
318 | { |
319 | ||
320 | if (!pst) | |
321 | return; | |
322 | ||
323 | if (info_verbose) | |
324 | { | |
325 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
326 | gdb_flush (gdb_stdout); | |
327 | } | |
328 | ||
329 | next_symbol_text_func = mdebug_next_symbol_text; | |
330 | ||
331 | psymtab_to_symtab_1 (pst, pst->filename); | |
332 | ||
333 | /* Match with global symbols. This only needs to be done once, | |
334 | after all of the symtabs and dependencies have been read in. */ | |
335 | scan_file_globals (pst->objfile); | |
336 | ||
337 | if (info_verbose) | |
338 | printf_filtered ("done.\n"); | |
339 | } | |
340 | \f | |
341 | /* File-level interface functions */ | |
342 | ||
343 | /* Find a file descriptor given its index RF relative to a file CF */ | |
344 | ||
345 | static FDR * | |
fba45db2 | 346 | get_rfd (int cf, int rf) |
c906108c SS |
347 | { |
348 | FDR *fdrs; | |
52f0bd74 | 349 | FDR *f; |
c906108c SS |
350 | RFDT rfd; |
351 | ||
352 | fdrs = debug_info->fdr; | |
353 | f = fdrs + cf; | |
354 | /* Object files do not have the RFD table, all refs are absolute */ | |
355 | if (f->rfdBase == 0) | |
356 | return fdrs + rf; | |
357 | (*debug_swap->swap_rfd_in) (cur_bfd, | |
c5aa993b JM |
358 | ((char *) debug_info->external_rfd |
359 | + ((f->rfdBase + rf) | |
360 | * debug_swap->external_rfd_size)), | |
361 | &rfd); | |
c906108c SS |
362 | return fdrs + rfd; |
363 | } | |
364 | ||
365 | /* Return a safer print NAME for a file descriptor */ | |
366 | ||
367 | static char * | |
fba45db2 | 368 | fdr_name (FDR *f) |
c906108c SS |
369 | { |
370 | if (f->rss == -1) | |
371 | return "<stripped file>"; | |
372 | if (f->rss == 0) | |
373 | return "<NFY>"; | |
374 | return debug_info->ss + f->issBase + f->rss; | |
375 | } | |
376 | ||
377 | ||
378 | /* Read in and parse the symtab of the file OBJFILE. Symbols from | |
379 | different sections are relocated via the SECTION_OFFSETS. */ | |
380 | ||
381 | void | |
fba45db2 KB |
382 | mdebug_build_psymtabs (struct objfile *objfile, |
383 | const struct ecoff_debug_swap *swap, | |
384 | struct ecoff_debug_info *info) | |
c906108c SS |
385 | { |
386 | cur_bfd = objfile->obfd; | |
387 | debug_swap = swap; | |
388 | debug_info = info; | |
389 | ||
d3d55eeb EZ |
390 | stabsread_new_init (); |
391 | buildsym_new_init (); | |
392 | free_header_files (); | |
393 | init_header_files (); | |
394 | ||
c906108c SS |
395 | /* Make sure all the FDR information is swapped in. */ |
396 | if (info->fdr == (FDR *) NULL) | |
397 | { | |
398 | char *fdr_src; | |
399 | char *fdr_end; | |
400 | FDR *fdr_ptr; | |
401 | ||
8b92e4d5 | 402 | info->fdr = (FDR *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
403 | (info->symbolic_header.ifdMax |
404 | * sizeof (FDR))); | |
405 | fdr_src = info->external_fdr; | |
406 | fdr_end = (fdr_src | |
407 | + info->symbolic_header.ifdMax * swap->external_fdr_size); | |
408 | fdr_ptr = info->fdr; | |
409 | for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++) | |
410 | (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr); | |
411 | } | |
412 | ||
d4f3574e | 413 | parse_partial_symbols (objfile); |
c906108c SS |
414 | |
415 | #if 0 | |
416 | /* Check to make sure file was compiled with -g. If not, warn the | |
417 | user of this limitation. */ | |
418 | if (compare_glevel (max_glevel, GLEVEL_2) < 0) | |
419 | { | |
420 | if (max_gdbinfo == 0) | |
421 | printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n", | |
c5aa993b | 422 | objfile->name); |
c906108c SS |
423 | printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n"); |
424 | gdb_flush (gdb_stdout); | |
425 | } | |
426 | #endif | |
427 | } | |
428 | \f | |
429 | /* Local utilities */ | |
430 | ||
431 | /* Map of FDR indexes to partial symtabs */ | |
432 | ||
433 | struct pst_map | |
434 | { | |
435 | struct partial_symtab *pst; /* the psymtab proper */ | |
436 | long n_globals; /* exported globals (external symbols) */ | |
437 | long globals_offset; /* cumulative */ | |
438 | }; | |
439 | ||
440 | ||
441 | /* Utility stack, used to nest procedures and blocks properly. | |
442 | It is a doubly linked list, to avoid too many alloc/free. | |
443 | Since we might need it quite a few times it is NOT deallocated | |
444 | after use. */ | |
445 | ||
446 | static struct parse_stack | |
c5aa993b JM |
447 | { |
448 | struct parse_stack *next, *prev; | |
449 | struct symtab *cur_st; /* Current symtab. */ | |
450 | struct block *cur_block; /* Block in it. */ | |
451 | ||
452 | /* What are we parsing. stFile, or stBlock are for files and | |
453 | blocks. stProc or stStaticProc means we have seen the start of a | |
454 | procedure, but not the start of the block within in. When we see | |
455 | the start of that block, we change it to stNil, without pushing a | |
456 | new block, i.e. stNil means both a procedure and a block. */ | |
457 | ||
458 | int blocktype; | |
459 | ||
c5aa993b JM |
460 | struct type *cur_type; /* Type we parse fields for. */ |
461 | int cur_field; /* Field number in cur_type. */ | |
462 | CORE_ADDR procadr; /* Start addres of this procedure */ | |
463 | int numargs; /* Its argument count */ | |
464 | } | |
c906108c SS |
465 | |
466 | *top_stack; /* Top stack ptr */ | |
467 | ||
468 | ||
469 | /* Enter a new lexical context */ | |
470 | ||
471 | static void | |
fba45db2 | 472 | push_parse_stack (void) |
c906108c SS |
473 | { |
474 | struct parse_stack *new; | |
475 | ||
476 | /* Reuse frames if possible */ | |
477 | if (top_stack && top_stack->prev) | |
478 | new = top_stack->prev; | |
479 | else | |
480 | new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack)); | |
481 | /* Initialize new frame with previous content */ | |
482 | if (top_stack) | |
483 | { | |
aa1ee363 | 484 | struct parse_stack *prev = new->prev; |
c906108c SS |
485 | |
486 | *new = *top_stack; | |
487 | top_stack->prev = new; | |
488 | new->prev = prev; | |
489 | new->next = top_stack; | |
490 | } | |
491 | top_stack = new; | |
492 | } | |
493 | ||
494 | /* Exit a lexical context */ | |
495 | ||
496 | static void | |
fba45db2 | 497 | pop_parse_stack (void) |
c906108c SS |
498 | { |
499 | if (!top_stack) | |
500 | return; | |
501 | if (top_stack->next) | |
502 | top_stack = top_stack->next; | |
503 | } | |
504 | ||
505 | ||
506 | /* Cross-references might be to things we haven't looked at | |
507 | yet, e.g. type references. To avoid too many type | |
508 | duplications we keep a quick fixup table, an array | |
509 | of lists of references indexed by file descriptor */ | |
510 | ||
511 | struct mdebug_pending | |
512 | { | |
513 | struct mdebug_pending *next; /* link */ | |
514 | char *s; /* the unswapped symbol */ | |
515 | struct type *t; /* its partial type descriptor */ | |
516 | }; | |
517 | ||
518 | ||
519 | /* The pending information is kept for an entire object file, and used | |
0a6ddd08 AC |
520 | to be in the deprecated_sym_private field. I took it out when I |
521 | split mdebugread from mipsread, because this might not be the only | |
522 | type of symbols read from an object file. Instead, we allocate the | |
c906108c SS |
523 | pending information table when we create the partial symbols, and |
524 | we store a pointer to the single table in each psymtab. */ | |
525 | ||
526 | static struct mdebug_pending **pending_list; | |
527 | ||
528 | /* Check whether we already saw symbol SH in file FH */ | |
529 | ||
530 | static struct mdebug_pending * | |
fba45db2 | 531 | is_pending_symbol (FDR *fh, char *sh) |
c906108c SS |
532 | { |
533 | int f_idx = fh - debug_info->fdr; | |
52f0bd74 | 534 | struct mdebug_pending *p; |
c906108c SS |
535 | |
536 | /* Linear search is ok, list is typically no more than 10 deep */ | |
537 | for (p = pending_list[f_idx]; p; p = p->next) | |
538 | if (p->s == sh) | |
539 | break; | |
540 | return p; | |
541 | } | |
542 | ||
543 | /* Add a new symbol SH of type T */ | |
544 | ||
545 | static void | |
fba45db2 | 546 | add_pending (FDR *fh, char *sh, struct type *t) |
c906108c SS |
547 | { |
548 | int f_idx = fh - debug_info->fdr; | |
549 | struct mdebug_pending *p = is_pending_symbol (fh, sh); | |
550 | ||
551 | /* Make sure we do not make duplicates */ | |
552 | if (!p) | |
553 | { | |
554 | p = ((struct mdebug_pending *) | |
8b92e4d5 | 555 | obstack_alloc (¤t_objfile->objfile_obstack, |
c906108c SS |
556 | sizeof (struct mdebug_pending))); |
557 | p->s = sh; | |
558 | p->t = t; | |
559 | p->next = pending_list[f_idx]; | |
560 | pending_list[f_idx] = p; | |
561 | } | |
562 | } | |
563 | \f | |
564 | ||
565 | /* Parsing Routines proper. */ | |
566 | ||
567 | /* Parse a single symbol. Mostly just make up a GDB symbol for it. | |
568 | For blocks, procedures and types we open a new lexical context. | |
569 | This is basically just a big switch on the symbol's type. Argument | |
570 | AX is the base pointer of aux symbols for this file (fh->iauxBase). | |
571 | EXT_SH points to the unswapped symbol, which is needed for struct, | |
572 | union, etc., types; it is NULL for an EXTR. BIGEND says whether | |
573 | aux symbols are big-endian or little-endian. Return count of | |
574 | SYMR's handled (normally one). */ | |
575 | ||
576 | static int | |
fba45db2 KB |
577 | parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend, |
578 | struct section_offsets *section_offsets, struct objfile *objfile) | |
c906108c SS |
579 | { |
580 | const bfd_size_type external_sym_size = debug_swap->external_sym_size; | |
12b9c64f | 581 | void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in; |
c906108c SS |
582 | char *name; |
583 | struct symbol *s; | |
584 | struct block *b; | |
585 | struct mdebug_pending *pend; | |
586 | struct type *t; | |
587 | struct field *f; | |
588 | int count = 1; | |
589 | enum address_class class; | |
590 | TIR tir; | |
591 | long svalue = sh->value; | |
592 | int bitsize; | |
593 | ||
594 | if (ext_sh == (char *) NULL) | |
595 | name = debug_info->ssext + sh->iss; | |
596 | else | |
597 | name = debug_info->ss + cur_fdr->issBase + sh->iss; | |
598 | ||
599 | switch (sh->sc) | |
600 | { | |
601 | case scText: | |
602 | case scRConst: | |
603 | /* Do not relocate relative values. | |
c5aa993b JM |
604 | The value of a stEnd symbol is the displacement from the |
605 | corresponding start symbol value. | |
606 | The value of a stBlock symbol is the displacement from the | |
607 | procedure address. */ | |
c906108c | 608 | if (sh->st != stEnd && sh->st != stBlock) |
b8fbeb18 | 609 | sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
610 | break; |
611 | case scData: | |
612 | case scSData: | |
613 | case scRData: | |
614 | case scPData: | |
615 | case scXData: | |
b8fbeb18 | 616 | sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); |
c906108c SS |
617 | break; |
618 | case scBss: | |
619 | case scSBss: | |
b8fbeb18 | 620 | sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile)); |
c906108c SS |
621 | break; |
622 | } | |
623 | ||
624 | switch (sh->st) | |
625 | { | |
626 | case stNil: | |
627 | break; | |
628 | ||
629 | case stGlobal: /* external symbol, goes into global block */ | |
630 | class = LOC_STATIC; | |
631 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st), | |
632 | GLOBAL_BLOCK); | |
633 | s = new_symbol (name); | |
634 | SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; | |
635 | goto data; | |
636 | ||
637 | case stStatic: /* static data, goes into current block. */ | |
638 | class = LOC_STATIC; | |
639 | b = top_stack->cur_block; | |
640 | s = new_symbol (name); | |
c5aa993b | 641 | if (SC_IS_COMMON (sh->sc)) |
c906108c SS |
642 | { |
643 | /* It is a FORTRAN common block. At least for SGI Fortran the | |
644 | address is not in the symbol; we need to fix it later in | |
645 | scan_file_globals. */ | |
22abf04a | 646 | int bucket = hashname (DEPRECATED_SYMBOL_NAME (s)); |
c906108c SS |
647 | SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket]; |
648 | global_sym_chain[bucket] = s; | |
649 | } | |
650 | else | |
651 | SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; | |
652 | goto data; | |
653 | ||
654 | case stLocal: /* local variable, goes into current block */ | |
655 | if (sh->sc == scRegister) | |
656 | { | |
657 | class = LOC_REGISTER; | |
658 | svalue = ECOFF_REG_TO_REGNUM (svalue); | |
659 | } | |
660 | else | |
661 | class = LOC_LOCAL; | |
662 | b = top_stack->cur_block; | |
663 | s = new_symbol (name); | |
664 | SYMBOL_VALUE (s) = svalue; | |
665 | ||
666 | data: /* Common code for symbols describing data */ | |
176620f1 | 667 | SYMBOL_DOMAIN (s) = VAR_DOMAIN; |
c906108c SS |
668 | SYMBOL_CLASS (s) = class; |
669 | add_symbol (s, b); | |
670 | ||
671 | /* Type could be missing if file is compiled without debugging info. */ | |
c5aa993b | 672 | if (SC_IS_UNDEF (sh->sc) |
c906108c SS |
673 | || sh->sc == scNil || sh->index == indexNil) |
674 | SYMBOL_TYPE (s) = nodebug_var_symbol_type; | |
675 | else | |
676 | SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name); | |
677 | /* Value of a data symbol is its memory address */ | |
678 | break; | |
679 | ||
680 | case stParam: /* arg to procedure, goes into current block */ | |
681 | max_gdbinfo++; | |
682 | found_ecoff_debugging_info = 1; | |
683 | top_stack->numargs++; | |
684 | ||
685 | /* Special GNU C++ name. */ | |
686 | if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0) | |
687 | name = "this"; /* FIXME, not alloc'd in obstack */ | |
688 | s = new_symbol (name); | |
689 | ||
176620f1 | 690 | SYMBOL_DOMAIN (s) = VAR_DOMAIN; |
c906108c SS |
691 | switch (sh->sc) |
692 | { | |
693 | case scRegister: | |
694 | /* Pass by value in register. */ | |
c5aa993b | 695 | SYMBOL_CLASS (s) = LOC_REGPARM; |
c906108c SS |
696 | svalue = ECOFF_REG_TO_REGNUM (svalue); |
697 | break; | |
698 | case scVar: | |
699 | /* Pass by reference on stack. */ | |
c5aa993b | 700 | SYMBOL_CLASS (s) = LOC_REF_ARG; |
c906108c SS |
701 | break; |
702 | case scVarRegister: | |
703 | /* Pass by reference in register. */ | |
c5aa993b | 704 | SYMBOL_CLASS (s) = LOC_REGPARM_ADDR; |
c906108c SS |
705 | svalue = ECOFF_REG_TO_REGNUM (svalue); |
706 | break; | |
707 | default: | |
708 | /* Pass by value on stack. */ | |
c5aa993b | 709 | SYMBOL_CLASS (s) = LOC_ARG; |
c906108c SS |
710 | break; |
711 | } | |
712 | SYMBOL_VALUE (s) = svalue; | |
713 | SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name); | |
714 | add_symbol (s, top_stack->cur_block); | |
715 | break; | |
716 | ||
717 | case stLabel: /* label, goes into current block */ | |
718 | s = new_symbol (name); | |
176620f1 | 719 | SYMBOL_DOMAIN (s) = VAR_DOMAIN; /* so that it can be used */ |
c906108c SS |
720 | SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */ |
721 | SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value; | |
722 | SYMBOL_TYPE (s) = mdebug_type_int; | |
723 | add_symbol (s, top_stack->cur_block); | |
724 | break; | |
725 | ||
726 | case stProc: /* Procedure, usually goes into global block */ | |
727 | case stStaticProc: /* Static procedure, goes into current block */ | |
1fb4c65b JB |
728 | /* For stProc symbol records, we need to check the storage class |
729 | as well, as only (stProc, scText) entries represent "real" | |
730 | procedures - See the Compaq document titled "Object File / | |
731 | Symbol Table Format Specification" for more information. | |
732 | If the storage class is not scText, we discard the whole block | |
733 | of symbol records for this stProc. */ | |
734 | if (sh->st == stProc && sh->sc != scText) | |
735 | { | |
736 | char *ext_tsym = ext_sh; | |
737 | int keep_counting = 1; | |
738 | SYMR tsym; | |
739 | ||
740 | while (keep_counting) | |
741 | { | |
742 | ext_tsym += external_sym_size; | |
743 | (*swap_sym_in) (cur_bfd, ext_tsym, &tsym); | |
744 | count++; | |
745 | switch (tsym.st) | |
746 | { | |
747 | case stParam: | |
748 | break; | |
749 | case stEnd: | |
750 | keep_counting = 0; | |
751 | break; | |
752 | default: | |
753 | complaint (&symfile_complaints, | |
754 | "unknown symbol type 0x%x", sh->st); | |
755 | break; | |
756 | } | |
757 | } | |
758 | break; | |
759 | } | |
c906108c | 760 | s = new_symbol (name); |
176620f1 | 761 | SYMBOL_DOMAIN (s) = VAR_DOMAIN; |
c906108c SS |
762 | SYMBOL_CLASS (s) = LOC_BLOCK; |
763 | /* Type of the return value */ | |
c5aa993b | 764 | if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil) |
c906108c SS |
765 | t = mdebug_type_int; |
766 | else | |
767 | { | |
768 | t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name); | |
ee300cd4 AC |
769 | if (strcmp (name, "malloc") == 0 |
770 | && TYPE_CODE (t) == TYPE_CODE_VOID) | |
c906108c SS |
771 | { |
772 | /* I don't know why, but, at least under Alpha GNU/Linux, | |
c5aa993b JM |
773 | when linking against a malloc without debugging |
774 | symbols, its read as a function returning void---this | |
775 | is bad because it means we cannot call functions with | |
776 | string arguments interactively; i.e., "call | |
777 | printf("howdy\n")" would fail with the error message | |
778 | "program has no memory available". To avoid this, we | |
779 | patch up the type and make it void* | |
780 | instead. (davidm@azstarnet.com) | |
781 | */ | |
c906108c SS |
782 | t = make_pointer_type (t, NULL); |
783 | } | |
784 | } | |
785 | b = top_stack->cur_block; | |
786 | if (sh->st == stProc) | |
787 | { | |
788 | struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st); | |
789 | /* The next test should normally be true, but provides a | |
790 | hook for nested functions (which we don't want to make | |
28397f59 | 791 | global). */ |
c906108c SS |
792 | if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) |
793 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
794 | /* Irix 5 sometimes has duplicate names for the same | |
795 | function. We want to add such names up at the global | |
796 | level, not as a nested function. */ | |
797 | else if (sh->value == top_stack->procadr) | |
798 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
799 | } | |
800 | add_symbol (s, b); | |
801 | ||
802 | /* Make a type for the procedure itself */ | |
803 | SYMBOL_TYPE (s) = lookup_function_type (t); | |
804 | ||
1e698235 DJ |
805 | /* All functions in C++ have prototypes. For C we don't have enough |
806 | information in the debug info. */ | |
807 | if (SYMBOL_LANGUAGE (s) == language_cplus) | |
808 | TYPE_FLAGS (SYMBOL_TYPE (s)) |= TYPE_FLAG_PROTOTYPED; | |
809 | ||
c906108c | 810 | /* Create and enter a new lexical context */ |
de4f826b | 811 | b = new_block (FUNCTION_BLOCK); |
c906108c SS |
812 | SYMBOL_BLOCK_VALUE (s) = b; |
813 | BLOCK_FUNCTION (b) = s; | |
814 | BLOCK_START (b) = BLOCK_END (b) = sh->value; | |
815 | BLOCK_SUPERBLOCK (b) = top_stack->cur_block; | |
816 | add_block (b, top_stack->cur_st); | |
817 | ||
818 | /* Not if we only have partial info */ | |
c5aa993b | 819 | if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil) |
c906108c SS |
820 | break; |
821 | ||
822 | push_parse_stack (); | |
823 | top_stack->cur_block = b; | |
824 | top_stack->blocktype = sh->st; | |
825 | top_stack->cur_type = SYMBOL_TYPE (s); | |
826 | top_stack->cur_field = -1; | |
827 | top_stack->procadr = sh->value; | |
828 | top_stack->numargs = 0; | |
829 | break; | |
830 | ||
831 | /* Beginning of code for structure, union, and enum definitions. | |
c5aa993b | 832 | They all share a common set of local variables, defined here. */ |
c906108c SS |
833 | { |
834 | enum type_code type_code; | |
835 | char *ext_tsym; | |
836 | int nfields; | |
837 | long max_value; | |
838 | struct field *f; | |
839 | ||
840 | case stStruct: /* Start a block defining a struct type */ | |
841 | type_code = TYPE_CODE_STRUCT; | |
842 | goto structured_common; | |
843 | ||
844 | case stUnion: /* Start a block defining a union type */ | |
845 | type_code = TYPE_CODE_UNION; | |
846 | goto structured_common; | |
847 | ||
848 | case stEnum: /* Start a block defining an enum type */ | |
849 | type_code = TYPE_CODE_ENUM; | |
850 | goto structured_common; | |
851 | ||
852 | case stBlock: /* Either a lexical block, or some type */ | |
c5aa993b | 853 | if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc)) |
c906108c SS |
854 | goto case_stBlock_code; /* Lexical block */ |
855 | ||
856 | type_code = TYPE_CODE_UNDEF; /* We have a type. */ | |
857 | ||
858 | /* Common code for handling struct, union, enum, and/or as-yet- | |
859 | unknown-type blocks of info about structured data. `type_code' | |
860 | has been set to the proper TYPE_CODE, if we know it. */ | |
861 | structured_common: | |
862 | found_ecoff_debugging_info = 1; | |
863 | push_parse_stack (); | |
864 | top_stack->blocktype = stBlock; | |
865 | ||
866 | /* First count the number of fields and the highest value. */ | |
867 | nfields = 0; | |
868 | max_value = 0; | |
869 | for (ext_tsym = ext_sh + external_sym_size; | |
870 | ; | |
871 | ext_tsym += external_sym_size) | |
872 | { | |
873 | SYMR tsym; | |
874 | ||
875 | (*swap_sym_in) (cur_bfd, ext_tsym, &tsym); | |
876 | ||
877 | switch (tsym.st) | |
878 | { | |
879 | case stEnd: | |
f0394be6 JB |
880 | /* C++ encodes class types as structures where there the |
881 | methods are encoded as stProc. The scope of stProc | |
882 | symbols also ends with stEnd, thus creating a risk of | |
883 | taking the wrong stEnd symbol record as the end of | |
884 | the current struct, which would cause GDB to undercount | |
885 | the real number of fields in this struct. To make sure | |
886 | we really reached the right stEnd symbol record, we | |
887 | check the associated name, and match it against the | |
888 | struct name. Since method names are mangled while | |
889 | the class name is not, there is no risk of having a | |
890 | method whose name is identical to the class name | |
891 | (in particular constructor method names are different | |
892 | from the class name). There is therefore no risk that | |
7bde8967 KB |
893 | this check stops the count on the StEnd of a method. |
894 | ||
895 | Also, assume that we're really at the end when tsym.iss | |
896 | is 0 (issNull). */ | |
897 | if (tsym.iss == issNull | |
898 | || strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss, | |
899 | name) == 0) | |
f0394be6 JB |
900 | goto end_of_fields; |
901 | break; | |
c906108c SS |
902 | |
903 | case stMember: | |
904 | if (nfields == 0 && type_code == TYPE_CODE_UNDEF) | |
7a292a7a SS |
905 | { |
906 | /* If the type of the member is Nil (or Void), | |
907 | without qualifiers, assume the tag is an | |
908 | enumeration. | |
909 | Alpha cc -migrate enums are recognized by a zero | |
910 | index and a zero symbol value. | |
911 | DU 4.0 cc enums are recognized by a member type of | |
912 | btEnum without qualifiers and a zero symbol value. */ | |
913 | if (tsym.index == indexNil | |
914 | || (tsym.index == 0 && sh->value == 0)) | |
915 | type_code = TYPE_CODE_ENUM; | |
916 | else | |
917 | { | |
918 | (*debug_swap->swap_tir_in) (bigend, | |
919 | &ax[tsym.index].a_ti, | |
920 | &tir); | |
921 | if ((tir.bt == btNil || tir.bt == btVoid | |
922 | || (tir.bt == btEnum && sh->value == 0)) | |
923 | && tir.tq0 == tqNil) | |
924 | type_code = TYPE_CODE_ENUM; | |
925 | } | |
926 | } | |
c906108c SS |
927 | nfields++; |
928 | if (tsym.value > max_value) | |
929 | max_value = tsym.value; | |
930 | break; | |
931 | ||
932 | case stBlock: | |
933 | case stUnion: | |
934 | case stEnum: | |
935 | case stStruct: | |
936 | { | |
937 | #if 0 | |
938 | /* This is a no-op; is it trying to tell us something | |
939 | we should be checking? */ | |
c5aa993b | 940 | if (tsym.sc == scVariant); /*UNIMPLEMENTED */ |
c906108c SS |
941 | #endif |
942 | if (tsym.index != 0) | |
943 | { | |
944 | /* This is something like a struct within a | |
c5aa993b JM |
945 | struct. Skip over the fields of the inner |
946 | struct. The -1 is because the for loop will | |
947 | increment ext_tsym. */ | |
c906108c SS |
948 | ext_tsym = ((char *) debug_info->external_sym |
949 | + ((cur_fdr->isymBase + tsym.index - 1) | |
950 | * external_sym_size)); | |
951 | } | |
952 | } | |
953 | break; | |
954 | ||
955 | case stTypedef: | |
956 | /* mips cc puts out a typedef for struct x if it is not yet | |
957 | defined when it encounters | |
958 | struct y { struct x *xp; }; | |
959 | Just ignore it. */ | |
960 | break; | |
961 | ||
962 | case stIndirect: | |
963 | /* Irix5 cc puts out a stIndirect for struct x if it is not | |
964 | yet defined when it encounters | |
965 | struct y { struct x *xp; }; | |
966 | Just ignore it. */ | |
967 | break; | |
968 | ||
969 | default: | |
23136709 KB |
970 | complaint (&symfile_complaints, |
971 | "declaration block contains unhandled symbol type %d", | |
972 | tsym.st); | |
c906108c SS |
973 | } |
974 | } | |
975 | end_of_fields:; | |
976 | ||
977 | /* In an stBlock, there is no way to distinguish structs, | |
978 | unions, and enums at this point. This is a bug in the | |
979 | original design (that has been fixed with the recent | |
980 | addition of the stStruct, stUnion, and stEnum symbol | |
981 | types.) The way you can tell is if/when you see a variable | |
982 | or field of that type. In that case the variable's type | |
983 | (in the AUX table) says if the type is struct, union, or | |
984 | enum, and points back to the stBlock here. So you can | |
985 | patch the tag kind up later - but only if there actually is | |
986 | a variable or field of that type. | |
987 | ||
988 | So until we know for sure, we will guess at this point. | |
989 | The heuristic is: | |
990 | If the first member has index==indexNil or a void type, | |
991 | assume we have an enumeration. | |
992 | Otherwise, if there is more than one member, and all | |
993 | the members have offset 0, assume we have a union. | |
994 | Otherwise, assume we have a struct. | |
995 | ||
996 | The heuristic could guess wrong in the case of of an | |
997 | enumeration with no members or a union with one (or zero) | |
998 | members, or when all except the last field of a struct have | |
999 | width zero. These are uncommon and/or illegal situations, | |
1000 | and in any case guessing wrong probably doesn't matter | |
1001 | much. | |
1002 | ||
1003 | But if we later do find out we were wrong, we fixup the tag | |
1004 | kind. Members of an enumeration must be handled | |
1005 | differently from struct/union fields, and that is harder to | |
1006 | patch up, but luckily we shouldn't need to. (If there are | |
1007 | any enumeration members, we can tell for sure it's an enum | |
1008 | here.) */ | |
1009 | ||
1010 | if (type_code == TYPE_CODE_UNDEF) | |
7a292a7a SS |
1011 | { |
1012 | if (nfields > 1 && max_value == 0) | |
1013 | type_code = TYPE_CODE_UNION; | |
1014 | else | |
1015 | type_code = TYPE_CODE_STRUCT; | |
1016 | } | |
c906108c SS |
1017 | |
1018 | /* Create a new type or use the pending type. */ | |
1019 | pend = is_pending_symbol (cur_fdr, ext_sh); | |
1020 | if (pend == (struct mdebug_pending *) NULL) | |
1021 | { | |
1022 | t = new_type (NULL); | |
1023 | add_pending (cur_fdr, ext_sh, t); | |
1024 | } | |
1025 | else | |
1026 | t = pend->t; | |
1027 | ||
1028 | /* Do not set the tag name if it is a compiler generated tag name | |
1029 | (.Fxx or .xxfake or empty) for unnamed struct/union/enums. | |
1030 | Alpha cc puts out an sh->iss of zero for those. */ | |
1031 | if (sh->iss == 0 || name[0] == '.' || name[0] == '\0') | |
1032 | TYPE_TAG_NAME (t) = NULL; | |
1033 | else | |
4a146b47 | 1034 | TYPE_TAG_NAME (t) = obconcat (¤t_objfile->objfile_obstack, |
c906108c SS |
1035 | "", "", name); |
1036 | ||
1037 | TYPE_CODE (t) = type_code; | |
1038 | TYPE_LENGTH (t) = sh->value; | |
1039 | TYPE_NFIELDS (t) = nfields; | |
1040 | TYPE_FIELDS (t) = f = ((struct field *) | |
1041 | TYPE_ALLOC (t, | |
1042 | nfields * sizeof (struct field))); | |
1043 | ||
1044 | if (type_code == TYPE_CODE_ENUM) | |
1045 | { | |
1046 | int unsigned_enum = 1; | |
1047 | ||
1048 | /* This is a non-empty enum. */ | |
1049 | ||
1050 | /* DEC c89 has the number of enumerators in the sh.value field, | |
1051 | not the type length, so we have to compensate for that | |
1052 | incompatibility quirk. | |
1053 | This might do the wrong thing for an enum with one or two | |
1054 | enumerators and gcc -gcoff -fshort-enums, but these cases | |
1055 | are hopefully rare enough. | |
1056 | Alpha cc -migrate has a sh.value field of zero, we adjust | |
1057 | that too. */ | |
1058 | if (TYPE_LENGTH (t) == TYPE_NFIELDS (t) | |
1059 | || TYPE_LENGTH (t) == 0) | |
1060 | TYPE_LENGTH (t) = TARGET_INT_BIT / HOST_CHAR_BIT; | |
1061 | for (ext_tsym = ext_sh + external_sym_size; | |
1062 | ; | |
1063 | ext_tsym += external_sym_size) | |
1064 | { | |
1065 | SYMR tsym; | |
1066 | struct symbol *enum_sym; | |
1067 | ||
1068 | (*swap_sym_in) (cur_bfd, ext_tsym, &tsym); | |
1069 | ||
1070 | if (tsym.st != stMember) | |
1071 | break; | |
1072 | ||
1073 | FIELD_BITPOS (*f) = tsym.value; | |
1074 | FIELD_TYPE (*f) = t; | |
1075 | FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss; | |
1076 | FIELD_BITSIZE (*f) = 0; | |
01ad7f36 | 1077 | FIELD_STATIC_KIND (*f) = 0; |
c906108c SS |
1078 | |
1079 | enum_sym = ((struct symbol *) | |
4a146b47 | 1080 | obstack_alloc (¤t_objfile->objfile_obstack, |
c906108c | 1081 | sizeof (struct symbol))); |
12b9c64f | 1082 | memset (enum_sym, 0, sizeof (struct symbol)); |
22abf04a | 1083 | DEPRECATED_SYMBOL_NAME (enum_sym) = |
c906108c | 1084 | obsavestring (f->name, strlen (f->name), |
4a146b47 | 1085 | ¤t_objfile->objfile_obstack); |
c906108c SS |
1086 | SYMBOL_CLASS (enum_sym) = LOC_CONST; |
1087 | SYMBOL_TYPE (enum_sym) = t; | |
176620f1 | 1088 | SYMBOL_DOMAIN (enum_sym) = VAR_DOMAIN; |
c906108c SS |
1089 | SYMBOL_VALUE (enum_sym) = tsym.value; |
1090 | if (SYMBOL_VALUE (enum_sym) < 0) | |
1091 | unsigned_enum = 0; | |
1092 | add_symbol (enum_sym, top_stack->cur_block); | |
1093 | ||
1094 | /* Skip the stMembers that we've handled. */ | |
1095 | count++; | |
1096 | f++; | |
1097 | } | |
1098 | if (unsigned_enum) | |
1099 | TYPE_FLAGS (t) |= TYPE_FLAG_UNSIGNED; | |
1100 | } | |
1101 | /* make this the current type */ | |
1102 | top_stack->cur_type = t; | |
1103 | top_stack->cur_field = 0; | |
1104 | ||
1105 | /* Do not create a symbol for alpha cc unnamed structs. */ | |
1106 | if (sh->iss == 0) | |
1107 | break; | |
1108 | ||
1109 | /* gcc puts out an empty struct for an opaque struct definitions, | |
1110 | do not create a symbol for it either. */ | |
1111 | if (TYPE_NFIELDS (t) == 0) | |
1112 | { | |
1113 | TYPE_FLAGS (t) |= TYPE_FLAG_STUB; | |
1114 | break; | |
1115 | } | |
1116 | ||
1117 | s = new_symbol (name); | |
176620f1 | 1118 | SYMBOL_DOMAIN (s) = STRUCT_DOMAIN; |
c906108c SS |
1119 | SYMBOL_CLASS (s) = LOC_TYPEDEF; |
1120 | SYMBOL_VALUE (s) = 0; | |
1121 | SYMBOL_TYPE (s) = t; | |
1122 | add_symbol (s, top_stack->cur_block); | |
1123 | break; | |
1124 | ||
1125 | /* End of local variables shared by struct, union, enum, and | |
1126 | block (as yet unknown struct/union/enum) processing. */ | |
1127 | } | |
1128 | ||
1129 | case_stBlock_code: | |
1130 | found_ecoff_debugging_info = 1; | |
1131 | /* beginnning of (code) block. Value of symbol | |
c5aa993b | 1132 | is the displacement from procedure start */ |
c906108c SS |
1133 | push_parse_stack (); |
1134 | ||
1135 | /* Do not start a new block if this is the outermost block of a | |
c5aa993b JM |
1136 | procedure. This allows the LOC_BLOCK symbol to point to the |
1137 | block with the local variables, so funcname::var works. */ | |
c906108c SS |
1138 | if (top_stack->blocktype == stProc |
1139 | || top_stack->blocktype == stStaticProc) | |
1140 | { | |
1141 | top_stack->blocktype = stNil; | |
1142 | break; | |
1143 | } | |
1144 | ||
1145 | top_stack->blocktype = stBlock; | |
de4f826b | 1146 | b = new_block (NON_FUNCTION_BLOCK); |
c906108c SS |
1147 | BLOCK_START (b) = sh->value + top_stack->procadr; |
1148 | BLOCK_SUPERBLOCK (b) = top_stack->cur_block; | |
1149 | top_stack->cur_block = b; | |
1150 | add_block (b, top_stack->cur_st); | |
1151 | break; | |
1152 | ||
1153 | case stEnd: /* end (of anything) */ | |
c5aa993b | 1154 | if (sh->sc == scInfo || SC_IS_COMMON (sh->sc)) |
c906108c SS |
1155 | { |
1156 | /* Finished with type */ | |
1157 | top_stack->cur_type = 0; | |
1158 | } | |
1159 | else if (sh->sc == scText && | |
1160 | (top_stack->blocktype == stProc || | |
1161 | top_stack->blocktype == stStaticProc)) | |
1162 | { | |
1163 | /* Finished with procedure */ | |
1164 | struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st); | |
f92761ec | 1165 | struct mdebug_extra_func_info *e; |
de4f826b | 1166 | struct block *b = top_stack->cur_block; |
c906108c SS |
1167 | struct type *ftype = top_stack->cur_type; |
1168 | int i; | |
1169 | ||
1170 | BLOCK_END (top_stack->cur_block) += sh->value; /* size */ | |
1171 | ||
1172 | /* Make up special symbol to contain procedure specific info */ | |
f92761ec | 1173 | s = new_symbol (MDEBUG_EFI_SYMBOL_NAME); |
176620f1 | 1174 | SYMBOL_DOMAIN (s) = LABEL_DOMAIN; |
c906108c SS |
1175 | SYMBOL_CLASS (s) = LOC_CONST; |
1176 | SYMBOL_TYPE (s) = mdebug_type_void; | |
f92761ec | 1177 | e = ((struct mdebug_extra_func_info *) |
4a146b47 | 1178 | obstack_alloc (¤t_objfile->objfile_obstack, |
f92761ec AC |
1179 | sizeof (struct mdebug_extra_func_info))); |
1180 | memset (e, 0, sizeof (struct mdebug_extra_func_info)); | |
c906108c SS |
1181 | SYMBOL_VALUE (s) = (long) e; |
1182 | e->numargs = top_stack->numargs; | |
1183 | e->pdr.framereg = -1; | |
1184 | add_symbol (s, top_stack->cur_block); | |
1185 | ||
c906108c SS |
1186 | /* f77 emits proc-level with address bounds==[0,0], |
1187 | So look for such child blocks, and patch them. */ | |
1188 | for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++) | |
1189 | { | |
1190 | struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i); | |
1191 | if (BLOCK_SUPERBLOCK (b_bad) == b | |
1192 | && BLOCK_START (b_bad) == top_stack->procadr | |
1193 | && BLOCK_END (b_bad) == top_stack->procadr) | |
1194 | { | |
1195 | BLOCK_START (b_bad) = BLOCK_START (b); | |
1196 | BLOCK_END (b_bad) = BLOCK_END (b); | |
1197 | } | |
1198 | } | |
1199 | ||
1200 | if (TYPE_NFIELDS (ftype) <= 0) | |
1201 | { | |
1202 | /* No parameter type information is recorded with the function's | |
c5aa993b | 1203 | type. Set that from the type of the parameter symbols. */ |
c906108c SS |
1204 | int nparams = top_stack->numargs; |
1205 | int iparams; | |
1206 | struct symbol *sym; | |
1207 | ||
1208 | if (nparams > 0) | |
1209 | { | |
de4f826b | 1210 | struct dict_iterator iter; |
c906108c SS |
1211 | TYPE_NFIELDS (ftype) = nparams; |
1212 | TYPE_FIELDS (ftype) = (struct field *) | |
1213 | TYPE_ALLOC (ftype, nparams * sizeof (struct field)); | |
c5aa993b | 1214 | |
de4f826b DC |
1215 | iparams = 0; |
1216 | ALL_BLOCK_SYMBOLS (b, iter, sym) | |
c906108c | 1217 | { |
de4f826b DC |
1218 | if (iparams == nparams) |
1219 | break; | |
1220 | ||
c906108c SS |
1221 | switch (SYMBOL_CLASS (sym)) |
1222 | { | |
1223 | case LOC_ARG: | |
1224 | case LOC_REF_ARG: | |
1225 | case LOC_REGPARM: | |
1226 | case LOC_REGPARM_ADDR: | |
1227 | TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym); | |
8176bb6d | 1228 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; |
c906108c SS |
1229 | iparams++; |
1230 | break; | |
1231 | default: | |
1232 | break; | |
1233 | } | |
1234 | } | |
1235 | } | |
1236 | } | |
1237 | } | |
1238 | else if (sh->sc == scText && top_stack->blocktype == stBlock) | |
1239 | { | |
1240 | /* End of (code) block. The value of the symbol is the | |
1241 | displacement from the procedure`s start address of the | |
1242 | end of this block. */ | |
1243 | BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr; | |
c906108c SS |
1244 | } |
1245 | else if (sh->sc == scText && top_stack->blocktype == stNil) | |
1246 | { | |
1247 | /* End of outermost block. Pop parse stack and ignore. The | |
1248 | following stEnd of stProc will take care of the block. */ | |
1249 | ; | |
1250 | } | |
1251 | else if (sh->sc == scText && top_stack->blocktype == stFile) | |
1252 | { | |
1253 | /* End of file. Pop parse stack and ignore. Higher | |
1254 | level code deals with this. */ | |
1255 | ; | |
1256 | } | |
1257 | else | |
23136709 KB |
1258 | complaint (&symfile_complaints, |
1259 | "stEnd with storage class %d not handled", sh->sc); | |
c906108c SS |
1260 | |
1261 | pop_parse_stack (); /* restore previous lexical context */ | |
1262 | break; | |
1263 | ||
1264 | case stMember: /* member of struct or union */ | |
1265 | f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++]; | |
1266 | FIELD_NAME (*f) = name; | |
1267 | FIELD_BITPOS (*f) = sh->value; | |
1268 | bitsize = 0; | |
1269 | FIELD_TYPE (*f) = parse_type (cur_fd, ax, sh->index, &bitsize, bigend, name); | |
1270 | FIELD_BITSIZE (*f) = bitsize; | |
01ad7f36 | 1271 | FIELD_STATIC_KIND (*f) = 0; |
c906108c SS |
1272 | break; |
1273 | ||
1274 | case stIndirect: /* forward declaration on Irix5 */ | |
1275 | /* Forward declarations from Irix5 cc are handled by cross_ref, | |
c5aa993b | 1276 | skip them. */ |
c906108c SS |
1277 | break; |
1278 | ||
1279 | case stTypedef: /* type definition */ | |
1280 | found_ecoff_debugging_info = 1; | |
1281 | ||
1282 | /* Typedefs for forward declarations and opaque structs from alpha cc | |
c5aa993b | 1283 | are handled by cross_ref, skip them. */ |
c906108c SS |
1284 | if (sh->iss == 0) |
1285 | break; | |
1286 | ||
1287 | /* Parse the type or use the pending type. */ | |
1288 | pend = is_pending_symbol (cur_fdr, ext_sh); | |
1289 | if (pend == (struct mdebug_pending *) NULL) | |
1290 | { | |
c5aa993b | 1291 | t = parse_type (cur_fd, ax, sh->index, (int *) NULL, bigend, name); |
c906108c SS |
1292 | add_pending (cur_fdr, ext_sh, t); |
1293 | } | |
1294 | else | |
1295 | t = pend->t; | |
1296 | ||
1297 | /* mips cc puts out a typedef with the name of the struct for forward | |
c5aa993b JM |
1298 | declarations. These should not go into the symbol table and |
1299 | TYPE_NAME should not be set for them. | |
1300 | They can't be distinguished from an intentional typedef to | |
1301 | the same name however: | |
1302 | x.h: | |
1303 | struct x { int ix; int jx; }; | |
1304 | struct xx; | |
1305 | x.c: | |
1306 | typedef struct x x; | |
1307 | struct xx {int ixx; int jxx; }; | |
1308 | generates a cross referencing stTypedef for x and xx. | |
1309 | The user visible effect of this is that the type of a pointer | |
1310 | to struct foo sometimes is given as `foo *' instead of `struct foo *'. | |
1311 | The problem is fixed with alpha cc and Irix5 cc. */ | |
c906108c SS |
1312 | |
1313 | /* However if the typedef cross references to an opaque aggregate, it | |
c5aa993b | 1314 | is safe to omit it from the symbol table. */ |
c906108c SS |
1315 | |
1316 | if (has_opaque_xref (cur_fdr, sh)) | |
1317 | break; | |
1318 | s = new_symbol (name); | |
176620f1 | 1319 | SYMBOL_DOMAIN (s) = VAR_DOMAIN; |
c906108c SS |
1320 | SYMBOL_CLASS (s) = LOC_TYPEDEF; |
1321 | SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block; | |
1322 | SYMBOL_TYPE (s) = t; | |
1323 | add_symbol (s, top_stack->cur_block); | |
1324 | ||
1325 | /* Incomplete definitions of structs should not get a name. */ | |
1326 | if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL | |
1327 | && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0 | |
c5aa993b | 1328 | || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT |
c906108c SS |
1329 | && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION))) |
1330 | { | |
1331 | if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR | |
1332 | || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC) | |
1333 | { | |
1334 | /* If we are giving a name to a type such as "pointer to | |
c5aa993b JM |
1335 | foo" or "function returning foo", we better not set |
1336 | the TYPE_NAME. If the program contains "typedef char | |
1337 | *caddr_t;", we don't want all variables of type char | |
1338 | * to print as caddr_t. This is not just a | |
1339 | consequence of GDB's type management; CC and GCC (at | |
1340 | least through version 2.4) both output variables of | |
1341 | either type char * or caddr_t with the type | |
1342 | refering to the stTypedef symbol for caddr_t. If a future | |
1343 | compiler cleans this up it GDB is not ready for it | |
1344 | yet, but if it becomes ready we somehow need to | |
1345 | disable this check (without breaking the PCC/GCC2.4 | |
1346 | case). | |
1347 | ||
1348 | Sigh. | |
1349 | ||
1350 | Fortunately, this check seems not to be necessary | |
1351 | for anything except pointers or functions. */ | |
c906108c SS |
1352 | } |
1353 | else | |
22abf04a | 1354 | TYPE_NAME (SYMBOL_TYPE (s)) = DEPRECATED_SYMBOL_NAME (s); |
c906108c SS |
1355 | } |
1356 | break; | |
1357 | ||
1358 | case stFile: /* file name */ | |
1359 | push_parse_stack (); | |
1360 | top_stack->blocktype = sh->st; | |
1361 | break; | |
1362 | ||
1363 | /* I`ve never seen these for C */ | |
1364 | case stRegReloc: | |
1365 | break; /* register relocation */ | |
1366 | case stForward: | |
1367 | break; /* forwarding address */ | |
1368 | case stConstant: | |
1369 | break; /* constant */ | |
1370 | default: | |
23136709 | 1371 | complaint (&symfile_complaints, "unknown symbol type 0x%x", sh->st); |
c906108c SS |
1372 | break; |
1373 | } | |
1374 | ||
1375 | return count; | |
1376 | } | |
1377 | ||
1378 | /* Parse the type information provided in the raw AX entries for | |
1379 | the symbol SH. Return the bitfield size in BS, in case. | |
1380 | We must byte-swap the AX entries before we use them; BIGEND says whether | |
1381 | they are big-endian or little-endian (from fh->fBigendian). */ | |
1382 | ||
1383 | static struct type * | |
fba45db2 KB |
1384 | parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs, |
1385 | int bigend, char *sym_name) | |
c906108c SS |
1386 | { |
1387 | /* Null entries in this map are treated specially */ | |
1388 | static struct type **map_bt[] = | |
1389 | { | |
c5aa993b JM |
1390 | &mdebug_type_void, /* btNil */ |
1391 | &mdebug_type_adr_32, /* btAdr */ | |
1392 | &mdebug_type_char, /* btChar */ | |
1393 | &mdebug_type_unsigned_char, /* btUChar */ | |
1394 | &mdebug_type_short, /* btShort */ | |
c906108c | 1395 | &mdebug_type_unsigned_short, /* btUShort */ |
c5aa993b | 1396 | &mdebug_type_int_32, /* btInt */ |
c906108c | 1397 | &mdebug_type_unsigned_int_32, /* btUInt */ |
c5aa993b | 1398 | &mdebug_type_long_32, /* btLong */ |
c906108c | 1399 | &mdebug_type_unsigned_long_32, /* btULong */ |
c5aa993b JM |
1400 | &mdebug_type_float, /* btFloat */ |
1401 | &mdebug_type_double, /* btDouble */ | |
1402 | 0, /* btStruct */ | |
1403 | 0, /* btUnion */ | |
1404 | 0, /* btEnum */ | |
1405 | 0, /* btTypedef */ | |
1406 | 0, /* btRange */ | |
1407 | 0, /* btSet */ | |
1408 | &mdebug_type_complex, /* btComplex */ | |
c906108c | 1409 | &mdebug_type_double_complex, /* btDComplex */ |
c5aa993b JM |
1410 | 0, /* btIndirect */ |
1411 | &mdebug_type_fixed_dec, /* btFixedDec */ | |
1412 | &mdebug_type_float_dec, /* btFloatDec */ | |
1413 | &mdebug_type_string, /* btString */ | |
1414 | 0, /* btBit */ | |
1415 | 0, /* btPicture */ | |
1416 | &mdebug_type_void, /* btVoid */ | |
1417 | 0, /* DEC C++: Pointer to member */ | |
1418 | 0, /* DEC C++: Virtual function table */ | |
1419 | 0, /* DEC C++: Class (Record) */ | |
1420 | &mdebug_type_long_64, /* btLong64 */ | |
c906108c | 1421 | &mdebug_type_unsigned_long_64, /* btULong64 */ |
c5aa993b JM |
1422 | &mdebug_type_long_long_64, /* btLongLong64 */ |
1423 | &mdebug_type_unsigned_long_long_64, /* btULongLong64 */ | |
1424 | &mdebug_type_adr_64, /* btAdr64 */ | |
1425 | &mdebug_type_int_64, /* btInt64 */ | |
c906108c SS |
1426 | &mdebug_type_unsigned_int_64, /* btUInt64 */ |
1427 | }; | |
1428 | ||
1429 | TIR t[1]; | |
1430 | struct type *tp = 0; | |
1431 | enum type_code type_code = TYPE_CODE_UNDEF; | |
1432 | ||
1433 | /* Handle undefined types, they have indexNil. */ | |
1434 | if (aux_index == indexNil) | |
1435 | return mdebug_type_int; | |
1436 | ||
1437 | /* Handle corrupt aux indices. */ | |
1438 | if (aux_index >= (debug_info->fdr + fd)->caux) | |
1439 | { | |
23136709 | 1440 | index_complaint (sym_name); |
c906108c SS |
1441 | return mdebug_type_int; |
1442 | } | |
1443 | ax += aux_index; | |
1444 | ||
1445 | /* Use aux as a type information record, map its basic type. */ | |
1446 | (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t); | |
1447 | if (t->bt >= (sizeof (map_bt) / sizeof (*map_bt))) | |
1448 | { | |
23136709 | 1449 | basic_type_complaint (t->bt, sym_name); |
c906108c SS |
1450 | return mdebug_type_int; |
1451 | } | |
1452 | if (map_bt[t->bt]) | |
1453 | { | |
1454 | tp = *map_bt[t->bt]; | |
1455 | } | |
1456 | else | |
1457 | { | |
1458 | tp = NULL; | |
1459 | /* Cannot use builtin types -- build our own */ | |
1460 | switch (t->bt) | |
1461 | { | |
1462 | case btStruct: | |
1463 | type_code = TYPE_CODE_STRUCT; | |
1464 | break; | |
1465 | case btUnion: | |
1466 | type_code = TYPE_CODE_UNION; | |
1467 | break; | |
1468 | case btEnum: | |
1469 | type_code = TYPE_CODE_ENUM; | |
1470 | break; | |
1471 | case btRange: | |
1472 | type_code = TYPE_CODE_RANGE; | |
1473 | break; | |
1474 | case btSet: | |
1475 | type_code = TYPE_CODE_SET; | |
1476 | break; | |
1477 | case btIndirect: | |
1478 | /* alpha cc -migrate uses this for typedefs. The true type will | |
1479 | be obtained by crossreferencing below. */ | |
1480 | type_code = TYPE_CODE_ERROR; | |
1481 | break; | |
1482 | case btTypedef: | |
1483 | /* alpha cc uses this for typedefs. The true type will be | |
1484 | obtained by crossreferencing below. */ | |
1485 | type_code = TYPE_CODE_ERROR; | |
1486 | break; | |
1487 | default: | |
23136709 | 1488 | basic_type_complaint (t->bt, sym_name); |
c906108c SS |
1489 | return mdebug_type_int; |
1490 | } | |
1491 | } | |
1492 | ||
1493 | /* Move on to next aux */ | |
1494 | ax++; | |
1495 | ||
1496 | if (t->fBitfield) | |
1497 | { | |
1498 | int width = AUX_GET_WIDTH (bigend, ax); | |
25caa7a8 | 1499 | /* Inhibit core dumps if TIR is corrupted. */ |
c5aa993b | 1500 | if (bs == (int *) NULL) |
c906108c SS |
1501 | { |
1502 | /* Alpha cc -migrate encodes char and unsigned char types | |
1503 | as short and unsigned short types with a field width of 8. | |
1504 | Enum types also have a field width which we ignore for now. */ | |
1505 | if (t->bt == btShort && width == 8) | |
1506 | tp = mdebug_type_char; | |
1507 | else if (t->bt == btUShort && width == 8) | |
1508 | tp = mdebug_type_unsigned_char; | |
1509 | else if (t->bt == btEnum) | |
1510 | ; | |
1511 | else | |
23136709 KB |
1512 | complaint (&symfile_complaints, "can't handle TIR fBitfield for %s", |
1513 | sym_name); | |
c906108c SS |
1514 | } |
1515 | else | |
c5aa993b | 1516 | *bs = width; |
c906108c SS |
1517 | ax++; |
1518 | } | |
1519 | ||
1520 | /* A btIndirect entry cross references to an aux entry containing | |
1521 | the type. */ | |
1522 | if (t->bt == btIndirect) | |
1523 | { | |
1524 | RNDXR rn[1]; | |
1525 | int rf; | |
1526 | FDR *xref_fh; | |
1527 | int xref_fd; | |
1528 | ||
1529 | (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn); | |
1530 | ax++; | |
1531 | if (rn->rfd == 0xfff) | |
1532 | { | |
1533 | rf = AUX_GET_ISYM (bigend, ax); | |
1534 | ax++; | |
1535 | } | |
1536 | else | |
1537 | rf = rn->rfd; | |
1538 | ||
1539 | if (rf == -1) | |
1540 | { | |
23136709 KB |
1541 | complaint (&symfile_complaints, |
1542 | "unable to cross ref btIndirect for %s", sym_name); | |
c906108c SS |
1543 | return mdebug_type_int; |
1544 | } | |
1545 | xref_fh = get_rfd (fd, rf); | |
1546 | xref_fd = xref_fh - debug_info->fdr; | |
1547 | tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase, | |
c5aa993b | 1548 | rn->index, (int *) NULL, xref_fh->fBigendian, sym_name); |
c906108c SS |
1549 | } |
1550 | ||
1551 | /* All these types really point to some (common) MIPS type | |
1552 | definition, and only the type-qualifiers fully identify | |
1553 | them. We'll make the same effort at sharing. */ | |
1554 | if (t->bt == btStruct || | |
1555 | t->bt == btUnion || | |
1556 | t->bt == btEnum || | |
1557 | ||
c5aa993b JM |
1558 | /* btSet (I think) implies that the name is a tag name, not a typedef |
1559 | name. This apparently is a MIPS extension for C sets. */ | |
c906108c SS |
1560 | t->bt == btSet) |
1561 | { | |
1562 | char *name; | |
1563 | ||
1564 | /* Try to cross reference this type, build new type on failure. */ | |
1565 | ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name); | |
1566 | if (tp == (struct type *) NULL) | |
1567 | tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile); | |
1568 | ||
1569 | /* DEC c89 produces cross references to qualified aggregate types, | |
c5aa993b | 1570 | dereference them. */ |
c906108c SS |
1571 | while (TYPE_CODE (tp) == TYPE_CODE_PTR |
1572 | || TYPE_CODE (tp) == TYPE_CODE_ARRAY) | |
0004e5a2 | 1573 | tp = TYPE_TARGET_TYPE (tp); |
c906108c SS |
1574 | |
1575 | /* Make sure that TYPE_CODE(tp) has an expected type code. | |
c5aa993b JM |
1576 | Any type may be returned from cross_ref if file indirect entries |
1577 | are corrupted. */ | |
c906108c SS |
1578 | if (TYPE_CODE (tp) != TYPE_CODE_STRUCT |
1579 | && TYPE_CODE (tp) != TYPE_CODE_UNION | |
1580 | && TYPE_CODE (tp) != TYPE_CODE_ENUM) | |
1581 | { | |
23136709 | 1582 | unexpected_type_code_complaint (sym_name); |
c906108c SS |
1583 | } |
1584 | else | |
1585 | { | |
1586 | ||
1587 | /* Usually, TYPE_CODE(tp) is already type_code. The main | |
1588 | exception is if we guessed wrong re struct/union/enum. | |
1589 | But for struct vs. union a wrong guess is harmless, so | |
1590 | don't complain(). */ | |
1591 | if ((TYPE_CODE (tp) == TYPE_CODE_ENUM | |
1592 | && type_code != TYPE_CODE_ENUM) | |
1593 | || (TYPE_CODE (tp) != TYPE_CODE_ENUM | |
1594 | && type_code == TYPE_CODE_ENUM)) | |
1595 | { | |
23136709 | 1596 | bad_tag_guess_complaint (sym_name); |
c906108c SS |
1597 | } |
1598 | ||
1599 | if (TYPE_CODE (tp) != type_code) | |
1600 | { | |
1601 | TYPE_CODE (tp) = type_code; | |
1602 | } | |
1603 | ||
1604 | /* Do not set the tag name if it is a compiler generated tag name | |
c5aa993b | 1605 | (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */ |
c906108c SS |
1606 | if (name[0] == '.' || name[0] == '\0') |
1607 | TYPE_TAG_NAME (tp) = NULL; | |
1608 | else if (TYPE_TAG_NAME (tp) == NULL | |
6314a349 | 1609 | || strcmp (TYPE_TAG_NAME (tp), name) != 0) |
c906108c | 1610 | TYPE_TAG_NAME (tp) = obsavestring (name, strlen (name), |
b99607ea | 1611 | ¤t_objfile->objfile_obstack); |
c906108c SS |
1612 | } |
1613 | } | |
1614 | ||
1615 | /* All these types really point to some (common) MIPS type | |
1616 | definition, and only the type-qualifiers fully identify | |
1617 | them. We'll make the same effort at sharing. | |
1618 | FIXME: We are not doing any guessing on range types. */ | |
1619 | if (t->bt == btRange) | |
1620 | { | |
1621 | char *name; | |
1622 | ||
1623 | /* Try to cross reference this type, build new type on failure. */ | |
1624 | ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name); | |
1625 | if (tp == (struct type *) NULL) | |
1626 | tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile); | |
1627 | ||
1628 | /* Make sure that TYPE_CODE(tp) has an expected type code. | |
c5aa993b JM |
1629 | Any type may be returned from cross_ref if file indirect entries |
1630 | are corrupted. */ | |
c906108c SS |
1631 | if (TYPE_CODE (tp) != TYPE_CODE_RANGE) |
1632 | { | |
23136709 | 1633 | unexpected_type_code_complaint (sym_name); |
c906108c SS |
1634 | } |
1635 | else | |
1636 | { | |
1637 | /* Usually, TYPE_CODE(tp) is already type_code. The main | |
1638 | exception is if we guessed wrong re struct/union/enum. */ | |
1639 | if (TYPE_CODE (tp) != type_code) | |
1640 | { | |
23136709 | 1641 | bad_tag_guess_complaint (sym_name); |
c906108c SS |
1642 | TYPE_CODE (tp) = type_code; |
1643 | } | |
ee300cd4 AC |
1644 | if (TYPE_NAME (tp) == NULL |
1645 | || strcmp (TYPE_NAME (tp), name) != 0) | |
c906108c | 1646 | TYPE_NAME (tp) = obsavestring (name, strlen (name), |
b99607ea | 1647 | ¤t_objfile->objfile_obstack); |
c906108c SS |
1648 | } |
1649 | } | |
1650 | if (t->bt == btTypedef) | |
1651 | { | |
1652 | char *name; | |
1653 | ||
1654 | /* Try to cross reference this type, it should succeed. */ | |
1655 | ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name); | |
1656 | if (tp == (struct type *) NULL) | |
1657 | { | |
23136709 KB |
1658 | complaint (&symfile_complaints, |
1659 | "unable to cross ref btTypedef for %s", sym_name); | |
c906108c SS |
1660 | tp = mdebug_type_int; |
1661 | } | |
1662 | } | |
1663 | ||
1664 | /* Deal with range types */ | |
1665 | if (t->bt == btRange) | |
1666 | { | |
1667 | TYPE_NFIELDS (tp) = 2; | |
1668 | TYPE_FIELDS (tp) = ((struct field *) | |
1669 | TYPE_ALLOC (tp, 2 * sizeof (struct field))); | |
1670 | TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"), | |
b99607ea | 1671 | ¤t_objfile->objfile_obstack); |
c906108c SS |
1672 | TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax); |
1673 | ax++; | |
1674 | TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"), | |
b99607ea | 1675 | ¤t_objfile->objfile_obstack); |
c906108c SS |
1676 | TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax); |
1677 | ax++; | |
1678 | } | |
1679 | ||
1680 | /* Parse all the type qualifiers now. If there are more | |
1681 | than 6 the game will continue in the next aux */ | |
1682 | ||
1683 | while (1) | |
1684 | { | |
1685 | #define PARSE_TQ(tq) \ | |
1686 | if (t->tq != tqNil) \ | |
1687 | ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \ | |
1688 | else \ | |
1689 | break; | |
1690 | ||
1691 | PARSE_TQ (tq0); | |
1692 | PARSE_TQ (tq1); | |
1693 | PARSE_TQ (tq2); | |
1694 | PARSE_TQ (tq3); | |
1695 | PARSE_TQ (tq4); | |
1696 | PARSE_TQ (tq5); | |
1697 | #undef PARSE_TQ | |
1698 | ||
1699 | /* mips cc 2.x and gcc never put out continued aux entries. */ | |
1700 | if (!t->continued) | |
1701 | break; | |
1702 | ||
1703 | (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t); | |
1704 | ax++; | |
1705 | } | |
1706 | ||
1707 | /* Complain for illegal continuations due to corrupt aux entries. */ | |
1708 | if (t->continued) | |
23136709 | 1709 | complaint (&symfile_complaints, "illegal TIR continued for %s", sym_name); |
c5aa993b | 1710 | |
c906108c SS |
1711 | return tp; |
1712 | } | |
1713 | ||
1714 | /* Make up a complex type from a basic one. Type is passed by | |
1715 | reference in TPP and side-effected as necessary. The type | |
1716 | qualifier TQ says how to handle the aux symbols at AX for | |
1717 | the symbol SX we are currently analyzing. BIGEND says whether | |
1718 | aux symbols are big-endian or little-endian. | |
1719 | Returns the number of aux symbols we parsed. */ | |
1720 | ||
1721 | static int | |
fba45db2 KB |
1722 | upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend, |
1723 | char *sym_name) | |
c906108c SS |
1724 | { |
1725 | int off; | |
1726 | struct type *t; | |
1727 | ||
1728 | /* Used in array processing */ | |
1729 | int rf, id; | |
1730 | FDR *fh; | |
1731 | struct type *range; | |
1732 | struct type *indx; | |
1733 | int lower, upper; | |
1734 | RNDXR rndx; | |
1735 | ||
1736 | switch (tq) | |
1737 | { | |
1738 | case tqPtr: | |
1739 | t = lookup_pointer_type (*tpp); | |
1740 | *tpp = t; | |
1741 | return 0; | |
1742 | ||
1743 | case tqProc: | |
1744 | t = lookup_function_type (*tpp); | |
1745 | *tpp = t; | |
1746 | return 0; | |
1747 | ||
1748 | case tqArray: | |
1749 | off = 0; | |
1750 | ||
1751 | /* Determine and record the domain type (type of index) */ | |
1752 | (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx); | |
1753 | id = rndx.index; | |
1754 | rf = rndx.rfd; | |
1755 | if (rf == 0xfff) | |
1756 | { | |
1757 | ax++; | |
1758 | rf = AUX_GET_ISYM (bigend, ax); | |
1759 | off++; | |
1760 | } | |
1761 | fh = get_rfd (fd, rf); | |
1762 | ||
1763 | indx = parse_type (fh - debug_info->fdr, | |
1764 | debug_info->external_aux + fh->iauxBase, | |
1765 | id, (int *) NULL, bigend, sym_name); | |
1766 | ||
1767 | /* The bounds type should be an integer type, but might be anything | |
c5aa993b | 1768 | else due to corrupt aux entries. */ |
c906108c SS |
1769 | if (TYPE_CODE (indx) != TYPE_CODE_INT) |
1770 | { | |
23136709 KB |
1771 | complaint (&symfile_complaints, |
1772 | "illegal array index type for %s, assuming int", sym_name); | |
c906108c SS |
1773 | indx = mdebug_type_int; |
1774 | } | |
1775 | ||
1776 | /* Get the bounds, and create the array type. */ | |
1777 | ax++; | |
1778 | lower = AUX_GET_DNLOW (bigend, ax); | |
1779 | ax++; | |
1780 | upper = AUX_GET_DNHIGH (bigend, ax); | |
1781 | ax++; | |
1782 | rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */ | |
1783 | ||
1784 | range = create_range_type ((struct type *) NULL, indx, | |
1785 | lower, upper); | |
1786 | ||
1787 | t = create_array_type ((struct type *) NULL, *tpp, range); | |
1788 | ||
1789 | /* We used to fill in the supplied array element bitsize | |
c5aa993b JM |
1790 | here if the TYPE_LENGTH of the target type was zero. |
1791 | This happens for a `pointer to an array of anonymous structs', | |
1792 | but in this case the array element bitsize is also zero, | |
1793 | so nothing is gained. | |
1794 | And we used to check the TYPE_LENGTH of the target type against | |
1795 | the supplied array element bitsize. | |
1796 | gcc causes a mismatch for `pointer to array of object', | |
1797 | since the sdb directives it uses do not have a way of | |
1798 | specifying the bitsize, but it does no harm (the | |
1799 | TYPE_LENGTH should be correct) and we should be able to | |
1800 | ignore the erroneous bitsize from the auxiliary entry safely. | |
1801 | dbx seems to ignore it too. */ | |
c906108c SS |
1802 | |
1803 | /* TYPE_FLAG_TARGET_STUB now takes care of the zero TYPE_LENGTH | |
c5aa993b | 1804 | problem. */ |
c906108c SS |
1805 | if (TYPE_LENGTH (*tpp) == 0) |
1806 | { | |
1807 | TYPE_FLAGS (t) |= TYPE_FLAG_TARGET_STUB; | |
1808 | } | |
1809 | ||
1810 | *tpp = t; | |
1811 | return 4 + off; | |
1812 | ||
1813 | case tqVol: | |
1814 | /* Volatile -- currently ignored */ | |
1815 | return 0; | |
1816 | ||
1817 | case tqConst: | |
1818 | /* Const -- currently ignored */ | |
1819 | return 0; | |
1820 | ||
1821 | default: | |
23136709 | 1822 | complaint (&symfile_complaints, "unknown type qualifier 0x%x", tq); |
c906108c SS |
1823 | return 0; |
1824 | } | |
1825 | } | |
1826 | ||
1827 | ||
1828 | /* Parse a procedure descriptor record PR. Note that the procedure is | |
1829 | parsed _after_ the local symbols, now we just insert the extra | |
f92761ec | 1830 | information we need into a MDEBUG_EFI_SYMBOL_NAME symbol that has |
c906108c SS |
1831 | already been placed in the procedure's main block. Note also that |
1832 | images that have been partially stripped (ld -x) have been deprived | |
1833 | of local symbols, and we have to cope with them here. FIRST_OFF is | |
1834 | the offset of the first procedure for this FDR; we adjust the | |
1835 | address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab | |
f92761ec | 1836 | to look for the function which contains the MDEBUG_EFI_SYMBOL_NAME symbol |
c906108c SS |
1837 | in question, or NULL to use top_stack->cur_block. */ |
1838 | ||
a14ed312 | 1839 | static void parse_procedure (PDR *, struct symtab *, struct partial_symtab *); |
c906108c SS |
1840 | |
1841 | static void | |
fba45db2 KB |
1842 | parse_procedure (PDR *pr, struct symtab *search_symtab, |
1843 | struct partial_symtab *pst) | |
c906108c SS |
1844 | { |
1845 | struct symbol *s, *i; | |
1846 | struct block *b; | |
f92761ec | 1847 | struct mdebug_extra_func_info *e; |
c906108c SS |
1848 | char *sh_name; |
1849 | ||
1850 | /* Simple rule to find files linked "-x" */ | |
1851 | if (cur_fdr->rss == -1) | |
1852 | { | |
1853 | if (pr->isym == -1) | |
1854 | { | |
1855 | /* Static procedure at address pr->adr. Sigh. */ | |
1856 | /* FIXME-32x64. assuming pr->adr fits in long. */ | |
23136709 KB |
1857 | complaint (&symfile_complaints, |
1858 | "can't handle PDR for static proc at 0x%lx", | |
1859 | (unsigned long) pr->adr); | |
c906108c SS |
1860 | return; |
1861 | } | |
1862 | else | |
1863 | { | |
1864 | /* external */ | |
1865 | EXTR she; | |
c5aa993b | 1866 | |
c906108c SS |
1867 | (*debug_swap->swap_ext_in) (cur_bfd, |
1868 | ((char *) debug_info->external_ext | |
1869 | + (pr->isym | |
1870 | * debug_swap->external_ext_size)), | |
1871 | &she); | |
1872 | sh_name = debug_info->ssext + she.asym.iss; | |
1873 | } | |
1874 | } | |
1875 | else | |
1876 | { | |
1877 | /* Full symbols */ | |
1878 | SYMR sh; | |
1879 | ||
1880 | (*debug_swap->swap_sym_in) (cur_bfd, | |
1881 | ((char *) debug_info->external_sym | |
1882 | + ((cur_fdr->isymBase + pr->isym) | |
1883 | * debug_swap->external_sym_size)), | |
1884 | &sh); | |
1885 | sh_name = debug_info->ss + cur_fdr->issBase + sh.iss; | |
1886 | } | |
1887 | ||
1888 | if (search_symtab != NULL) | |
1889 | { | |
1890 | #if 0 | |
1891 | /* This loses both in the case mentioned (want a static, find a global), | |
c5aa993b JM |
1892 | but also if we are looking up a non-mangled name which happens to |
1893 | match the name of a mangled function. */ | |
c906108c | 1894 | /* We have to save the cur_fdr across the call to lookup_symbol. |
c5aa993b JM |
1895 | If the pdr is for a static function and if a global function with |
1896 | the same name exists, lookup_symbol will eventually read in the symtab | |
1897 | for the global function and clobber cur_fdr. */ | |
c906108c | 1898 | FDR *save_cur_fdr = cur_fdr; |
176620f1 | 1899 | s = lookup_symbol (sh_name, NULL, VAR_DOMAIN, 0, NULL); |
c906108c SS |
1900 | cur_fdr = save_cur_fdr; |
1901 | #else | |
1902 | s = mylookup_symbol | |
1903 | (sh_name, | |
1904 | BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK), | |
176620f1 | 1905 | VAR_DOMAIN, |
c906108c SS |
1906 | LOC_BLOCK); |
1907 | #endif | |
1908 | } | |
1909 | else | |
1910 | s = mylookup_symbol (sh_name, top_stack->cur_block, | |
176620f1 | 1911 | VAR_DOMAIN, LOC_BLOCK); |
c906108c SS |
1912 | |
1913 | if (s != 0) | |
1914 | { | |
1915 | b = SYMBOL_BLOCK_VALUE (s); | |
1916 | } | |
1917 | else | |
1918 | { | |
23136709 | 1919 | complaint (&symfile_complaints, "PDR for %s, but no symbol", sh_name); |
c906108c SS |
1920 | #if 1 |
1921 | return; | |
1922 | #else | |
1923 | /* FIXME -- delete. We can't do symbol allocation now; it's all done. */ | |
1924 | s = new_symbol (sh_name); | |
176620f1 | 1925 | SYMBOL_DOMAIN (s) = VAR_DOMAIN; |
c906108c SS |
1926 | SYMBOL_CLASS (s) = LOC_BLOCK; |
1927 | /* Donno its type, hope int is ok */ | |
1928 | SYMBOL_TYPE (s) = lookup_function_type (mdebug_type_int); | |
1929 | add_symbol (s, top_stack->cur_block); | |
1930 | /* Wont have symbols for this one */ | |
1931 | b = new_block (2); | |
1932 | SYMBOL_BLOCK_VALUE (s) = b; | |
1933 | BLOCK_FUNCTION (b) = s; | |
1934 | BLOCK_START (b) = pr->adr; | |
1935 | /* BOUND used to be the end of procedure's text, but the | |
c5aa993b | 1936 | argument is no longer passed in. */ |
c906108c SS |
1937 | BLOCK_END (b) = bound; |
1938 | BLOCK_SUPERBLOCK (b) = top_stack->cur_block; | |
1939 | add_block (b, top_stack->cur_st); | |
1940 | #endif | |
1941 | } | |
1942 | ||
f92761ec | 1943 | i = mylookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, LOC_CONST); |
c906108c SS |
1944 | |
1945 | if (i) | |
1946 | { | |
f92761ec | 1947 | e = (struct mdebug_extra_func_info *) SYMBOL_VALUE (i); |
c906108c SS |
1948 | e->pdr = *pr; |
1949 | e->pdr.isym = (long) s; | |
1950 | ||
1951 | /* GDB expects the absolute function start address for the | |
c5aa993b JM |
1952 | procedure descriptor in e->pdr.adr. |
1953 | As the address in the procedure descriptor is usually relative, | |
1954 | we would have to relocate e->pdr.adr with cur_fdr->adr and | |
b8fbeb18 | 1955 | ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)). |
c5aa993b JM |
1956 | Unfortunately cur_fdr->adr and e->pdr.adr are both absolute |
1957 | in shared libraries on some systems, and on other systems | |
1958 | e->pdr.adr is sometimes offset by a bogus value. | |
1959 | To work around these problems, we replace e->pdr.adr with | |
1960 | the start address of the function. */ | |
c906108c SS |
1961 | e->pdr.adr = BLOCK_START (b); |
1962 | ||
1963 | /* Correct incorrect setjmp procedure descriptor from the library | |
c5aa993b | 1964 | to make backtrace through setjmp work. */ |
ee300cd4 AC |
1965 | if (e->pdr.pcreg == 0 |
1966 | && strcmp (sh_name, "setjmp") == 0) | |
c906108c | 1967 | { |
23136709 | 1968 | complaint (&symfile_complaints, "fixing bad setjmp PDR from libc"); |
9b792b1d | 1969 | #ifdef RA_REGNUM |
c906108c | 1970 | e->pdr.pcreg = RA_REGNUM; |
9b792b1d AC |
1971 | #else |
1972 | e->pdr.pcreg = 0; | |
1973 | #endif | |
c906108c SS |
1974 | e->pdr.regmask = 0x80000000; |
1975 | e->pdr.regoffset = -4; | |
1976 | } | |
1977 | } | |
1978 | ||
1979 | /* It would be reasonable that functions that have been compiled | |
1980 | without debugging info have a btNil type for their return value, | |
1981 | and functions that are void and are compiled with debugging info | |
1982 | have btVoid. | |
1983 | gcc and DEC f77 put out btNil types for both cases, so btNil is mapped | |
1984 | to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info' | |
1985 | case right. | |
1986 | The glevel field in cur_fdr could be used to determine the presence | |
1987 | of debugging info, but GCC doesn't always pass the -g switch settings | |
1988 | to the assembler and GAS doesn't set the glevel field from the -g switch | |
1989 | settings. | |
1990 | To work around these problems, the return value type of a TYPE_CODE_VOID | |
1991 | function is adjusted accordingly if no debugging info was found in the | |
1992 | compilation unit. */ | |
c5aa993b | 1993 | |
c906108c SS |
1994 | if (processing_gcc_compilation == 0 |
1995 | && found_ecoff_debugging_info == 0 | |
1996 | && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID) | |
1997 | SYMBOL_TYPE (s) = nodebug_func_symbol_type; | |
1998 | } | |
1999 | ||
c906108c SS |
2000 | /* Parse the external symbol ES. Just call parse_symbol() after |
2001 | making sure we know where the aux are for it. | |
2002 | BIGEND says whether aux entries are big-endian or little-endian. | |
2003 | ||
2004 | This routine clobbers top_stack->cur_block and ->cur_st. */ | |
2005 | ||
a14ed312 KB |
2006 | static void parse_external (EXTR *, int, struct section_offsets *, |
2007 | struct objfile *); | |
c906108c SS |
2008 | |
2009 | static void | |
fba45db2 KB |
2010 | parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets, |
2011 | struct objfile *objfile) | |
c906108c SS |
2012 | { |
2013 | union aux_ext *ax; | |
2014 | ||
2015 | if (es->ifd != ifdNil) | |
2016 | { | |
2017 | cur_fd = es->ifd; | |
2018 | cur_fdr = debug_info->fdr + cur_fd; | |
2019 | ax = debug_info->external_aux + cur_fdr->iauxBase; | |
2020 | } | |
2021 | else | |
2022 | { | |
2023 | cur_fdr = debug_info->fdr; | |
2024 | ax = 0; | |
2025 | } | |
2026 | ||
2027 | /* Reading .o files */ | |
c5aa993b | 2028 | if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil) |
c906108c SS |
2029 | { |
2030 | char *what; | |
2031 | switch (es->asym.st) | |
2032 | { | |
2033 | case stNil: | |
2034 | /* These are generated for static symbols in .o files, | |
2035 | ignore them. */ | |
2036 | return; | |
2037 | case stStaticProc: | |
2038 | case stProc: | |
2039 | what = "procedure"; | |
2040 | n_undef_procs++; | |
2041 | break; | |
2042 | case stGlobal: | |
2043 | what = "variable"; | |
2044 | n_undef_vars++; | |
2045 | break; | |
2046 | case stLabel: | |
2047 | what = "label"; | |
2048 | n_undef_labels++; | |
2049 | break; | |
2050 | default: | |
2051 | what = "symbol"; | |
2052 | break; | |
2053 | } | |
2054 | n_undef_symbols++; | |
2055 | /* FIXME: Turn this into a complaint? */ | |
2056 | if (info_verbose) | |
2057 | printf_filtered ("Warning: %s `%s' is undefined (in %s)\n", | |
2058 | what, debug_info->ssext + es->asym.iss, | |
2059 | fdr_name (cur_fdr)); | |
2060 | return; | |
2061 | } | |
2062 | ||
2063 | switch (es->asym.st) | |
2064 | { | |
2065 | case stProc: | |
2066 | case stStaticProc: | |
2067 | /* There is no need to parse the external procedure symbols. | |
c5aa993b JM |
2068 | If they are from objects compiled without -g, their index will |
2069 | be indexNil, and the symbol definition from the minimal symbol | |
2070 | is preferrable (yielding a function returning int instead of int). | |
2071 | If the index points to a local procedure symbol, the local | |
2072 | symbol already provides the correct type. | |
2073 | Note that the index of the external procedure symbol points | |
2074 | to the local procedure symbol in the local symbol table, and | |
2075 | _not_ to the auxiliary symbol info. */ | |
c906108c SS |
2076 | break; |
2077 | case stGlobal: | |
2078 | case stLabel: | |
2079 | /* Global common symbols are resolved by the runtime loader, | |
c5aa993b JM |
2080 | ignore them. */ |
2081 | if (SC_IS_COMMON (es->asym.sc)) | |
c906108c SS |
2082 | break; |
2083 | ||
2084 | /* Note that the case of a symbol with indexNil must be handled | |
c5aa993b | 2085 | anyways by parse_symbol(). */ |
b8fbeb18 | 2086 | parse_symbol (&es->asym, ax, (char *) NULL, bigend, section_offsets, objfile); |
c906108c SS |
2087 | break; |
2088 | default: | |
2089 | break; | |
2090 | } | |
2091 | } | |
2092 | ||
2093 | /* Parse the line number info for file descriptor FH into | |
2094 | GDB's linetable LT. MIPS' encoding requires a little bit | |
2095 | of magic to get things out. Note also that MIPS' line | |
2096 | numbers can go back and forth, apparently we can live | |
2097 | with that and do not need to reorder our linetables */ | |
2098 | ||
a14ed312 KB |
2099 | static void parse_lines (FDR *, PDR *, struct linetable *, int, |
2100 | struct partial_symtab *, CORE_ADDR); | |
c906108c SS |
2101 | |
2102 | static void | |
fba45db2 KB |
2103 | parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines, |
2104 | struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr) | |
c906108c SS |
2105 | { |
2106 | unsigned char *base; | |
2107 | int j, k; | |
2108 | int delta, count, lineno = 0; | |
2109 | ||
2110 | if (fh->cbLine == 0) | |
2111 | return; | |
2112 | ||
2113 | /* Scan by procedure descriptors */ | |
2114 | k = 0; | |
2115 | for (j = 0; j < fh->cpd; j++, pr++) | |
2116 | { | |
2117 | CORE_ADDR l; | |
2118 | CORE_ADDR adr; | |
2119 | unsigned char *halt; | |
2120 | ||
2121 | /* No code for this one */ | |
2122 | if (pr->iline == ilineNil || | |
2123 | pr->lnLow == -1 || pr->lnHigh == -1) | |
2124 | continue; | |
2125 | ||
2126 | /* Determine start and end address of compressed line bytes for | |
c5aa993b | 2127 | this procedure. */ |
c906108c SS |
2128 | base = debug_info->line + fh->cbLineOffset; |
2129 | if (j != (fh->cpd - 1)) | |
c5aa993b | 2130 | halt = base + pr[1].cbLineOffset; |
c906108c | 2131 | else |
c5aa993b | 2132 | halt = base + fh->cbLine; |
c906108c SS |
2133 | base += pr->cbLineOffset; |
2134 | ||
5afc051b | 2135 | adr = pst->textlow + pr->adr - lowest_pdr_addr; |
c906108c SS |
2136 | |
2137 | l = adr >> 2; /* in words */ | |
c5aa993b | 2138 | for (lineno = pr->lnLow; base < halt;) |
c906108c SS |
2139 | { |
2140 | count = *base & 0x0f; | |
2141 | delta = *base++ >> 4; | |
2142 | if (delta >= 8) | |
2143 | delta -= 16; | |
2144 | if (delta == -8) | |
2145 | { | |
2146 | delta = (base[0] << 8) | base[1]; | |
2147 | if (delta >= 0x8000) | |
2148 | delta -= 0x10000; | |
2149 | base += 2; | |
2150 | } | |
2151 | lineno += delta; /* first delta is 0 */ | |
2152 | ||
2153 | /* Complain if the line table overflows. Could happen | |
2154 | with corrupt binaries. */ | |
2155 | if (lt->nitems >= maxlines) | |
2156 | { | |
23136709 KB |
2157 | complaint (&symfile_complaints, |
2158 | "guessed size of linetable for %s incorrectly", | |
2159 | fdr_name (fh)); | |
c906108c SS |
2160 | break; |
2161 | } | |
2162 | k = add_line (lt, lineno, l, k); | |
2163 | l += count + 1; | |
2164 | } | |
2165 | } | |
2166 | } | |
2167 | \f | |
23136709 KB |
2168 | static void |
2169 | function_outside_compilation_unit_complaint (const char *arg1) | |
2170 | { | |
2171 | complaint (&symfile_complaints, | |
2172 | "function `%s' appears to be defined outside of all compilation units", | |
2173 | arg1); | |
2174 | } | |
2175 | ||
c906108c SS |
2176 | /* Master parsing procedure for first-pass reading of file symbols |
2177 | into a partial_symtab. */ | |
2178 | ||
2179 | static void | |
fba45db2 | 2180 | parse_partial_symbols (struct objfile *objfile) |
c906108c SS |
2181 | { |
2182 | const bfd_size_type external_sym_size = debug_swap->external_sym_size; | |
2183 | const bfd_size_type external_rfd_size = debug_swap->external_rfd_size; | |
2184 | const bfd_size_type external_ext_size = debug_swap->external_ext_size; | |
12b9c64f AO |
2185 | void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in; |
2186 | void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in; | |
2187 | void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in; | |
c906108c SS |
2188 | int f_idx, s_idx; |
2189 | HDRR *hdr = &debug_info->symbolic_header; | |
2190 | /* Running pointers */ | |
2191 | FDR *fh; | |
2192 | char *ext_out; | |
2193 | char *ext_out_end; | |
2194 | EXTR *ext_block; | |
52f0bd74 | 2195 | EXTR *ext_in; |
c906108c SS |
2196 | EXTR *ext_in_end; |
2197 | SYMR sh; | |
2198 | struct partial_symtab *pst; | |
2199 | int textlow_not_set = 1; | |
2200 | int past_first_source_file = 0; | |
2201 | ||
2202 | /* List of current psymtab's include files */ | |
2203 | char **psymtab_include_list; | |
2204 | int includes_allocated; | |
2205 | int includes_used; | |
2206 | EXTR *extern_tab; | |
2207 | struct pst_map *fdr_to_pst; | |
2208 | /* Index within current psymtab dependency list */ | |
2209 | struct partial_symtab **dependency_list; | |
2210 | int dependencies_used, dependencies_allocated; | |
2211 | struct cleanup *old_chain; | |
2212 | char *name; | |
2213 | enum language prev_language; | |
2214 | asection *text_sect; | |
2215 | int relocatable = 0; | |
2216 | ||
2217 | /* Irix 5.2 shared libraries have a fh->adr field of zero, but | |
2218 | the shared libraries are prelinked at a high memory address. | |
2219 | We have to adjust the start address of the object file for this case, | |
2220 | by setting it to the start address of the first procedure in the file. | |
2221 | But we should do no adjustments if we are debugging a .o file, where | |
2222 | the text section (and fh->adr) really starts at zero. */ | |
2223 | text_sect = bfd_get_section_by_name (cur_bfd, ".text"); | |
2224 | if (text_sect != NULL | |
2225 | && (bfd_get_section_flags (cur_bfd, text_sect) & SEC_RELOC)) | |
2226 | relocatable = 1; | |
2227 | ||
8b92e4d5 | 2228 | extern_tab = (EXTR *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
2229 | sizeof (EXTR) * hdr->iextMax); |
2230 | ||
2231 | includes_allocated = 30; | |
2232 | includes_used = 0; | |
2233 | psymtab_include_list = (char **) alloca (includes_allocated * | |
2234 | sizeof (char *)); | |
2235 | next_symbol_text_func = mdebug_next_symbol_text; | |
2236 | ||
2237 | dependencies_allocated = 30; | |
2238 | dependencies_used = 0; | |
2239 | dependency_list = | |
2240 | (struct partial_symtab **) alloca (dependencies_allocated * | |
2241 | sizeof (struct partial_symtab *)); | |
2242 | ||
2243 | last_source_file = NULL; | |
2244 | ||
2245 | /* | |
2246 | * Big plan: | |
2247 | * | |
2248 | * Only parse the Local and External symbols, and the Relative FDR. | |
2249 | * Fixup enough of the loader symtab to be able to use it. | |
2250 | * Allocate space only for the file's portions we need to | |
2251 | * look at. (XXX) | |
2252 | */ | |
2253 | ||
2254 | max_gdbinfo = 0; | |
2255 | max_glevel = MIN_GLEVEL; | |
2256 | ||
2257 | /* Allocate the map FDR -> PST. | |
2258 | Minor hack: -O3 images might claim some global data belongs | |
2259 | to FDR -1. We`ll go along with that */ | |
2260 | fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst); | |
b8c9b27d | 2261 | old_chain = make_cleanup (xfree, fdr_to_pst); |
c906108c SS |
2262 | fdr_to_pst++; |
2263 | { | |
d4f3574e | 2264 | struct partial_symtab *pst = new_psymtab ("", objfile); |
c906108c SS |
2265 | fdr_to_pst[-1].pst = pst; |
2266 | FDR_IDX (pst) = -1; | |
2267 | } | |
2268 | ||
2269 | /* Allocate the global pending list. */ | |
2270 | pending_list = | |
2271 | ((struct mdebug_pending **) | |
8b92e4d5 | 2272 | obstack_alloc (&objfile->objfile_obstack, |
c906108c | 2273 | hdr->ifdMax * sizeof (struct mdebug_pending *))); |
12b9c64f | 2274 | memset (pending_list, 0, |
c906108c SS |
2275 | hdr->ifdMax * sizeof (struct mdebug_pending *)); |
2276 | ||
2277 | /* Pass 0 over external syms: swap them in. */ | |
2278 | ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR)); | |
b8c9b27d | 2279 | make_cleanup (xfree, ext_block); |
c906108c SS |
2280 | |
2281 | ext_out = (char *) debug_info->external_ext; | |
2282 | ext_out_end = ext_out + hdr->iextMax * external_ext_size; | |
2283 | ext_in = ext_block; | |
2284 | for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++) | |
2285 | (*swap_ext_in) (cur_bfd, ext_out, ext_in); | |
2286 | ||
2287 | /* Pass 1 over external syms: Presize and partition the list */ | |
2288 | ext_in = ext_block; | |
2289 | ext_in_end = ext_in + hdr->iextMax; | |
2290 | for (; ext_in < ext_in_end; ext_in++) | |
2291 | { | |
2292 | /* See calls to complain below. */ | |
2293 | if (ext_in->ifd >= -1 | |
2294 | && ext_in->ifd < hdr->ifdMax | |
2295 | && ext_in->asym.iss >= 0 | |
2296 | && ext_in->asym.iss < hdr->issExtMax) | |
2297 | fdr_to_pst[ext_in->ifd].n_globals++; | |
2298 | } | |
2299 | ||
2300 | /* Pass 1.5 over files: partition out global symbol space */ | |
2301 | s_idx = 0; | |
2302 | for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) | |
2303 | { | |
2304 | fdr_to_pst[f_idx].globals_offset = s_idx; | |
2305 | s_idx += fdr_to_pst[f_idx].n_globals; | |
2306 | fdr_to_pst[f_idx].n_globals = 0; | |
2307 | } | |
2308 | ||
2309 | /* ECOFF in ELF: | |
2310 | ||
2311 | For ECOFF in ELF, we skip the creation of the minimal symbols. | |
2312 | The ECOFF symbols should be a subset of the Elf symbols, and the | |
2313 | section information of the elf symbols will be more accurate. | |
2314 | FIXME! What about Irix 5's native linker? | |
2315 | ||
2316 | By default, Elf sections which don't exist in ECOFF | |
2317 | get put in ECOFF's absolute section by the gnu linker. | |
2318 | Since absolute sections don't get relocated, we | |
2319 | end up calculating an address different from that of | |
2320 | the symbol's minimal symbol (created earlier from the | |
2321 | Elf symtab). | |
2322 | ||
2323 | To fix this, either : | |
2324 | 1) don't create the duplicate symbol | |
c5aa993b JM |
2325 | (assumes ECOFF symtab is a subset of the ELF symtab; |
2326 | assumes no side-effects result from ignoring ECOFF symbol) | |
c906108c | 2327 | 2) create it, only if lookup for existing symbol in ELF's minimal |
c5aa993b JM |
2328 | symbols fails |
2329 | (inefficient; | |
2330 | assumes no side-effects result from ignoring ECOFF symbol) | |
c906108c | 2331 | 3) create it, but lookup ELF's minimal symbol and use it's section |
c5aa993b JM |
2332 | during relocation, then modify "uniqify" phase to merge and |
2333 | eliminate the duplicate symbol | |
2334 | (highly inefficient) | |
c906108c SS |
2335 | |
2336 | I've implemented #1 here... | |
2337 | Skip the creation of the minimal symbols based on the ECOFF | |
2338 | symbol table. */ | |
2339 | ||
c5aa993b JM |
2340 | /* Pass 2 over external syms: fill in external symbols */ |
2341 | ext_in = ext_block; | |
2342 | ext_in_end = ext_in + hdr->iextMax; | |
2343 | for (; ext_in < ext_in_end; ext_in++) | |
2344 | { | |
2345 | enum minimal_symbol_type ms_type = mst_text; | |
2346 | CORE_ADDR svalue = ext_in->asym.value; | |
c906108c | 2347 | |
c5aa993b JM |
2348 | /* The Irix 5 native tools seem to sometimes generate bogus |
2349 | external symbols. */ | |
2350 | if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax) | |
2351 | { | |
23136709 KB |
2352 | complaint (&symfile_complaints, |
2353 | "bad ifd for external symbol: %d (max %ld)", ext_in->ifd, | |
2354 | hdr->ifdMax); | |
c5aa993b JM |
2355 | continue; |
2356 | } | |
2357 | if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax) | |
2358 | { | |
23136709 KB |
2359 | complaint (&symfile_complaints, |
2360 | "bad iss for external symbol: %ld (max %ld)", | |
2361 | ext_in->asym.iss, hdr->issExtMax); | |
c5aa993b JM |
2362 | continue; |
2363 | } | |
c906108c | 2364 | |
c5aa993b JM |
2365 | extern_tab[fdr_to_pst[ext_in->ifd].globals_offset |
2366 | + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in; | |
c906108c SS |
2367 | |
2368 | ||
c5aa993b JM |
2369 | if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil) |
2370 | continue; | |
c906108c | 2371 | |
c906108c | 2372 | |
c5aa993b JM |
2373 | /* Pass 3 over files, over local syms: fill in static symbols */ |
2374 | name = debug_info->ssext + ext_in->asym.iss; | |
2375 | ||
2376 | /* Process ECOFF Symbol Types and Storage Classes */ | |
2377 | switch (ext_in->asym.st) | |
2378 | { | |
2379 | case stProc: | |
2380 | /* Beginnning of Procedure */ | |
b8fbeb18 | 2381 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c5aa993b JM |
2382 | break; |
2383 | case stStaticProc: | |
2384 | /* Load time only static procs */ | |
2385 | ms_type = mst_file_text; | |
b8fbeb18 | 2386 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c5aa993b JM |
2387 | break; |
2388 | case stGlobal: | |
2389 | /* External symbol */ | |
2390 | if (SC_IS_COMMON (ext_in->asym.sc)) | |
2391 | { | |
2392 | /* The value of a common symbol is its size, not its address. | |
2393 | Ignore it. */ | |
c906108c | 2394 | continue; |
c5aa993b JM |
2395 | } |
2396 | else if (SC_IS_DATA (ext_in->asym.sc)) | |
2397 | { | |
2398 | ms_type = mst_data; | |
b8fbeb18 | 2399 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); |
c5aa993b JM |
2400 | } |
2401 | else if (SC_IS_BSS (ext_in->asym.sc)) | |
2402 | { | |
2403 | ms_type = mst_bss; | |
b8fbeb18 | 2404 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); |
c5aa993b | 2405 | } |
0e931cf0 JB |
2406 | else if (SC_IS_SBSS (ext_in->asym.sc)) |
2407 | { | |
2408 | ms_type = mst_bss; | |
2409 | svalue += ANOFFSET (objfile->section_offsets, | |
2410 | get_section_index (objfile, ".sbss")); | |
2411 | } | |
c5aa993b JM |
2412 | else |
2413 | ms_type = mst_abs; | |
2414 | break; | |
2415 | case stLabel: | |
2416 | /* Label */ | |
0e931cf0 JB |
2417 | |
2418 | /* On certain platforms, some extra label symbols can be | |
2419 | generated by the linker. One possible usage for this kind | |
2420 | of symbols is to represent the address of the begining of a | |
2421 | given section. For instance, on Tru64 5.1, the address of | |
2422 | the _ftext label is the start address of the .text section. | |
2423 | ||
2424 | The storage class of these symbols is usually directly | |
2425 | related to the section to which the symbol refers. For | |
2426 | instance, on Tru64 5.1, the storage class for the _fdata | |
2427 | label is scData, refering to the .data section. | |
2428 | ||
2429 | It is actually possible that the section associated to the | |
2430 | storage class of the label does not exist. On True64 5.1 | |
2431 | for instance, the libm.so shared library does not contain | |
2432 | any .data section, although it contains a _fpdata label | |
2433 | which storage class is scData... Since these symbols are | |
2434 | usually useless for the debugger user anyway, we just | |
2435 | discard these symbols. | |
2436 | */ | |
2437 | ||
c5aa993b JM |
2438 | if (SC_IS_TEXT (ext_in->asym.sc)) |
2439 | { | |
0e931cf0 JB |
2440 | if (objfile->sect_index_text == -1) |
2441 | continue; | |
2442 | ||
c5aa993b | 2443 | ms_type = mst_file_text; |
b8fbeb18 | 2444 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c5aa993b JM |
2445 | } |
2446 | else if (SC_IS_DATA (ext_in->asym.sc)) | |
2447 | { | |
0e931cf0 JB |
2448 | if (objfile->sect_index_data == -1) |
2449 | continue; | |
2450 | ||
c5aa993b | 2451 | ms_type = mst_file_data; |
b8fbeb18 | 2452 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); |
c5aa993b JM |
2453 | } |
2454 | else if (SC_IS_BSS (ext_in->asym.sc)) | |
2455 | { | |
0e931cf0 JB |
2456 | if (objfile->sect_index_bss == -1) |
2457 | continue; | |
2458 | ||
c5aa993b | 2459 | ms_type = mst_file_bss; |
b8fbeb18 | 2460 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); |
c5aa993b | 2461 | } |
0e931cf0 JB |
2462 | else if (SC_IS_SBSS (ext_in->asym.sc)) |
2463 | { | |
2464 | const int sbss_sect_index = get_section_index (objfile, ".sbss"); | |
2465 | ||
2466 | if (sbss_sect_index == -1) | |
2467 | continue; | |
2468 | ||
2469 | ms_type = mst_file_bss; | |
2470 | svalue += ANOFFSET (objfile->section_offsets, sbss_sect_index); | |
2471 | } | |
c5aa993b JM |
2472 | else |
2473 | ms_type = mst_abs; | |
2474 | break; | |
2475 | case stLocal: | |
2476 | case stNil: | |
2477 | /* The alpha has the section start addresses in stLocal symbols | |
2478 | whose name starts with a `.'. Skip those but complain for all | |
2479 | other stLocal symbols. | |
2480 | Irix6 puts the section start addresses in stNil symbols, skip | |
2481 | those too. */ | |
2482 | if (name[0] == '.') | |
2483 | continue; | |
2484 | /* Fall through. */ | |
2485 | default: | |
2486 | ms_type = mst_unknown; | |
23136709 | 2487 | unknown_ext_complaint (name); |
c5aa993b JM |
2488 | } |
2489 | if (!ECOFF_IN_ELF (cur_bfd)) | |
2490 | prim_record_minimal_symbol (name, svalue, ms_type, objfile); | |
2491 | } | |
c906108c SS |
2492 | |
2493 | /* Pass 3 over files, over local syms: fill in static symbols */ | |
2494 | for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) | |
2495 | { | |
2496 | struct partial_symtab *save_pst; | |
2497 | EXTR *ext_ptr; | |
2498 | CORE_ADDR textlow; | |
2499 | ||
2500 | cur_fdr = fh = debug_info->fdr + f_idx; | |
2501 | ||
2502 | if (fh->csym == 0) | |
2503 | { | |
2504 | fdr_to_pst[f_idx].pst = NULL; | |
2505 | continue; | |
2506 | } | |
2507 | ||
2508 | /* Determine the start address for this object file from the | |
c5aa993b | 2509 | file header and relocate it, except for Irix 5.2 zero fh->adr. */ |
c906108c SS |
2510 | if (fh->cpd) |
2511 | { | |
2512 | textlow = fh->adr; | |
2513 | if (relocatable || textlow != 0) | |
b8fbeb18 | 2514 | textlow += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2515 | } |
2516 | else | |
2517 | textlow = 0; | |
d4f3574e | 2518 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
c906108c SS |
2519 | fdr_name (fh), |
2520 | textlow, | |
2521 | objfile->global_psymbols.next, | |
2522 | objfile->static_psymbols.next); | |
2523 | pst->read_symtab_private = ((char *) | |
8b92e4d5 | 2524 | obstack_alloc (&objfile->objfile_obstack, |
c906108c | 2525 | sizeof (struct symloc))); |
12b9c64f | 2526 | memset (pst->read_symtab_private, 0, sizeof (struct symloc)); |
c906108c SS |
2527 | |
2528 | save_pst = pst; | |
2529 | FDR_IDX (pst) = f_idx; | |
2530 | CUR_BFD (pst) = cur_bfd; | |
2531 | DEBUG_SWAP (pst) = debug_swap; | |
2532 | DEBUG_INFO (pst) = debug_info; | |
2533 | PENDING_LIST (pst) = pending_list; | |
2534 | ||
2535 | /* The way to turn this into a symtab is to call... */ | |
2536 | pst->read_symtab = mdebug_psymtab_to_symtab; | |
2537 | ||
2538 | /* Set up language for the pst. | |
2539 | The language from the FDR is used if it is unambigious (e.g. cfront | |
c5aa993b JM |
2540 | with native cc and g++ will set the language to C). |
2541 | Otherwise we have to deduce the language from the filename. | |
2542 | Native ecoff has every header file in a separate FDR, so | |
2543 | deduce_language_from_filename will return language_unknown for | |
2544 | a header file, which is not what we want. | |
2545 | But the FDRs for the header files are after the FDR for the source | |
2546 | file, so we can assign the language of the source file to the | |
2547 | following header files. Then we save the language in the private | |
2548 | pst data so that we can reuse it when building symtabs. */ | |
c906108c SS |
2549 | prev_language = psymtab_language; |
2550 | ||
2551 | switch (fh->lang) | |
2552 | { | |
2553 | case langCplusplusV2: | |
2554 | psymtab_language = language_cplus; | |
2555 | break; | |
2556 | default: | |
2557 | psymtab_language = deduce_language_from_filename (fdr_name (fh)); | |
2558 | break; | |
2559 | } | |
2560 | if (psymtab_language == language_unknown) | |
2561 | psymtab_language = prev_language; | |
2562 | PST_PRIVATE (pst)->pst_language = psymtab_language; | |
2563 | ||
5afc051b | 2564 | pst->texthigh = pst->textlow; |
c906108c SS |
2565 | |
2566 | /* For stabs-in-ecoff files, the second symbol must be @stab. | |
c5aa993b JM |
2567 | This symbol is emitted by mips-tfile to signal that the |
2568 | current object file uses encapsulated stabs instead of mips | |
2569 | ecoff for local symbols. (It is the second symbol because | |
2570 | the first symbol is the stFile used to signal the start of a | |
2571 | file). */ | |
c906108c SS |
2572 | processing_gcc_compilation = 0; |
2573 | if (fh->csym >= 2) | |
2574 | { | |
2575 | (*swap_sym_in) (cur_bfd, | |
2576 | ((char *) debug_info->external_sym | |
2577 | + (fh->isymBase + 1) * external_sym_size), | |
2578 | &sh); | |
ee300cd4 AC |
2579 | if (strcmp (debug_info->ss + fh->issBase + sh.iss, |
2580 | stabs_symbol) == 0) | |
c906108c SS |
2581 | processing_gcc_compilation = 2; |
2582 | } | |
2583 | ||
2584 | if (processing_gcc_compilation != 0) | |
2585 | { | |
2586 | for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) | |
2587 | { | |
2588 | int type_code; | |
2589 | char *namestring; | |
2590 | ||
2591 | (*swap_sym_in) (cur_bfd, | |
2592 | (((char *) debug_info->external_sym) | |
c5aa993b | 2593 | + (fh->isymBase + cur_sdx) * external_sym_size), |
c906108c SS |
2594 | &sh); |
2595 | type_code = ECOFF_UNMARK_STAB (sh.index); | |
2596 | if (!ECOFF_IS_STAB (&sh)) | |
2597 | { | |
2598 | if (sh.st == stProc || sh.st == stStaticProc) | |
2599 | { | |
2600 | CORE_ADDR procaddr; | |
2601 | long isym; | |
c5aa993b | 2602 | |
b8fbeb18 | 2603 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2604 | if (sh.st == stStaticProc) |
2605 | { | |
2606 | namestring = debug_info->ss + fh->issBase + sh.iss; | |
2607 | prim_record_minimal_symbol_and_info (namestring, | |
2608 | sh.value, | |
2609 | mst_file_text, | |
2610 | NULL, | |
b8fbeb18 | 2611 | SECT_OFF_TEXT (objfile), |
c906108c SS |
2612 | NULL, |
2613 | objfile); | |
2614 | } | |
2615 | procaddr = sh.value; | |
2616 | ||
2617 | isym = AUX_GET_ISYM (fh->fBigendian, | |
2618 | (debug_info->external_aux | |
2619 | + fh->iauxBase | |
2620 | + sh.index)); | |
2621 | (*swap_sym_in) (cur_bfd, | |
2622 | ((char *) debug_info->external_sym | |
2623 | + ((fh->isymBase + isym - 1) | |
2624 | * external_sym_size)), | |
2625 | &sh); | |
2626 | if (sh.st == stEnd) | |
2627 | { | |
2628 | CORE_ADDR high = procaddr + sh.value; | |
2629 | ||
c5aa993b | 2630 | /* Kludge for Irix 5.2 zero fh->adr. */ |
c906108c | 2631 | if (!relocatable |
5afc051b JB |
2632 | && (pst->textlow == 0 || procaddr < pst->textlow)) |
2633 | pst->textlow = procaddr; | |
2634 | if (high > pst->texthigh) | |
2635 | pst->texthigh = high; | |
c906108c SS |
2636 | } |
2637 | } | |
2638 | else if (sh.st == stStatic) | |
2639 | { | |
2640 | switch (sh.sc) | |
2641 | { | |
2642 | case scUndefined: | |
2643 | case scSUndefined: | |
2644 | case scNil: | |
2645 | case scAbs: | |
2646 | break; | |
2647 | ||
2648 | case scData: | |
2649 | case scSData: | |
2650 | case scRData: | |
2651 | case scPData: | |
2652 | case scXData: | |
2653 | namestring = debug_info->ss + fh->issBase + sh.iss; | |
b8fbeb18 | 2654 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); |
c906108c SS |
2655 | prim_record_minimal_symbol_and_info (namestring, |
2656 | sh.value, | |
2657 | mst_file_data, | |
2658 | NULL, | |
b8fbeb18 | 2659 | SECT_OFF_DATA (objfile), |
c906108c SS |
2660 | NULL, |
2661 | objfile); | |
2662 | break; | |
2663 | ||
2664 | default: | |
2665 | /* FIXME! Shouldn't this use cases for bss, | |
2666 | then have the default be abs? */ | |
2667 | namestring = debug_info->ss + fh->issBase + sh.iss; | |
b8fbeb18 | 2668 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); |
c906108c SS |
2669 | prim_record_minimal_symbol_and_info (namestring, |
2670 | sh.value, | |
2671 | mst_file_bss, | |
2672 | NULL, | |
b8fbeb18 | 2673 | SECT_OFF_BSS (objfile), |
c906108c SS |
2674 | NULL, |
2675 | objfile); | |
2676 | break; | |
2677 | } | |
2678 | } | |
2679 | continue; | |
2680 | } | |
2681 | /* Handle stabs continuation */ | |
2682 | { | |
2683 | char *stabstring = debug_info->ss + fh->issBase + sh.iss; | |
2684 | int len = strlen (stabstring); | |
c5aa993b | 2685 | while (stabstring[len - 1] == '\\') |
c906108c SS |
2686 | { |
2687 | SYMR sh2; | |
2688 | char *stabstring1 = stabstring; | |
2689 | char *stabstring2; | |
2690 | int len2; | |
2691 | ||
2692 | /* Ignore continuation char from 1st string */ | |
2693 | len--; | |
2694 | ||
2695 | /* Read next stabstring */ | |
2696 | cur_sdx++; | |
2697 | (*swap_sym_in) (cur_bfd, | |
2698 | (((char *) debug_info->external_sym) | |
c5aa993b | 2699 | + (fh->isymBase + cur_sdx) |
c906108c SS |
2700 | * external_sym_size), |
2701 | &sh2); | |
2702 | stabstring2 = debug_info->ss + fh->issBase + sh2.iss; | |
2703 | len2 = strlen (stabstring2); | |
2704 | ||
2705 | /* Concatinate stabstring2 with stabstring1 */ | |
2706 | if (stabstring | |
c5aa993b | 2707 | && stabstring != debug_info->ss + fh->issBase + sh.iss) |
c906108c SS |
2708 | stabstring = xrealloc (stabstring, len + len2 + 1); |
2709 | else | |
86f902e0 FF |
2710 | { |
2711 | stabstring = xmalloc (len + len2 + 1); | |
2712 | strcpy (stabstring, stabstring1); | |
2713 | } | |
c906108c SS |
2714 | strcpy (stabstring + len, stabstring2); |
2715 | len += len2; | |
2716 | } | |
2717 | ||
d3119d1e EZ |
2718 | switch (type_code) |
2719 | { | |
d3119d1e EZ |
2720 | char *p; |
2721 | /* | |
2722 | * Standard, external, non-debugger, symbols | |
2723 | */ | |
2724 | ||
2725 | case N_TEXT | N_EXT: | |
2726 | case N_NBTEXT | N_EXT: | |
2727 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2728 | goto record_it; | |
2729 | ||
2730 | case N_DATA | N_EXT: | |
2731 | case N_NBDATA | N_EXT: | |
2732 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); | |
2733 | goto record_it; | |
2734 | ||
2735 | case N_BSS: | |
2736 | case N_BSS | N_EXT: | |
2737 | case N_NBBSS | N_EXT: | |
2738 | case N_SETV | N_EXT: /* FIXME, is this in BSS? */ | |
2739 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); | |
2740 | goto record_it; | |
2741 | ||
2742 | case N_ABS | N_EXT: | |
2743 | record_it: | |
2744 | continue; | |
2745 | ||
2746 | /* Standard, local, non-debugger, symbols */ | |
2747 | ||
2748 | case N_NBTEXT: | |
2749 | ||
2750 | /* We need to be able to deal with both N_FN or N_TEXT, | |
2751 | because we have no way of knowing whether the sys-supplied ld | |
2752 | or GNU ld was used to make the executable. Sequents throw | |
2753 | in another wrinkle -- they renumbered N_FN. */ | |
2754 | ||
2755 | case N_FN: | |
2756 | case N_FN_SEQ: | |
2757 | case N_TEXT: | |
2758 | continue; | |
2759 | ||
2760 | case N_DATA: | |
2761 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); | |
2762 | goto record_it; | |
2763 | ||
2764 | case N_UNDF | N_EXT: | |
2765 | continue; /* Just undefined, not COMMON */ | |
2766 | ||
2767 | case N_UNDF: | |
2768 | continue; | |
2769 | ||
2770 | /* Lots of symbol types we can just ignore. */ | |
2771 | ||
2772 | case N_ABS: | |
2773 | case N_NBDATA: | |
2774 | case N_NBBSS: | |
2775 | continue; | |
2776 | ||
2777 | /* Keep going . . . */ | |
2778 | ||
2779 | /* | |
2780 | * Special symbol types for GNU | |
2781 | */ | |
2782 | case N_INDR: | |
2783 | case N_INDR | N_EXT: | |
2784 | case N_SETA: | |
2785 | case N_SETA | N_EXT: | |
2786 | case N_SETT: | |
2787 | case N_SETT | N_EXT: | |
2788 | case N_SETD: | |
2789 | case N_SETD | N_EXT: | |
2790 | case N_SETB: | |
2791 | case N_SETB | N_EXT: | |
2792 | case N_SETV: | |
2793 | continue; | |
2794 | ||
2795 | /* | |
2796 | * Debugger symbols | |
2797 | */ | |
2798 | ||
2799 | case N_SO: | |
2800 | { | |
2801 | CORE_ADDR valu; | |
2802 | static int prev_so_symnum = -10; | |
2803 | static int first_so_symnum; | |
2804 | char *p; | |
2805 | int prev_textlow_not_set; | |
2806 | ||
2807 | valu = sh.value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2808 | ||
2809 | prev_textlow_not_set = textlow_not_set; | |
2810 | ||
2811 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
2812 | /* A zero value is probably an indication for the SunPRO 3.0 | |
2813 | compiler. end_psymtab explicitly tests for zero, so | |
2814 | don't relocate it. */ | |
2815 | ||
2816 | if (sh.value == 0) | |
2817 | { | |
2818 | textlow_not_set = 1; | |
2819 | valu = 0; | |
2820 | } | |
2821 | else | |
2822 | textlow_not_set = 0; | |
2823 | #else | |
2824 | textlow_not_set = 0; | |
2825 | #endif | |
2826 | past_first_source_file = 1; | |
2827 | ||
2828 | if (prev_so_symnum != symnum - 1) | |
2829 | { /* Here if prev stab wasn't N_SO */ | |
2830 | first_so_symnum = symnum; | |
2831 | ||
2832 | if (pst) | |
2833 | { | |
2834 | pst = (struct partial_symtab *) 0; | |
2835 | includes_used = 0; | |
2836 | dependencies_used = 0; | |
2837 | } | |
2838 | } | |
2839 | ||
2840 | prev_so_symnum = symnum; | |
c906108c | 2841 | |
d3119d1e EZ |
2842 | /* End the current partial symtab and start a new one */ |
2843 | ||
2844 | /* SET_NAMESTRING ();*/ | |
2845 | namestring = stabstring; | |
2846 | ||
2847 | /* Null name means end of .o file. Don't start a new one. */ | |
2848 | if (*namestring == '\000') | |
2849 | continue; | |
2850 | ||
2851 | /* Some compilers (including gcc) emit a pair of initial N_SOs. | |
2852 | The first one is a directory name; the second the file name. | |
2853 | If pst exists, is empty, and has a filename ending in '/', | |
2854 | we assume the previous N_SO was a directory name. */ | |
2855 | ||
2856 | p = strrchr (namestring, '/'); | |
2857 | if (p && *(p + 1) == '\000') | |
2858 | continue; /* Simply ignore directory name SOs */ | |
2859 | ||
2860 | /* Some other compilers (C++ ones in particular) emit useless | |
2861 | SOs for non-existant .c files. We ignore all subsequent SOs that | |
2862 | immediately follow the first. */ | |
2863 | ||
2864 | if (!pst) | |
2865 | pst = save_pst; | |
2866 | continue; | |
2867 | } | |
2868 | ||
2869 | case N_BINCL: | |
2870 | continue; | |
2871 | ||
2872 | case N_SOL: | |
2873 | { | |
2874 | enum language tmp_language; | |
2875 | /* Mark down an include file in the current psymtab */ | |
2876 | ||
2877 | /* SET_NAMESTRING ();*/ | |
2878 | namestring = stabstring; | |
2879 | ||
2880 | tmp_language = deduce_language_from_filename (namestring); | |
2881 | ||
2882 | /* Only change the psymtab's language if we've learned | |
2883 | something useful (eg. tmp_language is not language_unknown). | |
2884 | In addition, to match what start_subfile does, never change | |
2885 | from C++ to C. */ | |
2886 | if (tmp_language != language_unknown | |
2887 | && (tmp_language != language_c | |
2888 | || psymtab_language != language_cplus)) | |
2889 | psymtab_language = tmp_language; | |
2890 | ||
2891 | /* In C++, one may expect the same filename to come round many | |
2892 | times, when code is coming alternately from the main file | |
2893 | and from inline functions in other files. So I check to see | |
2894 | if this is a file we've seen before -- either the main | |
2895 | source file, or a previously included file. | |
2896 | ||
2897 | This seems to be a lot of time to be spending on N_SOL, but | |
2898 | things like "break c-exp.y:435" need to work (I | |
2899 | suppose the psymtab_include_list could be hashed or put | |
2900 | in a binary tree, if profiling shows this is a major hog). */ | |
ee300cd4 | 2901 | if (pst && strcmp (namestring, pst->filename) == 0) |
d3119d1e EZ |
2902 | continue; |
2903 | { | |
aa1ee363 | 2904 | int i; |
d3119d1e | 2905 | for (i = 0; i < includes_used; i++) |
ee300cd4 AC |
2906 | if (strcmp (namestring, |
2907 | psymtab_include_list[i]) == 0) | |
d3119d1e EZ |
2908 | { |
2909 | i = -1; | |
2910 | break; | |
2911 | } | |
2912 | if (i == -1) | |
2913 | continue; | |
2914 | } | |
2915 | ||
2916 | psymtab_include_list[includes_used++] = namestring; | |
2917 | if (includes_used >= includes_allocated) | |
2918 | { | |
2919 | char **orig = psymtab_include_list; | |
2920 | ||
2921 | psymtab_include_list = (char **) | |
2922 | alloca ((includes_allocated *= 2) * | |
2923 | sizeof (char *)); | |
4efb68b1 | 2924 | memcpy (psymtab_include_list, orig, |
d3119d1e EZ |
2925 | includes_used * sizeof (char *)); |
2926 | } | |
2927 | continue; | |
2928 | } | |
2929 | case N_LSYM: /* Typedef or automatic variable. */ | |
2930 | case N_STSYM: /* Data seg var -- static */ | |
2931 | case N_LCSYM: /* BSS " */ | |
2932 | case N_ROSYM: /* Read-only data seg var -- static. */ | |
2933 | case N_NBSTS: /* Gould nobase. */ | |
2934 | case N_NBLCS: /* symbols. */ | |
2935 | case N_FUN: | |
2936 | case N_GSYM: /* Global (extern) variable; can be | |
2937 | data or bss (sigh FIXME). */ | |
2938 | ||
2939 | /* Following may probably be ignored; I'll leave them here | |
2940 | for now (until I do Pascal and Modula 2 extensions). */ | |
2941 | ||
2942 | case N_PC: /* I may or may not need this; I | |
2943 | suspect not. */ | |
2944 | case N_M2C: /* I suspect that I can ignore this here. */ | |
2945 | case N_SCOPE: /* Same. */ | |
2946 | ||
2947 | /* SET_NAMESTRING ();*/ | |
2948 | namestring = stabstring; | |
2949 | p = (char *) strchr (namestring, ':'); | |
2950 | if (!p) | |
2951 | continue; /* Not a debugging symbol. */ | |
2952 | ||
2953 | ||
2954 | ||
2955 | /* Main processing section for debugging symbols which | |
2956 | the initial read through the symbol tables needs to worry | |
2957 | about. If we reach this point, the symbol which we are | |
2958 | considering is definitely one we are interested in. | |
2959 | p must also contain the (valid) index into the namestring | |
2960 | which indicates the debugging type symbol. */ | |
2961 | ||
2962 | switch (p[1]) | |
2963 | { | |
2964 | case 'S': | |
2965 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); | |
2966 | #ifdef STATIC_TRANSFORM_NAME | |
2967 | namestring = STATIC_TRANSFORM_NAME (namestring); | |
2968 | #endif | |
2969 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 2970 | VAR_DOMAIN, LOC_STATIC, |
d3119d1e EZ |
2971 | &objfile->static_psymbols, |
2972 | 0, sh.value, | |
2973 | psymtab_language, objfile); | |
2974 | continue; | |
2975 | case 'G': | |
2976 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); | |
2977 | /* The addresses in these entries are reported to be | |
2978 | wrong. See the code that reads 'G's for symtabs. */ | |
2979 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 2980 | VAR_DOMAIN, LOC_STATIC, |
d3119d1e EZ |
2981 | &objfile->global_psymbols, |
2982 | 0, sh.value, | |
2983 | psymtab_language, objfile); | |
2984 | continue; | |
2985 | ||
2986 | case 'T': | |
2987 | /* When a 'T' entry is defining an anonymous enum, it | |
2988 | may have a name which is the empty string, or a | |
2989 | single space. Since they're not really defining a | |
2990 | symbol, those shouldn't go in the partial symbol | |
2991 | table. We do pick up the elements of such enums at | |
2992 | 'check_enum:', below. */ | |
2993 | if (p >= namestring + 2 | |
2994 | || (p == namestring + 1 | |
2995 | && namestring[0] != ' ')) | |
2996 | { | |
2997 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 2998 | STRUCT_DOMAIN, LOC_TYPEDEF, |
d3119d1e EZ |
2999 | &objfile->static_psymbols, |
3000 | sh.value, 0, | |
3001 | psymtab_language, objfile); | |
3002 | if (p[2] == 't') | |
3003 | { | |
3004 | /* Also a typedef with the same name. */ | |
3005 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 3006 | VAR_DOMAIN, LOC_TYPEDEF, |
d3119d1e EZ |
3007 | &objfile->static_psymbols, |
3008 | sh.value, 0, | |
3009 | psymtab_language, objfile); | |
3010 | p += 1; | |
3011 | } | |
d3119d1e EZ |
3012 | } |
3013 | goto check_enum; | |
3014 | case 't': | |
3015 | if (p != namestring) /* a name is there, not just :T... */ | |
3016 | { | |
3017 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 3018 | VAR_DOMAIN, LOC_TYPEDEF, |
d3119d1e EZ |
3019 | &objfile->static_psymbols, |
3020 | sh.value, 0, | |
3021 | psymtab_language, objfile); | |
3022 | } | |
3023 | check_enum: | |
3024 | /* If this is an enumerated type, we need to | |
3025 | add all the enum constants to the partial symbol | |
3026 | table. This does not cover enums without names, e.g. | |
3027 | "enum {a, b} c;" in C, but fortunately those are | |
3028 | rare. There is no way for GDB to find those from the | |
3029 | enum type without spending too much time on it. Thus | |
3030 | to solve this problem, the compiler needs to put out the | |
3031 | enum in a nameless type. GCC2 does this. */ | |
3032 | ||
3033 | /* We are looking for something of the form | |
3034 | <name> ":" ("t" | "T") [<number> "="] "e" | |
3035 | {<constant> ":" <value> ","} ";". */ | |
3036 | ||
3037 | /* Skip over the colon and the 't' or 'T'. */ | |
3038 | p += 2; | |
3039 | /* This type may be given a number. Also, numbers can come | |
3040 | in pairs like (0,26). Skip over it. */ | |
3041 | while ((*p >= '0' && *p <= '9') | |
3042 | || *p == '(' || *p == ',' || *p == ')' | |
3043 | || *p == '=') | |
3044 | p++; | |
3045 | ||
3046 | if (*p++ == 'e') | |
3047 | { | |
3048 | /* The aix4 compiler emits extra crud before the members. */ | |
3049 | if (*p == '-') | |
3050 | { | |
3051 | /* Skip over the type (?). */ | |
3052 | while (*p != ':') | |
3053 | p++; | |
3054 | ||
3055 | /* Skip over the colon. */ | |
3056 | p++; | |
3057 | } | |
3058 | ||
3059 | /* We have found an enumerated type. */ | |
3060 | /* According to comments in read_enum_type | |
3061 | a comma could end it instead of a semicolon. | |
3062 | I don't know where that happens. | |
3063 | Accept either. */ | |
3064 | while (*p && *p != ';' && *p != ',') | |
3065 | { | |
3066 | char *q; | |
3067 | ||
3068 | /* Check for and handle cretinous dbx symbol name | |
3069 | continuation! */ | |
3070 | if (*p == '\\' || (*p == '?' && p[1] == '\0')) | |
3071 | p = next_symbol_text (objfile); | |
3072 | ||
3073 | /* Point to the character after the name | |
3074 | of the enum constant. */ | |
3075 | for (q = p; *q && *q != ':'; q++) | |
3076 | ; | |
3077 | /* Note that the value doesn't matter for | |
3078 | enum constants in psymtabs, just in symtabs. */ | |
3079 | add_psymbol_to_list (p, q - p, | |
176620f1 | 3080 | VAR_DOMAIN, LOC_CONST, |
d3119d1e EZ |
3081 | &objfile->static_psymbols, 0, |
3082 | 0, psymtab_language, objfile); | |
3083 | /* Point past the name. */ | |
3084 | p = q; | |
3085 | /* Skip over the value. */ | |
3086 | while (*p && *p != ',') | |
3087 | p++; | |
3088 | /* Advance past the comma. */ | |
3089 | if (*p) | |
3090 | p++; | |
3091 | } | |
3092 | } | |
3093 | continue; | |
3094 | case 'c': | |
3095 | /* Constant, e.g. from "const" in Pascal. */ | |
3096 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 3097 | VAR_DOMAIN, LOC_CONST, |
d3119d1e EZ |
3098 | &objfile->static_psymbols, sh.value, |
3099 | 0, psymtab_language, objfile); | |
3100 | continue; | |
3101 | ||
3102 | case 'f': | |
3103 | if (! pst) | |
3104 | { | |
3105 | int name_len = p - namestring; | |
3106 | char *name = xmalloc (name_len + 1); | |
3107 | memcpy (name, namestring, name_len); | |
3108 | name[name_len] = '\0'; | |
23136709 | 3109 | function_outside_compilation_unit_complaint (name); |
d3119d1e EZ |
3110 | xfree (name); |
3111 | } | |
3112 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3113 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 3114 | VAR_DOMAIN, LOC_BLOCK, |
d3119d1e EZ |
3115 | &objfile->static_psymbols, |
3116 | 0, sh.value, | |
3117 | psymtab_language, objfile); | |
3118 | continue; | |
3119 | ||
3120 | /* Global functions were ignored here, but now they | |
3121 | are put into the global psymtab like one would expect. | |
3122 | They're also in the minimal symbol table. */ | |
3123 | case 'F': | |
3124 | if (! pst) | |
3125 | { | |
3126 | int name_len = p - namestring; | |
3127 | char *name = xmalloc (name_len + 1); | |
3128 | memcpy (name, namestring, name_len); | |
3129 | name[name_len] = '\0'; | |
23136709 | 3130 | function_outside_compilation_unit_complaint (name); |
d3119d1e EZ |
3131 | xfree (name); |
3132 | } | |
3133 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
3134 | add_psymbol_to_list (namestring, p - namestring, | |
176620f1 | 3135 | VAR_DOMAIN, LOC_BLOCK, |
d3119d1e EZ |
3136 | &objfile->global_psymbols, |
3137 | 0, sh.value, | |
3138 | psymtab_language, objfile); | |
3139 | continue; | |
3140 | ||
3141 | /* Two things show up here (hopefully); static symbols of | |
3142 | local scope (static used inside braces) or extensions | |
3143 | of structure symbols. We can ignore both. */ | |
3144 | case 'V': | |
3145 | case '(': | |
3146 | case '0': | |
3147 | case '1': | |
3148 | case '2': | |
3149 | case '3': | |
3150 | case '4': | |
3151 | case '5': | |
3152 | case '6': | |
3153 | case '7': | |
3154 | case '8': | |
3155 | case '9': | |
3156 | case '-': | |
3157 | case '#': /* for symbol identification (used in live ranges) */ | |
d3119d1e EZ |
3158 | continue; |
3159 | ||
3160 | case ':': | |
3161 | /* It is a C++ nested symbol. We don't need to record it | |
3162 | (I don't think); if we try to look up foo::bar::baz, | |
3163 | then symbols for the symtab containing foo should get | |
3164 | read in, I think. */ | |
3165 | /* Someone says sun cc puts out symbols like | |
3166 | /foo/baz/maclib::/usr/local/bin/maclib, | |
3167 | which would get here with a symbol type of ':'. */ | |
3168 | continue; | |
3169 | ||
3170 | default: | |
3171 | /* Unexpected symbol descriptor. The second and subsequent stabs | |
3172 | of a continued stab can show up here. The question is | |
3173 | whether they ever can mimic a normal stab--it would be | |
3174 | nice if not, since we certainly don't want to spend the | |
3175 | time searching to the end of every string looking for | |
3176 | a backslash. */ | |
3177 | ||
23136709 KB |
3178 | complaint (&symfile_complaints, |
3179 | "unknown symbol descriptor `%c'", p[1]); | |
d3119d1e EZ |
3180 | |
3181 | /* Ignore it; perhaps it is an extension that we don't | |
3182 | know about. */ | |
3183 | continue; | |
3184 | } | |
3185 | ||
3186 | case N_EXCL: | |
3187 | continue; | |
3188 | ||
3189 | case N_ENDM: | |
3190 | #ifdef SOFUN_ADDRESS_MAYBE_MISSING | |
5afc051b JB |
3191 | /* Solaris 2 end of module, finish current partial |
3192 | symbol table. END_PSYMTAB will set | |
3193 | pst->texthigh to the proper value, which is | |
3194 | necessary if a module compiled without | |
3195 | debugging info follows this module. */ | |
d3119d1e EZ |
3196 | if (pst) |
3197 | { | |
3198 | pst = (struct partial_symtab *) 0; | |
3199 | includes_used = 0; | |
3200 | dependencies_used = 0; | |
3201 | } | |
3202 | #endif | |
3203 | continue; | |
3204 | ||
3205 | case N_RBRAC: | |
5afc051b JB |
3206 | if (sh.value > save_pst->texthigh) |
3207 | save_pst->texthigh = sh.value; | |
d3119d1e EZ |
3208 | continue; |
3209 | case N_EINCL: | |
3210 | case N_DSLINE: | |
3211 | case N_BSLINE: | |
3212 | case N_SSYM: /* Claim: Structure or union element. | |
3213 | Hopefully, I can ignore this. */ | |
3214 | case N_ENTRY: /* Alternate entry point; can ignore. */ | |
3215 | case N_MAIN: /* Can definitely ignore this. */ | |
3216 | case N_CATCH: /* These are GNU C++ extensions */ | |
3217 | case N_EHDECL: /* that can safely be ignored here. */ | |
3218 | case N_LENG: | |
3219 | case N_BCOMM: | |
3220 | case N_ECOMM: | |
3221 | case N_ECOML: | |
3222 | case N_FNAME: | |
3223 | case N_SLINE: | |
3224 | case N_RSYM: | |
3225 | case N_PSYM: | |
3226 | case N_LBRAC: | |
3227 | case N_NSYMS: /* Ultrix 4.0: symbol count */ | |
3228 | case N_DEFD: /* GNU Modula-2 */ | |
3229 | case N_ALIAS: /* SunPro F77: alias name, ignore for now. */ | |
3230 | ||
3231 | case N_OBJ: /* useless types from Solaris */ | |
3232 | case N_OPT: | |
3233 | /* These symbols aren't interesting; don't worry about them */ | |
3234 | ||
3235 | continue; | |
3236 | ||
3237 | default: | |
3238 | /* If we haven't found it yet, ignore it. It's probably some | |
3239 | new type we don't know about yet. */ | |
23136709 | 3240 | complaint (&symfile_complaints, "unknown symbol type %s", |
bb599908 | 3241 | hex_string (type_code)); /*CUR_SYMBOL_TYPE*/ |
d3119d1e EZ |
3242 | continue; |
3243 | } | |
c5aa993b | 3244 | if (stabstring |
c906108c | 3245 | && stabstring != debug_info->ss + fh->issBase + sh.iss) |
b8c9b27d | 3246 | xfree (stabstring); |
c906108c | 3247 | } |
c5aa993b | 3248 | /* end - Handle continuation */ |
c906108c SS |
3249 | } |
3250 | } | |
3251 | else | |
3252 | { | |
3253 | for (cur_sdx = 0; cur_sdx < fh->csym;) | |
3254 | { | |
3255 | char *name; | |
3256 | enum address_class class; | |
3257 | ||
3258 | (*swap_sym_in) (cur_bfd, | |
3259 | ((char *) debug_info->external_sym | |
3260 | + ((fh->isymBase + cur_sdx) | |
3261 | * external_sym_size)), | |
3262 | &sh); | |
3263 | ||
3264 | if (ECOFF_IS_STAB (&sh)) | |
3265 | { | |
3266 | cur_sdx++; | |
3267 | continue; | |
3268 | } | |
3269 | ||
3270 | /* Non absolute static symbols go into the minimal table. */ | |
c5aa993b | 3271 | if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil |
c906108c SS |
3272 | || (sh.index == indexNil |
3273 | && (sh.st != stStatic || sh.sc == scAbs))) | |
3274 | { | |
3275 | /* FIXME, premature? */ | |
3276 | cur_sdx++; | |
3277 | continue; | |
3278 | } | |
3279 | ||
3280 | name = debug_info->ss + fh->issBase + sh.iss; | |
3281 | ||
3282 | switch (sh.sc) | |
3283 | { | |
3284 | case scText: | |
3285 | case scRConst: | |
3286 | /* The value of a stEnd symbol is the displacement from the | |
3287 | corresponding start symbol value, do not relocate it. */ | |
3288 | if (sh.st != stEnd) | |
b8fbeb18 | 3289 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3290 | break; |
3291 | case scData: | |
3292 | case scSData: | |
3293 | case scRData: | |
3294 | case scPData: | |
3295 | case scXData: | |
b8fbeb18 | 3296 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); |
c906108c SS |
3297 | break; |
3298 | case scBss: | |
3299 | case scSBss: | |
b8fbeb18 | 3300 | sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); |
c906108c SS |
3301 | break; |
3302 | } | |
3303 | ||
3304 | switch (sh.st) | |
3305 | { | |
3306 | CORE_ADDR high; | |
3307 | CORE_ADDR procaddr; | |
3308 | int new_sdx; | |
3309 | ||
3310 | case stStaticProc: | |
3311 | prim_record_minimal_symbol_and_info (name, sh.value, | |
3312 | mst_file_text, NULL, | |
b8fbeb18 | 3313 | SECT_OFF_TEXT (objfile), NULL, |
c906108c SS |
3314 | objfile); |
3315 | ||
3316 | /* FALLTHROUGH */ | |
3317 | ||
3318 | case stProc: | |
1fb4c65b JB |
3319 | /* Ignore all parameter symbol records. */ |
3320 | if (sh.index >= hdr->iauxMax) | |
3321 | { | |
3322 | /* Should not happen, but does when cross-compiling | |
3323 | with the MIPS compiler. FIXME -- pull later. */ | |
3324 | index_complaint (name); | |
3325 | new_sdx = cur_sdx + 1; /* Don't skip at all */ | |
3326 | } | |
3327 | else | |
3328 | new_sdx = AUX_GET_ISYM (fh->fBigendian, | |
3329 | (debug_info->external_aux | |
3330 | + fh->iauxBase | |
3331 | + sh.index)); | |
3332 | ||
3333 | if (new_sdx <= cur_sdx) | |
3334 | { | |
3335 | /* This should not happen either... FIXME. */ | |
3336 | complaint (&symfile_complaints, | |
3337 | "bad proc end in aux found from symbol %s", | |
3338 | name); | |
3339 | new_sdx = cur_sdx + 1; /* Don't skip backward */ | |
3340 | } | |
3341 | ||
3342 | /* For stProc symbol records, we need to check the | |
3343 | storage class as well, as only (stProc, scText) | |
3344 | entries represent "real" procedures - See the | |
3345 | Compaq document titled "Object File / Symbol Table | |
3346 | Format Specification" for more information. If the | |
3347 | storage class is not scText, we discard the whole | |
3348 | block of symbol records for this stProc. */ | |
3349 | if (sh.st == stProc && sh.sc != scText) | |
3350 | goto skip; | |
3351 | ||
c906108c SS |
3352 | /* Usually there is a local and a global stProc symbol |
3353 | for a function. This means that the function name | |
3354 | has already been entered into the mimimal symbol table | |
3355 | while processing the global symbols in pass 2 above. | |
3356 | One notable exception is the PROGRAM name from | |
3357 | f77 compiled executables, it is only put out as | |
3358 | local stProc symbol, and a global MAIN__ stProc symbol | |
3359 | points to it. It doesn't matter though, as gdb is | |
3360 | still able to find the PROGRAM name via the partial | |
3361 | symbol table, and the MAIN__ symbol via the minimal | |
3362 | symbol table. */ | |
3363 | if (sh.st == stProc) | |
3364 | add_psymbol_to_list (name, strlen (name), | |
176620f1 | 3365 | VAR_DOMAIN, LOC_BLOCK, |
c906108c | 3366 | &objfile->global_psymbols, |
c5aa993b | 3367 | 0, sh.value, psymtab_language, objfile); |
c906108c SS |
3368 | else |
3369 | add_psymbol_to_list (name, strlen (name), | |
176620f1 | 3370 | VAR_DOMAIN, LOC_BLOCK, |
c906108c | 3371 | &objfile->static_psymbols, |
c5aa993b | 3372 | 0, sh.value, psymtab_language, objfile); |
c906108c | 3373 | |
c906108c SS |
3374 | procaddr = sh.value; |
3375 | ||
c906108c SS |
3376 | cur_sdx = new_sdx; |
3377 | (*swap_sym_in) (cur_bfd, | |
3378 | ((char *) debug_info->external_sym | |
3379 | + ((fh->isymBase + cur_sdx - 1) | |
3380 | * external_sym_size)), | |
3381 | &sh); | |
3382 | if (sh.st != stEnd) | |
3383 | continue; | |
3384 | ||
3385 | /* Kludge for Irix 5.2 zero fh->adr. */ | |
3386 | if (!relocatable | |
5afc051b JB |
3387 | && (pst->textlow == 0 || procaddr < pst->textlow)) |
3388 | pst->textlow = procaddr; | |
c906108c SS |
3389 | |
3390 | high = procaddr + sh.value; | |
5afc051b JB |
3391 | if (high > pst->texthigh) |
3392 | pst->texthigh = high; | |
c906108c SS |
3393 | continue; |
3394 | ||
3395 | case stStatic: /* Variable */ | |
c5aa993b | 3396 | if (SC_IS_DATA (sh.sc)) |
c906108c SS |
3397 | prim_record_minimal_symbol_and_info (name, sh.value, |
3398 | mst_file_data, NULL, | |
b8fbeb18 | 3399 | SECT_OFF_DATA (objfile), |
c906108c SS |
3400 | NULL, |
3401 | objfile); | |
3402 | else | |
3403 | prim_record_minimal_symbol_and_info (name, sh.value, | |
3404 | mst_file_bss, NULL, | |
b8fbeb18 | 3405 | SECT_OFF_BSS (objfile), |
c906108c SS |
3406 | NULL, |
3407 | objfile); | |
3408 | class = LOC_STATIC; | |
3409 | break; | |
3410 | ||
c5aa993b | 3411 | case stIndirect: /* Irix5 forward declaration */ |
c906108c SS |
3412 | /* Skip forward declarations from Irix5 cc */ |
3413 | goto skip; | |
3414 | ||
c5aa993b | 3415 | case stTypedef: /* Typedef */ |
c906108c SS |
3416 | /* Skip typedefs for forward declarations and opaque |
3417 | structs from alpha and mips cc. */ | |
3418 | if (sh.iss == 0 || has_opaque_xref (fh, &sh)) | |
3419 | goto skip; | |
3420 | class = LOC_TYPEDEF; | |
3421 | break; | |
3422 | ||
3423 | case stConstant: /* Constant decl */ | |
3424 | class = LOC_CONST; | |
3425 | break; | |
3426 | ||
3427 | case stUnion: | |
3428 | case stStruct: | |
3429 | case stEnum: | |
c5aa993b | 3430 | case stBlock: /* { }, str, un, enum */ |
c906108c SS |
3431 | /* Do not create a partial symbol for cc unnamed aggregates |
3432 | and gcc empty aggregates. */ | |
3433 | if ((sh.sc == scInfo | |
c5aa993b | 3434 | || SC_IS_COMMON (sh.sc)) |
c906108c SS |
3435 | && sh.iss != 0 |
3436 | && sh.index != cur_sdx + 2) | |
3437 | { | |
3438 | add_psymbol_to_list (name, strlen (name), | |
176620f1 | 3439 | STRUCT_DOMAIN, LOC_TYPEDEF, |
c906108c SS |
3440 | &objfile->static_psymbols, |
3441 | 0, (CORE_ADDR) 0, | |
3442 | psymtab_language, objfile); | |
3443 | } | |
3444 | handle_psymbol_enumerators (objfile, fh, sh.st, sh.value); | |
3445 | ||
3446 | /* Skip over the block */ | |
3447 | new_sdx = sh.index; | |
3448 | if (new_sdx <= cur_sdx) | |
3449 | { | |
3450 | /* This happens with the Ultrix kernel. */ | |
23136709 KB |
3451 | complaint (&symfile_complaints, |
3452 | "bad aux index at block symbol %s", name); | |
c906108c SS |
3453 | new_sdx = cur_sdx + 1; /* Don't skip backward */ |
3454 | } | |
3455 | cur_sdx = new_sdx; | |
3456 | continue; | |
3457 | ||
3458 | case stFile: /* File headers */ | |
3459 | case stLabel: /* Labels */ | |
3460 | case stEnd: /* Ends of files */ | |
3461 | goto skip; | |
3462 | ||
3463 | case stLocal: /* Local variables */ | |
3464 | /* Normally these are skipped because we skip over | |
3465 | all blocks we see. However, these can occur | |
3466 | as visible symbols in a .h file that contains code. */ | |
3467 | goto skip; | |
3468 | ||
3469 | default: | |
3470 | /* Both complaints are valid: one gives symbol name, | |
3471 | the other the offending symbol type. */ | |
23136709 KB |
3472 | complaint (&symfile_complaints, "unknown local symbol %s", |
3473 | name); | |
3474 | complaint (&symfile_complaints, "with type %d", sh.st); | |
c906108c SS |
3475 | cur_sdx++; |
3476 | continue; | |
3477 | } | |
3478 | /* Use this gdb symbol */ | |
3479 | add_psymbol_to_list (name, strlen (name), | |
176620f1 | 3480 | VAR_DOMAIN, class, |
c906108c SS |
3481 | &objfile->static_psymbols, |
3482 | 0, sh.value, psymtab_language, objfile); | |
3483 | skip: | |
3484 | cur_sdx++; /* Go to next file symbol */ | |
3485 | } | |
3486 | ||
3487 | /* Now do enter the external symbols. */ | |
3488 | ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset]; | |
3489 | cur_sdx = fdr_to_pst[f_idx].n_globals; | |
3490 | PST_PRIVATE (save_pst)->extern_count = cur_sdx; | |
3491 | PST_PRIVATE (save_pst)->extern_tab = ext_ptr; | |
3492 | for (; --cur_sdx >= 0; ext_ptr++) | |
3493 | { | |
3494 | enum address_class class; | |
3495 | SYMR *psh; | |
3496 | char *name; | |
3497 | CORE_ADDR svalue; | |
3498 | ||
3499 | if (ext_ptr->ifd != f_idx) | |
e1e9e218 | 3500 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
c906108c SS |
3501 | psh = &ext_ptr->asym; |
3502 | ||
3503 | /* Do not add undefined symbols to the partial symbol table. */ | |
c5aa993b | 3504 | if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil) |
c906108c SS |
3505 | continue; |
3506 | ||
3507 | svalue = psh->value; | |
3508 | switch (psh->sc) | |
3509 | { | |
3510 | case scText: | |
3511 | case scRConst: | |
b8fbeb18 | 3512 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
3513 | break; |
3514 | case scData: | |
3515 | case scSData: | |
3516 | case scRData: | |
3517 | case scPData: | |
3518 | case scXData: | |
b8fbeb18 | 3519 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); |
c906108c SS |
3520 | break; |
3521 | case scBss: | |
3522 | case scSBss: | |
b8fbeb18 | 3523 | svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile)); |
c906108c SS |
3524 | break; |
3525 | } | |
3526 | ||
3527 | switch (psh->st) | |
3528 | { | |
3529 | case stNil: | |
3530 | /* These are generated for static symbols in .o files, | |
3531 | ignore them. */ | |
3532 | continue; | |
3533 | case stProc: | |
3534 | case stStaticProc: | |
3535 | /* External procedure symbols have been entered | |
3536 | into the minimal symbol table in pass 2 above. | |
3537 | Ignore them, as parse_external will ignore them too. */ | |
3538 | continue; | |
3539 | case stLabel: | |
3540 | class = LOC_LABEL; | |
3541 | break; | |
3542 | default: | |
23136709 | 3543 | unknown_ext_complaint (debug_info->ssext + psh->iss); |
c906108c SS |
3544 | /* Fall through, pretend it's global. */ |
3545 | case stGlobal: | |
3546 | /* Global common symbols are resolved by the runtime loader, | |
3547 | ignore them. */ | |
c5aa993b | 3548 | if (SC_IS_COMMON (psh->sc)) |
c906108c SS |
3549 | continue; |
3550 | ||
3551 | class = LOC_STATIC; | |
3552 | break; | |
3553 | } | |
3554 | name = debug_info->ssext + psh->iss; | |
3555 | add_psymbol_to_list (name, strlen (name), | |
176620f1 | 3556 | VAR_DOMAIN, class, |
c906108c SS |
3557 | &objfile->global_psymbols, |
3558 | 0, svalue, | |
3559 | psymtab_language, objfile); | |
3560 | } | |
3561 | } | |
3562 | ||
3563 | /* Link pst to FDR. end_psymtab returns NULL if the psymtab was | |
c5aa993b | 3564 | empty and put on the free list. */ |
c906108c | 3565 | fdr_to_pst[f_idx].pst = end_psymtab (save_pst, |
c5aa993b | 3566 | psymtab_include_list, includes_used, |
5afc051b | 3567 | -1, save_pst->texthigh, |
c5aa993b | 3568 | dependency_list, dependencies_used, textlow_not_set); |
c906108c SS |
3569 | includes_used = 0; |
3570 | dependencies_used = 0; | |
3571 | ||
c906108c | 3572 | /* The objfile has its functions reordered if this partial symbol |
c5aa993b JM |
3573 | table overlaps any other partial symbol table. |
3574 | We cannot assume a reordered objfile if a partial symbol table | |
3575 | is contained within another partial symbol table, as partial symbol | |
3576 | tables for include files with executable code are contained | |
3577 | within the partial symbol table for the including source file, | |
3578 | and we do not want to flag the objfile reordered for these cases. | |
3579 | ||
3580 | This strategy works well for Irix-5.2 shared libraries, but we | |
3581 | might have to use a more elaborate (and slower) algorithm for | |
3582 | other cases. */ | |
c906108c SS |
3583 | save_pst = fdr_to_pst[f_idx].pst; |
3584 | if (save_pst != NULL | |
5afc051b | 3585 | && save_pst->textlow != 0 |
c906108c SS |
3586 | && !(objfile->flags & OBJF_REORDERED)) |
3587 | { | |
3588 | ALL_OBJFILE_PSYMTABS (objfile, pst) | |
c5aa993b JM |
3589 | { |
3590 | if (save_pst != pst | |
5afc051b JB |
3591 | && save_pst->textlow >= pst->textlow |
3592 | && save_pst->textlow < pst->texthigh | |
3593 | && save_pst->texthigh > pst->texthigh) | |
c5aa993b JM |
3594 | { |
3595 | objfile->flags |= OBJF_REORDERED; | |
3596 | break; | |
3597 | } | |
3598 | } | |
c906108c SS |
3599 | } |
3600 | } | |
3601 | ||
3602 | /* Now scan the FDRs for dependencies */ | |
3603 | for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) | |
3604 | { | |
3605 | fh = f_idx + debug_info->fdr; | |
3606 | pst = fdr_to_pst[f_idx].pst; | |
3607 | ||
c5aa993b | 3608 | if (pst == (struct partial_symtab *) NULL) |
c906108c SS |
3609 | continue; |
3610 | ||
3611 | /* This should catch stabs-in-ecoff. */ | |
3612 | if (fh->crfd <= 1) | |
3613 | continue; | |
3614 | ||
3615 | /* Skip the first file indirect entry as it is a self dependency | |
c5aa993b | 3616 | for source files or a reverse .h -> .c dependency for header files. */ |
c906108c SS |
3617 | pst->number_of_dependencies = 0; |
3618 | pst->dependencies = | |
3619 | ((struct partial_symtab **) | |
8b92e4d5 | 3620 | obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
3621 | ((fh->crfd - 1) |
3622 | * sizeof (struct partial_symtab *)))); | |
3623 | for (s_idx = 1; s_idx < fh->crfd; s_idx++) | |
3624 | { | |
3625 | RFDT rh; | |
3626 | ||
3627 | (*swap_rfd_in) (cur_bfd, | |
3628 | ((char *) debug_info->external_rfd | |
3629 | + (fh->rfdBase + s_idx) * external_rfd_size), | |
3630 | &rh); | |
3631 | if (rh < 0 || rh >= hdr->ifdMax) | |
3632 | { | |
23136709 | 3633 | complaint (&symfile_complaints, "bad file number %ld", rh); |
c906108c SS |
3634 | continue; |
3635 | } | |
3636 | ||
3637 | /* Skip self dependencies of header files. */ | |
3638 | if (rh == f_idx) | |
3639 | continue; | |
3640 | ||
3641 | /* Do not add to dependeny list if psymtab was empty. */ | |
c5aa993b | 3642 | if (fdr_to_pst[rh].pst == (struct partial_symtab *) NULL) |
c906108c SS |
3643 | continue; |
3644 | pst->dependencies[pst->number_of_dependencies++] = fdr_to_pst[rh].pst; | |
3645 | } | |
3646 | } | |
3647 | ||
3648 | /* Remove the dummy psymtab created for -O3 images above, if it is | |
3649 | still empty, to enable the detection of stripped executables. */ | |
3650 | if (objfile->psymtabs->next == NULL | |
3651 | && objfile->psymtabs->number_of_dependencies == 0 | |
3652 | && objfile->psymtabs->n_global_syms == 0 | |
3653 | && objfile->psymtabs->n_static_syms == 0) | |
3654 | objfile->psymtabs = NULL; | |
3655 | do_cleanups (old_chain); | |
3656 | } | |
3657 | ||
3658 | /* If the current psymbol has an enumerated type, we need to add | |
3659 | all the the enum constants to the partial symbol table. */ | |
3660 | ||
3661 | static void | |
fba45db2 KB |
3662 | handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype, |
3663 | CORE_ADDR svalue) | |
c906108c SS |
3664 | { |
3665 | const bfd_size_type external_sym_size = debug_swap->external_sym_size; | |
12b9c64f | 3666 | void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in; |
c906108c | 3667 | char *ext_sym = ((char *) debug_info->external_sym |
c5aa993b | 3668 | + ((fh->isymBase + cur_sdx + 1) * external_sym_size)); |
c906108c SS |
3669 | SYMR sh; |
3670 | TIR tir; | |
3671 | ||
3672 | switch (stype) | |
3673 | { | |
3674 | case stEnum: | |
3675 | break; | |
3676 | ||
3677 | case stBlock: | |
3678 | /* It is an enumerated type if the next symbol entry is a stMember | |
c5aa993b JM |
3679 | and its auxiliary index is indexNil or its auxiliary entry |
3680 | is a plain btNil or btVoid. | |
3681 | Alpha cc -migrate enums are recognized by a zero index and | |
3682 | a zero symbol value. | |
3683 | DU 4.0 cc enums are recognized by a member type of btEnum without | |
3684 | qualifiers and a zero symbol value. */ | |
c906108c SS |
3685 | (*swap_sym_in) (cur_bfd, ext_sym, &sh); |
3686 | if (sh.st != stMember) | |
3687 | return; | |
3688 | ||
3689 | if (sh.index == indexNil | |
3690 | || (sh.index == 0 && svalue == 0)) | |
3691 | break; | |
3692 | (*debug_swap->swap_tir_in) (fh->fBigendian, | |
3693 | &(debug_info->external_aux | |
3694 | + fh->iauxBase + sh.index)->a_ti, | |
3695 | &tir); | |
3696 | if ((tir.bt != btNil | |
3697 | && tir.bt != btVoid | |
3698 | && (tir.bt != btEnum || svalue != 0)) | |
3699 | || tir.tq0 != tqNil) | |
3700 | return; | |
3701 | break; | |
3702 | ||
3703 | default: | |
3704 | return; | |
3705 | } | |
3706 | ||
3707 | for (;;) | |
3708 | { | |
3709 | char *name; | |
3710 | ||
3711 | (*swap_sym_in) (cur_bfd, ext_sym, &sh); | |
3712 | if (sh.st != stMember) | |
3713 | break; | |
3714 | name = debug_info->ss + cur_fdr->issBase + sh.iss; | |
3715 | ||
3716 | /* Note that the value doesn't matter for enum constants | |
c5aa993b | 3717 | in psymtabs, just in symtabs. */ |
c906108c | 3718 | add_psymbol_to_list (name, strlen (name), |
176620f1 | 3719 | VAR_DOMAIN, LOC_CONST, |
c906108c SS |
3720 | &objfile->static_psymbols, 0, |
3721 | (CORE_ADDR) 0, psymtab_language, objfile); | |
3722 | ext_sym += external_sym_size; | |
3723 | } | |
3724 | } | |
3725 | ||
0e7e8d51 KB |
3726 | /* Get the next symbol. OBJFILE is unused. */ |
3727 | ||
c906108c | 3728 | static char * |
0e7e8d51 | 3729 | mdebug_next_symbol_text (struct objfile *objfile) |
c906108c SS |
3730 | { |
3731 | SYMR sh; | |
3732 | ||
3733 | cur_sdx++; | |
3734 | (*debug_swap->swap_sym_in) (cur_bfd, | |
3735 | ((char *) debug_info->external_sym | |
3736 | + ((cur_fdr->isymBase + cur_sdx) | |
3737 | * debug_swap->external_sym_size)), | |
3738 | &sh); | |
3739 | return debug_info->ss + cur_fdr->issBase + sh.iss; | |
3740 | } | |
3741 | ||
3742 | /* Ancillary function to psymtab_to_symtab(). Does all the work | |
3743 | for turning the partial symtab PST into a symtab, recurring | |
3744 | first on all dependent psymtabs. The argument FILENAME is | |
3745 | only passed so we can see in debug stack traces what file | |
3746 | is being read. | |
3747 | ||
3748 | This function has a split personality, based on whether the | |
3749 | symbol table contains ordinary ecoff symbols, or stabs-in-ecoff. | |
3750 | The flow of control and even the memory allocation differs. FIXME. */ | |
3751 | ||
3752 | static void | |
fba45db2 | 3753 | psymtab_to_symtab_1 (struct partial_symtab *pst, char *filename) |
c906108c SS |
3754 | { |
3755 | bfd_size_type external_sym_size; | |
3756 | bfd_size_type external_pdr_size; | |
12b9c64f AO |
3757 | void (*swap_sym_in) (bfd *, void *, SYMR *); |
3758 | void (*swap_pdr_in) (bfd *, void *, PDR *); | |
c906108c | 3759 | int i; |
16db6055 | 3760 | struct symtab *st = NULL; |
c906108c SS |
3761 | FDR *fh; |
3762 | struct linetable *lines; | |
3763 | CORE_ADDR lowest_pdr_addr = 0; | |
16db6055 | 3764 | int last_symtab_ended = 0; |
c906108c SS |
3765 | |
3766 | if (pst->readin) | |
3767 | return; | |
3768 | pst->readin = 1; | |
3769 | ||
3770 | /* Read in all partial symbtabs on which this one is dependent. | |
3771 | NOTE that we do have circular dependencies, sigh. We solved | |
3772 | that by setting pst->readin before this point. */ | |
3773 | ||
3774 | for (i = 0; i < pst->number_of_dependencies; i++) | |
3775 | if (!pst->dependencies[i]->readin) | |
3776 | { | |
3777 | /* Inform about additional files to be read in. */ | |
3778 | if (info_verbose) | |
3779 | { | |
3780 | fputs_filtered (" ", gdb_stdout); | |
3781 | wrap_here (""); | |
3782 | fputs_filtered ("and ", gdb_stdout); | |
3783 | wrap_here (""); | |
3784 | printf_filtered ("%s...", | |
3785 | pst->dependencies[i]->filename); | |
3786 | wrap_here (""); /* Flush output */ | |
3787 | gdb_flush (gdb_stdout); | |
3788 | } | |
3789 | /* We only pass the filename for debug purposes */ | |
3790 | psymtab_to_symtab_1 (pst->dependencies[i], | |
3791 | pst->dependencies[i]->filename); | |
3792 | } | |
3793 | ||
3794 | /* Do nothing if this is a dummy psymtab. */ | |
3795 | ||
3796 | if (pst->n_global_syms == 0 && pst->n_static_syms == 0 | |
5afc051b | 3797 | && pst->textlow == 0 && pst->texthigh == 0) |
c906108c SS |
3798 | return; |
3799 | ||
3800 | /* Now read the symbols for this symtab */ | |
3801 | ||
3802 | cur_bfd = CUR_BFD (pst); | |
3803 | debug_swap = DEBUG_SWAP (pst); | |
3804 | debug_info = DEBUG_INFO (pst); | |
3805 | pending_list = PENDING_LIST (pst); | |
3806 | external_sym_size = debug_swap->external_sym_size; | |
3807 | external_pdr_size = debug_swap->external_pdr_size; | |
3808 | swap_sym_in = debug_swap->swap_sym_in; | |
3809 | swap_pdr_in = debug_swap->swap_pdr_in; | |
3810 | current_objfile = pst->objfile; | |
3811 | cur_fd = FDR_IDX (pst); | |
3812 | fh = ((cur_fd == -1) | |
3813 | ? (FDR *) NULL | |
3814 | : debug_info->fdr + cur_fd); | |
3815 | cur_fdr = fh; | |
3816 | ||
3817 | /* See comment in parse_partial_symbols about the @stabs sentinel. */ | |
3818 | processing_gcc_compilation = 0; | |
3819 | if (fh != (FDR *) NULL && fh->csym >= 2) | |
3820 | { | |
3821 | SYMR sh; | |
3822 | ||
3823 | (*swap_sym_in) (cur_bfd, | |
3824 | ((char *) debug_info->external_sym | |
3825 | + (fh->isymBase + 1) * external_sym_size), | |
3826 | &sh); | |
ee300cd4 AC |
3827 | if (strcmp (debug_info->ss + fh->issBase + sh.iss, |
3828 | stabs_symbol) == 0) | |
c906108c SS |
3829 | { |
3830 | /* We indicate that this is a GCC compilation so that certain | |
3831 | features will be enabled in stabsread/dbxread. */ | |
3832 | processing_gcc_compilation = 2; | |
3833 | } | |
3834 | } | |
3835 | ||
3836 | if (processing_gcc_compilation != 0) | |
3837 | { | |
3838 | ||
3839 | /* This symbol table contains stabs-in-ecoff entries. */ | |
3840 | ||
3841 | /* Parse local symbols first */ | |
3842 | ||
3843 | if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */ | |
3844 | { | |
3845 | current_objfile = NULL; | |
3846 | return; | |
3847 | } | |
3848 | for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) | |
3849 | { | |
3850 | SYMR sh; | |
3851 | char *name; | |
3852 | CORE_ADDR valu; | |
3853 | ||
3854 | (*swap_sym_in) (cur_bfd, | |
3855 | (((char *) debug_info->external_sym) | |
3856 | + (fh->isymBase + cur_sdx) * external_sym_size), | |
3857 | &sh); | |
3858 | name = debug_info->ss + fh->issBase + sh.iss; | |
3859 | valu = sh.value; | |
3860 | /* XXX This is a hack. It will go away! */ | |
3861 | if (ECOFF_IS_STAB (&sh) || (name[0] == '#')) | |
3862 | { | |
3863 | int type_code = ECOFF_UNMARK_STAB (sh.index); | |
3864 | ||
3865 | /* We should never get non N_STAB symbols here, but they | |
c5aa993b JM |
3866 | should be harmless, so keep process_one_symbol from |
3867 | complaining about them. */ | |
c906108c SS |
3868 | if (type_code & N_STAB) |
3869 | { | |
16db6055 EZ |
3870 | /* If we found a trailing N_SO with no name, process |
3871 | it here instead of in process_one_symbol, so we | |
3872 | can keep a handle to its symtab. The symtab | |
3873 | would otherwise be ended twice, once in | |
3874 | process_one_symbol, and once after this loop. */ | |
3875 | if (type_code == N_SO | |
3876 | && last_source_file | |
3877 | && previous_stab_code != (unsigned char) N_SO | |
3878 | && *name == '\000') | |
3879 | { | |
3880 | valu += ANOFFSET (pst->section_offsets, | |
3881 | SECT_OFF_TEXT (pst->objfile)); | |
3882 | previous_stab_code = N_SO; | |
3883 | st = end_symtab (valu, pst->objfile, | |
3884 | SECT_OFF_TEXT (pst->objfile)); | |
3885 | end_stabs (); | |
3886 | last_symtab_ended = 1; | |
3887 | } | |
3888 | else | |
3889 | { | |
3890 | last_symtab_ended = 0; | |
3891 | process_one_symbol (type_code, 0, valu, name, | |
3892 | pst->section_offsets, pst->objfile); | |
3893 | } | |
c906108c SS |
3894 | } |
3895 | /* Similarly a hack. */ | |
3896 | else if (name[0] == '#') | |
3897 | { | |
3898 | process_one_symbol (N_SLINE, 0, valu, name, | |
3899 | pst->section_offsets, pst->objfile); | |
3900 | } | |
3901 | if (type_code == N_FUN) | |
3902 | { | |
3903 | /* Make up special symbol to contain | |
3904 | procedure specific info */ | |
f92761ec AC |
3905 | struct mdebug_extra_func_info *e = |
3906 | ((struct mdebug_extra_func_info *) | |
4a146b47 | 3907 | obstack_alloc (¤t_objfile->objfile_obstack, |
f92761ec AC |
3908 | sizeof (struct mdebug_extra_func_info))); |
3909 | struct symbol *s = new_symbol (MDEBUG_EFI_SYMBOL_NAME); | |
c906108c | 3910 | |
f92761ec | 3911 | memset (e, 0, sizeof (struct mdebug_extra_func_info)); |
176620f1 | 3912 | SYMBOL_DOMAIN (s) = LABEL_DOMAIN; |
c906108c SS |
3913 | SYMBOL_CLASS (s) = LOC_CONST; |
3914 | SYMBOL_TYPE (s) = mdebug_type_void; | |
3915 | SYMBOL_VALUE (s) = (long) e; | |
3916 | e->pdr.framereg = -1; | |
3917 | add_symbol_to_list (s, &local_symbols); | |
3918 | } | |
3919 | } | |
3920 | else if (sh.st == stLabel) | |
3921 | { | |
3922 | if (sh.index == indexNil) | |
3923 | { | |
3924 | /* This is what the gcc2_compiled and __gnu_compiled_* | |
3925 | show up as. So don't complain. */ | |
3926 | ; | |
3927 | } | |
3928 | else | |
3929 | { | |
3930 | /* Handle encoded stab line number. */ | |
b8fbeb18 | 3931 | valu += ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)); |
c906108c SS |
3932 | record_line (current_subfile, sh.index, valu); |
3933 | } | |
3934 | } | |
3935 | else if (sh.st == stProc || sh.st == stStaticProc | |
3936 | || sh.st == stStatic || sh.st == stEnd) | |
3937 | /* These are generated by gcc-2.x, do not complain */ | |
3938 | ; | |
3939 | else | |
23136709 | 3940 | complaint (&symfile_complaints, "unknown stabs symbol %s", name); |
c906108c | 3941 | } |
16db6055 EZ |
3942 | |
3943 | if (! last_symtab_ended) | |
3944 | { | |
5afc051b | 3945 | st = end_symtab (pst->texthigh, pst->objfile, SECT_OFF_TEXT (pst->objfile)); |
16db6055 EZ |
3946 | end_stabs (); |
3947 | } | |
c906108c | 3948 | |
c906108c | 3949 | /* There used to be a call to sort_blocks here, but this should not |
c5aa993b JM |
3950 | be necessary for stabs symtabs. And as sort_blocks modifies the |
3951 | start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK, | |
3952 | it did the wrong thing if the first procedure in a file was | |
3953 | generated via asm statements. */ | |
c906108c SS |
3954 | |
3955 | /* Fill in procedure info next. */ | |
3956 | if (fh->cpd > 0) | |
3957 | { | |
3958 | PDR *pr_block; | |
3959 | struct cleanup *old_chain; | |
3960 | char *pdr_ptr; | |
3961 | char *pdr_end; | |
3962 | PDR *pdr_in; | |
3963 | PDR *pdr_in_end; | |
3964 | ||
3965 | pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR)); | |
b8c9b27d | 3966 | old_chain = make_cleanup (xfree, pr_block); |
c906108c SS |
3967 | |
3968 | pdr_ptr = ((char *) debug_info->external_pdr | |
3969 | + fh->ipdFirst * external_pdr_size); | |
3970 | pdr_end = pdr_ptr + fh->cpd * external_pdr_size; | |
3971 | pdr_in = pr_block; | |
3972 | for (; | |
3973 | pdr_ptr < pdr_end; | |
3974 | pdr_ptr += external_pdr_size, pdr_in++) | |
3975 | { | |
3976 | (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in); | |
3977 | ||
3978 | /* Determine lowest PDR address, the PDRs are not always | |
c5aa993b | 3979 | sorted. */ |
c906108c SS |
3980 | if (pdr_in == pr_block) |
3981 | lowest_pdr_addr = pdr_in->adr; | |
3982 | else if (pdr_in->adr < lowest_pdr_addr) | |
3983 | lowest_pdr_addr = pdr_in->adr; | |
3984 | } | |
3985 | ||
3986 | pdr_in = pr_block; | |
3987 | pdr_in_end = pdr_in + fh->cpd; | |
3988 | for (; pdr_in < pdr_in_end; pdr_in++) | |
3989 | parse_procedure (pdr_in, st, pst); | |
3990 | ||
3991 | do_cleanups (old_chain); | |
3992 | } | |
3993 | } | |
3994 | else | |
3995 | { | |
3996 | /* This symbol table contains ordinary ecoff entries. */ | |
3997 | ||
3998 | int f_max; | |
3999 | int maxlines; | |
4000 | EXTR *ext_ptr; | |
4001 | ||
c906108c SS |
4002 | if (fh == 0) |
4003 | { | |
4004 | maxlines = 0; | |
de4f826b | 4005 | st = new_symtab ("unknown", 0, pst->objfile); |
c906108c SS |
4006 | } |
4007 | else | |
4008 | { | |
c906108c | 4009 | maxlines = 2 * fh->cline; |
de4f826b | 4010 | st = new_symtab (pst->filename, maxlines, pst->objfile); |
c906108c SS |
4011 | |
4012 | /* The proper language was already determined when building | |
4013 | the psymtab, use it. */ | |
4014 | st->language = PST_PRIVATE (pst)->pst_language; | |
4015 | } | |
4016 | ||
4017 | psymtab_language = st->language; | |
4018 | ||
4019 | lines = LINETABLE (st); | |
4020 | ||
4021 | /* Get a new lexical context */ | |
4022 | ||
4023 | push_parse_stack (); | |
4024 | top_stack->cur_st = st; | |
4025 | top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st), | |
4026 | STATIC_BLOCK); | |
5afc051b | 4027 | BLOCK_START (top_stack->cur_block) = pst->textlow; |
c906108c SS |
4028 | BLOCK_END (top_stack->cur_block) = 0; |
4029 | top_stack->blocktype = stFile; | |
c906108c SS |
4030 | top_stack->cur_type = 0; |
4031 | top_stack->procadr = 0; | |
4032 | top_stack->numargs = 0; | |
4033 | found_ecoff_debugging_info = 0; | |
4034 | ||
4035 | if (fh) | |
4036 | { | |
4037 | char *sym_ptr; | |
4038 | char *sym_end; | |
4039 | ||
4040 | /* Parse local symbols first */ | |
4041 | sym_ptr = ((char *) debug_info->external_sym | |
4042 | + fh->isymBase * external_sym_size); | |
4043 | sym_end = sym_ptr + fh->csym * external_sym_size; | |
4044 | while (sym_ptr < sym_end) | |
4045 | { | |
4046 | SYMR sh; | |
4047 | int c; | |
4048 | ||
4049 | (*swap_sym_in) (cur_bfd, sym_ptr, &sh); | |
4050 | c = parse_symbol (&sh, | |
4051 | debug_info->external_aux + fh->iauxBase, | |
b8fbeb18 | 4052 | sym_ptr, fh->fBigendian, pst->section_offsets, pst->objfile); |
c906108c SS |
4053 | sym_ptr += c * external_sym_size; |
4054 | } | |
4055 | ||
4056 | /* Linenumbers. At the end, check if we can save memory. | |
4057 | parse_lines has to look ahead an arbitrary number of PDR | |
4058 | structures, so we swap them all first. */ | |
4059 | if (fh->cpd > 0) | |
4060 | { | |
4061 | PDR *pr_block; | |
4062 | struct cleanup *old_chain; | |
4063 | char *pdr_ptr; | |
4064 | char *pdr_end; | |
4065 | PDR *pdr_in; | |
4066 | PDR *pdr_in_end; | |
4067 | ||
4068 | pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR)); | |
4069 | ||
b8c9b27d | 4070 | old_chain = make_cleanup (xfree, pr_block); |
c906108c SS |
4071 | |
4072 | pdr_ptr = ((char *) debug_info->external_pdr | |
4073 | + fh->ipdFirst * external_pdr_size); | |
4074 | pdr_end = pdr_ptr + fh->cpd * external_pdr_size; | |
4075 | pdr_in = pr_block; | |
4076 | for (; | |
4077 | pdr_ptr < pdr_end; | |
4078 | pdr_ptr += external_pdr_size, pdr_in++) | |
4079 | { | |
4080 | (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in); | |
4081 | ||
4082 | /* Determine lowest PDR address, the PDRs are not always | |
4083 | sorted. */ | |
4084 | if (pdr_in == pr_block) | |
4085 | lowest_pdr_addr = pdr_in->adr; | |
4086 | else if (pdr_in->adr < lowest_pdr_addr) | |
4087 | lowest_pdr_addr = pdr_in->adr; | |
4088 | } | |
4089 | ||
4090 | parse_lines (fh, pr_block, lines, maxlines, pst, lowest_pdr_addr); | |
4091 | if (lines->nitems < fh->cline) | |
4092 | lines = shrink_linetable (lines); | |
4093 | ||
4094 | /* Fill in procedure info next. */ | |
4095 | pdr_in = pr_block; | |
4096 | pdr_in_end = pdr_in + fh->cpd; | |
4097 | for (; pdr_in < pdr_in_end; pdr_in++) | |
4098 | parse_procedure (pdr_in, 0, pst); | |
4099 | ||
4100 | do_cleanups (old_chain); | |
4101 | } | |
4102 | } | |
4103 | ||
4104 | LINETABLE (st) = lines; | |
4105 | ||
4106 | /* .. and our share of externals. | |
c5aa993b JM |
4107 | XXX use the global list to speed up things here. how? |
4108 | FIXME, Maybe quit once we have found the right number of ext's? */ | |
c906108c SS |
4109 | top_stack->cur_st = st; |
4110 | top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st), | |
4111 | GLOBAL_BLOCK); | |
4112 | top_stack->blocktype = stFile; | |
c906108c SS |
4113 | |
4114 | ext_ptr = PST_PRIVATE (pst)->extern_tab; | |
4115 | for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++) | |
b8fbeb18 | 4116 | parse_external (ext_ptr, fh->fBigendian, pst->section_offsets, pst->objfile); |
c906108c SS |
4117 | |
4118 | /* If there are undefined symbols, tell the user. | |
c5aa993b JM |
4119 | The alpha has an undefined symbol for every symbol that is |
4120 | from a shared library, so tell the user only if verbose is on. */ | |
c906108c SS |
4121 | if (info_verbose && n_undef_symbols) |
4122 | { | |
4123 | printf_filtered ("File %s contains %d unresolved references:", | |
4124 | st->filename, n_undef_symbols); | |
4125 | printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n", | |
4126 | n_undef_vars, n_undef_procs, n_undef_labels); | |
4127 | n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0; | |
4128 | ||
4129 | } | |
4130 | pop_parse_stack (); | |
4131 | ||
4132 | st->primary = 1; | |
4133 | ||
c906108c SS |
4134 | sort_blocks (st); |
4135 | } | |
4136 | ||
4137 | /* Now link the psymtab and the symtab. */ | |
4138 | pst->symtab = st; | |
4139 | ||
4140 | current_objfile = NULL; | |
4141 | } | |
4142 | \f | |
4143 | /* Ancillary parsing procedures. */ | |
4144 | ||
4145 | /* Return 1 if the symbol pointed to by SH has a cross reference | |
4146 | to an opaque aggregate type, else 0. */ | |
4147 | ||
4148 | static int | |
fba45db2 | 4149 | has_opaque_xref (FDR *fh, SYMR *sh) |
c906108c SS |
4150 | { |
4151 | TIR tir; | |
4152 | union aux_ext *ax; | |
4153 | RNDXR rn[1]; | |
4154 | unsigned int rf; | |
4155 | ||
4156 | if (sh->index == indexNil) | |
4157 | return 0; | |
4158 | ||
4159 | ax = debug_info->external_aux + fh->iauxBase + sh->index; | |
4160 | (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir); | |
4161 | if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum) | |
4162 | return 0; | |
4163 | ||
4164 | ax++; | |
4165 | (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn); | |
4166 | if (rn->rfd == 0xfff) | |
4167 | rf = AUX_GET_ISYM (fh->fBigendian, ax + 1); | |
4168 | else | |
4169 | rf = rn->rfd; | |
4170 | if (rf != -1) | |
4171 | return 0; | |
4172 | return 1; | |
4173 | } | |
4174 | ||
4175 | /* Lookup the type at relative index RN. Return it in TPP | |
4176 | if found and in any event come up with its name PNAME. | |
4177 | BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian). | |
4178 | Return value says how many aux symbols we ate. */ | |
4179 | ||
4180 | static int | |
fba45db2 KB |
4181 | cross_ref (int fd, union aux_ext *ax, struct type **tpp, enum type_code type_code, /* Use to alloc new type if none is found. */ |
4182 | char **pname, int bigend, char *sym_name) | |
c906108c SS |
4183 | { |
4184 | RNDXR rn[1]; | |
4185 | unsigned int rf; | |
4186 | int result = 1; | |
4187 | FDR *fh; | |
4188 | char *esh; | |
4189 | SYMR sh; | |
4190 | int xref_fd; | |
4191 | struct mdebug_pending *pend; | |
4192 | ||
c5aa993b | 4193 | *tpp = (struct type *) NULL; |
c906108c SS |
4194 | |
4195 | (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn); | |
4196 | ||
4197 | /* Escape index means 'the next one' */ | |
4198 | if (rn->rfd == 0xfff) | |
4199 | { | |
4200 | result++; | |
4201 | rf = AUX_GET_ISYM (bigend, ax + 1); | |
4202 | } | |
4203 | else | |
4204 | { | |
4205 | rf = rn->rfd; | |
4206 | } | |
4207 | ||
4208 | /* mips cc uses a rf of -1 for opaque struct definitions. | |
4209 | Set TYPE_FLAG_STUB for these types so that check_typedef will | |
4210 | resolve them if the struct gets defined in another compilation unit. */ | |
4211 | if (rf == -1) | |
4212 | { | |
4213 | *pname = "<undefined>"; | |
0b3d7c6d | 4214 | *tpp = init_type (type_code, 0, TYPE_FLAG_STUB, (char *) NULL, current_objfile); |
c906108c SS |
4215 | return result; |
4216 | } | |
4217 | ||
4218 | /* mips cc uses an escaped rn->index of 0 for struct return types | |
4219 | of procedures that were compiled without -g. These will always remain | |
4220 | undefined. */ | |
4221 | if (rn->rfd == 0xfff && rn->index == 0) | |
4222 | { | |
4223 | *pname = "<undefined>"; | |
4224 | return result; | |
4225 | } | |
4226 | ||
4227 | /* Find the relative file descriptor and the symbol in it. */ | |
4228 | fh = get_rfd (fd, rf); | |
4229 | xref_fd = fh - debug_info->fdr; | |
4230 | ||
4231 | if (rn->index >= fh->csym) | |
4232 | { | |
4233 | /* File indirect entry is corrupt. */ | |
4234 | *pname = "<illegal>"; | |
23136709 | 4235 | bad_rfd_entry_complaint (sym_name, xref_fd, rn->index); |
c906108c SS |
4236 | return result; |
4237 | } | |
4238 | ||
4239 | /* If we have processed this symbol then we left a forwarding | |
4240 | pointer to the type in the pending list. If not, we`ll put | |
4241 | it in a list of pending types, to be processed later when | |
4242 | the file will be. In any event, we collect the name for the | |
4243 | type here. */ | |
4244 | ||
4245 | esh = ((char *) debug_info->external_sym | |
4246 | + ((fh->isymBase + rn->index) | |
4247 | * debug_swap->external_sym_size)); | |
4248 | (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh); | |
4249 | ||
4250 | /* Make sure that this type of cross reference can be handled. */ | |
4251 | if ((sh.sc != scInfo | |
4252 | || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect | |
4253 | && sh.st != stStruct && sh.st != stUnion | |
4254 | && sh.st != stEnum)) | |
c5aa993b | 4255 | && (sh.st != stBlock || !SC_IS_COMMON (sh.sc))) |
c906108c SS |
4256 | { |
4257 | /* File indirect entry is corrupt. */ | |
4258 | *pname = "<illegal>"; | |
23136709 | 4259 | bad_rfd_entry_complaint (sym_name, xref_fd, rn->index); |
c906108c SS |
4260 | return result; |
4261 | } | |
4262 | ||
4263 | *pname = debug_info->ss + fh->issBase + sh.iss; | |
4264 | ||
4265 | pend = is_pending_symbol (fh, esh); | |
4266 | if (pend) | |
4267 | *tpp = pend->t; | |
4268 | else | |
4269 | { | |
4270 | /* We have not yet seen this type. */ | |
4271 | ||
4272 | if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect) | |
4273 | { | |
4274 | TIR tir; | |
4275 | ||
4276 | /* alpha cc puts out a stTypedef with a sh.iss of zero for | |
4277 | two cases: | |
4278 | a) forward declarations of structs/unions/enums which are not | |
c5aa993b JM |
4279 | defined in this compilation unit. |
4280 | For these the type will be void. This is a bad design decision | |
4281 | as cross referencing across compilation units is impossible | |
4282 | due to the missing name. | |
c906108c | 4283 | b) forward declarations of structs/unions/enums/typedefs which |
c5aa993b JM |
4284 | are defined later in this file or in another file in the same |
4285 | compilation unit. Irix5 cc uses a stIndirect symbol for this. | |
4286 | Simply cross reference those again to get the true type. | |
c906108c SS |
4287 | The forward references are not entered in the pending list and |
4288 | in the symbol table. */ | |
4289 | ||
4290 | (*debug_swap->swap_tir_in) (bigend, | |
4291 | &(debug_info->external_aux | |
4292 | + fh->iauxBase + sh.index)->a_ti, | |
4293 | &tir); | |
4294 | if (tir.tq0 != tqNil) | |
23136709 KB |
4295 | complaint (&symfile_complaints, |
4296 | "illegal tq0 in forward typedef for %s", sym_name); | |
c906108c SS |
4297 | switch (tir.bt) |
4298 | { | |
4299 | case btVoid: | |
4300 | *tpp = init_type (type_code, 0, 0, (char *) NULL, | |
4301 | current_objfile); | |
c5aa993b | 4302 | *pname = "<undefined>"; |
c906108c SS |
4303 | break; |
4304 | ||
4305 | case btStruct: | |
4306 | case btUnion: | |
4307 | case btEnum: | |
4308 | cross_ref (xref_fd, | |
4309 | (debug_info->external_aux | |
4310 | + fh->iauxBase + sh.index + 1), | |
4311 | tpp, type_code, pname, | |
4312 | fh->fBigendian, sym_name); | |
4313 | break; | |
4314 | ||
4315 | case btTypedef: | |
4316 | /* Follow a forward typedef. This might recursively | |
c5aa993b JM |
4317 | call cross_ref till we get a non typedef'ed type. |
4318 | FIXME: This is not correct behaviour, but gdb currently | |
4319 | cannot handle typedefs without type copying. Type | |
4320 | copying is impossible as we might have mutual forward | |
4321 | references between two files and the copied type would not | |
4322 | get filled in when we later parse its definition. */ | |
c906108c SS |
4323 | *tpp = parse_type (xref_fd, |
4324 | debug_info->external_aux + fh->iauxBase, | |
4325 | sh.index, | |
c5aa993b | 4326 | (int *) NULL, |
c906108c SS |
4327 | fh->fBigendian, |
4328 | debug_info->ss + fh->issBase + sh.iss); | |
4329 | add_pending (fh, esh, *tpp); | |
4330 | break; | |
4331 | ||
4332 | default: | |
23136709 KB |
4333 | complaint (&symfile_complaints, |
4334 | "illegal bt %d in forward typedef for %s", tir.bt, | |
4335 | sym_name); | |
c906108c SS |
4336 | *tpp = init_type (type_code, 0, 0, (char *) NULL, |
4337 | current_objfile); | |
4338 | break; | |
4339 | } | |
4340 | return result; | |
4341 | } | |
4342 | else if (sh.st == stTypedef) | |
4343 | { | |
4344 | /* Parse the type for a normal typedef. This might recursively call | |
4345 | cross_ref till we get a non typedef'ed type. | |
4346 | FIXME: This is not correct behaviour, but gdb currently | |
4347 | cannot handle typedefs without type copying. But type copying is | |
4348 | impossible as we might have mutual forward references between | |
4349 | two files and the copied type would not get filled in when | |
4350 | we later parse its definition. */ | |
4351 | *tpp = parse_type (xref_fd, | |
4352 | debug_info->external_aux + fh->iauxBase, | |
4353 | sh.index, | |
c5aa993b | 4354 | (int *) NULL, |
c906108c SS |
4355 | fh->fBigendian, |
4356 | debug_info->ss + fh->issBase + sh.iss); | |
4357 | } | |
4358 | else | |
4359 | { | |
4360 | /* Cross reference to a struct/union/enum which is defined | |
4361 | in another file in the same compilation unit but that file | |
4362 | has not been parsed yet. | |
4363 | Initialize the type only, it will be filled in when | |
4364 | it's definition is parsed. */ | |
4365 | *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile); | |
4366 | } | |
4367 | add_pending (fh, esh, *tpp); | |
4368 | } | |
4369 | ||
4370 | /* We used one auxent normally, two if we got a "next one" rf. */ | |
4371 | return result; | |
4372 | } | |
4373 | ||
4374 | ||
4375 | /* Quick&dirty lookup procedure, to avoid the MI ones that require | |
4376 | keeping the symtab sorted */ | |
4377 | ||
4378 | static struct symbol * | |
aa1ee363 | 4379 | mylookup_symbol (char *name, struct block *block, |
176620f1 | 4380 | domain_enum domain, enum address_class class) |
c906108c | 4381 | { |
de4f826b DC |
4382 | struct dict_iterator iter; |
4383 | int inc; | |
e88c90f2 | 4384 | struct symbol *sym; |
c906108c | 4385 | |
c906108c | 4386 | inc = name[0]; |
de4f826b | 4387 | ALL_BLOCK_SYMBOLS (block, iter, sym) |
c906108c | 4388 | { |
22abf04a | 4389 | if (DEPRECATED_SYMBOL_NAME (sym)[0] == inc |
176620f1 | 4390 | && SYMBOL_DOMAIN (sym) == domain |
c906108c | 4391 | && SYMBOL_CLASS (sym) == class |
22abf04a | 4392 | && strcmp (DEPRECATED_SYMBOL_NAME (sym), name) == 0) |
c906108c | 4393 | return sym; |
c906108c | 4394 | } |
e88c90f2 | 4395 | |
c906108c SS |
4396 | block = BLOCK_SUPERBLOCK (block); |
4397 | if (block) | |
176620f1 | 4398 | return mylookup_symbol (name, block, domain, class); |
c906108c SS |
4399 | return 0; |
4400 | } | |
4401 | ||
4402 | ||
de4f826b | 4403 | /* Add a new symbol S to a block B. */ |
c906108c SS |
4404 | |
4405 | static void | |
fba45db2 | 4406 | add_symbol (struct symbol *s, struct block *b) |
c906108c | 4407 | { |
de4f826b | 4408 | dict_add_symbol (BLOCK_DICT (b), s); |
c906108c SS |
4409 | } |
4410 | ||
4411 | /* Add a new block B to a symtab S */ | |
4412 | ||
4413 | static void | |
fba45db2 | 4414 | add_block (struct block *b, struct symtab *s) |
c906108c SS |
4415 | { |
4416 | struct blockvector *bv = BLOCKVECTOR (s); | |
4417 | ||
12b9c64f | 4418 | bv = (struct blockvector *) xrealloc ((void *) bv, |
c906108c SS |
4419 | (sizeof (struct blockvector) |
4420 | + BLOCKVECTOR_NBLOCKS (bv) | |
4421 | * sizeof (bv->block))); | |
4422 | if (bv != BLOCKVECTOR (s)) | |
4423 | BLOCKVECTOR (s) = bv; | |
4424 | ||
4425 | BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b; | |
4426 | } | |
4427 | ||
4428 | /* Add a new linenumber entry (LINENO,ADR) to a linevector LT. | |
4429 | MIPS' linenumber encoding might need more than one byte | |
4430 | to describe it, LAST is used to detect these continuation lines. | |
4431 | ||
4432 | Combining lines with the same line number seems like a bad idea. | |
4433 | E.g: There could be a line number entry with the same line number after the | |
4434 | prologue and GDB should not ignore it (this is a better way to find | |
4435 | a prologue than mips_skip_prologue). | |
4436 | But due to the compressed line table format there are line number entries | |
4437 | for the same line which are needed to bridge the gap to the next | |
4438 | line number entry. These entries have a bogus address info with them | |
4439 | and we are unable to tell them from intended duplicate line number | |
4440 | entries. | |
4441 | This is another reason why -ggdb debugging format is preferable. */ | |
4442 | ||
4443 | static int | |
fba45db2 | 4444 | add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last) |
c906108c SS |
4445 | { |
4446 | /* DEC c89 sometimes produces zero linenos which confuse gdb. | |
4447 | Change them to something sensible. */ | |
4448 | if (lineno == 0) | |
4449 | lineno = 1; | |
4450 | if (last == 0) | |
4451 | last = -2; /* make sure we record first line */ | |
4452 | ||
4453 | if (last == lineno) /* skip continuation lines */ | |
4454 | return lineno; | |
4455 | ||
4456 | lt->item[lt->nitems].line = lineno; | |
4457 | lt->item[lt->nitems++].pc = adr << 2; | |
4458 | return lineno; | |
4459 | } | |
4460 | \f | |
4461 | /* Sorting and reordering procedures */ | |
4462 | ||
4463 | /* Blocks with a smaller low bound should come first */ | |
4464 | ||
4465 | static int | |
12b9c64f | 4466 | compare_blocks (const void *arg1, const void *arg2) |
c906108c | 4467 | { |
887432a5 | 4468 | LONGEST addr_diff; |
c906108c SS |
4469 | struct block **b1 = (struct block **) arg1; |
4470 | struct block **b2 = (struct block **) arg2; | |
4471 | ||
4472 | addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2))); | |
4473 | if (addr_diff == 0) | |
4474 | return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1))); | |
4475 | return addr_diff; | |
4476 | } | |
4477 | ||
4478 | /* Sort the blocks of a symtab S. | |
4479 | Reorder the blocks in the blockvector by code-address, | |
4480 | as required by some MI search routines */ | |
4481 | ||
4482 | static void | |
fba45db2 | 4483 | sort_blocks (struct symtab *s) |
c906108c SS |
4484 | { |
4485 | struct blockvector *bv = BLOCKVECTOR (s); | |
4486 | ||
4487 | if (BLOCKVECTOR_NBLOCKS (bv) <= 2) | |
4488 | { | |
4489 | /* Cosmetic */ | |
4490 | if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0) | |
4491 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0; | |
4492 | if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0) | |
4493 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0; | |
4494 | return; | |
4495 | } | |
4496 | /* | |
4497 | * This is very unfortunate: normally all functions are compiled in | |
4498 | * the order they are found, but if the file is compiled -O3 things | |
4499 | * are very different. It would be nice to find a reliable test | |
4500 | * to detect -O3 images in advance. | |
4501 | */ | |
4502 | if (BLOCKVECTOR_NBLOCKS (bv) > 3) | |
4503 | qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK), | |
4504 | BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK, | |
4505 | sizeof (struct block *), | |
4506 | compare_blocks); | |
4507 | ||
4508 | { | |
aa1ee363 AC |
4509 | CORE_ADDR high = 0; |
4510 | int i, j = BLOCKVECTOR_NBLOCKS (bv); | |
c906108c SS |
4511 | |
4512 | for (i = FIRST_LOCAL_BLOCK; i < j; i++) | |
4513 | if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i))) | |
4514 | high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)); | |
4515 | BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high; | |
4516 | } | |
4517 | ||
4518 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = | |
4519 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK)); | |
4520 | ||
4521 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = | |
4522 | BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); | |
4523 | BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = | |
4524 | BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)); | |
4525 | } | |
4526 | \f | |
4527 | ||
4528 | /* Constructor/restructor/destructor procedures */ | |
4529 | ||
de4f826b DC |
4530 | /* Allocate a new symtab for NAME. Needs an estimate of how many |
4531 | linenumbers MAXLINES we'll put in it */ | |
c906108c SS |
4532 | |
4533 | static struct symtab * | |
de4f826b | 4534 | new_symtab (char *name, int maxlines, struct objfile *objfile) |
c906108c SS |
4535 | { |
4536 | struct symtab *s = allocate_symtab (name, objfile); | |
4537 | ||
4538 | LINETABLE (s) = new_linetable (maxlines); | |
4539 | ||
4540 | /* All symtabs must have at least two blocks */ | |
4541 | BLOCKVECTOR (s) = new_bvect (2); | |
de4f826b DC |
4542 | BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) |
4543 | = new_block (NON_FUNCTION_BLOCK); | |
4544 | BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) | |
4545 | = new_block (NON_FUNCTION_BLOCK); | |
c906108c SS |
4546 | BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) = |
4547 | BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); | |
4548 | ||
4549 | s->free_code = free_linetable; | |
4550 | s->debugformat = obsavestring ("ECOFF", 5, | |
4a146b47 | 4551 | &objfile->objfile_obstack); |
c906108c SS |
4552 | return (s); |
4553 | } | |
4554 | ||
4555 | /* Allocate a new partial_symtab NAME */ | |
4556 | ||
4557 | static struct partial_symtab * | |
fba45db2 | 4558 | new_psymtab (char *name, struct objfile *objfile) |
c906108c SS |
4559 | { |
4560 | struct partial_symtab *psymtab; | |
4561 | ||
4562 | psymtab = allocate_psymtab (name, objfile); | |
d4f3574e | 4563 | psymtab->section_offsets = objfile->section_offsets; |
c906108c SS |
4564 | |
4565 | /* Keep a backpointer to the file's symbols */ | |
4566 | ||
4567 | psymtab->read_symtab_private = ((char *) | |
8b92e4d5 | 4568 | obstack_alloc (&objfile->objfile_obstack, |
c906108c | 4569 | sizeof (struct symloc))); |
12b9c64f | 4570 | memset (psymtab->read_symtab_private, 0, sizeof (struct symloc)); |
c906108c SS |
4571 | CUR_BFD (psymtab) = cur_bfd; |
4572 | DEBUG_SWAP (psymtab) = debug_swap; | |
4573 | DEBUG_INFO (psymtab) = debug_info; | |
4574 | PENDING_LIST (psymtab) = pending_list; | |
4575 | ||
4576 | /* The way to turn this into a symtab is to call... */ | |
4577 | psymtab->read_symtab = mdebug_psymtab_to_symtab; | |
4578 | return (psymtab); | |
4579 | } | |
4580 | ||
4581 | ||
4582 | /* Allocate a linetable array of the given SIZE. Since the struct | |
4583 | already includes one item, we subtract one when calculating the | |
4584 | proper size to allocate. */ | |
4585 | ||
4586 | static struct linetable * | |
fba45db2 | 4587 | new_linetable (int size) |
c906108c SS |
4588 | { |
4589 | struct linetable *l; | |
4590 | ||
4591 | size = (size - 1) * sizeof (l->item) + sizeof (struct linetable); | |
4592 | l = (struct linetable *) xmalloc (size); | |
4593 | l->nitems = 0; | |
4594 | return l; | |
4595 | } | |
4596 | ||
4597 | /* Oops, too big. Shrink it. This was important with the 2.4 linetables, | |
4598 | I am not so sure about the 3.4 ones. | |
4599 | ||
4600 | Since the struct linetable already includes one item, we subtract one when | |
4601 | calculating the proper size to allocate. */ | |
4602 | ||
4603 | static struct linetable * | |
fba45db2 | 4604 | shrink_linetable (struct linetable *lt) |
c906108c SS |
4605 | { |
4606 | ||
12b9c64f | 4607 | return (struct linetable *) xrealloc ((void *) lt, |
c906108c SS |
4608 | (sizeof (struct linetable) |
4609 | + ((lt->nitems - 1) | |
4610 | * sizeof (lt->item)))); | |
4611 | } | |
4612 | ||
4613 | /* Allocate and zero a new blockvector of NBLOCKS blocks. */ | |
4614 | ||
4615 | static struct blockvector * | |
fba45db2 | 4616 | new_bvect (int nblocks) |
c906108c SS |
4617 | { |
4618 | struct blockvector *bv; | |
4619 | int size; | |
4620 | ||
4621 | size = sizeof (struct blockvector) + nblocks * sizeof (struct block *); | |
4622 | bv = (struct blockvector *) xzalloc (size); | |
4623 | ||
4624 | BLOCKVECTOR_NBLOCKS (bv) = nblocks; | |
4625 | ||
4626 | return bv; | |
4627 | } | |
4628 | ||
de4f826b DC |
4629 | /* Allocate and zero a new block, and set its BLOCK_DICT. If function |
4630 | is non-zero, assume the block is associated to a function, and make | |
4631 | sure that the symbols are stored linearly; otherwise, store them | |
4632 | hashed. */ | |
c906108c SS |
4633 | |
4634 | static struct block * | |
de4f826b | 4635 | new_block (enum block_type type) |
c906108c | 4636 | { |
a1632d59 DC |
4637 | /* FIXME: carlton/2003-09-11: This should use allocate_block to |
4638 | allocate the block. Which, in turn, suggests that the block | |
4639 | should be allocated on an obstack. */ | |
de4f826b | 4640 | struct block *retval = xzalloc (sizeof (struct block)); |
c906108c | 4641 | |
de4f826b DC |
4642 | if (type == FUNCTION_BLOCK) |
4643 | BLOCK_DICT (retval) = dict_create_linear_expandable (); | |
4644 | else | |
4645 | BLOCK_DICT (retval) = dict_create_hashed_expandable (); | |
c906108c | 4646 | |
de4f826b | 4647 | return retval; |
c906108c SS |
4648 | } |
4649 | ||
4650 | /* Create a new symbol with printname NAME */ | |
4651 | ||
4652 | static struct symbol * | |
fba45db2 | 4653 | new_symbol (char *name) |
c906108c SS |
4654 | { |
4655 | struct symbol *s = ((struct symbol *) | |
4a146b47 | 4656 | obstack_alloc (¤t_objfile->objfile_obstack, |
c906108c SS |
4657 | sizeof (struct symbol))); |
4658 | ||
12b9c64f | 4659 | memset (s, 0, sizeof (*s)); |
c906108c | 4660 | SYMBOL_LANGUAGE (s) = psymtab_language; |
2de7ced7 | 4661 | SYMBOL_SET_NAMES (s, name, strlen (name), current_objfile); |
c906108c SS |
4662 | return s; |
4663 | } | |
4664 | ||
4665 | /* Create a new type with printname NAME */ | |
4666 | ||
4667 | static struct type * | |
fba45db2 | 4668 | new_type (char *name) |
c906108c SS |
4669 | { |
4670 | struct type *t; | |
4671 | ||
4672 | t = alloc_type (current_objfile); | |
4673 | TYPE_NAME (t) = name; | |
4674 | TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default; | |
4675 | return t; | |
4676 | } | |
4677 | \f | |
4678 | /* Read ECOFF debugging information from a BFD section. This is | |
4679 | called from elfread.c. It parses the section into a | |
4680 | ecoff_debug_info struct, and then lets the rest of the file handle | |
4681 | it as normal. */ | |
4682 | ||
4683 | void | |
fba45db2 KB |
4684 | elfmdebug_build_psymtabs (struct objfile *objfile, |
4685 | const struct ecoff_debug_swap *swap, asection *sec) | |
c906108c SS |
4686 | { |
4687 | bfd *abfd = objfile->obfd; | |
4688 | struct ecoff_debug_info *info; | |
7134143f DJ |
4689 | struct cleanup *back_to; |
4690 | ||
4691 | /* FIXME: It's not clear whether we should be getting minimal symbol | |
4692 | information from .mdebug in an ELF file, or whether we will. | |
4693 | Re-initialize the minimal symbol reader in case we do. */ | |
4694 | ||
4695 | init_minimal_symbol_collection (); | |
4696 | back_to = make_cleanup_discard_minimal_symbols (); | |
c906108c SS |
4697 | |
4698 | info = ((struct ecoff_debug_info *) | |
8b92e4d5 | 4699 | obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
4700 | sizeof (struct ecoff_debug_info))); |
4701 | ||
4702 | if (!(*swap->read_debug_info) (abfd, sec, info)) | |
4703 | error ("Error reading ECOFF debugging information: %s", | |
4704 | bfd_errmsg (bfd_get_error ())); | |
4705 | ||
d4f3574e | 4706 | mdebug_build_psymtabs (objfile, swap, info); |
7134143f DJ |
4707 | |
4708 | install_minimal_symbols (objfile); | |
4709 | do_cleanups (back_to); | |
c906108c | 4710 | } |
c906108c SS |
4711 | |
4712 | void | |
fba45db2 | 4713 | _initialize_mdebugread (void) |
c906108c SS |
4714 | { |
4715 | mdebug_type_void = | |
4716 | init_type (TYPE_CODE_VOID, 1, | |
4717 | 0, | |
4718 | "void", (struct objfile *) NULL); | |
4719 | mdebug_type_char = | |
4720 | init_type (TYPE_CODE_INT, 1, | |
4721 | 0, | |
4722 | "char", (struct objfile *) NULL); | |
4723 | mdebug_type_unsigned_char = | |
4724 | init_type (TYPE_CODE_INT, 1, | |
4725 | TYPE_FLAG_UNSIGNED, | |
4726 | "unsigned char", (struct objfile *) NULL); | |
4727 | mdebug_type_short = | |
4728 | init_type (TYPE_CODE_INT, 2, | |
4729 | 0, | |
4730 | "short", (struct objfile *) NULL); | |
4731 | mdebug_type_unsigned_short = | |
4732 | init_type (TYPE_CODE_INT, 2, | |
4733 | TYPE_FLAG_UNSIGNED, | |
4734 | "unsigned short", (struct objfile *) NULL); | |
4735 | mdebug_type_int_32 = | |
4736 | init_type (TYPE_CODE_INT, 4, | |
4737 | 0, | |
4738 | "int", (struct objfile *) NULL); | |
4739 | mdebug_type_unsigned_int_32 = | |
4740 | init_type (TYPE_CODE_INT, 4, | |
4741 | TYPE_FLAG_UNSIGNED, | |
4742 | "unsigned int", (struct objfile *) NULL); | |
4743 | mdebug_type_int_64 = | |
4744 | init_type (TYPE_CODE_INT, 8, | |
4745 | 0, | |
4746 | "int", (struct objfile *) NULL); | |
4747 | mdebug_type_unsigned_int_64 = | |
4748 | init_type (TYPE_CODE_INT, 8, | |
4749 | TYPE_FLAG_UNSIGNED, | |
4750 | "unsigned int", (struct objfile *) NULL); | |
4751 | mdebug_type_long_32 = | |
4752 | init_type (TYPE_CODE_INT, 4, | |
4753 | 0, | |
4754 | "long", (struct objfile *) NULL); | |
4755 | mdebug_type_unsigned_long_32 = | |
4756 | init_type (TYPE_CODE_INT, 4, | |
4757 | TYPE_FLAG_UNSIGNED, | |
4758 | "unsigned long", (struct objfile *) NULL); | |
4759 | mdebug_type_long_64 = | |
4760 | init_type (TYPE_CODE_INT, 8, | |
4761 | 0, | |
4762 | "long", (struct objfile *) NULL); | |
4763 | mdebug_type_unsigned_long_64 = | |
4764 | init_type (TYPE_CODE_INT, 8, | |
4765 | TYPE_FLAG_UNSIGNED, | |
4766 | "unsigned long", (struct objfile *) NULL); | |
4767 | mdebug_type_long_long_64 = | |
4768 | init_type (TYPE_CODE_INT, 8, | |
4769 | 0, | |
4770 | "long long", (struct objfile *) NULL); | |
c5aa993b | 4771 | mdebug_type_unsigned_long_long_64 = |
c906108c SS |
4772 | init_type (TYPE_CODE_INT, 8, |
4773 | TYPE_FLAG_UNSIGNED, | |
4774 | "unsigned long long", (struct objfile *) NULL); | |
4775 | mdebug_type_adr_32 = | |
4776 | init_type (TYPE_CODE_PTR, 4, | |
4777 | TYPE_FLAG_UNSIGNED, | |
4778 | "adr_32", (struct objfile *) NULL); | |
4779 | TYPE_TARGET_TYPE (mdebug_type_adr_32) = mdebug_type_void; | |
4780 | mdebug_type_adr_64 = | |
4781 | init_type (TYPE_CODE_PTR, 8, | |
4782 | TYPE_FLAG_UNSIGNED, | |
4783 | "adr_64", (struct objfile *) NULL); | |
4784 | TYPE_TARGET_TYPE (mdebug_type_adr_64) = mdebug_type_void; | |
4785 | mdebug_type_float = | |
4786 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
4787 | 0, | |
4788 | "float", (struct objfile *) NULL); | |
4789 | mdebug_type_double = | |
4790 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
4791 | 0, | |
4792 | "double", (struct objfile *) NULL); | |
4793 | mdebug_type_complex = | |
4794 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, | |
4795 | 0, | |
4796 | "complex", (struct objfile *) NULL); | |
4797 | TYPE_TARGET_TYPE (mdebug_type_complex) = mdebug_type_float; | |
4798 | mdebug_type_double_complex = | |
4799 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
4800 | 0, | |
4801 | "double complex", (struct objfile *) NULL); | |
4802 | TYPE_TARGET_TYPE (mdebug_type_double_complex) = mdebug_type_double; | |
4803 | ||
4804 | /* Is a "string" the way btString means it the same as TYPE_CODE_STRING? | |
4805 | FIXME. */ | |
4806 | mdebug_type_string = | |
4807 | init_type (TYPE_CODE_STRING, | |
4808 | TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
4809 | 0, "string", | |
4810 | (struct objfile *) NULL); | |
4811 | ||
4812 | /* We use TYPE_CODE_INT to print these as integers. Does this do any | |
4813 | good? Would we be better off with TYPE_CODE_ERROR? Should | |
4814 | TYPE_CODE_ERROR print things in hex if it knows the size? */ | |
4815 | mdebug_type_fixed_dec = | |
4816 | init_type (TYPE_CODE_INT, | |
4817 | TARGET_INT_BIT / TARGET_CHAR_BIT, | |
4818 | 0, "fixed decimal", | |
4819 | (struct objfile *) NULL); | |
4820 | ||
4821 | mdebug_type_float_dec = | |
4822 | init_type (TYPE_CODE_ERROR, | |
4823 | TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, | |
4824 | 0, "floating decimal", | |
4825 | (struct objfile *) NULL); | |
4826 | ||
4827 | nodebug_func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0, | |
4828 | "<function, no debug info>", NULL); | |
4829 | TYPE_TARGET_TYPE (nodebug_func_symbol_type) = mdebug_type_int; | |
4830 | nodebug_var_symbol_type = | |
4831 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0, | |
4832 | "<variable, no debug info>", NULL); | |
4833 | } |