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