[Lldb-commits] [lldb] e7c48f3 - [lldb] Use GetSupportedArchitectures on darwin platforms

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Dec 22 04:51:25 PST 2021


Author: Pavel Labath
Date: 2021-12-22T13:47:33+01:00
New Revision: e7c48f3cd5eb51b3bb9b928b3bde5da28da68e39

URL: https://github.com/llvm/llvm-project/commit/e7c48f3cd5eb51b3bb9b928b3bde5da28da68e39
DIFF: https://github.com/llvm/llvm-project/commit/e7c48f3cd5eb51b3bb9b928b3bde5da28da68e39.diff

LOG: [lldb] Use GetSupportedArchitectures on darwin platforms

This finishes the GetSupportedArchitectureAtIndex migration. There are
opportunities to simplify this even further, but I am going to leave
that to the platform owners.

Differential Revision: https://reviews.llvm.org/D116028

Added: 
    

Modified: 
    lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
    lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
    lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
index 69692ddc77c47..8f27f6a39f1ba 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
@@ -265,12 +265,11 @@ CoreSimulatorSupport::Device PlatformAppleSimulator::GetSimulatorDevice() {
 }
 #endif
 
-bool PlatformAppleSimulator::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                             ArchSpec &arch) {
-  if (idx >= m_supported_triples.size())
-    return false;
-  arch = ArchSpec(m_supported_triples[idx]);
-  return true;
+std::vector<ArchSpec> PlatformAppleSimulator::GetSupportedArchitectures() {
+  std::vector<ArchSpec> result(m_supported_triples.size());
+  llvm::transform(m_supported_triples, result.begin(),
+                  [](llvm::StringRef triple) { return ArchSpec(triple); });
+  return result;
 }
 
 PlatformSP PlatformAppleSimulator::CreateInstance(
@@ -380,10 +379,11 @@ Status PlatformAppleSimulator::ResolveExecutable(
     // so ask the platform for the architectures that we should be using (in
     // the correct order) and see if we can find a match that way
     StreamString arch_names;
+    llvm::ListSeparator LS;
     ArchSpec platform_arch;
-    for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
-             idx, resolved_module_spec.GetArchitecture());
-         ++idx) {
+    for (const ArchSpec &arch : GetSupportedArchitectures()) {
+      resolved_module_spec.GetArchitecture() = arch;
+
       // Only match x86 with x86 and x86_64 with x86_64...
       if (!module_spec.GetArchitecture().IsValid() ||
           module_spec.GetArchitecture().GetCore() ==
@@ -398,9 +398,7 @@ Status PlatformAppleSimulator::ResolveExecutable(
             error.SetErrorToGenericError();
         }
 
-        if (idx > 0)
-          arch_names.PutCString(", ");
-        arch_names.PutCString(platform_arch.GetArchitectureName());
+        arch_names << LS << platform_arch.GetArchitectureName();
       }
     }
 

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
index 583399073c580..e87636d9999cc 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
@@ -65,8 +65,7 @@ class PlatformAppleSimulator : public PlatformDarwin {
                                lldb_private::Target &target,
                                lldb_private::Status &error) override;
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
   lldb_private::Status ResolveExecutable(
       const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index f5ce3017a8f1b..de64426d7b647 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -514,45 +514,19 @@ bool PlatformDarwin::ModuleIsExcludedForUnconstrainedSearches(
   return obj_type == ObjectFile::eTypeDynamicLinker;
 }
 
-bool PlatformDarwin::x86GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                        ArchSpec &arch) {
+void PlatformDarwin::x86GetSupportedArchitectures(
+    std::vector<ArchSpec> &archs) {
   ArchSpec host_arch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
-  if (host_arch.GetCore() == ArchSpec::eCore_x86_64_x86_64h) {
-    switch (idx) {
-    case 0:
-      arch = host_arch;
-      return true;
-
-    case 1:
-      arch.SetTriple("x86_64-apple-macosx");
-      return true;
-
-    case 2:
-      arch = HostInfo::GetArchitecture(HostInfo::eArchKind32);
-      return true;
+  archs.push_back(host_arch);
 
-    default:
-      return false;
-    }
+  if (host_arch.GetCore() == ArchSpec::eCore_x86_64_x86_64h) {
+    archs.push_back(ArchSpec("x86_64-apple-macosx"));
+    archs.push_back(HostInfo::GetArchitecture(HostInfo::eArchKind32));
   } else {
-    if (idx == 0) {
-      arch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
-      return arch.IsValid();
-    } else if (idx == 1) {
-      ArchSpec platform_arch(
-          HostInfo::GetArchitecture(HostInfo::eArchKindDefault));
-      ArchSpec platform_arch64(
-          HostInfo::GetArchitecture(HostInfo::eArchKind64));
-      if (platform_arch.IsExactMatch(platform_arch64)) {
-        // This macosx platform supports both 32 and 64 bit. Since we already
-        // returned the 64 bit arch for idx == 0, return the 32 bit arch for
-        // idx == 1
-        arch = HostInfo::GetArchitecture(HostInfo::eArchKind32);
-        return arch.IsValid();
-      }
-    }
+    ArchSpec host_arch64 = HostInfo::GetArchitecture(HostInfo::eArchKind64);
+    if (host_arch.IsExactMatch(host_arch64))
+      archs.push_back(HostInfo::GetArchitecture(HostInfo::eArchKind32));
   }
-  return false;
 }
 
 static llvm::ArrayRef<const char *> GetCompatibleArchs(ArchSpec::Core core) {
@@ -669,21 +643,19 @@ const char *PlatformDarwin::GetCompatibleArch(ArchSpec::Core core, size_t idx) {
 /// The architecture selection rules for arm processors These cpu subtypes have
 /// distinct names (e.g. armv7f) but armv7 binaries run fine on an armv7f
 /// processor.
-bool PlatformDarwin::ARMGetSupportedArchitectureAtIndex(uint32_t idx,
-                                                        ArchSpec &arch) {
+void PlatformDarwin::ARMGetSupportedArchitectures(
+    std::vector<ArchSpec> &archs) {
   const ArchSpec system_arch = GetSystemArchitecture();
   const ArchSpec::Core system_core = system_arch.GetCore();
 
-  if (const char *compatible_arch = GetCompatibleArch(system_core, idx)) {
+  const char *compatible_arch;
+  for (unsigned idx = 0;
+       (compatible_arch = GetCompatibleArch(system_core, idx)); ++idx) {
     llvm::Triple triple;
     triple.setArchName(compatible_arch);
     triple.setVendor(llvm::Triple::VendorType::Apple);
-    arch.SetTriple(triple);
-    return true;
+    archs.push_back(ArchSpec(triple));
   }
-
-  arch.Clear();
-  return false;
 }
 
 static FileSpec GetXcodeSelectPath() {
@@ -1367,11 +1339,3 @@ FileSpec PlatformDarwin::GetCurrentCommandLineToolsDirectory() {
     return FileSpec(FindComponentInPath(fspec.GetPath(), "CommandLineTools"));
   return {};
 }
-
-std::vector<ArchSpec> PlatformDarwin::GetSupportedArchitectures() {
-  std::vector<ArchSpec> result;
-  ArchSpec arch;
-  for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(idx, arch); ++idx)
-    result.push_back(arch);
-  return result;
-}

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index 1a97c22cafffb..bbb2a336c56e0 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -60,11 +60,9 @@ class PlatformDarwin : public PlatformPOSIX {
   bool ModuleIsExcludedForUnconstrainedSearches(
       lldb_private::Target &target, const lldb::ModuleSP &module_sp) override;
 
-  bool ARMGetSupportedArchitectureAtIndex(uint32_t idx,
-                                          lldb_private::ArchSpec &arch);
+  void ARMGetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs);
 
-  bool x86GetSupportedArchitectureAtIndex(uint32_t idx,
-                                          lldb_private::ArchSpec &arch);
+  void x86GetSupportedArchitectures(std::vector<lldb_private::ArchSpec> &archs);
 
   uint32_t GetResumeCountForLaunchInfo(
       lldb_private::ProcessLaunchInfo &launch_info) override;
@@ -102,8 +100,6 @@ class PlatformDarwin : public PlatformPOSIX {
   /// located in.
   static lldb_private::FileSpec GetCurrentCommandLineToolsDirectory();
 
-  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
-
 protected:
   static const char *GetCompatibleArch(lldb_private::ArchSpec::Core core,
                                        size_t idx);
@@ -174,10 +170,6 @@ class PlatformDarwin : public PlatformPOSIX {
   static std::string FindComponentInPath(llvm::StringRef path,
                                          llvm::StringRef component);
 
-  virtual bool
-  GetSupportedArchitectureAtIndex(uint32_t idx,
-                                  lldb_private::ArchSpec &arch) = 0;
-
   std::string m_developer_directory;
   llvm::StringMap<std::string> m_sdk_path;
   std::mutex m_sdk_path_mutex;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
index 823c5a2fd198b..abb3b30e175a4 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -911,13 +911,14 @@ Status PlatformDarwinKernel::ExamineKextForMatchingUUID(
   return {};
 }
 
-bool PlatformDarwinKernel::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                           ArchSpec &arch) {
+std::vector<ArchSpec> PlatformDarwinKernel::GetSupportedArchitectures() {
+  std::vector<ArchSpec> result;
 #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
-  return ARMGetSupportedArchitectureAtIndex(idx, arch);
+  ARMGetSupportedArchitectures(result);
 #else
-  return x86GetSupportedArchitectureAtIndex(idx, arch);
+  x86GetSupportedArchitectures(result);
 #endif
+  return result;
 }
 
 void PlatformDarwinKernel::CalculateTrapHandlerSymbolNames() {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
index 4cb6c10fb8334..738594bda1403 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
@@ -56,8 +56,7 @@ class PlatformDarwinKernel : public PlatformDarwin {
                   llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
                   bool *did_create_ptr) override;
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
   bool SupportsModules() override { return false; }
 

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
index ac9604f681a09..3f2fb53ad654d 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
@@ -133,39 +133,23 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
   return {};
 }
 
-bool PlatformMacOSX::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                     ArchSpec &arch) {
+std::vector<ArchSpec> PlatformMacOSX::GetSupportedArchitectures() {
+  std::vector<ArchSpec> result;
 #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
   // macOS for ARM64 support both native and translated x86_64 processes
-  if (!m_num_arm_arches || idx < m_num_arm_arches) {
-    bool res = ARMGetSupportedArchitectureAtIndex(idx, arch);
-    if (res)
-      return true;
-    if (!m_num_arm_arches)
-      m_num_arm_arches = idx;
-  }
+  ARMGetSupportedArchitectures(result);
 
-  // We can't use x86GetSupportedArchitectureAtIndex() because it uses
+  // We can't use x86GetSupportedArchitectures() because it uses
   // the system architecture for some of its return values and also
   // has a 32bits variant.
-  if (idx == m_num_arm_arches) {
-    arch.SetTriple("x86_64-apple-macosx");
-    return true;
-  } else if (idx == m_num_arm_arches + 1) {
-    arch.SetTriple("x86_64-apple-ios-macabi");
-    return true;
-  } else if (idx == m_num_arm_arches + 2) {
-    arch.SetTriple("arm64-apple-ios");
-    return true;
-  } else if (idx == m_num_arm_arches + 3) {
-    arch.SetTriple("arm64e-apple-ios");
-    return true;
-  }
-
-  return false;
+  result.push_back(ArchSpec("x86_64-apple-macosx"));
+  result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
+  result.push_back(ArchSpec("arm64-apple-ios"));
+  result.push_back(ArchSpec("arm64e-apple-ios"));
 #else
-  return x86GetSupportedArchitectureAtIndex(idx, arch);
+  x86GetSupportedArchitectures(result);
 #endif
+  return result;
 }
 
 lldb_private::Status PlatformMacOSX::GetSharedModule(

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
index 404f93348dfa9..113214befa92d 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
@@ -47,8 +47,7 @@ class PlatformMacOSX : public PlatformDarwin {
     return PlatformDarwin::GetFile(source, destination);
   }
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
   lldb_private::ConstString
   GetSDKDirectory(lldb_private::Target &target) override;
@@ -59,11 +58,6 @@ class PlatformMacOSX : public PlatformDarwin {
     return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
         target, options, lldb_private::XcodeSDK::Type::MacOSX);
   }
-
-private:
-#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
-  uint32_t m_num_arm_arches = 0;
-#endif
 };
 
 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMMACOSX_H

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp
index b7ba2ea29bf68..495e8615c6120 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp
@@ -137,34 +137,8 @@ llvm::StringRef PlatformRemoteAppleBridge::GetDescriptionStatic() {
   return "Remote BridgeOS platform plug-in.";
 }
 
-bool PlatformRemoteAppleBridge::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                            ArchSpec &arch) {
-  ArchSpec system_arch(GetSystemArchitecture());
-
-  const ArchSpec::Core system_core = system_arch.GetCore();
-  switch (system_core) {
-  default:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("arm64-apple-bridgeos");
-      return true;
-    default:
-      break;
-    }
-    break;
-
-  case ArchSpec::eCore_arm_arm64:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("arm64-apple-bridgeos");
-      return true;
-    default:
-      break;
-    }
-    break;
-  }
-  arch.Clear();
-  return false;
+std::vector<ArchSpec> PlatformRemoteAppleBridge::GetSupportedArchitectures() {
+  return {ArchSpec("arm64-apple-bridgeos")};
 }
 
 llvm::StringRef PlatformRemoteAppleBridge::GetDeviceSupportDirectoryName() {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h
index 1f4a0b0b0d4dd..0d11df01d6332 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h
@@ -40,8 +40,7 @@ class PlatformRemoteAppleBridge : public PlatformRemoteDarwinDevice {
 
   llvm::StringRef GetDescription() override { return GetDescriptionStatic(); }
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
 protected:
   llvm::StringRef GetDeviceSupportDirectoryName() override;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
index 42d0de0e36c79..d11e13cd8239d 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
@@ -132,90 +132,24 @@ llvm::StringRef PlatformRemoteAppleTV::GetDescriptionStatic() {
   return "Remote Apple TV platform plug-in.";
 }
 
-bool PlatformRemoteAppleTV::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                            ArchSpec &arch) {
+std::vector<ArchSpec> PlatformRemoteAppleTV::GetSupportedArchitectures() {
   ArchSpec system_arch(GetSystemArchitecture());
 
   const ArchSpec::Core system_core = system_arch.GetCore();
   switch (system_core) {
   default:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("arm64-apple-tvos");
-      return true;
-    case 1:
-      arch.SetTriple("armv7s-apple-tvos");
-      return true;
-    case 2:
-      arch.SetTriple("armv7-apple-tvos");
-      return true;
-    case 3:
-      arch.SetTriple("thumbv7s-apple-tvos");
-      return true;
-    case 4:
-      arch.SetTriple("thumbv7-apple-tvos");
-      return true;
-    default:
-      break;
-    }
-    break;
-
   case ArchSpec::eCore_arm_arm64:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("arm64-apple-tvos");
-      return true;
-    case 1:
-      arch.SetTriple("armv7s-apple-tvos");
-      return true;
-    case 2:
-      arch.SetTriple("armv7-apple-tvos");
-      return true;
-    case 3:
-      arch.SetTriple("thumbv7s-apple-tvos");
-      return true;
-    case 4:
-      arch.SetTriple("thumbv7-apple-tvos");
-      return true;
-    default:
-      break;
-    }
-    break;
+    return {ArchSpec("arm64-apple-tvos"), ArchSpec("armv7s-apple-tvos"),
+            ArchSpec("armv7-apple-tvos"), ArchSpec("thumbv7s-apple-tvos"),
+            ArchSpec("thumbv7-apple-tvos")};
 
   case ArchSpec::eCore_arm_armv7s:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("armv7s-apple-tvos");
-      return true;
-    case 1:
-      arch.SetTriple("armv7-apple-tvos");
-      return true;
-    case 2:
-      arch.SetTriple("thumbv7s-apple-tvos");
-      return true;
-    case 3:
-      arch.SetTriple("thumbv7-apple-tvos");
-      return true;
-    default:
-      break;
-    }
-    break;
+    return {ArchSpec("armv7s-apple-tvos"), ArchSpec("armv7-apple-tvos"),
+            ArchSpec("thumbv7s-apple-tvos"), ArchSpec("thumbv7-apple-tvos")};
 
   case ArchSpec::eCore_arm_armv7:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("armv7-apple-tvos");
-      return true;
-    case 1:
-      arch.SetTriple("thumbv7-apple-tvos");
-      return true;
-    default:
-      break;
-    }
-    break;
+    return {ArchSpec("armv7-apple-tvos"), ArchSpec("thumbv7-apple-tvos")};
   }
-  arch.Clear();
-  return false;
 }
 
 llvm::StringRef PlatformRemoteAppleTV::GetDeviceSupportDirectoryName() {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h
index ce120082a74fe..f6dbc7cac7932 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h
@@ -40,8 +40,7 @@ class PlatformRemoteAppleTV : public PlatformRemoteDarwinDevice {
 
   llvm::StringRef GetDescription() override { return GetDescriptionStatic(); }
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
 protected:
   llvm::StringRef GetDeviceSupportDirectoryName() override;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
index 849ff3a50486c..e1d78be6c145f 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
@@ -143,154 +143,39 @@ llvm::StringRef PlatformRemoteAppleWatch::GetDescriptionStatic() {
 PlatformRemoteAppleWatch::PlatformRemoteAppleWatch()
     : PlatformRemoteDarwinDevice() {}
 
-bool PlatformRemoteAppleWatch::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                               ArchSpec &arch) {
+std::vector<ArchSpec> PlatformRemoteAppleWatch::GetSupportedArchitectures() {
   ArchSpec system_arch(GetSystemArchitecture());
 
   const ArchSpec::Core system_core = system_arch.GetCore();
   switch (system_core) {
   default:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("arm64-apple-watchos");
-      return true;
-    case 1:
-      arch.SetTriple("armv7k-apple-watchos");
-      return true;
-    case 2:
-      arch.SetTriple("armv7s-apple-watchos");
-      return true;
-    case 3:
-      arch.SetTriple("armv7-apple-watchos");
-      return true;
-    case 4:
-      arch.SetTriple("thumbv7k-apple-watchos");
-      return true;
-    case 5:
-      arch.SetTriple("thumbv7-apple-watchos");
-      return true;
-    case 6:
-      arch.SetTriple("thumbv7s-apple-watchos");
-      return true;
-    case 7:
-      arch.SetTriple("arm64_32-apple-watchos");
-      return true;
-    default:
-      break;
-    }
-    break;
-
   case ArchSpec::eCore_arm_arm64:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("arm64-apple-watchos");
-      return true;
-    case 1:
-      arch.SetTriple("armv7k-apple-watchos");
-      return true;
-    case 2:
-      arch.SetTriple("armv7s-apple-watchos");
-      return true;
-    case 3:
-      arch.SetTriple("armv7-apple-watchos");
-      return true;
-    case 4:
-      arch.SetTriple("thumbv7k-apple-watchos");
-      return true;
-    case 5:
-      arch.SetTriple("thumbv7-apple-watchos");
-      return true;
-    case 6:
-      arch.SetTriple("thumbv7s-apple-watchos");
-      return true;
-    case 7:
-      arch.SetTriple("arm64_32-apple-watchos");
-      return true;
-    default:
-      break;
-    }
-    break;
+    return {
+        ArchSpec("arm64-apple-watchos"),    ArchSpec("armv7k-apple-watchos"),
+        ArchSpec("armv7s-apple-watchos"),   ArchSpec("armv7-apple-watchos"),
+        ArchSpec("thumbv7k-apple-watchos"), ArchSpec("thumbv7-apple-watchos"),
+        ArchSpec("thumbv7s-apple-watchos"), ArchSpec("arm64_32-apple-watchos")};
 
   case ArchSpec::eCore_arm_armv7k:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("armv7k-apple-watchos");
-      return true;
-    case 1:
-      arch.SetTriple("armv7s-apple-watchos");
-      return true;
-    case 2:
-      arch.SetTriple("armv7-apple-watchos");
-      return true;
-    case 3:
-      arch.SetTriple("thumbv7k-apple-watchos");
-      return true;
-    case 4:
-      arch.SetTriple("thumbv7-apple-watchos");
-      return true;
-    case 5:
-      arch.SetTriple("thumbv7s-apple-watchos");
-      return true;
-    case 6:
-      arch.SetTriple("arm64_32-apple-watchos");
-      return true;
-    default:
-      break;
-    }
-    break;
+    return {
+        ArchSpec("armv7k-apple-watchos"),  ArchSpec("armv7s-apple-watchos"),
+        ArchSpec("armv7-apple-watchos"),   ArchSpec("thumbv7k-apple-watchos"),
+        ArchSpec("thumbv7-apple-watchos"), ArchSpec("thumbv7s-apple-watchos"),
+        ArchSpec("arm64_32-apple-watchos")};
 
   case ArchSpec::eCore_arm_armv7s:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("armv7s-apple-watchos");
-      return true;
-    case 1:
-      arch.SetTriple("armv7k-apple-watchos");
-      return true;
-    case 2:
-      arch.SetTriple("armv7-apple-watchos");
-      return true;
-    case 3:
-      arch.SetTriple("thumbv7k-apple-watchos");
-      return true;
-    case 4:
-      arch.SetTriple("thumbv7-apple-watchos");
-      return true;
-    case 5:
-      arch.SetTriple("thumbv7s-apple-watchos");
-      return true;
-    case 6:
-      arch.SetTriple("arm64_32-apple-watchos");
-      return true;
-    default:
-      break;
-    }
-    break;
+    return {
+        ArchSpec("armv7s-apple-watchos"),  ArchSpec("armv7k-apple-watchos"),
+        ArchSpec("armv7-apple-watchos"),   ArchSpec("thumbv7k-apple-watchos"),
+        ArchSpec("thumbv7-apple-watchos"), ArchSpec("thumbv7s-apple-watchos"),
+        ArchSpec("arm64_32-apple-watchos")};
 
   case ArchSpec::eCore_arm_armv7:
-    switch (idx) {
-    case 0:
-      arch.SetTriple("armv7-apple-watchos");
-      return true;
-    case 1:
-      arch.SetTriple("armv7k-apple-watchos");
-      return true;
-    case 2:
-      arch.SetTriple("thumbv7k-apple-watchos");
-      return true;
-    case 3:
-      arch.SetTriple("thumbv7-apple-watchos");
-      return true;
-    case 4:
-      arch.SetTriple("arm64_32-apple-watchos");
-      return true;
-    default:
-      break;
-    }
-    break;
+    return {ArchSpec("armv7-apple-watchos"), ArchSpec("armv7k-apple-watchos"),
+            ArchSpec("thumbv7k-apple-watchos"),
+            ArchSpec("thumbv7-apple-watchos"),
+            ArchSpec("arm64_32-apple-watchos")};
   }
-  arch.Clear();
-  return false;
 }
 
 llvm::StringRef PlatformRemoteAppleWatch::GetDeviceSupportDirectoryName() {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h
index abecbd7335052..07d1cff081ddc 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h
@@ -43,8 +43,7 @@ class PlatformRemoteAppleWatch : public PlatformRemoteDarwinDevice {
 
   // lldb_private::Platform functions
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
 protected:
   llvm::StringRef GetDeviceSupportDirectoryName() override;

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
index 97b2b4a3b7401..5bc90e77ba530 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp
@@ -90,9 +90,9 @@ Status PlatformRemoteDarwinDevice::ResolveExecutable(
     // so ask the platform for the architectures that we should be using (in
     // the correct order) and see if we can find a match that way
     StreamString arch_names;
-    for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
-             idx, resolved_module_spec.GetArchitecture());
-         ++idx) {
+    llvm::ListSeparator LS;
+    for (const ArchSpec &arch : GetSupportedArchitectures()) {
+      resolved_module_spec.GetArchitecture() = arch;
       error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
                                           nullptr, nullptr, nullptr);
       // Did we find an executable using one of the
@@ -103,10 +103,7 @@ Status PlatformRemoteDarwinDevice::ResolveExecutable(
           error.SetErrorToGenericError();
       }
 
-      if (idx > 0)
-        arch_names.PutCString(", ");
-      arch_names.PutCString(
-          resolved_module_spec.GetArchitecture().GetArchitectureName());
+      arch_names << LS << arch.GetArchitectureName();
     }
 
     if (error.Fail() || !exe_module_sp) {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
index 72c3480da6615..1e969f05e15bc 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
@@ -124,35 +124,19 @@ PlatformSP PlatformRemoteMacOSX::CreateInstance(bool force,
   return PlatformSP();
 }
 
-bool PlatformRemoteMacOSX::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                           ArchSpec &arch) {
+std::vector<ArchSpec> PlatformRemoteMacOSX::GetSupportedArchitectures() {
   // macOS for ARM64 support both native and translated x86_64 processes
-  if (!m_num_arm_arches || idx < m_num_arm_arches) {
-    bool res = ARMGetSupportedArchitectureAtIndex(idx, arch);
-    if (res)
-      return true;
-    if (!m_num_arm_arches)
-      m_num_arm_arches = idx;
-  }
+  std::vector<ArchSpec> result;
+  ARMGetSupportedArchitectures(result);
 
-  // We can't use x86GetSupportedArchitectureAtIndex() because it uses
+  // We can't use x86GetSupportedArchitectures() because it uses
   // the system architecture for some of its return values and also
   // has a 32bits variant.
-  if (idx == m_num_arm_arches) {
-    arch.SetTriple("x86_64-apple-macosx");
-    return true;
-  } else if (idx == m_num_arm_arches + 1) {
-    arch.SetTriple("x86_64-apple-ios-macabi");
-    return true;
-  } else if (idx == m_num_arm_arches + 2) {
-    arch.SetTriple("arm64-apple-ios");
-    return true;
-  } else if (idx == m_num_arm_arches + 3) {
-    arch.SetTriple("arm64e-apple-ios");
-    return true;
-  }
-
-  return false;
+  result.push_back(ArchSpec("x86_64-apple-macosx"));
+  result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
+  result.push_back(ArchSpec("arm64-apple-ios"));
+  result.push_back(ArchSpec("arm64e-apple-ios"));
+  return result;
 }
 
 lldb_private::Status PlatformRemoteMacOSX::GetFileWithUUID(

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h
index 83335cda1f807..8d08a51b31b8e 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h
@@ -42,15 +42,11 @@ class PlatformRemoteMacOSX : public virtual PlatformRemoteDarwinDevice {
                   const lldb_private::UUID *uuid_ptr,
                   lldb_private::FileSpec &local_file) override;
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
 protected:
   llvm::StringRef GetDeviceSupportDirectoryName() override;
   llvm::StringRef GetPlatformName() override;
-
-private:
-  uint32_t m_num_arm_arches = 0;
 };
 
 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEMACOSX_H

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
index 8824cab2fff28..616123698e664 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
@@ -133,9 +133,10 @@ llvm::StringRef PlatformRemoteiOS::GetDescriptionStatic() {
 PlatformRemoteiOS::PlatformRemoteiOS()
     : PlatformRemoteDarwinDevice() {}
 
-bool PlatformRemoteiOS::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                        ArchSpec &arch) {
-  return ARMGetSupportedArchitectureAtIndex(idx, arch);
+std::vector<ArchSpec> PlatformRemoteiOS::GetSupportedArchitectures() {
+  std::vector<ArchSpec> result;
+  ARMGetSupportedArchitectures(result);
+  return result;
 }
 
 llvm::StringRef PlatformRemoteiOS::GetDeviceSupportDirectoryName() {

diff  --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
index 302df33fc116b..94be124d4310b 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
@@ -39,8 +39,7 @@ class PlatformRemoteiOS : public PlatformRemoteDarwinDevice {
   // lldb_private::PluginInterface functions
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<lldb_private::ArchSpec> GetSupportedArchitectures() override;
 
 protected:
   llvm::StringRef GetDeviceSupportDirectoryName() override;


        


More information about the lldb-commits mailing list