LLDB mainline
RemoteAwarePlatform.cpp
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Core/Module.h"
14#include "lldb/Host/Host.h"
15#include "lldb/Host/HostInfo.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) {
26 return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,
27 module_spec);
28
29 return false;
30}
31
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))
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
56 llvm::StringRef command, const FileSpec &working_dir, int *status_ptr,
57 int *signo_ptr, std::string *command_output,
58 std::string *separated_error_output, const Timeout<std::micro> &timeout) {
59 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
60 signo_ptr, command_output, separated_error_output,
61 timeout);
62}
63
65 llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir,
66 int *status_ptr, int *signo_ptr, std::string *command_output,
67 std::string *separated_error_output, const Timeout<std::micro> &timeout) {
69 return m_remote_platform_sp->RunShellCommand(
70 shell, command, working_dir, status_ptr, signo_ptr, command_output,
71 separated_error_output, timeout);
72 return Platform::RunShellCommand(shell, command, working_dir, status_ptr,
73 signo_ptr, command_output,
74 separated_error_output, timeout);
75}
76
78 uint32_t file_permissions) {
80 return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions);
81 return Platform::MakeDirectory(file_spec, file_permissions);
82}
83
85 uint32_t &file_permissions) {
87 return m_remote_platform_sp->GetFilePermissions(file_spec,
88 file_permissions);
89 return Platform::GetFilePermissions(file_spec, file_permissions);
90}
91
93 uint32_t file_permissions) {
95 return m_remote_platform_sp->SetFilePermissions(file_spec,
96 file_permissions);
97 return Platform::SetFilePermissions(file_spec, file_permissions);
98}
99
101 File::OpenOptions flags,
102 uint32_t mode, Status &error) {
104 return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error);
105 return Platform::OpenFile(file_spec, flags, mode, error);
106}
107
113
115 void *dst, uint64_t dst_len,
116 Status &error) {
118 return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error);
119 return Platform::ReadFile(fd, offset, dst, dst_len, error);
120}
121
123 const void *src, uint64_t src_len,
124 Status &error) {
126 return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error);
127 return Platform::WriteFile(fd, offset, src, src_len, error);
128}
129
132 return m_remote_platform_sp->GetFileSize(file_spec);
133 return Platform::GetFileSize(file_spec);
134}
135
137 const FileSpec &dst) {
139 return m_remote_platform_sp->CreateSymlink(src, dst);
140 return Platform::CreateSymlink(src, dst);
141}
142
145 return m_remote_platform_sp->GetFileExists(file_spec);
146 return Platform::GetFileExists(file_spec);
147}
148
151 return m_remote_platform_sp->Unlink(file_spec);
152 return Platform::Unlink(file_spec);
153}
154
155llvm::ErrorOr<llvm::MD5::MD5Result>
158 return m_remote_platform_sp->CalculateMD5(file_spec);
159 return Platform::CalculateMD5(file_spec);
160}
161
167
169 const FileSpec &working_dir) {
171 return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir);
172 return Platform::SetRemoteWorkingDirectory(working_dir);
173}
174
176 const UUID *uuid_ptr,
177 FileSpec &local_file) {
179 return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
180 local_file);
181
182 // Default to the local case
183 local_file = platform_file;
184 return Status();
185}
186
189 m_os_version = m_remote_platform_sp->GetOSVersion();
190 return !m_os_version.empty();
191 }
192 return false;
193}
194
197 return m_remote_platform_sp->GetRemoteOSBuildString();
198 return std::nullopt;
199}
200
203 return m_remote_platform_sp->GetRemoteOSKernelDescription();
204 return std::nullopt;
205}
206
209 return m_remote_platform_sp->GetRemoteSystemArchitecture();
210 return ArchSpec();
211}
212
215 return m_remote_platform_sp->GetHostname();
216 return Platform::GetHostname();
217}
218
224
230
233 return m_remote_platform_sp->IsConnected();
234 return Platform::IsConnected();
235}
236
238 ProcessInstanceInfo &process_info) {
240 return m_remote_platform_sp->GetProcessInfo(pid, process_info);
241 return Platform::GetProcessInfo(pid, process_info);
242}
243
244uint32_t
246 ProcessInstanceInfoList &process_infos) {
248 return m_remote_platform_sp->FindProcesses(match_info, process_infos);
249 return Platform::FindProcesses(match_info, process_infos);
250}
251
253 llvm::StringRef plugin_name,
254 Debugger &debugger,
255 Target *target,
256 Status &error) {
258 return m_remote_platform_sp->ConnectProcess(connect_url, plugin_name,
259 debugger, target, error);
260 return Platform::ConnectProcess(connect_url, plugin_name, debugger, target,
261 error);
262}
263
266 return m_remote_platform_sp->LaunchProcess(launch_info);
267 return Platform::LaunchProcess(launch_info);
268}
269
272 return m_remote_platform_sp->KillProcess(pid);
273 return Platform::KillProcess(pid);
274}
275
277 Status &error) {
279 return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error);
281}
static llvm::raw_ostream & error(Stream &strm)
An architecture specification class.
Definition ArchSpec.h:32
A class to manage flag bits.
Definition Debugger.h:87
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
virtual FileSpec GetRemoteWorkingDirectory()
Definition Platform.h:238
virtual bool GetFileExists(const lldb_private::FileSpec &file_spec)
virtual bool CloseFile(lldb::user_id_t fd, Status &error)
Definition Platform.cpp:648
virtual bool IsConnected() const
Definition Platform.h:511
virtual lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error)
Definition Platform.cpp:640
virtual const char * GetHostname()
Definition Platform.cpp:690
virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
Attach to an existing process by process name.
Definition Platform.cpp:911
llvm::VersionTuple m_os_version
Definition Platform.h:1016
virtual Status ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp)
Set the target's executable based off of the existing architecture information in target given a path...
Definition Platform.cpp:733
virtual Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions)
Definition Platform.cpp:610
virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions)
Definition Platform.cpp:597
virtual UserIDResolver & GetUserIDResolver()
Definition Platform.cpp:684
virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec)
Definition Platform.cpp:654
virtual Status Unlink(const FileSpec &file_spec)
virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir)
Definition Platform.cpp:703
Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp)
virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Target *target, Status &error)
virtual Status LaunchProcess(ProcessLaunchInfo &launch_info)
Launch a new process on a platform, not necessarily for debugging, it could be just for running the p...
Definition Platform.cpp:929
virtual Status KillProcess(const lldb::pid_t pid)
Kill process on a platform.
Definition Platform.cpp:985
virtual Status CreateSymlink(const FileSpec &src, const FileSpec &dst)
virtual size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, lldb_private::Status &error)
Connect to all processes waiting for a debugger to attach.
virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error)
Definition Platform.cpp:674
bool IsRemote() const
Definition Platform.h:509
virtual Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions)
Definition Platform.cpp:626
virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition Platform.cpp:902
bool IsHost() const
Definition Platform.h:505
virtual Environment GetEnvironment()
virtual lldb_private::Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, std::string *separated_error_output, const Timeout< std::micro > &timeout)
virtual llvm::ErrorOr< llvm::MD5::MD5Result > CalculateMD5(const FileSpec &file_spec)
virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error)
Definition Platform.cpp:664
size_t ConnectToWaitingProcesses(Debugger &debugger, Status &error) override
Connect to all processes waiting for a debugger to attach.
virtual Status ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp) override
Set the target's executable based off of the existing architecture information in target given a path...
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error) override
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error) override
bool CloseFile(lldb::user_id_t fd, Status &error) override
Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid, FileSpec &local_file) override
Locate a file for a platform.
std::optional< std::string > GetRemoteOSBuildString() override
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override
llvm::ErrorOr< llvm::MD5::MD5Result > CalculateMD5(const FileSpec &file_spec) override
Status KillProcess(const lldb::pid_t pid) override
Kill process on a platform.
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override
bool GetFileExists(const FileSpec &file_spec) override
std::optional< std::string > GetRemoteOSKernelDescription() override
Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override
lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Target *target, Status &error) override
Status MakeDirectory(const FileSpec &file_spec, uint32_t mode) override
lldb_private::Environment GetEnvironment() override
lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error) override
Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, std::string *separated_error_output, const Timeout< std::micro > &timeout) override
Status LaunchProcess(ProcessLaunchInfo &launch_info) override
Launch a new process on a platform, not necessarily for debugging, it could be just for running the p...
Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override
lldb::user_id_t GetFileSize(const FileSpec &file_spec) override
bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override
Status Unlink(const FileSpec &file_spec) override
Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override
UserIDResolver & GetUserIDResolver() override
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) override
Attach to an existing process by process name.
An error handling class.
Definition Status.h:118
Represents UUID's of various sizes.
Definition UUID.h:27
An abstract interface for things that know how to map numeric user/group IDs into names.
A class that represents a running process on the host machine.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition Host.h:32
std::shared_ptr< lldb_private::Process > ProcessSP
uint64_t pid_t
Definition lldb-types.h:83
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::Module > ModuleSP