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