From afb41a37f9f6fa9e3c2d8df35fa9c9ae215299ee Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Wed, 18 Sep 2024 16:41:09 -0400 Subject: Add support for loading symbols from .gnu_debugdata --- view/elf/elfview.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'view/elf/elfview.cpp') diff --git a/view/elf/elfview.cpp b/view/elf/elfview.cpp index 677f0b67..b90b18a7 100644 --- a/view/elf/elfview.cpp +++ b/view/elf/elfview.cpp @@ -1325,6 +1325,8 @@ bool ElfView::Init() } } + ParseMiniDebugInfo(); + // Process the queued symbols m_symbolQueue->Process(); delete m_symbolQueue; @@ -2608,6 +2610,44 @@ bool ElfView::DerefPpc64Descriptor(BinaryReader& reader, uint64_t addr, uint64_t } +void ElfView::ParseMiniDebugInfo() +{ + Ref
gnuDebugdata = GetParentView()->GetSectionByName(".gnu_debugdata"); + if (!gnuDebugdata) + return; + + BinaryReader debugdataReader(GetParentView()); + debugdataReader.Seek(gnuDebugdata->GetStart()); + + DataBuffer compressedDebug = debugdataReader.Read(gnuDebugdata->GetLength()); + + DataBuffer debugElf; + if (!compressedDebug.XzDecompress(debugElf)) + { + m_logger->LogError("Invalid .gnu_debugdata contents: Failed to decompress"); + return; + } + + Ref debugBv = Load(debugElf, false); + if (!debugBv) + { + m_logger->LogError("Invalid .gnu_debugdata contents: Failed to create BinaryView"); + return; + } + + for (const auto& symbol : debugBv->GetSymbols()) + { + DefineElfSymbol( + symbol->GetType(), + symbol->GetRawName(), + GetStart() + symbol->GetAddress(), + false, + symbol->GetBinding() + ); + } +} + + vector ElfView::ParseSymbolTable(BinaryReader& reader, const Elf64SectionHeader& symbolSection, const Elf64SectionHeader& stringSection, bool dynamic, size_t startEntry) { -- cgit v1.3.1