LLDB  mainline
PlatformRemoteAppleTV.cpp
Go to the documentation of this file.
1 //===-- PlatformRemoteAppleTV.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 "PlatformRemoteAppleTV.h"
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 /// Default Constructor
34 
35 // Static Variables
37 
38 // Static Functions
41 
42  if (g_initialize_count++ == 0) {
43  PluginManager::RegisterPlugin(PlatformRemoteAppleTV::GetPluginNameStatic(),
46  }
47 }
48 
50  if (g_initialize_count > 0) {
51  if (--g_initialize_count == 0) {
52  PluginManager::UnregisterPlugin(PlatformRemoteAppleTV::CreateInstance);
53  }
54  }
55 
57 }
58 
60  const ArchSpec *arch) {
62  if (log) {
63  const char *arch_name;
64  if (arch && arch->GetArchitectureName())
65  arch_name = arch->GetArchitectureName();
66  else
67  arch_name = "<null>";
68 
69  const char *triple_cstr =
70  arch ? arch->GetTriple().getTriple().c_str() : "<null>";
71 
72  LLDB_LOGF(log, "PlatformRemoteAppleTV::%s(force=%s, arch={%s,%s})",
73  __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
74  }
75 
76  bool create = force;
77  if (!create && arch && arch->IsValid()) {
78  switch (arch->GetMachine()) {
79  case llvm::Triple::arm:
80  case llvm::Triple::aarch64:
81  case llvm::Triple::thumb: {
82  const llvm::Triple &triple = arch->GetTriple();
83  llvm::Triple::VendorType vendor = triple.getVendor();
84  switch (vendor) {
85  case llvm::Triple::Apple:
86  create = true;
87  break;
88 
89 #if defined(__APPLE__)
90  // Only accept "unknown" for the vendor if the host is Apple and
91  // "unknown" wasn't specified (it was just returned because it was NOT
92  // specified)
93  case llvm::Triple::UnknownVendor:
94  create = !arch->TripleVendorWasSpecified();
95  break;
96 
97 #endif
98  default:
99  break;
100  }
101  if (create) {
102  switch (triple.getOS()) {
103  case llvm::Triple::TvOS: // This is the right triple value for Apple TV
104  // debugging
105  break;
106 
107  default:
108  create = false;
109  break;
110  }
111  }
112  } break;
113  default:
114  break;
115  }
116  }
117 
118  if (create) {
119  LLDB_LOGF(log, "PlatformRemoteAppleTV::%s() creating platform",
120  __FUNCTION__);
121 
122  return lldb::PlatformSP(new PlatformRemoteAppleTV());
123  }
124 
125  LLDB_LOGF(log, "PlatformRemoteAppleTV::%s() aborting creation of platform",
126  __FUNCTION__);
127 
128  return lldb::PlatformSP();
129 }
130 
132  static ConstString g_name("remote-tvos");
133  return g_name;
134 }
135 
137  return "Remote Apple TV platform plug-in.";
138 }
139 
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-tvos");
150  return true;
151  case 1:
152  arch.SetTriple("armv7s-apple-tvos");
153  return true;
154  case 2:
155  arch.SetTriple("armv7-apple-tvos");
156  return true;
157  case 3:
158  arch.SetTriple("thumbv7s-apple-tvos");
159  return true;
160  case 4:
161  arch.SetTriple("thumbv7-apple-tvos");
162  return true;
163  default:
164  break;
165  }
166  break;
167 
168  case ArchSpec::eCore_arm_arm64:
169  switch (idx) {
170  case 0:
171  arch.SetTriple("arm64-apple-tvos");
172  return true;
173  case 1:
174  arch.SetTriple("armv7s-apple-tvos");
175  return true;
176  case 2:
177  arch.SetTriple("armv7-apple-tvos");
178  return true;
179  case 3:
180  arch.SetTriple("thumbv7s-apple-tvos");
181  return true;
182  case 4:
183  arch.SetTriple("thumbv7-apple-tvos");
184  return true;
185  default:
186  break;
187  }
188  break;
189 
190  case ArchSpec::eCore_arm_armv7s:
191  switch (idx) {
192  case 0:
193  arch.SetTriple("armv7s-apple-tvos");
194  return true;
195  case 1:
196  arch.SetTriple("armv7-apple-tvos");
197  return true;
198  case 2:
199  arch.SetTriple("thumbv7s-apple-tvos");
200  return true;
201  case 3:
202  arch.SetTriple("thumbv7-apple-tvos");
203  return true;
204  default:
205  break;
206  }
207  break;
208 
209  case ArchSpec::eCore_arm_armv7:
210  switch (idx) {
211  case 0:
212  arch.SetTriple("armv7-apple-tvos");
213  return true;
214  case 1:
215  arch.SetTriple("thumbv7-apple-tvos");
216  return true;
217  default:
218  break;
219  }
220  break;
221  }
222  arch.Clear();
223  return false;
224 }
225 
227  return "tvOS DeviceSupport";
228 }
229 
231  return "AppleTVOS.platform";
232 }
PlatformRemoteAppleTV.h
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ArchSpec::TripleVendorWasSpecified
bool TripleVendorWasSpecified() const
Definition: ArchSpec.h:347
PlatformRemoteAppleTV::Initialize
static void Initialize()
Definition: PlatformRemoteAppleTV.cpp:39
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:667
ModuleSpec.h
PlatformRemoteAppleTV::GetDescriptionStatic
static const char * GetDescriptionStatic()
Definition: PlatformRemoteAppleTV.cpp:136
Host.h
lldb_private::ArchSpec::GetCore
Core GetCore() const
Definition: ArchSpec.h:423
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
PlatformRemoteAppleTV::GetPlatformName
llvm::StringRef GetPlatformName() override
Definition: PlatformRemoteAppleTV.cpp:230
Module.h
BreakpointLocation.h
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
PlatformRemoteAppleTV::CreateInstance
static lldb::PlatformSP CreateInstance(bool force, const lldb_private::ArchSpec *arch)
Definition: PlatformRemoteAppleTV.cpp:59
PlatformRemoteDarwinDevice
Definition: PlatformRemoteDarwinDevice.h:19
Process.h
lldb_private::ArchSpec::Core
Core
Definition: ArchSpec.h:101
Target.h
lldb_private::Platform::GetSystemArchitecture
const ArchSpec & GetSystemArchitecture()
Definition: Platform.cpp:904
PlatformRemoteAppleTV::PlatformRemoteAppleTV
PlatformRemoteAppleTV()
Default Constructor.
Definition: PlatformRemoteAppleTV.cpp:32
ModuleList.h
Log.h
lldb_private::ArchSpec::SetTriple
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition: ArchSpec.cpp:739
StreamString.h
g_initialize_count
static uint32_t g_initialize_count
Definition: PlatformRemoteAppleTV.cpp:36
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
PlatformRemoteAppleTV::GetPluginNameStatic
static lldb_private::ConstString GetPluginNameStatic()
Definition: PlatformRemoteAppleTV.cpp:131
PlatformRemoteAppleTV::GetDeviceSupportDirectoryName
llvm::StringRef GetDeviceSupportDirectoryName() override
Definition: PlatformRemoteAppleTV.cpp:226
PlatformRemoteAppleTV::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: PlatformRemoteAppleTV.cpp:140
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
PlatformRemoteAppleTV::Terminate
static void Terminate()
Definition: PlatformRemoteAppleTV.cpp:49
uint32_t
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:49
lldb_private::ArchSpec::Clear
void Clear()
Clears the object state.
Definition: ArchSpec.cpp:527
lldb
Definition: SBAddress.h:15