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