[lldb] Create an enum to specify the kind of ArchSpec matching
s/true/ArchSpec::ExactMatch s/false/ArchSpec::CompatibleMatch Differential Revision: https://reviews.llvm.org/D121290
This commit is contained in:
parent
5dbd8faad5
commit
6093a77caf
|
@ -329,7 +329,7 @@ public:
|
|||
/// the target triple contained within.
|
||||
virtual bool IsCompatibleArchitecture(const ArchSpec &arch,
|
||||
const ArchSpec &process_host_arch,
|
||||
bool exact_arch_match,
|
||||
ArchSpec::MatchType match,
|
||||
ArchSpec *compatible_arch_ptr);
|
||||
|
||||
/// Not all platforms will support debugging a process by spawning somehow
|
||||
|
|
|
@ -488,19 +488,25 @@ public:
|
|||
/// 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;
|
||||
|
||||
|
@ -529,7 +535,6 @@ public:
|
|||
void SetFlags(const std::string &elf_abi);
|
||||
|
||||
protected:
|
||||
bool IsEqualTo(const ArchSpec &rhs, bool exact_match) const;
|
||||
void UpdateCore();
|
||||
|
||||
llvm::Triple m_triple;
|
||||
|
|
|
@ -30,8 +30,9 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
|
|||
m_platform_name);
|
||||
}
|
||||
if (platform_sp) {
|
||||
if (platform_arch.IsValid() && !platform_sp->IsCompatibleArchitecture(
|
||||
arch, {}, false, &platform_arch)) {
|
||||
if (platform_arch.IsValid() &&
|
||||
!platform_sp->IsCompatibleArchitecture(
|
||||
arch, {}, ArchSpec::CompatibleMatch, &platform_arch)) {
|
||||
error.SetErrorStringWithFormatv("platform '{0}' doesn't support '{1}'",
|
||||
platform_sp->GetPluginName(),
|
||||
arch.GetTriple().getTriple());
|
||||
|
|
|
@ -929,7 +929,8 @@ ArchSpec Platform::GetAugmentedArchSpec(llvm::StringRef triple) {
|
|||
|
||||
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())
|
||||
|
@ -1156,16 +1157,14 @@ Platform::CreateArchList(llvm::ArrayRef<llvm::Triple::ArchType> archs,
|
|||
/// architecture and the target triple contained within.
|
||||
bool Platform::IsCompatibleArchitecture(const ArchSpec &arch,
|
||||
const ArchSpec &process_host_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(process_host_arch)) {
|
||||
if ((arch.*match)(platform_arch)) {
|
||||
if (arch.IsMatch(platform_arch, match)) {
|
||||
if (compatible_arch_ptr)
|
||||
*compatible_arch_ptr = platform_arch;
|
||||
return true;
|
||||
|
@ -1966,14 +1965,15 @@ PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
|
|||
std::lock_guard<std::recursive_mutex> 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, process_host_arch, true,
|
||||
platform_arch_ptr))
|
||||
if (platform_sp->IsCompatibleArchitecture(
|
||||
arch, process_host_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, process_host_arch, false,
|
||||
if (platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
|
||||
ArchSpec::CompatibleMatch,
|
||||
platform_arch_ptr))
|
||||
return platform_sp;
|
||||
}
|
||||
|
@ -1985,8 +1985,9 @@ PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
|
|||
(create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx));
|
||||
++idx) {
|
||||
PlatformSP platform_sp = create_callback(false, &arch);
|
||||
if (platform_sp && platform_sp->IsCompatibleArchitecture(
|
||||
arch, process_host_arch, true, platform_arch_ptr)) {
|
||||
if (platform_sp &&
|
||||
platform_sp->IsCompatibleArchitecture(
|
||||
arch, process_host_arch, ArchSpec::ExactMatch, platform_arch_ptr)) {
|
||||
m_platforms.push_back(platform_sp);
|
||||
return platform_sp;
|
||||
}
|
||||
|
@ -1997,7 +1998,8 @@ PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
|
|||
++idx) {
|
||||
PlatformSP platform_sp = create_callback(false, &arch);
|
||||
if (platform_sp && platform_sp->IsCompatibleArchitecture(
|
||||
arch, process_host_arch, false, platform_arch_ptr)) {
|
||||
arch, process_host_arch, ArchSpec::CompatibleMatch,
|
||||
platform_arch_ptr)) {
|
||||
m_platforms.push_back(platform_sp);
|
||||
return platform_sp;
|
||||
}
|
||||
|
@ -2031,7 +2033,7 @@ PlatformSP PlatformList::GetOrCreate(llvm::ArrayRef<ArchSpec> archs,
|
|||
if (m_selected_platform_sp) {
|
||||
for (const ArchSpec &arch : archs) {
|
||||
if (m_selected_platform_sp->IsCompatibleArchitecture(
|
||||
arch, process_host_arch, false, nullptr))
|
||||
arch, process_host_arch, ArchSpec::CompatibleMatch, nullptr))
|
||||
return m_selected_platform_sp;
|
||||
}
|
||||
}
|
||||
|
@ -2039,8 +2041,8 @@ PlatformSP PlatformList::GetOrCreate(llvm::ArrayRef<ArchSpec> archs,
|
|||
// Prefer the host platform if it matches at least one architecture.
|
||||
if (host_platform_sp) {
|
||||
for (const ArchSpec &arch : archs) {
|
||||
if (host_platform_sp->IsCompatibleArchitecture(arch, process_host_arch,
|
||||
false, nullptr))
|
||||
if (host_platform_sp->IsCompatibleArchitecture(
|
||||
arch, process_host_arch, ArchSpec::CompatibleMatch, nullptr))
|
||||
return host_platform_sp;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2905,9 +2905,9 @@ void Process::CompleteAttach() {
|
|||
ArchSpec process_host_arch = GetSystemArchitecture();
|
||||
if (platform_sp) {
|
||||
const ArchSpec &target_arch = GetTarget().GetArchitecture();
|
||||
if (target_arch.IsValid() &&
|
||||
!platform_sp->IsCompatibleArchitecture(target_arch, process_host_arch,
|
||||
false, nullptr)) {
|
||||
if (target_arch.IsValid() && !platform_sp->IsCompatibleArchitecture(
|
||||
target_arch, process_host_arch,
|
||||
ArchSpec::CompatibleMatch, nullptr)) {
|
||||
ArchSpec platform_arch;
|
||||
platform_sp = GetTarget().GetDebugger().GetPlatformList().GetOrCreate(
|
||||
target_arch, process_host_arch, &platform_arch);
|
||||
|
|
|
@ -1488,8 +1488,8 @@ bool Target::SetArchitecture(const ArchSpec &arch_spec, bool set_platform) {
|
|||
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, {},
|
||||
|
|
|
@ -216,7 +216,8 @@ Status TargetList::CreateTargetInternal(
|
|||
// 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);
|
||||
|
@ -225,7 +226,8 @@ Status TargetList::CreateTargetInternal(
|
|||
// 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)
|
||||
|
@ -256,8 +258,8 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -928,14 +928,6 @@ uint32_t ArchSpec::GetMaximumOpcodeByteSize() const {
|
|||
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 @@ static bool IsCompatibleEnvironment(llvm::Triple::EnvironmentType lhs,
|
|||
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();
|
||||
|
@ -988,7 +980,7 @@ bool ArchSpec::IsEqualTo(const ArchSpec &rhs, bool exact_match) const {
|
|||
// On Windows, the vendor field doesn't have any practical effect, but
|
||||
// it is often set to either "pc" or "w64".
|
||||
if ((lhs_triple_vendor != rhs_triple_vendor) &&
|
||||
(exact_match || !both_windows)) {
|
||||
(match == ExactMatch || !both_windows)) {
|
||||
const bool rhs_vendor_specified = rhs.TripleVendorWasSpecified();
|
||||
const bool lhs_vendor_specified = TripleVendorWasSpecified();
|
||||
// Both architectures had the vendor specified, so if they aren't equal
|
||||
|
@ -1007,7 +999,7 @@ bool ArchSpec::IsEqualTo(const ArchSpec &rhs, bool exact_match) const {
|
|||
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 &&
|
||||
|
@ -1034,12 +1026,13 @@ bool ArchSpec::IsEqualTo(const ArchSpec &rhs, bool exact_match) const {
|
|||
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;
|
||||
}
|
||||
|
||||
if (!exact_match && both_windows)
|
||||
if (match == CompatibleMatch && both_windows)
|
||||
return true; // The Windows environments (MSVC vs GNU) are compatible
|
||||
|
||||
return IsCompatibleEnvironment(lhs_triple_env, rhs_triple_env);
|
||||
|
|
Loading…
Reference in New Issue