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/Log.h"
22 #include "lldb/Utility/Status.h"
24 
25 using namespace lldb;
26 using namespace lldb_private;
27 
29 
30 // Static Variables
32 
33 // Static Functions
34 void PlatformRemoteiOS::Initialize() {
36 
37  if (g_initialize_count++ == 0) {
38  PluginManager::RegisterPlugin(PlatformRemoteiOS::GetPluginNameStatic(),
41  }
42 }
43 
45  if (g_initialize_count > 0) {
46  if (--g_initialize_count == 0) {
47  PluginManager::UnregisterPlugin(PlatformRemoteiOS::CreateInstance);
48  }
49  }
50 
52 }
53 
54 PlatformSP PlatformRemoteiOS::CreateInstance(bool force, const ArchSpec *arch) {
56  if (log) {
57  const char *arch_name;
58  if (arch && arch->GetArchitectureName())
59  arch_name = arch->GetArchitectureName();
60  else
61  arch_name = "<null>";
62 
63  const char *triple_cstr =
64  arch ? arch->GetTriple().getTriple().c_str() : "<null>";
65 
66  LLDB_LOGF(log, "PlatformRemoteiOS::%s(force=%s, arch={%s,%s})",
67  __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
68  }
69 
70  bool create = force;
71  if (!create && arch && arch->IsValid()) {
72  switch (arch->GetMachine()) {
73  case llvm::Triple::arm:
74  case llvm::Triple::aarch64:
75  case llvm::Triple::thumb: {
76  const llvm::Triple &triple = arch->GetTriple();
77  llvm::Triple::VendorType vendor = triple.getVendor();
78  switch (vendor) {
79  case llvm::Triple::Apple:
80  create = true;
81  break;
82 
83 #if defined(__APPLE__)
84  // Only accept "unknown" for the vendor if the host is Apple and
85  // "unknown" wasn't specified (it was just returned because it was NOT
86  // specified)
87  case llvm::Triple::UnknownVendor:
88  create = !arch->TripleVendorWasSpecified();
89  break;
90 
91 #endif
92  default:
93  break;
94  }
95  if (create) {
96  switch (triple.getOS()) {
97  case llvm::Triple::Darwin: // Deprecated, but still support Darwin for
98  // historical reasons
99  case llvm::Triple::IOS: // This is the right triple value for iOS
100  // debugging
101  break;
102 
103  default:
104  create = false;
105  break;
106  }
107  }
108  } break;
109  default:
110  break;
111  }
112  }
113 
114  if (create) {
115  if (log)
116  LLDB_LOGF(log, "PlatformRemoteiOS::%s() creating platform", __FUNCTION__);
117 
118  return lldb::PlatformSP(new PlatformRemoteiOS());
119  }
120 
121  if (log)
122  LLDB_LOGF(log, "PlatformRemoteiOS::%s() aborting creation of platform",
123  __FUNCTION__);
124 
125  return lldb::PlatformSP();
126 }
127 
129  static ConstString g_name("remote-ios");
130  return g_name;
131 }
132 
134  return "Remote iOS platform plug-in.";
135 }
136 
137 /// Default Constructor
140 
142  ArchSpec &arch) {
143  return ARMGetSupportedArchitectureAtIndex(idx, arch);
144 }
145 
146 
147 void PlatformRemoteiOS::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
148 {
149  dirnames.clear();
150  dirnames.push_back("iOS DeviceSupport");
151 }
152 
154 {
155  return "iPhoneOS.platform";
156 }
A class that represents a running process on the host machine.
bool ARMGetSupportedArchitectureAtIndex(uint32_t idx, lldb_private::ArchSpec &arch)
An architecture specification class.
Definition: ArchSpec.h:33
#define LIBLLDB_LOG_PLATFORM
Definition: Logging.h:39
static void Terminate()
Definition: Platform.cpp:149
bool IsValid() const
Tests if this ArchSpec is valid.
Definition: ArchSpec.h:332
static const char * GetDescriptionStatic()
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:434
bool TripleVendorWasSpecified() const
Definition: ArchSpec.h:337
const char * GetArchitectureName() const
Returns a static string representing the current architecture.
Definition: ArchSpec.cpp:585
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
static lldb_private::ConstString GetPluginNameStatic()
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
static void Initialize()
Definition: Platform.cpp:147
PlatformRemoteiOS()
Default Constructor.
#define LLDB_LOGF(log,...)
Definition: Log.h:249
A uniqued constant string class.
Definition: ConstString.h:40
Definition: SBAddress.h:15
bool GetSupportedArchitectureAtIndex(uint32_t idx, lldb_private::ArchSpec &arch) override
Get the platform&#39;s supported architectures in the order in which they should be searched.
void GetDeviceSupportDirectoryNames(std::vector< std::string > &dirnames) override
static uint32_t g_initialize_count
std::string GetPlatformName() override
static void Terminate()
static lldb::PlatformSP CreateInstance(bool force, const lldb_private::ArchSpec *arch)
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:714