15796c8dcSSimon Schubert /* Read dbx symbol tables and convert to internal format, for GDB.
2*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert
45796c8dcSSimon Schubert This file is part of GDB.
55796c8dcSSimon Schubert
65796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
75796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
85796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
95796c8dcSSimon Schubert (at your option) any later version.
105796c8dcSSimon Schubert
115796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
125796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
135796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
145796c8dcSSimon Schubert GNU General Public License for more details.
155796c8dcSSimon Schubert
165796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
175796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
185796c8dcSSimon Schubert
195796c8dcSSimon Schubert /* This module provides three functions: dbx_symfile_init,
205796c8dcSSimon Schubert which initializes to read a symbol file; dbx_new_init, which
215796c8dcSSimon Schubert discards existing cached information when all symbols are being
225796c8dcSSimon Schubert discarded; and dbx_symfile_read, which reads a symbol table
235796c8dcSSimon Schubert from a file.
245796c8dcSSimon Schubert
255796c8dcSSimon Schubert dbx_symfile_read only does the minimum work necessary for letting the
265796c8dcSSimon Schubert user "name" things symbolically; it does not read the entire symtab.
275796c8dcSSimon Schubert Instead, it reads the external and static symbols and puts them in partial
285796c8dcSSimon Schubert symbol tables. When more extensive information is requested of a
295796c8dcSSimon Schubert file, the corresponding partial symbol table is mutated into a full
305796c8dcSSimon Schubert fledged symbol table by going back and reading the symbols
315796c8dcSSimon Schubert for real. dbx_psymtab_to_symtab() is the function that does this */
325796c8dcSSimon Schubert
335796c8dcSSimon Schubert #include "defs.h"
345796c8dcSSimon Schubert #include "gdb_string.h"
355796c8dcSSimon Schubert
365796c8dcSSimon Schubert #if defined(__CYGNUSCLIB__)
375796c8dcSSimon Schubert #include <sys/types.h>
385796c8dcSSimon Schubert #include <fcntl.h>
395796c8dcSSimon Schubert #endif
405796c8dcSSimon Schubert
415796c8dcSSimon Schubert #include "gdb_obstack.h"
425796c8dcSSimon Schubert #include "gdb_stat.h"
435796c8dcSSimon Schubert #include "symtab.h"
445796c8dcSSimon Schubert #include "breakpoint.h"
455796c8dcSSimon Schubert #include "target.h"
465796c8dcSSimon Schubert #include "gdbcore.h" /* for bfd stuff */
475796c8dcSSimon Schubert #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
48c50c785cSJohn Marino #include "filenames.h"
495796c8dcSSimon Schubert #include "objfiles.h"
505796c8dcSSimon Schubert #include "buildsym.h"
515796c8dcSSimon Schubert #include "stabsread.h"
525796c8dcSSimon Schubert #include "gdb-stabs.h"
535796c8dcSSimon Schubert #include "demangle.h"
545796c8dcSSimon Schubert #include "complaints.h"
555796c8dcSSimon Schubert #include "cp-abi.h"
565796c8dcSSimon Schubert #include "cp-support.h"
57cf7f2e2dSJohn Marino #include "psympriv.h"
58*ef5ccd6cSJohn Marino #include "block.h"
595796c8dcSSimon Schubert
605796c8dcSSimon Schubert #include "gdb_assert.h"
615796c8dcSSimon Schubert #include "gdb_string.h"
625796c8dcSSimon Schubert
635796c8dcSSimon Schubert #include "aout/aout64.h"
64c50c785cSJohn Marino #include "aout/stab_gnu.h" /* We always use GNU stabs, not
65c50c785cSJohn Marino native, now. */
665796c8dcSSimon Schubert
675796c8dcSSimon Schubert
68*ef5ccd6cSJohn Marino /* Key for dbx-associated data. */
69*ef5ccd6cSJohn Marino
70*ef5ccd6cSJohn Marino const struct objfile_data *dbx_objfile_data_key;
71*ef5ccd6cSJohn Marino
725796c8dcSSimon Schubert /* We put a pointer to this structure in the read_symtab_private field
735796c8dcSSimon Schubert of the psymtab. */
745796c8dcSSimon Schubert
755796c8dcSSimon Schubert struct symloc
765796c8dcSSimon Schubert {
775796c8dcSSimon Schubert /* Offset within the file symbol table of first local symbol for this
785796c8dcSSimon Schubert file. */
795796c8dcSSimon Schubert
805796c8dcSSimon Schubert int ldsymoff;
815796c8dcSSimon Schubert
825796c8dcSSimon Schubert /* Length (in bytes) of the section of the symbol table devoted to
835796c8dcSSimon Schubert this file's symbols (actually, the section bracketed may contain
845796c8dcSSimon Schubert more than just this file's symbols). If ldsymlen is 0, the only
855796c8dcSSimon Schubert reason for this thing's existence is the dependency list. Nothing
865796c8dcSSimon Schubert else will happen when it is read in. */
875796c8dcSSimon Schubert
885796c8dcSSimon Schubert int ldsymlen;
895796c8dcSSimon Schubert
905796c8dcSSimon Schubert /* The size of each symbol in the symbol file (in external form). */
915796c8dcSSimon Schubert
925796c8dcSSimon Schubert int symbol_size;
935796c8dcSSimon Schubert
945796c8dcSSimon Schubert /* Further information needed to locate the symbols if they are in
955796c8dcSSimon Schubert an ELF file. */
965796c8dcSSimon Schubert
975796c8dcSSimon Schubert int symbol_offset;
985796c8dcSSimon Schubert int string_offset;
995796c8dcSSimon Schubert int file_string_offset;
1005796c8dcSSimon Schubert };
1015796c8dcSSimon Schubert
1025796c8dcSSimon Schubert #define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff)
1035796c8dcSSimon Schubert #define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen)
1045796c8dcSSimon Schubert #define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private))
1055796c8dcSSimon Schubert #define SYMBOL_SIZE(p) (SYMLOC(p)->symbol_size)
1065796c8dcSSimon Schubert #define SYMBOL_OFFSET(p) (SYMLOC(p)->symbol_offset)
1075796c8dcSSimon Schubert #define STRING_OFFSET(p) (SYMLOC(p)->string_offset)
1085796c8dcSSimon Schubert #define FILE_STRING_OFFSET(p) (SYMLOC(p)->file_string_offset)
1095796c8dcSSimon Schubert
1105796c8dcSSimon Schubert
111a45ae5f8SJohn Marino /* The objfile we are currently reading. */
112a45ae5f8SJohn Marino
113a45ae5f8SJohn Marino static struct objfile *dbxread_objfile;
114a45ae5f8SJohn Marino
1155796c8dcSSimon Schubert /* Remember what we deduced to be the source language of this psymtab. */
1165796c8dcSSimon Schubert
1175796c8dcSSimon Schubert static enum language psymtab_language = language_unknown;
1185796c8dcSSimon Schubert
1195796c8dcSSimon Schubert /* The BFD for this file -- implicit parameter to next_symbol_text. */
1205796c8dcSSimon Schubert
1215796c8dcSSimon Schubert static bfd *symfile_bfd;
1225796c8dcSSimon Schubert
1235796c8dcSSimon Schubert /* The size of each symbol in the symbol file (in external form).
1245796c8dcSSimon Schubert This is set by dbx_symfile_read when building psymtabs, and by
1255796c8dcSSimon Schubert dbx_psymtab_to_symtab when building symtabs. */
1265796c8dcSSimon Schubert
1275796c8dcSSimon Schubert static unsigned symbol_size;
1285796c8dcSSimon Schubert
1295796c8dcSSimon Schubert /* This is the offset of the symbol table in the executable file. */
1305796c8dcSSimon Schubert
1315796c8dcSSimon Schubert static unsigned symbol_table_offset;
1325796c8dcSSimon Schubert
1335796c8dcSSimon Schubert /* This is the offset of the string table in the executable file. */
1345796c8dcSSimon Schubert
1355796c8dcSSimon Schubert static unsigned string_table_offset;
1365796c8dcSSimon Schubert
1375796c8dcSSimon Schubert /* For elf+stab executables, the n_strx field is not a simple index
1385796c8dcSSimon Schubert into the string table. Instead, each .o file has a base offset in
1395796c8dcSSimon Schubert the string table, and the associated symbols contain offsets from
1405796c8dcSSimon Schubert this base. The following two variables contain the base offset for
1415796c8dcSSimon Schubert the current and next .o files. */
1425796c8dcSSimon Schubert
1435796c8dcSSimon Schubert static unsigned int file_string_table_offset;
1445796c8dcSSimon Schubert static unsigned int next_file_string_table_offset;
1455796c8dcSSimon Schubert
1465796c8dcSSimon Schubert /* .o and NLM files contain unrelocated addresses which are based at
1475796c8dcSSimon Schubert 0. When non-zero, this flag disables some of the special cases for
1485796c8dcSSimon Schubert Solaris elf+stab text addresses at location 0. */
1495796c8dcSSimon Schubert
1505796c8dcSSimon Schubert static int symfile_relocatable = 0;
1515796c8dcSSimon Schubert
1525796c8dcSSimon Schubert /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are
1535796c8dcSSimon Schubert relative to the function start address. */
1545796c8dcSSimon Schubert
1555796c8dcSSimon Schubert static int block_address_function_relative = 0;
1565796c8dcSSimon Schubert
1575796c8dcSSimon Schubert /* The lowest text address we have yet encountered. This is needed
1585796c8dcSSimon Schubert because in an a.out file, there is no header field which tells us
1595796c8dcSSimon Schubert what address the program is actually going to be loaded at, so we
1605796c8dcSSimon Schubert need to make guesses based on the symbols (which *are* relocated to
1615796c8dcSSimon Schubert reflect the address it will be loaded at). */
1625796c8dcSSimon Schubert
1635796c8dcSSimon Schubert static CORE_ADDR lowest_text_address;
1645796c8dcSSimon Schubert
1655796c8dcSSimon Schubert /* Non-zero if there is any line number info in the objfile. Prevents
1665796c8dcSSimon Schubert end_psymtab from discarding an otherwise empty psymtab. */
1675796c8dcSSimon Schubert
1685796c8dcSSimon Schubert static int has_line_numbers;
1695796c8dcSSimon Schubert
1705796c8dcSSimon Schubert /* Complaints about the symbols we have encountered. */
1715796c8dcSSimon Schubert
1725796c8dcSSimon Schubert static void
unknown_symtype_complaint(const char * arg1)1735796c8dcSSimon Schubert unknown_symtype_complaint (const char *arg1)
1745796c8dcSSimon Schubert {
1755796c8dcSSimon Schubert complaint (&symfile_complaints, _("unknown symbol type %s"), arg1);
1765796c8dcSSimon Schubert }
1775796c8dcSSimon Schubert
1785796c8dcSSimon Schubert static void
lbrac_mismatch_complaint(int arg1)1795796c8dcSSimon Schubert lbrac_mismatch_complaint (int arg1)
1805796c8dcSSimon Schubert {
1815796c8dcSSimon Schubert complaint (&symfile_complaints,
1825796c8dcSSimon Schubert _("N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d"), arg1);
1835796c8dcSSimon Schubert }
1845796c8dcSSimon Schubert
1855796c8dcSSimon Schubert static void
repeated_header_complaint(const char * arg1,int arg2)1865796c8dcSSimon Schubert repeated_header_complaint (const char *arg1, int arg2)
1875796c8dcSSimon Schubert {
1885796c8dcSSimon Schubert complaint (&symfile_complaints,
189c50c785cSJohn Marino _("\"repeated\" header file %s not "
190c50c785cSJohn Marino "previously seen, at symtab pos %d"),
1915796c8dcSSimon Schubert arg1, arg2);
1925796c8dcSSimon Schubert }
1935796c8dcSSimon Schubert
1945796c8dcSSimon Schubert /* find_text_range --- find start and end of loadable code sections
1955796c8dcSSimon Schubert
1965796c8dcSSimon Schubert The find_text_range function finds the shortest address range that
1975796c8dcSSimon Schubert encloses all sections containing executable code, and stores it in
1985796c8dcSSimon Schubert objfile's text_addr and text_size members.
1995796c8dcSSimon Schubert
2005796c8dcSSimon Schubert dbx_symfile_read will use this to finish off the partial symbol
2015796c8dcSSimon Schubert table, in some cases. */
2025796c8dcSSimon Schubert
2035796c8dcSSimon Schubert static void
find_text_range(bfd * sym_bfd,struct objfile * objfile)2045796c8dcSSimon Schubert find_text_range (bfd * sym_bfd, struct objfile *objfile)
2055796c8dcSSimon Schubert {
2065796c8dcSSimon Schubert asection *sec;
2075796c8dcSSimon Schubert int found_any = 0;
2085796c8dcSSimon Schubert CORE_ADDR start = 0;
2095796c8dcSSimon Schubert CORE_ADDR end = 0;
2105796c8dcSSimon Schubert
2115796c8dcSSimon Schubert for (sec = sym_bfd->sections; sec; sec = sec->next)
2125796c8dcSSimon Schubert if (bfd_get_section_flags (sym_bfd, sec) & SEC_CODE)
2135796c8dcSSimon Schubert {
2145796c8dcSSimon Schubert CORE_ADDR sec_start = bfd_section_vma (sym_bfd, sec);
2155796c8dcSSimon Schubert CORE_ADDR sec_end = sec_start + bfd_section_size (sym_bfd, sec);
2165796c8dcSSimon Schubert
2175796c8dcSSimon Schubert if (found_any)
2185796c8dcSSimon Schubert {
2195796c8dcSSimon Schubert if (sec_start < start)
2205796c8dcSSimon Schubert start = sec_start;
2215796c8dcSSimon Schubert if (sec_end > end)
2225796c8dcSSimon Schubert end = sec_end;
2235796c8dcSSimon Schubert }
2245796c8dcSSimon Schubert else
2255796c8dcSSimon Schubert {
2265796c8dcSSimon Schubert start = sec_start;
2275796c8dcSSimon Schubert end = sec_end;
2285796c8dcSSimon Schubert }
2295796c8dcSSimon Schubert
2305796c8dcSSimon Schubert found_any = 1;
2315796c8dcSSimon Schubert }
2325796c8dcSSimon Schubert
2335796c8dcSSimon Schubert if (!found_any)
2345796c8dcSSimon Schubert error (_("Can't find any code sections in symbol file"));
2355796c8dcSSimon Schubert
2365796c8dcSSimon Schubert DBX_TEXT_ADDR (objfile) = start;
2375796c8dcSSimon Schubert DBX_TEXT_SIZE (objfile) = end - start;
2385796c8dcSSimon Schubert }
2395796c8dcSSimon Schubert
2405796c8dcSSimon Schubert
2415796c8dcSSimon Schubert
2425796c8dcSSimon Schubert /* During initial symbol readin, we need to have a structure to keep
2435796c8dcSSimon Schubert track of which psymtabs have which bincls in them. This structure
2445796c8dcSSimon Schubert is used during readin to setup the list of dependencies within each
2455796c8dcSSimon Schubert partial symbol table. */
2465796c8dcSSimon Schubert
2475796c8dcSSimon Schubert struct header_file_location
2485796c8dcSSimon Schubert {
2495796c8dcSSimon Schubert char *name; /* Name of header file */
2505796c8dcSSimon Schubert int instance; /* See above */
2515796c8dcSSimon Schubert struct partial_symtab *pst; /* Partial symtab that has the
252c50c785cSJohn Marino BINCL/EINCL defs for this file. */
2535796c8dcSSimon Schubert };
2545796c8dcSSimon Schubert
255c50c785cSJohn Marino /* The actual list and controling variables. */
2565796c8dcSSimon Schubert static struct header_file_location *bincl_list, *next_bincl;
2575796c8dcSSimon Schubert static int bincls_allocated;
2585796c8dcSSimon Schubert
259c50c785cSJohn Marino /* Local function prototypes. */
2605796c8dcSSimon Schubert
2615796c8dcSSimon Schubert extern void _initialize_dbxread (void);
2625796c8dcSSimon Schubert
263*ef5ccd6cSJohn Marino static void read_ofile_symtab (struct objfile *, struct partial_symtab *);
2645796c8dcSSimon Schubert
265*ef5ccd6cSJohn Marino static void dbx_read_symtab (struct partial_symtab *self,
266*ef5ccd6cSJohn Marino struct objfile *objfile);
2675796c8dcSSimon Schubert
268*ef5ccd6cSJohn Marino static void dbx_psymtab_to_symtab_1 (struct objfile *, struct partial_symtab *);
2695796c8dcSSimon Schubert
2705796c8dcSSimon Schubert static void read_dbx_dynamic_symtab (struct objfile *objfile);
2715796c8dcSSimon Schubert
2725796c8dcSSimon Schubert static void read_dbx_symtab (struct objfile *);
2735796c8dcSSimon Schubert
2745796c8dcSSimon Schubert static void free_bincl_list (struct objfile *);
2755796c8dcSSimon Schubert
2765796c8dcSSimon Schubert static struct partial_symtab *find_corresponding_bincl_psymtab (char *, int);
2775796c8dcSSimon Schubert
2785796c8dcSSimon Schubert static void add_bincl_to_list (struct partial_symtab *, char *, int);
2795796c8dcSSimon Schubert
2805796c8dcSSimon Schubert static void init_bincl_list (int, struct objfile *);
2815796c8dcSSimon Schubert
2825796c8dcSSimon Schubert static char *dbx_next_symbol_text (struct objfile *);
2835796c8dcSSimon Schubert
2845796c8dcSSimon Schubert static void fill_symbuf (bfd *);
2855796c8dcSSimon Schubert
2865796c8dcSSimon Schubert static void dbx_symfile_init (struct objfile *);
2875796c8dcSSimon Schubert
2885796c8dcSSimon Schubert static void dbx_new_init (struct objfile *);
2895796c8dcSSimon Schubert
2905796c8dcSSimon Schubert static void dbx_symfile_read (struct objfile *, int);
2915796c8dcSSimon Schubert
2925796c8dcSSimon Schubert static void dbx_symfile_finish (struct objfile *);
2935796c8dcSSimon Schubert
2945796c8dcSSimon Schubert static void record_minimal_symbol (char *, CORE_ADDR, int, struct objfile *);
2955796c8dcSSimon Schubert
2965796c8dcSSimon Schubert static void add_new_header_file (char *, int);
2975796c8dcSSimon Schubert
2985796c8dcSSimon Schubert static void add_old_header_file (char *, int);
2995796c8dcSSimon Schubert
3005796c8dcSSimon Schubert static void add_this_object_header_file (int);
3015796c8dcSSimon Schubert
3025796c8dcSSimon Schubert static struct partial_symtab *start_psymtab (struct objfile *, char *,
3035796c8dcSSimon Schubert CORE_ADDR, int,
3045796c8dcSSimon Schubert struct partial_symbol **,
3055796c8dcSSimon Schubert struct partial_symbol **);
3065796c8dcSSimon Schubert
307c50c785cSJohn Marino /* Free up old header file tables. */
3085796c8dcSSimon Schubert
3095796c8dcSSimon Schubert void
free_header_files(void)3105796c8dcSSimon Schubert free_header_files (void)
3115796c8dcSSimon Schubert {
3125796c8dcSSimon Schubert if (this_object_header_files)
3135796c8dcSSimon Schubert {
3145796c8dcSSimon Schubert xfree (this_object_header_files);
3155796c8dcSSimon Schubert this_object_header_files = NULL;
3165796c8dcSSimon Schubert }
3175796c8dcSSimon Schubert n_allocated_this_object_header_files = 0;
3185796c8dcSSimon Schubert }
3195796c8dcSSimon Schubert
320c50c785cSJohn Marino /* Allocate new header file tables. */
3215796c8dcSSimon Schubert
3225796c8dcSSimon Schubert void
init_header_files(void)3235796c8dcSSimon Schubert init_header_files (void)
3245796c8dcSSimon Schubert {
3255796c8dcSSimon Schubert n_allocated_this_object_header_files = 10;
3265796c8dcSSimon Schubert this_object_header_files = (int *) xmalloc (10 * sizeof (int));
3275796c8dcSSimon Schubert }
3285796c8dcSSimon Schubert
3295796c8dcSSimon Schubert /* Add header file number I for this object file
3305796c8dcSSimon Schubert at the next successive FILENUM. */
3315796c8dcSSimon Schubert
3325796c8dcSSimon Schubert static void
add_this_object_header_file(int i)3335796c8dcSSimon Schubert add_this_object_header_file (int i)
3345796c8dcSSimon Schubert {
3355796c8dcSSimon Schubert if (n_this_object_header_files == n_allocated_this_object_header_files)
3365796c8dcSSimon Schubert {
3375796c8dcSSimon Schubert n_allocated_this_object_header_files *= 2;
3385796c8dcSSimon Schubert this_object_header_files
3395796c8dcSSimon Schubert = (int *) xrealloc ((char *) this_object_header_files,
3405796c8dcSSimon Schubert n_allocated_this_object_header_files * sizeof (int));
3415796c8dcSSimon Schubert }
3425796c8dcSSimon Schubert
3435796c8dcSSimon Schubert this_object_header_files[n_this_object_header_files++] = i;
3445796c8dcSSimon Schubert }
3455796c8dcSSimon Schubert
3465796c8dcSSimon Schubert /* Add to this file an "old" header file, one already seen in
3475796c8dcSSimon Schubert a previous object file. NAME is the header file's name.
3485796c8dcSSimon Schubert INSTANCE is its instance code, to select among multiple
3495796c8dcSSimon Schubert symbol tables for the same header file. */
3505796c8dcSSimon Schubert
3515796c8dcSSimon Schubert static void
add_old_header_file(char * name,int instance)3525796c8dcSSimon Schubert add_old_header_file (char *name, int instance)
3535796c8dcSSimon Schubert {
354a45ae5f8SJohn Marino struct header_file *p = HEADER_FILES (dbxread_objfile);
3555796c8dcSSimon Schubert int i;
3565796c8dcSSimon Schubert
357a45ae5f8SJohn Marino for (i = 0; i < N_HEADER_FILES (dbxread_objfile); i++)
358c50c785cSJohn Marino if (filename_cmp (p[i].name, name) == 0 && instance == p[i].instance)
3595796c8dcSSimon Schubert {
3605796c8dcSSimon Schubert add_this_object_header_file (i);
3615796c8dcSSimon Schubert return;
3625796c8dcSSimon Schubert }
3635796c8dcSSimon Schubert repeated_header_complaint (name, symnum);
3645796c8dcSSimon Schubert }
3655796c8dcSSimon Schubert
3665796c8dcSSimon Schubert /* Add to this file a "new" header file: definitions for its types follow.
3675796c8dcSSimon Schubert NAME is the header file's name.
3685796c8dcSSimon Schubert Most often this happens only once for each distinct header file,
3695796c8dcSSimon Schubert but not necessarily. If it happens more than once, INSTANCE has
3705796c8dcSSimon Schubert a different value each time, and references to the header file
3715796c8dcSSimon Schubert use INSTANCE values to select among them.
3725796c8dcSSimon Schubert
3735796c8dcSSimon Schubert dbx output contains "begin" and "end" markers for each new header file,
3745796c8dcSSimon Schubert but at this level we just need to know which files there have been;
3755796c8dcSSimon Schubert so we record the file when its "begin" is seen and ignore the "end". */
3765796c8dcSSimon Schubert
3775796c8dcSSimon Schubert static void
add_new_header_file(char * name,int instance)3785796c8dcSSimon Schubert add_new_header_file (char *name, int instance)
3795796c8dcSSimon Schubert {
3805796c8dcSSimon Schubert int i;
3815796c8dcSSimon Schubert struct header_file *hfile;
3825796c8dcSSimon Schubert
3835796c8dcSSimon Schubert /* Make sure there is room for one more header file. */
3845796c8dcSSimon Schubert
385a45ae5f8SJohn Marino i = N_ALLOCATED_HEADER_FILES (dbxread_objfile);
3865796c8dcSSimon Schubert
387a45ae5f8SJohn Marino if (N_HEADER_FILES (dbxread_objfile) == i)
3885796c8dcSSimon Schubert {
3895796c8dcSSimon Schubert if (i == 0)
3905796c8dcSSimon Schubert {
391a45ae5f8SJohn Marino N_ALLOCATED_HEADER_FILES (dbxread_objfile) = 10;
392a45ae5f8SJohn Marino HEADER_FILES (dbxread_objfile) = (struct header_file *)
3935796c8dcSSimon Schubert xmalloc (10 * sizeof (struct header_file));
3945796c8dcSSimon Schubert }
3955796c8dcSSimon Schubert else
3965796c8dcSSimon Schubert {
3975796c8dcSSimon Schubert i *= 2;
398a45ae5f8SJohn Marino N_ALLOCATED_HEADER_FILES (dbxread_objfile) = i;
399a45ae5f8SJohn Marino HEADER_FILES (dbxread_objfile) = (struct header_file *)
400a45ae5f8SJohn Marino xrealloc ((char *) HEADER_FILES (dbxread_objfile),
4015796c8dcSSimon Schubert (i * sizeof (struct header_file)));
4025796c8dcSSimon Schubert }
4035796c8dcSSimon Schubert }
4045796c8dcSSimon Schubert
4055796c8dcSSimon Schubert /* Create an entry for this header file. */
4065796c8dcSSimon Schubert
407a45ae5f8SJohn Marino i = N_HEADER_FILES (dbxread_objfile)++;
408a45ae5f8SJohn Marino hfile = HEADER_FILES (dbxread_objfile) + i;
4095796c8dcSSimon Schubert hfile->name = xstrdup (name);
4105796c8dcSSimon Schubert hfile->instance = instance;
4115796c8dcSSimon Schubert hfile->length = 10;
4125796c8dcSSimon Schubert hfile->vector
4135796c8dcSSimon Schubert = (struct type **) xmalloc (10 * sizeof (struct type *));
4145796c8dcSSimon Schubert memset (hfile->vector, 0, 10 * sizeof (struct type *));
4155796c8dcSSimon Schubert
4165796c8dcSSimon Schubert add_this_object_header_file (i);
4175796c8dcSSimon Schubert }
4185796c8dcSSimon Schubert
4195796c8dcSSimon Schubert #if 0
4205796c8dcSSimon Schubert static struct type **
4215796c8dcSSimon Schubert explicit_lookup_type (int real_filenum, int index)
4225796c8dcSSimon Schubert {
423a45ae5f8SJohn Marino struct header_file *f = &HEADER_FILES (dbxread_objfile)[real_filenum];
4245796c8dcSSimon Schubert
4255796c8dcSSimon Schubert if (index >= f->length)
4265796c8dcSSimon Schubert {
4275796c8dcSSimon Schubert f->length *= 2;
4285796c8dcSSimon Schubert f->vector = (struct type **)
4295796c8dcSSimon Schubert xrealloc (f->vector, f->length * sizeof (struct type *));
4305796c8dcSSimon Schubert memset (&f->vector[f->length / 2],
4315796c8dcSSimon Schubert '\0', f->length * sizeof (struct type *) / 2);
4325796c8dcSSimon Schubert }
4335796c8dcSSimon Schubert return &f->vector[index];
4345796c8dcSSimon Schubert }
4355796c8dcSSimon Schubert #endif
4365796c8dcSSimon Schubert
4375796c8dcSSimon Schubert static void
record_minimal_symbol(char * name,CORE_ADDR address,int type,struct objfile * objfile)4385796c8dcSSimon Schubert record_minimal_symbol (char *name, CORE_ADDR address, int type,
4395796c8dcSSimon Schubert struct objfile *objfile)
4405796c8dcSSimon Schubert {
4415796c8dcSSimon Schubert enum minimal_symbol_type ms_type;
4425796c8dcSSimon Schubert int section;
4435796c8dcSSimon Schubert asection *bfd_section;
4445796c8dcSSimon Schubert
4455796c8dcSSimon Schubert switch (type)
4465796c8dcSSimon Schubert {
4475796c8dcSSimon Schubert case N_TEXT | N_EXT:
4485796c8dcSSimon Schubert ms_type = mst_text;
4495796c8dcSSimon Schubert section = SECT_OFF_TEXT (objfile);
4505796c8dcSSimon Schubert bfd_section = DBX_TEXT_SECTION (objfile);
4515796c8dcSSimon Schubert break;
4525796c8dcSSimon Schubert case N_DATA | N_EXT:
4535796c8dcSSimon Schubert ms_type = mst_data;
4545796c8dcSSimon Schubert section = SECT_OFF_DATA (objfile);
4555796c8dcSSimon Schubert bfd_section = DBX_DATA_SECTION (objfile);
4565796c8dcSSimon Schubert break;
4575796c8dcSSimon Schubert case N_BSS | N_EXT:
4585796c8dcSSimon Schubert ms_type = mst_bss;
4595796c8dcSSimon Schubert section = SECT_OFF_BSS (objfile);
4605796c8dcSSimon Schubert bfd_section = DBX_BSS_SECTION (objfile);
4615796c8dcSSimon Schubert break;
4625796c8dcSSimon Schubert case N_ABS | N_EXT:
4635796c8dcSSimon Schubert ms_type = mst_abs;
4645796c8dcSSimon Schubert section = -1;
4655796c8dcSSimon Schubert bfd_section = NULL;
4665796c8dcSSimon Schubert break;
4675796c8dcSSimon Schubert #ifdef N_SETV
4685796c8dcSSimon Schubert case N_SETV | N_EXT:
4695796c8dcSSimon Schubert ms_type = mst_data;
4705796c8dcSSimon Schubert section = SECT_OFF_DATA (objfile);
4715796c8dcSSimon Schubert bfd_section = DBX_DATA_SECTION (objfile);
4725796c8dcSSimon Schubert break;
4735796c8dcSSimon Schubert case N_SETV:
4745796c8dcSSimon Schubert /* I don't think this type actually exists; since a N_SETV is the result
4755796c8dcSSimon Schubert of going over many .o files, it doesn't make sense to have one
4765796c8dcSSimon Schubert file local. */
4775796c8dcSSimon Schubert ms_type = mst_file_data;
4785796c8dcSSimon Schubert section = SECT_OFF_DATA (objfile);
4795796c8dcSSimon Schubert bfd_section = DBX_DATA_SECTION (objfile);
4805796c8dcSSimon Schubert break;
4815796c8dcSSimon Schubert #endif
4825796c8dcSSimon Schubert case N_TEXT:
4835796c8dcSSimon Schubert case N_NBTEXT:
4845796c8dcSSimon Schubert case N_FN:
4855796c8dcSSimon Schubert case N_FN_SEQ:
4865796c8dcSSimon Schubert ms_type = mst_file_text;
4875796c8dcSSimon Schubert section = SECT_OFF_TEXT (objfile);
4885796c8dcSSimon Schubert bfd_section = DBX_TEXT_SECTION (objfile);
4895796c8dcSSimon Schubert break;
4905796c8dcSSimon Schubert case N_DATA:
4915796c8dcSSimon Schubert ms_type = mst_file_data;
4925796c8dcSSimon Schubert
4935796c8dcSSimon Schubert /* Check for __DYNAMIC, which is used by Sun shared libraries.
4945796c8dcSSimon Schubert Record it as global even if it's local, not global, so
4955796c8dcSSimon Schubert lookup_minimal_symbol can find it. We don't check symbol_leading_char
4965796c8dcSSimon Schubert because for SunOS4 it always is '_'. */
4975796c8dcSSimon Schubert if (name[8] == 'C' && strcmp ("__DYNAMIC", name) == 0)
4985796c8dcSSimon Schubert ms_type = mst_data;
4995796c8dcSSimon Schubert
5005796c8dcSSimon Schubert /* Same with virtual function tables, both global and static. */
5015796c8dcSSimon Schubert {
5025796c8dcSSimon Schubert char *tempstring = name;
503cf7f2e2dSJohn Marino
5045796c8dcSSimon Schubert if (tempstring[0] == bfd_get_symbol_leading_char (objfile->obfd))
5055796c8dcSSimon Schubert ++tempstring;
5065796c8dcSSimon Schubert if (is_vtable_name (tempstring))
5075796c8dcSSimon Schubert ms_type = mst_data;
5085796c8dcSSimon Schubert }
5095796c8dcSSimon Schubert section = SECT_OFF_DATA (objfile);
5105796c8dcSSimon Schubert bfd_section = DBX_DATA_SECTION (objfile);
5115796c8dcSSimon Schubert break;
5125796c8dcSSimon Schubert case N_BSS:
5135796c8dcSSimon Schubert ms_type = mst_file_bss;
5145796c8dcSSimon Schubert section = SECT_OFF_BSS (objfile);
5155796c8dcSSimon Schubert bfd_section = DBX_BSS_SECTION (objfile);
5165796c8dcSSimon Schubert break;
5175796c8dcSSimon Schubert default:
5185796c8dcSSimon Schubert ms_type = mst_unknown;
5195796c8dcSSimon Schubert section = -1;
5205796c8dcSSimon Schubert bfd_section = NULL;
5215796c8dcSSimon Schubert break;
5225796c8dcSSimon Schubert }
5235796c8dcSSimon Schubert
5245796c8dcSSimon Schubert if ((ms_type == mst_file_text || ms_type == mst_text)
5255796c8dcSSimon Schubert && address < lowest_text_address)
5265796c8dcSSimon Schubert lowest_text_address = address;
5275796c8dcSSimon Schubert
5285796c8dcSSimon Schubert prim_record_minimal_symbol_and_info
5295796c8dcSSimon Schubert (name, address, ms_type, section, bfd_section, objfile);
5305796c8dcSSimon Schubert }
5315796c8dcSSimon Schubert
5325796c8dcSSimon Schubert /* Scan and build partial symbols for a symbol file.
5335796c8dcSSimon Schubert We have been initialized by a call to dbx_symfile_init, which
5345796c8dcSSimon Schubert put all the relevant info into a "struct dbx_symfile_info",
535cf7f2e2dSJohn Marino hung off the objfile structure. */
5365796c8dcSSimon Schubert
5375796c8dcSSimon Schubert static void
dbx_symfile_read(struct objfile * objfile,int symfile_flags)538cf7f2e2dSJohn Marino dbx_symfile_read (struct objfile *objfile, int symfile_flags)
5395796c8dcSSimon Schubert {
5405796c8dcSSimon Schubert bfd *sym_bfd;
5415796c8dcSSimon Schubert int val;
5425796c8dcSSimon Schubert struct cleanup *back_to;
5435796c8dcSSimon Schubert
5445796c8dcSSimon Schubert sym_bfd = objfile->obfd;
5455796c8dcSSimon Schubert
5465796c8dcSSimon Schubert /* .o and .nlm files are relocatables with text, data and bss segs based at
5475796c8dcSSimon Schubert 0. This flag disables special (Solaris stabs-in-elf only) fixups for
5485796c8dcSSimon Schubert symbols with a value of 0. */
5495796c8dcSSimon Schubert
5505796c8dcSSimon Schubert symfile_relocatable = bfd_get_file_flags (sym_bfd) & HAS_RELOC;
5515796c8dcSSimon Schubert
5525796c8dcSSimon Schubert /* This is true for Solaris (and all other systems which put stabs
5535796c8dcSSimon Schubert in sections, hopefully, since it would be silly to do things
5545796c8dcSSimon Schubert differently from Solaris), and false for SunOS4 and other a.out
5555796c8dcSSimon Schubert file formats. */
5565796c8dcSSimon Schubert block_address_function_relative =
5575796c8dcSSimon Schubert ((0 == strncmp (bfd_get_target (sym_bfd), "elf", 3))
5585796c8dcSSimon Schubert || (0 == strncmp (bfd_get_target (sym_bfd), "som", 3))
5595796c8dcSSimon Schubert || (0 == strncmp (bfd_get_target (sym_bfd), "coff", 4))
5605796c8dcSSimon Schubert || (0 == strncmp (bfd_get_target (sym_bfd), "pe", 2))
5615796c8dcSSimon Schubert || (0 == strncmp (bfd_get_target (sym_bfd), "epoc-pe", 7))
5625796c8dcSSimon Schubert || (0 == strncmp (bfd_get_target (sym_bfd), "nlm", 3)));
5635796c8dcSSimon Schubert
5645796c8dcSSimon Schubert val = bfd_seek (sym_bfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
5655796c8dcSSimon Schubert if (val < 0)
5665796c8dcSSimon Schubert perror_with_name (objfile->name);
5675796c8dcSSimon Schubert
568cf7f2e2dSJohn Marino /* Size the symbol table. */
569cf7f2e2dSJohn Marino if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0)
5705796c8dcSSimon Schubert init_psymbol_list (objfile, DBX_SYMCOUNT (objfile));
5715796c8dcSSimon Schubert
5725796c8dcSSimon Schubert symbol_size = DBX_SYMBOL_SIZE (objfile);
5735796c8dcSSimon Schubert symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);
5745796c8dcSSimon Schubert
5755796c8dcSSimon Schubert free_pending_blocks ();
5765796c8dcSSimon Schubert back_to = make_cleanup (really_free_pendings, 0);
5775796c8dcSSimon Schubert
5785796c8dcSSimon Schubert init_minimal_symbol_collection ();
5795796c8dcSSimon Schubert make_cleanup_discard_minimal_symbols ();
5805796c8dcSSimon Schubert
5815796c8dcSSimon Schubert /* Read stabs data from executable file and define symbols. */
5825796c8dcSSimon Schubert
5835796c8dcSSimon Schubert read_dbx_symtab (objfile);
5845796c8dcSSimon Schubert
5855796c8dcSSimon Schubert /* Add the dynamic symbols. */
5865796c8dcSSimon Schubert
5875796c8dcSSimon Schubert read_dbx_dynamic_symtab (objfile);
5885796c8dcSSimon Schubert
5895796c8dcSSimon Schubert /* Install any minimal symbols that have been collected as the current
5905796c8dcSSimon Schubert minimal symbols for this objfile. */
5915796c8dcSSimon Schubert
5925796c8dcSSimon Schubert install_minimal_symbols (objfile);
5935796c8dcSSimon Schubert
5945796c8dcSSimon Schubert do_cleanups (back_to);
5955796c8dcSSimon Schubert }
5965796c8dcSSimon Schubert
5975796c8dcSSimon Schubert /* Initialize anything that needs initializing when a completely new
5985796c8dcSSimon Schubert symbol file is specified (not just adding some symbols from another
5995796c8dcSSimon Schubert file, e.g. a shared library). */
6005796c8dcSSimon Schubert
6015796c8dcSSimon Schubert static void
dbx_new_init(struct objfile * ignore)6025796c8dcSSimon Schubert dbx_new_init (struct objfile *ignore)
6035796c8dcSSimon Schubert {
6045796c8dcSSimon Schubert stabsread_new_init ();
6055796c8dcSSimon Schubert buildsym_new_init ();
6065796c8dcSSimon Schubert init_header_files ();
6075796c8dcSSimon Schubert }
6085796c8dcSSimon Schubert
6095796c8dcSSimon Schubert
6105796c8dcSSimon Schubert /* dbx_symfile_init ()
6115796c8dcSSimon Schubert is the dbx-specific initialization routine for reading symbols.
6125796c8dcSSimon Schubert It is passed a struct objfile which contains, among other things,
6135796c8dcSSimon Schubert the BFD for the file whose symbols are being read, and a slot for a pointer
6145796c8dcSSimon Schubert to "private data" which we fill with goodies.
6155796c8dcSSimon Schubert
6165796c8dcSSimon Schubert We read the string table into malloc'd space and stash a pointer to it.
6175796c8dcSSimon Schubert
6185796c8dcSSimon Schubert Since BFD doesn't know how to read debug symbols in a format-independent
6195796c8dcSSimon Schubert way (and may never do so...), we have to do it ourselves. We will never
6205796c8dcSSimon Schubert be called unless this is an a.out (or very similar) file.
6215796c8dcSSimon Schubert FIXME, there should be a cleaner peephole into the BFD environment here. */
6225796c8dcSSimon Schubert
6235796c8dcSSimon Schubert #define DBX_STRINGTAB_SIZE_SIZE sizeof(long) /* FIXME */
6245796c8dcSSimon Schubert
6255796c8dcSSimon Schubert static void
dbx_symfile_init(struct objfile * objfile)6265796c8dcSSimon Schubert dbx_symfile_init (struct objfile *objfile)
6275796c8dcSSimon Schubert {
6285796c8dcSSimon Schubert int val;
6295796c8dcSSimon Schubert bfd *sym_bfd = objfile->obfd;
6305796c8dcSSimon Schubert char *name = bfd_get_filename (sym_bfd);
6315796c8dcSSimon Schubert asection *text_sect;
6325796c8dcSSimon Schubert unsigned char size_temp[DBX_STRINGTAB_SIZE_SIZE];
633*ef5ccd6cSJohn Marino struct dbx_symfile_info *dbx;
6345796c8dcSSimon Schubert
635c50c785cSJohn Marino /* Allocate struct to keep track of the symfile. */
636*ef5ccd6cSJohn Marino dbx = XCNEW (struct dbx_symfile_info);
637*ef5ccd6cSJohn Marino set_objfile_data (objfile, dbx_objfile_data_key, dbx);
6385796c8dcSSimon Schubert
6395796c8dcSSimon Schubert DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
6405796c8dcSSimon Schubert DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data");
6415796c8dcSSimon Schubert DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss");
6425796c8dcSSimon Schubert
643c50c785cSJohn Marino /* FIXME POKING INSIDE BFD DATA STRUCTURES. */
6445796c8dcSSimon Schubert #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
6455796c8dcSSimon Schubert #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
6465796c8dcSSimon Schubert
647c50c785cSJohn Marino /* FIXME POKING INSIDE BFD DATA STRUCTURES. */
6485796c8dcSSimon Schubert
6495796c8dcSSimon Schubert DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;
6505796c8dcSSimon Schubert
6515796c8dcSSimon Schubert text_sect = bfd_get_section_by_name (sym_bfd, ".text");
6525796c8dcSSimon Schubert if (!text_sect)
6535796c8dcSSimon Schubert error (_("Can't find .text section in symbol file"));
6545796c8dcSSimon Schubert DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
6555796c8dcSSimon Schubert DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
6565796c8dcSSimon Schubert
6575796c8dcSSimon Schubert DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);
6585796c8dcSSimon Schubert DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
6595796c8dcSSimon Schubert DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
6605796c8dcSSimon Schubert
6615796c8dcSSimon Schubert /* Read the string table and stash it away in the objfile_obstack.
6625796c8dcSSimon Schubert When we blow away the objfile the string table goes away as well.
6635796c8dcSSimon Schubert Note that gdb used to use the results of attempting to malloc the
6645796c8dcSSimon Schubert string table, based on the size it read, as a form of sanity check
6655796c8dcSSimon Schubert for botched byte swapping, on the theory that a byte swapped string
6665796c8dcSSimon Schubert table size would be so totally bogus that the malloc would fail. Now
6675796c8dcSSimon Schubert that we put in on the objfile_obstack, we can't do this since gdb gets
6685796c8dcSSimon Schubert a fatal error (out of virtual memory) if the size is bogus. We can
6695796c8dcSSimon Schubert however at least check to see if the size is less than the size of
6705796c8dcSSimon Schubert the size field itself, or larger than the size of the entire file.
6715796c8dcSSimon Schubert Note that all valid string tables have a size greater than zero, since
6725796c8dcSSimon Schubert the bytes used to hold the size are included in the count. */
6735796c8dcSSimon Schubert
6745796c8dcSSimon Schubert if (STRING_TABLE_OFFSET == 0)
6755796c8dcSSimon Schubert {
6765796c8dcSSimon Schubert /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
6775796c8dcSSimon Schubert will never be zero, even when there is no string table. This
6785796c8dcSSimon Schubert would appear to be a bug in bfd. */
6795796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile) = 0;
6805796c8dcSSimon Schubert DBX_STRINGTAB (objfile) = NULL;
6815796c8dcSSimon Schubert }
6825796c8dcSSimon Schubert else
6835796c8dcSSimon Schubert {
6845796c8dcSSimon Schubert val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
6855796c8dcSSimon Schubert if (val < 0)
6865796c8dcSSimon Schubert perror_with_name (name);
6875796c8dcSSimon Schubert
6885796c8dcSSimon Schubert memset (size_temp, 0, sizeof (size_temp));
6895796c8dcSSimon Schubert val = bfd_bread (size_temp, sizeof (size_temp), sym_bfd);
6905796c8dcSSimon Schubert if (val < 0)
6915796c8dcSSimon Schubert {
6925796c8dcSSimon Schubert perror_with_name (name);
6935796c8dcSSimon Schubert }
6945796c8dcSSimon Schubert else if (val == 0)
6955796c8dcSSimon Schubert {
6965796c8dcSSimon Schubert /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
6975796c8dcSSimon Schubert EOF if there is no string table, and attempting to read the size
6985796c8dcSSimon Schubert from EOF will read zero bytes. */
6995796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile) = 0;
7005796c8dcSSimon Schubert DBX_STRINGTAB (objfile) = NULL;
7015796c8dcSSimon Schubert }
7025796c8dcSSimon Schubert else
7035796c8dcSSimon Schubert {
7045796c8dcSSimon Schubert /* Read some data that would appear to be the string table size.
7055796c8dcSSimon Schubert If there really is a string table, then it is probably the right
7065796c8dcSSimon Schubert size. Byteswap if necessary and validate the size. Note that
7075796c8dcSSimon Schubert the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
7085796c8dcSSimon Schubert random data that happened to be at STRING_TABLE_OFFSET, because
7095796c8dcSSimon Schubert bfd can't tell us there is no string table, the sanity checks may
7105796c8dcSSimon Schubert or may not catch this. */
7115796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
7125796c8dcSSimon Schubert
7135796c8dcSSimon Schubert if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
7145796c8dcSSimon Schubert || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
7155796c8dcSSimon Schubert error (_("ridiculous string table size (%d bytes)."),
7165796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile));
7175796c8dcSSimon Schubert
7185796c8dcSSimon Schubert DBX_STRINGTAB (objfile) =
7195796c8dcSSimon Schubert (char *) obstack_alloc (&objfile->objfile_obstack,
7205796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile));
7215796c8dcSSimon Schubert OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile));
7225796c8dcSSimon Schubert
7235796c8dcSSimon Schubert /* Now read in the string table in one big gulp. */
7245796c8dcSSimon Schubert
7255796c8dcSSimon Schubert val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
7265796c8dcSSimon Schubert if (val < 0)
7275796c8dcSSimon Schubert perror_with_name (name);
7285796c8dcSSimon Schubert val = bfd_bread (DBX_STRINGTAB (objfile),
7295796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile),
7305796c8dcSSimon Schubert sym_bfd);
7315796c8dcSSimon Schubert if (val != DBX_STRINGTAB_SIZE (objfile))
7325796c8dcSSimon Schubert perror_with_name (name);
7335796c8dcSSimon Schubert }
7345796c8dcSSimon Schubert }
7355796c8dcSSimon Schubert }
7365796c8dcSSimon Schubert
7375796c8dcSSimon Schubert /* Perform any local cleanups required when we are done with a particular
7385796c8dcSSimon Schubert objfile. I.E, we are in the process of discarding all symbol information
7395796c8dcSSimon Schubert for an objfile, freeing up all memory held for it, and unlinking the
7405796c8dcSSimon Schubert objfile struct from the global list of known objfiles. */
7415796c8dcSSimon Schubert
7425796c8dcSSimon Schubert static void
dbx_symfile_finish(struct objfile * objfile)7435796c8dcSSimon Schubert dbx_symfile_finish (struct objfile *objfile)
7445796c8dcSSimon Schubert {
745*ef5ccd6cSJohn Marino free_header_files ();
746*ef5ccd6cSJohn Marino }
747*ef5ccd6cSJohn Marino
748*ef5ccd6cSJohn Marino static void
dbx_free_symfile_info(struct objfile * objfile,void * arg)749*ef5ccd6cSJohn Marino dbx_free_symfile_info (struct objfile *objfile, void *arg)
7505796c8dcSSimon Schubert {
751*ef5ccd6cSJohn Marino struct dbx_symfile_info *dbx = arg;
752*ef5ccd6cSJohn Marino
753*ef5ccd6cSJohn Marino if (dbx->header_files != NULL)
7545796c8dcSSimon Schubert {
755*ef5ccd6cSJohn Marino int i = dbx->n_header_files;
756*ef5ccd6cSJohn Marino struct header_file *hfiles = dbx->header_files;
7575796c8dcSSimon Schubert
7585796c8dcSSimon Schubert while (--i >= 0)
7595796c8dcSSimon Schubert {
7605796c8dcSSimon Schubert xfree (hfiles[i].name);
7615796c8dcSSimon Schubert xfree (hfiles[i].vector);
7625796c8dcSSimon Schubert }
7635796c8dcSSimon Schubert xfree (hfiles);
7645796c8dcSSimon Schubert }
765*ef5ccd6cSJohn Marino
766*ef5ccd6cSJohn Marino xfree (dbx);
7675796c8dcSSimon Schubert }
768*ef5ccd6cSJohn Marino
7695796c8dcSSimon Schubert
7705796c8dcSSimon Schubert
7715796c8dcSSimon Schubert /* Buffer for reading the symbol table entries. */
7725796c8dcSSimon Schubert static struct external_nlist symbuf[4096];
7735796c8dcSSimon Schubert static int symbuf_idx;
7745796c8dcSSimon Schubert static int symbuf_end;
7755796c8dcSSimon Schubert
7765796c8dcSSimon Schubert /* Name of last function encountered. Used in Solaris to approximate
7775796c8dcSSimon Schubert object file boundaries. */
7785796c8dcSSimon Schubert static char *last_function_name;
7795796c8dcSSimon Schubert
7805796c8dcSSimon Schubert /* The address in memory of the string table of the object file we are
7815796c8dcSSimon Schubert reading (which might not be the "main" object file, but might be a
7825796c8dcSSimon Schubert shared library or some other dynamically loaded thing). This is
7835796c8dcSSimon Schubert set by read_dbx_symtab when building psymtabs, and by
7845796c8dcSSimon Schubert read_ofile_symtab when building symtabs, and is used only by
7855796c8dcSSimon Schubert next_symbol_text. FIXME: If that is true, we don't need it when
7865796c8dcSSimon Schubert building psymtabs, right? */
7875796c8dcSSimon Schubert static char *stringtab_global;
7885796c8dcSSimon Schubert
7895796c8dcSSimon Schubert /* These variables are used to control fill_symbuf when the stabs
7905796c8dcSSimon Schubert symbols are not contiguous (as may be the case when a COFF file is
7915796c8dcSSimon Schubert linked using --split-by-reloc). */
7925796c8dcSSimon Schubert static struct stab_section_list *symbuf_sections;
7935796c8dcSSimon Schubert static unsigned int symbuf_left;
7945796c8dcSSimon Schubert static unsigned int symbuf_read;
7955796c8dcSSimon Schubert
7965796c8dcSSimon Schubert /* This variable stores a global stabs buffer, if we read stabs into
7975796c8dcSSimon Schubert memory in one chunk in order to process relocations. */
7985796c8dcSSimon Schubert static bfd_byte *stabs_data;
7995796c8dcSSimon Schubert
8005796c8dcSSimon Schubert /* Refill the symbol table input buffer
8015796c8dcSSimon Schubert and set the variables that control fetching entries from it.
8025796c8dcSSimon Schubert Reports an error if no data available.
8035796c8dcSSimon Schubert This function can read past the end of the symbol table
8045796c8dcSSimon Schubert (into the string table) but this does no harm. */
8055796c8dcSSimon Schubert
8065796c8dcSSimon Schubert static void
fill_symbuf(bfd * sym_bfd)8075796c8dcSSimon Schubert fill_symbuf (bfd *sym_bfd)
8085796c8dcSSimon Schubert {
8095796c8dcSSimon Schubert unsigned int count;
8105796c8dcSSimon Schubert int nbytes;
8115796c8dcSSimon Schubert
8125796c8dcSSimon Schubert if (stabs_data)
8135796c8dcSSimon Schubert {
8145796c8dcSSimon Schubert nbytes = sizeof (symbuf);
8155796c8dcSSimon Schubert if (nbytes > symbuf_left)
8165796c8dcSSimon Schubert nbytes = symbuf_left;
8175796c8dcSSimon Schubert memcpy (symbuf, stabs_data + symbuf_read, nbytes);
8185796c8dcSSimon Schubert }
8195796c8dcSSimon Schubert else if (symbuf_sections == NULL)
8205796c8dcSSimon Schubert {
8215796c8dcSSimon Schubert count = sizeof (symbuf);
8225796c8dcSSimon Schubert nbytes = bfd_bread (symbuf, count, sym_bfd);
8235796c8dcSSimon Schubert }
8245796c8dcSSimon Schubert else
8255796c8dcSSimon Schubert {
8265796c8dcSSimon Schubert if (symbuf_left <= 0)
8275796c8dcSSimon Schubert {
8285796c8dcSSimon Schubert file_ptr filepos = symbuf_sections->section->filepos;
829cf7f2e2dSJohn Marino
8305796c8dcSSimon Schubert if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
8315796c8dcSSimon Schubert perror_with_name (bfd_get_filename (sym_bfd));
8325796c8dcSSimon Schubert symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section);
8335796c8dcSSimon Schubert symbol_table_offset = filepos - symbuf_read;
8345796c8dcSSimon Schubert symbuf_sections = symbuf_sections->next;
8355796c8dcSSimon Schubert }
8365796c8dcSSimon Schubert
8375796c8dcSSimon Schubert count = symbuf_left;
8385796c8dcSSimon Schubert if (count > sizeof (symbuf))
8395796c8dcSSimon Schubert count = sizeof (symbuf);
8405796c8dcSSimon Schubert nbytes = bfd_bread (symbuf, count, sym_bfd);
8415796c8dcSSimon Schubert }
8425796c8dcSSimon Schubert
8435796c8dcSSimon Schubert if (nbytes < 0)
8445796c8dcSSimon Schubert perror_with_name (bfd_get_filename (sym_bfd));
8455796c8dcSSimon Schubert else if (nbytes == 0)
8465796c8dcSSimon Schubert error (_("Premature end of file reading symbol table"));
8475796c8dcSSimon Schubert symbuf_end = nbytes / symbol_size;
8485796c8dcSSimon Schubert symbuf_idx = 0;
8495796c8dcSSimon Schubert symbuf_left -= nbytes;
8505796c8dcSSimon Schubert symbuf_read += nbytes;
8515796c8dcSSimon Schubert }
8525796c8dcSSimon Schubert
8535796c8dcSSimon Schubert static void
stabs_seek(int sym_offset)8545796c8dcSSimon Schubert stabs_seek (int sym_offset)
8555796c8dcSSimon Schubert {
8565796c8dcSSimon Schubert if (stabs_data)
8575796c8dcSSimon Schubert {
8585796c8dcSSimon Schubert symbuf_read += sym_offset;
8595796c8dcSSimon Schubert symbuf_left -= sym_offset;
8605796c8dcSSimon Schubert }
8615796c8dcSSimon Schubert else
8625796c8dcSSimon Schubert bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
8635796c8dcSSimon Schubert }
8645796c8dcSSimon Schubert
8655796c8dcSSimon Schubert #define INTERNALIZE_SYMBOL(intern, extern, abfd) \
8665796c8dcSSimon Schubert { \
8675796c8dcSSimon Schubert (intern).n_strx = bfd_h_get_32 (abfd, (extern)->e_strx); \
8685796c8dcSSimon Schubert (intern).n_type = bfd_h_get_8 (abfd, (extern)->e_type); \
8695796c8dcSSimon Schubert (intern).n_other = 0; \
8705796c8dcSSimon Schubert (intern).n_desc = bfd_h_get_16 (abfd, (extern)->e_desc); \
8715796c8dcSSimon Schubert if (bfd_get_sign_extend_vma (abfd)) \
8725796c8dcSSimon Schubert (intern).n_value = bfd_h_get_signed_32 (abfd, (extern)->e_value); \
8735796c8dcSSimon Schubert else \
8745796c8dcSSimon Schubert (intern).n_value = bfd_h_get_32 (abfd, (extern)->e_value); \
8755796c8dcSSimon Schubert }
8765796c8dcSSimon Schubert
8775796c8dcSSimon Schubert /* Invariant: The symbol pointed to by symbuf_idx is the first one
8785796c8dcSSimon Schubert that hasn't been swapped. Swap the symbol at the same time
8795796c8dcSSimon Schubert that symbuf_idx is incremented. */
8805796c8dcSSimon Schubert
8815796c8dcSSimon Schubert /* dbx allows the text of a symbol name to be continued into the
8825796c8dcSSimon Schubert next symbol name! When such a continuation is encountered
8835796c8dcSSimon Schubert (a \ at the end of the text of a name)
8845796c8dcSSimon Schubert call this function to get the continuation. */
8855796c8dcSSimon Schubert
8865796c8dcSSimon Schubert static char *
dbx_next_symbol_text(struct objfile * objfile)8875796c8dcSSimon Schubert dbx_next_symbol_text (struct objfile *objfile)
8885796c8dcSSimon Schubert {
8895796c8dcSSimon Schubert struct internal_nlist nlist;
8905796c8dcSSimon Schubert
8915796c8dcSSimon Schubert if (symbuf_idx == symbuf_end)
8925796c8dcSSimon Schubert fill_symbuf (symfile_bfd);
8935796c8dcSSimon Schubert
8945796c8dcSSimon Schubert symnum++;
8955796c8dcSSimon Schubert INTERNALIZE_SYMBOL (nlist, &symbuf[symbuf_idx], symfile_bfd);
8965796c8dcSSimon Schubert OBJSTAT (objfile, n_stabs++);
8975796c8dcSSimon Schubert
8985796c8dcSSimon Schubert symbuf_idx++;
8995796c8dcSSimon Schubert
9005796c8dcSSimon Schubert return nlist.n_strx + stringtab_global + file_string_table_offset;
9015796c8dcSSimon Schubert }
9025796c8dcSSimon Schubert
9035796c8dcSSimon Schubert /* Initialize the list of bincls to contain none and have some
9045796c8dcSSimon Schubert allocated. */
9055796c8dcSSimon Schubert
9065796c8dcSSimon Schubert static void
init_bincl_list(int number,struct objfile * objfile)9075796c8dcSSimon Schubert init_bincl_list (int number, struct objfile *objfile)
9085796c8dcSSimon Schubert {
9095796c8dcSSimon Schubert bincls_allocated = number;
9105796c8dcSSimon Schubert next_bincl = bincl_list = (struct header_file_location *)
9115796c8dcSSimon Schubert xmalloc (bincls_allocated * sizeof (struct header_file_location));
9125796c8dcSSimon Schubert }
9135796c8dcSSimon Schubert
9145796c8dcSSimon Schubert /* Add a bincl to the list. */
9155796c8dcSSimon Schubert
9165796c8dcSSimon Schubert static void
add_bincl_to_list(struct partial_symtab * pst,char * name,int instance)9175796c8dcSSimon Schubert add_bincl_to_list (struct partial_symtab *pst, char *name, int instance)
9185796c8dcSSimon Schubert {
9195796c8dcSSimon Schubert if (next_bincl >= bincl_list + bincls_allocated)
9205796c8dcSSimon Schubert {
9215796c8dcSSimon Schubert int offset = next_bincl - bincl_list;
922cf7f2e2dSJohn Marino
9235796c8dcSSimon Schubert bincls_allocated *= 2;
9245796c8dcSSimon Schubert bincl_list = (struct header_file_location *)
9255796c8dcSSimon Schubert xrealloc ((char *) bincl_list,
9265796c8dcSSimon Schubert bincls_allocated * sizeof (struct header_file_location));
9275796c8dcSSimon Schubert next_bincl = bincl_list + offset;
9285796c8dcSSimon Schubert }
9295796c8dcSSimon Schubert next_bincl->pst = pst;
9305796c8dcSSimon Schubert next_bincl->instance = instance;
9315796c8dcSSimon Schubert next_bincl++->name = name;
9325796c8dcSSimon Schubert }
9335796c8dcSSimon Schubert
9345796c8dcSSimon Schubert /* Given a name, value pair, find the corresponding
9355796c8dcSSimon Schubert bincl in the list. Return the partial symtab associated
9365796c8dcSSimon Schubert with that header_file_location. */
9375796c8dcSSimon Schubert
9385796c8dcSSimon Schubert static struct partial_symtab *
find_corresponding_bincl_psymtab(char * name,int instance)9395796c8dcSSimon Schubert find_corresponding_bincl_psymtab (char *name, int instance)
9405796c8dcSSimon Schubert {
9415796c8dcSSimon Schubert struct header_file_location *bincl;
9425796c8dcSSimon Schubert
9435796c8dcSSimon Schubert for (bincl = bincl_list; bincl < next_bincl; bincl++)
9445796c8dcSSimon Schubert if (bincl->instance == instance
9455796c8dcSSimon Schubert && strcmp (name, bincl->name) == 0)
9465796c8dcSSimon Schubert return bincl->pst;
9475796c8dcSSimon Schubert
9485796c8dcSSimon Schubert repeated_header_complaint (name, symnum);
9495796c8dcSSimon Schubert return (struct partial_symtab *) 0;
9505796c8dcSSimon Schubert }
9515796c8dcSSimon Schubert
9525796c8dcSSimon Schubert /* Free the storage allocated for the bincl list. */
9535796c8dcSSimon Schubert
9545796c8dcSSimon Schubert static void
free_bincl_list(struct objfile * objfile)9555796c8dcSSimon Schubert free_bincl_list (struct objfile *objfile)
9565796c8dcSSimon Schubert {
9575796c8dcSSimon Schubert xfree (bincl_list);
9585796c8dcSSimon Schubert bincls_allocated = 0;
9595796c8dcSSimon Schubert }
9605796c8dcSSimon Schubert
9615796c8dcSSimon Schubert static void
do_free_bincl_list_cleanup(void * objfile)9625796c8dcSSimon Schubert do_free_bincl_list_cleanup (void *objfile)
9635796c8dcSSimon Schubert {
9645796c8dcSSimon Schubert free_bincl_list (objfile);
9655796c8dcSSimon Schubert }
9665796c8dcSSimon Schubert
9675796c8dcSSimon Schubert static struct cleanup *
make_cleanup_free_bincl_list(struct objfile * objfile)9685796c8dcSSimon Schubert make_cleanup_free_bincl_list (struct objfile *objfile)
9695796c8dcSSimon Schubert {
9705796c8dcSSimon Schubert return make_cleanup (do_free_bincl_list_cleanup, objfile);
9715796c8dcSSimon Schubert }
9725796c8dcSSimon Schubert
9735796c8dcSSimon Schubert /* Set namestring based on nlist. If the string table index is invalid,
9745796c8dcSSimon Schubert give a fake name, and print a single error message per symbol file read,
9755796c8dcSSimon Schubert rather than abort the symbol reading or flood the user with messages. */
9765796c8dcSSimon Schubert
9775796c8dcSSimon Schubert static char *
set_namestring(struct objfile * objfile,const struct internal_nlist * nlist)9785796c8dcSSimon Schubert set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
9795796c8dcSSimon Schubert {
9805796c8dcSSimon Schubert char *namestring;
9815796c8dcSSimon Schubert
982cf7f2e2dSJohn Marino if (nlist->n_strx + file_string_table_offset
983cf7f2e2dSJohn Marino >= DBX_STRINGTAB_SIZE (objfile)
984cf7f2e2dSJohn Marino || nlist->n_strx + file_string_table_offset < nlist->n_strx)
9855796c8dcSSimon Schubert {
986c50c785cSJohn Marino complaint (&symfile_complaints,
987c50c785cSJohn Marino _("bad string table offset in symbol %d"),
9885796c8dcSSimon Schubert symnum);
9895796c8dcSSimon Schubert namestring = "<bad string table offset>";
9905796c8dcSSimon Schubert }
9915796c8dcSSimon Schubert else
9925796c8dcSSimon Schubert namestring = (nlist->n_strx + file_string_table_offset
9935796c8dcSSimon Schubert + DBX_STRINGTAB (objfile));
9945796c8dcSSimon Schubert return namestring;
9955796c8dcSSimon Schubert }
9965796c8dcSSimon Schubert
9975796c8dcSSimon Schubert /* Scan a SunOs dynamic symbol table for symbols of interest and
9985796c8dcSSimon Schubert add them to the minimal symbol table. */
9995796c8dcSSimon Schubert
10005796c8dcSSimon Schubert static void
read_dbx_dynamic_symtab(struct objfile * objfile)10015796c8dcSSimon Schubert read_dbx_dynamic_symtab (struct objfile *objfile)
10025796c8dcSSimon Schubert {
10035796c8dcSSimon Schubert bfd *abfd = objfile->obfd;
10045796c8dcSSimon Schubert struct cleanup *back_to;
10055796c8dcSSimon Schubert int counter;
10065796c8dcSSimon Schubert long dynsym_size;
10075796c8dcSSimon Schubert long dynsym_count;
10085796c8dcSSimon Schubert asymbol **dynsyms;
10095796c8dcSSimon Schubert asymbol **symptr;
10105796c8dcSSimon Schubert arelent **relptr;
10115796c8dcSSimon Schubert long dynrel_size;
10125796c8dcSSimon Schubert long dynrel_count;
10135796c8dcSSimon Schubert arelent **dynrels;
10145796c8dcSSimon Schubert CORE_ADDR sym_value;
10155796c8dcSSimon Schubert char *name;
10165796c8dcSSimon Schubert
10175796c8dcSSimon Schubert /* Check that the symbol file has dynamic symbols that we know about.
10185796c8dcSSimon Schubert bfd_arch_unknown can happen if we are reading a sun3 symbol file
10195796c8dcSSimon Schubert on a sun4 host (and vice versa) and bfd is not configured
10205796c8dcSSimon Schubert --with-target=all. This would trigger an assertion in bfd/sunos.c,
10215796c8dcSSimon Schubert so we ignore the dynamic symbols in this case. */
10225796c8dcSSimon Schubert if (bfd_get_flavour (abfd) != bfd_target_aout_flavour
10235796c8dcSSimon Schubert || (bfd_get_file_flags (abfd) & DYNAMIC) == 0
10245796c8dcSSimon Schubert || bfd_get_arch (abfd) == bfd_arch_unknown)
10255796c8dcSSimon Schubert return;
10265796c8dcSSimon Schubert
10275796c8dcSSimon Schubert dynsym_size = bfd_get_dynamic_symtab_upper_bound (abfd);
10285796c8dcSSimon Schubert if (dynsym_size < 0)
10295796c8dcSSimon Schubert return;
10305796c8dcSSimon Schubert
10315796c8dcSSimon Schubert dynsyms = (asymbol **) xmalloc (dynsym_size);
10325796c8dcSSimon Schubert back_to = make_cleanup (xfree, dynsyms);
10335796c8dcSSimon Schubert
10345796c8dcSSimon Schubert dynsym_count = bfd_canonicalize_dynamic_symtab (abfd, dynsyms);
10355796c8dcSSimon Schubert if (dynsym_count < 0)
10365796c8dcSSimon Schubert {
10375796c8dcSSimon Schubert do_cleanups (back_to);
10385796c8dcSSimon Schubert return;
10395796c8dcSSimon Schubert }
10405796c8dcSSimon Schubert
10415796c8dcSSimon Schubert /* Enter dynamic symbols into the minimal symbol table
10425796c8dcSSimon Schubert if this is a stripped executable. */
10435796c8dcSSimon Schubert if (bfd_get_symcount (abfd) <= 0)
10445796c8dcSSimon Schubert {
10455796c8dcSSimon Schubert symptr = dynsyms;
10465796c8dcSSimon Schubert for (counter = 0; counter < dynsym_count; counter++, symptr++)
10475796c8dcSSimon Schubert {
10485796c8dcSSimon Schubert asymbol *sym = *symptr;
10495796c8dcSSimon Schubert asection *sec;
10505796c8dcSSimon Schubert int type;
10515796c8dcSSimon Schubert
10525796c8dcSSimon Schubert sec = bfd_get_section (sym);
10535796c8dcSSimon Schubert
10545796c8dcSSimon Schubert /* BFD symbols are section relative. */
10555796c8dcSSimon Schubert sym_value = sym->value + sec->vma;
10565796c8dcSSimon Schubert
10575796c8dcSSimon Schubert if (bfd_get_section_flags (abfd, sec) & SEC_CODE)
10585796c8dcSSimon Schubert {
10595796c8dcSSimon Schubert sym_value += ANOFFSET (objfile->section_offsets,
10605796c8dcSSimon Schubert SECT_OFF_TEXT (objfile));
10615796c8dcSSimon Schubert type = N_TEXT;
10625796c8dcSSimon Schubert }
10635796c8dcSSimon Schubert else if (bfd_get_section_flags (abfd, sec) & SEC_DATA)
10645796c8dcSSimon Schubert {
10655796c8dcSSimon Schubert sym_value += ANOFFSET (objfile->section_offsets,
10665796c8dcSSimon Schubert SECT_OFF_DATA (objfile));
10675796c8dcSSimon Schubert type = N_DATA;
10685796c8dcSSimon Schubert }
10695796c8dcSSimon Schubert else if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
10705796c8dcSSimon Schubert {
10715796c8dcSSimon Schubert sym_value += ANOFFSET (objfile->section_offsets,
10725796c8dcSSimon Schubert SECT_OFF_BSS (objfile));
10735796c8dcSSimon Schubert type = N_BSS;
10745796c8dcSSimon Schubert }
10755796c8dcSSimon Schubert else
10765796c8dcSSimon Schubert continue;
10775796c8dcSSimon Schubert
10785796c8dcSSimon Schubert if (sym->flags & BSF_GLOBAL)
10795796c8dcSSimon Schubert type |= N_EXT;
10805796c8dcSSimon Schubert
10815796c8dcSSimon Schubert record_minimal_symbol ((char *) bfd_asymbol_name (sym), sym_value,
10825796c8dcSSimon Schubert type, objfile);
10835796c8dcSSimon Schubert }
10845796c8dcSSimon Schubert }
10855796c8dcSSimon Schubert
10865796c8dcSSimon Schubert /* Symbols from shared libraries have a dynamic relocation entry
10875796c8dcSSimon Schubert that points to the associated slot in the procedure linkage table.
10885796c8dcSSimon Schubert We make a mininal symbol table entry with type mst_solib_trampoline
10895796c8dcSSimon Schubert at the address in the procedure linkage table. */
10905796c8dcSSimon Schubert dynrel_size = bfd_get_dynamic_reloc_upper_bound (abfd);
10915796c8dcSSimon Schubert if (dynrel_size < 0)
10925796c8dcSSimon Schubert {
10935796c8dcSSimon Schubert do_cleanups (back_to);
10945796c8dcSSimon Schubert return;
10955796c8dcSSimon Schubert }
10965796c8dcSSimon Schubert
10975796c8dcSSimon Schubert dynrels = (arelent **) xmalloc (dynrel_size);
10985796c8dcSSimon Schubert make_cleanup (xfree, dynrels);
10995796c8dcSSimon Schubert
11005796c8dcSSimon Schubert dynrel_count = bfd_canonicalize_dynamic_reloc (abfd, dynrels, dynsyms);
11015796c8dcSSimon Schubert if (dynrel_count < 0)
11025796c8dcSSimon Schubert {
11035796c8dcSSimon Schubert do_cleanups (back_to);
11045796c8dcSSimon Schubert return;
11055796c8dcSSimon Schubert }
11065796c8dcSSimon Schubert
11075796c8dcSSimon Schubert for (counter = 0, relptr = dynrels;
11085796c8dcSSimon Schubert counter < dynrel_count;
11095796c8dcSSimon Schubert counter++, relptr++)
11105796c8dcSSimon Schubert {
11115796c8dcSSimon Schubert arelent *rel = *relptr;
11125796c8dcSSimon Schubert CORE_ADDR address =
11135796c8dcSSimon Schubert rel->address + ANOFFSET (objfile->section_offsets,
11145796c8dcSSimon Schubert SECT_OFF_DATA (objfile));
11155796c8dcSSimon Schubert
11165796c8dcSSimon Schubert switch (bfd_get_arch (abfd))
11175796c8dcSSimon Schubert {
11185796c8dcSSimon Schubert case bfd_arch_sparc:
11195796c8dcSSimon Schubert if (rel->howto->type != RELOC_JMP_SLOT)
11205796c8dcSSimon Schubert continue;
11215796c8dcSSimon Schubert break;
11225796c8dcSSimon Schubert case bfd_arch_m68k:
11235796c8dcSSimon Schubert /* `16' is the type BFD produces for a jump table relocation. */
11245796c8dcSSimon Schubert if (rel->howto->type != 16)
11255796c8dcSSimon Schubert continue;
11265796c8dcSSimon Schubert
11275796c8dcSSimon Schubert /* Adjust address in the jump table to point to
11285796c8dcSSimon Schubert the start of the bsr instruction. */
11295796c8dcSSimon Schubert address -= 2;
11305796c8dcSSimon Schubert break;
11315796c8dcSSimon Schubert default:
11325796c8dcSSimon Schubert continue;
11335796c8dcSSimon Schubert }
11345796c8dcSSimon Schubert
11355796c8dcSSimon Schubert name = (char *) bfd_asymbol_name (*rel->sym_ptr_ptr);
11365796c8dcSSimon Schubert prim_record_minimal_symbol (name, address, mst_solib_trampoline,
11375796c8dcSSimon Schubert objfile);
11385796c8dcSSimon Schubert }
11395796c8dcSSimon Schubert
11405796c8dcSSimon Schubert do_cleanups (back_to);
11415796c8dcSSimon Schubert }
11425796c8dcSSimon Schubert
11435796c8dcSSimon Schubert static CORE_ADDR
find_stab_function_addr(char * namestring,const char * filename,struct objfile * objfile)1144c50c785cSJohn Marino find_stab_function_addr (char *namestring, const char *filename,
11455796c8dcSSimon Schubert struct objfile *objfile)
11465796c8dcSSimon Schubert {
11475796c8dcSSimon Schubert struct minimal_symbol *msym;
11485796c8dcSSimon Schubert char *p;
11495796c8dcSSimon Schubert int n;
11505796c8dcSSimon Schubert
11515796c8dcSSimon Schubert p = strchr (namestring, ':');
11525796c8dcSSimon Schubert if (p == NULL)
11535796c8dcSSimon Schubert p = namestring;
11545796c8dcSSimon Schubert n = p - namestring;
11555796c8dcSSimon Schubert p = alloca (n + 2);
11565796c8dcSSimon Schubert strncpy (p, namestring, n);
11575796c8dcSSimon Schubert p[n] = 0;
11585796c8dcSSimon Schubert
11595796c8dcSSimon Schubert msym = lookup_minimal_symbol (p, filename, objfile);
11605796c8dcSSimon Schubert if (msym == NULL)
11615796c8dcSSimon Schubert {
11625796c8dcSSimon Schubert /* Sun Fortran appends an underscore to the minimal symbol name,
11635796c8dcSSimon Schubert try again with an appended underscore if the minimal symbol
11645796c8dcSSimon Schubert was not found. */
11655796c8dcSSimon Schubert p[n] = '_';
11665796c8dcSSimon Schubert p[n + 1] = 0;
11675796c8dcSSimon Schubert msym = lookup_minimal_symbol (p, filename, objfile);
11685796c8dcSSimon Schubert }
11695796c8dcSSimon Schubert
11705796c8dcSSimon Schubert if (msym == NULL && filename != NULL)
11715796c8dcSSimon Schubert {
11725796c8dcSSimon Schubert /* Try again without the filename. */
11735796c8dcSSimon Schubert p[n] = 0;
11745796c8dcSSimon Schubert msym = lookup_minimal_symbol (p, NULL, objfile);
11755796c8dcSSimon Schubert }
11765796c8dcSSimon Schubert if (msym == NULL && filename != NULL)
11775796c8dcSSimon Schubert {
11785796c8dcSSimon Schubert /* And try again for Sun Fortran, but without the filename. */
11795796c8dcSSimon Schubert p[n] = '_';
11805796c8dcSSimon Schubert p[n + 1] = 0;
11815796c8dcSSimon Schubert msym = lookup_minimal_symbol (p, NULL, objfile);
11825796c8dcSSimon Schubert }
11835796c8dcSSimon Schubert
11845796c8dcSSimon Schubert return msym == NULL ? 0 : SYMBOL_VALUE_ADDRESS (msym);
11855796c8dcSSimon Schubert }
11865796c8dcSSimon Schubert
11875796c8dcSSimon Schubert static void
function_outside_compilation_unit_complaint(const char * arg1)11885796c8dcSSimon Schubert function_outside_compilation_unit_complaint (const char *arg1)
11895796c8dcSSimon Schubert {
11905796c8dcSSimon Schubert complaint (&symfile_complaints,
1191c50c785cSJohn Marino _("function `%s' appears to be defined "
1192c50c785cSJohn Marino "outside of all compilation units"),
11935796c8dcSSimon Schubert arg1);
11945796c8dcSSimon Schubert }
11955796c8dcSSimon Schubert
11965796c8dcSSimon Schubert /* Setup partial_symtab's describing each source file for which
11975796c8dcSSimon Schubert debugging information is available. */
11985796c8dcSSimon Schubert
11995796c8dcSSimon Schubert static void
read_dbx_symtab(struct objfile * objfile)12005796c8dcSSimon Schubert read_dbx_symtab (struct objfile *objfile)
12015796c8dcSSimon Schubert {
12025796c8dcSSimon Schubert struct gdbarch *gdbarch = get_objfile_arch (objfile);
1203c50c785cSJohn Marino struct external_nlist *bufp = 0; /* =0 avoids gcc -Wall glitch. */
12045796c8dcSSimon Schubert struct internal_nlist nlist;
12055796c8dcSSimon Schubert CORE_ADDR text_addr;
12065796c8dcSSimon Schubert int text_size;
12075796c8dcSSimon Schubert char *sym_name;
12085796c8dcSSimon Schubert int sym_len;
12095796c8dcSSimon Schubert
12105796c8dcSSimon Schubert char *namestring;
12115796c8dcSSimon Schubert int nsl;
12125796c8dcSSimon Schubert int past_first_source_file = 0;
12135796c8dcSSimon Schubert CORE_ADDR last_o_file_start = 0;
12145796c8dcSSimon Schubert CORE_ADDR last_function_start = 0;
12155796c8dcSSimon Schubert struct cleanup *back_to;
12165796c8dcSSimon Schubert bfd *abfd;
12175796c8dcSSimon Schubert int textlow_not_set;
12185796c8dcSSimon Schubert int data_sect_index;
12195796c8dcSSimon Schubert
1220c50c785cSJohn Marino /* Current partial symtab. */
12215796c8dcSSimon Schubert struct partial_symtab *pst;
12225796c8dcSSimon Schubert
1223c50c785cSJohn Marino /* List of current psymtab's include files. */
1224*ef5ccd6cSJohn Marino const char **psymtab_include_list;
12255796c8dcSSimon Schubert int includes_allocated;
12265796c8dcSSimon Schubert int includes_used;
12275796c8dcSSimon Schubert
1228c50c785cSJohn Marino /* Index within current psymtab dependency list. */
12295796c8dcSSimon Schubert struct partial_symtab **dependency_list;
12305796c8dcSSimon Schubert int dependencies_used, dependencies_allocated;
12315796c8dcSSimon Schubert
12325796c8dcSSimon Schubert text_addr = DBX_TEXT_ADDR (objfile);
12335796c8dcSSimon Schubert text_size = DBX_TEXT_SIZE (objfile);
12345796c8dcSSimon Schubert
12355796c8dcSSimon Schubert /* FIXME. We probably want to change stringtab_global rather than add this
12365796c8dcSSimon Schubert while processing every symbol entry. FIXME. */
12375796c8dcSSimon Schubert file_string_table_offset = 0;
12385796c8dcSSimon Schubert next_file_string_table_offset = 0;
12395796c8dcSSimon Schubert
12405796c8dcSSimon Schubert stringtab_global = DBX_STRINGTAB (objfile);
12415796c8dcSSimon Schubert
12425796c8dcSSimon Schubert pst = (struct partial_symtab *) 0;
12435796c8dcSSimon Schubert
12445796c8dcSSimon Schubert includes_allocated = 30;
12455796c8dcSSimon Schubert includes_used = 0;
1246*ef5ccd6cSJohn Marino psymtab_include_list = (const char **) alloca (includes_allocated *
1247*ef5ccd6cSJohn Marino sizeof (const char *));
12485796c8dcSSimon Schubert
12495796c8dcSSimon Schubert dependencies_allocated = 30;
12505796c8dcSSimon Schubert dependencies_used = 0;
12515796c8dcSSimon Schubert dependency_list =
12525796c8dcSSimon Schubert (struct partial_symtab **) alloca (dependencies_allocated *
12535796c8dcSSimon Schubert sizeof (struct partial_symtab *));
12545796c8dcSSimon Schubert
12555796c8dcSSimon Schubert /* Init bincl list */
12565796c8dcSSimon Schubert init_bincl_list (20, objfile);
12575796c8dcSSimon Schubert back_to = make_cleanup_free_bincl_list (objfile);
12585796c8dcSSimon Schubert
1259*ef5ccd6cSJohn Marino set_last_source_file (NULL);
12605796c8dcSSimon Schubert
12615796c8dcSSimon Schubert lowest_text_address = (CORE_ADDR) -1;
12625796c8dcSSimon Schubert
1263c50c785cSJohn Marino symfile_bfd = objfile->obfd; /* For next_text_symbol. */
12645796c8dcSSimon Schubert abfd = objfile->obfd;
12655796c8dcSSimon Schubert symbuf_end = symbuf_idx = 0;
12665796c8dcSSimon Schubert next_symbol_text_func = dbx_next_symbol_text;
12675796c8dcSSimon Schubert textlow_not_set = 1;
12685796c8dcSSimon Schubert has_line_numbers = 0;
12695796c8dcSSimon Schubert
12705796c8dcSSimon Schubert /* FIXME: jimb/2003-09-12: We don't apply the right section's offset
12715796c8dcSSimon Schubert to global and static variables. The stab for a global or static
12725796c8dcSSimon Schubert variable doesn't give us any indication of which section it's in,
12735796c8dcSSimon Schubert so we can't tell immediately which offset in
12745796c8dcSSimon Schubert objfile->section_offsets we should apply to the variable's
12755796c8dcSSimon Schubert address.
12765796c8dcSSimon Schubert
12775796c8dcSSimon Schubert We could certainly find out which section contains the variable
12785796c8dcSSimon Schubert by looking up the variable's unrelocated address with
12795796c8dcSSimon Schubert find_pc_section, but that would be expensive; this is the
12805796c8dcSSimon Schubert function that constructs the partial symbol tables by examining
12815796c8dcSSimon Schubert every symbol in the entire executable, and it's
12825796c8dcSSimon Schubert performance-critical. So that expense would not be welcome. I'm
12835796c8dcSSimon Schubert not sure what to do about this at the moment.
12845796c8dcSSimon Schubert
12855796c8dcSSimon Schubert What we have done for years is to simply assume that the .data
12865796c8dcSSimon Schubert section's offset is appropriate for all global and static
12875796c8dcSSimon Schubert variables. Recently, this was expanded to fall back to the .bss
12885796c8dcSSimon Schubert section's offset if there is no .data section, and then to the
12895796c8dcSSimon Schubert .rodata section's offset. */
12905796c8dcSSimon Schubert data_sect_index = objfile->sect_index_data;
12915796c8dcSSimon Schubert if (data_sect_index == -1)
12925796c8dcSSimon Schubert data_sect_index = SECT_OFF_BSS (objfile);
12935796c8dcSSimon Schubert if (data_sect_index == -1)
12945796c8dcSSimon Schubert data_sect_index = SECT_OFF_RODATA (objfile);
12955796c8dcSSimon Schubert
12965796c8dcSSimon Schubert /* If data_sect_index is still -1, that's okay. It's perfectly fine
12975796c8dcSSimon Schubert for the file to have no .data, no .bss, and no .text at all, if
12985796c8dcSSimon Schubert it also has no global or static variables. If it does, we will
12995796c8dcSSimon Schubert get an internal error from an ANOFFSET macro below when we try to
13005796c8dcSSimon Schubert use data_sect_index. */
13015796c8dcSSimon Schubert
13025796c8dcSSimon Schubert for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
13035796c8dcSSimon Schubert {
1304c50c785cSJohn Marino /* Get the symbol for this run and pull out some info. */
1305c50c785cSJohn Marino QUIT; /* Allow this to be interruptable. */
13065796c8dcSSimon Schubert if (symbuf_idx == symbuf_end)
13075796c8dcSSimon Schubert fill_symbuf (abfd);
13085796c8dcSSimon Schubert bufp = &symbuf[symbuf_idx++];
13095796c8dcSSimon Schubert
13105796c8dcSSimon Schubert /*
13115796c8dcSSimon Schubert * Special case to speed up readin.
13125796c8dcSSimon Schubert */
13135796c8dcSSimon Schubert if (bfd_h_get_8 (abfd, bufp->e_type) == N_SLINE)
13145796c8dcSSimon Schubert {
13155796c8dcSSimon Schubert has_line_numbers = 1;
13165796c8dcSSimon Schubert continue;
13175796c8dcSSimon Schubert }
13185796c8dcSSimon Schubert
13195796c8dcSSimon Schubert INTERNALIZE_SYMBOL (nlist, bufp, abfd);
13205796c8dcSSimon Schubert OBJSTAT (objfile, n_stabs++);
13215796c8dcSSimon Schubert
13225796c8dcSSimon Schubert /* Ok. There is a lot of code duplicated in the rest of this
13235796c8dcSSimon Schubert switch statement (for efficiency reasons). Since I don't
13245796c8dcSSimon Schubert like duplicating code, I will do my penance here, and
13255796c8dcSSimon Schubert describe the code which is duplicated:
13265796c8dcSSimon Schubert
13275796c8dcSSimon Schubert *) The assignment to namestring.
13285796c8dcSSimon Schubert *) The call to strchr.
1329c50c785cSJohn Marino *) The addition of a partial symbol the two partial
13305796c8dcSSimon Schubert symbol lists. This last is a large section of code, so
1331c50c785cSJohn Marino I've imbedded it in the following macro. */
13325796c8dcSSimon Schubert
13335796c8dcSSimon Schubert switch (nlist.n_type)
13345796c8dcSSimon Schubert {
13355796c8dcSSimon Schubert /*
13365796c8dcSSimon Schubert * Standard, external, non-debugger, symbols
13375796c8dcSSimon Schubert */
13385796c8dcSSimon Schubert
13395796c8dcSSimon Schubert case N_TEXT | N_EXT:
13405796c8dcSSimon Schubert case N_NBTEXT | N_EXT:
13415796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
13425796c8dcSSimon Schubert SECT_OFF_TEXT (objfile));
13435796c8dcSSimon Schubert goto record_it;
13445796c8dcSSimon Schubert
13455796c8dcSSimon Schubert case N_DATA | N_EXT:
13465796c8dcSSimon Schubert case N_NBDATA | N_EXT:
13475796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
13485796c8dcSSimon Schubert SECT_OFF_DATA (objfile));
13495796c8dcSSimon Schubert goto record_it;
13505796c8dcSSimon Schubert
13515796c8dcSSimon Schubert case N_BSS:
13525796c8dcSSimon Schubert case N_BSS | N_EXT:
13535796c8dcSSimon Schubert case N_NBBSS | N_EXT:
13545796c8dcSSimon Schubert case N_SETV | N_EXT: /* FIXME, is this in BSS? */
13555796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
13565796c8dcSSimon Schubert SECT_OFF_BSS (objfile));
13575796c8dcSSimon Schubert goto record_it;
13585796c8dcSSimon Schubert
13595796c8dcSSimon Schubert case N_ABS | N_EXT:
13605796c8dcSSimon Schubert record_it:
13615796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
13625796c8dcSSimon Schubert
13635796c8dcSSimon Schubert bss_ext_symbol:
13645796c8dcSSimon Schubert record_minimal_symbol (namestring, nlist.n_value,
13655796c8dcSSimon Schubert nlist.n_type, objfile); /* Always */
13665796c8dcSSimon Schubert continue;
13675796c8dcSSimon Schubert
1368c50c785cSJohn Marino /* Standard, local, non-debugger, symbols. */
13695796c8dcSSimon Schubert
13705796c8dcSSimon Schubert case N_NBTEXT:
13715796c8dcSSimon Schubert
13725796c8dcSSimon Schubert /* We need to be able to deal with both N_FN or N_TEXT,
13735796c8dcSSimon Schubert because we have no way of knowing whether the sys-supplied ld
13745796c8dcSSimon Schubert or GNU ld was used to make the executable. Sequents throw
13755796c8dcSSimon Schubert in another wrinkle -- they renumbered N_FN. */
13765796c8dcSSimon Schubert
13775796c8dcSSimon Schubert case N_FN:
13785796c8dcSSimon Schubert case N_FN_SEQ:
13795796c8dcSSimon Schubert case N_TEXT:
13805796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
13815796c8dcSSimon Schubert SECT_OFF_TEXT (objfile));
13825796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
13835796c8dcSSimon Schubert
13845796c8dcSSimon Schubert if ((namestring[0] == '-' && namestring[1] == 'l')
13855796c8dcSSimon Schubert || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
13865796c8dcSSimon Schubert && namestring[nsl - 2] == '.'))
13875796c8dcSSimon Schubert {
13885796c8dcSSimon Schubert if (past_first_source_file && pst
13895796c8dcSSimon Schubert /* The gould NP1 uses low values for .o and -l symbols
13905796c8dcSSimon Schubert which are not the address. */
13915796c8dcSSimon Schubert && nlist.n_value >= pst->textlow)
13925796c8dcSSimon Schubert {
1393*ef5ccd6cSJohn Marino end_psymtab (objfile, pst, psymtab_include_list,
1394*ef5ccd6cSJohn Marino includes_used, symnum * symbol_size,
13955796c8dcSSimon Schubert nlist.n_value > pst->texthigh
13965796c8dcSSimon Schubert ? nlist.n_value : pst->texthigh,
13975796c8dcSSimon Schubert dependency_list, dependencies_used,
13985796c8dcSSimon Schubert textlow_not_set);
13995796c8dcSSimon Schubert pst = (struct partial_symtab *) 0;
14005796c8dcSSimon Schubert includes_used = 0;
14015796c8dcSSimon Schubert dependencies_used = 0;
14025796c8dcSSimon Schubert has_line_numbers = 0;
14035796c8dcSSimon Schubert }
14045796c8dcSSimon Schubert else
14055796c8dcSSimon Schubert past_first_source_file = 1;
14065796c8dcSSimon Schubert last_o_file_start = nlist.n_value;
14075796c8dcSSimon Schubert }
14085796c8dcSSimon Schubert else
14095796c8dcSSimon Schubert goto record_it;
14105796c8dcSSimon Schubert continue;
14115796c8dcSSimon Schubert
14125796c8dcSSimon Schubert case N_DATA:
14135796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
14145796c8dcSSimon Schubert SECT_OFF_DATA (objfile));
14155796c8dcSSimon Schubert goto record_it;
14165796c8dcSSimon Schubert
14175796c8dcSSimon Schubert case N_UNDF | N_EXT:
1418c50c785cSJohn Marino /* The case (nlist.n_value != 0) is a "Fortran COMMON" symbol.
1419c50c785cSJohn Marino We used to rely on the target to tell us whether it knows
1420c50c785cSJohn Marino where the symbol has been relocated to, but none of the
1421c50c785cSJohn Marino target implementations actually provided that operation.
1422c50c785cSJohn Marino So we just ignore the symbol, the same way we would do if
1423c50c785cSJohn Marino we had a target-side symbol lookup which returned no match.
14245796c8dcSSimon Schubert
1425c50c785cSJohn Marino All other symbols (with nlist.n_value == 0), are really
1426c50c785cSJohn Marino undefined, and so we ignore them too. */
1427c50c785cSJohn Marino continue;
14285796c8dcSSimon Schubert
14295796c8dcSSimon Schubert case N_UNDF:
14305796c8dcSSimon Schubert if (processing_acc_compilation && nlist.n_strx == 1)
14315796c8dcSSimon Schubert {
14325796c8dcSSimon Schubert /* Deal with relative offsets in the string table
14335796c8dcSSimon Schubert used in ELF+STAB under Solaris. If we want to use the
14345796c8dcSSimon Schubert n_strx field, which contains the name of the file,
14355796c8dcSSimon Schubert we must adjust file_string_table_offset *before* calling
14365796c8dcSSimon Schubert set_namestring(). */
14375796c8dcSSimon Schubert past_first_source_file = 1;
14385796c8dcSSimon Schubert file_string_table_offset = next_file_string_table_offset;
14395796c8dcSSimon Schubert next_file_string_table_offset =
14405796c8dcSSimon Schubert file_string_table_offset + nlist.n_value;
14415796c8dcSSimon Schubert if (next_file_string_table_offset < file_string_table_offset)
14425796c8dcSSimon Schubert error (_("string table offset backs up at %d"), symnum);
14435796c8dcSSimon Schubert /* FIXME -- replace error() with complaint. */
14445796c8dcSSimon Schubert continue;
14455796c8dcSSimon Schubert }
14465796c8dcSSimon Schubert continue;
14475796c8dcSSimon Schubert
14485796c8dcSSimon Schubert /* Lots of symbol types we can just ignore. */
14495796c8dcSSimon Schubert
14505796c8dcSSimon Schubert case N_ABS:
14515796c8dcSSimon Schubert case N_NBDATA:
14525796c8dcSSimon Schubert case N_NBBSS:
14535796c8dcSSimon Schubert continue;
14545796c8dcSSimon Schubert
14555796c8dcSSimon Schubert /* Keep going . . . */
14565796c8dcSSimon Schubert
14575796c8dcSSimon Schubert /*
14585796c8dcSSimon Schubert * Special symbol types for GNU
14595796c8dcSSimon Schubert */
14605796c8dcSSimon Schubert case N_INDR:
14615796c8dcSSimon Schubert case N_INDR | N_EXT:
14625796c8dcSSimon Schubert case N_SETA:
14635796c8dcSSimon Schubert case N_SETA | N_EXT:
14645796c8dcSSimon Schubert case N_SETT:
14655796c8dcSSimon Schubert case N_SETT | N_EXT:
14665796c8dcSSimon Schubert case N_SETD:
14675796c8dcSSimon Schubert case N_SETD | N_EXT:
14685796c8dcSSimon Schubert case N_SETB:
14695796c8dcSSimon Schubert case N_SETB | N_EXT:
14705796c8dcSSimon Schubert case N_SETV:
14715796c8dcSSimon Schubert continue;
14725796c8dcSSimon Schubert
14735796c8dcSSimon Schubert /*
14745796c8dcSSimon Schubert * Debugger symbols
14755796c8dcSSimon Schubert */
14765796c8dcSSimon Schubert
14775796c8dcSSimon Schubert case N_SO:
14785796c8dcSSimon Schubert {
14795796c8dcSSimon Schubert CORE_ADDR valu;
14805796c8dcSSimon Schubert static int prev_so_symnum = -10;
14815796c8dcSSimon Schubert static int first_so_symnum;
1482c50c785cSJohn Marino const char *p;
14835796c8dcSSimon Schubert static char *dirname_nso;
14845796c8dcSSimon Schubert int prev_textlow_not_set;
14855796c8dcSSimon Schubert
14865796c8dcSSimon Schubert valu = nlist.n_value + ANOFFSET (objfile->section_offsets,
14875796c8dcSSimon Schubert SECT_OFF_TEXT (objfile));
14885796c8dcSSimon Schubert
14895796c8dcSSimon Schubert prev_textlow_not_set = textlow_not_set;
14905796c8dcSSimon Schubert
14915796c8dcSSimon Schubert /* A zero value is probably an indication for the SunPRO 3.0
14925796c8dcSSimon Schubert compiler. end_psymtab explicitly tests for zero, so
14935796c8dcSSimon Schubert don't relocate it. */
14945796c8dcSSimon Schubert
14955796c8dcSSimon Schubert if (nlist.n_value == 0
14965796c8dcSSimon Schubert && gdbarch_sofun_address_maybe_missing (gdbarch))
14975796c8dcSSimon Schubert {
14985796c8dcSSimon Schubert textlow_not_set = 1;
14995796c8dcSSimon Schubert valu = 0;
15005796c8dcSSimon Schubert }
15015796c8dcSSimon Schubert else
15025796c8dcSSimon Schubert textlow_not_set = 0;
15035796c8dcSSimon Schubert
15045796c8dcSSimon Schubert past_first_source_file = 1;
15055796c8dcSSimon Schubert
15065796c8dcSSimon Schubert if (prev_so_symnum != symnum - 1)
1507c50c785cSJohn Marino { /* Here if prev stab wasn't N_SO. */
15085796c8dcSSimon Schubert first_so_symnum = symnum;
15095796c8dcSSimon Schubert
15105796c8dcSSimon Schubert if (pst)
15115796c8dcSSimon Schubert {
1512*ef5ccd6cSJohn Marino end_psymtab (objfile, pst, psymtab_include_list,
1513*ef5ccd6cSJohn Marino includes_used, symnum * symbol_size,
15145796c8dcSSimon Schubert valu > pst->texthigh ? valu : pst->texthigh,
15155796c8dcSSimon Schubert dependency_list, dependencies_used,
15165796c8dcSSimon Schubert prev_textlow_not_set);
15175796c8dcSSimon Schubert pst = (struct partial_symtab *) 0;
15185796c8dcSSimon Schubert includes_used = 0;
15195796c8dcSSimon Schubert dependencies_used = 0;
15205796c8dcSSimon Schubert has_line_numbers = 0;
15215796c8dcSSimon Schubert }
15225796c8dcSSimon Schubert }
15235796c8dcSSimon Schubert
15245796c8dcSSimon Schubert prev_so_symnum = symnum;
15255796c8dcSSimon Schubert
1526c50c785cSJohn Marino /* End the current partial symtab and start a new one. */
15275796c8dcSSimon Schubert
15285796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
15295796c8dcSSimon Schubert
15305796c8dcSSimon Schubert /* Null name means end of .o file. Don't start a new one. */
15315796c8dcSSimon Schubert if (*namestring == '\000')
15325796c8dcSSimon Schubert continue;
15335796c8dcSSimon Schubert
15345796c8dcSSimon Schubert /* Some compilers (including gcc) emit a pair of initial N_SOs.
15355796c8dcSSimon Schubert The first one is a directory name; the second the file name.
15365796c8dcSSimon Schubert If pst exists, is empty, and has a filename ending in '/',
15375796c8dcSSimon Schubert we assume the previous N_SO was a directory name. */
15385796c8dcSSimon Schubert
1539c50c785cSJohn Marino p = lbasename (namestring);
1540c50c785cSJohn Marino if (p != namestring && *p == '\000')
15415796c8dcSSimon Schubert {
15425796c8dcSSimon Schubert /* Save the directory name SOs locally, then save it into
15435796c8dcSSimon Schubert the psymtab when it's created below. */
15445796c8dcSSimon Schubert dirname_nso = namestring;
15455796c8dcSSimon Schubert continue;
15465796c8dcSSimon Schubert }
15475796c8dcSSimon Schubert
15485796c8dcSSimon Schubert /* Some other compilers (C++ ones in particular) emit useless
15495796c8dcSSimon Schubert SOs for non-existant .c files. We ignore all subsequent SOs
15505796c8dcSSimon Schubert that immediately follow the first. */
15515796c8dcSSimon Schubert
15525796c8dcSSimon Schubert if (!pst)
15535796c8dcSSimon Schubert {
15545796c8dcSSimon Schubert pst = start_psymtab (objfile,
15555796c8dcSSimon Schubert namestring, valu,
15565796c8dcSSimon Schubert first_so_symnum * symbol_size,
15575796c8dcSSimon Schubert objfile->global_psymbols.next,
15585796c8dcSSimon Schubert objfile->static_psymbols.next);
15595796c8dcSSimon Schubert pst->dirname = dirname_nso;
15605796c8dcSSimon Schubert dirname_nso = NULL;
15615796c8dcSSimon Schubert }
15625796c8dcSSimon Schubert continue;
15635796c8dcSSimon Schubert }
15645796c8dcSSimon Schubert
15655796c8dcSSimon Schubert case N_BINCL:
15665796c8dcSSimon Schubert {
15675796c8dcSSimon Schubert enum language tmp_language;
1568cf7f2e2dSJohn Marino
15695796c8dcSSimon Schubert /* Add this bincl to the bincl_list for future EXCLs. No
15705796c8dcSSimon Schubert need to save the string; it'll be around until
1571c50c785cSJohn Marino read_dbx_symtab function returns. */
15725796c8dcSSimon Schubert
15735796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
15745796c8dcSSimon Schubert tmp_language = deduce_language_from_filename (namestring);
15755796c8dcSSimon Schubert
15765796c8dcSSimon Schubert /* Only change the psymtab's language if we've learned
15775796c8dcSSimon Schubert something useful (eg. tmp_language is not language_unknown).
15785796c8dcSSimon Schubert In addition, to match what start_subfile does, never change
15795796c8dcSSimon Schubert from C++ to C. */
15805796c8dcSSimon Schubert if (tmp_language != language_unknown
15815796c8dcSSimon Schubert && (tmp_language != language_c
15825796c8dcSSimon Schubert || psymtab_language != language_cplus))
15835796c8dcSSimon Schubert psymtab_language = tmp_language;
15845796c8dcSSimon Schubert
15855796c8dcSSimon Schubert if (pst == NULL)
15865796c8dcSSimon Schubert {
15875796c8dcSSimon Schubert /* FIXME: we should not get here without a PST to work on.
15885796c8dcSSimon Schubert Attempt to recover. */
15895796c8dcSSimon Schubert complaint (&symfile_complaints,
1590c50c785cSJohn Marino _("N_BINCL %s not in entries for "
1591c50c785cSJohn Marino "any file, at symtab pos %d"),
15925796c8dcSSimon Schubert namestring, symnum);
15935796c8dcSSimon Schubert continue;
15945796c8dcSSimon Schubert }
15955796c8dcSSimon Schubert add_bincl_to_list (pst, namestring, nlist.n_value);
15965796c8dcSSimon Schubert
1597c50c785cSJohn Marino /* Mark down an include file in the current psymtab. */
15985796c8dcSSimon Schubert
15995796c8dcSSimon Schubert goto record_include_file;
16005796c8dcSSimon Schubert }
16015796c8dcSSimon Schubert
16025796c8dcSSimon Schubert case N_SOL:
16035796c8dcSSimon Schubert {
16045796c8dcSSimon Schubert enum language tmp_language;
16055796c8dcSSimon Schubert
1606c50c785cSJohn Marino /* Mark down an include file in the current psymtab. */
16075796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
16085796c8dcSSimon Schubert tmp_language = deduce_language_from_filename (namestring);
16095796c8dcSSimon Schubert
16105796c8dcSSimon Schubert /* Only change the psymtab's language if we've learned
16115796c8dcSSimon Schubert something useful (eg. tmp_language is not language_unknown).
16125796c8dcSSimon Schubert In addition, to match what start_subfile does, never change
16135796c8dcSSimon Schubert from C++ to C. */
16145796c8dcSSimon Schubert if (tmp_language != language_unknown
16155796c8dcSSimon Schubert && (tmp_language != language_c
16165796c8dcSSimon Schubert || psymtab_language != language_cplus))
16175796c8dcSSimon Schubert psymtab_language = tmp_language;
16185796c8dcSSimon Schubert
16195796c8dcSSimon Schubert /* In C++, one may expect the same filename to come round many
16205796c8dcSSimon Schubert times, when code is coming alternately from the main file
16215796c8dcSSimon Schubert and from inline functions in other files. So I check to see
16225796c8dcSSimon Schubert if this is a file we've seen before -- either the main
16235796c8dcSSimon Schubert source file, or a previously included file.
16245796c8dcSSimon Schubert
16255796c8dcSSimon Schubert This seems to be a lot of time to be spending on N_SOL, but
16265796c8dcSSimon Schubert things like "break c-exp.y:435" need to work (I
16275796c8dcSSimon Schubert suppose the psymtab_include_list could be hashed or put
16285796c8dcSSimon Schubert in a binary tree, if profiling shows this is a major hog). */
1629c50c785cSJohn Marino if (pst && filename_cmp (namestring, pst->filename) == 0)
16305796c8dcSSimon Schubert continue;
16315796c8dcSSimon Schubert {
16325796c8dcSSimon Schubert int i;
1633cf7f2e2dSJohn Marino
16345796c8dcSSimon Schubert for (i = 0; i < includes_used; i++)
1635c50c785cSJohn Marino if (filename_cmp (namestring, psymtab_include_list[i]) == 0)
16365796c8dcSSimon Schubert {
16375796c8dcSSimon Schubert i = -1;
16385796c8dcSSimon Schubert break;
16395796c8dcSSimon Schubert }
16405796c8dcSSimon Schubert if (i == -1)
16415796c8dcSSimon Schubert continue;
16425796c8dcSSimon Schubert }
16435796c8dcSSimon Schubert
16445796c8dcSSimon Schubert record_include_file:
16455796c8dcSSimon Schubert
16465796c8dcSSimon Schubert psymtab_include_list[includes_used++] = namestring;
16475796c8dcSSimon Schubert if (includes_used >= includes_allocated)
16485796c8dcSSimon Schubert {
1649*ef5ccd6cSJohn Marino const char **orig = psymtab_include_list;
16505796c8dcSSimon Schubert
1651*ef5ccd6cSJohn Marino psymtab_include_list = (const char **)
1652*ef5ccd6cSJohn Marino alloca ((includes_allocated *= 2) * sizeof (const char *));
16535796c8dcSSimon Schubert memcpy (psymtab_include_list, orig,
1654*ef5ccd6cSJohn Marino includes_used * sizeof (const char *));
16555796c8dcSSimon Schubert }
16565796c8dcSSimon Schubert continue;
16575796c8dcSSimon Schubert }
16585796c8dcSSimon Schubert case N_LSYM: /* Typedef or automatic variable. */
1659c50c785cSJohn Marino case N_STSYM: /* Data seg var -- static. */
16605796c8dcSSimon Schubert case N_LCSYM: /* BSS " */
16615796c8dcSSimon Schubert case N_ROSYM: /* Read-only data seg var -- static. */
16625796c8dcSSimon Schubert case N_NBSTS: /* Gould nobase. */
16635796c8dcSSimon Schubert case N_NBLCS: /* symbols. */
16645796c8dcSSimon Schubert case N_FUN:
16655796c8dcSSimon Schubert case N_GSYM: /* Global (extern) variable; can be
16665796c8dcSSimon Schubert data or bss (sigh FIXME). */
16675796c8dcSSimon Schubert
16685796c8dcSSimon Schubert /* Following may probably be ignored; I'll leave them here
16695796c8dcSSimon Schubert for now (until I do Pascal and Modula 2 extensions). */
16705796c8dcSSimon Schubert
16715796c8dcSSimon Schubert case N_PC: /* I may or may not need this; I
16725796c8dcSSimon Schubert suspect not. */
16735796c8dcSSimon Schubert case N_M2C: /* I suspect that I can ignore this here. */
16745796c8dcSSimon Schubert case N_SCOPE: /* Same. */
16755796c8dcSSimon Schubert {
16765796c8dcSSimon Schubert char *p;
16775796c8dcSSimon Schubert
16785796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
16795796c8dcSSimon Schubert
16805796c8dcSSimon Schubert /* See if this is an end of function stab. */
16815796c8dcSSimon Schubert if (pst && nlist.n_type == N_FUN && *namestring == '\000')
16825796c8dcSSimon Schubert {
16835796c8dcSSimon Schubert CORE_ADDR valu;
16845796c8dcSSimon Schubert
16855796c8dcSSimon Schubert /* It's value is the size (in bytes) of the function for
16865796c8dcSSimon Schubert function relative stabs, or the address of the function's
16875796c8dcSSimon Schubert end for old style stabs. */
16885796c8dcSSimon Schubert valu = nlist.n_value + last_function_start;
16895796c8dcSSimon Schubert if (pst->texthigh == 0 || valu > pst->texthigh)
16905796c8dcSSimon Schubert pst->texthigh = valu;
16915796c8dcSSimon Schubert break;
16925796c8dcSSimon Schubert }
16935796c8dcSSimon Schubert
16945796c8dcSSimon Schubert p = (char *) strchr (namestring, ':');
16955796c8dcSSimon Schubert if (!p)
16965796c8dcSSimon Schubert continue; /* Not a debugging symbol. */
16975796c8dcSSimon Schubert
16985796c8dcSSimon Schubert sym_len = 0;
16995796c8dcSSimon Schubert sym_name = NULL; /* pacify "gcc -Werror" */
17005796c8dcSSimon Schubert if (psymtab_language == language_cplus)
17015796c8dcSSimon Schubert {
17025796c8dcSSimon Schubert char *new_name, *name = xmalloc (p - namestring + 1);
17035796c8dcSSimon Schubert memcpy (name, namestring, p - namestring);
1704cf7f2e2dSJohn Marino
17055796c8dcSSimon Schubert name[p - namestring] = '\0';
17065796c8dcSSimon Schubert new_name = cp_canonicalize_string (name);
17075796c8dcSSimon Schubert if (new_name != NULL)
17085796c8dcSSimon Schubert {
17095796c8dcSSimon Schubert sym_len = strlen (new_name);
1710*ef5ccd6cSJohn Marino sym_name = obstack_copy0 (&objfile->objfile_obstack,
1711*ef5ccd6cSJohn Marino new_name, sym_len);
17125796c8dcSSimon Schubert xfree (new_name);
17135796c8dcSSimon Schubert }
17145796c8dcSSimon Schubert xfree (name);
17155796c8dcSSimon Schubert }
17165796c8dcSSimon Schubert
17175796c8dcSSimon Schubert if (sym_len == 0)
17185796c8dcSSimon Schubert {
17195796c8dcSSimon Schubert sym_name = namestring;
17205796c8dcSSimon Schubert sym_len = p - namestring;
17215796c8dcSSimon Schubert }
17225796c8dcSSimon Schubert
17235796c8dcSSimon Schubert /* Main processing section for debugging symbols which
17245796c8dcSSimon Schubert the initial read through the symbol tables needs to worry
17255796c8dcSSimon Schubert about. If we reach this point, the symbol which we are
17265796c8dcSSimon Schubert considering is definitely one we are interested in.
17275796c8dcSSimon Schubert p must also contain the (valid) index into the namestring
17285796c8dcSSimon Schubert which indicates the debugging type symbol. */
17295796c8dcSSimon Schubert
17305796c8dcSSimon Schubert switch (p[1])
17315796c8dcSSimon Schubert {
17325796c8dcSSimon Schubert case 'S':
17335796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
17345796c8dcSSimon Schubert data_sect_index);
17355796c8dcSSimon Schubert
17365796c8dcSSimon Schubert if (gdbarch_static_transform_name_p (gdbarch))
1737c50c785cSJohn Marino gdbarch_static_transform_name (gdbarch, namestring);
17385796c8dcSSimon Schubert
1739cf7f2e2dSJohn Marino add_psymbol_to_list (sym_name, sym_len, 1,
17405796c8dcSSimon Schubert VAR_DOMAIN, LOC_STATIC,
17415796c8dcSSimon Schubert &objfile->static_psymbols,
17425796c8dcSSimon Schubert 0, nlist.n_value,
17435796c8dcSSimon Schubert psymtab_language, objfile);
17445796c8dcSSimon Schubert continue;
17455796c8dcSSimon Schubert
17465796c8dcSSimon Schubert case 'G':
17475796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
17485796c8dcSSimon Schubert data_sect_index);
17495796c8dcSSimon Schubert /* The addresses in these entries are reported to be
17505796c8dcSSimon Schubert wrong. See the code that reads 'G's for symtabs. */
1751cf7f2e2dSJohn Marino add_psymbol_to_list (sym_name, sym_len, 1,
17525796c8dcSSimon Schubert VAR_DOMAIN, LOC_STATIC,
17535796c8dcSSimon Schubert &objfile->global_psymbols,
17545796c8dcSSimon Schubert 0, nlist.n_value,
17555796c8dcSSimon Schubert psymtab_language, objfile);
17565796c8dcSSimon Schubert continue;
17575796c8dcSSimon Schubert
17585796c8dcSSimon Schubert case 'T':
17595796c8dcSSimon Schubert /* When a 'T' entry is defining an anonymous enum, it
17605796c8dcSSimon Schubert may have a name which is the empty string, or a
17615796c8dcSSimon Schubert single space. Since they're not really defining a
17625796c8dcSSimon Schubert symbol, those shouldn't go in the partial symbol
17635796c8dcSSimon Schubert table. We do pick up the elements of such enums at
17645796c8dcSSimon Schubert 'check_enum:', below. */
17655796c8dcSSimon Schubert if (p >= namestring + 2
17665796c8dcSSimon Schubert || (p == namestring + 1
17675796c8dcSSimon Schubert && namestring[0] != ' '))
17685796c8dcSSimon Schubert {
1769cf7f2e2dSJohn Marino add_psymbol_to_list (sym_name, sym_len, 1,
17705796c8dcSSimon Schubert STRUCT_DOMAIN, LOC_TYPEDEF,
17715796c8dcSSimon Schubert &objfile->static_psymbols,
17725796c8dcSSimon Schubert nlist.n_value, 0,
17735796c8dcSSimon Schubert psymtab_language, objfile);
17745796c8dcSSimon Schubert if (p[2] == 't')
17755796c8dcSSimon Schubert {
17765796c8dcSSimon Schubert /* Also a typedef with the same name. */
1777cf7f2e2dSJohn Marino add_psymbol_to_list (sym_name, sym_len, 1,
17785796c8dcSSimon Schubert VAR_DOMAIN, LOC_TYPEDEF,
17795796c8dcSSimon Schubert &objfile->static_psymbols,
17805796c8dcSSimon Schubert nlist.n_value, 0,
17815796c8dcSSimon Schubert psymtab_language, objfile);
17825796c8dcSSimon Schubert p += 1;
17835796c8dcSSimon Schubert }
17845796c8dcSSimon Schubert }
17855796c8dcSSimon Schubert goto check_enum;
17865796c8dcSSimon Schubert
17875796c8dcSSimon Schubert case 't':
17885796c8dcSSimon Schubert if (p != namestring) /* a name is there, not just :T... */
17895796c8dcSSimon Schubert {
1790cf7f2e2dSJohn Marino add_psymbol_to_list (sym_name, sym_len, 1,
17915796c8dcSSimon Schubert VAR_DOMAIN, LOC_TYPEDEF,
17925796c8dcSSimon Schubert &objfile->static_psymbols,
17935796c8dcSSimon Schubert nlist.n_value, 0,
17945796c8dcSSimon Schubert psymtab_language, objfile);
17955796c8dcSSimon Schubert }
17965796c8dcSSimon Schubert check_enum:
17975796c8dcSSimon Schubert /* If this is an enumerated type, we need to
17985796c8dcSSimon Schubert add all the enum constants to the partial symbol
17995796c8dcSSimon Schubert table. This does not cover enums without names, e.g.
18005796c8dcSSimon Schubert "enum {a, b} c;" in C, but fortunately those are
18015796c8dcSSimon Schubert rare. There is no way for GDB to find those from the
18025796c8dcSSimon Schubert enum type without spending too much time on it. Thus
18035796c8dcSSimon Schubert to solve this problem, the compiler needs to put out the
18045796c8dcSSimon Schubert enum in a nameless type. GCC2 does this. */
18055796c8dcSSimon Schubert
18065796c8dcSSimon Schubert /* We are looking for something of the form
18075796c8dcSSimon Schubert <name> ":" ("t" | "T") [<number> "="] "e"
18085796c8dcSSimon Schubert {<constant> ":" <value> ","} ";". */
18095796c8dcSSimon Schubert
18105796c8dcSSimon Schubert /* Skip over the colon and the 't' or 'T'. */
18115796c8dcSSimon Schubert p += 2;
18125796c8dcSSimon Schubert /* This type may be given a number. Also, numbers can come
18135796c8dcSSimon Schubert in pairs like (0,26). Skip over it. */
18145796c8dcSSimon Schubert while ((*p >= '0' && *p <= '9')
18155796c8dcSSimon Schubert || *p == '(' || *p == ',' || *p == ')'
18165796c8dcSSimon Schubert || *p == '=')
18175796c8dcSSimon Schubert p++;
18185796c8dcSSimon Schubert
18195796c8dcSSimon Schubert if (*p++ == 'e')
18205796c8dcSSimon Schubert {
18215796c8dcSSimon Schubert /* The aix4 compiler emits extra crud before the members. */
18225796c8dcSSimon Schubert if (*p == '-')
18235796c8dcSSimon Schubert {
18245796c8dcSSimon Schubert /* Skip over the type (?). */
18255796c8dcSSimon Schubert while (*p != ':')
18265796c8dcSSimon Schubert p++;
18275796c8dcSSimon Schubert
18285796c8dcSSimon Schubert /* Skip over the colon. */
18295796c8dcSSimon Schubert p++;
18305796c8dcSSimon Schubert }
18315796c8dcSSimon Schubert
18325796c8dcSSimon Schubert /* We have found an enumerated type. */
18335796c8dcSSimon Schubert /* According to comments in read_enum_type
18345796c8dcSSimon Schubert a comma could end it instead of a semicolon.
18355796c8dcSSimon Schubert I don't know where that happens.
18365796c8dcSSimon Schubert Accept either. */
18375796c8dcSSimon Schubert while (*p && *p != ';' && *p != ',')
18385796c8dcSSimon Schubert {
18395796c8dcSSimon Schubert char *q;
18405796c8dcSSimon Schubert
18415796c8dcSSimon Schubert /* Check for and handle cretinous dbx symbol name
18425796c8dcSSimon Schubert continuation! */
18435796c8dcSSimon Schubert if (*p == '\\' || (*p == '?' && p[1] == '\0'))
18445796c8dcSSimon Schubert p = next_symbol_text (objfile);
18455796c8dcSSimon Schubert
18465796c8dcSSimon Schubert /* Point to the character after the name
18475796c8dcSSimon Schubert of the enum constant. */
18485796c8dcSSimon Schubert for (q = p; *q && *q != ':'; q++)
18495796c8dcSSimon Schubert ;
18505796c8dcSSimon Schubert /* Note that the value doesn't matter for
18515796c8dcSSimon Schubert enum constants in psymtabs, just in symtabs. */
1852cf7f2e2dSJohn Marino add_psymbol_to_list (p, q - p, 1,
18535796c8dcSSimon Schubert VAR_DOMAIN, LOC_CONST,
18545796c8dcSSimon Schubert &objfile->static_psymbols, 0,
18555796c8dcSSimon Schubert 0, psymtab_language, objfile);
18565796c8dcSSimon Schubert /* Point past the name. */
18575796c8dcSSimon Schubert p = q;
18585796c8dcSSimon Schubert /* Skip over the value. */
18595796c8dcSSimon Schubert while (*p && *p != ',')
18605796c8dcSSimon Schubert p++;
18615796c8dcSSimon Schubert /* Advance past the comma. */
18625796c8dcSSimon Schubert if (*p)
18635796c8dcSSimon Schubert p++;
18645796c8dcSSimon Schubert }
18655796c8dcSSimon Schubert }
18665796c8dcSSimon Schubert continue;
18675796c8dcSSimon Schubert
18685796c8dcSSimon Schubert case 'c':
18695796c8dcSSimon Schubert /* Constant, e.g. from "const" in Pascal. */
1870cf7f2e2dSJohn Marino add_psymbol_to_list (sym_name, sym_len, 1,
18715796c8dcSSimon Schubert VAR_DOMAIN, LOC_CONST,
18725796c8dcSSimon Schubert &objfile->static_psymbols, nlist.n_value,
18735796c8dcSSimon Schubert 0, psymtab_language, objfile);
18745796c8dcSSimon Schubert continue;
18755796c8dcSSimon Schubert
18765796c8dcSSimon Schubert case 'f':
18775796c8dcSSimon Schubert if (! pst)
18785796c8dcSSimon Schubert {
18795796c8dcSSimon Schubert int name_len = p - namestring;
18805796c8dcSSimon Schubert char *name = xmalloc (name_len + 1);
1881cf7f2e2dSJohn Marino
18825796c8dcSSimon Schubert memcpy (name, namestring, name_len);
18835796c8dcSSimon Schubert name[name_len] = '\0';
18845796c8dcSSimon Schubert function_outside_compilation_unit_complaint (name);
18855796c8dcSSimon Schubert xfree (name);
18865796c8dcSSimon Schubert }
18875796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
18885796c8dcSSimon Schubert SECT_OFF_TEXT (objfile));
1889c50c785cSJohn Marino /* Kludges for ELF/STABS with Sun ACC. */
18905796c8dcSSimon Schubert last_function_name = namestring;
18915796c8dcSSimon Schubert /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
18925796c8dcSSimon Schubert value for the bottom of the text seg in those cases. */
18935796c8dcSSimon Schubert if (nlist.n_value == ANOFFSET (objfile->section_offsets,
18945796c8dcSSimon Schubert SECT_OFF_TEXT (objfile))
18955796c8dcSSimon Schubert && gdbarch_sofun_address_maybe_missing (gdbarch))
18965796c8dcSSimon Schubert {
18975796c8dcSSimon Schubert CORE_ADDR minsym_valu =
18985796c8dcSSimon Schubert find_stab_function_addr (namestring,
18995796c8dcSSimon Schubert pst ? pst->filename : NULL,
19005796c8dcSSimon Schubert objfile);
1901cf7f2e2dSJohn Marino
19025796c8dcSSimon Schubert /* find_stab_function_addr will return 0 if the minimal
19035796c8dcSSimon Schubert symbol wasn't found. (Unfortunately, this might also
19045796c8dcSSimon Schubert be a valid address.) Anyway, if it *does* return 0,
19055796c8dcSSimon Schubert it is likely that the value was set correctly to begin
19065796c8dcSSimon Schubert with... */
19075796c8dcSSimon Schubert if (minsym_valu != 0)
19085796c8dcSSimon Schubert nlist.n_value = minsym_valu;
19095796c8dcSSimon Schubert }
19105796c8dcSSimon Schubert if (pst && textlow_not_set
19115796c8dcSSimon Schubert && gdbarch_sofun_address_maybe_missing (gdbarch))
19125796c8dcSSimon Schubert {
19135796c8dcSSimon Schubert pst->textlow = nlist.n_value;
19145796c8dcSSimon Schubert textlow_not_set = 0;
19155796c8dcSSimon Schubert }
19165796c8dcSSimon Schubert /* End kludge. */
19175796c8dcSSimon Schubert
19185796c8dcSSimon Schubert /* Keep track of the start of the last function so we
19195796c8dcSSimon Schubert can handle end of function symbols. */
19205796c8dcSSimon Schubert last_function_start = nlist.n_value;
19215796c8dcSSimon Schubert
19225796c8dcSSimon Schubert /* In reordered executables this function may lie outside
19235796c8dcSSimon Schubert the bounds created by N_SO symbols. If that's the case
19245796c8dcSSimon Schubert use the address of this function as the low bound for
19255796c8dcSSimon Schubert the partial symbol table. */
19265796c8dcSSimon Schubert if (pst
19275796c8dcSSimon Schubert && (textlow_not_set
19285796c8dcSSimon Schubert || (nlist.n_value < pst->textlow
19295796c8dcSSimon Schubert && (nlist.n_value
19305796c8dcSSimon Schubert != ANOFFSET (objfile->section_offsets,
19315796c8dcSSimon Schubert SECT_OFF_TEXT (objfile))))))
19325796c8dcSSimon Schubert {
19335796c8dcSSimon Schubert pst->textlow = nlist.n_value;
19345796c8dcSSimon Schubert textlow_not_set = 0;
19355796c8dcSSimon Schubert }
1936cf7f2e2dSJohn Marino add_psymbol_to_list (sym_name, sym_len, 1,
19375796c8dcSSimon Schubert VAR_DOMAIN, LOC_BLOCK,
19385796c8dcSSimon Schubert &objfile->static_psymbols,
19395796c8dcSSimon Schubert 0, nlist.n_value,
19405796c8dcSSimon Schubert psymtab_language, objfile);
19415796c8dcSSimon Schubert continue;
19425796c8dcSSimon Schubert
19435796c8dcSSimon Schubert /* Global functions were ignored here, but now they
19445796c8dcSSimon Schubert are put into the global psymtab like one would expect.
19455796c8dcSSimon Schubert They're also in the minimal symbol table. */
19465796c8dcSSimon Schubert case 'F':
19475796c8dcSSimon Schubert if (! pst)
19485796c8dcSSimon Schubert {
19495796c8dcSSimon Schubert int name_len = p - namestring;
19505796c8dcSSimon Schubert char *name = xmalloc (name_len + 1);
1951cf7f2e2dSJohn Marino
19525796c8dcSSimon Schubert memcpy (name, namestring, name_len);
19535796c8dcSSimon Schubert name[name_len] = '\0';
19545796c8dcSSimon Schubert function_outside_compilation_unit_complaint (name);
19555796c8dcSSimon Schubert xfree (name);
19565796c8dcSSimon Schubert }
19575796c8dcSSimon Schubert nlist.n_value += ANOFFSET (objfile->section_offsets,
19585796c8dcSSimon Schubert SECT_OFF_TEXT (objfile));
1959c50c785cSJohn Marino /* Kludges for ELF/STABS with Sun ACC. */
19605796c8dcSSimon Schubert last_function_name = namestring;
19615796c8dcSSimon Schubert /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
19625796c8dcSSimon Schubert value for the bottom of the text seg in those cases. */
19635796c8dcSSimon Schubert if (nlist.n_value == ANOFFSET (objfile->section_offsets,
19645796c8dcSSimon Schubert SECT_OFF_TEXT (objfile))
19655796c8dcSSimon Schubert && gdbarch_sofun_address_maybe_missing (gdbarch))
19665796c8dcSSimon Schubert {
19675796c8dcSSimon Schubert CORE_ADDR minsym_valu =
19685796c8dcSSimon Schubert find_stab_function_addr (namestring,
19695796c8dcSSimon Schubert pst ? pst->filename : NULL,
19705796c8dcSSimon Schubert objfile);
1971cf7f2e2dSJohn Marino
19725796c8dcSSimon Schubert /* find_stab_function_addr will return 0 if the minimal
19735796c8dcSSimon Schubert symbol wasn't found. (Unfortunately, this might also
19745796c8dcSSimon Schubert be a valid address.) Anyway, if it *does* return 0,
19755796c8dcSSimon Schubert it is likely that the value was set correctly to begin
19765796c8dcSSimon Schubert with... */
19775796c8dcSSimon Schubert if (minsym_valu != 0)
19785796c8dcSSimon Schubert nlist.n_value = minsym_valu;
19795796c8dcSSimon Schubert }
19805796c8dcSSimon Schubert if (pst && textlow_not_set
19815796c8dcSSimon Schubert && gdbarch_sofun_address_maybe_missing (gdbarch))
19825796c8dcSSimon Schubert {
19835796c8dcSSimon Schubert pst->textlow = nlist.n_value;
19845796c8dcSSimon Schubert textlow_not_set = 0;
19855796c8dcSSimon Schubert }
19865796c8dcSSimon Schubert /* End kludge. */
19875796c8dcSSimon Schubert
19885796c8dcSSimon Schubert /* Keep track of the start of the last function so we
19895796c8dcSSimon Schubert can handle end of function symbols. */
19905796c8dcSSimon Schubert last_function_start = nlist.n_value;
19915796c8dcSSimon Schubert
19925796c8dcSSimon Schubert /* In reordered executables this function may lie outside
19935796c8dcSSimon Schubert the bounds created by N_SO symbols. If that's the case
19945796c8dcSSimon Schubert use the address of this function as the low bound for
19955796c8dcSSimon Schubert the partial symbol table. */
19965796c8dcSSimon Schubert if (pst
19975796c8dcSSimon Schubert && (textlow_not_set
19985796c8dcSSimon Schubert || (nlist.n_value < pst->textlow
19995796c8dcSSimon Schubert && (nlist.n_value
20005796c8dcSSimon Schubert != ANOFFSET (objfile->section_offsets,
20015796c8dcSSimon Schubert SECT_OFF_TEXT (objfile))))))
20025796c8dcSSimon Schubert {
20035796c8dcSSimon Schubert pst->textlow = nlist.n_value;
20045796c8dcSSimon Schubert textlow_not_set = 0;
20055796c8dcSSimon Schubert }
2006cf7f2e2dSJohn Marino add_psymbol_to_list (sym_name, sym_len, 1,
20075796c8dcSSimon Schubert VAR_DOMAIN, LOC_BLOCK,
20085796c8dcSSimon Schubert &objfile->global_psymbols,
20095796c8dcSSimon Schubert 0, nlist.n_value,
20105796c8dcSSimon Schubert psymtab_language, objfile);
20115796c8dcSSimon Schubert continue;
20125796c8dcSSimon Schubert
20135796c8dcSSimon Schubert /* Two things show up here (hopefully); static symbols of
20145796c8dcSSimon Schubert local scope (static used inside braces) or extensions
20155796c8dcSSimon Schubert of structure symbols. We can ignore both. */
20165796c8dcSSimon Schubert case 'V':
20175796c8dcSSimon Schubert case '(':
20185796c8dcSSimon Schubert case '0':
20195796c8dcSSimon Schubert case '1':
20205796c8dcSSimon Schubert case '2':
20215796c8dcSSimon Schubert case '3':
20225796c8dcSSimon Schubert case '4':
20235796c8dcSSimon Schubert case '5':
20245796c8dcSSimon Schubert case '6':
20255796c8dcSSimon Schubert case '7':
20265796c8dcSSimon Schubert case '8':
20275796c8dcSSimon Schubert case '9':
20285796c8dcSSimon Schubert case '-':
2029c50c785cSJohn Marino case '#': /* For symbol identification (used in live ranges). */
20305796c8dcSSimon Schubert continue;
20315796c8dcSSimon Schubert
20325796c8dcSSimon Schubert case ':':
20335796c8dcSSimon Schubert /* It is a C++ nested symbol. We don't need to record it
20345796c8dcSSimon Schubert (I don't think); if we try to look up foo::bar::baz,
20355796c8dcSSimon Schubert then symbols for the symtab containing foo should get
20365796c8dcSSimon Schubert read in, I think. */
20375796c8dcSSimon Schubert /* Someone says sun cc puts out symbols like
20385796c8dcSSimon Schubert /foo/baz/maclib::/usr/local/bin/maclib,
20395796c8dcSSimon Schubert which would get here with a symbol type of ':'. */
20405796c8dcSSimon Schubert continue;
20415796c8dcSSimon Schubert
20425796c8dcSSimon Schubert default:
20435796c8dcSSimon Schubert /* Unexpected symbol descriptor. The second and subsequent stabs
20445796c8dcSSimon Schubert of a continued stab can show up here. The question is
20455796c8dcSSimon Schubert whether they ever can mimic a normal stab--it would be
20465796c8dcSSimon Schubert nice if not, since we certainly don't want to spend the
20475796c8dcSSimon Schubert time searching to the end of every string looking for
20485796c8dcSSimon Schubert a backslash. */
20495796c8dcSSimon Schubert
2050c50c785cSJohn Marino complaint (&symfile_complaints,
2051c50c785cSJohn Marino _("unknown symbol descriptor `%c'"),
20525796c8dcSSimon Schubert p[1]);
20535796c8dcSSimon Schubert
20545796c8dcSSimon Schubert /* Ignore it; perhaps it is an extension that we don't
20555796c8dcSSimon Schubert know about. */
20565796c8dcSSimon Schubert continue;
20575796c8dcSSimon Schubert }
20585796c8dcSSimon Schubert }
20595796c8dcSSimon Schubert
20605796c8dcSSimon Schubert case N_EXCL:
20615796c8dcSSimon Schubert
20625796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
20635796c8dcSSimon Schubert
20645796c8dcSSimon Schubert /* Find the corresponding bincl and mark that psymtab on the
2065c50c785cSJohn Marino psymtab dependency list. */
20665796c8dcSSimon Schubert {
20675796c8dcSSimon Schubert struct partial_symtab *needed_pst =
20685796c8dcSSimon Schubert find_corresponding_bincl_psymtab (namestring, nlist.n_value);
20695796c8dcSSimon Schubert
20705796c8dcSSimon Schubert /* If this include file was defined earlier in this file,
20715796c8dcSSimon Schubert leave it alone. */
20725796c8dcSSimon Schubert if (needed_pst == pst)
20735796c8dcSSimon Schubert continue;
20745796c8dcSSimon Schubert
20755796c8dcSSimon Schubert if (needed_pst)
20765796c8dcSSimon Schubert {
20775796c8dcSSimon Schubert int i;
20785796c8dcSSimon Schubert int found = 0;
20795796c8dcSSimon Schubert
20805796c8dcSSimon Schubert for (i = 0; i < dependencies_used; i++)
20815796c8dcSSimon Schubert if (dependency_list[i] == needed_pst)
20825796c8dcSSimon Schubert {
20835796c8dcSSimon Schubert found = 1;
20845796c8dcSSimon Schubert break;
20855796c8dcSSimon Schubert }
20865796c8dcSSimon Schubert
20875796c8dcSSimon Schubert /* If it's already in the list, skip the rest. */
20885796c8dcSSimon Schubert if (found)
20895796c8dcSSimon Schubert continue;
20905796c8dcSSimon Schubert
20915796c8dcSSimon Schubert dependency_list[dependencies_used++] = needed_pst;
20925796c8dcSSimon Schubert if (dependencies_used >= dependencies_allocated)
20935796c8dcSSimon Schubert {
20945796c8dcSSimon Schubert struct partial_symtab **orig = dependency_list;
2095cf7f2e2dSJohn Marino
20965796c8dcSSimon Schubert dependency_list =
20975796c8dcSSimon Schubert (struct partial_symtab **)
20985796c8dcSSimon Schubert alloca ((dependencies_allocated *= 2)
20995796c8dcSSimon Schubert * sizeof (struct partial_symtab *));
21005796c8dcSSimon Schubert memcpy (dependency_list, orig,
21015796c8dcSSimon Schubert (dependencies_used
21025796c8dcSSimon Schubert * sizeof (struct partial_symtab *)));
21035796c8dcSSimon Schubert #ifdef DEBUG_INFO
21045796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr,
2105c50c785cSJohn Marino "Had to reallocate "
2106c50c785cSJohn Marino "dependency list.\n");
21075796c8dcSSimon Schubert fprintf_unfiltered (gdb_stderr,
21085796c8dcSSimon Schubert "New dependencies allocated: %d\n",
21095796c8dcSSimon Schubert dependencies_allocated);
21105796c8dcSSimon Schubert #endif
21115796c8dcSSimon Schubert }
21125796c8dcSSimon Schubert }
21135796c8dcSSimon Schubert }
21145796c8dcSSimon Schubert continue;
21155796c8dcSSimon Schubert
21165796c8dcSSimon Schubert case N_ENDM:
21175796c8dcSSimon Schubert /* Solaris 2 end of module, finish current partial symbol table.
21185796c8dcSSimon Schubert end_psymtab will set pst->texthigh to the proper value, which
21195796c8dcSSimon Schubert is necessary if a module compiled without debugging info
21205796c8dcSSimon Schubert follows this module. */
21215796c8dcSSimon Schubert if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
21225796c8dcSSimon Schubert {
2123*ef5ccd6cSJohn Marino end_psymtab (objfile, pst, psymtab_include_list, includes_used,
21245796c8dcSSimon Schubert symnum * symbol_size,
2125c50c785cSJohn Marino (CORE_ADDR) 0, dependency_list,
2126c50c785cSJohn Marino dependencies_used, textlow_not_set);
21275796c8dcSSimon Schubert pst = (struct partial_symtab *) 0;
21285796c8dcSSimon Schubert includes_used = 0;
21295796c8dcSSimon Schubert dependencies_used = 0;
21305796c8dcSSimon Schubert has_line_numbers = 0;
21315796c8dcSSimon Schubert }
21325796c8dcSSimon Schubert continue;
21335796c8dcSSimon Schubert
21345796c8dcSSimon Schubert case N_RBRAC:
21355796c8dcSSimon Schubert #ifdef HANDLE_RBRAC
21365796c8dcSSimon Schubert HANDLE_RBRAC (nlist.n_value);
21375796c8dcSSimon Schubert continue;
21385796c8dcSSimon Schubert #endif
21395796c8dcSSimon Schubert case N_EINCL:
21405796c8dcSSimon Schubert case N_DSLINE:
21415796c8dcSSimon Schubert case N_BSLINE:
21425796c8dcSSimon Schubert case N_SSYM: /* Claim: Structure or union element.
21435796c8dcSSimon Schubert Hopefully, I can ignore this. */
21445796c8dcSSimon Schubert case N_ENTRY: /* Alternate entry point; can ignore. */
21455796c8dcSSimon Schubert case N_MAIN: /* Can definitely ignore this. */
21465796c8dcSSimon Schubert case N_CATCH: /* These are GNU C++ extensions */
21475796c8dcSSimon Schubert case N_EHDECL: /* that can safely be ignored here. */
21485796c8dcSSimon Schubert case N_LENG:
21495796c8dcSSimon Schubert case N_BCOMM:
21505796c8dcSSimon Schubert case N_ECOMM:
21515796c8dcSSimon Schubert case N_ECOML:
21525796c8dcSSimon Schubert case N_FNAME:
21535796c8dcSSimon Schubert case N_SLINE:
21545796c8dcSSimon Schubert case N_RSYM:
21555796c8dcSSimon Schubert case N_PSYM:
21565796c8dcSSimon Schubert case N_LBRAC:
21575796c8dcSSimon Schubert case N_NSYMS: /* Ultrix 4.0: symbol count */
21585796c8dcSSimon Schubert case N_DEFD: /* GNU Modula-2 */
21595796c8dcSSimon Schubert case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
21605796c8dcSSimon Schubert
2161c50c785cSJohn Marino case N_OBJ: /* Useless types from Solaris. */
21625796c8dcSSimon Schubert case N_OPT:
21635796c8dcSSimon Schubert case N_PATCH:
2164c50c785cSJohn Marino /* These symbols aren't interesting; don't worry about them. */
21655796c8dcSSimon Schubert continue;
21665796c8dcSSimon Schubert
21675796c8dcSSimon Schubert default:
21685796c8dcSSimon Schubert /* If we haven't found it yet, ignore it. It's probably some
21695796c8dcSSimon Schubert new type we don't know about yet. */
21705796c8dcSSimon Schubert unknown_symtype_complaint (hex_string (nlist.n_type));
21715796c8dcSSimon Schubert continue;
21725796c8dcSSimon Schubert }
21735796c8dcSSimon Schubert }
21745796c8dcSSimon Schubert
21755796c8dcSSimon Schubert /* If there's stuff to be cleaned up, clean it up. */
21765796c8dcSSimon Schubert if (pst)
21775796c8dcSSimon Schubert {
21785796c8dcSSimon Schubert /* Don't set pst->texthigh lower than it already is. */
21795796c8dcSSimon Schubert CORE_ADDR text_end =
21805796c8dcSSimon Schubert (lowest_text_address == (CORE_ADDR) -1
21815796c8dcSSimon Schubert ? (text_addr + ANOFFSET (objfile->section_offsets,
21825796c8dcSSimon Schubert SECT_OFF_TEXT (objfile)))
21835796c8dcSSimon Schubert : lowest_text_address)
21845796c8dcSSimon Schubert + text_size;
21855796c8dcSSimon Schubert
2186*ef5ccd6cSJohn Marino end_psymtab (objfile, pst, psymtab_include_list, includes_used,
21875796c8dcSSimon Schubert symnum * symbol_size,
21885796c8dcSSimon Schubert text_end > pst->texthigh ? text_end : pst->texthigh,
21895796c8dcSSimon Schubert dependency_list, dependencies_used, textlow_not_set);
21905796c8dcSSimon Schubert }
21915796c8dcSSimon Schubert
21925796c8dcSSimon Schubert do_cleanups (back_to);
21935796c8dcSSimon Schubert }
21945796c8dcSSimon Schubert
21955796c8dcSSimon Schubert /* Allocate and partially fill a partial symtab. It will be
21965796c8dcSSimon Schubert completely filled at the end of the symbol list.
21975796c8dcSSimon Schubert
21985796c8dcSSimon Schubert SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
21995796c8dcSSimon Schubert is the address relative to which its symbols are (incremental) or 0
22005796c8dcSSimon Schubert (normal). */
22015796c8dcSSimon Schubert
22025796c8dcSSimon Schubert static struct partial_symtab *
start_psymtab(struct objfile * objfile,char * filename,CORE_ADDR textlow,int ldsymoff,struct partial_symbol ** global_syms,struct partial_symbol ** static_syms)22035796c8dcSSimon Schubert start_psymtab (struct objfile *objfile, char *filename, CORE_ADDR textlow,
22045796c8dcSSimon Schubert int ldsymoff, struct partial_symbol **global_syms,
22055796c8dcSSimon Schubert struct partial_symbol **static_syms)
22065796c8dcSSimon Schubert {
22075796c8dcSSimon Schubert struct partial_symtab *result =
22085796c8dcSSimon Schubert start_psymtab_common (objfile, objfile->section_offsets,
22095796c8dcSSimon Schubert filename, textlow, global_syms, static_syms);
22105796c8dcSSimon Schubert
2211cf7f2e2dSJohn Marino result->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
2212cf7f2e2dSJohn Marino sizeof (struct symloc));
22135796c8dcSSimon Schubert LDSYMOFF (result) = ldsymoff;
2214*ef5ccd6cSJohn Marino result->read_symtab = dbx_read_symtab;
22155796c8dcSSimon Schubert SYMBOL_SIZE (result) = symbol_size;
22165796c8dcSSimon Schubert SYMBOL_OFFSET (result) = symbol_table_offset;
22175796c8dcSSimon Schubert STRING_OFFSET (result) = string_table_offset;
22185796c8dcSSimon Schubert FILE_STRING_OFFSET (result) = file_string_table_offset;
22195796c8dcSSimon Schubert
22205796c8dcSSimon Schubert #ifdef HAVE_ELF
22215796c8dcSSimon Schubert /* If we're handling an ELF file, drag some section-relocation info
22225796c8dcSSimon Schubert for this source file out of the ELF symbol table, to compensate for
22235796c8dcSSimon Schubert Sun brain death. This replaces the section_offsets in this psymtab,
22245796c8dcSSimon Schubert if successful. */
22255796c8dcSSimon Schubert elfstab_offset_sections (objfile, result);
22265796c8dcSSimon Schubert #endif
22275796c8dcSSimon Schubert
22285796c8dcSSimon Schubert /* Deduce the source language from the filename for this psymtab. */
22295796c8dcSSimon Schubert psymtab_language = deduce_language_from_filename (filename);
22305796c8dcSSimon Schubert
22315796c8dcSSimon Schubert return result;
22325796c8dcSSimon Schubert }
22335796c8dcSSimon Schubert
22345796c8dcSSimon Schubert /* Close off the current usage of PST.
22355796c8dcSSimon Schubert Returns PST or NULL if the partial symtab was empty and thrown away.
22365796c8dcSSimon Schubert
22375796c8dcSSimon Schubert FIXME: List variables and peculiarities of same. */
22385796c8dcSSimon Schubert
22395796c8dcSSimon Schubert struct partial_symtab *
end_psymtab(struct objfile * objfile,struct partial_symtab * pst,const char ** include_list,int num_includes,int capping_symbol_offset,CORE_ADDR capping_text,struct partial_symtab ** dependency_list,int number_dependencies,int textlow_not_set)2240*ef5ccd6cSJohn Marino end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
2241*ef5ccd6cSJohn Marino const char **include_list, int num_includes,
22425796c8dcSSimon Schubert int capping_symbol_offset, CORE_ADDR capping_text,
22435796c8dcSSimon Schubert struct partial_symtab **dependency_list, int number_dependencies,
22445796c8dcSSimon Schubert int textlow_not_set)
22455796c8dcSSimon Schubert {
22465796c8dcSSimon Schubert int i;
22475796c8dcSSimon Schubert struct gdbarch *gdbarch = get_objfile_arch (objfile);
22485796c8dcSSimon Schubert
22495796c8dcSSimon Schubert if (capping_symbol_offset != -1)
22505796c8dcSSimon Schubert LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
22515796c8dcSSimon Schubert pst->texthigh = capping_text;
22525796c8dcSSimon Schubert
22535796c8dcSSimon Schubert /* Under Solaris, the N_SO symbols always have a value of 0,
22545796c8dcSSimon Schubert instead of the usual address of the .o file. Therefore,
22555796c8dcSSimon Schubert we have to do some tricks to fill in texthigh and textlow.
22565796c8dcSSimon Schubert The first trick is: if we see a static
22575796c8dcSSimon Schubert or global function, and the textlow for the current pst
22585796c8dcSSimon Schubert is not set (ie: textlow_not_set), then we use that function's
22595796c8dcSSimon Schubert address for the textlow of the pst. */
22605796c8dcSSimon Schubert
22615796c8dcSSimon Schubert /* Now, to fill in texthigh, we remember the last function seen
22625796c8dcSSimon Schubert in the .o file. Also, there's a hack in
22635796c8dcSSimon Schubert bfd/elf.c and gdb/elfread.c to pass the ELF st_size field
22645796c8dcSSimon Schubert to here via the misc_info field. Therefore, we can fill in
22655796c8dcSSimon Schubert a reliable texthigh by taking the address plus size of the
22665796c8dcSSimon Schubert last function in the file. */
22675796c8dcSSimon Schubert
22685796c8dcSSimon Schubert if (pst->texthigh == 0 && last_function_name
22695796c8dcSSimon Schubert && gdbarch_sofun_address_maybe_missing (gdbarch))
22705796c8dcSSimon Schubert {
22715796c8dcSSimon Schubert char *p;
22725796c8dcSSimon Schubert int n;
22735796c8dcSSimon Schubert struct minimal_symbol *minsym;
22745796c8dcSSimon Schubert
22755796c8dcSSimon Schubert p = strchr (last_function_name, ':');
22765796c8dcSSimon Schubert if (p == NULL)
22775796c8dcSSimon Schubert p = last_function_name;
22785796c8dcSSimon Schubert n = p - last_function_name;
22795796c8dcSSimon Schubert p = alloca (n + 2);
22805796c8dcSSimon Schubert strncpy (p, last_function_name, n);
22815796c8dcSSimon Schubert p[n] = 0;
22825796c8dcSSimon Schubert
22835796c8dcSSimon Schubert minsym = lookup_minimal_symbol (p, pst->filename, objfile);
22845796c8dcSSimon Schubert if (minsym == NULL)
22855796c8dcSSimon Schubert {
22865796c8dcSSimon Schubert /* Sun Fortran appends an underscore to the minimal symbol name,
22875796c8dcSSimon Schubert try again with an appended underscore if the minimal symbol
22885796c8dcSSimon Schubert was not found. */
22895796c8dcSSimon Schubert p[n] = '_';
22905796c8dcSSimon Schubert p[n + 1] = 0;
22915796c8dcSSimon Schubert minsym = lookup_minimal_symbol (p, pst->filename, objfile);
22925796c8dcSSimon Schubert }
22935796c8dcSSimon Schubert
22945796c8dcSSimon Schubert if (minsym)
22955796c8dcSSimon Schubert pst->texthigh = SYMBOL_VALUE_ADDRESS (minsym) + MSYMBOL_SIZE (minsym);
22965796c8dcSSimon Schubert
22975796c8dcSSimon Schubert last_function_name = NULL;
22985796c8dcSSimon Schubert }
22995796c8dcSSimon Schubert
23005796c8dcSSimon Schubert if (!gdbarch_sofun_address_maybe_missing (gdbarch))
23015796c8dcSSimon Schubert ;
2302c50c785cSJohn Marino /* This test will be true if the last .o file is only data. */
23035796c8dcSSimon Schubert else if (textlow_not_set)
23045796c8dcSSimon Schubert pst->textlow = pst->texthigh;
23055796c8dcSSimon Schubert else
23065796c8dcSSimon Schubert {
23075796c8dcSSimon Schubert struct partial_symtab *p1;
23085796c8dcSSimon Schubert
23095796c8dcSSimon Schubert /* If we know our own starting text address, then walk through all other
23105796c8dcSSimon Schubert psymtabs for this objfile, and if any didn't know their ending text
23115796c8dcSSimon Schubert address, set it to our starting address. Take care to not set our
23125796c8dcSSimon Schubert own ending address to our starting address, nor to set addresses on
23135796c8dcSSimon Schubert `dependency' files that have both textlow and texthigh zero. */
23145796c8dcSSimon Schubert
23155796c8dcSSimon Schubert ALL_OBJFILE_PSYMTABS (objfile, p1)
23165796c8dcSSimon Schubert {
23175796c8dcSSimon Schubert if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
23185796c8dcSSimon Schubert {
23195796c8dcSSimon Schubert p1->texthigh = pst->textlow;
2320c50c785cSJohn Marino /* If this file has only data, then make textlow match
2321c50c785cSJohn Marino texthigh. */
23225796c8dcSSimon Schubert if (p1->textlow == 0)
23235796c8dcSSimon Schubert p1->textlow = p1->texthigh;
23245796c8dcSSimon Schubert }
23255796c8dcSSimon Schubert }
23265796c8dcSSimon Schubert }
23275796c8dcSSimon Schubert
23285796c8dcSSimon Schubert /* End of kludge for patching Solaris textlow and texthigh. */
23295796c8dcSSimon Schubert
23305796c8dcSSimon Schubert pst->n_global_syms =
23315796c8dcSSimon Schubert objfile->global_psymbols.next - (objfile->global_psymbols.list
23325796c8dcSSimon Schubert + pst->globals_offset);
23335796c8dcSSimon Schubert pst->n_static_syms =
23345796c8dcSSimon Schubert objfile->static_psymbols.next - (objfile->static_psymbols.list
23355796c8dcSSimon Schubert + pst->statics_offset);
23365796c8dcSSimon Schubert
23375796c8dcSSimon Schubert pst->number_of_dependencies = number_dependencies;
23385796c8dcSSimon Schubert if (number_dependencies)
23395796c8dcSSimon Schubert {
23405796c8dcSSimon Schubert pst->dependencies = (struct partial_symtab **)
23415796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack,
23425796c8dcSSimon Schubert number_dependencies * sizeof (struct partial_symtab *));
23435796c8dcSSimon Schubert memcpy (pst->dependencies, dependency_list,
23445796c8dcSSimon Schubert number_dependencies * sizeof (struct partial_symtab *));
23455796c8dcSSimon Schubert }
23465796c8dcSSimon Schubert else
23475796c8dcSSimon Schubert pst->dependencies = 0;
23485796c8dcSSimon Schubert
23495796c8dcSSimon Schubert for (i = 0; i < num_includes; i++)
23505796c8dcSSimon Schubert {
23515796c8dcSSimon Schubert struct partial_symtab *subpst =
23525796c8dcSSimon Schubert allocate_psymtab (include_list[i], objfile);
23535796c8dcSSimon Schubert
23545796c8dcSSimon Schubert /* Copy the sesction_offsets array from the main psymtab. */
23555796c8dcSSimon Schubert subpst->section_offsets = pst->section_offsets;
23565796c8dcSSimon Schubert subpst->read_symtab_private =
2357cf7f2e2dSJohn Marino obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc));
23585796c8dcSSimon Schubert LDSYMOFF (subpst) =
23595796c8dcSSimon Schubert LDSYMLEN (subpst) =
23605796c8dcSSimon Schubert subpst->textlow =
23615796c8dcSSimon Schubert subpst->texthigh = 0;
23625796c8dcSSimon Schubert
23635796c8dcSSimon Schubert /* We could save slight bits of space by only making one of these,
23645796c8dcSSimon Schubert shared by the entire set of include files. FIXME-someday. */
23655796c8dcSSimon Schubert subpst->dependencies = (struct partial_symtab **)
23665796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack,
23675796c8dcSSimon Schubert sizeof (struct partial_symtab *));
23685796c8dcSSimon Schubert subpst->dependencies[0] = pst;
23695796c8dcSSimon Schubert subpst->number_of_dependencies = 1;
23705796c8dcSSimon Schubert
23715796c8dcSSimon Schubert subpst->globals_offset =
23725796c8dcSSimon Schubert subpst->n_global_syms =
23735796c8dcSSimon Schubert subpst->statics_offset =
23745796c8dcSSimon Schubert subpst->n_static_syms = 0;
23755796c8dcSSimon Schubert
23765796c8dcSSimon Schubert subpst->readin = 0;
23775796c8dcSSimon Schubert subpst->symtab = 0;
23785796c8dcSSimon Schubert subpst->read_symtab = pst->read_symtab;
23795796c8dcSSimon Schubert }
23805796c8dcSSimon Schubert
2381*ef5ccd6cSJohn Marino sort_pst_symbols (objfile, pst);
23825796c8dcSSimon Schubert
23835796c8dcSSimon Schubert if (num_includes == 0
23845796c8dcSSimon Schubert && number_dependencies == 0
23855796c8dcSSimon Schubert && pst->n_global_syms == 0
23865796c8dcSSimon Schubert && pst->n_static_syms == 0
23875796c8dcSSimon Schubert && has_line_numbers == 0)
23885796c8dcSSimon Schubert {
23895796c8dcSSimon Schubert /* Throw away this psymtab, it's empty. We can't deallocate it, since
23905796c8dcSSimon Schubert it is on the obstack, but we can forget to chain it on the list. */
23915796c8dcSSimon Schubert /* Empty psymtabs happen as a result of header files which don't have
23925796c8dcSSimon Schubert any symbols in them. There can be a lot of them. But this check
23935796c8dcSSimon Schubert is wrong, in that a psymtab with N_SLINE entries but nothing else
23945796c8dcSSimon Schubert is not empty, but we don't realize that. Fixing that without slowing
23955796c8dcSSimon Schubert things down might be tricky. */
23965796c8dcSSimon Schubert
2397*ef5ccd6cSJohn Marino discard_psymtab (objfile, pst);
23985796c8dcSSimon Schubert
23995796c8dcSSimon Schubert /* Indicate that psymtab was thrown away. */
24005796c8dcSSimon Schubert pst = (struct partial_symtab *) NULL;
24015796c8dcSSimon Schubert }
24025796c8dcSSimon Schubert return pst;
24035796c8dcSSimon Schubert }
24045796c8dcSSimon Schubert
24055796c8dcSSimon Schubert static void
dbx_psymtab_to_symtab_1(struct objfile * objfile,struct partial_symtab * pst)2406*ef5ccd6cSJohn Marino dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst)
24075796c8dcSSimon Schubert {
24085796c8dcSSimon Schubert struct cleanup *old_chain;
24095796c8dcSSimon Schubert int i;
24105796c8dcSSimon Schubert
24115796c8dcSSimon Schubert if (pst->readin)
24125796c8dcSSimon Schubert {
2413c50c785cSJohn Marino fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. "
2414c50c785cSJohn Marino "Shouldn't happen.\n",
24155796c8dcSSimon Schubert pst->filename);
24165796c8dcSSimon Schubert return;
24175796c8dcSSimon Schubert }
24185796c8dcSSimon Schubert
2419c50c785cSJohn Marino /* Read in all partial symtabs on which this one is dependent. */
24205796c8dcSSimon Schubert for (i = 0; i < pst->number_of_dependencies; i++)
24215796c8dcSSimon Schubert if (!pst->dependencies[i]->readin)
24225796c8dcSSimon Schubert {
24235796c8dcSSimon Schubert /* Inform about additional files that need to be read in. */
24245796c8dcSSimon Schubert if (info_verbose)
24255796c8dcSSimon Schubert {
24265796c8dcSSimon Schubert fputs_filtered (" ", gdb_stdout);
24275796c8dcSSimon Schubert wrap_here ("");
24285796c8dcSSimon Schubert fputs_filtered ("and ", gdb_stdout);
24295796c8dcSSimon Schubert wrap_here ("");
24305796c8dcSSimon Schubert printf_filtered ("%s...", pst->dependencies[i]->filename);
2431c50c785cSJohn Marino wrap_here (""); /* Flush output. */
24325796c8dcSSimon Schubert gdb_flush (gdb_stdout);
24335796c8dcSSimon Schubert }
2434*ef5ccd6cSJohn Marino dbx_psymtab_to_symtab_1 (objfile, pst->dependencies[i]);
24355796c8dcSSimon Schubert }
24365796c8dcSSimon Schubert
2437c50c785cSJohn Marino if (LDSYMLEN (pst)) /* Otherwise it's a dummy. */
24385796c8dcSSimon Schubert {
24395796c8dcSSimon Schubert /* Init stuff necessary for reading in symbols */
24405796c8dcSSimon Schubert stabsread_init ();
24415796c8dcSSimon Schubert buildsym_init ();
24425796c8dcSSimon Schubert old_chain = make_cleanup (really_free_pendings, 0);
24435796c8dcSSimon Schubert file_string_table_offset = FILE_STRING_OFFSET (pst);
24445796c8dcSSimon Schubert symbol_size = SYMBOL_SIZE (pst);
24455796c8dcSSimon Schubert
2446c50c785cSJohn Marino /* Read in this file's symbols. */
2447*ef5ccd6cSJohn Marino bfd_seek (objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
2448*ef5ccd6cSJohn Marino read_ofile_symtab (objfile, pst);
24495796c8dcSSimon Schubert
24505796c8dcSSimon Schubert do_cleanups (old_chain);
24515796c8dcSSimon Schubert }
24525796c8dcSSimon Schubert
24535796c8dcSSimon Schubert pst->readin = 1;
24545796c8dcSSimon Schubert }
24555796c8dcSSimon Schubert
24565796c8dcSSimon Schubert /* Read in all of the symbols for a given psymtab for real.
2457*ef5ccd6cSJohn Marino Be verbose about it if the user wants that. SELF is not NULL. */
24585796c8dcSSimon Schubert
24595796c8dcSSimon Schubert static void
dbx_read_symtab(struct partial_symtab * self,struct objfile * objfile)2460*ef5ccd6cSJohn Marino dbx_read_symtab (struct partial_symtab *self, struct objfile *objfile)
24615796c8dcSSimon Schubert {
24625796c8dcSSimon Schubert bfd *sym_bfd;
24635796c8dcSSimon Schubert struct cleanup *back_to = NULL;
24645796c8dcSSimon Schubert
2465*ef5ccd6cSJohn Marino if (self->readin)
24665796c8dcSSimon Schubert {
2467c50c785cSJohn Marino fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in. "
2468c50c785cSJohn Marino "Shouldn't happen.\n",
2469*ef5ccd6cSJohn Marino self->filename);
24705796c8dcSSimon Schubert return;
24715796c8dcSSimon Schubert }
24725796c8dcSSimon Schubert
2473*ef5ccd6cSJohn Marino if (LDSYMLEN (self) || self->number_of_dependencies)
24745796c8dcSSimon Schubert {
24755796c8dcSSimon Schubert /* Print the message now, before reading the string table,
24765796c8dcSSimon Schubert to avoid disconcerting pauses. */
24775796c8dcSSimon Schubert if (info_verbose)
24785796c8dcSSimon Schubert {
2479*ef5ccd6cSJohn Marino printf_filtered ("Reading in symbols for %s...", self->filename);
24805796c8dcSSimon Schubert gdb_flush (gdb_stdout);
24815796c8dcSSimon Schubert }
24825796c8dcSSimon Schubert
2483*ef5ccd6cSJohn Marino sym_bfd = objfile->obfd;
24845796c8dcSSimon Schubert
24855796c8dcSSimon Schubert next_symbol_text_func = dbx_next_symbol_text;
24865796c8dcSSimon Schubert
2487*ef5ccd6cSJohn Marino if (DBX_STAB_SECTION (objfile))
24885796c8dcSSimon Schubert {
24895796c8dcSSimon Schubert stabs_data
2490*ef5ccd6cSJohn Marino = symfile_relocate_debug_section (objfile,
2491*ef5ccd6cSJohn Marino DBX_STAB_SECTION (objfile),
24925796c8dcSSimon Schubert NULL);
2493cf7f2e2dSJohn Marino
24945796c8dcSSimon Schubert if (stabs_data)
24955796c8dcSSimon Schubert back_to = make_cleanup (free_current_contents,
24965796c8dcSSimon Schubert (void *) &stabs_data);
24975796c8dcSSimon Schubert }
24985796c8dcSSimon Schubert
2499*ef5ccd6cSJohn Marino dbx_psymtab_to_symtab_1 (objfile, self);
25005796c8dcSSimon Schubert
25015796c8dcSSimon Schubert if (back_to)
25025796c8dcSSimon Schubert do_cleanups (back_to);
25035796c8dcSSimon Schubert
25045796c8dcSSimon Schubert /* Match with global symbols. This only needs to be done once,
25055796c8dcSSimon Schubert after all of the symtabs and dependencies have been read in. */
2506*ef5ccd6cSJohn Marino scan_file_globals (objfile);
25075796c8dcSSimon Schubert
25085796c8dcSSimon Schubert /* Finish up the debug error message. */
25095796c8dcSSimon Schubert if (info_verbose)
25105796c8dcSSimon Schubert printf_filtered ("done.\n");
25115796c8dcSSimon Schubert }
25125796c8dcSSimon Schubert }
25135796c8dcSSimon Schubert
25145796c8dcSSimon Schubert /* Read in a defined section of a specific object file's symbols. */
25155796c8dcSSimon Schubert
25165796c8dcSSimon Schubert static void
read_ofile_symtab(struct objfile * objfile,struct partial_symtab * pst)2517*ef5ccd6cSJohn Marino read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
25185796c8dcSSimon Schubert {
25195796c8dcSSimon Schubert char *namestring;
25205796c8dcSSimon Schubert struct external_nlist *bufp;
25215796c8dcSSimon Schubert struct internal_nlist nlist;
25225796c8dcSSimon Schubert unsigned char type;
25235796c8dcSSimon Schubert unsigned max_symnum;
25245796c8dcSSimon Schubert bfd *abfd;
25255796c8dcSSimon Schubert int sym_offset; /* Offset to start of symbols to read */
25265796c8dcSSimon Schubert int sym_size; /* Size of symbols to read */
25275796c8dcSSimon Schubert CORE_ADDR text_offset; /* Start of text segment for symbols */
25285796c8dcSSimon Schubert int text_size; /* Size of text segment for symbols */
25295796c8dcSSimon Schubert struct section_offsets *section_offsets;
25305796c8dcSSimon Schubert
25315796c8dcSSimon Schubert sym_offset = LDSYMOFF (pst);
25325796c8dcSSimon Schubert sym_size = LDSYMLEN (pst);
25335796c8dcSSimon Schubert text_offset = pst->textlow;
25345796c8dcSSimon Schubert text_size = pst->texthigh - pst->textlow;
25355796c8dcSSimon Schubert /* This cannot be simply objfile->section_offsets because of
25365796c8dcSSimon Schubert elfstab_offset_sections() which initializes the psymtab section
25375796c8dcSSimon Schubert offsets information in a special way, and that is different from
25385796c8dcSSimon Schubert objfile->section_offsets. */
25395796c8dcSSimon Schubert section_offsets = pst->section_offsets;
25405796c8dcSSimon Schubert
2541a45ae5f8SJohn Marino dbxread_objfile = objfile;
25425796c8dcSSimon Schubert subfile_stack = NULL;
25435796c8dcSSimon Schubert
25445796c8dcSSimon Schubert stringtab_global = DBX_STRINGTAB (objfile);
2545*ef5ccd6cSJohn Marino set_last_source_file (NULL);
25465796c8dcSSimon Schubert
25475796c8dcSSimon Schubert abfd = objfile->obfd;
2548c50c785cSJohn Marino symfile_bfd = objfile->obfd; /* Implicit param to next_text_symbol. */
25495796c8dcSSimon Schubert symbuf_end = symbuf_idx = 0;
25505796c8dcSSimon Schubert symbuf_read = 0;
25515796c8dcSSimon Schubert symbuf_left = sym_offset + sym_size;
25525796c8dcSSimon Schubert
25535796c8dcSSimon Schubert /* It is necessary to actually read one symbol *before* the start
25545796c8dcSSimon Schubert of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
25555796c8dcSSimon Schubert occurs before the N_SO symbol.
25565796c8dcSSimon Schubert
25575796c8dcSSimon Schubert Detecting this in read_dbx_symtab
25585796c8dcSSimon Schubert would slow down initial readin, so we look for it here instead. */
25595796c8dcSSimon Schubert if (!processing_acc_compilation && sym_offset >= (int) symbol_size)
25605796c8dcSSimon Schubert {
25615796c8dcSSimon Schubert stabs_seek (sym_offset - symbol_size);
25625796c8dcSSimon Schubert fill_symbuf (abfd);
25635796c8dcSSimon Schubert bufp = &symbuf[symbuf_idx++];
25645796c8dcSSimon Schubert INTERNALIZE_SYMBOL (nlist, bufp, abfd);
25655796c8dcSSimon Schubert OBJSTAT (objfile, n_stabs++);
25665796c8dcSSimon Schubert
25675796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
25685796c8dcSSimon Schubert
25695796c8dcSSimon Schubert processing_gcc_compilation = 0;
25705796c8dcSSimon Schubert if (nlist.n_type == N_TEXT)
25715796c8dcSSimon Schubert {
25725796c8dcSSimon Schubert const char *tempstring = namestring;
25735796c8dcSSimon Schubert
25745796c8dcSSimon Schubert if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
25755796c8dcSSimon Schubert processing_gcc_compilation = 1;
25765796c8dcSSimon Schubert else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
25775796c8dcSSimon Schubert processing_gcc_compilation = 2;
25785796c8dcSSimon Schubert if (tempstring[0] == bfd_get_symbol_leading_char (symfile_bfd))
25795796c8dcSSimon Schubert ++tempstring;
25805796c8dcSSimon Schubert if (strncmp (tempstring, "__gnu_compiled", 14) == 0)
25815796c8dcSSimon Schubert processing_gcc_compilation = 2;
25825796c8dcSSimon Schubert }
25835796c8dcSSimon Schubert
25845796c8dcSSimon Schubert /* Try to select a C++ demangling based on the compilation unit
25855796c8dcSSimon Schubert producer. */
25865796c8dcSSimon Schubert
25875796c8dcSSimon Schubert #if 0
25885796c8dcSSimon Schubert /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
25895796c8dcSSimon Schubert know whether it will use the old style or v3 mangling. */
25905796c8dcSSimon Schubert if (processing_gcc_compilation)
25915796c8dcSSimon Schubert {
25925796c8dcSSimon Schubert if (AUTO_DEMANGLING)
25935796c8dcSSimon Schubert {
25945796c8dcSSimon Schubert set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
25955796c8dcSSimon Schubert }
25965796c8dcSSimon Schubert }
25975796c8dcSSimon Schubert #endif
25985796c8dcSSimon Schubert }
25995796c8dcSSimon Schubert else
26005796c8dcSSimon Schubert {
26015796c8dcSSimon Schubert /* The N_SO starting this symtab is the first symbol, so we
26025796c8dcSSimon Schubert better not check the symbol before it. I'm not this can
26035796c8dcSSimon Schubert happen, but it doesn't hurt to check for it. */
26045796c8dcSSimon Schubert stabs_seek (sym_offset);
26055796c8dcSSimon Schubert processing_gcc_compilation = 0;
26065796c8dcSSimon Schubert }
26075796c8dcSSimon Schubert
26085796c8dcSSimon Schubert if (symbuf_idx == symbuf_end)
26095796c8dcSSimon Schubert fill_symbuf (abfd);
26105796c8dcSSimon Schubert bufp = &symbuf[symbuf_idx];
26115796c8dcSSimon Schubert if (bfd_h_get_8 (abfd, bufp->e_type) != N_SO)
26125796c8dcSSimon Schubert error (_("First symbol in segment of executable not a source symbol"));
26135796c8dcSSimon Schubert
26145796c8dcSSimon Schubert max_symnum = sym_size / symbol_size;
26155796c8dcSSimon Schubert
26165796c8dcSSimon Schubert for (symnum = 0;
26175796c8dcSSimon Schubert symnum < max_symnum;
26185796c8dcSSimon Schubert symnum++)
26195796c8dcSSimon Schubert {
2620c50c785cSJohn Marino QUIT; /* Allow this to be interruptable. */
26215796c8dcSSimon Schubert if (symbuf_idx == symbuf_end)
26225796c8dcSSimon Schubert fill_symbuf (abfd);
26235796c8dcSSimon Schubert bufp = &symbuf[symbuf_idx++];
26245796c8dcSSimon Schubert INTERNALIZE_SYMBOL (nlist, bufp, abfd);
26255796c8dcSSimon Schubert OBJSTAT (objfile, n_stabs++);
26265796c8dcSSimon Schubert
26275796c8dcSSimon Schubert type = bfd_h_get_8 (abfd, bufp->e_type);
26285796c8dcSSimon Schubert
26295796c8dcSSimon Schubert namestring = set_namestring (objfile, &nlist);
26305796c8dcSSimon Schubert
26315796c8dcSSimon Schubert if (type & N_STAB)
26325796c8dcSSimon Schubert {
26335796c8dcSSimon Schubert if (sizeof (nlist.n_value) > 4
26345796c8dcSSimon Schubert /* We are a 64-bit debugger debugging a 32-bit program. */
26355796c8dcSSimon Schubert && (type == N_LSYM || type == N_PSYM))
26365796c8dcSSimon Schubert /* We have to be careful with the n_value in the case of N_LSYM
26375796c8dcSSimon Schubert and N_PSYM entries, because they are signed offsets from frame
26385796c8dcSSimon Schubert pointer, but we actually read them as unsigned 32-bit values.
26395796c8dcSSimon Schubert This is not a problem for 32-bit debuggers, for which negative
26405796c8dcSSimon Schubert values end up being interpreted correctly (as negative
26415796c8dcSSimon Schubert offsets) due to integer overflow.
26425796c8dcSSimon Schubert But we need to sign-extend the value for 64-bit debuggers,
26435796c8dcSSimon Schubert or we'll end up interpreting negative values as very large
26445796c8dcSSimon Schubert positive offsets. */
26455796c8dcSSimon Schubert nlist.n_value = (nlist.n_value ^ 0x80000000) - 0x80000000;
26465796c8dcSSimon Schubert process_one_symbol (type, nlist.n_desc, nlist.n_value,
26475796c8dcSSimon Schubert namestring, section_offsets, objfile);
26485796c8dcSSimon Schubert }
26495796c8dcSSimon Schubert /* We skip checking for a new .o or -l file; that should never
26505796c8dcSSimon Schubert happen in this routine. */
26515796c8dcSSimon Schubert else if (type == N_TEXT)
26525796c8dcSSimon Schubert {
26535796c8dcSSimon Schubert /* I don't think this code will ever be executed, because
26545796c8dcSSimon Schubert the GCC_COMPILED_FLAG_SYMBOL usually is right before
26555796c8dcSSimon Schubert the N_SO symbol which starts this source file.
26565796c8dcSSimon Schubert However, there is no reason not to accept
26575796c8dcSSimon Schubert the GCC_COMPILED_FLAG_SYMBOL anywhere. */
26585796c8dcSSimon Schubert
26595796c8dcSSimon Schubert if (strcmp (namestring, GCC_COMPILED_FLAG_SYMBOL) == 0)
26605796c8dcSSimon Schubert processing_gcc_compilation = 1;
26615796c8dcSSimon Schubert else if (strcmp (namestring, GCC2_COMPILED_FLAG_SYMBOL) == 0)
26625796c8dcSSimon Schubert processing_gcc_compilation = 2;
26635796c8dcSSimon Schubert
26645796c8dcSSimon Schubert #if 0
26655796c8dcSSimon Schubert /* For now, stay with AUTO_DEMANGLING for g++ output, as we don't
26665796c8dcSSimon Schubert know whether it will use the old style or v3 mangling. */
26675796c8dcSSimon Schubert if (AUTO_DEMANGLING)
26685796c8dcSSimon Schubert {
26695796c8dcSSimon Schubert set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
26705796c8dcSSimon Schubert }
26715796c8dcSSimon Schubert #endif
26725796c8dcSSimon Schubert }
26735796c8dcSSimon Schubert else if (type & N_EXT || type == (unsigned char) N_TEXT
2674cf7f2e2dSJohn Marino || type == (unsigned char) N_NBTEXT)
26755796c8dcSSimon Schubert {
26765796c8dcSSimon Schubert /* Global symbol: see if we came across a dbx defintion for
26775796c8dcSSimon Schubert a corresponding symbol. If so, store the value. Remove
26785796c8dcSSimon Schubert syms from the chain when their values are stored, but
26795796c8dcSSimon Schubert search the whole chain, as there may be several syms from
26805796c8dcSSimon Schubert different files with the same name. */
26815796c8dcSSimon Schubert /* This is probably not true. Since the files will be read
26825796c8dcSSimon Schubert in one at a time, each reference to a global symbol will
26835796c8dcSSimon Schubert be satisfied in each file as it appears. So we skip this
26845796c8dcSSimon Schubert section. */
26855796c8dcSSimon Schubert ;
26865796c8dcSSimon Schubert }
26875796c8dcSSimon Schubert }
26885796c8dcSSimon Schubert
26895796c8dcSSimon Schubert /* In a Solaris elf file, this variable, which comes from the
26905796c8dcSSimon Schubert value of the N_SO symbol, will still be 0. Luckily, text_offset,
26915796c8dcSSimon Schubert which comes from pst->textlow is correct. */
26925796c8dcSSimon Schubert if (last_source_start_addr == 0)
26935796c8dcSSimon Schubert last_source_start_addr = text_offset;
26945796c8dcSSimon Schubert
26955796c8dcSSimon Schubert /* In reordered executables last_source_start_addr may not be the
26965796c8dcSSimon Schubert lower bound for this symtab, instead use text_offset which comes
26975796c8dcSSimon Schubert from pst->textlow which is correct. */
26985796c8dcSSimon Schubert if (last_source_start_addr > text_offset)
26995796c8dcSSimon Schubert last_source_start_addr = text_offset;
27005796c8dcSSimon Schubert
27015796c8dcSSimon Schubert pst->symtab = end_symtab (text_offset + text_size, objfile,
27025796c8dcSSimon Schubert SECT_OFF_TEXT (objfile));
27035796c8dcSSimon Schubert
27045796c8dcSSimon Schubert end_stabs ();
27055796c8dcSSimon Schubert
2706a45ae5f8SJohn Marino dbxread_objfile = NULL;
27075796c8dcSSimon Schubert }
27085796c8dcSSimon Schubert
27095796c8dcSSimon Schubert
2710*ef5ccd6cSJohn Marino /* Record the namespace that the function defined by SYMBOL was
2711*ef5ccd6cSJohn Marino defined in, if necessary. BLOCK is the associated block; use
2712*ef5ccd6cSJohn Marino OBSTACK for allocation. */
2713*ef5ccd6cSJohn Marino
2714*ef5ccd6cSJohn Marino static void
cp_set_block_scope(const struct symbol * symbol,struct block * block,struct obstack * obstack)2715*ef5ccd6cSJohn Marino cp_set_block_scope (const struct symbol *symbol,
2716*ef5ccd6cSJohn Marino struct block *block,
2717*ef5ccd6cSJohn Marino struct obstack *obstack)
2718*ef5ccd6cSJohn Marino {
2719*ef5ccd6cSJohn Marino if (SYMBOL_DEMANGLED_NAME (symbol) != NULL)
2720*ef5ccd6cSJohn Marino {
2721*ef5ccd6cSJohn Marino /* Try to figure out the appropriate namespace from the
2722*ef5ccd6cSJohn Marino demangled name. */
2723*ef5ccd6cSJohn Marino
2724*ef5ccd6cSJohn Marino /* FIXME: carlton/2003-04-15: If the function in question is
2725*ef5ccd6cSJohn Marino a method of a class, the name will actually include the
2726*ef5ccd6cSJohn Marino name of the class as well. This should be harmless, but
2727*ef5ccd6cSJohn Marino is a little unfortunate. */
2728*ef5ccd6cSJohn Marino
2729*ef5ccd6cSJohn Marino const char *name = SYMBOL_DEMANGLED_NAME (symbol);
2730*ef5ccd6cSJohn Marino unsigned int prefix_len = cp_entire_prefix_len (name);
2731*ef5ccd6cSJohn Marino
2732*ef5ccd6cSJohn Marino block_set_scope (block,
2733*ef5ccd6cSJohn Marino obstack_copy0 (obstack, name, prefix_len),
2734*ef5ccd6cSJohn Marino obstack);
2735*ef5ccd6cSJohn Marino }
2736*ef5ccd6cSJohn Marino }
2737*ef5ccd6cSJohn Marino
27385796c8dcSSimon Schubert /* This handles a single symbol from the symbol-file, building symbols
27395796c8dcSSimon Schubert into a GDB symtab. It takes these arguments and an implicit argument.
27405796c8dcSSimon Schubert
27415796c8dcSSimon Schubert TYPE is the type field of the ".stab" symbol entry.
27425796c8dcSSimon Schubert DESC is the desc field of the ".stab" entry.
27435796c8dcSSimon Schubert VALU is the value field of the ".stab" entry.
27445796c8dcSSimon Schubert NAME is the symbol name, in our address space.
27455796c8dcSSimon Schubert SECTION_OFFSETS is a set of amounts by which the sections of this
27465796c8dcSSimon Schubert object file were relocated when it was loaded into memory. Note
27475796c8dcSSimon Schubert that these section_offsets are not the objfile->section_offsets but
27485796c8dcSSimon Schubert the pst->section_offsets. All symbols that refer to memory
27495796c8dcSSimon Schubert locations need to be offset by these amounts.
27505796c8dcSSimon Schubert OBJFILE is the object file from which we are reading symbols. It
27515796c8dcSSimon Schubert is used in end_symtab. */
27525796c8dcSSimon Schubert
27535796c8dcSSimon Schubert void
process_one_symbol(int type,int desc,CORE_ADDR valu,char * name,struct section_offsets * section_offsets,struct objfile * objfile)27545796c8dcSSimon Schubert process_one_symbol (int type, int desc, CORE_ADDR valu, char *name,
27555796c8dcSSimon Schubert struct section_offsets *section_offsets,
27565796c8dcSSimon Schubert struct objfile *objfile)
27575796c8dcSSimon Schubert {
27585796c8dcSSimon Schubert struct gdbarch *gdbarch = get_objfile_arch (objfile);
27595796c8dcSSimon Schubert struct context_stack *new;
27605796c8dcSSimon Schubert /* This remembers the address of the start of a function. It is
27615796c8dcSSimon Schubert used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
27625796c8dcSSimon Schubert are relative to the current function's start address. On systems
27635796c8dcSSimon Schubert other than Solaris 2, this just holds the SECT_OFF_TEXT value,
27645796c8dcSSimon Schubert and is used to relocate these symbol types rather than
27655796c8dcSSimon Schubert SECTION_OFFSETS. */
27665796c8dcSSimon Schubert static CORE_ADDR function_start_offset;
27675796c8dcSSimon Schubert
27685796c8dcSSimon Schubert /* This holds the address of the start of a function, without the
27695796c8dcSSimon Schubert system peculiarities of function_start_offset. */
27705796c8dcSSimon Schubert static CORE_ADDR last_function_start;
27715796c8dcSSimon Schubert
27725796c8dcSSimon Schubert /* If this is nonzero, we've seen an N_SLINE since the start of the
27735796c8dcSSimon Schubert current function. We use this to tell us to move the first sline
27745796c8dcSSimon Schubert to the beginning of the function regardless of what its given
27755796c8dcSSimon Schubert value is. */
27765796c8dcSSimon Schubert static int sline_found_in_function = 1;
27775796c8dcSSimon Schubert
27785796c8dcSSimon Schubert /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this
27795796c8dcSSimon Schubert source file. Used to detect the SunPRO solaris compiler. */
27805796c8dcSSimon Schubert static int n_opt_found;
27815796c8dcSSimon Schubert
27825796c8dcSSimon Schubert /* The stab type used for the definition of the last function.
27835796c8dcSSimon Schubert N_STSYM or N_GSYM for SunOS4 acc; N_FUN for other compilers. */
27845796c8dcSSimon Schubert static int function_stab_type = 0;
27855796c8dcSSimon Schubert
27865796c8dcSSimon Schubert if (!block_address_function_relative)
27875796c8dcSSimon Schubert {
27885796c8dcSSimon Schubert /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
27895796c8dcSSimon Schubert function start address, so just use the text offset. */
27905796c8dcSSimon Schubert function_start_offset =
27915796c8dcSSimon Schubert ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
27925796c8dcSSimon Schubert }
27935796c8dcSSimon Schubert
27945796c8dcSSimon Schubert /* Something is wrong if we see real data before seeing a source
27955796c8dcSSimon Schubert file name. */
27965796c8dcSSimon Schubert
2797*ef5ccd6cSJohn Marino if (get_last_source_file () == NULL && type != (unsigned char) N_SO)
27985796c8dcSSimon Schubert {
27995796c8dcSSimon Schubert /* Ignore any symbols which appear before an N_SO symbol.
28005796c8dcSSimon Schubert Currently no one puts symbols there, but we should deal
28015796c8dcSSimon Schubert gracefully with the case. A complain()t might be in order,
28025796c8dcSSimon Schubert but this should not be an error (). */
28035796c8dcSSimon Schubert return;
28045796c8dcSSimon Schubert }
28055796c8dcSSimon Schubert
28065796c8dcSSimon Schubert switch (type)
28075796c8dcSSimon Schubert {
28085796c8dcSSimon Schubert case N_FUN:
28095796c8dcSSimon Schubert case N_FNAME:
28105796c8dcSSimon Schubert
28115796c8dcSSimon Schubert if (*name == '\000')
28125796c8dcSSimon Schubert {
28135796c8dcSSimon Schubert /* This N_FUN marks the end of a function. This closes off
28145796c8dcSSimon Schubert the current block. */
28155796c8dcSSimon Schubert struct block *block;
28165796c8dcSSimon Schubert
28175796c8dcSSimon Schubert if (context_stack_depth <= 0)
28185796c8dcSSimon Schubert {
28195796c8dcSSimon Schubert lbrac_mismatch_complaint (symnum);
28205796c8dcSSimon Schubert break;
28215796c8dcSSimon Schubert }
28225796c8dcSSimon Schubert
28235796c8dcSSimon Schubert /* The following check is added before recording line 0 at
28245796c8dcSSimon Schubert end of function so as to handle hand-generated stabs
28255796c8dcSSimon Schubert which may have an N_FUN stabs at the end of the function,
28265796c8dcSSimon Schubert but no N_SLINE stabs. */
28275796c8dcSSimon Schubert if (sline_found_in_function)
28285796c8dcSSimon Schubert {
28295796c8dcSSimon Schubert CORE_ADDR addr = last_function_start + valu;
2830cf7f2e2dSJohn Marino
28315796c8dcSSimon Schubert record_line (current_subfile, 0,
28325796c8dcSSimon Schubert gdbarch_addr_bits_remove (gdbarch, addr));
28335796c8dcSSimon Schubert }
28345796c8dcSSimon Schubert
28355796c8dcSSimon Schubert within_function = 0;
28365796c8dcSSimon Schubert new = pop_context ();
28375796c8dcSSimon Schubert
28385796c8dcSSimon Schubert /* Make a block for the local symbols within. */
28395796c8dcSSimon Schubert block = finish_block (new->name, &local_symbols, new->old_blocks,
28405796c8dcSSimon Schubert new->start_addr, new->start_addr + valu,
28415796c8dcSSimon Schubert objfile);
28425796c8dcSSimon Schubert
28435796c8dcSSimon Schubert /* For C++, set the block's scope. */
28445796c8dcSSimon Schubert if (SYMBOL_LANGUAGE (new->name) == language_cplus)
2845*ef5ccd6cSJohn Marino cp_set_block_scope (new->name, block, &objfile->objfile_obstack);
28465796c8dcSSimon Schubert
28475796c8dcSSimon Schubert /* May be switching to an assembler file which may not be using
28485796c8dcSSimon Schubert block relative stabs, so reset the offset. */
28495796c8dcSSimon Schubert if (block_address_function_relative)
28505796c8dcSSimon Schubert function_start_offset = 0;
28515796c8dcSSimon Schubert
28525796c8dcSSimon Schubert break;
28535796c8dcSSimon Schubert }
28545796c8dcSSimon Schubert
28555796c8dcSSimon Schubert sline_found_in_function = 0;
28565796c8dcSSimon Schubert
28575796c8dcSSimon Schubert /* Relocate for dynamic loading. */
28585796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
2859*ef5ccd6cSJohn Marino valu = gdbarch_addr_bits_remove (gdbarch, valu);
28605796c8dcSSimon Schubert last_function_start = valu;
28615796c8dcSSimon Schubert
28625796c8dcSSimon Schubert goto define_a_symbol;
28635796c8dcSSimon Schubert
28645796c8dcSSimon Schubert case N_LBRAC:
28655796c8dcSSimon Schubert /* This "symbol" just indicates the start of an inner lexical
28665796c8dcSSimon Schubert context within a function. */
28675796c8dcSSimon Schubert
28685796c8dcSSimon Schubert /* Ignore extra outermost context from SunPRO cc and acc. */
28695796c8dcSSimon Schubert if (n_opt_found && desc == 1)
28705796c8dcSSimon Schubert break;
28715796c8dcSSimon Schubert
28725796c8dcSSimon Schubert if (block_address_function_relative)
28735796c8dcSSimon Schubert /* Relocate for Sun ELF acc fn-relative syms. */
28745796c8dcSSimon Schubert valu += function_start_offset;
28755796c8dcSSimon Schubert else
28765796c8dcSSimon Schubert /* On most machines, the block addresses are relative to the
28775796c8dcSSimon Schubert N_SO, the linker did not relocate them (sigh). */
28785796c8dcSSimon Schubert valu += last_source_start_addr;
28795796c8dcSSimon Schubert
2880c50c785cSJohn Marino push_context (desc, valu);
28815796c8dcSSimon Schubert break;
28825796c8dcSSimon Schubert
28835796c8dcSSimon Schubert case N_RBRAC:
28845796c8dcSSimon Schubert /* This "symbol" just indicates the end of an inner lexical
28855796c8dcSSimon Schubert context that was started with N_LBRAC. */
28865796c8dcSSimon Schubert
28875796c8dcSSimon Schubert /* Ignore extra outermost context from SunPRO cc and acc. */
28885796c8dcSSimon Schubert if (n_opt_found && desc == 1)
28895796c8dcSSimon Schubert break;
28905796c8dcSSimon Schubert
28915796c8dcSSimon Schubert if (block_address_function_relative)
28925796c8dcSSimon Schubert /* Relocate for Sun ELF acc fn-relative syms. */
28935796c8dcSSimon Schubert valu += function_start_offset;
28945796c8dcSSimon Schubert else
28955796c8dcSSimon Schubert /* On most machines, the block addresses are relative to the
28965796c8dcSSimon Schubert N_SO, the linker did not relocate them (sigh). */
28975796c8dcSSimon Schubert valu += last_source_start_addr;
28985796c8dcSSimon Schubert
28995796c8dcSSimon Schubert if (context_stack_depth <= 0)
29005796c8dcSSimon Schubert {
29015796c8dcSSimon Schubert lbrac_mismatch_complaint (symnum);
29025796c8dcSSimon Schubert break;
29035796c8dcSSimon Schubert }
29045796c8dcSSimon Schubert
29055796c8dcSSimon Schubert new = pop_context ();
29065796c8dcSSimon Schubert if (desc != new->depth)
29075796c8dcSSimon Schubert lbrac_mismatch_complaint (symnum);
29085796c8dcSSimon Schubert
29095796c8dcSSimon Schubert if (local_symbols != NULL)
29105796c8dcSSimon Schubert {
29115796c8dcSSimon Schubert /* GCC development snapshots from March to December of
29125796c8dcSSimon Schubert 2000 would output N_LSYM entries after N_LBRAC
29135796c8dcSSimon Schubert entries. As a consequence, these symbols are simply
29145796c8dcSSimon Schubert discarded. Complain if this is the case. */
2915c50c785cSJohn Marino complaint (&symfile_complaints,
2916c50c785cSJohn Marino _("misplaced N_LBRAC entry; discarding local "
2917c50c785cSJohn Marino "symbols which have no enclosing block"));
29185796c8dcSSimon Schubert }
29195796c8dcSSimon Schubert local_symbols = new->locals;
29205796c8dcSSimon Schubert
29215796c8dcSSimon Schubert if (context_stack_depth > 1)
29225796c8dcSSimon Schubert {
29235796c8dcSSimon Schubert /* This is not the outermost LBRAC...RBRAC pair in the
29245796c8dcSSimon Schubert function, its local symbols preceded it, and are the ones
29255796c8dcSSimon Schubert just recovered from the context stack. Define the block
29265796c8dcSSimon Schubert for them (but don't bother if the block contains no
29275796c8dcSSimon Schubert symbols. Should we complain on blocks without symbols?
29285796c8dcSSimon Schubert I can't think of any useful purpose for them). */
29295796c8dcSSimon Schubert if (local_symbols != NULL)
29305796c8dcSSimon Schubert {
29315796c8dcSSimon Schubert /* Muzzle a compiler bug that makes end < start.
29325796c8dcSSimon Schubert
29335796c8dcSSimon Schubert ??? Which compilers? Is this ever harmful?. */
29345796c8dcSSimon Schubert if (new->start_addr > valu)
29355796c8dcSSimon Schubert {
29365796c8dcSSimon Schubert complaint (&symfile_complaints,
29375796c8dcSSimon Schubert _("block start larger than block end"));
29385796c8dcSSimon Schubert new->start_addr = valu;
29395796c8dcSSimon Schubert }
29405796c8dcSSimon Schubert /* Make a block for the local symbols within. */
29415796c8dcSSimon Schubert finish_block (0, &local_symbols, new->old_blocks,
29425796c8dcSSimon Schubert new->start_addr, valu, objfile);
29435796c8dcSSimon Schubert }
29445796c8dcSSimon Schubert }
29455796c8dcSSimon Schubert else
29465796c8dcSSimon Schubert {
29475796c8dcSSimon Schubert /* This is the outermost LBRAC...RBRAC pair. There is no
29485796c8dcSSimon Schubert need to do anything; leave the symbols that preceded it
29495796c8dcSSimon Schubert to be attached to the function's own block. We need to
29505796c8dcSSimon Schubert indicate that we just moved outside of the function. */
29515796c8dcSSimon Schubert within_function = 0;
29525796c8dcSSimon Schubert }
29535796c8dcSSimon Schubert
29545796c8dcSSimon Schubert break;
29555796c8dcSSimon Schubert
29565796c8dcSSimon Schubert case N_FN:
29575796c8dcSSimon Schubert case N_FN_SEQ:
29585796c8dcSSimon Schubert /* This kind of symbol indicates the start of an object file.
29595796c8dcSSimon Schubert Relocate for dynamic loading. */
29605796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
29615796c8dcSSimon Schubert break;
29625796c8dcSSimon Schubert
29635796c8dcSSimon Schubert case N_SO:
29645796c8dcSSimon Schubert /* This type of symbol indicates the start of data for one
29655796c8dcSSimon Schubert source file. Finish the symbol table of the previous source
29665796c8dcSSimon Schubert file (if any) and start accumulating a new symbol table.
29675796c8dcSSimon Schubert Relocate for dynamic loading. */
29685796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
29695796c8dcSSimon Schubert
29705796c8dcSSimon Schubert n_opt_found = 0;
29715796c8dcSSimon Schubert
2972*ef5ccd6cSJohn Marino if (get_last_source_file ())
29735796c8dcSSimon Schubert {
29745796c8dcSSimon Schubert /* Check if previous symbol was also an N_SO (with some
29755796c8dcSSimon Schubert sanity checks). If so, that one was actually the
29765796c8dcSSimon Schubert directory name, and the current one is the real file
29775796c8dcSSimon Schubert name. Patch things up. */
29785796c8dcSSimon Schubert if (previous_stab_code == (unsigned char) N_SO)
29795796c8dcSSimon Schubert {
29805796c8dcSSimon Schubert patch_subfile_names (current_subfile, name);
2981c50c785cSJohn Marino break; /* Ignore repeated SOs. */
29825796c8dcSSimon Schubert }
29835796c8dcSSimon Schubert end_symtab (valu, objfile, SECT_OFF_TEXT (objfile));
29845796c8dcSSimon Schubert end_stabs ();
29855796c8dcSSimon Schubert }
29865796c8dcSSimon Schubert
29875796c8dcSSimon Schubert /* Null name means this just marks the end of text for this .o
29885796c8dcSSimon Schubert file. Don't start a new symtab in this case. */
29895796c8dcSSimon Schubert if (*name == '\000')
29905796c8dcSSimon Schubert break;
29915796c8dcSSimon Schubert
29925796c8dcSSimon Schubert if (block_address_function_relative)
29935796c8dcSSimon Schubert function_start_offset = 0;
29945796c8dcSSimon Schubert
29955796c8dcSSimon Schubert start_stabs ();
29965796c8dcSSimon Schubert start_symtab (name, NULL, valu);
29975796c8dcSSimon Schubert record_debugformat ("stabs");
29985796c8dcSSimon Schubert break;
29995796c8dcSSimon Schubert
30005796c8dcSSimon Schubert case N_SOL:
30015796c8dcSSimon Schubert /* This type of symbol indicates the start of data for a
30025796c8dcSSimon Schubert sub-source-file, one whose contents were copied or included
30035796c8dcSSimon Schubert in the compilation of the main source file (whose name was
30045796c8dcSSimon Schubert given in the N_SO symbol). Relocate for dynamic loading. */
30055796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
30065796c8dcSSimon Schubert start_subfile (name, current_subfile->dirname);
30075796c8dcSSimon Schubert break;
30085796c8dcSSimon Schubert
30095796c8dcSSimon Schubert case N_BINCL:
30105796c8dcSSimon Schubert push_subfile ();
30115796c8dcSSimon Schubert add_new_header_file (name, valu);
30125796c8dcSSimon Schubert start_subfile (name, current_subfile->dirname);
30135796c8dcSSimon Schubert break;
30145796c8dcSSimon Schubert
30155796c8dcSSimon Schubert case N_EINCL:
30165796c8dcSSimon Schubert start_subfile (pop_subfile (), current_subfile->dirname);
30175796c8dcSSimon Schubert break;
30185796c8dcSSimon Schubert
30195796c8dcSSimon Schubert case N_EXCL:
30205796c8dcSSimon Schubert add_old_header_file (name, valu);
30215796c8dcSSimon Schubert break;
30225796c8dcSSimon Schubert
30235796c8dcSSimon Schubert case N_SLINE:
30245796c8dcSSimon Schubert /* This type of "symbol" really just records one line-number --
30255796c8dcSSimon Schubert core-address correspondence. Enter it in the line list for
30265796c8dcSSimon Schubert this symbol table. */
30275796c8dcSSimon Schubert
30285796c8dcSSimon Schubert /* Relocate for dynamic loading and for ELF acc
30295796c8dcSSimon Schubert function-relative symbols. */
30305796c8dcSSimon Schubert valu += function_start_offset;
30315796c8dcSSimon Schubert
30325796c8dcSSimon Schubert /* GCC 2.95.3 emits the first N_SLINE stab somwehere in the
30335796c8dcSSimon Schubert middle of the prologue instead of right at the start of the
30345796c8dcSSimon Schubert function. To deal with this we record the address for the
30355796c8dcSSimon Schubert first N_SLINE stab to be the start of the function instead of
30365796c8dcSSimon Schubert the listed location. We really shouldn't to this. When
30375796c8dcSSimon Schubert compiling with optimization, this first N_SLINE stab might be
30385796c8dcSSimon Schubert optimized away. Other (non-GCC) compilers don't emit this
30395796c8dcSSimon Schubert stab at all. There is no real harm in having an extra
30405796c8dcSSimon Schubert numbered line, although it can be a bit annoying for the
30415796c8dcSSimon Schubert user. However, it totally screws up our testsuite.
30425796c8dcSSimon Schubert
30435796c8dcSSimon Schubert So for now, keep adjusting the address of the first N_SLINE
30445796c8dcSSimon Schubert stab, but only for code compiled with GCC. */
30455796c8dcSSimon Schubert
30465796c8dcSSimon Schubert if (within_function && sline_found_in_function == 0)
30475796c8dcSSimon Schubert {
30485796c8dcSSimon Schubert CORE_ADDR addr = processing_gcc_compilation == 2 ?
30495796c8dcSSimon Schubert last_function_start : valu;
3050cf7f2e2dSJohn Marino
30515796c8dcSSimon Schubert record_line (current_subfile, desc,
30525796c8dcSSimon Schubert gdbarch_addr_bits_remove (gdbarch, addr));
30535796c8dcSSimon Schubert sline_found_in_function = 1;
30545796c8dcSSimon Schubert }
30555796c8dcSSimon Schubert else
30565796c8dcSSimon Schubert record_line (current_subfile, desc,
30575796c8dcSSimon Schubert gdbarch_addr_bits_remove (gdbarch, valu));
30585796c8dcSSimon Schubert break;
30595796c8dcSSimon Schubert
30605796c8dcSSimon Schubert case N_BCOMM:
30615796c8dcSSimon Schubert common_block_start (name, objfile);
30625796c8dcSSimon Schubert break;
30635796c8dcSSimon Schubert
30645796c8dcSSimon Schubert case N_ECOMM:
30655796c8dcSSimon Schubert common_block_end (objfile);
30665796c8dcSSimon Schubert break;
30675796c8dcSSimon Schubert
30685796c8dcSSimon Schubert /* The following symbol types need to have the appropriate
30695796c8dcSSimon Schubert offset added to their value; then we process symbol
30705796c8dcSSimon Schubert definitions in the name. */
30715796c8dcSSimon Schubert
30725796c8dcSSimon Schubert case N_STSYM: /* Static symbol in data segment. */
30735796c8dcSSimon Schubert case N_LCSYM: /* Static symbol in BSS segment. */
30745796c8dcSSimon Schubert case N_ROSYM: /* Static symbol in read-only data segment. */
30755796c8dcSSimon Schubert /* HORRID HACK DEPT. However, it's Sun's furgin' fault.
30765796c8dcSSimon Schubert Solaris 2's stabs-in-elf makes *most* symbols relative but
30775796c8dcSSimon Schubert leaves a few absolute (at least for Solaris 2.1 and version
30785796c8dcSSimon Schubert 2.0.1 of the SunPRO compiler). N_STSYM and friends sit on
30795796c8dcSSimon Schubert the fence. .stab "foo:S...",N_STSYM is absolute (ld
30805796c8dcSSimon Schubert relocates it) .stab "foo:V...",N_STSYM is relative (section
30815796c8dcSSimon Schubert base subtracted). This leaves us no choice but to search for
30825796c8dcSSimon Schubert the 'S' or 'V'... (or pass the whole section_offsets stuff
30835796c8dcSSimon Schubert down ONE MORE function call level, which we really don't want
30845796c8dcSSimon Schubert to do). */
30855796c8dcSSimon Schubert {
30865796c8dcSSimon Schubert char *p;
30875796c8dcSSimon Schubert
30885796c8dcSSimon Schubert /* Normal object file and NLMs have non-zero text seg offsets,
30895796c8dcSSimon Schubert but don't need their static syms offset in this fashion.
30905796c8dcSSimon Schubert XXX - This is really a crock that should be fixed in the
30915796c8dcSSimon Schubert solib handling code so that I don't have to work around it
30925796c8dcSSimon Schubert here. */
30935796c8dcSSimon Schubert
30945796c8dcSSimon Schubert if (!symfile_relocatable)
30955796c8dcSSimon Schubert {
30965796c8dcSSimon Schubert p = strchr (name, ':');
30975796c8dcSSimon Schubert if (p != 0 && p[1] == 'S')
30985796c8dcSSimon Schubert {
30995796c8dcSSimon Schubert /* The linker relocated it. We don't want to add an
31005796c8dcSSimon Schubert elfstab_offset_sections-type offset, but we *do*
31015796c8dcSSimon Schubert want to add whatever solib.c passed to
31025796c8dcSSimon Schubert symbol_file_add as addr (this is known to affect
31035796c8dcSSimon Schubert SunOS 4, and I suspect ELF too). Since
31045796c8dcSSimon Schubert elfstab_offset_sections currently does not muck
31055796c8dcSSimon Schubert with the text offset (there is no Ttext.text
31065796c8dcSSimon Schubert symbol), we can get addr from the text offset. If
31075796c8dcSSimon Schubert elfstab_offset_sections ever starts dealing with
31085796c8dcSSimon Schubert the text offset, and we still need to do this, we
31095796c8dcSSimon Schubert need to invent a SECT_OFF_ADDR_KLUDGE or something. */
31105796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
31115796c8dcSSimon Schubert goto define_a_symbol;
31125796c8dcSSimon Schubert }
31135796c8dcSSimon Schubert }
31145796c8dcSSimon Schubert /* Since it's not the kludge case, re-dispatch to the right
31155796c8dcSSimon Schubert handler. */
31165796c8dcSSimon Schubert switch (type)
31175796c8dcSSimon Schubert {
31185796c8dcSSimon Schubert case N_STSYM:
31195796c8dcSSimon Schubert goto case_N_STSYM;
31205796c8dcSSimon Schubert case N_LCSYM:
31215796c8dcSSimon Schubert goto case_N_LCSYM;
31225796c8dcSSimon Schubert case N_ROSYM:
31235796c8dcSSimon Schubert goto case_N_ROSYM;
31245796c8dcSSimon Schubert default:
31255796c8dcSSimon Schubert internal_error (__FILE__, __LINE__,
31265796c8dcSSimon Schubert _("failed internal consistency check"));
31275796c8dcSSimon Schubert }
31285796c8dcSSimon Schubert }
31295796c8dcSSimon Schubert
31305796c8dcSSimon Schubert case_N_STSYM: /* Static symbol in data segment. */
31315796c8dcSSimon Schubert case N_DSLINE: /* Source line number, data segment. */
31325796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
31335796c8dcSSimon Schubert goto define_a_symbol;
31345796c8dcSSimon Schubert
31355796c8dcSSimon Schubert case_N_LCSYM: /* Static symbol in BSS segment. */
31365796c8dcSSimon Schubert case N_BSLINE: /* Source line number, BSS segment. */
31375796c8dcSSimon Schubert /* N_BROWS: overlaps with N_BSLINE. */
31385796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
31395796c8dcSSimon Schubert goto define_a_symbol;
31405796c8dcSSimon Schubert
31415796c8dcSSimon Schubert case_N_ROSYM: /* Static symbol in read-only data segment. */
31425796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_RODATA (objfile));
31435796c8dcSSimon Schubert goto define_a_symbol;
31445796c8dcSSimon Schubert
31455796c8dcSSimon Schubert case N_ENTRY: /* Alternate entry point. */
31465796c8dcSSimon Schubert /* Relocate for dynamic loading. */
31475796c8dcSSimon Schubert valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
31485796c8dcSSimon Schubert goto define_a_symbol;
31495796c8dcSSimon Schubert
31505796c8dcSSimon Schubert /* The following symbol types we don't know how to process.
31515796c8dcSSimon Schubert Handle them in a "default" way, but complain to people who
31525796c8dcSSimon Schubert care. */
31535796c8dcSSimon Schubert default:
31545796c8dcSSimon Schubert case N_CATCH: /* Exception handler catcher. */
31555796c8dcSSimon Schubert case N_EHDECL: /* Exception handler name. */
31565796c8dcSSimon Schubert case N_PC: /* Global symbol in Pascal. */
31575796c8dcSSimon Schubert case N_M2C: /* Modula-2 compilation unit. */
31585796c8dcSSimon Schubert /* N_MOD2: overlaps with N_EHDECL. */
31595796c8dcSSimon Schubert case N_SCOPE: /* Modula-2 scope information. */
31605796c8dcSSimon Schubert case N_ECOML: /* End common (local name). */
31615796c8dcSSimon Schubert case N_NBTEXT: /* Gould Non-Base-Register symbols??? */
31625796c8dcSSimon Schubert case N_NBDATA:
31635796c8dcSSimon Schubert case N_NBBSS:
31645796c8dcSSimon Schubert case N_NBSTS:
31655796c8dcSSimon Schubert case N_NBLCS:
31665796c8dcSSimon Schubert unknown_symtype_complaint (hex_string (type));
31675796c8dcSSimon Schubert /* FALLTHROUGH */
31685796c8dcSSimon Schubert
31695796c8dcSSimon Schubert /* The following symbol types don't need the address field
31705796c8dcSSimon Schubert relocated, since it is either unused, or is absolute. */
31715796c8dcSSimon Schubert define_a_symbol:
31725796c8dcSSimon Schubert case N_GSYM: /* Global variable. */
31735796c8dcSSimon Schubert case N_NSYMS: /* Number of symbols (Ultrix). */
31745796c8dcSSimon Schubert case N_NOMAP: /* No map? (Ultrix). */
31755796c8dcSSimon Schubert case N_RSYM: /* Register variable. */
31765796c8dcSSimon Schubert case N_DEFD: /* Modula-2 GNU module dependency. */
31775796c8dcSSimon Schubert case N_SSYM: /* Struct or union element. */
31785796c8dcSSimon Schubert case N_LSYM: /* Local symbol in stack. */
31795796c8dcSSimon Schubert case N_PSYM: /* Parameter variable. */
31805796c8dcSSimon Schubert case N_LENG: /* Length of preceding symbol type. */
31815796c8dcSSimon Schubert if (name)
31825796c8dcSSimon Schubert {
31835796c8dcSSimon Schubert int deftype;
31845796c8dcSSimon Schubert char *colon_pos = strchr (name, ':');
3185cf7f2e2dSJohn Marino
31865796c8dcSSimon Schubert if (colon_pos == NULL)
31875796c8dcSSimon Schubert deftype = '\0';
31885796c8dcSSimon Schubert else
31895796c8dcSSimon Schubert deftype = colon_pos[1];
31905796c8dcSSimon Schubert
31915796c8dcSSimon Schubert switch (deftype)
31925796c8dcSSimon Schubert {
31935796c8dcSSimon Schubert case 'f':
31945796c8dcSSimon Schubert case 'F':
31955796c8dcSSimon Schubert function_stab_type = type;
31965796c8dcSSimon Schubert
31975796c8dcSSimon Schubert /* Deal with the SunPRO 3.0 compiler which omits the
31985796c8dcSSimon Schubert address from N_FUN symbols. */
31995796c8dcSSimon Schubert if (type == N_FUN
32005796c8dcSSimon Schubert && valu == ANOFFSET (section_offsets,
32015796c8dcSSimon Schubert SECT_OFF_TEXT (objfile))
32025796c8dcSSimon Schubert && gdbarch_sofun_address_maybe_missing (gdbarch))
32035796c8dcSSimon Schubert {
32045796c8dcSSimon Schubert CORE_ADDR minsym_valu =
3205*ef5ccd6cSJohn Marino find_stab_function_addr (name, get_last_source_file (),
3206*ef5ccd6cSJohn Marino objfile);
32075796c8dcSSimon Schubert
32085796c8dcSSimon Schubert /* The function find_stab_function_addr will return
32095796c8dcSSimon Schubert 0 if the minimal symbol wasn't found.
32105796c8dcSSimon Schubert (Unfortunately, this might also be a valid
32115796c8dcSSimon Schubert address.) Anyway, if it *does* return 0, it is
32125796c8dcSSimon Schubert likely that the value was set correctly to begin
32135796c8dcSSimon Schubert with... */
32145796c8dcSSimon Schubert if (minsym_valu != 0)
32155796c8dcSSimon Schubert valu = minsym_valu;
32165796c8dcSSimon Schubert }
32175796c8dcSSimon Schubert
32185796c8dcSSimon Schubert if (block_address_function_relative)
32195796c8dcSSimon Schubert /* For Solaris 2 compilers, the block addresses and
32205796c8dcSSimon Schubert N_SLINE's are relative to the start of the
32215796c8dcSSimon Schubert function. On normal systems, and when using GCC on
32225796c8dcSSimon Schubert Solaris 2, these addresses are just absolute, or
32235796c8dcSSimon Schubert relative to the N_SO, depending on
32245796c8dcSSimon Schubert BLOCK_ADDRESS_ABSOLUTE. */
32255796c8dcSSimon Schubert function_start_offset = valu;
32265796c8dcSSimon Schubert
32275796c8dcSSimon Schubert within_function = 1;
32285796c8dcSSimon Schubert
32295796c8dcSSimon Schubert if (context_stack_depth > 1)
32305796c8dcSSimon Schubert {
32315796c8dcSSimon Schubert complaint (&symfile_complaints,
32325796c8dcSSimon Schubert _("unmatched N_LBRAC before symtab pos %d"),
32335796c8dcSSimon Schubert symnum);
32345796c8dcSSimon Schubert break;
32355796c8dcSSimon Schubert }
32365796c8dcSSimon Schubert
32375796c8dcSSimon Schubert if (context_stack_depth > 0)
32385796c8dcSSimon Schubert {
32395796c8dcSSimon Schubert struct block *block;
32405796c8dcSSimon Schubert
32415796c8dcSSimon Schubert new = pop_context ();
32425796c8dcSSimon Schubert /* Make a block for the local symbols within. */
32435796c8dcSSimon Schubert block = finish_block (new->name, &local_symbols,
32445796c8dcSSimon Schubert new->old_blocks, new->start_addr,
32455796c8dcSSimon Schubert valu, objfile);
32465796c8dcSSimon Schubert
32475796c8dcSSimon Schubert /* For C++, set the block's scope. */
32485796c8dcSSimon Schubert if (SYMBOL_LANGUAGE (new->name) == language_cplus)
32495796c8dcSSimon Schubert cp_set_block_scope (new->name, block,
3250*ef5ccd6cSJohn Marino &objfile->objfile_obstack);
32515796c8dcSSimon Schubert }
32525796c8dcSSimon Schubert
32535796c8dcSSimon Schubert new = push_context (0, valu);
32545796c8dcSSimon Schubert new->name = define_symbol (valu, name, desc, type, objfile);
32555796c8dcSSimon Schubert break;
32565796c8dcSSimon Schubert
32575796c8dcSSimon Schubert default:
32585796c8dcSSimon Schubert define_symbol (valu, name, desc, type, objfile);
32595796c8dcSSimon Schubert break;
32605796c8dcSSimon Schubert }
32615796c8dcSSimon Schubert }
32625796c8dcSSimon Schubert break;
32635796c8dcSSimon Schubert
32645796c8dcSSimon Schubert /* We use N_OPT to carry the gcc2_compiled flag. Sun uses it
32655796c8dcSSimon Schubert for a bunch of other flags, too. Someday we may parse their
32665796c8dcSSimon Schubert flags; for now we ignore theirs and hope they'll ignore ours. */
32675796c8dcSSimon Schubert case N_OPT: /* Solaris 2: Compiler options. */
32685796c8dcSSimon Schubert if (name)
32695796c8dcSSimon Schubert {
32705796c8dcSSimon Schubert if (strcmp (name, GCC2_COMPILED_FLAG_SYMBOL) == 0)
32715796c8dcSSimon Schubert {
32725796c8dcSSimon Schubert processing_gcc_compilation = 2;
32735796c8dcSSimon Schubert #if 0 /* Works, but is experimental. -fnf */
32745796c8dcSSimon Schubert /* For now, stay with AUTO_DEMANGLING for g++ output, as
32755796c8dcSSimon Schubert we don't know whether it will use the old style or v3
32765796c8dcSSimon Schubert mangling. */
32775796c8dcSSimon Schubert if (AUTO_DEMANGLING)
32785796c8dcSSimon Schubert {
32795796c8dcSSimon Schubert set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
32805796c8dcSSimon Schubert }
32815796c8dcSSimon Schubert #endif
32825796c8dcSSimon Schubert }
32835796c8dcSSimon Schubert else
32845796c8dcSSimon Schubert n_opt_found = 1;
32855796c8dcSSimon Schubert }
32865796c8dcSSimon Schubert break;
32875796c8dcSSimon Schubert
32885796c8dcSSimon Schubert case N_MAIN: /* Name of main routine. */
32895796c8dcSSimon Schubert /* FIXME: If one has a symbol file with N_MAIN and then replaces
32905796c8dcSSimon Schubert it with a symbol file with "main" and without N_MAIN. I'm
32915796c8dcSSimon Schubert not sure exactly what rule to follow but probably something
32925796c8dcSSimon Schubert like: N_MAIN takes precedence over "main" no matter what
32935796c8dcSSimon Schubert objfile it is in; If there is more than one N_MAIN, choose
32945796c8dcSSimon Schubert the one in the symfile_objfile; If there is more than one
32955796c8dcSSimon Schubert N_MAIN within a given objfile, complain() and choose
32965796c8dcSSimon Schubert arbitrarily. (kingdon) */
32975796c8dcSSimon Schubert if (name != NULL)
32985796c8dcSSimon Schubert set_main_name (name);
32995796c8dcSSimon Schubert break;
33005796c8dcSSimon Schubert
33015796c8dcSSimon Schubert /* The following symbol types can be ignored. */
33025796c8dcSSimon Schubert case N_OBJ: /* Solaris 2: Object file dir and name. */
33035796c8dcSSimon Schubert case N_PATCH: /* Solaris 2: Patch Run Time Checker. */
33045796c8dcSSimon Schubert /* N_UNDF: Solaris 2: File separator mark. */
33055796c8dcSSimon Schubert /* N_UNDF: -- we will never encounter it, since we only process
33065796c8dcSSimon Schubert one file's symbols at once. */
33075796c8dcSSimon Schubert case N_ENDM: /* Solaris 2: End of module. */
33085796c8dcSSimon Schubert case N_ALIAS: /* SunPro F77: alias name, ignore for now. */
33095796c8dcSSimon Schubert break;
33105796c8dcSSimon Schubert }
33115796c8dcSSimon Schubert
33125796c8dcSSimon Schubert /* '#' is a GNU C extension to allow one symbol to refer to another
33135796c8dcSSimon Schubert related symbol.
33145796c8dcSSimon Schubert
33155796c8dcSSimon Schubert Generally this is used so that an alias can refer to its main
33165796c8dcSSimon Schubert symbol. */
3317c50c785cSJohn Marino gdb_assert (name);
33185796c8dcSSimon Schubert if (name[0] == '#')
33195796c8dcSSimon Schubert {
33205796c8dcSSimon Schubert /* Initialize symbol reference names and determine if this is a
33215796c8dcSSimon Schubert definition. If a symbol reference is being defined, go ahead
33225796c8dcSSimon Schubert and add it. Otherwise, just return. */
33235796c8dcSSimon Schubert
33245796c8dcSSimon Schubert char *s = name;
33255796c8dcSSimon Schubert int refnum;
33265796c8dcSSimon Schubert
33275796c8dcSSimon Schubert /* If this stab defines a new reference ID that is not on the
33285796c8dcSSimon Schubert reference list, then put it on the reference list.
33295796c8dcSSimon Schubert
33305796c8dcSSimon Schubert We go ahead and advance NAME past the reference, even though
33315796c8dcSSimon Schubert it is not strictly necessary at this time. */
33325796c8dcSSimon Schubert refnum = symbol_reference_defined (&s);
33335796c8dcSSimon Schubert if (refnum >= 0)
33345796c8dcSSimon Schubert if (!ref_search (refnum))
33355796c8dcSSimon Schubert ref_add (refnum, 0, name, valu);
33365796c8dcSSimon Schubert name = s;
33375796c8dcSSimon Schubert }
33385796c8dcSSimon Schubert
33395796c8dcSSimon Schubert previous_stab_code = type;
33405796c8dcSSimon Schubert }
33415796c8dcSSimon Schubert
33425796c8dcSSimon Schubert /* FIXME: The only difference between this and elfstab_build_psymtabs
33435796c8dcSSimon Schubert is the call to install_minimal_symbols for elf, and the support for
33445796c8dcSSimon Schubert split sections. If the differences are really that small, the code
33455796c8dcSSimon Schubert should be shared. */
33465796c8dcSSimon Schubert
33475796c8dcSSimon Schubert /* Scan and build partial symbols for an coff symbol file.
33485796c8dcSSimon Schubert The coff file has already been processed to get its minimal symbols.
33495796c8dcSSimon Schubert
33505796c8dcSSimon Schubert This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
33515796c8dcSSimon Schubert rolled into one.
33525796c8dcSSimon Schubert
33535796c8dcSSimon Schubert OBJFILE is the object file we are reading symbols from.
33545796c8dcSSimon Schubert ADDR is the address relative to which the symbols are (e.g.
33555796c8dcSSimon Schubert the base address of the text segment).
33565796c8dcSSimon Schubert TEXTADDR is the address of the text section.
33575796c8dcSSimon Schubert TEXTSIZE is the size of the text section.
33585796c8dcSSimon Schubert STABSECTS is the list of .stab sections in OBJFILE.
33595796c8dcSSimon Schubert STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
33605796c8dcSSimon Schubert .stabstr section exists.
33615796c8dcSSimon Schubert
33625796c8dcSSimon Schubert This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
33635796c8dcSSimon Schubert adjusted for coff details. */
33645796c8dcSSimon Schubert
33655796c8dcSSimon Schubert void
coffstab_build_psymtabs(struct objfile * objfile,CORE_ADDR textaddr,unsigned int textsize,struct stab_section_list * stabsects,file_ptr stabstroffset,unsigned int stabstrsize)3366cf7f2e2dSJohn Marino coffstab_build_psymtabs (struct objfile *objfile,
33675796c8dcSSimon Schubert CORE_ADDR textaddr, unsigned int textsize,
33685796c8dcSSimon Schubert struct stab_section_list *stabsects,
33695796c8dcSSimon Schubert file_ptr stabstroffset, unsigned int stabstrsize)
33705796c8dcSSimon Schubert {
33715796c8dcSSimon Schubert int val;
33725796c8dcSSimon Schubert bfd *sym_bfd = objfile->obfd;
33735796c8dcSSimon Schubert char *name = bfd_get_filename (sym_bfd);
33745796c8dcSSimon Schubert struct dbx_symfile_info *info;
33755796c8dcSSimon Schubert unsigned int stabsize;
33765796c8dcSSimon Schubert
33775796c8dcSSimon Schubert /* There is already a dbx_symfile_info allocated by our caller.
33785796c8dcSSimon Schubert It might even contain some info from the coff symtab to help us. */
3379*ef5ccd6cSJohn Marino info = DBX_SYMFILE_INFO (objfile);
33805796c8dcSSimon Schubert
33815796c8dcSSimon Schubert DBX_TEXT_ADDR (objfile) = textaddr;
33825796c8dcSSimon Schubert DBX_TEXT_SIZE (objfile) = textsize;
33835796c8dcSSimon Schubert
33845796c8dcSSimon Schubert #define COFF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
33855796c8dcSSimon Schubert DBX_SYMBOL_SIZE (objfile) = COFF_STABS_SYMBOL_SIZE;
33865796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
33875796c8dcSSimon Schubert
33885796c8dcSSimon Schubert if (stabstrsize > bfd_get_size (sym_bfd))
33895796c8dcSSimon Schubert error (_("ridiculous string table size: %d bytes"), stabstrsize);
33905796c8dcSSimon Schubert DBX_STRINGTAB (objfile) = (char *)
33915796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
33925796c8dcSSimon Schubert OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
33935796c8dcSSimon Schubert
33945796c8dcSSimon Schubert /* Now read in the string table in one big gulp. */
33955796c8dcSSimon Schubert
33965796c8dcSSimon Schubert val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
33975796c8dcSSimon Schubert if (val < 0)
33985796c8dcSSimon Schubert perror_with_name (name);
33995796c8dcSSimon Schubert val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
34005796c8dcSSimon Schubert if (val != stabstrsize)
34015796c8dcSSimon Schubert perror_with_name (name);
34025796c8dcSSimon Schubert
34035796c8dcSSimon Schubert stabsread_new_init ();
34045796c8dcSSimon Schubert buildsym_new_init ();
34055796c8dcSSimon Schubert free_header_files ();
34065796c8dcSSimon Schubert init_header_files ();
34075796c8dcSSimon Schubert
34085796c8dcSSimon Schubert processing_acc_compilation = 1;
34095796c8dcSSimon Schubert
34105796c8dcSSimon Schubert /* In a coff file, we've already installed the minimal symbols that came
34115796c8dcSSimon Schubert from the coff (non-stab) symbol table, so always act like an
34125796c8dcSSimon Schubert incremental load here. */
34135796c8dcSSimon Schubert if (stabsects->next == NULL)
34145796c8dcSSimon Schubert {
34155796c8dcSSimon Schubert stabsize = bfd_section_size (sym_bfd, stabsects->section);
34165796c8dcSSimon Schubert DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
34175796c8dcSSimon Schubert DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
34185796c8dcSSimon Schubert }
34195796c8dcSSimon Schubert else
34205796c8dcSSimon Schubert {
34215796c8dcSSimon Schubert struct stab_section_list *stabsect;
34225796c8dcSSimon Schubert
34235796c8dcSSimon Schubert DBX_SYMCOUNT (objfile) = 0;
34245796c8dcSSimon Schubert for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next)
34255796c8dcSSimon Schubert {
34265796c8dcSSimon Schubert stabsize = bfd_section_size (sym_bfd, stabsect->section);
34275796c8dcSSimon Schubert DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
34285796c8dcSSimon Schubert }
34295796c8dcSSimon Schubert
34305796c8dcSSimon Schubert DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
34315796c8dcSSimon Schubert
34325796c8dcSSimon Schubert symbuf_sections = stabsects->next;
34335796c8dcSSimon Schubert symbuf_left = bfd_section_size (sym_bfd, stabsects->section);
34345796c8dcSSimon Schubert symbuf_read = 0;
34355796c8dcSSimon Schubert }
34365796c8dcSSimon Schubert
34375796c8dcSSimon Schubert dbx_symfile_read (objfile, 0);
34385796c8dcSSimon Schubert }
34395796c8dcSSimon Schubert
34405796c8dcSSimon Schubert /* Scan and build partial symbols for an ELF symbol file.
34415796c8dcSSimon Schubert This ELF file has already been processed to get its minimal symbols.
34425796c8dcSSimon Schubert
34435796c8dcSSimon Schubert This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
34445796c8dcSSimon Schubert rolled into one.
34455796c8dcSSimon Schubert
34465796c8dcSSimon Schubert OBJFILE is the object file we are reading symbols from.
34475796c8dcSSimon Schubert ADDR is the address relative to which the symbols are (e.g.
34485796c8dcSSimon Schubert the base address of the text segment).
34495796c8dcSSimon Schubert STABSECT is the BFD section information for the .stab section.
34505796c8dcSSimon Schubert STABSTROFFSET and STABSTRSIZE define the location in OBJFILE where the
34515796c8dcSSimon Schubert .stabstr section exists.
34525796c8dcSSimon Schubert
34535796c8dcSSimon Schubert This routine is mostly copied from dbx_symfile_init and dbx_symfile_read,
34545796c8dcSSimon Schubert adjusted for elf details. */
34555796c8dcSSimon Schubert
34565796c8dcSSimon Schubert void
elfstab_build_psymtabs(struct objfile * objfile,asection * stabsect,file_ptr stabstroffset,unsigned int stabstrsize)3457cf7f2e2dSJohn Marino elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
34585796c8dcSSimon Schubert file_ptr stabstroffset, unsigned int stabstrsize)
34595796c8dcSSimon Schubert {
34605796c8dcSSimon Schubert int val;
34615796c8dcSSimon Schubert bfd *sym_bfd = objfile->obfd;
34625796c8dcSSimon Schubert char *name = bfd_get_filename (sym_bfd);
34635796c8dcSSimon Schubert struct dbx_symfile_info *info;
3464a45ae5f8SJohn Marino struct cleanup *back_to = make_cleanup (null_cleanup, NULL);
34655796c8dcSSimon Schubert
34665796c8dcSSimon Schubert /* There is already a dbx_symfile_info allocated by our caller.
34675796c8dcSSimon Schubert It might even contain some info from the ELF symtab to help us. */
3468*ef5ccd6cSJohn Marino info = DBX_SYMFILE_INFO (objfile);
34695796c8dcSSimon Schubert
34705796c8dcSSimon Schubert /* Find the first and last text address. dbx_symfile_read seems to
34715796c8dcSSimon Schubert want this. */
34725796c8dcSSimon Schubert find_text_range (sym_bfd, objfile);
34735796c8dcSSimon Schubert
34745796c8dcSSimon Schubert #define ELF_STABS_SYMBOL_SIZE 12 /* XXX FIXME XXX */
34755796c8dcSSimon Schubert DBX_SYMBOL_SIZE (objfile) = ELF_STABS_SYMBOL_SIZE;
34765796c8dcSSimon Schubert DBX_SYMCOUNT (objfile)
34775796c8dcSSimon Schubert = bfd_section_size (objfile->obfd, stabsect) / DBX_SYMBOL_SIZE (objfile);
34785796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile) = stabstrsize;
34795796c8dcSSimon Schubert DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos;
34805796c8dcSSimon Schubert DBX_STAB_SECTION (objfile) = stabsect;
34815796c8dcSSimon Schubert
34825796c8dcSSimon Schubert if (stabstrsize > bfd_get_size (sym_bfd))
34835796c8dcSSimon Schubert error (_("ridiculous string table size: %d bytes"), stabstrsize);
34845796c8dcSSimon Schubert DBX_STRINGTAB (objfile) = (char *)
34855796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack, stabstrsize + 1);
34865796c8dcSSimon Schubert OBJSTAT (objfile, sz_strtab += stabstrsize + 1);
34875796c8dcSSimon Schubert
34885796c8dcSSimon Schubert /* Now read in the string table in one big gulp. */
34895796c8dcSSimon Schubert
34905796c8dcSSimon Schubert val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
34915796c8dcSSimon Schubert if (val < 0)
34925796c8dcSSimon Schubert perror_with_name (name);
34935796c8dcSSimon Schubert val = bfd_bread (DBX_STRINGTAB (objfile), stabstrsize, sym_bfd);
34945796c8dcSSimon Schubert if (val != stabstrsize)
34955796c8dcSSimon Schubert perror_with_name (name);
34965796c8dcSSimon Schubert
34975796c8dcSSimon Schubert stabsread_new_init ();
34985796c8dcSSimon Schubert buildsym_new_init ();
34995796c8dcSSimon Schubert free_header_files ();
35005796c8dcSSimon Schubert init_header_files ();
35015796c8dcSSimon Schubert
35025796c8dcSSimon Schubert processing_acc_compilation = 1;
35035796c8dcSSimon Schubert
35045796c8dcSSimon Schubert symbuf_read = 0;
35055796c8dcSSimon Schubert symbuf_left = bfd_section_size (objfile->obfd, stabsect);
3506cf7f2e2dSJohn Marino stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL);
35075796c8dcSSimon Schubert if (stabs_data)
3508a45ae5f8SJohn Marino make_cleanup (free_current_contents, (void *) &stabs_data);
35095796c8dcSSimon Schubert
35105796c8dcSSimon Schubert /* In an elf file, we've already installed the minimal symbols that came
35115796c8dcSSimon Schubert from the elf (non-stab) symbol table, so always act like an
35125796c8dcSSimon Schubert incremental load here. dbx_symfile_read should not generate any new
35135796c8dcSSimon Schubert minimal symbols, since we will have already read the ELF dynamic symbol
35145796c8dcSSimon Schubert table and normal symbol entries won't be in the ".stab" section; but in
35155796c8dcSSimon Schubert case it does, it will install them itself. */
35165796c8dcSSimon Schubert dbx_symfile_read (objfile, 0);
35175796c8dcSSimon Schubert
35185796c8dcSSimon Schubert do_cleanups (back_to);
35195796c8dcSSimon Schubert }
35205796c8dcSSimon Schubert
35215796c8dcSSimon Schubert /* Scan and build partial symbols for a file with special sections for stabs
35225796c8dcSSimon Schubert and stabstrings. The file has already been processed to get its minimal
35235796c8dcSSimon Schubert symbols, and any other symbols that might be necessary to resolve GSYMs.
35245796c8dcSSimon Schubert
35255796c8dcSSimon Schubert This routine is the equivalent of dbx_symfile_init and dbx_symfile_read
35265796c8dcSSimon Schubert rolled into one.
35275796c8dcSSimon Schubert
35285796c8dcSSimon Schubert OBJFILE is the object file we are reading symbols from.
35295796c8dcSSimon Schubert ADDR is the address relative to which the symbols are (e.g. the base address
35305796c8dcSSimon Schubert of the text segment).
35315796c8dcSSimon Schubert STAB_NAME is the name of the section that contains the stabs.
35325796c8dcSSimon Schubert STABSTR_NAME is the name of the section that contains the stab strings.
35335796c8dcSSimon Schubert
3534c50c785cSJohn Marino This routine is mostly copied from dbx_symfile_init and
3535c50c785cSJohn Marino dbx_symfile_read. */
35365796c8dcSSimon Schubert
35375796c8dcSSimon Schubert void
stabsect_build_psymtabs(struct objfile * objfile,char * stab_name,char * stabstr_name,char * text_name)3538cf7f2e2dSJohn Marino stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
35395796c8dcSSimon Schubert char *stabstr_name, char *text_name)
35405796c8dcSSimon Schubert {
35415796c8dcSSimon Schubert int val;
35425796c8dcSSimon Schubert bfd *sym_bfd = objfile->obfd;
35435796c8dcSSimon Schubert char *name = bfd_get_filename (sym_bfd);
35445796c8dcSSimon Schubert asection *stabsect;
35455796c8dcSSimon Schubert asection *stabstrsect;
35465796c8dcSSimon Schubert asection *text_sect;
3547*ef5ccd6cSJohn Marino struct dbx_symfile_info *dbx;
35485796c8dcSSimon Schubert
35495796c8dcSSimon Schubert stabsect = bfd_get_section_by_name (sym_bfd, stab_name);
35505796c8dcSSimon Schubert stabstrsect = bfd_get_section_by_name (sym_bfd, stabstr_name);
35515796c8dcSSimon Schubert
35525796c8dcSSimon Schubert if (!stabsect)
35535796c8dcSSimon Schubert return;
35545796c8dcSSimon Schubert
35555796c8dcSSimon Schubert if (!stabstrsect)
3556c50c785cSJohn Marino error (_("stabsect_build_psymtabs: Found stabs (%s), "
3557c50c785cSJohn Marino "but not string section (%s)"),
35585796c8dcSSimon Schubert stab_name, stabstr_name);
35595796c8dcSSimon Schubert
3560*ef5ccd6cSJohn Marino dbx = XCNEW (struct dbx_symfile_info);
3561*ef5ccd6cSJohn Marino set_objfile_data (objfile, dbx_objfile_data_key, dbx);
35625796c8dcSSimon Schubert
35635796c8dcSSimon Schubert text_sect = bfd_get_section_by_name (sym_bfd, text_name);
35645796c8dcSSimon Schubert if (!text_sect)
35655796c8dcSSimon Schubert error (_("Can't find %s section in symbol file"), text_name);
35665796c8dcSSimon Schubert DBX_TEXT_ADDR (objfile) = bfd_section_vma (sym_bfd, text_sect);
35675796c8dcSSimon Schubert DBX_TEXT_SIZE (objfile) = bfd_section_size (sym_bfd, text_sect);
35685796c8dcSSimon Schubert
35695796c8dcSSimon Schubert DBX_SYMBOL_SIZE (objfile) = sizeof (struct external_nlist);
35705796c8dcSSimon Schubert DBX_SYMCOUNT (objfile) = bfd_section_size (sym_bfd, stabsect)
35715796c8dcSSimon Schubert / DBX_SYMBOL_SIZE (objfile);
35725796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile) = bfd_section_size (sym_bfd, stabstrsect);
3573c50c785cSJohn Marino DBX_SYMTAB_OFFSET (objfile) = stabsect->filepos; /* XXX - FIXME: POKING
3574c50c785cSJohn Marino INSIDE BFD DATA
3575c50c785cSJohn Marino STRUCTURES */
35765796c8dcSSimon Schubert
35775796c8dcSSimon Schubert if (DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
35785796c8dcSSimon Schubert error (_("ridiculous string table size: %d bytes"),
35795796c8dcSSimon Schubert DBX_STRINGTAB_SIZE (objfile));
35805796c8dcSSimon Schubert DBX_STRINGTAB (objfile) = (char *)
3581c50c785cSJohn Marino obstack_alloc (&objfile->objfile_obstack,
3582c50c785cSJohn Marino DBX_STRINGTAB_SIZE (objfile) + 1);
35835796c8dcSSimon Schubert OBJSTAT (objfile, sz_strtab += DBX_STRINGTAB_SIZE (objfile) + 1);
35845796c8dcSSimon Schubert
35855796c8dcSSimon Schubert /* Now read in the string table in one big gulp. */
35865796c8dcSSimon Schubert
35875796c8dcSSimon Schubert val = bfd_get_section_contents (sym_bfd, /* bfd */
35885796c8dcSSimon Schubert stabstrsect, /* bfd section */
35895796c8dcSSimon Schubert DBX_STRINGTAB (objfile), /* input buffer */
35905796c8dcSSimon Schubert 0, /* offset into section */
3591c50c785cSJohn Marino DBX_STRINGTAB_SIZE (objfile)); /* amount to
3592c50c785cSJohn Marino read */
35935796c8dcSSimon Schubert
35945796c8dcSSimon Schubert if (!val)
35955796c8dcSSimon Schubert perror_with_name (name);
35965796c8dcSSimon Schubert
35975796c8dcSSimon Schubert stabsread_new_init ();
35985796c8dcSSimon Schubert buildsym_new_init ();
35995796c8dcSSimon Schubert free_header_files ();
36005796c8dcSSimon Schubert init_header_files ();
36015796c8dcSSimon Schubert
3602c50c785cSJohn Marino /* Now, do an incremental load. */
36035796c8dcSSimon Schubert
36045796c8dcSSimon Schubert processing_acc_compilation = 1;
36055796c8dcSSimon Schubert dbx_symfile_read (objfile, 0);
36065796c8dcSSimon Schubert }
36075796c8dcSSimon Schubert
3608c50c785cSJohn Marino static const struct sym_fns aout_sym_fns =
36095796c8dcSSimon Schubert {
36105796c8dcSSimon Schubert bfd_target_aout_flavour,
3611c50c785cSJohn Marino dbx_new_init, /* init anything gbl to entire symtab */
3612c50c785cSJohn Marino dbx_symfile_init, /* read initial info, setup for sym_read() */
3613c50c785cSJohn Marino dbx_symfile_read, /* read a symbol file into symtab */
3614c50c785cSJohn Marino NULL, /* sym_read_psymbols */
3615c50c785cSJohn Marino dbx_symfile_finish, /* finished with file, cleanup */
3616c50c785cSJohn Marino default_symfile_offsets, /* parse user's offsets to internal form */
3617c50c785cSJohn Marino default_symfile_segments, /* Get segment information from a file. */
3618c50c785cSJohn Marino NULL,
3619c50c785cSJohn Marino default_symfile_relocate, /* Relocate a debug section. */
3620*ef5ccd6cSJohn Marino NULL, /* sym_probe_fns */
3621c50c785cSJohn Marino &psym_functions
36225796c8dcSSimon Schubert };
36235796c8dcSSimon Schubert
36245796c8dcSSimon Schubert void
_initialize_dbxread(void)36255796c8dcSSimon Schubert _initialize_dbxread (void)
36265796c8dcSSimon Schubert {
36275796c8dcSSimon Schubert add_symtab_fns (&aout_sym_fns);
3628*ef5ccd6cSJohn Marino
3629*ef5ccd6cSJohn Marino dbx_objfile_data_key
3630*ef5ccd6cSJohn Marino = register_objfile_data_with_cleanup (NULL, dbx_free_symfile_info);
36315796c8dcSSimon Schubert }
3632