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