-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Fix object format in the Triple of Mach-O files (approach 4) #145157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-lldb Author: None (royitaqi) ChangesContext: See previous approaches: #142704, #143633, #144177 This approachThis approach follows this previous suggestion:
Note: Full coverage of 2 in the above is guaranteed by how this patch is created:
Note: The callsites of AlternativesAnother previous suggestion was to specify/change the object format without any update to the triple string. This is impossible with the current implementation of Patch is 22.58 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/145157.diff 19 Files Affected:
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 603e306497841..e5e324589ce81 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -642,9 +642,9 @@ bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {
ArchSpec default_arch = Target::GetDefaultArchitecture();
if (default_arch.IsValid()) {
- const std::string &triple_str = default_arch.GetTriple().str();
+ const llvm::StringRef triple_str = default_arch.GetTriple().str(4);
if (!triple_str.empty())
- ::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());
+ ::snprintf(arch_name, arch_name_len, "%s", triple_str.str().c_str());
else
::snprintf(arch_name, arch_name_len, "%s",
default_arch.GetArchitectureName());
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 985107ec68efd..0ecc7a07b4337 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -576,7 +576,7 @@ const char *SBModule::GetTriple() {
if (!module_sp)
return nullptr;
- std::string triple(module_sp->GetArchitecture().GetTriple().str());
+ std::string triple(module_sp->GetArchitecture().GetTriple().str(4));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp
index fbbcfeac20178..8db9e2acae894 100644
--- a/lldb/source/API/SBModuleSpec.cpp
+++ b/lldb/source/API/SBModuleSpec.cpp
@@ -112,7 +112,7 @@ void SBModuleSpec::SetObjectName(const char *name) {
const char *SBModuleSpec::GetTriple() {
LLDB_INSTRUMENT_VA(this);
- std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());
+ std::string triple(m_opaque_up->GetArchitecture().GetTriple().str(4));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index f26f7951edc6f..98ea441c2a428 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1576,7 +1576,7 @@ const char *SBTarget::GetTriple() {
LLDB_INSTRUMENT_VA(this);
if (TargetSP target_sp = GetSP()) {
- std::string triple(target_sp->GetArchitecture().GetTriple().str());
+ std::string triple(target_sp->GetArchitecture().GetTriple().str(4));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 90997dada3666..b842531924e12 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1612,7 +1612,7 @@ bool Module::GetIsDynamicLinkEditor() {
uint32_t Module::Hash() {
std::string identifier;
llvm::raw_string_ostream id_strm(identifier);
- id_strm << m_arch.GetTriple().str() << '-' << m_file.GetPath();
+ id_strm << m_arch.GetTriple().str(4) << '-' << m_file.GetPath();
if (m_object_name)
id_strm << '(' << m_object_name << ')';
if (m_object_offset > 0)
@@ -1626,7 +1626,7 @@ uint32_t Module::Hash() {
std::string Module::GetCacheKey() {
std::string key;
llvm::raw_string_ostream strm(key);
- strm << m_arch.GetTriple().str() << '-' << m_file.GetFilename();
+ strm << m_arch.GetTriple().str(4) << '-' << m_file.GetFilename();
if (m_object_name)
strm << '(' << m_object_name << ')';
strm << '-' << llvm::format_hex(Hash(), 10);
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index fe9f5d086da2c..0b0d0d3b57463 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -494,11 +494,12 @@ DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress(lldb::addr_t addr,
} else {
uuid_str = "and no LC_UUID found in load commands ";
}
- LLDB_LOGF(
- log,
- "DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
- "kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().str().c_str(), uuid_str.c_str());
+ LLDB_LOGF(log,
+ "DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
+ "kernel binary image found at 0x%" PRIx64
+ " with arch '%s' %s",
+ addr, kernel_arch.GetTriple().str(4).str().c_str(),
+ uuid_str.c_str());
}
return memory_module_sp->GetUUID();
}
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index a23ba3ad5c545..1504fe1756a46 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -236,7 +236,8 @@ lldb_private::UUID DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
LLDB_LOGF(log,
"DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress: "
"kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().str().c_str(), uuid_str.c_str());
+ addr, kernel_arch.GetTriple().str(4),
+ uuid_str.c_str());
return memory_module_sp->GetUUID();
}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 7aa9cae5a5614..40780ccf0410b 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -509,7 +509,7 @@ static void SetupTargetOpts(CompilerInstance &compiler,
const auto target_machine = target_arch.GetMachine();
if (target_arch.IsValid()) {
- std::string triple = target_arch.GetTriple().str();
+ std::string triple(target_arch.GetTriple().str(4));
compiler.getTargetOpts().Triple = triple;
LLDB_LOGF(log, "Using %s as the target triple",
compiler.getTargetOpts().Triple.c_str());
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
index c99ed9dd0a68d..81269ac026f58 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -659,7 +659,7 @@ ClangModulesDeclVendor::Create(Target &target) {
"-fsyntax-only",
"-femit-all-decls",
"-target",
- arch.GetTriple().str(),
+ arch.GetTriple().str(4).str(),
"-fmodules-validate-system-headers",
"-Werror=non-modular-include-in-framework-module",
"-Xclang=-fincremental-extensions",
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
index f3aabc12f92b7..463374579aca9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
@@ -35,8 +35,9 @@ bool CppModuleConfiguration::SetOncePath::TrySet(llvm::StringRef path) {
static llvm::SmallVector<std::string, 2>
getTargetIncludePaths(const llvm::Triple &triple) {
llvm::SmallVector<std::string, 2> paths;
- if (!triple.str().empty()) {
- paths.push_back("/usr/include/" + triple.str());
+ llvm::StringRef triple_no_objfmt = triple.str(4);
+ if (!triple_no_objfmt.empty()) {
+ paths.push_back(("/usr/include/" + triple_no_objfmt).str());
if (!triple.getArchName().empty() ||
triple.getOSAndEnvironmentName().empty())
paths.push_back(("/usr/include/" + triple.getArchName() + "-" +
@@ -75,13 +76,14 @@ bool CppModuleConfiguration::analyzeFile(const FileSpec &f,
parent_path(posix_dir, Style::posix).ends_with("c++")) {
if (!m_std_inc.TrySet(posix_dir))
return false;
- if (triple.str().empty())
+ llvm::StringRef triple_no_objfmt = triple.str(4);
+ if (triple_no_objfmt.empty())
return true;
posix_dir.consume_back("c++/v1");
// Check if this is a target-specific libc++ include directory.
return m_std_target_inc.TrySet(
- (posix_dir + triple.str() + "/c++/v1").str());
+ (posix_dir + triple_no_objfmt + "/c++/v1").str());
}
std::optional<llvm::StringRef> inc_path;
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 3950454b7c90e..11e3877b4a9d1 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5148,6 +5148,7 @@ void ObjectFileMachO::GetAllArchSpecs(const llvm::MachO::mach_header &header,
llvm::Triple base_triple = base_arch.GetTriple();
base_triple.setOS(llvm::Triple::UnknownOS);
base_triple.setOSName(llvm::StringRef());
+ base_triple.setObjectFormat(llvm::Triple::MachO);
if (header.filetype == MH_PRELOAD) {
if (header.cputype == CPU_TYPE_ARM) {
@@ -6746,7 +6747,8 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
break;
default:
error = Status::FromErrorStringWithFormat(
- "unsupported core architecture: %s", target_triple.str().c_str());
+ "unsupported core architecture: %s",
+ target_triple.str(4).str().c_str());
break;
}
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 26ca6ed128972..a8b9717bbf359 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -354,7 +354,7 @@ Status PlatformRemoteGDBServer::LaunchProcess(ProcessLaunchInfo &launch_info) {
m_gdb_client_up->SendEnvironment(launch_info.GetEnvironment());
ArchSpec arch_spec = launch_info.GetArchitecture();
- const char *arch_triple = arch_spec.GetTriple().str().c_str();
+ const char *arch_triple = arch_spec.GetTriple().str(4).str().c_str();
m_gdb_client_up->SendLaunchArchPacket(arch_triple);
LLDB_LOGF(
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 29302413cf8fb..2faef32637164 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -497,8 +497,8 @@ static void ParseLangArgs(LangOptions &Opts, ArchSpec arch) {
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
llvm::Triple target_triple) {
m_display_name = name.str();
- if (!target_triple.str().empty())
- SetTargetTriple(target_triple.str());
+ if (!target_triple.str(4).empty())
+ SetTargetTriple(target_triple.str(4));
// The caller didn't pass an ASTContext so create a new one for this
// TypeSystemClang.
CreateASTContext();
@@ -509,7 +509,7 @@ TypeSystemClang::TypeSystemClang(llvm::StringRef name,
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
ASTContext &existing_ctxt) {
m_display_name = name.str();
- SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str());
+ SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str(4));
m_ast_up.reset(&existing_ctxt);
GetASTMap().Insert(&existing_ctxt, this);
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 8000cd07565ae..bb1314c0520a8 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -250,7 +250,7 @@ void Platform::GetStatus(Stream &strm) {
ArchSpec arch(GetSystemArchitecture());
if (arch.IsValid()) {
- if (!arch.GetTriple().str().empty()) {
+ if (!arch.GetTriple().str(4).empty()) {
strm.Printf(" Triple: ");
arch.DumpTriple(strm.AsRawOstream());
strm.EOL();
diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index 4cfd0629ea271..94af058d42641 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -401,7 +401,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
module_stat.path.append(1, ')');
}
module_stat.uuid = module->GetUUID().GetAsString();
- module_stat.triple = module->GetArchitecture().GetTriple().str();
+ module_stat.triple = module->GetArchitecture().GetTriple().str(4);
json_modules.emplace_back(module_stat.ToJSON());
}
}
diff --git a/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp b/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
index 0ef2d0b85fd36..e39a5398ab3e4 100644
--- a/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
+++ b/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
@@ -94,4 +94,120 @@ TEST_F(ObjectFileMachOTest, IndirectSymbolsInTheSharedCache) {
for (size_t i = 0; i < 10; i++)
OF->ParseSymtab(symtab);
}
+
+TEST_F(ObjectFileMachOTest, ObjectFormatWithVersionLoadCommand) {
+ // A Mach-O file of arm64 CPU type and macOS 10.14.0
+ const char *yamldata = R"(
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x0100000C
+ cpusubtype: 0x00000000
+ filetype: 0x00000001
+ ncmds: 1
+ sizeofcmds: 176
+ flags: 0x00002000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_BUILD_VERSION
+ cmdsize: 24
+ platform: 1
+ minos: 658944
+ sdk: 658944
+ ntools: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 152
+ segname: __TEXT
+ vmaddr: 0
+ vmsize: 4
+ fileoff: 208
+ filesize: 4
+ maxprot: 7
+ initprot: 7
+ nsects: 1
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ content: 'AABBCCDD'
+ size: 4
+ offset: 208
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+...
+)";
+
+ // Perform setup.
+ 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);
+
+ // Verify that the object file is recognized as Mach-O.
+ ASSERT_EQ(object_file->GetArchitecture().GetTriple().getObjectFormat(),
+ llvm::Triple::MachO);
+}
+
+TEST_F(ObjectFileMachOTest, ObjectFormatWithoutVersionLoadCommand) {
+ // A Mach-O file of arm64 CPU type, without load command LC_BUILD_VERSION.
+ const char *yamldata = R"(
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x0100000C
+ cpusubtype: 0x00000000
+ 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
+...
+)";
+
+ // Perform setup.
+ 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);
+
+ // Verify that the object file is recognized as Mach-O.
+ ASSERT_EQ(object_file->GetArchitecture().GetTriple().getObjectFormat(),
+ llvm::Triple::MachO);
+}
#endif
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 7fd5278f1ed53..6b9e80dc8743a 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -463,6 +463,27 @@ class Triple {
const std::string &str() const { return Data; }
+ /// Return the triple string but only keep the first \p N components.
+ ///
+ /// The returned string will preserve the first \p N components exactly the
+ /// same as the original (including the leading "-" and the value, empty or
+ /// not).
+ ///
+ /// E.g. Triple("arm64-apple-ios").str(5) == "arm64-apple-ios"
+ /// E.g. Triple("arm64-apple-ios--").str(5) == "arm64-apple-ios--"
+ /// E.g. Triple("arm64-apple-ios--").str(4) == "arm64-apple-ios-"
+ /// E.g. Triple("arm64-apple-ios--").str(3) == "arm64-apple-ios"
+ /// E.g. Triple("arm64-apple-ios--").str(2) == "arm64-apple"
+ /// E.g. Triple("arm64-apple-ios--").str(1) == "arm64"
+ /// E.g. Triple("arm64-apple-ios--").str(0) == ""
+ ///
+ /// This method does not normalize any triple strings. Clients that need to
+ /// handle the non-canonical triples that users often specify should use the
+ /// normalize method.
+ ///
+ /// \returns the (shorterned) triple string.
+ StringRef str(size_t N) const;
+
const std::string &getTriple() const { return Data; }
/// Whether the triple is empty / default constructed.
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 6a559ff023caa..0fdb62c473e73 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -2107,6 +2107,30 @@ std::string Triple::merge(const Triple &Other) const {
return Other.str();
}
+StringRef Triple::str(size_t N) const {
+ // If empty, return empty
+ if (N == 0 || Data == "")
+ return "";
+
+ // If keeping all components, return a full clone
+ if (N >= 5)
+ return Data;
+
+ // Find the N-th separator (which is after the N'th component)
+ size_t p = StringRef::npos;
+ for (uint32_t i = 0; i < N; ++i) {
+ p = Data.find('-', p + 1);
+ if (p == StringRef::npos)
+ break;
+ }
+
+ // Create a triple
+ if (p == StringRef::npos)
+ return Data;
+ else
+ return StringRef(Data).substr(0, p);
+}
+
bool Triple::isMacOSXVersionLT(unsigned Major, unsigned Minor,
unsigned Micro) const {
assert(isMacOSX() && "Not an OS X triple!");
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index bbd12e6d0e412..ba91e91d08a21 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -2926,4 +2926,97 @@ TEST(TripleTest, isCompatibleWith) {
EXPECT_TRUE(DoTest(C.B, C.A, C.Result));
}
}
+
+TEST(TripleTest, StrFirstN) {
+ // Empty triple
+ {
+ llvm::Triple triple;
+ ASSERT_EQ(triple.str(), "");
+ ASSERT_EQ(triple.str(5), "");
+ }
+
+ // Normal triple with 3 components
+ {
+ llvm::Triple triple("arm64-apple-ios");
+ ASSERT_EQ(triple.str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(5), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(4), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(3), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(2), "arm64-apple");
+ ASSERT_EQ(triple.str(1), "arm64");
+ ASSERT_EQ(triple.str(0...
[truncated]
|
9e6f3f9
to
7be86ff
Compare
7be86ff
to
e80ed09
Compare
e80ed09
to
3ea1296
Compare
Context: See previous approaches: #142704, #143633, #144177, #145150
This approach
This approach follows this previous suggestion: First, create a new
Triple::str(N)
method so that we can get triple strings without the object format component (to be upstreamed in #145150). Then, in LLDB, replace all callsites ofTriple::str()
withTriple::str(4)
(removes the object format component but keeps the environment component).Note: Full coverage of the replacement is guaranteed by the following process:
Triple::str()
method.Triple::str(N)
method.Triple::str()
method.Note: The callsites of
Triple::getTriple()
are not modified. My assumption is that these callsites intend to get the actual triple string (for computation purposes; not for display purposes).Alternatives
Another previous suggestion was to specify/change the object format without any update to the triple string. This is impossible with the current implementation of
llvm::Triple
, where the triple string (Data
) is the centerpiece of all the updates to the triple's components. Changing this to a enum-centric approach would change the behavior of the class (e.g. the triple will be normalized because of the enum) and would also require the rewrite of many of the methods, especially the setters. Given how fundamental this class is in llvm and lldb, a rewrite at this scale should probably be avoided.