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