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