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