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