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