diff options
author | Pavel Labath <pavel@labath.sk> | 2019-02-12 09:27:24 +0000 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2019-02-12 09:27:24 +0000 |
commit | 52d9c62a500a2cb31c95f4e7dcf244f444934058 (patch) | |
tree | de240ffc85fa7c5f9ce2d64675f621ebdfe589e1 /lldb/source/Target/RemoteAwarePlatform.cpp | |
parent | b87ea73706257147b9af5a4a693ff22071c22fe9 (diff) | |
download | bcm5719-llvm-52d9c62a500a2cb31c95f4e7dcf244f444934058.tar.gz bcm5719-llvm-52d9c62a500a2cb31c95f4e7dcf244f444934058.zip |
Extract common PlatformPOSIX/Windows code into a separate class
Summary:
The two classes contained a lot of duplicated code, but there wasn't a
good place to factor it to. It couldn't be the base Platform class,
since we also have platforms which are only remote (such as
PlatformGDBRemoteServer), and so it did not make sense for those to have
an m_remote_platform member.
This patch creates a new class, RemoteAwarePlatform, which can serve as
a base class for platforms which can both serve as a host, and forward
actions to a remote system. It is motivated partly by D56232 (which was
about to add a bunch of additional duplicated methods), and partly by my
own need to modify a function which happens to be implemented in both
places identically.
The patch moves the methods which are trivially identical in the two
classes into the common base class, there were one or two more methods
which could probably be merged into one, but this wasn't completely
trivial, so I did not attempt to do that now.
Reviewers: jingham, zturner, clayborg, asmith
Subscribers: emaste, mgorny, Hui, lldb-commits
Differential Revision: https://reviews.llvm.org/D58052
llvm-svn: 353812
Diffstat (limited to 'lldb/source/Target/RemoteAwarePlatform.cpp')
-rw-r--r-- | lldb/source/Target/RemoteAwarePlatform.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/lldb/source/Target/RemoteAwarePlatform.cpp b/lldb/source/Target/RemoteAwarePlatform.cpp new file mode 100644 index 00000000000..451211b5355 --- /dev/null +++ b/lldb/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; +} |