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