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/Plugins/Platform/Windows | |
| 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/Plugins/Platform/Windows')
| -rw-r--r-- | lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp | 143 | ||||
| -rw-r--r-- | lldb/source/Plugins/Platform/Windows/PlatformWindows.h | 45 |
2 files changed, 3 insertions, 185 deletions
diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp index 3826aaab55f..9f8e3258de1 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -155,7 +155,7 @@ void PlatformWindows::Terminate(void) { //------------------------------------------------------------------ /// 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(bool is_host) : Platform(is_host) {} //------------------------------------------------------------------ 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 @@ Status PlatformWindows::ResolveExecutable( 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 @@ Status PlatformWindows::DisconnectRemote() { 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 @@ lldb::ProcessSP PlatformWindows::Attach(ProcessAttachInfo &attach_info, 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 @@ void PlatformWindows::GetStatus(Stream &strm) { 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; diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h b/lldb/source/Plugins/Platform/Windows/PlatformWindows.h index 3b831487e2b..dc42998aabc 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.h +++ b/lldb/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 @@ public: //------------------------------------------------------------ // 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 @@ public: 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 @@ public: 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 @@ public: 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); }; |

