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