* stabsread.c (define_symbol): If REG_STRUCT_HAS_ADDR, also
[deliverable/binutils-gdb.git] / gdb / mdebugread.c
CommitLineData
a2f1e2e5 1/* Read a symbol table in ECOFF format (Third-Eye).
0434c1a0
PS
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
a2f1e2e5
ILT
4 Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
5 CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor
6 at Cygnus Support.
7
8This file is part of GDB.
9
10This program is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2 of the License, or
13(at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23
24/* This module provides the function mdebug_build_psymtabs. It reads
25 ECOFF debugging information into partial symbol tables. The
26 debugging information is read from two structures. A struct
27 ecoff_debug_swap includes the sizes of each ECOFF structure and
28 swapping routines; these are fixed for a particular target. A
29 struct ecoff_debug_info points to the debugging information for a
30 particular object file.
31
32 ECOFF symbol tables are mostly written in the byte order of the
33 target machine. However, one section of the table (the auxiliary
34 symbol information) is written in the host byte order. There is a
35 bit in the other symbol info which describes which host byte order
36 was used. ECOFF thereby takes the trophy from Intel `b.out' for
37 the most brain-dead adaptation of a file format to byte order.
38
39 This module can read all four of the known byte-order combinations,
40 on any type of host. */
41
42#include "defs.h"
43#include "symtab.h"
44#include "gdbtypes.h"
45#include "gdbcore.h"
46#include "symfile.h"
47#include "objfiles.h"
48#include "obstack.h"
49#include "buildsym.h"
50#include "stabsread.h"
51#include "complaints.h"
52
53#if !defined (SEEK_SET)
54#define SEEK_SET 0
55#define SEEK_CUR 1
56#endif
57
58/* These are needed if the tm.h file does not contain the necessary
59 mips specific definitions. */
60
61#ifndef MIPS_EFI_SYMBOL_NAME
62#define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
63#include "coff/sym.h"
64#include "coff/symconst.h"
65typedef struct mips_extra_func_info {
66 long numargs;
67 PDR pdr;
68} *mips_extra_func_info_t;
69#ifndef RA_REGNUM
70#define RA_REGNUM 0
71#endif
72#endif
73
74#ifdef USG
75#include <sys/types.h>
76#endif
77
78#include <sys/param.h>
79#include <sys/file.h>
80#include <sys/stat.h>
81#include <string.h>
82
83#include "gdb-stabs.h"
84
85#include "bfd.h"
86
87#include "coff/ecoff.h" /* COFF-like aspects of ecoff files */
88
89#include "libaout.h" /* Private BFD a.out information. */
90#include "aout/aout64.h"
91#include "aout/stab_gnu.h" /* STABS information */
92
93#include "expression.h"
94#include "language.h" /* Needed inside partial-stab.h */
95
96/* Provide a default mapping from a ecoff register number to a gdb REGNUM. */
97#ifndef ECOFF_REG_TO_REGNUM
98#define ECOFF_REG_TO_REGNUM(num) (num)
99#endif
100
101/* Each partial symbol table entry contains a pointer to private data
102 for the read_symtab() function to use when expanding a partial
103 symbol table entry to a full symbol table entry.
104
105 For mdebugread this structure contains the index of the FDR that this
106 psymtab represents and a pointer to the BFD that the psymtab was
107 created from. */
108
109#define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
110#define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
111#define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
112#define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
113#define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
114#define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
115
116struct symloc
117{
118 int fdr_idx;
119 bfd *cur_bfd;
120 const struct ecoff_debug_swap *debug_swap;
121 struct ecoff_debug_info *debug_info;
122 struct mdebug_pending **pending_list;
123 EXTR *extern_tab; /* Pointer to external symbols for this file. */
124 int extern_count; /* Size of extern_tab. */
125 enum language pst_language;
126};
127
128/* Things we import explicitly from other modules */
129
130extern int info_verbose;
131
132/* Various complaints about symbol reading that don't abort the process */
133
134static struct complaint bad_file_number_complaint =
135{"bad file number %d", 0, 0};
136
137static struct complaint index_complaint =
138{"bad aux index at symbol %s", 0, 0};
139
140static struct complaint aux_index_complaint =
141{"bad proc end in aux found from symbol %s", 0, 0};
142
143static struct complaint block_index_complaint =
144{"bad aux index at block symbol %s", 0, 0};
145
146static struct complaint unknown_ext_complaint =
147{"unknown external symbol %s", 0, 0};
148
149static struct complaint unknown_sym_complaint =
150{"unknown local symbol %s", 0, 0};
151
152static struct complaint unknown_st_complaint =
153{"with type %d", 0, 0};
154
155static struct complaint block_overflow_complaint =
156{"block containing %s overfilled", 0, 0};
157
158static struct complaint basic_type_complaint =
159{"cannot map ECOFF basic type 0x%x for %s", 0, 0};
160
161static struct complaint unknown_type_qual_complaint =
162{"unknown type qualifier 0x%x", 0, 0};
163
164static struct complaint array_index_type_complaint =
165{"illegal array index type for %s, assuming int", 0, 0};
166
167static struct complaint bad_tag_guess_complaint =
168{"guessed tag type of %s incorrectly", 0, 0};
169
170static struct complaint block_member_complaint =
171{"declaration block contains unhandled symbol type %d", 0, 0};
172
173static struct complaint stEnd_complaint =
174{"stEnd with storage class %d not handled", 0, 0};
175
176static struct complaint unknown_mdebug_symtype_complaint =
177{"unknown symbol type 0x%x", 0, 0};
178
179static struct complaint stab_unknown_complaint =
180{"unknown stabs symbol %s", 0, 0};
181
182static struct complaint pdr_for_nonsymbol_complaint =
183{"PDR for %s, but no symbol", 0, 0};
184
185static struct complaint pdr_static_symbol_complaint =
186{"can't handle PDR for static proc at 0x%lx", 0, 0};
187
188static struct complaint bad_setjmp_pdr_complaint =
189{"fixing bad setjmp PDR from libc", 0, 0};
190
191static struct complaint bad_fbitfield_complaint =
192{"can't handle TIR fBitfield for %s", 0, 0};
193
194static struct complaint bad_continued_complaint =
195{"illegal TIR continued for %s", 0, 0};
196
197static struct complaint bad_rfd_entry_complaint =
198{"bad rfd entry for %s: file %d, index %d", 0, 0};
199
200static struct complaint unexpected_type_code_complaint =
201{"unexpected type code for %s", 0, 0};
202
203static struct complaint unable_to_cross_ref_complaint =
204{"unable to cross ref btTypedef for %s", 0, 0};
205
206static struct complaint illegal_forward_tq0_complaint =
207{"illegal tq0 in forward typedef for %s", 0, 0};
208
209static struct complaint illegal_forward_bt_complaint =
210{"illegal bt %d in forward typedef for %s", 0, 0};
211
212static struct complaint bad_linetable_guess_complaint =
213{"guessed size of linetable for %s incorrectly", 0, 0};
214
215static struct complaint bad_ext_ifd_complaint =
216{"bad ifd for external symbol: %d (max %d)", 0, 0};
217
218static struct complaint bad_ext_iss_complaint =
219{"bad iss for external symbol: %ld (max %ld)", 0, 0};
220
221/* Macros and extra defs */
222
223/* Puns: hard to find whether -g was used and how */
224
225#define MIN_GLEVEL GLEVEL_0
226#define compare_glevel(a,b) \
227 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
228 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
229\f
230/* Things that really are local to this module */
231
232/* Remember what we deduced to be the source language of this psymtab. */
233
234static enum language psymtab_language = language_unknown;
235
236/* Current BFD. */
237
238static bfd *cur_bfd;
239
240/* How to parse debugging information for CUR_BFD. */
241
242static const struct ecoff_debug_swap *debug_swap;
243
244/* Pointers to debugging information for CUR_BFD. */
245
246static struct ecoff_debug_info *debug_info;
247
248/* Pointer to current file decriptor record, and its index */
249
250static FDR *cur_fdr;
251static int cur_fd;
252
253/* Index of current symbol */
254
255static int cur_sdx;
256
257/* Note how much "debuggable" this image is. We would like
258 to see at least one FDR with full symbols */
259
260static max_gdbinfo;
261static max_glevel;
262
263/* When examining .o files, report on undefined symbols */
264
265static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
266
267/* Pseudo symbol to use when putting stabs into the symbol table. */
268
269static char stabs_symbol[] = STABS_SYMBOL;
270
504ccfd7
JK
271/* Types corresponding to btComplex, btDComplex, etc. These are here
272 rather than in gdbtypes.c or some such, because the meaning of codes
273 like btComplex is specific to the mdebug debug format. FIXME: We should
274 be using our own types thoughout this file, instead of sometimes using
275 builtin_type_*. */
276
277static struct type *mdebug_type_complex;
278static struct type *mdebug_type_double_complex;
279static struct type *mdebug_type_fixed_dec;
280static struct type *mdebug_type_float_dec;
281static struct type *mdebug_type_string;
a2f1e2e5
ILT
282
283/* Forward declarations */
284
285static int
286upgrade_type PARAMS ((int, struct type **, int, union aux_ext *, int, char *));
287
288static void
289parse_partial_symbols PARAMS ((struct objfile *,
290 struct section_offsets *));
291
292static FDR
293*get_rfd PARAMS ((int, int));
294
295static int
296cross_ref PARAMS ((int, union aux_ext *, struct type **, enum type_code,
297 char **, int, char *));
298
299static struct symbol *
300new_symbol PARAMS ((char *));
301
302static struct type *
303new_type PARAMS ((char *));
304
305static struct block *
306new_block PARAMS ((int));
307
308static struct symtab *
309new_symtab PARAMS ((char *, int, int, struct objfile *));
310
311static struct linetable *
312new_linetable PARAMS ((int));
313
314static struct blockvector *
315new_bvect PARAMS ((int));
316
317static int
318parse_symbol PARAMS ((SYMR *, union aux_ext *, char *, int));
319
320static struct type *
321parse_type PARAMS ((int, union aux_ext *, unsigned int, int *, int, char *));
322
323static struct symbol *
324mylookup_symbol PARAMS ((char *, struct block *, enum namespace,
325 enum address_class));
326
327static struct block *
328shrink_block PARAMS ((struct block *, struct symtab *));
329
330static PTR
331xzalloc PARAMS ((unsigned int));
332
333static void
334sort_blocks PARAMS ((struct symtab *));
335
336static int
337compare_blocks PARAMS ((const void *, const void *));
338
339static struct partial_symtab *
847d9775 340new_psymtab PARAMS ((char *, struct objfile *, struct section_offsets *));
a2f1e2e5
ILT
341
342static void
343psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));
344
345static void
346add_block PARAMS ((struct block *, struct symtab *));
347
348static void
349add_symbol PARAMS ((struct symbol *, struct block *));
350
351static int
352add_line PARAMS ((struct linetable *, int, CORE_ADDR, int));
353
354static struct linetable *
355shrink_linetable PARAMS ((struct linetable *));
356
847d9775
PS
357static void
358handle_psymbol_enumerators PARAMS ((struct objfile *, FDR *, int));
359
a2f1e2e5
ILT
360static char *
361mdebug_next_symbol_text PARAMS ((void));
362\f
363/* Address bounds for the signal trampoline in inferior, if any */
364
365CORE_ADDR sigtramp_address, sigtramp_end;
366
367/* Allocate zeroed memory */
368
369static PTR
370xzalloc (size)
371 unsigned int size;
372{
373 PTR p = xmalloc (size);
374
375 memset (p, 0, size);
376 return p;
377}
378
379/* Exported procedure: Builds a symtab from the PST partial one.
380 Restores the environment in effect when PST was created, delegates
381 most of the work to an ancillary procedure, and sorts
382 and reorders the symtab list at the end */
383
384static void
385mdebug_psymtab_to_symtab (pst)
386 struct partial_symtab *pst;
387{
388
389 if (!pst)
390 return;
391
392 if (info_verbose)
393 {
394 printf_filtered ("Reading in symbols for %s...", pst->filename);
395 gdb_flush (gdb_stdout);
396 }
397
398 next_symbol_text_func = mdebug_next_symbol_text;
399
400 psymtab_to_symtab_1 (pst, pst->filename);
401
402 /* Match with global symbols. This only needs to be done once,
403 after all of the symtabs and dependencies have been read in. */
404 scan_file_globals (pst->objfile);
405
406 if (info_verbose)
407 printf_filtered ("done.\n");
408}
409\f
410/* File-level interface functions */
411
412/* Find a file descriptor given its index RF relative to a file CF */
413
414static FDR *
415get_rfd (cf, rf)
416 int cf, rf;
417{
418 FDR *fdrs;
419 register FDR *f;
420 RFDT rfd;
421
422 fdrs = debug_info->fdr;
423 f = fdrs + cf;
424 /* Object files do not have the RFD table, all refs are absolute */
425 if (f->rfdBase == 0)
426 return fdrs + rf;
427 (*debug_swap->swap_rfd_in) (cur_bfd,
428 ((char *) debug_info->external_rfd
429 + ((f->rfdBase + rf)
430 * debug_swap->external_rfd_size)),
431 &rfd);
432 return fdrs + rfd;
433}
434
435/* Return a safer print NAME for a file descriptor */
436
437static char *
438fdr_name (f)
439 FDR *f;
440{
441 if (f->rss == -1)
442 return "<stripped file>";
443 if (f->rss == 0)
444 return "<NFY>";
445 return debug_info->ss + f->issBase + f->rss;
446}
447
448
449/* Read in and parse the symtab of the file OBJFILE. Symbols from
450 different sections are relocated via the SECTION_OFFSETS. */
451
452void
453mdebug_build_psymtabs (objfile, swap, info, section_offsets)
454 struct objfile *objfile;
455 const struct ecoff_debug_swap *swap;
456 struct ecoff_debug_info *info;
457 struct section_offsets *section_offsets;
458{
459 cur_bfd = objfile->obfd;
460 debug_swap = swap;
461 debug_info = info;
462
463 /* Make sure all the FDR information is swapped in. */
464 if (info->fdr == (FDR *) NULL)
465 {
466 char *fdr_src;
467 char *fdr_end;
468 FDR *fdr_ptr;
469
470 info->fdr = (FDR *) obstack_alloc (&objfile->psymbol_obstack,
471 (info->symbolic_header.ifdMax
472 * sizeof (FDR)));
473 fdr_src = info->external_fdr;
474 fdr_end = (fdr_src
475 + info->symbolic_header.ifdMax * swap->external_fdr_size);
476 fdr_ptr = info->fdr;
477 for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
478 (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
479 }
480
481 parse_partial_symbols (objfile, section_offsets);
482
483#if 0
484 /* Check to make sure file was compiled with -g. If not, warn the
485 user of this limitation. */
486 if (compare_glevel (max_glevel, GLEVEL_2) < 0)
487 {
488 if (max_gdbinfo == 0)
489 printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n",
490 objfile->name);
491 printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n");
492 gdb_flush (gdb_stdout);
493 }
494#endif
495}
496\f
497/* Local utilities */
498
499/* Map of FDR indexes to partial symtabs */
500
501struct pst_map
502{
503 struct partial_symtab *pst; /* the psymtab proper */
504 long n_globals; /* exported globals (external symbols) */
505 long globals_offset; /* cumulative */
506};
507
508
509/* Utility stack, used to nest procedures and blocks properly.
510 It is a doubly linked list, to avoid too many alloc/free.
511 Since we might need it quite a few times it is NOT deallocated
512 after use. */
513
514static struct parse_stack
515{
516 struct parse_stack *next, *prev;
517 struct symtab *cur_st; /* Current symtab. */
518 struct block *cur_block; /* Block in it. */
519
520 /* What are we parsing. stFile, or stBlock are for files and
521 blocks. stProc or stStaticProc means we have seen the start of a
522 procedure, but not the start of the block within in. When we see
523 the start of that block, we change it to stNil, without pushing a
524 new block, i.e. stNil means both a procedure and a block. */
525
526 int blocktype;
527
528 int maxsyms; /* Max symbols in this block. */
529 struct type *cur_type; /* Type we parse fields for. */
530 int cur_field; /* Field number in cur_type. */
531 CORE_ADDR procadr; /* Start addres of this procedure */
532 int numargs; /* Its argument count */
533}
534
535 *top_stack; /* Top stack ptr */
536
537
538/* Enter a new lexical context */
539
540static void
541push_parse_stack ()
542{
543 struct parse_stack *new;
544
545 /* Reuse frames if possible */
546 if (top_stack && top_stack->prev)
547 new = top_stack->prev;
548 else
549 new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
550 /* Initialize new frame with previous content */
551 if (top_stack)
552 {
553 register struct parse_stack *prev = new->prev;
554
555 *new = *top_stack;
556 top_stack->prev = new;
557 new->prev = prev;
558 new->next = top_stack;
559 }
560 top_stack = new;
561}
562
563/* Exit a lexical context */
564
565static void
566pop_parse_stack ()
567{
568 if (!top_stack)
569 return;
570 if (top_stack->next)
571 top_stack = top_stack->next;
572}
573
574
575/* Cross-references might be to things we haven't looked at
576 yet, e.g. type references. To avoid too many type
577 duplications we keep a quick fixup table, an array
578 of lists of references indexed by file descriptor */
579
580struct mdebug_pending
581{
582 struct mdebug_pending *next; /* link */
583 char *s; /* the unswapped symbol */
584 struct type *t; /* its partial type descriptor */
585};
586
587
588/* The pending information is kept for an entire object file, and used
589 to be in the sym_private field. I took it out when I split
590 mdebugread from mipsread, because this might not be the only type
591 of symbols read from an object file. Instead, we allocate the
592 pending information table when we create the partial symbols, and
593 we store a pointer to the single table in each psymtab. */
594
595static struct mdebug_pending **pending_list;
596
597/* Check whether we already saw symbol SH in file FH */
598
599static struct mdebug_pending *
600is_pending_symbol (fh, sh)
601 FDR *fh;
602 char *sh;
603{
604 int f_idx = fh - debug_info->fdr;
605 register struct mdebug_pending *p;
606
607 /* Linear search is ok, list is typically no more than 10 deep */
608 for (p = pending_list[f_idx]; p; p = p->next)
609 if (p->s == sh)
610 break;
611 return p;
612}
613
614/* Add a new symbol SH of type T */
615
616static void
617add_pending (fh, sh, t)
618 FDR *fh;
619 char *sh;
620 struct type *t;
621{
622 int f_idx = fh - debug_info->fdr;
623 struct mdebug_pending *p = is_pending_symbol (fh, sh);
624
625 /* Make sure we do not make duplicates */
626 if (!p)
627 {
628 p = ((struct mdebug_pending *)
629 obstack_alloc (&current_objfile->psymbol_obstack,
630 sizeof (struct mdebug_pending)));
631 p->s = sh;
632 p->t = t;
633 p->next = pending_list[f_idx];
634 pending_list[f_idx] = p;
635 }
636}
637\f
638
639/* Parsing Routines proper. */
640
641/* Parse a single symbol. Mostly just make up a GDB symbol for it.
642 For blocks, procedures and types we open a new lexical context.
643 This is basically just a big switch on the symbol's type. Argument
644 AX is the base pointer of aux symbols for this file (fh->iauxBase).
645 EXT_SH points to the unswapped symbol, which is needed for struct,
646 union, etc., types; it is NULL for an EXTR. BIGEND says whether
647 aux symbols are big-endian or little-endian. Return count of
648 SYMR's handled (normally one). */
649
650static int
651parse_symbol (sh, ax, ext_sh, bigend)
652 SYMR *sh;
653 union aux_ext *ax;
654 char *ext_sh;
655 int bigend;
656{
657 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
658 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *)) =
659 debug_swap->swap_sym_in;
660 char *name;
661 struct symbol *s;
662 struct block *b;
663 struct mdebug_pending *pend;
664 struct type *t;
665 struct field *f;
666 int count = 1;
667 enum address_class class;
668 TIR tir;
669 long svalue = sh->value;
670 int bitsize;
671
672 if (ext_sh == (char *) NULL)
673 name = debug_info->ssext + sh->iss;
674 else
675 name = debug_info->ss + cur_fdr->issBase + sh->iss;
676
677 switch (sh->st)
678 {
679 case stNil:
680 break;
681
682 case stGlobal: /* external symbol, goes into global block */
683 class = LOC_STATIC;
684 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
685 GLOBAL_BLOCK);
686 s = new_symbol (name);
687 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
688 goto data;
689
690 case stStatic: /* static data, goes into current block. */
691 class = LOC_STATIC;
692 b = top_stack->cur_block;
693 s = new_symbol (name);
694 if (sh->sc == scCommon)
695 {
696 /* It is a FORTRAN common block. At least for SGI Fortran the
697 address is not in the symbol; we need to fix it later in
698 scan_file_globals. */
699 int bucket = hashname (SYMBOL_NAME (s));
700 SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
701 global_sym_chain[bucket] = s;
702 }
703 else
704 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
705 goto data;
706
707 case stLocal: /* local variable, goes into current block */
708 if (sh->sc == scRegister)
709 {
710 class = LOC_REGISTER;
711 svalue = ECOFF_REG_TO_REGNUM (svalue);
712 }
713 else
714 class = LOC_LOCAL;
715 b = top_stack->cur_block;
716 s = new_symbol (name);
717 SYMBOL_VALUE (s) = svalue;
718
719 data: /* Common code for symbols describing data */
720 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
721 SYMBOL_CLASS (s) = class;
722 add_symbol (s, b);
723
724 /* Type could be missing in a number of cases */
10373914 725 if (sh->sc == scUndefined || sh->sc == scNil)
a2f1e2e5
ILT
726 SYMBOL_TYPE (s) = builtin_type_int; /* undefined? */
727 else
728 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
729 /* Value of a data symbol is its memory address */
730 break;
731
732 case stParam: /* arg to procedure, goes into current block */
733 max_gdbinfo++;
734 top_stack->numargs++;
735
736 /* Special GNU C++ name. */
737 if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
738 name = "this"; /* FIXME, not alloc'd in obstack */
739 s = new_symbol (name);
740
741 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
742 switch (sh->sc)
743 {
744 case scRegister:
745 /* Pass by value in register. */
746 SYMBOL_CLASS(s) = LOC_REGPARM;
747 svalue = ECOFF_REG_TO_REGNUM (svalue);
748 break;
749 case scVar:
750 /* Pass by reference on stack. */
751 SYMBOL_CLASS(s) = LOC_REF_ARG;
752 break;
753 case scVarRegister:
754 /* Pass by reference in register. */
755 SYMBOL_CLASS(s) = LOC_REGPARM_ADDR;
756 svalue = ECOFF_REG_TO_REGNUM (svalue);
757 break;
758 default:
759 /* Pass by value on stack. */
760 SYMBOL_CLASS(s) = LOC_ARG;
761 break;
762 }
763 SYMBOL_VALUE (s) = svalue;
764 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
765 add_symbol (s, top_stack->cur_block);
766#if 0
767 /* FIXME: This has not been tested. See dbxread.c */
768 /* Add the type of this parameter to the function/procedure
769 type of this block. */
770 add_param_to_type (&top_stack->cur_block->function->type, s);
771#endif
772 break;
773
774 case stLabel: /* label, goes into current block */
775 s = new_symbol (name);
776 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; /* so that it can be used */
777 SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */
778 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
779 SYMBOL_TYPE (s) = builtin_type_int;
780 add_symbol (s, top_stack->cur_block);
781 break;
782
783 case stProc: /* Procedure, usually goes into global block */
784 case stStaticProc: /* Static procedure, goes into current block */
785 s = new_symbol (name);
786 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
787 SYMBOL_CLASS (s) = LOC_BLOCK;
788 /* Type of the return value */
789 if (sh->sc == scUndefined || sh->sc == scNil)
790 t = builtin_type_int;
791 else
792 t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
793 b = top_stack->cur_block;
794 if (sh->st == stProc)
795 {
796 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
797 /* The next test should normally be true, but provides a
798 hook for nested functions (which we don't want to make
799 global). */
800 if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
801 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
802 /* Irix 5 sometimes has duplicate names for the same
803 function. We want to add such names up at the global
804 level, not as a nested function. */
805 else if (sh->value == top_stack->procadr)
806 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
807 }
808 add_symbol (s, b);
809
810 /* Make a type for the procedure itself */
811#if 0
812 /* FIXME: This has not been tested yet! See dbxread.c */
813 /* Generate a template for the type of this function. The
814 types of the arguments will be added as we read the symbol
815 table. */
816 memcpy (lookup_function_type (t), SYMBOL_TYPE (s), sizeof (struct type));
817#else
818 SYMBOL_TYPE (s) = lookup_function_type (t);
819#endif
820
821 /* Create and enter a new lexical context */
822 b = new_block (top_stack->maxsyms);
823 SYMBOL_BLOCK_VALUE (s) = b;
824 BLOCK_FUNCTION (b) = s;
825 BLOCK_START (b) = BLOCK_END (b) = sh->value;
826 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
827 add_block (b, top_stack->cur_st);
828
829 /* Not if we only have partial info */
830 if (sh->sc == scUndefined || sh->sc == scNil)
831 break;
832
833 push_parse_stack ();
834 top_stack->cur_block = b;
835 top_stack->blocktype = sh->st;
836 top_stack->cur_type = SYMBOL_TYPE (s);
837 top_stack->cur_field = -1;
838 top_stack->procadr = sh->value;
839 top_stack->numargs = 0;
840 break;
841
842 /* Beginning of code for structure, union, and enum definitions.
843 They all share a common set of local variables, defined here. */
844 {
845 enum type_code type_code;
846 char *ext_tsym;
847 int nfields;
848 long max_value;
849 struct field *f;
850
851 case stStruct: /* Start a block defining a struct type */
852 type_code = TYPE_CODE_STRUCT;
853 goto structured_common;
854
855 case stUnion: /* Start a block defining a union type */
856 type_code = TYPE_CODE_UNION;
857 goto structured_common;
858
859 case stEnum: /* Start a block defining an enum type */
860 type_code = TYPE_CODE_ENUM;
861 goto structured_common;
862
863 case stBlock: /* Either a lexical block, or some type */
864 if (sh->sc != scInfo && sh->sc != scCommon)
865 goto case_stBlock_code; /* Lexical block */
866
867 type_code = TYPE_CODE_UNDEF; /* We have a type. */
868
869 /* Common code for handling struct, union, enum, and/or as-yet-
870 unknown-type blocks of info about structured data. `type_code'
871 has been set to the proper TYPE_CODE, if we know it. */
872 structured_common:
873 push_parse_stack ();
874 top_stack->blocktype = stBlock;
875
876 /* First count the number of fields and the highest value. */
877 nfields = 0;
878 max_value = 0;
879 for (ext_tsym = ext_sh + external_sym_size;
880 ;
881 ext_tsym += external_sym_size)
882 {
883 SYMR tsym;
884
885 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
886
887 switch (tsym.st)
888 {
889 case stEnd:
890 goto end_of_fields;
891
892 case stMember:
893 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
894 /* If the type of the member is Nil (or Void),
895 without qualifiers, assume the tag is an
896 enumeration. */
897 if (tsym.index == indexNil)
898 type_code = TYPE_CODE_ENUM;
899 else
900 {
901 ecoff_swap_tir_in (bigend,
902 &ax[tsym.index].a_ti,
903 &tir);
904 if ((tir.bt == btNil || tir.bt == btVoid)
905 && tir.tq0 == tqNil)
906 type_code = TYPE_CODE_ENUM;
907 }
908 nfields++;
909 if (tsym.value > max_value)
910 max_value = tsym.value;
911 break;
912
913 case stBlock:
914 case stUnion:
915 case stEnum:
916 case stStruct:
917 {
918#if 0
919 /* This is a no-op; is it trying to tell us something
920 we should be checking? */
921 if (tsym.sc == scVariant); /*UNIMPLEMENTED*/
922#endif
923 if (tsym.index != 0)
924 {
925 /* This is something like a struct within a
926 struct. Skip over the fields of the inner
927 struct. The -1 is because the for loop will
928 increment ext_tsym. */
929 ext_tsym = ((char *) debug_info->external_sym
930 + ((cur_fdr->isymBase + tsym.index - 1)
931 * external_sym_size));
932 }
933 }
934 break;
935
936 case stTypedef:
937 /* mips cc puts out a typedef for struct x if it is not yet
938 defined when it encounters
939 struct y { struct x *xp; };
940 Just ignore it. */
941 break;
942
943 default:
944 complain (&block_member_complaint, tsym.st);
945 }
946 }
947 end_of_fields:;
948
949 /* In an stBlock, there is no way to distinguish structs,
950 unions, and enums at this point. This is a bug in the
951 original design (that has been fixed with the recent
952 addition of the stStruct, stUnion, and stEnum symbol
953 types.) The way you can tell is if/when you see a variable
954 or field of that type. In that case the variable's type
955 (in the AUX table) says if the type is struct, union, or
956 enum, and points back to the stBlock here. So you can
957 patch the tag kind up later - but only if there actually is
958 a variable or field of that type.
959
960 So until we know for sure, we will guess at this point.
961 The heuristic is:
962 If the first member has index==indexNil or a void type,
963 assume we have an enumeration.
964 Otherwise, if there is more than one member, and all
965 the members have offset 0, assume we have a union.
966 Otherwise, assume we have a struct.
967
968 The heuristic could guess wrong in the case of of an
969 enumeration with no members or a union with one (or zero)
970 members, or when all except the last field of a struct have
971 width zero. These are uncommon and/or illegal situations,
972 and in any case guessing wrong probably doesn't matter
973 much.
974
975 But if we later do find out we were wrong, we fixup the tag
976 kind. Members of an enumeration must be handled
977 differently from struct/union fields, and that is harder to
978 patch up, but luckily we shouldn't need to. (If there are
979 any enumeration members, we can tell for sure it's an enum
980 here.) */
981
982 if (type_code == TYPE_CODE_UNDEF)
983 if (nfields > 1 && max_value == 0)
984 type_code = TYPE_CODE_UNION;
985 else
986 type_code = TYPE_CODE_STRUCT;
987
988 /* Create a new type or use the pending type. */
989 pend = is_pending_symbol (cur_fdr, ext_sh);
990 if (pend == (struct mdebug_pending *) NULL)
991 {
992 t = new_type (NULL);
993 add_pending (cur_fdr, ext_sh, t);
994 }
995 else
996 t = pend->t;
997
a8c49897
PS
998 /* Do not set the tag name if it is a compiler generated tag name
999 (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
1000 Alpha cc puts out an sh->iss of zero for those. */
1001 if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
a2f1e2e5
ILT
1002 TYPE_TAG_NAME (t) = NULL;
1003 else
1004 TYPE_TAG_NAME (t) = obconcat (&current_objfile->symbol_obstack,
1005 "", "", name);
1006
1007 TYPE_CODE (t) = type_code;
1008 TYPE_LENGTH (t) = sh->value;
1009 TYPE_NFIELDS (t) = nfields;
1010 TYPE_FIELDS (t) = f = ((struct field *)
1011 TYPE_ALLOC (t,
1012 nfields * sizeof (struct field)));
1013
1014 if (type_code == TYPE_CODE_ENUM)
1015 {
1016 /* This is a non-empty enum. */
9d51b3c5 1017
a8c49897 1018 /* DEC c89 has the number of enumerators in the sh.value field,
9d51b3c5
PS
1019 not the type length, so we have to compensate for that
1020 incompatibility quirk.
1021 This might do the wrong thing for an enum with one or two
1022 enumerators and gcc -gcoff -fshort-enums, but these cases
1023 are hopefully rare enough. */
1024 if (TYPE_LENGTH (t) == TYPE_NFIELDS (t))
1025 TYPE_LENGTH (t) = TARGET_INT_BIT / HOST_CHAR_BIT;
a2f1e2e5
ILT
1026 for (ext_tsym = ext_sh + external_sym_size;
1027 ;
1028 ext_tsym += external_sym_size)
1029 {
1030 SYMR tsym;
1031 struct symbol *enum_sym;
1032
1033 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
1034
1035 if (tsym.st != stMember)
1036 break;
1037
1038 f->bitpos = tsym.value;
1039 f->type = t;
1040 f->name = debug_info->ss + cur_fdr->issBase + tsym.iss;
1041 f->bitsize = 0;
1042
1043 enum_sym = ((struct symbol *)
1044 obstack_alloc (&current_objfile->symbol_obstack,
1045 sizeof (struct symbol)));
1046 memset ((PTR) enum_sym, 0, sizeof (struct symbol));
1047 SYMBOL_NAME (enum_sym) = f->name;
1048 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1049 SYMBOL_TYPE (enum_sym) = t;
1050 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1051 SYMBOL_VALUE (enum_sym) = tsym.value;
1052 add_symbol (enum_sym, top_stack->cur_block);
1053
1054 /* Skip the stMembers that we've handled. */
1055 count++;
1056 f++;
1057 }
1058 }
1059 /* make this the current type */
1060 top_stack->cur_type = t;
1061 top_stack->cur_field = 0;
1062
1063 /* Do not create a symbol for alpha cc unnamed structs. */
1064 if (sh->iss == 0)
1065 break;
1066
1067 /* gcc puts out an empty struct for an opaque struct definitions,
1068 do not create a symbol for it either. */
1069 if (TYPE_NFIELDS (t) == 0)
1070 {
1071 TYPE_FLAGS (t) |= TYPE_FLAG_STUB;
1072 break;
1073 }
1074
1075 s = new_symbol (name);
1076 SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE;
1077 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1078 SYMBOL_VALUE (s) = 0;
1079 SYMBOL_TYPE (s) = t;
1080 add_symbol (s, top_stack->cur_block);
1081 break;
1082
1083 /* End of local variables shared by struct, union, enum, and
1084 block (as yet unknown struct/union/enum) processing. */
1085 }
1086
1087 case_stBlock_code:
1088 /* beginnning of (code) block. Value of symbol
1089 is the displacement from procedure start */
1090 push_parse_stack ();
1091
1092 /* Do not start a new block if this is the outermost block of a
1093 procedure. This allows the LOC_BLOCK symbol to point to the
1094 block with the local variables, so funcname::var works. */
1095 if (top_stack->blocktype == stProc
1096 || top_stack->blocktype == stStaticProc)
1097 {
1098 top_stack->blocktype = stNil;
1099 break;
1100 }
1101
1102 top_stack->blocktype = stBlock;
1103 b = new_block (top_stack->maxsyms);
1104 BLOCK_START (b) = sh->value + top_stack->procadr;
1105 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1106 top_stack->cur_block = b;
1107 add_block (b, top_stack->cur_st);
1108 break;
1109
1110 case stEnd: /* end (of anything) */
1111 if (sh->sc == scInfo || sh->sc == scCommon)
1112 {
1113 /* Finished with type */
1114 top_stack->cur_type = 0;
1115 }
1116 else if (sh->sc == scText &&
1117 (top_stack->blocktype == stProc ||
1118 top_stack->blocktype == stStaticProc))
1119 {
1120 /* Finished with procedure */
1121 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
1122 struct mips_extra_func_info *e;
1123 struct block *b;
1124 int i;
1125
1126 BLOCK_END (top_stack->cur_block) += sh->value; /* size */
1127
1128 /* Make up special symbol to contain procedure specific info */
1129 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
1130 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
1131 SYMBOL_CLASS (s) = LOC_CONST;
1132 SYMBOL_TYPE (s) = builtin_type_void;
1133 e = ((struct mips_extra_func_info *)
1134 obstack_alloc (&current_objfile->symbol_obstack,
1135 sizeof (struct mips_extra_func_info)));
1136 SYMBOL_VALUE (s) = (long) e;
1137 e->numargs = top_stack->numargs;
1138 add_symbol (s, top_stack->cur_block);
1139
1140 /* Reallocate symbols, saving memory */
1141 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
1142
1143 /* f77 emits proc-level with address bounds==[0,0],
1144 So look for such child blocks, and patch them. */
1145 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
1146 {
1147 struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1148 if (BLOCK_SUPERBLOCK (b_bad) == b
1149 && BLOCK_START (b_bad) == top_stack->procadr
1150 && BLOCK_END (b_bad) == top_stack->procadr)
1151 {
1152 BLOCK_START (b_bad) = BLOCK_START (b);
1153 BLOCK_END (b_bad) = BLOCK_END (b);
1154 }
1155 }
1156 }
1157 else if (sh->sc == scText && top_stack->blocktype == stBlock)
1158 {
1159 /* End of (code) block. The value of the symbol is the
1160 displacement from the procedure`s start address of the
1161 end of this block. */
1162 BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
1163 shrink_block (top_stack->cur_block, top_stack->cur_st);
1164 }
1165 else if (sh->sc == scText && top_stack->blocktype == stNil)
1166 {
1167 /* End of outermost block. Pop parse stack and ignore. The
1168 following stEnd of stProc will take care of the block. */
1169 ;
1170 }
1171 else if (sh->sc == scText && top_stack->blocktype == stFile)
1172 {
1173 /* End of file. Pop parse stack and ignore. Higher
1174 level code deals with this. */
1175 ;
1176 }
1177 else
1178 complain (&stEnd_complaint, sh->sc);
1179
1180 pop_parse_stack (); /* restore previous lexical context */
1181 break;
1182
1183 case stMember: /* member of struct or union */
1184 f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
1185 f->name = name;
1186 f->bitpos = sh->value;
1187 bitsize = 0;
1188 f->type = parse_type (cur_fd, ax, sh->index, &bitsize, bigend, name);
1189 f->bitsize = bitsize;
1190 break;
1191
1192 case stTypedef: /* type definition */
1193 /* Typedefs for forward declarations and opaque structs from alpha cc
1194 are handled by cross_ref, skip them. */
1195 if (sh->iss == 0)
1196 break;
1197
1198 /* Parse the type or use the pending type. */
1199 pend = is_pending_symbol (cur_fdr, ext_sh);
1200 if (pend == (struct mdebug_pending *) NULL)
1201 {
1202 t = parse_type (cur_fd, ax, sh->index, (int *)NULL, bigend, name);
1203 add_pending (cur_fdr, ext_sh, t);
1204 }
1205 else
1206 t = pend->t;
1207
1208 /* mips cc puts out a typedef with the name of the struct for forward
1209 declarations. These should not go into the symbol table and
1210 TYPE_NAME should not be set for them.
1211 They can't be distinguished from an intentional typedef to
1212 the same name however:
1213 x.h:
1214 struct x { int ix; int jx; };
1215 struct xx;
1216 x.c:
1217 typedef struct x x;
1218 struct xx {int ixx; int jxx; };
1219 generates a cross referencing stTypedef for x and xx.
1220 The user visible effect of this is that the type of a pointer
1221 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1222 The problem is fixed with alpha cc. */
1223
1224 s = new_symbol (name);
1225 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1226 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1227 SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
1228 SYMBOL_TYPE (s) = t;
1229 add_symbol (s, top_stack->cur_block);
1230
1231 /* Incomplete definitions of structs should not get a name. */
1232 if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL
1233 && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
1234 || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT
1235 && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION)))
1236 {
1237 if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR
1238 || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC)
1239 {
1240 /* If we are giving a name to a type such as "pointer to
1241 foo" or "function returning foo", we better not set
1242 the TYPE_NAME. If the program contains "typedef char
1243 *caddr_t;", we don't want all variables of type char
1244 * to print as caddr_t. This is not just a
1245 consequence of GDB's type management; CC and GCC (at
1246 least through version 2.4) both output variables of
1247 either type char * or caddr_t with the type
1248 refering to the stTypedef symbol for caddr_t. If a future
1249 compiler cleans this up it GDB is not ready for it
1250 yet, but if it becomes ready we somehow need to
1251 disable this check (without breaking the PCC/GCC2.4
1252 case).
1253
1254 Sigh.
1255
1256 Fortunately, this check seems not to be necessary
1257 for anything except pointers or functions. */
1258 }
1259 else
1260 TYPE_NAME (SYMBOL_TYPE (s)) = SYMBOL_NAME (s);
1261 }
1262 break;
1263
1264 case stFile: /* file name */
1265 push_parse_stack ();
1266 top_stack->blocktype = sh->st;
1267 break;
1268
1269 /* I`ve never seen these for C */
1270 case stRegReloc:
1271 break; /* register relocation */
1272 case stForward:
1273 break; /* forwarding address */
1274 case stConstant:
1275 break; /* constant */
1276 default:
1277 complain (&unknown_mdebug_symtype_complaint, sh->st);
1278 break;
1279 }
1280
1281 return count;
1282}
1283
1284/* Parse the type information provided in the raw AX entries for
1285 the symbol SH. Return the bitfield size in BS, in case.
1286 We must byte-swap the AX entries before we use them; BIGEND says whether
1287 they are big-endian or little-endian (from fh->fBigendian). */
1288
1289static struct type *
1290parse_type (fd, ax, aux_index, bs, bigend, sym_name)
1291 int fd;
1292 union aux_ext *ax;
1293 unsigned int aux_index;
1294 int *bs;
1295 int bigend;
1296 char *sym_name;
1297{
1298 /* Null entries in this map are treated specially */
1299 static struct type **map_bt[] =
1300 {
1301 &builtin_type_void, /* btNil */
1302 0, /* btAdr */
1303 &builtin_type_char, /* btChar */
1304 &builtin_type_unsigned_char,/* btUChar */
1305 &builtin_type_short, /* btShort */
1306 &builtin_type_unsigned_short, /* btUShort */
1307 &builtin_type_int, /* btInt */
1308 &builtin_type_unsigned_int, /* btUInt */
1309 &builtin_type_long, /* btLong */
1310 &builtin_type_unsigned_long,/* btULong */
1311 &builtin_type_float, /* btFloat */
1312 &builtin_type_double, /* btDouble */
1313 0, /* btStruct */
1314 0, /* btUnion */
1315 0, /* btEnum */
1316 0, /* btTypedef */
1317 0, /* btRange */
1318 0, /* btSet */
504ccfd7
JK
1319 &mdebug_type_complex, /* btComplex */
1320 &mdebug_type_double_complex, /* btDComplex */
a2f1e2e5 1321 0, /* btIndirect */
504ccfd7
JK
1322 &mdebug_type_fixed_dec, /* btFixedDec */
1323 &mdebug_type_float_dec, /* btFloatDec */
1324 &mdebug_type_string, /* btString */
a2f1e2e5
ILT
1325 0, /* btBit */
1326 0, /* btPicture */
1327 &builtin_type_void, /* btVoid */
1328 0, /* DEC C++: Pointer to member */
1329 0, /* DEC C++: Virtual function table */
1330 0, /* DEC C++: Class (Record) */
1331 &builtin_type_long, /* btLong64 */
1332 &builtin_type_unsigned_long, /* btULong64 */
1333 &builtin_type_long_long, /* btLongLong64 */
1334 &builtin_type_unsigned_long_long, /* btULongLong64 */
1335 &builtin_type_unsigned_long, /* btAdr64 */
1336 &builtin_type_long, /* btInt64 */
1337 &builtin_type_unsigned_long, /* btUInt64 */
1338 };
1339
1340 TIR t[1];
1341 struct type *tp = 0;
1342 enum type_code type_code = TYPE_CODE_UNDEF;
1343
10373914
PS
1344 /* Handle undefined types, they have indexNil. */
1345 if (aux_index == indexNil)
1346 return builtin_type_int;
1347
a2f1e2e5
ILT
1348 /* Handle corrupt aux indices. */
1349 if (aux_index >= (debug_info->fdr + fd)->caux)
1350 {
1351 complain (&index_complaint, sym_name);
1352 return builtin_type_int;
1353 }
1354 ax += aux_index;
1355
1356 /* Use aux as a type information record, map its basic type. */
1357 ecoff_swap_tir_in (bigend, &ax->a_ti, t);
1358 if (t->bt >= (sizeof (map_bt) / sizeof (*map_bt)))
1359 {
1360 complain (&basic_type_complaint, t->bt, sym_name);
1361 return builtin_type_int;
1362 }
1363 if (map_bt[t->bt])
1364 {
1365 tp = *map_bt[t->bt];
1366 }
1367 else
1368 {
1369 tp = NULL;
1370 /* Cannot use builtin types -- build our own */
1371 switch (t->bt)
1372 {
1373 case btAdr:
1374 tp = lookup_pointer_type (builtin_type_void);
1375 break;
1376 case btStruct:
1377 type_code = TYPE_CODE_STRUCT;
1378 break;
1379 case btUnion:
1380 type_code = TYPE_CODE_UNION;
1381 break;
1382 case btEnum:
1383 type_code = TYPE_CODE_ENUM;
1384 break;
1385 case btRange:
1386 type_code = TYPE_CODE_RANGE;
1387 break;
1388 case btSet:
1389 type_code = TYPE_CODE_SET;
1390 break;
1391 case btTypedef:
1392 /* alpha cc uses this for typedefs. The true type will be
1393 obtained by crossreferencing below. */
1394 type_code = TYPE_CODE_ERROR;
1395 break;
1396 default:
1397 complain (&basic_type_complaint, t->bt, sym_name);
1398 return builtin_type_int;
1399 }
1400 }
1401
1402 /* Move on to next aux */
1403 ax++;
1404
1405 if (t->fBitfield)
1406 {
1407 /* Inhibit core dumps with some cfront generated objects that
1408 corrupt the TIR. */
1409 if (bs == (int *)NULL)
1410 {
1411 complain (&bad_fbitfield_complaint, sym_name);
1412 return builtin_type_int;
1413 }
1414 *bs = AUX_GET_WIDTH (bigend, ax);
1415 ax++;
1416 }
1417
1418 /* All these types really point to some (common) MIPS type
1419 definition, and only the type-qualifiers fully identify
1420 them. We'll make the same effort at sharing. */
1421 if (t->bt == btStruct ||
1422 t->bt == btUnion ||
1423 t->bt == btEnum ||
1424
1425 /* btSet (I think) implies that the name is a tag name, not a typedef
1426 name. This apparently is a MIPS extension for C sets. */
1427 t->bt == btSet)
1428 {
1429 char *name;
1430
1431 /* Try to cross reference this type, build new type on failure. */
1432 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1433 if (tp == (struct type *) NULL)
1434 tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
1435
a8c49897
PS
1436 /* DEC c89 produces cross references to qualified aggregate types,
1437 dereference them. */
1438 while (TYPE_CODE (tp) == TYPE_CODE_PTR
1439 || TYPE_CODE (tp) == TYPE_CODE_ARRAY)
1440 tp = tp->target_type;
1441
a2f1e2e5
ILT
1442 /* Make sure that TYPE_CODE(tp) has an expected type code.
1443 Any type may be returned from cross_ref if file indirect entries
1444 are corrupted. */
1445 if (TYPE_CODE (tp) != TYPE_CODE_STRUCT
1446 && TYPE_CODE (tp) != TYPE_CODE_UNION
1447 && TYPE_CODE (tp) != TYPE_CODE_ENUM)
1448 {
1449 complain (&unexpected_type_code_complaint, sym_name);
1450 }
1451 else
1452 {
1453
1454 /* Usually, TYPE_CODE(tp) is already type_code. The main
1455 exception is if we guessed wrong re struct/union/enum.
1456 But for struct vs. union a wrong guess is harmless, so
1457 don't complain(). */
1458 if ((TYPE_CODE (tp) == TYPE_CODE_ENUM
1459 && type_code != TYPE_CODE_ENUM)
1460 || (TYPE_CODE (tp) != TYPE_CODE_ENUM
1461 && type_code == TYPE_CODE_ENUM))
1462 {
1463 complain (&bad_tag_guess_complaint, sym_name);
1464 }
1465
1466 if (TYPE_CODE (tp) != type_code)
1467 {
1468 TYPE_CODE (tp) = type_code;
1469 }
1470
1471 /* Do not set the tag name if it is a compiler generated tag name
1472 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1473 if (name[0] == '.' || name[0] == '\0')
1474 TYPE_TAG_NAME (tp) = NULL;
1475 else if (TYPE_TAG_NAME (tp) == NULL
1476 || !STREQ (TYPE_TAG_NAME (tp), name))
1477 TYPE_TAG_NAME (tp) = obsavestring (name, strlen (name),
1478 &current_objfile->type_obstack);
1479 }
1480 }
1481
1482 /* All these types really point to some (common) MIPS type
1483 definition, and only the type-qualifiers fully identify
1484 them. We'll make the same effort at sharing.
1485 FIXME: btIndirect cannot happen here as it is handled by the
1486 switch t->bt above. And we are not doing any guessing on range types. */
1487 if (t->bt == btIndirect ||
1488 t->bt == btRange)
1489 {
1490 char *name;
1491
1492 /* Try to cross reference this type, build new type on failure. */
1493 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1494 if (tp == (struct type *) NULL)
1495 tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
1496
1497 /* Make sure that TYPE_CODE(tp) has an expected type code.
1498 Any type may be returned from cross_ref if file indirect entries
1499 are corrupted. */
1500 if (TYPE_CODE (tp) != TYPE_CODE_RANGE)
1501 {
1502 complain (&unexpected_type_code_complaint, sym_name);
1503 }
1504 else
1505 {
1506 /* Usually, TYPE_CODE(tp) is already type_code. The main
1507 exception is if we guessed wrong re struct/union/enum. */
1508 if (TYPE_CODE (tp) != type_code)
1509 {
1510 complain (&bad_tag_guess_complaint, sym_name);
1511 TYPE_CODE (tp) = type_code;
1512 }
1513 if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name))
1514 TYPE_NAME (tp) = obsavestring (name, strlen (name),
1515 &current_objfile->type_obstack);
1516 }
1517 }
1518 if (t->bt == btTypedef)
1519 {
1520 char *name;
1521
1522 /* Try to cross reference this type, it should succeed. */
1523 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1524 if (tp == (struct type *) NULL)
1525 {
1526 complain (&unable_to_cross_ref_complaint, sym_name);
1527 tp = builtin_type_int;
1528 }
1529 }
1530
1531 /* Deal with range types */
1532 if (t->bt == btRange)
1533 {
1534 TYPE_NFIELDS (tp) = 2;
1535 TYPE_FIELDS (tp) = ((struct field *)
1536 TYPE_ALLOC (tp, 2 * sizeof (struct field)));
1537 TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1538 &current_objfile->type_obstack);
1539 TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1540 ax++;
1541 TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1542 &current_objfile->type_obstack);
1543 TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1544 ax++;
1545 }
1546
1547 /* Parse all the type qualifiers now. If there are more
1548 than 6 the game will continue in the next aux */
1549
1550 while (1)
1551 {
1552#define PARSE_TQ(tq) \
1553 if (t->tq != tqNil) \
1554 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1555 else \
1556 break;
1557
1558 PARSE_TQ (tq0);
1559 PARSE_TQ (tq1);
1560 PARSE_TQ (tq2);
1561 PARSE_TQ (tq3);
1562 PARSE_TQ (tq4);
1563 PARSE_TQ (tq5);
1564#undef PARSE_TQ
1565
1566 /* mips cc 2.x and gcc never put out continued aux entries. */
1567 if (!t->continued)
1568 break;
1569
1570 ecoff_swap_tir_in (bigend, &ax->a_ti, t);
1571 ax++;
1572 }
1573
1574 /* Complain for illegal continuations due to corrupt aux entries. */
1575 if (t->continued)
1576 complain (&bad_continued_complaint, sym_name);
1577
1578 return tp;
1579}
1580
1581/* Make up a complex type from a basic one. Type is passed by
1582 reference in TPP and side-effected as necessary. The type
1583 qualifier TQ says how to handle the aux symbols at AX for
1584 the symbol SX we are currently analyzing. BIGEND says whether
1585 aux symbols are big-endian or little-endian.
1586 Returns the number of aux symbols we parsed. */
1587
1588static int
1589upgrade_type (fd, tpp, tq, ax, bigend, sym_name)
1590 int fd;
1591 struct type **tpp;
1592 int tq;
1593 union aux_ext *ax;
1594 int bigend;
1595 char *sym_name;
1596{
1597 int off;
1598 struct type *t;
1599
1600 /* Used in array processing */
1601 int rf, id;
1602 FDR *fh;
1603 struct type *range;
1604 struct type *indx;
1605 int lower, upper;
1606 RNDXR rndx;
1607
1608 switch (tq)
1609 {
1610 case tqPtr:
1611 t = lookup_pointer_type (*tpp);
1612 *tpp = t;
1613 return 0;
1614
1615 case tqProc:
1616 t = lookup_function_type (*tpp);
1617 *tpp = t;
1618 return 0;
1619
1620 case tqArray:
1621 off = 0;
1622
1623 /* Determine and record the domain type (type of index) */
1624 ecoff_swap_rndx_in (bigend, &ax->a_rndx, &rndx);
1625 id = rndx.index;
1626 rf = rndx.rfd;
1627 if (rf == 0xfff)
1628 {
1629 ax++;
1630 rf = AUX_GET_ISYM (bigend, ax);
1631 off++;
1632 }
1633 fh = get_rfd (fd, rf);
1634
1635 indx = parse_type (fd, debug_info->external_aux + fh->iauxBase,
1636 id, (int *) NULL, bigend, sym_name);
1637
1638 /* The bounds type should be an integer type, but might be anything
1639 else due to corrupt aux entries. */
1640 if (TYPE_CODE (indx) != TYPE_CODE_INT)
1641 {
1642 complain (&array_index_type_complaint, sym_name);
1643 indx = builtin_type_int;
1644 }
1645
1646 /* Get the bounds, and create the array type. */
1647 ax++;
1648 lower = AUX_GET_DNLOW (bigend, ax);
1649 ax++;
1650 upper = AUX_GET_DNHIGH (bigend, ax);
1651 ax++;
1652 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1653
1654 range = create_range_type ((struct type *) NULL, indx,
1655 lower, upper);
1656
1657 t = create_array_type ((struct type *) NULL, *tpp, range);
1658
1659 /* We used to fill in the supplied array element bitsize
1660 here if the TYPE_LENGTH of the target type was zero.
1661 This happens for a `pointer to an array of anonymous structs',
1662 but in this case the array element bitsize is also zero,
1663 so nothing is gained.
1664 And we used to check the TYPE_LENGTH of the target type against
1665 the supplied array element bitsize.
1666 gcc causes a mismatch for `pointer to array of object',
1667 since the sdb directives it uses do not have a way of
1668 specifying the bitsize, but it does no harm (the
1669 TYPE_LENGTH should be correct) and we should be able to
1670 ignore the erroneous bitsize from the auxiliary entry safely.
1671 dbx seems to ignore it too. */
1672
1673 *tpp = t;
1674 return 4 + off;
1675
1676 case tqVol:
1677 /* Volatile -- currently ignored */
1678 return 0;
1679
1680 case tqConst:
1681 /* Const -- currently ignored */
1682 return 0;
1683
1684 default:
1685 complain (&unknown_type_qual_complaint, tq);
1686 return 0;
1687 }
1688}
1689
1690
1691/* Parse a procedure descriptor record PR. Note that the procedure is
1692 parsed _after_ the local symbols, now we just insert the extra
1693 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1694 already been placed in the procedure's main block. Note also that
1695 images that have been partially stripped (ld -x) have been deprived
1696 of local symbols, and we have to cope with them here. FIRST_OFF is
1697 the offset of the first procedure for this FDR; we adjust the
1698 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1699 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1700 in question, or NULL to use top_stack->cur_block. */
1701
1702static void parse_procedure PARAMS ((PDR *, struct symtab *, unsigned long));
1703
1704static void
1705parse_procedure (pr, search_symtab, first_off)
1706 PDR *pr;
1707 struct symtab *search_symtab;
1708 unsigned long first_off;
1709{
1710 struct symbol *s, *i;
1711 struct block *b;
1712 struct mips_extra_func_info *e;
1713 char *sh_name;
1714
1715 /* Simple rule to find files linked "-x" */
1716 if (cur_fdr->rss == -1)
1717 {
1718 if (pr->isym == -1)
1719 {
1720 /* Static procedure at address pr->adr. Sigh. */
833e0d94 1721 /* FIXME-32x64. assuming pr->adr fits in long. */
a2f1e2e5
ILT
1722 complain (&pdr_static_symbol_complaint, (unsigned long) pr->adr);
1723 return;
1724 }
1725 else
1726 {
1727 /* external */
1728 EXTR she;
1729
1730 (*debug_swap->swap_ext_in) (cur_bfd,
1731 ((char *) debug_info->external_ext
1732 + (pr->isym
1733 * debug_swap->external_ext_size)),
1734 &she);
1735 sh_name = debug_info->ssext + she.asym.iss;
1736 }
1737 }
1738 else
1739 {
1740 /* Full symbols */
1741 SYMR sh;
1742
1743 (*debug_swap->swap_sym_in) (cur_bfd,
1744 ((char *) debug_info->external_sym
1745 + ((cur_fdr->isymBase + pr->isym)
1746 * debug_swap->external_sym_size)),
1747 &sh);
1748 sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
1749 }
1750
1751 if (search_symtab != NULL)
1752 {
1753#if 0
1754 /* This loses both in the case mentioned (want a static, find a global),
1755 but also if we are looking up a non-mangled name which happens to
1756 match the name of a mangled function. */
1757 /* We have to save the cur_fdr across the call to lookup_symbol.
1758 If the pdr is for a static function and if a global function with
1759 the same name exists, lookup_symbol will eventually read in the symtab
1760 for the global function and clobber cur_fdr. */
1761 FDR *save_cur_fdr = cur_fdr;
1762 s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1763 cur_fdr = save_cur_fdr;
1764#else
1765 s = mylookup_symbol
1766 (sh_name,
1767 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK),
1768 VAR_NAMESPACE,
1769 LOC_BLOCK);
1770#endif
1771 }
1772 else
1773 s = mylookup_symbol (sh_name, top_stack->cur_block,
1774 VAR_NAMESPACE, LOC_BLOCK);
1775
1776 if (s != 0)
1777 {
1778 b = SYMBOL_BLOCK_VALUE (s);
1779 }
1780 else
1781 {
1782 complain (&pdr_for_nonsymbol_complaint, sh_name);
1783#if 1
1784 return;
1785#else
1786/* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1787 s = new_symbol (sh_name);
1788 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1789 SYMBOL_CLASS (s) = LOC_BLOCK;
1790 /* Donno its type, hope int is ok */
1791 SYMBOL_TYPE (s) = lookup_function_type (builtin_type_int);
1792 add_symbol (s, top_stack->cur_block);
1793 /* Wont have symbols for this one */
1794 b = new_block (2);
1795 SYMBOL_BLOCK_VALUE (s) = b;
1796 BLOCK_FUNCTION (b) = s;
1797 BLOCK_START (b) = pr->adr;
1798 /* BOUND used to be the end of procedure's text, but the
1799 argument is no longer passed in. */
1800 BLOCK_END (b) = bound;
1801 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1802 add_block (b, top_stack->cur_st);
1803#endif
1804 }
1805
1806 i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1807
1808 if (i)
1809 {
1810 e = (struct mips_extra_func_info *) SYMBOL_VALUE (i);
1811 e->pdr = *pr;
1812 e->pdr.isym = (long) s;
1813 e->pdr.adr += cur_fdr->adr - first_off;
1814
1815 /* Correct incorrect setjmp procedure descriptor from the library
1816 to make backtrace through setjmp work. */
1817 if (e->pdr.pcreg == 0 && STREQ (sh_name, "setjmp"))
1818 {
1819 complain (&bad_setjmp_pdr_complaint, 0);
1820 e->pdr.pcreg = RA_REGNUM;
1821 e->pdr.regmask = 0x80000000;
1822 e->pdr.regoffset = -4;
1823 }
a2f1e2e5
ILT
1824 }
1825}
1826
1827/* Parse the external symbol ES. Just call parse_symbol() after
1828 making sure we know where the aux are for it. For procedures,
1829 parsing of the PDRs has already provided all the needed
1830 information, we only parse them if SKIP_PROCEDURES is false,
1831 and only if this causes no symbol duplication.
1832 BIGEND says whether aux entries are big-endian or little-endian.
1833
1834 This routine clobbers top_stack->cur_block and ->cur_st. */
1835
1836static void
1837parse_external (es, skip_procedures, bigend)
1838 EXTR *es;
1839 int skip_procedures;
1840 int bigend;
1841{
1842 union aux_ext *ax;
1843
1844 if (es->ifd != ifdNil)
1845 {
1846 cur_fd = es->ifd;
1847 cur_fdr = debug_info->fdr + cur_fd;
1848 ax = debug_info->external_aux + cur_fdr->iauxBase;
1849 }
1850 else
1851 {
1852 cur_fdr = debug_info->fdr;
1853 ax = 0;
1854 }
1855
1856 /* Reading .o files */
1857 if (es->asym.sc == scUndefined || es->asym.sc == scNil)
1858 {
1859 char *what;
1860 switch (es->asym.st)
1861 {
1862 case stNil:
1863 /* These are generated for static symbols in .o files,
1864 ignore them. */
1865 return;
1866 case stStaticProc:
1867 case stProc:
1868 what = "procedure";
1869 n_undef_procs++;
1870 break;
1871 case stGlobal:
1872 what = "variable";
1873 n_undef_vars++;
1874 break;
1875 case stLabel:
1876 what = "label";
1877 n_undef_labels++;
1878 break;
1879 default:
1880 what = "symbol";
1881 break;
1882 }
1883 n_undef_symbols++;
1884 /* FIXME: Turn this into a complaint? */
1885 if (info_verbose)
1886 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1887 what, debug_info->ssext + es->asym.iss,
1888 fdr_name (cur_fdr));
1889 return;
1890 }
1891
1892 switch (es->asym.st)
1893 {
1894 case stProc:
1895 /* If we have full symbols we do not need more */
1896 if (skip_procedures)
1897 return;
1898 if (mylookup_symbol (debug_info->ssext + es->asym.iss,
1899 top_stack->cur_block,
1900 VAR_NAMESPACE, LOC_BLOCK))
1901 break;
1902 /* fall through */
1903 case stGlobal:
1904 case stLabel:
1905 /* Note that the case of a symbol with indexNil must be handled
1906 anyways by parse_symbol(). */
1907 parse_symbol (&es->asym, ax, (char *) NULL, bigend);
1908 break;
1909 default:
1910 break;
1911 }
1912}
1913
1914/* Parse the line number info for file descriptor FH into
1915 GDB's linetable LT. MIPS' encoding requires a little bit
1916 of magic to get things out. Note also that MIPS' line
1917 numbers can go back and forth, apparently we can live
1918 with that and do not need to reorder our linetables */
1919
1920static void
1921parse_lines (fh, pr, lt, maxlines)
1922 FDR *fh;
1923 PDR *pr;
1924 struct linetable *lt;
1925 int maxlines;
1926{
1927 unsigned char *base;
1928 int j, k;
1929 int delta, count, lineno = 0;
1930 unsigned long first_off = pr->adr;
1931
1932 if (fh->cbLine == 0)
1933 return;
1934
1935 base = debug_info->line + fh->cbLineOffset;
1936
1937 /* Scan by procedure descriptors */
1938 k = 0;
1939 for (j = 0; j < fh->cpd; j++, pr++)
1940 {
1941 long l;
1942 unsigned long adr;
1943 unsigned char *halt;
1944
1945 /* No code for this one */
1946 if (pr->iline == ilineNil ||
1947 pr->lnLow == -1 || pr->lnHigh == -1)
1948 continue;
1949
1950 /* Determine start and end address of compressed line bytes for
1951 this procedure. */
1952 base = debug_info->line + fh->cbLineOffset;
1953 if (j != (fh->cpd - 1))
1954 halt = base + pr[1].cbLineOffset;
1955 else
1956 halt = base + fh->cbLine;
1957 base += pr->cbLineOffset;
1958
1959 adr = fh->adr + pr->adr - first_off;
1960 l = adr >> 2; /* in words */
1961 for (lineno = pr->lnLow; base < halt; )
1962 {
1963 count = *base & 0x0f;
1964 delta = *base++ >> 4;
1965 if (delta >= 8)
1966 delta -= 16;
1967 if (delta == -8)
1968 {
1969 delta = (base[0] << 8) | base[1];
1970 if (delta >= 0x8000)
1971 delta -= 0x10000;
1972 base += 2;
1973 }
1974 lineno += delta; /* first delta is 0 */
1975
1976 /* Complain if the line table overflows. Could happen
1977 with corrupt binaries. */
1978 if (lt->nitems >= maxlines)
1979 {
1980 complain (&bad_linetable_guess_complaint, fdr_name (fh));
1981 break;
1982 }
1983 k = add_line (lt, lineno, l, k);
1984 l += count + 1;
1985 }
1986 }
1987}
1988\f
1989/* Master parsing procedure for first-pass reading of file symbols
1990 into a partial_symtab. */
1991
1992static void
1993parse_partial_symbols (objfile, section_offsets)
1994 struct objfile *objfile;
1995 struct section_offsets *section_offsets;
1996{
1997 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
1998 const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
1999 const bfd_size_type external_ext_size = debug_swap->external_ext_size;
2000 void (* const swap_ext_in) PARAMS ((bfd *, PTR, EXTR *))
2001 = debug_swap->swap_ext_in;
2002 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
2003 = debug_swap->swap_sym_in;
2004 void (* const swap_rfd_in) PARAMS ((bfd *, PTR, RFDT *))
2005 = debug_swap->swap_rfd_in;
2006 int f_idx, s_idx;
2007 HDRR *hdr = &debug_info->symbolic_header;
2008 /* Running pointers */
2009 FDR *fh;
2010 char *ext_out;
2011 char *ext_out_end;
2012 EXTR *ext_block;
2013 register EXTR *ext_in;
2014 EXTR *ext_in_end;
2015 SYMR sh;
2016 struct partial_symtab *pst;
2017
2018 int past_first_source_file = 0;
2019
2020 /* List of current psymtab's include files */
2021 char **psymtab_include_list;
2022 int includes_allocated;
2023 int includes_used;
2024 EXTR *extern_tab;
2025 struct pst_map *fdr_to_pst;
2026 /* Index within current psymtab dependency list */
2027 struct partial_symtab **dependency_list;
2028 int dependencies_used, dependencies_allocated;
2029 struct cleanup *old_chain;
2030 char *name;
2031 enum language prev_language;
2032
2033 extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack,
2034 sizeof (EXTR) * hdr->iextMax);
2035
2036 includes_allocated = 30;
2037 includes_used = 0;
2038 psymtab_include_list = (char **) alloca (includes_allocated *
2039 sizeof (char *));
2040 next_symbol_text_func = mdebug_next_symbol_text;
2041
2042 dependencies_allocated = 30;
2043 dependencies_used = 0;
2044 dependency_list =
2045 (struct partial_symtab **) alloca (dependencies_allocated *
2046 sizeof (struct partial_symtab *));
2047
2048 last_source_file = NULL;
2049
2050 /*
2051 * Big plan:
2052 *
2053 * Only parse the Local and External symbols, and the Relative FDR.
2054 * Fixup enough of the loader symtab to be able to use it.
2055 * Allocate space only for the file's portions we need to
2056 * look at. (XXX)
2057 */
2058
2059 max_gdbinfo = 0;
2060 max_glevel = MIN_GLEVEL;
2061
2062 /* Allocate the map FDR -> PST.
2063 Minor hack: -O3 images might claim some global data belongs
2064 to FDR -1. We`ll go along with that */
2065 fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
2066 old_chain = make_cleanup (free, fdr_to_pst);
2067 fdr_to_pst++;
2068 {
847d9775 2069 struct partial_symtab *pst = new_psymtab ("", objfile, section_offsets);
a2f1e2e5
ILT
2070 fdr_to_pst[-1].pst = pst;
2071 FDR_IDX (pst) = -1;
2072 }
2073
2074 /* Allocate the global pending list. */
2075 pending_list =
2076 ((struct mdebug_pending **)
2077 obstack_alloc (&objfile->psymbol_obstack,
2078 hdr->ifdMax * sizeof (struct mdebug_pending *)));
2079 memset ((PTR) pending_list, 0,
2080 hdr->ifdMax * sizeof (struct mdebug_pending *));
2081
2082 /* Pass 0 over external syms: swap them in. */
2083 ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
2084 make_cleanup (free, ext_block);
2085
2086 ext_out = (char *) debug_info->external_ext;
2087 ext_out_end = ext_out + hdr->iextMax * external_ext_size;
2088 ext_in = ext_block;
2089 for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
2090 (*swap_ext_in) (cur_bfd, ext_out, ext_in);
2091
2092 /* Pass 1 over external syms: Presize and partition the list */
2093 ext_in = ext_block;
2094 ext_in_end = ext_in + hdr->iextMax;
2095 for (; ext_in < ext_in_end; ext_in++)
2096 {
2097 /* See calls to complain below. */
2098 if (ext_in->ifd >= -1
2099 && ext_in->ifd < hdr->ifdMax
2100 && ext_in->asym.iss >= 0
2101 && ext_in->asym.iss < hdr->issExtMax)
2102 fdr_to_pst[ext_in->ifd].n_globals++;
2103 }
2104
2105 /* Pass 1.5 over files: partition out global symbol space */
2106 s_idx = 0;
2107 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
2108 {
2109 fdr_to_pst[f_idx].globals_offset = s_idx;
2110 s_idx += fdr_to_pst[f_idx].n_globals;
2111 fdr_to_pst[f_idx].n_globals = 0;
2112 }
2113
2114 /* Pass 2 over external syms: fill in external symbols */
2115 ext_in = ext_block;
2116 ext_in_end = ext_in + hdr->iextMax;
2117 for (; ext_in < ext_in_end; ext_in++)
2118 {
2119 enum minimal_symbol_type ms_type = mst_text;
2120
2121 /* The Irix 5 native tools seem to sometimes generate bogus
2122 external symbols. */
2123 if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
2124 {
2125 complain (&bad_ext_ifd_complaint, ext_in->ifd, hdr->ifdMax);
2126 continue;
2127 }
2128 if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
2129 {
2130 complain (&bad_ext_iss_complaint, ext_in->asym.iss,
2131 hdr->issExtMax);
2132 continue;
2133 }
2134
2135 extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
2136 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
2137
2138 if (ext_in->asym.sc == scUndefined || ext_in->asym.sc == scNil)
2139 continue;
2140
2141 name = debug_info->ssext + ext_in->asym.iss;
2142 switch (ext_in->asym.st)
2143 {
2144 case stProc:
2145 break;
2146 case stStaticProc:
2147 ms_type = mst_file_text;
2148 break;
2149 case stGlobal:
10373914
PS
2150 if (ext_in->asym.sc == scCommon)
2151 {
2152 /* The value of a common symbol is its size, not its address.
2153 Ignore it. */
2154 continue;
2155 }
2156 else if (ext_in->asym.sc == scData
a2f1e2e5 2157 || ext_in->asym.sc == scSData
10373914
PS
2158 || ext_in->asym.sc == scRData
2159 || ext_in->asym.sc == scPData
2160 || ext_in->asym.sc == scXData)
a2f1e2e5
ILT
2161 ms_type = mst_data;
2162 else
2163 ms_type = mst_bss;
2164 break;
2165 case stLabel:
2166 if (ext_in->asym.sc == scAbs)
2167 ms_type = mst_abs;
10373914
PS
2168 else if (ext_in->asym.sc == scText
2169 || ext_in->asym.sc == scInit
2170 || ext_in->asym.sc == scFini)
2171 ms_type = mst_file_text;
a2f1e2e5
ILT
2172 else if (ext_in->asym.sc == scData
2173 || ext_in->asym.sc == scSData
10373914
PS
2174 || ext_in->asym.sc == scRData
2175 || ext_in->asym.sc == scPData
2176 || ext_in->asym.sc == scXData)
2177 ms_type = mst_file_data;
a2f1e2e5 2178 else
10373914 2179 ms_type = mst_file_bss;
a2f1e2e5
ILT
2180 break;
2181 case stLocal:
2182 /* The alpha has the section start addresses in stLocal symbols
2183 whose name starts with a `.'. Skip those but complain for all
2184 other stLocal symbols. */
2185 if (name[0] == '.')
2186 continue;
2187 /* Fall through. */
2188 default:
2189 ms_type = mst_unknown;
2190 complain (&unknown_ext_complaint, name);
2191 }
8d60affd 2192 prim_record_minimal_symbol (name, ext_in->asym.value, ms_type, objfile);
a2f1e2e5
ILT
2193 }
2194
2195 /* Pass 3 over files, over local syms: fill in static symbols */
2196 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2197 {
2198 struct partial_symtab *save_pst;
2199 EXTR *ext_ptr;
2200
2201 cur_fdr = fh = debug_info->fdr + f_idx;
2202
2203 if (fh->csym == 0)
2204 {
2205 fdr_to_pst[f_idx].pst = NULL;
2206 continue;
2207 }
2208 pst = start_psymtab_common (objfile, section_offsets,
2209 fdr_name (fh),
2210 fh->cpd ? fh->adr : 0,
2211 objfile->global_psymbols.next,
2212 objfile->static_psymbols.next);
2213 pst->read_symtab_private = ((char *)
2214 obstack_alloc (&objfile->psymbol_obstack,
2215 sizeof (struct symloc)));
2216 memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc));
2217
2218 save_pst = pst;
2219 FDR_IDX (pst) = f_idx;
2220 CUR_BFD (pst) = cur_bfd;
2221 DEBUG_SWAP (pst) = debug_swap;
2222 DEBUG_INFO (pst) = debug_info;
2223 PENDING_LIST (pst) = pending_list;
2224
2225 /* The way to turn this into a symtab is to call... */
2226 pst->read_symtab = mdebug_psymtab_to_symtab;
2227
2228 /* Set up language for the pst.
2229 The language from the FDR is used if it is unambigious (e.g. cfront
2230 with native cc and g++ will set the language to C).
2231 Otherwise we have to deduce the language from the filename.
2232 Native ecoff has every header file in a separate FDR, so
2233 deduce_language_from_filename will return language_unknown for
2234 a header file, which is not what we want.
2235 But the FDRs for the header files are after the FDR for the source
2236 file, so we can assign the language of the source file to the
2237 following header files. Then we save the language in the private
2238 pst data so that we can reuse it when building symtabs. */
2239 prev_language = psymtab_language;
2240
2241 switch (fh->lang)
2242 {
2243 case langCplusplusV2:
2244 psymtab_language = language_cplus;
2245 break;
2246 default:
2247 psymtab_language = deduce_language_from_filename (fdr_name (fh));
2248 break;
2249 }
2250 if (psymtab_language == language_unknown)
2251 psymtab_language = prev_language;
2252 PST_PRIVATE (pst)->pst_language = psymtab_language;
2253
2254 pst->texthigh = pst->textlow;
2255
2256 /* For stabs-in-ecoff files, the second symbol must be @stab.
2257 This symbol is emitted by mips-tfile to signal that the
2258 current object file uses encapsulated stabs instead of mips
2259 ecoff for local symbols. (It is the second symbol because
2260 the first symbol is the stFile used to signal the start of a
2261 file). */
2262 processing_gcc_compilation = 0;
2263 if (fh->csym >= 2)
2264 {
2265 (*swap_sym_in) (cur_bfd,
2266 ((char *) debug_info->external_sym
2267 + (fh->isymBase + 1) * external_sym_size),
2268 &sh);
2269 if (STREQ (debug_info->ss + fh->issBase + sh.iss, stabs_symbol))
2270 processing_gcc_compilation = 2;
2271 }
2272
2273 if (processing_gcc_compilation != 0)
2274 {
2275 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2276 {
2277 int type_code;
2278 char *namestring;
2279
2280 (*swap_sym_in) (cur_bfd,
2281 (((char *) debug_info->external_sym)
2282 + (fh->isymBase + cur_sdx) * external_sym_size),
2283 &sh);
2284 type_code = ECOFF_UNMARK_STAB (sh.index);
2285 if (!ECOFF_IS_STAB (&sh))
2286 {
2287 if (sh.st == stProc || sh.st == stStaticProc)
2288 {
2289 long procaddr = sh.value;
2290 long isym;
2291
2292
2293 isym = AUX_GET_ISYM (fh->fBigendian,
2294 (debug_info->external_aux
2295 + fh->iauxBase
2296 + sh.index));
2297 (*swap_sym_in) (cur_bfd,
2298 ((char *) debug_info->external_sym
2299 + ((fh->isymBase + isym - 1)
2300 * external_sym_size)),
2301 &sh);
2302 if (sh.st == stEnd)
2303 {
2304 long high = procaddr + sh.value;
2305 if (high > pst->texthigh)
2306 pst->texthigh = high;
2307 }
2308 }
2309 continue;
2310 }
2311#define SET_NAMESTRING() \
2312 namestring = debug_info->ss + fh->issBase + sh.iss
2313#define CUR_SYMBOL_TYPE type_code
2314#define CUR_SYMBOL_VALUE sh.value
2315#define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2316 pst = save_pst
2317#define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2318#define HANDLE_RBRAC(val) \
2319 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2320#include "partial-stab.h"
2321 }
2322 }
2323 else
2324 {
2325 for (cur_sdx = 0; cur_sdx < fh->csym;)
2326 {
2327 char *name;
2328 enum address_class class;
2329
2330 (*swap_sym_in) (cur_bfd,
2331 ((char *) debug_info->external_sym
2332 + ((fh->isymBase + cur_sdx)
2333 * external_sym_size)),
2334 &sh);
2335
2336 if (ECOFF_IS_STAB (&sh))
2337 {
2338 cur_sdx++;
2339 continue;
2340 }
2341
2342 /* Non absolute static symbols go into the minimal table. */
2343 if (sh.sc == scUndefined || sh.sc == scNil
2344 || (sh.index == indexNil
2345 && (sh.st != stStatic || sh.sc == scAbs)))
2346 {
2347 /* FIXME, premature? */
2348 cur_sdx++;
2349 continue;
2350 }
2351
2352 name = debug_info->ss + fh->issBase + sh.iss;
2353
2354 switch (sh.st)
2355 {
2356 long high;
2357 long procaddr;
2358 int new_sdx;
2359
10373914 2360 case stStaticProc:
8d60affd
JK
2361 prim_record_minimal_symbol (name, sh.value, mst_file_text,
2362 objfile);
10373914 2363
a2f1e2e5
ILT
2364 /* FALLTHROUGH */
2365
10373914
PS
2366 case stProc:
2367 /* Usually there is a local and a global stProc symbol
2368 for a function. This means that the function name
2369 has already been entered into the mimimal symbol table
2370 while processing the global symbols in pass 2 above.
2371 One notable exception is the PROGRAM name from
2372 f77 compiled executables, it is only put out as
2373 local stProc symbol, and a global MAIN__ stProc symbol
2374 points to it. It doesn't matter though, as gdb is
2375 still able to find the PROGRAM name via the partial
2376 symbol table, and the MAIN__ symbol via the minimal
2377 symbol table. */
a2f1e2e5
ILT
2378 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2379 VAR_NAMESPACE, LOC_BLOCK,
10373914
PS
2380 (sh.st == stProc)
2381 ? objfile->global_psymbols
2382 : objfile->static_psymbols,
2383 sh.value, psymtab_language, objfile);
a2f1e2e5
ILT
2384 /* Skip over procedure to next one. */
2385 if (sh.index >= hdr->iauxMax)
2386 {
2387 /* Should not happen, but does when cross-compiling
2388 with the MIPS compiler. FIXME -- pull later. */
2389 complain (&index_complaint, name);
2390 new_sdx = cur_sdx + 1; /* Don't skip at all */
2391 }
2392 else
2393 new_sdx = AUX_GET_ISYM (fh->fBigendian,
2394 (debug_info->external_aux
2395 + fh->iauxBase
2396 + sh.index));
2397 procaddr = sh.value;
2398
2399 if (new_sdx <= cur_sdx)
2400 {
2401 /* This should not happen either... FIXME. */
2402 complain (&aux_index_complaint, name);
2403 new_sdx = cur_sdx + 1; /* Don't skip backward */
2404 }
2405
2406 cur_sdx = new_sdx;
2407 (*swap_sym_in) (cur_bfd,
2408 ((char *) debug_info->external_sym
2409 + ((fh->isymBase + cur_sdx - 1)
2410 * external_sym_size)),
2411 &sh);
2412 if (sh.st != stEnd)
2413 continue;
2414 high = procaddr + sh.value;
2415 if (high > pst->texthigh)
2416 pst->texthigh = high;
2417 continue;
2418
2419 case stStatic: /* Variable */
10373914
PS
2420 if (sh.sc == scData
2421 || sh.sc == scSData
2422 || sh.sc == scRData
2423 || sh.sc == scPData
2424 || sh.sc == scXData)
8d60affd
JK
2425 prim_record_minimal_symbol (name, sh.value, mst_file_data,
2426 objfile);
a2f1e2e5 2427 else
8d60affd
JK
2428 prim_record_minimal_symbol (name, sh.value, mst_file_bss,
2429 objfile);
a2f1e2e5
ILT
2430 class = LOC_STATIC;
2431 break;
2432
2433 case stTypedef:/* Typedef */
2434 /* Skip typedefs for forward declarations and opaque
2435 structs from alpha cc. */
2436 if (sh.iss == 0)
2437 goto skip;
2438 class = LOC_TYPEDEF;
2439 break;
2440
2441 case stConstant: /* Constant decl */
2442 class = LOC_CONST;
2443 break;
2444
2445 case stUnion:
2446 case stStruct:
2447 case stEnum:
2448 case stBlock: /* { }, str, un, enum*/
2449 /* Do not create a partial symbol for cc unnamed aggregates
2450 and gcc empty aggregates. */
2451 if ((sh.sc == scInfo || sh.sc == scCommon)
2452 && sh.iss != 0
2453 && sh.index != cur_sdx + 2)
2454 {
2455 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2456 STRUCT_NAMESPACE, LOC_TYPEDEF,
2457 objfile->static_psymbols,
2458 sh.value,
2459 psymtab_language, objfile);
2460 }
847d9775
PS
2461 handle_psymbol_enumerators (objfile, fh, sh.st);
2462
a2f1e2e5
ILT
2463 /* Skip over the block */
2464 new_sdx = sh.index;
2465 if (new_sdx <= cur_sdx)
2466 {
2467 /* This happens with the Ultrix kernel. */
2468 complain (&block_index_complaint, name);
2469 new_sdx = cur_sdx + 1; /* Don't skip backward */
2470 }
2471 cur_sdx = new_sdx;
2472 continue;
2473
2474 case stFile: /* File headers */
2475 case stLabel: /* Labels */
2476 case stEnd: /* Ends of files */
2477 goto skip;
2478
2479 case stLocal: /* Local variables */
2480 /* Normally these are skipped because we skip over
2481 all blocks we see. However, these can occur
2482 as visible symbols in a .h file that contains code. */
2483 goto skip;
2484
2485 default:
2486 /* Both complaints are valid: one gives symbol name,
2487 the other the offending symbol type. */
2488 complain (&unknown_sym_complaint, name);
2489 complain (&unknown_st_complaint, sh.st);
2490 cur_sdx++;
2491 continue;
2492 }
2493 /* Use this gdb symbol */
2494 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2495 VAR_NAMESPACE, class,
2496 objfile->static_psymbols, sh.value,
2497 psymtab_language, objfile);
2498 skip:
2499 cur_sdx++; /* Go to next file symbol */
2500 }
2501
2502 /* Now do enter the external symbols. */
2503 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
2504 cur_sdx = fdr_to_pst[f_idx].n_globals;
2505 PST_PRIVATE (save_pst)->extern_count = cur_sdx;
2506 PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
2507 for (; --cur_sdx >= 0; ext_ptr++)
2508 {
2509 enum address_class class;
2510 SYMR *psh;
2511 char *name;
2512
2513 if (ext_ptr->ifd != f_idx)
2514 abort ();
2515 psh = &ext_ptr->asym;
2516
2517 /* Do not add undefined symbols to the partial symbol table. */
2518 if (psh->sc == scUndefined || psh->sc == scNil)
2519 continue;
2520
2521 switch (psh->st)
2522 {
2523 case stNil:
2524 /* These are generated for static symbols in .o files,
2525 ignore them. */
2526 continue;
2527 case stProc:
2528 case stStaticProc:
10373914
PS
2529 /* If the index of the global symbol is not indexNil,
2530 it points to the local stProc symbol with the same
2531 name, which has already been entered into the
2532 partial symbol table above. */
2533 if (psh->index != indexNil)
2534 continue;
a2f1e2e5
ILT
2535 class = LOC_BLOCK;
2536 break;
2537 case stLabel:
2538 class = LOC_LABEL;
2539 break;
2540 default:
2541 complain (&unknown_ext_complaint,
2542 debug_info->ssext + psh->iss);
2543 /* Fall through, pretend it's global. */
2544 case stGlobal:
2545 class = LOC_STATIC;
2546 break;
2547 }
2548 name = debug_info->ssext + psh->iss;
2549 ADD_PSYMBOL_ADDR_TO_LIST (name, strlen (name),
2550 VAR_NAMESPACE, class,
2551 objfile->global_psymbols,
2552 (CORE_ADDR) psh->value,
2553 psymtab_language, objfile);
2554 }
2555 }
2556
2557 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
2558 empty and put on the free list. */
2559 fdr_to_pst[f_idx].pst = end_psymtab (save_pst,
2560 psymtab_include_list, includes_used,
2561 -1, save_pst->texthigh,
2562 dependency_list, dependencies_used);
2563 if (objfile->ei.entry_point >= save_pst->textlow &&
2564 objfile->ei.entry_point < save_pst->texthigh)
2565 {
2566 objfile->ei.entry_file_lowpc = save_pst->textlow;
2567 objfile->ei.entry_file_highpc = save_pst->texthigh;
2568 }
2569 }
2570
2571 /* Now scan the FDRs for dependencies */
2572 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2573 {
2574 fh = f_idx + debug_info->fdr;
2575 pst = fdr_to_pst[f_idx].pst;
2576
2577 if (pst == (struct partial_symtab *)NULL)
2578 continue;
2579
2580 /* This should catch stabs-in-ecoff. */
2581 if (fh->crfd <= 1)
2582 continue;
2583
2584 /* Skip the first file indirect entry as it is a self dependency
2585 for source files or a reverse .h -> .c dependency for header files. */
2586 pst->number_of_dependencies = 0;
2587 pst->dependencies =
2588 ((struct partial_symtab **)
2589 obstack_alloc (&objfile->psymbol_obstack,
2590 ((fh->crfd - 1)
2591 * sizeof (struct partial_symtab *))));
2592 for (s_idx = 1; s_idx < fh->crfd; s_idx++)
2593 {
2594 RFDT rh;
2595
2596 (*swap_rfd_in) (cur_bfd,
2597 ((char *) debug_info->external_rfd
2598 + (fh->rfdBase + s_idx) * external_rfd_size),
2599 &rh);
2600 if (rh < 0 || rh >= hdr->ifdMax)
2601 {
2602 complain (&bad_file_number_complaint, rh);
2603 continue;
2604 }
2605
2606 /* Skip self dependencies of header files. */
2607 if (rh == f_idx)
2608 continue;
2609
2610 /* Do not add to dependeny list if psymtab was empty. */
2611 if (fdr_to_pst[rh].pst == (struct partial_symtab *)NULL)
2612 continue;
2613 pst->dependencies[pst->number_of_dependencies++] = fdr_to_pst[rh].pst;
2614 }
2615 }
10373914
PS
2616
2617 /* Remove the dummy psymtab created for -O3 images above, if it is
2618 still empty, to enable the detection of stripped executables. */
2619 if (objfile->psymtabs->next == NULL
2620 && objfile->psymtabs->number_of_dependencies == 0
2621 && objfile->psymtabs->n_global_syms == 0
2622 && objfile->psymtabs->n_static_syms == 0)
2623 objfile->psymtabs = NULL;
a2f1e2e5
ILT
2624 do_cleanups (old_chain);
2625}
2626
847d9775
PS
2627/* If the current psymbol has an enumerated type, we need to add
2628 all the the enum constants to the partial symbol table. */
2629
2630static void
2631handle_psymbol_enumerators (objfile, fh, stype)
2632 struct objfile *objfile;
2633 FDR *fh;
2634 int stype;
2635{
2636 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
2637 void (* const swap_sym_in) PARAMS ((bfd *, PTR, SYMR *))
2638 = debug_swap->swap_sym_in;
2639 char *ext_sym = ((char *) debug_info->external_sym
2640 + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
2641 SYMR sh;
2642 TIR tir;
2643
2644 switch (stype)
2645 {
2646 case stEnum:
2647 break;
2648
2649 case stBlock:
2650 /* It is an enumerated type if the next symbol entry is a stMember
2651 and its auxiliary index is indexNil or its auxiliary entry
2652 is a plain btNil or btVoid. */
2653 (*swap_sym_in) (cur_bfd, ext_sym, &sh);
2654 if (sh.st != stMember)
2655 return;
2656
2657 if (sh.index == indexNil)
2658 break;
2659 ecoff_swap_tir_in (fh->fBigendian,
2660 &(debug_info->external_aux
2661 + fh->iauxBase + sh.index)->a_ti,
2662 &tir);
2663 if ((tir.bt != btNil && tir.bt != btVoid) || tir.tq0 != tqNil)
2664 return;
2665 break;
2666
2667 default:
2668 return;
2669 }
2670
2671 for (;;)
2672 {
2673 char *name;
2674
2675 (*swap_sym_in) (cur_bfd, ext_sym, &sh);
2676 if (sh.st != stMember)
2677 break;
2678 name = debug_info->ss + cur_fdr->issBase + sh.iss;
2679
2680 /* Note that the value doesn't matter for enum constants
2681 in psymtabs, just in symtabs. */
2682 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2683 VAR_NAMESPACE, LOC_CONST,
2684 objfile->static_psymbols, 0,
2685 psymtab_language, objfile);
2686 ext_sym += external_sym_size;
2687 }
2688}
a2f1e2e5
ILT
2689
2690static char *
2691mdebug_next_symbol_text ()
2692{
2693 SYMR sh;
2694
2695 cur_sdx++;
2696 (*debug_swap->swap_sym_in) (cur_bfd,
2697 ((char *) debug_info->external_sym
2698 + ((cur_fdr->isymBase + cur_sdx)
2699 * debug_swap->external_sym_size)),
2700 &sh);
2701 return debug_info->ss + cur_fdr->issBase + sh.iss;
2702}
2703
2704/* Ancillary function to psymtab_to_symtab(). Does all the work
2705 for turning the partial symtab PST into a symtab, recurring
2706 first on all dependent psymtabs. The argument FILENAME is
2707 only passed so we can see in debug stack traces what file
2708 is being read.
2709
2710 This function has a split personality, based on whether the
2711 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2712 The flow of control and even the memory allocation differs. FIXME. */
2713
2714static void
2715psymtab_to_symtab_1 (pst, filename)
2716 struct partial_symtab *pst;
2717 char *filename;
2718{
2719 bfd_size_type external_sym_size;
2720 bfd_size_type external_pdr_size;
2721 void (*swap_sym_in) PARAMS ((bfd *, PTR, SYMR *));
2722 void (*swap_pdr_in) PARAMS ((bfd *, PTR, PDR *));
2723 int i;
2724 struct symtab *st;
2725 FDR *fh;
2726 struct linetable *lines;
2727
2728 if (pst->readin)
2729 return;
2730 pst->readin = 1;
2731
2732 /* Read in all partial symbtabs on which this one is dependent.
2733 NOTE that we do have circular dependencies, sigh. We solved
2734 that by setting pst->readin before this point. */
2735
2736 for (i = 0; i < pst->number_of_dependencies; i++)
2737 if (!pst->dependencies[i]->readin)
2738 {
2739 /* Inform about additional files to be read in. */
2740 if (info_verbose)
2741 {
2742 fputs_filtered (" ", gdb_stdout);
2743 wrap_here ("");
2744 fputs_filtered ("and ", gdb_stdout);
2745 wrap_here ("");
2746 printf_filtered ("%s...",
2747 pst->dependencies[i]->filename);
2748 wrap_here (""); /* Flush output */
2749 gdb_flush (gdb_stdout);
2750 }
2751 /* We only pass the filename for debug purposes */
2752 psymtab_to_symtab_1 (pst->dependencies[i],
2753 pst->dependencies[i]->filename);
2754 }
2755
2756 /* Do nothing if this is a dummy psymtab. */
2757
2758 if (pst->n_global_syms == 0 && pst->n_static_syms == 0
2759 && pst->textlow == 0 && pst->texthigh == 0)
2760 return;
2761
2762 /* Now read the symbols for this symtab */
2763
2764 cur_bfd = CUR_BFD (pst);
2765 debug_swap = DEBUG_SWAP (pst);
2766 debug_info = DEBUG_INFO (pst);
2767 pending_list = PENDING_LIST (pst);
2768 external_sym_size = debug_swap->external_sym_size;
2769 external_pdr_size = debug_swap->external_pdr_size;
2770 swap_sym_in = debug_swap->swap_sym_in;
2771 swap_pdr_in = debug_swap->swap_pdr_in;
2772 current_objfile = pst->objfile;
2773 cur_fd = FDR_IDX (pst);
2774 fh = ((cur_fd == -1)
2775 ? (FDR *) NULL
2776 : debug_info->fdr + cur_fd);
2777 cur_fdr = fh;
2778
2779 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2780 processing_gcc_compilation = 0;
2781 if (fh != (FDR *) NULL && fh->csym >= 2)
2782 {
2783 SYMR sh;
2784
2785 (*swap_sym_in) (cur_bfd,
2786 ((char *) debug_info->external_sym
2787 + (fh->isymBase + 1) * external_sym_size),
2788 &sh);
2789 if (STREQ (debug_info->ss + fh->issBase + sh.iss,
2790 stabs_symbol))
2791 {
2792 /* We indicate that this is a GCC compilation so that certain
2793 features will be enabled in stabsread/dbxread. */
2794 processing_gcc_compilation = 2;
2795 }
2796 }
2797
2798 if (processing_gcc_compilation != 0)
2799 {
2800 char *pdr_ptr;
2801 char *pdr_end;
2802 int first_pdr;
2803 unsigned long first_off = 0;
2804
2805 /* This symbol table contains stabs-in-ecoff entries. */
2806
2807 /* Parse local symbols first */
2808
2809 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */
2810 {
2811 current_objfile = NULL;
2812 return;
2813 }
2814 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2815 {
2816 SYMR sh;
2817 char *name;
2818 CORE_ADDR valu;
2819
2820 (*swap_sym_in) (cur_bfd,
2821 (((char *) debug_info->external_sym)
2822 + (fh->isymBase + cur_sdx) * external_sym_size),
2823 &sh);
2824 name = debug_info->ss + fh->issBase + sh.iss;
2825 valu = sh.value;
2826 if (ECOFF_IS_STAB (&sh))
2827 {
2828 int type_code = ECOFF_UNMARK_STAB (sh.index);
ae5c71d6
PS
2829
2830 /* We should never get non N_STAB symbols here, but they
2831 should be harmless, so keep process_one_symbol from
2832 complaining about them. */
2833 if (type_code & N_STAB)
2834 {
2835 process_one_symbol (type_code, 0, valu, name,
2836 pst->section_offsets, pst->objfile);
2837 }
a2f1e2e5
ILT
2838 if (type_code == N_FUN)
2839 {
2840 /* Make up special symbol to contain
2841 procedure specific info */
2842 struct mips_extra_func_info *e =
2843 ((struct mips_extra_func_info *)
2844 obstack_alloc (&current_objfile->symbol_obstack,
2845 sizeof (struct mips_extra_func_info)));
2846 struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
2847 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
2848 SYMBOL_CLASS (s) = LOC_CONST;
2849 SYMBOL_TYPE (s) = builtin_type_void;
2850 SYMBOL_VALUE (s) = (long) e;
2851 add_symbol_to_list (s, &local_symbols);
2852 }
2853 }
bb7cb982 2854 else if (sh.st == stLabel)
a2f1e2e5 2855 {
bb7cb982
JK
2856 if (sh.index == indexNil)
2857 {
2858 /* This is what the gcc2_compiled and __gnu_compiled_*
2859 show up as. So don't complain. */
2860 ;
2861 }
2862 else
2863 /* Handle encoded stab line number. */
2864 record_line (current_subfile, sh.index, valu);
a2f1e2e5
ILT
2865 }
2866 else if (sh.st == stProc || sh.st == stStaticProc || sh.st == stEnd)
2867 /* These are generated by gcc-2.x, do not complain */
2868 ;
2869 else
2870 complain (&stab_unknown_complaint, name);
2871 }
2872 st = end_symtab (pst->texthigh, 0, 0, pst->objfile, SECT_OFF_TEXT);
2873 end_stabs ();
2874
2875 /* Sort the symbol table now, we are done adding symbols to it.
2876 We must do this before parse_procedure calls lookup_symbol. */
2877 sort_symtab_syms (st);
2878
2879 /* This may not be necessary for stabs symtabs. FIXME. */
2880 sort_blocks (st);
2881
2882 /* Fill in procedure info next. */
2883 first_pdr = 1;
2884 pdr_ptr = ((char *) debug_info->external_pdr
2885 + fh->ipdFirst * external_pdr_size);
2886 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
2887 for (; pdr_ptr < pdr_end; pdr_ptr += external_pdr_size)
2888 {
2889 PDR pr;
2890
2891 (*swap_pdr_in) (cur_bfd, pdr_ptr, &pr);
2892 if (first_pdr)
2893 {
2894 first_off = pr.adr;
2895 first_pdr = 0;
2896 }
2897 parse_procedure (&pr, st, first_off);
2898 }
2899 }
2900 else
2901 {
2902 /* This symbol table contains ordinary ecoff entries. */
2903
2904 /* FIXME: doesn't use pst->section_offsets. */
2905
2906 int f_max;
2907 int maxlines;
2908 EXTR *ext_ptr;
2909
2910 /* How many symbols will we need */
2911 /* FIXME, this does not count enum values. */
2912 f_max = pst->n_global_syms + pst->n_static_syms;
2913 if (fh == 0)
2914 {
2915 maxlines = 0;
2916 st = new_symtab ("unknown", f_max, 0, pst->objfile);
2917 }
2918 else
2919 {
2920 f_max += fh->csym + fh->cpd;
2921 maxlines = 2 * fh->cline;
2922 st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
2923
2924 /* The proper language was already determined when building
2925 the psymtab, use it. */
2926 st->language = PST_PRIVATE (pst)->pst_language;
2927 }
2928
2929 psymtab_language = st->language;
2930
2931 lines = LINETABLE (st);
2932
2933 /* Get a new lexical context */
2934
2935 push_parse_stack ();
2936 top_stack->cur_st = st;
2937 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
2938 STATIC_BLOCK);
2939 BLOCK_START (top_stack->cur_block) = fh ? fh->adr : 0;
2940 BLOCK_END (top_stack->cur_block) = 0;
2941 top_stack->blocktype = stFile;
2942 top_stack->maxsyms = 2 * f_max;
2943 top_stack->cur_type = 0;
2944 top_stack->procadr = 0;
2945 top_stack->numargs = 0;
2946
2947 if (fh)
2948 {
2949 char *sym_ptr;
2950 char *sym_end;
2951
2952 /* Parse local symbols first */
2953 sym_ptr = ((char *) debug_info->external_sym
2954 + fh->isymBase * external_sym_size);
2955 sym_end = sym_ptr + fh->csym * external_sym_size;
2956 while (sym_ptr < sym_end)
2957 {
2958 SYMR sh;
2959 int c;
2960
2961 (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
2962 c = parse_symbol (&sh,
2963 debug_info->external_aux + fh->iauxBase,
2964 sym_ptr, fh->fBigendian);
2965 sym_ptr += c * external_sym_size;
2966 }
2967
2968 /* Linenumbers. At the end, check if we can save memory.
2969 parse_lines has to look ahead an arbitrary number of PDR
2970 structures, so we swap them all first. */
2971 if (fh->cpd > 0)
2972 {
2973 PDR *pr_block;
2974 struct cleanup *old_chain;
2975 char *pdr_ptr;
2976 char *pdr_end;
2977 PDR *pdr_in;
2978 PDR *pdr_in_end;
2979
2980 pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
2981
2982 old_chain = make_cleanup (free, pr_block);
2983
2984 pdr_ptr = ((char *) debug_info->external_pdr
2985 + fh->ipdFirst * external_pdr_size);
2986 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
2987 pdr_in = pr_block;
2988 for (;
2989 pdr_ptr < pdr_end;
2990 pdr_ptr += external_pdr_size, pdr_in++)
2991 (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
2992
2993 parse_lines (fh, pr_block, lines, maxlines);
2994 if (lines->nitems < fh->cline)
2995 lines = shrink_linetable (lines);
2996
2997 /* Fill in procedure info next. */
2998 pdr_in = pr_block;
2999 pdr_in_end = pdr_in + fh->cpd;
3000 for (; pdr_in < pdr_in_end; pdr_in++)
3001 parse_procedure (pdr_in, 0, pr_block->adr);
3002
3003 do_cleanups (old_chain);
3004 }
3005 }
3006
3007 LINETABLE (st) = lines;
3008
3009 /* .. and our share of externals.
3010 XXX use the global list to speed up things here. how?
3011 FIXME, Maybe quit once we have found the right number of ext's? */
3012 top_stack->cur_st = st;
3013 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
3014 GLOBAL_BLOCK);
3015 top_stack->blocktype = stFile;
3016 top_stack->maxsyms
3017 = (debug_info->symbolic_header.isymMax
3018 + debug_info->symbolic_header.ipdMax
3019 + debug_info->symbolic_header.iextMax);
3020
3021 ext_ptr = PST_PRIVATE (pst)->extern_tab;
3022 for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
3023 parse_external (ext_ptr, 1, fh->fBigendian);
3024
3025 /* If there are undefined symbols, tell the user.
3026 The alpha has an undefined symbol for every symbol that is
3027 from a shared library, so tell the user only if verbose is on. */
3028 if (info_verbose && n_undef_symbols)
3029 {
3030 printf_filtered ("File %s contains %d unresolved references:",
3031 st->filename, n_undef_symbols);
3032 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
3033 n_undef_vars, n_undef_procs, n_undef_labels);
3034 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
3035
3036 }
3037 pop_parse_stack ();
3038
3039 /* Sort the symbol table now, we are done adding symbols to it.*/
3040 sort_symtab_syms (st);
3041
3042 sort_blocks (st);
3043 }
3044
3045 /* Now link the psymtab and the symtab. */
3046 pst->symtab = st;
3047
3048 current_objfile = NULL;
3049}
3050\f
3051/* Ancillary parsing procedures. */
3052
3053/* Lookup the type at relative index RN. Return it in TPP
3054 if found and in any event come up with its name PNAME.
3055 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
3056 Return value says how many aux symbols we ate. */
3057
3058static int
3059cross_ref (fd, ax, tpp, type_code, pname, bigend, sym_name)
3060 int fd;
3061 union aux_ext *ax;
3062 struct type **tpp;
3063 enum type_code type_code; /* Use to alloc new type if none is found. */
3064 char **pname;
3065 int bigend;
3066 char *sym_name;
3067{
3068 RNDXR rn[1];
3069 unsigned int rf;
3070 int result = 1;
3071 FDR *fh;
3072 char *esh;
3073 SYMR sh;
3074 int xref_fd;
3075 struct mdebug_pending *pend;
3076
3077 *tpp = (struct type *)NULL;
3078
3079 ecoff_swap_rndx_in (bigend, &ax->a_rndx, rn);
3080
3081 /* Escape index means 'the next one' */
3082 if (rn->rfd == 0xfff)
3083 {
3084 result++;
3085 rf = AUX_GET_ISYM (bigend, ax + 1);
3086 }
3087 else
3088 {
3089 rf = rn->rfd;
3090 }
3091
3092 /* mips cc uses a rf of -1 for opaque struct definitions.
3093 Set TYPE_FLAG_STUB for these types so that check_stub_type will
3094 resolve them if the struct gets defined in another compilation unit. */
3095 if (rf == -1)
3096 {
3097 *pname = "<undefined>";
3098 *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
3099 TYPE_FLAGS (*tpp) |= TYPE_FLAG_STUB;
3100 return result;
3101 }
3102
3103 /* mips cc uses an escaped rn->index of 0 for struct return types
3104 of procedures that were compiled without -g. These will always remain
3105 undefined. */
3106 if (rn->rfd == 0xfff && rn->index == 0)
3107 {
3108 *pname = "<undefined>";
3109 return result;
3110 }
3111
3112 /* Find the relative file descriptor and the symbol in it. */
3113 fh = get_rfd (fd, rf);
3114 xref_fd = fh - debug_info->fdr;
3115
3116 if (rn->index >= fh->csym)
3117 {
3118 /* File indirect entry is corrupt. */
3119 *pname = "<illegal>";
3120 complain (&bad_rfd_entry_complaint,
3121 sym_name, xref_fd, rn->index);
3122 return result;
3123 }
3124
3125 /* If we have processed this symbol then we left a forwarding
3126 pointer to the type in the pending list. If not, we`ll put
3127 it in a list of pending types, to be processed later when
3128 the file will be. In any event, we collect the name for the
3129 type here. */
3130
3131 esh = ((char *) debug_info->external_sym
3132 + ((fh->isymBase + rn->index)
3133 * debug_swap->external_sym_size));
3134 (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
3135
3136 /* Make sure that this type of cross reference can be handled. */
10373914
PS
3137 if ((sh.sc != scInfo
3138 || (sh.st != stBlock && sh.st != stTypedef
3139 && sh.st != stStruct && sh.st != stUnion
3140 && sh.st != stEnum))
3141 && (sh.sc != scCommon || sh.st != stBlock))
a2f1e2e5
ILT
3142 {
3143 /* File indirect entry is corrupt. */
3144 *pname = "<illegal>";
3145 complain (&bad_rfd_entry_complaint,
3146 sym_name, xref_fd, rn->index);
3147 return result;
3148 }
3149
3150 *pname = debug_info->ss + fh->issBase + sh.iss;
3151
3152 pend = is_pending_symbol (fh, esh);
3153 if (pend)
3154 *tpp = pend->t;
3155 else
3156 {
3157 /* We have not yet seen this type. */
3158
3159 if (sh.iss == 0 && sh.st == stTypedef)
3160 {
3161 TIR tir;
3162
3163 /* alpha cc puts out a stTypedef with a sh.iss of zero for
3164 two cases:
3165 a) forward declarations of structs/unions/enums which are not
3166 defined in this compilation unit.
3167 For these the type will be void. This is a bad design decision
3168 as cross referencing across compilation units is impossible
3169 due to the missing name.
3170 b) forward declarations of structs/unions/enums which are defined
3171 later in this file or in another file in the same compilation
3172 unit. Simply cross reference those again to get the
3173 true type.
3174 The forward references are not entered in the pending list and
3175 in the symbol table. */
3176
3177 ecoff_swap_tir_in (bigend,
3178 &(debug_info->external_aux
3179 + fh->iauxBase + sh.index)->a_ti,
3180 &tir);
3181 if (tir.tq0 != tqNil)
3182 complain (&illegal_forward_tq0_complaint, sym_name);
3183 switch (tir.bt)
3184 {
3185 case btVoid:
3186 *tpp = init_type (type_code, 0, 0, (char *) NULL,
3187 current_objfile);
3188 *pname = "<undefined>";
3189 break;
3190
3191 case btStruct:
3192 case btUnion:
3193 case btEnum:
3194 cross_ref (xref_fd,
3195 (debug_info->external_aux
3196 + fh->iauxBase + sh.index + 1),
3197 tpp, type_code, pname,
3198 fh->fBigendian, sym_name);
3199 break;
3200
3201 default:
3202 complain (&illegal_forward_bt_complaint, tir.bt, sym_name);
3203 *tpp = init_type (type_code, 0, 0, (char *) NULL,
3204 current_objfile);
3205 break;
3206 }
3207 return result;
3208 }
3209 else if (sh.st == stTypedef)
3210 {
3211 /* Parse the type for a normal typedef. This might recursively call
3212 cross_ref till we get a non typedef'ed type.
3213 FIXME: This is not correct behaviour, but gdb currently
3214 cannot handle typedefs without type copying. But type copying is
3215 impossible as we might have mutual forward references between
3216 two files and the copied type would not get filled in when
3217 we later parse its definition. */
3218 *tpp = parse_type (xref_fd,
3219 debug_info->external_aux + fh->iauxBase,
3220 sh.index,
3221 (int *)NULL,
3222 fh->fBigendian,
3223 debug_info->ss + fh->issBase + sh.iss);
3224 }
3225 else
3226 {
3227 /* Cross reference to a struct/union/enum which is defined
3228 in another file in the same compilation unit but that file
3229 has not been parsed yet.
3230 Initialize the type only, it will be filled in when
3231 it's definition is parsed. */
3232 *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
3233 }
3234 add_pending (fh, esh, *tpp);
3235 }
3236
3237 /* We used one auxent normally, two if we got a "next one" rf. */
3238 return result;
3239}
3240
3241
3242/* Quick&dirty lookup procedure, to avoid the MI ones that require
3243 keeping the symtab sorted */
3244
3245static struct symbol *
3246mylookup_symbol (name, block, namespace, class)
3247 char *name;
3248 register struct block *block;
3249 enum namespace namespace;
3250 enum address_class class;
3251{
3252 register int bot, top, inc;
3253 register struct symbol *sym;
3254
3255 bot = 0;
3256 top = BLOCK_NSYMS (block);
3257 inc = name[0];
3258 while (bot < top)
3259 {
3260 sym = BLOCK_SYM (block, bot);
3261 if (SYMBOL_NAME (sym)[0] == inc
3262 && SYMBOL_NAMESPACE (sym) == namespace
3263 && SYMBOL_CLASS (sym) == class
3264 && strcmp (SYMBOL_NAME (sym), name) == 0)
3265 return sym;
3266 bot++;
3267 }
3268 block = BLOCK_SUPERBLOCK (block);
3269 if (block)
3270 return mylookup_symbol (name, block, namespace, class);
3271 return 0;
3272}
3273
3274
3275/* Add a new symbol S to a block B.
3276 Infrequently, we will need to reallocate the block to make it bigger.
3277 We only detect this case when adding to top_stack->cur_block, since
3278 that's the only time we know how big the block is. FIXME. */
3279
3280static void
3281add_symbol (s, b)
3282 struct symbol *s;
3283 struct block *b;
3284{
3285 int nsyms = BLOCK_NSYMS (b)++;
3286 struct block *origb;
3287 struct parse_stack *stackp;
3288
3289 if (b == top_stack->cur_block &&
3290 nsyms >= top_stack->maxsyms)
3291 {
3292 complain (&block_overflow_complaint, SYMBOL_NAME (s));
3293 /* In this case shrink_block is actually grow_block, since
3294 BLOCK_NSYMS(b) is larger than its current size. */
3295 origb = b;
3296 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
3297
3298 /* Now run through the stack replacing pointers to the
3299 original block. shrink_block has already done this
3300 for the blockvector and BLOCK_FUNCTION. */
3301 for (stackp = top_stack; stackp; stackp = stackp->next)
3302 {
3303 if (stackp->cur_block == origb)
3304 {
3305 stackp->cur_block = b;
3306 stackp->maxsyms = BLOCK_NSYMS (b);
3307 }
3308 }
3309 }
3310 BLOCK_SYM (b, nsyms) = s;
3311}
3312
3313/* Add a new block B to a symtab S */
3314
3315static void
3316add_block (b, s)
3317 struct block *b;
3318 struct symtab *s;
3319{
3320 struct blockvector *bv = BLOCKVECTOR (s);
3321
3322 bv = (struct blockvector *) xrealloc ((PTR) bv,
3323 (sizeof (struct blockvector)
3324 + BLOCKVECTOR_NBLOCKS (bv)
3325 * sizeof (bv->block)));
3326 if (bv != BLOCKVECTOR (s))
3327 BLOCKVECTOR (s) = bv;
3328
3329 BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
3330}
3331
3332/* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3333 MIPS' linenumber encoding might need more than one byte
3334 to describe it, LAST is used to detect these continuation lines.
3335
3336 Combining lines with the same line number seems like a bad idea.
3337 E.g: There could be a line number entry with the same line number after the
3338 prologue and GDB should not ignore it (this is a better way to find
3339 a prologue than mips_skip_prologue).
3340 But due to the compressed line table format there are line number entries
3341 for the same line which are needed to bridge the gap to the next
3342 line number entry. These entries have a bogus address info with them
3343 and we are unable to tell them from intended duplicate line number
3344 entries.
3345 This is another reason why -ggdb debugging format is preferable. */
3346
3347static int
3348add_line (lt, lineno, adr, last)
3349 struct linetable *lt;
3350 int lineno;
3351 CORE_ADDR adr;
3352 int last;
3353{
9d51b3c5
PS
3354 /* DEC c89 sometimes produces zero linenos which confuse gdb.
3355 Change them to something sensible. */
3356 if (lineno == 0)
3357 lineno = 1;
a2f1e2e5
ILT
3358 if (last == 0)
3359 last = -2; /* make sure we record first line */
3360
3361 if (last == lineno) /* skip continuation lines */
3362 return lineno;
3363
3364 lt->item[lt->nitems].line = lineno;
3365 lt->item[lt->nitems++].pc = adr << 2;
3366 return lineno;
3367}
3368\f
3369/* Sorting and reordering procedures */
3370
3371/* Blocks with a smaller low bound should come first */
3372
3373static int
3374compare_blocks (arg1, arg2)
3375 const PTR arg1;
3376 const PTR arg2;
3377{
3378 register int addr_diff;
3379 struct block **b1 = (struct block **) arg1;
3380 struct block **b2 = (struct block **) arg2;
3381
3382 addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
3383 if (addr_diff == 0)
3384 return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
3385 return addr_diff;
3386}
3387
3388/* Sort the blocks of a symtab S.
3389 Reorder the blocks in the blockvector by code-address,
3390 as required by some MI search routines */
3391
3392static void
3393sort_blocks (s)
3394 struct symtab *s;
3395{
3396 struct blockvector *bv = BLOCKVECTOR (s);
3397
3398 if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
3399 {
3400 /* Cosmetic */
3401 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
3402 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
3403 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
3404 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
3405 return;
3406 }
3407 /*
3408 * This is very unfortunate: normally all functions are compiled in
3409 * the order they are found, but if the file is compiled -O3 things
3410 * are very different. It would be nice to find a reliable test
3411 * to detect -O3 images in advance.
3412 */
3413 if (BLOCKVECTOR_NBLOCKS (bv) > 3)
3414 qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
3415 BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
3416 sizeof (struct block *),
3417 compare_blocks);
3418
3419 {
3420 register CORE_ADDR high = 0;
3421 register int i, j = BLOCKVECTOR_NBLOCKS (bv);
3422
3423 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
3424 if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
3425 high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
3426 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
3427 }
3428
3429 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
3430 BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
3431
3432 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
3433 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
3434 BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
3435 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
3436}
3437\f
3438
3439/* Constructor/restructor/destructor procedures */
3440
3441/* Allocate a new symtab for NAME. Needs an estimate of how many symbols
3442 MAXSYMS and linenumbers MAXLINES we'll put in it */
3443
3444static struct symtab *
3445new_symtab (name, maxsyms, maxlines, objfile)
3446 char *name;
3447 int maxsyms;
3448 int maxlines;
3449 struct objfile *objfile;
3450{
3451 struct symtab *s = allocate_symtab (name, objfile);
3452
3453 LINETABLE (s) = new_linetable (maxlines);
3454
3455 /* All symtabs must have at least two blocks */
3456 BLOCKVECTOR (s) = new_bvect (2);
3457 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
3458 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
3459 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
3460 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3461
3462 s->free_code = free_linetable;
3463
3464 return (s);
3465}
3466
3467/* Allocate a new partial_symtab NAME */
3468
3469static struct partial_symtab *
847d9775 3470new_psymtab (name, objfile, section_offsets)
a2f1e2e5
ILT
3471 char *name;
3472 struct objfile *objfile;
847d9775 3473 struct section_offsets *section_offsets;
a2f1e2e5
ILT
3474{
3475 struct partial_symtab *psymtab;
3476
3477 psymtab = allocate_psymtab (name, objfile);
847d9775 3478 psymtab->section_offsets = section_offsets;
a2f1e2e5
ILT
3479
3480 /* Keep a backpointer to the file's symbols */
3481
3482 psymtab->read_symtab_private = ((char *)
3483 obstack_alloc (&objfile->psymbol_obstack,
3484 sizeof (struct symloc)));
3485 memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
3486 CUR_BFD (psymtab) = cur_bfd;
3487 DEBUG_SWAP (psymtab) = debug_swap;
3488 DEBUG_INFO (psymtab) = debug_info;
3489 PENDING_LIST (psymtab) = pending_list;
3490
3491 /* The way to turn this into a symtab is to call... */
3492 psymtab->read_symtab = mdebug_psymtab_to_symtab;
3493 return (psymtab);
3494}
3495
3496
3497/* Allocate a linetable array of the given SIZE. Since the struct
3498 already includes one item, we subtract one when calculating the
3499 proper size to allocate. */
3500
3501static struct linetable *
3502new_linetable (size)
3503 int size;
3504{
3505 struct linetable *l;
3506
3507 size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
3508 l = (struct linetable *) xmalloc (size);
3509 l->nitems = 0;
3510 return l;
3511}
3512
3513/* Oops, too big. Shrink it. This was important with the 2.4 linetables,
3514 I am not so sure about the 3.4 ones.
3515
3516 Since the struct linetable already includes one item, we subtract one when
3517 calculating the proper size to allocate. */
3518
3519static struct linetable *
3520shrink_linetable (lt)
3521 struct linetable *lt;
3522{
3523
3524 return (struct linetable *) xrealloc ((PTR) lt,
3525 (sizeof (struct linetable)
3526 + ((lt->nitems - 1)
3527 * sizeof (lt->item))));
3528}
3529
3530/* Allocate and zero a new blockvector of NBLOCKS blocks. */
3531
3532static struct blockvector *
3533new_bvect (nblocks)
3534 int nblocks;
3535{
3536 struct blockvector *bv;
3537 int size;
3538
3539 size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
3540 bv = (struct blockvector *) xzalloc (size);
3541
3542 BLOCKVECTOR_NBLOCKS (bv) = nblocks;
3543
3544 return bv;
3545}
3546
3547/* Allocate and zero a new block of MAXSYMS symbols */
3548
3549static struct block *
3550new_block (maxsyms)
3551 int maxsyms;
3552{
3553 int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
3554
3555 return (struct block *) xzalloc (size);
3556}
3557
3558/* Ooops, too big. Shrink block B in symtab S to its minimal size.
3559 Shrink_block can also be used by add_symbol to grow a block. */
3560
3561static struct block *
3562shrink_block (b, s)
3563 struct block *b;
3564 struct symtab *s;
3565{
3566 struct block *new;
3567 struct blockvector *bv = BLOCKVECTOR (s);
3568 int i;
3569
3570 /* Just reallocate it and fix references to the old one */
3571
3572 new = (struct block *) xrealloc ((PTR) b,
3573 (sizeof (struct block)
3574 + ((BLOCK_NSYMS (b) - 1)
3575 * sizeof (struct symbol *))));
3576
3577 /* Should chase pointers to old one. Fortunately, that`s just
3578 the block`s function and inferior blocks */
3579 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
3580 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3581 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
3582 if (BLOCKVECTOR_BLOCK (bv, i) == b)
3583 BLOCKVECTOR_BLOCK (bv, i) = new;
3584 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
3585 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
3586 return new;
3587}
3588
3589/* Create a new symbol with printname NAME */
3590
3591static struct symbol *
3592new_symbol (name)
3593 char *name;
3594{
3595 struct symbol *s = ((struct symbol *)
3596 obstack_alloc (&current_objfile->symbol_obstack,
3597 sizeof (struct symbol)));
3598
3599 memset ((PTR) s, 0, sizeof (*s));
3600 SYMBOL_NAME (s) = name;
3601 SYMBOL_LANGUAGE (s) = psymtab_language;
3602 SYMBOL_INIT_DEMANGLED_NAME (s, &current_objfile->symbol_obstack);
3603 return s;
3604}
3605
3606/* Create a new type with printname NAME */
3607
3608static struct type *
3609new_type (name)
3610 char *name;
3611{
3612 struct type *t;
3613
3614 t = alloc_type (current_objfile);
3615 TYPE_NAME (t) = name;
3616 TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
3617 return t;
3618}
3619\f
3620/* Read ECOFF debugging information from a BFD section. This is
3621 called from elfread.c. It parses the section into a
3622 ecoff_debug_info struct, and then lets the rest of the file handle
3623 it as normal. */
3624
3625void
3626elfmdebug_build_psymtabs (objfile, swap, sec, section_offsets)
3627 struct objfile *objfile;
3628 const struct ecoff_debug_swap *swap;
3629 asection *sec;
3630 struct section_offsets *section_offsets;
3631{
3632 bfd *abfd = objfile->obfd;
3633 char *buf;
3634 struct ecoff_debug_info *info;
3635
3636 buf = alloca (swap->external_hdr_size);
3637 if (bfd_get_section_contents (abfd, sec, buf, (file_ptr) 0,
3638 swap->external_hdr_size) == false)
3639 perror_with_name (bfd_get_filename (abfd));
3640
3641 info = ((struct ecoff_debug_info *)
3642 obstack_alloc (&objfile->psymbol_obstack,
3643 sizeof (struct ecoff_debug_info)));
3644
3645 (*swap->swap_hdr_in) (abfd, buf, &info->symbolic_header);
3646
3647 /* The offsets in symbolic_header are file offsets, not section
3648 offsets. Strangely, on Irix 5 the information is not entirely
3649 within the .mdebug section. There are parts of an executable
3650 file which are not within any ELF section at all. This means
3651 that we must read the information using bfd_read. */
3652
3653#define READ(ptr, count, off, size, type) \
3654 do \
3655 { \
3656 if (info->symbolic_header.count == 0) \
3657 info->ptr = (type) NULL; \
3658 else \
3659 { \
3660 info->ptr = ((type) \
3661 obstack_alloc (&objfile->psymbol_obstack, \
3662 (info->symbolic_header.count \
3663 * size))); \
3664 if (bfd_seek (abfd, info->symbolic_header.off, SEEK_SET) < 0 \
3665 || (bfd_read ((PTR) info->ptr, size, \
3666 info->symbolic_header.count, abfd) \
3667 != info->symbolic_header.count * size)) \
3668 perror_with_name (bfd_get_filename (abfd)); \
3669 } \
3670 } \
3671 while (0)
3672
3673 READ (line, cbLine, cbLineOffset, sizeof (unsigned char), unsigned char *);
3674 READ (external_dnr, idnMax, cbDnOffset, swap->external_dnr_size, PTR);
3675 READ (external_pdr, ipdMax, cbPdOffset, swap->external_pdr_size, PTR);
3676 READ (external_sym, isymMax, cbSymOffset, swap->external_sym_size, PTR);
3677 READ (external_opt, ioptMax, cbOptOffset, swap->external_opt_size, PTR);
3678 READ (external_aux, iauxMax, cbAuxOffset, sizeof (union aux_ext),
3679 union aux_ext *);
3680 READ (ss, issMax, cbSsOffset, sizeof (char), char *);
3681 READ (ssext, issExtMax, cbSsExtOffset, sizeof (char), char *);
3682 READ (external_fdr, ifdMax, cbFdOffset, swap->external_fdr_size, PTR);
3683 READ (external_rfd, crfd, cbRfdOffset, swap->external_rfd_size, PTR);
3684 READ (external_ext, iextMax, cbExtOffset, swap->external_ext_size, PTR);
3685
3686#undef READ
3687
3688 info->fdr = NULL;
3689
3690 mdebug_build_psymtabs (objfile, swap, info, section_offsets);
3691}
3692\f
3693
3694/* Things used for calling functions in the inferior.
3695 These functions are exported to our companion
3696 mips-tdep.c file and are here because they play
3697 with the symbol-table explicitly. */
3698
3699/* Sigtramp: make sure we have all the necessary information
3700 about the signal trampoline code. Since the official code
3701 from MIPS does not do so, we make up that information ourselves.
3702 If they fix the library (unlikely) this code will neutralize itself. */
3703
3704/* FIXME: This function is called only by mips-tdep.c. It needs to be
3705 here because it calls functions defined in this file, but perhaps
3706 this could be handled in a better way. */
3707
3708void
3709fixup_sigtramp ()
3710{
3711 struct symbol *s;
3712 struct symtab *st;
3713 struct block *b, *b0 = NULL;
3714
3715 sigtramp_address = -1;
3716
3717 /* We have to handle the following cases here:
3718 a) The Mips library has a sigtramp label within sigvec.
3719 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
3720 s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL);
3721 if (s != 0)
3722 {
3723 b0 = SYMBOL_BLOCK_VALUE (s);
3724 s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
3725 }
3726 if (s == 0)
3727 {
3728 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
3729 s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
3730 }
3731
3732 /* But maybe this program uses its own version of sigvec */
3733 if (s == 0)
3734 return;
3735
3736 /* Did we or MIPSco fix the library ? */
3737 if (SYMBOL_CLASS (s) == LOC_BLOCK)
3738 {
3739 sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s));
3740 sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s));
3741 return;
3742 }
3743
3744 sigtramp_address = SYMBOL_VALUE (s);
3745 sigtramp_end = sigtramp_address + 0x88; /* black magic */
3746
3747 /* But what symtab does it live in ? */
3748 st = find_pc_symtab (SYMBOL_VALUE (s));
3749
3750 /*
3751 * Ok, there goes the fix: turn it into a procedure, with all the
3752 * needed info. Note we make it a nested procedure of sigvec,
3753 * which is the way the (assembly) code is actually written.
3754 */
3755 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
3756 SYMBOL_CLASS (s) = LOC_BLOCK;
3757 SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL,
3758 st->objfile);
3759 TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = builtin_type_void;
3760
3761 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3762 b = new_block (1);
3763 SYMBOL_BLOCK_VALUE (s) = b;
3764 BLOCK_START (b) = sigtramp_address;
3765 BLOCK_END (b) = sigtramp_end;
3766 BLOCK_FUNCTION (b) = s;
3767 BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
3768 add_block (b, st);
3769 sort_blocks (st);
3770
3771 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3772 {
3773 struct mips_extra_func_info *e =
3774 ((struct mips_extra_func_info *)
3775 xzalloc (sizeof (struct mips_extra_func_info)));
3776
3777 e->numargs = 0; /* the kernel thinks otherwise */
0434c1a0 3778 e->pdr.frameoffset = 32;
a2f1e2e5 3779 e->pdr.framereg = SP_REGNUM;
0434c1a0
PS
3780 /* Note that setting pcreg is no longer strictly necessary as
3781 mips_frame_saved_pc is now aware of signal handler frames. */
a2f1e2e5
ILT
3782 e->pdr.pcreg = PC_REGNUM;
3783 e->pdr.regmask = -2;
0434c1a0
PS
3784 /* Offset to saved r31, in the sigtramp case the saved registers
3785 are above the frame in the sigcontext.
3786 We have 4 alignment bytes, 12 bytes for onstack, mask and pc,
3787 32 * 4 bytes for the general registers, 12 bytes for mdhi, mdlo, ownedfp
3788 and 32 * 4 bytes for the floating point registers. */
3789 e->pdr.regoffset = 4 + 12 + 31 * 4;
a2f1e2e5 3790 e->pdr.fregmask = -1;
0434c1a0
PS
3791 /* Offset to saved f30 (first saved *double* register). */
3792 e->pdr.fregoffset = 4 + 12 + 32 * 4 + 12 + 30 * 4;
a2f1e2e5
ILT
3793 e->pdr.isym = (long) s;
3794 e->pdr.adr = sigtramp_address;
3795
3796 current_objfile = st->objfile; /* Keep new_symbol happy */
3797 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
3798 SYMBOL_VALUE (s) = (long) e;
3799 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
3800 SYMBOL_CLASS (s) = LOC_CONST;
3801 SYMBOL_TYPE (s) = builtin_type_void;
3802 current_objfile = NULL;
3803 }
3804
3805 BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s;
3806}
3807
3808void
3809_initialize_mdebugread ()
3810{
3811 /* Missing basic types */
3812
504ccfd7
JK
3813 /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
3814 FIXME. */
3815 mdebug_type_string =
a2f1e2e5
ILT
3816 init_type (TYPE_CODE_STRING,
3817 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3818 0, "string",
3819 (struct objfile *) NULL);
504ccfd7
JK
3820
3821 mdebug_type_complex =
3822 init_type (TYPE_CODE_ERROR,
a2f1e2e5
ILT
3823 TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
3824 0, "complex",
3825 (struct objfile *) NULL);
504ccfd7
JK
3826 mdebug_type_double_complex =
3827 init_type (TYPE_CODE_ERROR,
a2f1e2e5
ILT
3828 TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
3829 0, "double complex",
3830 (struct objfile *) NULL);
504ccfd7
JK
3831
3832 /* We use TYPE_CODE_INT to print these as integers. Does this do any
3833 good? Would we be better off with TYPE_CODE_ERROR? Should
3834 TYPE_CODE_ERROR print things in hex if it knows the size? */
3835 mdebug_type_fixed_dec =
a2f1e2e5
ILT
3836 init_type (TYPE_CODE_INT,
3837 TARGET_INT_BIT / TARGET_CHAR_BIT,
3838 0, "fixed decimal",
3839 (struct objfile *) NULL);
504ccfd7
JK
3840
3841 mdebug_type_float_dec =
3842 init_type (TYPE_CODE_ERROR,
a2f1e2e5
ILT
3843 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3844 0, "floating decimal",
3845 (struct objfile *) NULL);
3846}
This page took 0.285925 seconds and 4 git commands to generate.