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