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