https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/139170
>From c7432d04896c1eea67ed6a6d5f4b4c28941e5a90 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 8 May 2025 07:38:20 -0700 Subject: [PATCH 1/4] [lldb] Do not create SymbolFileDWARFDebugMap for non-Mach-O files --- .../Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index 961c212e2e6dc..f94c756868953 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -10,7 +10,6 @@ #include "DWARFCompileUnit.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" - #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/PluginManager.h" @@ -34,12 +33,12 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ScopedPrinter.h" - #include "lldb/Target/StackFrame.h" #include "LogChannelDWARF.h" #include "SymbolFileDWARF.h" #include "lldb/lldb-private-enumerations.h" +#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include <memory> #include <optional> @@ -246,6 +245,8 @@ llvm::StringRef SymbolFileDWARFDebugMap::GetPluginDescriptionStatic() { } SymbolFile *SymbolFileDWARFDebugMap::CreateInstance(ObjectFileSP objfile_sp) { + if (objfile_sp->GetPluginName() != ObjectFileMachO::GetPluginNameStatic()) + return nullptr; return new SymbolFileDWARFDebugMap(std::move(objfile_sp)); } >From 6c1ce45355ed1f955727e830019e7cafec4b0070 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 8 May 2025 10:22:25 -0700 Subject: [PATCH 2/4] Add test, but failing --- .../unittests/SymbolFile/DWARF/CMakeLists.txt | 1 + .../DWARF/SymbolFileDWARFDebugMapTests.cpp | 84 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp diff --git a/lldb/unittests/SymbolFile/DWARF/CMakeLists.txt b/lldb/unittests/SymbolFile/DWARF/CMakeLists.txt index d5b0be7ea2a28..5aacb24fc5206 100644 --- a/lldb/unittests/SymbolFile/DWARF/CMakeLists.txt +++ b/lldb/unittests/SymbolFile/DWARF/CMakeLists.txt @@ -4,6 +4,7 @@ add_lldb_unittest(SymbolFileDWARFTests DWARFDIETest.cpp DWARFIndexCachingTest.cpp DWARFUnitTest.cpp + SymbolFileDWARFDebugMapTests.cpp SymbolFileDWARFTests.cpp XcodeSDKModuleTests.cpp diff --git a/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp b/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp new file mode 100644 index 0000000000000..399510e519521 --- /dev/null +++ b/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp @@ -0,0 +1,84 @@ +//===-- SymbolFileDWARFDebugMapTests.cpp ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h" +#include "TestingSupport/TestUtilities.h" + +#include "lldb/Core/Module.h" +#include "llvm/Testing/Support/Error.h" + +#include "gtest/gtest.h" + +using namespace lldb; +using namespace lldb_private; +using namespace lldb_private::plugin::dwarf; + +TEST(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNullForNonMachOFile) { + // Make sure we don't crash parsing a null unit DIE. + const char *yamldata = R"( +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_386 +DWARF: + debug_abbrev: + - Table: + - Code: 0x00000001 + Tag: DW_TAG_compile_unit + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_addr_base + Form: DW_FORM_sec_offset + debug_info: + - Version: 5 + AddrSize: 4 + UnitType: DW_UT_compile + Entries: + - AbbrCode: 0x00000001 + Values: + - Value: 0x8 # Offset of the first Address past the header + - AbbrCode: 0x0 + debug_addr: + - Version: 5 + AddressSize: 4 + Entries: + - Address: 0x1234 + - Address: 0x5678 + debug_line: + - Length: 42 + Version: 2 + PrologueLength: 36 + MinInstLength: 1 + DefaultIsStmt: 1 + LineBase: 251 + LineRange: 14 + OpcodeBase: 13 + StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ] + IncludeDirs: + - '/tmp' + Files: + - Name: main.cpp + DirIdx: 1 + ModTime: 0 + Length: 0 +)"; + + // bool waiting = true; + // while (waiting) {} + + llvm::Expected<TestFile> file = TestFile::fromYaml(yamldata); + EXPECT_THAT_EXPECTED(file, llvm::Succeeded()); + auto module_sp = std::make_shared<Module>(file->moduleSpec()); + auto object_file = module_sp->GetObjectFile(); + ASSERT_NE(object_file, nullptr); + + auto debug_map = SymbolFileDWARFDebugMap::CreateInstance(object_file->shared_from_this()); + ASSERT_EQ(debug_map, nullptr); +} >From 8bf38e24f941b431b90dd7ff60a5ff4514410020 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 8 May 2025 15:32:37 -0700 Subject: [PATCH 3/4] Add/fix test --- .../DWARF/SymbolFileDWARFDebugMap.cpp | 4 +- .../DWARF/SymbolFileDWARFDebugMapTests.cpp | 70 +++++++++++++++++-- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index f94c756868953..1793c23950d55 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -10,6 +10,7 @@ #include "DWARFCompileUnit.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" + #include "lldb/Core/Module.h" #include "lldb/Core/ModuleList.h" #include "lldb/Core/PluginManager.h" @@ -33,12 +34,13 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ScopedPrinter.h" + #include "lldb/Target/StackFrame.h" #include "LogChannelDWARF.h" +#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "SymbolFileDWARF.h" #include "lldb/lldb-private-enumerations.h" -#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include <memory> #include <optional> diff --git a/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp b/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp index 399510e519521..8c65fca889a40 100644 --- a/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp +++ b/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp @@ -6,7 +6,10 @@ // //===----------------------------------------------------------------------===// +#include "Plugins/ObjectFile/ELF/ObjectFileELF.h" +#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h" +#include "TestingSupport/SubsystemRAII.h" #include "TestingSupport/TestUtilities.h" #include "lldb/Core/Module.h" @@ -18,7 +21,64 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::plugin::dwarf; -TEST(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNullForNonMachOFile) { +class SymbolFileDWARFDebugMapTests : public testing::Test { + SubsystemRAII<ObjectFileELF, ObjectFileMachO> subsystems; +}; + +TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNonNullForMachOFile) { + // Make sure we don't crash parsing a null unit DIE. + const char *yamldata = R"( +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x80000003 + filetype: 0x00000001 + ncmds: 1 + sizeofcmds: 152 + flags: 0x00002000 + reserved: 0x00000000 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 152 + segname: __TEXT + vmaddr: 0 + vmsize: 4 + fileoff: 184 + filesize: 4 + maxprot: 7 + initprot: 7 + nsects: 1 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0000000000000000 + content: 'AABBCCDD' + size: 4 + offset: 184 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 +... +)"; + + llvm::Expected<TestFile> file = TestFile::fromYaml(yamldata); + EXPECT_THAT_EXPECTED(file, llvm::Succeeded()); + auto module_sp = std::make_shared<Module>(file->moduleSpec()); + ASSERT_NE(module_sp, nullptr); + auto object_file = module_sp->GetObjectFile(); + ASSERT_NE(object_file, nullptr); + auto debug_map = + SymbolFileDWARFDebugMap::CreateInstance(object_file->shared_from_this()); + ASSERT_NE(debug_map, nullptr); +} + +TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNullForNonMachOFile) { // Make sure we don't crash parsing a null unit DIE. const char *yamldata = R"( --- !ELF @@ -70,15 +130,13 @@ TEST(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNullForNonMachOFile) { Length: 0 )"; - // bool waiting = true; - // while (waiting) {} - llvm::Expected<TestFile> file = TestFile::fromYaml(yamldata); EXPECT_THAT_EXPECTED(file, llvm::Succeeded()); auto module_sp = std::make_shared<Module>(file->moduleSpec()); + ASSERT_NE(module_sp, nullptr); auto object_file = module_sp->GetObjectFile(); ASSERT_NE(object_file, nullptr); - - auto debug_map = SymbolFileDWARFDebugMap::CreateInstance(object_file->shared_from_this()); + auto debug_map = + SymbolFileDWARFDebugMap::CreateInstance(object_file->shared_from_this()); ASSERT_EQ(debug_map, nullptr); } >From 96b17f895eca1f951ee7a31b314be33e8803e0a3 Mon Sep 17 00:00:00 2001 From: Roy Shi <roy...@meta.com> Date: Thu, 29 May 2025 22:05:37 -0700 Subject: [PATCH 4/4] Use objfile_sp->GetArchitecture().GetTriple().isAppleMachO() instead --- .../Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp | 3 +-- .../SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index 1793c23950d55..67adba0fbaefa 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -38,7 +38,6 @@ #include "lldb/Target/StackFrame.h" #include "LogChannelDWARF.h" -#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "SymbolFileDWARF.h" #include "lldb/lldb-private-enumerations.h" @@ -247,7 +246,7 @@ llvm::StringRef SymbolFileDWARFDebugMap::GetPluginDescriptionStatic() { } SymbolFile *SymbolFileDWARFDebugMap::CreateInstance(ObjectFileSP objfile_sp) { - if (objfile_sp->GetPluginName() != ObjectFileMachO::GetPluginNameStatic()) + if (objfile_sp->GetArchitecture().GetTriple().isAppleMachO()) return nullptr; return new SymbolFileDWARFDebugMap(std::move(objfile_sp)); } diff --git a/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp b/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp index 8c65fca889a40..259193b1cecf2 100644 --- a/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp +++ b/lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp @@ -25,6 +25,7 @@ class SymbolFileDWARFDebugMapTests : public testing::Test { SubsystemRAII<ObjectFileELF, ObjectFileMachO> subsystems; }; +#ifdef __APPLE__ TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNonNullForMachOFile) { // Make sure we don't crash parsing a null unit DIE. const char *yamldata = R"( @@ -77,7 +78,9 @@ TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNonNullForMachOFile) { SymbolFileDWARFDebugMap::CreateInstance(object_file->shared_from_this()); ASSERT_NE(debug_map, nullptr); } +#endif +#ifdef __linux__ TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNullForNonMachOFile) { // Make sure we don't crash parsing a null unit DIE. const char *yamldata = R"( @@ -140,3 +143,4 @@ TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNullForNonMachOFile) { SymbolFileDWARFDebugMap::CreateInstance(object_file->shared_from_this()); ASSERT_EQ(debug_map, nullptr); } +#endif _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits