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