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