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