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