diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -2262,7 +2262,9 @@ func_range.SetByteSize(highest_func_addr - lowest_func_addr); } - if (func_range.GetBaseAddress().IsValid()) { + auto base_address = func_range.GetBaseAddress(); + if (base_address.IsSectionOffset() && + base_address.GetSection()->GetType() == eSectionTypeCode) { Mangled func_name; if (mangled) func_name.SetValue(ConstString(mangled), true); diff --git a/lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml b/lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml --- a/lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml +++ b/lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-offsets.yaml @@ -408,8 +408,8 @@ - Value: 0x0000000100000F80 - Value: 0x0000000000000030 - AbbrCode: 0x00000002 - Values: - - Value: 0x0000000100000F80 + Values: # DW_TAG_subprogram foo + - Value: 0x0000000000000F80 # DW_AT_low_pc points to invalid loc - Value: 0x000000000000000B - Value: 0x0000000000000001 BlockData: [ 0x56 ] @@ -420,7 +420,7 @@ - Value: 0x000000000000006F - Value: 0x0000000000000001 - AbbrCode: 0x00000003 - Values: + Values: # DW_TAG_subprogram main - Value: 0x0000000100000F90 - Value: 0x0000000000000020 - Value: 0x0000000000000001 diff --git a/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp b/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp --- a/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp +++ b/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp @@ -35,14 +35,16 @@ #include "lldb/Utility/ArchSpec.h" #include "lldb/Utility/DataEncoder.h" #include "lldb/Utility/FileSpec.h" +#include "lldb/Utility/Reproducer.h" #include "lldb/Utility/StreamString.h" using namespace lldb; using namespace lldb_private; class SymbolFileDWARFTests : public testing::Test { - SubsystemRAII + SubsystemRAII subsystems; public: @@ -367,3 +369,27 @@ ASSERT_NE(section_sp.get(), nullptr); EXPECT_EQ(section_sp->GetType(), eSectionTypeCode); } + +TEST_F(SymbolFileDWARFTests, EnsureAllParseFunctionsExistInCodeSections) { + auto ExpectedFile = TestFile::fromYamlFile("test-invalid-offsets.yaml"); + ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded()); + + lldb::ModuleSP module_sp = + std::make_shared(ExpectedFile->moduleSpec()); + SymbolFile *symfile = module_sp->GetSymbolFile(); + ASSERT_NE(symfile, nullptr); + + SymbolContextList sc_list; + RegularExpression regex("."); + symfile->FindFunctions(regex, false, sc_list); + ASSERT_EQ(sc_list.GetSize(), 1U); + + SymbolContext sc; + sc_list.GetContextAtIndex(0, sc); + EXPECT_STREQ(sc.function->GetName().AsCString(), "main"); + + auto section_sp = + sc.function->GetAddressRange().GetBaseAddress().GetSection(); + ASSERT_NE(section_sp.get(), nullptr); + EXPECT_EQ(section_sp->GetType(), eSectionTypeCode); +}