Skip to content

[lldb] Upstream xros support in lldb #78389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/include/lldb/Utility/XcodeSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class XcodeSDK {
AppleTVOS,
WatchSimulator,
watchOS,
XRSimulator,
XROS,
bridgeOS,
Linux,
unknown = -1
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
#elif defined(TARGET_OS_WATCHOS) && TARGET_OS_WATCHOS == 1
arch_32.GetTriple().setOS(llvm::Triple::WatchOS);
arch_64.GetTriple().setOS(llvm::Triple::WatchOS);
#elif defined(TARGET_OS_XR) && TARGET_OS_XR == 1
arch_32.GetTriple().setOS(llvm::Triple::XROS);
arch_64.GetTriple().setOS(llvm::Triple::XROS);
#elif defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1
arch_32.GetTriple().setOS(llvm::Triple::MacOSX);
arch_64.GetTriple().setOS(llvm::Triple::MacOSX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ DynamicLoader *DynamicLoaderDarwinKernel::CreateInstance(Process *process,
case llvm::Triple::IOS:
case llvm::Triple::TvOS:
case llvm::Triple::WatchOS:
case llvm::Triple::XROS:
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
if (triple_ref.getVendor() != llvm::Triple::Apple) {
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process,
case llvm::Triple::IOS:
case llvm::Triple::TvOS:
case llvm::Triple::WatchOS:
case llvm::Triple::XROS:
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
create = triple_ref.getVendor() == llvm::Triple::Apple;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ DynamicLoader *DynamicLoaderMacOSXDYLD::CreateInstance(Process *process,
case llvm::Triple::IOS:
case llvm::Triple::TvOS:
case llvm::Triple::WatchOS:
case llvm::Triple::XROS:
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
create = triple_ref.getVendor() == llvm::Triple::Apple;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ uint32_t EmulateInstructionARM::GetFramePointerRegisterNumber() const {
case llvm::Triple::IOS:
case llvm::Triple::TvOS:
case llvm::Triple::WatchOS:
case llvm::Triple::XROS:
// NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
is_apple = true;
break;
Expand Down
11 changes: 10 additions & 1 deletion lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4916,6 +4916,14 @@ struct OSEnv {
environment =
llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
return;
case llvm::MachO::PLATFORM_XROS:
os_type = llvm::Triple::getOSTypeName(llvm::Triple::XROS);
return;
case llvm::MachO::PLATFORM_XROS_SIMULATOR:
os_type = llvm::Triple::getOSTypeName(llvm::Triple::XROS);
environment =
llvm::Triple::getEnvironmentTypeName(llvm::Triple::Simulator);
return;
default: {
Log *log(GetLog(LLDBLog::Symbols | LLDBLog::Process));
LLDB_LOGF(log, "unsupported platform in LC_BUILD_VERSION");
Expand Down Expand Up @@ -6483,7 +6491,8 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
(target_triple.getOS() == llvm::Triple::MacOSX ||
target_triple.getOS() == llvm::Triple::IOS ||
target_triple.getOS() == llvm::Triple::WatchOS ||
target_triple.getOS() == llvm::Triple::TvOS)) {
target_triple.getOS() == llvm::Triple::TvOS ||
target_triple.getOS() == llvm::Triple::XROS)) {
// NEED_BRIDGEOS_TRIPLE target_triple.getOS() == llvm::Triple::BridgeOS))
// {
bool make_core = false;
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Plugins/Platform/MacOSX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ list(APPEND PLUGIN_PLATFORM_MACOSX_SOURCES
PlatformRemoteAppleBridge.cpp
PlatformRemoteAppleTV.cpp
PlatformRemoteAppleWatch.cpp
PlatformRemoteAppleXR.cpp
PlatformRemoteDarwinDevice.cpp
PlatformRemoteMacOSX.cpp
PlatformRemoteiOS.cpp
Expand Down
37 changes: 37 additions & 0 deletions lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,41 @@ struct PlatformAppleWatchSimulator {
}
};

static const char *g_xros_plugin_name = "xros-simulator";
static const char *g_xros_description = "XROS simulator platform plug-in.";

/// XRSimulator Plugin.
struct PlatformXRSimulator {
static void Initialize() {
PluginManager::RegisterPlugin(g_xros_plugin_name, g_xros_description,
PlatformXRSimulator::CreateInstance);
}

static void Terminate() {
PluginManager::UnregisterPlugin(PlatformXRSimulator::CreateInstance);
}

static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
return PlatformAppleSimulator::CreateInstance(
"PlatformXRSimulator", g_xros_description,
ConstString(g_xros_plugin_name),
{llvm::Triple::aarch64, llvm::Triple::x86_64, llvm::Triple::x86},
llvm::Triple::XROS, {llvm::Triple::XROS},
{
#ifdef __APPLE__
#if __arm64__
"arm64e-apple-xros-simulator", "arm64-apple-xros-simulator",
#else
"x86_64-apple-xros-simulator", "x86_64h-apple-xros-simulator",
#endif
#endif
},
"XRSimulator.Internal.sdk", "XRSimulator.sdk",
XcodeSDK::Type::XRSimulator,
CoreSimulatorSupport::DeviceType::ProductFamilyID::appleXR, force,
arch);
}
};

static unsigned g_initialize_count = 0;

Expand All @@ -685,12 +720,14 @@ void PlatformAppleSimulator::Initialize() {
PlatformiOSSimulator::Initialize();
PlatformAppleTVSimulator::Initialize();
PlatformAppleWatchSimulator::Initialize();
PlatformXRSimulator::Initialize();
}
}

void PlatformAppleSimulator::Terminate() {
if (g_initialize_count > 0)
if (--g_initialize_count == 0) {
PlatformXRSimulator::Terminate();
PlatformAppleWatchSimulator::Terminate();
PlatformAppleTVSimulator::Terminate();
PlatformiOSSimulator::Terminate();
Expand Down
17 changes: 15 additions & 2 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,9 @@ FileSpec PlatformDarwin::GetSDKDirectoryForModules(XcodeSDK::Type sdk_type) {
case XcodeSDK::Type::AppleTVSimulator:
sdks_spec.AppendPathComponent("AppleTVSimulator.platform");
break;
case XcodeSDK::Type::XRSimulator:
sdks_spec.AppendPathComponent("XRSimulator.platform");
break;
default:
llvm_unreachable("unsupported sdk");
}
Expand Down Expand Up @@ -1032,6 +1035,9 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
case XcodeSDK::Type::watchOS:
use_current_os_version = get_host_os() == llvm::Triple::WatchOS;
break;
case XcodeSDK::Type::XROS:
use_current_os_version = get_host_os() == llvm::Triple::XROS;
break;
default:
break;
}
Expand All @@ -1049,8 +1055,10 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
version = object_file->GetMinimumOSVersion();
}
}
// Only add the version-min options if we got a version from somewhere
if (!version.empty() && sdk_type != XcodeSDK::Type::Linux) {
// Only add the version-min options if we got a version from somewhere.
// clang has no version-min clang flag for XROS.
if (!version.empty() && sdk_type != XcodeSDK::Type::Linux &&
sdk_type != XcodeSDK::Type::XROS) {
#define OPTION(PREFIX, NAME, VAR, ...) \
llvm::StringRef opt_##VAR = NAME; \
(void)opt_##VAR;
Expand Down Expand Up @@ -1079,6 +1087,9 @@ void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
case XcodeSDK::Type::watchOS:
minimum_version_option << opt_mwatchos_version_min_EQ;
break;
case XcodeSDK::Type::XRSimulator:
case XcodeSDK::Type::XROS:
// FIXME: Pass the right argument once it exists.
case XcodeSDK::Type::bridgeOS:
case XcodeSDK::Type::Linux:
case XcodeSDK::Type::unknown:
Expand Down Expand Up @@ -1343,6 +1354,8 @@ llvm::Triple::OSType PlatformDarwin::GetHostOSType() {
return llvm::Triple::TvOS;
#elif TARGET_OS_BRIDGE
return llvm::Triple::BridgeOS;
#elif TARGET_OS_XR
return llvm::Triple::XROS;
#else
#error "LLDB being compiled for an unrecognized Darwin OS"
#endif
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "PlatformRemoteAppleBridge.h"
#include "PlatformRemoteAppleTV.h"
#include "PlatformRemoteAppleWatch.h"
#include "PlatformRemoteAppleXR.h"
#endif
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Debugger.h"
Expand Down Expand Up @@ -53,6 +54,7 @@ void PlatformMacOSX::Initialize() {
PlatformRemoteAppleTV::Initialize();
PlatformRemoteAppleWatch::Initialize();
PlatformRemoteAppleBridge::Initialize();
PlatformRemoteAppleXR::Initialize();
#endif

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

#if defined(__APPLE__)
PlatformRemoteAppleXR::Terminate();
PlatformRemoteAppleBridge::Terminate();
PlatformRemoteAppleWatch::Terminate();
PlatformRemoteAppleTV::Terminate();
Expand Down
157 changes: 157 additions & 0 deletions lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleXR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
//===-- PlatformRemoteAppleXR.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <string>
#include <vector>

#include "PlatformRemoteAppleXR.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"

using namespace lldb;
using namespace lldb_private;

// Static Variables
static uint32_t g_xr_initialize_count = 0;

// Static Functions
void PlatformRemoteAppleXR::Initialize() {
PlatformDarwin::Initialize();

if (g_xr_initialize_count++ == 0) {
PluginManager::RegisterPlugin(PlatformRemoteAppleXR::GetPluginNameStatic(),
PlatformRemoteAppleXR::GetDescriptionStatic(),
PlatformRemoteAppleXR::CreateInstance);
}
}

void PlatformRemoteAppleXR::Terminate() {
if (g_xr_initialize_count > 0) {
if (--g_xr_initialize_count == 0) {
PluginManager::UnregisterPlugin(PlatformRemoteAppleXR::CreateInstance);
}
}

PlatformDarwin::Terminate();
}

PlatformSP PlatformRemoteAppleXR::CreateInstance(bool force,
const ArchSpec *arch) {
Log *log = GetLog(LLDBLog::Platform);
if (log) {
const char *arch_name;
if (arch && arch->GetArchitectureName())
arch_name = arch->GetArchitectureName();
else
arch_name = "<null>";

const char *triple_cstr =
arch ? arch->GetTriple().getTriple().c_str() : "<null>";

LLDB_LOGF(log, "PlatformRemoteAppleXR::%s(force=%s, arch={%s,%s})",
__FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
}

bool create = force;
if (!create && arch && arch->IsValid()) {
switch (arch->GetMachine()) {
case llvm::Triple::arm:
case llvm::Triple::aarch64:
case llvm::Triple::aarch64_32:
case llvm::Triple::thumb: {
const llvm::Triple &triple = arch->GetTriple();
llvm::Triple::VendorType vendor = triple.getVendor();
switch (vendor) {
case llvm::Triple::Apple:
create = true;
break;

#if defined(__APPLE__)
// Only accept "unknown" for the vendor if the host is Apple and
// "unknown" wasn't specified (it was just returned because it was NOT
// specified)
case llvm::Triple::UnknownVendor:
create = !arch->TripleVendorWasSpecified();
break;

#endif
default:
break;
}
if (create) {
switch (triple.getOS()) {
case llvm::Triple::XROS: // This is the right triple value for Apple
// XR debugging
break;

default:
create = false;
break;
}
}
} break;
default:
break;
}
}

#if defined(TARGET_OS_XR) && TARGET_OS_XR == 1
// If lldb is running on a XR device, this isn't a RemoteXR.
if (force == false) {
create = false;
}
#endif

if (create) {
LLDB_LOGF(log, "PlatformRemoteAppleXR::%s() creating platform",
__FUNCTION__);

return lldb::PlatformSP(new PlatformRemoteAppleXR());
}

LLDB_LOGF(log, "PlatformRemoteAppleXR::%s() aborting creation of platform",
__FUNCTION__);

return lldb::PlatformSP();
}

llvm::StringRef PlatformRemoteAppleXR::GetPluginNameStatic() {
return "remote-xros";
}

llvm::StringRef PlatformRemoteAppleXR::GetDescriptionStatic() {
return "Remote Apple XR platform plug-in.";
}

/// Default Constructor
PlatformRemoteAppleXR::PlatformRemoteAppleXR() : PlatformRemoteDarwinDevice() {}

std::vector<lldb_private::ArchSpec>
PlatformRemoteAppleXR::GetSupportedArchitectures(
const ArchSpec &process_host_arch) {
std::vector<ArchSpec> result;
result.push_back(ArchSpec("arm64-apple-xros"));
result.push_back(ArchSpec("arm64-apple-xros"));
return result;
}

llvm::StringRef PlatformRemoteAppleXR::GetDeviceSupportDirectoryName() {
return "XROS DeviceSupport";
}

llvm::StringRef PlatformRemoteAppleXR::GetPlatformName() {
return "XROS.platform";
}
Loading