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