1 //===-- PlatformRemoteAppleWatch.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 <string> 10 #include <vector> 11 12 #include "PlatformRemoteAppleWatch.h" 13 14 #include "lldb/Breakpoint/BreakpointLocation.h" 15 #include "lldb/Core/Module.h" 16 #include "lldb/Core/ModuleList.h" 17 #include "lldb/Core/ModuleSpec.h" 18 #include "lldb/Core/PluginManager.h" 19 #include "lldb/Host/Host.h" 20 #include "lldb/Target/Process.h" 21 #include "lldb/Target/Target.h" 22 #include "lldb/Utility/ArchSpec.h" 23 #include "lldb/Utility/FileSpec.h" 24 #include "lldb/Utility/Log.h" 25 #include "lldb/Utility/Status.h" 26 #include "lldb/Utility/StreamString.h" 27 28 using namespace lldb; 29 using namespace lldb_private; 30 31 // Static Variables 32 static uint32_t g_initialize_count = 0; 33 34 // Static Functions 35 void PlatformRemoteAppleWatch::Initialize() { 36 PlatformDarwin::Initialize(); 37 38 if (g_initialize_count++ == 0) { 39 PluginManager::RegisterPlugin( 40 PlatformRemoteAppleWatch::GetPluginNameStatic(), 41 PlatformRemoteAppleWatch::GetDescriptionStatic(), 42 PlatformRemoteAppleWatch::CreateInstance); 43 } 44 } 45 46 void PlatformRemoteAppleWatch::Terminate() { 47 if (g_initialize_count > 0) { 48 if (--g_initialize_count == 0) { 49 PluginManager::UnregisterPlugin(PlatformRemoteAppleWatch::CreateInstance); 50 } 51 } 52 53 PlatformDarwin::Terminate(); 54 } 55 56 PlatformSP PlatformRemoteAppleWatch::CreateInstance(bool force, 57 const ArchSpec *arch) { 58 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); 59 if (log) { 60 const char *arch_name; 61 if (arch && arch->GetArchitectureName()) 62 arch_name = arch->GetArchitectureName(); 63 else 64 arch_name = "<null>"; 65 66 const char *triple_cstr = 67 arch ? arch->GetTriple().getTriple().c_str() : "<null>"; 68 69 LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s(force=%s, arch={%s,%s})", 70 __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr); 71 } 72 73 bool create = force; 74 if (!create && arch && arch->IsValid()) { 75 switch (arch->GetMachine()) { 76 case llvm::Triple::arm: 77 case llvm::Triple::aarch64: 78 case llvm::Triple::aarch64_32: 79 case llvm::Triple::thumb: { 80 const llvm::Triple &triple = arch->GetTriple(); 81 llvm::Triple::VendorType vendor = triple.getVendor(); 82 switch (vendor) { 83 case llvm::Triple::Apple: 84 create = true; 85 break; 86 87 #if defined(__APPLE__) 88 // Only accept "unknown" for the vendor if the host is Apple and 89 // "unknown" wasn't specified (it was just returned because it was NOT 90 // specified) 91 case llvm::Triple::UnknownVendor: 92 create = !arch->TripleVendorWasSpecified(); 93 break; 94 95 #endif 96 default: 97 break; 98 } 99 if (create) { 100 switch (triple.getOS()) { 101 case llvm::Triple::WatchOS: // This is the right triple value for Apple 102 // Watch debugging 103 break; 104 105 default: 106 create = false; 107 break; 108 } 109 } 110 } break; 111 default: 112 break; 113 } 114 } 115 116 #if defined(__APPLE__) && \ 117 (defined(__arm__) || defined(__arm64__) || defined(__aarch64__)) 118 // If lldb is running on a watch, this isn't a RemoteWatch environment; it's 119 // a local system environment. 120 if (force == false) { 121 create = false; 122 } 123 #endif 124 125 if (create) { 126 LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s() creating platform", 127 __FUNCTION__); 128 129 return lldb::PlatformSP(new PlatformRemoteAppleWatch()); 130 } 131 132 LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s() aborting creation of platform", 133 __FUNCTION__); 134 135 return lldb::PlatformSP(); 136 } 137 138 lldb_private::ConstString PlatformRemoteAppleWatch::GetPluginNameStatic() { 139 static ConstString g_name("remote-watchos"); 140 return g_name; 141 } 142 143 const char *PlatformRemoteAppleWatch::GetDescriptionStatic() { 144 return "Remote Apple Watch platform plug-in."; 145 } 146 147 /// Default Constructor 148 PlatformRemoteAppleWatch::PlatformRemoteAppleWatch() 149 : PlatformRemoteDarwinDevice() {} 150 151 bool PlatformRemoteAppleWatch::GetSupportedArchitectureAtIndex(uint32_t idx, 152 ArchSpec &arch) { 153 ArchSpec system_arch(GetSystemArchitecture()); 154 155 const ArchSpec::Core system_core = system_arch.GetCore(); 156 switch (system_core) { 157 default: 158 switch (idx) { 159 case 0: 160 arch.SetTriple("arm64-apple-watchos"); 161 return true; 162 case 1: 163 arch.SetTriple("armv7k-apple-watchos"); 164 return true; 165 case 2: 166 arch.SetTriple("armv7s-apple-watchos"); 167 return true; 168 case 3: 169 arch.SetTriple("armv7-apple-watchos"); 170 return true; 171 case 4: 172 arch.SetTriple("thumbv7k-apple-watchos"); 173 return true; 174 case 5: 175 arch.SetTriple("thumbv7-apple-watchos"); 176 return true; 177 case 6: 178 arch.SetTriple("thumbv7s-apple-watchos"); 179 return true; 180 case 7: 181 arch.SetTriple("arm64_32-apple-watchos"); 182 return true; 183 default: 184 break; 185 } 186 break; 187 188 case ArchSpec::eCore_arm_arm64: 189 switch (idx) { 190 case 0: 191 arch.SetTriple("arm64-apple-watchos"); 192 return true; 193 case 1: 194 arch.SetTriple("armv7k-apple-watchos"); 195 return true; 196 case 2: 197 arch.SetTriple("armv7s-apple-watchos"); 198 return true; 199 case 3: 200 arch.SetTriple("armv7-apple-watchos"); 201 return true; 202 case 4: 203 arch.SetTriple("thumbv7k-apple-watchos"); 204 return true; 205 case 5: 206 arch.SetTriple("thumbv7-apple-watchos"); 207 return true; 208 case 6: 209 arch.SetTriple("thumbv7s-apple-watchos"); 210 return true; 211 case 7: 212 arch.SetTriple("arm64_32-apple-watchos"); 213 return true; 214 default: 215 break; 216 } 217 break; 218 219 case ArchSpec::eCore_arm_armv7k: 220 switch (idx) { 221 case 0: 222 arch.SetTriple("armv7k-apple-watchos"); 223 return true; 224 case 1: 225 arch.SetTriple("armv7s-apple-watchos"); 226 return true; 227 case 2: 228 arch.SetTriple("armv7-apple-watchos"); 229 return true; 230 case 3: 231 arch.SetTriple("thumbv7k-apple-watchos"); 232 return true; 233 case 4: 234 arch.SetTriple("thumbv7-apple-watchos"); 235 return true; 236 case 5: 237 arch.SetTriple("thumbv7s-apple-watchos"); 238 return true; 239 case 6: 240 arch.SetTriple("arm64_32-apple-watchos"); 241 return true; 242 default: 243 break; 244 } 245 break; 246 247 case ArchSpec::eCore_arm_armv7s: 248 switch (idx) { 249 case 0: 250 arch.SetTriple("armv7s-apple-watchos"); 251 return true; 252 case 1: 253 arch.SetTriple("armv7k-apple-watchos"); 254 return true; 255 case 2: 256 arch.SetTriple("armv7-apple-watchos"); 257 return true; 258 case 3: 259 arch.SetTriple("thumbv7k-apple-watchos"); 260 return true; 261 case 4: 262 arch.SetTriple("thumbv7-apple-watchos"); 263 return true; 264 case 5: 265 arch.SetTriple("thumbv7s-apple-watchos"); 266 return true; 267 case 6: 268 arch.SetTriple("arm64_32-apple-watchos"); 269 return true; 270 default: 271 break; 272 } 273 break; 274 275 case ArchSpec::eCore_arm_armv7: 276 switch (idx) { 277 case 0: 278 arch.SetTriple("armv7-apple-watchos"); 279 return true; 280 case 1: 281 arch.SetTriple("armv7k-apple-watchos"); 282 return true; 283 case 2: 284 arch.SetTriple("thumbv7k-apple-watchos"); 285 return true; 286 case 3: 287 arch.SetTriple("thumbv7-apple-watchos"); 288 return true; 289 case 4: 290 arch.SetTriple("arm64_32-apple-watchos"); 291 return true; 292 default: 293 break; 294 } 295 break; 296 } 297 arch.Clear(); 298 return false; 299 } 300 301 void PlatformRemoteAppleWatch::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) 302 { 303 dirnames.clear(); 304 dirnames.push_back("watchOS DeviceSupport"); 305 } 306 307 std::string PlatformRemoteAppleWatch::GetPlatformName () 308 { 309 return "WatchOS.platform"; 310 } 311