1 //===-- RemoteAwarePlatform.cpp -------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Target/RemoteAwarePlatform.h"
10 #include "lldb/Core/Module.h"
11 #include "lldb/Core/ModuleList.h"
12 #include "lldb/Core/ModuleSpec.h"
13 #include "lldb/Host/FileSystem.h"
14 #include "lldb/Host/Host.h"
15 #include "lldb/Host/HostInfo.h"
16 #include "lldb/Utility/StreamString.h"
19 using namespace lldb_private
;
22 bool RemoteAwarePlatform::GetModuleSpec(const FileSpec
&module_file_spec
,
24 ModuleSpec
&module_spec
) {
25 if (m_remote_platform_sp
)
26 return m_remote_platform_sp
->GetModuleSpec(module_file_spec
, arch
,
32 Status
RemoteAwarePlatform::ResolveExecutable(
33 const ModuleSpec
&module_spec
, lldb::ModuleSP
&exe_module_sp
,
34 const FileSpecList
*module_search_paths_ptr
) {
35 ModuleSpec
resolved_module_spec(module_spec
);
37 // The host platform can resolve the path more aggressively.
39 FileSpec
&resolved_file_spec
= resolved_module_spec
.GetFileSpec();
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
);
47 if (!FileSystem::Instance().Exists(resolved_file_spec
))
48 FileSystem::Instance().ResolveExecutableLocation(resolved_file_spec
);
49 } else if (m_remote_platform_sp
) {
50 return GetCachedExecutable(resolved_module_spec
, exe_module_sp
,
51 module_search_paths_ptr
);
54 return Platform::ResolveExecutable(resolved_module_spec
, exe_module_sp
,
55 module_search_paths_ptr
);
58 Status
RemoteAwarePlatform::RunShellCommand(
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
);
66 Status
RemoteAwarePlatform::RunShellCommand(
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
) {
70 if (m_remote_platform_sp
)
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
);
78 Status
RemoteAwarePlatform::MakeDirectory(const FileSpec
&file_spec
,
79 uint32_t file_permissions
) {
80 if (m_remote_platform_sp
)
81 return m_remote_platform_sp
->MakeDirectory(file_spec
, file_permissions
);
82 return Platform::MakeDirectory(file_spec
, file_permissions
);
85 Status
RemoteAwarePlatform::GetFilePermissions(const FileSpec
&file_spec
,
86 uint32_t &file_permissions
) {
87 if (m_remote_platform_sp
)
88 return m_remote_platform_sp
->GetFilePermissions(file_spec
,
90 return Platform::GetFilePermissions(file_spec
, file_permissions
);
93 Status
RemoteAwarePlatform::SetFilePermissions(const FileSpec
&file_spec
,
94 uint32_t file_permissions
) {
95 if (m_remote_platform_sp
)
96 return m_remote_platform_sp
->SetFilePermissions(file_spec
,
98 return Platform::SetFilePermissions(file_spec
, file_permissions
);
101 lldb::user_id_t
RemoteAwarePlatform::OpenFile(const FileSpec
&file_spec
,
102 File::OpenOptions flags
,
103 uint32_t mode
, Status
&error
) {
104 if (m_remote_platform_sp
)
105 return m_remote_platform_sp
->OpenFile(file_spec
, flags
, mode
, error
);
106 return Platform::OpenFile(file_spec
, flags
, mode
, error
);
109 bool RemoteAwarePlatform::CloseFile(lldb::user_id_t fd
, Status
&error
) {
110 if (m_remote_platform_sp
)
111 return m_remote_platform_sp
->CloseFile(fd
, error
);
112 return Platform::CloseFile(fd
, error
);
115 uint64_t RemoteAwarePlatform::ReadFile(lldb::user_id_t fd
, uint64_t offset
,
116 void *dst
, uint64_t dst_len
,
118 if (m_remote_platform_sp
)
119 return m_remote_platform_sp
->ReadFile(fd
, offset
, dst
, dst_len
, error
);
120 return Platform::ReadFile(fd
, offset
, dst
, dst_len
, error
);
123 uint64_t RemoteAwarePlatform::WriteFile(lldb::user_id_t fd
, uint64_t offset
,
124 const void *src
, uint64_t src_len
,
126 if (m_remote_platform_sp
)
127 return m_remote_platform_sp
->WriteFile(fd
, offset
, src
, src_len
, error
);
128 return Platform::WriteFile(fd
, offset
, src
, src_len
, error
);
131 lldb::user_id_t
RemoteAwarePlatform::GetFileSize(const FileSpec
&file_spec
) {
132 if (m_remote_platform_sp
)
133 return m_remote_platform_sp
->GetFileSize(file_spec
);
134 return Platform::GetFileSize(file_spec
);
137 Status
RemoteAwarePlatform::CreateSymlink(const FileSpec
&src
,
138 const FileSpec
&dst
) {
139 if (m_remote_platform_sp
)
140 return m_remote_platform_sp
->CreateSymlink(src
, dst
);
141 return Platform::CreateSymlink(src
, dst
);
144 bool RemoteAwarePlatform::GetFileExists(const FileSpec
&file_spec
) {
145 if (m_remote_platform_sp
)
146 return m_remote_platform_sp
->GetFileExists(file_spec
);
147 return Platform::GetFileExists(file_spec
);
150 Status
RemoteAwarePlatform::Unlink(const FileSpec
&file_spec
) {
151 if (m_remote_platform_sp
)
152 return m_remote_platform_sp
->Unlink(file_spec
);
153 return Platform::Unlink(file_spec
);
156 llvm::ErrorOr
<llvm::MD5::MD5Result
>
157 RemoteAwarePlatform::CalculateMD5(const FileSpec
&file_spec
) {
158 if (m_remote_platform_sp
)
159 return m_remote_platform_sp
->CalculateMD5(file_spec
);
160 return Platform::CalculateMD5(file_spec
);
163 FileSpec
RemoteAwarePlatform::GetRemoteWorkingDirectory() {
164 if (IsRemote() && m_remote_platform_sp
)
165 return m_remote_platform_sp
->GetRemoteWorkingDirectory();
166 return Platform::GetRemoteWorkingDirectory();
169 bool RemoteAwarePlatform::SetRemoteWorkingDirectory(
170 const FileSpec
&working_dir
) {
171 if (IsRemote() && m_remote_platform_sp
)
172 return m_remote_platform_sp
->SetRemoteWorkingDirectory(working_dir
);
173 return Platform::SetRemoteWorkingDirectory(working_dir
);
176 Status
RemoteAwarePlatform::GetFileWithUUID(const FileSpec
&platform_file
,
177 const UUID
*uuid_ptr
,
178 FileSpec
&local_file
) {
179 if (IsRemote() && m_remote_platform_sp
)
180 return m_remote_platform_sp
->GetFileWithUUID(platform_file
, uuid_ptr
,
183 // Default to the local case
184 local_file
= platform_file
;
188 bool RemoteAwarePlatform::GetRemoteOSVersion() {
189 if (m_remote_platform_sp
) {
190 m_os_version
= m_remote_platform_sp
->GetOSVersion();
191 return !m_os_version
.empty();
196 std::optional
<std::string
> RemoteAwarePlatform::GetRemoteOSBuildString() {
197 if (m_remote_platform_sp
)
198 return m_remote_platform_sp
->GetRemoteOSBuildString();
202 std::optional
<std::string
> RemoteAwarePlatform::GetRemoteOSKernelDescription() {
203 if (m_remote_platform_sp
)
204 return m_remote_platform_sp
->GetRemoteOSKernelDescription();
208 ArchSpec
RemoteAwarePlatform::GetRemoteSystemArchitecture() {
209 if (m_remote_platform_sp
)
210 return m_remote_platform_sp
->GetRemoteSystemArchitecture();
214 const char *RemoteAwarePlatform::GetHostname() {
215 if (m_remote_platform_sp
)
216 return m_remote_platform_sp
->GetHostname();
217 return Platform::GetHostname();
220 UserIDResolver
&RemoteAwarePlatform::GetUserIDResolver() {
221 if (m_remote_platform_sp
)
222 return m_remote_platform_sp
->GetUserIDResolver();
223 return Platform::GetUserIDResolver();
226 Environment
RemoteAwarePlatform::GetEnvironment() {
227 if (m_remote_platform_sp
)
228 return m_remote_platform_sp
->GetEnvironment();
229 return Platform::GetEnvironment();
232 bool RemoteAwarePlatform::IsConnected() const {
233 if (m_remote_platform_sp
)
234 return m_remote_platform_sp
->IsConnected();
235 return Platform::IsConnected();
238 bool RemoteAwarePlatform::GetProcessInfo(lldb::pid_t pid
,
239 ProcessInstanceInfo
&process_info
) {
240 if (m_remote_platform_sp
)
241 return m_remote_platform_sp
->GetProcessInfo(pid
, process_info
);
242 return Platform::GetProcessInfo(pid
, process_info
);
246 RemoteAwarePlatform::FindProcesses(const ProcessInstanceInfoMatch
&match_info
,
247 ProcessInstanceInfoList
&process_infos
) {
248 if (m_remote_platform_sp
)
249 return m_remote_platform_sp
->FindProcesses(match_info
, process_infos
);
250 return Platform::FindProcesses(match_info
, process_infos
);
253 lldb::ProcessSP
RemoteAwarePlatform::ConnectProcess(llvm::StringRef connect_url
,
254 llvm::StringRef plugin_name
,
258 if (m_remote_platform_sp
)
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
,
265 Status
RemoteAwarePlatform::LaunchProcess(ProcessLaunchInfo
&launch_info
) {
266 if (m_remote_platform_sp
)
267 return m_remote_platform_sp
->LaunchProcess(launch_info
);
268 return Platform::LaunchProcess(launch_info
);
271 Status
RemoteAwarePlatform::KillProcess(const lldb::pid_t pid
) {
272 if (m_remote_platform_sp
)
273 return m_remote_platform_sp
->KillProcess(pid
);
274 return Platform::KillProcess(pid
);
277 size_t RemoteAwarePlatform::ConnectToWaitingProcesses(Debugger
&debugger
,
279 if (m_remote_platform_sp
)
280 return m_remote_platform_sp
->ConnectToWaitingProcesses(debugger
, error
);
281 return Platform::ConnectToWaitingProcesses(debugger
, error
);