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