asmith created this revision. asmith added reviewers: zturner, llvm-commits. Herald added a subscriber: lldb-commits.
Implement a few routines for Windows to support some basic process interaction and file system operations. Repository: rLLDB LLDB https://reviews.llvm.org/D56232 Files: source/Plugins/Platform/Windows/PlatformWindows.cpp source/Plugins/Platform/Windows/PlatformWindows.h
Index: source/Plugins/Platform/Windows/PlatformWindows.h =================================================================== --- source/Plugins/Platform/Windows/PlatformWindows.h +++ source/Plugins/Platform/Windows/PlatformWindows.h @@ -54,6 +54,33 @@ return GetPluginDescriptionStatic(IsHost()); } + lldb::user_id_t OpenFile(const lldb_private::FileSpec &file_spec, + uint32_t flags, uint32_t mode, + lldb_private::Status &error) override; + + bool CloseFile(lldb::user_id_t fd, lldb_private::Status &error) override; + + uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, + uint64_t dst_len, lldb_private::Status &error) override; + + uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, + uint64_t src_len, lldb_private::Status &error) override; + + lldb::user_id_t GetFileSize(const lldb_private::FileSpec &file_spec) override; + + lldb_private::Status + CreateSymlink(const lldb_private::FileSpec &src, + const lldb_private::FileSpec &dst) override; + + bool GetFileExists(const lldb_private::FileSpec &file_spec) override; + + lldb_private::Status Unlink(const lldb_private::FileSpec &file_spec) override; + + lldb_private::FileSpec GetRemoteWorkingDirectory() override; + + bool + SetRemoteWorkingDirectory(const lldb_private::FileSpec &working_dir) override; + bool GetRemoteOSVersion() override; bool GetRemoteOSBuildString(std::string &s) override; @@ -65,6 +92,12 @@ bool IsConnected() const override; + lldb_private::Status + RunShellCommand(const char *command, + const lldb_private::FileSpec &working_dir, int *status_ptr, + int *signo_ptr, std::string *command_output, + const lldb_private::Timeout<std::micro> &timeout) override; + lldb_private::Status ConnectRemote(lldb_private::Args &args) override; lldb_private::Status DisconnectRemote() override; @@ -75,6 +108,17 @@ const char *GetGroupName(uint32_t gid) override; + lldb_private::Status MakeDirectory(const lldb_private::FileSpec &file_spec, + uint32_t mode) override; + + lldb_private::Status + GetFilePermissions(const lldb_private::FileSpec &file_spec, + uint32_t &file_permissions) override; + + lldb_private::Status + SetFilePermissions(const lldb_private::FileSpec &file_spec, + uint32_t file_permissions) override; + bool GetProcessInfo(lldb::pid_t pid, lldb_private::ProcessInstanceInfo &proc_info) override; @@ -82,9 +126,17 @@ FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info, lldb_private::ProcessInstanceInfoList &process_infos) override; + lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, + llvm::StringRef plugin_name, + lldb_private::Debugger &debugger, + lldb_private::Target *target, + lldb_private::Status &error) override; + lldb_private::Status LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override; + lldb_private::Status KillProcess(const lldb::pid_t pid) override; + lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info, lldb_private::Debugger &debugger, lldb_private::Target *target, @@ -95,6 +147,9 @@ lldb_private::Target *target, lldb_private::Status &error) override; + bool CalculateMD5(const lldb_private::FileSpec &file_spec, uint64_t &low, + uint64_t &high) override; + lldb_private::Status GetFileWithUUID(const lldb_private::FileSpec &platform_file, const lldb_private::UUID *uuid, Index: source/Plugins/Platform/Windows/PlatformWindows.cpp =================================================================== --- source/Plugins/Platform/Windows/PlatformWindows.cpp +++ source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -21,6 +21,8 @@ #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" #include "lldb/Core/PluginManager.h" +#include "lldb/Host/FileCache.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" #include "lldb/Target/Process.h" #include "lldb/Utility/Status.h" @@ -176,6 +178,23 @@ return Platform::GetModuleSpec(module_file_spec, arch, module_spec); } +lldb_private::Status +PlatformWindows::RunShellCommand(const char *command, + const FileSpec &working_dir, int *status_ptr, + int *signo_ptr, std::string *command_output, + const Timeout<std::micro> &timeout) { + if (IsHost()) + return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr, + command_output, timeout); + else { + if (m_remote_platform_sp) + return m_remote_platform_sp->RunShellCommand( + command, working_dir, status_ptr, signo_ptr, command_output, timeout); + else + return Status("unable to run a remote command without a platform"); + } +} + Status PlatformWindows::ResolveExecutable( const ModuleSpec &ms, lldb::ModuleSP &exe_module_sp, const FileSpecList *module_search_paths_ptr) { @@ -208,8 +227,9 @@ } } else { if (m_remote_platform_sp) { - error = GetCachedExecutable(resolved_module_spec, exe_module_sp, nullptr, - *m_remote_platform_sp); + error = + GetCachedExecutable(resolved_module_spec, exe_module_sp, + module_search_paths_ptr, *m_remote_platform_sp); } else { // We may connect to a process and use the provided executable (Don't use // local $PATH). @@ -244,7 +264,8 @@ idx, resolved_module_spec.GetArchitecture()); ++idx) { error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp, - nullptr, nullptr, nullptr); + module_search_paths_ptr, nullptr, + nullptr); // Did we find an executable using one of the if (error.Success()) { if (exe_module_sp && exe_module_sp->GetObjectFile()) @@ -278,6 +299,126 @@ return error; } +Status PlatformWindows::MakeDirectory(const FileSpec &file_spec, + uint32_t file_permissions) { + if (m_remote_platform_sp) + return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions); + else + return Platform::MakeDirectory(file_spec, file_permissions); +} + +Status PlatformWindows::GetFilePermissions(const FileSpec &file_spec, + uint32_t &file_permissions) { + if (m_remote_platform_sp) + return m_remote_platform_sp->GetFilePermissions(file_spec, + file_permissions); + else + return Platform::GetFilePermissions(file_spec, file_permissions); +} + +Status PlatformWindows::SetFilePermissions(const FileSpec &file_spec, + uint32_t file_permissions) { + if (m_remote_platform_sp) + return m_remote_platform_sp->SetFilePermissions(file_spec, + file_permissions); + else + return Platform::SetFilePermissions(file_spec, file_permissions); +} + +lldb::user_id_t PlatformWindows::OpenFile(const FileSpec &file_spec, + uint32_t flags, uint32_t mode, + Status &error) { + if (IsHost()) + return FileCache::GetInstance().OpenFile(file_spec, flags, mode, error); + else if (m_remote_platform_sp) + return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error); + else + return Platform::OpenFile(file_spec, flags, mode, error); +} + +bool PlatformWindows::CloseFile(lldb::user_id_t fd, Status &error) { + if (IsHost()) + return FileCache::GetInstance().CloseFile(fd, error); + else if (m_remote_platform_sp) + return m_remote_platform_sp->CloseFile(fd, error); + else + return Platform::CloseFile(fd, error); +} + +uint64_t PlatformWindows::ReadFile(lldb::user_id_t fd, uint64_t offset, + void *dst, uint64_t dst_len, Status &error) { + if (IsHost()) + return FileCache::GetInstance().ReadFile(fd, offset, dst, dst_len, error); + else if (m_remote_platform_sp) + return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error); + else + return Platform::ReadFile(fd, offset, dst, dst_len, error); +} + +uint64_t PlatformWindows::WriteFile(lldb::user_id_t fd, uint64_t offset, + const void *src, uint64_t src_len, + Status &error) { + if (IsHost()) + return FileCache::GetInstance().WriteFile(fd, offset, src, src_len, error); + else if (m_remote_platform_sp) + return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error); + else + return Platform::WriteFile(fd, offset, src, src_len, error); +} + +lldb::user_id_t PlatformWindows::GetFileSize(const FileSpec &file_spec) { + if (IsHost()) { + uint64_t Size; + if (llvm::sys::fs::file_size(file_spec.GetPath(), Size)) + return 0; + return Size; + } else if (m_remote_platform_sp) + return m_remote_platform_sp->GetFileSize(file_spec); + else + return Platform::GetFileSize(file_spec); +} + +Status PlatformWindows::CreateSymlink(const FileSpec &src, + const FileSpec &dst) { + if (IsHost()) + return FileSystem::Instance().Symlink(src, dst); + else if (m_remote_platform_sp) + return m_remote_platform_sp->CreateSymlink(src, dst); + else + return Platform::CreateSymlink(src, dst); +} + +bool PlatformWindows::GetFileExists(const FileSpec &file_spec) { + if (IsHost()) + return FileSystem::Instance().Exists(file_spec); + else if (m_remote_platform_sp) + return m_remote_platform_sp->GetFileExists(file_spec); + else + return Platform::GetFileExists(file_spec); +} + +Status PlatformWindows::Unlink(const FileSpec &file_spec) { + if (IsHost()) + return llvm::sys::fs::remove(file_spec.GetPath()); + else if (m_remote_platform_sp) + return m_remote_platform_sp->Unlink(file_spec); + else + return Platform::Unlink(file_spec); +} +FileSpec PlatformWindows::GetRemoteWorkingDirectory() { + if (IsRemote() && m_remote_platform_sp) + return m_remote_platform_sp->GetRemoteWorkingDirectory(); + else + return Platform::GetRemoteWorkingDirectory(); +} + +bool PlatformWindows::SetRemoteWorkingDirectory(const FileSpec &working_dir) { + if (IsRemote() && m_remote_platform_sp) + return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir); + else + return Platform::SetRemoteWorkingDirectory(working_dir); +} + bool PlatformWindows::GetRemoteOSVersion() { if (m_remote_platform_sp) { m_os_version = m_remote_platform_sp->GetOSVersion(); @@ -397,8 +538,21 @@ return match_count; } +lldb::ProcessSP PlatformWindows::ConnectProcess( + llvm::StringRef connect_url, llvm::StringRef plugin_name, + lldb_private::Debugger &debugger, lldb_private::Target *target, + lldb_private::Status &error) { + if (m_remote_platform_sp) + return m_remote_platform_sp->ConnectProcess(connect_url, plugin_name, + debugger, target, error); + + return Platform::ConnectProcess(connect_url, plugin_name, debugger, target, + error); +} + Status PlatformWindows::LaunchProcess(ProcessLaunchInfo &launch_info) { Status error; + if (IsHost()) { error = Platform::LaunchProcess(launch_info); } else { @@ -410,6 +564,16 @@ return error; } +lldb_private::Status PlatformWindows::KillProcess(const lldb::pid_t pid) { + if (IsHost()) + return Platform::KillProcess(pid); + + if (m_remote_platform_sp) + return m_remote_platform_sp->KillProcess(pid); + + return Status("the platform is not currently connected"); +} + ProcessSP PlatformWindows::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, Target *target, Status &error) { @@ -432,6 +596,14 @@ // plugin, and PlatformWindows::DebugProcess is just a pass-through to get to // the process plugin. + if (IsRemote()) { + if (m_remote_platform_sp) + return m_remote_platform_sp->DebugProcess(launch_info, debugger, target, + error); + else + error.SetErrorString("the platform is not currently connected"); + } + if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) { // This is a process attach. Don't need to launch anything. ProcessAttachInfo attach_info(launch_info); @@ -511,6 +683,15 @@ return nullptr; } +bool PlatformWindows::CalculateMD5(const FileSpec &file_spec, uint64_t &low, + uint64_t &high) { + if (IsHost()) + return Platform::CalculateMD5(file_spec, low, high); + if (m_remote_platform_sp) + return m_remote_platform_sp->CalculateMD5(file_spec, low, high); + return false; +} + Status PlatformWindows::GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid_ptr, FileSpec &local_file) { @@ -568,7 +749,7 @@ #ifdef _WIN32 llvm::VersionTuple version = HostInfo::GetOSVersion(); - strm << "Host: Windows " << version.getAsString() << '\n'; + strm << " Host: Windows " << version.getAsString() << '\n'; #endif }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits