brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · c7e734a Raw
158 lines · cpp
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-exception6//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 24using namespace lldb;25using namespace lldb_private;26 27// Static Variables28static uint32_t g_xr_initialize_count = 0;29 30// Static Functions31void 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 41void 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 51PlatformSP 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    else59      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 and84      // "unknown" wasn't specified (it was just returned because it was NOT85      // specified)86      case llvm::Triple::UnknownVendor:87        create = !arch->TripleVendorWasSpecified();88        break;89 90#endif91      default:92        break;93      }94      if (create) {95        switch (triple.getOS()) {96        case llvm::Triple::XROS: // This is the right triple value for Apple97                                 // XR debugging98          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 == 1112  // If lldb is running on a XR device, this isn't a RemoteXR.113  if (force == false) {114    create = false;115  }116#endif117 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 131llvm::StringRef PlatformRemoteAppleXR::GetPluginNameStatic() {132  return "remote-xros";133}134 135llvm::StringRef PlatformRemoteAppleXR::GetDescriptionStatic() {136  return "Remote Apple XR platform plug-in.";137}138 139/// Default Constructor140PlatformRemoteAppleXR::PlatformRemoteAppleXR() : PlatformRemoteDarwinDevice() {}141 142std::vector<lldb_private::ArchSpec>143PlatformRemoteAppleXR::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 151llvm::StringRef PlatformRemoteAppleXR::GetDeviceSupportDirectoryName() {152  return "XROS DeviceSupport";153}154 155llvm::StringRef PlatformRemoteAppleXR::GetPlatformName() {156  return "XROS.platform";157}158