180814287SRaphael Isemann //===-- RemoteAwarePlatform.cpp -------------------------------------------===//
252d9c62aSPavel Labath //
352d9c62aSPavel Labath // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
452d9c62aSPavel Labath // See https://llvm.org/LICENSE.txt for license information.
552d9c62aSPavel Labath // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
652d9c62aSPavel Labath //
752d9c62aSPavel Labath //===----------------------------------------------------------------------===//
852d9c62aSPavel Labath 
952d9c62aSPavel Labath #include "lldb/Target/RemoteAwarePlatform.h"
10e072b20bSPavel Labath #include "lldb/Core/Module.h"
11e072b20bSPavel Labath #include "lldb/Core/ModuleList.h"
12e072b20bSPavel Labath #include "lldb/Core/ModuleSpec.h"
13d504fe20SAaron Smith #include "lldb/Host/FileCache.h"
14d504fe20SAaron Smith #include "lldb/Host/FileSystem.h"
1552d9c62aSPavel Labath #include "lldb/Host/Host.h"
16aa51e6a6SPavel Labath #include "lldb/Host/HostInfo.h"
17e072b20bSPavel Labath #include "lldb/Utility/StreamString.h"
1852d9c62aSPavel Labath 
1952d9c62aSPavel Labath using namespace lldb_private;
20e072b20bSPavel Labath using namespace lldb;
2152d9c62aSPavel Labath 
2252d9c62aSPavel Labath bool RemoteAwarePlatform::GetModuleSpec(const FileSpec &module_file_spec,
2352d9c62aSPavel Labath                                         const ArchSpec &arch,
2452d9c62aSPavel Labath                                         ModuleSpec &module_spec) {
2552d9c62aSPavel Labath   if (m_remote_platform_sp)
2652d9c62aSPavel Labath     return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch,
2752d9c62aSPavel Labath                                                module_spec);
2852d9c62aSPavel Labath 
296afa5c40SYuri Per   return false;
3052d9c62aSPavel Labath }
3152d9c62aSPavel Labath 
32e072b20bSPavel Labath Status RemoteAwarePlatform::ResolveExecutable(
33e072b20bSPavel Labath     const ModuleSpec &module_spec, ModuleSP &exe_module_sp,
34e072b20bSPavel Labath     const FileSpecList *module_search_paths_ptr) {
35e072b20bSPavel Labath   Status error;
36e072b20bSPavel Labath   // Nothing special to do here, just use the actual file and architecture
37e072b20bSPavel Labath 
38e072b20bSPavel Labath   char exe_path[PATH_MAX];
39e072b20bSPavel Labath   ModuleSpec resolved_module_spec(module_spec);
40e072b20bSPavel Labath 
41e072b20bSPavel Labath   if (IsHost()) {
42e072b20bSPavel Labath     // If we have "ls" as the exe_file, resolve the executable location based
43e072b20bSPavel Labath     // on the current path variables
44e072b20bSPavel Labath     if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec())) {
45e072b20bSPavel Labath       resolved_module_spec.GetFileSpec().GetPath(exe_path, sizeof(exe_path));
46e072b20bSPavel Labath       resolved_module_spec.GetFileSpec().SetFile(exe_path,
47e072b20bSPavel Labath                                                  FileSpec::Style::native);
48e072b20bSPavel Labath       FileSystem::Instance().Resolve(resolved_module_spec.GetFileSpec());
49e072b20bSPavel Labath     }
50e072b20bSPavel Labath 
51e072b20bSPavel Labath     if (!FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
52e072b20bSPavel Labath       FileSystem::Instance().ResolveExecutableLocation(
53e072b20bSPavel Labath           resolved_module_spec.GetFileSpec());
54e072b20bSPavel Labath 
55e072b20bSPavel Labath     // Resolve any executable within a bundle on MacOSX
56e072b20bSPavel Labath     Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
57e072b20bSPavel Labath 
58e072b20bSPavel Labath     if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
59e072b20bSPavel Labath       error.Clear();
60e072b20bSPavel Labath     else {
61e072b20bSPavel Labath       const uint32_t permissions = FileSystem::Instance().GetPermissions(
62e072b20bSPavel Labath           resolved_module_spec.GetFileSpec());
63e072b20bSPavel Labath       if (permissions && (permissions & eFilePermissionsEveryoneR) == 0)
64e072b20bSPavel Labath         error.SetErrorStringWithFormat(
65e072b20bSPavel Labath             "executable '%s' is not readable",
66e072b20bSPavel Labath             resolved_module_spec.GetFileSpec().GetPath().c_str());
67e072b20bSPavel Labath       else
68e072b20bSPavel Labath         error.SetErrorStringWithFormat(
69e072b20bSPavel Labath             "unable to find executable for '%s'",
70e072b20bSPavel Labath             resolved_module_spec.GetFileSpec().GetPath().c_str());
71e072b20bSPavel Labath     }
72e072b20bSPavel Labath   } else {
73e072b20bSPavel Labath     if (m_remote_platform_sp) {
74631048e8SLevon Ter-Grigoryan       return GetCachedExecutable(resolved_module_spec, exe_module_sp,
75098c01c1SPavel Labath                                  module_search_paths_ptr);
76631048e8SLevon Ter-Grigoryan     }
77631048e8SLevon Ter-Grigoryan 
78e072b20bSPavel Labath     // We may connect to a process and use the provided executable (Don't use
79e072b20bSPavel Labath     // local $PATH).
80e072b20bSPavel Labath 
81e072b20bSPavel Labath     // Resolve any executable within a bundle on MacOSX
82e072b20bSPavel Labath     Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
83e072b20bSPavel Labath 
84e072b20bSPavel Labath     if (FileSystem::Instance().Exists(resolved_module_spec.GetFileSpec()))
85e072b20bSPavel Labath       error.Clear();
86e072b20bSPavel Labath     else
87e072b20bSPavel Labath       error.SetErrorStringWithFormat("the platform is not currently "
88e072b20bSPavel Labath                                      "connected, and '%s' doesn't exist in "
89e072b20bSPavel Labath                                      "the system root.",
90e072b20bSPavel Labath                                      exe_path);
91e072b20bSPavel Labath   }
92e072b20bSPavel Labath 
93e072b20bSPavel Labath   if (error.Success()) {
94e072b20bSPavel Labath     if (resolved_module_spec.GetArchitecture().IsValid()) {
95e072b20bSPavel Labath       error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
96e072b20bSPavel Labath                                           module_search_paths_ptr, nullptr, nullptr);
97e072b20bSPavel Labath       if (error.Fail()) {
98e072b20bSPavel Labath         // If we failed, it may be because the vendor and os aren't known. If
99e072b20bSPavel Labath 	// that is the case, try setting them to the host architecture and give
100e072b20bSPavel Labath 	// it another try.
101e072b20bSPavel Labath         llvm::Triple &module_triple =
102e072b20bSPavel Labath             resolved_module_spec.GetArchitecture().GetTriple();
103e072b20bSPavel Labath         bool is_vendor_specified =
104e072b20bSPavel Labath             (module_triple.getVendor() != llvm::Triple::UnknownVendor);
105e072b20bSPavel Labath         bool is_os_specified =
106e072b20bSPavel Labath             (module_triple.getOS() != llvm::Triple::UnknownOS);
107e072b20bSPavel Labath         if (!is_vendor_specified || !is_os_specified) {
108e072b20bSPavel Labath           const llvm::Triple &host_triple =
109e072b20bSPavel Labath               HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple();
110e072b20bSPavel Labath 
111e072b20bSPavel Labath           if (!is_vendor_specified)
112e072b20bSPavel Labath             module_triple.setVendorName(host_triple.getVendorName());
113e072b20bSPavel Labath           if (!is_os_specified)
114e072b20bSPavel Labath             module_triple.setOSName(host_triple.getOSName());
115e072b20bSPavel Labath 
116e072b20bSPavel Labath           error = ModuleList::GetSharedModule(resolved_module_spec,
117e072b20bSPavel Labath                                               exe_module_sp, module_search_paths_ptr, nullptr, nullptr);
118e072b20bSPavel Labath         }
119e072b20bSPavel Labath       }
120e072b20bSPavel Labath 
121e072b20bSPavel Labath       // TODO find out why exe_module_sp might be NULL
122e072b20bSPavel Labath       if (error.Fail() || !exe_module_sp || !exe_module_sp->GetObjectFile()) {
123e072b20bSPavel Labath         exe_module_sp.reset();
124e072b20bSPavel Labath         error.SetErrorStringWithFormat(
125e072b20bSPavel Labath             "'%s' doesn't contain the architecture %s",
126e072b20bSPavel Labath             resolved_module_spec.GetFileSpec().GetPath().c_str(),
127e072b20bSPavel Labath             resolved_module_spec.GetArchitecture().GetArchitectureName());
128e072b20bSPavel Labath       }
129e072b20bSPavel Labath     } else {
130e072b20bSPavel Labath       // No valid architecture was specified, ask the platform for the
131e072b20bSPavel Labath       // architectures that we should be using (in the correct order) and see
132e072b20bSPavel Labath       // if we can find a match that way
133e072b20bSPavel Labath       StreamString arch_names;
13496beb30fSPavel Labath       llvm::ListSeparator LS;
135*dde487e5SJonas Devlieghere       ArchSpec process_host_arch;
136*dde487e5SJonas Devlieghere       for (const ArchSpec &arch :
137*dde487e5SJonas Devlieghere            GetSupportedArchitectures(process_host_arch)) {
13896beb30fSPavel Labath         resolved_module_spec.GetArchitecture() = arch;
139e072b20bSPavel Labath         error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
140e072b20bSPavel Labath                                             module_search_paths_ptr, nullptr, nullptr);
141e072b20bSPavel Labath         // Did we find an executable using one of the
142e072b20bSPavel Labath         if (error.Success()) {
143e072b20bSPavel Labath           if (exe_module_sp && exe_module_sp->GetObjectFile())
144e072b20bSPavel Labath             break;
145e072b20bSPavel Labath           else
146e072b20bSPavel Labath             error.SetErrorToGenericError();
147e072b20bSPavel Labath         }
148e072b20bSPavel Labath 
14996beb30fSPavel Labath         arch_names << LS << arch.GetArchitectureName();
150e072b20bSPavel Labath       }
151e072b20bSPavel Labath 
152e072b20bSPavel Labath       if (error.Fail() || !exe_module_sp) {
153e072b20bSPavel Labath         if (FileSystem::Instance().Readable(
154e072b20bSPavel Labath                 resolved_module_spec.GetFileSpec())) {
155a3939e15SPavel Labath           error.SetErrorStringWithFormatv(
156a3939e15SPavel Labath               "'{0}' doesn't contain any '{1}' platform architectures: {2}",
157a3939e15SPavel Labath               resolved_module_spec.GetFileSpec(), GetPluginName(),
158a3939e15SPavel Labath               arch_names.GetData());
159e072b20bSPavel Labath         } else {
160e072b20bSPavel Labath           error.SetErrorStringWithFormat(
161e072b20bSPavel Labath               "'%s' is not readable",
162e072b20bSPavel Labath               resolved_module_spec.GetFileSpec().GetPath().c_str());
163e072b20bSPavel Labath         }
164e072b20bSPavel Labath       }
165e072b20bSPavel Labath     }
166e072b20bSPavel Labath   }
167e072b20bSPavel Labath 
168e072b20bSPavel Labath   return error;
169e072b20bSPavel Labath }
170e072b20bSPavel Labath 
171d504fe20SAaron Smith Status RemoteAwarePlatform::RunShellCommand(
172addb5148SMed Ismail Bennani     llvm::StringRef command, const FileSpec &working_dir, int *status_ptr,
173d504fe20SAaron Smith     int *signo_ptr, std::string *command_output,
174d504fe20SAaron Smith     const Timeout<std::micro> &timeout) {
175addb5148SMed Ismail Bennani   return RunShellCommand(llvm::StringRef(), command, working_dir, status_ptr,
176addb5148SMed Ismail Bennani                          signo_ptr, command_output, timeout);
177addb5148SMed Ismail Bennani }
178addb5148SMed Ismail Bennani 
179addb5148SMed Ismail Bennani Status RemoteAwarePlatform::RunShellCommand(
180addb5148SMed Ismail Bennani     llvm::StringRef shell, llvm::StringRef command, const FileSpec &working_dir,
181addb5148SMed Ismail Bennani     int *status_ptr, int *signo_ptr, std::string *command_output,
182addb5148SMed Ismail Bennani     const Timeout<std::micro> &timeout) {
183d504fe20SAaron Smith   if (IsHost())
184addb5148SMed Ismail Bennani     return Host::RunShellCommand(shell, command, working_dir, status_ptr,
185addb5148SMed Ismail Bennani                                  signo_ptr, command_output, timeout);
186d504fe20SAaron Smith   if (m_remote_platform_sp)
187addb5148SMed Ismail Bennani     return m_remote_platform_sp->RunShellCommand(shell, command, working_dir,
188addb5148SMed Ismail Bennani                                                  status_ptr, signo_ptr,
189addb5148SMed Ismail Bennani                                                  command_output, timeout);
190d504fe20SAaron Smith   return Status("unable to run a remote command without a platform");
191d504fe20SAaron Smith }
192d504fe20SAaron Smith 
193d504fe20SAaron Smith Status RemoteAwarePlatform::MakeDirectory(const FileSpec &file_spec,
194d504fe20SAaron Smith                                           uint32_t file_permissions) {
195d504fe20SAaron Smith   if (m_remote_platform_sp)
196d504fe20SAaron Smith     return m_remote_platform_sp->MakeDirectory(file_spec, file_permissions);
197d504fe20SAaron Smith   return Platform::MakeDirectory(file_spec, file_permissions);
198d504fe20SAaron Smith }
199d504fe20SAaron Smith 
200d504fe20SAaron Smith Status RemoteAwarePlatform::GetFilePermissions(const FileSpec &file_spec,
201d504fe20SAaron Smith                                                uint32_t &file_permissions) {
202d504fe20SAaron Smith   if (m_remote_platform_sp)
203d504fe20SAaron Smith     return m_remote_platform_sp->GetFilePermissions(file_spec,
204d504fe20SAaron Smith                                                     file_permissions);
205d504fe20SAaron Smith   return Platform::GetFilePermissions(file_spec, file_permissions);
206d504fe20SAaron Smith }
207d504fe20SAaron Smith 
208d504fe20SAaron Smith Status RemoteAwarePlatform::SetFilePermissions(const FileSpec &file_spec,
209d504fe20SAaron Smith                                                uint32_t file_permissions) {
210d504fe20SAaron Smith   if (m_remote_platform_sp)
211d504fe20SAaron Smith     return m_remote_platform_sp->SetFilePermissions(file_spec,
212d504fe20SAaron Smith                                                     file_permissions);
213d504fe20SAaron Smith   return Platform::SetFilePermissions(file_spec, file_permissions);
214d504fe20SAaron Smith }
215d504fe20SAaron Smith 
216d504fe20SAaron Smith lldb::user_id_t RemoteAwarePlatform::OpenFile(const FileSpec &file_spec,
21762c9fe42SLawrence D'Anna                                               File::OpenOptions flags,
21862c9fe42SLawrence D'Anna                                               uint32_t mode, Status &error) {
219d504fe20SAaron Smith   if (IsHost())
220d504fe20SAaron Smith     return FileCache::GetInstance().OpenFile(file_spec, flags, mode, error);
221d504fe20SAaron Smith   if (m_remote_platform_sp)
222d504fe20SAaron Smith     return m_remote_platform_sp->OpenFile(file_spec, flags, mode, error);
223d504fe20SAaron Smith   return Platform::OpenFile(file_spec, flags, mode, error);
224d504fe20SAaron Smith }
225d504fe20SAaron Smith 
226d504fe20SAaron Smith bool RemoteAwarePlatform::CloseFile(lldb::user_id_t fd, Status &error) {
227d504fe20SAaron Smith   if (IsHost())
228d504fe20SAaron Smith     return FileCache::GetInstance().CloseFile(fd, error);
229d504fe20SAaron Smith   if (m_remote_platform_sp)
230d504fe20SAaron Smith     return m_remote_platform_sp->CloseFile(fd, error);
231d504fe20SAaron Smith   return Platform::CloseFile(fd, error);
232d504fe20SAaron Smith }
233d504fe20SAaron Smith 
234d504fe20SAaron Smith uint64_t RemoteAwarePlatform::ReadFile(lldb::user_id_t fd, uint64_t offset,
235d504fe20SAaron Smith                                        void *dst, uint64_t dst_len,
236d504fe20SAaron Smith                                        Status &error) {
237d504fe20SAaron Smith   if (IsHost())
238d504fe20SAaron Smith     return FileCache::GetInstance().ReadFile(fd, offset, dst, dst_len, error);
239d504fe20SAaron Smith   if (m_remote_platform_sp)
240d504fe20SAaron Smith     return m_remote_platform_sp->ReadFile(fd, offset, dst, dst_len, error);
241d504fe20SAaron Smith   return Platform::ReadFile(fd, offset, dst, dst_len, error);
242d504fe20SAaron Smith }
243d504fe20SAaron Smith 
244d504fe20SAaron Smith uint64_t RemoteAwarePlatform::WriteFile(lldb::user_id_t fd, uint64_t offset,
245d504fe20SAaron Smith                                         const void *src, uint64_t src_len,
246d504fe20SAaron Smith                                         Status &error) {
247d504fe20SAaron Smith   if (IsHost())
248d504fe20SAaron Smith     return FileCache::GetInstance().WriteFile(fd, offset, src, src_len, error);
249d504fe20SAaron Smith   if (m_remote_platform_sp)
250d504fe20SAaron Smith     return m_remote_platform_sp->WriteFile(fd, offset, src, src_len, error);
251d504fe20SAaron Smith   return Platform::WriteFile(fd, offset, src, src_len, error);
252d504fe20SAaron Smith }
253d504fe20SAaron Smith 
254d504fe20SAaron Smith lldb::user_id_t RemoteAwarePlatform::GetFileSize(const FileSpec &file_spec) {
255d504fe20SAaron Smith   if (IsHost()) {
256d504fe20SAaron Smith     uint64_t Size;
257d504fe20SAaron Smith     if (llvm::sys::fs::file_size(file_spec.GetPath(), Size))
258d504fe20SAaron Smith       return 0;
259d504fe20SAaron Smith     return Size;
260d504fe20SAaron Smith   }
261d504fe20SAaron Smith   if (m_remote_platform_sp)
262d504fe20SAaron Smith     return m_remote_platform_sp->GetFileSize(file_spec);
263d504fe20SAaron Smith   return Platform::GetFileSize(file_spec);
264d504fe20SAaron Smith }
265d504fe20SAaron Smith 
266d504fe20SAaron Smith Status RemoteAwarePlatform::CreateSymlink(const FileSpec &src,
267d504fe20SAaron Smith                                           const FileSpec &dst) {
268d504fe20SAaron Smith   if (IsHost())
269d504fe20SAaron Smith     return FileSystem::Instance().Symlink(src, dst);
270d504fe20SAaron Smith   if (m_remote_platform_sp)
271d504fe20SAaron Smith     return m_remote_platform_sp->CreateSymlink(src, dst);
272d504fe20SAaron Smith   return Platform::CreateSymlink(src, dst);
273d504fe20SAaron Smith }
274d504fe20SAaron Smith 
275d504fe20SAaron Smith bool RemoteAwarePlatform::GetFileExists(const FileSpec &file_spec) {
276d504fe20SAaron Smith   if (IsHost())
277d504fe20SAaron Smith     return FileSystem::Instance().Exists(file_spec);
278d504fe20SAaron Smith   if (m_remote_platform_sp)
279d504fe20SAaron Smith     return m_remote_platform_sp->GetFileExists(file_spec);
280d504fe20SAaron Smith   return Platform::GetFileExists(file_spec);
281d504fe20SAaron Smith }
282d504fe20SAaron Smith 
283d504fe20SAaron Smith Status RemoteAwarePlatform::Unlink(const FileSpec &file_spec) {
284d504fe20SAaron Smith   if (IsHost())
285d504fe20SAaron Smith     return llvm::sys::fs::remove(file_spec.GetPath());
286d504fe20SAaron Smith   if (m_remote_platform_sp)
287d504fe20SAaron Smith     return m_remote_platform_sp->Unlink(file_spec);
288d504fe20SAaron Smith   return Platform::Unlink(file_spec);
289d504fe20SAaron Smith }
290d504fe20SAaron Smith 
291d504fe20SAaron Smith bool RemoteAwarePlatform::CalculateMD5(const FileSpec &file_spec, uint64_t &low,
292d504fe20SAaron Smith                                        uint64_t &high) {
293d504fe20SAaron Smith   if (IsHost())
294d504fe20SAaron Smith     return Platform::CalculateMD5(file_spec, low, high);
295d504fe20SAaron Smith   if (m_remote_platform_sp)
296d504fe20SAaron Smith     return m_remote_platform_sp->CalculateMD5(file_spec, low, high);
297d504fe20SAaron Smith   return false;
298d504fe20SAaron Smith }
299d504fe20SAaron Smith 
300d504fe20SAaron Smith FileSpec RemoteAwarePlatform::GetRemoteWorkingDirectory() {
301d504fe20SAaron Smith   if (IsRemote() && m_remote_platform_sp)
302d504fe20SAaron Smith     return m_remote_platform_sp->GetRemoteWorkingDirectory();
303d504fe20SAaron Smith   return Platform::GetRemoteWorkingDirectory();
304d504fe20SAaron Smith }
305d504fe20SAaron Smith 
306d504fe20SAaron Smith bool RemoteAwarePlatform::SetRemoteWorkingDirectory(
307d504fe20SAaron Smith     const FileSpec &working_dir) {
308d504fe20SAaron Smith   if (IsRemote() && m_remote_platform_sp)
309d504fe20SAaron Smith     return m_remote_platform_sp->SetRemoteWorkingDirectory(working_dir);
310d504fe20SAaron Smith   return Platform::SetRemoteWorkingDirectory(working_dir);
311d504fe20SAaron Smith }
312d504fe20SAaron Smith 
31352d9c62aSPavel Labath Status RemoteAwarePlatform::GetFileWithUUID(const FileSpec &platform_file,
31452d9c62aSPavel Labath                                             const UUID *uuid_ptr,
31552d9c62aSPavel Labath                                             FileSpec &local_file) {
31652d9c62aSPavel Labath   if (IsRemote() && m_remote_platform_sp)
31752d9c62aSPavel Labath     return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
31852d9c62aSPavel Labath                                                  local_file);
31952d9c62aSPavel Labath 
32052d9c62aSPavel Labath   // Default to the local case
32152d9c62aSPavel Labath   local_file = platform_file;
32252d9c62aSPavel Labath   return Status();
32352d9c62aSPavel Labath }
32452d9c62aSPavel Labath 
32552d9c62aSPavel Labath bool RemoteAwarePlatform::GetRemoteOSVersion() {
32652d9c62aSPavel Labath   if (m_remote_platform_sp) {
32752d9c62aSPavel Labath     m_os_version = m_remote_platform_sp->GetOSVersion();
32852d9c62aSPavel Labath     return !m_os_version.empty();
32952d9c62aSPavel Labath   }
33052d9c62aSPavel Labath   return false;
33152d9c62aSPavel Labath }
33252d9c62aSPavel Labath 
33340e4ac3eSPavel Labath llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSBuildString() {
33452d9c62aSPavel Labath   if (m_remote_platform_sp)
33540e4ac3eSPavel Labath     return m_remote_platform_sp->GetRemoteOSBuildString();
33640e4ac3eSPavel Labath   return llvm::None;
33752d9c62aSPavel Labath }
33852d9c62aSPavel Labath 
339f5158ca4SPavel Labath llvm::Optional<std::string> RemoteAwarePlatform::GetRemoteOSKernelDescription() {
34052d9c62aSPavel Labath   if (m_remote_platform_sp)
341f5158ca4SPavel Labath     return m_remote_platform_sp->GetRemoteOSKernelDescription();
342f5158ca4SPavel Labath   return llvm::None;
34352d9c62aSPavel Labath }
34452d9c62aSPavel Labath 
34552d9c62aSPavel Labath ArchSpec RemoteAwarePlatform::GetRemoteSystemArchitecture() {
34652d9c62aSPavel Labath   if (m_remote_platform_sp)
34752d9c62aSPavel Labath     return m_remote_platform_sp->GetRemoteSystemArchitecture();
34852d9c62aSPavel Labath   return ArchSpec();
34952d9c62aSPavel Labath }
35052d9c62aSPavel Labath 
35152d9c62aSPavel Labath const char *RemoteAwarePlatform::GetHostname() {
35252d9c62aSPavel Labath   if (IsHost())
35352d9c62aSPavel Labath     return Platform::GetHostname();
35452d9c62aSPavel Labath   if (m_remote_platform_sp)
35552d9c62aSPavel Labath     return m_remote_platform_sp->GetHostname();
35652d9c62aSPavel Labath   return nullptr;
35752d9c62aSPavel Labath }
35852d9c62aSPavel Labath 
359aa51e6a6SPavel Labath UserIDResolver &RemoteAwarePlatform::GetUserIDResolver() {
360aa51e6a6SPavel Labath   if (IsHost())
361aa51e6a6SPavel Labath     return HostInfo::GetUserIDResolver();
362aa51e6a6SPavel Labath   if (m_remote_platform_sp)
363aa51e6a6SPavel Labath     return m_remote_platform_sp->GetUserIDResolver();
364aa51e6a6SPavel Labath   return UserIDResolver::GetNoopResolver();
36552d9c62aSPavel Labath }
36652d9c62aSPavel Labath 
36752d9c62aSPavel Labath Environment RemoteAwarePlatform::GetEnvironment() {
36852d9c62aSPavel Labath   if (IsRemote()) {
36952d9c62aSPavel Labath     if (m_remote_platform_sp)
37052d9c62aSPavel Labath       return m_remote_platform_sp->GetEnvironment();
37152d9c62aSPavel Labath     return Environment();
37252d9c62aSPavel Labath   }
37352d9c62aSPavel Labath   return Host::GetEnvironment();
37452d9c62aSPavel Labath }
37552d9c62aSPavel Labath 
37652d9c62aSPavel Labath bool RemoteAwarePlatform::IsConnected() const {
37752d9c62aSPavel Labath   if (IsHost())
37852d9c62aSPavel Labath     return true;
37952d9c62aSPavel Labath   else if (m_remote_platform_sp)
38052d9c62aSPavel Labath     return m_remote_platform_sp->IsConnected();
38152d9c62aSPavel Labath   return false;
38252d9c62aSPavel Labath }
38352d9c62aSPavel Labath 
38452d9c62aSPavel Labath bool RemoteAwarePlatform::GetProcessInfo(lldb::pid_t pid,
38552d9c62aSPavel Labath                                          ProcessInstanceInfo &process_info) {
38652d9c62aSPavel Labath   if (IsHost())
38752d9c62aSPavel Labath     return Platform::GetProcessInfo(pid, process_info);
38852d9c62aSPavel Labath   if (m_remote_platform_sp)
38952d9c62aSPavel Labath     return m_remote_platform_sp->GetProcessInfo(pid, process_info);
39052d9c62aSPavel Labath   return false;
39152d9c62aSPavel Labath }
39252d9c62aSPavel Labath 
39352d9c62aSPavel Labath uint32_t
39452d9c62aSPavel Labath RemoteAwarePlatform::FindProcesses(const ProcessInstanceInfoMatch &match_info,
39552d9c62aSPavel Labath                                    ProcessInstanceInfoList &process_infos) {
39652d9c62aSPavel Labath   if (IsHost())
39752d9c62aSPavel Labath     return Platform::FindProcesses(match_info, process_infos);
39852d9c62aSPavel Labath   if (m_remote_platform_sp)
39952d9c62aSPavel Labath     return m_remote_platform_sp->FindProcesses(match_info, process_infos);
40052d9c62aSPavel Labath   return 0;
40152d9c62aSPavel Labath }
40252d9c62aSPavel Labath 
403d504fe20SAaron Smith lldb::ProcessSP RemoteAwarePlatform::ConnectProcess(llvm::StringRef connect_url,
404d504fe20SAaron Smith                                                     llvm::StringRef plugin_name,
405d504fe20SAaron Smith                                                     Debugger &debugger,
406d504fe20SAaron Smith                                                     Target *target,
407d504fe20SAaron Smith                                                     Status &error) {
408d504fe20SAaron Smith   if (m_remote_platform_sp)
409d504fe20SAaron Smith     return m_remote_platform_sp->ConnectProcess(connect_url, plugin_name,
410d504fe20SAaron Smith                                                 debugger, target, error);
411d504fe20SAaron Smith   return Platform::ConnectProcess(connect_url, plugin_name, debugger, target,
412d504fe20SAaron Smith                                   error);
413d504fe20SAaron Smith }
414d504fe20SAaron Smith 
41552d9c62aSPavel Labath Status RemoteAwarePlatform::LaunchProcess(ProcessLaunchInfo &launch_info) {
41652d9c62aSPavel Labath   Status error;
41752d9c62aSPavel Labath 
41852d9c62aSPavel Labath   if (IsHost()) {
41952d9c62aSPavel Labath     error = Platform::LaunchProcess(launch_info);
42052d9c62aSPavel Labath   } else {
42152d9c62aSPavel Labath     if (m_remote_platform_sp)
42252d9c62aSPavel Labath       error = m_remote_platform_sp->LaunchProcess(launch_info);
42352d9c62aSPavel Labath     else
42452d9c62aSPavel Labath       error.SetErrorString("the platform is not currently connected");
42552d9c62aSPavel Labath   }
42652d9c62aSPavel Labath   return error;
42752d9c62aSPavel Labath }
428d504fe20SAaron Smith 
429d504fe20SAaron Smith Status RemoteAwarePlatform::KillProcess(const lldb::pid_t pid) {
430d504fe20SAaron Smith   if (IsHost())
431d504fe20SAaron Smith     return Platform::KillProcess(pid);
432d504fe20SAaron Smith   if (m_remote_platform_sp)
433d504fe20SAaron Smith     return m_remote_platform_sp->KillProcess(pid);
434d504fe20SAaron Smith   return Status("the platform is not currently connected");
435d504fe20SAaron Smith }
436463863ffSPavel Labath 
437463863ffSPavel Labath size_t RemoteAwarePlatform::ConnectToWaitingProcesses(Debugger &debugger,
438463863ffSPavel Labath                                                 Status &error) {
439463863ffSPavel Labath   if (m_remote_platform_sp)
440463863ffSPavel Labath     return m_remote_platform_sp->ConnectToWaitingProcesses(debugger, error);
441463863ffSPavel Labath   return Platform::ConnectToWaitingProcesses(debugger, error);
442463863ffSPavel Labath }
443