1be691f3bSpatrick //===-- PlatformRemoteMacOSX.cpp -------------------------------------===//
2be691f3bSpatrick //
3be691f3bSpatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4be691f3bSpatrick // See https://llvm.org/LICENSE.txt for license information.
5be691f3bSpatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6be691f3bSpatrick //
7be691f3bSpatrick //===----------------------------------------------------------------------===//
8be691f3bSpatrick
9be691f3bSpatrick #include <memory>
10be691f3bSpatrick #include <string>
11be691f3bSpatrick #include <vector>
12be691f3bSpatrick
13be691f3bSpatrick #include "PlatformRemoteMacOSX.h"
14be691f3bSpatrick
15be691f3bSpatrick #include "lldb/Breakpoint/BreakpointLocation.h"
16be691f3bSpatrick #include "lldb/Core/Module.h"
17be691f3bSpatrick #include "lldb/Core/ModuleList.h"
18be691f3bSpatrick #include "lldb/Core/ModuleSpec.h"
19be691f3bSpatrick #include "lldb/Core/PluginManager.h"
20be691f3bSpatrick #include "lldb/Host/Host.h"
21be691f3bSpatrick #include "lldb/Host/HostInfo.h"
22be691f3bSpatrick #include "lldb/Target/Process.h"
23be691f3bSpatrick #include "lldb/Target/Target.h"
24be691f3bSpatrick #include "lldb/Utility/ArchSpec.h"
25be691f3bSpatrick #include "lldb/Utility/FileSpec.h"
26*f6aab3d8Srobert #include "lldb/Utility/LLDBLog.h"
27be691f3bSpatrick #include "lldb/Utility/Log.h"
28be691f3bSpatrick #include "lldb/Utility/StreamString.h"
29be691f3bSpatrick
30be691f3bSpatrick using namespace lldb;
31be691f3bSpatrick using namespace lldb_private;
32be691f3bSpatrick
33be691f3bSpatrick /// Default Constructor
PlatformRemoteMacOSX()34be691f3bSpatrick PlatformRemoteMacOSX::PlatformRemoteMacOSX() : PlatformRemoteDarwinDevice() {}
35be691f3bSpatrick
36be691f3bSpatrick // Static Variables
37be691f3bSpatrick static uint32_t g_initialize_count = 0;
38be691f3bSpatrick
39be691f3bSpatrick // Static Functions
Initialize()40be691f3bSpatrick void PlatformRemoteMacOSX::Initialize() {
41be691f3bSpatrick PlatformDarwin::Initialize();
42be691f3bSpatrick
43be691f3bSpatrick if (g_initialize_count++ == 0) {
44be691f3bSpatrick PluginManager::RegisterPlugin(PlatformRemoteMacOSX::GetPluginNameStatic(),
45be691f3bSpatrick PlatformRemoteMacOSX::GetDescriptionStatic(),
46be691f3bSpatrick PlatformRemoteMacOSX::CreateInstance);
47be691f3bSpatrick }
48be691f3bSpatrick }
49be691f3bSpatrick
Terminate()50be691f3bSpatrick void PlatformRemoteMacOSX::Terminate() {
51be691f3bSpatrick if (g_initialize_count > 0) {
52be691f3bSpatrick if (--g_initialize_count == 0) {
53be691f3bSpatrick PluginManager::UnregisterPlugin(PlatformRemoteMacOSX::CreateInstance);
54be691f3bSpatrick }
55be691f3bSpatrick }
56be691f3bSpatrick
57be691f3bSpatrick PlatformDarwin::Terminate();
58be691f3bSpatrick }
59be691f3bSpatrick
CreateInstance(bool force,const ArchSpec * arch)60be691f3bSpatrick PlatformSP PlatformRemoteMacOSX::CreateInstance(bool force,
61be691f3bSpatrick const ArchSpec *arch) {
62*f6aab3d8Srobert Log *log = GetLog(LLDBLog::Platform);
63be691f3bSpatrick if (log) {
64be691f3bSpatrick const char *arch_name;
65be691f3bSpatrick if (arch && arch->GetArchitectureName())
66be691f3bSpatrick arch_name = arch->GetArchitectureName();
67be691f3bSpatrick else
68be691f3bSpatrick arch_name = "<null>";
69be691f3bSpatrick
70be691f3bSpatrick const char *triple_cstr =
71be691f3bSpatrick arch ? arch->GetTriple().getTriple().c_str() : "<null>";
72be691f3bSpatrick
73*f6aab3d8Srobert LLDB_LOGF(log, "PlatformRemoteMacOSX::%s(force=%s, arch={%s,%s})",
74*f6aab3d8Srobert __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
75be691f3bSpatrick }
76be691f3bSpatrick
77be691f3bSpatrick bool create = force;
78be691f3bSpatrick if (!create && arch && arch->IsValid()) {
79be691f3bSpatrick const llvm::Triple &triple = arch->GetTriple();
80be691f3bSpatrick switch (triple.getVendor()) {
81be691f3bSpatrick case llvm::Triple::Apple:
82be691f3bSpatrick create = true;
83be691f3bSpatrick break;
84be691f3bSpatrick
85be691f3bSpatrick #if defined(__APPLE__)
86be691f3bSpatrick // Only accept "unknown" for vendor if the host is Apple and it "unknown"
87be691f3bSpatrick // wasn't specified (it was just returned because it was NOT specified)
88be691f3bSpatrick case llvm::Triple::UnknownVendor:
89be691f3bSpatrick create = !arch->TripleVendorWasSpecified();
90be691f3bSpatrick break;
91be691f3bSpatrick #endif
92be691f3bSpatrick default:
93be691f3bSpatrick break;
94be691f3bSpatrick }
95be691f3bSpatrick
96be691f3bSpatrick if (create) {
97be691f3bSpatrick switch (triple.getOS()) {
98be691f3bSpatrick case llvm::Triple::Darwin: // Deprecated, but still support Darwin for
99be691f3bSpatrick // historical reasons
100be691f3bSpatrick case llvm::Triple::MacOSX:
101be691f3bSpatrick break;
102be691f3bSpatrick #if defined(__APPLE__)
103be691f3bSpatrick // Only accept "vendor" for vendor if the host is Apple and it "unknown"
104be691f3bSpatrick // wasn't specified (it was just returned because it was NOT specified)
105be691f3bSpatrick case llvm::Triple::UnknownOS:
106be691f3bSpatrick create = !arch->TripleOSWasSpecified();
107be691f3bSpatrick break;
108be691f3bSpatrick #endif
109be691f3bSpatrick default:
110be691f3bSpatrick create = false;
111be691f3bSpatrick break;
112be691f3bSpatrick }
113be691f3bSpatrick }
114be691f3bSpatrick }
115be691f3bSpatrick
116be691f3bSpatrick if (create) {
117be691f3bSpatrick LLDB_LOGF(log, "PlatformRemoteMacOSX::%s() creating platform",
118be691f3bSpatrick __FUNCTION__);
119be691f3bSpatrick return std::make_shared<PlatformRemoteMacOSX>();
120be691f3bSpatrick }
121be691f3bSpatrick
122be691f3bSpatrick LLDB_LOGF(log, "PlatformRemoteMacOSX::%s() aborting creation of platform",
123be691f3bSpatrick __FUNCTION__);
124be691f3bSpatrick
125be691f3bSpatrick return PlatformSP();
126be691f3bSpatrick }
127be691f3bSpatrick
128*f6aab3d8Srobert std::vector<ArchSpec>
GetSupportedArchitectures(const ArchSpec & host_info)129*f6aab3d8Srobert PlatformRemoteMacOSX::GetSupportedArchitectures(const ArchSpec &host_info) {
130be691f3bSpatrick // macOS for ARM64 support both native and translated x86_64 processes
131*f6aab3d8Srobert std::vector<ArchSpec> result;
132*f6aab3d8Srobert ARMGetSupportedArchitectures(result, llvm::Triple::MacOSX);
133be691f3bSpatrick
134*f6aab3d8Srobert // We can't use x86GetSupportedArchitectures() because it uses
135be691f3bSpatrick // the system architecture for some of its return values and also
136be691f3bSpatrick // has a 32bits variant.
137*f6aab3d8Srobert result.push_back(ArchSpec("x86_64-apple-macosx"));
138*f6aab3d8Srobert result.push_back(ArchSpec("x86_64-apple-ios-macabi"));
139*f6aab3d8Srobert result.push_back(ArchSpec("arm64-apple-ios"));
140*f6aab3d8Srobert result.push_back(ArchSpec("arm64e-apple-ios"));
141*f6aab3d8Srobert return result;
142be691f3bSpatrick }
143be691f3bSpatrick
GetDescriptionStatic()144*f6aab3d8Srobert llvm::StringRef PlatformRemoteMacOSX::GetDescriptionStatic() {
145be691f3bSpatrick return "Remote Mac OS X user platform plug-in.";
146be691f3bSpatrick }
147be691f3bSpatrick
GetDeviceSupportDirectoryName()148be691f3bSpatrick llvm::StringRef PlatformRemoteMacOSX::GetDeviceSupportDirectoryName() {
149be691f3bSpatrick return "macOS DeviceSupport";
150be691f3bSpatrick }
151be691f3bSpatrick
GetPlatformName()152be691f3bSpatrick llvm::StringRef PlatformRemoteMacOSX::GetPlatformName() {
153be691f3bSpatrick return "MacOSX.platform";
154be691f3bSpatrick }
155