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