Skip to content

Commit 57145ec

Browse files
committed
Use objfile_sp->GetArchitecture().GetTriple().isAppleMachO() instead
1 parent 8bf38e2 commit 57145ec

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "lldb/Target/StackFrame.h"
3939

4040
#include "LogChannelDWARF.h"
41-
#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
4241
#include "SymbolFileDWARF.h"
4342
#include "lldb/lldb-private-enumerations.h"
4443

@@ -247,7 +246,8 @@ llvm::StringRef SymbolFileDWARFDebugMap::GetPluginDescriptionStatic() {
247246
}
248247

249248
SymbolFile *SymbolFileDWARFDebugMap::CreateInstance(ObjectFileSP objfile_sp) {
250-
if (objfile_sp->GetPluginName() != ObjectFileMachO::GetPluginNameStatic())
249+
// Don't create a debug map if the object file isn't a Mach-O.
250+
if (!objfile_sp->GetArchitecture().GetTriple().isAppleMachO())
251251
return nullptr;
252252
return new SymbolFileDWARFDebugMap(std::move(objfile_sp));
253253
}

lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFDebugMapTests.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ class SymbolFileDWARFDebugMapTests : public testing::Test {
2525
SubsystemRAII<ObjectFileELF, ObjectFileMachO> subsystems;
2626
};
2727

28+
#ifdef __APPLE__
2829
TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNonNullForMachOFile) {
29-
// Make sure we don't crash parsing a null unit DIE.
30+
// The file header represents an arm64 Mach-O file.
3031
const char *yamldata = R"(
3132
--- !mach-o
3233
FileHeader:
3334
magic: 0xFEEDFACF
34-
cputype: 0x01000007
35-
cpusubtype: 0x80000003
35+
cputype: 0x0100000C
36+
cpusubtype: 0x00000000
3637
filetype: 0x00000001
3738
ncmds: 1
3839
sizeofcmds: 152
@@ -69,15 +70,25 @@ TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNonNullForMachOFile) {
6970

7071
llvm::Expected<TestFile> file = TestFile::fromYaml(yamldata);
7172
EXPECT_THAT_EXPECTED(file, llvm::Succeeded());
72-
auto module_sp = std::make_shared<Module>(file->moduleSpec());
73+
74+
// Set the triple explicitly.
75+
ModuleSpec module_spec = file->moduleSpec();
76+
module_spec.GetArchitecture().SetTriple("arm64-apple-macosx15.0.0");
77+
78+
// Create module and get object file.
79+
auto module_sp = std::make_shared<Module>(module_spec);
7380
ASSERT_NE(module_sp, nullptr);
7481
auto object_file = module_sp->GetObjectFile();
7582
ASSERT_NE(object_file, nullptr);
83+
84+
// The debug map should be non-null, because the file is Apple Mach-O.
7685
auto debug_map =
7786
SymbolFileDWARFDebugMap::CreateInstance(object_file->shared_from_this());
7887
ASSERT_NE(debug_map, nullptr);
7988
}
89+
#endif
8090

91+
#ifdef __linux__
8192
TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNullForNonMachOFile) {
8293
// Make sure we don't crash parsing a null unit DIE.
8394
const char *yamldata = R"(
@@ -140,3 +151,4 @@ TEST_F(SymbolFileDWARFDebugMapTests, CreateInstanceReturnNullForNonMachOFile) {
140151
SymbolFileDWARFDebugMap::CreateInstance(object_file->shared_from_this());
141152
ASSERT_EQ(debug_map, nullptr);
142153
}
154+
#endif

0 commit comments

Comments
 (0)