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