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