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