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