1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003.
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This module provides three functions: dbx_symfile_init,
24 which initializes to read a symbol file; dbx_new_init, which
25 discards existing cached information when all symbols are being
26 discarded; and dbx_symfile_read, which reads a symbol table
29 dbx_symfile_read only does the minimum work necessary for letting the
30 user "name" things symbolically; it does not read the entire symtab.
31 Instead, it reads the external and static symbols and puts them in partial
32 symbol tables. When more extensive information is requested of a
33 file, the corresponding partial symbol table is mutated into a full
34 fledged symbol table by going back and reading the symbols
35 for real. dbx_psymtab_to_symtab() is the function that does this */
38 #include "gdb_string.h"
40 #if defined(USG) || defined(__CYGNUSCLIB__)
41 #include <sys/types.h>
45 #include "gdb_obstack.h"
48 #include "breakpoint.h"
50 #include "gdbcore.h" /* for bfd stuff */
51 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
55 #include "stabsread.h"
56 #include "gdb-stabs.h"
58 #include "language.h" /* Needed for local_hex_string */
59 #include "complaints.h"
62 #include "aout/aout64.h"
63 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
66 /* This macro returns the size field of a minimal symbol, which is normally
67 stored in the "info" field. The macro can be overridden for specific
68 targets (e.g. MIPS16) that use the info field for other purposes. */
70 #define MSYMBOL_SIZE(msym) ((long) MSYMBOL_INFO (msym))
74 /* We put a pointer to this structure in the read_symtab_private field
79 /* Offset within the file symbol table of first local symbol for this
84 /* Length (in bytes) of the section of the symbol table devoted to
85 this file's symbols (actually, the section bracketed may contain
86 more than just this file's symbols). If ldsymlen is 0, the only
87 reason for this thing's existence is the dependency list. Nothing
88 else will happen when it is read in. */
92 /* The size of each symbol in the symbol file (in external form). */
96 /* Further information needed to locate the symbols if they are in
101 int file_string_offset;
104 #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
105 #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
106 #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
107 #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
108 #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
109 #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
110 #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
113 /* Remember what we deduced to be the source language of this psymtab. */
115 static enum language psymtab_language = language_unknown;
117 /* The BFD for this file -- implicit parameter to next_symbol_text. */
119 static bfd *symfile_bfd;
121 /* The size of each symbol in the symbol file (in external form).
122 This is set by dbx_symfile_read when building psymtabs, and by
123 dbx_psymtab_to_symtab when building symtabs. */
125 static unsigned symbol_size;
127 /* This is the offset of the symbol table in the executable file. */
129 static unsigned symbol_table_offset;
131 /* This is the offset of the string table in the executable file. */
133 static unsigned string_table_offset;
135 /* For elf+stab executables, the n_strx field is not a simple index
136 into the string table. Instead, each .o file has a base offset in
137 the string table, and the associated symbols contain offsets from
138 this base. The following two variables contain the base offset for
139 the current and next .o files. */
141 static unsigned int file_string_table_offset;
142 static unsigned int next_file_string_table_offset;
144 /* .o and NLM files contain unrelocated addresses which are based at
145 0. When non-zero, this flag disables some of the special cases for
146 Solaris elf+stab text addresses at location 0. */
148 static int symfile_relocatable = 0;
150 /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are
151 relative to the function start address. */
153 static int block_address_function_relative = 0;
155 /* The lowest text address we have yet encountered. This is needed
156 because in an a.out file, there is no header field which tells us
157 what address the program is actually going to be loaded at, so we
158 need to make guesses based on the symbols (which *are* relocated to
159 reflect the address it will be loaded at). */
161 static CORE_ADDR lowest_text_address;
163 /* Non-zero if there is any line number info in the objfile. Prevents
164 end_psymtab from discarding an otherwise empty psymtab. */
166 static int has_line_numbers;
168 /* Complaints about the symbols we have encountered. */
171 unknown_symtype_complaint (const char *arg1)
173 complaint (&symfile_complaints, "unknown symbol type %s", arg1);
177 lbrac_mismatch_complaint (int arg1)
179 complaint (&symfile_complaints,
180 "N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", arg1);
184 repeated_header_complaint (const char *arg1, int arg2)
186 complaint (&symfile_complaints,
187 "\"repeated\" header file %s not previously seen, at symtab pos %d",
191 /* find_text_range --- find start and end of loadable code sections
193 The find_text_range function finds the shortest address range that
194 encloses all sections containing executable code, and stores it in
195 objfile's text_addr and text_size members.
197 dbx_symfile_read will use this to finish off the partial symbol
198 table, in some cases. */
201 find_text_range (bfd * sym_bfd, struct objfile *objfile)
208 for (sec = sym_bfd->sections; sec; sec = sec->next)
209 if (bfd_get_section_flags (sym_bfd, sec) & SEC_CODE)
211 CORE_ADDR sec_start = bfd_section_vma (sym_bfd, sec);
212 CORE_ADDR sec_end = sec_start + bfd_section_size (sym_bfd, sec);
216 if (sec_start < start)
231 error ("Can't find any code sections in symbol file");
233 DBX_TEXT_ADDR (objfile) = start;
234 DBX_TEXT_SIZE (objfile) = end - start;
239 /* During initial symbol readin, we need to have a structure to keep
240 track of which psymtabs have which bincls in them. This structure
241 is used during readin to setup the list of dependencies within each
242 partial symbol table. */
244 struct header_file_location
246 char *name; /* Name of header file */
247 int instance; /* See above */
248 struct partial_symtab *pst; /* Partial symtab that has the
249 BINCL/EINCL defs for this file */
252 /* The actual list and controling variables */
253 static struct header_file_location *bincl_list, *next_bincl;
254 static int bincls_allocated;
256 /* Local function prototypes */
258 extern void _initialize_dbxread (void);
260 #if 0 /* OBSOLETE CFront */
261 // OBSOLETE static void process_now (struct objfile *);
262 #endif /* OBSOLETE CFront */
264 static void read_ofile_symtab (struct partial_symtab *);
266 static void dbx_psymtab_to_symtab (struct partial_symtab *);
268 static void dbx_psymtab_to_symtab_1 (struct partial_symtab *);
270 static void read_dbx_dynamic_symtab (struct objfile *objfile);
272 static void read_dbx_symtab (struct objfile *);
274 static void free_bincl_list (struct objfile *);
276 static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int);
278 static void add_bincl_to_list (struct partial_symtab *, char *, int);
280 static void init_bincl_list (int, struct objfile *);
282 static char *dbx_next_symbol_text (struct objfile *);
284 static void fill_symbuf (bfd *);
286 static void dbx_symfile_init (struct objfile *);
288 static void dbx_new_init (struct objfile *);
290 static void dbx_symfile_read (struct objfile *, int);
292 static void dbx_symfile_finish (struct objfile *);
294 static void record_minimal_symbol (char *, CORE_ADDR, int, struct objfile *);
296 static void add_new_header_file (char *, int);
298 static void add_old_header_file (char *, int);
300 static void add_this_object_header_file (int);
302 static struct partial_symtab *start_psymtab (struct objfile *, char *,
304 struct partial_symbol **,
305 struct partial_symbol **);
307 /* Free up old header file tables */
310 free_header_files (void)
312 if (this_object_header_files)
314 xfree (this_object_header_files);
315 this_object_header_files = NULL;
317 n_allocated_this_object_header_files = 0;
320 /* Allocate new header file tables */
323 init_header_files (void)
325 n_allocated_this_object_header_files = 10;
326 this_object_header_files = (int *) xmalloc (10 * sizeof (int));
329 /* Add header file number I for this object file
330 at the next successive FILENUM. */
333 add_this_object_header_file (int i)
335 if (n_this_object_header_files == n_allocated_this_object_header_files)
337 n_allocated_this_object_header_files *= 2;
338 this_object_header_files
339 = (int *) xrealloc ((char *) this_object_header_files,
340 n_allocated_this_object_header_files * sizeof (int));
343 this_object_header_files[n_this_object_header_files++] = i;
346 /* Add to this file an "old" header file, one already seen in
347 a previous object file. NAME is the header file's name.
348 INSTANCE is its instance code, to select among multiple
349 symbol tables for the same header file. */
352 add_old_header_file (char *name, int instance)
354 register struct header_file *p = HEADER_FILES (current_objfile);
357 for (i = 0; i < N_HEADER_FILES (current_objfile); i++)
358 if (STREQ (p[i].name, name) && instance == p[i].instance)
360 add_this_object_header_file (i);
363 repeated_header_complaint (name, symnum);
366 /* Add to this file a "new" header file: definitions for its types follow.
367 NAME is the header file's name.
368 Most often this happens only once for each distinct header file,
369 but not necessarily. If it happens more than once, INSTANCE has
370 a different value each time, and references to the header file
371 use INSTANCE values to select among them.
373 dbx output contains "begin" and "end" markers for each new header file,
374 but at this level we just need to know which files there have been;
375 so we record the file when its "begin" is seen and ignore the "end". */
378 add_new_header_file (char *name, int instance)
381 register struct header_file *hfile;
383 /* Make sure there is room for one more header file. */
385 i = N_ALLOCATED_HEADER_FILES (current_objfile);
387 if (N_HEADER_FILES (current_objfile) == i)
391 N_ALLOCATED_HEADER_FILES (current_objfile) = 10;
392 HEADER_FILES (current_objfile) = (struct header_file *)
393 xmalloc (10 * sizeof (struct header_file));
398 N_ALLOCATED_HEADER_FILES (current_objfile) = i;
399 HEADER_FILES (current_objfile) = (struct header_file *)
400 xrealloc ((char *) HEADER_FILES (current_objfile),
401 (i * sizeof (struct header_file)));
405 /* Create an entry for this header file. */
407 i = N_HEADER_FILES (current_objfile)++;
408 hfile = HEADER_FILES (current_objfile) + i;
409 hfile->name = savestring (name, strlen (name));
410 hfile->instance = instance;
413 = (struct type **) xmalloc (10 * sizeof (struct type *));
414 memset (hfile->vector, 0, 10 * sizeof (struct type *));
416 add_this_object_header_file (i);
420 static struct type **
421 explicit_lookup_type (int real_filenum, int index)
423 register struct header_file *f = &HEADER_FILES (current_objfile)[real_filenum];
425 if (index >= f->length)
428 f->vector = (struct type **)
429 xrealloc (f->vector, f->length * sizeof (struct type *));
430 memset (&f->vector[f->length / 2],
431 '\0', f->length * sizeof (struct type *) / 2);
433 return &f->vector[index];
438 record_minimal_symbol (char *name, CORE_ADDR address, int type,
439 struct objfile *objfile)
441 enum minimal_symbol_type ms_type;
443 asection *bfd_section;
449 section = SECT_OFF_TEXT (objfile);
450 bfd_section = DBX_TEXT_SECTION (objfile);
454 section = SECT_OFF_DATA (objfile);
455 bfd_section = DBX_DATA_SECTION (objfile);
459 section = SECT_OFF_BSS (objfile);
460 bfd_section = DBX_BSS_SECTION (objfile);
470 section = SECT_OFF_DATA (objfile);
471 bfd_section = DBX_DATA_SECTION (objfile);
474 /* I don't think this type actually exists; since a N_SETV is the result
475 of going over many .o files, it doesn't make sense to have one
477 ms_type = mst_file_data;
478 section = SECT_OFF_DATA (objfile);
479 bfd_section = DBX_DATA_SECTION (objfile);
486 ms_type = mst_file_text;
487 section = SECT_OFF_TEXT (objfile);
488 bfd_section = DBX_TEXT_SECTION (objfile);
491 ms_type = mst_file_data;
493 /* Check for __DYNAMIC, which is used by Sun shared libraries.
494 Record it as global even if it's local, not global, so
495 lookup_minimal_symbol can find it. We don't check symbol_leading_char
496 because for SunOS4 it always is '_'. */
497 if (name[8] == 'C' && STREQ ("__DYNAMIC", name))
500 /* Same with virtual function tables, both global and static. */
502 char *tempstring = name;
503 if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
505 if (is_vtable_name (tempstring))
508 section = SECT_OFF_DATA (objfile);
509 bfd_section = DBX_DATA_SECTION (objfile);
512 ms_type = mst_file_bss;
513 section = SECT_OFF_BSS (objfile);
514 bfd_section = DBX_BSS_SECTION (objfile);
517 ms_type = mst_unknown;
523 if ((ms_type == mst_file_text || ms_type == mst_text)
524 && address < lowest_text_address)
525 lowest_text_address = address;
527 prim_record_minimal_symbol_and_info
528 (name, address, ms_type, NULL, section, bfd_section, objfile);
531 /* Scan and build partial symbols for a symbol file.
532 We have been initialized by a call to dbx_symfile_init, which
533 put all the relevant info into a "struct dbx_symfile_info",
534 hung off the objfile structure.
536 MAINLINE is true if we are reading the main symbol
537 table (as opposed to a shared lib or dynamically loaded file). */
540 dbx_symfile_read (struct objfile *objfile, int mainline)
544 struct cleanup *back_to;
546 sym_bfd = objfile->obfd;
548 /* .o and .nlm files are relocatables with text, data and bss segs based at
549 0. This flag disables special (Solaris stabs-in-elf only) fixups for
550 symbols with a value of 0. */
552 symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
554 /* This is true for Solaris (and all other systems which put stabs
555 in sections, hopefully, since it would be silly to do things
556 differently from Solaris), and false for SunOS4 and other a.out
558 block_address_function_relative =
559 ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3))
560 || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3))
561 || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4))
562 || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2))
563 || (0 == strncmp (bfd_get_target (sym_bfd), "epoc-pe", 7))
564 || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));
566 val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
568 perror_with_name (objfile->name);
570 /* If we are reinitializing, or if we have never loaded syms yet, init */
572 || (objfile->global_psymbols.size == 0
573 && objfile->static_psymbols.size == 0))
574 init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
576 symbol_size = DBX_SYMBOL_SIZE (objfile);
577 symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
579 free_pending_blocks ();
580 back_to = make_cleanup (really_free_pendings, 0);
582 init_minimal_symbol_collection ();
583 make_cleanup_discard_minimal_symbols ();
585 /* Read stabs data from executable file and define symbols. */
587 read_dbx_symtab (objfile);
589 /* Add the dynamic symbols. */
591 read_dbx_dynamic_symtab (objfile);
593 /* Install any minimal symbols that have been collected as the current
594 minimal symbols for this objfile. */
596 install_minimal_symbols (objfile);
598 do_cleanups (back_to);
601 /* Initialize anything that needs initializing when a completely new
602 symbol file is specified (not just adding some symbols from another
603 file, e.g. a shared library). */
606 dbx_new_init (struct objfile *ignore)
608 stabsread_new_init ();
609 buildsym_new_init ();
610 init_header_files ();
614 /* dbx_symfile_init ()
615 is the dbx-specific initialization routine for reading symbols.
616 It is passed a struct objfile which contains, among other things,
617 the BFD for the file whose symbols are being read, and a slot for a pointer
618 to "private data" which we fill with goodies.
620 We read the string table into malloc'd space and stash a pointer to it.
622 Since BFD doesn't know how to read debug symbols in a format-independent
623 way (and may never do so...), we have to do it ourselves. We will never
624 be called unless this is an a.out (or very similar) file.
625 FIXME, there should be a cleaner peephole into the BFD environment here. */
627 #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
630 dbx_symfile_init (struct objfile *objfile)
633 bfd *sym_bfd = objfile->obfd;
634 char *name = bfd_get_filename (sym_bfd);
636 unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
638 /* Allocate struct to keep track of the symfile */
639 objfile->sym_stab_info = (struct dbx_symfile_info *)
640 xmmalloc (objfile->md, sizeof (struct dbx_symfile_info));
641 memset (objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
643 DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
644 DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data");
645 DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss");
647 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
648 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
649 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
651 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
653 DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
655 text_sect = bfd_get_section_by_name (sym_bfd, ".text");
657 error ("Can't find .text section in symbol file");
658 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
659 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
661 DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);
662 DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
663 DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
665 /* Read the string table and stash it away in the psymbol_obstack. It is
666 only needed as long as we need to expand psymbols into full symbols,
667 so when we blow away the psymbol the string table goes away as well.
668 Note that gdb used to use the results of attempting to malloc the
669 string table, based on the size it read, as a form of sanity check
670 for botched byte swapping, on the theory that a byte swapped string
671 table size would be so totally bogus that the malloc would fail. Now
672 that we put in on the psymbol_obstack, we can't do this since gdb gets
673 a fatal error (out of virtual memory) if the size is bogus. We can
674 however at least check to see if the size is less than the size of
675 the size field itself, or larger than the size of the entire file.
676 Note that all valid string tables have a size greater than zero, since
677 the bytes used to hold the size are included in the count. */
679 if (STRING_TABLE_OFFSET == 0)
681 /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
682 will never be zero, even when there is no string table. This
683 would appear to be a bug in bfd. */
684 DBX_STRINGTAB_SIZE (objfile) = 0;
685 DBX_STRINGTAB (objfile) = NULL;
689 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
691 perror_with_name (name);
693 memset (size_temp, 0, sizeof (size_temp));
694 val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd);
697 perror_with_name (name);
701 /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
702 EOF if there is no string table, and attempting to read the size
703 from EOF will read zero bytes. */
704 DBX_STRINGTAB_SIZE (objfile) = 0;
705 DBX_STRINGTAB (objfile) = NULL;
709 /* Read some data that would appear to be the string table size.
710 If there really is a string table, then it is probably the right
711 size. Byteswap if necessary and validate the size. Note that
712 the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
713 random data that happened to be at STRING_TABLE_OFFSET, because
714 bfd can't tell us there is no string table, the sanity checks may
715 or may not catch this. */
716 DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
718 if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
719 || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
720 error ("ridiculous string table size (%d bytes).",
721 DBX_STRINGTAB_SIZE (objfile));
723 DBX_STRINGTAB (objfile) =
724 (char *) obstack_alloc (&objfile->psymbol_obstack,
725 DBX_STRINGTAB_SIZE (objfile));
726 OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile));
728 /* Now read in the string table in one big gulp. */
730 val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
732 perror_with_name (name);
733 val = bfd_bread (DBX_STRINGTAB (objfile),
734 DBX_STRINGTAB_SIZE (objfile),
736 if (val != DBX_STRINGTAB_SIZE (objfile))
737 perror_with_name (name);
742 /* Perform any local cleanups required when we are done with a particular
743 objfile. I.E, we are in the process of discarding all symbol information
744 for an objfile, freeing up all memory held for it, and unlinking the
745 objfile struct from the global list of known objfiles. */
748 dbx_symfile_finish (struct objfile *objfile)
750 if (objfile->sym_stab_info != NULL)
752 if (HEADER_FILES (objfile) != NULL)
754 register int i = N_HEADER_FILES (objfile);
755 register struct header_file *hfiles = HEADER_FILES (objfile);
759 xfree (hfiles[i].name);
760 xfree (hfiles[i].vector);
764 xmfree (objfile->md, objfile->sym_stab_info);
766 free_header_files ();
770 /* Buffer for reading the symbol table entries. */
771 static struct external_nlist symbuf[4096];
772 static int symbuf_idx;
773 static int symbuf_end;
775 #if 0 /* OBSOLETE CFront */
776 // OBSOLETE /* cont_elem is used for continuing information in cfront.
777 // OBSOLETE It saves information about which types need to be fixed up and
778 // OBSOLETE completed after all the stabs are read. */
779 // OBSOLETE struct cont_elem
781 // OBSOLETE /* sym and stabstring for continuing information in cfront */
782 // OBSOLETE struct symbol *sym;
783 // OBSOLETE char *stabs;
784 // OBSOLETE /* state dependencies (statics that must be preserved) */
785 // OBSOLETE int sym_idx;
786 // OBSOLETE int sym_end;
787 // OBSOLETE int symnum;
788 // OBSOLETE int (*func) (struct objfile *, struct symbol *, char *);
789 // OBSOLETE /* other state dependencies include:
790 // OBSOLETE (assumption is that these will not change since process_now FIXME!!)
791 // OBSOLETE stringtab_global
794 // OBSOLETE symfile_bfd */
797 // OBSOLETE static struct cont_elem *cont_list = 0;
798 // OBSOLETE static int cont_limit = 0;
799 // OBSOLETE static int cont_count = 0;
801 // OBSOLETE /* Arrange for function F to be called with arguments SYM and P later
802 // OBSOLETE in the stabs reading process. */
804 // OBSOLETE process_later (struct symbol *sym, char *p,
805 // OBSOLETE int (*f) (struct objfile *, struct symbol *, char *))
808 // OBSOLETE /* Allocate more space for the deferred list. */
809 // OBSOLETE if (cont_count >= cont_limit - 1)
811 // OBSOLETE cont_limit += 32; /* chunk size */
813 // OBSOLETE cont_list
814 // OBSOLETE = (struct cont_elem *) xrealloc (cont_list,
815 // OBSOLETE (cont_limit
816 // OBSOLETE * sizeof (struct cont_elem)));
817 // OBSOLETE if (!cont_list)
818 // OBSOLETE error ("Virtual memory exhausted\n");
821 // OBSOLETE /* Save state variables so we can process these stabs later. */
822 // OBSOLETE cont_list[cont_count].sym_idx = symbuf_idx;
823 // OBSOLETE cont_list[cont_count].sym_end = symbuf_end;
824 // OBSOLETE cont_list[cont_count].symnum = symnum;
825 // OBSOLETE cont_list[cont_count].sym = sym;
826 // OBSOLETE cont_list[cont_count].stabs = p;
827 // OBSOLETE cont_list[cont_count].func = f;
828 // OBSOLETE cont_count++;
831 // OBSOLETE /* Call deferred funtions in CONT_LIST. */
833 // OBSOLETE static void
834 // OBSOLETE process_now (struct objfile *objfile)
837 // OBSOLETE int save_symbuf_idx;
838 // OBSOLETE int save_symbuf_end;
839 // OBSOLETE int save_symnum;
840 // OBSOLETE struct symbol *sym;
841 // OBSOLETE char *stabs;
843 // OBSOLETE int (*func) (struct objfile *, struct symbol *, char *);
845 // OBSOLETE /* Save the state of our caller, we'll want to restore it before
846 // OBSOLETE returning. */
847 // OBSOLETE save_symbuf_idx = symbuf_idx;
848 // OBSOLETE save_symbuf_end = symbuf_end;
849 // OBSOLETE save_symnum = symnum;
851 // OBSOLETE /* Iterate over all the deferred stabs. */
852 // OBSOLETE for (i = 0; i < cont_count; i++)
854 // OBSOLETE /* Restore the state for this deferred stab. */
855 // OBSOLETE symbuf_idx = cont_list[i].sym_idx;
856 // OBSOLETE symbuf_end = cont_list[i].sym_end;
857 // OBSOLETE symnum = cont_list[i].symnum;
858 // OBSOLETE sym = cont_list[i].sym;
859 // OBSOLETE stabs = cont_list[i].stabs;
860 // OBSOLETE func = cont_list[i].func;
862 // OBSOLETE /* Call the function to handle this deferrd stab. */
863 // OBSOLETE err = (*func) (objfile, sym, stabs);
865 // OBSOLETE error ("Internal error: unable to resolve stab.\n");
868 // OBSOLETE /* Restore our caller's state. */
869 // OBSOLETE symbuf_idx = save_symbuf_idx;
870 // OBSOLETE symbuf_end = save_symbuf_end;
871 // OBSOLETE symnum = save_symnum;
872 // OBSOLETE cont_count = 0;
874 #endif /* OBSOLETE CFront */
876 /* Name of last function encountered. Used in Solaris to approximate
877 object file boundaries. */
878 static char *last_function_name;
880 /* The address in memory of the string table of the object file we are
881 reading (which might not be the "main" object file, but might be a
882 shared library or some other dynamically loaded thing). This is
883 set by read_dbx_symtab when building psymtabs, and by
884 read_ofile_symtab when building symtabs, and is used only by
885 next_symbol_text. FIXME: If that is true, we don't need it when
886 building psymtabs, right? */
887 static char *stringtab_global;
889 /* These variables are used to control fill_symbuf when the stabs
890 symbols are not contiguous (as may be the case when a COFF file is
891 linked using --split-by-reloc). */
892 static struct stab_section_list *symbuf_sections;
893 static unsigned int symbuf_left;
894 static unsigned int symbuf_read;
896 /* This variable stores a global stabs buffer, if we read stabs into
897 memory in one chunk in order to process relocations. */
898 static bfd_byte *stabs_data;
900 /* Refill the symbol table input buffer
901 and set the variables that control fetching entries from it.
902 Reports an error if no data available.
903 This function can read past the end of the symbol table
904 (into the string table) but this does no harm. */
907 fill_symbuf (bfd *sym_bfd)
914 nbytes = sizeof (symbuf);
915 if (nbytes > symbuf_left)
916 nbytes = symbuf_left;
917 memcpy (symbuf, stabs_data + symbuf_read, nbytes);
919 else if (symbuf_sections == NULL)
921 count = sizeof (symbuf);
922 nbytes = bfd_bread (symbuf, count, sym_bfd);
926 if (symbuf_left <= 0)
928 file_ptr filepos = symbuf_sections->section->filepos;
929 if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
930 perror_with_name (bfd_get_filename (sym_bfd));
931 symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section);
932 symbol_table_offset = filepos - symbuf_read;
933 symbuf_sections = symbuf_sections->next;
937 if (count > sizeof (symbuf))
938 count = sizeof (symbuf);
939 nbytes = bfd_bread (symbuf, count, sym_bfd);
943 perror_with_name (bfd_get_filename (sym_bfd));
944 else if (nbytes == 0)
945 error ("Premature end of file reading symbol table");
946 symbuf_end = nbytes / symbol_size;
948 symbuf_left -= nbytes;
949 symbuf_read += nbytes;
953 stabs_seek (int sym_offset)
957 symbuf_read += sym_offset;
958 symbuf_left -= sym_offset;
961 bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
964 #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
966 (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
967 (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
968 (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
969 if (bfd_get_sign_extend_vma (abfd)) \
970 (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \
972 (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
975 /* Invariant: The symbol pointed to by symbuf_idx is the first one
976 that hasn't been swapped. Swap the symbol at the same time
977 that symbuf_idx is incremented. */
979 /* dbx allows the text of a symbol name to be continued into the
980 next symbol name! When such a continuation is encountered
981 (a \ at the end of the text of a name)
982 call this function to get the continuation. */
985 dbx_next_symbol_text (struct objfile *objfile)
987 struct internal_nlist nlist;
989 if (symbuf_idx == symbuf_end)
990 fill_symbuf (symfile_bfd);
993 INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd);
994 OBJSTAT (objfile, n_stabs++);
998 return nlist.n_strx + stringtab_global + file_string_table_offset;
1001 /* Initialize the list of bincls to contain none and have some
1005 init_bincl_list (int number, struct objfile *objfile)
1007 bincls_allocated = number;
1008 next_bincl = bincl_list = (struct header_file_location *)
1009 xmmalloc (objfile->md, bincls_allocated * sizeof (struct header_file_location));
1012 /* Add a bincl to the list. */
1015 add_bincl_to_list (struct partial_symtab *pst, char *name, int instance)
1017 if (next_bincl >= bincl_list + bincls_allocated)
1019 int offset = next_bincl - bincl_list;
1020 bincls_allocated *= 2;
1021 bincl_list = (struct header_file_location *)
1022 xmrealloc (pst->objfile->md, (char *) bincl_list,
1023 bincls_allocated * sizeof (struct header_file_location));
1024 next_bincl = bincl_list + offset;
1026 next_bincl->pst = pst;
1027 next_bincl->instance = instance;
1028 next_bincl++->name = name;
1031 /* Given a name, value pair, find the corresponding
1032 bincl in the list. Return the partial symtab associated
1033 with that header_file_location. */
1035 static struct partial_symtab *
1036 find_corresponding_bincl_psymtab (char *name, int instance)
1038 struct header_file_location *bincl;
1040 for (bincl = bincl_list; bincl < next_bincl; bincl++)
1041 if (bincl->instance == instance
1042 && STREQ (name, bincl->name))
1045 repeated_header_complaint (name, symnum);
1046 return (struct partial_symtab *) 0;
1049 /* Free the storage allocated for the bincl list. */
1052 free_bincl_list (struct objfile *objfile)
1054 xmfree (objfile->md, bincl_list);
1055 bincls_allocated = 0;
1059 do_free_bincl_list_cleanup (void *objfile)
1061 free_bincl_list (objfile);
1064 static struct cleanup *
1065 make_cleanup_free_bincl_list (struct objfile *objfile)
1067 return make_cleanup (do_free_bincl_list_cleanup, objfile);
1070 /* Set namestring based on nlist. If the string table index is invalid,
1071 give a fake name, and print a single error message per symbol file read,
1072 rather than abort the symbol reading or flood the user with messages. */
1075 set_namestring (struct objfile *objfile, struct internal_nlist nlist)
1079 if (((unsigned) nlist.n_strx + file_string_table_offset) >=
1080 DBX_STRINGTAB_SIZE (objfile))
1082 complaint (&symfile_complaints, "bad string table offset in symbol %d",
1084 namestring = "<bad string table offset>";
1087 namestring = nlist.n_strx + file_string_table_offset +
1088 DBX_STRINGTAB (objfile);
1092 /* Scan a SunOs dynamic symbol table for symbols of interest and
1093 add them to the minimal symbol table. */
1096 read_dbx_dynamic_symtab (struct objfile *objfile)
1098 bfd *abfd = objfile->obfd;
1099 struct cleanup *back_to;
1109 CORE_ADDR sym_value;
1112 /* Check that the symbol file has dynamic symbols that we know about.
1113 bfd_arch_unknown can happen if we are reading a sun3 symbol file
1114 on a sun4 host (and vice versa) and bfd is not configured
1115 --with-target=all. This would trigger an assertion in bfd/sunos.c,
1116 so we ignore the dynamic symbols in this case. */
1117 if (bfd_get_flavour (abfd) != bfd_target_aout_flavour
1118 || (bfd_get_file_flags (abfd) & DYNAMIC) == 0
1119 || bfd_get_arch (abfd) == bfd_arch_unknown)
1122 dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd);
1123 if (dynsym_size < 0)
1126 dynsyms = (asymbol **) xmalloc (dynsym_size);
1127 back_to = make_cleanup (xfree, dynsyms);
1129 dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms);
1130 if (dynsym_count < 0)
1132 do_cleanups (back_to);
1136 /* Enter dynamic symbols into the minimal symbol table
1137 if this is a stripped executable. */
1138 if (bfd_get_symcount (abfd) <= 0)
1141 for (counter = 0; counter < dynsym_count; counter++, symptr++)
1143 asymbol *sym = *symptr;
1147 sec = bfd_get_section (sym);
1149 /* BFD symbols are section relative. */
1150 sym_value = sym->value + sec->vma;
1152 if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
1154 sym_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1157 else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
1159 sym_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
1162 else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
1164 sym_value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
1170 if (sym->flags & BSF_GLOBAL)
1173 record_minimal_symbol ((char *) bfd_asymbol_name (sym), sym_value,
1178 /* Symbols from shared libraries have a dynamic relocation entry
1179 that points to the associated slot in the procedure linkage table.
1180 We make a mininal symbol table entry with type mst_solib_trampoline
1181 at the address in the procedure linkage table. */
1182 dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd);
1183 if (dynrel_size < 0)
1185 do_cleanups (back_to);
1189 dynrels = (arelent **) xmalloc (dynrel_size);
1190 make_cleanup (xfree, dynrels);
1192 dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms);
1193 if (dynrel_count < 0)
1195 do_cleanups (back_to);
1199 for (counter = 0, relptr = dynrels;
1200 counter < dynrel_count;
1201 counter++, relptr++)
1203 arelent *rel = *relptr;
1205 rel->address + ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
1207 switch (bfd_get_arch (abfd))
1209 case bfd_arch_sparc:
1210 if (rel->howto->type != RELOC_JMP_SLOT)
1214 /* `16' is the type BFD produces for a jump table relocation. */
1215 if (rel->howto->type != 16)
1218 /* Adjust address in the jump table to point to
1219 the start of the bsr instruction. */
1226 name = (char *) bfd_asymbol_name (*rel->sym_ptr_ptr);
1227 prim_record_minimal_symbol (name, address, mst_solib_trampoline,
1231 do_cleanups (back_to);
1234 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1236 find_stab_function_addr (char *namestring, char *filename,
1237 struct objfile *objfile)
1239 struct minimal_symbol *msym;
1243 p = strchr (namestring, ':');
1248 strncpy (p, namestring, n);
1251 msym = lookup_minimal_symbol (p, filename, objfile);
1254 /* Sun Fortran appends an underscore to the minimal symbol name,
1255 try again with an appended underscore if the minimal symbol
1259 msym = lookup_minimal_symbol (p, filename, objfile);
1262 if (msym == NULL && filename != NULL)
1264 /* Try again without the filename. */
1266 msym = lookup_minimal_symbol (p, NULL, objfile);
1268 if (msym == NULL && filename != NULL)
1270 /* And try again for Sun Fortran, but without the filename. */
1273 msym = lookup_minimal_symbol (p, NULL, objfile);
1276 return msym == NULL ? 0 : SYMBOL_VALUE_ADDRESS (msym);
1278 #endif /* SOFUN_ADDRESS_MAYBE_MISSING */
1281 function_outside_compilation_unit_complaint (const char *arg1)
1283 complaint (&symfile_complaints,
1284 "function `%s' appears to be defined outside of all compilation units",
1288 /* Setup partial_symtab's describing each source file for which
1289 debugging information is available. */
1292 read_dbx_symtab (struct objfile *objfile)
1294 register struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch */
1295 struct internal_nlist nlist;
1296 CORE_ADDR text_addr;
1299 register char *namestring;
1301 int past_first_source_file = 0;
1302 CORE_ADDR last_o_file_start = 0;
1303 CORE_ADDR last_function_start = 0;
1304 struct cleanup *back_to;
1306 int textlow_not_set;
1308 /* Current partial symtab */
1309 struct partial_symtab *pst;
1311 /* List of current psymtab's include files */
1312 char **psymtab_include_list;
1313 int includes_allocated;
1316 /* Index within current psymtab dependency list */
1317 struct partial_symtab **dependency_list;
1318 int dependencies_used, dependencies_allocated;
1320 text_addr = DBX_TEXT_ADDR (objfile);
1321 text_size = DBX_TEXT_SIZE (objfile);
1323 /* FIXME. We probably want to change stringtab_global rather than add this
1324 while processing every symbol entry. FIXME. */
1325 file_string_table_offset = 0;
1326 next_file_string_table_offset = 0;
1328 stringtab_global = DBX_STRINGTAB (objfile);
1330 pst = (struct partial_symtab *) 0;
1332 includes_allocated = 30;
1334 psymtab_include_list = (char **) alloca (includes_allocated *
1337 dependencies_allocated = 30;
1338 dependencies_used = 0;
1340 (struct partial_symtab **) alloca (dependencies_allocated *
1341 sizeof (struct partial_symtab *));
1343 /* Init bincl list */
1344 init_bincl_list (20, objfile);
1345 back_to = make_cleanup_free_bincl_list (objfile);
1347 last_source_file = NULL;
1349 lowest_text_address = (CORE_ADDR) -1;
1351 symfile_bfd = objfile->obfd; /* For next_text_symbol */
1352 abfd = objfile->obfd;
1353 symbuf_end = symbuf_idx = 0;
1354 next_symbol_text_func = dbx_next_symbol_text;
1355 textlow_not_set = 1;
1356 has_line_numbers = 0;
1358 for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
1360 /* Get the symbol for this run and pull out some info */
1361 QUIT; /* allow this to be interruptable */
1362 if (symbuf_idx == symbuf_end)
1364 bufp = &symbuf[symbuf_idx++];
1367 * Special case to speed up readin.
1369 if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
1371 has_line_numbers = 1;
1375 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
1376 OBJSTAT (objfile, n_stabs++);
1378 /* Ok. There is a lot of code duplicated in the rest of this
1379 switch statement (for efficiency reasons). Since I don't
1380 like duplicating code, I will do my penance here, and
1381 describe the code which is duplicated:
1383 *) The assignment to namestring.
1384 *) The call to strchr.
1385 *) The addition of a partial symbol the the two partial
1386 symbol lists. This last is a large section of code, so
1387 I've imbedded it in the following macro.
1390 switch (nlist.n_type)
1394 * Standard, external, non-debugger, symbols
1397 case N_TEXT | N_EXT:
1398 case N_NBTEXT | N_EXT:
1399 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1402 case N_DATA | N_EXT:
1403 case N_NBDATA | N_EXT:
1404 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
1409 case N_NBBSS | N_EXT:
1410 case N_SETV | N_EXT: /* FIXME, is this in BSS? */
1411 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
1416 namestring = set_namestring (objfile, nlist);
1419 record_minimal_symbol (namestring, nlist.n_value,
1420 nlist.n_type, objfile); /* Always */
1423 /* Standard, local, non-debugger, symbols */
1427 /* We need to be able to deal with both N_FN or N_TEXT,
1428 because we have no way of knowing whether the sys-supplied ld
1429 or GNU ld was used to make the executable. Sequents throw
1430 in another wrinkle -- they renumbered N_FN. */
1435 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1436 namestring = set_namestring (objfile, nlist);
1438 if ((namestring[0] == '-' && namestring[1] == 'l')
1439 || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
1440 && namestring[nsl - 2] == '.'))
1442 if (objfile->ei.entry_point < nlist.n_value &&
1443 objfile->ei.entry_point >= last_o_file_start)
1445 objfile->ei.entry_file_lowpc = last_o_file_start;
1446 objfile->ei.entry_file_highpc = nlist.n_value;
1448 if (past_first_source_file && pst
1449 /* The gould NP1 uses low values for .o and -l symbols
1450 which are not the address. */
1451 && nlist.n_value >= pst->textlow)
1453 end_psymtab (pst, psymtab_include_list, includes_used,
1454 symnum * symbol_size,
1455 nlist.n_value > pst->texthigh
1456 ? nlist.n_value : pst->texthigh,
1457 dependency_list, dependencies_used, textlow_not_set);
1458 pst = (struct partial_symtab *) 0;
1460 dependencies_used = 0;
1463 past_first_source_file = 1;
1464 last_o_file_start = nlist.n_value;
1471 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
1474 case N_UNDF | N_EXT:
1475 if (nlist.n_value != 0)
1477 /* This is a "Fortran COMMON" symbol. See if the target
1478 environment knows where it has been relocated to. */
1482 namestring = set_namestring (objfile, nlist);
1483 if (target_lookup_symbol (namestring, &reladdr))
1485 continue; /* Error in lookup; ignore symbol for now. */
1487 nlist.n_type ^= (N_BSS ^ N_UNDF); /* Define it as a bss-symbol */
1488 nlist.n_value = reladdr;
1489 goto bss_ext_symbol;
1491 continue; /* Just undefined, not COMMON */
1494 if (processing_acc_compilation && nlist.n_strx == 1)
1496 /* Deal with relative offsets in the string table
1497 used in ELF+STAB under Solaris. If we want to use the
1498 n_strx field, which contains the name of the file,
1499 we must adjust file_string_table_offset *before* calling
1500 set_namestring(). */
1501 past_first_source_file = 1;
1502 file_string_table_offset = next_file_string_table_offset;
1503 next_file_string_table_offset =
1504 file_string_table_offset + nlist.n_value;
1505 if (next_file_string_table_offset < file_string_table_offset)
1506 error ("string table offset backs up at %d", symnum);
1507 /* FIXME -- replace error() with complaint. */
1512 /* Lots of symbol types we can just ignore. */
1519 /* Keep going . . . */
1522 * Special symbol types for GNU
1525 case N_INDR | N_EXT:
1527 case N_SETA | N_EXT:
1529 case N_SETT | N_EXT:
1531 case N_SETD | N_EXT:
1533 case N_SETB | N_EXT:
1544 static int prev_so_symnum = -10;
1545 static int first_so_symnum;
1547 int prev_textlow_not_set;
1549 valu = nlist.n_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1551 prev_textlow_not_set = textlow_not_set;
1553 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1554 /* A zero value is probably an indication for the SunPRO 3.0
1555 compiler. end_psymtab explicitly tests for zero, so
1556 don't relocate it. */
1558 if (nlist.n_value == 0)
1560 textlow_not_set = 1;
1564 textlow_not_set = 0;
1566 textlow_not_set = 0;
1568 past_first_source_file = 1;
1570 if (prev_so_symnum != symnum - 1)
1571 { /* Here if prev stab wasn't N_SO */
1572 first_so_symnum = symnum;
1576 end_psymtab (pst, psymtab_include_list, includes_used,
1577 symnum * symbol_size,
1578 valu > pst->texthigh ? valu : pst->texthigh,
1579 dependency_list, dependencies_used,
1580 prev_textlow_not_set);
1581 pst = (struct partial_symtab *) 0;
1583 dependencies_used = 0;
1587 prev_so_symnum = symnum;
1589 /* End the current partial symtab and start a new one */
1591 namestring = set_namestring (objfile, nlist);
1593 /* Null name means end of .o file. Don't start a new one. */
1594 if (*namestring == '\000')
1597 /* Some compilers (including gcc) emit a pair of initial N_SOs.
1598 The first one is a directory name; the second the file name.
1599 If pst exists, is empty, and has a filename ending in '/',
1600 we assume the previous N_SO was a directory name. */
1602 p = strrchr (namestring, '/');
1603 if (p && *(p + 1) == '\000')
1604 continue; /* Simply ignore directory name SOs */
1606 /* Some other compilers (C++ ones in particular) emit useless
1607 SOs for non-existant .c files. We ignore all subsequent SOs that
1608 immediately follow the first. */
1611 pst = start_psymtab (objfile,
1613 first_so_symnum * symbol_size,
1614 objfile->global_psymbols.next,
1615 objfile->static_psymbols.next);
1621 enum language tmp_language;
1622 /* Add this bincl to the bincl_list for future EXCLs. No
1623 need to save the string; it'll be around until
1624 read_dbx_symtab function returns */
1626 namestring = set_namestring (objfile, nlist);
1627 tmp_language = deduce_language_from_filename (namestring);
1629 /* Only change the psymtab's language if we've learned
1630 something useful (eg. tmp_language is not language_unknown).
1631 In addition, to match what start_subfile does, never change
1633 if (tmp_language != language_unknown
1634 && (tmp_language != language_c
1635 || psymtab_language != language_cplus))
1636 psymtab_language = tmp_language;
1640 /* FIXME: we should not get here without a PST to work on.
1641 Attempt to recover. */
1642 complaint (&symfile_complaints,
1643 "N_BINCL %s not in entries for any file, at symtab pos %d",
1644 namestring, symnum);
1647 add_bincl_to_list (pst, namestring, nlist.n_value);
1649 /* Mark down an include file in the current psymtab */
1651 goto record_include_file;
1656 enum language tmp_language;
1657 /* Mark down an include file in the current psymtab */
1659 namestring = set_namestring (objfile, nlist);
1660 tmp_language = deduce_language_from_filename (namestring);
1662 /* Only change the psymtab's language if we've learned
1663 something useful (eg. tmp_language is not language_unknown).
1664 In addition, to match what start_subfile does, never change
1666 if (tmp_language != language_unknown
1667 && (tmp_language != language_c
1668 || psymtab_language != language_cplus))
1669 psymtab_language = tmp_language;
1671 /* In C++, one may expect the same filename to come round many
1672 times, when code is coming alternately from the main file
1673 and from inline functions in other files. So I check to see
1674 if this is a file we've seen before -- either the main
1675 source file, or a previously included file.
1677 This seems to be a lot of time to be spending on N_SOL, but
1678 things like "break c-exp.y:435" need to work (I
1679 suppose the psymtab_include_list could be hashed or put
1680 in a binary tree, if profiling shows this is a major hog). */
1681 if (pst && STREQ (namestring, pst->filename))
1685 for (i = 0; i < includes_used; i++)
1686 if (STREQ (namestring, psymtab_include_list[i]))
1695 record_include_file:
1697 psymtab_include_list[includes_used++] = namestring;
1698 if (includes_used >= includes_allocated)
1700 char **orig = psymtab_include_list;
1702 psymtab_include_list = (char **)
1703 alloca ((includes_allocated *= 2) *
1705 memcpy (psymtab_include_list, orig,
1706 includes_used * sizeof (char *));
1710 case N_LSYM: /* Typedef or automatic variable. */
1711 case N_STSYM: /* Data seg var -- static */
1712 case N_LCSYM: /* BSS " */
1713 case N_ROSYM: /* Read-only data seg var -- static. */
1714 case N_NBSTS: /* Gould nobase. */
1715 case N_NBLCS: /* symbols. */
1717 case N_GSYM: /* Global (extern) variable; can be
1718 data or bss (sigh FIXME). */
1720 /* Following may probably be ignored; I'll leave them here
1721 for now (until I do Pascal and Modula 2 extensions). */
1723 case N_PC: /* I may or may not need this; I
1725 case N_M2C: /* I suspect that I can ignore this here. */
1726 case N_SCOPE: /* Same. */
1728 namestring = set_namestring (objfile, nlist);
1730 /* See if this is an end of function stab. */
1731 if (pst && nlist.n_type == N_FUN && *namestring == '\000')
1735 /* It's value is the size (in bytes) of the function for
1736 function relative stabs, or the address of the function's
1737 end for old style stabs. */
1738 valu = nlist.n_value + last_function_start;
1739 if (pst->texthigh == 0 || valu > pst->texthigh)
1740 pst->texthigh = valu;
1744 p = (char *) strchr (namestring, ':');
1746 continue; /* Not a debugging symbol. */
1750 /* Main processing section for debugging symbols which
1751 the initial read through the symbol tables needs to worry
1752 about. If we reach this point, the symbol which we are
1753 considering is definitely one we are interested in.
1754 p must also contain the (valid) index into the namestring
1755 which indicates the debugging type symbol. */
1760 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
1761 #ifdef STATIC_TRANSFORM_NAME
1762 namestring = STATIC_TRANSFORM_NAME (namestring);
1764 add_psymbol_to_list (namestring, p - namestring,
1765 VAR_NAMESPACE, LOC_STATIC,
1766 &objfile->static_psymbols,
1768 psymtab_language, objfile);
1771 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
1772 /* The addresses in these entries are reported to be
1773 wrong. See the code that reads 'G's for symtabs. */
1774 add_psymbol_to_list (namestring, p - namestring,
1775 VAR_NAMESPACE, LOC_STATIC,
1776 &objfile->global_psymbols,
1778 psymtab_language, objfile);
1782 /* When a 'T' entry is defining an anonymous enum, it
1783 may have a name which is the empty string, or a
1784 single space. Since they're not really defining a
1785 symbol, those shouldn't go in the partial symbol
1786 table. We do pick up the elements of such enums at
1787 'check_enum:', below. */
1788 if (p >= namestring + 2
1789 || (p == namestring + 1
1790 && namestring[0] != ' '))
1792 add_psymbol_to_list (namestring, p - namestring,
1793 STRUCT_NAMESPACE, LOC_TYPEDEF,
1794 &objfile->static_psymbols,
1796 psymtab_language, objfile);
1799 /* Also a typedef with the same name. */
1800 add_psymbol_to_list (namestring, p - namestring,
1801 VAR_NAMESPACE, LOC_TYPEDEF,
1802 &objfile->static_psymbols,
1804 psymtab_language, objfile);
1807 #if 0 /* OBSOLETE CFront */
1808 // OBSOLETE /* The semantics of C++ state that "struct foo { ... }"
1809 // OBSOLETE also defines a typedef for "foo". Unfortuantely, cfront
1810 // OBSOLETE never makes the typedef when translating from C++ to C.
1811 // OBSOLETE We make the typedef here so that "ptype foo" works as
1812 // OBSOLETE expected for cfront translated code. */
1813 // OBSOLETE else if (psymtab_language == language_cplus)
1815 // OBSOLETE /* Also a typedef with the same name. */
1816 // OBSOLETE add_psymbol_to_list (namestring, p - namestring,
1817 // OBSOLETE VAR_NAMESPACE, LOC_TYPEDEF,
1818 // OBSOLETE &objfile->static_psymbols,
1819 // OBSOLETE nlist.n_value, 0,
1820 // OBSOLETE psymtab_language, objfile);
1822 #endif /* OBSOLETE CFront */
1826 if (p != namestring) /* a name is there, not just :T... */
1828 add_psymbol_to_list (namestring, p - namestring,
1829 VAR_NAMESPACE, LOC_TYPEDEF,
1830 &objfile->static_psymbols,
1832 psymtab_language, objfile);
1835 /* If this is an enumerated type, we need to
1836 add all the enum constants to the partial symbol
1837 table. This does not cover enums without names, e.g.
1838 "enum {a, b} c;" in C, but fortunately those are
1839 rare. There is no way for GDB to find those from the
1840 enum type without spending too much time on it. Thus
1841 to solve this problem, the compiler needs to put out the
1842 enum in a nameless type. GCC2 does this. */
1844 /* We are looking for something of the form
1845 <name> ":" ("t" | "T") [<number> "="] "e"
1846 {<constant> ":" <value> ","} ";". */
1848 /* Skip over the colon and the 't' or 'T'. */
1850 /* This type may be given a number. Also, numbers can come
1851 in pairs like (0,26). Skip over it. */
1852 while ((*p >= '0' && *p <= '9')
1853 || *p == '(' || *p == ',' || *p == ')'
1859 /* The aix4 compiler emits extra crud before the members. */
1862 /* Skip over the type (?). */
1866 /* Skip over the colon. */
1870 /* We have found an enumerated type. */
1871 /* According to comments in read_enum_type
1872 a comma could end it instead of a semicolon.
1873 I don't know where that happens.
1875 while (*p && *p != ';' && *p != ',')
1879 /* Check for and handle cretinous dbx symbol name
1881 if (*p == '\\' || (*p == '?' && p[1] == '\0'))
1882 p = next_symbol_text (objfile);
1884 /* Point to the character after the name
1885 of the enum constant. */
1886 for (q = p; *q && *q != ':'; q++)
1888 /* Note that the value doesn't matter for
1889 enum constants in psymtabs, just in symtabs. */
1890 add_psymbol_to_list (p, q - p,
1891 VAR_NAMESPACE, LOC_CONST,
1892 &objfile->static_psymbols, 0,
1893 0, psymtab_language, objfile);
1894 /* Point past the name. */
1896 /* Skip over the value. */
1897 while (*p && *p != ',')
1899 /* Advance past the comma. */
1906 /* Constant, e.g. from "const" in Pascal. */
1907 add_psymbol_to_list (namestring, p - namestring,
1908 VAR_NAMESPACE, LOC_CONST,
1909 &objfile->static_psymbols, nlist.n_value,
1910 0, psymtab_language, objfile);
1916 int name_len = p - namestring;
1917 char *name = xmalloc (name_len + 1);
1918 memcpy (name, namestring, name_len);
1919 name[name_len] = '\0';
1920 function_outside_compilation_unit_complaint (name);
1923 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1924 /* Kludges for ELF/STABS with Sun ACC */
1925 last_function_name = namestring;
1926 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1927 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1928 value for the bottom of the text seg in those cases. */
1929 if (nlist.n_value == ANOFFSET (objfile->section_offsets,
1930 SECT_OFF_TEXT (objfile)))
1932 CORE_ADDR minsym_valu =
1933 find_stab_function_addr (namestring, pst->filename, objfile);
1934 /* find_stab_function_addr will return 0 if the minimal
1935 symbol wasn't found. (Unfortunately, this might also
1936 be a valid address.) Anyway, if it *does* return 0,
1937 it is likely that the value was set correctly to begin
1939 if (minsym_valu != 0)
1940 nlist.n_value = minsym_valu;
1942 if (pst && textlow_not_set)
1944 pst->textlow = nlist.n_value;
1945 textlow_not_set = 0;
1950 /* Keep track of the start of the last function so we
1951 can handle end of function symbols. */
1952 last_function_start = nlist.n_value;
1954 /* In reordered executables this function may lie outside
1955 the bounds created by N_SO symbols. If that's the case
1956 use the address of this function as the low bound for
1957 the partial symbol table. */
1960 || (nlist.n_value < pst->textlow
1962 != ANOFFSET (objfile->section_offsets,
1963 SECT_OFF_TEXT (objfile))))))
1965 pst->textlow = nlist.n_value;
1966 textlow_not_set = 0;
1968 add_psymbol_to_list (namestring, p - namestring,
1969 VAR_NAMESPACE, LOC_BLOCK,
1970 &objfile->static_psymbols,
1972 psymtab_language, objfile);
1975 /* Global functions were ignored here, but now they
1976 are put into the global psymtab like one would expect.
1977 They're also in the minimal symbol table. */
1981 int name_len = p - namestring;
1982 char *name = xmalloc (name_len + 1);
1983 memcpy (name, namestring, name_len);
1984 name[name_len] = '\0';
1985 function_outside_compilation_unit_complaint (name);
1988 nlist.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
1989 /* Kludges for ELF/STABS with Sun ACC */
1990 last_function_name = namestring;
1991 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1992 /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
1993 value for the bottom of the text seg in those cases. */
1994 if (nlist.n_value == ANOFFSET (objfile->section_offsets,
1995 SECT_OFF_TEXT (objfile)))
1997 CORE_ADDR minsym_valu =
1998 find_stab_function_addr (namestring, pst->filename, objfile);
1999 /* find_stab_function_addr will return 0 if the minimal
2000 symbol wasn't found. (Unfortunately, this might also
2001 be a valid address.) Anyway, if it *does* return 0,
2002 it is likely that the value was set correctly to begin
2004 if (minsym_valu != 0)
2005 nlist.n_value = minsym_valu;
2007 if (pst && textlow_not_set)
2009 pst->textlow = nlist.n_value;
2010 textlow_not_set = 0;
2015 /* Keep track of the start of the last function so we
2016 can handle end of function symbols. */
2017 last_function_start = nlist.n_value;
2019 /* In reordered executables this function may lie outside
2020 the bounds created by N_SO symbols. If that's the case
2021 use the address of this function as the low bound for
2022 the partial symbol table. */
2025 || (nlist.n_value < pst->textlow
2027 != ANOFFSET (objfile->section_offsets,
2028 SECT_OFF_TEXT (objfile))))))
2030 pst->textlow = nlist.n_value;
2031 textlow_not_set = 0;
2033 add_psymbol_to_list (namestring, p - namestring,
2034 VAR_NAMESPACE, LOC_BLOCK,
2035 &objfile->global_psymbols,
2037 psymtab_language, objfile);
2040 /* Two things show up here (hopefully); static symbols of
2041 local scope (static used inside braces) or extensions
2042 of structure symbols. We can ignore both. */
2056 case '#': /* for symbol identification (used in live ranges) */
2057 #if 0 /* OBSOLETE CFront */
2058 // OBSOLETE /* added to support cfront stabs strings */
2059 // OBSOLETE case 'Z': /* for definition continuations */
2060 // OBSOLETE case 'P': /* for prototypes */
2061 #endif /* OBSOLETE CFront */
2065 /* It is a C++ nested symbol. We don't need to record it
2066 (I don't think); if we try to look up foo::bar::baz,
2067 then symbols for the symtab containing foo should get
2068 read in, I think. */
2069 /* Someone says sun cc puts out symbols like
2070 /foo/baz/maclib::/usr/local/bin/maclib,
2071 which would get here with a symbol type of ':'. */
2075 /* Unexpected symbol descriptor. The second and subsequent stabs
2076 of a continued stab can show up here. The question is
2077 whether they ever can mimic a normal stab--it would be
2078 nice if not, since we certainly don't want to spend the
2079 time searching to the end of every string looking for
2082 complaint (&symfile_complaints, "unknown symbol descriptor `%c'",
2085 /* Ignore it; perhaps it is an extension that we don't
2092 namestring = set_namestring (objfile, nlist);
2094 /* Find the corresponding bincl and mark that psymtab on the
2095 psymtab dependency list */
2097 struct partial_symtab *needed_pst =
2098 find_corresponding_bincl_psymtab (namestring, nlist.n_value);
2100 /* If this include file was defined earlier in this file,
2102 if (needed_pst == pst)
2110 for (i = 0; i < dependencies_used; i++)
2111 if (dependency_list[i] == needed_pst)
2117 /* If it's already in the list, skip the rest. */
2121 dependency_list[dependencies_used++] = needed_pst;
2122 if (dependencies_used >= dependencies_allocated)
2124 struct partial_symtab **orig = dependency_list;
2126 (struct partial_symtab **)
2127 alloca ((dependencies_allocated *= 2)
2128 * sizeof (struct partial_symtab *));
2129 memcpy (dependency_list, orig,
2131 * sizeof (struct partial_symtab *)));
2133 fprintf_unfiltered (gdb_stderr, "Had to reallocate dependency list.\n");
2134 fprintf_unfiltered (gdb_stderr, "New dependencies allocated: %d\n",
2135 dependencies_allocated);
2143 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2144 /* Solaris 2 end of module, finish current partial symbol table.
2145 end_psymtab will set pst->texthigh to the proper value, which
2146 is necessary if a module compiled without debugging info
2147 follows this module. */
2150 end_psymtab (pst, psymtab_include_list, includes_used,
2151 symnum * symbol_size,
2153 dependency_list, dependencies_used, textlow_not_set);
2154 pst = (struct partial_symtab *) 0;
2156 dependencies_used = 0;
2163 HANDLE_RBRAC (nlist.n_value);
2169 case N_SSYM: /* Claim: Structure or union element.
2170 Hopefully, I can ignore this. */
2171 case N_ENTRY: /* Alternate entry point; can ignore. */
2172 case N_MAIN: /* Can definitely ignore this. */
2173 case N_CATCH: /* These are GNU C++ extensions */
2174 case N_EHDECL: /* that can safely be ignored here. */
2184 case N_NSYMS: /* Ultrix 4.0: symbol count */
2185 case N_DEFD: /* GNU Modula-2 */
2186 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
2188 case N_OBJ: /* useless types from Solaris */
2190 /* These symbols aren't interesting; don't worry about them */
2195 /* If we haven't found it yet, ignore it. It's probably some
2196 new type we don't know about yet. */
2197 unknown_symtype_complaint (local_hex_string (nlist.n_type));
2202 /* If there's stuff to be cleaned up, clean it up. */
2203 if (DBX_SYMCOUNT (objfile) > 0 /* We have some syms */
2204 /*FIXME, does this have a bug at start address 0? */
2205 && last_o_file_start
2206 && objfile->ei.entry_point < nlist.n_value
2207 && objfile->ei.entry_point >= last_o_file_start)
2209 objfile->ei.entry_file_lowpc = last_o_file_start;
2210 objfile->ei.entry_file_highpc = nlist.n_value;
2215 /* Don't set pst->texthigh lower than it already is. */
2216 CORE_ADDR text_end =
2217 (lowest_text_address == (CORE_ADDR) -1
2218 ? (text_addr + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)))
2219 : lowest_text_address)
2222 end_psymtab (pst, psymtab_include_list, includes_used,
2223 symnum * symbol_size,
2224 text_end > pst->texthigh ? text_end : pst->texthigh,
2225 dependency_list, dependencies_used, textlow_not_set);
2228 do_cleanups (back_to);
2231 /* Allocate and partially fill a partial symtab. It will be
2232 completely filled at the end of the symbol list.
2234 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2235 is the address relative to which its symbols are (incremental) or 0
2239 static struct partial_symtab *
2240 start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
2241 int ldsymoff, struct partial_symbol **global_syms,
2242 struct partial_symbol **static_syms)
2244 struct partial_symtab *result =
2245 start_psymtab_common (objfile, objfile->section_offsets,
2246 filename, textlow, global_syms, static_syms);
2248 result->read_symtab_private = (char *)
2249 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
2250 LDSYMOFF (result) = ldsymoff;
2251 result->read_symtab = dbx_psymtab_to_symtab;
2252 SYMBOL_SIZE (result) = symbol_size;
2253 SYMBOL_OFFSET (result) = symbol_table_offset;
2254 STRING_OFFSET (result) = string_table_offset;
2255 FILE_STRING_OFFSET (result) = file_string_table_offset;
2257 /* If we're handling an ELF file, drag some section-relocation info
2258 for this source file out of the ELF symbol table, to compensate for
2259 Sun brain death. This replaces the section_offsets in this psymtab,
2261 elfstab_offset_sections (objfile, result);
2263 /* Deduce the source language from the filename for this psymtab. */
2264 psymtab_language = deduce_language_from_filename (filename);
2269 /* Close off the current usage of PST.
2270 Returns PST or NULL if the partial symtab was empty and thrown away.
2272 FIXME: List variables and peculiarities of same. */
2274 struct partial_symtab *
2275 end_psymtab (struct partial_symtab *pst, char **include_list, int num_includes,
2276 int capping_symbol_offset, CORE_ADDR capping_text,
2277 struct partial_symtab **dependency_list, int number_dependencies,
2278 int textlow_not_set)
2281 struct objfile *objfile = pst->objfile;
2283 if (capping_symbol_offset != -1)
2284 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2285 pst->texthigh = capping_text;
2287 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
2288 /* Under Solaris, the N_SO symbols always have a value of 0,
2289 instead of the usual address of the .o file. Therefore,
2290 we have to do some tricks to fill in texthigh and textlow.
2291 The first trick is: if we see a static
2292 or global function, and the textlow for the current pst
2293 is not set (ie: textlow_not_set), then we use that function's
2294 address for the textlow of the pst. */
2296 /* Now, to fill in texthigh, we remember the last function seen
2297 in the .o file. Also, there's a hack in
2298 bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
2299 to here via the misc_info field. Therefore, we can fill in
2300 a reliable texthigh by taking the address plus size of the
2301 last function in the file. */
2303 if (pst->texthigh == 0 && last_function_name)
2307 struct minimal_symbol *minsym;
2309 p = strchr (last_function_name, ':');
2311 p = last_function_name;
2312 n = p - last_function_name;
2314 strncpy (p, last_function_name, n);
2317 minsym = lookup_minimal_symbol (p, pst->filename, objfile);
2320 /* Sun Fortran appends an underscore to the minimal symbol name,
2321 try again with an appended underscore if the minimal symbol
2325 minsym = lookup_minimal_symbol (p, pst->filename, objfile);
2329 pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + MSYMBOL_SIZE (minsym);
2331 last_function_name = NULL;
2334 /* this test will be true if the last .o file is only data */
2335 if (textlow_not_set)
2336 pst->textlow = pst->texthigh;
2339 struct partial_symtab *p1;
2341 /* If we know our own starting text address, then walk through all other
2342 psymtabs for this objfile, and if any didn't know their ending text
2343 address, set it to our starting address. Take care to not set our
2344 own ending address to our starting address, nor to set addresses on
2345 `dependency' files that have both textlow and texthigh zero. */
2347 ALL_OBJFILE_PSYMTABS (objfile, p1)
2349 if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
2351 p1->texthigh = pst->textlow;
2352 /* if this file has only data, then make textlow match texthigh */
2353 if (p1->textlow == 0)
2354 p1->textlow = p1->texthigh;
2359 /* End of kludge for patching Solaris textlow and texthigh. */
2360 #endif /* SOFUN_ADDRESS_MAYBE_MISSING. */
2362 pst->n_global_syms =
2363 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2364 pst->n_static_syms =
2365 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2367 pst->number_of_dependencies = number_dependencies;
2368 if (number_dependencies)
2370 pst->dependencies = (struct partial_symtab **)
2371 obstack_alloc (&objfile->psymbol_obstack,
2372 number_dependencies * sizeof (struct partial_symtab *));
2373 memcpy (pst->dependencies, dependency_list,
2374 number_dependencies * sizeof (struct partial_symtab *));
2377 pst->dependencies = 0;
2379 for (i = 0; i < num_includes; i++)
2381 struct partial_symtab *subpst =
2382 allocate_psymtab (include_list[i], objfile);
2384 /* Copy the sesction_offsets array from the main psymtab. */
2385 subpst->section_offsets = pst->section_offsets;
2386 subpst->read_symtab_private =
2387 (char *) obstack_alloc (&objfile->psymbol_obstack,
2388 sizeof (struct symloc));
2392 subpst->texthigh = 0;
2394 /* We could save slight bits of space by only making one of these,
2395 shared by the entire set of include files. FIXME-someday. */
2396 subpst->dependencies = (struct partial_symtab **)
2397 obstack_alloc (&objfile->psymbol_obstack,
2398 sizeof (struct partial_symtab *));
2399 subpst->dependencies[0] = pst;
2400 subpst->number_of_dependencies = 1;
2402 subpst->globals_offset =
2403 subpst->n_global_syms =
2404 subpst->statics_offset =
2405 subpst->n_static_syms = 0;
2409 subpst->read_symtab = pst->read_symtab;
2412 sort_pst_symbols (pst);
2414 /* If there is already a psymtab or symtab for a file of this name, remove it.
2415 (If there is a symtab, more drastic things also happen.)
2416 This happens in VxWorks. */
2417 free_named_symtabs (pst->filename);
2419 if (num_includes == 0
2420 && number_dependencies == 0
2421 && pst->n_global_syms == 0
2422 && pst->n_static_syms == 0
2423 && has_line_numbers == 0)
2425 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2426 it is on the obstack, but we can forget to chain it on the list. */
2427 /* Empty psymtabs happen as a result of header files which don't have
2428 any symbols in them. There can be a lot of them. But this check
2429 is wrong, in that a psymtab with N_SLINE entries but nothing else
2430 is not empty, but we don't realize that. Fixing that without slowing
2431 things down might be tricky. */
2433 discard_psymtab (pst);
2435 /* Indicate that psymtab was thrown away. */
2436 pst = (struct partial_symtab *) NULL;
2442 dbx_psymtab_to_symtab_1 (struct partial_symtab *pst)
2444 struct cleanup *old_chain;
2452 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2457 /* Read in all partial symtabs on which this one is dependent */
2458 for (i = 0; i < pst->number_of_dependencies; i++)
2459 if (!pst->dependencies[i]->readin)
2461 /* Inform about additional files that need to be read in. */
2464 fputs_filtered (" ", gdb_stdout);
2466 fputs_filtered ("and ", gdb_stdout);
2468 printf_filtered ("%s...", pst->dependencies[i]->filename);
2469 wrap_here (""); /* Flush output */
2470 gdb_flush (gdb_stdout);
2472 dbx_psymtab_to_symtab_1 (pst->dependencies[i]);
2475 if (LDSYMLEN (pst)) /* Otherwise it's a dummy */
2477 /* Init stuff necessary for reading in symbols */
2480 old_chain = make_cleanup (really_free_pendings, 0);
2481 file_string_table_offset = FILE_STRING_OFFSET (pst);
2482 symbol_size = SYMBOL_SIZE (pst);
2484 /* Read in this file's symbols */
2485 bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
2486 read_ofile_symtab (pst);
2487 sort_symtab_syms (pst->symtab);
2489 do_cleanups (old_chain);
2495 /* Read in all of the symbols for a given psymtab for real.
2496 Be verbose about it if the user wants that. */
2499 dbx_psymtab_to_symtab (struct partial_symtab *pst)
2502 struct cleanup *back_to = NULL;
2509 fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. Shouldn't happen.\n",
2514 if (LDSYMLEN (pst) || pst->number_of_dependencies)
2516 /* Print the message now, before reading the string table,
2517 to avoid disconcerting pauses. */
2520 printf_filtered ("Reading in symbols for %s...", pst->filename);
2521 gdb_flush (gdb_stdout);
2524 sym_bfd = pst->objfile->obfd;
2526 next_symbol_text_func = dbx_next_symbol_text;
2528 if (DBX_STAB_SECTION (pst->objfile))
2531 = symfile_relocate_debug_section (pst->objfile->obfd,
2532 DBX_STAB_SECTION (pst->objfile),
2535 back_to = make_cleanup (free_current_contents, (void *) &stabs_data);
2538 dbx_psymtab_to_symtab_1 (pst);
2541 do_cleanups (back_to);
2543 /* Match with global symbols. This only needs to be done once,
2544 after all of the symtabs and dependencies have been read in. */
2545 scan_file_globals (pst->objfile);
2547 /* Finish up the debug error message. */
2549 printf_filtered ("done.\n");
2553 /* Read in a defined section of a specific object file's symbols. */
2556 read_ofile_symtab (struct partial_symtab *pst)
2558 register char *namestring;
2559 register struct external_nlist *bufp;
2560 struct internal_nlist nlist;
2562 unsigned max_symnum;
2564 struct objfile *objfile;
2565 int sym_offset; /* Offset to start of symbols to read */
2566 int sym_size; /* Size of symbols to read */
2567 CORE_ADDR text_offset; /* Start of text segment for symbols */
2568 int text_size; /* Size of text segment for symbols */
2569 struct section_offsets *section_offsets;
2571 objfile = pst->objfile;
2572 sym_offset = LDSYMOFF (pst);
2573 sym_size = LDSYMLEN (pst);
2574 text_offset = pst->textlow;
2575 text_size = pst->texthigh - pst->textlow;
2576 /* This cannot be simply objfile->section_offsets because of
2577 elfstab_offset_sections() which initializes the psymtab section
2578 offsets information in a special way, and that is different from
2579 objfile->section_offsets. */
2580 section_offsets = pst->section_offsets;
2582 current_objfile = objfile;
2583 subfile_stack = NULL;
2585 stringtab_global = DBX_STRINGTAB (objfile);
2586 last_source_file = NULL;
2588 abfd = objfile->obfd;
2589 symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol */
2590 symbuf_end = symbuf_idx = 0;
2592 symbuf_left = sym_offset + sym_size;
2594 /* It is necessary to actually read one symbol *before* the start
2595 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
2596 occurs before the N_SO symbol.
2598 Detecting this in read_dbx_symtab
2599 would slow down initial readin, so we look for it here instead. */
2600 if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
2602 stabs_seek (sym_offset - symbol_size);
2604 bufp = &symbuf[symbuf_idx++];
2605 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
2606 OBJSTAT (objfile, n_stabs++);
2608 namestring = set_namestring (objfile, nlist);
2610 processing_gcc_compilation = 0;
2611 if (nlist.n_type == N_TEXT)
2613 const char *tempstring = namestring;
2615 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
2616 processing_gcc_compilation = 1;
2617 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
2618 processing_gcc_compilation = 2;
2619 if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
2621 if (STREQN (tempstring, "__gnu_compiled", 14))
2622 processing_gcc_compilation = 2;
2625 /* Try to select a C++ demangling based on the compilation unit
2629 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
2630 know whether it will use the old style or v3 mangling. */
2631 if (processing_gcc_compilation)
2633 if (AUTO_DEMANGLING)
2635 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
2642 /* The N_SO starting this symtab is the first symbol, so we
2643 better not check the symbol before it. I'm not this can
2644 happen, but it doesn't hurt to check for it. */
2645 stabs_seek (sym_offset);
2646 processing_gcc_compilation = 0;
2649 if (symbuf_idx == symbuf_end)
2651 bufp = &symbuf[symbuf_idx];
2652 if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
2653 error ("First symbol in segment of executable not a source symbol");
2655 max_symnum = sym_size / symbol_size;
2658 symnum < max_symnum;
2661 QUIT; /* Allow this to be interruptable */
2662 if (symbuf_idx == symbuf_end)
2664 bufp = &symbuf[symbuf_idx++];
2665 INTERNALIZE_SYMBOL (nlist, bufp, abfd);
2666 OBJSTAT (objfile, n_stabs++);
2668 type = bfd_h_get_8 (abfd, bufp->e_type);
2670 namestring = set_namestring (objfile, nlist);
2674 process_one_symbol (type, nlist.n_desc, nlist.n_value,
2675 namestring, section_offsets, objfile);
2677 /* We skip checking for a new .o or -l file; that should never
2678 happen in this routine. */
2679 else if (type == N_TEXT)
2681 /* I don't think this code will ever be executed, because
2682 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2683 the N_SO symbol which starts this source file.
2684 However, there is no reason not to accept
2685 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2687 if (STREQ (namestring, GCC_COMPILED_FLAG_SYMBOL))
2688 processing_gcc_compilation = 1;
2689 else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
2690 processing_gcc_compilation = 2;
2693 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
2694 know whether it will use the old style or v3 mangling. */
2695 if (AUTO_DEMANGLING)
2697 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
2701 else if (type & N_EXT || type == (unsigned char) N_TEXT
2702 || type == (unsigned char) N_NBTEXT
2705 /* Global symbol: see if we came across a dbx defintion for
2706 a corresponding symbol. If so, store the value. Remove
2707 syms from the chain when their values are stored, but
2708 search the whole chain, as there may be several syms from
2709 different files with the same name. */
2710 /* This is probably not true. Since the files will be read
2711 in one at a time, each reference to a global symbol will
2712 be satisfied in each file as it appears. So we skip this
2718 current_objfile = NULL;
2720 /* In a Solaris elf file, this variable, which comes from the
2721 value of the N_SO symbol, will still be 0. Luckily, text_offset,
2722 which comes from pst->textlow is correct. */
2723 if (last_source_start_addr == 0)
2724 last_source_start_addr = text_offset;
2726 /* In reordered executables last_source_start_addr may not be the
2727 lower bound for this symtab, instead use text_offset which comes
2728 from pst->textlow which is correct. */
2729 if (last_source_start_addr > text_offset)
2730 last_source_start_addr = text_offset;
2732 pst->symtab = end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile));
2734 #if 0 /* OBSOLETE CFront */
2735 // OBSOLETE /* Process items which we had to "process_later" due to dependencies
2736 // OBSOLETE on other stabs. */
2737 // OBSOLETE process_now (objfile);
2738 #endif /* OBSOLETE CFront */
2743 /* This handles a single symbol from the symbol-file, building symbols
2744 into a GDB symtab. It takes these arguments and an implicit argument.
2746 TYPE is the type field of the ".stab" symbol entry.
2747 DESC is the desc field of the ".stab" entry.
2748 VALU is the value field of the ".stab" entry.
2749 NAME is the symbol name, in our address space.
2750 SECTION_OFFSETS is a set of amounts by which the sections of this object
2751 file were relocated when it was loaded into memory.
2752 Note that these section_offsets are not the
2753 objfile->section_offsets but the pst->section_offsets.
2754 All symbols that refer
2755 to memory locations need to be offset by these amounts.
2756 OBJFILE is the object file from which we are reading symbols.
2757 It is used in end_symtab. */
2760 process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
2761 struct section_offsets *section_offsets,
2762 struct objfile *objfile)
2764 #ifdef SUN_FIXED_LBRAC_BUG
2765 /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need
2766 to correct the address of N_LBRAC's. If it is not defined, then
2767 we never need to correct the addresses. */
2769 /* This records the last pc address we've seen. We depend on there being
2770 an SLINE or FUN or SO before the first LBRAC, since the variable does
2771 not get reset in between reads of different symbol files. */
2772 static CORE_ADDR last_pc_address;
2775 register struct context_stack *new;
2776 /* This remembers the address of the start of a function. It is used
2777 because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are
2778 relative to the current function's start address. On systems
2779 other than Solaris 2, this just holds the SECT_OFF_TEXT value, and is
2780 used to relocate these symbol types rather than SECTION_OFFSETS. */
2781 static CORE_ADDR function_start_offset;
2783 /* This holds the address of the start of a function, without the system
2784 peculiarities of function_start_offset. */
2785 static CORE_ADDR last_function_start;
2787 /* If this is nonzero, we've seen an N_SLINE since the start of the
2788 current function. We use this to tell us to move the first sline
2789 to the beginning of the function regardless of what its given
2791 static int sline_found_in_function = 1;
2793 /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
2794 file. Used to detect the SunPRO solaris compiler. */
2795 static int n_opt_found;
2797 /* The stab type used for the definition of the last function.
2798 N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
2799 static int function_stab_type = 0;
2801 if (!block_address_function_relative)
2802 /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
2803 function start address, so just use the text offset. */
2804 function_start_offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2806 /* Something is wrong if we see real data before
2807 seeing a source file name. */
2809 if (last_source_file == NULL && type != (unsigned char) N_SO)
2811 /* Ignore any symbols which appear before an N_SO symbol.
2812 Currently no one puts symbols there, but we should deal
2813 gracefully with the case. A complain()t might be in order,
2814 but this should not be an error (). */
2823 if (*name == '\000')
2825 /* This N_FUN marks the end of a function. This closes off the
2828 if (context_stack_depth <= 0)
2830 lbrac_mismatch_complaint (symnum);
2834 /* The following check is added before recording line 0 at
2835 end of function so as to handle hand-generated stabs
2836 which may have an N_FUN stabs at the end of the function, but
2837 no N_SLINE stabs. */
2838 if (sline_found_in_function)
2839 record_line (current_subfile, 0, last_function_start + valu);
2841 within_function = 0;
2842 new = pop_context ();
2844 /* Make a block for the local symbols within. */
2845 finish_block (new->name, &local_symbols, new->old_blocks,
2846 new->start_addr, new->start_addr + valu,
2849 /* May be switching to an assembler file which may not be using
2850 block relative stabs, so reset the offset. */
2851 if (block_address_function_relative)
2852 function_start_offset = 0;
2857 sline_found_in_function = 0;
2859 /* Relocate for dynamic loading */
2860 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2861 valu = SMASH_TEXT_ADDRESS (valu);
2862 last_function_start = valu;
2864 goto define_a_symbol;
2867 /* This "symbol" just indicates the start of an inner lexical
2868 context within a function. */
2870 /* Ignore extra outermost context from SunPRO cc and acc. */
2871 if (n_opt_found && desc == 1)
2874 if (block_address_function_relative)
2875 /* Relocate for Sun ELF acc fn-relative syms. */
2876 valu += function_start_offset;
2878 /* On most machines, the block addresses are relative to the
2879 N_SO, the linker did not relocate them (sigh). */
2880 valu += last_source_start_addr;
2882 #ifdef SUN_FIXED_LBRAC_BUG
2883 if (!SUN_FIXED_LBRAC_BUG && valu < last_pc_address)
2885 /* Patch current LBRAC pc value to match last handy pc value */
2886 complaint (&symfile_complaints, "bad block start address patched");
2887 valu = last_pc_address;
2890 new = push_context (desc, valu);
2894 /* This "symbol" just indicates the end of an inner lexical
2895 context that was started with N_LBRAC. */
2897 /* Ignore extra outermost context from SunPRO cc and acc. */
2898 if (n_opt_found && desc == 1)
2901 if (block_address_function_relative)
2902 /* Relocate for Sun ELF acc fn-relative syms. */
2903 valu += function_start_offset;
2905 /* On most machines, the block addresses are relative to the
2906 N_SO, the linker did not relocate them (sigh). */
2907 valu += last_source_start_addr;
2909 if (context_stack_depth <= 0)
2911 lbrac_mismatch_complaint (symnum);
2915 new = pop_context ();
2916 if (desc != new->depth)
2917 lbrac_mismatch_complaint (symnum);
2919 /* Some compilers put the variable decls inside of an
2920 LBRAC/RBRAC block. This macro should be nonzero if this
2921 is true. DESC is N_DESC from the N_RBRAC symbol.
2922 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL
2923 or the GCC2_COMPILED_SYMBOL. */
2924 #if !defined (VARIABLES_INSIDE_BLOCK)
2925 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
2928 /* Can only use new->locals as local symbols here if we're in
2929 gcc or on a machine that puts them before the lbrack. */
2930 if (!VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation))
2932 if (local_symbols != NULL)
2934 /* GCC development snapshots from March to December of
2935 2000 would output N_LSYM entries after N_LBRAC
2936 entries. As a consequence, these symbols are simply
2937 discarded. Complain if this is the case. Note that
2938 there are some compilers which legitimately put local
2939 symbols within an LBRAC/RBRAC block; this complaint
2940 might also help sort out problems in which
2941 VARIABLES_INSIDE_BLOCK is incorrectly defined. */
2942 complaint (&symfile_complaints,
2943 "misplaced N_LBRAC entry; discarding local symbols which have no enclosing block");
2945 local_symbols = new->locals;
2948 if (context_stack_depth
2949 > !VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation))
2951 /* This is not the outermost LBRAC...RBRAC pair in the function,
2952 its local symbols preceded it, and are the ones just recovered
2953 from the context stack. Define the block for them (but don't
2954 bother if the block contains no symbols. Should we complain
2955 on blocks without symbols? I can't think of any useful purpose
2957 if (local_symbols != NULL)
2959 /* Muzzle a compiler bug that makes end < start. (which
2960 compilers? Is this ever harmful?). */
2961 if (new->start_addr > valu)
2963 complaint (&symfile_complaints,
2964 "block start larger than block end");
2965 new->start_addr = valu;
2967 /* Make a block for the local symbols within. */
2968 finish_block (0, &local_symbols, new->old_blocks,
2969 new->start_addr, valu, objfile);
2974 /* This is the outermost LBRAC...RBRAC pair. There is no
2975 need to do anything; leave the symbols that preceded it
2976 to be attached to the function's own block. We need to
2977 indicate that we just moved outside of the function. */
2978 within_function = 0;
2981 if (VARIABLES_INSIDE_BLOCK (desc, processing_gcc_compilation))
2982 /* Now pop locals of block just finished. */
2983 local_symbols = new->locals;
2988 /* This kind of symbol indicates the start of an object file. */
2989 /* Relocate for dynamic loading */
2990 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2994 /* This type of symbol indicates the start of data
2995 for one source file.
2996 Finish the symbol table of the previous source file
2997 (if any) and start accumulating a new symbol table. */
2998 /* Relocate for dynamic loading */
2999 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
3003 #ifdef SUN_FIXED_LBRAC_BUG
3004 last_pc_address = valu; /* Save for SunOS bug circumcision */
3007 #ifdef PCC_SOL_BROKEN
3008 /* pcc bug, occasionally puts out SO for SOL. */
3009 if (context_stack_depth > 0)
3011 start_subfile (name, NULL);
3015 if (last_source_file)
3017 /* Check if previous symbol was also an N_SO (with some
3018 sanity checks). If so, that one was actually the directory
3019 name, and the current one is the real file name.
3021 if (previous_stab_code == (unsigned char) N_SO)
3023 patch_subfile_names (current_subfile, name);
3024 break; /* Ignore repeated SOs */
3026 end_symtab (valu, objfile, SECT_OFF_TEXT (objfile));
3030 /* Null name means this just marks the end of text for this .o file.
3031 Don't start a new symtab in this case. */
3032 if (*name == '\000')
3035 if (block_address_function_relative)
3036 function_start_offset = 0;
3039 start_symtab (name, NULL, valu);
3040 record_debugformat ("stabs");
3044 /* This type of symbol indicates the start of data for
3045 a sub-source-file, one whose contents were copied or
3046 included in the compilation of the main source file
3047 (whose name was given in the N_SO symbol.) */
3048 /* Relocate for dynamic loading */
3049 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
3050 start_subfile (name, current_subfile->dirname);
3055 add_new_header_file (name, valu);
3056 start_subfile (name, current_subfile->dirname);
3060 start_subfile (pop_subfile (), current_subfile->dirname);
3064 add_old_header_file (name, valu);
3068 /* This type of "symbol" really just records
3069 one line-number -- core-address correspondence.
3070 Enter it in the line list for this symbol table. */
3072 /* Relocate for dynamic loading and for ELF acc fn-relative syms. */
3073 valu += function_start_offset;
3075 #ifdef SUN_FIXED_LBRAC_BUG
3076 last_pc_address = valu; /* Save for SunOS bug circumcision */
3078 /* If this is the first SLINE note in the function, record it at
3079 the start of the function instead of at the listed location. */
3080 if (within_function && sline_found_in_function == 0)
3082 record_line (current_subfile, desc, last_function_start);
3083 sline_found_in_function = 1;
3086 record_line (current_subfile, desc, valu);
3090 common_block_start (name, objfile);
3094 common_block_end (objfile);
3097 /* The following symbol types need to have the appropriate offset added
3098 to their value; then we process symbol definitions in the name. */
3100 case N_STSYM: /* Static symbol in data seg */
3101 case N_LCSYM: /* Static symbol in BSS seg */
3102 case N_ROSYM: /* Static symbol in Read-only data seg */
3103 /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
3104 Solaris2's stabs-in-elf makes *most* symbols relative
3105 but leaves a few absolute (at least for Solaris 2.1 and version
3106 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on the fence.
3107 .stab "foo:S...",N_STSYM is absolute (ld relocates it)
3108 .stab "foo:V...",N_STSYM is relative (section base subtracted).
3109 This leaves us no choice but to search for the 'S' or 'V'...
3110 (or pass the whole section_offsets stuff down ONE MORE function
3111 call level, which we really don't want to do). */
3115 /* .o files and NLMs have non-zero text seg offsets, but don't need
3116 their static syms offset in this fashion. XXX - This is really a
3117 crock that should be fixed in the solib handling code so that I
3118 don't have to work around it here. */
3120 if (!symfile_relocatable)
3122 p = strchr (name, ':');
3123 if (p != 0 && p[1] == 'S')
3125 /* The linker relocated it. We don't want to add an
3126 elfstab_offset_sections-type offset, but we *do* want
3127 to add whatever solib.c passed to symbol_file_add as
3128 addr (this is known to affect SunOS4, and I suspect ELF
3129 too). Since elfstab_offset_sections currently does not
3130 muck with the text offset (there is no Ttext.text
3131 symbol), we can get addr from the text offset. If
3132 elfstab_offset_sections ever starts dealing with the
3133 text offset, and we still need to do this, we need to
3134 invent a SECT_OFF_ADDR_KLUDGE or something. */
3135 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
3136 goto define_a_symbol;
3139 /* Since it's not the kludge case, re-dispatch to the right handler. */
3149 internal_error (__FILE__, __LINE__, "failed internal consistency check");
3153 case_N_STSYM: /* Static symbol in data seg */
3154 case N_DSLINE: /* Source line number, data seg */
3155 valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
3156 goto define_a_symbol;
3158 case_N_LCSYM: /* Static symbol in BSS seg */
3159 case N_BSLINE: /* Source line number, bss seg */
3160 /* N_BROWS: overlaps with N_BSLINE */
3161 valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
3162 goto define_a_symbol;
3164 case_N_ROSYM: /* Static symbol in Read-only data seg */
3165 valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile));
3166 goto define_a_symbol;
3168 case N_ENTRY: /* Alternate entry point */
3169 /* Relocate for dynamic loading */
3170 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
3171 goto define_a_symbol;
3173 /* The following symbol types we don't know how to process. Handle
3174 them in a "default" way, but complain to people who care. */
3176 case N_CATCH: /* Exception handler catcher */
3177 case N_EHDECL: /* Exception handler name */
3178 case N_PC: /* Global symbol in Pascal */
3179 case N_M2C: /* Modula-2 compilation unit */
3180 /* N_MOD2: overlaps with N_EHDECL */
3181 case N_SCOPE: /* Modula-2 scope information */
3182 case N_ECOML: /* End common (local name) */
3183 case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
3188 unknown_symtype_complaint (local_hex_string (type));
3191 /* The following symbol types don't need the address field relocated,
3192 since it is either unused, or is absolute. */
3194 case N_GSYM: /* Global variable */
3195 case N_NSYMS: /* Number of symbols (ultrix) */
3196 case N_NOMAP: /* No map? (ultrix) */
3197 case N_RSYM: /* Register variable */
3198 case N_DEFD: /* Modula-2 GNU module dependency */
3199 case N_SSYM: /* Struct or union element */
3200 case N_LSYM: /* Local symbol in stack */
3201 case N_PSYM: /* Parameter variable */
3202 case N_LENG: /* Length of preceding symbol type */
3206 char *colon_pos = strchr (name, ':');
3207 if (colon_pos == NULL)
3210 deftype = colon_pos[1];
3216 function_stab_type = type;
3218 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
3219 /* Deal with the SunPRO 3.0 compiler which omits the address
3220 from N_FUN symbols. */
3222 && valu == ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)))
3224 CORE_ADDR minsym_valu =
3225 find_stab_function_addr (name, last_source_file, objfile);
3227 /* find_stab_function_addr will return 0 if the minimal
3228 symbol wasn't found. (Unfortunately, this might also
3229 be a valid address.) Anyway, if it *does* return 0,
3230 it is likely that the value was set correctly to begin
3232 if (minsym_valu != 0)
3237 #ifdef SUN_FIXED_LBRAC_BUG
3238 /* The Sun acc compiler, under SunOS4, puts out
3239 functions with N_GSYM or N_STSYM. The problem is
3240 that the address of the symbol is no good (for N_GSYM
3241 it doesn't even attept an address; for N_STSYM it
3242 puts out an address but then it gets relocated
3243 relative to the data segment, not the text segment).
3244 Currently we can't fix this up later as we do for
3245 some types of symbol in scan_file_globals.
3246 Fortunately we do have a way of finding the address -
3247 we know that the value in last_pc_address is either
3248 the one we want (if we're dealing with the first
3249 function in an object file), or somewhere in the
3250 previous function. This means that we can use the
3251 minimal symbol table to get the address. */
3253 /* Starting with release 3.0, the Sun acc compiler,
3254 under SunOS4, puts out functions with N_FUN and a value
3255 of zero. This gets relocated to the start of the text
3256 segment of the module, which is no good either.
3257 Under SunOS4 we can deal with this as N_SLINE and N_SO
3258 entries contain valid absolute addresses.
3259 Release 3.0 acc also puts out N_OPT entries, which makes
3260 it possible to discern acc from cc or gcc. */
3262 if (type == N_GSYM || type == N_STSYM
3264 && n_opt_found && !block_address_function_relative))
3266 struct minimal_symbol *m;
3267 int l = colon_pos - name;
3269 m = lookup_minimal_symbol_by_pc (last_pc_address);
3270 if (m && STREQN (DEPRECATED_SYMBOL_NAME (m), name, l)
3271 && DEPRECATED_SYMBOL_NAME (m)[l] == '\0')
3272 /* last_pc_address was in this function */
3273 valu = SYMBOL_VALUE (m);
3274 else if (m && DEPRECATED_SYMBOL_NAME (m + 1)
3275 && STREQN (DEPRECATED_SYMBOL_NAME (m + 1), name, l)
3276 && DEPRECATED_SYMBOL_NAME (m + 1)[l] == '\0')
3277 /* last_pc_address was in last function */
3278 valu = SYMBOL_VALUE (m + 1);
3280 /* Not found - use last_pc_address (for finish_block) */
3281 valu = last_pc_address;
3284 last_pc_address = valu; /* Save for SunOS bug circumcision */
3287 if (block_address_function_relative)
3288 /* For Solaris 2.0 compilers, the block addresses and
3289 N_SLINE's are relative to the start of the
3290 function. On normal systems, and when using gcc on
3291 Solaris 2.0, these addresses are just absolute, or
3292 relative to the N_SO, depending on
3293 BLOCK_ADDRESS_ABSOLUTE. */
3294 function_start_offset = valu;
3296 within_function = 1;
3298 if (context_stack_depth > 1)
3300 complaint (&symfile_complaints,
3301 "unmatched N_LBRAC before symtab pos %d", symnum);
3305 if (context_stack_depth > 0)
3307 new = pop_context ();
3308 /* Make a block for the local symbols within. */
3309 finish_block (new->name, &local_symbols, new->old_blocks,
3310 new->start_addr, valu, objfile);
3313 new = push_context (0, valu);
3314 new->name = define_symbol (valu, name, desc, type, objfile);
3318 define_symbol (valu, name, desc, type, objfile);
3324 /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
3325 for a bunch of other flags, too. Someday we may parse their
3326 flags; for now we ignore theirs and hope they'll ignore ours. */
3327 case N_OPT: /* Solaris 2: Compiler options */
3330 if (STREQ (name, GCC2_COMPILED_FLAG_SYMBOL))
3332 processing_gcc_compilation = 2;
3333 #if 0 /* Works, but is experimental. -fnf */
3334 /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
3335 know whether it will use the old style or v3 mangling. */
3336 if (AUTO_DEMANGLING)
3338 set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
3347 case N_MAIN: /* Name of main routine. */
3348 /* FIXME: If one has a symbol file with N_MAIN and then replaces
3349 it with a symbol file with "main" and without N_MAIN. I'm
3350 not sure exactly what rule to follow but probably something
3351 like: N_MAIN takes precedence over "main" no matter what
3352 objfile it is in; If there is more than one N_MAIN, choose
3353 the one in the symfile_objfile; If there is more than one
3354 N_MAIN within a given objfile, complain() and choose
3355 arbitrarily. (kingdon) */
3357 set_main_name (name);
3360 /* The following symbol types can be ignored. */
3361 case N_OBJ: /* Solaris 2: Object file dir and name */
3362 /* N_UNDF: Solaris 2: file separator mark */
3363 /* N_UNDF: -- we will never encounter it, since we only process one
3364 file's symbols at once. */
3365 case N_ENDM: /* Solaris 2: End of module */
3366 case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
3370 /* '#' is a GNU C extension to allow one symbol to refer to another
3373 Generally this is used so that an alias can refer to its main
3377 /* Initialize symbol reference names and determine if this is
3378 a definition. If symbol reference is being defined, go
3379 ahead and add it. Otherwise, just return sym. */
3384 /* If this stab defines a new reference ID that is not on the
3385 reference list, then put it on the reference list.
3387 We go ahead and advance NAME past the reference, even though
3388 it is not strictly necessary at this time. */
3389 refnum = symbol_reference_defined (&s);
3391 if (!ref_search (refnum))
3392 ref_add (refnum, 0, name, valu);
3397 previous_stab_code = type;
3400 /* FIXME: The only difference between this and elfstab_build_psymtabs
3401 is the call to install_minimal_symbols for elf, and the support for
3402 split sections. If the differences are really that small, the code
3403 should be shared. */
3405 /* Scan and build partial symbols for an coff symbol file.
3406 The coff file has already been processed to get its minimal symbols.
3408 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3411 OBJFILE is the object file we are reading symbols from.
3412 ADDR is the address relative to which the symbols are (e.g.
3413 the base address of the text segment).
3414 MAINLINE is true if we are reading the main symbol
3415 table (as opposed to a shared lib or dynamically loaded file).
3416 TEXTADDR is the address of the text section.
3417 TEXTSIZE is the size of the text section.
3418 STABSECTS is the list of .stab sections in OBJFILE.
3419 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
3420 .stabstr section exists.
3422 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
3423 adjusted for coff details. */
3426 coffstab_build_psymtabs (struct objfile *objfile, int mainline,
3427 CORE_ADDR textaddr, unsigned int textsize,
3428 struct stab_section_list *stabsects,
3429 file_ptr stabstroffset, unsigned int stabstrsize)
3432 bfd *sym_bfd = objfile->obfd;
3433 char *name = bfd_get_filename (sym_bfd);
3434 struct dbx_symfile_info *info;
3435 unsigned int stabsize;
3437 /* There is already a dbx_symfile_info allocated by our caller.
3438 It might even contain some info from the coff symtab to help us. */
3439 info = objfile->sym_stab_info;
3441 DBX_TEXT_ADDR (objfile) = textaddr;
3442 DBX_TEXT_SIZE (objfile) = textsize;
3444 #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
3445 DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE;
3446 DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
3448 if (stabstrsize > bfd_get_size (sym_bfd))
3449 error ("ridiculous string table size: %d bytes", stabstrsize);
3450 DBX_STRINGTAB (objfile) = (char *)
3451 obstack_alloc (&objfile->psymbol_obstack, stabstrsize + 1);
3452 OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
3454 /* Now read in the string table in one big gulp. */
3456 val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
3458 perror_with_name (name);
3459 val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
3460 if (val != stabstrsize)
3461 perror_with_name (name);
3463 stabsread_new_init ();
3464 buildsym_new_init ();
3465 free_header_files ();
3466 init_header_files ();
3468 processing_acc_compilation = 1;
3470 /* In a coff file, we've already installed the minimal symbols that came
3471 from the coff (non-stab) symbol table, so always act like an
3472 incremental load here. */
3473 if (stabsects->next == NULL)
3475 stabsize = bfd_section_size (sym_bfd, stabsects->section);
3476 DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
3477 DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
3481 struct stab_section_list *stabsect;
3483 DBX_SYMCOUNT (objfile) = 0;
3484 for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next)
3486 stabsize = bfd_section_size (sym_bfd, stabsect->section);
3487 DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
3490 DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
3492 symbuf_sections = stabsects->next;
3493 symbuf_left = bfd_section_size (sym_bfd, stabsects->section);
3497 dbx_symfile_read (objfile, 0);
3500 /* Scan and build partial symbols for an ELF symbol file.
3501 This ELF file has already been processed to get its minimal symbols,
3502 and any DWARF symbols that were in it.
3504 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3507 OBJFILE is the object file we are reading symbols from.
3508 ADDR is the address relative to which the symbols are (e.g.
3509 the base address of the text segment).
3510 MAINLINE is true if we are reading the main symbol
3511 table (as opposed to a shared lib or dynamically loaded file).
3512 STABSECT is the BFD section information for the .stab section.
3513 STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
3514 .stabstr section exists.
3516 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
3517 adjusted for elf details. */
3520 elfstab_build_psymtabs (struct objfile *objfile, int mainline,
3522 file_ptr stabstroffset, unsigned int stabstrsize)
3525 bfd *sym_bfd = objfile->obfd;
3526 char *name = bfd_get_filename (sym_bfd);
3527 struct dbx_symfile_info *info;
3528 struct cleanup *back_to = NULL;
3530 /* There is already a dbx_symfile_info allocated by our caller.
3531 It might even contain some info from the ELF symtab to help us. */
3532 info = objfile->sym_stab_info;
3534 /* Find the first and last text address. dbx_symfile_read seems to
3536 find_text_range (sym_bfd, objfile);
3538 #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
3539 DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE;
3540 DBX_SYMCOUNT (objfile)
3541 = bfd_section_size (objfile->obfd, stabsect) / DBX_SYMBOL_SIZE (objfile);
3542 DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
3543 DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;
3544 DBX_STAB_SECTION (objfile) = stabsect;
3546 if (stabstrsize > bfd_get_size (sym_bfd))
3547 error ("ridiculous string table size: %d bytes", stabstrsize);
3548 DBX_STRINGTAB (objfile) = (char *)
3549 obstack_alloc (&objfile->psymbol_obstack, stabstrsize + 1);
3550 OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
3552 /* Now read in the string table in one big gulp. */
3554 val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
3556 perror_with_name (name);
3557 val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
3558 if (val != stabstrsize)
3559 perror_with_name (name);
3561 stabsread_new_init ();
3562 buildsym_new_init ();
3563 free_header_files ();
3564 init_header_files ();
3566 processing_acc_compilation = 1;
3569 symbuf_left = bfd_section_size (objfile->obfd, stabsect);
3570 stabs_data = symfile_relocate_debug_section (objfile->obfd, stabsect, NULL);
3572 back_to = make_cleanup (free_current_contents, (void *) &stabs_data);
3574 /* In an elf file, we've already installed the minimal symbols that came
3575 from the elf (non-stab) symbol table, so always act like an
3576 incremental load here. dbx_symfile_read should not generate any new
3577 minimal symbols, since we will have already read the ELF dynamic symbol
3578 table and normal symbol entries won't be in the ".stab" section; but in
3579 case it does, it will install them itself. */
3580 dbx_symfile_read (objfile, 0);
3583 do_cleanups (back_to);
3586 /* Scan and build partial symbols for a file with special sections for stabs
3587 and stabstrings. The file has already been processed to get its minimal
3588 symbols, and any other symbols that might be necessary to resolve GSYMs.
3590 This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
3593 OBJFILE is the object file we are reading symbols from.
3594 ADDR is the address relative to which the symbols are (e.g. the base address
3595 of the text segment).
3596 MAINLINE is true if we are reading the main symbol table (as opposed to a
3597 shared lib or dynamically loaded file).
3598 STAB_NAME is the name of the section that contains the stabs.
3599 STABSTR_NAME is the name of the section that contains the stab strings.
3601 This routine is mostly copied from dbx_symfile_init and dbx_symfile_read. */
3604 stabsect_build_psymtabs (struct objfile *objfile, int mainline, char *stab_name,
3605 char *stabstr_name, char *text_name)
3608 bfd *sym_bfd = objfile->obfd;
3609 char *name = bfd_get_filename (sym_bfd);
3611 asection *stabstrsect;
3612 asection *text_sect;
3614 stabsect = bfd_get_section_by_name (sym_bfd, stab_name);
3615 stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name);
3621 error ("stabsect_build_psymtabs: Found stabs (%s), but not string section (%s)",
3622 stab_name, stabstr_name);
3624 objfile->sym_stab_info = (struct dbx_symfile_info *)
3625 xmalloc (sizeof (struct dbx_symfile_info));
3626 memset (objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
3628 text_sect = bfd_get_section_by_name (sym_bfd, text_name);
3630 error ("Can't find %s section in symbol file", text_name);
3631 DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
3632 DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
3634 DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist);
3635 DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect)
3636 / DBX_SYMBOL_SIZE (objfile);
3637 DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect);
3638 DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; /* XXX - FIXME: POKING INSIDE BFD DATA STRUCTURES */
3640 if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
3641 error ("ridiculous string table size: %d bytes", DBX_STRINGTAB_SIZE (objfile));
3642 DBX_STRINGTAB (objfile) = (char *)
3643 obstack_alloc (&objfile->psymbol_obstack, DBX_STRINGTAB_SIZE (objfile) + 1);
3644 OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1);
3646 /* Now read in the string table in one big gulp. */
3648 val = bfd_get_section_contents (sym_bfd, /* bfd */
3649 stabstrsect, /* bfd section */
3650 DBX_STRINGTAB (objfile), /* input buffer */
3651 0, /* offset into section */
3652 DBX_STRINGTAB_SIZE (objfile)); /* amount to read */
3655 perror_with_name (name);
3657 stabsread_new_init ();
3658 buildsym_new_init ();
3659 free_header_files ();
3660 init_header_files ();
3662 /* Now, do an incremental load */
3664 processing_acc_compilation = 1;
3665 dbx_symfile_read (objfile, 0);
3668 static struct sym_fns aout_sym_fns =
3670 bfd_target_aout_flavour,
3671 dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
3672 dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
3673 dbx_symfile_read, /* sym_read: read a symbol file into symtab */
3674 dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
3675 default_symfile_offsets, /* sym_offsets: parse user's offsets to internal form */
3676 NULL /* next: pointer to next struct sym_fns */
3680 _initialize_dbxread (void)
3682 add_symtab_fns (&aout_sym_fns);