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