/* DWARF 2 debugging format support for GDB.
- Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
- 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 1994-2012 Free Software Foundation, Inc.
Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
Inc. with support from Florida State University (under contract
typedef struct symbol *symbolp;
DEF_VEC_P (symbolp);
-#if 0
-/* .debug_info header for a compilation unit
- Because of alignment constraints, this structure has padding and cannot
- be mapped directly onto the beginning of the .debug_info section. */
-typedef struct comp_unit_header
- {
- unsigned int length; /* length of the .debug_info
- contribution */
- unsigned short version; /* version number -- 2 for DWARF
- version 2 */
- unsigned int abbrev_offset; /* offset into .debug_abbrev section */
- unsigned char addr_size; /* byte size of an address -- 4 */
- }
-_COMP_UNIT_HEADER;
-#define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
-#endif
-
/* .debug_line statement program prologue
Because of alignment constraints, this structure has padding and cannot
be mapped directly onto the beginning of the .debug_info section. */
const char *constant_pool;
};
+/* Collection of data recorded per objfile.
+ This hangs off of dwarf2_objfile_data_key. */
+
struct dwarf2_per_objfile
{
struct dwarf2_section_info info;
/* Note that if the debugging section has been compressed, it might
have a name like .zdebug_info. */
-static const struct dwarf2_debug_sections dwarf2_elf_names = {
+static const struct dwarf2_debug_sections dwarf2_elf_names =
+{
{ ".debug_info", ".zdebug_info" },
{ ".debug_abbrev", ".zdebug_abbrev" },
{ ".debug_line", ".zdebug_line" },
This test is imperfect as there may exist optimized debug code not using
any location list and still facing inlining issues if handled as
unoptimized code. For a future better test see GCC PR other/32998. */
-
unsigned int has_loclist : 1;
};
/* Persistent data held for a compilation unit, even when not
processing it. We put a pointer to this structure in the
- read_symtab_private field of the psymtab. If we encounter
- inter-compilation-unit references, we also maintain a sorted
- list of all compilation units. */
+ read_symtab_private field of the psymtab. */
struct dwarf2_per_cu_data
{
of the CU cache it gets reset to NULL again. */
struct dwarf2_cu *cu;
- /* The corresponding objfile. */
+ /* The corresponding objfile.
+ Normally we can get the objfile from dwarf2_per_objfile.
+ However we can enter this file with just a "per_cu" handle. */
struct objfile *objfile;
/* When using partial symbol tables, the 'psymtab' field is active.
static void psymtab_to_symtab_1 (struct partial_symtab *);
-static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu);
+static void dwarf2_read_abbrevs (struct dwarf2_cu *cu);
static void dwarf2_free_abbrev_table (void *);
struct dwarf2_section_info *section,
unsigned int offset);
-static void read_signatured_type_at_offset (struct objfile *objfile,
- struct dwarf2_section_info *sect,
- unsigned int offset);
+static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
-static void read_signatured_type (struct objfile *,
- struct signatured_type *type_sig);
+static void read_signatured_type (struct signatured_type *type_sig);
/* memory allocation interface */
(unsigned int offset, struct objfile *objfile);
static void init_one_comp_unit (struct dwarf2_cu *cu,
- struct objfile *objfile);
+ struct dwarf2_per_cu_data *per_cu);
static void prepare_one_comp_unit (struct dwarf2_cu *cu,
struct die_info *comp_unit_die);
-static void free_one_comp_unit (void *);
+static void free_heap_comp_unit (void *);
static void free_cached_comp_units (void *);
static int create_debug_types_hash_table (struct objfile *objfile);
-static void load_full_comp_unit (struct dwarf2_per_cu_data *,
- struct objfile *);
+static void load_full_comp_unit (struct dwarf2_per_cu_data *);
static void process_full_comp_unit (struct dwarf2_per_cu_data *);
static void dwarf2_release_queue (void *dummy);
-static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
- struct objfile *objfile);
+static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu);
-static void process_queue (struct objfile *objfile);
+static void process_queue (void);
static void find_file_and_directory (struct die_info *die,
struct dwarf2_cu *cu,
return info->asection == NULL || info->size == 0;
}
-/* Read the contents of the section SECTP from object file specified by
+/* Read the contents of the section INFO from object file specified by
OBJFILE, store info about the section into INFO.
If the section is compressed, uncompress it before returning. */
load_cu (struct dwarf2_per_cu_data *per_cu)
{
if (per_cu->debug_types_section)
- read_signatured_type_at_offset (per_cu->objfile,
- per_cu->debug_types_section,
- per_cu->offset);
+ load_full_type_unit (per_cu);
else
- load_full_comp_unit (per_cu, per_cu->objfile);
-
- dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
+ load_full_comp_unit (per_cu);
gdb_assert (per_cu->cu != NULL);
+
+ dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
}
-/* Read in the symbols for PER_CU. OBJFILE is the objfile from which
- this CU came. */
+/* Read in the symbols for PER_CU. */
static void
-dw2_do_instantiate_symtab (struct objfile *objfile,
- struct dwarf2_per_cu_data *per_cu)
+dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
{
struct cleanup *back_to;
back_to = make_cleanup (dwarf2_release_queue, NULL);
- queue_comp_unit (per_cu, objfile);
+ queue_comp_unit (per_cu);
load_cu (per_cu);
- process_queue (objfile);
+ process_queue ();
/* Age the cache, releasing compilation units that have not
been used recently. */
table. */
static struct symtab *
-dw2_instantiate_symtab (struct objfile *objfile,
- struct dwarf2_per_cu_data *per_cu)
+dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
{
if (!per_cu->v.quick->symtab)
{
struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL);
increment_reading_symtab ();
- dw2_do_instantiate_symtab (objfile, per_cu);
+ dw2_do_instantiate_symtab (per_cu);
do_cleanups (back_to);
}
return per_cu->v.quick->symtab;
if (this_cu->v.quick->no_file_data)
return NULL;
- init_one_comp_unit (&cu, objfile);
+ init_one_comp_unit (&cu, this_cu);
cleanups = make_cleanup (free_stack_comp_unit, &cu);
if (this_cu->debug_types_section)
return NULL;
}
- this_cu->cu = &cu;
- cu.per_cu = this_cu;
-
- dwarf2_read_abbrevs (abfd, &cu);
+ dwarf2_read_abbrevs (&cu);
make_cleanup (dwarf2_free_abbrev_table, &cu);
init_cu_die_reader (&reader_specs, &cu);
dw2_setup (objfile);
index = dwarf2_per_objfile->n_comp_units - 1;
- return dw2_instantiate_symtab (objfile, dw2_get_cu (index));
+ return dw2_instantiate_symtab (dw2_get_cu (index));
}
/* Traversal function for dw2_forget_cached_source_info. */
/* This may expand more than one symtab, and we want to iterate over
all of them. */
- dw2_instantiate_symtab (objfile, per_cu);
+ dw2_instantiate_symtab (per_cu);
return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
objfile->symtabs, last_made);
offset_type cu_index = MAYBE_SWAP (vec[i + 1]);
struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index);
- dw2_instantiate_symtab (objfile, per_cu);
+ dw2_instantiate_symtab (per_cu);
}
}
}
{
struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i);
- dw2_instantiate_symtab (objfile, per_cu);
+ dw2_instantiate_symtab (per_cu);
}
}
const char *this_name = file_data->file_names[j];
if (FILENAME_CMP (this_name, filename) == 0)
{
- dw2_instantiate_symtab (objfile, per_cu);
+ dw2_instantiate_symtab (per_cu);
break;
}
}
per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1]));
if (file_matcher == NULL || per_cu->v.quick->mark)
- dw2_instantiate_symtab (objfile, per_cu);
+ dw2_instantiate_symtab (per_cu);
}
}
}
warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
paddress (get_objfile_arch (objfile), pc));
- return dw2_instantiate_symtab (objfile, data);
+ return dw2_instantiate_symtab (data);
}
static void
Returns a pointer to the next CU. */
static gdb_byte *
-process_psymtab_comp_unit (struct objfile *objfile,
- struct dwarf2_per_cu_data *this_cu,
+process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
gdb_byte *buffer, gdb_byte *info_ptr,
unsigned int buffer_size)
{
+ struct objfile *objfile = this_cu->objfile;
bfd *abfd = objfile->obfd;
gdb_byte *beg_of_comp_unit = info_ptr;
struct die_info *comp_unit_die;
struct die_reader_specs reader_specs;
const char *filename;
- init_one_comp_unit (&cu, objfile);
+ /* If this compilation unit was already read in, free the
+ cached copy in order to read it in again. This is
+ necessary because we skipped some symbols when we first
+ read in the compilation unit (see load_partial_dies).
+ This problem could be avoided, but the benefit is
+ unclear. */
+ if (this_cu->cu != NULL)
+ free_one_cached_comp_unit (this_cu->cu);
+
+ /* Note that this is a pointer to our stack frame, being
+ added to a global data structure. It will be cleaned up
+ in free_stack_comp_unit when we finish with this
+ compilation unit. */
+ init_one_comp_unit (&cu, this_cu);
back_to_inner = make_cleanup (free_stack_comp_unit, &cu);
info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr,
cu.list_in_scope = &file_symbols;
- /* If this compilation unit was already read in, free the
- cached copy in order to read it in again. This is
- necessary because we skipped some symbols when we first
- read in the compilation unit (see load_partial_dies).
- This problem could be avoided, but the benefit is
- unclear. */
- if (this_cu->cu != NULL)
- free_one_cached_comp_unit (this_cu->cu);
-
- /* Note that this is a pointer to our stack frame, being
- added to a global data structure. It will be cleaned up
- in free_stack_comp_unit when we finish with this
- compilation unit. */
- this_cu->cu = &cu;
- cu.per_cu = this_cu;
-
/* Read the abbrevs for this compilation unit into a table. */
- dwarf2_read_abbrevs (abfd, &cu);
+ dwarf2_read_abbrevs (&cu);
make_cleanup (dwarf2_free_abbrev_table, &cu);
/* Read the compilation unit die. */
process_type_comp_unit (void **slot, void *info)
{
struct signatured_type *entry = (struct signatured_type *) *slot;
- struct objfile *objfile = (struct objfile *) info;
struct dwarf2_per_cu_data *this_cu;
+ gdb_assert (info == NULL);
this_cu = &entry->per_cu;
gdb_assert (this_cu->debug_types_section->readin);
- process_psymtab_comp_unit (objfile, this_cu,
+ process_psymtab_comp_unit (this_cu,
this_cu->debug_types_section->buffer,
(this_cu->debug_types_section->buffer
+ this_cu->offset),
return;
htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
- process_type_comp_unit, objfile);
+ process_type_comp_unit, NULL);
}
/* A cleanup function that clears objfile's psymtabs_addrmap field. */
- dwarf2_per_objfile->info.buffer,
objfile);
- info_ptr = process_psymtab_comp_unit (objfile, this_cu,
+ info_ptr = process_psymtab_comp_unit (this_cu,
dwarf2_per_objfile->info.buffer,
info_ptr,
dwarf2_per_objfile->info.size);
/* Load the partial DIEs for a secondary CU into memory. */
static void
-load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu,
- struct objfile *objfile)
+load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
{
+ struct objfile *objfile = this_cu->objfile;
bfd *abfd = objfile->obfd;
gdb_byte *info_ptr;
struct die_info *comp_unit_die;
if (this_cu->cu == NULL)
{
cu = xmalloc (sizeof (*cu));
- init_one_comp_unit (cu, objfile);
+ init_one_comp_unit (cu, this_cu);
read_cu = 1;
/* If an error occurs while loading, release our storage. */
- free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
+ free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr,
dwarf2_per_objfile->info.buffer,
return;
}
- /* Link this compilation unit into the compilation unit tree. */
- this_cu->cu = cu;
- cu->per_cu = this_cu;
-
/* Link this CU into read_in_chain. */
this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
dwarf2_per_objfile->read_in_chain = this_cu;
/* Read the abbrevs for this compilation unit into a table. */
gdb_assert (cu->dwarf2_abbrevs == NULL);
- dwarf2_read_abbrevs (abfd, cu);
+ dwarf2_read_abbrevs (cu);
free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
/* Read the compilation unit die. */
}
}
-/* Create a list of all compilation units in OBJFILE. We do this only
- if an inter-comp-unit reference is found; presumably if there is one,
- there will be many, and one will occur early in the .debug_info section.
- So there's no point in building this list incrementally. */
+/* Create a list of all compilation units in OBJFILE.
+ This is only done for -readnow and building partial symtabs. */
static void
create_all_comp_units (struct objfile *objfile)
}
}
}
+\f
+/* Reading in full CUs. */
/* Add PER_CU to the queue. */
static void
-queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile)
+queue_comp_unit (struct dwarf2_per_cu_data *per_cu)
{
struct dwarf2_queue_item *item;
/* Process the queue. */
static void
-process_queue (struct objfile *objfile)
+process_queue (void)
{
struct dwarf2_queue_item *item, *next_item;
return;
}
- dw2_do_instantiate_symtab (pst->objfile, per_cu);
+ dw2_do_instantiate_symtab (per_cu);
}
/* Load the DIEs associated with PER_CU into memory. */
static void
-load_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
- struct objfile *objfile)
+load_full_comp_unit (struct dwarf2_per_cu_data *per_cu)
{
+ struct objfile *objfile = per_cu->objfile;
bfd *abfd = objfile->obfd;
struct dwarf2_cu *cu;
unsigned int offset;
if (per_cu->cu == NULL)
{
cu = xmalloc (sizeof (*cu));
- init_one_comp_unit (cu, objfile);
+ init_one_comp_unit (cu, per_cu);
read_cu = 1;
/* If an error occurs while loading, release our storage. */
- free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
+ free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
/* Read in the comp_unit header. */
info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd);
cu->header.first_die_offset = info_ptr - beg_of_comp_unit;
/* Read the abbrevs for this compilation unit. */
- dwarf2_read_abbrevs (abfd, cu);
+ dwarf2_read_abbrevs (cu);
free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu);
- /* Link this compilation unit into the compilation unit tree. */
- per_cu->cu = cu;
- cu->per_cu = per_cu;
-
/* Link this CU into read_in_chain. */
per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain;
dwarf2_per_objfile->read_in_chain = per_cu;
cu->dies = read_comp_unit (info_ptr, cu);
/* We try not to read any attributes in this function, because not
- all objfiles needed for references have been loaded yet, and symbol
+ all CUs needed for references have been loaded yet, and symbol
table processing isn't initialized. But we have to set the CU language,
or we won't be able to build types correctly. */
prepare_one_comp_unit (cu, cu->dies);
}
}
-/* Generate full symbol information for PST and CU, whose DIEs have
+/* Generate full symbol information for PER_CU, whose DIEs have
already been loaded into memory. */
static void
dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu,
int physname)
{
+ struct objfile *objfile = cu->objfile;
+
if (name == NULL)
name = dwarf2_name (die, cu);
}
}
- name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack,
+ name = ui_file_obsavestring (buf, &objfile->objfile_obstack,
&length);
ui_file_delete (buf);
{
char *cname
= dwarf2_canonicalize_name (name, cu,
- &cu->objfile->objfile_obstack);
+ &objfile->objfile_obstack);
if (cname != NULL)
name = cname;
static const char *
dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu)
{
+ struct objfile *objfile = cu->objfile;
struct attribute *attr;
const char *retval, *mangled = NULL, *canon = NULL;
struct cleanup *back_to;
complaint (&symfile_complaints,
_("Computed physname <%s> does not match demangled <%s> "
"(from linkage <%s>) - DIE at 0x%x [in module %s]"),
- physname, canon, mangled, die->offset, cu->objfile->name);
+ physname, canon, mangled, die->offset, objfile->name);
/* Prefer DW_AT_linkage_name (in the CANON form) - when it
is available here - over computed PHYSNAME. It is safer
if (need_copy)
retval = obsavestring (retval, strlen (retval),
- &cu->objfile->objfile_obstack);
+ &objfile->objfile_obstack);
do_cleanups (back_to);
return retval;
static void
read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
{
+ struct objfile *objfile = cu->objfile;
struct attribute *import_attr;
struct die_info *imported_die, *child_die;
struct dwarf2_cu *imported_cu;
complaint (&symfile_complaints,
_("child DW_TAG_imported_declaration expected "
"- DIE at 0x%x [in module %s]"),
- child_die->offset, cu->objfile->name);
+ child_die->offset, objfile->name);
continue;
}
complaint (&symfile_complaints,
_("child DW_TAG_imported_declaration has unknown "
"imported name - DIE at 0x%x [in module %s]"),
- child_die->offset, cu->objfile->name);
+ child_die->offset, objfile->name);
continue;
}
import_alias,
imported_declaration,
excludes,
- &cu->objfile->objfile_obstack);
+ &objfile->objfile_obstack);
do_cleanups (cleanups);
}
&dwarf2_per_objfile->macinfo, 0);
}
}
+
do_cleanups (back_to);
}
complaint (&symfile_complaints,
_("missing DW_AT_low_pc for DW_TAG_GNU_call_site "
"DIE 0x%x [in module %s]"),
- die->offset, cu->objfile->name);
+ die->offset, objfile->name);
return;
}
pc = DW_ADDR (attr) + baseaddr;
complaint (&symfile_complaints,
_("Duplicate PC %s for DW_TAG_GNU_call_site "
"DIE 0x%x [in module %s]"),
- paddress (gdbarch, pc), die->offset, cu->objfile->name);
+ paddress (gdbarch, pc), die->offset, objfile->name);
return;
}
complaint (&symfile_complaints,
_("Tag %d is not DW_TAG_GNU_call_site_parameter in "
"DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
- child_die->tag, child_die->offset, cu->objfile->name);
+ child_die->tag, child_die->offset, objfile->name);
continue;
}
complaint (&symfile_complaints,
_("Cannot find function owning DW_TAG_GNU_call_site "
"DIE 0x%x [in module %s]"),
- die->offset, cu->objfile->name);
+ die->offset, objfile->name);
}
}
}
else if (is_ref_attr (attr))
{
- struct objfile *objfile = cu->objfile;
struct dwarf2_cu *target_cu = cu;
struct die_info *target_die;
complaint (&symfile_complaints,
_("DW_AT_GNU_call_site_target target DIE has invalid "
"physname, for referencing DIE 0x%x [in module %s]"),
- die->offset, cu->objfile->name);
+ die->offset, objfile->name);
else
SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname);
}
complaint (&symfile_complaints,
_("DW_AT_GNU_call_site_target target DIE has invalid "
"low pc, for referencing DIE 0x%x [in module %s]"),
- die->offset, cu->objfile->name);
+ die->offset, objfile->name);
else
SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr);
}
complaint (&symfile_complaints,
_("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither "
"block nor reference, for DIE 0x%x [in module %s]"),
- die->offset, cu->objfile->name);
+ die->offset, objfile->name);
call_site->per_cu = cu->per_cu;
complaint (&symfile_complaints,
_("No DW_FORM_block* DW_AT_location for "
"DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
- child_die->offset, cu->objfile->name);
+ child_die->offset, objfile->name);
continue;
}
parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data,
_("Only single DW_OP_reg or DW_OP_fbreg is supported "
"for DW_FORM_block* DW_AT_location for "
"DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
- child_die->offset, cu->objfile->name);
+ child_die->offset, objfile->name);
continue;
}
complaint (&symfile_complaints,
_("No DW_FORM_block* DW_AT_GNU_call_site_value for "
"DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
- child_die->offset, cu->objfile->name);
+ child_die->offset, objfile->name);
continue;
}
parameter->value = DW_BLOCK (attr)->data;
complaint (&symfile_complaints,
_("No DW_FORM_block* DW_AT_GNU_call_site_data_value for "
"DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"),
- child_die->offset, cu->objfile->name);
+ child_die->offset, objfile->name);
else
{
parameter->data_value = DW_BLOCK (attr)->data;
dwarf2_record_block_ranges (struct die_info *die, struct block *block,
CORE_ADDR baseaddr, struct dwarf2_cu *cu)
{
+ struct objfile *objfile = cu->objfile;
struct attribute *attr;
attr = dwarf2_attr (die, DW_AT_high_pc, cu);
attr = dwarf2_attr (die, DW_AT_ranges, cu);
if (attr)
{
- bfd *obfd = cu->objfile->obfd;
+ bfd *obfd = objfile->obfd;
/* The value of the DW_AT_ranges attribute is the offset of the
address range list in the .debug_ranges section. */
TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java;
}
- quirk_gcc_member_function_pointer (type, cu->objfile);
+ quirk_gcc_member_function_pointer (type, objfile);
/* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
snapshots) has been known to create a die giving a declaration
static struct type *
read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
{
+ struct objfile *objfile = cu->objfile;
struct type *type; /* Type that this function returns. */
struct type *ftype; /* Function that returns above type. */
struct attribute *attr;
if (die->child != NULL)
{
- struct type *void_type = objfile_type (cu->objfile)->builtin_void;
+ struct type *void_type = objfile_type (objfile)->builtin_void;
struct die_info *child_die;
int nparams, iparams;
{
struct objfile *objfile = cu->objfile;
const char *name = NULL;
- struct type *this_type;
+ struct type *this_type, *target_type;
name = dwarf2_full_name (NULL, die, cu);
this_type = init_type (TYPE_CODE_TYPEDEF, 0,
TYPE_FLAG_TARGET_STUB, NULL, objfile);
TYPE_NAME (this_type) = (char *) name;
set_die_type (die, this_type, cu);
- TYPE_TARGET_TYPE (this_type) = die_type (die, cu);
+ target_type = die_type (die, cu);
+ if (target_type != this_type)
+ TYPE_TARGET_TYPE (this_type) = target_type;
+ else
+ {
+ /* Self-referential typedefs are, it seems, not allowed by the DWARF
+ spec and cause infinite loops in GDB. */
+ complaint (&symfile_complaints,
+ _("Self-referential DW_TAG_typedef "
+ "- DIE at 0x%x [in module %s]"),
+ die->offset, objfile->name);
+ TYPE_TARGET_TYPE (this_type) = NULL;
+ }
return this_type;
}
if (cu->dwarf2_abbrevs == NULL)
{
- dwarf2_read_abbrevs (cu->objfile->obfd, cu);
+ dwarf2_read_abbrevs (cu);
back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
read_abbrevs = 1;
}
the data found in the abbrev table. */
static void
-dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu)
+dwarf2_read_abbrevs (struct dwarf2_cu *cu)
{
+ bfd *abfd = cu->objfile->obfd;
struct comp_unit_head *cu_header = &cu->header;
gdb_byte *abbrev_ptr;
struct abbrev_info *cur_abbrev;
load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr,
int building_psymtab, struct dwarf2_cu *cu)
{
+ struct objfile *objfile = cu->objfile;
struct partial_die_info *part_die;
struct partial_die_info *parent_die, *last_die, *first_die = NULL;
struct abbrev_info *abbrev;
if (building_psymtab && part_die->name != NULL)
add_psymbol_to_list (part_die->name, strlen (part_die->name), 0,
VAR_DOMAIN, LOC_TYPEDEF,
- &cu->objfile->static_psymbols,
- 0, (CORE_ADDR) 0, cu->language, cu->objfile);
+ &objfile->static_psymbols,
+ 0, (CORE_ADDR) 0, cu->language, objfile);
info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
continue;
}
complaint (&symfile_complaints,
_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
"- DIE at 0x%x [in module %s]"),
- part_die->offset, cu->objfile->name);
+ part_die->offset, objfile->name);
/* If we're at the second level, and we're an enumerator, and
our parent has no specification (meaning possibly lives in a
VAR_DOMAIN, LOC_CONST,
(cu->language == language_cplus
|| cu->language == language_java)
- ? &cu->objfile->global_psymbols
- : &cu->objfile->static_psymbols,
- 0, (CORE_ADDR) 0, cu->language, cu->objfile);
+ ? &objfile->global_psymbols
+ : &objfile->static_psymbols,
+ 0, (CORE_ADDR) 0, cu->language, objfile);
info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu);
continue;
gdb_byte *buffer, gdb_byte *info_ptr,
struct dwarf2_cu *cu)
{
+ struct objfile *objfile = cu->objfile;
unsigned int i;
struct attribute attr;
int has_low_pc_attr = 0;
default:
part_die->name
= dwarf2_canonicalize_name (DW_STRING (&attr), cu,
- &cu->objfile->objfile_obstack);
+ &objfile->objfile_obstack);
break;
}
break;
so that GDB will ignore it. */
if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
{
- struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
complaint (&symfile_complaints,
_("DW_AT_low_pc %s is zero "
"for DIE at 0x%x [in module %s]"),
paddress (gdbarch, part_die->lowpc),
- part_die->offset, cu->objfile->name);
+ part_die->offset, objfile->name);
}
/* dwarf2_get_pc_bounds has also the strict low < high requirement. */
else if (part_die->lowpc >= part_die->highpc)
{
- struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
complaint (&symfile_complaints,
_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
"for DIE at 0x%x [in module %s]"),
paddress (gdbarch, part_die->lowpc),
paddress (gdbarch, part_die->highpc),
- part_die->offset, cu->objfile->name);
+ part_die->offset, objfile->name);
}
else
part_die->has_pc_info = 1;
static struct partial_die_info *
find_partial_die (unsigned int offset, struct dwarf2_cu *cu)
{
+ struct objfile *objfile = cu->objfile;
struct dwarf2_per_cu_data *per_cu = NULL;
struct partial_die_info *pd = NULL;
return pd;
}
- per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile);
+ per_cu = dwarf2_find_containing_comp_unit (offset, objfile);
if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
- load_partial_comp_unit (per_cu, cu->objfile);
+ load_partial_comp_unit (per_cu);
per_cu->cu->last_used = 0;
pd = find_partial_die_in_comp_unit (offset, per_cu->cu);
back_to = make_cleanup (null_cleanup, 0);
if (per_cu->cu->dwarf2_abbrevs == NULL)
{
- dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu);
+ dwarf2_read_abbrevs (per_cu->cu);
make_cleanup (dwarf2_free_abbrev_table, per_cu->cu);
}
info_ptr = (dwarf2_per_objfile->info.buffer
+ per_cu->cu->header.first_die_offset);
abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu);
info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read,
- per_cu->cu->objfile->obfd,
+ objfile->obfd,
dwarf2_per_objfile->info.buffer, info_ptr,
per_cu->cu);
if (comp_unit_die.has_children)
- load_partial_dies (per_cu->cu->objfile->obfd,
+ load_partial_dies (objfile->obfd,
dwarf2_per_objfile->info.buffer, info_ptr,
0, per_cu->cu);
do_cleanups (back_to);
internal_error (__FILE__, __LINE__,
_("could not find partial DIE 0x%x "
"in cache [from module %s]\n"),
- offset, bfd_get_filename (cu->objfile->obfd));
+ offset, bfd_get_filename (objfile->obfd));
return pd;
}
complaint (&symfile_complaints,
_(".debug_line address at offset 0x%lx is 0 "
"[in module %s]"),
- line_offset, cu->objfile->name);
+ line_offset, objfile->name);
p_record_line = noop_record_line;
}
if (current_subfile->symtab == NULL)
current_subfile->symtab = allocate_symtab (current_subfile->name,
- cu->objfile);
+ objfile);
fe->symtab = current_subfile->symtab;
}
}
lookup_die_type (struct die_info *die, struct attribute *attr,
struct dwarf2_cu *cu)
{
+ struct objfile *objfile = cu->objfile;
struct type *this_type;
/* First see if we have it cached. */
if (sig_type == NULL)
error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
"at 0x%x [in module %s]"),
- die->offset, cu->objfile->name);
+ die->offset, objfile->name);
gdb_assert (sig_type->per_cu.debug_types_section);
offset = sig_type->per_cu.offset + sig_type->type_offset;
{
dump_die_for_error (die);
error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
- dwarf_attr_name (attr->name), cu->objfile->name);
+ dwarf_attr_name (attr->name), objfile->name);
}
/* If not cached we need to read it in. */
/* read_type_die already issued a complaint. */
message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
- cu->objfile->name,
+ objfile->name,
cu->header.offset,
die->offset);
- saved = obstack_copy0 (&cu->objfile->objfile_obstack,
+ saved = obstack_copy0 (&objfile->objfile_obstack,
message, strlen (message));
xfree (message);
- this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile);
+ this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile);
}
return this_type;
}
/* Add it to the queue. */
- queue_comp_unit (per_cu, this_cu->objfile);
+ queue_comp_unit (per_cu);
return 1;
}
/* If necessary, add it to the queue and load its DIEs. */
if (maybe_queue_comp_unit (cu, per_cu))
- load_full_comp_unit (per_cu, cu->objfile);
+ load_full_comp_unit (per_cu);
target_cu = per_cu->cu;
}
{
/* We're loading full DIEs during partial symbol reading. */
gdb_assert (dwarf2_per_objfile->reading_partial_symbols);
- load_full_comp_unit (cu->per_cu, cu->objfile);
+ load_full_comp_unit (cu->per_cu);
}
*ref_cu = target_cu;
die = follow_die_offset (offset, &cu);
if (!die)
error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
- offset, per_cu->cu->objfile->name);
+ offset, per_cu->objfile->name);
attr = dwarf2_attr (die, DW_AT_location, cu);
if (!attr)
if (!attr_form_is_block (attr))
error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
"is neither DW_FORM_block* nor DW_FORM_exprloc"),
- offset, per_cu->cu->objfile->name);
+ offset, per_cu->objfile->name);
retval.data = DW_BLOCK (attr)->data;
retval.size = DW_BLOCK (attr)->size;
/* If necessary, add it to the queue and load its DIEs. */
if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu))
- read_signatured_type (objfile, sig_type);
+ read_signatured_type (sig_type);
gdb_assert (sig_type->per_cu.cu != NULL);
return type_sig;
}
-/* Read in signatured type at OFFSET and build its CU and die(s). */
+/* Load the DIEs associated with type unit PER_CU into memory. */
static void
-read_signatured_type_at_offset (struct objfile *objfile,
- struct dwarf2_section_info *sect,
- unsigned int offset)
+load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
{
+ struct objfile *objfile = per_cu->objfile;
+ struct dwarf2_section_info *sect = per_cu->debug_types_section;
+ unsigned int offset = per_cu->offset;
struct signatured_type *type_sig;
dwarf2_read_section (objfile, sect);
/* We have the section offset, but we need the signature to do the
- hash table lookup. */
+ hash table lookup. */
+ /* FIXME: This is sorta unnecessary, read_signatured_type only uses
+ the signature to assert we found the right one.
+ Ok, but it's a lot of work. We should simplify things so any needed
+ assert doesn't require all this clumsiness. */
type_sig = lookup_signatured_type_at_offset (objfile, sect, offset);
gdb_assert (type_sig->per_cu.cu == NULL);
- read_signatured_type (objfile, type_sig);
+ read_signatured_type (type_sig);
gdb_assert (type_sig->per_cu.cu != NULL);
}
/* Read in a signatured type and build its CU and DIEs. */
static void
-read_signatured_type (struct objfile *objfile,
- struct signatured_type *type_sig)
+read_signatured_type (struct signatured_type *type_sig)
{
+ struct objfile *objfile = type_sig->per_cu.objfile;
gdb_byte *types_ptr;
struct die_reader_specs reader_specs;
struct dwarf2_cu *cu;
gdb_assert (type_sig->per_cu.cu == NULL);
cu = xmalloc (sizeof (*cu));
- init_one_comp_unit (cu, objfile);
-
- type_sig->per_cu.cu = cu;
- cu->per_cu = &type_sig->per_cu;
+ init_one_comp_unit (cu, &type_sig->per_cu);
/* If an error occurs while loading, release our storage. */
- free_cu_cleanup = make_cleanup (free_one_comp_unit, cu);
+ free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu);
types_ptr = read_type_comp_unit_head (&cu->header, section, &signature,
types_ptr, objfile->obfd);
hashtab_obstack_allocate,
dummy_obstack_deallocate);
- dwarf2_read_abbrevs (cu->objfile->obfd, cu);
+ dwarf2_read_abbrevs (cu);
back_to = make_cleanup (dwarf2_free_abbrev_table, cu);
init_cu_die_reader (&reader_specs, cu);
NULL /*parent*/);
/* We try not to read any attributes in this function, because not
- all objfiles needed for references have been loaded yet, and symbol
+ all CUs needed for references have been loaded yet, and symbol
table processing isn't initialized. But we have to set the CU language,
or we won't be able to build types correctly. */
prepare_one_comp_unit (cu, cu->dies);
struct dwarf2_section_info *section,
int section_is_gnu)
{
+ struct objfile *objfile = dwarf2_per_objfile->objfile;
gdb_byte *mac_ptr, *mac_end;
struct macro_source_file *current_file = 0;
enum dwarf_macro_record_type macinfo_type;
unsigned int offset_size = cu->header.offset_size;
gdb_byte *opcode_definitions[256];
- dwarf2_read_section (dwarf2_per_objfile->objfile, section);
+ dwarf2_read_section (objfile, section);
if (section->buffer == NULL)
{
complaint (&symfile_complaints, _("missing %s section"),
mac_ptr += bytes_read;
current_file = macro_start_file (file, line, current_file,
- comp_dir, lh, cu->objfile);
+ comp_dir, lh, objfile);
}
break;
dwarf_decode_macro_bytes (abfd, section->buffer + offset, mac_end,
current_file, lh, comp_dir, section, section_is_gnu,
- offset_size, cu->objfile);
+ offset_size, objfile);
}
/* Check if the attribute's form is a DW_FORM_block*
dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
struct dwarf2_cu *cu)
{
+ struct objfile *objfile = dwarf2_per_objfile->objfile;
+
if (attr_form_is_section_offset (attr)
/* ".debug_loc" may not exist at all, or the offset may be outside
the section. If so, fall through to the complaint in the
other branch. */
- && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile,
+ && DW_UNSND (attr) < dwarf2_section_size (objfile,
&dwarf2_per_objfile->loc))
{
struct dwarf2_loclist_baton *baton;
- baton = obstack_alloc (&cu->objfile->objfile_obstack,
+ baton = obstack_alloc (&objfile->objfile_obstack,
sizeof (struct dwarf2_loclist_baton));
fill_in_loclist_baton (cu, baton, attr);
{
struct dwarf2_locexpr_baton *baton;
- baton = obstack_alloc (&cu->objfile->objfile_obstack,
+ baton = obstack_alloc (&objfile->objfile_obstack,
sizeof (struct dwarf2_locexpr_baton));
baton->per_cu = cu->per_cu;
gdb_assert (baton->per_cu);
/* Return the address size given in the compilation unit header for CU. */
-CORE_ADDR
+int
dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
{
struct comp_unit_head cu_header_local;
return this_cu;
}
-/* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
+/* Initialize dwarf2_cu CU, owned by PER_CU. */
static void
-init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile)
+init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu)
{
memset (cu, 0, sizeof (*cu));
- cu->objfile = objfile;
+ per_cu->cu = cu;
+ cu->per_cu = per_cu;
+ cu->objfile = per_cu->objfile;
obstack_init (&cu->comp_unit_obstack);
}
cleanup routine. */
static void
-free_one_comp_unit (void *data)
+free_heap_comp_unit (void *data)
{
struct dwarf2_cu *cu = data;
- if (cu->per_cu != NULL)
- cu->per_cu->cu = NULL;
+ gdb_assert (cu->per_cu != NULL);
+ cu->per_cu->cu = NULL;
cu->per_cu = NULL;
obstack_free (&cu->comp_unit_obstack, NULL);
{
struct dwarf2_cu *cu = data;
+ gdb_assert (cu->per_cu != NULL);
+ cu->per_cu->cu = NULL;
+ cu->per_cu = NULL;
+
obstack_free (&cu->comp_unit_obstack, NULL);
cu->partial_dies = NULL;
- if (cu->per_cu != NULL)
- {
- /* This compilation unit is on the stack in our caller, so we
- should not xfree it. Just unlink it. */
- cu->per_cu->cu = NULL;
- cu->per_cu = NULL;
-
- /* If we had a per-cu pointer, then we may have other compilation
- units loaded, so age them now. */
- age_cached_comp_units ();
- }
+ /* The previous code only did this if per_cu != NULL.
+ But that would always succeed, so now we just unconditionally do
+ the aging. This seems like the wrong place to do such aging,
+ but cleaning that up is left for later. */
+ age_cached_comp_units ();
}
/* Free all cached compilation units. */
next_cu = per_cu->cu->read_in_chain;
- free_one_comp_unit (per_cu->cu);
+ free_heap_comp_unit (per_cu->cu);
*last_chain = next_cu;
per_cu = next_cu;
if (!per_cu->cu->mark)
{
- free_one_comp_unit (per_cu->cu);
+ free_heap_comp_unit (per_cu->cu);
*last_chain = next_cu;
}
else
if (per_cu->cu == target_cu)
{
- free_one_comp_unit (per_cu->cu);
+ free_heap_comp_unit (per_cu->cu);
*last_chain = next_cu;
break;
}