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 const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp,
34 const FileSpecList *module_search_paths_ptr) {
35 ModuleSpec resolved_module_spec(module_spec);
36
37 // The host platform can resolve the path more aggressively.
38 if (IsHost()) {
39 FileSpec &resolved_file_spec = resolved_module_spec.GetFileSpec();
40
41 if (!FileSystem::Instance().Exists(resolved_file_spec)) {
42 resolved_module_spec.GetFileSpec().SetFile(resolved_file_spec.GetPath(),
43 FileSpec::Style::native);
44 FileSystem::Instance().Resolve(resolved_file_spec);
45 }
46
47 if (!FileSystem::Instance().Exists(resolved_file_spec))
49 } else if (m_remote_platform_sp) {
50 return GetCachedExecutable(resolved_module_spec, exe_module_sp,
51 module_search_paths_ptr);
52 }
53
54 return Platform::ResolveExecutable(resolved_module_spec, exe_module_sp,
55 module_search_paths_ptr);
56}
57
59 llvm::StringRef command, const FileSpec &working_dir, int *status_ptr,
60 int *signo_ptr, std::string *command_output,
61 const Timeout<std::micro> &timeout) {
62 return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
63 signo_ptr, command_output, timeout);
64}
65
67 llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir,
68 int *status_ptr, int *signo_ptr, std::string *command_output,
69 const Timeout<std::micro> &timeout) {
71 return m_remote_platform_sp->RunShellCommand(shell, command, working_dir,
72 status_ptr, signo_ptr,
73 command_output, timeout);
74 return Platform::RunShellCommand(shell, command, working_dir, status_ptr,
75 signo_ptr, command_output, timeout);
76}
77
79 uint32_t file_permissions) {
81 return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions);
82 return Platform::MakeDirectory(file_spec, file_permissions);
83}
84
86 uint32_t &file_permissions) {
88 return m_remote_platform_sp->GetFilePermissions(file_spec,
89 file_permissions);
90 return Platform::GetFilePermissions(file_spec, file_permissions);
91}
92
94 uint32_t file_permissions) {
96 return m_remote_platform_sp->SetFilePermissions(file_spec,
97 file_permissions);
98 return Platform::SetFilePermissions(file_spec, file_permissions);
99}
100
102 File::OpenOptions flags,
103 uint32_t mode, Status &error) {
105 return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error);
106 return Platform::OpenFile(file_spec, flags, mode, error);
107}
108
111 return m_remote_platform_sp->CloseFile(fd, error);
112 return Platform::CloseFile(fd, error);
113}
114
116 void *dst, uint64_t dst_len,
117 Status &error) {
119 return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error);
120 return Platform::ReadFile(fd, offset, dst, dst_len, error);
121}
122
124 const void *src, uint64_t src_len,
125 Status &error) {
127 return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error);
128 return Platform::WriteFile(fd, offset, src, src_len, error);
129}
130
133 return m_remote_platform_sp->GetFileSize(file_spec);
134 return Platform::GetFileSize(file_spec);
135}
136
138 const FileSpec &dst) {
140 return m_remote_platform_sp->CreateSymlink(src, dst);
141 return Platform::CreateSymlink(src, dst);
142}
143
146 return m_remote_platform_sp->GetFileExists(file_spec);
147 return Platform::GetFileExists(file_spec);
148}
149
152 return m_remote_platform_sp->Unlink(file_spec);
153 return Platform::Unlink(file_spec);
154}
155
156llvm::ErrorOr<llvm::MD5::MD5Result>
159 return m_remote_platform_sp->CalculateMD5(file_spec);
160 return Platform::CalculateMD5(file_spec);
161}
162
165 return m_remote_platform_sp->GetRemoteWorkingDirectory();
167}
168
170 const FileSpec &working_dir) {
172 return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir);
173 return Platform::SetRemoteWorkingDirectory(working_dir);
174}
175
177 const UUID *uuid_ptr,
178 FileSpec &local_file) {
180 return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
181 local_file);
182
183 // Default to the local case
184 local_file = platform_file;
185 return Status();
186}
187
190 m_os_version = m_remote_platform_sp->GetOSVersion();
191 return !m_os_version.empty();
192 }
193 return false;
194}
195
198 return m_remote_platform_sp->GetRemoteOSBuildString();
199 return std::nullopt;
200}
201
204 return m_remote_platform_sp->GetRemoteOSKernelDescription();
205 return std::nullopt;
206}
207
210 return m_remote_platform_sp->GetRemoteSystemArchitecture();
211 return ArchSpec();
212}
213
216 return m_remote_platform_sp->GetHostname();
217 return Platform::GetHostname();
218}
219
222 return m_remote_platform_sp->GetUserIDResolver();
224}
225
228 return m_remote_platform_sp->GetEnvironment();
230}
231
234 return m_remote_platform_sp->IsConnected();
235 return Platform::IsConnected();
236}
237
239 ProcessInstanceInfo &process_info) {
241 return m_remote_platform_sp->GetProcessInfo(pid, process_info);
242 return Platform::GetProcessInfo(pid, process_info);
243}
244
245uint32_t
247 ProcessInstanceInfoList &process_infos) {
249 return m_remote_platform_sp->FindProcesses(match_info, process_infos);
250 return Platform::FindProcesses(match_info, process_infos);
251}
252
254 llvm::StringRef plugin_name,
255 Debugger &debugger,
256 Target *target,
257 Status &error) {
259 return m_remote_platform_sp->ConnectProcess(connect_url, plugin_name,
260 debugger, target, error);
261 return Platform::ConnectProcess(connect_url, plugin_name, debugger, target,
262 error);
263}
264
267 return m_remote_platform_sp->LaunchProcess(launch_info);
268 return Platform::LaunchProcess(launch_info);
269}
270
273 return m_remote_platform_sp->KillProcess(pid);
274 return Platform::KillProcess(pid);
275}
276
278 Status &error) {
280 return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error);
282}
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 collection class.
Definition: FileSpecList.h:91
A file utility class.
Definition: FileSpec.h:56
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:367
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:53
virtual FileSpec GetRemoteWorkingDirectory()
Definition: Platform.h:237
virtual bool GetFileExists(const lldb_private::FileSpec &file_spec)
Definition: Platform.cpp:1214
virtual bool CloseFile(lldb::user_id_t fd, Status &error)
Definition: Platform.cpp:646
virtual bool IsConnected() const
Definition: Platform.h:484
virtual lldb::user_id_t OpenFile(const FileSpec &file_spec, File::OpenOptions flags, uint32_t mode, Status &error)
Definition: Platform.cpp:638
virtual const char * GetHostname()
Definition: Platform.cpp:688
virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
Attach to an existing process by process name.
Definition: Platform.cpp:912
virtual Status ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, const FileSpecList *module_search_paths_ptr)
Set the target's executable based off of the existing architecture information in target given a path...
Definition: Platform.cpp:732
llvm::VersionTuple m_os_version
Definition: Platform.h:982
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:598
virtual UserIDResolver & GetUserIDResolver()
Definition: Platform.cpp:682
virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec)
Definition: Platform.cpp:652
Status GetCachedExecutable(ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr)
Definition: Platform.cpp:1442
virtual Status Unlink(const FileSpec &file_spec)
Definition: Platform.cpp:1220
virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir)
Definition: Platform.cpp:701
virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Target *target, Status &error)
Definition: Platform.cpp:1863
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:930
virtual Status KillProcess(const lldb::pid_t pid)
Kill process on a platform.
Definition: Platform.cpp:984
virtual Status CreateSymlink(const FileSpec &src, const FileSpec &dst)
Definition: Platform.cpp:1206
virtual size_t ConnectToWaitingProcesses(lldb_private::Debugger &debugger, lldb_private::Status &error)
Connect to all processes waiting for a debugger to attach.
Definition: Platform.cpp:1935
virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error)
Definition: Platform.cpp:672
bool IsRemote() const
Definition: Platform.h:482
virtual Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions)
Definition: Platform.cpp:625
virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition: Platform.cpp:903
bool IsHost() const
Definition: Platform.h:478
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)
Definition: Platform.cpp:1240
virtual Environment GetEnvironment()
Definition: Platform.cpp:1424
virtual llvm::ErrorOr< llvm::MD5::MD5Result > CalculateMD5(const FileSpec &file_spec)
Definition: Platform.cpp:1273
virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error)
Definition: Platform.cpp:662
size_t ConnectToWaitingProcesses(Debugger &debugger, Status &error) override
Connect to all processes waiting for a debugger to attach.
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...
virtual Status ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp, const FileSpecList *module_search_paths_ptr) override
Set the target's executable based off of the existing architecture information in target given a path...
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:44
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
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
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
Definition: lldb-forward.h:371