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