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
PlatformRemoteAppleBridge()31 PlatformRemoteAppleBridge::PlatformRemoteAppleBridge()
32 : PlatformRemoteDarwinDevice () {}
33
34 // Static Variables
35 static uint32_t g_initialize_count = 0;
36
37 // Static Functions
Initialize()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
Terminate()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
CreateInstance(bool force,const ArchSpec * arch)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
GetPluginNameStatic()136 lldb_private::ConstString PlatformRemoteAppleBridge::GetPluginNameStatic() {
137 static ConstString g_name("remote-bridgeos");
138 return g_name;
139 }
140
GetDescriptionStatic()141 const char *PlatformRemoteAppleBridge::GetDescriptionStatic() {
142 return "Remote BridgeOS platform plug-in.";
143 }
144
GetSupportedArchitectureAtIndex(uint32_t idx,ArchSpec & arch)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
GetDeviceSupportDirectoryName()175 llvm::StringRef PlatformRemoteAppleBridge::GetDeviceSupportDirectoryName() {
176 return "BridgeOS DeviceSupport";
177 }
178
GetPlatformName()179 llvm::StringRef PlatformRemoteAppleBridge::GetPlatformName() {
180 return "BridgeOS.platform";
181 }
182