This revision was automatically updated to reflect the committed changes.
Closed by commit rLLDB353812: Extract common PlatformPOSIX/Windows code into a 
separate class (authored by labath, committed by ).
Herald added a subscriber: jdoerfert.
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D58052?vs=186258&id=186414#toc

Repository:
  rLLDB LLDB

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58052/new/

https://reviews.llvm.org/D58052

Files:
  include/lldb/Target/RemoteAwarePlatform.h
  source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
  source/Plugins/Platform/POSIX/PlatformPOSIX.h
  source/Plugins/Platform/Windows/PlatformWindows.cpp
  source/Plugins/Platform/Windows/PlatformWindows.h
  source/Target/CMakeLists.txt
  source/Target/RemoteAwarePlatform.cpp

Index: include/lldb/Target/RemoteAwarePlatform.h
===================================================================
--- include/lldb/Target/RemoteAwarePlatform.h
+++ include/lldb/Target/RemoteAwarePlatform.h
@@ -0,0 +1,50 @@
+//===-- RemoteAwarePlatform.h -----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_TARGET_REMOTEAWAREPLATFORM_H
+#define LLDB_TARGET_REMOTEAWAREPLATFORM_H
+
+#include "lldb/Target/Platform.h"
+
+namespace lldb_private {
+
+/// A base class for platforms which automatically want to be able to forward
+/// operations to a remote platform instance (such as PlatformRemoteGDBServer).
+class RemoteAwarePlatform : public Platform {
+public:
+  using Platform::Platform;
+
+  bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch,
+                     ModuleSpec &module_spec) override;
+  Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid,
+                         FileSpec &local_file) override;
+
+  bool GetRemoteOSVersion() override;
+  bool GetRemoteOSBuildString(std::string &s) override;
+  bool GetRemoteOSKernelDescription(std::string &s) override;
+  ArchSpec GetRemoteSystemArchitecture() override;
+
+  const char *GetHostname() override;
+  const char *GetUserName(uint32_t uid) override;
+  const char *GetGroupName(uint32_t gid) override;
+  lldb_private::Environment GetEnvironment() override;
+
+  bool IsConnected() const override;
+
+  bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override;
+  uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
+                         ProcessInstanceInfoList &process_infos) override;
+  Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
+
+protected:
+  lldb::PlatformSP m_remote_platform_sp;
+};
+
+} // namespace lldb_private
+
+#endif // LLDB_TARGET_REMOTEAWAREPLATFORM_H
Index: source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
===================================================================
--- source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
+++ source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
@@ -40,11 +40,10 @@
 /// Default Constructor
 //------------------------------------------------------------------
 PlatformPOSIX::PlatformPOSIX(bool is_host)
-    : Platform(is_host), // This is the local host platform
+    : RemoteAwarePlatform(is_host), // This is the local host platform
       m_option_group_platform_rsync(new OptionGroupPlatformRSync()),
       m_option_group_platform_ssh(new OptionGroupPlatformSSH()),
-      m_option_group_platform_caching(new OptionGroupPlatformCaching()),
-      m_remote_platform_sp() {}
+      m_option_group_platform_caching(new OptionGroupPlatformCaching()) {}
 
 //------------------------------------------------------------------
 /// Destructor.
@@ -54,16 +53,6 @@
 //------------------------------------------------------------------
 PlatformPOSIX::~PlatformPOSIX() {}
 
-bool PlatformPOSIX::GetModuleSpec(const FileSpec &module_file_spec,
-                                  const ArchSpec &arch,
-                                  ModuleSpec &module_spec) {
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,
-                                               module_spec);
-
-  return Platform::GetModuleSpec(module_file_spec, arch, module_spec);
-}
-
 lldb_private::OptionGroupOptions *PlatformPOSIX::GetConnectionOptions(
     lldb_private::CommandInterpreter &interpreter) {
   auto iter = m_options.find(&interpreter), end = m_options.end();
@@ -79,14 +68,6 @@
   return m_options.at(&interpreter).get();
 }
 
-bool PlatformPOSIX::IsConnected() const {
-  if (IsHost())
-    return true;
-  else if (m_remote_platform_sp)
-    return m_remote_platform_sp->IsConnected();
-  return false;
-}
-
 lldb_private::Status PlatformPOSIX::RunShellCommand(
     const char *command, // Shouldn't be NULL
     const FileSpec &
@@ -251,38 +232,6 @@
   return error;
 }
 
-Status PlatformPOSIX::GetFileWithUUID(const FileSpec &platform_file,
-                                      const UUID *uuid_ptr,
-                                      FileSpec &local_file) {
-  if (IsRemote() && m_remote_platform_sp)
-      return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
-                                                   local_file);
-
-  // Default to the local case
-  local_file = platform_file;
-  return Status();
-}
-
-bool PlatformPOSIX::GetProcessInfo(lldb::pid_t pid,
-                                     ProcessInstanceInfo &process_info) {
-  if (IsHost())
-    return Platform::GetProcessInfo(pid, process_info);
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetProcessInfo(pid, process_info);
-  return false;
-}
-
-uint32_t
-PlatformPOSIX::FindProcesses(const ProcessInstanceInfoMatch &match_info,
-                               ProcessInstanceInfoList &process_infos) {
-  if (IsHost())
-    return Platform::FindProcesses(match_info, process_infos);
-  if (m_remote_platform_sp)
-    return
-      m_remote_platform_sp->FindProcesses(match_info, process_infos);
-  return 0;
-}
-
 Status PlatformPOSIX::MakeDirectory(const FileSpec &file_spec,
                                     uint32_t file_permissions) {
   if (m_remote_platform_sp)
@@ -649,74 +598,6 @@
     return Platform::SetRemoteWorkingDirectory(working_dir);
 }
 
-bool PlatformPOSIX::GetRemoteOSVersion() {
-  if (m_remote_platform_sp) {
-    m_os_version = m_remote_platform_sp->GetOSVersion();
-    return !m_os_version.empty();
-  }
-  return false;
-}
-
-bool PlatformPOSIX::GetRemoteOSBuildString(std::string &s) {
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetRemoteOSBuildString(s);
-  s.clear();
-  return false;
-}
-
-Environment PlatformPOSIX::GetEnvironment() {
-  if (IsRemote()) {
-    if (m_remote_platform_sp)
-      return m_remote_platform_sp->GetEnvironment();
-    return Environment();
-  }
-  return Host::GetEnvironment();
-}
-
-bool PlatformPOSIX::GetRemoteOSKernelDescription(std::string &s) {
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetRemoteOSKernelDescription(s);
-  s.clear();
-  return false;
-}
-
-// Remote Platform subclasses need to override this function
-ArchSpec PlatformPOSIX::GetRemoteSystemArchitecture() {
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetRemoteSystemArchitecture();
-  return ArchSpec();
-}
-
-const char *PlatformPOSIX::GetHostname() {
-  if (IsHost())
-    return Platform::GetHostname();
-
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetHostname();
-  return NULL;
-}
-
-const char *PlatformPOSIX::GetUserName(uint32_t uid) {
-  // Check the cache in Platform in case we have already looked this uid up
-  const char *user_name = Platform::GetUserName(uid);
-  if (user_name)
-    return user_name;
-
-  if (IsRemote() && m_remote_platform_sp)
-    return m_remote_platform_sp->GetUserName(uid);
-  return NULL;
-}
-
-const char *PlatformPOSIX::GetGroupName(uint32_t gid) {
-  const char *group_name = Platform::GetGroupName(gid);
-  if (group_name)
-    return group_name;
-
-  if (IsRemote() && m_remote_platform_sp)
-    return m_remote_platform_sp->GetGroupName(gid);
-  return NULL;
-}
-
 Status PlatformPOSIX::ConnectRemote(Args &args) {
   Status error;
   if (IsHost()) {
@@ -776,20 +657,6 @@
   return error;
 }
 
-Status PlatformPOSIX::LaunchProcess(ProcessLaunchInfo &launch_info) {
-  Status error;
-
-  if (IsHost()) {
-    error = Platform::LaunchProcess(launch_info);
-  } else {
-    if (m_remote_platform_sp)
-      error = m_remote_platform_sp->LaunchProcess(launch_info);
-    else
-      error.SetErrorString("the platform is not currently connected");
-  }
-  return error;
-}
-
 lldb_private::Status PlatformPOSIX::KillProcess(const lldb::pid_t pid) {
   if (IsHost())
     return Platform::KillProcess(pid);
Index: source/Plugins/Platform/POSIX/PlatformPOSIX.h
===================================================================
--- source/Plugins/Platform/POSIX/PlatformPOSIX.h
+++ source/Plugins/Platform/POSIX/PlatformPOSIX.h
@@ -13,9 +13,9 @@
 #include <memory>
 
 #include "lldb/Interpreter/Options.h"
-#include "lldb/Target/Platform.h"
+#include "lldb/Target/RemoteAwarePlatform.h"
 
-class PlatformPOSIX : public lldb_private::Platform {
+class PlatformPOSIX : public lldb_private::RemoteAwarePlatform {
 public:
   PlatformPOSIX(bool is_host);
 
@@ -25,19 +25,9 @@
   // lldb_private::Platform functions
   //------------------------------------------------------------
 
-  bool GetModuleSpec(const lldb_private::FileSpec &module_file_spec,
-                     const lldb_private::ArchSpec &arch,
-                     lldb_private::ModuleSpec &module_spec) override;
-
   lldb_private::OptionGroupOptions *
   GetConnectionOptions(lldb_private::CommandInterpreter &interpreter) override;
 
-  const char *GetHostname() override;
-
-  const char *GetUserName(uint32_t uid) override;
-
-  const char *GetGroupName(uint32_t gid) override;
-
   lldb_private::Status PutFile(const lldb_private::FileSpec &source,
                                const lldb_private::FileSpec &destination,
                                uint32_t uid = UINT32_MAX,
@@ -70,20 +60,8 @@
   bool
   SetRemoteWorkingDirectory(const lldb_private::FileSpec &working_dir) override;
 
-  bool GetRemoteOSVersion() override;
-
-  bool GetRemoteOSBuildString(std::string &s) override;
-
-  bool GetRemoteOSKernelDescription(std::string &s) override;
-
-  lldb_private::ArchSpec GetRemoteSystemArchitecture() override;
-
   const lldb::UnixSignalsSP &GetRemoteUnixSignals() override;
 
-  lldb_private::Environment GetEnvironment() override;
-
-  bool IsConnected() const override;
-
   lldb_private::Status RunShellCommand(
       const char *command,                       // Shouldn't be nullptr
       const lldb_private::FileSpec &working_dir, // Pass empty FileSpec to use
@@ -100,16 +78,6 @@
       const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
       const lldb_private::FileSpecList *module_search_paths_ptr) override;
 
-  lldb_private::Status
-  GetFileWithUUID(const lldb_private::FileSpec &platform_file,
-                  const lldb_private::UUID *uuid,
-                  lldb_private::FileSpec &local_file) override;
-
-  bool GetProcessInfo(lldb::pid_t pid, lldb_private::ProcessInstanceInfo &proc_info) override;
-
-  uint32_t FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info,
-                         lldb_private::ProcessInstanceInfoList &process_infos) override;
-
   lldb_private::Status MakeDirectory(const lldb_private::FileSpec &file_spec,
                                      uint32_t mode) override;
 
@@ -125,9 +93,6 @@
 
   lldb_private::Status Unlink(const lldb_private::FileSpec &file_spec) override;
 
-  lldb_private::Status
-  LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
-
   lldb_private::Status KillProcess(const lldb::pid_t pid) override;
 
   lldb::ProcessSP Attach(lldb_private::ProcessAttachInfo &attach_info,
@@ -189,8 +154,6 @@
   std::map<lldb_private::CommandInterpreter *,
            std::unique_ptr<lldb_private::OptionGroupOptions>>
       m_options;
-  lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a
-                                         // remote POSIX-compliant OS
 
   lldb_private::Status
   EvaluateLibdlExpression(lldb_private::Process *process, const char *expr_cstr,
Index: source/Plugins/Platform/Windows/PlatformWindows.h
===================================================================
--- source/Plugins/Platform/Windows/PlatformWindows.h
+++ source/Plugins/Platform/Windows/PlatformWindows.h
@@ -9,11 +9,11 @@
 #ifndef liblldb_PlatformWindows_h_
 #define liblldb_PlatformWindows_h_
 
-#include "lldb/Target/Platform.h"
+#include "lldb/Target/RemoteAwarePlatform.h"
 
 namespace lldb_private {
 
-class PlatformWindows : public Platform {
+class PlatformWindows : public RemoteAwarePlatform {
 public:
   PlatformWindows(bool is_host);
 
@@ -40,10 +40,6 @@
   //------------------------------------------------------------
   // lldb_private::Platform functions
   //------------------------------------------------------------
-  bool GetModuleSpec(const lldb_private::FileSpec &module_file_spec,
-                     const lldb_private::ArchSpec &arch,
-                     lldb_private::ModuleSpec &module_spec) override;
-
   Status
   ResolveExecutable(const lldb_private::ModuleSpec &module_spec,
                     lldb::ModuleSP &module_sp,
@@ -53,37 +49,10 @@
     return GetPluginDescriptionStatic(IsHost());
   }
 
-  bool GetRemoteOSVersion() override;
-
-  bool GetRemoteOSBuildString(std::string &s) override;
-
-  bool GetRemoteOSKernelDescription(std::string &s) override;
-
-  // Remote Platform subclasses need to override this function
-  lldb_private::ArchSpec GetRemoteSystemArchitecture() override;
-
-  bool IsConnected() const override;
-
   lldb_private::Status ConnectRemote(lldb_private::Args &args) override;
 
   lldb_private::Status DisconnectRemote() override;
 
-  const char *GetHostname() override;
-
-  const char *GetUserName(uint32_t uid) override;
-
-  const char *GetGroupName(uint32_t gid) override;
-
-  bool GetProcessInfo(lldb::pid_t pid,
-                      lldb_private::ProcessInstanceInfo &proc_info) override;
-
-  uint32_t
-  FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info,
-                lldb_private::ProcessInstanceInfoList &process_infos) override;
-
-  lldb_private::Status
-  LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
-
   lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
                                lldb_private::Debugger &debugger,
                                lldb_private::Target *target,
@@ -95,11 +64,6 @@
                          lldb_private::Status &error) override;
 
   lldb_private::Status
-  GetFileWithUUID(const lldb_private::FileSpec &platform_file,
-                  const lldb_private::UUID *uuid,
-                  lldb_private::FileSpec &local_file) override;
-
-  lldb_private::Status
   GetSharedModule(const lldb_private::ModuleSpec &module_spec,
                   lldb_private::Process *process, lldb::ModuleSP &module_sp,
                   const lldb_private::FileSpecList *module_search_paths_ptr,
@@ -113,16 +77,11 @@
 
   bool CanDebugProcess() override;
 
-  Environment GetEnvironment() override;
-
   // FIXME not sure what the _sigtramp equivalent would be on this platform
   void CalculateTrapHandlerSymbolNames() override {}
 
   ConstString GetFullNameForDylib(ConstString basename) override;
 
-protected:
-  lldb::PlatformSP m_remote_platform_sp;
-
 private:
   DISALLOW_COPY_AND_ASSIGN(PlatformWindows);
 };
Index: source/Plugins/Platform/Windows/PlatformWindows.cpp
===================================================================
--- source/Plugins/Platform/Windows/PlatformWindows.cpp
+++ source/Plugins/Platform/Windows/PlatformWindows.cpp
@@ -155,7 +155,7 @@
 //------------------------------------------------------------------
 /// Default Constructor
 //------------------------------------------------------------------
-PlatformWindows::PlatformWindows(bool is_host) : Platform(is_host) {}
+PlatformWindows::PlatformWindows(bool is_host) : RemoteAwarePlatform(is_host) {}
 
 //------------------------------------------------------------------
 /// Destructor.
@@ -165,16 +165,6 @@
 //------------------------------------------------------------------
 PlatformWindows::~PlatformWindows() = default;
 
-bool PlatformWindows::GetModuleSpec(const FileSpec &module_file_spec,
-                                    const ArchSpec &arch,
-                                    ModuleSpec &module_spec) {
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,
-                                               module_spec);
-
-  return Platform::GetModuleSpec(module_file_spec, arch, module_spec);
-}
-
 Status PlatformWindows::ResolveExecutable(
     const ModuleSpec &ms, lldb::ModuleSP &exe_module_sp,
     const FileSpecList *module_search_paths_ptr) {
@@ -277,52 +267,6 @@
   return error;
 }
 
-bool PlatformWindows::GetRemoteOSVersion() {
-  if (m_remote_platform_sp) {
-    m_os_version = m_remote_platform_sp->GetOSVersion();
-    return !m_os_version.empty();
-  }
-  return false;
-}
-
-bool PlatformWindows::GetRemoteOSBuildString(std::string &s) {
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetRemoteOSBuildString(s);
-  s.clear();
-  return false;
-}
-
-bool PlatformWindows::GetRemoteOSKernelDescription(std::string &s) {
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetRemoteOSKernelDescription(s);
-  s.clear();
-  return false;
-}
-
-// Remote Platform subclasses need to override this function
-ArchSpec PlatformWindows::GetRemoteSystemArchitecture() {
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetRemoteSystemArchitecture();
-  return ArchSpec();
-}
-
-const char *PlatformWindows::GetHostname() {
-  if (IsHost())
-    return Platform::GetHostname();
-
-  if (m_remote_platform_sp)
-    return m_remote_platform_sp->GetHostname();
-  return nullptr;
-}
-
-bool PlatformWindows::IsConnected() const {
-  if (IsHost())
-    return true;
-  else if (m_remote_platform_sp)
-    return m_remote_platform_sp->IsConnected();
-  return false;
-}
-
 Status PlatformWindows::ConnectRemote(Args &args) {
   Status error;
   if (IsHost()) {
@@ -369,46 +313,6 @@
   return error;
 }
 
-bool PlatformWindows::GetProcessInfo(lldb::pid_t pid,
-                                     ProcessInstanceInfo &process_info) {
-  bool success = false;
-  if (IsHost()) {
-    success = Platform::GetProcessInfo(pid, process_info);
-  } else if (m_remote_platform_sp) {
-    success = m_remote_platform_sp->GetProcessInfo(pid, process_info);
-  }
-  return success;
-}
-
-uint32_t
-PlatformWindows::FindProcesses(const ProcessInstanceInfoMatch &match_info,
-                               ProcessInstanceInfoList &process_infos) {
-  uint32_t match_count = 0;
-  if (IsHost()) {
-    // Let the base class figure out the host details
-    match_count = Platform::FindProcesses(match_info, process_infos);
-  } else {
-    // If we are remote, we can only return results if we are connected
-    if (m_remote_platform_sp)
-      match_count =
-          m_remote_platform_sp->FindProcesses(match_info, process_infos);
-  }
-  return match_count;
-}
-
-Status PlatformWindows::LaunchProcess(ProcessLaunchInfo &launch_info) {
-  Status error;
-  if (IsHost()) {
-    error = Platform::LaunchProcess(launch_info);
-  } else {
-    if (m_remote_platform_sp)
-      error = m_remote_platform_sp->LaunchProcess(launch_info);
-    else
-      error.SetErrorString("the platform is not currently connected");
-  }
-  return error;
-}
-
 ProcessSP PlatformWindows::DebugProcess(ProcessLaunchInfo &launch_info,
                                         Debugger &debugger, Target *target,
                                         Status &error) {
@@ -488,41 +392,6 @@
   return process_sp;
 }
 
-const char *PlatformWindows::GetUserName(uint32_t uid) {
-  // Check the cache in Platform in case we have already looked this uid up
-  const char *user_name = Platform::GetUserName(uid);
-  if (user_name)
-    return user_name;
-
-  if (IsRemote() && m_remote_platform_sp)
-    return m_remote_platform_sp->GetUserName(uid);
-  return nullptr;
-}
-
-const char *PlatformWindows::GetGroupName(uint32_t gid) {
-  const char *group_name = Platform::GetGroupName(gid);
-  if (group_name)
-    return group_name;
-
-  if (IsRemote() && m_remote_platform_sp)
-    return m_remote_platform_sp->GetGroupName(gid);
-  return nullptr;
-}
-
-Status PlatformWindows::GetFileWithUUID(const FileSpec &platform_file,
-                                        const UUID *uuid_ptr,
-                                        FileSpec &local_file) {
-  if (IsRemote()) {
-    if (m_remote_platform_sp)
-      return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
-                                                   local_file);
-  }
-
-  // Default to the local case
-  local_file = platform_file;
-  return Status();
-}
-
 Status PlatformWindows::GetSharedModule(
     const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
     const FileSpecList *module_search_paths_ptr, ModuleSP *old_module_sp_ptr,
@@ -572,16 +441,6 @@
 
 bool PlatformWindows::CanDebugProcess() { return true; }
 
-Environment PlatformWindows::GetEnvironment() {
-  if (IsRemote()) {
-    if (m_remote_platform_sp)
-      return m_remote_platform_sp->GetEnvironment();
-    return Environment();
-  }
-
-  return Host::GetEnvironment();
-}
-
 ConstString PlatformWindows::GetFullNameForDylib(ConstString basename) {
   if (basename.IsEmpty())
     return basename;
Index: source/Target/CMakeLists.txt
===================================================================
--- source/Target/CMakeLists.txt
+++ source/Target/CMakeLists.txt
@@ -21,6 +21,7 @@
   QueueList.cpp
   RegisterContext.cpp
   RegisterNumber.cpp
+  RemoteAwarePlatform.cpp
   SectionLoadHistory.cpp
   SectionLoadList.cpp
   StackFrame.cpp
Index: source/Target/RemoteAwarePlatform.cpp
===================================================================
--- source/Target/RemoteAwarePlatform.cpp
+++ source/Target/RemoteAwarePlatform.cpp
@@ -0,0 +1,142 @@
+//===-- RemoteAwarePlatform.cpp ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/RemoteAwarePlatform.h"
+#include "lldb/Host/Host.h"
+
+using namespace lldb_private;
+
+bool RemoteAwarePlatform::GetModuleSpec(const FileSpec &module_file_spec,
+                                        const ArchSpec &arch,
+                                        ModuleSpec &module_spec) {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,
+                                               module_spec);
+
+  return Platform::GetModuleSpec(module_file_spec, arch, module_spec);
+}
+
+Status RemoteAwarePlatform::GetFileWithUUID(const FileSpec &platform_file,
+                                            const UUID *uuid_ptr,
+                                            FileSpec &local_file) {
+  if (IsRemote() && m_remote_platform_sp)
+    return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
+                                                 local_file);
+
+  // Default to the local case
+  local_file = platform_file;
+  return Status();
+}
+
+bool RemoteAwarePlatform::GetRemoteOSVersion() {
+  if (m_remote_platform_sp) {
+    m_os_version = m_remote_platform_sp->GetOSVersion();
+    return !m_os_version.empty();
+  }
+  return false;
+}
+
+bool RemoteAwarePlatform::GetRemoteOSBuildString(std::string &s) {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetRemoteOSBuildString(s);
+  s.clear();
+  return false;
+}
+
+bool RemoteAwarePlatform::GetRemoteOSKernelDescription(std::string &s) {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetRemoteOSKernelDescription(s);
+  s.clear();
+  return false;
+}
+
+ArchSpec RemoteAwarePlatform::GetRemoteSystemArchitecture() {
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetRemoteSystemArchitecture();
+  return ArchSpec();
+}
+
+const char *RemoteAwarePlatform::GetHostname() {
+  if (IsHost())
+    return Platform::GetHostname();
+
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetHostname();
+  return nullptr;
+}
+
+const char *RemoteAwarePlatform::GetUserName(uint32_t uid) {
+  // Check the cache in Platform in case we have already looked this uid up
+  const char *user_name = Platform::GetUserName(uid);
+  if (user_name)
+    return user_name;
+
+  if (IsRemote() && m_remote_platform_sp)
+    return m_remote_platform_sp->GetUserName(uid);
+  return nullptr;
+}
+
+const char *RemoteAwarePlatform::GetGroupName(uint32_t gid) {
+  const char *group_name = Platform::GetGroupName(gid);
+  if (group_name)
+    return group_name;
+
+  if (IsRemote() && m_remote_platform_sp)
+    return m_remote_platform_sp->GetGroupName(gid);
+  return nullptr;
+}
+
+Environment RemoteAwarePlatform::GetEnvironment() {
+  if (IsRemote()) {
+    if (m_remote_platform_sp)
+      return m_remote_platform_sp->GetEnvironment();
+    return Environment();
+  }
+  return Host::GetEnvironment();
+}
+
+bool RemoteAwarePlatform::IsConnected() const {
+  if (IsHost())
+    return true;
+  else if (m_remote_platform_sp)
+    return m_remote_platform_sp->IsConnected();
+  return false;
+}
+
+bool RemoteAwarePlatform::GetProcessInfo(lldb::pid_t pid,
+                                         ProcessInstanceInfo &process_info) {
+  if (IsHost())
+    return Platform::GetProcessInfo(pid, process_info);
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->GetProcessInfo(pid, process_info);
+  return false;
+}
+
+uint32_t
+RemoteAwarePlatform::FindProcesses(const ProcessInstanceInfoMatch &match_info,
+                                   ProcessInstanceInfoList &process_infos) {
+  if (IsHost())
+    return Platform::FindProcesses(match_info, process_infos);
+  if (m_remote_platform_sp)
+    return m_remote_platform_sp->FindProcesses(match_info, process_infos);
+  return 0;
+}
+
+Status RemoteAwarePlatform::LaunchProcess(ProcessLaunchInfo &launch_info) {
+  Status error;
+
+  if (IsHost()) {
+    error = Platform::LaunchProcess(launch_info);
+  } else {
+    if (m_remote_platform_sp)
+      error = m_remote_platform_sp->LaunchProcess(launch_info);
+    else
+      error.SetErrorString("the platform is not currently connected");
+  }
+  return error;
+}
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to