summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Wilson <wilsons@start.ca>2011-05-20 04:27:12 +0000
committerStephen Wilson <wilsons@start.ca>2011-05-20 04:27:12 +0000
commit8063a4a47a5ace1fc01c3bf843fd2bdfb504481a (patch)
tree76e388d02b39c8ab1e164d86ac20257c5f5871da
parentf663741db009e4bdfd569e4ba1df7bba95e826db (diff)
downloadbcm5719-llvm-8063a4a47a5ace1fc01c3bf843fd2bdfb504481a.tar.gz
bcm5719-llvm-8063a4a47a5ace1fc01c3bf843fd2bdfb504481a.zip
Do not parse DIE's outside a compilation units range.
In DWARFCompileUnit::ExtractDIEsIfNeeded we are relying on a compilation units DIEs to be terminated by a null entry. I think the standard is fairly clear that all sibling chains are to be terminated by null, but at least gcc 4.5.2 disagrees -- the top level chain drops the final entry. This results in us interpreting the next compilation unit header as a DIE. Regardless of whether gcc is right or wrong, we should not overstep a compilation units extent. This patch ensures that we do not attempt to extract a DIE beyond the length specified for a given DWARFCompileUnit by ensuring our current offset is strictly less than the start of the next CU. llvm-svn: 131721
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
index 966d28f263d..1e0431aa8cd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -154,8 +154,11 @@ DWARFCompileUnit::ExtractDIEsIfNeeded (bool cu_die_only)
m_offset,
cu_die_only);
- // Set the offset to that of the first DIE
+ // Set the offset to that of the first DIE and calculate the start of the
+ // next compilation unit header.
uint32_t offset = GetFirstDIEOffset();
+ uint32_t next_cu_offset = GetNextCompileUnitOffset();
+
DWARFDebugInfoEntry die;
// Keep a flat array of the DIE for binary lookup by DIE offset
// Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
@@ -173,7 +176,8 @@ DWARFCompileUnit::ExtractDIEsIfNeeded (bool cu_die_only)
const DataExtractor& debug_info_data = m_dwarf2Data->get_debug_info_data();
const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize());
- while (die.FastExtract (debug_info_data, this, fixed_form_sizes, &offset))
+ while (offset < next_cu_offset &&
+ die.FastExtract (debug_info_data, this, fixed_form_sizes, &offset))
{
// if (log)
// log->Printf("0x%8.8x: %*.*s%s%s",
@@ -220,18 +224,22 @@ DWARFCompileUnit::ExtractDIEsIfNeeded (bool cu_die_only)
break; // We are done with this compile unit!
}
- if (offset > GetNextCompileUnitOffset())
+ }
+
+ // Give a little bit of info if we encounter corrupt DWARF (our offset
+ // should always terminate at or before the start of the next compilation
+ // unit header).
+ if (offset > next_cu_offset)
+ {
+ char path[PATH_MAX];
+ ObjectFile *objfile = m_dwarf2Data->GetObjectFile();
+ if (objfile)
{
- char path[PATH_MAX];
- ObjectFile *objfile = m_dwarf2Data->GetObjectFile();
- if (objfile)
- {
- objfile->GetFileSpec().GetPath(path, sizeof(path));
- }
- fprintf (stderr, "warning: DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8x in '%s'\n", GetOffset(), offset, path);
- break;
+ objfile->GetFileSpec().GetPath(path, sizeof(path));
}
+ fprintf (stderr, "warning: DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8x in '%s'\n", GetOffset(), offset, path);
}
+
SetDIERelations();
return m_die_array.size();
}
OpenPOWER on IntegriCloud