[Lldb-commits] [lldb] 1b468f1 - [lldb] Port PlatformWindows, PlatformOpenBSD and PlatformRemoteGDBServer to GetSupportedArchitectures

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 17 11:09:47 PST 2021


Author: Pavel Labath
Date: 2021-11-17T20:09:31+01:00
New Revision: 1b468f1c1b46734f64f15c22cfbd403bada9fed8

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

LOG: [lldb] Port PlatformWindows, PlatformOpenBSD and PlatformRemoteGDBServer to GetSupportedArchitectures

Added: 
    

Modified: 
    lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
    lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
    lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
    lldb/source/Plugins/Platform/Windows/PlatformWindows.h
    lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
    lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp b/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
index 7fcc30b92d295..84d9ff799f474 100644
--- a/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
+++ b/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
@@ -106,53 +106,21 @@ void PlatformOpenBSD::Terminate() {
 /// Default Constructor
 PlatformOpenBSD::PlatformOpenBSD(bool is_host)
     : PlatformPOSIX(is_host) // This is the local host platform
-{}
-
-bool PlatformOpenBSD::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                      ArchSpec &arch) {
-  if (IsHost()) {
-    ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
-    if (hostArch.GetTriple().isOSOpenBSD()) {
-      if (idx == 0) {
-        arch = hostArch;
-        return arch.IsValid();
-      }
-    }
+{
+  if (is_host) {
+    m_supported_architectures.push_back(HostInfo::GetArchitecture());
   } else {
-    if (m_remote_platform_sp)
-      return m_remote_platform_sp->GetSupportedArchitectureAtIndex(idx, arch);
-
-    llvm::Triple triple;
-    // Set the OS to OpenBSD
-    triple.setOS(llvm::Triple::OpenBSD);
-    // Set the architecture
-    switch (idx) {
-    case 0:
-      triple.setArchName("x86_64");
-      break;
-    case 1:
-      triple.setArchName("i386");
-      break;
-    case 2:
-      triple.setArchName("aarch64");
-      break;
-    case 3:
-      triple.setArchName("arm");
-      break;
-    default:
-      return false;
-    }
-    // Leave the vendor as "llvm::Triple:UnknownVendor" and don't specify the
-    // vendor by calling triple.SetVendorName("unknown") so that it is a
-    // "unspecified unknown". This means when someone calls
-    // triple.GetVendorName() it will return an empty string which indicates
-    // that the vendor can be set when two architectures are merged
-
-    // Now set the triple into "arch" and return true
-    arch.SetTriple(triple);
-    return true;
+    m_supported_architectures =
+        CreateArchList({llvm::Triple::x86_64, llvm::Triple::x86,
+                        llvm::Triple::aarch64, llvm::Triple::arm},
+                       llvm::Triple::OpenBSD);
   }
-  return false;
+}
+
+std::vector<ArchSpec> PlatformOpenBSD::GetSupportedArchitectures() {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetSupportedArchitectures();
+  return m_supported_architectures;
 }
 
 void PlatformOpenBSD::GetStatus(Stream &strm) {

diff  --git a/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h b/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
index 81680fe81e6f5..fd03988590cad 100644
--- a/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
+++ b/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
@@ -42,7 +42,7 @@ class PlatformOpenBSD : public PlatformPOSIX {
 
   void GetStatus(Stream &strm) override;
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
+  std::vector<ArchSpec> GetSupportedArchitectures() override;
 
   bool CanDebugProcess() override;
 
@@ -52,6 +52,8 @@ class PlatformOpenBSD : public PlatformPOSIX {
                                   lldb::addr_t length, unsigned prot,
                                   unsigned flags, lldb::addr_t fd,
                                   lldb::addr_t offset) override;
+
+  std::vector<ArchSpec> m_supported_architectures;
 };
 
 } // namespace platform_openbsd

diff  --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
index f991e127d0e22..8714953a9cdb8 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
@@ -30,35 +30,6 @@ LLDB_PLUGIN_DEFINE(PlatformWindows)
 
 static uint32_t g_initialize_count = 0;
 
-namespace {
-class SupportedArchList {
-public:
-  SupportedArchList() {
-    AddArch(ArchSpec("i686-pc-windows"));
-    AddArch(HostInfo::GetArchitecture(HostInfo::eArchKindDefault));
-    AddArch(HostInfo::GetArchitecture(HostInfo::eArchKind32));
-    AddArch(HostInfo::GetArchitecture(HostInfo::eArchKind64));
-    AddArch(ArchSpec("i386-pc-windows"));
-  }
-
-  size_t Count() const { return m_archs.size(); }
-
-  const ArchSpec &operator[](int idx) { return m_archs[idx]; }
-
-private:
-  void AddArch(const ArchSpec &spec) {
-    if (llvm::any_of(m_archs, [spec](const ArchSpec &rhs) {
-          return spec.IsExactMatch(rhs);
-        }))
-      return;
-    if (spec.IsValid())
-      m_archs.push_back(spec);
-  }
-
-  std::vector<ArchSpec> m_archs;
-};
-} // anonymous namespace
-
 PlatformSP PlatformWindows::CreateInstance(bool force,
                                            const lldb_private::ArchSpec *arch) {
   // The only time we create an instance is when we are creating a remote
@@ -134,7 +105,21 @@ void PlatformWindows::Terminate() {
 }
 
 /// Default Constructor
-PlatformWindows::PlatformWindows(bool is_host) : RemoteAwarePlatform(is_host) {}
+PlatformWindows::PlatformWindows(bool is_host) : RemoteAwarePlatform(is_host) {
+  const auto &AddArch = [&](const ArchSpec &spec) {
+    if (llvm::any_of(m_supported_architectures, [spec](const ArchSpec &rhs) {
+          return spec.IsExactMatch(rhs);
+        }))
+      return;
+    if (spec.IsValid())
+      m_supported_architectures.push_back(spec);
+  };
+  AddArch(ArchSpec("i686-pc-windows"));
+  AddArch(HostInfo::GetArchitecture(HostInfo::eArchKindDefault));
+  AddArch(HostInfo::GetArchitecture(HostInfo::eArchKind32));
+  AddArch(HostInfo::GetArchitecture(HostInfo::eArchKind64));
+  AddArch(ArchSpec("i386-pc-windows"));
+}
 
 Status PlatformWindows::ConnectRemote(Args &args) {
   Status error;
@@ -268,16 +253,6 @@ lldb::ProcessSP PlatformWindows::Attach(ProcessAttachInfo &attach_info,
   return process_sp;
 }
 
-bool PlatformWindows::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                      ArchSpec &arch) {
-  static SupportedArchList architectures;
-
-  if (idx >= architectures.Count())
-    return false;
-  arch = architectures[idx];
-  return true;
-}
-
 void PlatformWindows::GetStatus(Stream &strm) {
   Platform::GetStatus(strm);
 

diff  --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
index 672c94f0e7817..1708e08f3d46c 100644
--- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
+++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h
@@ -54,8 +54,9 @@ class PlatformWindows : public RemoteAwarePlatform {
                          lldb_private::Target *target,
                          lldb_private::Status &error) override;
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx,
-                                       lldb_private::ArchSpec &arch) override;
+  std::vector<ArchSpec> GetSupportedArchitectures() override {
+    return m_supported_architectures;
+  }
 
   void GetStatus(lldb_private::Stream &strm) override;
 
@@ -68,6 +69,8 @@ class PlatformWindows : public RemoteAwarePlatform {
 
   size_t GetSoftwareBreakpointTrapOpcode(Target &target,
                                          BreakpointSite *bp_site) override;
+
+  std::vector<ArchSpec> m_supported_architectures;
 };
 
 } // namespace lldb_private

diff  --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 56e624ab982a8..987f7c7f57e76 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -139,21 +139,6 @@ PlatformRemoteGDBServer::PlatformRemoteGDBServer()
 /// inherited from by the plug-in instance.
 PlatformRemoteGDBServer::~PlatformRemoteGDBServer() = default;
 
-bool PlatformRemoteGDBServer::GetSupportedArchitectureAtIndex(uint32_t idx,
-                                                              ArchSpec &arch) {
-  ArchSpec remote_arch = m_gdb_client.GetSystemArchitecture();
-
-  if (idx == 0) {
-    arch = remote_arch;
-    return arch.IsValid();
-  } else if (idx == 1 && remote_arch.IsValid() &&
-             remote_arch.GetTriple().isArch64Bit()) {
-    arch.SetTriple(remote_arch.GetTriple().get32BitArchVariant());
-    return arch.IsValid();
-  }
-  return false;
-}
-
 size_t PlatformRemoteGDBServer::GetSoftwareBreakpointTrapOpcode(
     Target &target, BreakpointSite *bp_site) {
   // This isn't needed if the z/Z packets are supported in the GDB remote
@@ -262,6 +247,15 @@ Status PlatformRemoteGDBServer::ConnectRemote(Args &args) {
     // now.
     if (m_working_dir)
       m_gdb_client.SetWorkingDir(m_working_dir);
+
+    m_supported_architectures.clear();
+    ArchSpec remote_arch = m_gdb_client.GetSystemArchitecture();
+    if (remote_arch) {
+      m_supported_architectures.push_back(remote_arch);
+      if (remote_arch.GetTriple().isArch64Bit())
+        m_supported_architectures.push_back(
+            ArchSpec(remote_arch.GetTriple().get32BitArchVariant()));
+    }
   } else {
     m_gdb_client.Disconnect();
     if (error.Success())

diff  --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
index e8536f2744b40..f594f43b3f136 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
@@ -66,7 +66,9 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {
                                          // target, else use existing one
                          Status &error) override;
 
-  bool GetSupportedArchitectureAtIndex(uint32_t idx, ArchSpec &arch) override;
+  std::vector<ArchSpec> GetSupportedArchitectures() override {
+    return m_supported_architectures;
+  }
 
   size_t GetSoftwareBreakpointTrapOpcode(Target &target,
                                          BreakpointSite *bp_site) override;
@@ -182,6 +184,8 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {
   llvm::Optional<std::string> DoGetUserName(UserIDResolver::id_t uid) override;
   llvm::Optional<std::string> DoGetGroupName(UserIDResolver::id_t uid) override;
 
+  std::vector<ArchSpec> m_supported_architectures;
+
   PlatformRemoteGDBServer(const PlatformRemoteGDBServer &) = delete;
   const PlatformRemoteGDBServer &
   operator=(const PlatformRemoteGDBServer &) = delete;


        


More information about the lldb-commits mailing list