LLDB  mainline
PlatformRemoteAppleWatch.cpp
Go to the documentation of this file.
1 //===-- PlatformRemoteAppleWatch.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 
13 
15 #include "lldb/Core/Module.h"
16 #include "lldb/Core/ModuleList.h"
17 #include "lldb/Core/ModuleSpec.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/Status.h"
27 
28 using namespace lldb;
29 using namespace lldb_private;
30 
31 // Static Variables
33 
34 // Static Functions
37 
38  if (g_initialize_count++ == 0) {
39  PluginManager::RegisterPlugin(
43  }
44 }
45 
47  if (g_initialize_count > 0) {
48  if (--g_initialize_count == 0) {
49  PluginManager::UnregisterPlugin(PlatformRemoteAppleWatch::CreateInstance);
50  }
51  }
52 
54 }
55 
57  const ArchSpec *arch) {
59  if (log) {
60  const char *arch_name;
61  if (arch && arch->GetArchitectureName())
62  arch_name = arch->GetArchitectureName();
63  else
64  arch_name = "<null>";
65 
66  const char *triple_cstr =
67  arch ? arch->GetTriple().getTriple().c_str() : "<null>";
68 
69  LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s(force=%s, arch={%s,%s})",
70  __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
71  }
72 
73  bool create = force;
74  if (!create && arch && arch->IsValid()) {
75  switch (arch->GetMachine()) {
76  case llvm::Triple::arm:
77  case llvm::Triple::aarch64:
78  case llvm::Triple::aarch64_32:
79  case llvm::Triple::thumb: {
80  const llvm::Triple &triple = arch->GetTriple();
81  llvm::Triple::VendorType vendor = triple.getVendor();
82  switch (vendor) {
83  case llvm::Triple::Apple:
84  create = true;
85  break;
86 
87 #if defined(__APPLE__)
88  // Only accept "unknown" for the vendor if the host is Apple and
89  // "unknown" wasn't specified (it was just returned because it was NOT
90  // specified)
91  case llvm::Triple::UnknownVendor:
92  create = !arch->TripleVendorWasSpecified();
93  break;
94 
95 #endif
96  default:
97  break;
98  }
99  if (create) {
100  switch (triple.getOS()) {
101  case llvm::Triple::WatchOS: // This is the right triple value for Apple
102  // Watch debugging
103  break;
104 
105  default:
106  create = false;
107  break;
108  }
109  }
110  } break;
111  default:
112  break;
113  }
114  }
115 
116 #if defined(__APPLE__) && \
117  (defined(__arm__) || defined(__arm64__) || defined(__aarch64__))
118  // If lldb is running on a watch, this isn't a RemoteWatch environment; it's
119  // a local system environment.
120  if (force == false) {
121  create = false;
122  }
123 #endif
124 
125  if (create) {
126  LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s() creating platform",
127  __FUNCTION__);
128 
129  return lldb::PlatformSP(new PlatformRemoteAppleWatch());
130  }
131 
132  LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s() aborting creation of platform",
133  __FUNCTION__);
134 
135  return lldb::PlatformSP();
136 }
137 
139  static ConstString g_name("remote-watchos");
140  return g_name;
141 }
142 
144  return "Remote Apple Watch platform plug-in.";
145 }
146 
147 /// Default Constructor
150 
152  ArchSpec &arch) {
153  ArchSpec system_arch(GetSystemArchitecture());
154 
155  const ArchSpec::Core system_core = system_arch.GetCore();
156  switch (system_core) {
157  default:
158  switch (idx) {
159  case 0:
160  arch.SetTriple("arm64-apple-watchos");
161  return true;
162  case 1:
163  arch.SetTriple("armv7k-apple-watchos");
164  return true;
165  case 2:
166  arch.SetTriple("armv7s-apple-watchos");
167  return true;
168  case 3:
169  arch.SetTriple("armv7-apple-watchos");
170  return true;
171  case 4:
172  arch.SetTriple("thumbv7k-apple-watchos");
173  return true;
174  case 5:
175  arch.SetTriple("thumbv7-apple-watchos");
176  return true;
177  case 6:
178  arch.SetTriple("thumbv7s-apple-watchos");
179  return true;
180  case 7:
181  arch.SetTriple("arm64_32-apple-watchos");
182  return true;
183  default:
184  break;
185  }
186  break;
187 
188  case ArchSpec::eCore_arm_arm64:
189  switch (idx) {
190  case 0:
191  arch.SetTriple("arm64-apple-watchos");
192  return true;
193  case 1:
194  arch.SetTriple("armv7k-apple-watchos");
195  return true;
196  case 2:
197  arch.SetTriple("armv7s-apple-watchos");
198  return true;
199  case 3:
200  arch.SetTriple("armv7-apple-watchos");
201  return true;
202  case 4:
203  arch.SetTriple("thumbv7k-apple-watchos");
204  return true;
205  case 5:
206  arch.SetTriple("thumbv7-apple-watchos");
207  return true;
208  case 6:
209  arch.SetTriple("thumbv7s-apple-watchos");
210  return true;
211  case 7:
212  arch.SetTriple("arm64_32-apple-watchos");
213  return true;
214  default:
215  break;
216  }
217  break;
218 
219  case ArchSpec::eCore_arm_armv7k:
220  switch (idx) {
221  case 0:
222  arch.SetTriple("armv7k-apple-watchos");
223  return true;
224  case 1:
225  arch.SetTriple("armv7s-apple-watchos");
226  return true;
227  case 2:
228  arch.SetTriple("armv7-apple-watchos");
229  return true;
230  case 3:
231  arch.SetTriple("thumbv7k-apple-watchos");
232  return true;
233  case 4:
234  arch.SetTriple("thumbv7-apple-watchos");
235  return true;
236  case 5:
237  arch.SetTriple("thumbv7s-apple-watchos");
238  return true;
239  case 6:
240  arch.SetTriple("arm64_32-apple-watchos");
241  return true;
242  default:
243  break;
244  }
245  break;
246 
247  case ArchSpec::eCore_arm_armv7s:
248  switch (idx) {
249  case 0:
250  arch.SetTriple("armv7s-apple-watchos");
251  return true;
252  case 1:
253  arch.SetTriple("armv7k-apple-watchos");
254  return true;
255  case 2:
256  arch.SetTriple("armv7-apple-watchos");
257  return true;
258  case 3:
259  arch.SetTriple("thumbv7k-apple-watchos");
260  return true;
261  case 4:
262  arch.SetTriple("thumbv7-apple-watchos");
263  return true;
264  case 5:
265  arch.SetTriple("thumbv7s-apple-watchos");
266  return true;
267  case 6:
268  arch.SetTriple("arm64_32-apple-watchos");
269  return true;
270  default:
271  break;
272  }
273  break;
274 
275  case ArchSpec::eCore_arm_armv7:
276  switch (idx) {
277  case 0:
278  arch.SetTriple("armv7-apple-watchos");
279  return true;
280  case 1:
281  arch.SetTriple("armv7k-apple-watchos");
282  return true;
283  case 2:
284  arch.SetTriple("thumbv7k-apple-watchos");
285  return true;
286  case 3:
287  arch.SetTriple("thumbv7-apple-watchos");
288  return true;
289  case 4:
290  arch.SetTriple("arm64_32-apple-watchos");
291  return true;
292  default:
293  break;
294  }
295  break;
296  }
297  arch.Clear();
298  return false;
299 }
300 
302  return "watchOS DeviceSupport";
303 }
304 
306  return "WatchOS.platform";
307 }
PlatformRemoteAppleWatch::GetDeviceSupportDirectoryName
llvm::StringRef GetDeviceSupportDirectoryName() override
Definition: PlatformRemoteAppleWatch.cpp:301
PlatformRemoteAppleWatch
Definition: PlatformRemoteAppleWatch.h:21
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ArchSpec::TripleVendorWasSpecified
bool TripleVendorWasSpecified() const
Definition: ArchSpec.h:347
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:667
ModuleSpec.h
Host.h
lldb_private::ArchSpec::GetCore
Core GetCore() const
Definition: ArchSpec.h:423
PlatformRemoteAppleWatch::Terminate
static void Terminate()
Definition: PlatformRemoteAppleWatch.cpp:46
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
Module.h
BreakpointLocation.h
PlatformRemoteAppleWatch::PlatformRemoteAppleWatch
PlatformRemoteAppleWatch()
Default Constructor.
Definition: PlatformRemoteAppleWatch.cpp:148
LIBLLDB_LOG_PLATFORM
#define LIBLLDB_LOG_PLATFORM
Definition: Logging.h:39
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
PlatformRemoteDarwinDevice
Definition: PlatformRemoteDarwinDevice.h:19
PlatformRemoteAppleWatch::GetSupportedArchitectureAtIndex
bool GetSupportedArchitectureAtIndex(uint32_t idx, lldb_private::ArchSpec &arch) override
Get the platform's supported architectures in the order in which they should be searched.
Definition: PlatformRemoteAppleWatch.cpp:151
Process.h
lldb_private::ArchSpec::Core
Core
Definition: ArchSpec.h:101
Target.h
lldb_private::Platform::GetSystemArchitecture
const ArchSpec & GetSystemArchitecture()
Definition: Platform.cpp:904
ModuleList.h
PlatformRemoteAppleWatch::GetPluginNameStatic
static lldb_private::ConstString GetPluginNameStatic()
Definition: PlatformRemoteAppleWatch.cpp:138
Log.h
PlatformRemoteAppleWatch::GetDescriptionStatic
static const char * GetDescriptionStatic()
Definition: PlatformRemoteAppleWatch.cpp:143
lldb_private::ArchSpec::SetTriple
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition: ArchSpec.cpp:739
g_initialize_count
static uint32_t g_initialize_count
Definition: PlatformRemoteAppleWatch.cpp:32
StreamString.h
PlatformRemoteAppleWatch::GetPlatformName
llvm::StringRef GetPlatformName() override
Definition: PlatformRemoteAppleWatch.cpp:305
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::Platform::Terminate
static void Terminate()
Definition: Platform.cpp:149
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::ArchSpec::IsValid
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:342
lldb_private::Platform::Initialize
static void Initialize()
Definition: Platform.cpp:147
lldb_private::ArchSpec::GetArchitectureName
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:538
uint32_t
ArchSpec.h
PluginManager.h
PlatformRemoteAppleWatch::Initialize
static void Initialize()
Definition: PlatformRemoteAppleWatch.cpp:35
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
PlatformRemoteAppleWatch::CreateInstance
static lldb::PlatformSP CreateInstance(bool force, const lldb_private::ArchSpec *arch)
Definition: PlatformRemoteAppleWatch.cpp:56
FileSpec.h
lldb_private::Log
Definition: Log.h:49
lldb_private::ArchSpec::Clear
void Clear()
Clears the object state.
Definition: ArchSpec.cpp:527
lldb
Definition: SBAddress.h:15
PlatformRemoteAppleWatch.h