summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2020-05-23 14:55:39 +0300
committerAndreas Kling <kling@serenityos.org>2020-05-24 10:42:21 +0200
commit2686957836069484bdf9886fd5fb792f55376d1b (patch)
treee21badb99991d5eb2c392b7af446f0929fc9e880 /Libraries
parent58480a510fee0d632b7cb4caa51fbce6a52f2aa0 (diff)
downloadserenity-2686957836069484bdf9886fd5fb792f55376d1b.zip
LibDebug: Tolerate missing debug information
We previously crashed when programs were missing certain debug information.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibDebug/DebugInfo.cpp9
-rw-r--r--Libraries/LibDebug/Dwarf/DwarfInfo.cpp5
2 files changed, 11 insertions, 3 deletions
diff --git a/Libraries/LibDebug/DebugInfo.cpp b/Libraries/LibDebug/DebugInfo.cpp
index d5486f868e..93dbcf11f2 100644
--- a/Libraries/LibDebug/DebugInfo.cpp
+++ b/Libraries/LibDebug/DebugInfo.cpp
@@ -69,6 +69,10 @@ void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die)
if (name.has_value())
scope.name = name.value().data.as_string;
+ if (!child.get_attribute(Dwarf::Attribute::LowPc).has_value()) {
+ dbg() << "DWARF: Couldn't find attribtue LowPc for scope";
+ return;
+ }
scope.address_low = child.get_attribute(Dwarf::Attribute::LowPc).value().data.as_u32;
// The attribute name HighPc is confusing. In this context, it seems to actually be a positive offset from LowPc
scope.address_high = scope.address_low + child.get_attribute(Dwarf::Attribute::HighPc).value().data.as_u32;
@@ -88,9 +92,10 @@ void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die)
void DebugInfo::prepare_lines()
{
auto section = m_elf->image().lookup_section(".debug_line");
- ASSERT(!section.is_undefined());
+ if (section.is_undefined())
+ return;
- auto buffer = ByteBuffer::wrap(reinterpret_cast<const u8*>(section.raw_data()), section.size());
+ auto buffer = section.wrapping_byte_buffer();
BufferStream stream(buffer);
Vector<LineProgram::LineInfo> all_lines;
diff --git a/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Libraries/LibDebug/Dwarf/DwarfInfo.cpp
index 8c8781e6db..e105099b4c 100644
--- a/Libraries/LibDebug/Dwarf/DwarfInfo.cpp
+++ b/Libraries/LibDebug/Dwarf/DwarfInfo.cpp
@@ -41,12 +41,15 @@ DwarfInfo::DwarfInfo(NonnullRefPtr<const ELF::Loader> elf)
ByteBuffer DwarfInfo::section_data(const String& section_name)
{
auto section = m_elf->image().lookup_section(section_name);
- ASSERT(!section.is_undefined());
+ if (section.is_undefined())
+ return {};
return section.wrapping_byte_buffer();
}
void DwarfInfo::populate_compilation_units()
{
+ if (m_debug_info_data.is_null())
+ return;
// We have to const_cast here because there isn't a version of
// BufferStream that accepts a const ByteStream
// We take care not to use BufferStream operations that modify the underlying buffer