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