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/LLDBLog.h"
25 #include "lldb/Utility/Log.h"
26 #include "lldb/Utility/Status.h"
28 
29 using namespace lldb;
30 using namespace lldb_private;
31 
32 // Static Variables
34 
35 // Static Functions
36 void PlatformRemoteAppleWatch::Initialize() {
37  PlatformDarwin::Initialize();
38 
39  if (g_initialize_count++ == 0) {
40  PluginManager::RegisterPlugin(
41  PlatformRemoteAppleWatch::GetPluginNameStatic(),
42  PlatformRemoteAppleWatch::GetDescriptionStatic(),
43  PlatformRemoteAppleWatch::CreateInstance);
44  }
45 }
46 
47 void PlatformRemoteAppleWatch::Terminate() {
48  if (g_initialize_count > 0) {
49  if (--g_initialize_count == 0) {
50  PluginManager::UnregisterPlugin(PlatformRemoteAppleWatch::CreateInstance);
51  }
52  }
53 
54  PlatformDarwin::Terminate();
55 }
56 
57 PlatformSP PlatformRemoteAppleWatch::CreateInstance(bool force,
58  const ArchSpec *arch) {
59  Log *log = GetLog(LLDBLog::Platform);
60  if (log) {
61  const char *arch_name;
62  if (arch && arch->GetArchitectureName())
63  arch_name = arch->GetArchitectureName();
64  else
65  arch_name = "<null>";
66 
67  const char *triple_cstr =
68  arch ? arch->GetTriple().getTriple().c_str() : "<null>";
69 
70  LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s(force=%s, arch={%s,%s})",
71  __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
72  }
73 
74  bool create = force;
75  if (!create && arch && arch->IsValid()) {
76  switch (arch->GetMachine()) {
77  case llvm::Triple::arm:
78  case llvm::Triple::aarch64:
79  case llvm::Triple::aarch64_32:
80  case llvm::Triple::thumb: {
81  const llvm::Triple &triple = arch->GetTriple();
82  llvm::Triple::VendorType vendor = triple.getVendor();
83  switch (vendor) {
84  case llvm::Triple::Apple:
85  create = true;
86  break;
87 
88 #if defined(__APPLE__)
89  // Only accept "unknown" for the vendor if the host is Apple and
90  // "unknown" wasn't specified (it was just returned because it was NOT
91  // specified)
92  case llvm::Triple::UnknownVendor:
93  create = !arch->TripleVendorWasSpecified();
94  break;
95 
96 #endif
97  default:
98  break;
99  }
100  if (create) {
101  switch (triple.getOS()) {
102  case llvm::Triple::WatchOS: // This is the right triple value for Apple
103  // Watch debugging
104  break;
105 
106  default:
107  create = false;
108  break;
109  }
110  }
111  } break;
112  default:
113  break;
114  }
115  }
116 
117 #if defined(__APPLE__) && \
118  (defined(__arm__) || defined(__arm64__) || defined(__aarch64__))
119  // If lldb is running on a watch, this isn't a RemoteWatch environment; it's
120  // a local system environment.
121  if (force == false) {
122  create = false;
123  }
124 #endif
125 
126  if (create) {
127  LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s() creating platform",
128  __FUNCTION__);
129 
130  return lldb::PlatformSP(new PlatformRemoteAppleWatch());
131  }
132 
133  LLDB_LOGF(log, "PlatformRemoteAppleWatch::%s() aborting creation of platform",
134  __FUNCTION__);
135 
136  return lldb::PlatformSP();
137 }
138 
139 llvm::StringRef PlatformRemoteAppleWatch::GetDescriptionStatic() {
140  return "Remote Apple Watch platform plug-in.";
141 }
142 
143 /// Default Constructor
144 PlatformRemoteAppleWatch::PlatformRemoteAppleWatch()
146 
147 std::vector<ArchSpec>
149  ArchSpec system_arch(GetSystemArchitecture());
150 
151  const ArchSpec::Core system_core = system_arch.GetCore();
152  switch (system_core) {
153  default:
155  return {
156  ArchSpec("arm64-apple-watchos"), ArchSpec("armv7k-apple-watchos"),
157  ArchSpec("armv7s-apple-watchos"), ArchSpec("armv7-apple-watchos"),
158  ArchSpec("thumbv7k-apple-watchos"), ArchSpec("thumbv7-apple-watchos"),
159  ArchSpec("thumbv7s-apple-watchos"), ArchSpec("arm64_32-apple-watchos")};
160 
162  return {
163  ArchSpec("armv7k-apple-watchos"), ArchSpec("armv7s-apple-watchos"),
164  ArchSpec("armv7-apple-watchos"), ArchSpec("thumbv7k-apple-watchos"),
165  ArchSpec("thumbv7-apple-watchos"), ArchSpec("thumbv7s-apple-watchos"),
166  ArchSpec("arm64_32-apple-watchos")};
167 
169  return {
170  ArchSpec("armv7s-apple-watchos"), ArchSpec("armv7k-apple-watchos"),
171  ArchSpec("armv7-apple-watchos"), ArchSpec("thumbv7k-apple-watchos"),
172  ArchSpec("thumbv7-apple-watchos"), ArchSpec("thumbv7s-apple-watchos"),
173  ArchSpec("arm64_32-apple-watchos")};
174 
176  return {ArchSpec("armv7-apple-watchos"), ArchSpec("armv7k-apple-watchos"),
177  ArchSpec("thumbv7k-apple-watchos"),
178  ArchSpec("thumbv7-apple-watchos"),
179  ArchSpec("arm64_32-apple-watchos")};
180  }
181 }
182 
184  return "watchOS DeviceSupport";
185 }
186 
188  return "WatchOS.platform";
189 }
lldb_private::ArchSpec::eCore_arm_armv7k
@ eCore_arm_armv7k
Definition: ArchSpec.h:125
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ArchSpec::TripleVendorWasSpecified
bool TripleVendorWasSpecified() const
Definition: ArchSpec.h:358
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:668
ModuleSpec.h
Host.h
lldb_private::ArchSpec::GetCore
Core GetCore() const
Definition: ArchSpec.h:434
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:343
Module.h
BreakpointLocation.h
lldb_private::ArchSpec::eCore_arm_arm64
@ eCore_arm_arm64
Definition: ArchSpec.h:142
lldb_private::PlatformRemoteAppleWatch::GetSupportedArchitectures
std::vector< ArchSpec > GetSupportedArchitectures(const ArchSpec &process_host_arch) override
Get the platform's supported architectures in the order in which they should be searched.
Definition: PlatformRemoteAppleWatch.cpp:148
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:455
Process.h
lldb_private::ArchSpec::Core
Core
Definition: ArchSpec.h:112
lldb_private::PlatformRemoteAppleWatch::GetDeviceSupportDirectoryName
llvm::StringRef GetDeviceSupportDirectoryName() override
Definition: PlatformRemoteAppleWatch.cpp:183
Target.h
lldb_private::Platform::GetSystemArchitecture
const ArchSpec & GetSystemArchitecture()
Definition: Platform.cpp:885
ModuleList.h
Log.h
g_initialize_count
static uint32_t g_initialize_count
Definition: PlatformRemoteAppleWatch.cpp:33
lldb_private::PlatformRemoteAppleWatch::GetPlatformName
llvm::StringRef GetPlatformName() override
Definition: PlatformRemoteAppleWatch.cpp:187
StreamString.h
lldb_private::ArchSpec::eCore_arm_armv7
@ eCore_arm_armv7
Definition: ArchSpec.h:121
lldb_private::PlatformRemoteDarwinDevice
Definition: PlatformRemoteDarwinDevice.h:36
lldb_private::ArchSpec::IsValid
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:353
lldb_private::ArchSpec::GetArchitectureName
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:539
lldb_private::PlatformRemoteAppleWatch
Definition: PlatformRemoteAppleWatch.h:21
uint32_t
lldb_private::ArchSpec::eCore_arm_armv7s
@ eCore_arm_armv7s
Definition: ArchSpec.h:124
ArchSpec.h
PluginManager.h
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
FileSpec.h
lldb_private::Log
Definition: Log.h:115
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:308
lldb
Definition: SBAddress.h:15
LLDBLog.h
PlatformRemoteAppleWatch.h