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