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