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