1 //===-- PlatformRemoteAppleBridge.cpp -------------------------------------===// 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 "PlatformRemoteAppleBridge.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/StreamString.h" 26 27 using namespace lldb; 28 using namespace lldb_private; 29 30 /// Default Constructor 31 PlatformRemoteAppleBridge::PlatformRemoteAppleBridge() 32 : PlatformRemoteDarwinDevice () {} 33 34 // Static Variables 35 static uint32_t g_initialize_count = 0; 36 37 // Static Functions 38 void PlatformRemoteAppleBridge::Initialize() { 39 PlatformDarwin::Initialize(); 40 41 if (g_initialize_count++ == 0) { 42 PluginManager::RegisterPlugin(PlatformRemoteAppleBridge::GetPluginNameStatic(), 43 PlatformRemoteAppleBridge::GetDescriptionStatic(), 44 PlatformRemoteAppleBridge::CreateInstance); 45 } 46 } 47 48 void PlatformRemoteAppleBridge::Terminate() { 49 if (g_initialize_count > 0) { 50 if (--g_initialize_count == 0) { 51 PluginManager::UnregisterPlugin(PlatformRemoteAppleBridge::CreateInstance); 52 } 53 } 54 55 PlatformDarwin::Terminate(); 56 } 57 58 PlatformSP PlatformRemoteAppleBridge::CreateInstance(bool force, 59 const ArchSpec *arch) { 60 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); 61 if (log) { 62 const char *arch_name; 63 if (arch && arch->GetArchitectureName()) 64 arch_name = arch->GetArchitectureName(); 65 else 66 arch_name = "<null>"; 67 68 const char *triple_cstr = 69 arch ? arch->GetTriple().getTriple().c_str() : "<null>"; 70 71 LLDB_LOGF(log, "PlatformRemoteAppleBridge::%s(force=%s, arch={%s,%s})", 72 __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr); 73 } 74 75 bool create = force; 76 if (!create && arch && arch->IsValid()) { 77 switch (arch->GetMachine()) { 78 case llvm::Triple::aarch64: { 79 const llvm::Triple &triple = arch->GetTriple(); 80 llvm::Triple::VendorType vendor = triple.getVendor(); 81 switch (vendor) { 82 case llvm::Triple::Apple: 83 create = true; 84 break; 85 86 #if defined(__APPLE__) 87 // Only accept "unknown" for the vendor if the host is Apple and 88 // it "unknown" wasn't specified (it was just returned because it 89 // was NOT specified) 90 case llvm::Triple::UnknownVendor: 91 create = !arch->TripleVendorWasSpecified(); 92 break; 93 94 #endif 95 default: 96 break; 97 } 98 if (create) { 99 // Suppress warning "switch statement contains 'default' but no 'case' labels". 100 #ifdef _MSC_VER 101 #pragma warning(push) 102 #pragma warning(disable : 4065) 103 #endif 104 switch (triple.getOS()) { 105 // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS: 106 // break; 107 108 default: 109 create = false; 110 break; 111 } 112 #ifdef _MSC_VER 113 #pragma warning(pop) 114 #endif 115 } 116 } break; 117 default: 118 break; 119 } 120 } 121 122 if (create) { 123 LLDB_LOGF(log, "PlatformRemoteAppleBridge::%s() creating platform", 124 __FUNCTION__); 125 126 return lldb::PlatformSP(new PlatformRemoteAppleBridge()); 127 } 128 129 LLDB_LOGF(log, 130 "PlatformRemoteAppleBridge::%s() aborting creation of platform", 131 __FUNCTION__); 132 133 return lldb::PlatformSP(); 134 } 135 136 llvm::StringRef PlatformRemoteAppleBridge::GetDescriptionStatic() { 137 return "Remote BridgeOS platform plug-in."; 138 } 139 140 bool PlatformRemoteAppleBridge::GetSupportedArchitectureAtIndex(uint32_t idx, 141 ArchSpec &arch) { 142 ArchSpec system_arch(GetSystemArchitecture()); 143 144 const ArchSpec::Core system_core = system_arch.GetCore(); 145 switch (system_core) { 146 default: 147 switch (idx) { 148 case 0: 149 arch.SetTriple("arm64-apple-bridgeos"); 150 return true; 151 default: 152 break; 153 } 154 break; 155 156 case ArchSpec::eCore_arm_arm64: 157 switch (idx) { 158 case 0: 159 arch.SetTriple("arm64-apple-bridgeos"); 160 return true; 161 default: 162 break; 163 } 164 break; 165 } 166 arch.Clear(); 167 return false; 168 } 169 170 llvm::StringRef PlatformRemoteAppleBridge::GetDeviceSupportDirectoryName() { 171 return "BridgeOS DeviceSupport"; 172 } 173 174 llvm::StringRef PlatformRemoteAppleBridge::GetPlatformName() { 175 return "BridgeOS.platform"; 176 } 177