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