LLDB  mainline
PlatformRemoteiOS.cpp
Go to the documentation of this file.
1 //===-- PlatformRemoteiOS.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 "PlatformRemoteiOS.h"
10 
12 #include "lldb/Core/Module.h"
13 #include "lldb/Core/ModuleList.h"
14 #include "lldb/Core/ModuleSpec.h"
16 #include "lldb/Host/Host.h"
17 #include "lldb/Target/Process.h"
18 #include "lldb/Target/Target.h"
19 #include "lldb/Utility/ArchSpec.h"
20 #include "lldb/Utility/FileSpec.h"
21 #include "lldb/Utility/LLDBLog.h"
22 #include "lldb/Utility/Log.h"
23 #include "lldb/Utility/Status.h"
25 
26 using namespace lldb;
27 using namespace lldb_private;
28 
30 
31 // Static Variables
33 
34 // Static Functions
35 void PlatformRemoteiOS::Initialize() {
36  PlatformDarwin::Initialize();
37 
38  if (g_initialize_count++ == 0) {
39  PluginManager::RegisterPlugin(PlatformRemoteiOS::GetPluginNameStatic(),
40  PlatformRemoteiOS::GetDescriptionStatic(),
41  PlatformRemoteiOS::CreateInstance);
42  }
43 }
44 
45 void PlatformRemoteiOS::Terminate() {
46  if (g_initialize_count > 0) {
47  if (--g_initialize_count == 0) {
48  PluginManager::UnregisterPlugin(PlatformRemoteiOS::CreateInstance);
49  }
50  }
51 
52  PlatformDarwin::Terminate();
53 }
54 
55 PlatformSP PlatformRemoteiOS::CreateInstance(bool force, const ArchSpec *arch) {
56  Log *log = GetLog(LLDBLog::Platform);
57  if (log) {
58  const char *arch_name;
59  if (arch && arch->GetArchitectureName())
60  arch_name = arch->GetArchitectureName();
61  else
62  arch_name = "<null>";
63 
64  const char *triple_cstr =
65  arch ? arch->GetTriple().getTriple().c_str() : "<null>";
66 
67  LLDB_LOGF(log, "PlatformRemoteiOS::%s(force=%s, arch={%s,%s})",
68  __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
69  }
70 
71  bool create = force;
72  if (!create && arch && arch->IsValid()) {
73  switch (arch->GetMachine()) {
74  case llvm::Triple::arm:
75  case llvm::Triple::aarch64:
76  case llvm::Triple::thumb: {
77  const llvm::Triple &triple = arch->GetTriple();
78  llvm::Triple::VendorType vendor = triple.getVendor();
79  switch (vendor) {
80  case llvm::Triple::Apple:
81  create = true;
82  break;
83 
84 #if defined(__APPLE__)
85  // Only accept "unknown" for the vendor if the host is Apple and
86  // "unknown" wasn't specified (it was just returned because it was NOT
87  // specified)
88  case llvm::Triple::UnknownVendor:
89  create = !arch->TripleVendorWasSpecified();
90  break;
91 
92 #endif
93  default:
94  break;
95  }
96  if (create) {
97  switch (triple.getOS()) {
98  case llvm::Triple::Darwin: // Deprecated, but still support Darwin for
99  // historical reasons
100  case llvm::Triple::IOS: // This is the right triple value for iOS
101  // debugging
102  break;
103 
104  default:
105  create = false;
106  break;
107  }
108  }
109  } break;
110  default:
111  break;
112  }
113  }
114 
115  if (create) {
116  if (log)
117  LLDB_LOGF(log, "PlatformRemoteiOS::%s() creating platform", __FUNCTION__);
118 
119  return lldb::PlatformSP(new PlatformRemoteiOS());
120  }
121 
122  if (log)
123  LLDB_LOGF(log, "PlatformRemoteiOS::%s() aborting creation of platform",
124  __FUNCTION__);
125 
126  return lldb::PlatformSP();
127 }
128 
129 llvm::StringRef PlatformRemoteiOS::GetDescriptionStatic() {
130  return "Remote iOS platform plug-in.";
131 }
132 
133 /// Default Constructor
134 PlatformRemoteiOS::PlatformRemoteiOS()
136 
138  const ArchSpec &process_host_arch) {
139  std::vector<ArchSpec> result;
140  ARMGetSupportedArchitectures(result, llvm::Triple::IOS);
141  return result;
142 }
143 
145  // You can run iPhone and iPad apps on Mac with Apple Silicon. At the
146  // platform level there's no way to distinguish them from remote iOS
147  // applications. Make sure we still read from our own shared cache.
148  return true;
149 }
150 
152  return "iOS DeviceSupport";
153 }
154 
156  return "iPhoneOS.platform";
157 }
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_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:343
lldb_private::PlatformDarwin::ARMGetSupportedArchitectures
void ARMGetSupportedArchitectures(std::vector< ArchSpec > &archs, llvm::Optional< llvm::Triple::OSType > os={})
The architecture selection rules for arm processors These cpu subtypes have distinct names (e....
Definition: PlatformDarwin.cpp:603
Module.h
BreakpointLocation.h
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:455
Process.h
Target.h
lldb_private::PlatformRemoteiOS::GetPlatformName
llvm::StringRef GetPlatformName() override
Definition: PlatformRemoteiOS.cpp:155
lldb_private::PlatformRemoteiOS::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: PlatformRemoteiOS.cpp:137
ModuleList.h
Log.h
StreamString.h
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::PlatformRemoteiOS::GetDeviceSupportDirectoryName
llvm::StringRef GetDeviceSupportDirectoryName() override
Definition: PlatformRemoteiOS.cpp:151
PlatformRemoteiOS.h
lldb_private::ArchSpec::GetArchitectureName
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:539
lldb_private::PlatformRemoteiOS::CheckLocalSharedCache
bool CheckLocalSharedCache() const override
Definition: PlatformRemoteiOS.cpp:144
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_PLUGIN_DEFINE
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
lldb_private::Log
Definition: Log.h:115
lldb_private::PlatformRemoteiOS
Definition: PlatformRemoteiOS.h:21
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
g_initialize_count
static uint32_t g_initialize_count
Definition: PlatformRemoteiOS.cpp:32