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