Path: blob/main/contrib/llvm-project/lldb/source/Target/RemoteAwarePlatform.cpp
39587 views
//===-- RemoteAwarePlatform.cpp -------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Target/RemoteAwarePlatform.h"9#include "lldb/Core/Module.h"10#include "lldb/Core/ModuleList.h"11#include "lldb/Core/ModuleSpec.h"12#include "lldb/Host/FileSystem.h"13#include "lldb/Host/Host.h"14#include "lldb/Host/HostInfo.h"15#include "lldb/Utility/StreamString.h"16#include <optional>1718using namespace lldb_private;19using namespace lldb;2021bool RemoteAwarePlatform::GetModuleSpec(const FileSpec &module_file_spec,22const ArchSpec &arch,23ModuleSpec &module_spec) {24if (m_remote_platform_sp)25return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,26module_spec);2728return false;29}3031Status RemoteAwarePlatform::ResolveExecutable(32const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp,33const FileSpecList *module_search_paths_ptr) {34ModuleSpec resolved_module_spec(module_spec);3536// The host platform can resolve the path more aggressively.37if (IsHost()) {38FileSpec &resolved_file_spec = resolved_module_spec.GetFileSpec();3940if (!FileSystem::Instance().Exists(resolved_file_spec)) {41resolved_module_spec.GetFileSpec().SetFile(resolved_file_spec.GetPath(),42FileSpec::Style::native);43FileSystem::Instance().Resolve(resolved_file_spec);44}4546if (!FileSystem::Instance().Exists(resolved_file_spec))47FileSystem::Instance().ResolveExecutableLocation(resolved_file_spec);48} else if (m_remote_platform_sp) {49return GetCachedExecutable(resolved_module_spec, exe_module_sp,50module_search_paths_ptr);51}5253return Platform::ResolveExecutable(resolved_module_spec, exe_module_sp,54module_search_paths_ptr);55}5657Status RemoteAwarePlatform::RunShellCommand(58llvm::StringRef command, const FileSpec &working_dir, int *status_ptr,59int *signo_ptr, std::string *command_output,60const Timeout<std::micro> &timeout) {61return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,62signo_ptr, command_output, timeout);63}6465Status RemoteAwarePlatform::RunShellCommand(66llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir,67int *status_ptr, int *signo_ptr, std::string *command_output,68const Timeout<std::micro> &timeout) {69if (m_remote_platform_sp)70return m_remote_platform_sp->RunShellCommand(shell, command, working_dir,71status_ptr, signo_ptr,72command_output, timeout);73return Platform::RunShellCommand(shell, command, working_dir, status_ptr,74signo_ptr, command_output, timeout);75}7677Status RemoteAwarePlatform::MakeDirectory(const FileSpec &file_spec,78uint32_t file_permissions) {79if (m_remote_platform_sp)80return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions);81return Platform::MakeDirectory(file_spec, file_permissions);82}8384Status RemoteAwarePlatform::GetFilePermissions(const FileSpec &file_spec,85uint32_t &file_permissions) {86if (m_remote_platform_sp)87return m_remote_platform_sp->GetFilePermissions(file_spec,88file_permissions);89return Platform::GetFilePermissions(file_spec, file_permissions);90}9192Status RemoteAwarePlatform::SetFilePermissions(const FileSpec &file_spec,93uint32_t file_permissions) {94if (m_remote_platform_sp)95return m_remote_platform_sp->SetFilePermissions(file_spec,96file_permissions);97return Platform::SetFilePermissions(file_spec, file_permissions);98}99100lldb::user_id_t RemoteAwarePlatform::OpenFile(const FileSpec &file_spec,101File::OpenOptions flags,102uint32_t mode, Status &error) {103if (m_remote_platform_sp)104return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error);105return Platform::OpenFile(file_spec, flags, mode, error);106}107108bool RemoteAwarePlatform::CloseFile(lldb::user_id_t fd, Status &error) {109if (m_remote_platform_sp)110return m_remote_platform_sp->CloseFile(fd, error);111return Platform::CloseFile(fd, error);112}113114uint64_t RemoteAwarePlatform::ReadFile(lldb::user_id_t fd, uint64_t offset,115void *dst, uint64_t dst_len,116Status &error) {117if (m_remote_platform_sp)118return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error);119return Platform::ReadFile(fd, offset, dst, dst_len, error);120}121122uint64_t RemoteAwarePlatform::WriteFile(lldb::user_id_t fd, uint64_t offset,123const void *src, uint64_t src_len,124Status &error) {125if (m_remote_platform_sp)126return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error);127return Platform::WriteFile(fd, offset, src, src_len, error);128}129130lldb::user_id_t RemoteAwarePlatform::GetFileSize(const FileSpec &file_spec) {131if (m_remote_platform_sp)132return m_remote_platform_sp->GetFileSize(file_spec);133return Platform::GetFileSize(file_spec);134}135136Status RemoteAwarePlatform::CreateSymlink(const FileSpec &src,137const FileSpec &dst) {138if (m_remote_platform_sp)139return m_remote_platform_sp->CreateSymlink(src, dst);140return Platform::CreateSymlink(src, dst);141}142143bool RemoteAwarePlatform::GetFileExists(const FileSpec &file_spec) {144if (m_remote_platform_sp)145return m_remote_platform_sp->GetFileExists(file_spec);146return Platform::GetFileExists(file_spec);147}148149Status RemoteAwarePlatform::Unlink(const FileSpec &file_spec) {150if (m_remote_platform_sp)151return m_remote_platform_sp->Unlink(file_spec);152return Platform::Unlink(file_spec);153}154155llvm::ErrorOr<llvm::MD5::MD5Result>156RemoteAwarePlatform::CalculateMD5(const FileSpec &file_spec) {157if (m_remote_platform_sp)158return m_remote_platform_sp->CalculateMD5(file_spec);159return Platform::CalculateMD5(file_spec);160}161162FileSpec RemoteAwarePlatform::GetRemoteWorkingDirectory() {163if (IsRemote() && m_remote_platform_sp)164return m_remote_platform_sp->GetRemoteWorkingDirectory();165return Platform::GetRemoteWorkingDirectory();166}167168bool RemoteAwarePlatform::SetRemoteWorkingDirectory(169const FileSpec &working_dir) {170if (IsRemote() && m_remote_platform_sp)171return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir);172return Platform::SetRemoteWorkingDirectory(working_dir);173}174175Status RemoteAwarePlatform::GetFileWithUUID(const FileSpec &platform_file,176const UUID *uuid_ptr,177FileSpec &local_file) {178if (IsRemote() && m_remote_platform_sp)179return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,180local_file);181182// Default to the local case183local_file = platform_file;184return Status();185}186187bool RemoteAwarePlatform::GetRemoteOSVersion() {188if (m_remote_platform_sp) {189m_os_version = m_remote_platform_sp->GetOSVersion();190return !m_os_version.empty();191}192return false;193}194195std::optional<std::string> RemoteAwarePlatform::GetRemoteOSBuildString() {196if (m_remote_platform_sp)197return m_remote_platform_sp->GetRemoteOSBuildString();198return std::nullopt;199}200201std::optional<std::string> RemoteAwarePlatform::GetRemoteOSKernelDescription() {202if (m_remote_platform_sp)203return m_remote_platform_sp->GetRemoteOSKernelDescription();204return std::nullopt;205}206207ArchSpec RemoteAwarePlatform::GetRemoteSystemArchitecture() {208if (m_remote_platform_sp)209return m_remote_platform_sp->GetRemoteSystemArchitecture();210return ArchSpec();211}212213const char *RemoteAwarePlatform::GetHostname() {214if (m_remote_platform_sp)215return m_remote_platform_sp->GetHostname();216return Platform::GetHostname();217}218219UserIDResolver &RemoteAwarePlatform::GetUserIDResolver() {220if (m_remote_platform_sp)221return m_remote_platform_sp->GetUserIDResolver();222return Platform::GetUserIDResolver();223}224225Environment RemoteAwarePlatform::GetEnvironment() {226if (m_remote_platform_sp)227return m_remote_platform_sp->GetEnvironment();228return Platform::GetEnvironment();229}230231bool RemoteAwarePlatform::IsConnected() const {232if (m_remote_platform_sp)233return m_remote_platform_sp->IsConnected();234return Platform::IsConnected();235}236237bool RemoteAwarePlatform::GetProcessInfo(lldb::pid_t pid,238ProcessInstanceInfo &process_info) {239if (m_remote_platform_sp)240return m_remote_platform_sp->GetProcessInfo(pid, process_info);241return Platform::GetProcessInfo(pid, process_info);242}243244uint32_t245RemoteAwarePlatform::FindProcesses(const ProcessInstanceInfoMatch &match_info,246ProcessInstanceInfoList &process_infos) {247if (m_remote_platform_sp)248return m_remote_platform_sp->FindProcesses(match_info, process_infos);249return Platform::FindProcesses(match_info, process_infos);250}251252lldb::ProcessSP RemoteAwarePlatform::ConnectProcess(llvm::StringRef connect_url,253llvm::StringRef plugin_name,254Debugger &debugger,255Target *target,256Status &error) {257if (m_remote_platform_sp)258return m_remote_platform_sp->ConnectProcess(connect_url, plugin_name,259debugger, target, error);260return Platform::ConnectProcess(connect_url, plugin_name, debugger, target,261error);262}263264Status RemoteAwarePlatform::LaunchProcess(ProcessLaunchInfo &launch_info) {265if (m_remote_platform_sp)266return m_remote_platform_sp->LaunchProcess(launch_info);267return Platform::LaunchProcess(launch_info);268}269270Status RemoteAwarePlatform::KillProcess(const lldb::pid_t pid) {271if (m_remote_platform_sp)272return m_remote_platform_sp->KillProcess(pid);273return Platform::KillProcess(pid);274}275276size_t RemoteAwarePlatform::ConnectToWaitingProcesses(Debugger &debugger,277Status &error) {278if (m_remote_platform_sp)279return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error);280return Platform::ConnectToWaitingProcesses(debugger, error);281}282283284