mdebugread.c revision 1.9 1 /* Read a symbol table in ECOFF format (Third-Eye).
2
3 Copyright (C) 1986-2020 Free Software Foundation, Inc.
4
5 Original version contributed by Alessandro Forin (af (at) cs.cmu.edu) at
6 CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor
7 at Cygnus Support.
8
9 This file is part of GDB.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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 "filenames.h"
47 #include "objfiles.h"
48 #include "gdb_obstack.h"
49 #include "buildsym-legacy.h"
50 #include "stabsread.h"
51 #include "complaints.h"
52 #include "demangle.h"
53 #include "gdb-demangle.h"
54 #include "block.h"
55 #include "dictionary.h"
56 #include "mdebugread.h"
57 #include <sys/stat.h>
58 #include "psympriv.h"
59 #include "source.h"
60
61 #include "bfd.h"
62
63 #include "coff/ecoff.h" /* COFF-like aspects of ecoff files. */
64
65 #include "libaout.h" /* Private BFD a.out information. */
66 #include "aout/aout64.h"
67 #include "aout/stab_gnu.h" /* STABS information. */
68
69 #include "expression.h"
70
71 #include <algorithm>
72
73 /* Provide a way to test if we have both ECOFF and ELF symbol tables.
74 We use this define in order to know whether we should override a
75 symbol's ECOFF section with its ELF section. This is necessary in
76 case the symbol's ELF section could not be represented in ECOFF. */
77 #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
78 && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
79
80 /* The objfile we are currently reading. */
81
82 static struct objfile *mdebugread_objfile;
83
84
85
87 /* We put a pointer to this structure in the read_symtab_private field
88 of the psymtab. */
89
90 struct symloc
91 {
92 /* Index of the FDR that this psymtab represents. */
93 int fdr_idx;
94 /* The BFD that the psymtab was created from. */
95 bfd *cur_bfd;
96 const struct ecoff_debug_swap *debug_swap;
97 struct ecoff_debug_info *debug_info;
98 struct mdebug_pending **pending_list;
99 /* Pointer to external symbols for this file. */
100 EXTR *extern_tab;
101 /* Size of extern_tab. */
102 int extern_count;
103 enum language pst_language;
104 };
105
106 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
107 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
108 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
109 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
110 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
111 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
112
113 #define SC_IS_TEXT(sc) ((sc) == scText \
114 || (sc) == scRConst \
115 || (sc) == scInit \
116 || (sc) == scFini)
117 #define SC_IS_DATA(sc) ((sc) == scData \
118 || (sc) == scSData \
119 || (sc) == scRData \
120 || (sc) == scPData \
121 || (sc) == scXData)
122 #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
123 #define SC_IS_BSS(sc) ((sc) == scBss)
124 #define SC_IS_SBSS(sc) ((sc) == scSBss)
125 #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
126
127 /* Various complaints about symbol reading that don't abort the process. */
129 static void
130 index_complaint (const char *arg1)
131 {
132 complaint (_("bad aux index at symbol %s"), arg1);
133 }
134
135 static void
136 unknown_ext_complaint (const char *arg1)
137 {
138 complaint (_("unknown external symbol %s"), arg1);
139 }
140
141 static void
142 basic_type_complaint (int arg1, const char *arg2)
143 {
144 complaint (_("cannot map ECOFF basic type 0x%x for %s"),
145 arg1, arg2);
146 }
147
148 static void
149 bad_tag_guess_complaint (const char *arg1)
150 {
151 complaint (_("guessed tag type of %s incorrectly"), arg1);
152 }
153
154 static void
155 bad_rfd_entry_complaint (const char *arg1, int arg2, int arg3)
156 {
157 complaint (_("bad rfd entry for %s: file %d, index %d"),
158 arg1, arg2, arg3);
159 }
160
161 static void
162 unexpected_type_code_complaint (const char *arg1)
163 {
164 complaint (_("unexpected type code for %s"), arg1);
165 }
166
167 /* Macros and extra defs. */
168
169 /* Puns: hard to find whether -g was used and how. */
170
171 #define MIN_GLEVEL GLEVEL_0
172 #define compare_glevel(a,b) \
173 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
174 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
175
176 /* Things that really are local to this module. */
178
179 /* Remember what we deduced to be the source language of this psymtab. */
180
181 static enum language psymtab_language = language_unknown;
182
183 /* Current BFD. */
184
185 static bfd *cur_bfd;
186
187 /* How to parse debugging information for CUR_BFD. */
188
189 static const struct ecoff_debug_swap *debug_swap;
190
191 /* Pointers to debugging information for CUR_BFD. */
192
193 static struct ecoff_debug_info *debug_info;
194
195 /* Pointer to current file descriptor record, and its index. */
196
197 static FDR *cur_fdr;
198 static int cur_fd;
199
200 /* Index of current symbol. */
201
202 static int cur_sdx;
203
204 /* Note how much "debuggable" this image is. We would like
205 to see at least one FDR with full symbols. */
206
207 static int max_gdbinfo;
208 static int max_glevel;
209
210 /* When examining .o files, report on undefined symbols. */
211
212 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
213
214 /* Pseudo symbol to use when putting stabs into the symbol table. */
215
216 static char stabs_symbol[] = STABS_SYMBOL;
217
218 /* Nonzero if we have seen ecoff debugging info for a file. */
219
220 static int found_ecoff_debugging_info;
221
222 /* Forward declarations. */
223
224 static int upgrade_type (int, struct type **, int, union aux_ext *,
225 int, const char *);
226
227 static void parse_partial_symbols (minimal_symbol_reader &,
228 struct objfile *);
229
230 static int has_opaque_xref (FDR *, SYMR *);
231
232 static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
233 const char **, int, const char *);
234
235 static struct symbol *new_symbol (const char *);
236
237 static struct type *new_type (char *);
238
239 enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
240
241 static struct block *new_block (enum block_type, enum language);
242
243 static struct compunit_symtab *new_symtab (const char *, int, struct objfile *);
244
245 static struct linetable *new_linetable (int);
246
247 static struct blockvector *new_bvect (int);
248
249 static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
250 int, const char *);
251
252 static struct symbol *mylookup_symbol (const char *, const struct block *,
253 domain_enum, enum address_class);
254
255 static void sort_blocks (struct symtab *);
256
257 static legacy_psymtab *new_psymtab (const char *, struct objfile *);
258
259 static void mdebug_expand_psymtab (legacy_psymtab *pst,
260 struct objfile *objfile);
261
262 static void add_block (struct block *, struct symtab *);
263
264 static void add_symbol (struct symbol *, struct symtab *, struct block *);
265
266 static int add_line (struct linetable *, int, CORE_ADDR, int);
267
268 static struct linetable *shrink_linetable (struct linetable *);
269
270 static void handle_psymbol_enumerators (struct objfile *, FDR *, int,
271 CORE_ADDR);
272
273 static const char *mdebug_next_symbol_text (struct objfile *);
274
275 /* Exported procedure: Builds a symtab from the partial symtab SELF.
277 Restores the environment in effect when SELF was created, delegates
278 most of the work to an ancillary procedure, and sorts
279 and reorders the symtab list at the end. SELF is not NULL. */
280
281 static void
282 mdebug_read_symtab (legacy_psymtab *self, struct objfile *objfile)
283 {
284 next_symbol_text_func = mdebug_next_symbol_text;
285
286 self->expand_psymtab (objfile);
287
288 /* Match with global symbols. This only needs to be done once,
289 after all of the symtabs and dependencies have been read in. */
290 scan_file_globals (objfile);
291 }
292
293 /* File-level interface functions. */
295
296 /* Find a file descriptor given its index RF relative to a file CF. */
297
298 static FDR *
299 get_rfd (int cf, int rf)
300 {
301 FDR *fdrs;
302 FDR *f;
303 RFDT rfd;
304
305 fdrs = debug_info->fdr;
306 f = fdrs + cf;
307 /* Object files do not have the RFD table, all refs are absolute. */
308 if (f->rfdBase == 0)
309 return fdrs + rf;
310 (*debug_swap->swap_rfd_in) (cur_bfd,
311 ((char *) debug_info->external_rfd
312 + ((f->rfdBase + rf)
313 * debug_swap->external_rfd_size)),
314 &rfd);
315 return fdrs + rfd;
316 }
317
318 /* Return a safer print NAME for a file descriptor. */
319
320 static const char *
321 fdr_name (FDR *f)
322 {
323 if (f->rss == -1)
324 return "<stripped file>";
325 if (f->rss == 0)
326 return "<NFY>";
327 return debug_info->ss + f->issBase + f->rss;
328 }
329
330
331 /* Read in and parse the symtab of the file OBJFILE. Symbols from
332 different sections are relocated via the SECTION_OFFSETS. */
333
334 void
335 mdebug_build_psymtabs (minimal_symbol_reader &reader,
336 struct objfile *objfile,
337 const struct ecoff_debug_swap *swap,
338 struct ecoff_debug_info *info)
339 {
340 cur_bfd = objfile->obfd;
341 debug_swap = swap;
342 debug_info = info;
343
344 stabsread_new_init ();
345 free_header_files ();
346 init_header_files ();
347
348 /* Make sure all the FDR information is swapped in. */
349 if (info->fdr == NULL)
350 {
351 char *fdr_src;
352 char *fdr_end;
353 FDR *fdr_ptr;
354
355 info->fdr = (FDR *) XOBNEWVEC (&objfile->objfile_obstack, FDR,
356 info->symbolic_header.ifdMax);
357 fdr_src = (char *) info->external_fdr;
358 fdr_end = (fdr_src
359 + info->symbolic_header.ifdMax * swap->external_fdr_size);
360 fdr_ptr = info->fdr;
361 for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
362 (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
363 }
364
365 parse_partial_symbols (reader, objfile);
366
367 #if 0
368 /* Check to make sure file was compiled with -g. If not, warn the
369 user of this limitation. */
370 if (compare_glevel (max_glevel, GLEVEL_2) < 0)
371 {
372 if (max_gdbinfo == 0)
373 printf_unfiltered (_("\n%s not compiled with -g, "
374 "debugging support is limited.\n"),
375 objfile->name);
376 printf_unfiltered (_("You should compile with -g2 or "
377 "-g3 for best debugging support.\n"));
378 }
379 #endif
380 }
381
382 /* Local utilities */
384
385 /* Map of FDR indexes to partial symtabs. */
386
387 struct pst_map
388 {
389 legacy_psymtab *pst; /* the psymtab proper */
390 long n_globals; /* exported globals (external symbols) */
391 long globals_offset; /* cumulative */
392 };
393
394
395 /* Utility stack, used to nest procedures and blocks properly.
396 It is a doubly linked list, to avoid too many alloc/free.
397 Since we might need it quite a few times it is NOT deallocated
398 after use. */
399
400 static struct parse_stack
401 {
402 struct parse_stack *next, *prev;
403 struct symtab *cur_st; /* Current symtab. */
404 struct block *cur_block; /* Block in it. */
405
406 /* What are we parsing. stFile, or stBlock are for files and
407 blocks. stProc or stStaticProc means we have seen the start of a
408 procedure, but not the start of the block within in. When we see
409 the start of that block, we change it to stNil, without pushing a
410 new block, i.e. stNil means both a procedure and a block. */
411
412 int blocktype;
413
414 struct type *cur_type; /* Type we parse fields for. */
415 int cur_field; /* Field number in cur_type. */
416 CORE_ADDR procadr; /* Start addres of this procedure. */
417 int numargs; /* Its argument count. */
418 }
419
420 *top_stack; /* Top stack ptr */
421
422
423 /* Enter a new lexical context. */
424
425 static void
426 push_parse_stack (void)
427 {
428 struct parse_stack *newobj;
429
430 /* Reuse frames if possible. */
431 if (top_stack && top_stack->prev)
432 newobj = top_stack->prev;
433 else
434 newobj = XCNEW (struct parse_stack);
435 /* Initialize new frame with previous content. */
436 if (top_stack)
437 {
438 struct parse_stack *prev = newobj->prev;
439
440 *newobj = *top_stack;
441 top_stack->prev = newobj;
442 newobj->prev = prev;
443 newobj->next = top_stack;
444 }
445 top_stack = newobj;
446 }
447
448 /* Exit a lexical context. */
449
450 static void
451 pop_parse_stack (void)
452 {
453 if (!top_stack)
454 return;
455 if (top_stack->next)
456 top_stack = top_stack->next;
457 }
458
459
460 /* Cross-references might be to things we haven't looked at
461 yet, e.g. type references. To avoid too many type
462 duplications we keep a quick fixup table, an array
463 of lists of references indexed by file descriptor. */
464
465 struct mdebug_pending
466 {
467 struct mdebug_pending *next; /* link */
468 char *s; /* the unswapped symbol */
469 struct type *t; /* its partial type descriptor */
470 };
471
472
473 /* The pending information is kept for an entire object file. We
474 allocate the pending information table when we create the partial
475 symbols, and we store a pointer to the single table in each
476 psymtab. */
477
478 static struct mdebug_pending **pending_list;
479
480 /* Check whether we already saw symbol SH in file FH. */
481
482 static struct mdebug_pending *
483 is_pending_symbol (FDR *fh, char *sh)
484 {
485 int f_idx = fh - debug_info->fdr;
486 struct mdebug_pending *p;
487
488 /* Linear search is ok, list is typically no more than 10 deep. */
489 for (p = pending_list[f_idx]; p; p = p->next)
490 if (p->s == sh)
491 break;
492 return p;
493 }
494
495 /* Add a new symbol SH of type T. */
496
497 static void
498 add_pending (FDR *fh, char *sh, struct type *t)
499 {
500 int f_idx = fh - debug_info->fdr;
501 struct mdebug_pending *p = is_pending_symbol (fh, sh);
502
503 /* Make sure we do not make duplicates. */
504 if (!p)
505 {
506 p = XOBNEW (&mdebugread_objfile->objfile_obstack, mdebug_pending);
507 p->s = sh;
508 p->t = t;
509 p->next = pending_list[f_idx];
510 pending_list[f_idx] = p;
511 }
512 }
513
514
516 /* Parsing Routines proper. */
517
518 static void
519 reg_value_complaint (int regnum, int num_regs, const char *sym)
520 {
521 complaint (_("bad register number %d (max %d) in symbol %s"),
522 regnum, num_regs - 1, sym);
523 }
524
525 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
526 For blocks, procedures and types we open a new lexical context.
527 This is basically just a big switch on the symbol's type. Argument
528 AX is the base pointer of aux symbols for this file (fh->iauxBase).
529 EXT_SH points to the unswapped symbol, which is needed for struct,
530 union, etc., types; it is NULL for an EXTR. BIGEND says whether
531 aux symbols are big-endian or little-endian. Return count of
532 SYMR's handled (normally one). */
533
534 static int
535 mdebug_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
536 {
537 int regno = gdbarch_ecoff_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));
538
539 if (regno < 0 || regno >= gdbarch_num_cooked_regs (gdbarch))
540 {
541 reg_value_complaint (regno, gdbarch_num_cooked_regs (gdbarch),
542 sym->print_name ());
543
544 regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless. */
545 }
546
547 return regno;
548 }
549
550 static const struct symbol_register_ops mdebug_register_funcs = {
551 mdebug_reg_to_regnum
552 };
553
554 /* The "aclass" indices for computed symbols. */
555
556 static int mdebug_register_index;
557 static int mdebug_regparm_index;
558
559 /* Common code for symbols describing data. */
560
561 static void
562 add_data_symbol (SYMR *sh, union aux_ext *ax, int bigend,
563 struct symbol *s, int aclass_index, struct block *b,
564 struct objfile *objfile, const char *name)
565 {
566 SYMBOL_DOMAIN (s) = VAR_DOMAIN;
567 SYMBOL_ACLASS_INDEX (s) = aclass_index;
568 add_symbol (s, top_stack->cur_st, b);
569
570 /* Type could be missing if file is compiled without debugging info. */
571 if (SC_IS_UNDEF (sh->sc)
572 || sh->sc == scNil || sh->index == indexNil)
573 SYMBOL_TYPE (s) = objfile_type (objfile)->nodebug_data_symbol;
574 else
575 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
576 /* Value of a data symbol is its memory address. */
577 }
578
579 static int
580 parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
581 const section_offsets §ion_offsets, struct objfile *objfile)
582 {
583 struct gdbarch *gdbarch = objfile->arch ();
584 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
585 void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
586 const char *name;
587 struct symbol *s;
588 struct block *b;
589 struct mdebug_pending *pend;
590 struct type *t;
591 int count = 1;
592 TIR tir;
593 long svalue = sh->value;
594 int bitsize;
595
596 if (ext_sh == NULL)
597 name = debug_info->ssext + sh->iss;
598 else
599 name = debug_info->ss + cur_fdr->issBase + sh->iss;
600
601 switch (sh->sc)
602 {
603 case scText:
604 case scRConst:
605 /* Do not relocate relative values.
606 The value of a stEnd symbol is the displacement from the
607 corresponding start symbol value.
608 The value of a stBlock symbol is the displacement from the
609 procedure address. */
610 if (sh->st != stEnd && sh->st != stBlock)
611 sh->value += section_offsets[SECT_OFF_TEXT (objfile)];
612 break;
613 case scData:
614 case scSData:
615 case scRData:
616 case scPData:
617 case scXData:
618 sh->value += section_offsets[SECT_OFF_DATA (objfile)];
619 break;
620 case scBss:
621 case scSBss:
622 sh->value += section_offsets[SECT_OFF_BSS (objfile)];
623 break;
624 }
625
626 switch (sh->st)
627 {
628 case stNil:
629 break;
630
631 case stGlobal: /* External symbol, goes into global block. */
632 b = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (top_stack->cur_st),
633 GLOBAL_BLOCK);
634 s = new_symbol (name);
635 SET_SYMBOL_VALUE_ADDRESS (s, (CORE_ADDR) sh->value);
636 add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
637 break;
638
639 case stStatic: /* Static data, goes into current block. */
640 b = top_stack->cur_block;
641 s = new_symbol (name);
642 if (SC_IS_COMMON (sh->sc))
643 {
644 /* It is a FORTRAN common block. At least for SGI Fortran the
645 address is not in the symbol; we need to fix it later in
646 scan_file_globals. */
647 int bucket = hashname (s->linkage_name ());
648 SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
649 global_sym_chain[bucket] = s;
650 }
651 else
652 SET_SYMBOL_VALUE_ADDRESS (s, (CORE_ADDR) sh->value);
653 add_data_symbol (sh, ax, bigend, s, LOC_STATIC, b, objfile, name);
654 break;
655
656 case stLocal: /* Local variable, goes into current block. */
657 b = top_stack->cur_block;
658 s = new_symbol (name);
659 SYMBOL_VALUE (s) = svalue;
660 if (sh->sc == scRegister)
661 add_data_symbol (sh, ax, bigend, s, mdebug_register_index,
662 b, objfile, name);
663 else
664 add_data_symbol (sh, ax, bigend, s, LOC_LOCAL,
665 b, objfile, name);
666 break;
667
668 case stParam: /* Arg to procedure, goes into current
669 block. */
670 max_gdbinfo++;
671 found_ecoff_debugging_info = 1;
672 top_stack->numargs++;
673
674 /* Special GNU C++ name. */
675 if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
676 name = "this"; /* FIXME, not alloc'd in obstack. */
677 s = new_symbol (name);
678
679 SYMBOL_DOMAIN (s) = VAR_DOMAIN;
680 SYMBOL_IS_ARGUMENT (s) = 1;
681 switch (sh->sc)
682 {
683 case scRegister:
684 /* Pass by value in register. */
685 SYMBOL_ACLASS_INDEX (s) = mdebug_register_index;
686 break;
687 case scVar:
688 /* Pass by reference on stack. */
689 SYMBOL_ACLASS_INDEX (s) = LOC_REF_ARG;
690 break;
691 case scVarRegister:
692 /* Pass by reference in register. */
693 SYMBOL_ACLASS_INDEX (s) = mdebug_regparm_index;
694 break;
695 default:
696 /* Pass by value on stack. */
697 SYMBOL_ACLASS_INDEX (s) = LOC_ARG;
698 break;
699 }
700 SYMBOL_VALUE (s) = svalue;
701 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
702 add_symbol (s, top_stack->cur_st, top_stack->cur_block);
703 break;
704
705 case stLabel: /* label, goes into current block. */
706 s = new_symbol (name);
707 SYMBOL_DOMAIN (s) = VAR_DOMAIN; /* So that it can be used */
708 SYMBOL_ACLASS_INDEX (s) = LOC_LABEL; /* but not misused. */
709 SET_SYMBOL_VALUE_ADDRESS (s, (CORE_ADDR) sh->value);
710 SYMBOL_TYPE (s) = objfile_type (objfile)->builtin_int;
711 add_symbol (s, top_stack->cur_st, top_stack->cur_block);
712 break;
713
714 case stProc: /* Procedure, usually goes into global block. */
715 case stStaticProc: /* Static procedure, goes into current block. */
716 /* For stProc symbol records, we need to check the storage class
717 as well, as only (stProc, scText) entries represent "real"
718 procedures - See the Compaq document titled "Object File /
719 Symbol Table Format Specification" for more information.
720 If the storage class is not scText, we discard the whole block
721 of symbol records for this stProc. */
722 if (sh->st == stProc && sh->sc != scText)
723 {
724 char *ext_tsym = ext_sh;
725 int keep_counting = 1;
726 SYMR tsym;
727
728 while (keep_counting)
729 {
730 ext_tsym += external_sym_size;
731 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
732 count++;
733 switch (tsym.st)
734 {
735 case stParam:
736 break;
737 case stEnd:
738 keep_counting = 0;
739 break;
740 default:
741 complaint (_("unknown symbol type 0x%x"), sh->st);
742 break;
743 }
744 }
745 break;
746 }
747 s = new_symbol (name);
748 SYMBOL_DOMAIN (s) = VAR_DOMAIN;
749 SYMBOL_ACLASS_INDEX (s) = LOC_BLOCK;
750 /* Type of the return value. */
751 if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
752 t = objfile_type (objfile)->builtin_int;
753 else
754 {
755 t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
756 if (strcmp (name, "malloc") == 0
757 && t->code () == TYPE_CODE_VOID)
758 {
759 /* I don't know why, but, at least under Alpha GNU/Linux,
760 when linking against a malloc without debugging
761 symbols, its read as a function returning void---this
762 is bad because it means we cannot call functions with
763 string arguments interactively; i.e., "call
764 printf("howdy\n")" would fail with the error message
765 "program has no memory available". To avoid this, we
766 patch up the type and make it void*
767 instead. (davidm (at) azstarnet.com). */
768 t = make_pointer_type (t, NULL);
769 }
770 }
771 b = top_stack->cur_block;
772 if (sh->st == stProc)
773 {
774 const struct blockvector *bv
775 = SYMTAB_BLOCKVECTOR (top_stack->cur_st);
776
777 /* The next test should normally be true, but provides a
778 hook for nested functions (which we don't want to make
779 global). */
780 if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
781 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
782 /* Irix 5 sometimes has duplicate names for the same
783 function. We want to add such names up at the global
784 level, not as a nested function. */
785 else if (sh->value == top_stack->procadr)
786 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
787 }
788 add_symbol (s, top_stack->cur_st, b);
789
790 /* Make a type for the procedure itself. */
791 SYMBOL_TYPE (s) = lookup_function_type (t);
792
793 /* All functions in C++ have prototypes. For C we don't have enough
794 information in the debug info. */
795 if (s->language () == language_cplus)
796 TYPE_PROTOTYPED (SYMBOL_TYPE (s)) = 1;
797
798 /* Create and enter a new lexical context. */
799 b = new_block (FUNCTION_BLOCK, s->language ());
800 SYMBOL_BLOCK_VALUE (s) = b;
801 BLOCK_FUNCTION (b) = s;
802 BLOCK_START (b) = BLOCK_END (b) = sh->value;
803 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
804 add_block (b, top_stack->cur_st);
805
806 /* Not if we only have partial info. */
807 if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
808 break;
809
810 push_parse_stack ();
811 top_stack->cur_block = b;
812 top_stack->blocktype = sh->st;
813 top_stack->cur_type = SYMBOL_TYPE (s);
814 top_stack->cur_field = -1;
815 top_stack->procadr = sh->value;
816 top_stack->numargs = 0;
817 break;
818
819 /* Beginning of code for structure, union, and enum definitions.
820 They all share a common set of local variables, defined here. */
821 {
822 enum type_code type_code;
823 char *ext_tsym;
824 int nfields;
825 long max_value;
826 struct field *f;
827
828 case stStruct: /* Start a block defining a struct type. */
829 type_code = TYPE_CODE_STRUCT;
830 goto structured_common;
831
832 case stUnion: /* Start a block defining a union type. */
833 type_code = TYPE_CODE_UNION;
834 goto structured_common;
835
836 case stEnum: /* Start a block defining an enum type. */
837 type_code = TYPE_CODE_ENUM;
838 goto structured_common;
839
840 case stBlock: /* Either a lexical block, or some type. */
841 if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
842 goto case_stBlock_code; /* Lexical block */
843
844 type_code = TYPE_CODE_UNDEF; /* We have a type. */
845
846 /* Common code for handling struct, union, enum, and/or as-yet-
847 unknown-type blocks of info about structured data. `type_code'
848 has been set to the proper TYPE_CODE, if we know it. */
849 structured_common:
850 found_ecoff_debugging_info = 1;
851 push_parse_stack ();
852 top_stack->blocktype = stBlock;
853
854 /* First count the number of fields and the highest value. */
855 nfields = 0;
856 max_value = 0;
857 for (ext_tsym = ext_sh + external_sym_size;
858 ;
859 ext_tsym += external_sym_size)
860 {
861 SYMR tsym;
862
863 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
864
865 switch (tsym.st)
866 {
867 case stEnd:
868 /* C++ encodes class types as structures where there the
869 methods are encoded as stProc. The scope of stProc
870 symbols also ends with stEnd, thus creating a risk of
871 taking the wrong stEnd symbol record as the end of
872 the current struct, which would cause GDB to undercount
873 the real number of fields in this struct. To make sure
874 we really reached the right stEnd symbol record, we
875 check the associated name, and match it against the
876 struct name. Since method names are mangled while
877 the class name is not, there is no risk of having a
878 method whose name is identical to the class name
879 (in particular constructor method names are different
880 from the class name). There is therefore no risk that
881 this check stops the count on the StEnd of a method.
882
883 Also, assume that we're really at the end when tsym.iss
884 is 0 (issNull). */
885 if (tsym.iss == issNull
886 || strcmp (debug_info->ss + cur_fdr->issBase + tsym.iss,
887 name) == 0)
888 goto end_of_fields;
889 break;
890
891 case stMember:
892 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
893 {
894 /* If the type of the member is Nil (or Void),
895 without qualifiers, assume the tag is an
896 enumeration.
897 Alpha cc -migrate enums are recognized by a zero
898 index and a zero symbol value.
899 DU 4.0 cc enums are recognized by a member type of
900 btEnum without qualifiers and a zero symbol value. */
901 if (tsym.index == indexNil
902 || (tsym.index == 0 && sh->value == 0))
903 type_code = TYPE_CODE_ENUM;
904 else
905 {
906 (*debug_swap->swap_tir_in) (bigend,
907 &ax[tsym.index].a_ti,
908 &tir);
909 if ((tir.bt == btNil || tir.bt == btVoid
910 || (tir.bt == btEnum && sh->value == 0))
911 && tir.tq0 == tqNil)
912 type_code = TYPE_CODE_ENUM;
913 }
914 }
915 nfields++;
916 if (tsym.value > max_value)
917 max_value = tsym.value;
918 break;
919
920 case stBlock:
921 case stUnion:
922 case stEnum:
923 case stStruct:
924 {
925 #if 0
926 /* This is a no-op; is it trying to tell us something
927 we should be checking? */
928 if (tsym.sc == scVariant); /*UNIMPLEMENTED */
929 #endif
930 if (tsym.index != 0)
931 {
932 /* This is something like a struct within a
933 struct. Skip over the fields of the inner
934 struct. The -1 is because the for loop will
935 increment ext_tsym. */
936 ext_tsym = ((char *) debug_info->external_sym
937 + ((cur_fdr->isymBase + tsym.index - 1)
938 * external_sym_size));
939 }
940 }
941 break;
942
943 case stTypedef:
944 /* mips cc puts out a typedef for struct x if it is not yet
945 defined when it encounters
946 struct y { struct x *xp; };
947 Just ignore it. */
948 break;
949
950 case stIndirect:
951 /* Irix5 cc puts out a stIndirect for struct x if it is not
952 yet defined when it encounters
953 struct y { struct x *xp; };
954 Just ignore it. */
955 break;
956
957 default:
958 complaint (_("declaration block contains "
959 "unhandled symbol type %d"),
960 tsym.st);
961 }
962 }
963 end_of_fields:
964
965 /* In an stBlock, there is no way to distinguish structs,
966 unions, and enums at this point. This is a bug in the
967 original design (that has been fixed with the recent
968 addition of the stStruct, stUnion, and stEnum symbol
969 types.) The way you can tell is if/when you see a variable
970 or field of that type. In that case the variable's type
971 (in the AUX table) says if the type is struct, union, or
972 enum, and points back to the stBlock here. So you can
973 patch the tag kind up later - but only if there actually is
974 a variable or field of that type.
975
976 So until we know for sure, we will guess at this point.
977 The heuristic is:
978 If the first member has index==indexNil or a void type,
979 assume we have an enumeration.
980 Otherwise, if there is more than one member, and all
981 the members have offset 0, assume we have a union.
982 Otherwise, assume we have a struct.
983
984 The heuristic could guess wrong in the case of of an
985 enumeration with no members or a union with one (or zero)
986 members, or when all except the last field of a struct have
987 width zero. These are uncommon and/or illegal situations,
988 and in any case guessing wrong probably doesn't matter
989 much.
990
991 But if we later do find out we were wrong, we fixup the tag
992 kind. Members of an enumeration must be handled
993 differently from struct/union fields, and that is harder to
994 patch up, but luckily we shouldn't need to. (If there are
995 any enumeration members, we can tell for sure it's an enum
996 here.) */
997
998 if (type_code == TYPE_CODE_UNDEF)
999 {
1000 if (nfields > 1 && max_value == 0)
1001 type_code = TYPE_CODE_UNION;
1002 else
1003 type_code = TYPE_CODE_STRUCT;
1004 }
1005
1006 /* Create a new type or use the pending type. */
1007 pend = is_pending_symbol (cur_fdr, ext_sh);
1008 if (pend == NULL)
1009 {
1010 t = new_type (NULL);
1011 add_pending (cur_fdr, ext_sh, t);
1012 }
1013 else
1014 t = pend->t;
1015
1016 /* Do not set the tag name if it is a compiler generated tag name
1017 (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
1018 Alpha cc puts out an sh->iss of zero for those. */
1019 if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
1020 t->set_name (NULL);
1021 else
1022 t->set_name (obconcat (&mdebugread_objfile->objfile_obstack,
1023 name, (char *) NULL));
1024
1025 t->set_code (type_code);
1026 TYPE_LENGTH (t) = sh->value;
1027 t->set_num_fields (nfields);
1028 f = ((struct field *) TYPE_ALLOC (t, nfields * sizeof (struct field)));
1029 t->set_fields (f);
1030
1031 if (type_code == TYPE_CODE_ENUM)
1032 {
1033 int unsigned_enum = 1;
1034
1035 /* This is a non-empty enum. */
1036
1037 /* DEC c89 has the number of enumerators in the sh.value field,
1038 not the type length, so we have to compensate for that
1039 incompatibility quirk.
1040 This might do the wrong thing for an enum with one or two
1041 enumerators and gcc -gcoff -fshort-enums, but these cases
1042 are hopefully rare enough.
1043 Alpha cc -migrate has a sh.value field of zero, we adjust
1044 that too. */
1045 if (TYPE_LENGTH (t) == t->num_fields ()
1046 || TYPE_LENGTH (t) == 0)
1047 TYPE_LENGTH (t) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
1048 for (ext_tsym = ext_sh + external_sym_size;
1049 ;
1050 ext_tsym += external_sym_size)
1051 {
1052 SYMR tsym;
1053 struct symbol *enum_sym;
1054
1055 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
1056
1057 if (tsym.st != stMember)
1058 break;
1059
1060 SET_FIELD_ENUMVAL (*f, tsym.value);
1061 f->set_type (t);
1062 FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
1063 FIELD_BITSIZE (*f) = 0;
1064
1065 enum_sym = new (&mdebugread_objfile->objfile_obstack) symbol;
1066 enum_sym->set_linkage_name
1067 (obstack_strdup (&mdebugread_objfile->objfile_obstack,
1068 f->name));
1069 SYMBOL_ACLASS_INDEX (enum_sym) = LOC_CONST;
1070 SYMBOL_TYPE (enum_sym) = t;
1071 SYMBOL_DOMAIN (enum_sym) = VAR_DOMAIN;
1072 SYMBOL_VALUE (enum_sym) = tsym.value;
1073 if (SYMBOL_VALUE (enum_sym) < 0)
1074 unsigned_enum = 0;
1075 add_symbol (enum_sym, top_stack->cur_st, top_stack->cur_block);
1076
1077 /* Skip the stMembers that we've handled. */
1078 count++;
1079 f++;
1080 }
1081 if (unsigned_enum)
1082 TYPE_UNSIGNED (t) = 1;
1083 }
1084 /* Make this the current type. */
1085 top_stack->cur_type = t;
1086 top_stack->cur_field = 0;
1087
1088 /* Do not create a symbol for alpha cc unnamed structs. */
1089 if (sh->iss == 0)
1090 break;
1091
1092 /* gcc puts out an empty struct for an opaque struct definitions,
1093 do not create a symbol for it either. */
1094 if (t->num_fields () == 0)
1095 {
1096 TYPE_STUB (t) = 1;
1097 break;
1098 }
1099
1100 s = new_symbol (name);
1101 SYMBOL_DOMAIN (s) = STRUCT_DOMAIN;
1102 SYMBOL_ACLASS_INDEX (s) = LOC_TYPEDEF;
1103 SYMBOL_VALUE (s) = 0;
1104 SYMBOL_TYPE (s) = t;
1105 add_symbol (s, top_stack->cur_st, top_stack->cur_block);
1106 break;
1107
1108 /* End of local variables shared by struct, union, enum, and
1109 block (as yet unknown struct/union/enum) processing. */
1110 }
1111
1112 case_stBlock_code:
1113 found_ecoff_debugging_info = 1;
1114 /* Beginnning of (code) block. Value of symbol
1115 is the displacement from procedure start. */
1116 push_parse_stack ();
1117
1118 /* Do not start a new block if this is the outermost block of a
1119 procedure. This allows the LOC_BLOCK symbol to point to the
1120 block with the local variables, so funcname::var works. */
1121 if (top_stack->blocktype == stProc
1122 || top_stack->blocktype == stStaticProc)
1123 {
1124 top_stack->blocktype = stNil;
1125 break;
1126 }
1127
1128 top_stack->blocktype = stBlock;
1129 b = new_block (NON_FUNCTION_BLOCK, psymtab_language);
1130 BLOCK_START (b) = sh->value + top_stack->procadr;
1131 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1132 top_stack->cur_block = b;
1133 add_block (b, top_stack->cur_st);
1134 break;
1135
1136 case stEnd: /* end (of anything) */
1137 if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
1138 {
1139 /* Finished with type */
1140 top_stack->cur_type = 0;
1141 }
1142 else if (sh->sc == scText &&
1143 (top_stack->blocktype == stProc ||
1144 top_stack->blocktype == stStaticProc))
1145 {
1146 /* Finished with procedure */
1147 const struct blockvector *bv
1148 = SYMTAB_BLOCKVECTOR (top_stack->cur_st);
1149 struct mdebug_extra_func_info *e;
1150 struct block *cblock = top_stack->cur_block;
1151 struct type *ftype = top_stack->cur_type;
1152 int i;
1153
1154 BLOCK_END (top_stack->cur_block) += sh->value; /* size */
1155
1156 /* Make up special symbol to contain procedure specific info. */
1157 s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
1158 SYMBOL_DOMAIN (s) = LABEL_DOMAIN;
1159 SYMBOL_ACLASS_INDEX (s) = LOC_CONST;
1160 SYMBOL_TYPE (s) = objfile_type (mdebugread_objfile)->builtin_void;
1161 e = OBSTACK_ZALLOC (&mdebugread_objfile->objfile_obstack,
1162 mdebug_extra_func_info);
1163 SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
1164 e->numargs = top_stack->numargs;
1165 e->pdr.framereg = -1;
1166 add_symbol (s, top_stack->cur_st, top_stack->cur_block);
1167
1168 /* f77 emits proc-level with address bounds==[0,0],
1169 So look for such child blocks, and patch them. */
1170 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
1171 {
1172 struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1173
1174 if (BLOCK_SUPERBLOCK (b_bad) == cblock
1175 && BLOCK_START (b_bad) == top_stack->procadr
1176 && BLOCK_END (b_bad) == top_stack->procadr)
1177 {
1178 BLOCK_START (b_bad) = BLOCK_START (cblock);
1179 BLOCK_END (b_bad) = BLOCK_END (cblock);
1180 }
1181 }
1182
1183 if (ftype->num_fields () <= 0)
1184 {
1185 /* No parameter type information is recorded with the function's
1186 type. Set that from the type of the parameter symbols. */
1187 int nparams = top_stack->numargs;
1188 int iparams;
1189 struct symbol *sym;
1190
1191 if (nparams > 0)
1192 {
1193 struct block_iterator iter;
1194
1195 ftype->set_num_fields (nparams);
1196 ftype->set_fields
1197 ((struct field *)
1198 TYPE_ALLOC (ftype, nparams * sizeof (struct field)));
1199
1200 iparams = 0;
1201 ALL_BLOCK_SYMBOLS (cblock, iter, sym)
1202 {
1203 if (iparams == nparams)
1204 break;
1205
1206 if (SYMBOL_IS_ARGUMENT (sym))
1207 {
1208 ftype->field (iparams).set_type (SYMBOL_TYPE (sym));
1209 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
1210 iparams++;
1211 }
1212 }
1213 }
1214 }
1215 }
1216 else if (sh->sc == scText && top_stack->blocktype == stBlock)
1217 {
1218 /* End of (code) block. The value of the symbol is the
1219 displacement from the procedure`s start address of the
1220 end of this block. */
1221 BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
1222 }
1223 else if (sh->sc == scText && top_stack->blocktype == stNil)
1224 {
1225 /* End of outermost block. Pop parse stack and ignore. The
1226 following stEnd of stProc will take care of the block. */
1227 ;
1228 }
1229 else if (sh->sc == scText && top_stack->blocktype == stFile)
1230 {
1231 /* End of file. Pop parse stack and ignore. Higher
1232 level code deals with this. */
1233 ;
1234 }
1235 else
1236 complaint (_("stEnd with storage class %d not handled"), sh->sc);
1237
1238 pop_parse_stack (); /* Restore previous lexical context. */
1239 break;
1240
1241 case stMember: /* member of struct or union */
1242 {
1243 struct field *f = &top_stack->cur_type->field (top_stack->cur_field);
1244 top_stack->cur_field++;
1245 FIELD_NAME (*f) = name;
1246 SET_FIELD_BITPOS (*f, sh->value);
1247 bitsize = 0;
1248 f->set_type (parse_type (cur_fd, ax, sh->index, &bitsize, bigend,
1249 name));
1250 FIELD_BITSIZE (*f) = bitsize;
1251 }
1252 break;
1253
1254 case stIndirect: /* forward declaration on Irix5 */
1255 /* Forward declarations from Irix5 cc are handled by cross_ref,
1256 skip them. */
1257 break;
1258
1259 case stTypedef: /* type definition */
1260 found_ecoff_debugging_info = 1;
1261
1262 /* Typedefs for forward declarations and opaque structs from alpha cc
1263 are handled by cross_ref, skip them. */
1264 if (sh->iss == 0)
1265 break;
1266
1267 /* Parse the type or use the pending type. */
1268 pend = is_pending_symbol (cur_fdr, ext_sh);
1269 if (pend == NULL)
1270 {
1271 t = parse_type (cur_fd, ax, sh->index, NULL, bigend, name);
1272 add_pending (cur_fdr, ext_sh, t);
1273 }
1274 else
1275 t = pend->t;
1276
1277 /* Mips cc puts out a typedef with the name of the struct for forward
1278 declarations. These should not go into the symbol table and
1279 TYPE_NAME should not be set for them.
1280 They can't be distinguished from an intentional typedef to
1281 the same name however:
1282 x.h:
1283 struct x { int ix; int jx; };
1284 struct xx;
1285 x.c:
1286 typedef struct x x;
1287 struct xx {int ixx; int jxx; };
1288 generates a cross referencing stTypedef for x and xx.
1289 The user visible effect of this is that the type of a pointer
1290 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1291 The problem is fixed with alpha cc and Irix5 cc. */
1292
1293 /* However if the typedef cross references to an opaque aggregate, it
1294 is safe to omit it from the symbol table. */
1295
1296 if (has_opaque_xref (cur_fdr, sh))
1297 break;
1298 s = new_symbol (name);
1299 SYMBOL_DOMAIN (s) = VAR_DOMAIN;
1300 SYMBOL_ACLASS_INDEX (s) = LOC_TYPEDEF;
1301 SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
1302 SYMBOL_TYPE (s) = t;
1303 add_symbol (s, top_stack->cur_st, top_stack->cur_block);
1304
1305 /* Incomplete definitions of structs should not get a name. */
1306 if (SYMBOL_TYPE (s)->name () == NULL
1307 && (SYMBOL_TYPE (s)->num_fields () != 0
1308 || (SYMBOL_TYPE (s)->code () != TYPE_CODE_STRUCT
1309 && SYMBOL_TYPE (s)->code () != TYPE_CODE_UNION)))
1310 {
1311 if (SYMBOL_TYPE (s)->code () == TYPE_CODE_PTR
1312 || SYMBOL_TYPE (s)->code () == TYPE_CODE_FUNC)
1313 {
1314 /* If we are giving a name to a type such as "pointer to
1315 foo" or "function returning foo", we better not set
1316 the TYPE_NAME. If the program contains "typedef char
1317 *caddr_t;", we don't want all variables of type char
1318 * to print as caddr_t. This is not just a
1319 consequence of GDB's type management; CC and GCC (at
1320 least through version 2.4) both output variables of
1321 either type char * or caddr_t with the type
1322 refering to the stTypedef symbol for caddr_t. If a future
1323 compiler cleans this up it GDB is not ready for it
1324 yet, but if it becomes ready we somehow need to
1325 disable this check (without breaking the PCC/GCC2.4
1326 case).
1327
1328 Sigh.
1329
1330 Fortunately, this check seems not to be necessary
1331 for anything except pointers or functions. */
1332 }
1333 else
1334 SYMBOL_TYPE (s)->set_name (s->linkage_name ());
1335 }
1336 break;
1337
1338 case stFile: /* file name */
1339 push_parse_stack ();
1340 top_stack->blocktype = sh->st;
1341 break;
1342
1343 /* I`ve never seen these for C */
1344 case stRegReloc:
1345 break; /* register relocation */
1346 case stForward:
1347 break; /* forwarding address */
1348 case stConstant:
1349 break; /* constant */
1350 default:
1351 complaint (_("unknown symbol type 0x%x"), sh->st);
1352 break;
1353 }
1354
1355 return count;
1356 }
1357
1358 /* Basic types. */
1359
1360 static const struct objfile_key<struct type *,
1361 gdb::noop_deleter<struct type *>>
1362 basic_type_data;
1363
1364 static struct type *
1365 basic_type (int bt, struct objfile *objfile)
1366 {
1367 struct gdbarch *gdbarch = objfile->arch ();
1368 struct type **map_bt = basic_type_data.get (objfile);
1369 struct type *tp;
1370
1371 if (bt >= btMax)
1372 return NULL;
1373
1374 if (!map_bt)
1375 {
1376 map_bt = OBSTACK_CALLOC (&objfile->objfile_obstack,
1377 btMax, struct type *);
1378 basic_type_data.set (objfile, map_bt);
1379 }
1380
1381 if (map_bt[bt])
1382 return map_bt[bt];
1383
1384 switch (bt)
1385 {
1386 case btNil:
1387 tp = objfile_type (objfile)->builtin_void;
1388 break;
1389
1390 case btAdr:
1391 tp = init_pointer_type (objfile, 32, "adr_32",
1392 objfile_type (objfile)->builtin_void);
1393 break;
1394
1395 case btChar:
1396 tp = init_integer_type (objfile, 8, 0, "char");
1397 TYPE_NOSIGN (tp) = 1;
1398 break;
1399
1400 case btUChar:
1401 tp = init_integer_type (objfile, 8, 1, "unsigned char");
1402 break;
1403
1404 case btShort:
1405 tp = init_integer_type (objfile, 16, 0, "short");
1406 break;
1407
1408 case btUShort:
1409 tp = init_integer_type (objfile, 16, 1, "unsigned short");
1410 break;
1411
1412 case btInt:
1413 tp = init_integer_type (objfile, 32, 0, "int");
1414 break;
1415
1416 case btUInt:
1417 tp = init_integer_type (objfile, 32, 1, "unsigned int");
1418 break;
1419
1420 case btLong:
1421 tp = init_integer_type (objfile, 32, 0, "long");
1422 break;
1423
1424 case btULong:
1425 tp = init_integer_type (objfile, 32, 1, "unsigned long");
1426 break;
1427
1428 case btFloat:
1429 tp = init_float_type (objfile, gdbarch_float_bit (gdbarch),
1430 "float", gdbarch_float_format (gdbarch));
1431 break;
1432
1433 case btDouble:
1434 tp = init_float_type (objfile, gdbarch_double_bit (gdbarch),
1435 "double", gdbarch_double_format (gdbarch));
1436 break;
1437
1438 case btComplex:
1439 tp = init_complex_type ("complex", basic_type (btFloat, objfile));
1440 break;
1441
1442 case btDComplex:
1443 tp = init_complex_type ("double complex", basic_type (btFloat, objfile));
1444 break;
1445
1446 case btFixedDec:
1447 /* We use TYPE_CODE_INT to print these as integers. Does this do any
1448 good? Would we be better off with TYPE_CODE_ERROR? Should
1449 TYPE_CODE_ERROR print things in hex if it knows the size? */
1450 tp = init_integer_type (objfile, gdbarch_int_bit (gdbarch), 0,
1451 "fixed decimal");
1452 break;
1453
1454 case btFloatDec:
1455 tp = init_type (objfile, TYPE_CODE_ERROR,
1456 gdbarch_double_bit (gdbarch), "floating decimal");
1457 break;
1458
1459 case btString:
1460 /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
1461 FIXME. */
1462 tp = init_type (objfile, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
1463 break;
1464
1465 case btVoid:
1466 tp = objfile_type (objfile)->builtin_void;
1467 break;
1468
1469 case btLong64:
1470 tp = init_integer_type (objfile, 64, 0, "long");
1471 break;
1472
1473 case btULong64:
1474 tp = init_integer_type (objfile, 64, 1, "unsigned long");
1475 break;
1476
1477 case btLongLong64:
1478 tp = init_integer_type (objfile, 64, 0, "long long");
1479 break;
1480
1481 case btULongLong64:
1482 tp = init_integer_type (objfile, 64, 1, "unsigned long long");
1483 break;
1484
1485 case btAdr64:
1486 tp = init_pointer_type (objfile, 64, "adr_64",
1487 objfile_type (objfile)->builtin_void);
1488 break;
1489
1490 case btInt64:
1491 tp = init_integer_type (objfile, 64, 0, "int");
1492 break;
1493
1494 case btUInt64:
1495 tp = init_integer_type (objfile, 64, 1, "unsigned int");
1496 break;
1497
1498 default:
1499 tp = NULL;
1500 break;
1501 }
1502
1503 map_bt[bt] = tp;
1504 return tp;
1505 }
1506
1507 /* Parse the type information provided in the raw AX entries for
1508 the symbol SH. Return the bitfield size in BS, in case.
1509 We must byte-swap the AX entries before we use them; BIGEND says whether
1510 they are big-endian or little-endian (from fh->fBigendian). */
1511
1512 static struct type *
1513 parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
1514 int bigend, const char *sym_name)
1515 {
1516 TIR t[1];
1517 struct type *tp = 0;
1518 enum type_code type_code = TYPE_CODE_UNDEF;
1519
1520 /* Handle undefined types, they have indexNil. */
1521 if (aux_index == indexNil)
1522 return basic_type (btInt, mdebugread_objfile);
1523
1524 /* Handle corrupt aux indices. */
1525 if (aux_index >= (debug_info->fdr + fd)->caux)
1526 {
1527 index_complaint (sym_name);
1528 return basic_type (btInt, mdebugread_objfile);
1529 }
1530 ax += aux_index;
1531
1532 /* Use aux as a type information record, map its basic type. */
1533 (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1534 tp = basic_type (t->bt, mdebugread_objfile);
1535 if (tp == NULL)
1536 {
1537 /* Cannot use builtin types -- build our own. */
1538 switch (t->bt)
1539 {
1540 case btStruct:
1541 type_code = TYPE_CODE_STRUCT;
1542 break;
1543 case btUnion:
1544 type_code = TYPE_CODE_UNION;
1545 break;
1546 case btEnum:
1547 type_code = TYPE_CODE_ENUM;
1548 break;
1549 case btRange:
1550 type_code = TYPE_CODE_RANGE;
1551 break;
1552 case btSet:
1553 type_code = TYPE_CODE_SET;
1554 break;
1555 case btIndirect:
1556 /* alpha cc -migrate uses this for typedefs. The true type will
1557 be obtained by crossreferencing below. */
1558 type_code = TYPE_CODE_ERROR;
1559 break;
1560 case btTypedef:
1561 /* alpha cc uses this for typedefs. The true type will be
1562 obtained by crossreferencing below. */
1563 type_code = TYPE_CODE_ERROR;
1564 break;
1565 default:
1566 basic_type_complaint (t->bt, sym_name);
1567 return basic_type (btInt, mdebugread_objfile);
1568 }
1569 }
1570
1571 /* Move on to next aux. */
1572 ax++;
1573
1574 if (t->fBitfield)
1575 {
1576 int width = AUX_GET_WIDTH (bigend, ax);
1577
1578 /* Inhibit core dumps if TIR is corrupted. */
1579 if (bs == NULL)
1580 {
1581 /* Alpha cc -migrate encodes char and unsigned char types
1582 as short and unsigned short types with a field width of 8.
1583 Enum types also have a field width which we ignore for now. */
1584 if (t->bt == btShort && width == 8)
1585 tp = basic_type (btChar, mdebugread_objfile);
1586 else if (t->bt == btUShort && width == 8)
1587 tp = basic_type (btUChar, mdebugread_objfile);
1588 else if (t->bt == btEnum)
1589 ;
1590 else
1591 complaint (_("can't handle TIR fBitfield for %s"),
1592 sym_name);
1593 }
1594 else
1595 *bs = width;
1596 ax++;
1597 }
1598
1599 /* A btIndirect entry cross references to an aux entry containing
1600 the type. */
1601 if (t->bt == btIndirect)
1602 {
1603 RNDXR rn[1];
1604 int rf;
1605 FDR *xref_fh;
1606 int xref_fd;
1607
1608 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
1609 ax++;
1610 if (rn->rfd == 0xfff)
1611 {
1612 rf = AUX_GET_ISYM (bigend, ax);
1613 ax++;
1614 }
1615 else
1616 rf = rn->rfd;
1617
1618 if (rf == -1)
1619 {
1620 complaint (_("unable to cross ref btIndirect for %s"), sym_name);
1621 return basic_type (btInt, mdebugread_objfile);
1622 }
1623 xref_fh = get_rfd (fd, rf);
1624 xref_fd = xref_fh - debug_info->fdr;
1625 tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
1626 rn->index, NULL, xref_fh->fBigendian, sym_name);
1627 }
1628
1629 /* All these types really point to some (common) MIPS type
1630 definition, and only the type-qualifiers fully identify
1631 them. We'll make the same effort at sharing. */
1632 if (t->bt == btStruct ||
1633 t->bt == btUnion ||
1634 t->bt == btEnum ||
1635
1636 /* btSet (I think) implies that the name is a tag name, not a typedef
1637 name. This apparently is a MIPS extension for C sets. */
1638 t->bt == btSet)
1639 {
1640 const char *name;
1641
1642 /* Try to cross reference this type, build new type on failure. */
1643 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1644 if (tp == NULL)
1645 tp = init_type (mdebugread_objfile, type_code, 0, NULL);
1646
1647 /* DEC c89 produces cross references to qualified aggregate types,
1648 dereference them. */
1649 while (tp->code () == TYPE_CODE_PTR
1650 || tp->code () == TYPE_CODE_ARRAY)
1651 tp = TYPE_TARGET_TYPE (tp);
1652
1653 /* Make sure that TYPE_CODE(tp) has an expected type code.
1654 Any type may be returned from cross_ref if file indirect entries
1655 are corrupted. */
1656 if (tp->code () != TYPE_CODE_STRUCT
1657 && tp->code () != TYPE_CODE_UNION
1658 && tp->code () != TYPE_CODE_ENUM)
1659 {
1660 unexpected_type_code_complaint (sym_name);
1661 }
1662 else
1663 {
1664 /* Usually, TYPE_CODE(tp) is already type_code. The main
1665 exception is if we guessed wrong re struct/union/enum.
1666 But for struct vs. union a wrong guess is harmless, so
1667 don't complain(). */
1668 if ((tp->code () == TYPE_CODE_ENUM
1669 && type_code != TYPE_CODE_ENUM)
1670 || (tp->code () != TYPE_CODE_ENUM
1671 && type_code == TYPE_CODE_ENUM))
1672 {
1673 bad_tag_guess_complaint (sym_name);
1674 }
1675
1676 if (tp->code () != type_code)
1677 {
1678 tp->set_code (type_code);
1679 }
1680
1681 /* Do not set the tag name if it is a compiler generated tag name
1682 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1683 if (name[0] == '.' || name[0] == '\0')
1684 tp->set_name (NULL);
1685 else if (tp->name () == NULL
1686 || strcmp (tp->name (), name) != 0)
1687 tp->set_name (obstack_strdup (&mdebugread_objfile->objfile_obstack,
1688 name));
1689 }
1690 }
1691
1692 /* All these types really point to some (common) MIPS type
1693 definition, and only the type-qualifiers fully identify
1694 them. We'll make the same effort at sharing.
1695 FIXME: We are not doing any guessing on range types. */
1696 if (t->bt == btRange)
1697 {
1698 const char *name;
1699
1700 /* Try to cross reference this type, build new type on failure. */
1701 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1702 if (tp == NULL)
1703 tp = init_type (mdebugread_objfile, type_code, 0, NULL);
1704
1705 /* Make sure that TYPE_CODE(tp) has an expected type code.
1706 Any type may be returned from cross_ref if file indirect entries
1707 are corrupted. */
1708 if (tp->code () != TYPE_CODE_RANGE)
1709 {
1710 unexpected_type_code_complaint (sym_name);
1711 }
1712 else
1713 {
1714 /* Usually, TYPE_CODE(tp) is already type_code. The main
1715 exception is if we guessed wrong re struct/union/enum. */
1716 if (tp->code () != type_code)
1717 {
1718 bad_tag_guess_complaint (sym_name);
1719 tp->set_code (type_code);
1720 }
1721 if (tp->name () == NULL
1722 || strcmp (tp->name (), name) != 0)
1723 tp->set_name (obstack_strdup (&mdebugread_objfile->objfile_obstack,
1724 name));
1725 }
1726 }
1727 if (t->bt == btTypedef)
1728 {
1729 const char *name;
1730
1731 /* Try to cross reference this type, it should succeed. */
1732 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1733 if (tp == NULL)
1734 {
1735 complaint (_("unable to cross ref btTypedef for %s"), sym_name);
1736 tp = basic_type (btInt, mdebugread_objfile);
1737 }
1738 }
1739
1740 /* Deal with range types. */
1741 if (t->bt == btRange)
1742 {
1743 tp->set_num_fields (0);
1744 tp->set_bounds (((struct range_bounds *)
1745 TYPE_ZALLOC (tp, sizeof (struct range_bounds))));
1746 tp->bounds ()->low.set_const_val (AUX_GET_DNLOW (bigend, ax));
1747 ax++;
1748 tp->bounds ()->high.set_const_val (AUX_GET_DNHIGH (bigend, ax));
1749 ax++;
1750 }
1751
1752 /* Parse all the type qualifiers now. If there are more
1753 than 6 the game will continue in the next aux. */
1754
1755 while (1)
1756 {
1757 #define PARSE_TQ(tq) \
1758 if (t->tq != tqNil) \
1759 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1760 else \
1761 break;
1762
1763 PARSE_TQ (tq0);
1764 PARSE_TQ (tq1);
1765 PARSE_TQ (tq2);
1766 PARSE_TQ (tq3);
1767 PARSE_TQ (tq4);
1768 PARSE_TQ (tq5);
1769 #undef PARSE_TQ
1770
1771 /* mips cc 2.x and gcc never put out continued aux entries. */
1772 if (!t->continued)
1773 break;
1774
1775 (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1776 ax++;
1777 }
1778
1779 /* Complain for illegal continuations due to corrupt aux entries. */
1780 if (t->continued)
1781 complaint (_("illegal TIR continued for %s"), sym_name);
1782
1783 return tp;
1784 }
1785
1786 /* Make up a complex type from a basic one. Type is passed by
1787 reference in TPP and side-effected as necessary. The type
1788 qualifier TQ says how to handle the aux symbols at AX for
1789 the symbol SX we are currently analyzing. BIGEND says whether
1790 aux symbols are big-endian or little-endian.
1791 Returns the number of aux symbols we parsed. */
1792
1793 static int
1794 upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
1795 const char *sym_name)
1796 {
1797 int off;
1798 struct type *t;
1799
1800 /* Used in array processing. */
1801 int rf, id;
1802 FDR *fh;
1803 struct type *range;
1804 struct type *indx;
1805 int lower, upper;
1806 RNDXR rndx;
1807
1808 switch (tq)
1809 {
1810 case tqPtr:
1811 t = lookup_pointer_type (*tpp);
1812 *tpp = t;
1813 return 0;
1814
1815 case tqProc:
1816 t = lookup_function_type (*tpp);
1817 *tpp = t;
1818 return 0;
1819
1820 case tqArray:
1821 off = 0;
1822
1823 /* Determine and record the domain type (type of index). */
1824 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
1825 id = rndx.index;
1826 rf = rndx.rfd;
1827 if (rf == 0xfff)
1828 {
1829 ax++;
1830 rf = AUX_GET_ISYM (bigend, ax);
1831 off++;
1832 }
1833 fh = get_rfd (fd, rf);
1834
1835 indx = parse_type (fh - debug_info->fdr,
1836 debug_info->external_aux + fh->iauxBase,
1837 id, NULL, bigend, sym_name);
1838
1839 /* The bounds type should be an integer type, but might be anything
1840 else due to corrupt aux entries. */
1841 if (indx->code () != TYPE_CODE_INT)
1842 {
1843 complaint (_("illegal array index type for %s, assuming int"),
1844 sym_name);
1845 indx = objfile_type (mdebugread_objfile)->builtin_int;
1846 }
1847
1848 /* Get the bounds, and create the array type. */
1849 ax++;
1850 lower = AUX_GET_DNLOW (bigend, ax);
1851 ax++;
1852 upper = AUX_GET_DNHIGH (bigend, ax);
1853 ax++;
1854 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1855
1856 range = create_static_range_type (NULL, indx, lower, upper);
1857
1858 t = create_array_type (NULL, *tpp, range);
1859
1860 /* We used to fill in the supplied array element bitsize
1861 here if the TYPE_LENGTH of the target type was zero.
1862 This happens for a `pointer to an array of anonymous structs',
1863 but in this case the array element bitsize is also zero,
1864 so nothing is gained.
1865 And we used to check the TYPE_LENGTH of the target type against
1866 the supplied array element bitsize.
1867 gcc causes a mismatch for `pointer to array of object',
1868 since the sdb directives it uses do not have a way of
1869 specifying the bitsize, but it does no harm (the
1870 TYPE_LENGTH should be correct) and we should be able to
1871 ignore the erroneous bitsize from the auxiliary entry safely.
1872 dbx seems to ignore it too. */
1873
1874 /* TYPE_TARGET_STUB now takes care of the zero TYPE_LENGTH problem. */
1875 if (TYPE_LENGTH (*tpp) == 0)
1876 TYPE_TARGET_STUB (t) = 1;
1877
1878 *tpp = t;
1879 return 4 + off;
1880
1881 case tqVol:
1882 /* Volatile -- currently ignored */
1883 return 0;
1884
1885 case tqConst:
1886 /* Const -- currently ignored */
1887 return 0;
1888
1889 default:
1890 complaint (_("unknown type qualifier 0x%x"), tq);
1891 return 0;
1892 }
1893 }
1894
1895
1896 /* Parse a procedure descriptor record PR. Note that the procedure is
1897 parsed _after_ the local symbols, now we just insert the extra
1898 information we need into a MDEBUG_EFI_SYMBOL_NAME symbol that has
1899 already been placed in the procedure's main block. Note also that
1900 images that have been partially stripped (ld -x) have been deprived
1901 of local symbols, and we have to cope with them here. FIRST_OFF is
1902 the offset of the first procedure for this FDR; we adjust the
1903 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1904 to look for the function which contains the MDEBUG_EFI_SYMBOL_NAME symbol
1905 in question, or NULL to use top_stack->cur_block. */
1906
1907 static void
1908 parse_procedure (PDR *pr, struct compunit_symtab *search_symtab,
1909 legacy_psymtab *pst)
1910 {
1911 struct symbol *s, *i;
1912 const struct block *b;
1913 char *sh_name;
1914
1915 /* Simple rule to find files linked "-x". */
1916 if (cur_fdr->rss == -1)
1917 {
1918 if (pr->isym == -1)
1919 {
1920 /* Static procedure at address pr->adr. Sigh. */
1921 /* FIXME-32x64. assuming pr->adr fits in long. */
1922 complaint (_("can't handle PDR for static proc at 0x%lx"),
1923 (unsigned long) pr->adr);
1924 return;
1925 }
1926 else
1927 {
1928 /* external */
1929 EXTR she;
1930
1931 (*debug_swap->swap_ext_in) (cur_bfd,
1932 ((char *) debug_info->external_ext
1933 + (pr->isym
1934 * debug_swap->external_ext_size)),
1935 &she);
1936 sh_name = debug_info->ssext + she.asym.iss;
1937 }
1938 }
1939 else
1940 {
1941 /* Full symbols */
1942 SYMR sh;
1943
1944 (*debug_swap->swap_sym_in) (cur_bfd,
1945 ((char *) debug_info->external_sym
1946 + ((cur_fdr->isymBase + pr->isym)
1947 * debug_swap->external_sym_size)),
1948 &sh);
1949 sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
1950 }
1951
1952 if (search_symtab != NULL)
1953 {
1954 #if 0
1955 /* This loses both in the case mentioned (want a static, find a global),
1956 but also if we are looking up a non-mangled name which happens to
1957 match the name of a mangled function. */
1958 /* We have to save the cur_fdr across the call to lookup_symbol.
1959 If the pdr is for a static function and if a global function with
1960 the same name exists, lookup_symbol will eventually read in the symtab
1961 for the global function and clobber cur_fdr. */
1962 FDR *save_cur_fdr = cur_fdr;
1963
1964 s = lookup_symbol (sh_name, NULL, VAR_DOMAIN, 0);
1965 cur_fdr = save_cur_fdr;
1966 #else
1967 s = mylookup_symbol
1968 (sh_name,
1969 BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (search_symtab),
1970 STATIC_BLOCK),
1971 VAR_DOMAIN,
1972 LOC_BLOCK);
1973 #endif
1974 }
1975 else
1976 s = mylookup_symbol (sh_name, top_stack->cur_block,
1977 VAR_DOMAIN, LOC_BLOCK);
1978
1979 if (s != 0)
1980 {
1981 b = SYMBOL_BLOCK_VALUE (s);
1982 }
1983 else
1984 {
1985 complaint (_("PDR for %s, but no symbol"), sh_name);
1986 #if 1
1987 return;
1988 #else
1989 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1990 s = new_symbol (sh_name);
1991 SYMBOL_DOMAIN (s) = VAR_DOMAIN;
1992 SYMBOL_CLASS (s) = LOC_BLOCK;
1993 /* Don't know its type, hope int is ok. */
1994 SYMBOL_TYPE (s)
1995 = lookup_function_type (objfile_type (pst->objfile)->builtin_int);
1996 add_symbol (s, top_stack->cur_st, top_stack->cur_block);
1997 /* Won't have symbols for this one. */
1998 b = new_block (2);
1999 SYMBOL_BLOCK_VALUE (s) = b;
2000 BLOCK_FUNCTION (b) = s;
2001 BLOCK_START (b) = pr->adr;
2002 /* BOUND used to be the end of procedure's text, but the
2003 argument is no longer passed in. */
2004 BLOCK_END (b) = bound;
2005 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
2006 add_block (b, top_stack->cur_st);
2007 #endif
2008 }
2009
2010 i = mylookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, LOC_CONST);
2011
2012 if (i)
2013 {
2014 struct mdebug_extra_func_info *e;
2015
2016 e = (struct mdebug_extra_func_info *) SYMBOL_VALUE_BYTES (i);
2017 e->pdr = *pr;
2018
2019 /* GDB expects the absolute function start address for the
2020 procedure descriptor in e->pdr.adr.
2021 As the address in the procedure descriptor is usually relative,
2022 we would have to relocate e->pdr.adr with cur_fdr->adr.
2023 Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
2024 in shared libraries on some systems, and on other systems
2025 e->pdr.adr is sometimes offset by a bogus value.
2026 To work around these problems, we replace e->pdr.adr with
2027 the start address of the function. */
2028 e->pdr.adr = BLOCK_START (b);
2029 }
2030
2031 /* It would be reasonable that functions that have been compiled
2032 without debugging info have a btNil type for their return value,
2033 and functions that are void and are compiled with debugging info
2034 have btVoid.
2035 gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
2036 to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
2037 case right.
2038 The glevel field in cur_fdr could be used to determine the presence
2039 of debugging info, but GCC doesn't always pass the -g switch settings
2040 to the assembler and GAS doesn't set the glevel field from the -g switch
2041 settings.
2042 To work around these problems, the return value type of a TYPE_CODE_VOID
2043 function is adjusted accordingly if no debugging info was found in the
2044 compilation unit. */
2045
2046 if (processing_gcc_compilation == 0
2047 && found_ecoff_debugging_info == 0
2048 && TYPE_TARGET_TYPE (SYMBOL_TYPE (s))->code () == TYPE_CODE_VOID)
2049 SYMBOL_TYPE (s) = objfile_type (mdebugread_objfile)->nodebug_text_symbol;
2050 }
2051
2052 /* Parse the external symbol ES. Just call parse_symbol() after
2053 making sure we know where the aux are for it.
2054 BIGEND says whether aux entries are big-endian or little-endian.
2055
2056 This routine clobbers top_stack->cur_block and ->cur_st. */
2057
2058 static void
2059 parse_external (EXTR *es, int bigend, const section_offsets §ion_offsets,
2060 struct objfile *objfile)
2061 {
2062 union aux_ext *ax;
2063
2064 if (es->ifd != ifdNil)
2065 {
2066 cur_fd = es->ifd;
2067 cur_fdr = debug_info->fdr + cur_fd;
2068 ax = debug_info->external_aux + cur_fdr->iauxBase;
2069 }
2070 else
2071 {
2072 cur_fdr = debug_info->fdr;
2073 ax = 0;
2074 }
2075
2076 /* Reading .o files */
2077 if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
2078 {
2079 const char *what;
2080 switch (es->asym.st)
2081 {
2082 case stNil:
2083 /* These are generated for static symbols in .o files,
2084 ignore them. */
2085 return;
2086 case stStaticProc:
2087 case stProc:
2088 what = "procedure";
2089 n_undef_procs++;
2090 break;
2091 case stGlobal:
2092 what = "variable";
2093 n_undef_vars++;
2094 break;
2095 case stLabel:
2096 what = "label";
2097 n_undef_labels++;
2098 break;
2099 default:
2100 what = "symbol";
2101 break;
2102 }
2103 n_undef_symbols++;
2104 /* FIXME: Turn this into a complaint? */
2105 if (info_verbose)
2106 printf_filtered (_("Warning: %s `%s' is undefined (in %s)\n"),
2107 what, debug_info->ssext + es->asym.iss,
2108 fdr_name (cur_fdr));
2109 return;
2110 }
2111
2112 switch (es->asym.st)
2113 {
2114 case stProc:
2115 case stStaticProc:
2116 /* There is no need to parse the external procedure symbols.
2117 If they are from objects compiled without -g, their index will
2118 be indexNil, and the symbol definition from the minimal symbol
2119 is preferrable (yielding a function returning int instead of int).
2120 If the index points to a local procedure symbol, the local
2121 symbol already provides the correct type.
2122 Note that the index of the external procedure symbol points
2123 to the local procedure symbol in the local symbol table, and
2124 _not_ to the auxiliary symbol info. */
2125 break;
2126 case stGlobal:
2127 case stLabel:
2128 /* Global common symbols are resolved by the runtime loader,
2129 ignore them. */
2130 if (SC_IS_COMMON (es->asym.sc))
2131 break;
2132
2133 /* Note that the case of a symbol with indexNil must be handled
2134 anyways by parse_symbol(). */
2135 parse_symbol (&es->asym, ax, NULL,
2136 bigend, section_offsets, objfile);
2137 break;
2138 default:
2139 break;
2140 }
2141 }
2142
2143 /* Parse the line number info for file descriptor FH into
2144 GDB's linetable LT. MIPS' encoding requires a little bit
2145 of magic to get things out. Note also that MIPS' line
2146 numbers can go back and forth, apparently we can live
2147 with that and do not need to reorder our linetables. */
2148
2149 static void
2150 parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
2151 CORE_ADDR textlow, CORE_ADDR lowest_pdr_addr)
2152 {
2153 unsigned char *base;
2154 int j, k;
2155 int delta, count, lineno = 0;
2156
2157 if (fh->cbLine == 0)
2158 return;
2159
2160 /* Scan by procedure descriptors. */
2161 k = 0;
2162 for (j = 0; j < fh->cpd; j++, pr++)
2163 {
2164 CORE_ADDR l;
2165 CORE_ADDR adr;
2166 unsigned char *halt;
2167
2168 /* No code for this one. */
2169 if (pr->iline == ilineNil ||
2170 pr->lnLow == -1 || pr->lnHigh == -1)
2171 continue;
2172
2173 /* Determine start and end address of compressed line bytes for
2174 this procedure. */
2175 base = debug_info->line + fh->cbLineOffset;
2176 if (j != (fh->cpd - 1))
2177 halt = base + pr[1].cbLineOffset;
2178 else
2179 halt = base + fh->cbLine;
2180 base += pr->cbLineOffset;
2181
2182 adr = textlow + pr->adr - lowest_pdr_addr;
2183
2184 l = adr >> 2; /* in words */
2185 for (lineno = pr->lnLow; base < halt;)
2186 {
2187 count = *base & 0x0f;
2188 delta = *base++ >> 4;
2189 if (delta >= 8)
2190 delta -= 16;
2191 if (delta == -8)
2192 {
2193 delta = (base[0] << 8) | base[1];
2194 if (delta >= 0x8000)
2195 delta -= 0x10000;
2196 base += 2;
2197 }
2198 lineno += delta; /* first delta is 0 */
2199
2200 /* Complain if the line table overflows. Could happen
2201 with corrupt binaries. */
2202 if (lt->nitems >= maxlines)
2203 {
2204 complaint (_("guessed size of linetable for %s incorrectly"),
2205 fdr_name (fh));
2206 break;
2207 }
2208 k = add_line (lt, lineno, l, k);
2209 l += count + 1;
2210 }
2211 }
2212 }
2213
2214 static void
2216 function_outside_compilation_unit_complaint (const char *arg1)
2217 {
2218 complaint (_("function `%s' appears to be defined "
2219 "outside of all compilation units"),
2220 arg1);
2221 }
2222
2223 /* Use the STORAGE_CLASS to compute which section the given symbol
2224 belongs to, and then records this new minimal symbol. */
2225
2226 static void
2227 record_minimal_symbol (minimal_symbol_reader &reader,
2228 const char *name, const CORE_ADDR address,
2229 enum minimal_symbol_type ms_type, int storage_class,
2230 struct objfile *objfile)
2231 {
2232 int section;
2233
2234 switch (storage_class)
2235 {
2236 case scText:
2237 section = SECT_OFF_TEXT (objfile);
2238 break;
2239 case scData:
2240 section = SECT_OFF_DATA (objfile);
2241 break;
2242 case scBss:
2243 section = SECT_OFF_BSS (objfile);
2244 break;
2245 case scSData:
2246 section = get_section_index (objfile, ".sdata");
2247 break;
2248 case scSBss:
2249 section = get_section_index (objfile, ".sbss");
2250 break;
2251 case scRData:
2252 section = get_section_index (objfile, ".rdata");
2253 break;
2254 case scInit:
2255 section = get_section_index (objfile, ".init");
2256 break;
2257 case scXData:
2258 section = get_section_index (objfile, ".xdata");
2259 break;
2260 case scPData:
2261 section = get_section_index (objfile, ".pdata");
2262 break;
2263 case scFini:
2264 section = get_section_index (objfile, ".fini");
2265 break;
2266 case scRConst:
2267 section = get_section_index (objfile, ".rconst");
2268 break;
2269 #ifdef scTlsData
2270 case scTlsData:
2271 section = get_section_index (objfile, ".tlsdata");
2272 break;
2273 #endif
2274 #ifdef scTlsBss
2275 case scTlsBss:
2276 section = get_section_index (objfile, ".tlsbss");
2277 break;
2278 #endif
2279 default:
2280 /* This kind of symbol is not associated to a section. */
2281 section = -1;
2282 }
2283
2284 reader.record_with_info (name, address, ms_type, section);
2285 }
2286
2287 /* Master parsing procedure for first-pass reading of file symbols
2288 into a partial_symtab. */
2289
2290 static void
2291 parse_partial_symbols (minimal_symbol_reader &reader,
2292 struct objfile *objfile)
2293 {
2294 struct gdbarch *gdbarch = objfile->arch ();
2295 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
2296 const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
2297 const bfd_size_type external_ext_size = debug_swap->external_ext_size;
2298 void (*const swap_ext_in) (bfd *, void *, EXTR *) = debug_swap->swap_ext_in;
2299 void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
2300 void (*const swap_rfd_in) (bfd *, void *, RFDT *) = debug_swap->swap_rfd_in;
2301 int f_idx, s_idx;
2302 HDRR *hdr = &debug_info->symbolic_header;
2303 /* Running pointers */
2304 FDR *fh;
2305 char *ext_out;
2306 char *ext_out_end;
2307 EXTR *ext_in;
2308 EXTR *ext_in_end;
2309 SYMR sh;
2310 legacy_psymtab *pst;
2311 int textlow_not_set = 1;
2312
2313 /* List of current psymtab's include files. */
2314 const char **psymtab_include_list;
2315 int includes_allocated;
2316 int includes_used;
2317 EXTR *extern_tab;
2318 struct pst_map *fdr_to_pst;
2319 /* Index within current psymtab dependency list. */
2320 legacy_psymtab **dependency_list;
2321 int dependencies_used, dependencies_allocated;
2322 char *name;
2323 enum language prev_language;
2324 asection *text_sect;
2325 int relocatable = 0;
2326
2327 /* Irix 5.2 shared libraries have a fh->adr field of zero, but
2328 the shared libraries are prelinked at a high memory address.
2329 We have to adjust the start address of the object file for this case,
2330 by setting it to the start address of the first procedure in the file.
2331 But we should do no adjustments if we are debugging a .o file, where
2332 the text section (and fh->adr) really starts at zero. */
2333 text_sect = bfd_get_section_by_name (cur_bfd, ".text");
2334 if (text_sect != NULL
2335 && (bfd_section_flags (text_sect) & SEC_RELOC))
2336 relocatable = 1;
2337
2338 extern_tab = XOBNEWVEC (&objfile->objfile_obstack, EXTR, hdr->iextMax);
2339
2340 includes_allocated = 30;
2341 includes_used = 0;
2342 psymtab_include_list = (const char **) alloca (includes_allocated *
2343 sizeof (const char *));
2344 next_symbol_text_func = mdebug_next_symbol_text;
2345
2346 dependencies_allocated = 30;
2347 dependencies_used = 0;
2348 dependency_list =
2349 (legacy_psymtab **) alloca (dependencies_allocated *
2350 sizeof (legacy_psymtab *));
2351
2352 set_last_source_file (NULL);
2353
2354 /*
2355 * Big plan:
2356 *
2357 * Only parse the Local and External symbols, and the Relative FDR.
2358 * Fixup enough of the loader symtab to be able to use it.
2359 * Allocate space only for the file's portions we need to
2360 * look at. (XXX)
2361 */
2362
2363 max_gdbinfo = 0;
2364 max_glevel = MIN_GLEVEL;
2365
2366 /* Allocate the map FDR -> PST.
2367 Minor hack: -O3 images might claim some global data belongs
2368 to FDR -1. We`ll go along with that. */
2369 gdb::def_vector<struct pst_map> fdr_to_pst_holder (hdr->ifdMax + 1);
2370 fdr_to_pst = fdr_to_pst_holder.data ();
2371 fdr_to_pst++;
2372 {
2373 legacy_psymtab *new_pst = new_psymtab ("", objfile);
2374
2375 fdr_to_pst[-1].pst = new_pst;
2376 FDR_IDX (new_pst) = -1;
2377 }
2378
2379 /* Allocate the global pending list. */
2380 pending_list = XOBNEWVEC (&objfile->objfile_obstack, mdebug_pending *,
2381 hdr->ifdMax);
2382 memset (pending_list, 0,
2383 hdr->ifdMax * sizeof (struct mdebug_pending *));
2384
2385 /* Pass 0 over external syms: swap them in. */
2386 gdb::def_vector<EXTR> ext_block (hdr->iextMax);
2387
2388 ext_out = (char *) debug_info->external_ext;
2389 ext_out_end = ext_out + hdr->iextMax * external_ext_size;
2390 ext_in = ext_block.data ();
2391 for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
2392 (*swap_ext_in) (cur_bfd, ext_out, ext_in);
2393
2394 /* Pass 1 over external syms: Presize and partition the list. */
2395 ext_in = ext_block.data ();
2396 ext_in_end = ext_in + hdr->iextMax;
2397 for (; ext_in < ext_in_end; ext_in++)
2398 {
2399 /* See calls to complain below. */
2400 if (ext_in->ifd >= -1
2401 && ext_in->ifd < hdr->ifdMax
2402 && ext_in->asym.iss >= 0
2403 && ext_in->asym.iss < hdr->issExtMax)
2404 fdr_to_pst[ext_in->ifd].n_globals++;
2405 }
2406
2407 /* Pass 1.5 over files: partition out global symbol space. */
2408 s_idx = 0;
2409 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
2410 {
2411 fdr_to_pst[f_idx].globals_offset = s_idx;
2412 s_idx += fdr_to_pst[f_idx].n_globals;
2413 fdr_to_pst[f_idx].n_globals = 0;
2414 }
2415
2416 /* ECOFF in ELF:
2417
2418 For ECOFF in ELF, we skip the creation of the minimal symbols.
2419 The ECOFF symbols should be a subset of the Elf symbols, and the
2420 section information of the elf symbols will be more accurate.
2421 FIXME! What about Irix 5's native linker?
2422
2423 By default, Elf sections which don't exist in ECOFF
2424 get put in ECOFF's absolute section by the gnu linker.
2425 Since absolute sections don't get relocated, we
2426 end up calculating an address different from that of
2427 the symbol's minimal symbol (created earlier from the
2428 Elf symtab).
2429
2430 To fix this, either :
2431 1) don't create the duplicate symbol
2432 (assumes ECOFF symtab is a subset of the ELF symtab;
2433 assumes no side-effects result from ignoring ECOFF symbol)
2434 2) create it, only if lookup for existing symbol in ELF's minimal
2435 symbols fails
2436 (inefficient;
2437 assumes no side-effects result from ignoring ECOFF symbol)
2438 3) create it, but lookup ELF's minimal symbol and use it's section
2439 during relocation, then modify "uniquify" phase to merge and
2440 eliminate the duplicate symbol
2441 (highly inefficient)
2442
2443 I've implemented #1 here...
2444 Skip the creation of the minimal symbols based on the ECOFF
2445 symbol table. */
2446
2447 /* Pass 2 over external syms: fill in external symbols. */
2448 ext_in = ext_block.data ();
2449 ext_in_end = ext_in + hdr->iextMax;
2450 for (; ext_in < ext_in_end; ext_in++)
2451 {
2452 enum minimal_symbol_type ms_type = mst_text;
2453 CORE_ADDR svalue = ext_in->asym.value;
2454
2455 /* The Irix 5 native tools seem to sometimes generate bogus
2456 external symbols. */
2457 if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
2458 {
2459 complaint (_("bad ifd for external symbol: %d (max %ld)"),
2460 ext_in->ifd, hdr->ifdMax);
2461 continue;
2462 }
2463 if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
2464 {
2465 complaint (_("bad iss for external symbol: %ld (max %ld)"),
2466 ext_in->asym.iss, hdr->issExtMax);
2467 continue;
2468 }
2469
2470 extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
2471 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
2472
2473
2474 if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
2475 continue;
2476
2477
2478 /* Pass 3 over files, over local syms: fill in static symbols. */
2479 name = debug_info->ssext + ext_in->asym.iss;
2480
2481 /* Process ECOFF Symbol Types and Storage Classes. */
2482 switch (ext_in->asym.st)
2483 {
2484 case stProc:
2485 /* Beginnning of Procedure */
2486 break;
2487 case stStaticProc:
2488 /* Load time only static procs */
2489 ms_type = mst_file_text;
2490 break;
2491 case stGlobal:
2492 /* External symbol */
2493 if (SC_IS_COMMON (ext_in->asym.sc))
2494 {
2495 /* The value of a common symbol is its size, not its address.
2496 Ignore it. */
2497 continue;
2498 }
2499 else if (SC_IS_DATA (ext_in->asym.sc))
2500 {
2501 ms_type = mst_data;
2502 }
2503 else if (SC_IS_BSS (ext_in->asym.sc))
2504 {
2505 ms_type = mst_bss;
2506 }
2507 else if (SC_IS_SBSS (ext_in->asym.sc))
2508 {
2509 ms_type = mst_bss;
2510 }
2511 else
2512 ms_type = mst_abs;
2513 break;
2514 case stLabel:
2515 /* Label */
2516
2517 /* On certain platforms, some extra label symbols can be
2518 generated by the linker. One possible usage for this kind
2519 of symbols is to represent the address of the begining of a
2520 given section. For instance, on Tru64 5.1, the address of
2521 the _ftext label is the start address of the .text section.
2522
2523 The storage class of these symbols is usually directly
2524 related to the section to which the symbol refers. For
2525 instance, on Tru64 5.1, the storage class for the _fdata
2526 label is scData, refering to the .data section.
2527
2528 It is actually possible that the section associated to the
2529 storage class of the label does not exist. On True64 5.1
2530 for instance, the libm.so shared library does not contain
2531 any .data section, although it contains a _fpdata label
2532 which storage class is scData... Since these symbols are
2533 usually useless for the debugger user anyway, we just
2534 discard these symbols. */
2535
2536 if (SC_IS_TEXT (ext_in->asym.sc))
2537 {
2538 if (objfile->sect_index_text == -1)
2539 continue;
2540
2541 ms_type = mst_file_text;
2542 }
2543 else if (SC_IS_DATA (ext_in->asym.sc))
2544 {
2545 if (objfile->sect_index_data == -1)
2546 continue;
2547
2548 ms_type = mst_file_data;
2549 }
2550 else if (SC_IS_BSS (ext_in->asym.sc))
2551 {
2552 if (objfile->sect_index_bss == -1)
2553 continue;
2554
2555 ms_type = mst_file_bss;
2556 }
2557 else if (SC_IS_SBSS (ext_in->asym.sc))
2558 {
2559 const int sbss_sect_index = get_section_index (objfile, ".sbss");
2560
2561 if (sbss_sect_index == -1)
2562 continue;
2563
2564 ms_type = mst_file_bss;
2565 }
2566 else
2567 ms_type = mst_abs;
2568 break;
2569 case stLocal:
2570 case stNil:
2571 /* The alpha has the section start addresses in stLocal symbols
2572 whose name starts with a `.'. Skip those but complain for all
2573 other stLocal symbols.
2574 Irix6 puts the section start addresses in stNil symbols, skip
2575 those too. */
2576 if (name[0] == '.')
2577 continue;
2578 /* Fall through. */
2579 default:
2580 ms_type = mst_unknown;
2581 unknown_ext_complaint (name);
2582 }
2583 if (!ECOFF_IN_ELF (cur_bfd))
2584 record_minimal_symbol (reader, name, svalue, ms_type, ext_in->asym.sc,
2585 objfile);
2586 }
2587
2588 /* Pass 3 over files, over local syms: fill in static symbols. */
2589 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2590 {
2591 legacy_psymtab *save_pst;
2592 EXTR *ext_ptr;
2593 CORE_ADDR textlow;
2594
2595 cur_fdr = fh = debug_info->fdr + f_idx;
2596
2597 if (fh->csym == 0)
2598 {
2599 fdr_to_pst[f_idx].pst = NULL;
2600 continue;
2601 }
2602
2603 /* Determine the start address for this object file from the
2604 file header and relocate it, except for Irix 5.2 zero fh->adr. */
2605 if (fh->cpd)
2606 textlow = fh->adr;
2607 else
2608 textlow = 0;
2609 pst = new legacy_psymtab (fdr_name (fh), objfile, textlow);
2610 pst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, symloc);
2611 memset (pst->read_symtab_private, 0, sizeof (struct symloc));
2612
2613 save_pst = pst;
2614 FDR_IDX (pst) = f_idx;
2615 CUR_BFD (pst) = cur_bfd;
2616 DEBUG_SWAP (pst) = debug_swap;
2617 DEBUG_INFO (pst) = debug_info;
2618 PENDING_LIST (pst) = pending_list;
2619
2620 /* The way to turn this into a symtab is to call... */
2621 pst->legacy_read_symtab = mdebug_read_symtab;
2622 pst->legacy_expand_psymtab = mdebug_expand_psymtab;
2623
2624 /* Set up language for the pst.
2625 The language from the FDR is used if it is unambigious (e.g. cfront
2626 with native cc and g++ will set the language to C).
2627 Otherwise we have to deduce the language from the filename.
2628 Native ecoff has every header file in a separate FDR, so
2629 deduce_language_from_filename will return language_unknown for
2630 a header file, which is not what we want.
2631 But the FDRs for the header files are after the FDR for the source
2632 file, so we can assign the language of the source file to the
2633 following header files. Then we save the language in the private
2634 pst data so that we can reuse it when building symtabs. */
2635 prev_language = psymtab_language;
2636
2637 switch (fh->lang)
2638 {
2639 case langCplusplusV2:
2640 psymtab_language = language_cplus;
2641 break;
2642 default:
2643 psymtab_language = deduce_language_from_filename (fdr_name (fh));
2644 break;
2645 }
2646 if (psymtab_language == language_unknown)
2647 psymtab_language = prev_language;
2648 PST_PRIVATE (pst)->pst_language = psymtab_language;
2649
2650 pst->set_text_high (pst->raw_text_low ());
2651
2652 /* For stabs-in-ecoff files, the second symbol must be @stab.
2653 This symbol is emitted by mips-tfile to signal that the
2654 current object file uses encapsulated stabs instead of mips
2655 ecoff for local symbols. (It is the second symbol because
2656 the first symbol is the stFile used to signal the start of a
2657 file). */
2658 processing_gcc_compilation = 0;
2659 if (fh->csym >= 2)
2660 {
2661 (*swap_sym_in) (cur_bfd,
2662 ((char *) debug_info->external_sym
2663 + (fh->isymBase + 1) * external_sym_size),
2664 &sh);
2665 if (strcmp (debug_info->ss + fh->issBase + sh.iss,
2666 stabs_symbol) == 0)
2667 processing_gcc_compilation = 2;
2668 }
2669
2670 if (processing_gcc_compilation != 0)
2671 {
2672 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2673 {
2674 int type_code;
2675 const char *namestring;
2676
2677 (*swap_sym_in) (cur_bfd,
2678 (((char *) debug_info->external_sym)
2679 + (fh->isymBase + cur_sdx) * external_sym_size),
2680 &sh);
2681 type_code = ECOFF_UNMARK_STAB (sh.index);
2682 if (!ECOFF_IS_STAB (&sh))
2683 {
2684 if (sh.st == stProc || sh.st == stStaticProc)
2685 {
2686 CORE_ADDR procaddr;
2687 long isym;
2688
2689 if (sh.st == stStaticProc)
2690 {
2691 namestring = debug_info->ss + fh->issBase + sh.iss;
2692 record_minimal_symbol (reader, namestring, sh.value,
2693 mst_file_text, sh.sc,
2694 objfile);
2695 }
2696 procaddr = sh.value;
2697
2698 isym = AUX_GET_ISYM (fh->fBigendian,
2699 (debug_info->external_aux
2700 + fh->iauxBase
2701 + sh.index));
2702 (*swap_sym_in) (cur_bfd,
2703 ((char *) debug_info->external_sym
2704 + ((fh->isymBase + isym - 1)
2705 * external_sym_size)),
2706 &sh);
2707 if (sh.st == stEnd)
2708 {
2709 CORE_ADDR high = procaddr + sh.value;
2710
2711 /* Kludge for Irix 5.2 zero fh->adr. */
2712 if (!relocatable
2713 && (!pst->text_low_valid
2714 || procaddr < pst->raw_text_low ()))
2715 pst->set_text_low (procaddr);
2716 if (high > pst->raw_text_high ())
2717 pst->set_text_high (high);
2718 }
2719 }
2720 else if (sh.st == stStatic)
2721 {
2722 switch (sh.sc)
2723 {
2724 case scUndefined:
2725 case scSUndefined:
2726 case scNil:
2727 case scAbs:
2728 break;
2729
2730 case scData:
2731 case scSData:
2732 case scRData:
2733 case scPData:
2734 case scXData:
2735 namestring = debug_info->ss + fh->issBase + sh.iss;
2736 record_minimal_symbol (reader, namestring, sh.value,
2737 mst_file_data, sh.sc,
2738 objfile);
2739 break;
2740
2741 default:
2742 /* FIXME! Shouldn't this use cases for bss,
2743 then have the default be abs? */
2744 namestring = debug_info->ss + fh->issBase + sh.iss;
2745 record_minimal_symbol (reader, namestring, sh.value,
2746 mst_file_bss, sh.sc,
2747 objfile);
2748 break;
2749 }
2750 }
2751 continue;
2752 }
2753 /* Handle stabs continuation. */
2754 {
2755 char *stabstring = debug_info->ss + fh->issBase + sh.iss;
2756 /* If we need to heap-allocate STABSTRING, this owns
2757 it. */
2758 gdb::unique_xmalloc_ptr<char> stabstring_storage;
2759 int len = strlen (stabstring);
2760
2761 while (stabstring[len - 1] == '\\')
2762 {
2763 SYMR sh2;
2764 char *stabstring1 = stabstring;
2765 char *stabstring2;
2766 int len2;
2767
2768 /* Ignore continuation char from 1st string. */
2769 len--;
2770
2771 /* Read next stabstring. */
2772 cur_sdx++;
2773 (*swap_sym_in) (cur_bfd,
2774 (((char *) debug_info->external_sym)
2775 + (fh->isymBase + cur_sdx)
2776 * external_sym_size),
2777 &sh2);
2778 stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
2779 len2 = strlen (stabstring2);
2780
2781 /* Concatenate stabstring2 with stabstring1. */
2782 if (stabstring_storage != nullptr)
2783 {
2784 stabstring_storage.reset
2785 ((char *) xrealloc (stabstring_storage.release (),
2786 len + len2 + 1));
2787 stabstring = stabstring_storage.get ();
2788 }
2789 else
2790 {
2791 stabstring_storage.reset
2792 ((char *) xmalloc (len + len2 + 1));
2793 stabstring = stabstring_storage.get ();
2794 strcpy (stabstring, stabstring1);
2795 }
2796 strcpy (stabstring + len, stabstring2);
2797 len += len2;
2798 }
2799
2800 switch (type_code)
2801 {
2802 const char *p;
2803
2804 /* Standard, external, non-debugger, symbols. */
2805
2806 case N_TEXT | N_EXT:
2807 case N_NBTEXT | N_EXT:
2808 goto record_it;
2809
2810 case N_DATA | N_EXT:
2811 case N_NBDATA | N_EXT:
2812 goto record_it;
2813
2814 case N_BSS:
2815 case N_BSS | N_EXT:
2816 case N_NBBSS | N_EXT:
2817 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
2818 goto record_it;
2819
2820 case N_ABS | N_EXT:
2821 record_it:
2822 continue;
2823
2824 /* Standard, local, non-debugger, symbols. */
2825
2826 case N_NBTEXT:
2827
2828 /* We need to be able to deal with both N_FN or
2829 N_TEXT, because we have no way of knowing
2830 whether the sys-supplied ld or GNU ld was used
2831 to make the executable. Sequents throw in
2832 another wrinkle -- they renumbered N_FN. */
2833
2834 case N_FN:
2835 case N_FN_SEQ:
2836 case N_TEXT:
2837 continue;
2838
2839 case N_DATA:
2840 goto record_it;
2841
2842 case N_UNDF | N_EXT:
2843 continue; /* Just undefined, not COMMON. */
2844
2845 case N_UNDF:
2846 continue;
2847
2848 /* Lots of symbol types we can just ignore. */
2849
2850 case N_ABS:
2851 case N_NBDATA:
2852 case N_NBBSS:
2853 continue;
2854
2855 /* Keep going . . . */
2856
2857 /*
2858 * Special symbol types for GNU
2859 */
2860 case N_INDR:
2861 case N_INDR | N_EXT:
2862 case N_SETA:
2863 case N_SETA | N_EXT:
2864 case N_SETT:
2865 case N_SETT | N_EXT:
2866 case N_SETD:
2867 case N_SETD | N_EXT:
2868 case N_SETB:
2869 case N_SETB | N_EXT:
2870 case N_SETV:
2871 continue;
2872
2873 /*
2874 * Debugger symbols
2875 */
2876
2877 case N_SO:
2878 {
2879 static int prev_so_symnum = -10;
2880 const char *basename;
2881
2882 /* A zero value is probably an indication for the
2883 SunPRO 3.0 compiler. dbx_end_psymtab explicitly tests
2884 for zero, so don't relocate it. */
2885
2886 if (sh.value == 0
2887 && gdbarch_sofun_address_maybe_missing (gdbarch))
2888 textlow_not_set = 1;
2889 else
2890 textlow_not_set = 0;
2891
2892 if (prev_so_symnum != symnum - 1)
2893 { /* Here if prev stab wasn't N_SO. */
2894 if (pst)
2895 {
2896 pst = (legacy_psymtab *) 0;
2897 includes_used = 0;
2898 dependencies_used = 0;
2899 }
2900 }
2901
2902 prev_so_symnum = symnum;
2903
2904 /* End the current partial symtab and start a
2905 new one. */
2906
2907 /* SET_NAMESTRING ();*/
2908 namestring = stabstring;
2909
2910 /* Null name means end of .o file. Don't start a new
2911 one. */
2912 if (*namestring == '\000')
2913 continue;
2914
2915 /* Some compilers (including gcc) emit a pair of
2916 initial N_SOs. The first one is a directory name;
2917 the second the file name. If pst exists, is
2918 empty, and has a filename ending in '/', we assume
2919 the previous N_SO was a directory name. */
2920 basename = lbasename (namestring);
2921 if (basename != namestring && *basename == '\000')
2922 continue; /* Simply ignore directory
2923 name SOs. */
2924
2925 /* Some other compilers (C++ ones in particular) emit
2926 useless SOs for non-existant .c files. We ignore
2927 all subsequent SOs that immediately follow the
2928 first. */
2929
2930 if (!pst)
2931 pst = save_pst;
2932 continue;
2933 }
2934
2935 case N_BINCL:
2936 continue;
2937
2938 case N_SOL:
2939 {
2940 enum language tmp_language;
2941
2942 /* Mark down an include file in the current psymtab. */
2943
2944 /* SET_NAMESTRING (); */
2945 namestring = stabstring;
2946
2947 tmp_language
2948 = deduce_language_from_filename (namestring);
2949
2950 /* Only change the psymtab's language if we've
2951 learned something useful (eg. tmp_language is not
2952 language_unknown). In addition, to match what
2953 start_subfile does, never change from C++ to
2954 C. */
2955 if (tmp_language != language_unknown
2956 && (tmp_language != language_c
2957 || psymtab_language != language_cplus))
2958 psymtab_language = tmp_language;
2959
2960 /* In C++, one may expect the same filename to come
2961 round many times, when code is coming alternately
2962 from the main file and from inline functions in
2963 other files. So I check to see if this is a file
2964 we've seen before -- either the main source file,
2965 or a previously included file.
2966
2967 This seems to be a lot of time to be spending on
2968 N_SOL, but things like "break c-exp.y:435" need to
2969 work (I suppose the psymtab_include_list could be
2970 hashed or put in a binary tree, if profiling shows
2971 this is a major hog). */
2972 if (pst && filename_cmp (namestring, pst->filename) == 0)
2973 continue;
2974
2975 {
2976 int i;
2977
2978 for (i = 0; i < includes_used; i++)
2979 if (filename_cmp (namestring,
2980 psymtab_include_list[i]) == 0)
2981 {
2982 i = -1;
2983 break;
2984 }
2985 if (i == -1)
2986 continue;
2987 }
2988
2989 psymtab_include_list[includes_used++] = namestring;
2990 if (includes_used >= includes_allocated)
2991 {
2992 const char **orig = psymtab_include_list;
2993
2994 psymtab_include_list = (const char **)
2995 alloca ((includes_allocated *= 2) *
2996 sizeof (const char *));
2997 memcpy (psymtab_include_list, orig,
2998 includes_used * sizeof (const char *));
2999 }
3000 continue;
3001 }
3002 case N_LSYM: /* Typedef or automatic variable. */
3003 case N_STSYM: /* Data seg var -- static */
3004 case N_LCSYM: /* BSS " */
3005 case N_ROSYM: /* Read-only data seg var -- static. */
3006 case N_NBSTS: /* Gould nobase. */
3007 case N_NBLCS: /* symbols. */
3008 case N_FUN:
3009 case N_GSYM: /* Global (extern) variable; can be
3010 data or bss (sigh FIXME). */
3011
3012 /* Following may probably be ignored; I'll leave them here
3013 for now (until I do Pascal and Modula 2 extensions). */
3014
3015 case N_PC: /* I may or may not need this; I
3016 suspect not. */
3017 case N_M2C: /* I suspect that I can ignore this
3018 here. */
3019 case N_SCOPE: /* Same. */
3020
3021 /* SET_NAMESTRING (); */
3022 namestring = stabstring;
3023 p = (char *) strchr (namestring, ':');
3024 if (!p)
3025 continue; /* Not a debugging symbol. */
3026
3027
3028
3029 /* Main processing section for debugging symbols which
3030 the initial read through the symbol tables needs to
3031 worry about. If we reach this point, the symbol
3032 which we are considering is definitely one we are
3033 interested in. p must also contain the (valid)
3034 index into the namestring which indicates the
3035 debugging type symbol. */
3036
3037 switch (p[1])
3038 {
3039 case 'S':
3040 add_psymbol_to_list (gdb::string_view (namestring,
3041 p - namestring),
3042 true, VAR_DOMAIN, LOC_STATIC,
3043 SECT_OFF_DATA (objfile),
3044 psymbol_placement::STATIC,
3045 sh.value,
3046 psymtab_language, objfile);
3047 continue;
3048 case 'G':
3049 /* The addresses in these entries are reported
3050 to be wrong. See the code that reads 'G's
3051 for symtabs. */
3052 add_psymbol_to_list (gdb::string_view (namestring,
3053 p - namestring),
3054 true, VAR_DOMAIN, LOC_STATIC,
3055 SECT_OFF_DATA (objfile),
3056 psymbol_placement::GLOBAL,
3057 sh.value,
3058 psymtab_language, objfile);
3059 continue;
3060
3061 case 'T':
3062 /* When a 'T' entry is defining an anonymous enum, it
3063 may have a name which is the empty string, or a
3064 single space. Since they're not really defining a
3065 symbol, those shouldn't go in the partial symbol
3066 table. We do pick up the elements of such enums at
3067 'check_enum:', below. */
3068 if (p >= namestring + 2
3069 || (p == namestring + 1
3070 && namestring[0] != ' '))
3071 {
3072 add_psymbol_to_list
3073 (gdb::string_view (namestring, p - namestring),
3074 true, STRUCT_DOMAIN, LOC_TYPEDEF, -1,
3075 psymbol_placement::STATIC, 0, psymtab_language,
3076 objfile);
3077 if (p[2] == 't')
3078 {
3079 /* Also a typedef with the same name. */
3080 add_psymbol_to_list
3081 (gdb::string_view (namestring,
3082 p - namestring),
3083 true, VAR_DOMAIN, LOC_TYPEDEF, -1,
3084 psymbol_placement::STATIC, 0,
3085 psymtab_language, objfile);
3086 p += 1;
3087 }
3088 }
3089 goto check_enum;
3090 case 't':
3091 if (p != namestring) /* a name is there, not
3092 just :T... */
3093 {
3094 add_psymbol_to_list
3095 (gdb::string_view (namestring,
3096 p - namestring),
3097 true, VAR_DOMAIN, LOC_TYPEDEF, -1,
3098 psymbol_placement::STATIC, 0, psymtab_language,
3099 objfile);
3100 }
3101 check_enum:
3102 /* If this is an enumerated type, we need to add
3103 all the enum constants to the partial symbol
3104 table. This does not cover enums without names,
3105 e.g. "enum {a, b} c;" in C, but fortunately
3106 those are rare. There is no way for GDB to find
3107 those from the enum type without spending too
3108 much time on it. Thus to solve this problem,
3109 the compiler needs to put out the enum in a
3110 nameless type. GCC2 does this. */
3111
3112 /* We are looking for something of the form
3113 <name> ":" ("t" | "T") [<number> "="] "e"
3114 {<constant> ":" <value> ","} ";". */
3115
3116 /* Skip over the colon and the 't' or 'T'. */
3117 p += 2;
3118 /* This type may be given a number. Also, numbers
3119 can come in pairs like (0,26). Skip over it. */
3120 while ((*p >= '0' && *p <= '9')
3121 || *p == '(' || *p == ',' || *p == ')'
3122 || *p == '=')
3123 p++;
3124
3125 if (*p++ == 'e')
3126 {
3127 /* The aix4 compiler emits extra crud before
3128 the members. */
3129 if (*p == '-')
3130 {
3131 /* Skip over the type (?). */
3132 while (*p != ':')
3133 p++;
3134
3135 /* Skip over the colon. */
3136 p++;
3137 }
3138
3139 /* We have found an enumerated type. */
3140 /* According to comments in read_enum_type
3141 a comma could end it instead of a semicolon.
3142 I don't know where that happens.
3143 Accept either. */
3144 while (*p && *p != ';' && *p != ',')
3145 {
3146 const char *q;
3147
3148 /* Check for and handle cretinous dbx
3149 symbol name continuation! */
3150 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
3151 p = next_symbol_text (objfile);
3152
3153 /* Point to the character after the name
3154 of the enum constant. */
3155 for (q = p; *q && *q != ':'; q++)
3156 ;
3157 /* Note that the value doesn't matter for
3158 enum constants in psymtabs, just in
3159 symtabs. */
3160 add_psymbol_to_list (gdb::string_view (p,
3161 q - p),
3162 true, VAR_DOMAIN,
3163 LOC_CONST, -1,
3164 psymbol_placement::STATIC,
3165 0, psymtab_language,
3166 objfile);
3167 /* Point past the name. */
3168 p = q;
3169 /* Skip over the value. */
3170 while (*p && *p != ',')
3171 p++;
3172 /* Advance past the comma. */
3173 if (*p)
3174 p++;
3175 }
3176 }
3177 continue;
3178 case 'c':
3179 /* Constant, e.g. from "const" in Pascal. */
3180 add_psymbol_to_list (gdb::string_view (namestring,
3181 p - namestring),
3182 true, VAR_DOMAIN, LOC_CONST, -1,
3183 psymbol_placement::STATIC,
3184 0, psymtab_language, objfile);
3185 continue;
3186
3187 case 'f':
3188 if (! pst)
3189 {
3190 std::string copy (namestring, p);
3191 function_outside_compilation_unit_complaint
3192 (copy.c_str ());
3193 }
3194 add_psymbol_to_list (gdb::string_view (namestring,
3195 p - namestring),
3196 true, VAR_DOMAIN, LOC_BLOCK,
3197 SECT_OFF_TEXT (objfile),
3198 psymbol_placement::STATIC,
3199 sh.value,
3200 psymtab_language, objfile);
3201 continue;
3202
3203 /* Global functions were ignored here, but now they
3204 are put into the global psymtab like one would
3205 expect. They're also in the minimal symbol
3206 table. */
3207 case 'F':
3208 if (! pst)
3209 {
3210 std::string copy (namestring, p);
3211 function_outside_compilation_unit_complaint
3212 (copy.c_str ());
3213 }
3214 add_psymbol_to_list (gdb::string_view (namestring,
3215 p - namestring),
3216 true, VAR_DOMAIN, LOC_BLOCK,
3217 SECT_OFF_TEXT (objfile),
3218 psymbol_placement::GLOBAL,
3219 sh.value,
3220 psymtab_language, objfile);
3221 continue;
3222
3223 /* Two things show up here (hopefully); static
3224 symbols of local scope (static used inside
3225 braces) or extensions of structure symbols. We
3226 can ignore both. */
3227 case 'V':
3228 case '(':
3229 case '0':
3230 case '1':
3231 case '2':
3232 case '3':
3233 case '4':
3234 case '5':
3235 case '6':
3236 case '7':
3237 case '8':
3238 case '9':
3239 case '-':
3240 case '#': /* For symbol identification (used
3241 in live ranges). */
3242 continue;
3243
3244 case ':':
3245 /* It is a C++ nested symbol. We don't need to
3246 record it (I don't think); if we try to look up
3247 foo::bar::baz, then symbols for the symtab
3248 containing foo should get read in, I think. */
3249 /* Someone says sun cc puts out symbols like
3250 /foo/baz/maclib::/usr/local/bin/maclib,
3251 which would get here with a symbol type of ':'. */
3252 continue;
3253
3254 default:
3255 /* Unexpected symbol descriptor. The second and
3256 subsequent stabs of a continued stab can show up
3257 here. The question is whether they ever can
3258 mimic a normal stab--it would be nice if not,
3259 since we certainly don't want to spend the time
3260 searching to the end of every string looking for
3261 a backslash. */
3262
3263 complaint (_("unknown symbol descriptor `%c'"), p[1]);
3264
3265 /* Ignore it; perhaps it is an extension that we don't
3266 know about. */
3267 continue;
3268 }
3269
3270 case N_EXCL:
3271 continue;
3272
3273 case N_ENDM:
3274 /* Solaris 2 end of module, finish current partial
3275 symbol table. dbx_end_psymtab will set the
3276 high text address of PST to the proper value,
3277 which is necessary if a module compiled without
3278 debugging info follows this module. */
3279 if (pst
3280 && gdbarch_sofun_address_maybe_missing (gdbarch))
3281 {
3282 pst = (legacy_psymtab *) 0;
3283 includes_used = 0;
3284 dependencies_used = 0;
3285 }
3286 continue;
3287
3288 case N_RBRAC:
3289 if (sh.value > save_pst->raw_text_high ())
3290 save_pst->set_text_high (sh.value);
3291 continue;
3292 case N_EINCL:
3293 case N_DSLINE:
3294 case N_BSLINE:
3295 case N_SSYM: /* Claim: Structure or union
3296 element. Hopefully, I can
3297 ignore this. */
3298 case N_ENTRY: /* Alternate entry point; can
3299 ignore. */
3300 case N_MAIN: /* Can definitely ignore this. */
3301 case N_CATCH: /* These are GNU C++ extensions. */
3302 case N_EHDECL: /* that can safely be ignored here. */
3303 case N_LENG:
3304 case N_BCOMM:
3305 case N_ECOMM:
3306 case N_ECOML:
3307 case N_FNAME:
3308 case N_SLINE:
3309 case N_RSYM:
3310 case N_PSYM:
3311 case N_LBRAC:
3312 case N_NSYMS: /* Ultrix 4.0: symbol count */
3313 case N_DEFD: /* GNU Modula-2 */
3314 case N_ALIAS: /* SunPro F77: alias name, ignore
3315 for now. */
3316
3317 case N_OBJ: /* Useless types from Solaris. */
3318 case N_OPT:
3319 /* These symbols aren't interesting; don't worry about
3320 them. */
3321
3322 continue;
3323
3324 default:
3325 /* If we haven't found it yet, ignore it. It's
3326 probably some new type we don't know about yet. */
3327 complaint (_("unknown symbol type %s"),
3328 hex_string (type_code)); /* CUR_SYMBOL_TYPE */
3329 continue;
3330 }
3331 }
3332 /* end - Handle continuation */
3333 }
3334 }
3335 else
3336 {
3337 for (cur_sdx = 0; cur_sdx < fh->csym;)
3338 {
3339 char *sym_name;
3340 enum address_class theclass;
3341 CORE_ADDR minsym_value;
3342 short section = -1;
3343
3344 (*swap_sym_in) (cur_bfd,
3345 ((char *) debug_info->external_sym
3346 + ((fh->isymBase + cur_sdx)
3347 * external_sym_size)),
3348 &sh);
3349
3350 if (ECOFF_IS_STAB (&sh))
3351 {
3352 cur_sdx++;
3353 continue;
3354 }
3355
3356 /* Non absolute static symbols go into the minimal table. */
3357 if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
3358 || (sh.index == indexNil
3359 && (sh.st != stStatic || sh.sc == scAbs)))
3360 {
3361 /* FIXME, premature? */
3362 cur_sdx++;
3363 continue;
3364 }
3365
3366 sym_name = debug_info->ss + fh->issBase + sh.iss;
3367
3368 minsym_value = sh.value;
3369
3370 switch (sh.sc)
3371 {
3372 case scText:
3373 case scRConst:
3374 /* The value of a stEnd symbol is the displacement from the
3375 corresponding start symbol value, do not relocate it. */
3376 if (sh.st != stEnd)
3377 section = SECT_OFF_TEXT (objfile);
3378 break;
3379 case scData:
3380 case scSData:
3381 case scRData:
3382 case scPData:
3383 case scXData:
3384 section = SECT_OFF_DATA (objfile);
3385 break;
3386 case scBss:
3387 case scSBss:
3388 section = SECT_OFF_BSS (objfile);
3389 break;
3390 }
3391
3392 switch (sh.st)
3393 {
3394 CORE_ADDR high;
3395 CORE_ADDR procaddr;
3396 int new_sdx;
3397
3398 case stStaticProc:
3399 reader.record_with_info (sym_name, minsym_value,
3400 mst_file_text,
3401 SECT_OFF_TEXT (objfile));
3402
3403 /* FALLTHROUGH */
3404
3405 case stProc:
3406 /* Ignore all parameter symbol records. */
3407 if (sh.index >= hdr->iauxMax)
3408 {
3409 /* Should not happen, but does when cross-compiling
3410 with the MIPS compiler. FIXME -- pull later. */
3411 index_complaint (sym_name);
3412 new_sdx = cur_sdx + 1; /* Don't skip at all. */
3413 }
3414 else
3415 new_sdx = AUX_GET_ISYM (fh->fBigendian,
3416 (debug_info->external_aux
3417 + fh->iauxBase
3418 + sh.index));
3419
3420 if (new_sdx <= cur_sdx)
3421 {
3422 /* This should not happen either... FIXME. */
3423 complaint (_("bad proc end in aux found from symbol %s"),
3424 sym_name);
3425 new_sdx = cur_sdx + 1; /* Don't skip backward. */
3426 }
3427
3428 /* For stProc symbol records, we need to check the
3429 storage class as well, as only (stProc, scText)
3430 entries represent "real" procedures - See the
3431 Compaq document titled "Object File / Symbol Table
3432 Format Specification" for more information. If the
3433 storage class is not scText, we discard the whole
3434 block of symbol records for this stProc. */
3435 if (sh.st == stProc && sh.sc != scText)
3436 goto skip;
3437
3438 /* Usually there is a local and a global stProc symbol
3439 for a function. This means that the function name
3440 has already been entered into the minimal symbol table
3441 while processing the global symbols in pass 2 above.
3442 One notable exception is the PROGRAM name from
3443 f77 compiled executables, it is only put out as
3444 local stProc symbol, and a global MAIN__ stProc symbol
3445 points to it. It doesn't matter though, as gdb is
3446 still able to find the PROGRAM name via the partial
3447 symbol table, and the MAIN__ symbol via the minimal
3448 symbol table. */
3449 if (sh.st == stProc)
3450 add_psymbol_to_list (sym_name, true,
3451 VAR_DOMAIN, LOC_BLOCK,
3452 section,
3453 psymbol_placement::GLOBAL,
3454 sh.value, psymtab_language, objfile);
3455 else
3456 add_psymbol_to_list (sym_name, true,
3457 VAR_DOMAIN, LOC_BLOCK,
3458 section,
3459 psymbol_placement::STATIC,
3460 sh.value, psymtab_language, objfile);
3461
3462 procaddr = sh.value;
3463
3464 cur_sdx = new_sdx;
3465 (*swap_sym_in) (cur_bfd,
3466 ((char *) debug_info->external_sym
3467 + ((fh->isymBase + cur_sdx - 1)
3468 * external_sym_size)),
3469 &sh);
3470 if (sh.st != stEnd)
3471 continue;
3472
3473 /* Kludge for Irix 5.2 zero fh->adr. */
3474 if (!relocatable
3475 && (!pst->text_low_valid
3476 || procaddr < pst->raw_text_low ()))
3477 pst->set_text_low (procaddr);
3478
3479 high = procaddr + sh.value;
3480 if (high > pst->raw_text_high ())
3481 pst->set_text_high (high);
3482 continue;
3483
3484 case stStatic: /* Variable */
3485 if (SC_IS_DATA (sh.sc))
3486 reader.record_with_info (sym_name, minsym_value,
3487 mst_file_data,
3488 SECT_OFF_DATA (objfile));
3489 else
3490 reader.record_with_info (sym_name, minsym_value,
3491 mst_file_bss,
3492 SECT_OFF_BSS (objfile));
3493 theclass = LOC_STATIC;
3494 break;
3495
3496 case stIndirect: /* Irix5 forward declaration */
3497 /* Skip forward declarations from Irix5 cc. */
3498 goto skip;
3499
3500 case stTypedef: /* Typedef */
3501 /* Skip typedefs for forward declarations and opaque
3502 structs from alpha and mips cc. */
3503 if (sh.iss == 0 || has_opaque_xref (fh, &sh))
3504 goto skip;
3505 theclass = LOC_TYPEDEF;
3506 break;
3507
3508 case stConstant: /* Constant decl */
3509 theclass = LOC_CONST;
3510 break;
3511
3512 case stUnion:
3513 case stStruct:
3514 case stEnum:
3515 case stBlock: /* { }, str, un, enum */
3516 /* Do not create a partial symbol for cc unnamed aggregates
3517 and gcc empty aggregates. */
3518 if ((sh.sc == scInfo
3519 || SC_IS_COMMON (sh.sc))
3520 && sh.iss != 0
3521 && sh.index != cur_sdx + 2)
3522 {
3523 add_psymbol_to_list (sym_name, true,
3524 STRUCT_DOMAIN, LOC_TYPEDEF, -1,
3525 psymbol_placement::STATIC,
3526 0, psymtab_language, objfile);
3527 }
3528 handle_psymbol_enumerators (objfile, fh, sh.st, sh.value);
3529
3530 /* Skip over the block. */
3531 new_sdx = sh.index;
3532 if (new_sdx <= cur_sdx)
3533 {
3534 /* This happens with the Ultrix kernel. */
3535 complaint (_("bad aux index at block symbol %s"),
3536 sym_name);
3537 new_sdx = cur_sdx + 1; /* Don't skip backward. */
3538 }
3539 cur_sdx = new_sdx;
3540 continue;
3541
3542 case stFile: /* File headers */
3543 case stLabel: /* Labels */
3544 case stEnd: /* Ends of files */
3545 goto skip;
3546
3547 case stLocal: /* Local variables */
3548 /* Normally these are skipped because we skip over
3549 all blocks we see. However, these can occur
3550 as visible symbols in a .h file that contains code. */
3551 goto skip;
3552
3553 default:
3554 /* Both complaints are valid: one gives symbol sym_name,
3555 the other the offending symbol type. */
3556 complaint (_("unknown local symbol %s"),
3557 sym_name);
3558 complaint (_("with type %d"), sh.st);
3559 cur_sdx++;
3560 continue;
3561 }
3562 /* Use this gdb symbol. */
3563 add_psymbol_to_list (sym_name, true,
3564 VAR_DOMAIN, theclass, section,
3565 psymbol_placement::STATIC,
3566 sh.value, psymtab_language, objfile);
3567 skip:
3568 cur_sdx++; /* Go to next file symbol. */
3569 }
3570
3571 /* Now do enter the external symbols. */
3572 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
3573 cur_sdx = fdr_to_pst[f_idx].n_globals;
3574 PST_PRIVATE (save_pst)->extern_count = cur_sdx;
3575 PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
3576 for (; --cur_sdx >= 0; ext_ptr++)
3577 {
3578 enum address_class theclass;
3579 SYMR *psh;
3580 CORE_ADDR svalue;
3581 short section;
3582
3583 gdb_assert (ext_ptr->ifd == f_idx);
3584
3585 psh = &ext_ptr->asym;
3586
3587 /* Do not add undefined symbols to the partial symbol table. */
3588 if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
3589 continue;
3590
3591 svalue = psh->value;
3592 switch (psh->sc)
3593 {
3594 default:
3595 case scText:
3596 case scRConst:
3597 section = SECT_OFF_TEXT (objfile);
3598 break;
3599 case scData:
3600 case scSData:
3601 case scRData:
3602 case scPData:
3603 case scXData:
3604 section = SECT_OFF_DATA (objfile);
3605 break;
3606 case scBss:
3607 case scSBss:
3608 section = SECT_OFF_BSS (objfile);
3609 break;
3610 }
3611
3612 switch (psh->st)
3613 {
3614 case stNil:
3615 /* These are generated for static symbols in .o files,
3616 ignore them. */
3617 continue;
3618 case stProc:
3619 case stStaticProc:
3620 /* External procedure symbols have been entered
3621 into the minimal symbol table in pass 2 above.
3622 Ignore them, as parse_external will ignore them too. */
3623 continue;
3624 case stLabel:
3625 theclass = LOC_LABEL;
3626 break;
3627 default:
3628 unknown_ext_complaint (debug_info->ssext + psh->iss);
3629 /* Pretend it's global. */
3630 /* Fall through. */
3631 case stGlobal:
3632 /* Global common symbols are resolved by the runtime loader,
3633 ignore them. */
3634 if (SC_IS_COMMON (psh->sc))
3635 continue;
3636
3637 theclass = LOC_STATIC;
3638 break;
3639 }
3640 char *sym_name = debug_info->ssext + psh->iss;
3641 add_psymbol_to_list (sym_name, true,
3642 VAR_DOMAIN, theclass,
3643 section,
3644 psymbol_placement::GLOBAL,
3645 svalue, psymtab_language, objfile);
3646 }
3647 }
3648
3649 /* Link pst to FDR. dbx_end_psymtab returns NULL if the psymtab was
3650 empty and put on the free list. */
3651 fdr_to_pst[f_idx].pst
3652 = dbx_end_psymtab (objfile, save_pst,
3653 psymtab_include_list, includes_used,
3654 -1, save_pst->raw_text_high (),
3655 dependency_list, dependencies_used,
3656 textlow_not_set);
3657 includes_used = 0;
3658 dependencies_used = 0;
3659
3660 /* The objfile has its functions reordered if this partial symbol
3661 table overlaps any other partial symbol table.
3662 We cannot assume a reordered objfile if a partial symbol table
3663 is contained within another partial symbol table, as partial symbol
3664 tables for include files with executable code are contained
3665 within the partial symbol table for the including source file,
3666 and we do not want to flag the objfile reordered for these cases.
3667
3668 This strategy works well for Irix-5.2 shared libraries, but we
3669 might have to use a more elaborate (and slower) algorithm for
3670 other cases. */
3671 save_pst = fdr_to_pst[f_idx].pst;
3672 if (save_pst != NULL
3673 && save_pst->text_low_valid
3674 && !(objfile->flags & OBJF_REORDERED))
3675 {
3676 for (partial_symtab *iter : objfile->psymtabs ())
3677 {
3678 if (save_pst != iter
3679 && save_pst->raw_text_low () >= iter->raw_text_low ()
3680 && save_pst->raw_text_low () < iter->raw_text_high ()
3681 && save_pst->raw_text_high () > iter->raw_text_high ())
3682 {
3683 objfile->flags |= OBJF_REORDERED;
3684 break;
3685 }
3686 }
3687 }
3688 }
3689
3690 /* Now scan the FDRs for dependencies. */
3691 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
3692 {
3693 fh = f_idx + debug_info->fdr;
3694 pst = fdr_to_pst[f_idx].pst;
3695
3696 if (pst == NULL)
3697 continue;
3698
3699 /* This should catch stabs-in-ecoff. */
3700 if (fh->crfd <= 1)
3701 continue;
3702
3703 /* Skip the first file indirect entry as it is a self dependency for
3704 source files or a reverse .h -> .c dependency for header files. */
3705 pst->number_of_dependencies = 0;
3706 pst->dependencies
3707 = objfile->partial_symtabs->allocate_dependencies (fh->crfd - 1);
3708 for (s_idx = 1; s_idx < fh->crfd; s_idx++)
3709 {
3710 RFDT rh;
3711
3712 (*swap_rfd_in) (cur_bfd,
3713 ((char *) debug_info->external_rfd
3714 + (fh->rfdBase + s_idx) * external_rfd_size),
3715 &rh);
3716 if (rh < 0 || rh >= hdr->ifdMax)
3717 {
3718 complaint (_("bad file number %ld"), rh);
3719 continue;
3720 }
3721
3722 /* Skip self dependencies of header files. */
3723 if (rh == f_idx)
3724 continue;
3725
3726 /* Do not add to dependency list if psymtab was empty. */
3727 if (fdr_to_pst[rh].pst == NULL)
3728 continue;
3729 pst->dependencies[pst->number_of_dependencies++]
3730 = fdr_to_pst[rh].pst;
3731 }
3732 }
3733
3734 /* Remove the dummy psymtab created for -O3 images above, if it is
3735 still empty, to enable the detection of stripped executables. */
3736 partial_symtab *pst_del = objfile->partial_symtabs->psymtabs;
3737 if (pst_del->next == NULL
3738 && pst_del->number_of_dependencies == 0
3739 && pst_del->n_global_syms == 0
3740 && pst_del->n_static_syms == 0)
3741 objfile->partial_symtabs->discard_psymtab (pst_del);
3742 }
3743
3744 /* If the current psymbol has an enumerated type, we need to add
3745 all the enum constants to the partial symbol table. */
3746
3747 static void
3748 handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
3749 CORE_ADDR svalue)
3750 {
3751 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
3752 void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
3753 char *ext_sym = ((char *) debug_info->external_sym
3754 + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
3755 SYMR sh;
3756 TIR tir;
3757
3758 switch (stype)
3759 {
3760 case stEnum:
3761 break;
3762
3763 case stBlock:
3764 /* It is an enumerated type if the next symbol entry is a stMember
3765 and its auxiliary index is indexNil or its auxiliary entry
3766 is a plain btNil or btVoid.
3767 Alpha cc -migrate enums are recognized by a zero index and
3768 a zero symbol value.
3769 DU 4.0 cc enums are recognized by a member type of btEnum without
3770 qualifiers and a zero symbol value. */
3771 (*swap_sym_in) (cur_bfd, ext_sym, &sh);
3772 if (sh.st != stMember)
3773 return;
3774
3775 if (sh.index == indexNil
3776 || (sh.index == 0 && svalue == 0))
3777 break;
3778 (*debug_swap->swap_tir_in) (fh->fBigendian,
3779 &(debug_info->external_aux
3780 + fh->iauxBase + sh.index)->a_ti,
3781 &tir);
3782 if ((tir.bt != btNil
3783 && tir.bt != btVoid
3784 && (tir.bt != btEnum || svalue != 0))
3785 || tir.tq0 != tqNil)
3786 return;
3787 break;
3788
3789 default:
3790 return;
3791 }
3792
3793 for (;;)
3794 {
3795 char *name;
3796
3797 (*swap_sym_in) (cur_bfd, ext_sym, &sh);
3798 if (sh.st != stMember)
3799 break;
3800 name = debug_info->ss + cur_fdr->issBase + sh.iss;
3801
3802 /* Note that the value doesn't matter for enum constants
3803 in psymtabs, just in symtabs. */
3804 add_psymbol_to_list (name, true,
3805 VAR_DOMAIN, LOC_CONST, -1,
3806 psymbol_placement::STATIC, 0,
3807 psymtab_language, objfile);
3808 ext_sym += external_sym_size;
3809 }
3810 }
3811
3812 /* Get the next symbol. OBJFILE is unused. */
3813
3814 static const char *
3815 mdebug_next_symbol_text (struct objfile *objfile)
3816 {
3817 SYMR sh;
3818
3819 cur_sdx++;
3820 (*debug_swap->swap_sym_in) (cur_bfd,
3821 ((char *) debug_info->external_sym
3822 + ((cur_fdr->isymBase + cur_sdx)
3823 * debug_swap->external_sym_size)),
3824 &sh);
3825 return debug_info->ss + cur_fdr->issBase + sh.iss;
3826 }
3827
3828 /* Ancillary function to psymtab_to_symtab(). Does all the work
3829 for turning the partial symtab PST into a symtab, recurring
3830 first on all dependent psymtabs. The argument FILENAME is
3831 only passed so we can see in debug stack traces what file
3832 is being read.
3833
3834 This function has a split personality, based on whether the
3835 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
3836 The flow of control and even the memory allocation differs. FIXME. */
3837
3838 static void
3839 mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
3840 {
3841 bfd_size_type external_sym_size;
3842 bfd_size_type external_pdr_size;
3843 void (*swap_sym_in) (bfd *, void *, SYMR *);
3844 void (*swap_pdr_in) (bfd *, void *, PDR *);
3845 int i;
3846 struct compunit_symtab *cust = NULL;
3847 FDR *fh;
3848 struct linetable *lines;
3849 CORE_ADDR lowest_pdr_addr = 0;
3850 int last_symtab_ended = 0;
3851 const section_offsets §ion_offsets = objfile->section_offsets;
3852
3853 if (pst->readin)
3854 return;
3855 pst->readin = true;
3856
3857 /* Read in all partial symtabs on which this one is dependent.
3858 NOTE that we do have circular dependencies, sigh. We solved
3859 that by setting pst->readin before this point. */
3860 pst->expand_dependencies (objfile);
3861
3862 /* Do nothing if this is a dummy psymtab. */
3863
3864 if (pst->n_global_syms == 0 && pst->n_static_syms == 0
3865 && !pst->text_low_valid && !pst->text_high_valid)
3866 return;
3867
3868 /* Now read the symbols for this symtab. */
3869
3870 cur_bfd = CUR_BFD (pst);
3871 debug_swap = DEBUG_SWAP (pst);
3872 debug_info = DEBUG_INFO (pst);
3873 pending_list = PENDING_LIST (pst);
3874 external_sym_size = debug_swap->external_sym_size;
3875 external_pdr_size = debug_swap->external_pdr_size;
3876 swap_sym_in = debug_swap->swap_sym_in;
3877 swap_pdr_in = debug_swap->swap_pdr_in;
3878 mdebugread_objfile = objfile;
3879 cur_fd = FDR_IDX (pst);
3880 fh = ((cur_fd == -1)
3881 ? NULL
3882 : debug_info->fdr + cur_fd);
3883 cur_fdr = fh;
3884
3885 /* See comment in parse_partial_symbols about the @stabs sentinel. */
3886 processing_gcc_compilation = 0;
3887 if (fh != NULL && fh->csym >= 2)
3888 {
3889 SYMR sh;
3890
3891 (*swap_sym_in) (cur_bfd,
3892 ((char *) debug_info->external_sym
3893 + (fh->isymBase + 1) * external_sym_size),
3894 &sh);
3895 if (strcmp (debug_info->ss + fh->issBase + sh.iss,
3896 stabs_symbol) == 0)
3897 {
3898 /* We indicate that this is a GCC compilation so that certain
3899 features will be enabled in stabsread/dbxread. */
3900 processing_gcc_compilation = 2;
3901 }
3902 }
3903
3904 if (processing_gcc_compilation != 0)
3905 {
3906 struct gdbarch *gdbarch = objfile->arch ();
3907
3908 /* This symbol table contains stabs-in-ecoff entries. */
3909
3910 /* Parse local symbols first. */
3911
3912 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr. */
3913 {
3914 mdebugread_objfile = NULL;
3915 return;
3916 }
3917 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
3918 {
3919 SYMR sh;
3920 char *name;
3921 CORE_ADDR valu;
3922
3923 (*swap_sym_in) (cur_bfd,
3924 (((char *) debug_info->external_sym)
3925 + (fh->isymBase + cur_sdx) * external_sym_size),
3926 &sh);
3927 name = debug_info->ss + fh->issBase + sh.iss;
3928 valu = sh.value;
3929 /* XXX This is a hack. It will go away! */
3930 if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
3931 {
3932 int type_code = ECOFF_UNMARK_STAB (sh.index);
3933 enum language language = PST_PRIVATE (pst)->pst_language;
3934
3935 /* We should never get non N_STAB symbols here, but they
3936 should be harmless, so keep process_one_symbol from
3937 complaining about them. */
3938 if (type_code & N_STAB)
3939 {
3940 /* If we found a trailing N_SO with no name, process
3941 it here instead of in process_one_symbol, so we
3942 can keep a handle to its symtab. The symtab
3943 would otherwise be ended twice, once in
3944 process_one_symbol, and once after this loop. */
3945 if (type_code == N_SO
3946 && get_last_source_file ()
3947 && previous_stab_code != (unsigned char) N_SO
3948 && *name == '\000')
3949 {
3950 valu += section_offsets[SECT_OFF_TEXT (objfile)];
3951 previous_stab_code = N_SO;
3952 cust = end_symtab (valu, SECT_OFF_TEXT (objfile));
3953 end_stabs ();
3954 last_symtab_ended = 1;
3955 }
3956 else
3957 {
3958 last_symtab_ended = 0;
3959 process_one_symbol (type_code, 0, valu, name,
3960 section_offsets, objfile, language);
3961 }
3962 }
3963 /* Similarly a hack. */
3964 else if (name[0] == '#')
3965 {
3966 process_one_symbol (N_SLINE, 0, valu, name,
3967 section_offsets, objfile, language);
3968 }
3969 if (type_code == N_FUN)
3970 {
3971 /* Make up special symbol to contain
3972 procedure specific info. */
3973 mdebug_extra_func_info *e
3974 = OBSTACK_ZALLOC (&mdebugread_objfile->objfile_obstack,
3975 mdebug_extra_func_info);
3976 struct symbol *s = new_symbol (MDEBUG_EFI_SYMBOL_NAME);
3977
3978 SYMBOL_DOMAIN (s) = LABEL_DOMAIN;
3979 SYMBOL_ACLASS_INDEX (s) = LOC_CONST;
3980 SYMBOL_TYPE (s) = objfile_type (objfile)->builtin_void;
3981 SYMBOL_VALUE_BYTES (s) = (gdb_byte *) e;
3982 e->pdr.framereg = -1;
3983 add_symbol_to_list (s, get_local_symbols ());
3984 }
3985 }
3986 else if (sh.st == stLabel)
3987 {
3988 if (sh.index == indexNil)
3989 {
3990 /* This is what the gcc2_compiled and __gnu_compiled_*
3991 show up as. So don't complain. */
3992 ;
3993 }
3994 else
3995 {
3996 /* Handle encoded stab line number. */
3997 valu += section_offsets[SECT_OFF_TEXT (objfile)];
3998 record_line (get_current_subfile (), sh.index,
3999 gdbarch_addr_bits_remove (gdbarch, valu));
4000 }
4001 }
4002 else if (sh.st == stProc || sh.st == stStaticProc
4003 || sh.st == stStatic || sh.st == stEnd)
4004 /* These are generated by gcc-2.x, do not complain. */
4005 ;
4006 else
4007 complaint (_("unknown stabs symbol %s"), name);
4008 }
4009
4010 if (! last_symtab_ended)
4011 {
4012 cust = end_symtab (pst->raw_text_high (), SECT_OFF_TEXT (objfile));
4013 end_stabs ();
4014 }
4015
4016 /* There used to be a call to sort_blocks here, but this should not
4017 be necessary for stabs symtabs. And as sort_blocks modifies the
4018 start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
4019 it did the wrong thing if the first procedure in a file was
4020 generated via asm statements. */
4021
4022 /* Fill in procedure info next. */
4023 if (fh->cpd > 0)
4024 {
4025 char *pdr_ptr;
4026 char *pdr_end;
4027 PDR *pdr_in;
4028 PDR *pdr_in_end;
4029
4030 gdb::def_vector<PDR> pr_block (fh->cpd);
4031
4032 pdr_ptr = ((char *) debug_info->external_pdr
4033 + fh->ipdFirst * external_pdr_size);
4034 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
4035 pdr_in = pr_block.data ();
4036 for (;
4037 pdr_ptr < pdr_end;
4038 pdr_ptr += external_pdr_size, pdr_in++)
4039 {
4040 (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
4041
4042 /* Determine lowest PDR address, the PDRs are not always
4043 sorted. */
4044 if (pdr_in == pr_block.data ())
4045 lowest_pdr_addr = pdr_in->adr;
4046 else if (pdr_in->adr < lowest_pdr_addr)
4047 lowest_pdr_addr = pdr_in->adr;
4048 }
4049
4050 pdr_in = pr_block.data ();
4051 pdr_in_end = pdr_in + fh->cpd;
4052 for (; pdr_in < pdr_in_end; pdr_in++)
4053 parse_procedure (pdr_in, cust, pst);
4054 }
4055 }
4056 else
4057 {
4058 /* This symbol table contains ordinary ecoff entries. */
4059
4060 int maxlines, size;
4061 EXTR *ext_ptr;
4062
4063 if (fh == 0)
4064 {
4065 maxlines = 0;
4066 cust = new_symtab ("unknown", 0, objfile);
4067 }
4068 else
4069 {
4070 maxlines = 2 * fh->cline;
4071 cust = new_symtab (pst->filename, maxlines, objfile);
4072
4073 /* The proper language was already determined when building
4074 the psymtab, use it. */
4075 COMPUNIT_FILETABS (cust)->language = PST_PRIVATE (pst)->pst_language;
4076 }
4077
4078 psymtab_language = COMPUNIT_FILETABS (cust)->language;
4079
4080 lines = SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust));
4081
4082 /* Get a new lexical context. */
4083
4084 push_parse_stack ();
4085 top_stack->cur_st = COMPUNIT_FILETABS (cust);
4086 top_stack->cur_block
4087 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
4088 BLOCK_START (top_stack->cur_block) = pst->text_low (objfile);
4089 BLOCK_END (top_stack->cur_block) = 0;
4090 top_stack->blocktype = stFile;
4091 top_stack->cur_type = 0;
4092 top_stack->procadr = 0;
4093 top_stack->numargs = 0;
4094 found_ecoff_debugging_info = 0;
4095
4096 if (fh)
4097 {
4098 char *sym_ptr;
4099 char *sym_end;
4100
4101 /* Parse local symbols first. */
4102 sym_ptr = ((char *) debug_info->external_sym
4103 + fh->isymBase * external_sym_size);
4104 sym_end = sym_ptr + fh->csym * external_sym_size;
4105 while (sym_ptr < sym_end)
4106 {
4107 SYMR sh;
4108 int c;
4109
4110 (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
4111 c = parse_symbol (&sh,
4112 debug_info->external_aux + fh->iauxBase,
4113 sym_ptr, fh->fBigendian,
4114 section_offsets, objfile);
4115 sym_ptr += c * external_sym_size;
4116 }
4117
4118 /* Linenumbers. At the end, check if we can save memory.
4119 parse_lines has to look ahead an arbitrary number of PDR
4120 structures, so we swap them all first. */
4121 if (fh->cpd > 0)
4122 {
4123 char *pdr_ptr;
4124 char *pdr_end;
4125 PDR *pdr_in;
4126 PDR *pdr_in_end;
4127
4128 gdb::def_vector<PDR> pr_block (fh->cpd);
4129
4130 pdr_ptr = ((char *) debug_info->external_pdr
4131 + fh->ipdFirst * external_pdr_size);
4132 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
4133 pdr_in = pr_block.data ();
4134 for (;
4135 pdr_ptr < pdr_end;
4136 pdr_ptr += external_pdr_size, pdr_in++)
4137 {
4138 (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
4139
4140 /* Determine lowest PDR address, the PDRs are not always
4141 sorted. */
4142 if (pdr_in == pr_block.data ())
4143 lowest_pdr_addr = pdr_in->adr;
4144 else if (pdr_in->adr < lowest_pdr_addr)
4145 lowest_pdr_addr = pdr_in->adr;
4146 }
4147
4148 parse_lines (fh, pr_block.data (), lines, maxlines,
4149 pst->text_low (objfile), lowest_pdr_addr);
4150 if (lines->nitems < fh->cline)
4151 lines = shrink_linetable (lines);
4152
4153 /* Fill in procedure info next. */
4154 pdr_in = pr_block.data ();
4155 pdr_in_end = pdr_in + fh->cpd;
4156 for (; pdr_in < pdr_in_end; pdr_in++)
4157 parse_procedure (pdr_in, NULL, pst);
4158 }
4159 }
4160
4161 size = lines->nitems;
4162 if (size > 1)
4163 --size;
4164 SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust))
4165 = ((struct linetable *)
4166 obstack_copy (&mdebugread_objfile->objfile_obstack,
4167 lines, (sizeof (struct linetable)
4168 + size * sizeof (lines->item))));
4169 xfree (lines);
4170
4171 /* .. and our share of externals.
4172 XXX use the global list to speed up things here. How?
4173 FIXME, Maybe quit once we have found the right number of ext's? */
4174 top_stack->cur_st = COMPUNIT_FILETABS (cust);
4175 top_stack->cur_block
4176 = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (top_stack->cur_st),
4177 GLOBAL_BLOCK);
4178 top_stack->blocktype = stFile;
4179
4180 ext_ptr = PST_PRIVATE (pst)->extern_tab;
4181 for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
4182 parse_external (ext_ptr, fh->fBigendian,
4183 section_offsets, objfile);
4184
4185 /* If there are undefined symbols, tell the user.
4186 The alpha has an undefined symbol for every symbol that is
4187 from a shared library, so tell the user only if verbose is on. */
4188 if (info_verbose && n_undef_symbols)
4189 {
4190 printf_filtered (_("File %s contains %d unresolved references:"),
4191 symtab_to_filename_for_display
4192 (COMPUNIT_FILETABS (cust)),
4193 n_undef_symbols);
4194 printf_filtered ("\n\t%4d variables\n\t%4d "
4195 "procedures\n\t%4d labels\n",
4196 n_undef_vars, n_undef_procs, n_undef_labels);
4197 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
4198
4199 }
4200 pop_parse_stack ();
4201
4202 sort_blocks (COMPUNIT_FILETABS (cust));
4203 }
4204
4205 /* Now link the psymtab and the symtab. */
4206 pst->compunit_symtab = cust;
4207
4208 mdebugread_objfile = NULL;
4209 }
4210
4211 /* Ancillary parsing procedures. */
4213
4214 /* Return 1 if the symbol pointed to by SH has a cross reference
4215 to an opaque aggregate type, else 0. */
4216
4217 static int
4218 has_opaque_xref (FDR *fh, SYMR *sh)
4219 {
4220 TIR tir;
4221 union aux_ext *ax;
4222 RNDXR rn[1];
4223 unsigned int rf;
4224
4225 if (sh->index == indexNil)
4226 return 0;
4227
4228 ax = debug_info->external_aux + fh->iauxBase + sh->index;
4229 (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
4230 if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
4231 return 0;
4232
4233 ax++;
4234 (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
4235 if (rn->rfd == 0xfff)
4236 rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
4237 else
4238 rf = rn->rfd;
4239 if (rf != -1)
4240 return 0;
4241 return 1;
4242 }
4243
4244 /* Lookup the type at relative index RN. Return it in TPP
4245 if found and in any event come up with its name PNAME.
4246 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
4247 Return value says how many aux symbols we ate. */
4248
4249 static int
4250 cross_ref (int fd, union aux_ext *ax, struct type **tpp,
4251 enum type_code type_code,
4252 /* Use to alloc new type if none is found. */
4253 const char **pname, int bigend, const char *sym_name)
4254 {
4255 RNDXR rn[1];
4256 unsigned int rf;
4257 int result = 1;
4258 FDR *fh;
4259 char *esh;
4260 SYMR sh;
4261 int xref_fd;
4262 struct mdebug_pending *pend;
4263
4264 *tpp = NULL;
4265
4266 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
4267
4268 /* Escape index means 'the next one'. */
4269 if (rn->rfd == 0xfff)
4270 {
4271 result++;
4272 rf = AUX_GET_ISYM (bigend, ax + 1);
4273 }
4274 else
4275 {
4276 rf = rn->rfd;
4277 }
4278
4279 /* mips cc uses a rf of -1 for opaque struct definitions.
4280 Set TYPE_STUB for these types so that check_typedef will
4281 resolve them if the struct gets defined in another compilation unit. */
4282 if (rf == -1)
4283 {
4284 *pname = "<undefined>";
4285 *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
4286 TYPE_STUB (*tpp) = 1;
4287 return result;
4288 }
4289
4290 /* mips cc uses an escaped rn->index of 0 for struct return types
4291 of procedures that were compiled without -g. These will always remain
4292 undefined. */
4293 if (rn->rfd == 0xfff && rn->index == 0)
4294 {
4295 *pname = "<undefined>";
4296 return result;
4297 }
4298
4299 /* Find the relative file descriptor and the symbol in it. */
4300 fh = get_rfd (fd, rf);
4301 xref_fd = fh - debug_info->fdr;
4302
4303 if (rn->index >= fh->csym)
4304 {
4305 /* File indirect entry is corrupt. */
4306 *pname = "<illegal>";
4307 bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
4308 return result;
4309 }
4310
4311 /* If we have processed this symbol then we left a forwarding
4312 pointer to the type in the pending list. If not, we`ll put
4313 it in a list of pending types, to be processed later when
4314 the file will be. In any event, we collect the name for the
4315 type here. */
4316
4317 esh = ((char *) debug_info->external_sym
4318 + ((fh->isymBase + rn->index)
4319 * debug_swap->external_sym_size));
4320 (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
4321
4322 /* Make sure that this type of cross reference can be handled. */
4323 if ((sh.sc != scInfo
4324 || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
4325 && sh.st != stStruct && sh.st != stUnion
4326 && sh.st != stEnum))
4327 && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
4328 {
4329 /* File indirect entry is corrupt. */
4330 *pname = "<illegal>";
4331 bad_rfd_entry_complaint (sym_name, xref_fd, rn->index);
4332 return result;
4333 }
4334
4335 *pname = debug_info->ss + fh->issBase + sh.iss;
4336
4337 pend = is_pending_symbol (fh, esh);
4338 if (pend)
4339 *tpp = pend->t;
4340 else
4341 {
4342 /* We have not yet seen this type. */
4343
4344 if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
4345 {
4346 TIR tir;
4347
4348 /* alpha cc puts out a stTypedef with a sh.iss of zero for
4349 two cases:
4350 a) forward declarations of structs/unions/enums which are not
4351 defined in this compilation unit.
4352 For these the type will be void. This is a bad design decision
4353 as cross referencing across compilation units is impossible
4354 due to the missing name.
4355 b) forward declarations of structs/unions/enums/typedefs which
4356 are defined later in this file or in another file in the same
4357 compilation unit. Irix5 cc uses a stIndirect symbol for this.
4358 Simply cross reference those again to get the true type.
4359 The forward references are not entered in the pending list and
4360 in the symbol table. */
4361
4362 (*debug_swap->swap_tir_in) (bigend,
4363 &(debug_info->external_aux
4364 + fh->iauxBase + sh.index)->a_ti,
4365 &tir);
4366 if (tir.tq0 != tqNil)
4367 complaint (_("illegal tq0 in forward typedef for %s"), sym_name);
4368 switch (tir.bt)
4369 {
4370 case btVoid:
4371 *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
4372 *pname = "<undefined>";
4373 break;
4374
4375 case btStruct:
4376 case btUnion:
4377 case btEnum:
4378 cross_ref (xref_fd,
4379 (debug_info->external_aux
4380 + fh->iauxBase + sh.index + 1),
4381 tpp, type_code, pname,
4382 fh->fBigendian, sym_name);
4383 break;
4384
4385 case btTypedef:
4386 /* Follow a forward typedef. This might recursively
4387 call cross_ref till we get a non typedef'ed type.
4388 FIXME: This is not correct behaviour, but gdb currently
4389 cannot handle typedefs without type copying. Type
4390 copying is impossible as we might have mutual forward
4391 references between two files and the copied type would not
4392 get filled in when we later parse its definition. */
4393 *tpp = parse_type (xref_fd,
4394 debug_info->external_aux + fh->iauxBase,
4395 sh.index,
4396 NULL,
4397 fh->fBigendian,
4398 debug_info->ss + fh->issBase + sh.iss);
4399 add_pending (fh, esh, *tpp);
4400 break;
4401
4402 default:
4403 complaint (_("illegal bt %d in forward typedef for %s"), tir.bt,
4404 sym_name);
4405 *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
4406 break;
4407 }
4408 return result;
4409 }
4410 else if (sh.st == stTypedef)
4411 {
4412 /* Parse the type for a normal typedef. This might recursively call
4413 cross_ref till we get a non typedef'ed type.
4414 FIXME: This is not correct behaviour, but gdb currently
4415 cannot handle typedefs without type copying. But type copying is
4416 impossible as we might have mutual forward references between
4417 two files and the copied type would not get filled in when
4418 we later parse its definition. */
4419 *tpp = parse_type (xref_fd,
4420 debug_info->external_aux + fh->iauxBase,
4421 sh.index,
4422 NULL,
4423 fh->fBigendian,
4424 debug_info->ss + fh->issBase + sh.iss);
4425 }
4426 else
4427 {
4428 /* Cross reference to a struct/union/enum which is defined
4429 in another file in the same compilation unit but that file
4430 has not been parsed yet.
4431 Initialize the type only, it will be filled in when
4432 it's definition is parsed. */
4433 *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
4434 }
4435 add_pending (fh, esh, *tpp);
4436 }
4437
4438 /* We used one auxent normally, two if we got a "next one" rf. */
4439 return result;
4440 }
4441
4442
4443 /* Quick&dirty lookup procedure, to avoid the MI ones that require
4444 keeping the symtab sorted. */
4445
4446 static struct symbol *
4447 mylookup_symbol (const char *name, const struct block *block,
4448 domain_enum domain, enum address_class theclass)
4449 {
4450 struct block_iterator iter;
4451 int inc;
4452 struct symbol *sym;
4453
4454 inc = name[0];
4455 ALL_BLOCK_SYMBOLS (block, iter, sym)
4456 {
4457 if (sym->linkage_name ()[0] == inc
4458 && SYMBOL_DOMAIN (sym) == domain
4459 && SYMBOL_CLASS (sym) == theclass
4460 && strcmp (sym->linkage_name (), name) == 0)
4461 return sym;
4462 }
4463
4464 block = BLOCK_SUPERBLOCK (block);
4465 if (block)
4466 return mylookup_symbol (name, block, domain, theclass);
4467 return 0;
4468 }
4469
4470
4471 /* Add a new symbol S to a block B. */
4472
4473 static void
4474 add_symbol (struct symbol *s, struct symtab *symtab, struct block *b)
4475 {
4476 symbol_set_symtab (s, symtab);
4477 mdict_add_symbol (BLOCK_MULTIDICT (b), s);
4478 }
4479
4480 /* Add a new block B to a symtab S. */
4481
4482 static void
4483 add_block (struct block *b, struct symtab *s)
4484 {
4485 /* Cast away "const", but that's ok because we're building the
4486 symtab and blockvector here. */
4487 struct blockvector *bv = (struct blockvector *) SYMTAB_BLOCKVECTOR (s);
4488
4489 bv = (struct blockvector *) xrealloc ((void *) bv,
4490 (sizeof (struct blockvector)
4491 + BLOCKVECTOR_NBLOCKS (bv)
4492 * sizeof (bv->block)));
4493 if (bv != SYMTAB_BLOCKVECTOR (s))
4494 SYMTAB_BLOCKVECTOR (s) = bv;
4495
4496 BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
4497 }
4498
4499 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
4500 MIPS' linenumber encoding might need more than one byte
4501 to describe it, LAST is used to detect these continuation lines.
4502
4503 Combining lines with the same line number seems like a bad idea.
4504 E.g: There could be a line number entry with the same line number after the
4505 prologue and GDB should not ignore it (this is a better way to find
4506 a prologue than mips_skip_prologue).
4507 But due to the compressed line table format there are line number entries
4508 for the same line which are needed to bridge the gap to the next
4509 line number entry. These entries have a bogus address info with them
4510 and we are unable to tell them from intended duplicate line number
4511 entries.
4512 This is another reason why -ggdb debugging format is preferable. */
4513
4514 static int
4515 add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
4516 {
4517 /* DEC c89 sometimes produces zero linenos which confuse gdb.
4518 Change them to something sensible. */
4519 if (lineno == 0)
4520 lineno = 1;
4521 if (last == 0)
4522 last = -2; /* Make sure we record first line. */
4523
4524 if (last == lineno) /* Skip continuation lines. */
4525 return lineno;
4526
4527 lt->item[lt->nitems].line = lineno;
4528 lt->item[lt->nitems++].pc = adr << 2;
4529 return lineno;
4530 }
4531
4532 /* Sorting and reordering procedures. */
4534
4535 /* Blocks with a smaller low bound should come first. */
4536
4537 static bool
4538 block_is_less_than (const struct block *b1, const struct block *b2)
4539 {
4540 CORE_ADDR start1 = BLOCK_START (b1);
4541 CORE_ADDR start2 = BLOCK_START (b2);
4542
4543 if (start1 != start2)
4544 return start1 < start2;
4545
4546 return (BLOCK_END (b2)) < (BLOCK_END (b1));
4547 }
4548
4549 /* Sort the blocks of a symtab S.
4550 Reorder the blocks in the blockvector by code-address,
4551 as required by some MI search routines. */
4552
4553 static void
4554 sort_blocks (struct symtab *s)
4555 {
4556 /* We have to cast away const here, but this is ok because we're
4557 constructing the blockvector in this code. */
4558 struct blockvector *bv = (struct blockvector *) SYMTAB_BLOCKVECTOR (s);
4559
4560 if (BLOCKVECTOR_NBLOCKS (bv) <= FIRST_LOCAL_BLOCK)
4561 {
4562 /* Cosmetic */
4563 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
4564 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
4565 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
4566 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
4567 return;
4568 }
4569 /*
4570 * This is very unfortunate: normally all functions are compiled in
4571 * the order they are found, but if the file is compiled -O3 things
4572 * are very different. It would be nice to find a reliable test
4573 * to detect -O3 images in advance.
4574 */
4575 if (BLOCKVECTOR_NBLOCKS (bv) > FIRST_LOCAL_BLOCK + 1)
4576 std::sort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
4577 &BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)),
4578 block_is_less_than);
4579
4580 {
4581 CORE_ADDR high = 0;
4582 int i, j = BLOCKVECTOR_NBLOCKS (bv);
4583
4584 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
4585 if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
4586 high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
4587 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
4588 }
4589
4590 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
4591 BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
4592
4593 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
4594 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
4595 BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
4596 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
4597 }
4598
4599
4601 /* Constructor/restructor/destructor procedures. */
4602
4603 /* Allocate a new symtab for NAME. Needs an estimate of how many
4604 linenumbers MAXLINES we'll put in it. */
4605
4606 static struct compunit_symtab *
4607 new_symtab (const char *name, int maxlines, struct objfile *objfile)
4608 {
4609 struct compunit_symtab *cust = allocate_compunit_symtab (objfile, name);
4610 struct symtab *symtab;
4611 struct blockvector *bv;
4612 enum language lang;
4613
4614 add_compunit_symtab_to_objfile (cust);
4615 symtab = allocate_symtab (cust, name);
4616
4617 SYMTAB_LINETABLE (symtab) = new_linetable (maxlines);
4618 lang = compunit_language (cust);
4619
4620 /* All symtabs must have at least two blocks. */
4621 bv = new_bvect (2);
4622 BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
4623 BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
4624 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
4625 BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
4626 COMPUNIT_BLOCKVECTOR (cust) = bv;
4627
4628 COMPUNIT_DEBUGFORMAT (cust) = "ECOFF";
4629 return cust;
4630 }
4631
4632 /* Allocate a new partial_symtab NAME. */
4633
4634 static legacy_psymtab *
4635 new_psymtab (const char *name, struct objfile *objfile)
4636 {
4637 legacy_psymtab *psymtab;
4638
4639 psymtab = new legacy_psymtab (name, objfile);
4640
4641 /* Keep a backpointer to the file's symbols. */
4642
4643 psymtab->read_symtab_private
4644 = OBSTACK_ZALLOC (&objfile->objfile_obstack, symloc);
4645 CUR_BFD (psymtab) = cur_bfd;
4646 DEBUG_SWAP (psymtab) = debug_swap;
4647 DEBUG_INFO (psymtab) = debug_info;
4648 PENDING_LIST (psymtab) = pending_list;
4649
4650 /* The way to turn this into a symtab is to call... */
4651 psymtab->legacy_read_symtab = mdebug_read_symtab;
4652 psymtab->legacy_expand_psymtab = mdebug_expand_psymtab;
4653 return (psymtab);
4654 }
4655
4656
4657 /* Allocate a linetable array of the given SIZE. Since the struct
4658 already includes one item, we subtract one when calculating the
4659 proper size to allocate. */
4660
4661 static struct linetable *
4662 new_linetable (int size)
4663 {
4664 struct linetable *l;
4665
4666 if (size > 1)
4667 --size;
4668 size = size * sizeof (l->item) + sizeof (struct linetable);
4669 l = (struct linetable *) xmalloc (size);
4670 l->nitems = 0;
4671 return l;
4672 }
4673
4674 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
4675 I am not so sure about the 3.4 ones.
4676
4677 Since the struct linetable already includes one item, we subtract one when
4678 calculating the proper size to allocate. */
4679
4680 static struct linetable *
4681 shrink_linetable (struct linetable *lt)
4682 {
4683 return (struct linetable *) xrealloc ((void *) lt,
4684 (sizeof (struct linetable)
4685 + ((lt->nitems - 1)
4686 * sizeof (lt->item))));
4687 }
4688
4689 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
4690
4691 static struct blockvector *
4692 new_bvect (int nblocks)
4693 {
4694 struct blockvector *bv;
4695 int size;
4696
4697 size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
4698 bv = (struct blockvector *) xzalloc (size);
4699
4700 BLOCKVECTOR_NBLOCKS (bv) = nblocks;
4701
4702 return bv;
4703 }
4704
4705 /* Allocate and zero a new block of language LANGUAGE, and set its
4706 BLOCK_MULTIDICT. If function is non-zero, assume the block is
4707 associated to a function, and make sure that the symbols are stored
4708 linearly; otherwise, store them hashed. */
4709
4710 static struct block *
4711 new_block (enum block_type type, enum language language)
4712 {
4713 /* FIXME: carlton/2003-09-11: This should use allocate_block to
4714 allocate the block. Which, in turn, suggests that the block
4715 should be allocated on an obstack. */
4716 struct block *retval = XCNEW (struct block);
4717
4718 if (type == FUNCTION_BLOCK)
4719 BLOCK_MULTIDICT (retval) = mdict_create_linear_expandable (language);
4720 else
4721 BLOCK_MULTIDICT (retval) = mdict_create_hashed_expandable (language);
4722
4723 return retval;
4724 }
4725
4726 /* Create a new symbol with printname NAME. */
4727
4728 static struct symbol *
4729 new_symbol (const char *name)
4730 {
4731 struct symbol *s = new (&mdebugread_objfile->objfile_obstack) symbol;
4732
4733 s->set_language (psymtab_language, &mdebugread_objfile->objfile_obstack);
4734 s->compute_and_set_names (name, true, mdebugread_objfile->per_bfd);
4735 return s;
4736 }
4737
4738 /* Create a new type with printname NAME. */
4739
4740 static struct type *
4741 new_type (char *name)
4742 {
4743 struct type *t;
4744
4745 t = alloc_type (mdebugread_objfile);
4746 t->set_name (name);
4747 INIT_CPLUS_SPECIFIC (t);
4748 return t;
4749 }
4750
4751 /* Read ECOFF debugging information from a BFD section. This is
4753 called from elfread.c. It parses the section into a
4754 ecoff_debug_info struct, and then lets the rest of the file handle
4755 it as normal. */
4756
4757 void
4758 elfmdebug_build_psymtabs (struct objfile *objfile,
4759 const struct ecoff_debug_swap *swap, asection *sec)
4760 {
4761 bfd *abfd = objfile->obfd;
4762 struct ecoff_debug_info *info;
4763
4764 /* FIXME: It's not clear whether we should be getting minimal symbol
4765 information from .mdebug in an ELF file, or whether we will.
4766 Re-initialize the minimal symbol reader in case we do. */
4767
4768 minimal_symbol_reader reader (objfile);
4769
4770 info = XOBNEW (&objfile->objfile_obstack, ecoff_debug_info);
4771
4772 if (!(*swap->read_debug_info) (abfd, sec, info))
4773 error (_("Error reading ECOFF debugging information: %s"),
4774 bfd_errmsg (bfd_get_error ()));
4775
4776 mdebug_build_psymtabs (reader, objfile, swap, info);
4777
4778 reader.install ();
4779 }
4780
4781 void _initialize_mdebugread ();
4782 void
4783 _initialize_mdebugread ()
4784 {
4785 mdebug_register_index
4786 = register_symbol_register_impl (LOC_REGISTER, &mdebug_register_funcs);
4787 mdebug_regparm_index
4788 = register_symbol_register_impl (LOC_REGPARM_ADDR, &mdebug_register_funcs);
4789 }
4790