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

+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
@@ -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

+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
@@ -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

+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
@@ -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

+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:
@@ -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

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)