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