LLDB  mainline
PlatformRemoteAppleBridge.cpp
Go to the documentation of this file.
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 
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"
26 
27 using namespace lldb;
28 using namespace lldb_private;
29 
30 /// Default Constructor
33 
34 // Static Variables
36 
37 // Static Functions
40 
41  if (g_initialize_count++ == 0) {
42  PluginManager::RegisterPlugin(PlatformRemoteAppleBridge::GetPluginNameStatic(),
45  }
46 }
47 
49  if (g_initialize_count > 0) {
50  if (--g_initialize_count == 0) {
51  PluginManager::UnregisterPlugin(PlatformRemoteAppleBridge::CreateInstance);
52  }
53  }
54 
56 }
57 
59  const ArchSpec *arch) {
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 
137  static ConstString g_name("remote-bridgeos");
138  return g_name;
139 }
140 
142  return "Remote BridgeOS platform plug-in.";
143 }
144 
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 
176  return "BridgeOS DeviceSupport";
177 }
178 
180  return "BridgeOS.platform";
181 }
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
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
Module.h
BreakpointLocation.h
PlatformRemoteAppleBridge::GetPluginNameStatic
static lldb_private::ConstString GetPluginNameStatic()
Definition: PlatformRemoteAppleBridge.cpp:136
PlatformRemoteAppleBridge::GetDescriptionStatic
static const char * GetDescriptionStatic()
Definition: PlatformRemoteAppleBridge.cpp:141
LIBLLDB_LOG_PLATFORM
#define LIBLLDB_LOG_PLATFORM
Definition: Logging.h:39
g_initialize_count
static uint32_t g_initialize_count
Definition: PlatformRemoteAppleBridge.cpp:35
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
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
ModuleList.h
Log.h
PlatformRemoteAppleBridge::GetDeviceSupportDirectoryName
llvm::StringRef GetDeviceSupportDirectoryName() override
Definition: PlatformRemoteAppleBridge.cpp:175
lldb_private::ArchSpec::SetTriple
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
Definition: ArchSpec.cpp:739
PlatformRemoteAppleBridge::PlatformRemoteAppleBridge
PlatformRemoteAppleBridge()
Default Constructor.
Definition: PlatformRemoteAppleBridge.cpp:31
StreamString.h
lldb_private::ConstString
Definition: ConstString.h:40
PlatformRemoteAppleBridge::Terminate
static void Terminate()
Definition: PlatformRemoteAppleBridge.cpp:48
lldb_private::Platform::Terminate
static void Terminate()
Definition: Platform.cpp:149
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
PlatformRemoteAppleBridge::CreateInstance
static lldb::PlatformSP CreateInstance(bool force, const lldb_private::ArchSpec *arch)
Definition: PlatformRemoteAppleBridge.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
PlatformRemoteAppleBridge::Initialize
static void Initialize()
Definition: PlatformRemoteAppleBridge.cpp:38
lldb_private::ArchSpec::GetArchitectureName
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:538
uint32_t
PlatformRemoteAppleBridge::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: PlatformRemoteAppleBridge.cpp:145
PlatformRemoteAppleBridge.h
ArchSpec.h
PluginManager.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
PlatformRemoteAppleBridge::GetPlatformName
llvm::StringRef GetPlatformName() override
Definition: PlatformRemoteAppleBridge.cpp:179
lldb
Definition: SBAddress.h:15