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