280 lines · cpp
1//===-- RemoteAwarePlatform.cpp -------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Target/RemoteAwarePlatform.h"10#include "lldb/Core/Module.h"11#include "lldb/Core/ModuleList.h"12#include "lldb/Core/ModuleSpec.h"13#include "lldb/Host/FileSystem.h"14#include "lldb/Host/Host.h"15#include "lldb/Host/HostInfo.h"16#include "lldb/Utility/StreamString.h"17#include <optional>18 19using namespace lldb_private;20using namespace lldb;21 22bool RemoteAwarePlatform::GetModuleSpec(const FileSpec &module_file_spec,23 const ArchSpec &arch,24 ModuleSpec &module_spec) {25 if (m_remote_platform_sp)26 return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,27 module_spec);28 29 return false;30}31 32Status RemoteAwarePlatform::ResolveExecutable(const ModuleSpec &module_spec,33 lldb::ModuleSP &exe_module_sp) {34 ModuleSpec resolved_module_spec(module_spec);35 36 // The host platform can resolve the path more aggressively.37 if (IsHost()) {38 FileSpec &resolved_file_spec = resolved_module_spec.GetFileSpec();39 40 if (!FileSystem::Instance().Exists(resolved_file_spec)) {41 resolved_module_spec.GetFileSpec().SetFile(resolved_file_spec.GetPath(),42 FileSpec::Style::native);43 FileSystem::Instance().Resolve(resolved_file_spec);44 }45 46 if (!FileSystem::Instance().Exists(resolved_file_spec))47 FileSystem::Instance().ResolveExecutableLocation(resolved_file_spec);48 } else if (m_remote_platform_sp) {49 return GetCachedExecutable(resolved_module_spec, exe_module_sp);50 }51 52 return Platform::ResolveExecutable(resolved_module_spec, exe_module_sp);53}54 55Status RemoteAwarePlatform::RunShellCommand(56 llvm::StringRef command, const FileSpec &working_dir, int *status_ptr,57 int *signo_ptr, std::string *command_output,58 const Timeout<std::micro> &timeout) {59 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,60 signo_ptr, command_output, timeout);61}62 63Status RemoteAwarePlatform::RunShellCommand(64 llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir,65 int *status_ptr, int *signo_ptr, std::string *command_output,66 const Timeout<std::micro> &timeout) {67 if (m_remote_platform_sp)68 return m_remote_platform_sp->RunShellCommand(shell, command, working_dir,69 status_ptr, signo_ptr,70 command_output, timeout);71 return Platform::RunShellCommand(shell, command, working_dir, status_ptr,72 signo_ptr, command_output, timeout);73}74 75Status RemoteAwarePlatform::MakeDirectory(const FileSpec &file_spec,76 uint32_t file_permissions) {77 if (m_remote_platform_sp)78 return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions);79 return Platform::MakeDirectory(file_spec, file_permissions);80}81 82Status RemoteAwarePlatform::GetFilePermissions(const FileSpec &file_spec,83 uint32_t &file_permissions) {84 if (m_remote_platform_sp)85 return m_remote_platform_sp->GetFilePermissions(file_spec,86 file_permissions);87 return Platform::GetFilePermissions(file_spec, file_permissions);88}89 90Status RemoteAwarePlatform::SetFilePermissions(const FileSpec &file_spec,91 uint32_t file_permissions) {92 if (m_remote_platform_sp)93 return m_remote_platform_sp->SetFilePermissions(file_spec,94 file_permissions);95 return Platform::SetFilePermissions(file_spec, file_permissions);96}97 98lldb::user_id_t RemoteAwarePlatform::OpenFile(const FileSpec &file_spec,99 File::OpenOptions flags,100 uint32_t mode, Status &error) {101 if (m_remote_platform_sp)102 return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error);103 return Platform::OpenFile(file_spec, flags, mode, error);104}105 106bool RemoteAwarePlatform::CloseFile(lldb::user_id_t fd, Status &error) {107 if (m_remote_platform_sp)108 return m_remote_platform_sp->CloseFile(fd, error);109 return Platform::CloseFile(fd, error);110}111 112uint64_t RemoteAwarePlatform::ReadFile(lldb::user_id_t fd, uint64_t offset,113 void *dst, uint64_t dst_len,114 Status &error) {115 if (m_remote_platform_sp)116 return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error);117 return Platform::ReadFile(fd, offset, dst, dst_len, error);118}119 120uint64_t RemoteAwarePlatform::WriteFile(lldb::user_id_t fd, uint64_t offset,121 const void *src, uint64_t src_len,122 Status &error) {123 if (m_remote_platform_sp)124 return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error);125 return Platform::WriteFile(fd, offset, src, src_len, error);126}127 128lldb::user_id_t RemoteAwarePlatform::GetFileSize(const FileSpec &file_spec) {129 if (m_remote_platform_sp)130 return m_remote_platform_sp->GetFileSize(file_spec);131 return Platform::GetFileSize(file_spec);132}133 134Status RemoteAwarePlatform::CreateSymlink(const FileSpec &src,135 const FileSpec &dst) {136 if (m_remote_platform_sp)137 return m_remote_platform_sp->CreateSymlink(src, dst);138 return Platform::CreateSymlink(src, dst);139}140 141bool RemoteAwarePlatform::GetFileExists(const FileSpec &file_spec) {142 if (m_remote_platform_sp)143 return m_remote_platform_sp->GetFileExists(file_spec);144 return Platform::GetFileExists(file_spec);145}146 147Status RemoteAwarePlatform::Unlink(const FileSpec &file_spec) {148 if (m_remote_platform_sp)149 return m_remote_platform_sp->Unlink(file_spec);150 return Platform::Unlink(file_spec);151}152 153llvm::ErrorOr<llvm::MD5::MD5Result>154RemoteAwarePlatform::CalculateMD5(const FileSpec &file_spec) {155 if (m_remote_platform_sp)156 return m_remote_platform_sp->CalculateMD5(file_spec);157 return Platform::CalculateMD5(file_spec);158}159 160FileSpec RemoteAwarePlatform::GetRemoteWorkingDirectory() {161 if (IsRemote() && m_remote_platform_sp)162 return m_remote_platform_sp->GetRemoteWorkingDirectory();163 return Platform::GetRemoteWorkingDirectory();164}165 166bool RemoteAwarePlatform::SetRemoteWorkingDirectory(167 const FileSpec &working_dir) {168 if (IsRemote() && m_remote_platform_sp)169 return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir);170 return Platform::SetRemoteWorkingDirectory(working_dir);171}172 173Status RemoteAwarePlatform::GetFileWithUUID(const FileSpec &platform_file,174 const UUID *uuid_ptr,175 FileSpec &local_file) {176 if (IsRemote() && m_remote_platform_sp)177 return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,178 local_file);179 180 // Default to the local case181 local_file = platform_file;182 return Status();183}184 185bool RemoteAwarePlatform::GetRemoteOSVersion() {186 if (m_remote_platform_sp) {187 m_os_version = m_remote_platform_sp->GetOSVersion();188 return !m_os_version.empty();189 }190 return false;191}192 193std::optional<std::string> RemoteAwarePlatform::GetRemoteOSBuildString() {194 if (m_remote_platform_sp)195 return m_remote_platform_sp->GetRemoteOSBuildString();196 return std::nullopt;197}198 199std::optional<std::string> RemoteAwarePlatform::GetRemoteOSKernelDescription() {200 if (m_remote_platform_sp)201 return m_remote_platform_sp->GetRemoteOSKernelDescription();202 return std::nullopt;203}204 205ArchSpec RemoteAwarePlatform::GetRemoteSystemArchitecture() {206 if (m_remote_platform_sp)207 return m_remote_platform_sp->GetRemoteSystemArchitecture();208 return ArchSpec();209}210 211const char *RemoteAwarePlatform::GetHostname() {212 if (m_remote_platform_sp)213 return m_remote_platform_sp->GetHostname();214 return Platform::GetHostname();215}216 217UserIDResolver &RemoteAwarePlatform::GetUserIDResolver() {218 if (m_remote_platform_sp)219 return m_remote_platform_sp->GetUserIDResolver();220 return Platform::GetUserIDResolver();221}222 223Environment RemoteAwarePlatform::GetEnvironment() {224 if (m_remote_platform_sp)225 return m_remote_platform_sp->GetEnvironment();226 return Platform::GetEnvironment();227}228 229bool RemoteAwarePlatform::IsConnected() const {230 if (m_remote_platform_sp)231 return m_remote_platform_sp->IsConnected();232 return Platform::IsConnected();233}234 235bool RemoteAwarePlatform::GetProcessInfo(lldb::pid_t pid,236 ProcessInstanceInfo &process_info) {237 if (m_remote_platform_sp)238 return m_remote_platform_sp->GetProcessInfo(pid, process_info);239 return Platform::GetProcessInfo(pid, process_info);240}241 242uint32_t243RemoteAwarePlatform::FindProcesses(const ProcessInstanceInfoMatch &match_info,244 ProcessInstanceInfoList &process_infos) {245 if (m_remote_platform_sp)246 return m_remote_platform_sp->FindProcesses(match_info, process_infos);247 return Platform::FindProcesses(match_info, process_infos);248}249 250lldb::ProcessSP RemoteAwarePlatform::ConnectProcess(llvm::StringRef connect_url,251 llvm::StringRef plugin_name,252 Debugger &debugger,253 Target *target,254 Status &error) {255 if (m_remote_platform_sp)256 return m_remote_platform_sp->ConnectProcess(connect_url, plugin_name,257 debugger, target, error);258 return Platform::ConnectProcess(connect_url, plugin_name, debugger, target,259 error);260}261 262Status RemoteAwarePlatform::LaunchProcess(ProcessLaunchInfo &launch_info) {263 if (m_remote_platform_sp)264 return m_remote_platform_sp->LaunchProcess(launch_info);265 return Platform::LaunchProcess(launch_info);266}267 268Status RemoteAwarePlatform::KillProcess(const lldb::pid_t pid) {269 if (m_remote_platform_sp)270 return m_remote_platform_sp->KillProcess(pid);271 return Platform::KillProcess(pid);272}273 274size_t RemoteAwarePlatform::ConnectToWaitingProcesses(Debugger &debugger,275 Status &error) {276 if (m_remote_platform_sp)277 return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error);278 return Platform::ConnectToWaitingProcesses(debugger, error);279}280