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