Skip to content

Commit 3b6a8f8

Browse files
authored
[lldb] Upstream xros support in lldb (llvm#78389)
Upstream support for debugging xros applications through LLDB.
1 parent d525e2b commit 3b6a8f8

File tree

21 files changed

+340
-9
lines changed

21 files changed

+340
-9
lines changed

lldb/include/lldb/Utility/XcodeSDK.h

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class XcodeSDK {
3434
AppleTVOS,
3535
WatchSimulator,
3636
watchOS,
37+
XRSimulator,
38+
XROS,
3739
bridgeOS,
3840
Linux,
3941
unknown = -1

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

+3
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
276276
#elif defined(TARGET_OS_WATCHOS) && TARGET_OS_WATCHOS == 1
277277
arch_32.GetTriple().setOS(llvm::Triple::WatchOS);
278278
arch_64.GetTriple().setOS(llvm::Triple::WatchOS);
279+
#elif defined(TARGET_OS_XR) && TARGET_OS_XR == 1
280+
arch_32.GetTriple().setOS(llvm::Triple::XROS);
281+
arch_64.GetTriple().setOS(llvm::Triple::XROS);
279282
#elif defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1
280283
arch_32.GetTriple().setOS(llvm::Triple::MacOSX);
281284
arch_64.GetTriple().setOS(llvm::Triple::MacOSX);

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ DynamicLoader *DynamicLoaderDarwinKernel::CreateInstance(Process *process,
166166
case llvm::Triple::IOS:
167167
case llvm::Triple::TvOS:
168168
case llvm::Triple::WatchOS:
169+
case llvm::Triple::XROS:
169170
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
170171
if (triple_ref.getVendor() != llvm::Triple::Apple) {
171172
return nullptr;

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process,
5555
case llvm::Triple::IOS:
5656
case llvm::Triple::TvOS:
5757
case llvm::Triple::WatchOS:
58+
case llvm::Triple::XROS:
5859
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
5960
create = triple_ref.getVendor() == llvm::Triple::Apple;
6061
break;

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ DynamicLoader *DynamicLoaderMacOSXDYLD::CreateInstance(Process *process,
7575
case llvm::Triple::IOS:
7676
case llvm::Triple::TvOS:
7777
case llvm::Triple::WatchOS:
78+
case llvm::Triple::XROS:
7879
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
7980
create = triple_ref.getVendor() == llvm::Triple::Apple;
8081
break;

lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ uint32_t EmulateInstructionARM::GetFramePointerRegisterNumber() const {
830830
case llvm::Triple::IOS:
831831
case llvm::Triple::TvOS:
832832
case llvm::Triple::WatchOS:
833+
case llvm::Triple::XROS:
833834
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
834835
is_apple = true;
835836
break;

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -4916,6 +4916,14 @@ struct OSEnv {
49164916
environment =
49174917
llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
49184918
return;
4919+
case llvm::MachO::PLATFORM_XROS:
4920+
os_type = llvm::Triple::getOSTypeName(llvm::Triple::XROS);
4921+
return;
4922+
case llvm::MachO::PLATFORM_XROS_SIMULATOR:
4923+
os_type = llvm::Triple::getOSTypeName(llvm::Triple::XROS);
4924+
environment =
4925+
llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
4926+
return;
49194927
default: {
49204928
Log *log(GetLog(LLDBLog::Symbols | LLDBLog::Process));
49214929
LLDB_LOGF(log, "unsupported platform in LC_BUILD_VERSION");
@@ -6483,7 +6491,8 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
64836491
(target_triple.getOS() == llvm::Triple::MacOSX ||
64846492
target_triple.getOS() == llvm::Triple::IOS ||
64856493
target_triple.getOS() == llvm::Triple::WatchOS ||
6486-
target_triple.getOS() == llvm::Triple::TvOS)) {
6494+
target_triple.getOS() == llvm::Triple::TvOS ||
6495+
target_triple.getOS() == llvm::Triple::XROS)) {
64876496
// NEED_BRIDGEOS_TRIPLE target_triple.getOS() == llvm::Triple::BridgeOS))
64886497
// {
64896498
bool make_core = false;

lldb/source/Plugins/Platform/MacOSX/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ list(APPEND PLUGIN_PLATFORM_MACOSX_SOURCES
1414
PlatformRemoteAppleBridge.cpp
1515
PlatformRemoteAppleTV.cpp
1616
PlatformRemoteAppleWatch.cpp
17+
PlatformRemoteAppleXR.cpp
1718
PlatformRemoteDarwinDevice.cpp
1819
PlatformRemoteMacOSX.cpp
1920
PlatformRemoteiOS.cpp

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,41 @@ struct PlatformAppleWatchSimulator {
675675
}
676676
};
677677

678+
static const char *g_xros_plugin_name = "xros-simulator";
679+
static const char *g_xros_description = "XROS simulator platform plug-in.";
680+
681+
/// XRSimulator Plugin.
682+
struct PlatformXRSimulator {
683+
static void Initialize() {
684+
PluginManager::RegisterPlugin(g_xros_plugin_name, g_xros_description,
685+
PlatformXRSimulator::CreateInstance);
686+
}
687+
688+
static void Terminate() {
689+
PluginManager::UnregisterPlugin(PlatformXRSimulator::CreateInstance);
690+
}
691+
692+
static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
693+
return PlatformAppleSimulator::CreateInstance(
694+
"PlatformXRSimulator", g_xros_description,
695+
ConstString(g_xros_plugin_name),
696+
{llvm::Triple::aarch64, llvm::Triple::x86_64, llvm::Triple::x86},
697+
llvm::Triple::XROS, {llvm::Triple::XROS},
698+
{
699+
#ifdef __APPLE__
700+
#if __arm64__
701+
"arm64e-apple-xros-simulator", "arm64-apple-xros-simulator",
702+
#else
703+
"x86_64-apple-xros-simulator", "x86_64h-apple-xros-simulator",
704+
#endif
705+
#endif
706+
},
707+
"XRSimulator.Internal.sdk", "XRSimulator.sdk",
708+
XcodeSDK::Type::XRSimulator,
709+
CoreSimulatorSupport::DeviceType::ProductFamilyID::appleXR, force,
710+
arch);
711+
}
712+
};
678713

679714
static unsigned g_initialize_count = 0;
680715

@@ -685,12 +720,14 @@ void PlatformAppleSimulator::Initialize() {
685720
PlatformiOSSimulator::Initialize();
686721
PlatformAppleTVSimulator::Initialize();
687722
PlatformAppleWatchSimulator::Initialize();
723+
PlatformXRSimulator::Initialize();
688724
}
689725
}
690726

691727
void PlatformAppleSimulator::Terminate() {
692728
if (g_initialize_count > 0)
693729
if (--g_initialize_count == 0) {
730+
PlatformXRSimulator::Terminate();
694731
PlatformAppleWatchSimulator::Terminate();
695732
PlatformAppleTVSimulator::Terminate();
696733
PlatformiOSSimulator::Terminate();

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,9 @@ FileSpec PlatformDarwin::GetSDKDirectoryForModules(XcodeSDK::Type sdk_type) {
796796
case XcodeSDK::Type::AppleTVSimulator:
797797
sdks_spec.AppendPathComponent("AppleTVSimulator.platform");
798798
break;
799+
case XcodeSDK::Type::XRSimulator:
800+
sdks_spec.AppendPathComponent("XRSimulator.platform");
801+
break;
799802
default:
800803
llvm_unreachable("unsupported sdk");
801804
}
@@ -1032,6 +1035,9 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
10321035
case XcodeSDK::Type::watchOS:
10331036
use_current_os_version = get_host_os() == llvm::Triple::WatchOS;
10341037
break;
1038+
case XcodeSDK::Type::XROS:
1039+
use_current_os_version = get_host_os() == llvm::Triple::XROS;
1040+
break;
10351041
default:
10361042
break;
10371043
}
@@ -1049,8 +1055,10 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
10491055
version = object_file->GetMinimumOSVersion();
10501056
}
10511057
}
1052-
// Only add the version-min options if we got a version from somewhere
1053-
if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
1058+
// Only add the version-min options if we got a version from somewhere.
1059+
// clang has no version-min clang flag for XROS.
1060+
if (!version.empty() && sdk_type != XcodeSDK::Type::Linux &&
1061+
sdk_type != XcodeSDK::Type::XROS) {
10541062
#define OPTION(PREFIX, NAME, VAR, ...) \
10551063
llvm::StringRef opt_##VAR = NAME; \
10561064
(void)opt_##VAR;
@@ -1079,6 +1087,9 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
10791087
case XcodeSDK::Type::watchOS:
10801088
minimum_version_option << opt_mwatchos_version_min_EQ;
10811089
break;
1090+
case XcodeSDK::Type::XRSimulator:
1091+
case XcodeSDK::Type::XROS:
1092+
// FIXME: Pass the right argument once it exists.
10821093
case XcodeSDK::Type::bridgeOS:
10831094
case XcodeSDK::Type::Linux:
10841095
case XcodeSDK::Type::unknown:
@@ -1343,6 +1354,8 @@ llvm::Triple::OSType PlatformDarwin::GetHostOSType() {
13431354
return llvm::Triple::TvOS;
13441355
#elif TARGET_OS_BRIDGE
13451356
return llvm::Triple::BridgeOS;
1357+
#elif TARGET_OS_XR
1358+
return llvm::Triple::XROS;
13461359
#else
13471360
#error "LLDB being compiled for an unrecognized Darwin OS"
13481361
#endif

lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "PlatformRemoteAppleBridge.h"
1616
#include "PlatformRemoteAppleTV.h"
1717
#include "PlatformRemoteAppleWatch.h"
18+
#include "PlatformRemoteAppleXR.h"
1819
#endif
1920
#include "lldb/Breakpoint/BreakpointLocation.h"
2021
#include "lldb/Core/Debugger.h"
@@ -53,6 +54,7 @@ void PlatformMacOSX::Initialize() {
5354
PlatformRemoteAppleTV::Initialize();
5455
PlatformRemoteAppleWatch::Initialize();
5556
PlatformRemoteAppleBridge::Initialize();
57+
PlatformRemoteAppleXR::Initialize();
5658
#endif
5759

5860
if (g_initialize_count++ == 0) {
@@ -75,6 +77,7 @@ void PlatformMacOSX::Terminate() {
7577
}
7678

7779
#if defined(__APPLE__)
80+
PlatformRemoteAppleXR::Terminate();
7881
PlatformRemoteAppleBridge::Terminate();
7982
PlatformRemoteAppleWatch::Terminate();
8083
PlatformRemoteAppleTV::Terminate();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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+
24+
using namespace lldb;
25+
using namespace lldb_private;
26+
27+
// Static Variables
28+
static uint32_t g_xr_initialize_count = 0;
29+
30+
// Static Functions
31+
void PlatformRemoteAppleXR::Initialize() {
32+
PlatformDarwin::Initialize();
33+
34+
if (g_xr_initialize_count++ == 0) {
35+
PluginManager::RegisterPlugin(PlatformRemoteAppleXR::GetPluginNameStatic(),
36+
PlatformRemoteAppleXR::GetDescriptionStatic(),
37+
PlatformRemoteAppleXR::CreateInstance);
38+
}
39+
}
40+
41+
void PlatformRemoteAppleXR::Terminate() {
42+
if (g_xr_initialize_count > 0) {
43+
if (--g_xr_initialize_count == 0) {
44+
PluginManager::UnregisterPlugin(PlatformRemoteAppleXR::CreateInstance);
45+
}
46+
}
47+
48+
PlatformDarwin::Terminate();
49+
}
50+
51+
PlatformSP PlatformRemoteAppleXR::CreateInstance(bool force,
52+
const ArchSpec *arch) {
53+
Log *log = GetLog(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+
131+
llvm::StringRef PlatformRemoteAppleXR::GetPluginNameStatic() {
132+
return "remote-xros";
133+
}
134+
135+
llvm::StringRef PlatformRemoteAppleXR::GetDescriptionStatic() {
136+
return "Remote Apple XR platform plug-in.";
137+
}
138+
139+
/// Default Constructor
140+
PlatformRemoteAppleXR::PlatformRemoteAppleXR() : PlatformRemoteDarwinDevice() {}
141+
142+
std::vector<lldb_private::ArchSpec>
143+
PlatformRemoteAppleXR::GetSupportedArchitectures(
144+
const ArchSpec &process_host_arch) {
145+
std::vector<ArchSpec> result;
146+
result.push_back(ArchSpec("arm64-apple-xros"));
147+
result.push_back(ArchSpec("arm64-apple-xros"));
148+
return result;
149+
}
150+
151+
llvm::StringRef PlatformRemoteAppleXR::GetDeviceSupportDirectoryName() {
152+
return "XROS DeviceSupport";
153+
}
154+
155+
llvm::StringRef PlatformRemoteAppleXR::GetPlatformName() {
156+
return "XROS.platform";
157+
}

0 commit comments

Comments
 (0)