* mipsread.c (parse_symbol): Avoid clobbering enum pointer when
[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 there is more than one member, and all
1051 the members have offset 0, 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 (nfields > 1 && max_value == 0)
1070 type_code = TYPE_CODE_UNION;
1071 else
1072 type_code = TYPE_CODE_STRUCT;
1073
1074 /* If this type was expected, use its partial definition */
1075 if (pend)
1076 t = is_pending_symbol(cur_fdr, sh)->t;
1077 else
1078 t = new_type(prepend_tag_kind(sh->iss, type_code));
1079
1080 TYPE_CODE(t) = type_code;
1081 TYPE_LENGTH(t) = sh->value;
1082 TYPE_NFIELDS(t) = nfields;
1083 TYPE_FIELDS(t) = f = (struct field*)
1084 obstack_alloc (symbol_obstack,
1085 nfields * sizeof (struct field));
1086
1087 if (type_code == TYPE_CODE_ENUM) {
1088 /* This is a non-empty enum. */
1089 for (tsym = sh + 1; tsym->st == stMember; tsym++) {
1090 struct symbol *enum_sym;
1091 f->bitpos = tsym->value;
1092 f->type = t;
1093 f->name = (char*)tsym->iss;
1094 f->bitsize = 0;
1095
1096 enum_sym = (struct symbol *)
1097 obstack_alloc (symbol_obstack,
1098 sizeof (struct symbol));
1099 memset (enum_sym, 0, sizeof (struct symbol));
1100 SYMBOL_NAME (enum_sym) = f->name;
1101 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1102 SYMBOL_TYPE (enum_sym) = t;
1103 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1104 SYMBOL_VALUE (enum_sym) = tsym->value;
1105 add_symbol(enum_sym, top_stack->cur_block);
1106
1107 /* Skip the stMembers that we've handled. */
1108 count++;
1109 f++;
1110 }
1111 }
1112 SYMBOL_TYPE(s) = t;
1113 /* make this the current type */
1114 top_stack->cur_type = t;
1115 top_stack->cur_field = 0;
1116 /* Mark that symbol has a type, and say which one */
1117 sh->value = (long) t;
1118 } else {
1119 /* beginnning of (code) block. Value of symbol
1120 is the displacement from procedure start */
1121 b = new_block(top_stack->maxsyms);
1122 BLOCK_START(b) = sh->value + top_stack->procadr;
1123 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1124 top_stack->cur_block = b;
1125 add_block(b, top_stack->cur_st);
1126 }
1127 break;
1128
1129 case stEnd: /* end (of anything) */
1130 if (sh->sc == scInfo) {
1131 /* Finished with type */
1132 top_stack->cur_type = 0;
1133 } else if (sh->sc == scText &&
1134 (top_stack->blocktype == stProc ||
1135 top_stack->blocktype == stStaticProc)) {
1136 /* Finished with procedure */
1137 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
1138 struct block *b;
1139 int i;
1140
1141 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
1142 got_numargs(top_stack->procadr, top_stack->numargs);
1143 /* Reallocate symbols, saving memory */
1144 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
1145
1146 /* f77 emits proc-level with address bounds==[0,0],
1147 So look for such child blocks, and patch them. */
1148 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
1149 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
1150 if (BLOCK_SUPERBLOCK(b_bad) == b
1151 && BLOCK_START(b_bad) == top_stack->procadr
1152 && BLOCK_END(b_bad) == top_stack->procadr) {
1153 BLOCK_START(b_bad) = BLOCK_START(b);
1154 BLOCK_END(b_bad) = BLOCK_END(b);
1155 }
1156 }
1157 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
1158 /* End of (code) block. The value of the symbol
1159 is the displacement from the procedure`s start
1160 address of the end of this block. */
1161 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
1162 (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
1163 }
1164 pop_parse_stack(); /* restore previous lexical context */
1165 break;
1166
1167 case stMember: /* member of struct or union */
1168 f = &TYPE_FIELDS(top_stack->cur_type)[top_stack->cur_field++];
1169 f->name = (char*)sh->iss;
1170 f->bitpos = sh->value;
1171 f->bitsize = 0;
1172 f->type = parse_type(ax + sh->index, sh, &f->bitsize);
1173 break;
1174
1175 case stTypedef: /* type definition */
1176 s = new_symbol(sh->iss);
1177 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1178 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1179 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
1180 add_symbol(s, top_stack->cur_block);
1181 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
1182 sh->value = (long) SYMBOL_TYPE(s);
1183 break;
1184
1185 case stFile: /* file name */
1186 push_parse_stack();
1187 top_stack->blocktype = sh->st;
1188 break;
1189
1190 /* I`ve never seen these for C */
1191 case stRegReloc:
1192 break; /* register relocation */
1193 case stForward:
1194 break; /* forwarding address */
1195 case stConstant:
1196 break; /* constant */
1197 default:
1198 error("Unknown symbol type %x.", sh->st);
1199 }
1200 sh->st = stParsed;
1201 return count;
1202 }
1203
1204 /* Parse the type information provided in the AX entries for
1205 the symbol SH. Return the bitfield size in BS, in case. */
1206
1207 static struct type *parse_type(ax, sh, bs)
1208 AUXU *ax;
1209 SYMR *sh;
1210 int *bs;
1211 {
1212 /* Null entries in this map are treated specially */
1213 static struct type **map_bt[] =
1214 {
1215 &builtin_type_void, /* btNil */
1216 0, /* btAdr */
1217 &builtin_type_char, /* btChar */
1218 &builtin_type_unsigned_char, /* btUChar */
1219 &builtin_type_short, /* btShort */
1220 &builtin_type_unsigned_short, /* btUShort */
1221 &builtin_type_int, /* btInt */
1222 &builtin_type_unsigned_int, /* btUInt */
1223 &builtin_type_long, /* btLong */
1224 &builtin_type_unsigned_long, /* btULong */
1225 &builtin_type_float, /* btFloat */
1226 &builtin_type_double, /* btDouble */
1227 0, /* btStruct */
1228 0, /* btUnion */
1229 0, /* btEnum */
1230 0, /* btTypedef */
1231 0, /* btRange */
1232 0, /* btSet */
1233 &builtin_type_complex, /* btComplex */
1234 &builtin_type_double_complex, /* btDComplex */
1235 0, /* btIndirect */
1236 &builtin_type_fixed_dec, /* btFixedDec */
1237 &builtin_type_float_dec, /* btFloatDec */
1238 &builtin_type_string, /* btString */
1239 0, /* btBit */
1240 0, /* btPicture */
1241 &builtin_type_void, /* btVoid */
1242 };
1243
1244 TIR *t;
1245 struct type *tp = 0;
1246 char *fmt;
1247 int i;
1248 int type_code;
1249
1250 /* Procedures start off by one */
1251 if (sh->st == stProc || sh->st == stStaticProc)
1252 ax++;
1253
1254 /* Undefined ? Should not happen */
1255 if (ax->rndx.rfd == 0xfff) {
1256 return builtin_type_void;
1257 }
1258
1259 /* Use aux as a type information record, map its basic type */
1260 t = &ax->ti;
1261 if (t->bt > (sizeof (map_bt)/sizeof (*map_bt))) {
1262 complain (&basic_type_complaint, t->bt);
1263 return builtin_type_int;
1264 }
1265 if (map_bt[t->bt]) {
1266 tp = *map_bt[t->bt];
1267 fmt = "%s";
1268 } else {
1269 tp = NULL;
1270 /* Cannot use builtin types -- build our own */
1271 switch (t->bt) {
1272 case btAdr:
1273 tp = lookup_pointer_type (builtin_type_void);
1274 fmt = "%s";
1275 break;
1276 case btStruct:
1277 type_code = TYPE_CODE_STRUCT;
1278 fmt = "struct %s";
1279 break;
1280 case btUnion:
1281 type_code = TYPE_CODE_UNION;
1282 fmt = "union %s";
1283 break;
1284 case btEnum:
1285 type_code = TYPE_CODE_ENUM;
1286 fmt = "enum %s";
1287 break;
1288 case btRange:
1289 type_code = TYPE_CODE_RANGE;
1290 fmt = "%s";
1291 break;
1292 case btSet:
1293 type_code = TYPE_CODE_SET;
1294 fmt = "set %s";
1295 break;
1296 case btTypedef:
1297 default:
1298 complain (&basic_type_complaint, t->bt);
1299 return builtin_type_int;
1300 }
1301 }
1302
1303 /* Move on to next aux */
1304 ax++;
1305 if (t->continued) {
1306 /* This is the way it would work if the compiler worked */
1307 register TIR *t1 = t;
1308 while (t1->continued)
1309 ax++;
1310 }
1311
1312 if (t->fBitfield) {
1313 *bs = ax->width;
1314 ax++;
1315 }
1316
1317 /* All these types really point to some (common) MIPS type
1318 definition, and only the type-qualifiers fully identify
1319 them. We'll make the same effort at sharing. */
1320 if (t->bt == btIndirect ||
1321 t->bt == btStruct ||
1322 t->bt == btUnion ||
1323 t->bt == btEnum ||
1324 t->bt == btTypedef ||
1325 t->bt == btRange ||
1326 t->bt == btSet) {
1327 char name[256], *pn;
1328
1329 /* Try to cross reference this type */
1330 ax += cross_ref(ax, &tp, type_code, &pn);
1331 /* reading .o file ? */
1332 if (UNSAFE_DATA_ADDR(tp))
1333 tp = make_type(type_code, 0, 0, 0);
1334 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1335 sprintf(name, fmt, pn);
1336
1337 /* Usually, TYPE_CODE(tp) is already type_code. The main
1338 exception is if we guessed wrong re struct/union/enum. */
1339 if (TYPE_CODE(tp) != type_code) {
1340 complain (&bad_tag_guess_complaint, 0);
1341 TYPE_CODE(tp) = type_code;
1342 }
1343 if (TYPE_NAME(tp) == NULL || strcmp(TYPE_NAME(tp), name) != 0)
1344 TYPE_NAME(tp) = obsavestring(name, strlen(name));
1345 }
1346
1347 /* Deal with range types */
1348 if (t->bt == btRange) {
1349 struct field *f;
1350
1351 TYPE_NFIELDS (tp) = 2;
1352 TYPE_FIELDS (tp) =
1353 (struct field *) obstack_alloc (symbol_obstack,
1354 2 * sizeof (struct field));
1355 TYPE_FIELD_NAME (tp, 0) = "Low";
1356 TYPE_FIELD_BITPOS (tp, 0) = ax->dnLow;
1357 ax++;
1358 TYPE_FIELD_NAME (tp, 1) = "High";
1359 TYPE_FIELD_BITPOS (tp, 1) = ax->dnHigh;
1360 ax++;
1361 }
1362
1363 /* Parse all the type qualifiers now. If there are more
1364 than 6 the game will continue in the next aux */
1365
1366 #define PARSE_TQ(tq) \
1367 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1368
1369 again: PARSE_TQ(tq0);
1370 PARSE_TQ(tq1);
1371 PARSE_TQ(tq2);
1372 PARSE_TQ(tq3);
1373 PARSE_TQ(tq4);
1374 PARSE_TQ(tq5);
1375 #undef PARSE_TQ
1376
1377 if (t->continued) {
1378 t++;
1379 goto again;
1380 }
1381 return tp;
1382 }
1383
1384 /* Make up a complex type from a basic one. Type is passed by
1385 reference in TPP and side-effected as necessary. The type
1386 qualifier TQ says how to handle the aux symbols at AX for
1387 the symbol SX we are currently analyzing.
1388 Returns the number of aux symbols we parsed. */
1389
1390 static int
1391 upgrade_type(tpp, tq, ax, sh)
1392 struct type **tpp;
1393 AUXU *ax;
1394 SYMR *sh;
1395 {
1396 int off;
1397 struct type *t;
1398
1399 /* Used in array processing */
1400 int rf, id;
1401 FDR *fh;
1402 struct field *f;
1403 SYMR ss;
1404 int lower, upper;
1405
1406 switch (tq) {
1407 case tqPtr:
1408 t = lookup_pointer_type (*tpp);
1409 *tpp = t;
1410 return 0;
1411
1412 case tqProc:
1413 t = lookup_function_type (*tpp);
1414 *tpp = t;
1415 return 0;
1416
1417 case tqArray:
1418 off = 0;
1419 t = make_type(TYPE_CODE_ARRAY, 0, 0, 0);
1420 TYPE_TARGET_TYPE(t) = *tpp;
1421
1422 /* Determine and record the domain type (type of index) */
1423 id = ax->rndx.index;
1424 rf = ax->rndx.rfd;
1425 if (rf == 0xfff) {
1426 rf = (++ax)->isym;
1427 off++;
1428 }
1429 fh = get_rfd(cur_fd, rf);
1430
1431 /* Fields are kept in an array */
1432 /* FIXME - Memory leak! */
1433 if (TYPE_NFIELDS(t))
1434 TYPE_FIELDS(t) = (struct field*)
1435 xrealloc(TYPE_FIELDS(t),
1436 (TYPE_NFIELDS(t)+1) * sizeof(struct field));
1437 else
1438 TYPE_FIELDS(t) = (struct field*)
1439 xzalloc(sizeof(struct field));
1440 f = &(TYPE_FIELD(t,TYPE_NFIELDS(t)));
1441 TYPE_NFIELDS(t)++;
1442 memset(f, 0, sizeof(struct field));
1443
1444 memset(&ss, 0, sizeof ss);
1445 /* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU),
1446 &ss, &f->bitsize);
1447
1448 if (off == 0) {
1449 /*
1450 * This seems to be a pointer to the end of the Block defining
1451 * the type. Why it is here is magic for me, and I have no
1452 * good use for it anyways.
1453 */
1454 /* This used to occur because cross_ref returned
1455 the wrong result (ax pointed wrong). FIXME,
1456 delete this code in a while. -- gnu@cygnus jul91 */
1457 complain (&array_parse_complaint, 0);
1458 off++;
1459 id = (++ax)->rndx.index;
1460 if ((rf = ax->rndx.rfd) == 0xfff)
1461 rf = (++ax)->isym, off++;
1462 }
1463 lower = (++ax)->dnLow;
1464 upper = (++ax)->dnHigh;
1465 rf = (++ax)->width; /* bit size of array element */
1466
1467 /* Check whether supplied array element bit size matches
1468 the known size of the element type. If this complaint
1469 ends up not happening, we can remove this code. It's
1470 here because we aren't sure we understand this *&%&$
1471 symbol format. */
1472 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1473 if (id == 0) {
1474 /* Most likely an undefined type */
1475 id = rf;
1476 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1477 }
1478 if (id != rf)
1479 complain (&array_bitsize_complaint, rf);
1480
1481 TYPE_LENGTH(t) = (upper < 0) ? 0 :
1482 (upper - lower + 1) * (rf >> 3);
1483 *tpp = t;
1484 return 4 + off;
1485
1486 case tqVol:
1487 /* Volatile -- currently ignored */
1488 return 0;
1489
1490 default:
1491 complain (&unknown_type_qual_complaint, tq);
1492 return 0;
1493 }
1494 }
1495
1496
1497 /* Parse a procedure descriptor record PR. Note that the procedure
1498 is parsed _after_ the local symbols, now we just make up the
1499 extra information we need into a special symbol that we insert
1500 in the procedure's main block. Note also that images that
1501 have been partially stripped (ld -x) have been deprived
1502 of local symbols, and we have to cope with them here.
1503 The procedure's code ends at BOUND */
1504
1505 static
1506 parse_procedure(pr, bound)
1507 PDR *pr;
1508 {
1509 struct symbol *s, *i;
1510 SYMR *sh = (SYMR*)pr->isym;
1511 struct block *b;
1512 struct mips_extra_func_info *e;
1513 char name[100];
1514 char *sh_name;
1515
1516 /* Reuse the MIPS record */
1517 e = (struct mips_extra_func_info *) pr;
1518 e->numargs = lookup_numargs(pr->adr);
1519
1520 /* Make up our special symbol */
1521 i = new_symbol(".gdbinfo.");
1522 SYMBOL_VALUE(i) = (int)e;
1523 SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE;
1524 SYMBOL_CLASS(i) = LOC_CONST;
1525 SYMBOL_TYPE(i) = builtin_type_void;
1526
1527 /* Make up a name for static procedures. Sigh. */
1528 if (sh == (SYMR*)-1) {
1529 sprintf(name,".static_procedure@%x",pr->adr);
1530 sh_name = savestring(name, strlen(name));
1531 s = NULL;
1532 }
1533 else {
1534 sh_name = (char*)sh->iss;
1535 s = mylookup_symbol(sh_name, top_stack->cur_block,
1536 VAR_NAMESPACE, LOC_BLOCK);
1537 }
1538 if (s != 0) {
1539 b = SYMBOL_BLOCK_VALUE(s);
1540 } else {
1541 s = new_symbol(sh_name);
1542 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1543 SYMBOL_CLASS(s) = LOC_BLOCK;
1544 /* Donno its type, hope int is ok */
1545 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1546 add_symbol(s, top_stack->cur_block);
1547 /* Wont have symbols for this one */
1548 b = new_block(2);
1549 SYMBOL_BLOCK_VALUE(s) = b;
1550 BLOCK_FUNCTION(b) = s;
1551 BLOCK_START(b) = pr->adr;
1552 BLOCK_END(b) = bound;
1553 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1554 add_block(b, top_stack->cur_st);
1555 }
1556 e->isym = (long)s;
1557 add_symbol(i,b);
1558 }
1559
1560 /* Parse the external symbol ES. Just call parse_symbol() after
1561 making sure we know where the aux are for it. For procedures,
1562 parsing of the PDRs has already provided all the needed
1563 information, we only parse them if SKIP_PROCEDURES is false,
1564 and only if this causes no symbol duplication.
1565
1566 This routine clobbers top_stack->cur_block and ->cur_st. */
1567
1568 static
1569 parse_external(es, skip_procedures)
1570 EXTR *es;
1571 {
1572 AUXU *ax;
1573
1574 if (es->ifd != ifdNil) {
1575 cur_fd = es->ifd;
1576 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1577 ax = (AUXU*)cur_fdr->iauxBase;
1578 } else {
1579 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1580 ax = 0;
1581 }
1582 top_stack->cur_st = cur_stab;
1583 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
1584 GLOBAL_BLOCK);
1585
1586 /* Reading .o files */
1587 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1588 char *what;
1589 switch (es->asym.st) {
1590 case stStaticProc:
1591 case stProc: what = "procedure"; n_undef_procs++; break;
1592 case stGlobal: what = "variable"; n_undef_vars++; break;
1593 case stLabel: what = "label"; n_undef_labels++; break;
1594 default : what = "symbol"; break;
1595 }
1596 n_undef_symbols++;
1597 if (info_verbose)
1598 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what,
1599 es->asym.iss, fdr_name(cur_fdr->rss));
1600 return;
1601 }
1602
1603 switch (es->asym.st) {
1604 case stProc:
1605 /* If we have full symbols we do not need more */
1606 if (skip_procedures)
1607 return;
1608 if (mylookup_symbol (es->asym.iss, top_stack->cur_block,
1609 VAR_NAMESPACE, LOC_BLOCK))
1610 break;
1611 /* fall through */
1612 case stGlobal:
1613 case stLabel:
1614 /*
1615 * Note that the case of a symbol with indexNil
1616 * must be handled anyways by parse_symbol().
1617 */
1618 parse_symbol(&es->asym, ax);
1619 break;
1620 default:
1621 break;
1622 }
1623 }
1624
1625 /* Parse the line number info for file descriptor FH into
1626 GDB's linetable LT. MIPS' encoding requires a little bit
1627 of magic to get things out. Note also that MIPS' line
1628 numbers can go back and forth, apparently we can live
1629 with that and do not need to reorder our linetables */
1630
1631 static
1632 parse_lines(fh, lt)
1633 FDR *fh;
1634 struct linetable *lt;
1635 {
1636 unsigned char *base = (unsigned char*)fh->cbLineOffset;
1637 int i, j, k;
1638 int delta, count, lineno = 0;
1639 PDR *pr;
1640
1641 if (base == 0)
1642 return;
1643
1644 /* Scan by procedure descriptors */
1645 i = 0; j = 0, k = 0;
1646 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1647 int l, halt;
1648
1649 /* No code for this one */
1650 if (pr->iline == ilineNil ||
1651 pr->lnLow == -1 || pr->lnHigh == -1)
1652 continue;
1653 /*
1654 * Aurgh! To know where to stop expanding we
1655 * must look-ahead.
1656 */
1657 for (l = 1; l < (fh->cpd - j); l++)
1658 if (pr[l].iline != -1)
1659 break;
1660 if (l == (fh->cpd - j))
1661 halt = fh->cline;
1662 else
1663 halt = pr[l].iline;
1664 /*
1665 * When procedures are moved around the linenumbers
1666 * are attributed to the next procedure up
1667 */
1668 if (pr->iline >= halt) continue;
1669
1670 base = (unsigned char*)pr->cbLineOffset;
1671 l = pr->adr >> 2; /* in words */
1672 halt += (pr->adr >> 2) - pr->iline;
1673 for (lineno = pr->lnLow; l < halt;) {
1674 count = *base & 0x0f;
1675 delta = *base++ >> 4;
1676 if (delta >= 8)
1677 delta -= 16;
1678 if (delta == -8) {
1679 delta = (base[0] << 8) | base[1];
1680 if (delta >= 0x8000)
1681 delta -= 0x10000;
1682 base += 2;
1683 }
1684 lineno += delta;/* first delta is 0 */
1685 k = add_line(lt, lineno, l, k);
1686 l += count + 1;
1687 }
1688 }
1689 }
1690
1691 \f
1692 /* Master parsing procedure for first-pass reading of file symbols
1693 into a partial_symtab.
1694
1695 Parses the symtab described by the global symbolic header CUR_HDR.
1696 END_OF_TEXT_SEG gives the address just after the text segment for
1697 the symtab we are reading. */
1698
1699 static
1700 parse_partial_symbols(end_of_text_seg, objfile)
1701 int end_of_text_seg;
1702 struct objfile *objfile;
1703 {
1704 int f_idx, s_idx;
1705 /* int stat_idx, h_max;*/
1706 HDRR *hdr = cur_hdr;
1707 /* Running pointers */
1708 FDR *fh;
1709 RFDT *rh;
1710 register EXTR *esh;
1711 register SYMR *sh;
1712 struct partial_symtab *pst;
1713
1714 int past_first_source_file = 0;
1715
1716 /* List of current psymtab's include files */
1717 char **psymtab_include_list;
1718 int includes_allocated;
1719 int includes_used;
1720 EXTR **extern_tab;
1721 struct pst_map * fdr_to_pst;
1722 /* Index within current psymtab dependency list */
1723 struct partial_symtab **dependency_list;
1724 int dependencies_used, dependencies_allocated;
1725 struct cleanup *old_chain;
1726
1727 extern_tab = (EXTR**)obstack_alloc (psymbol_obstack,
1728 sizeof(EXTR *) * hdr->iextMax);
1729
1730 includes_allocated = 30;
1731 includes_used = 0;
1732 psymtab_include_list = (char **) alloca (includes_allocated *
1733 sizeof (char *));
1734 next_symbol_text_func = mips_next_symbol_text;
1735
1736 dependencies_allocated = 30;
1737 dependencies_used = 0;
1738 dependency_list =
1739 (struct partial_symtab **) alloca (dependencies_allocated *
1740 sizeof (struct partial_symtab *));
1741
1742 last_source_file = 0;
1743
1744 /*
1745 * Big plan:
1746 *
1747 * Only parse the Local and External symbols, and the Relative FDR.
1748 * Fixup enough of the loader symtab to be able to use it.
1749 * Allocate space only for the file's portions we need to
1750 * look at. (XXX)
1751 */
1752
1753 max_gdbinfo = 0;
1754 max_glevel = MIN_GLEVEL;
1755
1756 /* Allocate the map FDR -> PST.
1757 Minor hack: -O3 images might claim some global data belongs
1758 to FDR -1. We`ll go along with that */
1759 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1760 old_chain = make_cleanup (free, fdr_to_pst);
1761 fdr_to_pst++;
1762 {
1763 struct partial_symtab * pst = new_psymtab("", objfile);
1764 fdr_to_pst[-1].pst = pst;
1765 FDR_IDX(pst) = -1;
1766 }
1767
1768 /* Pass 1 over external syms: Presize and partition the list */
1769 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1770 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1771 fdr_to_pst[esh->ifd].n_globals++;
1772 }
1773
1774 /* Pass 1.5 over files: partition out global symbol space */
1775 s_idx = 0;
1776 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1777 fdr_to_pst[f_idx].globals_offset = s_idx;
1778 s_idx += fdr_to_pst[f_idx].n_globals;
1779 fdr_to_pst[f_idx].n_globals = 0;
1780 }
1781
1782 /* Pass 2 over external syms: fill in external symbols */
1783 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1784 enum misc_function_type misc_type = mf_text;
1785 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1786
1787 extern_tab[fdr_to_pst[esh->ifd].globals_offset
1788 + fdr_to_pst[esh->ifd].n_globals++] = esh;
1789
1790 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1791 continue;
1792
1793 switch (esh->asym.st) {
1794 case stProc:
1795 break;
1796 case stGlobal:
1797 misc_type = mf_data;
1798 break;
1799 case stLabel:
1800 break;
1801 default:
1802 misc_type = mf_unknown;
1803 complain (&unknown_ext_complaint,
1804 (char *)(esh->asym.iss));
1805 }
1806 prim_record_misc_function ((char *)(esh->asym.iss),
1807 esh->asym.value,
1808 misc_type);
1809 }
1810
1811 /* Pass 3 over files, over local syms: fill in static symbols */
1812 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1813 struct partial_symtab *save_pst;
1814 EXTR **ext_ptr;
1815 cur_fdr = fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1816
1817 if (fh->csym == 0) {
1818 fdr_to_pst[f_idx].pst = NULL;
1819 continue;
1820 }
1821 pst = start_psymtab_common (objfile, 0, (char*)fh->rss,
1822 fh->cpd ? fh->adr : 0,
1823 global_psymbols.next,
1824 static_psymbols.next);
1825 pst->read_symtab_private = (char *)
1826 obstack_alloc (psymbol_obstack, sizeof (struct symloc));
1827
1828 save_pst = pst;
1829 /* Make everything point to everything. */
1830 FDR_IDX(pst) = f_idx;
1831 fdr_to_pst[f_idx].pst = pst;
1832 fh->ioptBase = (int)pst;
1833
1834 CUR_HDR(pst) = cur_hdr;
1835
1836 /* The way to turn this into a symtab is to call... */
1837 pst->read_symtab = mipscoff_psymtab_to_symtab;
1838
1839 pst->texthigh = pst->textlow;
1840
1841 pst->globals_offset = global_psymbols.next - global_psymbols.list;
1842 pst->statics_offset = static_psymbols.next - static_psymbols.list;
1843
1844 pst->n_global_syms = 0;
1845 pst->n_static_syms = 0;
1846
1847 /* The second symbol must be @stab.
1848 This symbol is emitted by mips-tfile to signal
1849 that the current object file uses encapsulated stabs
1850 instead of mips ecoff for local symbols.
1851 (It is the second symbol because the first symbol is
1852 the stFile used to signal the start of a file). */
1853 if (fh->csym >= 2
1854 && strcmp(((SYMR *)fh->isymBase)[1].iss, stabs_symbol) == 0) {
1855 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
1856 int type_code;
1857 char *namestring;
1858 sh = cur_sdx + (SYMR *) fh->isymBase;
1859 type_code = MIPS_UNMARK_STAB(sh->index);
1860 if (!MIPS_IS_STAB(sh)) {
1861 if (sh->st == stProc || sh->st == stStaticProc) {
1862 long procaddr = sh->value;
1863 sh = (sh->index + (AUXU *)fh->iauxBase)->isym
1864 + (SYMR *) fh->isymBase - 1;
1865 if (sh->st == stEnd) {
1866 long high = procaddr + sh->value;
1867 if (high > pst->texthigh)
1868 pst->texthigh = high;
1869 }
1870 }
1871 continue;
1872 }
1873 #define SET_NAMESTRING() namestring = (char*)sh->iss
1874 #define CUR_SYMBOL_TYPE type_code
1875 #define CUR_SYMBOL_VALUE sh->value
1876 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1877 pst = save_pst
1878 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1879 #define addr 0 /* FIXME, should be offset of addresses */
1880 #define HANDLE_RBRAC(val) \
1881 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1882 #include "partial-stab.h"
1883 #undef addr
1884 }
1885 }
1886 else {
1887 register struct partial_symbol *psym;
1888 for (cur_sdx = 0; cur_sdx < fh->csym; ) {
1889 register struct partial_symbol *p;
1890 char *name;
1891 int class;
1892 sh = cur_sdx + (SYMR *) fh->isymBase;
1893
1894 if (MIPS_IS_STAB(sh)) {
1895 cur_sdx++;
1896 continue;
1897 }
1898
1899 if (sh->sc == scUndefined || sh->sc == scNil ||
1900 sh->index == 0xfffff) {
1901 /* FIXME, premature? */
1902 cur_sdx++;
1903 continue;
1904 }
1905
1906 name = (char *)(sh->iss);
1907
1908 switch (sh->st) {
1909 long high;
1910 long procaddr;
1911 case stProc: /* Asm labels apparently */
1912 case stStaticProc: /* Function */
1913 ADD_PSYMBOL_TO_LIST(name, strlen(name),
1914 VAR_NAMESPACE, LOC_BLOCK,
1915 static_psymbols, sh->value);
1916 /* Skip over procedure to next one. */
1917 cur_sdx = (sh->index + (AUXU *)fh->iauxBase)->isym;
1918 procaddr = sh->value;
1919
1920 sh = cur_sdx + (SYMR *) fh->isymBase - 1;
1921 if (sh->st != stEnd)
1922 continue;
1923 high = procaddr + sh->value;
1924 if (high > pst->texthigh)
1925 pst->texthigh = high;
1926 continue;
1927 case stStatic: /* Variable */
1928 class = LOC_STATIC;
1929 break;
1930 case stTypedef: /* Typedef */
1931 class = LOC_TYPEDEF;
1932 break;
1933 case stConstant: /* Constant decl */
1934 class = LOC_CONST;
1935 break;
1936 case stBlock: /* { }, str, un, enum*/
1937 if (sh->sc == scInfo) {
1938 ADD_PSYMBOL_TO_LIST(name, strlen(name),
1939 STRUCT_NAMESPACE, LOC_TYPEDEF,
1940 static_psymbols, sh->value);
1941 }
1942 /* Skip over the block */
1943 cur_sdx = sh->index;
1944 continue;
1945 case stFile: /* File headers */
1946 case stLabel: /* Labels */
1947 case stEnd: /* Ends of files */
1948 goto skip;
1949 default:
1950 complain (&unknown_sym_complaint, SYMBOL_NAME(p));
1951 complain (&unknown_st_complaint, sh->st);
1952 cur_sdx++;
1953 continue;
1954 }
1955 /* Use this gdb symbol */
1956 ADD_PSYMBOL_TO_LIST(name, strlen(name),
1957 VAR_NAMESPACE, class,
1958 static_psymbols, sh->value);
1959 skip:
1960 cur_sdx++; /* Go to next file symbol */
1961 }
1962
1963 /* Now do enter the external symbols. */
1964 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
1965 cur_sdx = fdr_to_pst[f_idx].n_globals;
1966 PST_PRIVATE(save_pst)->extern_count = cur_sdx;
1967 PST_PRIVATE(save_pst)->extern_tab = ext_ptr;
1968 for (; --cur_sdx >= 0; ext_ptr++) {
1969 enum address_class class;
1970 if ((*ext_ptr)->ifd != f_idx)
1971 abort();
1972 sh = &(*ext_ptr)->asym;
1973 switch (sh->st) {
1974 case stProc:
1975 class = LOC_BLOCK;
1976 break;
1977 case stLabel:
1978 class = LOC_LABEL;
1979 break;
1980 default:
1981 complain (&unknown_ext_complaint, sh->iss);
1982 case stGlobal:
1983 class = LOC_STATIC;
1984 break;
1985 }
1986 if (global_psymbols.next >=
1987 global_psymbols.list + global_psymbols.size)
1988 extend_psymbol_list (&global_psymbols);
1989 psym = global_psymbols.next++;
1990 SYMBOL_NAME (psym) = (char*)sh->iss;
1991 SYMBOL_NAMESPACE (psym) = VAR_NAMESPACE;
1992 SYMBOL_CLASS (psym) = class;
1993 SYMBOL_VALUE_ADDRESS (psym) = (CORE_ADDR)sh->value;
1994 }
1995 }
1996
1997 end_psymtab (save_pst, psymtab_include_list, includes_used,
1998 -1, save_pst->texthigh,
1999 dependency_list, dependencies_used,
2000 global_psymbols.next, static_psymbols.next);
2001 if (entry_point < save_pst->texthigh
2002 && entry_point >= save_pst->textlow) {
2003 startup_file_start = save_pst->textlow;
2004 startup_file_end = save_pst->texthigh;
2005 }
2006 }
2007
2008 /* Mark the last code address, and remember it for later */
2009 hdr->cbDnOffset = end_of_text_seg;
2010
2011 do_cleanups (old_chain);
2012 }
2013
2014
2015 #if 0
2016 /* Do the initial analisys of the F_IDX-th file descriptor.
2017 Allocates a partial symtab for it, and builds the list
2018 of dependent files by recursion. LEV says at which level
2019 of recursion we are called (to pretty up debug traces) */
2020
2021 static struct partial_symtab *
2022 parse_fdr(f_idx, lev, objfile)
2023 int f_idx;
2024 int lev;
2025 struct objfile *objfile;
2026 {
2027 register FDR *fh;
2028 register struct partial_symtab *pst;
2029 int s_idx, s_id0;
2030
2031 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
2032
2033 /* Use this to indicate into which symtab this file was parsed */
2034 if (fh->ioptBase)
2035 return (struct partial_symtab *) fh->ioptBase;
2036
2037 /* Debuggability level */
2038 if (compare_glevel(max_glevel, fh->glevel) < 0)
2039 max_glevel = fh->glevel;
2040
2041 /* Make a new partial_symtab */
2042 pst = new_psymtab(fh->rss, objfile);
2043 if (fh->cpd == 0){
2044 pst->textlow = 0;
2045 pst->texthigh = 0;
2046 } else {
2047 pst->textlow = fh->adr;
2048 pst->texthigh = fh->cpd; /* To be fixed later */
2049 }
2050
2051 /* Make everything point to everything. */
2052 FDR_IDX(pst) = f_idx;
2053 fdr_to_pst[f_idx].pst = pst;
2054 fh->ioptBase = (int)pst;
2055
2056 /* Analyze its dependencies */
2057 if (fh->crfd <= 1)
2058 return pst;
2059
2060 s_id0 = 0;
2061 if (fh->cpd == 0) { /* If there are no functions defined here ... */
2062 /* ...then presumably a .h file: drop reverse depends .h->.c */
2063 for (; s_id0 < fh->crfd; s_id0++) {
2064 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
2065 if (*rh == f_idx) {
2066 s_id0++; /* Skip self-dependency */
2067 break;
2068 }
2069 }
2070 }
2071 pst->number_of_dependencies = fh->crfd - s_id0;
2072 pst->dependencies = (struct partial_symtab **)
2073 obstack_alloc (psymbol_obstack,
2074 pst->number_of_dependencies *
2075 sizeof (struct partial_symtab *));
2076 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
2077 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
2078
2079 pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);
2080 }
2081
2082 return pst;
2083 }
2084 #endif
2085
2086 static char*
2087 mips_next_symbol_text ()
2088 {
2089 cur_sdx++;
2090 return (char*)((SYMR *)cur_fdr->isymBase)[cur_sdx].iss;
2091 }
2092
2093 /* Ancillary function to psymtab_to_symtab(). Does all the work
2094 for turning the partial symtab PST into a symtab, recurring
2095 first on all dependent psymtabs. The argument FILENAME is
2096 only passed so we can see in debug stack traces what file
2097 is being read. */
2098
2099 static void
2100 psymtab_to_symtab_1(pst, filename)
2101 struct partial_symtab *pst;
2102 char *filename;
2103 {
2104 int have_stabs;
2105 int i, f_max;
2106 struct symtab *st;
2107 FDR *fh;
2108 int maxlines;
2109 struct linetable *lines;
2110
2111 if (pst->readin)
2112 return;
2113 pst->readin = 1;
2114
2115 /* How many symbols will we need */
2116 /* FIXME, this does not count enum values. */
2117 f_max = pst->n_global_syms + pst->n_static_syms;
2118 if (FDR_IDX(pst) == -1) {
2119 fh = 0;
2120 maxlines = 0;
2121 } else {
2122 fh = (FDR *) (cur_hdr->cbFdOffset) + FDR_IDX(pst);
2123 f_max += fh->csym + fh->cpd;
2124 maxlines = 2 * fh->cline;
2125 }
2126
2127 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2128 have_stabs =
2129 fh && fh->csym >= 2
2130 && strcmp(((SYMR *)fh->isymBase)[1].iss, stabs_symbol) == 0;
2131
2132 if (!have_stabs) {
2133 if (fh)
2134 st = new_symtab (pst->filename, 2 * f_max, maxlines,
2135 pst->objfile);
2136 else
2137 st = new_symtab ("unknown", f_max, 0, pst->objfile);
2138 lines = LINETABLE(st);
2139 pending_list = (struct mips_pending **) cur_hdr->cbOptOffset;
2140 if (pending_list == 0) {
2141 pending_list = (struct mips_pending **)
2142 xzalloc(cur_hdr->ifdMax * sizeof(struct mips_pending *));
2143 cur_hdr->cbOptOffset = (int)pending_list;
2144 }
2145 }
2146
2147 /* Read in all partial symbtabs on which this one is dependent.
2148 NOTE that we do have circular dependencies, sigh. We solved
2149 that by setting pst->readin before this point. */
2150
2151 for (i = 0; i < pst->number_of_dependencies; i++)
2152 if (!pst->dependencies[i]->readin) {
2153 /* Inform about additional files to be read in. */
2154 if (info_verbose)
2155 {
2156 fputs_filtered (" ", stdout);
2157 wrap_here ("");
2158 fputs_filtered ("and ", stdout);
2159 wrap_here ("");
2160 printf_filtered ("%s...",
2161 pst->dependencies[i]->filename);
2162 wrap_here (""); /* Flush output */
2163 fflush (stdout);
2164 }
2165 /* We only pass the filename for debug purposes */
2166 psymtab_to_symtab_1(pst->dependencies[i],
2167 pst->dependencies[i]->filename);
2168 }
2169
2170 cur_fdr = fh;
2171 /* Now read the symbols for this symtab */
2172
2173 if (!have_stabs) {
2174 cur_fd = FDR_IDX(pst);
2175 cur_stab = st;
2176
2177 /* Get a new lexical context */
2178
2179 push_parse_stack();
2180 top_stack->cur_st = cur_stab;
2181 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab),
2182 STATIC_BLOCK);
2183 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
2184 BLOCK_END(top_stack->cur_block) = 0;
2185 top_stack->blocktype = stFile;
2186 top_stack->maxsyms = 2*f_max;
2187 top_stack->cur_type = 0;
2188 top_stack->procadr = 0;
2189 top_stack->numargs = 0;
2190 }
2191
2192 /* Parse locals and procedures */
2193 if (fh) {
2194 SYMR *sh;
2195 PDR *pr;
2196 int f_idx = cur_fd;
2197 char *fh_name = (char*)fh->rss;
2198
2199 /* Parse local symbols first */
2200
2201
2202 if (have_stabs) {
2203 if (fh->csym <= 2)
2204 return;
2205 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
2206 register SYMR *sh = cur_sdx + (SYMR *) fh->isymBase;
2207 char *name = (char*)sh->iss;
2208 CORE_ADDR valu = sh->value;
2209 if (MIPS_IS_STAB(sh)) {
2210 int type_code = MIPS_UNMARK_STAB(sh->index);
2211 process_one_symbol (type_code, 0, valu, name, /*FIXME*/ 0);
2212 }
2213 else if (sh->st == stLabel && sh->index != indexNil) {
2214 /* Handle encoded stab line number. */
2215 record_line (current_subfile, sh->index, valu);
2216 }
2217 }
2218 st = end_symtab (pst->texthigh, 0, 0, pst->objfile);
2219 }
2220 else {
2221 /* BOUND is the highest core address of this file's procedures */
2222 int bound = cur_fd == cur_hdr->ifdMax - 1 ? cur_hdr->cbDnOffset
2223 : fh[1].adr;
2224 for (cur_sdx = 0; cur_sdx < fh->csym; ) {
2225 sh = (SYMR *) (fh->isymBase) + cur_sdx;
2226 cur_sdx += parse_symbol(sh, fh->iauxBase);
2227 }
2228
2229 /* Procedures next, note we need to look-ahead to
2230 find out where the procedure's code ends */
2231
2232 for (i = 0; i < fh->cpd-1; i++) {
2233 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
2234 parse_procedure(pr, pr[1].adr); /* next proc up */
2235 }
2236 if (fh->cpd) {
2237 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
2238 parse_procedure(pr, bound); /* next file up */
2239 }
2240 /* Linenumbers. At the end, check if we can save memory */
2241 parse_lines(fh, lines);
2242 if (lines->nitems < fh->cline)
2243 lines = shrink_linetable(lines);
2244 }
2245
2246 }
2247 if (!have_stabs) {
2248 EXTR **ext_ptr;
2249 LINETABLE(st) = lines;
2250
2251 /* .. and our share of externals.
2252 XXX use the global list to speed up things here. how ?
2253 FIXME, Maybe quit once we have found the right number of ext's? */
2254 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2255 top_stack->blocktype = stFile;
2256 top_stack->maxsyms =
2257 cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
2258
2259 ext_ptr = PST_PRIVATE(pst)->extern_tab;
2260 for (i = PST_PRIVATE(pst)->extern_count; --i >= 0; ext_ptr++)
2261 parse_external(*ext_ptr, 1);
2262
2263 /* If there are undefined, tell the user */
2264 if (n_undef_symbols) {
2265 printf_filtered("File %s contains %d unresolved references:",
2266 st->filename, n_undef_symbols);
2267 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2268 n_undef_vars, n_undef_procs, n_undef_labels);
2269 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
2270
2271 }
2272 pop_parse_stack();
2273 }
2274
2275 /* Sort the symbol table now, we are done adding symbols to it.*/
2276 sort_symtab_syms(st);
2277
2278 sort_blocks (st);
2279
2280 /* Now link the psymtab and the symtab. */
2281 pst->symtab = st;
2282 }
2283 \f
2284 /* Ancillary parsing procedures. */
2285
2286 /* Lookup the type at relative index RN. Return it in TPP
2287 if found and in any event come up with its name PNAME.
2288 Return value says how many aux symbols we ate */
2289
2290 static
2291 cross_ref(rn, tpp, type_code, pname)
2292 RNDXR *rn;
2293 struct type **tpp;
2294 int type_code; /* Use to alloc new type if none is found. */
2295 char **pname;
2296 {
2297 unsigned rf;
2298
2299 /* Escape index means 'the next one' */
2300 if (rn->rfd == 0xfff)
2301 rf = *(unsigned *) (rn + 1);
2302 else
2303 rf = rn->rfd;
2304
2305 if (rf == -1) {
2306 /* Ooops */
2307 *pname = "<undefined>";
2308 } else {
2309 /*
2310 * Find the relative file descriptor and the symbol in it
2311 */
2312 FDR *fh = get_rfd(cur_fd, rf);
2313 SYMR *sh;
2314 struct type *t;
2315
2316 /*
2317 * If we have processed this symbol then we left a forwarding
2318 * pointer to the corresponding GDB symbol. If not, we`ll put
2319 * it in a list of pending symbols, to be processed later when
2320 * the file f will be. In any event, we collect the name for
2321 * the type here. Which is why we made a first pass at
2322 * strings.
2323 */
2324 sh = (SYMR *) (fh->isymBase) + rn->index;
2325
2326 /* Careful, we might be looking at .o files */
2327 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2328 (char *) sh->iss;
2329
2330 /* Have we parsed it ? */
2331 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2332 t = (struct type *) sh->value;
2333 *tpp = t;
2334 } else {
2335 /* Avoid duplicates */
2336 struct mips_pending *p = is_pending_symbol(fh, sh);
2337 if (p)
2338 *tpp = p->t;
2339 else {
2340 *tpp = make_type(type_code, 0, 0, 0);
2341 add_pending(fh, sh, *tpp);
2342 }
2343 }
2344 }
2345
2346 /* We used one auxent normally, two if we got a "next one" rf. */
2347 return (rn->rfd == 0xfff? 2: 1);
2348 }
2349
2350
2351 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2352 keeping the symtab sorted */
2353
2354 static struct symbol *
2355 mylookup_symbol (name, block, namespace, class)
2356 char *name;
2357 register struct block *block;
2358 enum namespace namespace;
2359 enum address_class class;
2360 {
2361 register int bot, top, inc;
2362 register struct symbol *sym;
2363
2364 bot = 0;
2365 top = BLOCK_NSYMS(block);
2366 inc = name[0];
2367 while (bot < top) {
2368 sym = BLOCK_SYM(block, bot);
2369 if (SYMBOL_NAME(sym)[0] == inc
2370 && SYMBOL_NAMESPACE(sym) == namespace
2371 && SYMBOL_CLASS(sym) == class
2372 && !strcmp(SYMBOL_NAME(sym), name))
2373 return sym;
2374 bot++;
2375 }
2376 if (block = BLOCK_SUPERBLOCK (block))
2377 return mylookup_symbol (name, block, namespace, class);
2378 return 0;
2379 }
2380
2381
2382 /* Add a new symbol S to a block B.
2383 Infrequently, we will need to reallocate the block to make it bigger.
2384 We only detect this case when adding to top_stack->cur_block, since
2385 that's the only time we know how big the block is. FIXME. */
2386
2387 static void
2388 add_symbol(s,b)
2389 struct symbol *s;
2390 struct block *b;
2391 {
2392 int nsyms = BLOCK_NSYMS(b)++;
2393 struct block *origb;
2394 struct parse_stack *stackp;
2395
2396 if (b == top_stack->cur_block &&
2397 nsyms >= top_stack->maxsyms) {
2398 complain (&block_overflow_complaint, s->name);
2399 /* In this case shrink_block is actually grow_block, since
2400 BLOCK_NSYMS(b) is larger than its current size. */
2401 origb = b;
2402 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2403
2404 /* Now run through the stack replacing pointers to the
2405 original block. shrink_block has already done this
2406 for the blockvector and BLOCK_FUNCTION. */
2407 for (stackp = top_stack; stackp; stackp = stackp->next) {
2408 if (stackp->cur_block == origb) {
2409 stackp->cur_block = b;
2410 stackp->maxsyms = BLOCK_NSYMS (b);
2411 }
2412 }
2413 }
2414 BLOCK_SYM(b,nsyms) = s;
2415 }
2416
2417 /* Add a new block B to a symtab S */
2418
2419 static void
2420 add_block(b,s)
2421 struct block *b;
2422 struct symtab *s;
2423 {
2424 struct blockvector *bv = BLOCKVECTOR(s);
2425
2426 bv = (struct blockvector *)xrealloc(bv, sizeof(struct blockvector) +
2427 BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block));
2428 if (bv != BLOCKVECTOR(s))
2429 BLOCKVECTOR(s) = bv;
2430
2431 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2432 }
2433
2434 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2435 MIPS' linenumber encoding might need more than one byte
2436 to describe it, LAST is used to detect these continuation lines */
2437
2438 static int
2439 add_line(lt, lineno, adr, last)
2440 struct linetable *lt;
2441 int lineno;
2442 CORE_ADDR adr;
2443 int last;
2444 {
2445 if (last == 0)
2446 last = -2; /* make sure we record first line */
2447
2448 if (last == lineno) /* skip continuation lines */
2449 return lineno;
2450
2451 lt->item[lt->nitems].line = lineno;
2452 lt->item[lt->nitems++].pc = adr << 2;
2453 return lineno;
2454 }
2455
2456
2457 \f
2458 /* Comparison functions, used when sorting things */
2459
2460 /* Symtabs must be ordered viz the code segments they cover */
2461
2462 static int
2463 compare_symtabs( s1, s2)
2464 struct symtab **s1, **s2;
2465 {
2466 /* "most specific" first */
2467
2468 register struct block *b1, *b2;
2469 b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK);
2470 b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK);
2471 if (BLOCK_END(b1) == BLOCK_END(b2))
2472 return BLOCK_START(b1) - BLOCK_START(b2);
2473 return BLOCK_END(b1) - BLOCK_END(b2);
2474 }
2475
2476
2477 /* Partial Symtabs, same */
2478
2479 static int
2480 compare_psymtabs( s1, s2)
2481 struct partial_symtab **s1, **s2;
2482 {
2483 /* Perf twist: put the ones with no code at the end */
2484
2485 register int a = (*s1)->textlow;
2486 register int b = (*s2)->textlow;
2487 if (a == 0)
2488 return b;
2489 if (b == 0)
2490 return -a;
2491 return a - b;
2492 }
2493
2494
2495 /* Blocks with a smaller low bound should come first */
2496
2497 static int compare_blocks(b1,b2)
2498 struct block **b1, **b2;
2499 {
2500 register int addr_diff;
2501
2502 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2503 if (addr_diff == 0)
2504 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2505 return addr_diff;
2506 }
2507
2508 \f
2509 /* Sorting and reordering procedures */
2510
2511 /* Sort the blocks of a symtab S.
2512 Reorder the blocks in the blockvector by code-address,
2513 as required by some MI search routines */
2514
2515 static void
2516 sort_blocks(s)
2517 struct symtab *s;
2518 {
2519 struct blockvector *bv = BLOCKVECTOR(s);
2520
2521 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2522 /* Cosmetic */
2523 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2524 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2525 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2526 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2527 return;
2528 }
2529 /*
2530 * This is very unfortunate: normally all functions are compiled in
2531 * the order they are found, but if the file is compiled -O3 things
2532 * are very different. It would be nice to find a reliable test
2533 * to detect -O3 images in advance.
2534 */
2535 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2536 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2537 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2538 sizeof(struct block *),
2539 compare_blocks);
2540
2541 {
2542 register CORE_ADDR high = 0;
2543 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2544
2545 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2546 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2547 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2548 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2549 }
2550
2551 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2552 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2553
2554 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2555 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2556 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2557 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2558 }
2559
2560 \f
2561 /* Constructor/restructor/destructor procedures */
2562
2563 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2564 MAXSYMS and linenumbers MAXLINES we'll put in it */
2565
2566 static
2567 struct symtab *
2568 new_symtab(name, maxsyms, maxlines, objfile)
2569 char *name;
2570 {
2571 struct symtab *s = allocate_symtab (name, objfile);
2572
2573 LINETABLE(s) = new_linetable(maxlines);
2574
2575 /* All symtabs must have at least two blocks */
2576 BLOCKVECTOR(s) = new_bvect(2);
2577 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2578 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2579 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2580 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2581
2582 s->free_code = free_linetable;
2583
2584 /* Link the new symtab into the list of such. */
2585 s->next = symtab_list;
2586 symtab_list = s;
2587
2588 return s;
2589 }
2590
2591 /* Allocate a new partial_symtab NAME */
2592
2593 static struct partial_symtab *
2594 new_psymtab(name, objfile)
2595 char *name;
2596 struct objfile *objfile;
2597 {
2598 struct partial_symtab *pst;
2599
2600 pst = (struct partial_symtab *)
2601 obstack_alloc (psymbol_obstack, sizeof (*pst));
2602 memset (pst, 0, sizeof (*pst));
2603
2604 if (name == (char*)-1) /* FIXME -- why not null here? */
2605 pst->filename = "<no name>";
2606 else
2607 pst->filename = name;
2608
2609 /* Chain it to its object file */
2610 pst->objfile = objfile;
2611 pst->objfile_chain = objfile->psymtabs;
2612 objfile->psymtabs = pst;
2613
2614 pst->next = partial_symtab_list;
2615 partial_symtab_list = pst;
2616
2617 /* Keep a backpointer to the file's symbols */
2618 pst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
2619 sizeof (struct symloc));
2620 CUR_HDR(pst) = cur_hdr;
2621
2622 /* The way to turn this into a symtab is to call... */
2623 pst->read_symtab = mipscoff_psymtab_to_symtab;
2624
2625 return pst;
2626 }
2627
2628
2629 /* Allocate a linetable array of the given SIZE */
2630
2631 static struct linetable *
2632 new_linetable(size)
2633 {
2634 struct linetable *l;
2635
2636 size = size * sizeof(l->item) + sizeof(struct linetable);
2637 l = (struct linetable *)xmalloc(size);
2638 l->nitems = 0;
2639 return l;
2640 }
2641
2642 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2643 I am not so sure about the 3.4 ones */
2644
2645 static struct linetable *
2646 shrink_linetable(lt)
2647 struct linetable * lt;
2648 {
2649 struct linetable *l = new_linetable(lt->nitems);
2650
2651 memcpy(l, lt, lt->nitems * sizeof(l->item) + sizeof(struct linetable));
2652 free (lt);
2653 return l;
2654 }
2655
2656 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2657
2658 static
2659 struct blockvector *
2660 new_bvect(nblocks)
2661 {
2662 struct blockvector *bv;
2663 int size;
2664
2665 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2666 bv = (struct blockvector *) xzalloc(size);
2667
2668 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2669
2670 return bv;
2671 }
2672
2673 /* Allocate and zero a new block of MAXSYMS symbols */
2674
2675 static
2676 struct block *
2677 new_block(maxsyms)
2678 {
2679 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2680 struct block *b = (struct block *)xzalloc(size);
2681
2682 return b;
2683 }
2684
2685 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2686 Shrink_block can also be used by add_symbol to grow a block. */
2687
2688 static struct block *
2689 shrink_block(b, s)
2690 struct block *b;
2691 struct symtab *s;
2692 {
2693 struct block *new;
2694 struct blockvector *bv = BLOCKVECTOR(s);
2695 int i;
2696
2697 /* Just reallocate it and fix references to the old one */
2698
2699 new = (struct block *) xrealloc ((char *)b, sizeof(struct block) +
2700 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2701
2702 /* Should chase pointers to old one. Fortunately, that`s just
2703 the block`s function and inferior blocks */
2704 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
2705 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2706 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2707 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2708 BLOCKVECTOR_BLOCK(bv,i) = new;
2709 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2710 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2711 return new;
2712 }
2713
2714 /* Create a new symbol with printname NAME */
2715
2716 static
2717 struct symbol *
2718 new_symbol(name)
2719 char *name;
2720 {
2721 struct symbol *s = (struct symbol *)
2722 obstack_alloc (symbol_obstack, sizeof (struct symbol));
2723
2724 memset (s, 0, sizeof (*s));
2725 SYMBOL_NAME(s) = name;
2726 return s;
2727 }
2728
2729 /* Create a new type with printname NAME */
2730
2731 static
2732 struct type *
2733 new_type(name)
2734 char *name;
2735 {
2736 struct type *t = (struct type *)
2737 obstack_alloc (symbol_obstack, sizeof (struct type));
2738
2739 memset (t, 0, sizeof (*t));
2740 TYPE_VPTR_FIELDNO (t) = -1;
2741 TYPE_NAME(t) = name;
2742 TYPE_CPLUS_SPECIFIC(t) = &cplus_struct_default;
2743 return t;
2744 }
2745
2746 /* Create and initialize a new type with printname NAME.
2747 CODE and LENGTH are the initial info we put in,
2748 UNS says whether the type is unsigned or not. */
2749
2750 static
2751 struct type *
2752 make_type(code, length, uns, name)
2753 enum type_code code;
2754 int length, uns;
2755 char *name;
2756 {
2757 register struct type *type;
2758
2759 /* FIXME, I don't think this ever gets freed. */
2760 type = (struct type *) xzalloc(sizeof(struct type));
2761 TYPE_CODE(type) = code;
2762 TYPE_LENGTH(type) = length;
2763 TYPE_FLAGS(type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2764 TYPE_NAME(type) = name;
2765 TYPE_VPTR_FIELDNO (type) = -1;
2766
2767 if (code != TYPE_CODE_METHOD && code != TYPE_CODE_FUNC)
2768 TYPE_CPLUS_SPECIFIC(type) = &cplus_struct_default;
2769 return type;
2770 }
2771 \f
2772 /* Things used for calling functions in the inferior.
2773 These functions are exported to our companion
2774 mips-tdep.c file and are here because they play
2775 with the symbol-table explicitly. */
2776
2777 /* Sigtramp: make sure we have all the necessary information
2778 about the signal trampoline code. Since the official code
2779 from MIPS does not do so, we make up that information ourselves.
2780 If they fix the library (unlikely) this code will neutralize itself. */
2781
2782 static
2783 fixup_sigtramp()
2784 {
2785 struct symbol *s;
2786 struct symtab *st;
2787 struct block *b, *b0;
2788
2789 sigtramp_address = -1;
2790
2791 /* We know it is sold as sigvec */
2792 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2793
2794 /* Most programs do not play with signals */
2795 if (s == 0)
2796 return;
2797
2798 b0 = SYMBOL_BLOCK_VALUE(s);
2799
2800 /* A label of sigvec, to be more precise */
2801 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2802
2803 /* But maybe this program uses its own version of sigvec */
2804 if (s == 0)
2805 return;
2806
2807 sigtramp_address = SYMBOL_VALUE(s);
2808 sigtramp_end = sigtramp_address + 0x88; /* black magic */
2809
2810 /* Did we or MIPSco fix the library ? */
2811 if (SYMBOL_CLASS(s) == LOC_BLOCK)
2812 return;
2813
2814 /* But what symtab does it live in ? */
2815 st = find_pc_symtab(SYMBOL_VALUE(s));
2816
2817 /*
2818 * Ok, there goes the fix: turn it into a procedure, with all the
2819 * needed info. Note we make it a nested procedure of sigvec,
2820 * which is the way the (assembly) code is actually written.
2821 */
2822 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2823 SYMBOL_CLASS(s) = LOC_BLOCK;
2824 SYMBOL_TYPE(s) = make_type(TYPE_CODE_FUNC, 4, 0, 0);
2825 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
2826
2827 /* Need a block to allocate .gdbinfo. in */
2828 b = new_block(1);
2829 SYMBOL_BLOCK_VALUE(s) = b;
2830 BLOCK_START(b) = sigtramp_address;
2831 BLOCK_END(b) = sigtramp_end;
2832 BLOCK_FUNCTION(b) = s;
2833 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
2834 add_block(b, st);
2835 sort_blocks(st);
2836
2837 /* Make a .gdbinfo. for it */
2838 {
2839 struct mips_extra_func_info *e =
2840 (struct mips_extra_func_info *)
2841 xzalloc(sizeof(struct mips_extra_func_info));
2842
2843 e->numargs = 0; /* the kernel thinks otherwise */
2844 /* align_longword(sigcontext + SIGFRAME) */
2845 e->framesize = 0x150;
2846 e->framereg = SP_REGNUM;
2847 e->pcreg = 31;
2848 e->regmask = -2;
2849 e->regoffset = -(41 * sizeof(int));
2850 e->fregmask = -1;
2851 e->fregoffset = -(37 * sizeof(int));
2852 e->isym = (long)s;
2853
2854 s = new_symbol(".gdbinfo.");
2855 SYMBOL_VALUE(s) = (int) e;
2856 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2857 SYMBOL_CLASS(s) = LOC_CONST;
2858 SYMBOL_TYPE(s) = builtin_type_void;
2859 }
2860
2861 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
2862 }
2863 \f
2864 /* Initialization */
2865
2866 static struct sym_fns ecoff_sym_fns = {"ecoff", 5,
2867 mipscoff_new_init, mipscoff_symfile_init,
2868 mipscoff_symfile_read};
2869
2870 _initialize_mipsread ()
2871 {
2872 add_symtab_fns (&ecoff_sym_fns);
2873
2874 /* Missing basic types */
2875 builtin_type_string = make_type(TYPE_CODE_PASCAL_ARRAY,
2876 1, 0, "string");
2877 builtin_type_complex = make_type(TYPE_CODE_FLT,
2878 2 * sizeof(float), 0, "complex");
2879 builtin_type_double_complex = make_type(TYPE_CODE_FLT,
2880 2 * sizeof(double), 0, "double_complex");
2881 builtin_type_fixed_dec = make_type(TYPE_CODE_INT, sizeof(int),
2882 0, "fixed_decimal");
2883 builtin_type_float_dec = make_type(TYPE_CODE_FLT, sizeof(double),
2884 0, "floating_decimal");
2885 }
This page took 0.091559 seconds and 5 git commands to generate.