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