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