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