1 //===-- PlatformRemoteMacOSX.cpp -------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 #include "PlatformRemoteMacOSX.h"
15 #include "lldb/Breakpoint/BreakpointLocation.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/ModuleList.h"
18 #include "lldb/Core/ModuleSpec.h"
19 #include "lldb/Core/PluginManager.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"
28 #include "lldb/Utility/StreamString.h"
31 using namespace lldb_private
;
33 /// Default Constructor
34 PlatformRemoteMacOSX::PlatformRemoteMacOSX() : PlatformRemoteDarwinDevice() {}
37 static uint32_t g_initialize_count
= 0;
40 void PlatformRemoteMacOSX::Initialize() {
41 PlatformDarwin::Initialize();
43 if (g_initialize_count
++ == 0) {
44 PluginManager::RegisterPlugin(PlatformRemoteMacOSX::GetPluginNameStatic(),
45 PlatformRemoteMacOSX::GetDescriptionStatic(),
46 PlatformRemoteMacOSX::CreateInstance
);
50 void PlatformRemoteMacOSX::Terminate() {
51 if (g_initialize_count
> 0) {
52 if (--g_initialize_count
== 0) {
53 PluginManager::UnregisterPlugin(PlatformRemoteMacOSX::CreateInstance
);
57 PlatformDarwin::Terminate();
60 PlatformSP
PlatformRemoteMacOSX::CreateInstance(bool force
,
61 const ArchSpec
*arch
) {
62 Log
*log
= GetLog(LLDBLog::Platform
);
64 const char *arch_name
;
65 if (arch
&& arch
->GetArchitectureName())
66 arch_name
= arch
->GetArchitectureName();
70 const char *triple_cstr
=
71 arch
? arch
->GetTriple().getTriple().c_str() : "<null>";
73 LLDB_LOGF(log
, "PlatformRemoteMacOSX::%s(force=%s, arch={%s,%s})",
74 __FUNCTION__
, force
? "true" : "false", arch_name
, triple_cstr
);
78 if (!create
&& arch
&& arch
->IsValid()) {
79 const llvm::Triple
&triple
= arch
->GetTriple();
80 switch (triple
.getVendor()) {
81 case llvm::Triple::Apple
:
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();
97 switch (triple
.getOS()) {
98 case llvm::Triple::Darwin
: // Deprecated, but still support Darwin for
100 case llvm::Triple::MacOSX
:
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();
117 LLDB_LOGF(log
, "PlatformRemoteMacOSX::%s() creating platform",
119 return std::make_shared
<PlatformRemoteMacOSX
>();
122 LLDB_LOGF(log
, "PlatformRemoteMacOSX::%s() aborting creation of platform",
128 std::vector
<ArchSpec
>
129 PlatformRemoteMacOSX::GetSupportedArchitectures(const ArchSpec
&host_info
) {
130 // macOS for ARM64 support both native and translated x86_64 processes
131 std::vector
<ArchSpec
> result
;
132 ARMGetSupportedArchitectures(result
, llvm::Triple::MacOSX
);
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"));
144 llvm::StringRef
PlatformRemoteMacOSX::GetDescriptionStatic() {
145 return "Remote Mac OS X user platform plug-in.";
148 llvm::StringRef
PlatformRemoteMacOSX::GetDeviceSupportDirectoryName() {
149 return "macOS DeviceSupport";
152 llvm::StringRef
PlatformRemoteMacOSX::GetPlatformName() {
153 return "MacOSX.platform";