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