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