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