Skip to content

Commit d5c4988

Browse files
JDevliegherecyndyishida
authored andcommitted
[lldb] Upstream xros support in lldb (llvm#78389)
Upstream support for debugging xros applications through LLDB. (cherry picked from commit 3b6a8f8)
1 parent 532a182 commit d5c4988

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
@@ -168,6 +168,7 @@ DynamicLoader *DynamicLoaderDarwinKernel::CreateInstance(Process *process,
168168
case llvm::Triple::IOS:
169169
case llvm::Triple::TvOS:
170170
case llvm::Triple::WatchOS:
171+
case llvm::Triple::XROS:
171172
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
172173
if (triple_ref.getVendor() != llvm::Triple::Apple) {
173174
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
@@ -4947,6 +4947,14 @@ struct OSEnv {
49474947
environment =
49484948
llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
49494949
return;
4950+
case llvm::MachO::PLATFORM_XROS:
4951+
os_type = llvm::Triple::getOSTypeName(llvm::Triple::XROS);
4952+
return;
4953+
case llvm::MachO::PLATFORM_XROS_SIMULATOR:
4954+
os_type = llvm::Triple::getOSTypeName(llvm::Triple::XROS);
4955+
environment =
4956+
llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
4957+
return;
49504958
default: {
49514959
Log *log(GetLog(LLDBLog::Symbols | LLDBLog::Process));
49524960
LLDB_LOGF(log, "unsupported platform in LC_BUILD_VERSION");
@@ -6513,7 +6521,8 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
65136521
(target_triple.getOS() == llvm::Triple::MacOSX ||
65146522
target_triple.getOS() == llvm::Triple::IOS ||
65156523
target_triple.getOS() == llvm::Triple::WatchOS ||
6516-
target_triple.getOS() == llvm::Triple::TvOS)) {
6524+
target_triple.getOS() == llvm::Triple::TvOS ||
6525+
target_triple.getOS() == llvm::Triple::XROS)) {
65176526
// NEED_BRIDGEOS_TRIPLE target_triple.getOS() == llvm::Triple::BridgeOS))
65186527
// {
65196528
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
@@ -676,6 +676,41 @@ struct PlatformAppleWatchSimulator {
676676
}
677677
};
678678

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

680715
static unsigned g_initialize_count = 0;
681716

@@ -686,12 +721,14 @@ void PlatformAppleSimulator::Initialize() {
686721
PlatformiOSSimulator::Initialize();
687722
PlatformAppleTVSimulator::Initialize();
688723
PlatformAppleWatchSimulator::Initialize();
724+
PlatformXRSimulator::Initialize();
689725
}
690726
}
691727

692728
void PlatformAppleSimulator::Terminate() {
693729
if (g_initialize_count > 0)
694730
if (--g_initialize_count == 0) {
731+
PlatformXRSimulator::Terminate();
695732
PlatformAppleWatchSimulator::Terminate();
696733
PlatformAppleTVSimulator::Terminate();
697734
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:
@@ -1330,6 +1341,8 @@ llvm::Triple::OSType PlatformDarwin::GetHostOSType() {
13301341
return llvm::Triple::TvOS;
13311342
#elif TARGET_OS_BRIDGE
13321343
return llvm::Triple::BridgeOS;
1344+
#elif TARGET_OS_XR
1345+
return llvm::Triple::XROS;
13331346
#else
13341347
#error "LLDB being compiled for an unrecognized Darwin OS"
13351348
#endif

0 commit comments

Comments
 (0)