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 const Timeout<std::micro> &timeout) {
59 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
60 signo_ptr, command_output, timeout);
61}
62
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) {
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
76 uint32_t file_permissions) {
78 return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions);
79 return Platform::MakeDirectory(file_spec, file_permissions);
80}
81
83 uint32_t &file_permissions) {
85 return m_remote_platform_sp->GetFilePermissions(file_spec,
86 file_permissions);
87 return Platform::GetFilePermissions(file_spec, file_permissions);
88}
89
91 uint32_t file_permissions) {
93 return m_remote_platform_sp->SetFilePermissions(file_spec,
94 file_permissions);
95 return Platform::SetFilePermissions(file_spec, file_permissions);
96}
97
100 uint32_t mode, Status &error) {
102 return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error);
103 return Platform::OpenFile(file_spec, flags, mode, error);
104}
105
111
113 void *dst, uint64_t dst_len,
114 Status &error) {
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
121 const void *src, uint64_t src_len,
122 Status &error) {
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
130 return m_remote_platform_sp->GetFileSize(file_spec);
131 return Platform::GetFileSize(file_spec);
132}
133
135 const FileSpec &dst) {
137 return m_remote_platform_sp->CreateSymlink(src, dst);
138 return Platform::CreateSymlink(src, dst);
139}
140
143 return m_remote_platform_sp->GetFileExists(file_spec);
144 return Platform::GetFileExists(file_spec);
145}
146
149 return m_remote_platform_sp->Unlink(file_spec);
150 return Platform::Unlink(file_spec);
151}
152
153llvm::ErrorOr<llvm::MD5::MD5Result>
156 return m_remote_platform_sp->CalculateMD5(file_spec);
157 return Platform::CalculateMD5(file_spec);
158}
159
165
167 const FileSpec &working_dir) {
169 return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir);
170 return Platform::SetRemoteWorkingDirectory(working_dir);
171}
172
174 const UUID *uuid_ptr,
175 FileSpec &local_file) {
177 return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
178 local_file);
179
180 // Default to the local case
181 local_file = platform_file;
182 return Status();
183}
184
187 m_os_version = m_remote_platform_sp->GetOSVersion();
188 return !m_os_version.empty();
189 }
190 return false;
191}
192
195 return m_remote_platform_sp->GetRemoteOSBuildString();
196 return std::nullopt;
197}
198
201 return m_remote_platform_sp->GetRemoteOSKernelDescription();
202 return std::nullopt;
203}
204
207 return m_remote_platform_sp->GetRemoteSystemArchitecture();
208 return ArchSpec();
209}
210
213 return m_remote_platform_sp->GetHostname();
214 return Platform::GetHostname();
215}
216
222
228
231 return m_remote_platform_sp->IsConnected();
232 return Platform::IsConnected();
233}
234
236 ProcessInstanceInfo &process_info) {
238 return m_remote_platform_sp->GetProcessInfo(pid, process_info);
239 return Platform::GetProcessInfo(pid, process_info);
240}
241
242uint32_t
244 ProcessInstanceInfoList &process_infos) {
246 return m_remote_platform_sp->FindProcesses(match_info, process_infos);
247 return Platform::FindProcesses(match_info, process_infos);
248}
249
251 llvm::StringRef plugin_name,
252 Debugger &debugger,
253 Target *target,
254 Status &error) {
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
264 return m_remote_platform_sp->LaunchProcess(launch_info);
265 return Platform::LaunchProcess(launch_info);
266}
267
270 return m_remote_platform_sp->KillProcess(pid);
271 return Platform::KillProcess(pid);
272}
273
275 Status &error) {
277 return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error);
279}
static llvm::raw_ostream & error(Stream &strm)
An architecture specification class.
Definition ArchSpec.h:31
A class to manage flag bits.
Definition Debugger.h:80
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
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
static FileSystem & Instance()
FileSpec & GetFileSpec()
Definition ModuleSpec.h:55
virtual FileSpec GetRemoteWorkingDirectory()
Definition Platform.h:237
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:509
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:1008
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:507
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:503
virtual lldb_private::Status RunShellCommand(llvm::StringRef command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const Timeout< std::micro > &timeout)
virtual Environment GetEnvironment()
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, 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