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 9 #include "lldb/Target/RemoteAwarePlatform.h" 10 #include "lldb/Host/Host.h" 11 12 using namespace lldb_private; 13 14 bool RemoteAwarePlatform::GetModuleSpec(const FileSpec &module_file_spec, 15 const ArchSpec &arch, 16 ModuleSpec &module_spec) { 17 if (m_remote_platform_sp) 18 return m_remote_platform_sp->GetModuleSpec(module_file_spec, arch, 19 module_spec); 20 21 return Platform::GetModuleSpec(module_file_spec, arch, module_spec); 22 } 23 24 Status RemoteAwarePlatform::GetFileWithUUID(const FileSpec &platform_file, 25 const UUID *uuid_ptr, 26 FileSpec &local_file) { 27 if (IsRemote() && m_remote_platform_sp) 28 return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr, 29 local_file); 30 31 // Default to the local case 32 local_file = platform_file; 33 return Status(); 34 } 35 36 bool RemoteAwarePlatform::GetRemoteOSVersion() { 37 if (m_remote_platform_sp) { 38 m_os_version = m_remote_platform_sp->GetOSVersion(); 39 return !m_os_version.empty(); 40 } 41 return false; 42 } 43 44 bool RemoteAwarePlatform::GetRemoteOSBuildString(std::string &s) { 45 if (m_remote_platform_sp) 46 return m_remote_platform_sp->GetRemoteOSBuildString(s); 47 s.clear(); 48 return false; 49 } 50 51 bool RemoteAwarePlatform::GetRemoteOSKernelDescription(std::string &s) { 52 if (m_remote_platform_sp) 53 return m_remote_platform_sp->GetRemoteOSKernelDescription(s); 54 s.clear(); 55 return false; 56 } 57 58 ArchSpec RemoteAwarePlatform::GetRemoteSystemArchitecture() { 59 if (m_remote_platform_sp) 60 return m_remote_platform_sp->GetRemoteSystemArchitecture(); 61 return ArchSpec(); 62 } 63 64 const char *RemoteAwarePlatform::GetHostname() { 65 if (IsHost()) 66 return Platform::GetHostname(); 67 68 if (m_remote_platform_sp) 69 return m_remote_platform_sp->GetHostname(); 70 return nullptr; 71 } 72 73 const char *RemoteAwarePlatform::GetUserName(uint32_t uid) { 74 // Check the cache in Platform in case we have already looked this uid up 75 const char *user_name = Platform::GetUserName(uid); 76 if (user_name) 77 return user_name; 78 79 if (IsRemote() && m_remote_platform_sp) 80 return m_remote_platform_sp->GetUserName(uid); 81 return nullptr; 82 } 83 84 const char *RemoteAwarePlatform::GetGroupName(uint32_t gid) { 85 const char *group_name = Platform::GetGroupName(gid); 86 if (group_name) 87 return group_name; 88 89 if (IsRemote() && m_remote_platform_sp) 90 return m_remote_platform_sp->GetGroupName(gid); 91 return nullptr; 92 } 93 94 Environment RemoteAwarePlatform::GetEnvironment() { 95 if (IsRemote()) { 96 if (m_remote_platform_sp) 97 return m_remote_platform_sp->GetEnvironment(); 98 return Environment(); 99 } 100 return Host::GetEnvironment(); 101 } 102 103 bool RemoteAwarePlatform::IsConnected() const { 104 if (IsHost()) 105 return true; 106 else if (m_remote_platform_sp) 107 return m_remote_platform_sp->IsConnected(); 108 return false; 109 } 110 111 bool RemoteAwarePlatform::GetProcessInfo(lldb::pid_t pid, 112 ProcessInstanceInfo &process_info) { 113 if (IsHost()) 114 return Platform::GetProcessInfo(pid, process_info); 115 if (m_remote_platform_sp) 116 return m_remote_platform_sp->GetProcessInfo(pid, process_info); 117 return false; 118 } 119 120 uint32_t 121 RemoteAwarePlatform::FindProcesses(const ProcessInstanceInfoMatch &match_info, 122 ProcessInstanceInfoList &process_infos) { 123 if (IsHost()) 124 return Platform::FindProcesses(match_info, process_infos); 125 if (m_remote_platform_sp) 126 return m_remote_platform_sp->FindProcesses(match_info, process_infos); 127 return 0; 128 } 129 130 Status RemoteAwarePlatform::LaunchProcess(ProcessLaunchInfo &launch_info) { 131 Status error; 132 133 if (IsHost()) { 134 error = Platform::LaunchProcess(launch_info); 135 } else { 136 if (m_remote_platform_sp) 137 error = m_remote_platform_sp->LaunchProcess(launch_info); 138 else 139 error.SetErrorString("the platform is not currently connected"); 140 } 141 return error; 142 } 143