1//===-- PlatformRemoteAppleXR.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 <string>
10#include <vector>
11
12#include "PlatformRemoteAppleXR.h"
13#include "lldb/Breakpoint/BreakpointLocation.h"
14#include "lldb/Core/Module.h"
15#include "lldb/Core/ModuleList.h"
16#include "lldb/Core/PluginManager.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
24using namespace lldb;
25using namespace lldb_private;
26
27// Static Variables
28static uint32_t g_xr_initialize_count = 0;
29
30// Static Functions
31void PlatformRemoteAppleXR::Initialize() {
32 PlatformDarwin::Initialize();
33
34 if (g_xr_initialize_count++ == 0) {
35 PluginManager::RegisterPlugin(name: PlatformRemoteAppleXR::GetPluginNameStatic(),
36 description: PlatformRemoteAppleXR::GetDescriptionStatic(),
37 create_callback: PlatformRemoteAppleXR::CreateInstance);
38 }
39}
40
41void PlatformRemoteAppleXR::Terminate() {
42 if (g_xr_initialize_count > 0) {
43 if (--g_xr_initialize_count == 0) {
44 PluginManager::UnregisterPlugin(create_callback: PlatformRemoteAppleXR::CreateInstance);
45 }
46 }
47
48 PlatformDarwin::Terminate();
49}
50
51PlatformSP PlatformRemoteAppleXR::CreateInstance(bool force,
52 const ArchSpec *arch) {
53 Log *log = GetLog(mask: LLDBLog::Platform);
54 if (log) {
55 const char *arch_name;
56 if (arch && arch->GetArchitectureName())
57 arch_name = arch->GetArchitectureName();
58 else
59 arch_name = "<null>";
60
61 const char *triple_cstr =
62 arch ? arch->GetTriple().getTriple().c_str() : "<null>";
63
64 LLDB_LOGF(log, "PlatformRemoteAppleXR::%s(force=%s, arch={%s,%s})",
65 __FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
66 }
67
68 bool create = force;
69 if (!create && arch && arch->IsValid()) {
70 switch (arch->GetMachine()) {
71 case llvm::Triple::arm:
72 case llvm::Triple::aarch64:
73 case llvm::Triple::aarch64_32:
74 case llvm::Triple::thumb: {
75 const llvm::Triple &triple = arch->GetTriple();
76 llvm::Triple::VendorType vendor = triple.getVendor();
77 switch (vendor) {
78 case llvm::Triple::Apple:
79 create = true;
80 break;
81
82#if defined(__APPLE__)
83 // Only accept "unknown" for the vendor if the host is Apple and
84 // "unknown" wasn't specified (it was just returned because it was NOT
85 // specified)
86 case llvm::Triple::UnknownVendor:
87 create = !arch->TripleVendorWasSpecified();
88 break;
89
90#endif
91 default:
92 break;
93 }
94 if (create) {
95 switch (triple.getOS()) {
96 case llvm::Triple::XROS: // This is the right triple value for Apple
97 // XR debugging
98 break;
99
100 default:
101 create = false;
102 break;
103 }
104 }
105 } break;
106 default:
107 break;
108 }
109 }
110
111#if defined(TARGET_OS_XR) && TARGET_OS_XR == 1
112 // If lldb is running on a XR device, this isn't a RemoteXR.
113 if (force == false) {
114 create = false;
115 }
116#endif
117
118 if (create) {
119 LLDB_LOGF(log, "PlatformRemoteAppleXR::%s() creating platform",
120 __FUNCTION__);
121
122 return lldb::PlatformSP(new PlatformRemoteAppleXR());
123 }
124
125 LLDB_LOGF(log, "PlatformRemoteAppleXR::%s() aborting creation of platform",
126 __FUNCTION__);
127
128 return lldb::PlatformSP();
129}
130
131llvm::StringRef PlatformRemoteAppleXR::GetPluginNameStatic() {
132 return "remote-xros";
133}
134
135llvm::StringRef PlatformRemoteAppleXR::GetDescriptionStatic() {
136 return "Remote Apple XR platform plug-in.";
137}
138
139/// Default Constructor
140PlatformRemoteAppleXR::PlatformRemoteAppleXR() : PlatformRemoteDarwinDevice() {}
141
142std::vector<lldb_private::ArchSpec>
143PlatformRemoteAppleXR::GetSupportedArchitectures(
144 const ArchSpec &process_host_arch) {
145 std::vector<ArchSpec> result;
146 result.push_back(x: ArchSpec("arm64-apple-xros"));
147 result.push_back(x: ArchSpec("arm64-apple-xros"));
148 return result;
149}
150
151llvm::StringRef PlatformRemoteAppleXR::GetDeviceSupportDirectoryName() {
152 return "XROS DeviceSupport";
153}
154
155llvm::StringRef PlatformRemoteAppleXR::GetPlatformName() {
156 return "XROS.platform";
157}
158

source code of lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleXR.cpp