/* DWARF debugging format support for GDB.
- Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
+ Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996
+ Free Software Foundation, Inc.
Written by Fred Fish at Cygnus Support. Portions based on dbxread.c,
mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*
#include "complaints.h"
#include <fcntl.h>
-#include <string.h>
+#include "gdb_string.h"
#ifndef NO_SYS_FILE
#include <sys/file.h>
#endif
-/* FIXME -- convert this to SEEK_SET a la POSIX, move to config files. */
-#ifndef L_SET
-#define L_SET 0
-#endif
-
/* Some macros to provide DIE info for complaints. */
#define DIE_ID (curdie!=NULL ? curdie->die_ref : 0)
"DIE @ 0x%x \"%s\", array not row major; not handled correctly", 0, 0
};
+struct complaint missing_at_name =
+{
+ "DIE @ 0x%x, AT_name tag missing", 0, 0
+};
+
typedef unsigned int DIE_REF; /* Reference to a DIE */
#ifndef GCC_PRODUCER
static int dbroff; /* Relative offset from start of .debug section */
static char *lnbase; /* Base pointer to line section */
static int isreg; /* Kludge to identify register variables */
+static int optimized_out; /* Kludge to identify optimized out variables */
/* Kludge to identify basereg references. Nonzero if we have an offset
relative to a basereg. */
static int offreg;
only used to pass one value (baseaddr) at the moment. */
static struct section_offsets *base_section_offsets;
-/* 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. For DWARF debugging info, this data is
- contained in the following structure and macros are provided for easy
- access to the members given a pointer to a partial symbol table entry.
-
- dbfoff Always the absolute file offset to the start of the ".debug"
- section for the file containing the DIE's being accessed.
-
- dbroff Relative offset from the start of the ".debug" access to the
- first DIE to be accessed. When building the partial symbol
- table, this value will be zero since we are accessing the
- entire ".debug" section. When expanding a partial symbol
- table entry, this value will be the offset to the first
- DIE for the compilation unit containing the symbol that
- triggers the expansion.
-
- dblength The size of the chunk of DIE's being examined, in bytes.
-
- lnfoff The absolute file offset to the line table fragment. Ignored
- when building partial symbol tables, but used when expanding
- them, and contains the absolute file offset to the fragment
- of the ".line" section containing the line numbers for the
- current compilation unit.
- */
+/* We put a pointer to this structure in the read_symtab_private field
+ of the psymtab. */
struct dwfinfo {
- file_ptr dbfoff; /* Absolute file offset to start of .debug section */
- int dbroff; /* Relative offset from start of .debug section */
- int dblength; /* Size of the chunk of DIE's being examined */
- file_ptr lnfoff; /* Absolute file offset to line table fragment */
+ /* Always the absolute file offset to the start of the ".debug"
+ section for the file containing the DIE's being accessed. */
+ file_ptr dbfoff;
+ /* Relative offset from the start of the ".debug" section to the
+ first DIE to be accessed. When building the partial symbol
+ table, this value will be zero since we are accessing the
+ entire ".debug" section. When expanding a partial symbol
+ table entry, this value will be the offset to the first
+ DIE for the compilation unit containing the symbol that
+ triggers the expansion. */
+ int dbroff;
+ /* The size of the chunk of DIE's being examined, in bytes. */
+ int dblength;
+ /* The absolute file offset to the line table fragment. Ignored
+ when building partial symbol tables, but used when expanding
+ them, and contains the absolute file offset to the fragment
+ of the ".line" section containing the line numbers for the
+ current compilation unit. */
+ file_ptr lnfoff;
};
#define DBFOFF(p) (((struct dwfinfo *)((p)->read_symtab_private))->dbfoff)
/* Forward declarations of static functions so we don't have to worry
about ordering within this file. */
+static void
+free_utypes PARAMS ((PTR));
+
static int
attribute_size PARAMS ((unsigned int));
static void
add_partial_symbol PARAMS ((struct dieinfo *, struct objfile *));
-static void
-init_psymbol_list PARAMS ((struct objfile *, int));
-
static void
basicdieinfo PARAMS ((struct dieinfo *, char *, struct objfile *));
dbsize = dbfsize;
dbbase = xmalloc (dbsize);
dbroff = 0;
- if ((bfd_seek (abfd, dbfoff, L_SET) != 0) ||
+ if ((bfd_seek (abfd, dbfoff, SEEK_SET) != 0) ||
(bfd_read (dbbase, dbsize, 1, abfd) != dbsize))
{
free (dbbase);
return (utypep);
}
+/*
+
+LOCAL FUNCTION
+
+ free_utypes -- free the utypes array and reset pointer & count
+
+SYNOPSIS
+
+ static void free_utypes (PTR dummy)
+
+DESCRIPTION
+
+ Called via do_cleanups to free the utypes array, reset the pointer to NULL,
+ and set numutypes back to zero. This ensures that the utypes does not get
+ referenced after being freed.
+ */
+
+static void
+free_utypes (dummy)
+ PTR dummy;
+{
+ free (utypes);
+ utypes = NULL;
+ numutypes = 0;
+}
+
+
/*
LOCAL FUNCTION
unsigned short blocksz;
struct symbol *sym;
int nbytes;
+ int unsigned_enum = 1;
if ((type = lookup_utype (dip -> die_ref)) == NULL)
{
SYMBOL_CLASS (sym) = LOC_CONST;
SYMBOL_TYPE (sym) = type;
SYMBOL_VALUE (sym) = list -> field.bitpos;
+ if (SYMBOL_VALUE (sym) < 0)
+ unsigned_enum = 0;
add_symbol_to_list (sym, list_in_scope);
}
/* Now create the vector of fields, and record how big it is. This is
vector. */
if (nfields > 0)
{
+ if (unsigned_enum)
+ TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
TYPE_NFIELDS (type) = nfields;
TYPE_FIELDS (type) = (struct field *)
obstack_alloc (&objfile->symbol_obstack, sizeof (struct field) * nfields);
{
register struct context_stack *new;
+ /* AT_name is absent if the function is described with an
+ AT_abstract_origin tag.
+ Ignore the function description for now to avoid GDB core dumps.
+ FIXME: Add code to handle AT_abstract_origin tags properly. */
+ if (dip -> at_name == NULL)
+ {
+ complain (&missing_at_name, DIE_ID);
+ return;
+ }
+
if (objfile -> ei.entry_point >= dip -> at_low_pc &&
objfile -> ei.entry_point < dip -> at_high_pc)
{
}
numutypes = (enddie - thisdie) / 4;
utypes = (struct type **) xmalloc (numutypes * sizeof (struct type *));
- back_to = make_cleanup (free, utypes);
+ back_to = make_cleanup (free_utypes, NULL);
memset (utypes, 0, numutypes * sizeof (struct type *));
memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *));
start_symtab (dip -> at_name, dip -> at_comp_dir, dip -> at_low_pc);
decode_line_numbers (lnbase);
process_dies (thisdie + dip -> die_length, enddie, objfile);
- symtab = end_symtab (dip -> at_high_pc, 0, 0, objfile, 0);
+ symtab = end_symtab (dip -> at_high_pc, objfile, 0);
if (symtab != NULL)
{
symtab -> language = cu_language;
}
do_cleanups (back_to);
- utypes = NULL;
- numutypes = 0;
}
/*
Given pointer to a string of bytes that define a location, compute
the location and return the value.
+ A location description containing no atoms indicates that the
+ object is optimized out. The global optimized_out flag is set for
+ those, the return value is meaningless.
When computing values involving the current value of the frame pointer,
the value zero is used, which results in a value relative to the frame
stack[stacki] = 0;
isreg = 0;
offreg = 0;
+ optimized_out = 1;
loc_value_size = TARGET_FT_LONG_SIZE (current_objfile);
while (loc < end)
{
+ optimized_out = 0;
loc_atom_code = target_to_host (loc, SIZEOF_LOC_ATOM_CODE, GET_UNSIGNED,
current_objfile);
loc += SIZEOF_LOC_ATOM_CODE;
foffset = DBFOFF(pst) + dbroff;
base_section_offsets = pst->section_offsets;
baseaddr = ANOFFSET (pst->section_offsets, 0);
- if (bfd_seek (abfd, foffset, L_SET) ||
+ if (bfd_seek (abfd, foffset, SEEK_SET) ||
(bfd_read (dbbase, dbsize, 1, abfd) != dbsize))
{
free (dbbase);
lnbase = NULL;
if (LNFOFF (pst))
{
- if (bfd_seek (abfd, LNFOFF (pst), L_SET) ||
+ if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
(bfd_read ((PTR) lnsizedata, sizeof (lnsizedata), 1, abfd) !=
sizeof (lnsizedata)))
{
lnsize = target_to_host (lnsizedata, SIZEOF_LINETBL_LENGTH,
GET_UNSIGNED, pst -> objfile);
lnbase = xmalloc (lnsize);
- if (bfd_seek (abfd, LNFOFF (pst), L_SET) ||
+ if (bfd_seek (abfd, LNFOFF (pst), SEEK_SET) ||
(bfd_read (lnbase, lnsize, 1, abfd) != lnsize))
{
free (lnbase);
/*
-LOCAL FUNCTION
-
- init_psymbol_list -- initialize storage for partial symbols
-
-SYNOPSIS
-
- static void init_psymbol_list (struct objfile *objfile, int total_symbols)
-
-DESCRIPTION
-
- Initializes storage for all of the partial symbols that will be
- created by dwarf_build_psymtabs and subsidiaries.
- */
-
-static void
-init_psymbol_list (objfile, total_symbols)
- struct objfile *objfile;
- int total_symbols;
-{
- /* Free any previously allocated psymbol lists. */
-
- if (objfile -> global_psymbols.list)
- {
- mfree (objfile -> md, (PTR)objfile -> global_psymbols.list);
- }
- if (objfile -> static_psymbols.list)
- {
- mfree (objfile -> md, (PTR)objfile -> static_psymbols.list);
- }
-
- /* Current best guess is that there are approximately a twentieth
- of the total symbols (in a debugging file) are global or static
- oriented symbols */
-
- objfile -> global_psymbols.size = total_symbols / 10;
- objfile -> static_psymbols.size = total_symbols / 10;
- objfile -> global_psymbols.next =
- objfile -> global_psymbols.list = (struct partial_symbol *)
- xmmalloc (objfile -> md, objfile -> global_psymbols.size
- * sizeof (struct partial_symbol));
- objfile -> static_psymbols.next =
- objfile -> static_psymbols.list = (struct partial_symbol *)
- xmmalloc (objfile -> md, objfile -> static_psymbols.size
- * sizeof (struct partial_symbol));
-}
-
-/*
-
LOCAL FUNCTION
add_enum_psymbol -- add enumeration members to partial symbol table
while (scan < listend)
{
scan += TARGET_FT_LONG_SIZE (objfile);
- ADD_PSYMBOL_TO_LIST (scan, strlen (scan), VAR_NAMESPACE, LOC_CONST,
- objfile -> static_psymbols, 0, cu_language,
+ add_psymbol_to_list (scan, strlen (scan), VAR_NAMESPACE, LOC_CONST,
+ &objfile -> static_psymbols, 0, 0, cu_language,
objfile);
scan += strlen (scan) + 1;
}
switch (dip -> die_tag)
{
case TAG_global_subroutine:
- ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
- VAR_NAMESPACE, LOC_BLOCK,
- objfile -> global_psymbols,
- dip -> at_low_pc, cu_language, objfile);
+ add_psymbol_to_list (dip -> at_name, strlen (dip -> at_name),
+ VAR_NAMESPACE, LOC_BLOCK,
+ &objfile -> global_psymbols,
+ 0, dip -> at_low_pc, cu_language, objfile);
break;
case TAG_global_variable:
- ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
+ add_psymbol_to_list (dip -> at_name, strlen (dip -> at_name),
VAR_NAMESPACE, LOC_STATIC,
- objfile -> global_psymbols,
- 0, cu_language, objfile);
+ &objfile -> global_psymbols,
+ 0, 0, cu_language, objfile);
break;
case TAG_subroutine:
- ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
- VAR_NAMESPACE, LOC_BLOCK,
- objfile -> static_psymbols,
- dip -> at_low_pc, cu_language, objfile);
+ add_psymbol_to_list (dip -> at_name, strlen (dip -> at_name),
+ VAR_NAMESPACE, LOC_BLOCK,
+ &objfile -> static_psymbols,
+ 0, dip -> at_low_pc, cu_language, objfile);
break;
case TAG_local_variable:
- ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
+ add_psymbol_to_list (dip -> at_name, strlen (dip -> at_name),
VAR_NAMESPACE, LOC_STATIC,
- objfile -> static_psymbols,
- 0, cu_language, objfile);
+ &objfile -> static_psymbols,
+ 0, 0, cu_language, objfile);
break;
case TAG_typedef:
- ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
+ add_psymbol_to_list (dip -> at_name, strlen (dip -> at_name),
VAR_NAMESPACE, LOC_TYPEDEF,
- objfile -> static_psymbols,
- 0, cu_language, objfile);
+ &objfile -> static_psymbols,
+ 0, 0, cu_language, objfile);
break;
case TAG_class_type:
case TAG_structure_type:
/* Do not add opaque aggregate definitions to the psymtab. */
if (!dip -> has_at_byte_size)
break;
- ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
+ add_psymbol_to_list (dip -> at_name, strlen (dip -> at_name),
STRUCT_NAMESPACE, LOC_TYPEDEF,
- objfile -> static_psymbols,
- 0, cu_language, objfile);
+ &objfile -> static_psymbols,
+ 0, 0, cu_language, objfile);
if (cu_language == language_cplus)
{
/* For C++, these implicitly act as typedefs as well. */
- ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
+ add_psymbol_to_list (dip -> at_name, strlen (dip -> at_name),
VAR_NAMESPACE, LOC_TYPEDEF,
- objfile -> static_psymbols,
- 0, cu_language, objfile);
+ &objfile -> static_psymbols,
+ 0, 0, cu_language, objfile);
}
break;
}
{
sym = (struct symbol *) obstack_alloc (&objfile -> symbol_obstack,
sizeof (struct symbol));
+ OBJSTAT (objfile, n_syms++);
memset (sym, 0, sizeof (struct symbol));
SYMBOL_NAME (sym) = create_name (dip -> at_name,
&objfile->symbol_obstack);
switch (dip -> die_tag)
{
case TAG_label:
- SYMBOL_VALUE (sym) = dip -> at_low_pc;
+ SYMBOL_VALUE_ADDRESS (sym) = dip -> at_low_pc;
SYMBOL_CLASS (sym) = LOC_LABEL;
break;
case TAG_global_subroutine:
case TAG_subroutine:
- SYMBOL_VALUE (sym) = dip -> at_low_pc;
+ SYMBOL_VALUE_ADDRESS (sym) = dip -> at_low_pc;
SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
SYMBOL_CLASS (sym) = LOC_BLOCK;
if (dip -> die_tag == TAG_global_subroutine)
{
SYMBOL_VALUE (sym) = locval (dip -> at_location);
add_symbol_to_list (sym, list_in_scope);
- if (isreg)
+ if (optimized_out)
+ {
+ SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
+ }
+ else if (isreg)
{
SYMBOL_CLASS (sym) = LOC_REGISTER;
}
{
sym = (struct symbol *)
obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
+ OBJSTAT (objfile, n_syms++);
memset (sym, 0, sizeof (struct symbol));
SYMBOL_NAME (sym) = create_name (dip -> at_name,
&objfile->symbol_obstack);