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