diff --git a/lldb/include/lldb/Target/Platform.h b/lldb/include/lldb/Target/Platform.h --- a/lldb/include/lldb/Target/Platform.h +++ b/lldb/include/lldb/Target/Platform.h @@ -323,7 +323,7 @@ /// Lets a platform answer if it is compatible with a given architecture and /// the target triple contained within. virtual bool IsCompatibleArchitecture(const ArchSpec &arch, - bool exact_arch_match, + ArchSpec::MatchType match, ArchSpec *compatible_arch_ptr); /// Not all platforms will support debugging a process by spawning somehow diff --git a/lldb/include/lldb/Utility/ArchSpec.h b/lldb/include/lldb/Utility/ArchSpec.h --- a/lldb/include/lldb/Utility/ArchSpec.h +++ b/lldb/include/lldb/Utility/ArchSpec.h @@ -477,19 +477,25 @@ /// architecture and false otherwise. bool CharIsSignedByDefault() const; - /// Compare an ArchSpec to another ArchSpec, requiring an exact cpu type - /// match between them. e.g. armv7s is not an exact match with armv7 - this - /// would return false + enum MatchType : bool { CompatibleMatch, ExactMatch }; + + /// Compare this ArchSpec to another ArchSpec. \a match specifies the kind of + /// matching that is to be done. CompatibleMatch requires only a compatible + /// cpu type (e.g., armv7s is compatible with armv7). ExactMatch requires an + /// exact match (armv7s is not an exact match with armv7). /// /// \return true if the two ArchSpecs match. - bool IsExactMatch(const ArchSpec &rhs) const; + bool IsMatch(const ArchSpec &rhs, MatchType match) const; - /// Compare an ArchSpec to another ArchSpec, requiring a compatible cpu type - /// match between them. e.g. armv7s is compatible with armv7 - this method - /// would return true - /// - /// \return true if the two ArchSpecs are compatible - bool IsCompatibleMatch(const ArchSpec &rhs) const; + /// Shorthand for IsMatch(rhs, ExactMatch). + bool IsExactMatch(const ArchSpec &rhs) const { + return IsMatch(rhs, ExactMatch); + } + + /// Shorthand for IsMatch(rhs, CompatibleMatch). + bool IsCompatibleMatch(const ArchSpec &rhs) const { + return IsMatch(rhs, CompatibleMatch); + } bool IsFullySpecifiedTriple() const; @@ -518,7 +524,6 @@ void SetFlags(const std::string &elf_abi); protected: - bool IsEqualTo(const ArchSpec &rhs, bool exact_match) const; void UpdateCore(); llvm::Triple m_triple; diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp --- a/lldb/source/Interpreter/OptionGroupPlatform.cpp +++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp @@ -31,7 +31,8 @@ } if (platform_sp) { if (platform_arch.IsValid() && - !platform_sp->IsCompatibleArchitecture(arch, false, &platform_arch)) { + !platform_sp->IsCompatibleArchitecture( + arch, ArchSpec::CompatibleMatch, &platform_arch)) { error.SetErrorStringWithFormatv("platform '{0}' doesn't support '{1}'", platform_sp->GetPluginName(), arch.GetTriple().getTriple()); diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -873,7 +873,8 @@ ArchSpec compatible_arch; ArchSpec raw_arch(triple); - if (!IsCompatibleArchitecture(raw_arch, false, &compatible_arch)) + if (!IsCompatibleArchitecture(raw_arch, ArchSpec::CompatibleMatch, + &compatible_arch)) return raw_arch; if (!compatible_arch.IsValid()) @@ -1099,15 +1100,13 @@ /// Lets a platform answer if it is compatible with a given /// architecture and the target triple contained within. bool Platform::IsCompatibleArchitecture(const ArchSpec &arch, - bool exact_arch_match, + ArchSpec::MatchType match, ArchSpec *compatible_arch_ptr) { // If the architecture is invalid, we must answer true... if (arch.IsValid()) { ArchSpec platform_arch; - auto match = exact_arch_match ? &ArchSpec::IsExactMatch - : &ArchSpec::IsCompatibleMatch; for (const ArchSpec &platform_arch : GetSupportedArchitectures()) { - if ((arch.*match)(platform_arch)) { + if (arch.IsMatch(platform_arch, match)) { if (compatible_arch_ptr) *compatible_arch_ptr = platform_arch; return true; @@ -1894,13 +1893,14 @@ std::lock_guard guard(m_mutex); // First try exact arch matches across all platforms already created for (const auto &platform_sp : m_platforms) { - if (platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr)) + if (platform_sp->IsCompatibleArchitecture(arch, ArchSpec::ExactMatch, platform_arch_ptr)) return platform_sp; } // Next try compatible arch matches across all platforms already created for (const auto &platform_sp : m_platforms) { - if (platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr)) + if (platform_sp->IsCompatibleArchitecture(arch, ArchSpec::CompatibleMatch, + platform_arch_ptr)) return platform_sp; } @@ -1911,8 +1911,8 @@ (create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx)); ++idx) { PlatformSP platform_sp = create_callback(false, &arch); - if (platform_sp && - platform_sp->IsCompatibleArchitecture(arch, true, platform_arch_ptr)) { + if (platform_sp && platform_sp->IsCompatibleArchitecture( + arch, ArchSpec::ExactMatch, platform_arch_ptr)) { m_platforms.push_back(platform_sp); return platform_sp; } @@ -1923,7 +1923,8 @@ ++idx) { PlatformSP platform_sp = create_callback(false, &arch); if (platform_sp && - platform_sp->IsCompatibleArchitecture(arch, false, platform_arch_ptr)) { + platform_sp->IsCompatibleArchitecture(arch, ArchSpec::CompatibleMatch, + platform_arch_ptr)) { m_platforms.push_back(platform_sp); return platform_sp; } diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -2888,7 +2888,8 @@ if (platform_sp) { const ArchSpec &target_arch = GetTarget().GetArchitecture(); if (target_arch.IsValid() && - !platform_sp->IsCompatibleArchitecture(target_arch, false, nullptr)) { + !platform_sp->IsCompatibleArchitecture( + target_arch, ArchSpec::CompatibleMatch, nullptr)) { ArchSpec platform_arch; platform_sp = GetTarget().GetDebugger().GetPlatformList().GetOrCreate( target_arch, &platform_arch); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -1469,8 +1469,8 @@ if (set_platform) { if (other.IsValid()) { auto platform_sp = GetPlatform(); - if (!platform_sp || - !platform_sp->IsCompatibleArchitecture(other, false, nullptr)) { + if (!platform_sp || !platform_sp->IsCompatibleArchitecture( + other, ArchSpec::CompatibleMatch, nullptr)) { ArchSpec platform_arch; if (PlatformSP arch_platform_sp = GetDebugger().GetPlatformList().GetOrCreate(other, diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -181,7 +181,8 @@ // the selected platform otherwise. if (platform_sp) { if (platform_sp->IsCompatibleArchitecture( - module_spec.GetArchitecture(), false, nullptr)) { + module_spec.GetArchitecture(), ArchSpec::CompatibleMatch, + nullptr)) { platforms.push_back(platform_sp); continue; } @@ -193,7 +194,8 @@ (!platform_sp || host_platform_sp->GetName() != platform_sp->GetName())) { if (host_platform_sp->IsCompatibleArchitecture( - module_spec.GetArchitecture(), false, nullptr)) { + module_spec.GetArchitecture(), ArchSpec::CompatibleMatch, + nullptr)) { platforms.push_back(host_platform_sp); continue; } @@ -257,7 +259,8 @@ // If we have a valid architecture, make sure the current platform is // compatible with that architecture. if (!prefer_platform_arch && arch.IsValid()) { - if (!platform_sp->IsCompatibleArchitecture(arch, false, nullptr)) { + if (!platform_sp->IsCompatibleArchitecture(arch, ArchSpec::CompatibleMatch, + nullptr)) { platform_sp = platform_list.GetOrCreate(arch, &platform_arch); if (platform_sp) platform_list.SetSelectedPlatform(platform_sp); @@ -266,7 +269,8 @@ // If "arch" isn't valid, yet "platform_arch" is, it means we have an // executable file with a single architecture which should be used. ArchSpec fixed_platform_arch; - if (!platform_sp->IsCompatibleArchitecture(platform_arch, false, nullptr)) { + if (!platform_sp->IsCompatibleArchitecture( + platform_arch, ArchSpec::CompatibleMatch, nullptr)) { platform_sp = platform_list.GetOrCreate(platform_arch, &fixed_platform_arch); if (platform_sp) @@ -297,8 +301,8 @@ ArchSpec arch(specified_arch); if (arch.IsValid()) { - if (!platform_sp || - !platform_sp->IsCompatibleArchitecture(arch, false, nullptr)) + if (!platform_sp || !platform_sp->IsCompatibleArchitecture( + arch, ArchSpec::CompatibleMatch, nullptr)) platform_sp = debugger.GetPlatformList().GetOrCreate(specified_arch, &arch); } diff --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp --- a/lldb/source/Utility/ArchSpec.cpp +++ b/lldb/source/Utility/ArchSpec.cpp @@ -928,14 +928,6 @@ return 0; } -bool ArchSpec::IsExactMatch(const ArchSpec &rhs) const { - return IsEqualTo(rhs, true); -} - -bool ArchSpec::IsCompatibleMatch(const ArchSpec &rhs) const { - return IsEqualTo(rhs, false); -} - static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs, llvm::Triple::EnvironmentType rhs) { if (lhs == rhs) @@ -967,11 +959,11 @@ return false; } -bool ArchSpec::IsEqualTo(const ArchSpec &rhs, bool exact_match) const { +bool ArchSpec::IsMatch(const ArchSpec &rhs, MatchType match) const { // explicitly ignoring m_distribution_id in this method. if (GetByteOrder() != rhs.GetByteOrder() || - !cores_match(GetCore(), rhs.GetCore(), true, exact_match)) + !cores_match(GetCore(), rhs.GetCore(), true, match == ExactMatch)) return false; const llvm::Triple &lhs_triple = GetTriple(); @@ -1000,7 +992,7 @@ const llvm::Triple::EnvironmentType rhs_triple_env = rhs_triple.getEnvironment(); - if (!exact_match) { + if (match == CompatibleMatch) { // x86_64-apple-ios-macabi, x86_64-apple-macosx are compatible, no match. if ((lhs_triple_os == llvm::Triple::IOS && lhs_triple_env == llvm::Triple::MacABI && @@ -1027,8 +1019,9 @@ return false; // If the pair of os+env is both unspecified, match any other os+env combo. - if (!exact_match && ((!lhs_os_specified && !lhs_triple.hasEnvironment()) || - (!rhs_os_specified && !rhs_triple.hasEnvironment()))) + if (match == CompatibleMatch && + ((!lhs_os_specified && !lhs_triple.hasEnvironment()) || + (!rhs_os_specified && !rhs_triple.hasEnvironment()))) return true; }