LLDB  mainline
PlatformRemoteMacOSX.cpp
Go to the documentation of this file.
1 //===-- PlatformRemoteMacOSX.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 <memory>
10 #include <string>
11 #include <vector>
12 
13 #include "PlatformRemoteMacOSX.h"
14 
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/ModuleList.h"
18 #include "lldb/Core/ModuleSpec.h"
20 #include "lldb/Host/Host.h"
21 #include "lldb/Host/HostInfo.h"
22 #include "lldb/Target/Process.h"
23 #include "lldb/Target/Target.h"
24 #include "lldb/Utility/ArchSpec.h"
25 #include "lldb/Utility/FileSpec.h"
26 #include "lldb/Utility/LLDBLog.h"
27 #include "lldb/Utility/Log.h"
29 
30 using namespace lldb;
31 using namespace lldb_private;
32 
33 /// Default Constructor
34 PlatformRemoteMacOSX::PlatformRemoteMacOSX() : PlatformRemoteDarwinDevice() {}
35 
36 // Static Variables
38 
39 // Static Functions
42 
43  if (g_initialize_count++ == 0) {
47  }
48 }
49 
51  if (g_initialize_count > 0) {
52  if (--g_initialize_count == 0) {
54  }
55  }
56 
58 }
59 
61  const ArchSpec *arch) {
63  if (log) {
64  const char *arch_name;
65  if (arch && arch->GetArchitectureName())
66  arch_name = arch->GetArchitectureName();
67  else
68  arch_name = "<null>";
69 
70  const char *triple_cstr =
71  arch ? arch->GetTriple().getTriple().c_str() : "<null>";
72 
73  LLDB_LOGF(log, "PlatformRemoteMacOSX::%s(force=%s, arch={%s,%s})",
74  __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
75  }
76 
77  bool create = force;
78  if (!create && arch && arch->IsValid()) {
79  const llvm::Triple &triple = arch->GetTriple();
80  switch (triple.getVendor()) {
81  case llvm::Triple::Apple:
82  create = true;
83  break;
84 
85 #if defined(__APPLE__)
86  // Only accept "unknown" for vendor if the host is Apple and it "unknown"
87  // wasn't specified (it was just returned because it was NOT specified)
88  case llvm::Triple::UnknownVendor:
89  create = !arch->TripleVendorWasSpecified();
90  break;
91 #endif
92  default:
93  break;
94  }
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::MacOSX:
101  break;
102 #if defined(__APPLE__)
103  // Only accept "vendor" for vendor if the host is Apple and it "unknown"
104  // wasn't specified (it was just returned because it was NOT specified)
105  case llvm::Triple::UnknownOS:
106  create = !arch->TripleOSWasSpecified();
107  break;
108 #endif
109  default:
110  create = false;
111  break;
112  }
113  }
114  }
115 
116  if (create) {
117  LLDB_LOGF(log, "PlatformRemoteMacOSX::%s() creating platform",
118  __FUNCTION__);
119  return std::make_shared<PlatformRemoteMacOSX>();
120  }
121 
122  LLDB_LOGF(log, "PlatformRemoteMacOSX::%s() aborting creation of platform",
123  __FUNCTION__);
124 
125  return PlatformSP();
126 }
127 
128 std::vector<ArchSpec>
130  // macOS for ARM64 support both native and translated x86_64 processes
131  std::vector<ArchSpec> result;
132  ARMGetSupportedArchitectures(result, llvm::Triple::MacOSX);
133 
134  // We can't use x86GetSupportedArchitectures() because it uses
135  // the system architecture for some of its return values and also
136  // has a 32bits variant.
137  result.push_back(ArchSpec("x86_64-apple-macosx"));
138  result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
139  result.push_back(ArchSpec("arm64-apple-ios"));
140  result.push_back(ArchSpec("arm64e-apple-ios"));
141  return result;
142 }
143 
145  return "Remote Mac OS X user platform plug-in.";
146 }
147 
149  return "macOS DeviceSupport";
150 }
151 
153  return "MacOSX.platform";
154 }
lldb_private::PlatformRemoteMacOSX::Initialize
static void Initialize()
Definition: PlatformRemoteMacOSX.cpp:40
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ArchSpec::TripleVendorWasSpecified
bool TripleVendorWasSpecified() const
Definition: ArchSpec.h:358
PlatformRemoteMacOSX.h
ModuleSpec.h
Host.h
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:270
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
g_initialize_count
static uint32_t g_initialize_count
Definition: PlatformRemoteMacOSX.cpp:37
lldb_private::PlatformRemoteMacOSX::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: PlatformRemoteMacOSX.cpp:129
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:455
Process.h
lldb_private::PlatformDarwin::Initialize
static void Initialize()
Definition: PlatformDarwin.cpp:83
Target.h
ModuleList.h
lldb_private::PluginManager::UnregisterPlugin
static bool UnregisterPlugin(ABICreateInstance create_callback)
Definition: PluginManager.cpp:293
Log.h
lldb_private::PlatformDarwin::Terminate
static void Terminate()
Definition: PlatformDarwin.cpp:94
StreamString.h
lldb_private::PlatformRemoteDarwinDevice
Definition: PlatformRemoteDarwinDevice.h:36
lldb_private::ArchSpec::TripleOSWasSpecified
bool TripleOSWasSpecified() const
Definition: ArchSpec.h:362
HostInfo.h
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::PlatformRemoteMacOSX::Terminate
static void Terminate()
Definition: PlatformRemoteMacOSX.cpp:50
uint32_t
lldb_private::PlatformRemoteMacOSX::GetDescriptionStatic
static llvm::StringRef GetDescriptionStatic()
Definition: PlatformRemoteMacOSX.cpp:144
ArchSpec.h
lldb_private::PlatformRemoteMacOSX::GetPlatformName
llvm::StringRef GetPlatformName() override
Definition: PlatformRemoteMacOSX.cpp:152
PluginManager.h
lldb_private::PluginManager::RegisterPlugin
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
Definition: PluginManager.cpp:287
lldb_private::LLDBLog::Platform
@ Platform
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
FileSpec.h
lldb_private::PlatformRemoteMacOSX::CreateInstance
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
Definition: PlatformRemoteMacOSX.cpp:60
lldb_private::Log
Definition: Log.h:48
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:235
lldb
Definition: SBAddress.h:15
LLDBLog.h
lldb_private::PlatformRemoteMacOSX::GetDeviceSupportDirectoryName
llvm::StringRef GetDeviceSupportDirectoryName() override
Definition: PlatformRemoteMacOSX.cpp:148
lldb_private::PlatformRemoteMacOSX::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: PlatformRemoteMacOSX.h:36