* config/i386/{i386m3.mh,i386mk.mh}, config/mips/mipsm3.mh,
[deliverable/binutils-gdb.git] / gdb / mipsread.c
CommitLineData
bd5635a1 1/* Read a symbol table in MIPS' format (Third-Eye).
6c2e7392
PS
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software
3 Foundation, Inc.
4 Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU. Major work
5 by Per Bothner, John Gilmore and Ian Lance Taylor at Cygnus Support.
bd5635a1
RP
6
7This file is part of GDB.
8
b8c50f09 9This program is free software; you can redistribute it and/or modify
bd5635a1 10it under the terms of the GNU General Public License as published by
b8c50f09
JG
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
bd5635a1 13
b8c50f09 14This program is distributed in the hope that it will be useful,
bd5635a1
RP
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
b8c50f09
JG
20along with this program; if not, write to the Free Software
21Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 22
3eaebb75 23/* This module provides three functions: mipscoff_symfile_init,
817bc7b8 24 which initializes to read a symbol file; mipscoff_new_init, which
3eaebb75
SG
25 discards existing cached information when all symbols are being
26 discarded; and mipscoff_symfile_read, which reads a symbol table
27 from a file.
28
29 mipscoff_symfile_read only does the minimum work necessary for letting the
30 user "name" things symbolically; it does not read the entire symtab.
31 Instead, it reads the external and static symbols and puts them in partial
32 symbol tables. When more extensive information is requested of a
33 file, the corresponding partial symbol table is mutated into a full
34 fledged symbol table by going back and reading the symbols
35 for real. mipscoff_psymtab_to_symtab() is called indirectly through
d747e0af
MT
36 a pointer in the psymtab to do this.
37
38 ECOFF symbol tables are mostly written in the byte order of the
39 target machine. However, one section of the table (the auxiliary
40 symbol information) is written in the host byte order. There is a
41 bit in the other symbol info which describes which host byte order
42 was used. ECOFF thereby takes the trophy from Intel `b.out' for
43 the most brain-dead adaptation of a file format to byte order.
44
45 This module can read all four of the known byte-order combinations,
6c2e7392 46 on any type of host. */
d747e0af 47
bd5635a1
RP
48#include "defs.h"
49#include "symtab.h"
d747e0af 50#include "gdbtypes.h"
bd5635a1
RP
51#include "gdbcore.h"
52#include "symfile.h"
5e2e79f8 53#include "objfiles.h"
7d9884b9 54#include "obstack.h"
7e258d18 55#include "buildsym.h"
dac4929a 56#include "stabsread.h"
51b80b00 57#include "complaints.h"
817bc7b8 58
ac8cf67d
PS
59/* These are needed if the tm.h file does not contain the necessary
60 mips specific definitions. */
61
62#ifndef MIPS_EFI_SYMBOL_NAME
63#define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
64#include "coff/sym.h"
65#include "coff/symconst.h"
66typedef struct mips_extra_func_info {
67 long numargs;
68 PDR pdr;
69} *mips_extra_func_info_t;
70#ifndef RA_REGNUM
71#define RA_REGNUM 0
72#endif
ac8cf67d
PS
73#endif
74
817bc7b8
JG
75#ifdef USG
76#include <sys/types.h>
817bc7b8
JG
77#endif
78
7d9884b9
JG
79#include <sys/param.h>
80#include <sys/file.h>
81#include <sys/stat.h>
85f0a848 82#include <string.h>
fa0bcaa3 83
dac4929a
SG
84#include "gdb-stabs.h"
85
6c2e7392
PS
86#include "bfd.h"
87
88#include "coff/internal.h"
6ac14d25 89#include "coff/ecoff.h" /* COFF-like aspects of ecoff files */
e10a3052 90
6c2e7392
PS
91/* FIXME: coff/internal.h and aout/aout64.h both define N_ABS. We
92 want the definition from aout/aout64.h. */
93#undef N_ABS
6c2e7392
PS
94
95#include "libaout.h" /* Private BFD a.out information. */
7e258d18 96#include "aout/aout64.h"
817bc7b8 97#include "aout/stab_gnu.h" /* STABS information */
6c2e7392
PS
98
99/* FIXME: libcoff.h and libaout.h both define a couple of macros. We
100 don't use them. */
101#undef exec_hdr
102#undef obj_sym_filepos
103
104#include "libcoff.h" /* Private BFD COFF information. */
105#include "libecoff.h" /* Private BFD ECOFF information. */
106
85f0a848
FF
107#include "expression.h"
108#include "language.h" /* Needed inside partial-stab.h */
bd5635a1 109
85999c05
PS
110/* Provide a default mapping from a ecoff register number to a gdb REGNUM. */
111#ifndef ECOFF_REG_TO_REGNUM
112#define ECOFF_REG_TO_REGNUM(num) (num)
113#endif
114
e7e02420
PS
115/* Information is passed among various mipsread routines for accessing
116 symbol files. A pointer to this structure is kept in the sym_private
117 field of the objfile struct. */
118
119struct ecoff_symfile_info {
120 struct mips_pending **pending_list;
121};
122#define ECOFF_SYMFILE_INFO(o) ((struct ecoff_symfile_info *)((o)->sym_private))
123#define ECOFF_PENDING_LIST(o) (ECOFF_SYMFILE_INFO(o)->pending_list)
124
125
6c2e7392
PS
126/* Each partial symbol table entry contains a pointer to private data
127 for the read_symtab() function to use when expanding a partial
128 symbol table entry to a full symbol table entry.
4a35d6e9 129
6c2e7392
PS
130 For mipsread this structure contains the index of the FDR that this
131 psymtab represents and a pointer to the BFD that the psymtab was
132 created from. */
4a35d6e9 133
d4ea2aba
PB
134#define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
135#define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
6c2e7392 136#define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
4a35d6e9 137
5f7b2142
ILT
138struct symloc
139{
4a35d6e9 140 int fdr_idx;
6c2e7392
PS
141 bfd *cur_bfd;
142 EXTR *extern_tab; /* Pointer to external symbols for this file. */
143 int extern_count; /* Size of extern_tab. */
cbba020f 144 enum language pst_language;
4a35d6e9
FF
145};
146
bd5635a1
RP
147/* Things we import explicitly from other modules */
148
5f7b2142 149extern int info_verbose;
bd5635a1 150
3eaebb75 151/* Various complaints about symbol reading that don't abort the process */
817bc7b8
JG
152
153struct complaint bad_file_number_complaint =
5f7b2142 154{"bad file number %d", 0, 0};
021959e2 155
817bc7b8 156struct complaint index_complaint =
5f7b2142 157{"bad aux index at symbol %s", 0, 0};
817bc7b8
JG
158
159struct complaint aux_index_complaint =
5f7b2142 160{"bad proc end in aux found from symbol %s", 0, 0};
817bc7b8 161
6edd74ae 162struct complaint block_index_complaint =
5f7b2142 163{"bad aux index at block symbol %s", 0, 0};
6edd74ae 164
817bc7b8 165struct complaint unknown_ext_complaint =
5f7b2142 166{"unknown external symbol %s", 0, 0};
bd5635a1 167
817bc7b8 168struct complaint unknown_sym_complaint =
5f7b2142 169{"unknown local symbol %s", 0, 0};
101f259c 170
817bc7b8 171struct complaint unknown_st_complaint =
5f7b2142 172{"with type %d", 0, 0};
101f259c 173
817bc7b8 174struct complaint block_overflow_complaint =
5f7b2142 175{"block containing %s overfilled", 0, 0};
3eaebb75 176
817bc7b8 177struct complaint basic_type_complaint =
cbba020f 178{"cannot map MIPS basic type 0x%x for %s", 0, 0};
3eaebb75 179
817bc7b8 180struct complaint unknown_type_qual_complaint =
5f7b2142 181{"unknown type qualifier 0x%x", 0, 0};
3eaebb75 182
99a15c64
PS
183struct complaint array_index_type_complaint =
184{"illegal array index type for %s, assuming int", 0, 0};
185
817bc7b8 186struct complaint array_bitsize_complaint =
99a15c64 187{"size of array target type for %s not known, assuming %d bits", 0, 0};
3eaebb75 188
817bc7b8 189struct complaint bad_tag_guess_complaint =
5f7b2142 190{"guessed tag type of %s incorrectly", 0, 0};
817bc7b8
JG
191
192struct complaint block_member_complaint =
5f7b2142 193{"declaration block contains unhandled symbol type %d", 0, 0};
817bc7b8
JG
194
195struct complaint stEnd_complaint =
5f7b2142 196{"stEnd with storage class %d not handled", 0, 0};
817bc7b8
JG
197
198struct complaint unknown_mips_symtype_complaint =
5f7b2142 199{"unknown symbol type 0x%x", 0, 0};
817bc7b8
JG
200
201struct complaint stab_unknown_complaint =
5f7b2142 202{"unknown stabs symbol %s", 0, 0};
817bc7b8
JG
203
204struct complaint pdr_for_nonsymbol_complaint =
5f7b2142 205{"PDR for %s, but no symbol", 0, 0};
817bc7b8
JG
206
207struct complaint pdr_static_symbol_complaint =
99a15c64 208{"can't handle PDR for static proc at 0x%lx", 0, 0};
c55e6167 209
e157305c
PS
210struct complaint bad_setjmp_pdr_complaint =
211{"fixing bad setjmp PDR from libc", 0, 0};
212
6ac14d25 213struct complaint bad_fbitfield_complaint =
cbba020f 214{"can't handle TIR fBitfield for %s", 0, 0};
6ac14d25 215
99a15c64
PS
216struct complaint bad_continued_complaint =
217{"illegal TIR continued for %s", 0, 0};
218
6ac14d25 219struct complaint bad_rfd_entry_complaint =
cbba020f 220{"bad rfd entry for %s: file %d, index %d", 0, 0};
6ac14d25
PS
221
222struct complaint unexpected_type_code_complaint =
223{"unexpected type code for %s", 0, 0};
224
85999c05
PS
225struct complaint unable_to_cross_ref_complaint =
226{"unable to cross ref btTypedef for %s", 0, 0};
227
228struct complaint illegal_forward_tq0_complaint =
229{"illegal tq0 in forward typedef for %s", 0, 0};
3eaebb75 230
85999c05
PS
231struct complaint illegal_forward_bt_complaint =
232{"illegal bt %d in forward typedef for %s", 0, 0};
bd5635a1 233
99a15c64
PS
234struct complaint bad_linetable_guess_complaint =
235{"guessed size of linetable for %s incorrectly", 0, 0};
236
85999c05 237/* Macros and extra defs */
bd5635a1
RP
238
239/* Puns: hard to find whether -g was used and how */
240
241#define MIN_GLEVEL GLEVEL_0
242#define compare_glevel(a,b) \
243 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
244 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
e072c738
JG
245\f
246/* Things that really are local to this module */
247
c4413e2c
FF
248/* Remember what we deduced to be the source language of this psymtab. */
249
250static enum language psymtab_language = language_unknown;
251
6c2e7392 252/* Current BFD. */
3eaebb75 253
6c2e7392 254static bfd *cur_bfd;
3eaebb75 255
e072c738
JG
256/* Pointer to current file decriptor record, and its index */
257
5f7b2142
ILT
258static FDR *cur_fdr;
259static int cur_fd;
e072c738
JG
260
261/* Index of current symbol */
262
5f7b2142 263static int cur_sdx;
e072c738
JG
264
265/* Note how much "debuggable" this image is. We would like
266 to see at least one FDR with full symbols */
267
268static max_gdbinfo;
269static max_glevel;
270
271/* When examining .o files, report on undefined symbols */
272
273static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
274
7e258d18
PB
275/* Pseudo symbol to use when putting stabs into the symbol table. */
276
c55e6167 277static char stabs_symbol[] = STABS_SYMBOL;
7e258d18 278
e072c738
JG
279/* Extra builtin types */
280
281struct type *builtin_type_complex;
282struct type *builtin_type_double_complex;
283struct type *builtin_type_fixed_dec;
284struct type *builtin_type_float_dec;
285struct type *builtin_type_string;
286
3eaebb75 287/* Forward declarations */
e072c738 288
d747e0af 289static void
dac4929a 290read_mips_symtab PARAMS ((struct objfile *, struct section_offsets *));
84ffdec2
JG
291
292static void
6c2e7392 293read_the_mips_symtab PARAMS ((bfd *));
84ffdec2
JG
294
295static int
99a15c64 296upgrade_type PARAMS ((int, struct type **, int, union aux_ext *, int, char *));
84ffdec2
JG
297
298static void
6c2e7392 299parse_partial_symbols PARAMS ((struct objfile *,
dac4929a 300 struct section_offsets *));
d747e0af
MT
301
302static int
85999c05
PS
303cross_ref PARAMS ((int, union aux_ext *, struct type **, enum type_code,
304 char **, int, char *));
84ffdec2
JG
305
306static void
307fixup_sigtramp PARAMS ((void));
308
309static struct symbol *
310new_symbol PARAMS ((char *));
311
312static struct type *
313new_type PARAMS ((char *));
314
315static struct block *
316new_block PARAMS ((int));
317
318static struct symtab *
319new_symtab PARAMS ((char *, int, int, struct objfile *));
320
321static struct linetable *
322new_linetable PARAMS ((int));
323
324static struct blockvector *
325new_bvect PARAMS ((int));
326
85999c05
PS
327static int
328parse_symbol PARAMS ((SYMR *, union aux_ext *, char *, int));
329
84ffdec2 330static struct type *
99a15c64 331parse_type PARAMS ((int, union aux_ext *, unsigned int, int *, int, char *));
84ffdec2
JG
332
333static struct symbol *
334mylookup_symbol PARAMS ((char *, struct block *, enum namespace,
335 enum address_class));
336
337static struct block *
338shrink_block PARAMS ((struct block *, struct symtab *));
339
340static PTR
341xzalloc PARAMS ((unsigned int));
d747e0af
MT
342
343static void
84ffdec2 344sort_blocks PARAMS ((struct symtab *));
d747e0af
MT
345
346static int
391ca579 347compare_blocks PARAMS ((const void *, const void *));
84ffdec2
JG
348
349static struct partial_symtab *
350new_psymtab PARAMS ((char *, struct objfile *));
351
d747e0af 352static void
84ffdec2 353psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));
c55e6167 354
84ffdec2
JG
355static void
356add_block PARAMS ((struct block *, struct symtab *));
357
358static void
359add_symbol PARAMS ((struct symbol *, struct block *));
360
361static int
362add_line PARAMS ((struct linetable *, int, CORE_ADDR, int));
363
364static struct linetable *
365shrink_linetable PARAMS ((struct linetable *));
366
367static char *
368mips_next_symbol_text PARAMS ((void));
bd5635a1
RP
369\f
370/* Things we export to other modules */
371
bd5635a1 372/* Address bounds for the signal trampoline in inferior, if any */
101f259c 373/* FIXME: Nothing really seems to use this. Why is it here? */
bd5635a1
RP
374
375CORE_ADDR sigtramp_address, sigtramp_end;
376
4ad1963e 377static void
84ffdec2
JG
378mipscoff_new_init (ignore)
379 struct objfile *ignore;
bd5635a1 380{
e7ff735c 381 sigtramp_address = 0;
0b0d6c3f
PS
382 stabsread_new_init ();
383 buildsym_new_init ();
bd5635a1
RP
384}
385
4ad1963e 386static void
80d68b1d
FF
387mipscoff_symfile_init (objfile)
388 struct objfile *objfile;
bd5635a1 389{
5f7b2142 390 if (objfile->sym_private != NULL)
80d68b1d 391 {
5f7b2142 392 mfree (objfile->md, objfile->sym_private);
80d68b1d 393 }
e7e02420
PS
394 objfile->sym_private = (PTR)
395 xmmalloc (objfile->md, sizeof (struct ecoff_symfile_info));
bd5635a1
RP
396}
397
4ad1963e 398static void
dac4929a 399mipscoff_symfile_read (objfile, section_offsets, mainline)
80d68b1d 400 struct objfile *objfile;
dac4929a 401 struct section_offsets *section_offsets;
bd5635a1
RP
402 int mainline;
403{
6ac14d25
PS
404 struct cleanup * back_to;
405
021959e2 406 init_minimal_symbol_collection ();
6ac14d25 407 back_to = make_cleanup (discard_minimal_symbols, 0);
bd5635a1
RP
408
409 /* Now that the executable file is positioned at symbol table,
410 process it and define symbols accordingly. */
411
5f7b2142 412 read_mips_symtab (objfile, section_offsets);
bd5635a1 413
021959e2
JG
414 /* Install any minimal symbols that have been collected as the current
415 minimal symbols for this objfile. */
bd5635a1 416
80d68b1d 417 install_minimal_symbols (objfile);
6ac14d25
PS
418
419 do_cleanups (back_to);
bd5635a1 420}
817bc7b8 421
80d68b1d
FF
422/* Perform any local cleanups required when we are done with a particular
423 objfile. I.E, we are in the process of discarding all symbol information
424 for an objfile, freeing up all memory held for it, and unlinking the
425 objfile struct from the global list of known objfiles. */
426
427static void
428mipscoff_symfile_finish (objfile)
429 struct objfile *objfile;
430{
5f7b2142 431 if (objfile->sym_private != NULL)
80d68b1d 432 {
5f7b2142 433 mfree (objfile->md, objfile->sym_private);
80d68b1d
FF
434 }
435
6c2e7392 436 cur_bfd = 0;
80d68b1d
FF
437}
438
d747e0af 439/* Allocate zeroed memory */
bd5635a1 440
84ffdec2 441static PTR
5f7b2142 442xzalloc (size)
e10a3052 443 unsigned int size;
bd5635a1 444{
51b57ded 445 PTR p = xmalloc (size);
bd5635a1 446
4ed3a9ea 447 memset (p, 0, size);
51b57ded 448 return p;
bd5635a1
RP
449}
450
451/* Exported procedure: Builds a symtab from the PST partial one.
452 Restores the environment in effect when PST was created, delegates
453 most of the work to an ancillary procedure, and sorts
454 and reorders the symtab list at the end */
455
3eaebb75 456static void
5f7b2142
ILT
457mipscoff_psymtab_to_symtab (pst)
458 struct partial_symtab *pst;
bd5635a1 459{
bd5635a1 460
5f7b2142
ILT
461 if (!pst)
462 return;
bd5635a1 463
5f7b2142
ILT
464 if (info_verbose)
465 {
466 printf_filtered ("Reading in symbols for %s...", pst->filename);
467 fflush (stdout);
468 }
bd5635a1 469
5f7b2142 470 next_symbol_text_func = mips_next_symbol_text;
c55e6167 471
5f7b2142 472 psymtab_to_symtab_1 (pst, pst->filename);
bd5635a1 473
5f7b2142
ILT
474 /* Match with global symbols. This only needs to be done once,
475 after all of the symtabs and dependencies have been read in. */
476 scan_file_globals (pst->objfile);
bd5635a1 477
5f7b2142
ILT
478 if (info_verbose)
479 printf_filtered ("done.\n");
bd5635a1
RP
480}
481
482/* Exported procedure: Is PC in the signal trampoline code */
483
b8c50f09 484int
5f7b2142
ILT
485in_sigtramp (pc, ignore)
486 CORE_ADDR pc;
487 char *ignore; /* function name */
bd5635a1 488{
5f7b2142
ILT
489 if (sigtramp_address == 0)
490 fixup_sigtramp ();
491 return (pc >= sigtramp_address && pc < sigtramp_end);
bd5635a1 492}
bd5635a1
RP
493\f
494/* File-level interface functions */
495
6c2e7392 496/* Read the symtab information from file ABFD into memory. */
d747e0af
MT
497
498static void
6c2e7392 499read_the_mips_symtab (abfd)
5f7b2142 500 bfd *abfd;
bd5635a1 501{
6c2e7392
PS
502 if (ecoff_slurp_symbolic_info (abfd) == false)
503 error ("Error reading symbol table: %s", bfd_errmsg (bfd_error));
bd5635a1
RP
504}
505
bd5635a1
RP
506/* Find a file descriptor given its index RF relative to a file CF */
507
3eaebb75
SG
508static FDR *
509get_rfd (cf, rf)
5f7b2142 510 int cf, rf;
bd5635a1 511{
6c2e7392 512 FDR *fdrs;
5f7b2142 513 register FDR *f;
6c2e7392 514 RFDT rfd;
5f7b2142 515
6c2e7392
PS
516 fdrs = ecoff_data (cur_bfd)->fdr;
517 f = fdrs + cf;
5f7b2142
ILT
518 /* Object files do not have the RFD table, all refs are absolute */
519 if (f->rfdBase == 0)
6c2e7392 520 return fdrs + rf;
6ac14d25
PS
521 (*ecoff_backend (cur_bfd)->swap_rfd_in)
522 (cur_bfd,
523 ((char *) ecoff_data (cur_bfd)->external_rfd
524 + (f->rfdBase + rf) * ecoff_backend (cur_bfd)->external_rfd_size),
525 &rfd);
6c2e7392 526 return fdrs + rfd;
bd5635a1
RP
527}
528
529/* Return a safer print NAME for a file descriptor */
530
3eaebb75 531static char *
6c2e7392
PS
532fdr_name (f)
533 FDR *f;
bd5635a1 534{
6c2e7392 535 if (f->rss == -1)
5f7b2142 536 return "<stripped file>";
6c2e7392 537 if (f->rss == 0)
5f7b2142 538 return "<NFY>";
6c2e7392 539 return ecoff_data (cur_bfd)->ss + f->issBase + f->rss;
bd5635a1
RP
540}
541
542
dac4929a
SG
543/* Read in and parse the symtab of the file OBJFILE. Symbols from
544 different sections are relocated via the SECTION_OFFSETS. */
bd5635a1 545
d747e0af 546static void
dac4929a 547read_mips_symtab (objfile, section_offsets)
5f7b2142
ILT
548 struct objfile *objfile;
549 struct section_offsets *section_offsets;
bd5635a1 550{
6c2e7392 551 cur_bfd = objfile->obfd;
bd5635a1 552
6c2e7392 553 read_the_mips_symtab (objfile->obfd);
bd5635a1 554
6c2e7392 555 parse_partial_symbols (objfile, section_offsets);
bd5635a1 556
7e258d18 557#if 0
6c2e7392
PS
558 /* Check to make sure file was compiled with -g. If not, warn the
559 user of this limitation. */
5f7b2142
ILT
560 if (compare_glevel (max_glevel, GLEVEL_2) < 0)
561 {
562 if (max_gdbinfo == 0)
6c2e7392 563 printf ("\n%s not compiled with -g, debugging support is limited.\n",
5f7b2142 564 objfile->name);
6c2e7392 565 printf ("You should compile with -g2 or -g3 for best debugging support.\n");
5f7b2142
ILT
566 fflush (stdout);
567 }
7e258d18 568#endif
bd5635a1 569}
bd5635a1
RP
570\f
571/* Local utilities */
572
bd5635a1
RP
573/* Map of FDR indexes to partial symtabs */
574
5f7b2142
ILT
575struct pst_map
576{
577 struct partial_symtab *pst; /* the psymtab proper */
85999c05
PS
578 long n_globals; /* exported globals (external symbols) */
579 long globals_offset; /* cumulative */
d4ea2aba 580};
bd5635a1
RP
581
582
583/* Utility stack, used to nest procedures and blocks properly.
584 It is a doubly linked list, to avoid too many alloc/free.
585 Since we might need it quite a few times it is NOT deallocated
586 after use. */
587
5f7b2142
ILT
588static struct parse_stack
589{
590 struct parse_stack *next, *prev;
591 struct symtab *cur_st; /* Current symtab. */
592 struct block *cur_block; /* Block in it. */
593 int blocktype; /* What are we parsing. */
594 int maxsyms; /* Max symbols in this block. */
595 struct type *cur_type; /* Type we parse fields for. */
596 int cur_field; /* Field number in cur_type. */
85999c05 597 CORE_ADDR procadr; /* Start addres of this procedure */
5f7b2142 598 int numargs; /* Its argument count */
6c2e7392
PS
599}
600
601 *top_stack; /* Top stack ptr */
bd5635a1
RP
602
603
604/* Enter a new lexical context */
605
4ad1963e 606static void
5f7b2142 607push_parse_stack ()
bd5635a1 608{
5f7b2142
ILT
609 struct parse_stack *new;
610
611 /* Reuse frames if possible */
612 if (top_stack && top_stack->prev)
613 new = top_stack->prev;
614 else
615 new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
616 /* Initialize new frame with previous content */
617 if (top_stack)
618 {
619 register struct parse_stack *prev = new->prev;
bd5635a1 620
5f7b2142
ILT
621 *new = *top_stack;
622 top_stack->prev = new;
623 new->prev = prev;
624 new->next = top_stack;
625 }
626 top_stack = new;
bd5635a1
RP
627}
628
629/* Exit a lexical context */
630
4ad1963e 631static void
5f7b2142 632pop_parse_stack ()
bd5635a1 633{
5f7b2142
ILT
634 if (!top_stack)
635 return;
636 if (top_stack->next)
637 top_stack = top_stack->next;
bd5635a1
RP
638}
639
640
641/* Cross-references might be to things we haven't looked at
642 yet, e.g. type references. To avoid too many type
643 duplications we keep a quick fixup table, an array
644 of lists of references indexed by file descriptor */
645
e7e02420 646struct mips_pending
5f7b2142
ILT
647{
648 struct mips_pending *next; /* link */
6ac14d25 649 char *s; /* the unswapped symbol */
5f7b2142 650 struct type *t; /* its partial type descriptor */
e7e02420 651};
bd5635a1
RP
652
653
85999c05 654/* Check whether we already saw symbol SH in file FH */
bd5635a1 655
4ad1963e 656static struct mips_pending *
5f7b2142
ILT
657is_pending_symbol (fh, sh)
658 FDR *fh;
6ac14d25 659 char *sh;
bd5635a1 660{
6c2e7392 661 int f_idx = fh - ecoff_data (cur_bfd)->fdr;
5f7b2142 662 register struct mips_pending *p;
e7e02420 663 struct mips_pending **pending_list = ECOFF_PENDING_LIST (current_objfile);
5f7b2142
ILT
664
665 /* Linear search is ok, list is typically no more than 10 deep */
666 for (p = pending_list[f_idx]; p; p = p->next)
667 if (p->s == sh)
668 break;
669 return p;
bd5635a1
RP
670}
671
85999c05 672/* Add a new symbol SH of type T */
bd5635a1 673
4ad1963e 674static void
5f7b2142
ILT
675add_pending (fh, sh, t)
676 FDR *fh;
6ac14d25 677 char *sh;
5f7b2142 678 struct type *t;
bd5635a1 679{
6c2e7392 680 int f_idx = fh - ecoff_data (cur_bfd)->fdr;
5f7b2142
ILT
681 struct mips_pending *p = is_pending_symbol (fh, sh);
682
683 /* Make sure we do not make duplicates */
684 if (!p)
685 {
e7e02420
PS
686 struct mips_pending **pending_list = ECOFF_PENDING_LIST (current_objfile);
687
688 p = ((struct mips_pending *)
689 obstack_alloc (&current_objfile->psymbol_obstack,
690 sizeof (struct mips_pending)));
5f7b2142
ILT
691 p->s = sh;
692 p->t = t;
693 p->next = pending_list[f_idx];
694 pending_list[f_idx] = p;
695 }
bd5635a1 696}
bd5635a1 697\f
5f7b2142 698
bd5635a1
RP
699/* Parsing Routines proper. */
700
701/* Parse a single symbol. Mostly just make up a GDB symbol for it.
702 For blocks, procedures and types we open a new lexical context.
6c2e7392
PS
703 This is basically just a big switch on the symbol's type. Argument
704 AX is the base pointer of aux symbols for this file (fh->iauxBase).
705 EXT_SH points to the unswapped symbol, which is needed for struct,
706 union, etc., types; it is NULL for an EXTR. BIGEND says whether
707 aux symbols are big-endian or little-endian. Return count of
85999c05 708 SYMR's handled (normally one). */
bd5635a1 709
7e258d18 710static int
6c2e7392 711parse_symbol (sh, ax, ext_sh, bigend)
5f7b2142
ILT
712 SYMR *sh;
713 union aux_ext *ax;
6ac14d25 714 char *ext_sh;
5f7b2142 715 int bigend;
bd5635a1 716{
6ac14d25
PS
717 const bfd_size_type external_sym_size
718 = ecoff_backend (cur_bfd)->external_sym_size;
719 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *)) =
720 ecoff_backend (cur_bfd)->swap_sym_in;
5f7b2142
ILT
721 char *name;
722 struct symbol *s;
723 struct block *b;
6c2e7392 724 struct mips_pending *pend;
5f7b2142
ILT
725 struct type *t;
726 struct field *f;
727 int count = 1;
5f7b2142
ILT
728 enum address_class class;
729 TIR tir;
85999c05 730 long svalue = sh->value;
99a15c64 731 int bitsize;
5f7b2142 732
6ac14d25 733 if (ext_sh == (char *) NULL)
6c2e7392
PS
734 name = ecoff_data (cur_bfd)->ssext + sh->iss;
735 else
736 name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh->iss;
737
5f7b2142
ILT
738 switch (sh->st)
739 {
5f7b2142
ILT
740 case stNil:
741 break;
742
743 case stGlobal: /* external symbol, goes into global block */
744 class = LOC_STATIC;
745 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
746 GLOBAL_BLOCK);
6c2e7392 747 s = new_symbol (name);
5f7b2142
ILT
748 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
749 goto data;
750
751 case stStatic: /* static data, goes into current block. */
752 class = LOC_STATIC;
753 b = top_stack->cur_block;
6c2e7392 754 s = new_symbol (name);
e7ff735c
JK
755 if (sh->sc == scCommon)
756 {
757 /* It is a FORTRAN common block. At least for SGI Fortran the
758 address is not in the symbol; we need to fix it later in
759 scan_file_globals. */
760 int bucket = hashname (SYMBOL_NAME (s));
761 SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
762 global_sym_chain[bucket] = s;
763 }
764 else
765 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
5f7b2142
ILT
766 goto data;
767
768 case stLocal: /* local variable, goes into current block */
769 if (sh->sc == scRegister)
770 {
771 class = LOC_REGISTER;
85999c05 772 svalue = ECOFF_REG_TO_REGNUM (svalue);
5f7b2142
ILT
773 }
774 else
775 class = LOC_LOCAL;
776 b = top_stack->cur_block;
6c2e7392 777 s = new_symbol (name);
85999c05 778 SYMBOL_VALUE (s) = svalue;
5f7b2142
ILT
779
780 data: /* Common code for symbols describing data */
781 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
782 SYMBOL_CLASS (s) = class;
783 add_symbol (s, b);
784
785 /* Type could be missing in a number of cases */
786 if (sh->sc == scUndefined || sh->sc == scNil ||
787 sh->index == 0xfffff)
788 SYMBOL_TYPE (s) = builtin_type_int; /* undefined? */
789 else
99a15c64 790 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
5f7b2142
ILT
791 /* Value of a data symbol is its memory address */
792 break;
793
794 case stParam: /* arg to procedure, goes into current block */
795 max_gdbinfo++;
796 top_stack->numargs++;
797
5f7b2142
ILT
798 /* Special GNU C++ name. */
799 if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
800 name = "this"; /* FIXME, not alloc'd in obstack */
801 s = new_symbol (name);
802
803 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
e7ff735c 804 switch (sh->sc)
5f7b2142 805 {
e7ff735c
JK
806 case scRegister:
807 /* Pass by value in register. */
808 SYMBOL_CLASS(s) = LOC_REGPARM;
85999c05 809 svalue = ECOFF_REG_TO_REGNUM (svalue);
e7ff735c
JK
810 break;
811 case scVar:
812 /* Pass by reference on stack. */
813 SYMBOL_CLASS(s) = LOC_REF_ARG;
814 break;
815 case scVarRegister:
816 /* Pass by reference in register. */
817 SYMBOL_CLASS(s) = LOC_REGPARM_ADDR;
85999c05 818 svalue = ECOFF_REG_TO_REGNUM (svalue);
e7ff735c
JK
819 break;
820 default:
821 /* Pass by value on stack. */
822 SYMBOL_CLASS(s) = LOC_ARG;
823 break;
5f7b2142 824 }
85999c05 825 SYMBOL_VALUE (s) = svalue;
99a15c64 826 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
5f7b2142 827 add_symbol (s, top_stack->cur_block);
0c4d2cc2 828#if 0
5f7b2142
ILT
829 /* FIXME: This has not been tested. See dbxread.c */
830 /* Add the type of this parameter to the function/procedure
0c4d2cc2 831 type of this block. */
5f7b2142 832 add_param_to_type (&top_stack->cur_block->function->type, s);
0c4d2cc2 833#endif
5f7b2142
ILT
834 break;
835
836 case stLabel: /* label, goes into current block */
6c2e7392 837 s = new_symbol (name);
5f7b2142
ILT
838 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; /* so that it can be used */
839 SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */
840 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
841 SYMBOL_TYPE (s) = builtin_type_int;
842 add_symbol (s, top_stack->cur_block);
843 break;
844
845 case stProc: /* Procedure, usually goes into global block */
6ac14d25 846 case stStaticProc: /* Static procedure, goes into current block */
6c2e7392 847 s = new_symbol (name);
5f7b2142
ILT
848 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
849 SYMBOL_CLASS (s) = LOC_BLOCK;
850 /* Type of the return value */
851 if (sh->sc == scUndefined || sh->sc == scNil)
852 t = builtin_type_int;
853 else
99a15c64 854 t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
5f7b2142
ILT
855 b = top_stack->cur_block;
856 if (sh->st == stProc)
857 {
858 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
859 /* The next test should normally be true,
0c4d2cc2
JG
860 but provides a hook for nested functions
861 (which we don't want to make global). */
5f7b2142
ILT
862 if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
863 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
864 }
865 add_symbol (s, b);
bd5635a1 866
5f7b2142 867 /* Make a type for the procedure itself */
0c4d2cc2 868#if 0
5f7b2142
ILT
869 /* FIXME: This has not been tested yet! See dbxread.c */
870 /* Generate a template for the type of this function. The
871 types of the arguments will be added as we read the symbol
872 table. */
ade40d31 873 memcpy (lookup_function_type (t), SYMBOL_TYPE (s), sizeof (struct type));
0c4d2cc2 874#else
5f7b2142 875 SYMBOL_TYPE (s) = lookup_function_type (t);
0c4d2cc2 876#endif
bd5635a1 877
5f7b2142
ILT
878 /* Create and enter a new lexical context */
879 b = new_block (top_stack->maxsyms);
880 SYMBOL_BLOCK_VALUE (s) = b;
881 BLOCK_FUNCTION (b) = s;
882 BLOCK_START (b) = BLOCK_END (b) = sh->value;
883 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
884 add_block (b, top_stack->cur_st);
885
886 /* Not if we only have partial info */
887 if (sh->sc == scUndefined || sh->sc == scNil)
888 break;
889
890 push_parse_stack ();
891 top_stack->cur_block = b;
892 top_stack->blocktype = sh->st;
893 top_stack->cur_type = SYMBOL_TYPE (s);
894 top_stack->cur_field = -1;
895 top_stack->procadr = sh->value;
896 top_stack->numargs = 0;
5f7b2142
ILT
897 break;
898
899 /* Beginning of code for structure, union, and enum definitions.
817bc7b8 900 They all share a common set of local variables, defined here. */
5f7b2142
ILT
901 {
902 enum type_code type_code;
6ac14d25 903 char *ext_tsym;
5f7b2142
ILT
904 int nfields;
905 long max_value;
906 struct field *f;
907
908 case stStruct: /* Start a block defining a struct type */
909 type_code = TYPE_CODE_STRUCT;
910 goto structured_common;
911
912 case stUnion: /* Start a block defining a union type */
913 type_code = TYPE_CODE_UNION;
914 goto structured_common;
915
916 case stEnum: /* Start a block defining an enum type */
917 type_code = TYPE_CODE_ENUM;
918 goto structured_common;
919
920 case stBlock: /* Either a lexical block, or some type */
e7ff735c 921 if (sh->sc != scInfo && sh->sc != scCommon)
5f7b2142
ILT
922 goto case_stBlock_code; /* Lexical block */
923
924 type_code = TYPE_CODE_UNDEF; /* We have a type. */
925
926 /* Common code for handling struct, union, enum, and/or as-yet-
927 unknown-type blocks of info about structured data. `type_code'
928 has been set to the proper TYPE_CODE, if we know it. */
929 structured_common:
930 push_parse_stack ();
931 top_stack->blocktype = stBlock;
932
5f7b2142
ILT
933 /* First count the number of fields and the highest value. */
934 nfields = 0;
935 max_value = 0;
6ac14d25
PS
936 for (ext_tsym = ext_sh + external_sym_size;
937 ;
938 ext_tsym += external_sym_size)
5f7b2142 939 {
6c2e7392
PS
940 SYMR tsym;
941
6ac14d25 942 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
6c2e7392 943
1c8961dd 944 switch (tsym.st)
5f7b2142 945 {
1c8961dd
JK
946 case stEnd:
947 goto end_of_fields;
948
949 case stMember:
5f7b2142
ILT
950 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
951 /* If the type of the member is Nil (or Void),
952 without qualifiers, assume the tag is an
953 enumeration. */
6c2e7392 954 if (tsym.index == indexNil)
5f7b2142
ILT
955 type_code = TYPE_CODE_ENUM;
956 else
957 {
958 ecoff_swap_tir_in (bigend,
6c2e7392 959 &ax[tsym.index].a_ti,
5f7b2142
ILT
960 &tir);
961 if ((tir.bt == btNil || tir.bt == btVoid)
962 && tir.tq0 == tqNil)
963 type_code = TYPE_CODE_ENUM;
817bc7b8 964 }
5f7b2142 965 nfields++;
6c2e7392
PS
966 if (tsym.value > max_value)
967 max_value = tsym.value;
1c8961dd
JK
968 break;
969
1c8961dd
JK
970 case stBlock:
971 case stUnion:
972 case stEnum:
973 case stStruct:
1c8961dd
JK
974 {
975#if 0
976 /* This is a no-op; is it trying to tell us something
977 we should be checking? */
978 if (tsym.sc == scVariant); /*UNIMPLEMENTED*/
979#endif
980 if (tsym.index != 0)
981 {
982 /* This is something like a struct within a
983 struct. Skip over the fields of the inner
984 struct. The -1 is because the for loop will
985 increment ext_tsym. */
6ac14d25
PS
986 ext_tsym = ((char *) ecoff_data (cur_bfd)->external_sym
987 + ((cur_fdr->isymBase + tsym.index - 1)
988 * external_sym_size));
1c8961dd
JK
989 }
990 }
991 break;
992
6ac14d25
PS
993 case stTypedef:
994 /* mips cc puts out a typedef for struct x if it is not yet
995 defined when it encounters
996 struct y { struct x *xp; };
997 Just ignore it. */
998 break;
999
1c8961dd
JK
1000 default:
1001 complain (&block_member_complaint, tsym.st);
5f7b2142 1002 }
5f7b2142 1003 }
1c8961dd 1004 end_of_fields:;
5f7b2142
ILT
1005
1006 /* In an stBlock, there is no way to distinguish structs,
1007 unions, and enums at this point. This is a bug in the
1008 original design (that has been fixed with the recent
1009 addition of the stStruct, stUnion, and stEnum symbol
1010 types.) The way you can tell is if/when you see a variable
1011 or field of that type. In that case the variable's type
1012 (in the AUX table) says if the type is struct, union, or
1013 enum, and points back to the stBlock here. So you can
1014 patch the tag kind up later - but only if there actually is
1015 a variable or field of that type.
1016
1017 So until we know for sure, we will guess at this point.
1018 The heuristic is:
1019 If the first member has index==indexNil or a void type,
1020 assume we have an enumeration.
1021 Otherwise, if there is more than one member, and all
1022 the members have offset 0, assume we have a union.
1023 Otherwise, assume we have a struct.
1024
1025 The heuristic could guess wrong in the case of of an
1026 enumeration with no members or a union with one (or zero)
1027 members, or when all except the last field of a struct have
1028 width zero. These are uncommon and/or illegal situations,
1029 and in any case guessing wrong probably doesn't matter
1030 much.
1031
1032 But if we later do find out we were wrong, we fixup the tag
1033 kind. Members of an enumeration must be handled
1034 differently from struct/union fields, and that is harder to
1035 patch up, but luckily we shouldn't need to. (If there are
1036 any enumeration members, we can tell for sure it's an enum
1037 here.) */
1038
1039 if (type_code == TYPE_CODE_UNDEF)
1040 if (nfields > 1 && max_value == 0)
1041 type_code = TYPE_CODE_UNION;
1042 else
1043 type_code = TYPE_CODE_STRUCT;
1044
85999c05 1045 /* Create a new type or use the pending type. */
6c2e7392 1046 pend = is_pending_symbol (cur_fdr, ext_sh);
85999c05
PS
1047 if (pend == (struct mips_pending *) NULL)
1048 {
1049 t = new_type (NULL);
1050 add_pending (cur_fdr, ext_sh, t);
1051 }
1052 else
6c2e7392 1053 t = pend->t;
85999c05
PS
1054
1055 /* Alpha cc unnamed structs do not get a tag name. */
1056 if (sh->iss == 0)
1057 TYPE_TAG_NAME (t) = NULL;
5f7b2142 1058 else
85999c05
PS
1059 TYPE_TAG_NAME (t) = obconcat (&current_objfile->symbol_obstack,
1060 "", "", name);
5f7b2142
ILT
1061
1062 TYPE_CODE (t) = type_code;
1063 TYPE_LENGTH (t) = sh->value;
1064 TYPE_NFIELDS (t) = nfields;
6c2e7392
PS
1065 TYPE_FIELDS (t) = f = ((struct field *)
1066 TYPE_ALLOC (t,
1067 nfields * sizeof (struct field)));
5f7b2142
ILT
1068
1069 if (type_code == TYPE_CODE_ENUM)
1070 {
1071 /* This is a non-empty enum. */
6ac14d25
PS
1072 for (ext_tsym = ext_sh + external_sym_size;
1073 ;
1074 ext_tsym += external_sym_size)
5f7b2142 1075 {
6c2e7392 1076 SYMR tsym;
5f7b2142 1077 struct symbol *enum_sym;
6c2e7392 1078
6ac14d25 1079 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
6c2e7392
PS
1080
1081 if (tsym.st != stMember)
1082 break;
1083
1084 f->bitpos = tsym.value;
5f7b2142 1085 f->type = t;
6c2e7392
PS
1086 f->name = (ecoff_data (cur_bfd)->ss
1087 + cur_fdr->issBase
1088 + tsym.iss);
5f7b2142
ILT
1089 f->bitsize = 0;
1090
1091 enum_sym = ((struct symbol *)
817bc7b8 1092 obstack_alloc (&current_objfile->symbol_obstack,
5f7b2142
ILT
1093 sizeof (struct symbol)));
1094 memset ((PTR) enum_sym, 0, sizeof (struct symbol));
1095 SYMBOL_NAME (enum_sym) = f->name;
1096 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1097 SYMBOL_TYPE (enum_sym) = t;
1098 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
6c2e7392 1099 SYMBOL_VALUE (enum_sym) = tsym.value;
5f7b2142
ILT
1100 add_symbol (enum_sym, top_stack->cur_block);
1101
1102 /* Skip the stMembers that we've handled. */
1103 count++;
1104 f++;
1105 }
1106 }
5f7b2142
ILT
1107 /* make this the current type */
1108 top_stack->cur_type = t;
1109 top_stack->cur_field = 0;
85999c05
PS
1110
1111 /* Do not create a symbol for alpha cc unnamed structs. */
1112 if (sh->iss == 0)
1113 break;
1114 s = new_symbol (name);
1115 SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE;
1116 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1117 SYMBOL_VALUE (s) = 0;
1118 SYMBOL_TYPE (s) = t;
1119
1120 /* gcc puts out an empty struct for an opaque struct definitions. */
1121 if (TYPE_NFIELDS (t) == 0)
1122 {
1123 TYPE_FLAGS (t) |= TYPE_FLAG_STUB;
1124 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1125 }
1126 add_symbol (s, top_stack->cur_block);
5f7b2142
ILT
1127 break;
1128
1129 /* End of local variables shared by struct, union, enum, and
1130 block (as yet unknown struct/union/enum) processing. */
1131 }
817bc7b8 1132
5f7b2142
ILT
1133 case_stBlock_code:
1134 /* beginnning of (code) block. Value of symbol
1135 is the displacement from procedure start */
1136 push_parse_stack ();
1137 top_stack->blocktype = stBlock;
1138 b = new_block (top_stack->maxsyms);
1139 BLOCK_START (b) = sh->value + top_stack->procadr;
1140 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1141 top_stack->cur_block = b;
1142 add_block (b, top_stack->cur_st);
1143 break;
1144
1145 case stEnd: /* end (of anything) */
e7ff735c 1146 if (sh->sc == scInfo || sh->sc == scCommon)
5f7b2142
ILT
1147 {
1148 /* Finished with type */
1149 top_stack->cur_type = 0;
1150 }
6c2e7392
PS
1151 else if (sh->sc == scText &&
1152 (top_stack->blocktype == stProc ||
1153 top_stack->blocktype == stStaticProc))
5f7b2142
ILT
1154 {
1155 /* Finished with procedure */
1156 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
1157 struct mips_extra_func_info *e;
1158 struct block *b;
1159 int i;
1160
1161 BLOCK_END (top_stack->cur_block) += sh->value; /* size */
1162
1163 /* Make up special symbol to contain procedure specific info */
1164 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
1165 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
1166 SYMBOL_CLASS (s) = LOC_CONST;
1167 SYMBOL_TYPE (s) = builtin_type_void;
1168 e = ((struct mips_extra_func_info *)
1169 obstack_alloc (&current_objfile->symbol_obstack,
1170 sizeof (struct mips_extra_func_info)));
85999c05 1171 SYMBOL_VALUE (s) = (long) e;
5f7b2142
ILT
1172 e->numargs = top_stack->numargs;
1173 add_symbol (s, top_stack->cur_block);
1174
1175 /* Reallocate symbols, saving memory */
1176 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
1177
1178 /* f77 emits proc-level with address bounds==[0,0],
6c2e7392 1179 So look for such child blocks, and patch them. */
5f7b2142
ILT
1180 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
1181 {
1182 struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1183 if (BLOCK_SUPERBLOCK (b_bad) == b
1184 && BLOCK_START (b_bad) == top_stack->procadr
1185 && BLOCK_END (b_bad) == top_stack->procadr)
1186 {
1187 BLOCK_START (b_bad) = BLOCK_START (b);
1188 BLOCK_END (b_bad) = BLOCK_END (b);
1189 }
1190 }
1191 }
1192 else if (sh->sc == scText && top_stack->blocktype == stBlock)
1193 {
6c2e7392
PS
1194 /* End of (code) block. The value of the symbol is the
1195 displacement from the procedure`s start address of the
1196 end of this block. */
5f7b2142
ILT
1197 BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
1198 shrink_block (top_stack->cur_block, top_stack->cur_st);
1199 }
1200 else if (sh->sc == scText && top_stack->blocktype == stFile)
1201 {
1202 /* End of file. Pop parse stack and ignore. Higher
6c2e7392 1203 level code deals with this. */
5f7b2142 1204 ;
bd5635a1 1205 }
5f7b2142
ILT
1206 else
1207 complain (&stEnd_complaint, sh->sc);
1208
1209 pop_parse_stack (); /* restore previous lexical context */
1210 break;
1211
1212 case stMember: /* member of struct or union */
1213 f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
6c2e7392 1214 f->name = name;
5f7b2142 1215 f->bitpos = sh->value;
99a15c64
PS
1216 bitsize = 0;
1217 f->type = parse_type (cur_fd, ax, sh->index, &bitsize, bigend, name);
1218 f->bitsize = bitsize;
5f7b2142
ILT
1219 break;
1220
1221 case stTypedef: /* type definition */
85999c05
PS
1222 /* Typedefs for forward declarations and opaque structs from alpha cc
1223 are handled by cross_ref, skip them. */
1224 if (sh->iss == 0)
1225 break;
1226
1227 /* Parse the type or use the pending type. */
1228 pend = is_pending_symbol (cur_fdr, ext_sh);
1229 if (pend == (struct mips_pending *) NULL)
1230 {
99a15c64 1231 t = parse_type (cur_fd, ax, sh->index, (int *)NULL, bigend, name);
85999c05
PS
1232 add_pending (cur_fdr, ext_sh, t);
1233 }
1234 else
1235 t = pend->t;
1236
1237 /* mips cc puts out a typedef with the name of the struct for forward
1238 declarations. These should not go into the symbol table and
1239 TYPE_NAME should not be set for them.
1240 They can't be distinguished from an intentional typedef to
1241 the same name however:
1242 x.h:
1243 struct x { int ix; int jx; };
1244 struct xx;
1245 x.c:
1246 typedef struct x x;
1247 struct xx {int ixx; int jxx; };
1248 generates a cross referencing stTypedef for x and xx.
1249 The user visible effect of this is that the type of a pointer
1250 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1251 The problem is fixed with alpha cc. */
1252
6c2e7392 1253 s = new_symbol (name);
5f7b2142
ILT
1254 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1255 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1256 SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
85999c05 1257 SYMBOL_TYPE (s) = t;
5f7b2142 1258 add_symbol (s, top_stack->cur_block);
85999c05 1259
6ac14d25
PS
1260 /* Incomplete definitions of structs should not get a name. */
1261 if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL
1262 && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
1263 || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT
1264 && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION)))
1265 {
1266 if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR
1267 || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC)
1268 {
1269 /* If we are giving a name to a type such as "pointer to
1270 foo" or "function returning foo", we better not set
1271 the TYPE_NAME. If the program contains "typedef char
1272 *caddr_t;", we don't want all variables of type char
1273 * to print as caddr_t. This is not just a
1274 consequence of GDB's type management; CC and GCC (at
1275 least through version 2.4) both output variables of
1276 either type char * or caddr_t with the type
1277 refering to the stTypedef symbol for caddr_t. If a future
1278 compiler cleans this up it GDB is not ready for it
1279 yet, but if it becomes ready we somehow need to
1280 disable this check (without breaking the PCC/GCC2.4
1281 case).
1282
1283 Sigh.
1284
1285 Fortunately, this check seems not to be necessary
1286 for anything except pointers or functions. */
1287 }
1288 else
1289 TYPE_NAME (SYMBOL_TYPE (s)) = SYMBOL_NAME (s);
1290 }
5f7b2142
ILT
1291 break;
1292
1293 case stFile: /* file name */
1294 push_parse_stack ();
1295 top_stack->blocktype = sh->st;
1296 break;
1297
1298 /* I`ve never seen these for C */
1299 case stRegReloc:
1300 break; /* register relocation */
1301 case stForward:
1302 break; /* forwarding address */
1303 case stConstant:
1304 break; /* constant */
1305 default:
1306 complain (&unknown_mips_symtype_complaint, sh->st);
1307 break;
1308 }
6c2e7392 1309
5f7b2142 1310 return count;
bd5635a1
RP
1311}
1312
d747e0af
MT
1313/* Parse the type information provided in the raw AX entries for
1314 the symbol SH. Return the bitfield size in BS, in case.
1315 We must byte-swap the AX entries before we use them; BIGEND says whether
1316 they are big-endian or little-endian (from fh->fBigendian). */
bd5635a1 1317
84ffdec2 1318static struct type *
99a15c64 1319parse_type (fd, ax, aux_index, bs, bigend, sym_name)
85999c05 1320 int fd;
5f7b2142 1321 union aux_ext *ax;
99a15c64 1322 unsigned int aux_index;
5f7b2142
ILT
1323 int *bs;
1324 int bigend;
cbba020f 1325 char *sym_name;
bd5635a1 1326{
5f7b2142
ILT
1327 /* Null entries in this map are treated specially */
1328 static struct type **map_bt[] =
1329 {
1330 &builtin_type_void, /* btNil */
1331 0, /* btAdr */
1332 &builtin_type_char, /* btChar */
1333 &builtin_type_unsigned_char,/* btUChar */
1334 &builtin_type_short, /* btShort */
1335 &builtin_type_unsigned_short, /* btUShort */
1336 &builtin_type_int, /* btInt */
1337 &builtin_type_unsigned_int, /* btUInt */
1338 &builtin_type_long, /* btLong */
1339 &builtin_type_unsigned_long,/* btULong */
1340 &builtin_type_float, /* btFloat */
1341 &builtin_type_double, /* btDouble */
1342 0, /* btStruct */
1343 0, /* btUnion */
1344 0, /* btEnum */
1345 0, /* btTypedef */
1346 0, /* btRange */
1347 0, /* btSet */
1348 &builtin_type_complex, /* btComplex */
1349 &builtin_type_double_complex, /* btDComplex */
1350 0, /* btIndirect */
1351 &builtin_type_fixed_dec, /* btFixedDec */
1352 &builtin_type_float_dec, /* btFloatDec */
1353 &builtin_type_string, /* btString */
1354 0, /* btBit */
1355 0, /* btPicture */
1356 &builtin_type_void, /* btVoid */
85999c05
PS
1357 0, /* DEC C++: Pointer to member */
1358 0, /* DEC C++: Virtual function table */
1359 0, /* DEC C++: Class (Record) */
1360 &builtin_type_long, /* btLong64 */
1361 &builtin_type_unsigned_long, /* btULong64 */
1362 &builtin_type_long_long, /* btLongLong64 */
1363 &builtin_type_unsigned_long_long, /* btULongLong64 */
1364 &builtin_type_unsigned_long, /* btAdr64 */
1365 &builtin_type_long, /* btInt64 */
1366 &builtin_type_unsigned_long, /* btUInt64 */
5f7b2142
ILT
1367 };
1368
1369 TIR t[1];
1370 struct type *tp = 0;
6c2e7392 1371 enum type_code type_code = TYPE_CODE_UNDEF;
5f7b2142 1372
99a15c64
PS
1373 /* Handle corrupt aux indices. */
1374 if (aux_index >= (ecoff_data (cur_bfd)->fdr + fd)->caux)
1375 {
1376 complain (&index_complaint, sym_name);
1377 return builtin_type_int;
1378 }
1379 ax += aux_index;
1380
5f7b2142 1381 /* Use aux as a type information record, map its basic type. */
99a15c64 1382 ecoff_swap_tir_in (bigend, &ax->a_ti, t);
cbba020f 1383 if (t->bt >= (sizeof (map_bt) / sizeof (*map_bt)))
5f7b2142 1384 {
cbba020f 1385 complain (&basic_type_complaint, t->bt, sym_name);
5f7b2142
ILT
1386 return builtin_type_int;
1387 }
1388 if (map_bt[t->bt])
1389 {
1390 tp = *map_bt[t->bt];
5f7b2142
ILT
1391 }
1392 else
1393 {
1394 tp = NULL;
1395 /* Cannot use builtin types -- build our own */
1396 switch (t->bt)
bd5635a1 1397 {
5f7b2142
ILT
1398 case btAdr:
1399 tp = lookup_pointer_type (builtin_type_void);
5f7b2142
ILT
1400 break;
1401 case btStruct:
1402 type_code = TYPE_CODE_STRUCT;
5f7b2142
ILT
1403 break;
1404 case btUnion:
1405 type_code = TYPE_CODE_UNION;
5f7b2142
ILT
1406 break;
1407 case btEnum:
1408 type_code = TYPE_CODE_ENUM;
5f7b2142
ILT
1409 break;
1410 case btRange:
1411 type_code = TYPE_CODE_RANGE;
5f7b2142
ILT
1412 break;
1413 case btSet:
1414 type_code = TYPE_CODE_SET;
5f7b2142
ILT
1415 break;
1416 case btTypedef:
85999c05
PS
1417 /* alpha cc uses this for typedefs. The true type will be
1418 obtained by crossreferencing below. */
1419 type_code = TYPE_CODE_ERROR;
1420 break;
5f7b2142 1421 default:
cbba020f 1422 complain (&basic_type_complaint, t->bt, sym_name);
5f7b2142 1423 return builtin_type_int;
bd5635a1 1424 }
5f7b2142 1425 }
bd5635a1 1426
5f7b2142
ILT
1427 /* Move on to next aux */
1428 ax++;
d747e0af 1429
5f7b2142
ILT
1430 if (t->fBitfield)
1431 {
6ac14d25
PS
1432 /* Inhibit core dumps with some cfront generated objects that
1433 corrupt the TIR. */
1434 if (bs == (int *)NULL)
1435 {
cbba020f 1436 complain (&bad_fbitfield_complaint, sym_name);
6ac14d25
PS
1437 return builtin_type_int;
1438 }
5f7b2142
ILT
1439 *bs = AUX_GET_WIDTH (bigend, ax);
1440 ax++;
1441 }
bd5635a1 1442
5f7b2142
ILT
1443 /* All these types really point to some (common) MIPS type
1444 definition, and only the type-qualifiers fully identify
1445 them. We'll make the same effort at sharing. */
e7ff735c 1446 if (t->bt == btStruct ||
5f7b2142
ILT
1447 t->bt == btUnion ||
1448 t->bt == btEnum ||
e7ff735c
JK
1449
1450 /* btSet (I think) implies that the name is a tag name, not a typedef
1451 name. This apparently is a MIPS extension for C sets. */
5f7b2142
ILT
1452 t->bt == btSet)
1453 {
e7ff735c
JK
1454 char *name;
1455
85999c05
PS
1456 /* Try to cross reference this type, build new type on failure. */
1457 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
e7ff735c 1458 if (tp == (struct type *) NULL)
85999c05 1459 tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
e7ff735c 1460
6ac14d25
PS
1461 /* Make sure that TYPE_CODE(tp) has an expected type code.
1462 Any type may be returned from cross_ref if file indirect entries
1463 are corrupted. */
1464 if (TYPE_CODE (tp) != TYPE_CODE_STRUCT
1465 && TYPE_CODE (tp) != TYPE_CODE_UNION
1466 && TYPE_CODE (tp) != TYPE_CODE_ENUM)
e7ff735c 1467 {
cbba020f 1468 complain (&unexpected_type_code_complaint, sym_name);
6ac14d25
PS
1469 }
1470 else
1471 {
1472
1473 /* Usually, TYPE_CODE(tp) is already type_code. The main
1fdbc4d1
JK
1474 exception is if we guessed wrong re struct/union/enum.
1475 But for struct vs. union a wrong guess is harmless, so
1476 don't complain(). */
1477 if ((TYPE_CODE (tp) == TYPE_CODE_ENUM
1478 && type_code != TYPE_CODE_ENUM)
1479 || (TYPE_CODE (tp) != TYPE_CODE_ENUM
1480 && type_code == TYPE_CODE_ENUM))
6ac14d25 1481 {
cbba020f 1482 complain (&bad_tag_guess_complaint, sym_name);
1fdbc4d1
JK
1483 }
1484
1485 if (TYPE_CODE (tp) != type_code)
1486 {
6ac14d25
PS
1487 TYPE_CODE (tp) = type_code;
1488 }
1fdbc4d1 1489
6ac14d25
PS
1490 /* Do not set the tag name if it is a compiler generated tag name
1491 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1492 if (name[0] == '.' || name[0] == '\0')
1493 TYPE_TAG_NAME (tp) = NULL;
1494 else if (TYPE_TAG_NAME (tp) == NULL
1495 || !STREQ (TYPE_TAG_NAME (tp), name))
1496 TYPE_TAG_NAME (tp) = obsavestring (name, strlen (name),
1497 &current_objfile->type_obstack);
e7ff735c 1498 }
e7ff735c
JK
1499 }
1500
1501 /* All these types really point to some (common) MIPS type
1502 definition, and only the type-qualifiers fully identify
6ac14d25
PS
1503 them. We'll make the same effort at sharing.
1504 FIXME: btIndirect cannot happen here as it is handled by the
1505 switch t->bt above. And we are not doing any guessing on range types. */
e7ff735c
JK
1506 if (t->bt == btIndirect ||
1507 t->bt == btRange)
1508 {
1509 char *name;
5f7b2142 1510
85999c05
PS
1511 /* Try to cross reference this type, build new type on failure. */
1512 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
6c2e7392 1513 if (tp == (struct type *) NULL)
85999c05 1514 tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
5f7b2142 1515
6ac14d25
PS
1516 /* Make sure that TYPE_CODE(tp) has an expected type code.
1517 Any type may be returned from cross_ref if file indirect entries
1518 are corrupted. */
1519 if (TYPE_CODE (tp) != TYPE_CODE_RANGE)
1520 {
cbba020f 1521 complain (&unexpected_type_code_complaint, sym_name);
6ac14d25
PS
1522 }
1523 else
5f7b2142 1524 {
6ac14d25
PS
1525 /* Usually, TYPE_CODE(tp) is already type_code. The main
1526 exception is if we guessed wrong re struct/union/enum. */
1527 if (TYPE_CODE (tp) != type_code)
1528 {
cbba020f 1529 complain (&bad_tag_guess_complaint, sym_name);
6ac14d25
PS
1530 TYPE_CODE (tp) = type_code;
1531 }
1532 if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name))
1533 TYPE_NAME (tp) = obsavestring (name, strlen (name),
1534 &current_objfile->type_obstack);
bd5635a1 1535 }
5f7b2142 1536 }
85999c05
PS
1537 if (t->bt == btTypedef)
1538 {
1539 char *name;
1540
1541 /* Try to cross reference this type, it should succeed. */
1542 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1543 if (tp == (struct type *) NULL)
1544 {
1545 complain (&unable_to_cross_ref_complaint, sym_name);
1546 tp = builtin_type_int;
1547 }
1548 }
bd5635a1 1549
5f7b2142
ILT
1550 /* Deal with range types */
1551 if (t->bt == btRange)
1552 {
1553 TYPE_NFIELDS (tp) = 2;
1554 TYPE_FIELDS (tp) = ((struct field *)
1555 TYPE_ALLOC (tp, 2 * sizeof (struct field)));
1556 TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1557 &current_objfile->type_obstack);
1558 TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1559 ax++;
1560 TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1561 &current_objfile->type_obstack);
1562 TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1563 ax++;
1564 }
bd5635a1 1565
5f7b2142 1566 /* Parse all the type qualifiers now. If there are more
6c2e7392 1567 than 6 the game will continue in the next aux */
bd5635a1 1568
99a15c64
PS
1569 while (1)
1570 {
bd5635a1 1571#define PARSE_TQ(tq) \
99a15c64
PS
1572 if (t->tq != tqNil) \
1573 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1574 else \
1575 break;
1576
1577 PARSE_TQ (tq0);
1578 PARSE_TQ (tq1);
1579 PARSE_TQ (tq2);
1580 PARSE_TQ (tq3);
1581 PARSE_TQ (tq4);
1582 PARSE_TQ (tq5);
bd5635a1
RP
1583#undef PARSE_TQ
1584
99a15c64
PS
1585 /* mips cc 2.x and gcc never put out continued aux entries. */
1586 if (!t->continued)
1587 break;
1588
1589 ecoff_swap_tir_in (bigend, &ax->a_ti, t);
1590 ax++;
5f7b2142 1591 }
99a15c64
PS
1592
1593 /* Complain for illegal continuations due to corrupt aux entries. */
1594 if (t->continued)
1595 complain (&bad_continued_complaint, sym_name);
1596
5f7b2142 1597 return tp;
bd5635a1
RP
1598}
1599
1600/* Make up a complex type from a basic one. Type is passed by
1601 reference in TPP and side-effected as necessary. The type
1602 qualifier TQ says how to handle the aux symbols at AX for
d747e0af
MT
1603 the symbol SX we are currently analyzing. BIGEND says whether
1604 aux symbols are big-endian or little-endian.
bd5635a1
RP
1605 Returns the number of aux symbols we parsed. */
1606
3eaebb75 1607static int
99a15c64 1608upgrade_type (fd, tpp, tq, ax, bigend, sym_name)
85999c05 1609 int fd;
5f7b2142
ILT
1610 struct type **tpp;
1611 int tq;
1612 union aux_ext *ax;
1613 int bigend;
99a15c64 1614 char *sym_name;
bd5635a1 1615{
5f7b2142
ILT
1616 int off;
1617 struct type *t;
1618
1619 /* Used in array processing */
1620 int rf, id;
1621 FDR *fh;
1622 struct type *range;
1623 struct type *indx;
1624 int lower, upper;
1625 RNDXR rndx;
1626
1627 switch (tq)
1628 {
1629 case tqPtr:
1630 t = lookup_pointer_type (*tpp);
1631 *tpp = t;
1632 return 0;
1633
1634 case tqProc:
1635 t = lookup_function_type (*tpp);
1636 *tpp = t;
1637 return 0;
1638
1639 case tqArray:
1640 off = 0;
1641
1642 /* Determine and record the domain type (type of index) */
6c2e7392 1643 ecoff_swap_rndx_in (bigend, &ax->a_rndx, &rndx);
5f7b2142
ILT
1644 id = rndx.index;
1645 rf = rndx.rfd;
1646 if (rf == 0xfff)
1647 {
1648 ax++;
1649 rf = AUX_GET_ISYM (bigend, ax);
1650 off++;
1651 }
85999c05 1652 fh = get_rfd (fd, rf);
5f7b2142 1653
85999c05 1654 indx = parse_type (fd,
99a15c64
PS
1655 ecoff_data (cur_bfd)->external_aux + fh->iauxBase,
1656 id, (int *) NULL, bigend, sym_name);
1657
1658 /* The bounds type should be an integer type, but might be anything
1659 else due to corrupt aux entries. */
1660 if (TYPE_CODE (indx) != TYPE_CODE_INT)
1661 {
1662 complain (&array_index_type_complaint, sym_name);
1663 indx = builtin_type_int;
1664 }
5f7b2142
ILT
1665
1666 /* Get the bounds, and create the array type. */
1667 ax++;
1668 lower = AUX_GET_DNLOW (bigend, ax);
1669 ax++;
1670 upper = AUX_GET_DNHIGH (bigend, ax);
1671 ax++;
1672 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1673
1674 range = create_range_type ((struct type *) NULL, indx,
1675 lower, upper);
1676
1677 t = create_array_type ((struct type *) NULL, *tpp, range);
1678
1679 /* Check whether supplied array element bit size matches
1680 the known size of the element type. If this complaint
1681 ends up not happening, we can remove this code. It's
1682 here because we aren't sure we understand this *&%&$
1683 symbol format. */
1684 id = TYPE_LENGTH (TYPE_TARGET_TYPE (t)) << 3; /* bitsize */
1685 if (id == 0)
1686 {
1687 /* Most likely an undefined type */
1688 id = rf;
1689 TYPE_LENGTH (TYPE_TARGET_TYPE (t)) = id >> 3;
1690 }
1691 if (id != rf)
99a15c64 1692 complain (&array_bitsize_complaint, sym_name, rf);
3eaebb75 1693
5f7b2142
ILT
1694 *tpp = t;
1695 return 4 + off;
bd5635a1 1696
5f7b2142
ILT
1697 case tqVol:
1698 /* Volatile -- currently ignored */
1699 return 0;
3eaebb75 1700
5f7b2142
ILT
1701 case tqConst:
1702 /* Const -- currently ignored */
1703 return 0;
817bc7b8 1704
5f7b2142
ILT
1705 default:
1706 complain (&unknown_type_qual_complaint, tq);
1707 return 0;
1708 }
bd5635a1
RP
1709}
1710
1711
6c2e7392
PS
1712/* Parse a procedure descriptor record PR. Note that the procedure is
1713 parsed _after_ the local symbols, now we just insert the extra
1714 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1715 already been placed in the procedure's main block. Note also that
1716 images that have been partially stripped (ld -x) have been deprived
1717 of local symbols, and we have to cope with them here. FIRST_OFF is
1718 the offset of the first procedure for this FDR; we adjust the
b5d4d6d7
JK
1719 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1720 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1721 in question, or NULL to use top_stack->cur_block. */
9adb88b7 1722
b5d4d6d7 1723static void parse_procedure PARAMS ((PDR *, struct symtab *, unsigned long));
bd5635a1 1724
d1bb1d41 1725static void
b5d4d6d7 1726parse_procedure (pr, search_symtab, first_off)
5f7b2142 1727 PDR *pr;
b5d4d6d7 1728 struct symtab *search_symtab;
6c2e7392 1729 unsigned long first_off;
bd5635a1 1730{
b5d4d6d7 1731 struct symbol *s, *i;
5f7b2142
ILT
1732 struct block *b;
1733 struct mips_extra_func_info *e;
1734 char *sh_name;
1735
6c2e7392
PS
1736 /* Simple rule to find files linked "-x" */
1737 if (cur_fdr->rss == -1)
5f7b2142 1738 {
6c2e7392
PS
1739 if (pr->isym == -1)
1740 {
1741 /* Static procedure at address pr->adr. Sigh. */
99a15c64 1742 complain (&pdr_static_symbol_complaint, (unsigned long) pr->adr);
6c2e7392
PS
1743 return;
1744 }
1745 else
1746 {
1747 /* external */
1748 EXTR she;
1749
6ac14d25
PS
1750 (*ecoff_backend (cur_bfd)->swap_ext_in)
1751 (cur_bfd,
1752 ((char *) ecoff_data (cur_bfd)->external_ext
1753 + pr->isym * ecoff_backend (cur_bfd)->external_ext_size),
1754 &she);
6c2e7392
PS
1755 sh_name = ecoff_data (cur_bfd)->ssext + she.asym.iss;
1756 }
5f7b2142 1757 }
6c2e7392
PS
1758 else
1759 {
1760 /* Full symbols */
1761 SYMR sh;
1762
6ac14d25
PS
1763 (*ecoff_backend (cur_bfd)->swap_sym_in)
1764 (cur_bfd,
1765 ((char *) ecoff_data (cur_bfd)->external_sym
1766 + ((cur_fdr->isymBase + pr->isym)
1767 * ecoff_backend (cur_bfd)->external_sym_size)),
1768 &sh);
6c2e7392
PS
1769 sh_name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss;
1770 }
1771
b5d4d6d7 1772 if (search_symtab != NULL)
6c2e7392 1773 {
b5d4d6d7
JK
1774#if 0
1775 /* This loses both in the case mentioned (want a static, find a global),
1776 but also if we are looking up a non-mangled name which happens to
1777 match the name of a mangled function. */
1778 /* We have to save the cur_fdr across the call to lookup_symbol.
1779 If the pdr is for a static function and if a global function with
1780 the same name exists, lookup_symbol will eventually read in the symtab
1781 for the global function and clobber cur_fdr. */
1782 FDR *save_cur_fdr = cur_fdr;
1783 s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1784 cur_fdr = save_cur_fdr;
1785#else
1786 s = mylookup_symbol
1787 (sh_name,
1788 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK),
1789 VAR_NAMESPACE,
1790 LOC_BLOCK);
1791#endif
1792 }
1793 else
1794 s = mylookup_symbol (sh_name, top_stack->cur_block,
1795 VAR_NAMESPACE, LOC_BLOCK);
9adb88b7 1796
b5d4d6d7
JK
1797 if (s != 0)
1798 {
1799 b = SYMBOL_BLOCK_VALUE (s);
1800 }
1801 else
1802 {
1803 complain (&pdr_for_nonsymbol_complaint, sh_name);
b303297a 1804#if 1
b5d4d6d7 1805 return;
dac4929a 1806#else
817bc7b8 1807/* FIXME -- delete. We can't do symbol allocation now; it's all done. */
b5d4d6d7
JK
1808 s = new_symbol (sh_name);
1809 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1810 SYMBOL_CLASS (s) = LOC_BLOCK;
1811 /* Donno its type, hope int is ok */
1812 SYMBOL_TYPE (s) = lookup_function_type (builtin_type_int);
1813 add_symbol (s, top_stack->cur_block);
1814 /* Wont have symbols for this one */
1815 b = new_block (2);
1816 SYMBOL_BLOCK_VALUE (s) = b;
1817 BLOCK_FUNCTION (b) = s;
1818 BLOCK_START (b) = pr->adr;
1819 /* BOUND used to be the end of procedure's text, but the
1820 argument is no longer passed in. */
1821 BLOCK_END (b) = bound;
1822 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1823 add_block (b, top_stack->cur_st);
817bc7b8 1824#endif
9adb88b7 1825 }
d1bb1d41 1826
b5d4d6d7
JK
1827 i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1828
1829 if (i)
5f7b2142 1830 {
b5d4d6d7 1831 e = (struct mips_extra_func_info *) SYMBOL_VALUE (i);
5f7b2142
ILT
1832 e->pdr = *pr;
1833 e->pdr.isym = (long) s;
6c2e7392 1834 e->pdr.adr += cur_fdr->adr - first_off;
e157305c
PS
1835
1836 /* Correct incorrect setjmp procedure descriptor from the library
1837 to make backtrace through setjmp work. */
99a15c64 1838 if (e->pdr.pcreg == 0 && STREQ (sh_name, "setjmp"))
e157305c
PS
1839 {
1840 complain (&bad_setjmp_pdr_complaint, 0);
1841 e->pdr.pcreg = RA_REGNUM;
1842 e->pdr.regmask = 0x80000000;
1843 e->pdr.regoffset = -4;
1844 }
99a15c64
PS
1845
1846 /* Fake PC_REGNUM for alpha __sigtramp so that read_next_frame_reg
1847 will use the saved user pc from the sigcontext. */
1848 if (STREQ (sh_name, "__sigtramp"))
1849 e->pdr.pcreg = PC_REGNUM;
5f7b2142 1850 }
bd5635a1
RP
1851}
1852
1853/* Parse the external symbol ES. Just call parse_symbol() after
1854 making sure we know where the aux are for it. For procedures,
1855 parsing of the PDRs has already provided all the needed
1856 information, we only parse them if SKIP_PROCEDURES is false,
101f259c 1857 and only if this causes no symbol duplication.
d747e0af 1858 BIGEND says whether aux entries are big-endian or little-endian.
101f259c
JG
1859
1860 This routine clobbers top_stack->cur_block and ->cur_st. */
bd5635a1 1861
4ad1963e 1862static void
5f7b2142
ILT
1863parse_external (es, skip_procedures, bigend)
1864 EXTR *es;
1865 int skip_procedures;
1866 int bigend;
bd5635a1 1867{
5f7b2142 1868 union aux_ext *ax;
bd5635a1 1869
5f7b2142
ILT
1870 if (es->ifd != ifdNil)
1871 {
1872 cur_fd = es->ifd;
6c2e7392
PS
1873 cur_fdr = ecoff_data (cur_bfd)->fdr + cur_fd;
1874 ax = ecoff_data (cur_bfd)->external_aux + cur_fdr->iauxBase;
5f7b2142
ILT
1875 }
1876 else
1877 {
6c2e7392 1878 cur_fdr = ecoff_data (cur_bfd)->fdr;
5f7b2142
ILT
1879 ax = 0;
1880 }
bd5635a1 1881
5f7b2142
ILT
1882 /* Reading .o files */
1883 if (es->asym.sc == scUndefined || es->asym.sc == scNil)
1884 {
1885 char *what;
1886 switch (es->asym.st)
1887 {
99a15c64
PS
1888 case stNil:
1889 /* These are generated for static symbols in .o files,
1890 ignore them. */
1891 return;
5f7b2142 1892 case stStaticProc:
bd5635a1 1893 case stProc:
5f7b2142
ILT
1894 what = "procedure";
1895 n_undef_procs++;
1896 break;
bd5635a1 1897 case stGlobal:
5f7b2142
ILT
1898 what = "variable";
1899 n_undef_vars++;
1900 break;
bd5635a1 1901 case stLabel:
5f7b2142
ILT
1902 what = "label";
1903 n_undef_labels++;
1904 break;
1905 default:
1906 what = "symbol";
1907 break;
1908 }
1909 n_undef_symbols++;
1910 /* FIXME: Turn this into a complaint? */
1911 if (info_verbose)
1912 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
6c2e7392
PS
1913 what,
1914 ecoff_data (cur_bfd)->ssext + es->asym.iss,
1915 fdr_name (cur_fdr));
5f7b2142
ILT
1916 return;
1917 }
1918
1919 switch (es->asym.st)
1920 {
1921 case stProc:
1922 /* If we have full symbols we do not need more */
1923 if (skip_procedures)
1924 return;
6c2e7392
PS
1925 if (mylookup_symbol (ecoff_data (cur_bfd)->ssext + es->asym.iss,
1926 top_stack->cur_block,
5f7b2142
ILT
1927 VAR_NAMESPACE, LOC_BLOCK))
1928 break;
1929 /* fall through */
1930 case stGlobal:
1931 case stLabel:
6c2e7392
PS
1932 /* Note that the case of a symbol with indexNil must be handled
1933 anyways by parse_symbol(). */
6ac14d25 1934 parse_symbol (&es->asym, ax, (char *) NULL, bigend);
5f7b2142
ILT
1935 break;
1936 default:
1937 break;
1938 }
bd5635a1
RP
1939}
1940
1941/* Parse the line number info for file descriptor FH into
1942 GDB's linetable LT. MIPS' encoding requires a little bit
1943 of magic to get things out. Note also that MIPS' line
1944 numbers can go back and forth, apparently we can live
1945 with that and do not need to reorder our linetables */
1946
4ad1963e 1947static void
99a15c64 1948parse_lines (fh, pr, lt, maxlines)
5f7b2142 1949 FDR *fh;
6c2e7392 1950 PDR *pr;
5f7b2142 1951 struct linetable *lt;
99a15c64 1952 int maxlines;
bd5635a1 1953{
6c2e7392 1954 unsigned char *base;
5f7b2142
ILT
1955 int j, k;
1956 int delta, count, lineno = 0;
6c2e7392 1957 unsigned long first_off = pr->adr;
5f7b2142 1958
cbba020f 1959 if (fh->cbLine == 0)
5f7b2142
ILT
1960 return;
1961
6c2e7392
PS
1962 base = ecoff_data (cur_bfd)->line + fh->cbLineOffset;
1963
5f7b2142 1964 /* Scan by procedure descriptors */
6c2e7392
PS
1965 k = 0;
1966 for (j = 0; j < fh->cpd; j++, pr++)
5f7b2142 1967 {
99a15c64 1968 long l;
6c2e7392 1969 unsigned long adr;
99a15c64 1970 unsigned char *halt;
5f7b2142
ILT
1971
1972 /* No code for this one */
1973 if (pr->iline == ilineNil ||
1974 pr->lnLow == -1 || pr->lnHigh == -1)
1975 continue;
6c2e7392 1976
99a15c64
PS
1977 /* Determine start and end address of compressed line bytes for
1978 this procedure. */
1979 base = ecoff_data (cur_bfd)->line + fh->cbLineOffset;
1980 if (j != (fh->cpd - 1))
1981 halt = base + pr[1].cbLineOffset;
5f7b2142 1982 else
99a15c64
PS
1983 halt = base + fh->cbLine;
1984 base += pr->cbLineOffset;
6c2e7392 1985
6c2e7392
PS
1986 adr = fh->adr + pr->adr - first_off;
1987 l = adr >> 2; /* in words */
99a15c64 1988 for (lineno = pr->lnLow; base < halt; )
5f7b2142
ILT
1989 {
1990 count = *base & 0x0f;
1991 delta = *base++ >> 4;
1992 if (delta >= 8)
1993 delta -= 16;
1994 if (delta == -8)
1995 {
1996 delta = (base[0] << 8) | base[1];
1997 if (delta >= 0x8000)
1998 delta -= 0x10000;
1999 base += 2;
2000 }
2001 lineno += delta; /* first delta is 0 */
99a15c64
PS
2002
2003 /* Complain if the line table overflows. Could happen
2004 with corrupt binaries. */
2005 if (lt->nitems >= maxlines)
2006 {
2007 complain (&bad_linetable_guess_complaint, fdr_name (fh));
2008 break;
2009 }
5f7b2142
ILT
2010 k = add_line (lt, lineno, l, k);
2011 l += count + 1;
bd5635a1 2012 }
5f7b2142 2013 }
bd5635a1 2014}
101f259c
JG
2015\f
2016/* Master parsing procedure for first-pass reading of file symbols
6c2e7392 2017 into a partial_symtab. */
bd5635a1 2018
d747e0af 2019static void
6c2e7392 2020parse_partial_symbols (objfile, section_offsets)
d4ea2aba 2021 struct objfile *objfile;
dac4929a 2022 struct section_offsets *section_offsets;
bd5635a1 2023{
6ac14d25
PS
2024 const struct ecoff_backend_data * const backend = ecoff_backend (cur_bfd);
2025 const bfd_size_type external_sym_size = backend->external_sym_size;
2026 const bfd_size_type external_rfd_size = backend->external_rfd_size;
2027 const bfd_size_type external_ext_size = backend->external_ext_size;
2028 void (* const swap_ext_in) PARAMS ((bfd *, PTR, EXTR *))
2029 = backend->swap_ext_in;
2030 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
2031 = backend->swap_sym_in;
2032 void (* const swap_rfd_in) PARAMS ((bfd *, PTR, RFDT *))
2033 = backend->swap_rfd_in;
5f7b2142 2034 int f_idx, s_idx;
6c2e7392 2035 HDRR *hdr = &ecoff_data (cur_bfd)->symbolic_header;
5f7b2142
ILT
2036 /* Running pointers */
2037 FDR *fh;
6ac14d25
PS
2038 char *ext_out;
2039 char *ext_out_end;
6c2e7392
PS
2040 EXTR *ext_block;
2041 register EXTR *ext_in;
2042 EXTR *ext_in_end;
2043 SYMR sh;
5f7b2142
ILT
2044 struct partial_symtab *pst;
2045
2046 int past_first_source_file = 0;
2047
2048 /* List of current psymtab's include files */
2049 char **psymtab_include_list;
2050 int includes_allocated;
2051 int includes_used;
6c2e7392 2052 EXTR *extern_tab;
5f7b2142
ILT
2053 struct pst_map *fdr_to_pst;
2054 /* Index within current psymtab dependency list */
2055 struct partial_symtab **dependency_list;
2056 int dependencies_used, dependencies_allocated;
2057 struct cleanup *old_chain;
2058 char *name;
cbba020f 2059 enum language prev_language;
5f7b2142 2060
6c2e7392
PS
2061 extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack,
2062 sizeof (EXTR) * hdr->iextMax);
5f7b2142
ILT
2063
2064 includes_allocated = 30;
2065 includes_used = 0;
2066 psymtab_include_list = (char **) alloca (includes_allocated *
2067 sizeof (char *));
2068 next_symbol_text_func = mips_next_symbol_text;
2069
2070 dependencies_allocated = 30;
2071 dependencies_used = 0;
2072 dependency_list =
2073 (struct partial_symtab **) alloca (dependencies_allocated *
2074 sizeof (struct partial_symtab *));
2075
2076 last_source_file = NULL;
2077
2078 /*
6c2e7392
PS
2079 * Big plan:
2080 *
2081 * Only parse the Local and External symbols, and the Relative FDR.
2082 * Fixup enough of the loader symtab to be able to use it.
2083 * Allocate space only for the file's portions we need to
2084 * look at. (XXX)
2085 */
817bc7b8 2086
5f7b2142
ILT
2087 max_gdbinfo = 0;
2088 max_glevel = MIN_GLEVEL;
2089
2090 /* Allocate the map FDR -> PST.
2091 Minor hack: -O3 images might claim some global data belongs
2092 to FDR -1. We`ll go along with that */
2093 fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
2094 old_chain = make_cleanup (free, fdr_to_pst);
2095 fdr_to_pst++;
2096 {
2097 struct partial_symtab *pst = new_psymtab ("", objfile);
2098 fdr_to_pst[-1].pst = pst;
2099 FDR_IDX (pst) = -1;
2100 }
2101
e7e02420
PS
2102 /* Allocate the global pending list. */
2103 ECOFF_PENDING_LIST (objfile) =
2104 ((struct mips_pending **)
2105 obstack_alloc (&objfile->psymbol_obstack,
2106 hdr->ifdMax * sizeof (struct mips_pending *)));
2107 memset ((PTR) ECOFF_PENDING_LIST (objfile), 0,
2108 hdr->ifdMax * sizeof (struct mips_pending *));
2109
6c2e7392
PS
2110 /* Pass 0 over external syms: swap them in. */
2111 ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
2112 make_cleanup (free, ext_block);
2113
6ac14d25
PS
2114 ext_out = (char *) ecoff_data (cur_bfd)->external_ext;
2115 ext_out_end = ext_out + hdr->iextMax * external_ext_size;
6c2e7392 2116 ext_in = ext_block;
6ac14d25
PS
2117 for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
2118 (*swap_ext_in) (cur_bfd, ext_out, ext_in);
6c2e7392 2119
5f7b2142 2120 /* Pass 1 over external syms: Presize and partition the list */
6c2e7392
PS
2121 ext_in = ext_block;
2122 ext_in_end = ext_in + hdr->iextMax;
2123 for (; ext_in < ext_in_end; ext_in++)
2124 fdr_to_pst[ext_in->ifd].n_globals++;
817bc7b8 2125
5f7b2142
ILT
2126 /* Pass 1.5 over files: partition out global symbol space */
2127 s_idx = 0;
2128 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
2129 {
2130 fdr_to_pst[f_idx].globals_offset = s_idx;
2131 s_idx += fdr_to_pst[f_idx].n_globals;
2132 fdr_to_pst[f_idx].n_globals = 0;
d4ea2aba 2133 }
bd5635a1 2134
5f7b2142 2135 /* Pass 2 over external syms: fill in external symbols */
6c2e7392
PS
2136 ext_in = ext_block;
2137 ext_in_end = ext_in + hdr->iextMax;
2138 for (; ext_in < ext_in_end; ext_in++)
5f7b2142
ILT
2139 {
2140 enum minimal_symbol_type ms_type = mst_text;
bd5635a1 2141
6c2e7392
PS
2142 extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
2143 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
d4ea2aba 2144
6c2e7392 2145 if (ext_in->asym.sc == scUndefined || ext_in->asym.sc == scNil)
5f7b2142 2146 continue;
101f259c 2147
6c2e7392
PS
2148 name = ecoff_data (cur_bfd)->ssext + ext_in->asym.iss;
2149 switch (ext_in->asym.st)
5f7b2142 2150 {
817bc7b8 2151 case stProc:
5f7b2142 2152 break;
85999c05
PS
2153 case stStaticProc:
2154 ms_type = mst_file_text;
2155 break;
817bc7b8 2156 case stGlobal:
6ac14d25
PS
2157 if (ext_in->asym.sc == scData
2158 || ext_in->asym.sc == scSData
2159 || ext_in->asym.sc == scRData)
2160 ms_type = mst_data;
2161 else
2162 ms_type = mst_bss;
5f7b2142 2163 break;
817bc7b8 2164 case stLabel:
6ac14d25
PS
2165 if (ext_in->asym.sc == scAbs)
2166 ms_type = mst_abs;
2167 else if (ext_in->asym.sc == scText)
2168 ms_type = mst_text;
2169 else if (ext_in->asym.sc == scData
2170 || ext_in->asym.sc == scSData
2171 || ext_in->asym.sc == scRData)
2172 ms_type = mst_data;
2173 else
2174 ms_type = mst_bss;
5f7b2142 2175 break;
99a15c64
PS
2176 case stLocal:
2177 /* The alpha has the section start addresses in stLocal symbols
2178 whose name starts with a `.'. Skip those but complain for all
2179 other stLocal symbols. */
2180 if (name[0] == '.')
2181 continue;
2182 /* Fall through. */
817bc7b8 2183 default:
5f7b2142 2184 ms_type = mst_unknown;
6c2e7392 2185 complain (&unknown_ext_complaint, name);
bd5635a1 2186 }
6c2e7392 2187 prim_record_minimal_symbol (name, ext_in->asym.value, ms_type);
817bc7b8 2188 }
bd5635a1 2189
5f7b2142
ILT
2190 /* Pass 3 over files, over local syms: fill in static symbols */
2191 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2192 {
2193 struct partial_symtab *save_pst;
6c2e7392 2194 EXTR *ext_ptr;
dac4929a 2195
6c2e7392 2196 cur_fdr = fh = ecoff_data (cur_bfd)->fdr + f_idx;
c55e6167 2197
5f7b2142
ILT
2198 if (fh->csym == 0)
2199 {
2200 fdr_to_pst[f_idx].pst = NULL;
2201 continue;
817bc7b8 2202 }
6c2e7392
PS
2203 pst = start_psymtab_common (objfile, section_offsets,
2204 fdr_name (fh),
5f7b2142
ILT
2205 fh->cpd ? fh->adr : 0,
2206 objfile->global_psymbols.next,
2207 objfile->static_psymbols.next);
2208 pst->read_symtab_private = ((char *)
2209 obstack_alloc (&objfile->psymbol_obstack,
2210 sizeof (struct symloc)));
6c2e7392 2211 memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc));
5f7b2142
ILT
2212
2213 save_pst = pst;
5f7b2142 2214 FDR_IDX (pst) = f_idx;
6c2e7392 2215 CUR_BFD (pst) = cur_bfd;
5f7b2142
ILT
2216
2217 /* The way to turn this into a symtab is to call... */
2218 pst->read_symtab = mipscoff_psymtab_to_symtab;
2219
e7e02420
PS
2220 /* Set up language for the pst.
2221 The language from the FDR is used if it is unambigious (e.g. cfront
2222 with native cc and g++ will set the language to C).
2223 Otherwise we have to deduce the language from the filename.
2224 Native ecoff has every header file in a separate FDR, so
2225 deduce_language_from_filename will return language_unknown for
2226 a header file, which is not what we want.
cbba020f
PS
2227 But the FDRs for the header files are after the FDR for the source
2228 file, so we can assign the language of the source file to the
2229 following header files. Then we save the language in the private
2230 pst data so that we can reuse it when building symtabs. */
2231 prev_language = psymtab_language;
e7e02420
PS
2232
2233 switch (fh->lang)
2234 {
2235 case langCplusplusV2:
2236 psymtab_language = language_cplus;
2237 break;
2238 default:
2239 psymtab_language = deduce_language_from_filename (fdr_name (fh));
2240 break;
2241 }
cbba020f
PS
2242 if (psymtab_language == language_unknown)
2243 psymtab_language = prev_language;
2244 PST_PRIVATE (pst)->pst_language = psymtab_language;
018ab14f 2245
5f7b2142
ILT
2246 pst->texthigh = pst->textlow;
2247
2248 /* For stabs-in-ecoff files, the second symbol must be @stab.
6c2e7392
PS
2249 This symbol is emitted by mips-tfile to signal that the
2250 current object file uses encapsulated stabs instead of mips
2251 ecoff for local symbols. (It is the second symbol because
2252 the first symbol is the stFile used to signal the start of a
2253 file). */
2254 processing_gcc_compilation = 0;
2255 if (fh->csym >= 2)
2256 {
6ac14d25
PS
2257 (*swap_sym_in) (cur_bfd,
2258 ((char *) ecoff_data (cur_bfd)->external_sym
2259 + (fh->isymBase + 1) * external_sym_size),
2260 &sh);
6c2e7392
PS
2261 if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss,
2262 stabs_symbol))
2263 processing_gcc_compilation = 2;
2264 }
2265
2266 if (processing_gcc_compilation != 0)
5f7b2142 2267 {
5f7b2142
ILT
2268 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2269 {
2270 int type_code;
2271 char *namestring;
6c2e7392 2272
6ac14d25
PS
2273 (*swap_sym_in) (cur_bfd,
2274 ((char *) ecoff_data (cur_bfd)->external_sym
2275 + (fh->isymBase + cur_sdx) * external_sym_size),
2276 &sh);
2277 type_code = ECOFF_UNMARK_STAB (sh.index);
2278 if (!ECOFF_IS_STAB (&sh))
5f7b2142 2279 {
6c2e7392 2280 if (sh.st == stProc || sh.st == stStaticProc)
5f7b2142 2281 {
6c2e7392
PS
2282 long procaddr = sh.value;
2283 long isym;
2284
2285
2286 isym = AUX_GET_ISYM (fh->fBigendian,
2287 (ecoff_data (cur_bfd)->external_aux
2288 + fh->iauxBase
2289 + sh.index));
6ac14d25
PS
2290 (*swap_sym_in) (cur_bfd,
2291 (((char *)
2292 ecoff_data (cur_bfd)->external_sym)
2293 + ((fh->isymBase + isym - 1)
2294 * external_sym_size)),
2295 &sh);
6c2e7392 2296 if (sh.st == stEnd)
5f7b2142 2297 {
6c2e7392 2298 long high = procaddr + sh.value;
5f7b2142
ILT
2299 if (high > pst->texthigh)
2300 pst->texthigh = high;
101f259c 2301 }
7e258d18 2302 }
5f7b2142 2303 continue;
817bc7b8 2304 }
6c2e7392
PS
2305#define SET_NAMESTRING() \
2306 namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss
7e258d18 2307#define CUR_SYMBOL_TYPE type_code
6c2e7392 2308#define CUR_SYMBOL_VALUE sh.value
dac4929a 2309#define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
7e258d18
PB
2310 pst = save_pst
2311#define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
7e258d18
PB
2312#define HANDLE_RBRAC(val) \
2313 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
7e258d18 2314#include "partial-stab.h"
7e258d18 2315 }
817bc7b8 2316 }
5f7b2142
ILT
2317 else
2318 {
5f7b2142
ILT
2319 for (cur_sdx = 0; cur_sdx < fh->csym;)
2320 {
2321 char *name;
2322 enum address_class class;
5f7b2142 2323
6ac14d25
PS
2324 (*swap_sym_in) (cur_bfd,
2325 ((char *) ecoff_data (cur_bfd)->external_sym
2326 + ((fh->isymBase + cur_sdx)
2327 * external_sym_size)),
2328 &sh);
6c2e7392 2329
6ac14d25 2330 if (ECOFF_IS_STAB (&sh))
5f7b2142
ILT
2331 {
2332 cur_sdx++;
2333 continue;
817bc7b8 2334 }
101f259c 2335
6ac14d25
PS
2336 /* Non absolute static symbols go into the minimal table. */
2337 if (sh.sc == scUndefined || sh.sc == scNil
2338 || (sh.index == indexNil
2339 && (sh.st != stStatic || sh.sc == scAbs)))
5f7b2142
ILT
2340 {
2341 /* FIXME, premature? */
2342 cur_sdx++;
2343 continue;
817bc7b8 2344 }
dac4929a 2345
6c2e7392 2346 name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
817bc7b8 2347
6c2e7392 2348 switch (sh.st)
5f7b2142
ILT
2349 {
2350 long high;
2351 long procaddr;
2352 int new_sdx;
2353
5f7b2142 2354 case stStaticProc: /* Function */
6ac14d25
PS
2355 /* I believe this is used only for file-local functions.
2356 The comment in symconst.h ("load time only static procs")
2357 isn't particularly clear on this point. */
2358 prim_record_minimal_symbol (name, sh.value, mst_file_text);
2359 /* FALLTHROUGH */
2360
2361 case stProc: /* Asm labels apparently */
5f7b2142
ILT
2362 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2363 VAR_NAMESPACE, LOC_BLOCK,
6c2e7392 2364 objfile->static_psymbols, sh.value,
5f7b2142
ILT
2365 psymtab_language, objfile);
2366 /* Skip over procedure to next one. */
6c2e7392 2367 if (sh.index >= hdr->iauxMax)
5f7b2142
ILT
2368 {
2369 /* Should not happen, but does when cross-compiling
2370 with the MIPS compiler. FIXME -- pull later. */
2371 complain (&index_complaint, name);
2372 new_sdx = cur_sdx + 1; /* Don't skip at all */
2373 }
2374 else
2375 new_sdx = AUX_GET_ISYM (fh->fBigendian,
6c2e7392
PS
2376 (ecoff_data (cur_bfd)->external_aux
2377 + fh->iauxBase
2378 + sh.index));
2379 procaddr = sh.value;
5f7b2142
ILT
2380
2381 if (new_sdx <= cur_sdx)
2382 {
2383 /* This should not happen either... FIXME. */
2384 complain (&aux_index_complaint, name);
2385 new_sdx = cur_sdx + 1; /* Don't skip backward */
7e258d18 2386 }
817bc7b8 2387
5f7b2142 2388 cur_sdx = new_sdx;
6ac14d25
PS
2389 (*swap_sym_in) (cur_bfd,
2390 ((char *) ecoff_data (cur_bfd)->external_sym
2391 + ((fh->isymBase + cur_sdx - 1)
2392 * external_sym_size)),
2393 &sh);
6c2e7392 2394 if (sh.st != stEnd)
817bc7b8 2395 continue;
6c2e7392 2396 high = procaddr + sh.value;
5f7b2142
ILT
2397 if (high > pst->texthigh)
2398 pst->texthigh = high;
2399 continue;
2400
2401 case stStatic: /* Variable */
6ac14d25
PS
2402 if (sh.sc == scData || sh.sc == scSData || sh.sc == scRData)
2403 prim_record_minimal_symbol (name, sh.value, mst_file_data);
2404 else
2405 prim_record_minimal_symbol (name, sh.value, mst_file_bss);
5f7b2142
ILT
2406 class = LOC_STATIC;
2407 break;
2408
2409 case stTypedef:/* Typedef */
2410 class = LOC_TYPEDEF;
2411 break;
2412
2413 case stConstant: /* Constant decl */
2414 class = LOC_CONST;
2415 break;
2416
2417 case stUnion:
2418 case stStruct:
2419 case stEnum:
2420 case stBlock: /* { }, str, un, enum*/
e7ff735c 2421 if (sh.sc == scInfo || sh.sc == scCommon)
5f7b2142
ILT
2422 {
2423 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2424 STRUCT_NAMESPACE, LOC_TYPEDEF,
2425 objfile->static_psymbols,
6c2e7392 2426 sh.value,
5f7b2142
ILT
2427 psymtab_language, objfile);
2428 }
2429 /* Skip over the block */
6c2e7392 2430 new_sdx = sh.index;
5f7b2142
ILT
2431 if (new_sdx <= cur_sdx)
2432 {
2433 /* This happens with the Ultrix kernel. */
2434 complain (&block_index_complaint, name);
2435 new_sdx = cur_sdx + 1; /* Don't skip backward */
2436 }
2437 cur_sdx = new_sdx;
2438 continue;
2439
2440 case stFile: /* File headers */
2441 case stLabel: /* Labels */
2442 case stEnd: /* Ends of files */
2443 goto skip;
2444
2445 case stLocal: /* Local variables */
2446 /* Normally these are skipped because we skip over
2447 all blocks we see. However, these can occur
2448 as visible symbols in a .h file that contains code. */
2449 goto skip;
2450
2451 default:
2452 /* Both complaints are valid: one gives symbol name,
2453 the other the offending symbol type. */
6c2e7392
PS
2454 complain (&unknown_sym_complaint, name);
2455 complain (&unknown_st_complaint, sh.st);
5f7b2142
ILT
2456 cur_sdx++;
2457 continue;
101f259c 2458 }
5f7b2142
ILT
2459 /* Use this gdb symbol */
2460 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2461 VAR_NAMESPACE, class,
6c2e7392 2462 objfile->static_psymbols, sh.value,
5f7b2142
ILT
2463 psymtab_language, objfile);
2464 skip:
2465 cur_sdx++; /* Go to next file symbol */
817bc7b8 2466 }
d4ea2aba 2467
5f7b2142
ILT
2468 /* Now do enter the external symbols. */
2469 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
2470 cur_sdx = fdr_to_pst[f_idx].n_globals;
2471 PST_PRIVATE (save_pst)->extern_count = cur_sdx;
2472 PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
2473 for (; --cur_sdx >= 0; ext_ptr++)
2474 {
5f7b2142 2475 enum address_class class;
6c2e7392
PS
2476 SYMR *psh;
2477 char *name;
5f7b2142 2478
6c2e7392 2479 if (ext_ptr->ifd != f_idx)
5f7b2142 2480 abort ();
6c2e7392 2481 psh = &ext_ptr->asym;
99a15c64
PS
2482
2483 /* Do not add undefined symbols to the partial symbol table. */
2484 if (psh->sc == scUndefined || psh->sc == scNil)
2485 continue;
2486
6c2e7392 2487 switch (psh->st)
5f7b2142 2488 {
99a15c64
PS
2489 case stNil:
2490 /* These are generated for static symbols in .o files,
2491 ignore them. */
2492 continue;
5f7b2142 2493 case stProc:
85999c05 2494 case stStaticProc:
5f7b2142
ILT
2495 class = LOC_BLOCK;
2496 break;
2497 case stLabel:
2498 class = LOC_LABEL;
2499 break;
2500 default:
6c2e7392
PS
2501 complain (&unknown_ext_complaint,
2502 ecoff_data (cur_bfd)->ssext + psh->iss);
5f7b2142
ILT
2503 /* Fall through, pretend it's global. */
2504 case stGlobal:
2505 class = LOC_STATIC;
2506 break;
d4ea2aba 2507 }
6c2e7392
PS
2508 name = ecoff_data (cur_bfd)->ssext + psh->iss;
2509 ADD_PSYMBOL_ADDR_TO_LIST (name, strlen (name),
2510 VAR_NAMESPACE, class,
2511 objfile->global_psymbols, (CORE_ADDR) psh->value,
2512 psymtab_language, objfile);
7e258d18 2513 }
bd5635a1
RP
2514 }
2515
cbba020f
PS
2516 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
2517 empty and put on the free list. */
2518 fdr_to_pst[f_idx].pst = end_psymtab (save_pst,
2519 psymtab_include_list, includes_used,
2520 -1, save_pst->texthigh,
2521 dependency_list, dependencies_used);
5f7b2142
ILT
2522 if (objfile->ei.entry_point >= save_pst->textlow &&
2523 objfile->ei.entry_point < save_pst->texthigh)
2524 {
2525 objfile->ei.entry_file_lowpc = save_pst->textlow;
2526 objfile->ei.entry_file_highpc = save_pst->texthigh;
2527 }
817bc7b8
JG
2528 }
2529
5f7b2142
ILT
2530 /* Now scan the FDRs for dependencies */
2531 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2532 {
6c2e7392 2533 fh = f_idx + ecoff_data (cur_bfd)->fdr;
5f7b2142
ILT
2534 pst = fdr_to_pst[f_idx].pst;
2535
cbba020f
PS
2536 if (pst == (struct partial_symtab *)NULL)
2537 continue;
2538
5f7b2142
ILT
2539 /* This should catch stabs-in-ecoff. */
2540 if (fh->crfd <= 1)
2541 continue;
2542
e7e02420
PS
2543 /* Skip the first file indirect entry as it is a self dependency
2544 for source files or a reverse .h -> .c dependency for header files. */
cbba020f 2545 pst->number_of_dependencies = 0;
5f7b2142
ILT
2546 pst->dependencies =
2547 ((struct partial_symtab **)
2548 obstack_alloc (&objfile->psymbol_obstack,
e7e02420 2549 ((fh->crfd - 1)
5f7b2142 2550 * sizeof (struct partial_symtab *))));
e7e02420 2551 for (s_idx = 1; s_idx < fh->crfd; s_idx++)
5f7b2142 2552 {
6c2e7392
PS
2553 RFDT rh;
2554
6ac14d25
PS
2555 (*swap_rfd_in) (cur_bfd,
2556 ((char *) ecoff_data (cur_bfd)->external_rfd
2557 + (fh->rfdBase + s_idx) * external_rfd_size),
2558 &rh);
6c2e7392 2559 if (rh < 0 || rh >= hdr->ifdMax)
5f7b2142 2560 {
cbba020f
PS
2561 complain (&bad_file_number_complaint, rh);
2562 continue;
5f7b2142 2563 }
6c2e7392 2564
e7e02420 2565 /* Skip self dependencies of header files. */
cbba020f
PS
2566 if (rh == f_idx)
2567 continue;
bd5635a1 2568
cbba020f
PS
2569 /* Do not add to dependeny list if psymtab was empty. */
2570 if (fdr_to_pst[rh].pst == (struct partial_symtab *)NULL)
2571 continue;
2572 pst->dependencies[pst->number_of_dependencies++] = fdr_to_pst[rh].pst;
2573 }
2574 }
2575 do_cleanups (old_chain);
bd5635a1 2576}
5f7b2142 2577
bd5635a1 2578
5f7b2142 2579static char *
c55e6167 2580mips_next_symbol_text ()
7e258d18 2581{
6c2e7392
PS
2582 SYMR sh;
2583
5f7b2142 2584 cur_sdx++;
6ac14d25
PS
2585 (*ecoff_backend (cur_bfd)->swap_sym_in)
2586 (cur_bfd,
2587 ((char *) ecoff_data (cur_bfd)->external_sym
2588 + ((cur_fdr->isymBase + cur_sdx)
2589 * ecoff_backend (cur_bfd)->external_sym_size)),
2590 &sh);
6c2e7392 2591 return ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss;
7e258d18 2592}
bd5635a1
RP
2593
2594/* Ancillary function to psymtab_to_symtab(). Does all the work
2595 for turning the partial symtab PST into a symtab, recurring
3eaebb75
SG
2596 first on all dependent psymtabs. The argument FILENAME is
2597 only passed so we can see in debug stack traces what file
817bc7b8
JG
2598 is being read.
2599
2600 This function has a split personality, based on whether the
2601 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2602 The flow of control and even the memory allocation differs. FIXME. */
bd5635a1 2603
e072c738 2604static void
5f7b2142 2605psymtab_to_symtab_1 (pst, filename)
7e258d18
PB
2606 struct partial_symtab *pst;
2607 char *filename;
bd5635a1 2608{
6ac14d25
PS
2609 const bfd_size_type external_sym_size
2610 = ecoff_backend (cur_bfd)->external_sym_size;
2611 const bfd_size_type external_pdr_size
2612 = ecoff_backend (cur_bfd)->external_pdr_size;
2613 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
2614 = ecoff_backend (cur_bfd)->swap_sym_in;
6ac14d25
PS
2615 void (* const swap_pdr_in) PARAMS ((bfd *, PTR, PDR *))
2616 = ecoff_backend (cur_bfd)->swap_pdr_in;
5f7b2142
ILT
2617 int i;
2618 struct symtab *st;
2619 FDR *fh;
2620 struct linetable *lines;
7e258d18 2621
5f7b2142
ILT
2622 if (pst->readin)
2623 return;
2624 pst->readin = 1;
7e258d18 2625
5f7b2142
ILT
2626 /* Read in all partial symbtabs on which this one is dependent.
2627 NOTE that we do have circular dependencies, sigh. We solved
2628 that by setting pst->readin before this point. */
817bc7b8 2629
5f7b2142
ILT
2630 for (i = 0; i < pst->number_of_dependencies; i++)
2631 if (!pst->dependencies[i]->readin)
2632 {
2633 /* Inform about additional files to be read in. */
2634 if (info_verbose)
2635 {
2636 fputs_filtered (" ", stdout);
2637 wrap_here ("");
2638 fputs_filtered ("and ", stdout);
2639 wrap_here ("");
2640 printf_filtered ("%s...",
2641 pst->dependencies[i]->filename);
2642 wrap_here (""); /* Flush output */
2643 fflush (stdout);
2644 }
2645 /* We only pass the filename for debug purposes */
2646 psymtab_to_symtab_1 (pst->dependencies[i],
2647 pst->dependencies[i]->filename);
2648 }
817bc7b8 2649
ac8cf67d
PS
2650 /* Do nothing if this is a dummy psymtab. */
2651
2652 if (pst->n_global_syms == 0 && pst->n_static_syms == 0
2653 && pst->textlow == 0 && pst->texthigh == 0)
2654 return;
2655
5f7b2142 2656 /* Now read the symbols for this symtab */
817bc7b8 2657
ac8cf67d 2658 cur_bfd = CUR_BFD (pst);
5f7b2142
ILT
2659 current_objfile = pst->objfile;
2660 cur_fd = FDR_IDX (pst);
6c2e7392 2661 fh = (cur_fd == -1) ? (FDR *) NULL : ecoff_data (cur_bfd)->fdr + cur_fd;
5f7b2142 2662 cur_fdr = fh;
817bc7b8 2663
5f7b2142 2664 /* See comment in parse_partial_symbols about the @stabs sentinel. */
6c2e7392
PS
2665 processing_gcc_compilation = 0;
2666 if (fh != (FDR *) NULL && fh->csym >= 2)
5f7b2142 2667 {
6c2e7392
PS
2668 SYMR sh;
2669
6ac14d25
PS
2670 (*swap_sym_in) (cur_bfd,
2671 ((char *) ecoff_data (cur_bfd)->external_sym
2672 + (fh->isymBase + 1) * external_sym_size),
2673 &sh);
6c2e7392
PS
2674 if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss,
2675 stabs_symbol))
2676 {
2677 /* We indicate that this is a GCC compilation so that certain
2678 features will be enabled in stabsread/dbxread. */
2679 processing_gcc_compilation = 2;
2680 }
2681 }
817bc7b8 2682
6c2e7392
PS
2683 if (processing_gcc_compilation != 0)
2684 {
6ac14d25
PS
2685 char *pdr_ptr;
2686 char *pdr_end;
6c2e7392 2687 int first_pdr;
e7bf1152 2688 unsigned long first_off = 0;
9adb88b7 2689
b5d4d6d7 2690 /* This symbol table contains stabs-in-ecoff entries. */
dac4929a 2691
5f7b2142 2692 /* Parse local symbols first */
817bc7b8 2693
5f7b2142
ILT
2694 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */
2695 {
2696 current_objfile = NULL;
2697 return;
2698 }
2699 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2700 {
6c2e7392
PS
2701 SYMR sh;
2702 char *name;
2703 CORE_ADDR valu;
2704
6ac14d25
PS
2705 (*swap_sym_in) (cur_bfd,
2706 ((char *) ecoff_data (cur_bfd)->external_sym
2707 + (fh->isymBase + cur_sdx) * external_sym_size),
2708 &sh);
6c2e7392
PS
2709 name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
2710 valu = sh.value;
6ac14d25 2711 if (ECOFF_IS_STAB (&sh))
5f7b2142 2712 {
6ac14d25 2713 int type_code = ECOFF_UNMARK_STAB (sh.index);
5f7b2142
ILT
2714 process_one_symbol (type_code, 0, valu, name,
2715 pst->section_offsets, pst->objfile);
2716 if (type_code == N_FUN)
2717 {
2718 /* Make up special symbol to contain
2719 procedure specific info */
2720 struct mips_extra_func_info *e =
6c2e7392
PS
2721 ((struct mips_extra_func_info *)
2722 obstack_alloc (&current_objfile->symbol_obstack,
2723 sizeof (struct mips_extra_func_info)));
5f7b2142
ILT
2724 struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
2725 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
2726 SYMBOL_CLASS (s) = LOC_CONST;
2727 SYMBOL_TYPE (s) = builtin_type_void;
85999c05 2728 SYMBOL_VALUE (s) = (long) e;
5f7b2142 2729 add_symbol_to_list (s, &local_symbols);
817bc7b8
JG
2730 }
2731 }
6c2e7392 2732 else if (sh.st == stLabel && sh.index != indexNil)
5f7b2142
ILT
2733 {
2734 /* Handle encoded stab line number. */
6c2e7392 2735 record_line (current_subfile, sh.index, valu);
817bc7b8 2736 }
0b0d6c3f
PS
2737 else if (sh.st == stProc || sh.st == stStaticProc || sh.st == stEnd)
2738 /* These are generated by gcc-2.x, do not complain */
2739 ;
5f7b2142 2740 else
6c2e7392 2741 complain (&stab_unknown_complaint, name);
817bc7b8 2742 }
0b0d6c3f 2743 st = end_symtab (pst->texthigh, 0, 0, pst->objfile, SECT_OFF_TEXT);
5f7b2142 2744 end_stabs ();
817bc7b8 2745
5f7b2142
ILT
2746 /* Sort the symbol table now, we are done adding symbols to it.
2747 We must do this before parse_procedure calls lookup_symbol. */
2748 sort_symtab_syms (st);
817bc7b8 2749
5f7b2142
ILT
2750 /* This may not be necessary for stabs symtabs. FIXME. */
2751 sort_blocks (st);
817bc7b8 2752
6c2e7392
PS
2753 /* Fill in procedure info next. */
2754 first_pdr = 1;
6ac14d25
PS
2755 pdr_ptr = ((char *) ecoff_data (cur_bfd)->external_pdr
2756 + fh->ipdFirst * external_pdr_size);
2757 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
2758 for (; pdr_ptr < pdr_end; pdr_ptr += external_pdr_size)
5f7b2142 2759 {
6c2e7392
PS
2760 PDR pr;
2761
6ac14d25 2762 (*swap_pdr_in) (cur_bfd, pdr_ptr, &pr);
6c2e7392
PS
2763 if (first_pdr)
2764 {
2765 first_off = pr.adr;
2766 first_pdr = 0;
2767 }
b5d4d6d7 2768 parse_procedure (&pr, st, first_off);
817bc7b8 2769 }
5f7b2142
ILT
2770 }
2771 else
2772 {
6c2e7392 2773 /* This symbol table contains ordinary ecoff entries. */
817bc7b8 2774
5f7b2142 2775 /* FIXME: doesn't use pst->section_offsets. */
dac4929a 2776
5f7b2142
ILT
2777 int f_max;
2778 int maxlines;
6c2e7392 2779 EXTR *ext_ptr;
85f0a848 2780
5f7b2142
ILT
2781 /* How many symbols will we need */
2782 /* FIXME, this does not count enum values. */
2783 f_max = pst->n_global_syms + pst->n_static_syms;
2784 if (fh == 0)
2785 {
2786 maxlines = 0;
2787 st = new_symtab ("unknown", f_max, 0, pst->objfile);
2788 }
2789 else
2790 {
2791 f_max += fh->csym + fh->cpd;
2792 maxlines = 2 * fh->cline;
2793 st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
cbba020f
PS
2794
2795 /* The proper language was already determined when building
2796 the psymtab, use it. */
2797 st->language = PST_PRIVATE (pst)->pst_language;
817bc7b8
JG
2798 }
2799
018ab14f
PS
2800 psymtab_language = st->language;
2801
5f7b2142 2802 lines = LINETABLE (st);
817bc7b8 2803
5f7b2142
ILT
2804 /* Get a new lexical context */
2805
2806 push_parse_stack ();
2807 top_stack->cur_st = st;
2808 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
2809 STATIC_BLOCK);
2810 BLOCK_START (top_stack->cur_block) = fh ? fh->adr : 0;
2811 BLOCK_END (top_stack->cur_block) = 0;
2812 top_stack->blocktype = stFile;
2813 top_stack->maxsyms = 2 * f_max;
2814 top_stack->cur_type = 0;
2815 top_stack->procadr = 0;
2816 top_stack->numargs = 0;
2817
2818 if (fh)
2819 {
6ac14d25
PS
2820 char *sym_ptr;
2821 char *sym_end;
5f7b2142
ILT
2822
2823 /* Parse local symbols first */
6ac14d25
PS
2824 sym_ptr = ((char *) ecoff_data (cur_bfd)->external_sym
2825 + fh->isymBase * external_sym_size);
2826 sym_end = sym_ptr + fh->csym * external_sym_size;
6c2e7392 2827 while (sym_ptr < sym_end)
5f7b2142 2828 {
6c2e7392
PS
2829 SYMR sh;
2830 int c;
2831
6ac14d25 2832 (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
6c2e7392
PS
2833 c = parse_symbol (&sh,
2834 (ecoff_data (cur_bfd)->external_aux
2835 + fh->iauxBase),
2836 sym_ptr, fh->fBigendian);
6ac14d25 2837 sym_ptr += c * external_sym_size;
7e258d18 2838 }
bd5635a1 2839
6c2e7392
PS
2840 /* Linenumbers. At the end, check if we can save memory.
2841 parse_lines has to look ahead an arbitrary number of PDR
2842 structures, so we swap them all first. */
2843 if (fh->cpd > 0)
5f7b2142 2844 {
6c2e7392
PS
2845 PDR *pr_block;
2846 struct cleanup *old_chain;
6ac14d25
PS
2847 char *pdr_ptr;
2848 char *pdr_end;
6c2e7392
PS
2849 PDR *pdr_in;
2850 PDR *pdr_in_end;
2851
2852 pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
2853
2854 old_chain = make_cleanup (free, pr_block);
2855
6ac14d25
PS
2856 pdr_ptr = ((char *) ecoff_data (cur_bfd)->external_pdr
2857 + fh->ipdFirst * external_pdr_size);
2858 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
6c2e7392 2859 pdr_in = pr_block;
6ac14d25
PS
2860 for (;
2861 pdr_ptr < pdr_end;
2862 pdr_ptr += external_pdr_size, pdr_in++)
2863 (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
6c2e7392 2864
99a15c64 2865 parse_lines (fh, pr_block, lines, maxlines);
6c2e7392
PS
2866 if (lines->nitems < fh->cline)
2867 lines = shrink_linetable (lines);
2868
2869 /* Fill in procedure info next. */
2870 pdr_in = pr_block;
2871 pdr_in_end = pdr_in + fh->cpd;
2872 for (; pdr_in < pdr_in_end; pdr_in++)
2873 parse_procedure (pdr_in, 0, pr_block->adr);
2874
2875 do_cleanups (old_chain);
817bc7b8 2876 }
ad142b8e 2877 }
817bc7b8 2878
5f7b2142
ILT
2879 LINETABLE (st) = lines;
2880
2881 /* .. and our share of externals.
2882 XXX use the global list to speed up things here. how?
2883 FIXME, Maybe quit once we have found the right number of ext's? */
2884 top_stack->cur_st = st;
2885 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
2886 GLOBAL_BLOCK);
2887 top_stack->blocktype = stFile;
6c2e7392
PS
2888 top_stack->maxsyms = (ecoff_data (cur_bfd)->symbolic_header.isymMax
2889 + ecoff_data (cur_bfd)->symbolic_header.ipdMax
2890 + ecoff_data (cur_bfd)->symbolic_header.iextMax);
5f7b2142
ILT
2891
2892 ext_ptr = PST_PRIVATE (pst)->extern_tab;
2893 for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
6c2e7392 2894 parse_external (ext_ptr, 1, fh->fBigendian);
5f7b2142 2895
99a15c64
PS
2896 /* If there are undefined symbols, tell the user.
2897 The alpha has an undefined symbol for every symbol that is
2898 from a shared library, so tell the user only if verbose is on. */
2899 if (info_verbose && n_undef_symbols)
5f7b2142
ILT
2900 {
2901 printf_filtered ("File %s contains %d unresolved references:",
2902 st->filename, n_undef_symbols);
2903 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2904 n_undef_vars, n_undef_procs, n_undef_labels);
2905 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
bd5635a1 2906
7e258d18 2907 }
5f7b2142 2908 pop_parse_stack ();
817bc7b8 2909
5f7b2142
ILT
2910 /* Sort the symbol table now, we are done adding symbols to it.*/
2911 sort_symtab_syms (st);
817bc7b8 2912
5f7b2142 2913 sort_blocks (st);
7e258d18 2914 }
7e258d18 2915
5f7b2142
ILT
2916 /* Now link the psymtab and the symtab. */
2917 pst->symtab = st;
021959e2 2918
5f7b2142 2919 current_objfile = NULL;
101f259c 2920}
bd5635a1
RP
2921\f
2922/* Ancillary parsing procedures. */
2923
2924/* Lookup the type at relative index RN. Return it in TPP
2925 if found and in any event come up with its name PNAME.
d747e0af
MT
2926 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2927 Return value says how many aux symbols we ate. */
bd5635a1 2928
d747e0af 2929static int
85999c05
PS
2930cross_ref (fd, ax, tpp, type_code, pname, bigend, sym_name)
2931 int fd;
d747e0af 2932 union aux_ext *ax;
7e258d18 2933 struct type **tpp;
5f7b2142 2934 enum type_code type_code; /* Use to alloc new type if none is found. */
7e258d18 2935 char **pname;
d747e0af 2936 int bigend;
cbba020f 2937 char *sym_name;
bd5635a1 2938{
5f7b2142 2939 RNDXR rn[1];
6ac14d25 2940 unsigned int rf;
5f7b2142 2941 int result = 1;
85999c05
PS
2942 FDR *fh;
2943 char *esh;
2944 SYMR sh;
2945 int xref_fd;
2946 struct mips_pending *pend;
2947
2948 *tpp = (struct type *)NULL;
bd5635a1 2949
6c2e7392 2950 ecoff_swap_rndx_in (bigend, &ax->a_rndx, rn);
5f7b2142
ILT
2951
2952 /* Escape index means 'the next one' */
2953 if (rn->rfd == 0xfff)
2954 {
2955 result++;
2956 rf = AUX_GET_ISYM (bigend, ax + 1);
2957 }
2958 else
2959 {
2960 rf = rn->rfd;
2961 }
2962
85999c05
PS
2963 /* mips cc uses a rf of -1 for opaque struct definitions.
2964 Set TYPE_FLAG_STUB for these types so that check_stub_type will
2965 resolve them if the struct gets defined in another compilation unit. */
5f7b2142
ILT
2966 if (rf == -1)
2967 {
5f7b2142 2968 *pname = "<undefined>";
85999c05
PS
2969 *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
2970 TYPE_FLAGS (*tpp) |= TYPE_FLAG_STUB;
2971 return result;
5f7b2142 2972 }
85999c05
PS
2973
2974 /* mips cc uses an escaped rn->index of 0 for struct return types
2975 of procedures that were compiled without -g. These will always remain
2976 undefined. */
2977 if (rn->rfd == 0xfff && rn->index == 0)
5f7b2142 2978 {
85999c05
PS
2979 *pname = "<undefined>";
2980 return result;
2981 }
5f7b2142 2982
85999c05
PS
2983 /* Find the relative file descriptor and the symbol in it. */
2984 fh = get_rfd (fd, rf);
2985 xref_fd = fh - ecoff_data (cur_bfd)->fdr;
6ac14d25 2986
85999c05
PS
2987 if (rn->index >= fh->csym)
2988 {
2989 /* File indirect entry is corrupt. */
2990 *pname = "<illegal>";
2991 complain (&bad_rfd_entry_complaint,
2992 sym_name, xref_fd, rn->index);
2993 return result;
2994 }
2995
2996 /* If we have processed this symbol then we left a forwarding
2997 pointer to the type in the pending list. If not, we`ll put
2998 it in a list of pending types, to be processed later when
2999 the file will be. In any event, we collect the name for the
3000 type here. */
3001
3002 esh = ((char *) ecoff_data (cur_bfd)->external_sym
3003 + ((fh->isymBase + rn->index)
3004 * ecoff_backend (cur_bfd)->external_sym_size));
3005 (*ecoff_backend (cur_bfd)->swap_sym_in) (cur_bfd, esh, &sh);
3006
3007 /* Make sure that this type of cross reference can be handled. */
3008 if (sh.sc != scInfo
3009 || (sh.st != stBlock && sh.st != stTypedef
3010 && sh.st != stStruct && sh.st != stUnion
3011 && sh.st != stEnum))
3012 {
3013 /* File indirect entry is corrupt. */
3014 *pname = "<illegal>";
3015 complain (&bad_rfd_entry_complaint,
3016 sym_name, xref_fd, rn->index);
3017 return result;
3018 }
3019
3020 *pname = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
3021
3022 pend = is_pending_symbol (fh, esh);
3023 if (pend)
3024 *tpp = pend->t;
3025 else
3026 {
3027 /* We have not yet seen this type. */
3028
3029 if (sh.iss == 0 && sh.st == stTypedef)
6ac14d25 3030 {
85999c05
PS
3031 TIR tir;
3032
3033 /* alpha cc puts out a stTypedef with a sh.iss of zero for
3034 two cases:
3035 a) forward declarations of structs/unions/enums which are not
3036 defined in this compilation unit.
3037 For these the type will be void. This is a bad design decision
3038 as cross referencing across compilation units is impossible
3039 due to the missing name.
3040 b) forward declarations of structs/unions/enums which are defined
3041 later in this file or in another file in the same compilation
3042 unit. Simply cross reference those again to get the
3043 true type.
3044 The forward references are not entered in the pending list and
3045 in the symbol table. */
3046
3047 ecoff_swap_tir_in (bigend,
3048 &(ecoff_data (cur_bfd)->external_aux
3049 + fh->iauxBase + sh.index)->a_ti,
3050 &tir);
3051 if (tir.tq0 != tqNil)
3052 complain (&illegal_forward_tq0_complaint, sym_name);
3053 switch (tir.bt)
3054 {
3055 case btVoid:
3056 *tpp = init_type (type_code, 0, 0, (char *) NULL,
3057 current_objfile);
3058 *pname = "<undefined>";
3059 break;
3060
3061 case btStruct:
3062 case btUnion:
3063 case btEnum:
3064 cross_ref (xref_fd,
3065 (ecoff_data (cur_bfd)->external_aux
3066 + fh->iauxBase + sh.index + 1),
3067 tpp, type_code, pname,
3068 fh->fBigendian, sym_name);
3069 break;
3070
3071 default:
3072 complain (&illegal_forward_bt_complaint, tir.bt, sym_name);
3073 *tpp = init_type (type_code, 0, 0, (char *) NULL,
3074 current_objfile);
3075 break;
3076 }
6ac14d25
PS
3077 return result;
3078 }
85999c05 3079 else if (sh.st == stTypedef)
5f7b2142 3080 {
85999c05
PS
3081 /* Parse the type for a normal typedef. This might recursively call
3082 cross_ref till we get a non typedef'ed type.
3083 FIXME: This is not correct behaviour, but gdb currently
3084 cannot handle typedefs without type copying. But type copying is
3085 impossible as we might have mutual forward references between
3086 two files and the copied type would not get filled in when
3087 we later parse its definition. */
3088 *tpp = parse_type (xref_fd,
99a15c64
PS
3089 ecoff_data (cur_bfd)->external_aux + fh->iauxBase,
3090 sh.index,
85999c05
PS
3091 (int *)NULL,
3092 fh->fBigendian,
3093 (ecoff_data (cur_bfd)->ss
3094 + fh->issBase + sh.iss));
bd5635a1 3095 }
5f7b2142
ILT
3096 else
3097 {
85999c05
PS
3098 /* Cross reference to a struct/union/enum which is defined
3099 in another file in the same compilation unit but that file
3100 has not been parsed yet.
3101 Initialize the type only, it will be filled in when
3102 it's definition is parsed. */
3103 *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
5f7b2142 3104 }
85999c05 3105 add_pending (fh, esh, *tpp);
5f7b2142 3106 }
3eaebb75 3107
5f7b2142
ILT
3108 /* We used one auxent normally, two if we got a "next one" rf. */
3109 return result;
bd5635a1
RP
3110}
3111
3112
3113/* Quick&dirty lookup procedure, to avoid the MI ones that require
3114 keeping the symtab sorted */
3115
3116static struct symbol *
3117mylookup_symbol (name, block, namespace, class)
3118 char *name;
3119 register struct block *block;
3120 enum namespace namespace;
3121 enum address_class class;
3122{
5f7b2142
ILT
3123 register int bot, top, inc;
3124 register struct symbol *sym;
3125
3126 bot = 0;
3127 top = BLOCK_NSYMS (block);
3128 inc = name[0];
3129 while (bot < top)
3130 {
3131 sym = BLOCK_SYM (block, bot);
3132 if (SYMBOL_NAME (sym)[0] == inc
3133 && SYMBOL_NAMESPACE (sym) == namespace
3134 && SYMBOL_CLASS (sym) == class
4fb0ff3b 3135 && strcmp (SYMBOL_NAME (sym), name) == 0)
5f7b2142
ILT
3136 return sym;
3137 bot++;
3138 }
3139 block = BLOCK_SUPERBLOCK (block);
3140 if (block)
3141 return mylookup_symbol (name, block, namespace, class);
3142 return 0;
bd5635a1
RP
3143}
3144
3145
3eaebb75
SG
3146/* Add a new symbol S to a block B.
3147 Infrequently, we will need to reallocate the block to make it bigger.
3148 We only detect this case when adding to top_stack->cur_block, since
3149 that's the only time we know how big the block is. FIXME. */
bd5635a1 3150
3eaebb75 3151static void
5f7b2142
ILT
3152add_symbol (s, b)
3153 struct symbol *s;
3154 struct block *b;
bd5635a1 3155{
5f7b2142
ILT
3156 int nsyms = BLOCK_NSYMS (b)++;
3157 struct block *origb;
3158 struct parse_stack *stackp;
3159
3160 if (b == top_stack->cur_block &&
3161 nsyms >= top_stack->maxsyms)
3162 {
3163 complain (&block_overflow_complaint, SYMBOL_NAME (s));
3164 /* In this case shrink_block is actually grow_block, since
3eaebb75 3165 BLOCK_NSYMS(b) is larger than its current size. */
5f7b2142
ILT
3166 origb = b;
3167 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
3168
3169 /* Now run through the stack replacing pointers to the
3170 original block. shrink_block has already done this
3171 for the blockvector and BLOCK_FUNCTION. */
3172 for (stackp = top_stack; stackp; stackp = stackp->next)
3173 {
3174 if (stackp->cur_block == origb)
3175 {
3176 stackp->cur_block = b;
3177 stackp->maxsyms = BLOCK_NSYMS (b);
3178 }
3eaebb75 3179 }
5f7b2142
ILT
3180 }
3181 BLOCK_SYM (b, nsyms) = s;
bd5635a1
RP
3182}
3183
3184/* Add a new block B to a symtab S */
3185
3eaebb75 3186static void
5f7b2142
ILT
3187add_block (b, s)
3188 struct block *b;
3189 struct symtab *s;
bd5635a1 3190{
5f7b2142 3191 struct blockvector *bv = BLOCKVECTOR (s);
bd5635a1 3192
5f7b2142 3193 bv = (struct blockvector *) xrealloc ((PTR) bv,
6c2e7392
PS
3194 (sizeof (struct blockvector)
3195 + BLOCKVECTOR_NBLOCKS (bv)
3196 * sizeof (bv->block)));
5f7b2142
ILT
3197 if (bv != BLOCKVECTOR (s))
3198 BLOCKVECTOR (s) = bv;
bd5635a1 3199
5f7b2142 3200 BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
bd5635a1
RP
3201}
3202
3203/* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3204 MIPS' linenumber encoding might need more than one byte
e157305c
PS
3205 to describe it, LAST is used to detect these continuation lines.
3206
3207 Combining lines with the same line number seems like a bad idea.
3208 E.g: There could be a line number entry with the same line number after the
3209 prologue and GDB should not ignore it (this is a better way to find
3210 a prologue than mips_skip_prologue).
3211 But due to the compressed line table format there are line number entries
3212 for the same line which are needed to bridge the gap to the next
3213 line number entry. These entries have a bogus address info with them
3214 and we are unable to tell them from intended duplicate line number
3215 entries.
3216 This is another reason why -ggdb debugging format is preferable. */
bd5635a1 3217
3eaebb75 3218static int
5f7b2142
ILT
3219add_line (lt, lineno, adr, last)
3220 struct linetable *lt;
3221 int lineno;
3222 CORE_ADDR adr;
3223 int last;
bd5635a1 3224{
5f7b2142
ILT
3225 if (last == 0)
3226 last = -2; /* make sure we record first line */
bd5635a1 3227
5f7b2142
ILT
3228 if (last == lineno) /* skip continuation lines */
3229 return lineno;
bd5635a1 3230
5f7b2142
ILT
3231 lt->item[lt->nitems].line = lineno;
3232 lt->item[lt->nitems++].pc = adr << 2;
3233 return lineno;
bd5635a1 3234}
bd5635a1 3235\f
84ffdec2 3236/* Sorting and reordering procedures */
bd5635a1 3237
bd5635a1
RP
3238/* Blocks with a smaller low bound should come first */
3239
84ffdec2 3240static int
5f7b2142 3241compare_blocks (arg1, arg2)
99a15c64
PS
3242 const PTR arg1;
3243 const PTR arg2;
bd5635a1 3244{
5f7b2142
ILT
3245 register int addr_diff;
3246 struct block **b1 = (struct block **) arg1;
3247 struct block **b2 = (struct block **) arg2;
3248
3249 addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
3250 if (addr_diff == 0)
5f5341a7 3251 return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
5f7b2142 3252 return addr_diff;
bd5635a1
RP
3253}
3254
bd5635a1
RP
3255/* Sort the blocks of a symtab S.
3256 Reorder the blocks in the blockvector by code-address,
3257 as required by some MI search routines */
3258
e072c738 3259static void
5f7b2142
ILT
3260sort_blocks (s)
3261 struct symtab *s;
bd5635a1 3262{
5f7b2142 3263 struct blockvector *bv = BLOCKVECTOR (s);
bd5635a1 3264
5f7b2142
ILT
3265 if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
3266 {
3267 /* Cosmetic */
3268 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
3269 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
3270 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
3271 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
3272 return;
3273 }
3274 /*
3275 * This is very unfortunate: normally all functions are compiled in
3276 * the order they are found, but if the file is compiled -O3 things
3277 * are very different. It would be nice to find a reliable test
3278 * to detect -O3 images in advance.
3279 */
3280 if (BLOCKVECTOR_NBLOCKS (bv) > 3)
3281 qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
3282 BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
3283 sizeof (struct block *),
3284 compare_blocks);
3285
3286 {
3287 register CORE_ADDR high = 0;
3288 register int i, j = BLOCKVECTOR_NBLOCKS (bv);
3289
3290 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
3291 if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
3292 high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
3293 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
3294 }
3295
3296 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
3297 BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
3298
3299 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
3300 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
3301 BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
3302 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
bd5635a1 3303}
bd5635a1 3304\f
5f7b2142 3305
bd5635a1
RP
3306/* Constructor/restructor/destructor procedures */
3307
3308/* Allocate a new symtab for NAME. Needs an estimate of how many symbols
3309 MAXSYMS and linenumbers MAXLINES we'll put in it */
3310
4ad1963e 3311static struct symtab *
5f7b2142
ILT
3312new_symtab (name, maxsyms, maxlines, objfile)
3313 char *name;
3314 int maxsyms;
3315 int maxlines;
3316 struct objfile *objfile;
bd5635a1 3317{
021959e2 3318 struct symtab *s = allocate_symtab (name, objfile);
bd5635a1 3319
5f7b2142 3320 LINETABLE (s) = new_linetable (maxlines);
bd5635a1 3321
021959e2 3322 /* All symtabs must have at least two blocks */
5f7b2142
ILT
3323 BLOCKVECTOR (s) = new_bvect (2);
3324 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
3325 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
3326 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
3327 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
bd5635a1 3328
021959e2 3329 s->free_code = free_linetable;
bd5635a1 3330
021959e2 3331 return (s);
bd5635a1
RP
3332}
3333
bd5635a1
RP
3334/* Allocate a new partial_symtab NAME */
3335
3336static struct partial_symtab *
5f7b2142
ILT
3337new_psymtab (name, objfile)
3338 char *name;
3339 struct objfile *objfile;
bd5635a1 3340{
021959e2 3341 struct partial_symtab *psymtab;
817bc7b8 3342
6c2e7392 3343 psymtab = allocate_psymtab (name, objfile);
817bc7b8 3344
021959e2 3345 /* Keep a backpointer to the file's symbols */
bd5635a1 3346
5f7b2142
ILT
3347 psymtab->read_symtab_private = ((char *)
3348 obstack_alloc (&objfile->psymbol_obstack,
3349 sizeof (struct symloc)));
6c2e7392
PS
3350 memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
3351 CUR_BFD (psymtab) = cur_bfd;
817bc7b8 3352
021959e2
JG
3353 /* The way to turn this into a symtab is to call... */
3354 psymtab->read_symtab = mipscoff_psymtab_to_symtab;
3355 return (psymtab);
bd5635a1
RP
3356}
3357
3358
84ffdec2 3359/* Allocate a linetable array of the given SIZE. Since the struct
817bc7b8 3360 already includes one item, we subtract one when calculating the
84ffdec2 3361 proper size to allocate. */
bd5635a1 3362
7e258d18 3363static struct linetable *
5f7b2142
ILT
3364new_linetable (size)
3365 int size;
bd5635a1 3366{
5f7b2142 3367 struct linetable *l;
bd5635a1 3368
5f7b2142
ILT
3369 size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
3370 l = (struct linetable *) xmalloc (size);
3371 l->nitems = 0;
3372 return l;
bd5635a1
RP
3373}
3374
3375/* Oops, too big. Shrink it. This was important with the 2.4 linetables,
84ffdec2
JG
3376 I am not so sure about the 3.4 ones.
3377
3378 Since the struct linetable already includes one item, we subtract one when
3379 calculating the proper size to allocate. */
bd5635a1 3380
7e258d18 3381static struct linetable *
5f7b2142
ILT
3382shrink_linetable (lt)
3383 struct linetable *lt;
bd5635a1 3384{
bd5635a1 3385
5f7b2142 3386 return (struct linetable *) xrealloc ((PTR) lt,
6c2e7392
PS
3387 (sizeof (struct linetable)
3388 + ((lt->nitems - 1)
3389 * sizeof (lt->item))));
bd5635a1
RP
3390}
3391
3392/* Allocate and zero a new blockvector of NBLOCKS blocks. */
3393
4ad1963e 3394static struct blockvector *
5f7b2142
ILT
3395new_bvect (nblocks)
3396 int nblocks;
bd5635a1 3397{
5f7b2142
ILT
3398 struct blockvector *bv;
3399 int size;
bd5635a1 3400
5f7b2142
ILT
3401 size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
3402 bv = (struct blockvector *) xzalloc (size);
bd5635a1 3403
5f7b2142 3404 BLOCKVECTOR_NBLOCKS (bv) = nblocks;
bd5635a1 3405
5f7b2142 3406 return bv;
bd5635a1
RP
3407}
3408
3409/* Allocate and zero a new block of MAXSYMS symbols */
3410
4ad1963e 3411static struct block *
5f7b2142
ILT
3412new_block (maxsyms)
3413 int maxsyms;
bd5635a1 3414{
5f7b2142 3415 int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
bd5635a1 3416
5f7b2142 3417 return (struct block *) xzalloc (size);
bd5635a1
RP
3418}
3419
3eaebb75
SG
3420/* Ooops, too big. Shrink block B in symtab S to its minimal size.
3421 Shrink_block can also be used by add_symbol to grow a block. */
bd5635a1
RP
3422
3423static struct block *
5f7b2142
ILT
3424shrink_block (b, s)
3425 struct block *b;
3426 struct symtab *s;
bd5635a1 3427{
5f7b2142
ILT
3428 struct block *new;
3429 struct blockvector *bv = BLOCKVECTOR (s);
3430 int i;
bd5635a1 3431
5f7b2142 3432 /* Just reallocate it and fix references to the old one */
bd5635a1 3433
6c2e7392
PS
3434 new = (struct block *) xrealloc ((PTR) b,
3435 (sizeof (struct block)
3436 + ((BLOCK_NSYMS (b) - 1)
3437 * sizeof (struct symbol *))));
bd5635a1 3438
5f7b2142 3439 /* Should chase pointers to old one. Fortunately, that`s just
bd5635a1 3440 the block`s function and inferior blocks */
5f7b2142
ILT
3441 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
3442 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3443 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
3444 if (BLOCKVECTOR_BLOCK (bv, i) == b)
3445 BLOCKVECTOR_BLOCK (bv, i) = new;
3446 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
3447 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
3448 return new;
bd5635a1
RP
3449}
3450
3451/* Create a new symbol with printname NAME */
3452
4ad1963e 3453static struct symbol *
5f7b2142
ILT
3454new_symbol (name)
3455 char *name;
bd5635a1 3456{
6c2e7392
PS
3457 struct symbol *s = ((struct symbol *)
3458 obstack_alloc (&current_objfile->symbol_obstack,
3459 sizeof (struct symbol)));
bd5635a1 3460
5f7b2142
ILT
3461 memset ((PTR) s, 0, sizeof (*s));
3462 SYMBOL_NAME (s) = name;
018ab14f
PS
3463 SYMBOL_LANGUAGE (s) = psymtab_language;
3464 SYMBOL_INIT_DEMANGLED_NAME (s, &current_objfile->symbol_obstack);
5f7b2142 3465 return s;
bd5635a1
RP
3466}
3467
3468/* Create a new type with printname NAME */
3469
4ad1963e 3470static struct type *
5f7b2142
ILT
3471new_type (name)
3472 char *name;
bd5635a1 3473{
5f7b2142 3474 struct type *t;
bd5635a1 3475
5f7b2142
ILT
3476 t = alloc_type (current_objfile);
3477 TYPE_NAME (t) = name;
6c2e7392 3478 TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
5f7b2142 3479 return t;
bd5635a1 3480}
bd5635a1 3481\f
5f7b2142 3482
bd5635a1
RP
3483/* Things used for calling functions in the inferior.
3484 These functions are exported to our companion
7e258d18 3485 mips-tdep.c file and are here because they play
bd5635a1
RP
3486 with the symbol-table explicitly. */
3487
bd5635a1
RP
3488/* Sigtramp: make sure we have all the necessary information
3489 about the signal trampoline code. Since the official code
3490 from MIPS does not do so, we make up that information ourselves.
3491 If they fix the library (unlikely) this code will neutralize itself. */
3492
d747e0af 3493static void
5f7b2142 3494fixup_sigtramp ()
bd5635a1 3495{
5f7b2142
ILT
3496 struct symbol *s;
3497 struct symtab *st;
e7bf1152 3498 struct block *b, *b0 = NULL;
bd5635a1 3499
5f7b2142 3500 sigtramp_address = -1;
bd5635a1 3501
7cf92dd2
PS
3502 /* We have to handle the following cases here:
3503 a) The Mips library has a sigtramp label within sigvec.
3504 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
5f7b2142 3505 s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL);
7cf92dd2 3506 if (s != 0)
5f7b2142
ILT
3507 {
3508 b0 = SYMBOL_BLOCK_VALUE (s);
5f7b2142
ILT
3509 s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
3510 }
7cf92dd2
PS
3511 if (s == 0)
3512 {
3513 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
3514 s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
3515 }
4ad1963e 3516
5f7b2142
ILT
3517 /* But maybe this program uses its own version of sigvec */
3518 if (s == 0)
3519 return;
bd5635a1 3520
5f7b2142
ILT
3521 /* Did we or MIPSco fix the library ? */
3522 if (SYMBOL_CLASS (s) == LOC_BLOCK)
3523 {
3524 sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s));
3525 sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s));
3526 return;
3527 }
bd5635a1 3528
5f7b2142
ILT
3529 sigtramp_address = SYMBOL_VALUE (s);
3530 sigtramp_end = sigtramp_address + 0x88; /* black magic */
3531
3532 /* But what symtab does it live in ? */
3533 st = find_pc_symtab (SYMBOL_VALUE (s));
3534
3535 /*
3536 * Ok, there goes the fix: turn it into a procedure, with all the
3537 * needed info. Note we make it a nested procedure of sigvec,
3538 * which is the way the (assembly) code is actually written.
3539 */
3540 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
3541 SYMBOL_CLASS (s) = LOC_BLOCK;
3542 SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL,
85999c05 3543 st->objfile);
5f7b2142
ILT
3544 TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = builtin_type_void;
3545
3546 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3547 b = new_block (1);
3548 SYMBOL_BLOCK_VALUE (s) = b;
3549 BLOCK_START (b) = sigtramp_address;
3550 BLOCK_END (b) = sigtramp_end;
3551 BLOCK_FUNCTION (b) = s;
3552 BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
3553 add_block (b, st);
3554 sort_blocks (st);
3555
3556 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3557 {
3558 struct mips_extra_func_info *e =
3559 ((struct mips_extra_func_info *)
3560 xzalloc (sizeof (struct mips_extra_func_info)));
3561
3562 e->numargs = 0; /* the kernel thinks otherwise */
3563 /* align_longword(sigcontext + SIGFRAME) */
3564 e->pdr.frameoffset = 0x150;
3565 e->pdr.framereg = SP_REGNUM;
e157305c
PS
3566 /* read_next_frame_reg provides the true pc at the time of signal */
3567 e->pdr.pcreg = PC_REGNUM;
5f7b2142
ILT
3568 e->pdr.regmask = -2;
3569 e->pdr.regoffset = -(41 * sizeof (int));
3570 e->pdr.fregmask = -1;
e157305c 3571 e->pdr.fregoffset = -(7 * sizeof (int));
5f7b2142 3572 e->pdr.isym = (long) s;
579f0258 3573 e->pdr.adr = sigtramp_address;
5f7b2142
ILT
3574
3575 current_objfile = st->objfile; /* Keep new_symbol happy */
3576 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
85999c05 3577 SYMBOL_VALUE (s) = (long) e;
5f7b2142
ILT
3578 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
3579 SYMBOL_CLASS (s) = LOC_CONST;
3580 SYMBOL_TYPE (s) = builtin_type_void;
3581 current_objfile = NULL;
3582 }
bd5635a1 3583
5f7b2142 3584 BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s;
bd5635a1 3585}
dac4929a
SG
3586
3587
3588/* Fake up identical offsets for all sections. */
3589
3590struct section_offsets *
3591mipscoff_symfile_offsets (objfile, addr)
3592 struct objfile *objfile;
3593 CORE_ADDR addr;
3594{
3595 struct section_offsets *section_offsets;
3596 int i;
3597
5f7b2142
ILT
3598 section_offsets = ((struct section_offsets *)
3599 obstack_alloc (&objfile->psymbol_obstack,
3600 (sizeof (struct section_offsets)
3601 + (sizeof (section_offsets->offsets)
3602 * (SECT_OFF_MAX - 1)))));
dac4929a
SG
3603
3604 for (i = 0; i < SECT_OFF_MAX; i++)
3605 ANOFFSET (section_offsets, i) = addr;
3606
3607 return section_offsets;
3608}
bd5635a1
RP
3609\f
3610/* Initialization */
3611
80d68b1d
FF
3612static struct sym_fns ecoff_sym_fns =
3613{
5f7b2142
ILT
3614 "ecoff", /* sym_name: name or name prefix of BFD target type */
3615 5, /* sym_namelen: number of significant sym_name chars */
3616 mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
3617 mipscoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
3618 mipscoff_symfile_read, /* sym_read: read a symbol file into symtab */
3619 mipscoff_symfile_finish, /* sym_finish: finished with file, cleanup */
3620 mipscoff_symfile_offsets, /* sym_offsets: dummy FIXME til implem sym reloc */
3621 NULL /* next: pointer to next struct sym_fns */
80d68b1d
FF
3622};
3623
bd5635a1 3624
4ad1963e 3625void
bd5635a1
RP
3626_initialize_mipsread ()
3627{
5f7b2142
ILT
3628 add_symtab_fns (&ecoff_sym_fns);
3629
3630 /* Missing basic types */
3631
3632 builtin_type_string =
3633 init_type (TYPE_CODE_STRING,
3634 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3635 0, "string",
3636 (struct objfile *) NULL);
3637 builtin_type_complex =
3638 init_type (TYPE_CODE_FLT,
3639 TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
3640 0, "complex",
3641 (struct objfile *) NULL);
3642 builtin_type_double_complex =
3643 init_type (TYPE_CODE_FLT,
3644 TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
3645 0, "double complex",
3646 (struct objfile *) NULL);
3647 builtin_type_fixed_dec =
3648 init_type (TYPE_CODE_INT,
3649 TARGET_INT_BIT / TARGET_CHAR_BIT,
3650 0, "fixed decimal",
3651 (struct objfile *) NULL);
3652 builtin_type_float_dec =
3653 init_type (TYPE_CODE_FLT,
3654 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3655 0, "floating decimal",
3656 (struct objfile *) NULL);
bd5635a1 3657}
This page took 0.333074 seconds and 4 git commands to generate.