aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2015-07-23 09:21:48 -0700
committerDoug Evans <dje@google.com>2015-07-23 09:25:49 -0700
commitcc12ce380e8dab7e3cee8ecad29db6e9bb36a8fa (patch)
tree65b3974359af6c528e974227d005ae365c273b70 /gdb/dwarf2read.c
parent7b849db4f213d6734b4121ca5e5cab3341a5140c (diff)
downloadgdb-cc12ce380e8dab7e3cee8ecad29db6e9bb36a8fa.zip
gdb-cc12ce380e8dab7e3cee8ecad29db6e9bb36a8fa.tar.gz
gdb-cc12ce380e8dab7e3cee8ecad29db6e9bb36a8fa.tar.bz2
Fix crash when reading dummy CUs.
Dummy CUs are used by the incremental linker to pre-allocate space in the output file. They have a DWARF header but no contents. gdb/ChangeLog: * dwarf2read.c (dwarf2_per_cu_data): Add comment. (load_cu): Handle dummy CUs. (dw2_do_instantiate_symtab, process_queuef): Ditto. (dwarf2_fetch_die_loc_sect_off, dwarf2_fetch_constant_bytes): Ditto. gdb/testsuite/ChangeLog: * gdb.dwarf2/dw2-dummy-cu.S: New file. * gdb.dwarf2/dw2-dummy-cu.exp: New file.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index f4409568..24a4022 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -610,7 +610,8 @@ struct dwarf2_per_cu_data
struct dwarf2_section_info *section;
/* Set to non-NULL iff this CU is currently loaded. When it gets freed out
- of the CU cache it gets reset to NULL again. */
+ of the CU cache it gets reset to NULL again. This is left as NULL for
+ dummy CUs (a CU header, but nothing else). */
struct dwarf2_cu *cu;
/* The corresponding objfile.
@@ -2655,7 +2656,8 @@ load_cu (struct dwarf2_per_cu_data *per_cu)
else
load_full_comp_unit (per_cu, language_minimal);
- gdb_assert (per_cu->cu != NULL);
+ if (per_cu->cu == NULL)
+ return; /* Dummy CU. */
dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu);
}
@@ -2685,6 +2687,7 @@ dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
that may badly handle TUs, load all the TUs in that DWO as well.
http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
if (!per_cu->is_debug_types
+ && per_cu->cu != NULL
&& per_cu->cu->dwo_unit != NULL
&& dwarf2_per_objfile->index_table != NULL
&& dwarf2_per_objfile->index_table->version <= 7
@@ -7544,9 +7547,11 @@ process_queue (void)
may load a new CU, adding it to the end of the queue. */
for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
{
- if (dwarf2_per_objfile->using_index
- ? !item->per_cu->v.quick->compunit_symtab
- : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
+ if ((dwarf2_per_objfile->using_index
+ ? !item->per_cu->v.quick->compunit_symtab
+ : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
+ /* Skip dummy CUs. */
+ && item->per_cu->cu != NULL)
{
struct dwarf2_per_cu_data *per_cu = item->per_cu;
unsigned int debug_print_threshold;
@@ -20017,6 +20022,13 @@ dwarf2_fetch_die_loc_sect_off (sect_offset offset,
if (per_cu->cu == NULL)
load_cu (per_cu);
cu = per_cu->cu;
+ if (cu == NULL)
+ {
+ /* We shouldn't get here for a dummy CU, but don't crash on the user.
+ Instead just throw an error, not much else we can do. */
+ error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
+ offset.sect_off, objfile_name (per_cu->objfile));
+ }
die = follow_die_offset (offset, per_cu->is_dwz, &cu);
if (!die)
@@ -20118,6 +20130,13 @@ dwarf2_fetch_constant_bytes (sect_offset offset,
if (per_cu->cu == NULL)
load_cu (per_cu);
cu = per_cu->cu;
+ if (cu == NULL)
+ {
+ /* We shouldn't get here for a dummy CU, but don't crash on the user.
+ Instead just throw an error, not much else we can do. */
+ error (_("Dwarf Error: Dummy CU at 0x%x referenced in module %s"),
+ offset.sect_off, objfile_name (per_cu->objfile));
+ }
die = follow_die_offset (offset, per_cu->is_dwz, &cu);
if (!die)