/* Read dbx symbol tables and convert to internal format, for GDB.
- Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
+ Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
+ Free Software Foundation, Inc.
This file is part of GDB.
#if defined(USG) || defined(__CYGNUSCLIB__)
#include <sys/types.h>
#include <fcntl.h>
-#define L_SET 0
-#define L_INCR 1
#endif
#include <obstack.h>
#include "aout/aout64.h"
#include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
+#if !defined (SEEK_SET)
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#endif
+
/* Each partial symbol table entry contains a pointer to private data for the
read_symtab() function to use when expanding a partial symbol table entry
to a full symbol table entry.
struct complaint unknown_symtype_complaint =
{"unknown symbol type %s", 0, 0};
+struct complaint unknown_symchar_complaint =
+ {"unknown symbol type character `%c'", 0, 0};
+
struct complaint lbrac_rbrac_complaint =
{"block start larger than block end", 0, 0};
static struct pending *
copy_pending PARAMS ((struct pending *, int, struct pending *));
-static struct symtab *
-read_ofile_symtab PARAMS ((struct objfile *, int, int, CORE_ADDR, int,
- struct section_offsets *));
+static void
+read_ofile_symtab PARAMS ((struct partial_symtab *));
static void
dbx_psymtab_to_symtab PARAMS ((struct partial_symtab *));
int val;
sym_bfd = objfile->obfd;
- val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), L_SET);
+ val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), SEEK_SET);
if (val < 0)
perror_with_name (objfile->name);
if (STRING_TABLE_OFFSET == 0)
{
+ /* It appears that with the existing bfd code, STRING_TABLE_OFFSET
+ will never be zero, even when there is no string table. This
+ would appear to be a bug in bfd. */
DBX_STRINGTAB_SIZE (objfile) = 0;
DBX_STRINGTAB (objfile) = NULL;
}
else
{
- val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
+ val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
if (val < 0)
perror_with_name (name);
memset ((PTR) size_temp, 0, sizeof (size_temp));
val = bfd_read ((PTR) size_temp, sizeof (size_temp), 1, sym_bfd);
if (val < 0)
- perror_with_name (name);
-
- DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
-
- if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
- || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
- error ("ridiculous string table size (%d bytes).",
- DBX_STRINGTAB_SIZE (objfile));
-
- DBX_STRINGTAB (objfile) =
- (char *) obstack_alloc (&objfile -> psymbol_obstack,
- DBX_STRINGTAB_SIZE (objfile));
-
- /* Now read in the string table in one big gulp. */
-
- val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
- if (val < 0)
- perror_with_name (name);
- val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
- sym_bfd);
- if (val != DBX_STRINGTAB_SIZE (objfile))
- perror_with_name (name);
+ {
+ perror_with_name (name);
+ }
+ else if (val == 0)
+ {
+ /* With the existing bfd code, STRING_TABLE_OFFSET will be set to
+ EOF if there is no string table, and attempting to read the size
+ from EOF will read zero bytes. */
+ DBX_STRINGTAB_SIZE (objfile) = 0;
+ DBX_STRINGTAB (objfile) = NULL;
+ }
+ else
+ {
+ /* Read some data that would appear to be the string table size.
+ If there really is a string table, then it is probably the right
+ size. Byteswap if necessary and validate the size. Note that
+ the minimum is DBX_STRINGTAB_SIZE_SIZE. If we just read some
+ random data that happened to be at STRING_TABLE_OFFSET, because
+ bfd can't tell us there is no string table, the sanity checks may
+ or may not catch this. */
+ DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
+
+ if (DBX_STRINGTAB_SIZE (objfile) < sizeof (size_temp)
+ || DBX_STRINGTAB_SIZE (objfile) > bfd_get_size (sym_bfd))
+ error ("ridiculous string table size (%d bytes).",
+ DBX_STRINGTAB_SIZE (objfile));
+
+ DBX_STRINGTAB (objfile) =
+ (char *) obstack_alloc (&objfile -> psymbol_obstack,
+ DBX_STRINGTAB_SIZE (objfile));
+
+ /* Now read in the string table in one big gulp. */
+
+ val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, SEEK_SET);
+ if (val < 0)
+ perror_with_name (name);
+ val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
+ sym_bfd);
+ if (val != DBX_STRINGTAB_SIZE (objfile))
+ perror_with_name (name);
+ }
}
}
subpst->readin = 0;
subpst->symtab = 0;
- subpst->read_symtab = dbx_psymtab_to_symtab;
+ subpst->read_symtab = pst->read_symtab;
}
sort_pst_symbols (pst);
symbol_size = SYMBOL_SIZE (pst);
/* Read in this file's symbols */
- bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), L_SET);
- pst->symtab =
- read_ofile_symtab (pst->objfile, LDSYMOFF(pst), LDSYMLEN(pst),
- pst->textlow, pst->texthigh - pst->textlow,
- pst->section_offsets);
+ bfd_seek (pst->objfile->obfd, SYMBOL_OFFSET (pst), SEEK_SET);
+ read_ofile_symtab (pst);
sort_symtab_syms (pst->symtab);
do_cleanups (old_chain);
}
}
-/* Read in a defined section of a specific object file's symbols.
+/* Read in a defined section of a specific object file's symbols. */
- DESC is the file descriptor for the file, positioned at the
- beginning of the symtab
- SYM_OFFSET is the offset within the file of
- the beginning of the symbols we want to read
- SYM_SIZE is the size of the symbol info to read in.
- TEXT_OFFSET is the beginning of the text segment we are reading symbols for
- TEXT_SIZE is the size of the text segment read in.
- SECTION_OFFSETS are the relocation offsets which get added to each symbol. */
-
-static struct symtab *
-read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
- section_offsets)
- struct objfile *objfile;
- int sym_offset;
- int sym_size;
- CORE_ADDR text_offset;
- int text_size;
- struct section_offsets *section_offsets;
+static void
+read_ofile_symtab (pst)
+ struct partial_symtab *pst;
{
register char *namestring;
register struct internal_nlist *bufp;
unsigned max_symnum;
register bfd *abfd;
struct symtab *rtn;
+ struct objfile *objfile;
+ int sym_offset; /* Offset to start of symbols to read */
+ int sym_size; /* Size of symbols to read */
+ CORE_ADDR text_offset; /* Start of text segment for symbols */
+ int text_size; /* Size of text segment for symbols */
+ struct section_offsets *section_offsets;
+
+ objfile = pst->objfile;
+ sym_offset = LDSYMOFF(pst);
+ sym_size = LDSYMLEN(pst);
+ text_offset = pst->textlow;
+ text_size = pst->texthigh - pst->textlow;
+ section_offsets = pst->section_offsets;
current_objfile = objfile;
subfile_stack = NULL;
would slow down initial readin, so we look for it here instead. */
if (!processing_acc_compilation && sym_offset >= (int)symbol_size)
{
- bfd_seek (symfile_bfd, sym_offset - symbol_size, L_INCR);
+ bfd_seek (symfile_bfd, sym_offset - symbol_size, SEEK_CUR);
fill_symbuf (abfd);
bufp = &symbuf[symbuf_idx++];
SWAP_SYMBOL (bufp, abfd);
if (processing_gcc_compilation)
{
-#if 1 /* Works, but is experimental. -fnf */
if (AUTO_DEMANGLING)
{
set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
}
-#endif
}
}
else
/* The N_SO starting this symtab is the first symbol, so we
better not check the symbol before it. I'm not this can
happen, but it doesn't hurt to check for it. */
- bfd_seek (symfile_bfd, sym_offset, L_INCR);
+ bfd_seek (symfile_bfd, sym_offset, SEEK_CUR);
processing_gcc_compilation = 0;
}
else if (STREQ (namestring, GCC2_COMPILED_FLAG_SYMBOL))
processing_gcc_compilation = 2;
-#if 1 /* Works, but is experimental. -fnf */
if (AUTO_DEMANGLING)
{
set_demangling_style (GNU_DEMANGLING_STYLE_STRING);
}
-#endif
}
else if (type & N_EXT || type == (unsigned char)N_TEXT
|| type == (unsigned char)N_NBTEXT
if (last_source_start_addr == 0)
last_source_start_addr = text_offset;
- rtn = end_symtab (text_offset + text_size, 0, 0, objfile);
+ pst->symtab = end_symtab (text_offset + text_size, 0, 0, objfile,
+ SECT_OFF_TEXT);
end_stabs ();
- return (rtn);
}
+
\f
/* This handles a single symbol from the symbol-file, building symbols
into a GDB symtab. It takes these arguments and an implicit argument.
struct section_offsets *section_offsets;
struct objfile *objfile;
{
-#ifndef SUN_FIXED_LBRAC_BUG
+#ifdef SUN_FIXED_LBRAC_BUG
+ /* If SUN_FIXED_LBRAC_BUG is defined, then it tells us whether we need
+ to correct the address of N_LBRAC's. If it is not defined, then
+ we never need to correct the addresses. */
+
/* This records the last pc address we've seen. We depend on there being
an SLINE or FUN or SO before the first LBRAC, since the variable does
not get reset in between reads of different symbol files. */
static CORE_ADDR last_pc_address;
#endif
+
register struct context_stack *new;
/* This remembers the address of the start of a function. It is used
because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries are
static CORE_ADDR function_start_offset;
char *colon_pos;
-#ifndef BLOCK_ADDRESS_FUNCTION_RELATIVE
- /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
- function start address, so just use the text offset. */
- function_start_offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
-#endif
+ /* If this is nonzero, N_LBRAC, N_RBRAC, and N_SLINE entries are relative
+ to the function start address. */
+ int block_address_function_relative;
+
+ /* If this is nonzero, we've seen a non-gcc N_OPT symbol for this source
+ file. */
+ int n_opt_found;
+
+ /* This is true for Solaris (and all other stabs-in-elf systems, hopefully,
+ since it would be silly to do things differently from Solaris), and
+ false for SunOS4 and other a.out file formats. */
+ block_address_function_relative =
+ 0 == strncmp (bfd_get_target (objfile->obfd), "elf", 3);
+
+ if (!block_address_function_relative)
+ /* N_LBRAC, N_RBRAC and N_SLINE entries are not relative to the
+ function start address, so just use the text offset. */
+ function_start_offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
/* Something is wrong if we see real data before
seeing a source file name. */
if (last_source_file == NULL && type != (unsigned char)N_SO)
{
- /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
- where that code is defined. */
- if (IGNORE_SYMBOL (type))
- return;
-
- /* FIXME, this should not be an error, since it precludes extending
- the symbol table information in this way... */
- error ("Invalid symbol data: does not start by identifying a source file.");
+ /* Ignore any symbols which appear before an N_SO symbol. Currently
+ no one puts symbols there, but we should deal gracefully with the
+ case. A complain()t might be in order (if !IGNORE_SYMBOL (type)),
+ but this should not be an error (). */
+ return;
}
switch (type)
break;
}
-#ifndef SUN_FIXED_LBRAC_BUG
+#ifdef SUN_FIXED_LBRAC_BUG
last_pc_address = valu; /* Save for SunOS bug circumcision */
#endif
-#ifdef BLOCK_ADDRESS_FUNCTION_RELATIVE
- /* On Solaris 2.0 compilers, the block addresses and N_SLINE's
- are relative to the start of the function. On normal systems,
- and when using gcc on Solaris 2.0, these addresses are just
- absolute, or relative to the N_SO, depending on
- BLOCK_ADDRESS_ABSOLUTE. */
- function_start_offset = valu;
-#endif
+ if (block_address_function_relative)
+ /* On Solaris 2.0 compilers, the block addresses and N_SLINE's
+ are relative to the start of the function. On normal systems,
+ and when using gcc on Solaris 2.0, these addresses are just
+ absolute, or relative to the N_SO, depending on
+ BLOCK_ADDRESS_ABSOLUTE. */
+ function_start_offset = valu;
within_function = 1;
if (context_stack_depth > 0)
/* This "symbol" just indicates the start of an inner lexical
context within a function. */
-#if defined(BLOCK_ADDRESS_ABSOLUTE) || defined(BLOCK_ADDRESS_FUNCTION_RELATIVE)
- /* Relocate for dynamic loading and Sun ELF acc fn-relative syms. */
+#if defined(BLOCK_ADDRESS_ABSOLUTE)
+ /* Relocate for dynamic loading (?). */
valu += function_start_offset;
#else
- /* On most machines, the block addresses are relative to the
- N_SO, the linker did not relocate them (sigh). */
- valu += last_source_start_addr;
+ if (block_address_function_relative)
+ /* Relocate for Sun ELF acc fn-relative syms. */
+ valu += function_start_offset;
+ else
+ /* On most machines, the block addresses are relative to the
+ N_SO, the linker did not relocate them (sigh). */
+ valu += last_source_start_addr;
#endif
-#ifndef SUN_FIXED_LBRAC_BUG
- if (valu < last_pc_address) {
+#ifdef SUN_FIXED_LBRAC_BUG
+ if (!SUN_FIXED_LBRAC_BUG && valu < last_pc_address) {
/* Patch current LBRAC pc value to match last handy pc value */
complain (&lbrac_complaint);
valu = last_pc_address;
/* This "symbol" just indicates the end of an inner lexical
context that was started with N_LBRAC. */
-#if defined(BLOCK_ADDRESS_ABSOLUTE) || defined(BLOCK_ADDRESS_FUNCTION_RELATIVE)
- /* Relocate for dynamic loading and Sun ELF acc fn-relative syms. */
+#if defined(BLOCK_ADDRESS_ABSOLUTE)
+ /* Relocate for dynamic loading (?). */
valu += function_start_offset;
#else
- /* On most machines, the block addresses are relative to the
- N_SO, the linker did not relocate them (sigh). */
- valu += last_source_start_addr;
+ if (block_address_function_relative)
+ /* Relocate for Sun ELF acc fn-relative syms. */
+ valu += function_start_offset;
+ else
+ /* On most machines, the block addresses are relative to the
+ N_SO, the linker did not relocate them (sigh). */
+ valu += last_source_start_addr;
#endif
new = pop_context();
/* Relocate for dynamic loading */
valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
-#ifndef SUN_FIXED_LBRAC_BUG
+ n_opt_found = 0;
+
+#ifdef SUN_FIXED_LBRAC_BUG
last_pc_address = valu; /* Save for SunOS bug circumcision */
#endif
-
+
#ifdef PCC_SOL_BROKEN
/* pcc bug, occasionally puts out SO for SOL. */
if (context_stack_depth > 0)
patch_subfile_names (current_subfile, name);
break; /* Ignore repeated SOs */
}
- end_symtab (valu, 0, 0, objfile);
+ end_symtab (valu, 0, 0, objfile, SECT_OFF_TEXT);
end_stabs ();
}
start_stabs ();
Enter it in the line list for this symbol table. */
/* Relocate for dynamic loading and for ELF acc fn-relative syms. */
valu += function_start_offset;
-#ifndef SUN_FIXED_LBRAC_BUG
+#ifdef SUN_FIXED_LBRAC_BUG
last_pc_address = valu; /* Save for SunOS bug circumcision */
#endif
record_line (current_subfile, desc, valu);
case N_BCOMM:
if (common_block)
- error ("Invalid symbol data: common within common at symtab pos %d",
- symnum);
+ {
+ static struct complaint msg = {
+ "Invalid symbol data: common within common at symtab pos %d",
+ 0, 0};
+ complain (&msg, symnum);
+ }
common_block = local_symbols;
common_block_i = local_symbols ? local_symbols->nsyms : 0;
break;
}
#endif
}
+ else
+ n_opt_found = 1;
}
break;
}
\f
/* Copy a pending list, used to record the contents of a common
- block for later fixup. */
+ block for later fixup. We copy the symbols starting with all
+ symbols in BEG, and ending with the symbols which are in
+ END at index ENDI. */
static struct pending *
-copy_pending (beg, begi, end)
+copy_pending (beg, endi, end)
struct pending *beg;
- int begi;
+ int endi;
struct pending *end;
{
struct pending *new = 0;
struct pending *next;
+ int j;
- for (next = beg; next != 0 && (next != end || begi < end->nsyms);
- next = next->next, begi = 0)
+ /* Copy all the struct pendings before end. */
+ for (next = beg; next != NULL && next != end; next = next->next)
{
- register int j;
- for (j = begi; j < next->nsyms; j++)
+ for (j = 0; j < next->nsyms; j++)
add_symbol_to_list (next->symbol[j], &new);
}
+
+ /* Copy however much of END we need. */
+ for (j = endi; j < end->nsyms; j++)
+ add_symbol_to_list (end->symbol[j], &new);
+
return new;
}
\f
/* Now read in the string table in one big gulp. */
- val = bfd_seek (sym_bfd, stabstroffset, L_SET);
+ val = bfd_seek (sym_bfd, stabstroffset, SEEK_SET);
if (val < 0)
perror_with_name (name);
val = bfd_read (DBX_STRINGTAB (objfile), stabstrsize, 1, sym_bfd);