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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 37 additions & 0 deletions
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

Lines changed: 15 additions & 2 deletions
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

0 commit comments

Comments
 (0)