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