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