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