2002-12-13 Jeff Johnston <jjohnstn@redhat.com>
[deliverable/binutils-gdb.git] / gdb / mdebugread.c
1 /* Read a symbol table in ECOFF format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
3 1997, 1998, 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
5 Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
6 CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor
7 at Cygnus Support.
8
9 This file is part of GDB.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
25
26 /* This module provides the function mdebug_build_psymtabs. It reads
27 ECOFF debugging information into partial symbol tables. The
28 debugging information is read from two structures. A struct
29 ecoff_debug_swap includes the sizes of each ECOFF structure and
30 swapping routines; these are fixed for a particular target. A
31 struct ecoff_debug_info points to the debugging information for a
32 particular object file.
33
34 ECOFF symbol tables are mostly written in the byte order of the
35 target machine. However, one section of the table (the auxiliary
36 symbol information) is written in the host byte order. There is a
37 bit in the other symbol info which describes which host byte order
38 was used. ECOFF thereby takes the trophy from Intel `b.out' for
39 the most brain-dead adaptation of a file format to byte order.
40
41 This module can read all four of the known byte-order combinations,
42 on any type of host. */
43
44 #include "defs.h"
45 #include "symtab.h"
46 #include "gdbtypes.h"
47 #include "gdbcore.h"
48 #include "symfile.h"
49 #include "objfiles.h"
50 #include "gdb_obstack.h"
51 #include "buildsym.h"
52 #include "stabsread.h"
53 #include "complaints.h"
54 #include "demangle.h"
55 #include "gdb_assert.h"
56
57 /* These are needed if the tm.h file does not contain the necessary
58 mips specific definitions. */
59
60 #ifndef MIPS_EFI_SYMBOL_NAME
61 #define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
62 extern void ecoff_relocate_efi (struct symbol *, CORE_ADDR);
63 #include "coff/sym.h"
64 #include "coff/symconst.h"
65 typedef struct mips_extra_func_info
66 {
67 long numargs;
68 PDR pdr;
69 }
70 *mips_extra_func_info_t;
71 #ifndef RA_REGNUM
72 #define RA_REGNUM 0
73 #endif
74 #endif
75
76 #ifdef USG
77 #include <sys/types.h>
78 #endif
79
80 #include "gdb_stat.h"
81 #include "gdb_string.h"
82
83 #include "bfd.h"
84
85 #include "coff/ecoff.h" /* COFF-like aspects of ecoff files */
86
87 #include "libaout.h" /* Private BFD a.out information. */
88 #include "aout/aout64.h"
89 #include "aout/stab_gnu.h" /* STABS information */
90
91 #include "expression.h"
92 #include "language.h" /* For local_hex_string() */
93
94 extern void _initialize_mdebugread (void);
95
96 /* Provide a way to test if we have both ECOFF and ELF symbol tables.
97 We use this define in order to know whether we should override a
98 symbol's ECOFF section with its ELF section. This is necessary in
99 case the symbol's ELF section could not be represented in ECOFF. */
100 #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
101 && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
102 \f
103
104 /* We put a pointer to this structure in the read_symtab_private field
105 of the psymtab. */
106
107 struct symloc
108 {
109 /* Index of the FDR that this psymtab represents. */
110 int fdr_idx;
111 /* The BFD that the psymtab was created from. */
112 bfd *cur_bfd;
113 const struct ecoff_debug_swap *debug_swap;
114 struct ecoff_debug_info *debug_info;
115 struct mdebug_pending **pending_list;
116 /* Pointer to external symbols for this file. */
117 EXTR *extern_tab;
118 /* Size of extern_tab. */
119 int extern_count;
120 enum language pst_language;
121 };
122
123 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
124 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
125 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
126 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
127 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
128 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
129
130 #define SC_IS_TEXT(sc) ((sc) == scText \
131 || (sc) == scRConst \
132 || (sc) == scInit \
133 || (sc) == scFini)
134 #define SC_IS_DATA(sc) ((sc) == scData \
135 || (sc) == scSData \
136 || (sc) == scRData \
137 || (sc) == scPData \
138 || (sc) == scXData)
139 #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
140 #define SC_IS_BSS(sc) ((sc) == scBss)
141 #define SC_IS_SBSS(sc) ((sc) == scSBss)
142 #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
143 \f
144 /* Various complaints about symbol reading that don't abort the process */
145
146 static struct deprecated_complaint bad_file_number_complaint =
147 {"bad file number %d", 0, 0};
148
149 static struct deprecated_complaint index_complaint =
150 {"bad aux index at symbol %s", 0, 0};
151
152 static struct deprecated_complaint aux_index_complaint =
153 {"bad proc end in aux found from symbol %s", 0, 0};
154
155 static struct deprecated_complaint block_index_complaint =
156 {"bad aux index at block symbol %s", 0, 0};
157
158 static struct deprecated_complaint unknown_ext_complaint =
159 {"unknown external symbol %s", 0, 0};
160
161 static struct deprecated_complaint unknown_sym_complaint =
162 {"unknown local symbol %s", 0, 0};
163
164 static struct deprecated_complaint unknown_st_complaint =
165 {"with type %d", 0, 0};
166
167 static struct deprecated_complaint block_overflow_complaint =
168 {"block containing %s overfilled", 0, 0};
169
170 static struct deprecated_complaint basic_type_complaint =
171 {"cannot map ECOFF basic type 0x%x for %s", 0, 0};
172
173 static struct deprecated_complaint unknown_type_qual_complaint =
174 {"unknown type qualifier 0x%x", 0, 0};
175
176 static struct deprecated_complaint array_index_type_complaint =
177 {"illegal array index type for %s, assuming int", 0, 0};
178
179 static struct deprecated_complaint bad_tag_guess_complaint =
180 {"guessed tag type of %s incorrectly", 0, 0};
181
182 static struct deprecated_complaint block_member_complaint =
183 {"declaration block contains unhandled symbol type %d", 0, 0};
184
185 static struct deprecated_complaint stEnd_complaint =
186 {"stEnd with storage class %d not handled", 0, 0};
187
188 static struct deprecated_complaint unknown_mdebug_symtype_complaint =
189 {"unknown symbol type 0x%x", 0, 0};
190
191 static struct deprecated_complaint stab_unknown_complaint =
192 {"unknown stabs symbol %s", 0, 0};
193
194 static struct deprecated_complaint pdr_for_nonsymbol_complaint =
195 {"PDR for %s, but no symbol", 0, 0};
196
197 static struct deprecated_complaint pdr_static_symbol_complaint =
198 {"can't handle PDR for static proc at 0x%lx", 0, 0};
199
200 static struct deprecated_complaint bad_setjmp_pdr_complaint =
201 {"fixing bad setjmp PDR from libc", 0, 0};
202
203 static struct deprecated_complaint bad_fbitfield_complaint =
204 {"can't handle TIR fBitfield for %s", 0, 0};
205
206 static struct deprecated_complaint bad_continued_complaint =
207 {"illegal TIR continued for %s", 0, 0};
208
209 static struct deprecated_complaint bad_rfd_entry_complaint =
210 {"bad rfd entry for %s: file %d, index %d", 0, 0};
211
212 static struct deprecated_complaint unexpected_type_code_complaint =
213 {"unexpected type code for %s", 0, 0};
214
215 static struct deprecated_complaint unable_to_cross_ref_complaint =
216 {"unable to cross ref btTypedef for %s", 0, 0};
217
218 static struct deprecated_complaint bad_indirect_xref_complaint =
219 {"unable to cross ref btIndirect for %s", 0, 0};
220
221 static struct deprecated_complaint illegal_forward_tq0_complaint =
222 {"illegal tq0 in forward typedef for %s", 0, 0};
223
224 static struct deprecated_complaint illegal_forward_bt_complaint =
225 {"illegal bt %d in forward typedef for %s", 0, 0};
226
227 static struct deprecated_complaint bad_linetable_guess_complaint =
228 {"guessed size of linetable for %s incorrectly", 0, 0};
229
230 static struct deprecated_complaint bad_ext_ifd_complaint =
231 {"bad ifd for external symbol: %d (max %d)", 0, 0};
232
233 static struct deprecated_complaint bad_ext_iss_complaint =
234 {"bad iss for external symbol: %ld (max %ld)", 0, 0};
235
236 /* Macros and extra defs */
237
238 /* Puns: hard to find whether -g was used and how */
239
240 #define MIN_GLEVEL GLEVEL_0
241 #define compare_glevel(a,b) \
242 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
243 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
244 \f
245 /* Things that really are local to this module */
246
247 /* Remember what we deduced to be the source language of this psymtab. */
248
249 static enum language psymtab_language = language_unknown;
250
251 /* Current BFD. */
252
253 static bfd *cur_bfd;
254
255 /* How to parse debugging information for CUR_BFD. */
256
257 static const struct ecoff_debug_swap *debug_swap;
258
259 /* Pointers to debugging information for CUR_BFD. */
260
261 static struct ecoff_debug_info *debug_info;
262
263 /* Pointer to current file decriptor record, and its index */
264
265 static FDR *cur_fdr;
266 static int cur_fd;
267
268 /* Index of current symbol */
269
270 static int cur_sdx;
271
272 /* Note how much "debuggable" this image is. We would like
273 to see at least one FDR with full symbols */
274
275 static int max_gdbinfo;
276 static int max_glevel;
277
278 /* When examining .o files, report on undefined symbols */
279
280 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
281
282 /* Pseudo symbol to use when putting stabs into the symbol table. */
283
284 static char stabs_symbol[] = STABS_SYMBOL;
285
286 /* Types corresponding to mdebug format bt* basic types. */
287
288 static struct type *mdebug_type_void;
289 static struct type *mdebug_type_char;
290 static struct type *mdebug_type_short;
291 static struct type *mdebug_type_int_32;
292 #define mdebug_type_int mdebug_type_int_32
293 static struct type *mdebug_type_int_64;
294 static struct type *mdebug_type_long_32;
295 static struct type *mdebug_type_long_64;
296 static struct type *mdebug_type_long_long_64;
297 static struct type *mdebug_type_unsigned_char;
298 static struct type *mdebug_type_unsigned_short;
299 static struct type *mdebug_type_unsigned_int_32;
300 static struct type *mdebug_type_unsigned_int_64;
301 static struct type *mdebug_type_unsigned_long_32;
302 static struct type *mdebug_type_unsigned_long_64;
303 static struct type *mdebug_type_unsigned_long_long_64;
304 static struct type *mdebug_type_adr_32;
305 static struct type *mdebug_type_adr_64;
306 static struct type *mdebug_type_float;
307 static struct type *mdebug_type_double;
308 static struct type *mdebug_type_complex;
309 static struct type *mdebug_type_double_complex;
310 static struct type *mdebug_type_fixed_dec;
311 static struct type *mdebug_type_float_dec;
312 static struct type *mdebug_type_string;
313
314 /* Types for symbols from files compiled without debugging info. */
315
316 static struct type *nodebug_func_symbol_type;
317 static struct type *nodebug_var_symbol_type;
318
319 /* Nonzero if we have seen ecoff debugging info for a file. */
320
321 static int found_ecoff_debugging_info;
322
323 /* Forward declarations */
324
325 static int upgrade_type (int, struct type **, int, union aux_ext *,
326 int, char *);
327
328 static void parse_partial_symbols (struct objfile *);
329
330 static int has_opaque_xref (FDR *, SYMR *);
331
332 static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
333 char **, int, char *);
334
335 static struct symbol *new_symbol (char *);
336
337 static struct type *new_type (char *);
338
339 static struct block *new_block (int);
340
341 static struct symtab *new_symtab (char *, int, int, struct objfile *);
342
343 static struct linetable *new_linetable (int);
344
345 static struct blockvector *new_bvect (int);
346
347 static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
348 int, char *);
349
350 static struct symbol *mylookup_symbol (char *, struct block *, namespace_enum,
351 enum address_class);
352
353 static struct block *shrink_block (struct block *, struct symtab *);
354
355 static void sort_blocks (struct symtab *);
356
357 static struct partial_symtab *new_psymtab (char *, struct objfile *);
358
359 static void psymtab_to_symtab_1 (struct partial_symtab *, char *);
360
361 static void add_block (struct block *, struct symtab *);
362
363 static void add_symbol (struct symbol *, struct block *);
364
365 static int add_line (struct linetable *, int, CORE_ADDR, int);
366
367 static struct linetable *shrink_linetable (struct linetable *);
368
369 static void handle_psymbol_enumerators (struct objfile *, FDR *, int,
370 CORE_ADDR);
371
372 static char *mdebug_next_symbol_text (struct objfile *);
373 \f
374 /* Address bounds for the signal trampoline in inferior, if any */
375
376 CORE_ADDR sigtramp_address, sigtramp_end;
377
378 /* Allocate zeroed memory */
379
380 static void *
381 xzalloc (unsigned int size)
382 {
383 void *p = xmalloc (size);
384
385 memset (p, 0, size);
386 return p;
387 }
388
389 /* Exported procedure: Builds a symtab from the PST partial one.
390 Restores the environment in effect when PST was created, delegates
391 most of the work to an ancillary procedure, and sorts
392 and reorders the symtab list at the end */
393
394 static void
395 mdebug_psymtab_to_symtab (struct partial_symtab *pst)
396 {
397
398 if (!pst)
399 return;
400
401 if (info_verbose)
402 {
403 printf_filtered ("Reading in symbols for %s...", pst->filename);
404 gdb_flush (gdb_stdout);
405 }
406
407 next_symbol_text_func = mdebug_next_symbol_text;
408
409 psymtab_to_symtab_1 (pst, pst->filename);
410
411 /* Match with global symbols. This only needs to be done once,
412 after all of the symtabs and dependencies have been read in. */
413 scan_file_globals (pst->objfile);
414
415 if (info_verbose)
416 printf_filtered ("done.\n");
417 }
418 \f
419 /* File-level interface functions */
420
421 /* Find a file descriptor given its index RF relative to a file CF */
422
423 static FDR *
424 get_rfd (int cf, int rf)
425 {
426 FDR *fdrs;
427 register FDR *f;
428 RFDT rfd;
429
430 fdrs = debug_info->fdr;
431 f = fdrs + cf;
432 /* Object files do not have the RFD table, all refs are absolute */
433 if (f->rfdBase == 0)
434 return fdrs + rf;
435 (*debug_swap->swap_rfd_in) (cur_bfd,
436 ((char *) debug_info->external_rfd
437 + ((f->rfdBase + rf)
438 * debug_swap->external_rfd_size)),
439 &rfd);
440 return fdrs + rfd;
441 }
442
443 /* Return a safer print NAME for a file descriptor */
444
445 static char *
446 fdr_name (FDR *f)
447 {
448 if (f->rss == -1)
449 return "<stripped file>";
450 if (f->rss == 0)
451 return "<NFY>";
452 return debug_info->ss + f->issBase + f->rss;
453 }
454
455
456 /* Read in and parse the symtab of the file OBJFILE. Symbols from
457 different sections are relocated via the SECTION_OFFSETS. */
458
459 void
460 mdebug_build_psymtabs (struct objfile *objfile,
461 const struct ecoff_debug_swap *swap,
462 struct ecoff_debug_info *info)
463 {
464 cur_bfd = objfile->obfd;
465 debug_swap = swap;
466 debug_info = info;
467
468 stabsread_new_init ();
469 buildsym_new_init ();
470 free_header_files ();
471 init_header_files ();
472
473 /* Make sure all the FDR information is swapped in. */
474 if (info->fdr == (FDR *) NULL)
475 {
476 char *fdr_src;
477 char *fdr_end;
478 FDR *fdr_ptr;
479
480 info->fdr = (FDR *) obstack_alloc (&objfile->psymbol_obstack,
481 (info->symbolic_header.ifdMax
482 * sizeof (FDR)));
483 fdr_src = info->external_fdr;
484 fdr_end = (fdr_src
485 + info->symbolic_header.ifdMax * swap->external_fdr_size);
486 fdr_ptr = info->fdr;
487 for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
488 (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
489 }
490
491 parse_partial_symbols (objfile);
492
493 #if 0
494 /* Check to make sure file was compiled with -g. If not, warn the
495 user of this limitation. */
496 if (compare_glevel (max_glevel, GLEVEL_2) < 0)
497 {
498 if (max_gdbinfo == 0)
499 printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n",
500 objfile->name);
501 printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n");
502 gdb_flush (gdb_stdout);
503 }
504 #endif
505 }
506 \f
507 /* Local utilities */
508
509 /* Map of FDR indexes to partial symtabs */
510
511 struct pst_map
512 {
513 struct partial_symtab *pst; /* the psymtab proper */
514 long n_globals; /* exported globals (external symbols) */
515 long globals_offset; /* cumulative */
516 };
517
518
519 /* Utility stack, used to nest procedures and blocks properly.
520 It is a doubly linked list, to avoid too many alloc/free.
521 Since we might need it quite a few times it is NOT deallocated
522 after use. */
523
524 static struct parse_stack
525 {
526 struct parse_stack *next, *prev;
527 struct symtab *cur_st; /* Current symtab. */
528 struct block *cur_block; /* Block in it. */
529
530 /* What are we parsing. stFile, or stBlock are for files and
531 blocks. stProc or stStaticProc means we have seen the start of a
532 procedure, but not the start of the block within in. When we see
533 the start of that block, we change it to stNil, without pushing a
534 new block, i.e. stNil means both a procedure and a block. */
535
536 int blocktype;
537
538 int maxsyms; /* Max symbols in this block. */
539 struct type *cur_type; /* Type we parse fields for. */
540 int cur_field; /* Field number in cur_type. */
541 CORE_ADDR procadr; /* Start addres of this procedure */
542 int numargs; /* Its argument count */
543 }
544
545 *top_stack; /* Top stack ptr */
546
547
548 /* Enter a new lexical context */
549
550 static void
551 push_parse_stack (void)
552 {
553 struct parse_stack *new;
554
555 /* Reuse frames if possible */
556 if (top_stack && top_stack->prev)
557 new = top_stack->prev;
558 else
559 new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
560 /* Initialize new frame with previous content */
561 if (top_stack)
562 {
563 register struct parse_stack *prev = new->prev;
564
565 *new = *top_stack;
566 top_stack->prev = new;
567 new->prev = prev;
568 new->next = top_stack;
569 }
570 top_stack = new;
571 }
572
573 /* Exit a lexical context */
574
575 static void
576 pop_parse_stack (void)
577 {
578 if (!top_stack)
579 return;
580 if (top_stack->next)
581 top_stack = top_stack->next;
582 }
583
584
585 /* Cross-references might be to things we haven't looked at
586 yet, e.g. type references. To avoid too many type
587 duplications we keep a quick fixup table, an array
588 of lists of references indexed by file descriptor */
589
590 struct mdebug_pending
591 {
592 struct mdebug_pending *next; /* link */
593 char *s; /* the unswapped symbol */
594 struct type *t; /* its partial type descriptor */
595 };
596
597
598 /* The pending information is kept for an entire object file, and used
599 to be in the sym_private field. I took it out when I split
600 mdebugread from mipsread, because this might not be the only type
601 of symbols read from an object file. Instead, we allocate the
602 pending information table when we create the partial symbols, and
603 we store a pointer to the single table in each psymtab. */
604
605 static struct mdebug_pending **pending_list;
606
607 /* Check whether we already saw symbol SH in file FH */
608
609 static struct mdebug_pending *
610 is_pending_symbol (FDR *fh, char *sh)
611 {
612 int f_idx = fh - debug_info->fdr;
613 register struct mdebug_pending *p;
614
615 /* Linear search is ok, list is typically no more than 10 deep */
616 for (p = pending_list[f_idx]; p; p = p->next)
617 if (p->s == sh)
618 break;
619 return p;
620 }
621
622 /* Add a new symbol SH of type T */
623
624 static void
625 add_pending (FDR *fh, char *sh, struct type *t)
626 {
627 int f_idx = fh - debug_info->fdr;
628 struct mdebug_pending *p = is_pending_symbol (fh, sh);
629
630 /* Make sure we do not make duplicates */
631 if (!p)
632 {
633 p = ((struct mdebug_pending *)
634 obstack_alloc (&current_objfile->psymbol_obstack,
635 sizeof (struct mdebug_pending)));
636 p->s = sh;
637 p->t = t;
638 p->next = pending_list[f_idx];
639 pending_list[f_idx] = p;
640 }
641 }
642 \f
643
644 /* Parsing Routines proper. */
645
646 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
647 For blocks, procedures and types we open a new lexical context.
648 This is basically just a big switch on the symbol's type. Argument
649 AX is the base pointer of aux symbols for this file (fh->iauxBase).
650 EXT_SH points to the unswapped symbol, which is needed for struct,
651 union, etc., types; it is NULL for an EXTR. BIGEND says whether
652 aux symbols are big-endian or little-endian. Return count of
653 SYMR's handled (normally one). */
654
655 static int
656 parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
657 struct section_offsets *section_offsets, struct objfile *objfile)
658 {
659 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
660 void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
661 char *name;
662 struct symbol *s;
663 struct block *b;
664 struct mdebug_pending *pend;
665 struct type *t;
666 struct field *f;
667 int count = 1;
668 enum address_class class;
669 TIR tir;
670 long svalue = sh->value;
671 int bitsize;
672
673 if (ext_sh == (char *) NULL)
674 name = debug_info->ssext + sh->iss;
675 else
676 name = debug_info->ss + cur_fdr->issBase + sh->iss;
677
678 switch (sh->sc)
679 {
680 case scText:
681 case scRConst:
682 /* Do not relocate relative values.
683 The value of a stEnd symbol is the displacement from the
684 corresponding start symbol value.
685 The value of a stBlock symbol is the displacement from the
686 procedure address. */
687 if (sh->st != stEnd && sh->st != stBlock)
688 sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
689 break;
690 case scData:
691 case scSData:
692 case scRData:
693 case scPData:
694 case scXData:
695 sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
696 break;
697 case scBss:
698 case scSBss:
699 sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
700 break;
701 }
702
703 switch (sh->st)
704 {
705 case stNil:
706 break;
707
708 case stGlobal: /* external symbol, goes into global block */
709 class = LOC_STATIC;
710 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
711 GLOBAL_BLOCK);
712 s = new_symbol (name);
713 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
714 goto data;
715
716 case stStatic: /* static data, goes into current block. */
717 class = LOC_STATIC;
718 b = top_stack->cur_block;
719 s = new_symbol (name);
720 if (SC_IS_COMMON (sh->sc))
721 {
722 /* It is a FORTRAN common block. At least for SGI Fortran the
723 address is not in the symbol; we need to fix it later in
724 scan_file_globals. */
725 int bucket = hashname (SYMBOL_NAME (s));
726 SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
727 global_sym_chain[bucket] = s;
728 }
729 else
730 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
731 goto data;
732
733 case stLocal: /* local variable, goes into current block */
734 if (sh->sc == scRegister)
735 {
736 class = LOC_REGISTER;
737 svalue = ECOFF_REG_TO_REGNUM (svalue);
738 }
739 else
740 class = LOC_LOCAL;
741 b = top_stack->cur_block;
742 s = new_symbol (name);
743 SYMBOL_VALUE (s) = svalue;
744
745 data: /* Common code for symbols describing data */
746 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
747 SYMBOL_CLASS (s) = class;
748 add_symbol (s, b);
749
750 /* Type could be missing if file is compiled without debugging info. */
751 if (SC_IS_UNDEF (sh->sc)
752 || sh->sc == scNil || sh->index == indexNil)
753 SYMBOL_TYPE (s) = nodebug_var_symbol_type;
754 else
755 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
756 /* Value of a data symbol is its memory address */
757 break;
758
759 case stParam: /* arg to procedure, goes into current block */
760 max_gdbinfo++;
761 found_ecoff_debugging_info = 1;
762 top_stack->numargs++;
763
764 /* Special GNU C++ name. */
765 if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
766 name = "this"; /* FIXME, not alloc'd in obstack */
767 s = new_symbol (name);
768
769 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
770 switch (sh->sc)
771 {
772 case scRegister:
773 /* Pass by value in register. */
774 SYMBOL_CLASS (s) = LOC_REGPARM;
775 svalue = ECOFF_REG_TO_REGNUM (svalue);
776 break;
777 case scVar:
778 /* Pass by reference on stack. */
779 SYMBOL_CLASS (s) = LOC_REF_ARG;
780 break;
781 case scVarRegister:
782 /* Pass by reference in register. */
783 SYMBOL_CLASS (s) = LOC_REGPARM_ADDR;
784 svalue = ECOFF_REG_TO_REGNUM (svalue);
785 break;
786 default:
787 /* Pass by value on stack. */
788 SYMBOL_CLASS (s) = LOC_ARG;
789 break;
790 }
791 SYMBOL_VALUE (s) = svalue;
792 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
793 add_symbol (s, top_stack->cur_block);
794 break;
795
796 case stLabel: /* label, goes into current block */
797 s = new_symbol (name);
798 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; /* so that it can be used */
799 SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */
800 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
801 SYMBOL_TYPE (s) = mdebug_type_int;
802 add_symbol (s, top_stack->cur_block);
803 break;
804
805 case stProc: /* Procedure, usually goes into global block */
806 case stStaticProc: /* Static procedure, goes into current block */
807 s = new_symbol (name);
808 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
809 SYMBOL_CLASS (s) = LOC_BLOCK;
810 /* Type of the return value */
811 if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
812 t = mdebug_type_int;
813 else
814 {
815 t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
816 if (STREQ (name, "malloc") && TYPE_CODE (t) == TYPE_CODE_VOID)
817 {
818 /* I don't know why, but, at least under Alpha GNU/Linux,
819 when linking against a malloc without debugging
820 symbols, its read as a function returning void---this
821 is bad because it means we cannot call functions with
822 string arguments interactively; i.e., "call
823 printf("howdy\n")" would fail with the error message
824 "program has no memory available". To avoid this, we
825 patch up the type and make it void*
826 instead. (davidm@azstarnet.com)
827 */
828 t = make_pointer_type (t, NULL);
829 }
830 }
831 b = top_stack->cur_block;
832 if (sh->st == stProc)
833 {
834 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
835 /* The next test should normally be true, but provides a
836 hook for nested functions (which we don't want to make
837 global). */
838 if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
839 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
840 /* Irix 5 sometimes has duplicate names for the same
841 function. We want to add such names up at the global
842 level, not as a nested function. */
843 else if (sh->value == top_stack->procadr)
844 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
845 }
846 add_symbol (s, b);
847
848 /* Make a type for the procedure itself */
849 SYMBOL_TYPE (s) = lookup_function_type (t);
850
851 /* Create and enter a new lexical context */
852 b = new_block (top_stack->maxsyms);
853 SYMBOL_BLOCK_VALUE (s) = b;
854 BLOCK_FUNCTION (b) = s;
855 BLOCK_START (b) = BLOCK_END (b) = sh->value;
856 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
857 add_block (b, top_stack->cur_st);
858
859 /* Not if we only have partial info */
860 if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
861 break;
862
863 push_parse_stack ();
864 top_stack->cur_block = b;
865 top_stack->blocktype = sh->st;
866 top_stack->cur_type = SYMBOL_TYPE (s);
867 top_stack->cur_field = -1;
868 top_stack->procadr = sh->value;
869 top_stack->numargs = 0;
870 break;
871
872 /* Beginning of code for structure, union, and enum definitions.
873 They all share a common set of local variables, defined here. */
874 {
875 enum type_code type_code;
876 char *ext_tsym;
877 int nfields;
878 long max_value;
879 struct field *f;
880
881 case stStruct: /* Start a block defining a struct type */
882 type_code = TYPE_CODE_STRUCT;
883 goto structured_common;
884
885 case stUnion: /* Start a block defining a union type */
886 type_code = TYPE_CODE_UNION;
887 goto structured_common;
888
889 case stEnum: /* Start a block defining an enum type */
890 type_code = TYPE_CODE_ENUM;
891 goto structured_common;
892
893 case stBlock: /* Either a lexical block, or some type */
894 if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
895 goto case_stBlock_code; /* Lexical block */
896
897 type_code = TYPE_CODE_UNDEF; /* We have a type. */
898
899 /* Common code for handling struct, union, enum, and/or as-yet-
900 unknown-type blocks of info about structured data. `type_code'
901 has been set to the proper TYPE_CODE, if we know it. */
902 structured_common:
903 found_ecoff_debugging_info = 1;
904 push_parse_stack ();
905 top_stack->blocktype = stBlock;
906
907 /* First count the number of fields and the highest value. */
908 nfields = 0;
909 max_value = 0;
910 for (ext_tsym = ext_sh + external_sym_size;
911 ;
912 ext_tsym += external_sym_size)
913 {
914 SYMR tsym;
915
916 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
917
918 switch (tsym.st)
919 {
920 case stEnd:
921 goto end_of_fields;
922
923 case stMember:
924 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
925 {
926 /* If the type of the member is Nil (or Void),
927 without qualifiers, assume the tag is an
928 enumeration.
929 Alpha cc -migrate enums are recognized by a zero
930 index and a zero symbol value.
931 DU 4.0 cc enums are recognized by a member type of
932 btEnum without qualifiers and a zero symbol value. */
933 if (tsym.index == indexNil
934 || (tsym.index == 0 && sh->value == 0))
935 type_code = TYPE_CODE_ENUM;
936 else
937 {
938 (*debug_swap->swap_tir_in) (bigend,
939 &ax[tsym.index].a_ti,
940 &tir);
941 if ((tir.bt == btNil || tir.bt == btVoid
942 || (tir.bt == btEnum && sh->value == 0))
943 && tir.tq0 == tqNil)
944 type_code = TYPE_CODE_ENUM;
945 }
946 }
947 nfields++;
948 if (tsym.value > max_value)
949 max_value = tsym.value;
950 break;
951
952 case stBlock:
953 case stUnion:
954 case stEnum:
955 case stStruct:
956 {
957 #if 0
958 /* This is a no-op; is it trying to tell us something
959 we should be checking? */
960 if (tsym.sc == scVariant); /*UNIMPLEMENTED */
961 #endif
962 if (tsym.index != 0)
963 {
964 /* This is something like a struct within a
965 struct. Skip over the fields of the inner
966 struct. The -1 is because the for loop will
967 increment ext_tsym. */
968 ext_tsym = ((char *) debug_info->external_sym
969 + ((cur_fdr->isymBase + tsym.index - 1)
970 * external_sym_size));
971 }
972 }
973 break;
974
975 case stTypedef:
976 /* mips cc puts out a typedef for struct x if it is not yet
977 defined when it encounters
978 struct y { struct x *xp; };
979 Just ignore it. */
980 break;
981
982 case stIndirect:
983 /* Irix5 cc puts out a stIndirect for struct x if it is not
984 yet defined when it encounters
985 struct y { struct x *xp; };
986 Just ignore it. */
987 break;
988
989 default:
990 complain (&block_member_complaint, tsym.st);
991 }
992 }
993 end_of_fields:;
994
995 /* In an stBlock, there is no way to distinguish structs,
996 unions, and enums at this point. This is a bug in the
997 original design (that has been fixed with the recent
998 addition of the stStruct, stUnion, and stEnum symbol
999 types.) The way you can tell is if/when you see a variable
1000 or field of that type. In that case the variable's type
1001 (in the AUX table) says if the type is struct, union, or
1002 enum, and points back to the stBlock here. So you can
1003 patch the tag kind up later - but only if there actually is
1004 a variable or field of that type.
1005
1006 So until we know for sure, we will guess at this point.
1007 The heuristic is:
1008 If the first member has index==indexNil or a void type,
1009 assume we have an enumeration.
1010 Otherwise, if there is more than one member, and all
1011 the members have offset 0, assume we have a union.
1012 Otherwise, assume we have a struct.
1013
1014 The heuristic could guess wrong in the case of of an
1015 enumeration with no members or a union with one (or zero)
1016 members, or when all except the last field of a struct have
1017 width zero. These are uncommon and/or illegal situations,
1018 and in any case guessing wrong probably doesn't matter
1019 much.
1020
1021 But if we later do find out we were wrong, we fixup the tag
1022 kind. Members of an enumeration must be handled
1023 differently from struct/union fields, and that is harder to
1024 patch up, but luckily we shouldn't need to. (If there are
1025 any enumeration members, we can tell for sure it's an enum
1026 here.) */
1027
1028 if (type_code == TYPE_CODE_UNDEF)
1029 {
1030 if (nfields > 1 && max_value == 0)
1031 type_code = TYPE_CODE_UNION;
1032 else
1033 type_code = TYPE_CODE_STRUCT;
1034 }
1035
1036 /* Create a new type or use the pending type. */
1037 pend = is_pending_symbol (cur_fdr, ext_sh);
1038 if (pend == (struct mdebug_pending *) NULL)
1039 {
1040 t = new_type (NULL);
1041 add_pending (cur_fdr, ext_sh, t);
1042 }
1043 else
1044 t = pend->t;
1045
1046 /* Do not set the tag name if it is a compiler generated tag name
1047 (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
1048 Alpha cc puts out an sh->iss of zero for those. */
1049 if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
1050 TYPE_TAG_NAME (t) = NULL;
1051 else
1052 TYPE_TAG_NAME (t) = obconcat (&current_objfile->symbol_obstack,
1053 "", "", name);
1054
1055 TYPE_CODE (t) = type_code;
1056 TYPE_LENGTH (t) = sh->value;
1057 TYPE_NFIELDS (t) = nfields;
1058 TYPE_FIELDS (t) = f = ((struct field *)
1059 TYPE_ALLOC (t,
1060 nfields * sizeof (struct field)));
1061
1062 if (type_code == TYPE_CODE_ENUM)
1063 {
1064 int unsigned_enum = 1;
1065
1066 /* This is a non-empty enum. */
1067
1068 /* DEC c89 has the number of enumerators in the sh.value field,
1069 not the type length, so we have to compensate for that
1070 incompatibility quirk.
1071 This might do the wrong thing for an enum with one or two
1072 enumerators and gcc -gcoff -fshort-enums, but these cases
1073 are hopefully rare enough.
1074 Alpha cc -migrate has a sh.value field of zero, we adjust
1075 that too. */
1076 if (TYPE_LENGTH (t) == TYPE_NFIELDS (t)
1077 || TYPE_LENGTH (t) == 0)
1078 TYPE_LENGTH (t) = TARGET_INT_BIT / HOST_CHAR_BIT;
1079 for (ext_tsym = ext_sh + external_sym_size;
1080 ;
1081 ext_tsym += external_sym_size)
1082 {
1083 SYMR tsym;
1084 struct symbol *enum_sym;
1085
1086 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
1087
1088 if (tsym.st != stMember)
1089 break;
1090
1091 FIELD_BITPOS (*f) = tsym.value;
1092 FIELD_TYPE (*f) = t;
1093 FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
1094 FIELD_BITSIZE (*f) = 0;
1095 FIELD_STATIC_KIND (*f) = 0;
1096
1097 enum_sym = ((struct symbol *)
1098 obstack_alloc (&current_objfile->symbol_obstack,
1099 sizeof (struct symbol)));
1100 memset (enum_sym, 0, sizeof (struct symbol));
1101 SYMBOL_NAME (enum_sym) =
1102 obsavestring (f->name, strlen (f->name),
1103 &current_objfile->symbol_obstack);
1104 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1105 SYMBOL_TYPE (enum_sym) = t;
1106 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1107 SYMBOL_VALUE (enum_sym) = tsym.value;
1108 if (SYMBOL_VALUE (enum_sym) < 0)
1109 unsigned_enum = 0;
1110 add_symbol (enum_sym, top_stack->cur_block);
1111
1112 /* Skip the stMembers that we've handled. */
1113 count++;
1114 f++;
1115 }
1116 if (unsigned_enum)
1117 TYPE_FLAGS (t) |= TYPE_FLAG_UNSIGNED;
1118 }
1119 /* make this the current type */
1120 top_stack->cur_type = t;
1121 top_stack->cur_field = 0;
1122
1123 /* Do not create a symbol for alpha cc unnamed structs. */
1124 if (sh->iss == 0)
1125 break;
1126
1127 /* gcc puts out an empty struct for an opaque struct definitions,
1128 do not create a symbol for it either. */
1129 if (TYPE_NFIELDS (t) == 0)
1130 {
1131 TYPE_FLAGS (t) |= TYPE_FLAG_STUB;
1132 break;
1133 }
1134
1135 s = new_symbol (name);
1136 SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE;
1137 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1138 SYMBOL_VALUE (s) = 0;
1139 SYMBOL_TYPE (s) = t;
1140 add_symbol (s, top_stack->cur_block);
1141 break;
1142
1143 /* End of local variables shared by struct, union, enum, and
1144 block (as yet unknown struct/union/enum) processing. */
1145 }
1146
1147 case_stBlock_code:
1148 found_ecoff_debugging_info = 1;
1149 /* beginnning of (code) block. Value of symbol
1150 is the displacement from procedure start */
1151 push_parse_stack ();
1152
1153 /* Do not start a new block if this is the outermost block of a
1154 procedure. This allows the LOC_BLOCK symbol to point to the
1155 block with the local variables, so funcname::var works. */
1156 if (top_stack->blocktype == stProc
1157 || top_stack->blocktype == stStaticProc)
1158 {
1159 top_stack->blocktype = stNil;
1160 break;
1161 }
1162
1163 top_stack->blocktype = stBlock;
1164 b = new_block (top_stack->maxsyms);
1165 BLOCK_START (b) = sh->value + top_stack->procadr;
1166 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1167 top_stack->cur_block = b;
1168 add_block (b, top_stack->cur_st);
1169 break;
1170
1171 case stEnd: /* end (of anything) */
1172 if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
1173 {
1174 /* Finished with type */
1175 top_stack->cur_type = 0;
1176 }
1177 else if (sh->sc == scText &&
1178 (top_stack->blocktype == stProc ||
1179 top_stack->blocktype == stStaticProc))
1180 {
1181 /* Finished with procedure */
1182 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
1183 struct mips_extra_func_info *e;
1184 struct block *b;
1185 struct type *ftype = top_stack->cur_type;
1186 int i;
1187
1188 BLOCK_END (top_stack->cur_block) += sh->value; /* size */
1189
1190 /* Make up special symbol to contain procedure specific info */
1191 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
1192 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
1193 SYMBOL_CLASS (s) = LOC_CONST;
1194 SYMBOL_TYPE (s) = mdebug_type_void;
1195 e = ((struct mips_extra_func_info *)
1196 obstack_alloc (&current_objfile->symbol_obstack,
1197 sizeof (struct mips_extra_func_info)));
1198 memset (e, 0, sizeof (struct mips_extra_func_info));
1199 SYMBOL_VALUE (s) = (long) e;
1200 e->numargs = top_stack->numargs;
1201 e->pdr.framereg = -1;
1202 add_symbol (s, top_stack->cur_block);
1203
1204 /* Reallocate symbols, saving memory */
1205 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
1206
1207 /* f77 emits proc-level with address bounds==[0,0],
1208 So look for such child blocks, and patch them. */
1209 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
1210 {
1211 struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1212 if (BLOCK_SUPERBLOCK (b_bad) == b
1213 && BLOCK_START (b_bad) == top_stack->procadr
1214 && BLOCK_END (b_bad) == top_stack->procadr)
1215 {
1216 BLOCK_START (b_bad) = BLOCK_START (b);
1217 BLOCK_END (b_bad) = BLOCK_END (b);
1218 }
1219 }
1220
1221 if (TYPE_NFIELDS (ftype) <= 0)
1222 {
1223 /* No parameter type information is recorded with the function's
1224 type. Set that from the type of the parameter symbols. */
1225 int nparams = top_stack->numargs;
1226 int iparams;
1227 struct symbol *sym;
1228
1229 if (nparams > 0)
1230 {
1231 TYPE_NFIELDS (ftype) = nparams;
1232 TYPE_FIELDS (ftype) = (struct field *)
1233 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
1234
1235 for (i = iparams = 0; iparams < nparams; i++)
1236 {
1237 sym = BLOCK_SYM (b, i);
1238 switch (SYMBOL_CLASS (sym))
1239 {
1240 case LOC_ARG:
1241 case LOC_REF_ARG:
1242 case LOC_REGPARM:
1243 case LOC_REGPARM_ADDR:
1244 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
1245 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
1246 iparams++;
1247 break;
1248 default:
1249 break;
1250 }
1251 }
1252 }
1253 }
1254 }
1255 else if (sh->sc == scText && top_stack->blocktype == stBlock)
1256 {
1257 /* End of (code) block. The value of the symbol is the
1258 displacement from the procedure`s start address of the
1259 end of this block. */
1260 BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
1261 shrink_block (top_stack->cur_block, top_stack->cur_st);
1262 }
1263 else if (sh->sc == scText && top_stack->blocktype == stNil)
1264 {
1265 /* End of outermost block. Pop parse stack and ignore. The
1266 following stEnd of stProc will take care of the block. */
1267 ;
1268 }
1269 else if (sh->sc == scText && top_stack->blocktype == stFile)
1270 {
1271 /* End of file. Pop parse stack and ignore. Higher
1272 level code deals with this. */
1273 ;
1274 }
1275 else
1276 complain (&stEnd_complaint, sh->sc);
1277
1278 pop_parse_stack (); /* restore previous lexical context */
1279 break;
1280
1281 case stMember: /* member of struct or union */
1282 f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
1283 FIELD_NAME (*f) = name;
1284 FIELD_BITPOS (*f) = sh->value;
1285 bitsize = 0;
1286 FIELD_TYPE (*f) = parse_type (cur_fd, ax, sh->index, &bitsize, bigend, name);
1287 FIELD_BITSIZE (*f) = bitsize;
1288 FIELD_STATIC_KIND (*f) = 0;
1289 break;
1290
1291 case stIndirect: /* forward declaration on Irix5 */
1292 /* Forward declarations from Irix5 cc are handled by cross_ref,
1293 skip them. */
1294 break;
1295
1296 case stTypedef: /* type definition */
1297 found_ecoff_debugging_info = 1;
1298
1299 /* Typedefs for forward declarations and opaque structs from alpha cc
1300 are handled by cross_ref, skip them. */
1301 if (sh->iss == 0)
1302 break;
1303
1304 /* Parse the type or use the pending type. */
1305 pend = is_pending_symbol (cur_fdr, ext_sh);
1306 if (pend == (struct mdebug_pending *) NULL)
1307 {
1308 t = parse_type (cur_fd, ax, sh->index, (int *) NULL, bigend, name);
1309 add_pending (cur_fdr, ext_sh, t);
1310 }
1311 else
1312 t = pend->t;
1313
1314 /* mips cc puts out a typedef with the name of the struct for forward
1315 declarations. These should not go into the symbol table and
1316 TYPE_NAME should not be set for them.
1317 They can't be distinguished from an intentional typedef to
1318 the same name however:
1319 x.h:
1320 struct x { int ix; int jx; };
1321 struct xx;
1322 x.c:
1323 typedef struct x x;
1324 struct xx {int ixx; int jxx; };
1325 generates a cross referencing stTypedef for x and xx.
1326 The user visible effect of this is that the type of a pointer
1327 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1328 The problem is fixed with alpha cc and Irix5 cc. */
1329
1330 /* However if the typedef cross references to an opaque aggregate, it
1331 is safe to omit it from the symbol table. */
1332
1333 if (has_opaque_xref (cur_fdr, sh))
1334 break;
1335 s = new_symbol (name);
1336 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1337 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1338 SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
1339 SYMBOL_TYPE (s) = t;
1340 add_symbol (s, top_stack->cur_block);
1341
1342 /* Incomplete definitions of structs should not get a name. */
1343 if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL
1344 && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
1345 || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT
1346 && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION)))
1347 {
1348 if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR
1349 || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC)
1350 {
1351 /* If we are giving a name to a type such as "pointer to
1352 foo" or "function returning foo", we better not set
1353 the TYPE_NAME. If the program contains "typedef char
1354 *caddr_t;", we don't want all variables of type char
1355 * to print as caddr_t. This is not just a
1356 consequence of GDB's type management; CC and GCC (at
1357 least through version 2.4) both output variables of
1358 either type char * or caddr_t with the type
1359 refering to the stTypedef symbol for caddr_t. If a future
1360 compiler cleans this up it GDB is not ready for it
1361 yet, but if it becomes ready we somehow need to
1362 disable this check (without breaking the PCC/GCC2.4
1363 case).
1364
1365 Sigh.
1366
1367 Fortunately, this check seems not to be necessary
1368 for anything except pointers or functions. */
1369 }
1370 else
1371 TYPE_NAME (SYMBOL_TYPE (s)) = SYMBOL_NAME (s);
1372 }
1373 break;
1374
1375 case stFile: /* file name */
1376 push_parse_stack ();
1377 top_stack->blocktype = sh->st;
1378 break;
1379
1380 /* I`ve never seen these for C */
1381 case stRegReloc:
1382 break; /* register relocation */
1383 case stForward:
1384 break; /* forwarding address */
1385 case stConstant:
1386 break; /* constant */
1387 default:
1388 complain (&unknown_mdebug_symtype_complaint, sh->st);
1389 break;
1390 }
1391
1392 return count;
1393 }
1394
1395 /* Parse the type information provided in the raw AX entries for
1396 the symbol SH. Return the bitfield size in BS, in case.
1397 We must byte-swap the AX entries before we use them; BIGEND says whether
1398 they are big-endian or little-endian (from fh->fBigendian). */
1399
1400 static struct type *
1401 parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
1402 int bigend, char *sym_name)
1403 {
1404 /* Null entries in this map are treated specially */
1405 static struct type **map_bt[] =
1406 {
1407 &mdebug_type_void, /* btNil */
1408 &mdebug_type_adr_32, /* btAdr */
1409 &mdebug_type_char, /* btChar */
1410 &mdebug_type_unsigned_char, /* btUChar */
1411 &mdebug_type_short, /* btShort */
1412 &mdebug_type_unsigned_short, /* btUShort */
1413 &mdebug_type_int_32, /* btInt */
1414 &mdebug_type_unsigned_int_32, /* btUInt */
1415 &mdebug_type_long_32, /* btLong */
1416 &mdebug_type_unsigned_long_32, /* btULong */
1417 &mdebug_type_float, /* btFloat */
1418 &mdebug_type_double, /* btDouble */
1419 0, /* btStruct */
1420 0, /* btUnion */
1421 0, /* btEnum */
1422 0, /* btTypedef */
1423 0, /* btRange */
1424 0, /* btSet */
1425 &mdebug_type_complex, /* btComplex */
1426 &mdebug_type_double_complex, /* btDComplex */
1427 0, /* btIndirect */
1428 &mdebug_type_fixed_dec, /* btFixedDec */
1429 &mdebug_type_float_dec, /* btFloatDec */
1430 &mdebug_type_string, /* btString */
1431 0, /* btBit */
1432 0, /* btPicture */
1433 &mdebug_type_void, /* btVoid */
1434 0, /* DEC C++: Pointer to member */
1435 0, /* DEC C++: Virtual function table */
1436 0, /* DEC C++: Class (Record) */
1437 &mdebug_type_long_64, /* btLong64 */
1438 &mdebug_type_unsigned_long_64, /* btULong64 */
1439 &mdebug_type_long_long_64, /* btLongLong64 */
1440 &mdebug_type_unsigned_long_long_64, /* btULongLong64 */
1441 &mdebug_type_adr_64, /* btAdr64 */
1442 &mdebug_type_int_64, /* btInt64 */
1443 &mdebug_type_unsigned_int_64, /* btUInt64 */
1444 };
1445
1446 TIR t[1];
1447 struct type *tp = 0;
1448 enum type_code type_code = TYPE_CODE_UNDEF;
1449
1450 /* Handle undefined types, they have indexNil. */
1451 if (aux_index == indexNil)
1452 return mdebug_type_int;
1453
1454 /* Handle corrupt aux indices. */
1455 if (aux_index >= (debug_info->fdr + fd)->caux)
1456 {
1457 complain (&index_complaint, sym_name);
1458 return mdebug_type_int;
1459 }
1460 ax += aux_index;
1461
1462 /* Use aux as a type information record, map its basic type. */
1463 (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1464 if (t->bt >= (sizeof (map_bt) / sizeof (*map_bt)))
1465 {
1466 complain (&basic_type_complaint, t->bt, sym_name);
1467 return mdebug_type_int;
1468 }
1469 if (map_bt[t->bt])
1470 {
1471 tp = *map_bt[t->bt];
1472 }
1473 else
1474 {
1475 tp = NULL;
1476 /* Cannot use builtin types -- build our own */
1477 switch (t->bt)
1478 {
1479 case btStruct:
1480 type_code = TYPE_CODE_STRUCT;
1481 break;
1482 case btUnion:
1483 type_code = TYPE_CODE_UNION;
1484 break;
1485 case btEnum:
1486 type_code = TYPE_CODE_ENUM;
1487 break;
1488 case btRange:
1489 type_code = TYPE_CODE_RANGE;
1490 break;
1491 case btSet:
1492 type_code = TYPE_CODE_SET;
1493 break;
1494 case btIndirect:
1495 /* alpha cc -migrate uses this for typedefs. The true type will
1496 be obtained by crossreferencing below. */
1497 type_code = TYPE_CODE_ERROR;
1498 break;
1499 case btTypedef:
1500 /* alpha cc uses this for typedefs. The true type will be
1501 obtained by crossreferencing below. */
1502 type_code = TYPE_CODE_ERROR;
1503 break;
1504 default:
1505 complain (&basic_type_complaint, t->bt, sym_name);
1506 return mdebug_type_int;
1507 }
1508 }
1509
1510 /* Move on to next aux */
1511 ax++;
1512
1513 if (t->fBitfield)
1514 {
1515 int width = AUX_GET_WIDTH (bigend, ax);
1516
1517 /* Inhibit core dumps with some cfront generated objects that
1518 corrupt the TIR. */
1519 if (bs == (int *) NULL)
1520 {
1521 /* Alpha cc -migrate encodes char and unsigned char types
1522 as short and unsigned short types with a field width of 8.
1523 Enum types also have a field width which we ignore for now. */
1524 if (t->bt == btShort && width == 8)
1525 tp = mdebug_type_char;
1526 else if (t->bt == btUShort && width == 8)
1527 tp = mdebug_type_unsigned_char;
1528 else if (t->bt == btEnum)
1529 ;
1530 else
1531 complain (&bad_fbitfield_complaint, sym_name);
1532 }
1533 else
1534 *bs = width;
1535 ax++;
1536 }
1537
1538 /* A btIndirect entry cross references to an aux entry containing
1539 the type. */
1540 if (t->bt == btIndirect)
1541 {
1542 RNDXR rn[1];
1543 int rf;
1544 FDR *xref_fh;
1545 int xref_fd;
1546
1547 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
1548 ax++;
1549 if (rn->rfd == 0xfff)
1550 {
1551 rf = AUX_GET_ISYM (bigend, ax);
1552 ax++;
1553 }
1554 else
1555 rf = rn->rfd;
1556
1557 if (rf == -1)
1558 {
1559 complain (&bad_indirect_xref_complaint, sym_name);
1560 return mdebug_type_int;
1561 }
1562 xref_fh = get_rfd (fd, rf);
1563 xref_fd = xref_fh - debug_info->fdr;
1564 tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
1565 rn->index, (int *) NULL, xref_fh->fBigendian, sym_name);
1566 }
1567
1568 /* All these types really point to some (common) MIPS type
1569 definition, and only the type-qualifiers fully identify
1570 them. We'll make the same effort at sharing. */
1571 if (t->bt == btStruct ||
1572 t->bt == btUnion ||
1573 t->bt == btEnum ||
1574
1575 /* btSet (I think) implies that the name is a tag name, not a typedef
1576 name. This apparently is a MIPS extension for C sets. */
1577 t->bt == btSet)
1578 {
1579 char *name;
1580
1581 /* Try to cross reference this type, build new type on failure. */
1582 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1583 if (tp == (struct type *) NULL)
1584 tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
1585
1586 /* DEC c89 produces cross references to qualified aggregate types,
1587 dereference them. */
1588 while (TYPE_CODE (tp) == TYPE_CODE_PTR
1589 || TYPE_CODE (tp) == TYPE_CODE_ARRAY)
1590 tp = TYPE_TARGET_TYPE (tp);
1591
1592 /* Make sure that TYPE_CODE(tp) has an expected type code.
1593 Any type may be returned from cross_ref if file indirect entries
1594 are corrupted. */
1595 if (TYPE_CODE (tp) != TYPE_CODE_STRUCT
1596 && TYPE_CODE (tp) != TYPE_CODE_UNION
1597 && TYPE_CODE (tp) != TYPE_CODE_ENUM)
1598 {
1599 complain (&unexpected_type_code_complaint, sym_name);
1600 }
1601 else
1602 {
1603
1604 /* Usually, TYPE_CODE(tp) is already type_code. The main
1605 exception is if we guessed wrong re struct/union/enum.
1606 But for struct vs. union a wrong guess is harmless, so
1607 don't complain(). */
1608 if ((TYPE_CODE (tp) == TYPE_CODE_ENUM
1609 && type_code != TYPE_CODE_ENUM)
1610 || (TYPE_CODE (tp) != TYPE_CODE_ENUM
1611 && type_code == TYPE_CODE_ENUM))
1612 {
1613 complain (&bad_tag_guess_complaint, sym_name);
1614 }
1615
1616 if (TYPE_CODE (tp) != type_code)
1617 {
1618 TYPE_CODE (tp) = type_code;
1619 }
1620
1621 /* Do not set the tag name if it is a compiler generated tag name
1622 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1623 if (name[0] == '.' || name[0] == '\0')
1624 TYPE_TAG_NAME (tp) = NULL;
1625 else if (TYPE_TAG_NAME (tp) == NULL
1626 || !STREQ (TYPE_TAG_NAME (tp), name))
1627 TYPE_TAG_NAME (tp) = obsavestring (name, strlen (name),
1628 &current_objfile->type_obstack);
1629 }
1630 }
1631
1632 /* All these types really point to some (common) MIPS type
1633 definition, and only the type-qualifiers fully identify
1634 them. We'll make the same effort at sharing.
1635 FIXME: We are not doing any guessing on range types. */
1636 if (t->bt == btRange)
1637 {
1638 char *name;
1639
1640 /* Try to cross reference this type, build new type on failure. */
1641 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1642 if (tp == (struct type *) NULL)
1643 tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
1644
1645 /* Make sure that TYPE_CODE(tp) has an expected type code.
1646 Any type may be returned from cross_ref if file indirect entries
1647 are corrupted. */
1648 if (TYPE_CODE (tp) != TYPE_CODE_RANGE)
1649 {
1650 complain (&unexpected_type_code_complaint, sym_name);
1651 }
1652 else
1653 {
1654 /* Usually, TYPE_CODE(tp) is already type_code. The main
1655 exception is if we guessed wrong re struct/union/enum. */
1656 if (TYPE_CODE (tp) != type_code)
1657 {
1658 complain (&bad_tag_guess_complaint, sym_name);
1659 TYPE_CODE (tp) = type_code;
1660 }
1661 if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name))
1662 TYPE_NAME (tp) = obsavestring (name, strlen (name),
1663 &current_objfile->type_obstack);
1664 }
1665 }
1666 if (t->bt == btTypedef)
1667 {
1668 char *name;
1669
1670 /* Try to cross reference this type, it should succeed. */
1671 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1672 if (tp == (struct type *) NULL)
1673 {
1674 complain (&unable_to_cross_ref_complaint, sym_name);
1675 tp = mdebug_type_int;
1676 }
1677 }
1678
1679 /* Deal with range types */
1680 if (t->bt == btRange)
1681 {
1682 TYPE_NFIELDS (tp) = 2;
1683 TYPE_FIELDS (tp) = ((struct field *)
1684 TYPE_ALLOC (tp, 2 * sizeof (struct field)));
1685 TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1686 &current_objfile->type_obstack);
1687 TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1688 ax++;
1689 TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1690 &current_objfile->type_obstack);
1691 TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1692 ax++;
1693 }
1694
1695 /* Parse all the type qualifiers now. If there are more
1696 than 6 the game will continue in the next aux */
1697
1698 while (1)
1699 {
1700 #define PARSE_TQ(tq) \
1701 if (t->tq != tqNil) \
1702 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1703 else \
1704 break;
1705
1706 PARSE_TQ (tq0);
1707 PARSE_TQ (tq1);
1708 PARSE_TQ (tq2);
1709 PARSE_TQ (tq3);
1710 PARSE_TQ (tq4);
1711 PARSE_TQ (tq5);
1712 #undef PARSE_TQ
1713
1714 /* mips cc 2.x and gcc never put out continued aux entries. */
1715 if (!t->continued)
1716 break;
1717
1718 (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1719 ax++;
1720 }
1721
1722 /* Complain for illegal continuations due to corrupt aux entries. */
1723 if (t->continued)
1724 complain (&bad_continued_complaint, sym_name);
1725
1726 return tp;
1727 }
1728
1729 /* Make up a complex type from a basic one. Type is passed by
1730 reference in TPP and side-effected as necessary. The type
1731 qualifier TQ says how to handle the aux symbols at AX for
1732 the symbol SX we are currently analyzing. BIGEND says whether
1733 aux symbols are big-endian or little-endian.
1734 Returns the number of aux symbols we parsed. */
1735
1736 static int
1737 upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
1738 char *sym_name)
1739 {
1740 int off;
1741 struct type *t;
1742
1743 /* Used in array processing */
1744 int rf, id;
1745 FDR *fh;
1746 struct type *range;
1747 struct type *indx;
1748 int lower, upper;
1749 RNDXR rndx;
1750
1751 switch (tq)
1752 {
1753 case tqPtr:
1754 t = lookup_pointer_type (*tpp);
1755 *tpp = t;
1756 return 0;
1757
1758 case tqProc:
1759 t = lookup_function_type (*tpp);
1760 *tpp = t;
1761 return 0;
1762
1763 case tqArray:
1764 off = 0;
1765
1766 /* Determine and record the domain type (type of index) */
1767 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
1768 id = rndx.index;
1769 rf = rndx.rfd;
1770 if (rf == 0xfff)
1771 {
1772 ax++;
1773 rf = AUX_GET_ISYM (bigend, ax);
1774 off++;
1775 }
1776 fh = get_rfd (fd, rf);
1777
1778 indx = parse_type (fh - debug_info->fdr,
1779 debug_info->external_aux + fh->iauxBase,
1780 id, (int *) NULL, bigend, sym_name);
1781
1782 /* The bounds type should be an integer type, but might be anything
1783 else due to corrupt aux entries. */
1784 if (TYPE_CODE (indx) != TYPE_CODE_INT)
1785 {
1786 complain (&array_index_type_complaint, sym_name);
1787 indx = mdebug_type_int;
1788 }
1789
1790 /* Get the bounds, and create the array type. */
1791 ax++;
1792 lower = AUX_GET_DNLOW (bigend, ax);
1793 ax++;
1794 upper = AUX_GET_DNHIGH (bigend, ax);
1795 ax++;
1796 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1797
1798 range = create_range_type ((struct type *) NULL, indx,
1799 lower, upper);
1800
1801 t = create_array_type ((struct type *) NULL, *tpp, range);
1802
1803 /* We used to fill in the supplied array element bitsize
1804 here if the TYPE_LENGTH of the target type was zero.
1805 This happens for a `pointer to an array of anonymous structs',
1806 but in this case the array element bitsize is also zero,
1807 so nothing is gained.
1808 And we used to check the TYPE_LENGTH of the target type against
1809 the supplied array element bitsize.
1810 gcc causes a mismatch for `pointer to array of object',
1811 since the sdb directives it uses do not have a way of
1812 specifying the bitsize, but it does no harm (the
1813 TYPE_LENGTH should be correct) and we should be able to
1814 ignore the erroneous bitsize from the auxiliary entry safely.
1815 dbx seems to ignore it too. */
1816
1817 /* TYPE_FLAG_TARGET_STUB now takes care of the zero TYPE_LENGTH
1818 problem. */
1819 if (TYPE_LENGTH (*tpp) == 0)
1820 {
1821 TYPE_FLAGS (t) |= TYPE_FLAG_TARGET_STUB;
1822 }
1823
1824 *tpp = t;
1825 return 4 + off;
1826
1827 case tqVol:
1828 /* Volatile -- currently ignored */
1829 return 0;
1830
1831 case tqConst:
1832 /* Const -- currently ignored */
1833 return 0;
1834
1835 default:
1836 complain (&unknown_type_qual_complaint, tq);
1837 return 0;
1838 }
1839 }
1840
1841
1842 /* Parse a procedure descriptor record PR. Note that the procedure is
1843 parsed _after_ the local symbols, now we just insert the extra
1844 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1845 already been placed in the procedure's main block. Note also that
1846 images that have been partially stripped (ld -x) have been deprived
1847 of local symbols, and we have to cope with them here. FIRST_OFF is
1848 the offset of the first procedure for this FDR; we adjust the
1849 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1850 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1851 in question, or NULL to use top_stack->cur_block. */
1852
1853 static void parse_procedure (PDR *, struct symtab *, struct partial_symtab *);
1854
1855 static void
1856 parse_procedure (PDR *pr, struct symtab *search_symtab,
1857 struct partial_symtab *pst)
1858 {
1859 struct symbol *s, *i;
1860 struct block *b;
1861 struct mips_extra_func_info *e;
1862 char *sh_name;
1863
1864 /* Simple rule to find files linked "-x" */
1865 if (cur_fdr->rss == -1)
1866 {
1867 if (pr->isym == -1)
1868 {
1869 /* Static procedure at address pr->adr. Sigh. */
1870 /* FIXME-32x64. assuming pr->adr fits in long. */
1871 complain (&pdr_static_symbol_complaint, (unsigned long) pr->adr);
1872 return;
1873 }
1874 else
1875 {
1876 /* external */
1877 EXTR she;
1878
1879 (*debug_swap->swap_ext_in) (cur_bfd,
1880 ((char *) debug_info->external_ext
1881 + (pr->isym
1882 * debug_swap->external_ext_size)),
1883 &she);
1884 sh_name = debug_info->ssext + she.asym.iss;
1885 }
1886 }
1887 else
1888 {
1889 /* Full symbols */
1890 SYMR sh;
1891
1892 (*debug_swap->swap_sym_in) (cur_bfd,
1893 ((char *) debug_info->external_sym
1894 + ((cur_fdr->isymBase + pr->isym)
1895 * debug_swap->external_sym_size)),
1896 &sh);
1897 sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
1898 }
1899
1900 if (search_symtab != NULL)
1901 {
1902 #if 0
1903 /* This loses both in the case mentioned (want a static, find a global),
1904 but also if we are looking up a non-mangled name which happens to
1905 match the name of a mangled function. */
1906 /* We have to save the cur_fdr across the call to lookup_symbol.
1907 If the pdr is for a static function and if a global function with
1908 the same name exists, lookup_symbol will eventually read in the symtab
1909 for the global function and clobber cur_fdr. */
1910 FDR *save_cur_fdr = cur_fdr;
1911 s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1912 cur_fdr = save_cur_fdr;
1913 #else
1914 s = mylookup_symbol
1915 (sh_name,
1916 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK),
1917 VAR_NAMESPACE,
1918 LOC_BLOCK);
1919 #endif
1920 }
1921 else
1922 s = mylookup_symbol (sh_name, top_stack->cur_block,
1923 VAR_NAMESPACE, LOC_BLOCK);
1924
1925 if (s != 0)
1926 {
1927 b = SYMBOL_BLOCK_VALUE (s);
1928 }
1929 else
1930 {
1931 complain (&pdr_for_nonsymbol_complaint, sh_name);
1932 #if 1
1933 return;
1934 #else
1935 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1936 s = new_symbol (sh_name);
1937 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1938 SYMBOL_CLASS (s) = LOC_BLOCK;
1939 /* Donno its type, hope int is ok */
1940 SYMBOL_TYPE (s) = lookup_function_type (mdebug_type_int);
1941 add_symbol (s, top_stack->cur_block);
1942 /* Wont have symbols for this one */
1943 b = new_block (2);
1944 SYMBOL_BLOCK_VALUE (s) = b;
1945 BLOCK_FUNCTION (b) = s;
1946 BLOCK_START (b) = pr->adr;
1947 /* BOUND used to be the end of procedure's text, but the
1948 argument is no longer passed in. */
1949 BLOCK_END (b) = bound;
1950 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1951 add_block (b, top_stack->cur_st);
1952 #endif
1953 }
1954
1955 i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1956
1957 if (i)
1958 {
1959 e = (struct mips_extra_func_info *) SYMBOL_VALUE (i);
1960 e->pdr = *pr;
1961 e->pdr.isym = (long) s;
1962
1963 /* GDB expects the absolute function start address for the
1964 procedure descriptor in e->pdr.adr.
1965 As the address in the procedure descriptor is usually relative,
1966 we would have to relocate e->pdr.adr with cur_fdr->adr and
1967 ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)).
1968 Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
1969 in shared libraries on some systems, and on other systems
1970 e->pdr.adr is sometimes offset by a bogus value.
1971 To work around these problems, we replace e->pdr.adr with
1972 the start address of the function. */
1973 e->pdr.adr = BLOCK_START (b);
1974
1975 /* Correct incorrect setjmp procedure descriptor from the library
1976 to make backtrace through setjmp work. */
1977 if (e->pdr.pcreg == 0 && STREQ (sh_name, "setjmp"))
1978 {
1979 complain (&bad_setjmp_pdr_complaint, 0);
1980 e->pdr.pcreg = RA_REGNUM;
1981 e->pdr.regmask = 0x80000000;
1982 e->pdr.regoffset = -4;
1983 }
1984 }
1985
1986 /* It would be reasonable that functions that have been compiled
1987 without debugging info have a btNil type for their return value,
1988 and functions that are void and are compiled with debugging info
1989 have btVoid.
1990 gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
1991 to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
1992 case right.
1993 The glevel field in cur_fdr could be used to determine the presence
1994 of debugging info, but GCC doesn't always pass the -g switch settings
1995 to the assembler and GAS doesn't set the glevel field from the -g switch
1996 settings.
1997 To work around these problems, the return value type of a TYPE_CODE_VOID
1998 function is adjusted accordingly if no debugging info was found in the
1999 compilation unit. */
2000
2001 if (processing_gcc_compilation == 0
2002 && found_ecoff_debugging_info == 0
2003 && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID)
2004 SYMBOL_TYPE (s) = nodebug_func_symbol_type;
2005 }
2006
2007 /* Relocate the extra function info pointed to by the symbol table. */
2008
2009 void
2010 ecoff_relocate_efi (struct symbol *sym, CORE_ADDR delta)
2011 {
2012 struct mips_extra_func_info *e;
2013
2014 e = (struct mips_extra_func_info *) SYMBOL_VALUE (sym);
2015
2016 e->pdr.adr += delta;
2017 }
2018
2019 /* Parse the external symbol ES. Just call parse_symbol() after
2020 making sure we know where the aux are for it.
2021 BIGEND says whether aux entries are big-endian or little-endian.
2022
2023 This routine clobbers top_stack->cur_block and ->cur_st. */
2024
2025 static void parse_external (EXTR *, int, struct section_offsets *,
2026 struct objfile *);
2027
2028 static void
2029 parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
2030 struct objfile *objfile)
2031 {
2032 union aux_ext *ax;
2033
2034 if (es->ifd != ifdNil)
2035 {
2036 cur_fd = es->ifd;
2037 cur_fdr = debug_info->fdr + cur_fd;
2038 ax = debug_info->external_aux + cur_fdr->iauxBase;
2039 }
2040 else
2041 {
2042 cur_fdr = debug_info->fdr;
2043 ax = 0;
2044 }
2045
2046 /* Reading .o files */
2047 if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
2048 {
2049 char *what;
2050 switch (es->asym.st)
2051 {
2052 case stNil:
2053 /* These are generated for static symbols in .o files,
2054 ignore them. */
2055 return;
2056 case stStaticProc:
2057 case stProc:
2058 what = "procedure";
2059 n_undef_procs++;
2060 break;
2061 case stGlobal:
2062 what = "variable";
2063 n_undef_vars++;
2064 break;
2065 case stLabel:
2066 what = "label";
2067 n_undef_labels++;
2068 break;
2069 default:
2070 what = "symbol";
2071 break;
2072 }
2073 n_undef_symbols++;
2074 /* FIXME: Turn this into a complaint? */
2075 if (info_verbose)
2076 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
2077 what, debug_info->ssext + es->asym.iss,
2078 fdr_name (cur_fdr));
2079 return;
2080 }
2081
2082 switch (es->asym.st)
2083 {
2084 case stProc:
2085 case stStaticProc:
2086 /* There is no need to parse the external procedure symbols.
2087 If they are from objects compiled without -g, their index will
2088 be indexNil, and the symbol definition from the minimal symbol
2089 is preferrable (yielding a function returning int instead of int).
2090 If the index points to a local procedure symbol, the local
2091 symbol already provides the correct type.
2092 Note that the index of the external procedure symbol points
2093 to the local procedure symbol in the local symbol table, and
2094 _not_ to the auxiliary symbol info. */
2095 break;
2096 case stGlobal:
2097 case stLabel:
2098 /* Global common symbols are resolved by the runtime loader,
2099 ignore them. */
2100 if (SC_IS_COMMON (es->asym.sc))
2101 break;
2102
2103 /* Note that the case of a symbol with indexNil must be handled
2104 anyways by parse_symbol(). */
2105 parse_symbol (&es->asym, ax, (char *) NULL, bigend, section_offsets, objfile);
2106 break;
2107 default:
2108 break;
2109 }
2110 }
2111
2112 /* Parse the line number info for file descriptor FH into
2113 GDB's linetable LT. MIPS' encoding requires a little bit
2114 of magic to get things out. Note also that MIPS' line
2115 numbers can go back and forth, apparently we can live
2116 with that and do not need to reorder our linetables */
2117
2118 static void parse_lines (FDR *, PDR *, struct linetable *, int,
2119 struct partial_symtab *, CORE_ADDR);
2120
2121 static void
2122 parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
2123 struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr)
2124 {
2125 unsigned char *base;
2126 int j, k;
2127 int delta, count, lineno = 0;
2128
2129 if (fh->cbLine == 0)
2130 return;
2131
2132 /* Scan by procedure descriptors */
2133 k = 0;
2134 for (j = 0; j < fh->cpd; j++, pr++)
2135 {
2136 CORE_ADDR l;
2137 CORE_ADDR adr;
2138 unsigned char *halt;
2139
2140 /* No code for this one */
2141 if (pr->iline == ilineNil ||
2142 pr->lnLow == -1 || pr->lnHigh == -1)
2143 continue;
2144
2145 /* Determine start and end address of compressed line bytes for
2146 this procedure. */
2147 base = debug_info->line + fh->cbLineOffset;
2148 if (j != (fh->cpd - 1))
2149 halt = base + pr[1].cbLineOffset;
2150 else
2151 halt = base + fh->cbLine;
2152 base += pr->cbLineOffset;
2153
2154 adr = pst->textlow + pr->adr - lowest_pdr_addr;
2155
2156 l = adr >> 2; /* in words */
2157 for (lineno = pr->lnLow; base < halt;)
2158 {
2159 count = *base & 0x0f;
2160 delta = *base++ >> 4;
2161 if (delta >= 8)
2162 delta -= 16;
2163 if (delta == -8)
2164 {
2165 delta = (base[0] << 8) | base[1];
2166 if (delta >= 0x8000)
2167 delta -= 0x10000;
2168 base += 2;
2169 }
2170 lineno += delta; /* first delta is 0 */
2171
2172 /* Complain if the line table overflows. Could happen
2173 with corrupt binaries. */
2174 if (lt->nitems >= maxlines)
2175 {
2176 complain (&bad_linetable_guess_complaint, fdr_name (fh));
2177 break;
2178 }
2179 k = add_line (lt, lineno, l, k);
2180 l += count + 1;
2181 }
2182 }
2183 }
2184 \f
2185 /* Master parsing procedure for first-pass reading of file symbols
2186 into a partial_symtab. */
2187
2188 static void
2189 parse_partial_symbols (struct objfile *objfile)
2190 {
2191 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
2192 const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
2193 const bfd_size_type external_ext_size = debug_swap->external_ext_size;
2194 void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in;
2195 void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
2196 void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in;
2197 int f_idx, s_idx;
2198 HDRR *hdr = &debug_info->symbolic_header;
2199 /* Running pointers */
2200 FDR *fh;
2201 char *ext_out;
2202 char *ext_out_end;
2203 EXTR *ext_block;
2204 register EXTR *ext_in;
2205 EXTR *ext_in_end;
2206 SYMR sh;
2207 struct partial_symtab *pst;
2208 int textlow_not_set = 1;
2209 int past_first_source_file = 0;
2210
2211 /* List of current psymtab's include files */
2212 char **psymtab_include_list;
2213 int includes_allocated;
2214 int includes_used;
2215 EXTR *extern_tab;
2216 struct pst_map *fdr_to_pst;
2217 /* Index within current psymtab dependency list */
2218 struct partial_symtab **dependency_list;
2219 int dependencies_used, dependencies_allocated;
2220 struct cleanup *old_chain;
2221 char *name;
2222 enum language prev_language;
2223 asection *text_sect;
2224 int relocatable = 0;
2225
2226 /* Irix 5.2 shared libraries have a fh->adr field of zero, but
2227 the shared libraries are prelinked at a high memory address.
2228 We have to adjust the start address of the object file for this case,
2229 by setting it to the start address of the first procedure in the file.
2230 But we should do no adjustments if we are debugging a .o file, where
2231 the text section (and fh->adr) really starts at zero. */
2232 text_sect = bfd_get_section_by_name (cur_bfd, ".text");
2233 if (text_sect != NULL
2234 && (bfd_get_section_flags (cur_bfd, text_sect) & SEC_RELOC))
2235 relocatable = 1;
2236
2237 extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack,
2238 sizeof (EXTR) * hdr->iextMax);
2239
2240 includes_allocated = 30;
2241 includes_used = 0;
2242 psymtab_include_list = (char **) alloca (includes_allocated *
2243 sizeof (char *));
2244 next_symbol_text_func = mdebug_next_symbol_text;
2245
2246 dependencies_allocated = 30;
2247 dependencies_used = 0;
2248 dependency_list =
2249 (struct partial_symtab **) alloca (dependencies_allocated *
2250 sizeof (struct partial_symtab *));
2251
2252 last_source_file = NULL;
2253
2254 /*
2255 * Big plan:
2256 *
2257 * Only parse the Local and External symbols, and the Relative FDR.
2258 * Fixup enough of the loader symtab to be able to use it.
2259 * Allocate space only for the file's portions we need to
2260 * look at. (XXX)
2261 */
2262
2263 max_gdbinfo = 0;
2264 max_glevel = MIN_GLEVEL;
2265
2266 /* Allocate the map FDR -> PST.
2267 Minor hack: -O3 images might claim some global data belongs
2268 to FDR -1. We`ll go along with that */
2269 fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
2270 old_chain = make_cleanup (xfree, fdr_to_pst);
2271 fdr_to_pst++;
2272 {
2273 struct partial_symtab *pst = new_psymtab ("", objfile);
2274 fdr_to_pst[-1].pst = pst;
2275 FDR_IDX (pst) = -1;
2276 }
2277
2278 /* Allocate the global pending list. */
2279 pending_list =
2280 ((struct mdebug_pending **)
2281 obstack_alloc (&objfile->psymbol_obstack,
2282 hdr->ifdMax * sizeof (struct mdebug_pending *)));
2283 memset (pending_list, 0,
2284 hdr->ifdMax * sizeof (struct mdebug_pending *));
2285
2286 /* Pass 0 over external syms: swap them in. */
2287 ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
2288 make_cleanup (xfree, ext_block);
2289
2290 ext_out = (char *) debug_info->external_ext;
2291 ext_out_end = ext_out + hdr->iextMax * external_ext_size;
2292 ext_in = ext_block;
2293 for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
2294 (*swap_ext_in) (cur_bfd, ext_out, ext_in);
2295
2296 /* Pass 1 over external syms: Presize and partition the list */
2297 ext_in = ext_block;
2298 ext_in_end = ext_in + hdr->iextMax;
2299 for (; ext_in < ext_in_end; ext_in++)
2300 {
2301 /* See calls to complain below. */
2302 if (ext_in->ifd >= -1
2303 && ext_in->ifd < hdr->ifdMax
2304 && ext_in->asym.iss >= 0
2305 && ext_in->asym.iss < hdr->issExtMax)
2306 fdr_to_pst[ext_in->ifd].n_globals++;
2307 }
2308
2309 /* Pass 1.5 over files: partition out global symbol space */
2310 s_idx = 0;
2311 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
2312 {
2313 fdr_to_pst[f_idx].globals_offset = s_idx;
2314 s_idx += fdr_to_pst[f_idx].n_globals;
2315 fdr_to_pst[f_idx].n_globals = 0;
2316 }
2317
2318 /* ECOFF in ELF:
2319
2320 For ECOFF in ELF, we skip the creation of the minimal symbols.
2321 The ECOFF symbols should be a subset of the Elf symbols, and the
2322 section information of the elf symbols will be more accurate.
2323 FIXME! What about Irix 5's native linker?
2324
2325 By default, Elf sections which don't exist in ECOFF
2326 get put in ECOFF's absolute section by the gnu linker.
2327 Since absolute sections don't get relocated, we
2328 end up calculating an address different from that of
2329 the symbol's minimal symbol (created earlier from the
2330 Elf symtab).
2331
2332 To fix this, either :
2333 1) don't create the duplicate symbol
2334 (assumes ECOFF symtab is a subset of the ELF symtab;
2335 assumes no side-effects result from ignoring ECOFF symbol)
2336 2) create it, only if lookup for existing symbol in ELF's minimal
2337 symbols fails
2338 (inefficient;
2339 assumes no side-effects result from ignoring ECOFF symbol)
2340 3) create it, but lookup ELF's minimal symbol and use it's section
2341 during relocation, then modify "uniqify" phase to merge and
2342 eliminate the duplicate symbol
2343 (highly inefficient)
2344
2345 I've implemented #1 here...
2346 Skip the creation of the minimal symbols based on the ECOFF
2347 symbol table. */
2348
2349 /* Pass 2 over external syms: fill in external symbols */
2350 ext_in = ext_block;
2351 ext_in_end = ext_in + hdr->iextMax;
2352 for (; ext_in < ext_in_end; ext_in++)
2353 {
2354 enum minimal_symbol_type ms_type = mst_text;
2355 CORE_ADDR svalue = ext_in->asym.value;
2356
2357 /* The Irix 5 native tools seem to sometimes generate bogus
2358 external symbols. */
2359 if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
2360 {
2361 complain (&bad_ext_ifd_complaint, ext_in->ifd, hdr->ifdMax);
2362 continue;
2363 }
2364 if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
2365 {
2366 complain (&bad_ext_iss_complaint, ext_in->asym.iss,
2367 hdr->issExtMax);
2368 continue;
2369 }
2370
2371 extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
2372 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
2373
2374
2375 if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
2376 continue;
2377
2378
2379 /* Pass 3 over files, over local syms: fill in static symbols */
2380 name = debug_info->ssext + ext_in->asym.iss;
2381
2382 /* Process ECOFF Symbol Types and Storage Classes */
2383 switch (ext_in->asym.st)
2384 {
2385 case stProc:
2386 /* Beginnning of Procedure */
2387 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2388 break;
2389 case stStaticProc:
2390 /* Load time only static procs */
2391 ms_type = mst_file_text;
2392 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2393 break;
2394 case stGlobal:
2395 /* External symbol */
2396 if (SC_IS_COMMON (ext_in->asym.sc))
2397 {
2398 /* The value of a common symbol is its size, not its address.
2399 Ignore it. */
2400 continue;
2401 }
2402 else if (SC_IS_DATA (ext_in->asym.sc))
2403 {
2404 ms_type = mst_data;
2405 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2406 }
2407 else if (SC_IS_BSS (ext_in->asym.sc))
2408 {
2409 ms_type = mst_bss;
2410 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2411 }
2412 else if (SC_IS_SBSS (ext_in->asym.sc))
2413 {
2414 ms_type = mst_bss;
2415 svalue += ANOFFSET (objfile->section_offsets,
2416 get_section_index (objfile, ".sbss"));
2417 }
2418 else
2419 ms_type = mst_abs;
2420 break;
2421 case stLabel:
2422 /* Label */
2423
2424 /* On certain platforms, some extra label symbols can be
2425 generated by the linker. One possible usage for this kind
2426 of symbols is to represent the address of the begining of a
2427 given section. For instance, on Tru64 5.1, the address of
2428 the _ftext label is the start address of the .text section.
2429
2430 The storage class of these symbols is usually directly
2431 related to the section to which the symbol refers. For
2432 instance, on Tru64 5.1, the storage class for the _fdata
2433 label is scData, refering to the .data section.
2434
2435 It is actually possible that the section associated to the
2436 storage class of the label does not exist. On True64 5.1
2437 for instance, the libm.so shared library does not contain
2438 any .data section, although it contains a _fpdata label
2439 which storage class is scData... Since these symbols are
2440 usually useless for the debugger user anyway, we just
2441 discard these symbols.
2442 */
2443
2444 if (SC_IS_TEXT (ext_in->asym.sc))
2445 {
2446 if (objfile->sect_index_text == -1)
2447 continue;
2448
2449 ms_type = mst_file_text;
2450 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2451 }
2452 else if (SC_IS_DATA (ext_in->asym.sc))
2453 {
2454 if (objfile->sect_index_data == -1)
2455 continue;
2456
2457 ms_type = mst_file_data;
2458 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2459 }
2460 else if (SC_IS_BSS (ext_in->asym.sc))
2461 {
2462 if (objfile->sect_index_bss == -1)
2463 continue;
2464
2465 ms_type = mst_file_bss;
2466 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2467 }
2468 else if (SC_IS_SBSS (ext_in->asym.sc))
2469 {
2470 const int sbss_sect_index = get_section_index (objfile, ".sbss");
2471
2472 if (sbss_sect_index == -1)
2473 continue;
2474
2475 ms_type = mst_file_bss;
2476 svalue += ANOFFSET (objfile->section_offsets, sbss_sect_index);
2477 }
2478 else
2479 ms_type = mst_abs;
2480 break;
2481 case stLocal:
2482 case stNil:
2483 /* The alpha has the section start addresses in stLocal symbols
2484 whose name starts with a `.'. Skip those but complain for all
2485 other stLocal symbols.
2486 Irix6 puts the section start addresses in stNil symbols, skip
2487 those too. */
2488 if (name[0] == '.')
2489 continue;
2490 /* Fall through. */
2491 default:
2492 ms_type = mst_unknown;
2493 complain (&unknown_ext_complaint, name);
2494 }
2495 if (!ECOFF_IN_ELF (cur_bfd))
2496 prim_record_minimal_symbol (name, svalue, ms_type, objfile);
2497 }
2498
2499 /* Pass 3 over files, over local syms: fill in static symbols */
2500 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2501 {
2502 struct partial_symtab *save_pst;
2503 EXTR *ext_ptr;
2504 CORE_ADDR textlow;
2505
2506 cur_fdr = fh = debug_info->fdr + f_idx;
2507
2508 if (fh->csym == 0)
2509 {
2510 fdr_to_pst[f_idx].pst = NULL;
2511 continue;
2512 }
2513
2514 /* Determine the start address for this object file from the
2515 file header and relocate it, except for Irix 5.2 zero fh->adr. */
2516 if (fh->cpd)
2517 {
2518 textlow = fh->adr;
2519 if (relocatable || textlow != 0)
2520 textlow += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2521 }
2522 else
2523 textlow = 0;
2524 pst = start_psymtab_common (objfile, objfile->section_offsets,
2525 fdr_name (fh),
2526 textlow,
2527 objfile->global_psymbols.next,
2528 objfile->static_psymbols.next);
2529 pst->read_symtab_private = ((char *)
2530 obstack_alloc (&objfile->psymbol_obstack,
2531 sizeof (struct symloc)));
2532 memset (pst->read_symtab_private, 0, sizeof (struct symloc));
2533
2534 save_pst = pst;
2535 FDR_IDX (pst) = f_idx;
2536 CUR_BFD (pst) = cur_bfd;
2537 DEBUG_SWAP (pst) = debug_swap;
2538 DEBUG_INFO (pst) = debug_info;
2539 PENDING_LIST (pst) = pending_list;
2540
2541 /* The way to turn this into a symtab is to call... */
2542 pst->read_symtab = mdebug_psymtab_to_symtab;
2543
2544 /* Set up language for the pst.
2545 The language from the FDR is used if it is unambigious (e.g. cfront
2546 with native cc and g++ will set the language to C).
2547 Otherwise we have to deduce the language from the filename.
2548 Native ecoff has every header file in a separate FDR, so
2549 deduce_language_from_filename will return language_unknown for
2550 a header file, which is not what we want.
2551 But the FDRs for the header files are after the FDR for the source
2552 file, so we can assign the language of the source file to the
2553 following header files. Then we save the language in the private
2554 pst data so that we can reuse it when building symtabs. */
2555 prev_language = psymtab_language;
2556
2557 switch (fh->lang)
2558 {
2559 case langCplusplusV2:
2560 psymtab_language = language_cplus;
2561 break;
2562 default:
2563 psymtab_language = deduce_language_from_filename (fdr_name (fh));
2564 break;
2565 }
2566 if (psymtab_language == language_unknown)
2567 psymtab_language = prev_language;
2568 PST_PRIVATE (pst)->pst_language = psymtab_language;
2569
2570 pst->texthigh = pst->textlow;
2571
2572 /* For stabs-in-ecoff files, the second symbol must be @stab.
2573 This symbol is emitted by mips-tfile to signal that the
2574 current object file uses encapsulated stabs instead of mips
2575 ecoff for local symbols. (It is the second symbol because
2576 the first symbol is the stFile used to signal the start of a
2577 file). */
2578 processing_gcc_compilation = 0;
2579 if (fh->csym >= 2)
2580 {
2581 (*swap_sym_in) (cur_bfd,
2582 ((char *) debug_info->external_sym
2583 + (fh->isymBase + 1) * external_sym_size),
2584 &sh);
2585 if (STREQ (debug_info->ss + fh->issBase + sh.iss, stabs_symbol))
2586 processing_gcc_compilation = 2;
2587 }
2588
2589 if (processing_gcc_compilation != 0)
2590 {
2591 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2592 {
2593 int type_code;
2594 char *namestring;
2595
2596 (*swap_sym_in) (cur_bfd,
2597 (((char *) debug_info->external_sym)
2598 + (fh->isymBase + cur_sdx) * external_sym_size),
2599 &sh);
2600 type_code = ECOFF_UNMARK_STAB (sh.index);
2601 if (!ECOFF_IS_STAB (&sh))
2602 {
2603 if (sh.st == stProc || sh.st == stStaticProc)
2604 {
2605 CORE_ADDR procaddr;
2606 long isym;
2607
2608 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2609 if (sh.st == stStaticProc)
2610 {
2611 namestring = debug_info->ss + fh->issBase + sh.iss;
2612 prim_record_minimal_symbol_and_info (namestring,
2613 sh.value,
2614 mst_file_text,
2615 NULL,
2616 SECT_OFF_TEXT (objfile),
2617 NULL,
2618 objfile);
2619 }
2620 procaddr = sh.value;
2621
2622 isym = AUX_GET_ISYM (fh->fBigendian,
2623 (debug_info->external_aux
2624 + fh->iauxBase
2625 + sh.index));
2626 (*swap_sym_in) (cur_bfd,
2627 ((char *) debug_info->external_sym
2628 + ((fh->isymBase + isym - 1)
2629 * external_sym_size)),
2630 &sh);
2631 if (sh.st == stEnd)
2632 {
2633 CORE_ADDR high = procaddr + sh.value;
2634
2635 /* Kludge for Irix 5.2 zero fh->adr. */
2636 if (!relocatable
2637 && (pst->textlow == 0 || procaddr < pst->textlow))
2638 pst->textlow = procaddr;
2639 if (high > pst->texthigh)
2640 pst->texthigh = high;
2641 }
2642 }
2643 else if (sh.st == stStatic)
2644 {
2645 switch (sh.sc)
2646 {
2647 case scUndefined:
2648 case scSUndefined:
2649 case scNil:
2650 case scAbs:
2651 break;
2652
2653 case scData:
2654 case scSData:
2655 case scRData:
2656 case scPData:
2657 case scXData:
2658 namestring = debug_info->ss + fh->issBase + sh.iss;
2659 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2660 prim_record_minimal_symbol_and_info (namestring,
2661 sh.value,
2662 mst_file_data,
2663 NULL,
2664 SECT_OFF_DATA (objfile),
2665 NULL,
2666 objfile);
2667 break;
2668
2669 default:
2670 /* FIXME! Shouldn't this use cases for bss,
2671 then have the default be abs? */
2672 namestring = debug_info->ss + fh->issBase + sh.iss;
2673 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2674 prim_record_minimal_symbol_and_info (namestring,
2675 sh.value,
2676 mst_file_bss,
2677 NULL,
2678 SECT_OFF_BSS (objfile),
2679 NULL,
2680 objfile);
2681 break;
2682 }
2683 }
2684 continue;
2685 }
2686 /* Handle stabs continuation */
2687 {
2688 char *stabstring = debug_info->ss + fh->issBase + sh.iss;
2689 int len = strlen (stabstring);
2690 while (stabstring[len - 1] == '\\')
2691 {
2692 SYMR sh2;
2693 char *stabstring1 = stabstring;
2694 char *stabstring2;
2695 int len2;
2696
2697 /* Ignore continuation char from 1st string */
2698 len--;
2699
2700 /* Read next stabstring */
2701 cur_sdx++;
2702 (*swap_sym_in) (cur_bfd,
2703 (((char *) debug_info->external_sym)
2704 + (fh->isymBase + cur_sdx)
2705 * external_sym_size),
2706 &sh2);
2707 stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
2708 len2 = strlen (stabstring2);
2709
2710 /* Concatinate stabstring2 with stabstring1 */
2711 if (stabstring
2712 && stabstring != debug_info->ss + fh->issBase + sh.iss)
2713 stabstring = xrealloc (stabstring, len + len2 + 1);
2714 else
2715 {
2716 stabstring = xmalloc (len + len2 + 1);
2717 strcpy (stabstring, stabstring1);
2718 }
2719 strcpy (stabstring + len, stabstring2);
2720 len += len2;
2721 }
2722
2723 switch (type_code)
2724 {
2725 static struct deprecated_complaint function_outside_compilation_unit = {
2726 "function `%s' appears to be defined outside of all compilation units", 0, 0
2727 };
2728 char *p;
2729 /*
2730 * Standard, external, non-debugger, symbols
2731 */
2732
2733 case N_TEXT | N_EXT:
2734 case N_NBTEXT | N_EXT:
2735 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2736 goto record_it;
2737
2738 case N_DATA | N_EXT:
2739 case N_NBDATA | N_EXT:
2740 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2741 goto record_it;
2742
2743 case N_BSS:
2744 case N_BSS | N_EXT:
2745 case N_NBBSS | N_EXT:
2746 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
2747 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2748 goto record_it;
2749
2750 case N_ABS | N_EXT:
2751 record_it:
2752 continue;
2753
2754 /* Standard, local, non-debugger, symbols */
2755
2756 case N_NBTEXT:
2757
2758 /* We need to be able to deal with both N_FN or N_TEXT,
2759 because we have no way of knowing whether the sys-supplied ld
2760 or GNU ld was used to make the executable. Sequents throw
2761 in another wrinkle -- they renumbered N_FN. */
2762
2763 case N_FN:
2764 case N_FN_SEQ:
2765 case N_TEXT:
2766 continue;
2767
2768 case N_DATA:
2769 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2770 goto record_it;
2771
2772 case N_UNDF | N_EXT:
2773 continue; /* Just undefined, not COMMON */
2774
2775 case N_UNDF:
2776 continue;
2777
2778 /* Lots of symbol types we can just ignore. */
2779
2780 case N_ABS:
2781 case N_NBDATA:
2782 case N_NBBSS:
2783 continue;
2784
2785 /* Keep going . . . */
2786
2787 /*
2788 * Special symbol types for GNU
2789 */
2790 case N_INDR:
2791 case N_INDR | N_EXT:
2792 case N_SETA:
2793 case N_SETA | N_EXT:
2794 case N_SETT:
2795 case N_SETT | N_EXT:
2796 case N_SETD:
2797 case N_SETD | N_EXT:
2798 case N_SETB:
2799 case N_SETB | N_EXT:
2800 case N_SETV:
2801 continue;
2802
2803 /*
2804 * Debugger symbols
2805 */
2806
2807 case N_SO:
2808 {
2809 CORE_ADDR valu;
2810 static int prev_so_symnum = -10;
2811 static int first_so_symnum;
2812 char *p;
2813 int prev_textlow_not_set;
2814
2815 valu = sh.value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2816
2817 prev_textlow_not_set = textlow_not_set;
2818
2819 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2820 /* A zero value is probably an indication for the SunPRO 3.0
2821 compiler. end_psymtab explicitly tests for zero, so
2822 don't relocate it. */
2823
2824 if (sh.value == 0)
2825 {
2826 textlow_not_set = 1;
2827 valu = 0;
2828 }
2829 else
2830 textlow_not_set = 0;
2831 #else
2832 textlow_not_set = 0;
2833 #endif
2834 past_first_source_file = 1;
2835
2836 if (prev_so_symnum != symnum - 1)
2837 { /* Here if prev stab wasn't N_SO */
2838 first_so_symnum = symnum;
2839
2840 if (pst)
2841 {
2842 pst = (struct partial_symtab *) 0;
2843 includes_used = 0;
2844 dependencies_used = 0;
2845 }
2846 }
2847
2848 prev_so_symnum = symnum;
2849
2850 /* End the current partial symtab and start a new one */
2851
2852 /* SET_NAMESTRING ();*/
2853 namestring = stabstring;
2854
2855 /* Null name means end of .o file. Don't start a new one. */
2856 if (*namestring == '\000')
2857 continue;
2858
2859 /* Some compilers (including gcc) emit a pair of initial N_SOs.
2860 The first one is a directory name; the second the file name.
2861 If pst exists, is empty, and has a filename ending in '/',
2862 we assume the previous N_SO was a directory name. */
2863
2864 p = strrchr (namestring, '/');
2865 if (p && *(p + 1) == '\000')
2866 continue; /* Simply ignore directory name SOs */
2867
2868 /* Some other compilers (C++ ones in particular) emit useless
2869 SOs for non-existant .c files. We ignore all subsequent SOs that
2870 immediately follow the first. */
2871
2872 if (!pst)
2873 pst = save_pst;
2874 continue;
2875 }
2876
2877 case N_BINCL:
2878 continue;
2879
2880 case N_SOL:
2881 {
2882 enum language tmp_language;
2883 /* Mark down an include file in the current psymtab */
2884
2885 /* SET_NAMESTRING ();*/
2886 namestring = stabstring;
2887
2888 tmp_language = deduce_language_from_filename (namestring);
2889
2890 /* Only change the psymtab's language if we've learned
2891 something useful (eg. tmp_language is not language_unknown).
2892 In addition, to match what start_subfile does, never change
2893 from C++ to C. */
2894 if (tmp_language != language_unknown
2895 && (tmp_language != language_c
2896 || psymtab_language != language_cplus))
2897 psymtab_language = tmp_language;
2898
2899 /* In C++, one may expect the same filename to come round many
2900 times, when code is coming alternately from the main file
2901 and from inline functions in other files. So I check to see
2902 if this is a file we've seen before -- either the main
2903 source file, or a previously included file.
2904
2905 This seems to be a lot of time to be spending on N_SOL, but
2906 things like "break c-exp.y:435" need to work (I
2907 suppose the psymtab_include_list could be hashed or put
2908 in a binary tree, if profiling shows this is a major hog). */
2909 if (pst && STREQ (namestring, pst->filename))
2910 continue;
2911 {
2912 register int i;
2913 for (i = 0; i < includes_used; i++)
2914 if (STREQ (namestring, psymtab_include_list[i]))
2915 {
2916 i = -1;
2917 break;
2918 }
2919 if (i == -1)
2920 continue;
2921 }
2922
2923 psymtab_include_list[includes_used++] = namestring;
2924 if (includes_used >= includes_allocated)
2925 {
2926 char **orig = psymtab_include_list;
2927
2928 psymtab_include_list = (char **)
2929 alloca ((includes_allocated *= 2) *
2930 sizeof (char *));
2931 memcpy ((PTR) psymtab_include_list, (PTR) orig,
2932 includes_used * sizeof (char *));
2933 }
2934 continue;
2935 }
2936 case N_LSYM: /* Typedef or automatic variable. */
2937 case N_STSYM: /* Data seg var -- static */
2938 case N_LCSYM: /* BSS " */
2939 case N_ROSYM: /* Read-only data seg var -- static. */
2940 case N_NBSTS: /* Gould nobase. */
2941 case N_NBLCS: /* symbols. */
2942 case N_FUN:
2943 case N_GSYM: /* Global (extern) variable; can be
2944 data or bss (sigh FIXME). */
2945
2946 /* Following may probably be ignored; I'll leave them here
2947 for now (until I do Pascal and Modula 2 extensions). */
2948
2949 case N_PC: /* I may or may not need this; I
2950 suspect not. */
2951 case N_M2C: /* I suspect that I can ignore this here. */
2952 case N_SCOPE: /* Same. */
2953
2954 /* SET_NAMESTRING ();*/
2955 namestring = stabstring;
2956 p = (char *) strchr (namestring, ':');
2957 if (!p)
2958 continue; /* Not a debugging symbol. */
2959
2960
2961
2962 /* Main processing section for debugging symbols which
2963 the initial read through the symbol tables needs to worry
2964 about. If we reach this point, the symbol which we are
2965 considering is definitely one we are interested in.
2966 p must also contain the (valid) index into the namestring
2967 which indicates the debugging type symbol. */
2968
2969 switch (p[1])
2970 {
2971 case 'S':
2972 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2973 #ifdef STATIC_TRANSFORM_NAME
2974 namestring = STATIC_TRANSFORM_NAME (namestring);
2975 #endif
2976 add_psymbol_to_list (namestring, p - namestring,
2977 VAR_NAMESPACE, LOC_STATIC,
2978 &objfile->static_psymbols,
2979 0, sh.value,
2980 psymtab_language, objfile);
2981 continue;
2982 case 'G':
2983 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2984 /* The addresses in these entries are reported to be
2985 wrong. See the code that reads 'G's for symtabs. */
2986 add_psymbol_to_list (namestring, p - namestring,
2987 VAR_NAMESPACE, LOC_STATIC,
2988 &objfile->global_psymbols,
2989 0, sh.value,
2990 psymtab_language, objfile);
2991 continue;
2992
2993 case 'T':
2994 /* When a 'T' entry is defining an anonymous enum, it
2995 may have a name which is the empty string, or a
2996 single space. Since they're not really defining a
2997 symbol, those shouldn't go in the partial symbol
2998 table. We do pick up the elements of such enums at
2999 'check_enum:', below. */
3000 if (p >= namestring + 2
3001 || (p == namestring + 1
3002 && namestring[0] != ' '))
3003 {
3004 add_psymbol_to_list (namestring, p - namestring,
3005 STRUCT_NAMESPACE, LOC_TYPEDEF,
3006 &objfile->static_psymbols,
3007 sh.value, 0,
3008 psymtab_language, objfile);
3009 if (p[2] == 't')
3010 {
3011 /* Also a typedef with the same name. */
3012 add_psymbol_to_list (namestring, p - namestring,
3013 VAR_NAMESPACE, LOC_TYPEDEF,
3014 &objfile->static_psymbols,
3015 sh.value, 0,
3016 psymtab_language, objfile);
3017 p += 1;
3018 }
3019 /* The semantics of C++ state that "struct foo { ... }"
3020 also defines a typedef for "foo". Unfortuantely, cfront
3021 never makes the typedef when translating from C++ to C.
3022 We make the typedef here so that "ptype foo" works as
3023 expected for cfront translated code. */
3024 else if (psymtab_language == language_cplus)
3025 {
3026 /* Also a typedef with the same name. */
3027 add_psymbol_to_list (namestring, p - namestring,
3028 VAR_NAMESPACE, LOC_TYPEDEF,
3029 &objfile->static_psymbols,
3030 sh.value, 0,
3031 psymtab_language, objfile);
3032 }
3033 }
3034 goto check_enum;
3035 case 't':
3036 if (p != namestring) /* a name is there, not just :T... */
3037 {
3038 add_psymbol_to_list (namestring, p - namestring,
3039 VAR_NAMESPACE, LOC_TYPEDEF,
3040 &objfile->static_psymbols,
3041 sh.value, 0,
3042 psymtab_language, objfile);
3043 }
3044 check_enum:
3045 /* If this is an enumerated type, we need to
3046 add all the enum constants to the partial symbol
3047 table. This does not cover enums without names, e.g.
3048 "enum {a, b} c;" in C, but fortunately those are
3049 rare. There is no way for GDB to find those from the
3050 enum type without spending too much time on it. Thus
3051 to solve this problem, the compiler needs to put out the
3052 enum in a nameless type. GCC2 does this. */
3053
3054 /* We are looking for something of the form
3055 <name> ":" ("t" | "T") [<number> "="] "e"
3056 {<constant> ":" <value> ","} ";". */
3057
3058 /* Skip over the colon and the 't' or 'T'. */
3059 p += 2;
3060 /* This type may be given a number. Also, numbers can come
3061 in pairs like (0,26). Skip over it. */
3062 while ((*p >= '0' && *p <= '9')
3063 || *p == '(' || *p == ',' || *p == ')'
3064 || *p == '=')
3065 p++;
3066
3067 if (*p++ == 'e')
3068 {
3069 /* The aix4 compiler emits extra crud before the members. */
3070 if (*p == '-')
3071 {
3072 /* Skip over the type (?). */
3073 while (*p != ':')
3074 p++;
3075
3076 /* Skip over the colon. */
3077 p++;
3078 }
3079
3080 /* We have found an enumerated type. */
3081 /* According to comments in read_enum_type
3082 a comma could end it instead of a semicolon.
3083 I don't know where that happens.
3084 Accept either. */
3085 while (*p && *p != ';' && *p != ',')
3086 {
3087 char *q;
3088
3089 /* Check for and handle cretinous dbx symbol name
3090 continuation! */
3091 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
3092 p = next_symbol_text (objfile);
3093
3094 /* Point to the character after the name
3095 of the enum constant. */
3096 for (q = p; *q && *q != ':'; q++)
3097 ;
3098 /* Note that the value doesn't matter for
3099 enum constants in psymtabs, just in symtabs. */
3100 add_psymbol_to_list (p, q - p,
3101 VAR_NAMESPACE, LOC_CONST,
3102 &objfile->static_psymbols, 0,
3103 0, psymtab_language, objfile);
3104 /* Point past the name. */
3105 p = q;
3106 /* Skip over the value. */
3107 while (*p && *p != ',')
3108 p++;
3109 /* Advance past the comma. */
3110 if (*p)
3111 p++;
3112 }
3113 }
3114 continue;
3115 case 'c':
3116 /* Constant, e.g. from "const" in Pascal. */
3117 add_psymbol_to_list (namestring, p - namestring,
3118 VAR_NAMESPACE, LOC_CONST,
3119 &objfile->static_psymbols, sh.value,
3120 0, psymtab_language, objfile);
3121 continue;
3122
3123 case 'f':
3124 if (! pst)
3125 {
3126 int name_len = p - namestring;
3127 char *name = xmalloc (name_len + 1);
3128 memcpy (name, namestring, name_len);
3129 name[name_len] = '\0';
3130 complain (&function_outside_compilation_unit, name);
3131 xfree (name);
3132 }
3133 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3134 add_psymbol_to_list (namestring, p - namestring,
3135 VAR_NAMESPACE, LOC_BLOCK,
3136 &objfile->static_psymbols,
3137 0, sh.value,
3138 psymtab_language, objfile);
3139 continue;
3140
3141 /* Global functions were ignored here, but now they
3142 are put into the global psymtab like one would expect.
3143 They're also in the minimal symbol table. */
3144 case 'F':
3145 if (! pst)
3146 {
3147 int name_len = p - namestring;
3148 char *name = xmalloc (name_len + 1);
3149 memcpy (name, namestring, name_len);
3150 name[name_len] = '\0';
3151 complain (&function_outside_compilation_unit, name);
3152 xfree (name);
3153 }
3154 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3155 add_psymbol_to_list (namestring, p - namestring,
3156 VAR_NAMESPACE, LOC_BLOCK,
3157 &objfile->global_psymbols,
3158 0, sh.value,
3159 psymtab_language, objfile);
3160 continue;
3161
3162 /* Two things show up here (hopefully); static symbols of
3163 local scope (static used inside braces) or extensions
3164 of structure symbols. We can ignore both. */
3165 case 'V':
3166 case '(':
3167 case '0':
3168 case '1':
3169 case '2':
3170 case '3':
3171 case '4':
3172 case '5':
3173 case '6':
3174 case '7':
3175 case '8':
3176 case '9':
3177 case '-':
3178 case '#': /* for symbol identification (used in live ranges) */
3179 /* added to support cfront stabs strings */
3180 case 'Z': /* for definition continuations */
3181 case 'P': /* for prototypes */
3182 continue;
3183
3184 case ':':
3185 /* It is a C++ nested symbol. We don't need to record it
3186 (I don't think); if we try to look up foo::bar::baz,
3187 then symbols for the symtab containing foo should get
3188 read in, I think. */
3189 /* Someone says sun cc puts out symbols like
3190 /foo/baz/maclib::/usr/local/bin/maclib,
3191 which would get here with a symbol type of ':'. */
3192 continue;
3193
3194 default:
3195 /* Unexpected symbol descriptor. The second and subsequent stabs
3196 of a continued stab can show up here. The question is
3197 whether they ever can mimic a normal stab--it would be
3198 nice if not, since we certainly don't want to spend the
3199 time searching to the end of every string looking for
3200 a backslash. */
3201
3202 complain (&unknown_symchar_complaint, p[1]);
3203
3204 /* Ignore it; perhaps it is an extension that we don't
3205 know about. */
3206 continue;
3207 }
3208
3209 case N_EXCL:
3210 continue;
3211
3212 case N_ENDM:
3213 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
3214 /* Solaris 2 end of module, finish current partial
3215 symbol table. END_PSYMTAB will set
3216 pst->texthigh to the proper value, which is
3217 necessary if a module compiled without
3218 debugging info follows this module. */
3219 if (pst)
3220 {
3221 pst = (struct partial_symtab *) 0;
3222 includes_used = 0;
3223 dependencies_used = 0;
3224 }
3225 #endif
3226 continue;
3227
3228 case N_RBRAC:
3229 if (sh.value > save_pst->texthigh)
3230 save_pst->texthigh = sh.value;
3231 continue;
3232 case N_EINCL:
3233 case N_DSLINE:
3234 case N_BSLINE:
3235 case N_SSYM: /* Claim: Structure or union element.
3236 Hopefully, I can ignore this. */
3237 case N_ENTRY: /* Alternate entry point; can ignore. */
3238 case N_MAIN: /* Can definitely ignore this. */
3239 case N_CATCH: /* These are GNU C++ extensions */
3240 case N_EHDECL: /* that can safely be ignored here. */
3241 case N_LENG:
3242 case N_BCOMM:
3243 case N_ECOMM:
3244 case N_ECOML:
3245 case N_FNAME:
3246 case N_SLINE:
3247 case N_RSYM:
3248 case N_PSYM:
3249 case N_LBRAC:
3250 case N_NSYMS: /* Ultrix 4.0: symbol count */
3251 case N_DEFD: /* GNU Modula-2 */
3252 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
3253
3254 case N_OBJ: /* useless types from Solaris */
3255 case N_OPT:
3256 /* These symbols aren't interesting; don't worry about them */
3257
3258 continue;
3259
3260 default:
3261 /* If we haven't found it yet, ignore it. It's probably some
3262 new type we don't know about yet. */
3263 complain (&unknown_symtype_complaint,
3264 local_hex_string (type_code)); /*CUR_SYMBOL_TYPE*/
3265 continue;
3266 }
3267 if (stabstring
3268 && stabstring != debug_info->ss + fh->issBase + sh.iss)
3269 xfree (stabstring);
3270 }
3271 /* end - Handle continuation */
3272 }
3273 }
3274 else
3275 {
3276 for (cur_sdx = 0; cur_sdx < fh->csym;)
3277 {
3278 char *name;
3279 enum address_class class;
3280
3281 (*swap_sym_in) (cur_bfd,
3282 ((char *) debug_info->external_sym
3283 + ((fh->isymBase + cur_sdx)
3284 * external_sym_size)),
3285 &sh);
3286
3287 if (ECOFF_IS_STAB (&sh))
3288 {
3289 cur_sdx++;
3290 continue;
3291 }
3292
3293 /* Non absolute static symbols go into the minimal table. */
3294 if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
3295 || (sh.index == indexNil
3296 && (sh.st != stStatic || sh.sc == scAbs)))
3297 {
3298 /* FIXME, premature? */
3299 cur_sdx++;
3300 continue;
3301 }
3302
3303 name = debug_info->ss + fh->issBase + sh.iss;
3304
3305 switch (sh.sc)
3306 {
3307 case scText:
3308 case scRConst:
3309 /* The value of a stEnd symbol is the displacement from the
3310 corresponding start symbol value, do not relocate it. */
3311 if (sh.st != stEnd)
3312 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3313 break;
3314 case scData:
3315 case scSData:
3316 case scRData:
3317 case scPData:
3318 case scXData:
3319 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
3320 break;
3321 case scBss:
3322 case scSBss:
3323 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
3324 break;
3325 }
3326
3327 switch (sh.st)
3328 {
3329 CORE_ADDR high;
3330 CORE_ADDR procaddr;
3331 int new_sdx;
3332
3333 case stStaticProc:
3334 prim_record_minimal_symbol_and_info (name, sh.value,
3335 mst_file_text, NULL,
3336 SECT_OFF_TEXT (objfile), NULL,
3337 objfile);
3338
3339 /* FALLTHROUGH */
3340
3341 case stProc:
3342 /* Usually there is a local and a global stProc symbol
3343 for a function. This means that the function name
3344 has already been entered into the mimimal symbol table
3345 while processing the global symbols in pass 2 above.
3346 One notable exception is the PROGRAM name from
3347 f77 compiled executables, it is only put out as
3348 local stProc symbol, and a global MAIN__ stProc symbol
3349 points to it. It doesn't matter though, as gdb is
3350 still able to find the PROGRAM name via the partial
3351 symbol table, and the MAIN__ symbol via the minimal
3352 symbol table. */
3353 if (sh.st == stProc)
3354 add_psymbol_to_list (name, strlen (name),
3355 VAR_NAMESPACE, LOC_BLOCK,
3356 &objfile->global_psymbols,
3357 0, sh.value, psymtab_language, objfile);
3358 else
3359 add_psymbol_to_list (name, strlen (name),
3360 VAR_NAMESPACE, LOC_BLOCK,
3361 &objfile->static_psymbols,
3362 0, sh.value, psymtab_language, objfile);
3363
3364 /* Skip over procedure to next one. */
3365 if (sh.index >= hdr->iauxMax)
3366 {
3367 /* Should not happen, but does when cross-compiling
3368 with the MIPS compiler. FIXME -- pull later. */
3369 complain (&index_complaint, name);
3370 new_sdx = cur_sdx + 1; /* Don't skip at all */
3371 }
3372 else
3373 new_sdx = AUX_GET_ISYM (fh->fBigendian,
3374 (debug_info->external_aux
3375 + fh->iauxBase
3376 + sh.index));
3377 procaddr = sh.value;
3378
3379 if (new_sdx <= cur_sdx)
3380 {
3381 /* This should not happen either... FIXME. */
3382 complain (&aux_index_complaint, name);
3383 new_sdx = cur_sdx + 1; /* Don't skip backward */
3384 }
3385
3386 cur_sdx = new_sdx;
3387 (*swap_sym_in) (cur_bfd,
3388 ((char *) debug_info->external_sym
3389 + ((fh->isymBase + cur_sdx - 1)
3390 * external_sym_size)),
3391 &sh);
3392 if (sh.st != stEnd)
3393 continue;
3394
3395 /* Kludge for Irix 5.2 zero fh->adr. */
3396 if (!relocatable
3397 && (pst->textlow == 0 || procaddr < pst->textlow))
3398 pst->textlow = procaddr;
3399
3400 high = procaddr + sh.value;
3401 if (high > pst->texthigh)
3402 pst->texthigh = high;
3403 continue;
3404
3405 case stStatic: /* Variable */
3406 if (SC_IS_DATA (sh.sc))
3407 prim_record_minimal_symbol_and_info (name, sh.value,
3408 mst_file_data, NULL,
3409 SECT_OFF_DATA (objfile),
3410 NULL,
3411 objfile);
3412 else
3413 prim_record_minimal_symbol_and_info (name, sh.value,
3414 mst_file_bss, NULL,
3415 SECT_OFF_BSS (objfile),
3416 NULL,
3417 objfile);
3418 class = LOC_STATIC;
3419 break;
3420
3421 case stIndirect: /* Irix5 forward declaration */
3422 /* Skip forward declarations from Irix5 cc */
3423 goto skip;
3424
3425 case stTypedef: /* Typedef */
3426 /* Skip typedefs for forward declarations and opaque
3427 structs from alpha and mips cc. */
3428 if (sh.iss == 0 || has_opaque_xref (fh, &sh))
3429 goto skip;
3430 class = LOC_TYPEDEF;
3431 break;
3432
3433 case stConstant: /* Constant decl */
3434 class = LOC_CONST;
3435 break;
3436
3437 case stUnion:
3438 case stStruct:
3439 case stEnum:
3440 case stBlock: /* { }, str, un, enum */
3441 /* Do not create a partial symbol for cc unnamed aggregates
3442 and gcc empty aggregates. */
3443 if ((sh.sc == scInfo
3444 || SC_IS_COMMON (sh.sc))
3445 && sh.iss != 0
3446 && sh.index != cur_sdx + 2)
3447 {
3448 add_psymbol_to_list (name, strlen (name),
3449 STRUCT_NAMESPACE, LOC_TYPEDEF,
3450 &objfile->static_psymbols,
3451 0, (CORE_ADDR) 0,
3452 psymtab_language, objfile);
3453 }
3454 handle_psymbol_enumerators (objfile, fh, sh.st, sh.value);
3455
3456 /* Skip over the block */
3457 new_sdx = sh.index;
3458 if (new_sdx <= cur_sdx)
3459 {
3460 /* This happens with the Ultrix kernel. */
3461 complain (&block_index_complaint, name);
3462 new_sdx = cur_sdx + 1; /* Don't skip backward */
3463 }
3464 cur_sdx = new_sdx;
3465 continue;
3466
3467 case stFile: /* File headers */
3468 case stLabel: /* Labels */
3469 case stEnd: /* Ends of files */
3470 goto skip;
3471
3472 case stLocal: /* Local variables */
3473 /* Normally these are skipped because we skip over
3474 all blocks we see. However, these can occur
3475 as visible symbols in a .h file that contains code. */
3476 goto skip;
3477
3478 default:
3479 /* Both complaints are valid: one gives symbol name,
3480 the other the offending symbol type. */
3481 complain (&unknown_sym_complaint, name);
3482 complain (&unknown_st_complaint, sh.st);
3483 cur_sdx++;
3484 continue;
3485 }
3486 /* Use this gdb symbol */
3487 add_psymbol_to_list (name, strlen (name),
3488 VAR_NAMESPACE, class,
3489 &objfile->static_psymbols,
3490 0, sh.value, psymtab_language, objfile);
3491 skip:
3492 cur_sdx++; /* Go to next file symbol */
3493 }
3494
3495 /* Now do enter the external symbols. */
3496 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
3497 cur_sdx = fdr_to_pst[f_idx].n_globals;
3498 PST_PRIVATE (save_pst)->extern_count = cur_sdx;
3499 PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
3500 for (; --cur_sdx >= 0; ext_ptr++)
3501 {
3502 enum address_class class;
3503 SYMR *psh;
3504 char *name;
3505 CORE_ADDR svalue;
3506
3507 if (ext_ptr->ifd != f_idx)
3508 internal_error (__FILE__, __LINE__, "failed internal consistency check");
3509 psh = &ext_ptr->asym;
3510
3511 /* Do not add undefined symbols to the partial symbol table. */
3512 if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
3513 continue;
3514
3515 svalue = psh->value;
3516 switch (psh->sc)
3517 {
3518 case scText:
3519 case scRConst:
3520 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
3521 break;
3522 case scData:
3523 case scSData:
3524 case scRData:
3525 case scPData:
3526 case scXData:
3527 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
3528 break;
3529 case scBss:
3530 case scSBss:
3531 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
3532 break;
3533 }
3534
3535 switch (psh->st)
3536 {
3537 case stNil:
3538 /* These are generated for static symbols in .o files,
3539 ignore them. */
3540 continue;
3541 case stProc:
3542 case stStaticProc:
3543 /* External procedure symbols have been entered
3544 into the minimal symbol table in pass 2 above.
3545 Ignore them, as parse_external will ignore them too. */
3546 continue;
3547 case stLabel:
3548 class = LOC_LABEL;
3549 break;
3550 default:
3551 complain (&unknown_ext_complaint,
3552 debug_info->ssext + psh->iss);
3553 /* Fall through, pretend it's global. */
3554 case stGlobal:
3555 /* Global common symbols are resolved by the runtime loader,
3556 ignore them. */
3557 if (SC_IS_COMMON (psh->sc))
3558 continue;
3559
3560 class = LOC_STATIC;
3561 break;
3562 }
3563 name = debug_info->ssext + psh->iss;
3564 add_psymbol_to_list (name, strlen (name),
3565 VAR_NAMESPACE, class,
3566 &objfile->global_psymbols,
3567 0, svalue,
3568 psymtab_language, objfile);
3569 }
3570 }
3571
3572 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
3573 empty and put on the free list. */
3574 fdr_to_pst[f_idx].pst = end_psymtab (save_pst,
3575 psymtab_include_list, includes_used,
3576 -1, save_pst->texthigh,
3577 dependency_list, dependencies_used, textlow_not_set);
3578 includes_used = 0;
3579 dependencies_used = 0;
3580
3581 if (objfile->ei.entry_point >= save_pst->textlow &&
3582 objfile->ei.entry_point < save_pst->texthigh)
3583 {
3584 objfile->ei.entry_file_lowpc = save_pst->textlow;
3585 objfile->ei.entry_file_highpc = save_pst->texthigh;
3586 }
3587
3588 /* The objfile has its functions reordered if this partial symbol
3589 table overlaps any other partial symbol table.
3590 We cannot assume a reordered objfile if a partial symbol table
3591 is contained within another partial symbol table, as partial symbol
3592 tables for include files with executable code are contained
3593 within the partial symbol table for the including source file,
3594 and we do not want to flag the objfile reordered for these cases.
3595
3596 This strategy works well for Irix-5.2 shared libraries, but we
3597 might have to use a more elaborate (and slower) algorithm for
3598 other cases. */
3599 save_pst = fdr_to_pst[f_idx].pst;
3600 if (save_pst != NULL
3601 && save_pst->textlow != 0
3602 && !(objfile->flags & OBJF_REORDERED))
3603 {
3604 ALL_OBJFILE_PSYMTABS (objfile, pst)
3605 {
3606 if (save_pst != pst
3607 && save_pst->textlow >= pst->textlow
3608 && save_pst->textlow < pst->texthigh
3609 && save_pst->texthigh > pst->texthigh)
3610 {
3611 objfile->flags |= OBJF_REORDERED;
3612 break;
3613 }
3614 }
3615 }
3616 }
3617
3618 /* Now scan the FDRs for dependencies */
3619 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
3620 {
3621 fh = f_idx + debug_info->fdr;
3622 pst = fdr_to_pst[f_idx].pst;
3623
3624 if (pst == (struct partial_symtab *) NULL)
3625 continue;
3626
3627 /* This should catch stabs-in-ecoff. */
3628 if (fh->crfd <= 1)
3629 continue;
3630
3631 /* Skip the first file indirect entry as it is a self dependency
3632 for source files or a reverse .h -> .c dependency for header files. */
3633 pst->number_of_dependencies = 0;
3634 pst->dependencies =
3635 ((struct partial_symtab **)
3636 obstack_alloc (&objfile->psymbol_obstack,
3637 ((fh->crfd - 1)
3638 * sizeof (struct partial_symtab *))));
3639 for (s_idx = 1; s_idx < fh->crfd; s_idx++)
3640 {
3641 RFDT rh;
3642
3643 (*swap_rfd_in) (cur_bfd,
3644 ((char *) debug_info->external_rfd
3645 + (fh->rfdBase + s_idx) * external_rfd_size),
3646 &rh);
3647 if (rh < 0 || rh >= hdr->ifdMax)
3648 {
3649 complain (&bad_file_number_complaint, rh);
3650 continue;
3651 }
3652
3653 /* Skip self dependencies of header files. */
3654 if (rh == f_idx)
3655 continue;
3656
3657 /* Do not add to dependeny list if psymtab was empty. */
3658 if (fdr_to_pst[rh].pst == (struct partial_symtab *) NULL)
3659 continue;
3660 pst->dependencies[pst->number_of_dependencies++] = fdr_to_pst[rh].pst;
3661 }
3662 }
3663
3664 /* Remove the dummy psymtab created for -O3 images above, if it is
3665 still empty, to enable the detection of stripped executables. */
3666 if (objfile->psymtabs->next == NULL
3667 && objfile->psymtabs->number_of_dependencies == 0
3668 && objfile->psymtabs->n_global_syms == 0
3669 && objfile->psymtabs->n_static_syms == 0)
3670 objfile->psymtabs = NULL;
3671 do_cleanups (old_chain);
3672 }
3673
3674 /* If the current psymbol has an enumerated type, we need to add
3675 all the the enum constants to the partial symbol table. */
3676
3677 static void
3678 handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
3679 CORE_ADDR svalue)
3680 {
3681 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
3682 void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
3683 char *ext_sym = ((char *) debug_info->external_sym
3684 + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
3685 SYMR sh;
3686 TIR tir;
3687
3688 switch (stype)
3689 {
3690 case stEnum:
3691 break;
3692
3693 case stBlock:
3694 /* It is an enumerated type if the next symbol entry is a stMember
3695 and its auxiliary index is indexNil or its auxiliary entry
3696 is a plain btNil or btVoid.
3697 Alpha cc -migrate enums are recognized by a zero index and
3698 a zero symbol value.
3699 DU 4.0 cc enums are recognized by a member type of btEnum without
3700 qualifiers and a zero symbol value. */
3701 (*swap_sym_in) (cur_bfd, ext_sym, &sh);
3702 if (sh.st != stMember)
3703 return;
3704
3705 if (sh.index == indexNil
3706 || (sh.index == 0 && svalue == 0))
3707 break;
3708 (*debug_swap->swap_tir_in) (fh->fBigendian,
3709 &(debug_info->external_aux
3710 + fh->iauxBase + sh.index)->a_ti,
3711 &tir);
3712 if ((tir.bt != btNil
3713 && tir.bt != btVoid
3714 && (tir.bt != btEnum || svalue != 0))
3715 || tir.tq0 != tqNil)
3716 return;
3717 break;
3718
3719 default:
3720 return;
3721 }
3722
3723 for (;;)
3724 {
3725 char *name;
3726
3727 (*swap_sym_in) (cur_bfd, ext_sym, &sh);
3728 if (sh.st != stMember)
3729 break;
3730 name = debug_info->ss + cur_fdr->issBase + sh.iss;
3731
3732 /* Note that the value doesn't matter for enum constants
3733 in psymtabs, just in symtabs. */
3734 add_psymbol_to_list (name, strlen (name),
3735 VAR_NAMESPACE, LOC_CONST,
3736 &objfile->static_psymbols, 0,
3737 (CORE_ADDR) 0, psymtab_language, objfile);
3738 ext_sym += external_sym_size;
3739 }
3740 }
3741
3742 /* Get the next symbol. OBJFILE is unused. */
3743
3744 static char *
3745 mdebug_next_symbol_text (struct objfile *objfile)
3746 {
3747 SYMR sh;
3748
3749 cur_sdx++;
3750 (*debug_swap->swap_sym_in) (cur_bfd,
3751 ((char *) debug_info->external_sym
3752 + ((cur_fdr->isymBase + cur_sdx)
3753 * debug_swap->external_sym_size)),
3754 &sh);
3755 return debug_info->ss + cur_fdr->issBase + sh.iss;
3756 }
3757
3758 /* Ancillary function to psymtab_to_symtab(). Does all the work
3759 for turning the partial symtab PST into a symtab, recurring
3760 first on all dependent psymtabs. The argument FILENAME is
3761 only passed so we can see in debug stack traces what file
3762 is being read.
3763
3764 This function has a split personality, based on whether the
3765 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
3766 The flow of control and even the memory allocation differs. FIXME. */
3767
3768 static void
3769 psymtab_to_symtab_1 (struct partial_symtab *pst, char *filename)
3770 {
3771 bfd_size_type external_sym_size;
3772 bfd_size_type external_pdr_size;
3773 void (*swap_sym_in) (bfd *, void *, SYMR *);
3774 void (*swap_pdr_in) (bfd *, void *, PDR *);
3775 int i;
3776 struct symtab *st = NULL;
3777 FDR *fh;
3778 struct linetable *lines;
3779 CORE_ADDR lowest_pdr_addr = 0;
3780 int last_symtab_ended = 0;
3781
3782 if (pst->readin)
3783 return;
3784 pst->readin = 1;
3785
3786 /* Read in all partial symbtabs on which this one is dependent.
3787 NOTE that we do have circular dependencies, sigh. We solved
3788 that by setting pst->readin before this point. */
3789
3790 for (i = 0; i < pst->number_of_dependencies; i++)
3791 if (!pst->dependencies[i]->readin)
3792 {
3793 /* Inform about additional files to be read in. */
3794 if (info_verbose)
3795 {
3796 fputs_filtered (" ", gdb_stdout);
3797 wrap_here ("");
3798 fputs_filtered ("and ", gdb_stdout);
3799 wrap_here ("");
3800 printf_filtered ("%s...",
3801 pst->dependencies[i]->filename);
3802 wrap_here (""); /* Flush output */
3803 gdb_flush (gdb_stdout);
3804 }
3805 /* We only pass the filename for debug purposes */
3806 psymtab_to_symtab_1 (pst->dependencies[i],
3807 pst->dependencies[i]->filename);
3808 }
3809
3810 /* Do nothing if this is a dummy psymtab. */
3811
3812 if (pst->n_global_syms == 0 && pst->n_static_syms == 0
3813 && pst->textlow == 0 && pst->texthigh == 0)
3814 return;
3815
3816 /* Now read the symbols for this symtab */
3817
3818 cur_bfd = CUR_BFD (pst);
3819 debug_swap = DEBUG_SWAP (pst);
3820 debug_info = DEBUG_INFO (pst);
3821 pending_list = PENDING_LIST (pst);
3822 external_sym_size = debug_swap->external_sym_size;
3823 external_pdr_size = debug_swap->external_pdr_size;
3824 swap_sym_in = debug_swap->swap_sym_in;
3825 swap_pdr_in = debug_swap->swap_pdr_in;
3826 current_objfile = pst->objfile;
3827 cur_fd = FDR_IDX (pst);
3828 fh = ((cur_fd == -1)
3829 ? (FDR *) NULL
3830 : debug_info->fdr + cur_fd);
3831 cur_fdr = fh;
3832
3833 /* See comment in parse_partial_symbols about the @stabs sentinel. */
3834 processing_gcc_compilation = 0;
3835 if (fh != (FDR *) NULL && fh->csym >= 2)
3836 {
3837 SYMR sh;
3838
3839 (*swap_sym_in) (cur_bfd,
3840 ((char *) debug_info->external_sym
3841 + (fh->isymBase + 1) * external_sym_size),
3842 &sh);
3843 if (STREQ (debug_info->ss + fh->issBase + sh.iss,
3844 stabs_symbol))
3845 {
3846 /* We indicate that this is a GCC compilation so that certain
3847 features will be enabled in stabsread/dbxread. */
3848 processing_gcc_compilation = 2;
3849 }
3850 }
3851
3852 if (processing_gcc_compilation != 0)
3853 {
3854
3855 /* This symbol table contains stabs-in-ecoff entries. */
3856
3857 /* Parse local symbols first */
3858
3859 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */
3860 {
3861 current_objfile = NULL;
3862 return;
3863 }
3864 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
3865 {
3866 SYMR sh;
3867 char *name;
3868 CORE_ADDR valu;
3869
3870 (*swap_sym_in) (cur_bfd,
3871 (((char *) debug_info->external_sym)
3872 + (fh->isymBase + cur_sdx) * external_sym_size),
3873 &sh);
3874 name = debug_info->ss + fh->issBase + sh.iss;
3875 valu = sh.value;
3876 /* XXX This is a hack. It will go away! */
3877 if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
3878 {
3879 int type_code = ECOFF_UNMARK_STAB (sh.index);
3880
3881 /* We should never get non N_STAB symbols here, but they
3882 should be harmless, so keep process_one_symbol from
3883 complaining about them. */
3884 if (type_code & N_STAB)
3885 {
3886 /* If we found a trailing N_SO with no name, process
3887 it here instead of in process_one_symbol, so we
3888 can keep a handle to its symtab. The symtab
3889 would otherwise be ended twice, once in
3890 process_one_symbol, and once after this loop. */
3891 if (type_code == N_SO
3892 && last_source_file
3893 && previous_stab_code != (unsigned char) N_SO
3894 && *name == '\000')
3895 {
3896 valu += ANOFFSET (pst->section_offsets,
3897 SECT_OFF_TEXT (pst->objfile));
3898 previous_stab_code = N_SO;
3899 st = end_symtab (valu, pst->objfile,
3900 SECT_OFF_TEXT (pst->objfile));
3901 end_stabs ();
3902 last_symtab_ended = 1;
3903 }
3904 else
3905 {
3906 last_symtab_ended = 0;
3907 process_one_symbol (type_code, 0, valu, name,
3908 pst->section_offsets, pst->objfile);
3909 }
3910 }
3911 /* Similarly a hack. */
3912 else if (name[0] == '#')
3913 {
3914 process_one_symbol (N_SLINE, 0, valu, name,
3915 pst->section_offsets, pst->objfile);
3916 }
3917 if (type_code == N_FUN)
3918 {
3919 /* Make up special symbol to contain
3920 procedure specific info */
3921 struct mips_extra_func_info *e =
3922 ((struct mips_extra_func_info *)
3923 obstack_alloc (&current_objfile->symbol_obstack,
3924 sizeof (struct mips_extra_func_info)));
3925 struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
3926
3927 memset (e, 0, sizeof (struct mips_extra_func_info));
3928 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
3929 SYMBOL_CLASS (s) = LOC_CONST;
3930 SYMBOL_TYPE (s) = mdebug_type_void;
3931 SYMBOL_VALUE (s) = (long) e;
3932 e->pdr.framereg = -1;
3933 add_symbol_to_list (s, &local_symbols);
3934 }
3935 }
3936 else if (sh.st == stLabel)
3937 {
3938 if (sh.index == indexNil)
3939 {
3940 /* This is what the gcc2_compiled and __gnu_compiled_*
3941 show up as. So don't complain. */
3942 ;
3943 }
3944 else
3945 {
3946 /* Handle encoded stab line number. */
3947 valu += ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile));
3948 record_line (current_subfile, sh.index, valu);
3949 }
3950 }
3951 else if (sh.st == stProc || sh.st == stStaticProc
3952 || sh.st == stStatic || sh.st == stEnd)
3953 /* These are generated by gcc-2.x, do not complain */
3954 ;
3955 else
3956 complain (&stab_unknown_complaint, name);
3957 }
3958
3959 if (! last_symtab_ended)
3960 {
3961 st = end_symtab (pst->texthigh, pst->objfile, SECT_OFF_TEXT (pst->objfile));
3962 end_stabs ();
3963 }
3964
3965 /* Sort the symbol table now, we are done adding symbols to it.
3966 We must do this before parse_procedure calls lookup_symbol. */
3967 sort_symtab_syms (st);
3968
3969 /* There used to be a call to sort_blocks here, but this should not
3970 be necessary for stabs symtabs. And as sort_blocks modifies the
3971 start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
3972 it did the wrong thing if the first procedure in a file was
3973 generated via asm statements. */
3974
3975 /* Fill in procedure info next. */
3976 if (fh->cpd > 0)
3977 {
3978 PDR *pr_block;
3979 struct cleanup *old_chain;
3980 char *pdr_ptr;
3981 char *pdr_end;
3982 PDR *pdr_in;
3983 PDR *pdr_in_end;
3984
3985 pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
3986 old_chain = make_cleanup (xfree, pr_block);
3987
3988 pdr_ptr = ((char *) debug_info->external_pdr
3989 + fh->ipdFirst * external_pdr_size);
3990 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
3991 pdr_in = pr_block;
3992 for (;
3993 pdr_ptr < pdr_end;
3994 pdr_ptr += external_pdr_size, pdr_in++)
3995 {
3996 (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
3997
3998 /* Determine lowest PDR address, the PDRs are not always
3999 sorted. */
4000 if (pdr_in == pr_block)
4001 lowest_pdr_addr = pdr_in->adr;
4002 else if (pdr_in->adr < lowest_pdr_addr)
4003 lowest_pdr_addr = pdr_in->adr;
4004 }
4005
4006 pdr_in = pr_block;
4007 pdr_in_end = pdr_in + fh->cpd;
4008 for (; pdr_in < pdr_in_end; pdr_in++)
4009 parse_procedure (pdr_in, st, pst);
4010
4011 do_cleanups (old_chain);
4012 }
4013 }
4014 else
4015 {
4016 /* This symbol table contains ordinary ecoff entries. */
4017
4018 int f_max;
4019 int maxlines;
4020 EXTR *ext_ptr;
4021
4022 /* How many symbols will we need */
4023 /* FIXME, this does not count enum values. */
4024 f_max = pst->n_global_syms + pst->n_static_syms;
4025 if (fh == 0)
4026 {
4027 maxlines = 0;
4028 st = new_symtab ("unknown", f_max, 0, pst->objfile);
4029 }
4030 else
4031 {
4032 f_max += fh->csym + fh->cpd;
4033 maxlines = 2 * fh->cline;
4034 st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
4035
4036 /* The proper language was already determined when building
4037 the psymtab, use it. */
4038 st->language = PST_PRIVATE (pst)->pst_language;
4039 }
4040
4041 psymtab_language = st->language;
4042
4043 lines = LINETABLE (st);
4044
4045 /* Get a new lexical context */
4046
4047 push_parse_stack ();
4048 top_stack->cur_st = st;
4049 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
4050 STATIC_BLOCK);
4051 BLOCK_START (top_stack->cur_block) = pst->textlow;
4052 BLOCK_END (top_stack->cur_block) = 0;
4053 top_stack->blocktype = stFile;
4054 top_stack->maxsyms = 2 * f_max;
4055 top_stack->cur_type = 0;
4056 top_stack->procadr = 0;
4057 top_stack->numargs = 0;
4058 found_ecoff_debugging_info = 0;
4059
4060 if (fh)
4061 {
4062 char *sym_ptr;
4063 char *sym_end;
4064
4065 /* Parse local symbols first */
4066 sym_ptr = ((char *) debug_info->external_sym
4067 + fh->isymBase * external_sym_size);
4068 sym_end = sym_ptr + fh->csym * external_sym_size;
4069 while (sym_ptr < sym_end)
4070 {
4071 SYMR sh;
4072 int c;
4073
4074 (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
4075 c = parse_symbol (&sh,
4076 debug_info->external_aux + fh->iauxBase,
4077 sym_ptr, fh->fBigendian, pst->section_offsets, pst->objfile);
4078 sym_ptr += c * external_sym_size;
4079 }
4080
4081 /* Linenumbers. At the end, check if we can save memory.
4082 parse_lines has to look ahead an arbitrary number of PDR
4083 structures, so we swap them all first. */
4084 if (fh->cpd > 0)
4085 {
4086 PDR *pr_block;
4087 struct cleanup *old_chain;
4088 char *pdr_ptr;
4089 char *pdr_end;
4090 PDR *pdr_in;
4091 PDR *pdr_in_end;
4092
4093 pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
4094
4095 old_chain = make_cleanup (xfree, pr_block);
4096
4097 pdr_ptr = ((char *) debug_info->external_pdr
4098 + fh->ipdFirst * external_pdr_size);
4099 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
4100 pdr_in = pr_block;
4101 for (;
4102 pdr_ptr < pdr_end;
4103 pdr_ptr += external_pdr_size, pdr_in++)
4104 {
4105 (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
4106
4107 /* Determine lowest PDR address, the PDRs are not always
4108 sorted. */
4109 if (pdr_in == pr_block)
4110 lowest_pdr_addr = pdr_in->adr;
4111 else if (pdr_in->adr < lowest_pdr_addr)
4112 lowest_pdr_addr = pdr_in->adr;
4113 }
4114
4115 parse_lines (fh, pr_block, lines, maxlines, pst, lowest_pdr_addr);
4116 if (lines->nitems < fh->cline)
4117 lines = shrink_linetable (lines);
4118
4119 /* Fill in procedure info next. */
4120 pdr_in = pr_block;
4121 pdr_in_end = pdr_in + fh->cpd;
4122 for (; pdr_in < pdr_in_end; pdr_in++)
4123 parse_procedure (pdr_in, 0, pst);
4124
4125 do_cleanups (old_chain);
4126 }
4127 }
4128
4129 LINETABLE (st) = lines;
4130
4131 /* .. and our share of externals.
4132 XXX use the global list to speed up things here. how?
4133 FIXME, Maybe quit once we have found the right number of ext's? */
4134 top_stack->cur_st = st;
4135 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
4136 GLOBAL_BLOCK);
4137 top_stack->blocktype = stFile;
4138 top_stack->maxsyms
4139 = (debug_info->symbolic_header.isymMax
4140 + debug_info->symbolic_header.ipdMax
4141 + debug_info->symbolic_header.iextMax);
4142
4143 ext_ptr = PST_PRIVATE (pst)->extern_tab;
4144 for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
4145 parse_external (ext_ptr, fh->fBigendian, pst->section_offsets, pst->objfile);
4146
4147 /* If there are undefined symbols, tell the user.
4148 The alpha has an undefined symbol for every symbol that is
4149 from a shared library, so tell the user only if verbose is on. */
4150 if (info_verbose && n_undef_symbols)
4151 {
4152 printf_filtered ("File %s contains %d unresolved references:",
4153 st->filename, n_undef_symbols);
4154 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
4155 n_undef_vars, n_undef_procs, n_undef_labels);
4156 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
4157
4158 }
4159 pop_parse_stack ();
4160
4161 st->primary = 1;
4162
4163 /* Sort the symbol table now, we are done adding symbols to it. */
4164 sort_symtab_syms (st);
4165
4166 sort_blocks (st);
4167 }
4168
4169 /* Now link the psymtab and the symtab. */
4170 pst->symtab = st;
4171
4172 current_objfile = NULL;
4173 }
4174 \f
4175 /* Ancillary parsing procedures. */
4176
4177 /* Return 1 if the symbol pointed to by SH has a cross reference
4178 to an opaque aggregate type, else 0. */
4179
4180 static int
4181 has_opaque_xref (FDR *fh, SYMR *sh)
4182 {
4183 TIR tir;
4184 union aux_ext *ax;
4185 RNDXR rn[1];
4186 unsigned int rf;
4187
4188 if (sh->index == indexNil)
4189 return 0;
4190
4191 ax = debug_info->external_aux + fh->iauxBase + sh->index;
4192 (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
4193 if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
4194 return 0;
4195
4196 ax++;
4197 (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
4198 if (rn->rfd == 0xfff)
4199 rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
4200 else
4201 rf = rn->rfd;
4202 if (rf != -1)
4203 return 0;
4204 return 1;
4205 }
4206
4207 /* Lookup the type at relative index RN. Return it in TPP
4208 if found and in any event come up with its name PNAME.
4209 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
4210 Return value says how many aux symbols we ate. */
4211
4212 static int
4213 cross_ref (int fd, union aux_ext *ax, struct type **tpp, enum type_code type_code, /* Use to alloc new type if none is found. */
4214 char **pname, int bigend, char *sym_name)
4215 {
4216 RNDXR rn[1];
4217 unsigned int rf;
4218 int result = 1;
4219 FDR *fh;
4220 char *esh;
4221 SYMR sh;
4222 int xref_fd;
4223 struct mdebug_pending *pend;
4224
4225 *tpp = (struct type *) NULL;
4226
4227 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
4228
4229 /* Escape index means 'the next one' */
4230 if (rn->rfd == 0xfff)
4231 {
4232 result++;
4233 rf = AUX_GET_ISYM (bigend, ax + 1);
4234 }
4235 else
4236 {
4237 rf = rn->rfd;
4238 }
4239
4240 /* mips cc uses a rf of -1 for opaque struct definitions.
4241 Set TYPE_FLAG_STUB for these types so that check_typedef will
4242 resolve them if the struct gets defined in another compilation unit. */
4243 if (rf == -1)
4244 {
4245 *pname = "<undefined>";
4246 *tpp = init_type (type_code, 0, TYPE_FLAG_STUB, (char *) NULL, current_objfile);
4247 return result;
4248 }
4249
4250 /* mips cc uses an escaped rn->index of 0 for struct return types
4251 of procedures that were compiled without -g. These will always remain
4252 undefined. */
4253 if (rn->rfd == 0xfff && rn->index == 0)
4254 {
4255 *pname = "<undefined>";
4256 return result;
4257 }
4258
4259 /* Find the relative file descriptor and the symbol in it. */
4260 fh = get_rfd (fd, rf);
4261 xref_fd = fh - debug_info->fdr;
4262
4263 if (rn->index >= fh->csym)
4264 {
4265 /* File indirect entry is corrupt. */
4266 *pname = "<illegal>";
4267 complain (&bad_rfd_entry_complaint,
4268 sym_name, xref_fd, rn->index);
4269 return result;
4270 }
4271
4272 /* If we have processed this symbol then we left a forwarding
4273 pointer to the type in the pending list. If not, we`ll put
4274 it in a list of pending types, to be processed later when
4275 the file will be. In any event, we collect the name for the
4276 type here. */
4277
4278 esh = ((char *) debug_info->external_sym
4279 + ((fh->isymBase + rn->index)
4280 * debug_swap->external_sym_size));
4281 (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
4282
4283 /* Make sure that this type of cross reference can be handled. */
4284 if ((sh.sc != scInfo
4285 || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
4286 && sh.st != stStruct && sh.st != stUnion
4287 && sh.st != stEnum))
4288 && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
4289 {
4290 /* File indirect entry is corrupt. */
4291 *pname = "<illegal>";
4292 complain (&bad_rfd_entry_complaint,
4293 sym_name, xref_fd, rn->index);
4294 return result;
4295 }
4296
4297 *pname = debug_info->ss + fh->issBase + sh.iss;
4298
4299 pend = is_pending_symbol (fh, esh);
4300 if (pend)
4301 *tpp = pend->t;
4302 else
4303 {
4304 /* We have not yet seen this type. */
4305
4306 if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
4307 {
4308 TIR tir;
4309
4310 /* alpha cc puts out a stTypedef with a sh.iss of zero for
4311 two cases:
4312 a) forward declarations of structs/unions/enums which are not
4313 defined in this compilation unit.
4314 For these the type will be void. This is a bad design decision
4315 as cross referencing across compilation units is impossible
4316 due to the missing name.
4317 b) forward declarations of structs/unions/enums/typedefs which
4318 are defined later in this file or in another file in the same
4319 compilation unit. Irix5 cc uses a stIndirect symbol for this.
4320 Simply cross reference those again to get the true type.
4321 The forward references are not entered in the pending list and
4322 in the symbol table. */
4323
4324 (*debug_swap->swap_tir_in) (bigend,
4325 &(debug_info->external_aux
4326 + fh->iauxBase + sh.index)->a_ti,
4327 &tir);
4328 if (tir.tq0 != tqNil)
4329 complain (&illegal_forward_tq0_complaint, sym_name);
4330 switch (tir.bt)
4331 {
4332 case btVoid:
4333 *tpp = init_type (type_code, 0, 0, (char *) NULL,
4334 current_objfile);
4335 *pname = "<undefined>";
4336 break;
4337
4338 case btStruct:
4339 case btUnion:
4340 case btEnum:
4341 cross_ref (xref_fd,
4342 (debug_info->external_aux
4343 + fh->iauxBase + sh.index + 1),
4344 tpp, type_code, pname,
4345 fh->fBigendian, sym_name);
4346 break;
4347
4348 case btTypedef:
4349 /* Follow a forward typedef. This might recursively
4350 call cross_ref till we get a non typedef'ed type.
4351 FIXME: This is not correct behaviour, but gdb currently
4352 cannot handle typedefs without type copying. Type
4353 copying is impossible as we might have mutual forward
4354 references between two files and the copied type would not
4355 get filled in when we later parse its definition. */
4356 *tpp = parse_type (xref_fd,
4357 debug_info->external_aux + fh->iauxBase,
4358 sh.index,
4359 (int *) NULL,
4360 fh->fBigendian,
4361 debug_info->ss + fh->issBase + sh.iss);
4362 add_pending (fh, esh, *tpp);
4363 break;
4364
4365 default:
4366 complain (&illegal_forward_bt_complaint, tir.bt, sym_name);
4367 *tpp = init_type (type_code, 0, 0, (char *) NULL,
4368 current_objfile);
4369 break;
4370 }
4371 return result;
4372 }
4373 else if (sh.st == stTypedef)
4374 {
4375 /* Parse the type for a normal typedef. This might recursively call
4376 cross_ref till we get a non typedef'ed type.
4377 FIXME: This is not correct behaviour, but gdb currently
4378 cannot handle typedefs without type copying. But type copying is
4379 impossible as we might have mutual forward references between
4380 two files and the copied type would not get filled in when
4381 we later parse its definition. */
4382 *tpp = parse_type (xref_fd,
4383 debug_info->external_aux + fh->iauxBase,
4384 sh.index,
4385 (int *) NULL,
4386 fh->fBigendian,
4387 debug_info->ss + fh->issBase + sh.iss);
4388 }
4389 else
4390 {
4391 /* Cross reference to a struct/union/enum which is defined
4392 in another file in the same compilation unit but that file
4393 has not been parsed yet.
4394 Initialize the type only, it will be filled in when
4395 it's definition is parsed. */
4396 *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
4397 }
4398 add_pending (fh, esh, *tpp);
4399 }
4400
4401 /* We used one auxent normally, two if we got a "next one" rf. */
4402 return result;
4403 }
4404
4405
4406 /* Quick&dirty lookup procedure, to avoid the MI ones that require
4407 keeping the symtab sorted */
4408
4409 static struct symbol *
4410 mylookup_symbol (char *name, register struct block *block,
4411 namespace_enum namespace, enum address_class class)
4412 {
4413 int i, inc;
4414 struct symbol *sym;
4415
4416 inc = name[0];
4417 ALL_BLOCK_SYMBOLS (block, i, sym)
4418 {
4419 if (SYMBOL_NAME (sym)[0] == inc
4420 && SYMBOL_NAMESPACE (sym) == namespace
4421 && SYMBOL_CLASS (sym) == class
4422 && strcmp (SYMBOL_NAME (sym), name) == 0)
4423 return sym;
4424 }
4425
4426 block = BLOCK_SUPERBLOCK (block);
4427 if (block)
4428 return mylookup_symbol (name, block, namespace, class);
4429 return 0;
4430 }
4431
4432
4433 /* Add a new symbol S to a block B.
4434 Infrequently, we will need to reallocate the block to make it bigger.
4435 We only detect this case when adding to top_stack->cur_block, since
4436 that's the only time we know how big the block is. FIXME. */
4437
4438 static void
4439 add_symbol (struct symbol *s, struct block *b)
4440 {
4441 int nsyms = BLOCK_NSYMS (b)++;
4442 struct block *origb;
4443 struct parse_stack *stackp;
4444
4445 if (b == top_stack->cur_block &&
4446 nsyms >= top_stack->maxsyms)
4447 {
4448 complain (&block_overflow_complaint, SYMBOL_NAME (s));
4449 /* In this case shrink_block is actually grow_block, since
4450 BLOCK_NSYMS(b) is larger than its current size. */
4451 origb = b;
4452 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
4453
4454 /* Now run through the stack replacing pointers to the
4455 original block. shrink_block has already done this
4456 for the blockvector and BLOCK_FUNCTION. */
4457 for (stackp = top_stack; stackp; stackp = stackp->next)
4458 {
4459 if (stackp->cur_block == origb)
4460 {
4461 stackp->cur_block = b;
4462 stackp->maxsyms = BLOCK_NSYMS (b);
4463 }
4464 }
4465 }
4466 BLOCK_SYM (b, nsyms) = s;
4467 }
4468
4469 /* Add a new block B to a symtab S */
4470
4471 static void
4472 add_block (struct block *b, struct symtab *s)
4473 {
4474 struct blockvector *bv = BLOCKVECTOR (s);
4475
4476 bv = (struct blockvector *) xrealloc ((void *) bv,
4477 (sizeof (struct blockvector)
4478 + BLOCKVECTOR_NBLOCKS (bv)
4479 * sizeof (bv->block)));
4480 if (bv != BLOCKVECTOR (s))
4481 BLOCKVECTOR (s) = bv;
4482
4483 BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
4484 }
4485
4486 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
4487 MIPS' linenumber encoding might need more than one byte
4488 to describe it, LAST is used to detect these continuation lines.
4489
4490 Combining lines with the same line number seems like a bad idea.
4491 E.g: There could be a line number entry with the same line number after the
4492 prologue and GDB should not ignore it (this is a better way to find
4493 a prologue than mips_skip_prologue).
4494 But due to the compressed line table format there are line number entries
4495 for the same line which are needed to bridge the gap to the next
4496 line number entry. These entries have a bogus address info with them
4497 and we are unable to tell them from intended duplicate line number
4498 entries.
4499 This is another reason why -ggdb debugging format is preferable. */
4500
4501 static int
4502 add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
4503 {
4504 /* DEC c89 sometimes produces zero linenos which confuse gdb.
4505 Change them to something sensible. */
4506 if (lineno == 0)
4507 lineno = 1;
4508 if (last == 0)
4509 last = -2; /* make sure we record first line */
4510
4511 if (last == lineno) /* skip continuation lines */
4512 return lineno;
4513
4514 lt->item[lt->nitems].line = lineno;
4515 lt->item[lt->nitems++].pc = adr << 2;
4516 return lineno;
4517 }
4518 \f
4519 /* Sorting and reordering procedures */
4520
4521 /* Blocks with a smaller low bound should come first */
4522
4523 static int
4524 compare_blocks (const void *arg1, const void *arg2)
4525 {
4526 register int addr_diff;
4527 struct block **b1 = (struct block **) arg1;
4528 struct block **b2 = (struct block **) arg2;
4529
4530 addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
4531 if (addr_diff == 0)
4532 return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
4533 return addr_diff;
4534 }
4535
4536 /* Sort the blocks of a symtab S.
4537 Reorder the blocks in the blockvector by code-address,
4538 as required by some MI search routines */
4539
4540 static void
4541 sort_blocks (struct symtab *s)
4542 {
4543 struct blockvector *bv = BLOCKVECTOR (s);
4544
4545 if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
4546 {
4547 /* Cosmetic */
4548 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
4549 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
4550 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
4551 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
4552 return;
4553 }
4554 /*
4555 * This is very unfortunate: normally all functions are compiled in
4556 * the order they are found, but if the file is compiled -O3 things
4557 * are very different. It would be nice to find a reliable test
4558 * to detect -O3 images in advance.
4559 */
4560 if (BLOCKVECTOR_NBLOCKS (bv) > 3)
4561 qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
4562 BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
4563 sizeof (struct block *),
4564 compare_blocks);
4565
4566 {
4567 register CORE_ADDR high = 0;
4568 register int i, j = BLOCKVECTOR_NBLOCKS (bv);
4569
4570 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
4571 if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
4572 high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
4573 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
4574 }
4575
4576 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
4577 BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
4578
4579 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
4580 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
4581 BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
4582 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
4583 }
4584 \f
4585
4586 /* Constructor/restructor/destructor procedures */
4587
4588 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
4589 MAXSYMS and linenumbers MAXLINES we'll put in it */
4590
4591 static struct symtab *
4592 new_symtab (char *name, int maxsyms, int maxlines, struct objfile *objfile)
4593 {
4594 struct symtab *s = allocate_symtab (name, objfile);
4595
4596 LINETABLE (s) = new_linetable (maxlines);
4597
4598 /* All symtabs must have at least two blocks */
4599 BLOCKVECTOR (s) = new_bvect (2);
4600 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
4601 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
4602 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
4603 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
4604
4605 s->free_code = free_linetable;
4606 s->debugformat = obsavestring ("ECOFF", 5,
4607 &objfile->symbol_obstack);
4608 return (s);
4609 }
4610
4611 /* Allocate a new partial_symtab NAME */
4612
4613 static struct partial_symtab *
4614 new_psymtab (char *name, struct objfile *objfile)
4615 {
4616 struct partial_symtab *psymtab;
4617
4618 psymtab = allocate_psymtab (name, objfile);
4619 psymtab->section_offsets = objfile->section_offsets;
4620
4621 /* Keep a backpointer to the file's symbols */
4622
4623 psymtab->read_symtab_private = ((char *)
4624 obstack_alloc (&objfile->psymbol_obstack,
4625 sizeof (struct symloc)));
4626 memset (psymtab->read_symtab_private, 0, sizeof (struct symloc));
4627 CUR_BFD (psymtab) = cur_bfd;
4628 DEBUG_SWAP (psymtab) = debug_swap;
4629 DEBUG_INFO (psymtab) = debug_info;
4630 PENDING_LIST (psymtab) = pending_list;
4631
4632 /* The way to turn this into a symtab is to call... */
4633 psymtab->read_symtab = mdebug_psymtab_to_symtab;
4634 return (psymtab);
4635 }
4636
4637
4638 /* Allocate a linetable array of the given SIZE. Since the struct
4639 already includes one item, we subtract one when calculating the
4640 proper size to allocate. */
4641
4642 static struct linetable *
4643 new_linetable (int size)
4644 {
4645 struct linetable *l;
4646
4647 size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
4648 l = (struct linetable *) xmalloc (size);
4649 l->nitems = 0;
4650 return l;
4651 }
4652
4653 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
4654 I am not so sure about the 3.4 ones.
4655
4656 Since the struct linetable already includes one item, we subtract one when
4657 calculating the proper size to allocate. */
4658
4659 static struct linetable *
4660 shrink_linetable (struct linetable *lt)
4661 {
4662
4663 return (struct linetable *) xrealloc ((void *) lt,
4664 (sizeof (struct linetable)
4665 + ((lt->nitems - 1)
4666 * sizeof (lt->item))));
4667 }
4668
4669 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
4670
4671 static struct blockvector *
4672 new_bvect (int nblocks)
4673 {
4674 struct blockvector *bv;
4675 int size;
4676
4677 size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
4678 bv = (struct blockvector *) xzalloc (size);
4679
4680 BLOCKVECTOR_NBLOCKS (bv) = nblocks;
4681
4682 return bv;
4683 }
4684
4685 /* Allocate and zero a new block of MAXSYMS symbols */
4686
4687 static struct block *
4688 new_block (int maxsyms)
4689 {
4690 int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
4691
4692 return (struct block *) xzalloc (size);
4693 }
4694
4695 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
4696 Shrink_block can also be used by add_symbol to grow a block. */
4697
4698 static struct block *
4699 shrink_block (struct block *b, struct symtab *s)
4700 {
4701 struct block *new;
4702 struct blockvector *bv = BLOCKVECTOR (s);
4703 int i;
4704
4705 /* Just reallocate it and fix references to the old one */
4706
4707 new = (struct block *) xrealloc ((void *) b,
4708 (sizeof (struct block)
4709 + ((BLOCK_NSYMS (b) - 1)
4710 * sizeof (struct symbol *))));
4711
4712 /* FIXME: Not worth hashing this block as it's built. */
4713 /* All callers should have created the block with new_block (), which
4714 would mean it was not previously hashed. Make sure. */
4715 gdb_assert (BLOCK_HASHTABLE (new) == 0);
4716
4717 /* Should chase pointers to old one. Fortunately, that`s just
4718 the block`s function and inferior blocks */
4719 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
4720 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
4721 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
4722 if (BLOCKVECTOR_BLOCK (bv, i) == b)
4723 BLOCKVECTOR_BLOCK (bv, i) = new;
4724 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
4725 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
4726 return new;
4727 }
4728
4729 /* Create a new symbol with printname NAME */
4730
4731 static struct symbol *
4732 new_symbol (char *name)
4733 {
4734 struct symbol *s = ((struct symbol *)
4735 obstack_alloc (&current_objfile->symbol_obstack,
4736 sizeof (struct symbol)));
4737
4738 memset (s, 0, sizeof (*s));
4739 SYMBOL_NAME (s) = obsavestring (name, strlen (name),
4740 &current_objfile->symbol_obstack);
4741 SYMBOL_LANGUAGE (s) = psymtab_language;
4742 SYMBOL_INIT_DEMANGLED_NAME (s, &current_objfile->symbol_obstack);
4743 return s;
4744 }
4745
4746 /* Create a new type with printname NAME */
4747
4748 static struct type *
4749 new_type (char *name)
4750 {
4751 struct type *t;
4752
4753 t = alloc_type (current_objfile);
4754 TYPE_NAME (t) = name;
4755 TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
4756 return t;
4757 }
4758 \f
4759 /* Read ECOFF debugging information from a BFD section. This is
4760 called from elfread.c. It parses the section into a
4761 ecoff_debug_info struct, and then lets the rest of the file handle
4762 it as normal. */
4763
4764 void
4765 elfmdebug_build_psymtabs (struct objfile *objfile,
4766 const struct ecoff_debug_swap *swap, asection *sec)
4767 {
4768 bfd *abfd = objfile->obfd;
4769 struct ecoff_debug_info *info;
4770
4771 info = ((struct ecoff_debug_info *)
4772 obstack_alloc (&objfile->psymbol_obstack,
4773 sizeof (struct ecoff_debug_info)));
4774
4775 if (!(*swap->read_debug_info) (abfd, sec, info))
4776 error ("Error reading ECOFF debugging information: %s",
4777 bfd_errmsg (bfd_get_error ()));
4778
4779 mdebug_build_psymtabs (objfile, swap, info);
4780 }
4781 \f
4782
4783 /* Things used for calling functions in the inferior.
4784 These functions are exported to our companion
4785 mips-tdep.c file and are here because they play
4786 with the symbol-table explicitly. */
4787
4788 /* Sigtramp: make sure we have all the necessary information
4789 about the signal trampoline code. Since the official code
4790 from MIPS does not do so, we make up that information ourselves.
4791 If they fix the library (unlikely) this code will neutralize itself. */
4792
4793 /* FIXME: This function is called only by mips-tdep.c. It needs to be
4794 here because it calls functions defined in this file, but perhaps
4795 this could be handled in a better way. Only compile it in when
4796 tm-mips.h is included. */
4797
4798 #ifdef TM_MIPS_H
4799
4800 void
4801 fixup_sigtramp (void)
4802 {
4803 struct symbol *s;
4804 struct symtab *st;
4805 struct block *b, *b0 = NULL;
4806
4807 sigtramp_address = -1;
4808
4809 /* We have to handle the following cases here:
4810 a) The Mips library has a sigtramp label within sigvec.
4811 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
4812 s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL);
4813 if (s != 0)
4814 {
4815 b0 = SYMBOL_BLOCK_VALUE (s);
4816 s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
4817 }
4818 if (s == 0)
4819 {
4820 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
4821 s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
4822 }
4823
4824 /* But maybe this program uses its own version of sigvec */
4825 if (s == 0)
4826 return;
4827
4828 /* Did we or MIPSco fix the library ? */
4829 if (SYMBOL_CLASS (s) == LOC_BLOCK)
4830 {
4831 sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s));
4832 sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s));
4833 return;
4834 }
4835
4836 sigtramp_address = SYMBOL_VALUE (s);
4837 sigtramp_end = sigtramp_address + 0x88; /* black magic */
4838
4839 /* But what symtab does it live in ? */
4840 st = find_pc_symtab (SYMBOL_VALUE (s));
4841
4842 /*
4843 * Ok, there goes the fix: turn it into a procedure, with all the
4844 * needed info. Note we make it a nested procedure of sigvec,
4845 * which is the way the (assembly) code is actually written.
4846 */
4847 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
4848 SYMBOL_CLASS (s) = LOC_BLOCK;
4849 SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL,
4850 st->objfile);
4851 TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = mdebug_type_void;
4852
4853 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
4854 b = new_block (1);
4855 SYMBOL_BLOCK_VALUE (s) = b;
4856 BLOCK_START (b) = sigtramp_address;
4857 BLOCK_END (b) = sigtramp_end;
4858 BLOCK_FUNCTION (b) = s;
4859 BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
4860 add_block (b, st);
4861 sort_blocks (st);
4862
4863 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
4864 {
4865 struct mips_extra_func_info *e =
4866 ((struct mips_extra_func_info *)
4867 xzalloc (sizeof (struct mips_extra_func_info)));
4868
4869 e->numargs = 0; /* the kernel thinks otherwise */
4870 e->pdr.frameoffset = 32;
4871 e->pdr.framereg = SP_REGNUM;
4872 /* Note that setting pcreg is no longer strictly necessary as
4873 mips_frame_saved_pc is now aware of signal handler frames. */
4874 e->pdr.pcreg = PC_REGNUM;
4875 e->pdr.regmask = -2;
4876 /* Offset to saved r31, in the sigtramp case the saved registers
4877 are above the frame in the sigcontext.
4878 We have 4 alignment bytes, 12 bytes for onstack, mask and pc,
4879 32 * 4 bytes for the general registers, 12 bytes for mdhi, mdlo, ownedfp
4880 and 32 * 4 bytes for the floating point registers. */
4881 e->pdr.regoffset = 4 + 12 + 31 * 4;
4882 e->pdr.fregmask = -1;
4883 /* Offset to saved f30 (first saved *double* register). */
4884 e->pdr.fregoffset = 4 + 12 + 32 * 4 + 12 + 30 * 4;
4885 e->pdr.isym = (long) s;
4886 e->pdr.adr = sigtramp_address;
4887
4888 current_objfile = st->objfile; /* Keep new_symbol happy */
4889 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
4890 SYMBOL_VALUE (s) = (long) e;
4891 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
4892 SYMBOL_CLASS (s) = LOC_CONST;
4893 SYMBOL_TYPE (s) = mdebug_type_void;
4894 current_objfile = NULL;
4895 }
4896
4897 BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s;
4898 }
4899
4900 #endif /* TM_MIPS_H */
4901
4902 void
4903 _initialize_mdebugread (void)
4904 {
4905 mdebug_type_void =
4906 init_type (TYPE_CODE_VOID, 1,
4907 0,
4908 "void", (struct objfile *) NULL);
4909 mdebug_type_char =
4910 init_type (TYPE_CODE_INT, 1,
4911 0,
4912 "char", (struct objfile *) NULL);
4913 mdebug_type_unsigned_char =
4914 init_type (TYPE_CODE_INT, 1,
4915 TYPE_FLAG_UNSIGNED,
4916 "unsigned char", (struct objfile *) NULL);
4917 mdebug_type_short =
4918 init_type (TYPE_CODE_INT, 2,
4919 0,
4920 "short", (struct objfile *) NULL);
4921 mdebug_type_unsigned_short =
4922 init_type (TYPE_CODE_INT, 2,
4923 TYPE_FLAG_UNSIGNED,
4924 "unsigned short", (struct objfile *) NULL);
4925 mdebug_type_int_32 =
4926 init_type (TYPE_CODE_INT, 4,
4927 0,
4928 "int", (struct objfile *) NULL);
4929 mdebug_type_unsigned_int_32 =
4930 init_type (TYPE_CODE_INT, 4,
4931 TYPE_FLAG_UNSIGNED,
4932 "unsigned int", (struct objfile *) NULL);
4933 mdebug_type_int_64 =
4934 init_type (TYPE_CODE_INT, 8,
4935 0,
4936 "int", (struct objfile *) NULL);
4937 mdebug_type_unsigned_int_64 =
4938 init_type (TYPE_CODE_INT, 8,
4939 TYPE_FLAG_UNSIGNED,
4940 "unsigned int", (struct objfile *) NULL);
4941 mdebug_type_long_32 =
4942 init_type (TYPE_CODE_INT, 4,
4943 0,
4944 "long", (struct objfile *) NULL);
4945 mdebug_type_unsigned_long_32 =
4946 init_type (TYPE_CODE_INT, 4,
4947 TYPE_FLAG_UNSIGNED,
4948 "unsigned long", (struct objfile *) NULL);
4949 mdebug_type_long_64 =
4950 init_type (TYPE_CODE_INT, 8,
4951 0,
4952 "long", (struct objfile *) NULL);
4953 mdebug_type_unsigned_long_64 =
4954 init_type (TYPE_CODE_INT, 8,
4955 TYPE_FLAG_UNSIGNED,
4956 "unsigned long", (struct objfile *) NULL);
4957 mdebug_type_long_long_64 =
4958 init_type (TYPE_CODE_INT, 8,
4959 0,
4960 "long long", (struct objfile *) NULL);
4961 mdebug_type_unsigned_long_long_64 =
4962 init_type (TYPE_CODE_INT, 8,
4963 TYPE_FLAG_UNSIGNED,
4964 "unsigned long long", (struct objfile *) NULL);
4965 mdebug_type_adr_32 =
4966 init_type (TYPE_CODE_PTR, 4,
4967 TYPE_FLAG_UNSIGNED,
4968 "adr_32", (struct objfile *) NULL);
4969 TYPE_TARGET_TYPE (mdebug_type_adr_32) = mdebug_type_void;
4970 mdebug_type_adr_64 =
4971 init_type (TYPE_CODE_PTR, 8,
4972 TYPE_FLAG_UNSIGNED,
4973 "adr_64", (struct objfile *) NULL);
4974 TYPE_TARGET_TYPE (mdebug_type_adr_64) = mdebug_type_void;
4975 mdebug_type_float =
4976 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
4977 0,
4978 "float", (struct objfile *) NULL);
4979 mdebug_type_double =
4980 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
4981 0,
4982 "double", (struct objfile *) NULL);
4983 mdebug_type_complex =
4984 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
4985 0,
4986 "complex", (struct objfile *) NULL);
4987 TYPE_TARGET_TYPE (mdebug_type_complex) = mdebug_type_float;
4988 mdebug_type_double_complex =
4989 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
4990 0,
4991 "double complex", (struct objfile *) NULL);
4992 TYPE_TARGET_TYPE (mdebug_type_double_complex) = mdebug_type_double;
4993
4994 /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
4995 FIXME. */
4996 mdebug_type_string =
4997 init_type (TYPE_CODE_STRING,
4998 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4999 0, "string",
5000 (struct objfile *) NULL);
5001
5002 /* We use TYPE_CODE_INT to print these as integers. Does this do any
5003 good? Would we be better off with TYPE_CODE_ERROR? Should
5004 TYPE_CODE_ERROR print things in hex if it knows the size? */
5005 mdebug_type_fixed_dec =
5006 init_type (TYPE_CODE_INT,
5007 TARGET_INT_BIT / TARGET_CHAR_BIT,
5008 0, "fixed decimal",
5009 (struct objfile *) NULL);
5010
5011 mdebug_type_float_dec =
5012 init_type (TYPE_CODE_ERROR,
5013 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
5014 0, "floating decimal",
5015 (struct objfile *) NULL);
5016
5017 nodebug_func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
5018 "<function, no debug info>", NULL);
5019 TYPE_TARGET_TYPE (nodebug_func_symbol_type) = mdebug_type_int;
5020 nodebug_var_symbol_type =
5021 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
5022 "<variable, no debug info>", NULL);
5023 }
This page took 0.178688 seconds and 4 git commands to generate.