LLDB  mainline
RemoteAwarePlatform.cpp
Go to the documentation of this file.
1 //===-- RemoteAwarePlatform.cpp ---------------------------------*- C++ -*-===//
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/Host/FileCache.h"
11 #include "lldb/Host/FileSystem.h"
12 #include "lldb/Host/Host.h"
13 #include "lldb/Host/HostInfo.h"
14 
15 using namespace lldb_private;
16 
17 bool RemoteAwarePlatform::GetModuleSpec(const FileSpec &module_file_spec,
18  const ArchSpec &arch,
19  ModuleSpec &module_spec) {
21  return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,
22  module_spec);
23 
24  return Platform::GetModuleSpec(module_file_spec, arch, module_spec);
25 }
26 
28  const char *command, const FileSpec &working_dir, int *status_ptr,
29  int *signo_ptr, std::string *command_output,
30  const Timeout<std::micro> &timeout) {
31  if (IsHost())
32  return Host::RunShellCommand(command, working_dir, status_ptr, signo_ptr,
33  command_output, timeout);
35  return m_remote_platform_sp->RunShellCommand(
36  command, working_dir, status_ptr, signo_ptr, command_output, timeout);
37  return Status("unable to run a remote command without a platform");
38 }
39 
41  uint32_t file_permissions) {
43  return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions);
44  return Platform::MakeDirectory(file_spec, file_permissions);
45 }
46 
48  uint32_t &file_permissions) {
50  return m_remote_platform_sp->GetFilePermissions(file_spec,
51  file_permissions);
52  return Platform::GetFilePermissions(file_spec, file_permissions);
53 }
54 
56  uint32_t file_permissions) {
58  return m_remote_platform_sp->SetFilePermissions(file_spec,
59  file_permissions);
60  return Platform::SetFilePermissions(file_spec, file_permissions);
61 }
62 
64  uint32_t flags, uint32_t mode,
65  Status &error) {
66  if (IsHost())
67  return FileCache::GetInstance().OpenFile(file_spec, flags, mode, error);
69  return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error);
70  return Platform::OpenFile(file_spec, flags, mode, error);
71 }
72 
74  if (IsHost())
75  return FileCache::GetInstance().CloseFile(fd, error);
77  return m_remote_platform_sp->CloseFile(fd, error);
78  return Platform::CloseFile(fd, error);
79 }
80 
81 uint64_t RemoteAwarePlatform::ReadFile(lldb::user_id_t fd, uint64_t offset,
82  void *dst, uint64_t dst_len,
83  Status &error) {
84  if (IsHost())
85  return FileCache::GetInstance().ReadFile(fd, offset, dst, dst_len, error);
87  return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error);
88  return Platform::ReadFile(fd, offset, dst, dst_len, error);
89 }
90 
91 uint64_t RemoteAwarePlatform::WriteFile(lldb::user_id_t fd, uint64_t offset,
92  const void *src, uint64_t src_len,
93  Status &error) {
94  if (IsHost())
95  return FileCache::GetInstance().WriteFile(fd, offset, src, src_len, error);
97  return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error);
98  return Platform::WriteFile(fd, offset, src, src_len, error);
99 }
100 
102  if (IsHost()) {
103  uint64_t Size;
104  if (llvm::sys::fs::file_size(file_spec.GetPath(), Size))
105  return 0;
106  return Size;
107  }
109  return m_remote_platform_sp->GetFileSize(file_spec);
110  return Platform::GetFileSize(file_spec);
111 }
112 
114  const FileSpec &dst) {
115  if (IsHost())
116  return FileSystem::Instance().Symlink(src, dst);
118  return m_remote_platform_sp->CreateSymlink(src, dst);
119  return Platform::CreateSymlink(src, dst);
120 }
121 
123  if (IsHost())
124  return FileSystem::Instance().Exists(file_spec);
126  return m_remote_platform_sp->GetFileExists(file_spec);
127  return Platform::GetFileExists(file_spec);
128 }
129 
131  if (IsHost())
132  return llvm::sys::fs::remove(file_spec.GetPath());
134  return m_remote_platform_sp->Unlink(file_spec);
135  return Platform::Unlink(file_spec);
136 }
137 
138 bool RemoteAwarePlatform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
139  uint64_t &high) {
140  if (IsHost())
141  return Platform::CalculateMD5(file_spec, low, high);
143  return m_remote_platform_sp->CalculateMD5(file_spec, low, high);
144  return false;
145 }
146 
149  return m_remote_platform_sp->GetRemoteWorkingDirectory();
151 }
152 
154  const FileSpec &working_dir) {
156  return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir);
157  return Platform::SetRemoteWorkingDirectory(working_dir);
158 }
159 
161  const UUID *uuid_ptr,
162  FileSpec &local_file) {
164  return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
165  local_file);
166 
167  // Default to the local case
168  local_file = platform_file;
169  return Status();
170 }
171 
173  if (m_remote_platform_sp) {
174  m_os_version = m_remote_platform_sp->GetOSVersion();
175  return !m_os_version.empty();
176  }
177  return false;
178 }
179 
182  return m_remote_platform_sp->GetRemoteOSBuildString(s);
183  s.clear();
184  return false;
185 }
186 
189  return m_remote_platform_sp->GetRemoteOSKernelDescription(s);
190  s.clear();
191  return false;
192 }
193 
196  return m_remote_platform_sp->GetRemoteSystemArchitecture();
197  return ArchSpec();
198 }
199 
201  if (IsHost())
202  return Platform::GetHostname();
204  return m_remote_platform_sp->GetHostname();
205  return nullptr;
206 }
207 
209  if (IsHost())
210  return HostInfo::GetUserIDResolver();
212  return m_remote_platform_sp->GetUserIDResolver();
214 }
215 
217  if (IsRemote()) {
219  return m_remote_platform_sp->GetEnvironment();
220  return Environment();
221  }
222  return Host::GetEnvironment();
223 }
224 
226  if (IsHost())
227  return true;
228  else if (m_remote_platform_sp)
229  return m_remote_platform_sp->IsConnected();
230  return false;
231 }
232 
234  ProcessInstanceInfo &process_info) {
235  if (IsHost())
236  return Platform::GetProcessInfo(pid, process_info);
238  return m_remote_platform_sp->GetProcessInfo(pid, process_info);
239  return false;
240 }
241 
242 uint32_t
244  ProcessInstanceInfoList &process_infos) {
245  if (IsHost())
246  return Platform::FindProcesses(match_info, process_infos);
248  return m_remote_platform_sp->FindProcesses(match_info, process_infos);
249  return 0;
250 }
251 
252 lldb::ProcessSP RemoteAwarePlatform::ConnectProcess(llvm::StringRef connect_url,
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 
265  Status error;
266 
267  if (IsHost()) {
268  error = Platform::LaunchProcess(launch_info);
269  } else {
271  error = m_remote_platform_sp->LaunchProcess(launch_info);
272  else
273  error.SetErrorString("the platform is not currently connected");
274  }
275  return error;
276 }
277 
279  if (IsHost())
280  return Platform::KillProcess(pid);
282  return m_remote_platform_sp->KillProcess(pid);
283  return Status("the platform is not currently connected");
284 }
A class to manage flag bits.
Definition: Debugger.h:82
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error)
Definition: FileCache.cpp:61
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error) override
virtual uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
Attach to an existing process by process name.
Definition: Platform.cpp:1000
Status CreateSymlink(const FileSpec &src, const FileSpec &dst) override
bool GetRemoteOSKernelDescription(std::string &s) override
lldb::user_id_t GetFileSize(const FileSpec &file_spec) 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 CreateSymlink(const FileSpec &src, const FileSpec &dst)
Definition: Platform.cpp:1299
uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &process_infos) override
Attach to an existing process by process name.
virtual bool GetFileExists(const lldb_private::FileSpec &file_spec)
Definition: Platform.cpp:1306
virtual FileSpec GetRemoteWorkingDirectory()
Definition: Platform.h:256
virtual Status KillProcess(const lldb::pid_t pid)
Kill process on a platform.
Definition: Platform.cpp:1068
bool IsHost() const
Definition: Platform.h:450
A file utility class.
Definition: FileSpec.h:55
An architecture specification class.
Definition: ArchSpec.h:32
virtual uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Status &error)
Definition: Platform.h:540
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error)
Definition: FileCache.cpp:88
Status MakeDirectory(const FileSpec &file_spec, uint32_t mode) override
bool CloseFile(lldb::user_id_t fd, Status &error) override
virtual lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, lldb_private::Debugger &debugger, lldb_private::Target *target, lldb_private::Status &error)
Definition: Platform.cpp:1781
static FileSystem & Instance()
lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags, uint32_t mode, Status &error)
Definition: FileCache.cpp:26
bool CalculateMD5(const FileSpec &file_spec, uint64_t &low, uint64_t &high) override
bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info) override
Status Unlink(const FileSpec &file_spec) override
uint64_t user_id_t
Definition: lldb-types.h:84
uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error) override
bool IsRemote() const
Definition: Platform.h:454
bool GetRemoteOSBuildString(std::string &s) override
virtual lldb::user_id_t GetFileSize(const FileSpec &file_spec)
Definition: Platform.h:528
static UserIDResolver & GetNoopResolver()
Returns a resolver which returns a failure value for each query.
virtual lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags, uint32_t mode, Status &error)
Definition: Platform.h:521
virtual bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec)
Definition: Platform.cpp:256
static Environment GetEnvironment()
lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url, llvm::StringRef plugin_name, Debugger &debugger, Target *target, Status &error) override
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
bool SetRemoteWorkingDirectory(const FileSpec &working_dir) override
lldb_private::Environment GetEnvironment() override
bool GetFileExists(const FileSpec &file_spec) override
virtual bool SetRemoteWorkingDirectory(const FileSpec &working_dir)
Definition: Platform.cpp:822
virtual bool CloseFile(lldb::user_id_t fd, Status &error)
Definition: Platform.h:526
Status Symlink(const FileSpec &src, const FileSpec &dst)
Status GetFileWithUUID(const FileSpec &platform_file, const UUID *uuid, FileSpec &local_file) override
Locate a file for a platform.
virtual Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions)
Definition: Platform.cpp:793
An abstract interface for things that know how to map numeric user/group IDs into names...
Status KillProcess(const lldb::pid_t pid) override
Kill process on a platform.
static Status RunShellCommand(const char *command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const Timeout< std::micro > &timeout, bool run_in_default_shell=true, bool hide_stderr=false)
Run a shell command.
UserIDResolver & GetUserIDResolver() override
virtual Status MakeDirectory(const FileSpec &file_spec, uint32_t permissions)
Definition: Platform.cpp:764
bool GetModuleSpec(const FileSpec &module_file_spec, const ArchSpec &arch, ModuleSpec &module_spec) override
static FileCache & GetInstance()
Definition: FileCache.cpp:19
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
uint64_t pid_t
Definition: lldb-types.h:85
virtual Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions)
Definition: Platform.cpp:777
virtual bool CalculateMD5(const FileSpec &file_spec, uint64_t &low, uint64_t &high)
Definition: Platform.cpp:1346
virtual uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Status &error)
Definition: Platform.h:532
lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags, uint32_t mode, Status &error) override
Status GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions) override
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:376
llvm::VersionTuple m_os_version
Definition: Platform.h:856
virtual Status Unlink(const FileSpec &file_spec)
Definition: Platform.cpp:1310
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:1010
Status RunShellCommand(const char *command, const FileSpec &working_dir, int *status_ptr, int *signo_ptr, std::string *command_output, const Timeout< std::micro > &timeout) override
virtual bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition: Platform.cpp:991
bool CloseFile(lldb::user_id_t fd, Status &error)
Definition: FileCache.cpp:41
An error handling class.
Definition: Status.h:44
Status SetFilePermissions(const FileSpec &file_spec, uint32_t file_permissions) override
virtual const char * GetHostname()
Definition: Platform.cpp:809