1 //===-- PlatformRemoteiOS.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 "PlatformRemoteiOS.h" 10 11 #include "lldb/Breakpoint/BreakpointLocation.h" 12 #include "lldb/Core/Module.h" 13 #include "lldb/Core/ModuleList.h" 14 #include "lldb/Core/ModuleSpec.h" 15 #include "lldb/Core/PluginManager.h" 16 #include "lldb/Host/Host.h" 17 #include "lldb/Target/Process.h" 18 #include "lldb/Target/Target.h" 19 #include "lldb/Utility/ArchSpec.h" 20 #include "lldb/Utility/FileSpec.h" 21 #include "lldb/Utility/Log.h" 22 #include "lldb/Utility/Status.h" 23 #include "lldb/Utility/StreamString.h" 24 25 using namespace lldb; 26 using namespace lldb_private; 27 28 //------------------------------------------------------------------ 29 // Static Variables 30 //------------------------------------------------------------------ 31 static uint32_t g_initialize_count = 0; 32 33 //------------------------------------------------------------------ 34 // Static Functions 35 //------------------------------------------------------------------ 36 void PlatformRemoteiOS::Initialize() { 37 PlatformDarwin::Initialize(); 38 39 if (g_initialize_count++ == 0) { 40 PluginManager::RegisterPlugin(PlatformRemoteiOS::GetPluginNameStatic(), 41 PlatformRemoteiOS::GetDescriptionStatic(), 42 PlatformRemoteiOS::CreateInstance); 43 } 44 } 45 46 void PlatformRemoteiOS::Terminate() { 47 if (g_initialize_count > 0) { 48 if (--g_initialize_count == 0) { 49 PluginManager::UnregisterPlugin(PlatformRemoteiOS::CreateInstance); 50 } 51 } 52 53 PlatformDarwin::Terminate(); 54 } 55 56 PlatformSP PlatformRemoteiOS::CreateInstance(bool force, const ArchSpec *arch) { 57 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); 58 if (log) { 59 const char *arch_name; 60 if (arch && arch->GetArchitectureName()) 61 arch_name = arch->GetArchitectureName(); 62 else 63 arch_name = "<null>"; 64 65 const char *triple_cstr = 66 arch ? arch->GetTriple().getTriple().c_str() : "<null>"; 67 68 log->Printf("PlatformRemoteiOS::%s(force=%s, arch={%s,%s})", __FUNCTION__, 69 force ? "true" : "false", arch_name, triple_cstr); 70 } 71 72 bool create = force; 73 if (!create && arch && arch->IsValid()) { 74 switch (arch->GetMachine()) { 75 case llvm::Triple::arm: 76 case llvm::Triple::aarch64: 77 case llvm::Triple::thumb: { 78 const llvm::Triple &triple = arch->GetTriple(); 79 llvm::Triple::VendorType vendor = triple.getVendor(); 80 switch (vendor) { 81 case llvm::Triple::Apple: 82 create = true; 83 break; 84 85 #if defined(__APPLE__) 86 // Only accept "unknown" for the vendor if the host is Apple and 87 // "unknown" wasn't specified (it was just returned because it was NOT 88 // specified) 89 case llvm::Triple::UnknownVendor: 90 create = !arch->TripleVendorWasSpecified(); 91 break; 92 93 #endif 94 default: 95 break; 96 } 97 if (create) { 98 switch (triple.getOS()) { 99 case llvm::Triple::Darwin: // Deprecated, but still support Darwin for 100 // historical reasons 101 case llvm::Triple::IOS: // This is the right triple value for iOS 102 // debugging 103 break; 104 105 default: 106 create = false; 107 break; 108 } 109 } 110 } break; 111 default: 112 break; 113 } 114 } 115 116 if (create) { 117 if (log) 118 log->Printf("PlatformRemoteiOS::%s() creating platform", __FUNCTION__); 119 120 return lldb::PlatformSP(new PlatformRemoteiOS()); 121 } 122 123 if (log) 124 log->Printf("PlatformRemoteiOS::%s() aborting creation of platform", 125 __FUNCTION__); 126 127 return lldb::PlatformSP(); 128 } 129 130 lldb_private::ConstString PlatformRemoteiOS::GetPluginNameStatic() { 131 static ConstString g_name("remote-ios"); 132 return g_name; 133 } 134 135 const char *PlatformRemoteiOS::GetDescriptionStatic() { 136 return "Remote iOS platform plug-in."; 137 } 138 139 //------------------------------------------------------------------ 140 /// Default Constructor 141 //------------------------------------------------------------------ 142 PlatformRemoteiOS::PlatformRemoteiOS() 143 : PlatformRemoteDarwinDevice() {} 144 145 bool PlatformRemoteiOS::GetSupportedArchitectureAtIndex(uint32_t idx, 146 ArchSpec &arch) { 147 return ARMGetSupportedArchitectureAtIndex(idx, arch); 148 } 149 150 151 void PlatformRemoteiOS::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) 152 { 153 dirnames.clear(); 154 dirnames.push_back("iOS DeviceSupport"); 155 } 156 157 std::string PlatformRemoteiOS::GetPlatformName () 158 { 159 return "iPhoneOS.platform"; 160 } 161