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