1 //===-- PlatformRemoteAppleBridge.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 <string> 11 #include <vector> 12 13 #include "PlatformRemoteAppleBridge.h" 14 15 #include "lldb/Breakpoint/BreakpointLocation.h" 16 #include "lldb/Core/Module.h" 17 #include "lldb/Core/ModuleList.h" 18 #include "lldb/Core/ModuleSpec.h" 19 #include "lldb/Core/PluginManager.h" 20 #include "lldb/Host/Host.h" 21 #include "lldb/Target/Process.h" 22 #include "lldb/Target/Target.h" 23 #include "lldb/Utility/ArchSpec.h" 24 #include "lldb/Utility/FileSpec.h" 25 #include "lldb/Utility/Log.h" 26 #include "lldb/Utility/StreamString.h" 27 28 using namespace lldb; 29 using namespace lldb_private; 30 31 //------------------------------------------------------------------ 32 /// Default Constructor 33 //------------------------------------------------------------------ 34 PlatformRemoteAppleBridge::PlatformRemoteAppleBridge() 35 : PlatformRemoteDarwinDevice () {} 36 37 //------------------------------------------------------------------ 38 // Static Variables 39 //------------------------------------------------------------------ 40 static uint32_t g_initialize_count = 0; 41 42 //------------------------------------------------------------------ 43 // Static Functions 44 //------------------------------------------------------------------ 45 void PlatformRemoteAppleBridge::Initialize() { 46 PlatformDarwin::Initialize(); 47 48 if (g_initialize_count++ == 0) { 49 PluginManager::RegisterPlugin(PlatformRemoteAppleBridge::GetPluginNameStatic(), 50 PlatformRemoteAppleBridge::GetDescriptionStatic(), 51 PlatformRemoteAppleBridge::CreateInstance); 52 } 53 } 54 55 void PlatformRemoteAppleBridge::Terminate() { 56 if (g_initialize_count > 0) { 57 if (--g_initialize_count == 0) { 58 PluginManager::UnregisterPlugin(PlatformRemoteAppleBridge::CreateInstance); 59 } 60 } 61 62 PlatformDarwin::Terminate(); 63 } 64 65 PlatformSP PlatformRemoteAppleBridge::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("PlatformRemoteAppleBridge::%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::aarch64: { 86 const llvm::Triple &triple = arch->GetTriple(); 87 llvm::Triple::VendorType vendor = triple.getVendor(); 88 switch (vendor) { 89 case llvm::Triple::Apple: 90 create = true; 91 break; 92 93 #if defined(__APPLE__) 94 // Only accept "unknown" for the vendor if the host is Apple and 95 // it "unknown" wasn't specified (it was just returned because it 96 // was NOT specified) 97 case llvm::Triple::UnknownArch: 98 create = !arch->TripleVendorWasSpecified(); 99 break; 100 101 #endif 102 default: 103 break; 104 } 105 if (create) { 106 switch (triple.getOS()) { 107 // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS: 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("PlatformRemoteAppleBridge::%s() creating platform", 124 __FUNCTION__); 125 126 return lldb::PlatformSP(new PlatformRemoteAppleBridge()); 127 } 128 129 if (log) 130 log->Printf("PlatformRemoteAppleBridge::%s() aborting creation of platform", 131 __FUNCTION__); 132 133 return lldb::PlatformSP(); 134 } 135 136 lldb_private::ConstString PlatformRemoteAppleBridge::GetPluginNameStatic() { 137 static ConstString g_name("remote-bridgeos"); 138 return g_name; 139 } 140 141 const char *PlatformRemoteAppleBridge::GetDescriptionStatic() { 142 return "Remote BridgeOS platform plug-in."; 143 } 144 145 bool PlatformRemoteAppleBridge::GetSupportedArchitectureAtIndex(uint32_t idx, 146 ArchSpec &arch) { 147 ArchSpec system_arch(GetSystemArchitecture()); 148 149 const ArchSpec::Core system_core = system_arch.GetCore(); 150 switch (system_core) { 151 default: 152 switch (idx) { 153 case 0: 154 arch.SetTriple("arm64-apple-bridgeos"); 155 return true; 156 default: 157 break; 158 } 159 break; 160 161 case ArchSpec::eCore_arm_arm64: 162 switch (idx) { 163 case 0: 164 arch.SetTriple("arm64-apple-bridgeos"); 165 return true; 166 default: 167 break; 168 } 169 break; 170 } 171 arch.Clear(); 172 return false; 173 } 174 175 176 void PlatformRemoteAppleBridge::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) 177 { 178 dirnames.clear(); 179 dirnames.push_back("BridgeOS DeviceSupport"); 180 } 181 182 std::string PlatformRemoteAppleBridge::GetPlatformName () 183 { 184 return "BridgeOS.platform"; 185 } 186 187