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