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