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