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