Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,43 @@
list(APPEND PLUGIN_PLATFORM_MACOSX_SOURCES
PlatformDarwin.cpp
PlatformDarwinKernel.cpp
PlatformMacOSX.cpp
PlatformRemoteiOS.cpp
PlatformRemoteAppleTV.cpp
PlatformRemoteAppleWatch.cpp
PlatformRemoteDarwinDevice.cpp
)
list(APPEND PLUGIN_PLATFORM_MACOSX_DARWIN_ONLY_SOURCES
PlatformAppleSimulator.cpp
PlatformiOSSimulator.cpp
PlatformiOSSimulatorCoreSimulatorSupport.mm
PlatformAppleTVSimulator.cpp
PlatformAppleWatchSimulator.cpp
)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
include_directories(${LIBXML2_INCLUDE_DIR})
list(APPEND PLUGIN_PLATFORM_MACOSX_SOURCES
${PLUGIN_PLATFORM_MACOSX_DARWIN_ONLY_SOURCES})
else()
list(APPEND LLVM_OPTIONAL_SOURCES
${PLUGIN_PLATFORM_MACOSX_DARWIN_ONLY_SOURCES})
endif()
add_lldb_library(lldbPluginPlatformMacOSX PLUGIN
${PLUGIN_PLATFORM_MACOSX_SOURCES}
LINK_LIBS
clangBasic
lldbBreakpoint
lldbCore
lldbHost
lldbInterpreter
lldbSymbol
lldbTarget
lldbUtility
lldbPluginPlatformPOSIX
LINK_COMPONENTS
Support
)

View File

@@ -0,0 +1,270 @@
//===-- PlatformAppleSimulator.cpp ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "PlatformAppleSimulator.h"
// C Includes
#if defined(__APPLE__)
#include <dlfcn.h>
#endif
// C++ Includes
#include <mutex>
#include <thread>
// Other libraries and framework includes
// Project includes
#include "lldb/Host/PseudoTerminal.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/Support/Threading.h"
using namespace lldb;
using namespace lldb_private;
#if !defined(__APPLE__)
#define UNSUPPORTED_ERROR ("Apple simulators aren't supported on this platform")
#endif
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
void PlatformAppleSimulator::Initialize() { PlatformDarwin::Initialize(); }
void PlatformAppleSimulator::Terminate() { PlatformDarwin::Terminate(); }
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformAppleSimulator::PlatformAppleSimulator()
: PlatformDarwin(true), m_core_sim_path_mutex(),
m_core_simulator_framework_path(), m_device() {}
//------------------------------------------------------------------
/// Destructor.
///
/// The destructor is virtual since this class is designed to be
/// inherited from by the plug-in instance.
//------------------------------------------------------------------
PlatformAppleSimulator::~PlatformAppleSimulator() {}
lldb_private::Status PlatformAppleSimulator::LaunchProcess(
lldb_private::ProcessLaunchInfo &launch_info) {
#if defined(__APPLE__)
LoadCoreSimulator();
CoreSimulatorSupport::Device device(GetSimulatorDevice());
if (device.GetState() != CoreSimulatorSupport::Device::State::Booted) {
Status boot_err;
device.Boot(boot_err);
if (boot_err.Fail())
return boot_err;
}
auto spawned = device.Spawn(launch_info);
if (spawned) {
launch_info.SetProcessID(spawned.GetPID());
return Status();
} else
return spawned.GetError();
#else
Status err;
err.SetErrorString(UNSUPPORTED_ERROR);
return err;
#endif
}
void PlatformAppleSimulator::GetStatus(Stream &strm) {
#if defined(__APPLE__)
// This will get called by subclasses, so just output status on the
// current simulator
PlatformAppleSimulator::LoadCoreSimulator();
CoreSimulatorSupport::DeviceSet devices =
CoreSimulatorSupport::DeviceSet::GetAvailableDevices(
GetDeveloperDirectory());
const size_t num_devices = devices.GetNumDevices();
if (num_devices) {
strm.Printf("Available devices:\n");
for (size_t i = 0; i < num_devices; ++i) {
CoreSimulatorSupport::Device device = devices.GetDeviceAtIndex(i);
strm.Printf(" %s: %s\n", device.GetUDID().c_str(),
device.GetName().c_str());
}
if (m_device.hasValue() && m_device->operator bool()) {
strm.Printf("Current device: %s: %s", m_device->GetUDID().c_str(),
m_device->GetName().c_str());
if (m_device->GetState() == CoreSimulatorSupport::Device::State::Booted) {
strm.Printf(" state = booted");
}
strm.Printf("\nType \"platform connect <ARG>\" where <ARG> is a device "
"UDID or a device name to disconnect and connect to a "
"different device.\n");
} else {
strm.Printf("No current device is selected, \"platform connect <ARG>\" "
"where <ARG> is a device UDID or a device name to connect to "
"a specific device.\n");
}
} else {
strm.Printf("No devices are available.\n");
}
#else
strm.Printf(UNSUPPORTED_ERROR);
#endif
}
Status PlatformAppleSimulator::ConnectRemote(Args &args) {
#if defined(__APPLE__)
Status error;
if (args.GetArgumentCount() == 1) {
if (m_device)
DisconnectRemote();
PlatformAppleSimulator::LoadCoreSimulator();
const char *arg_cstr = args.GetArgumentAtIndex(0);
if (arg_cstr) {
std::string arg_str(arg_cstr);
CoreSimulatorSupport::DeviceSet devices =
CoreSimulatorSupport::DeviceSet::GetAvailableDevices(
GetDeveloperDirectory());
devices.ForEach(
[this, &arg_str](const CoreSimulatorSupport::Device &device) -> bool {
if (arg_str == device.GetUDID() || arg_str == device.GetName()) {
m_device = device;
return false; // Stop iterating
} else {
return true; // Keep iterating
}
});
if (!m_device)
error.SetErrorStringWithFormat(
"no device with UDID or name '%s' was found", arg_cstr);
}
} else {
error.SetErrorString("this command take a single UDID argument of the "
"device you want to connect to.");
}
return error;
#else
Status err;
err.SetErrorString(UNSUPPORTED_ERROR);
return err;
#endif
}
Status PlatformAppleSimulator::DisconnectRemote() {
#if defined(__APPLE__)
m_device.reset();
return Status();
#else
Status err;
err.SetErrorString(UNSUPPORTED_ERROR);
return err;
#endif
}
lldb::ProcessSP PlatformAppleSimulator::DebugProcess(
ProcessLaunchInfo &launch_info, Debugger &debugger,
Target *target, // Can be NULL, if NULL create a new target, else use
// existing one
Status &error) {
#if defined(__APPLE__)
ProcessSP process_sp;
// Make sure we stop at the entry point
launch_info.GetFlags().Set(eLaunchFlagDebug);
// We always launch the process we are going to debug in a separate process
// group, since then we can handle ^C interrupts ourselves w/o having to worry
// about the target getting them as well.
launch_info.SetLaunchInSeparateProcessGroup(true);
error = LaunchProcess(launch_info);
if (error.Success()) {
if (launch_info.GetProcessID() != LLDB_INVALID_PROCESS_ID) {
ProcessAttachInfo attach_info(launch_info);
process_sp = Attach(attach_info, debugger, target, error);
if (process_sp) {
launch_info.SetHijackListener(attach_info.GetHijackListener());
// Since we attached to the process, it will think it needs to detach
// if the process object just goes away without an explicit call to
// Process::Kill() or Process::Detach(), so let it know to kill the
// process if this happens.
process_sp->SetShouldDetach(false);
// If we didn't have any file actions, the pseudo terminal might
// have been used where the slave side was given as the file to
// open for stdin/out/err after we have already opened the master
// so we can read/write stdin/out/err.
int pty_fd = launch_info.GetPTY().ReleaseMasterFileDescriptor();
if (pty_fd != PseudoTerminal::invalid_fd) {
process_sp->SetSTDIOFileDescriptor(pty_fd);
}
}
}
}
return process_sp;
#else
return ProcessSP();
#endif
}
FileSpec PlatformAppleSimulator::GetCoreSimulatorPath() {
#if defined(__APPLE__)
std::lock_guard<std::mutex> guard(m_core_sim_path_mutex);
if (!m_core_simulator_framework_path.hasValue()) {
const char *developer_dir = GetDeveloperDirectory();
if (developer_dir) {
StreamString cs_path;
cs_path.Printf(
"%s/Library/PrivateFrameworks/CoreSimulator.framework/CoreSimulator",
developer_dir);
const bool resolve_path = true;
m_core_simulator_framework_path =
FileSpec(cs_path.GetData(), resolve_path);
}
}
return m_core_simulator_framework_path.getValue();
#else
return FileSpec();
#endif
}
void PlatformAppleSimulator::LoadCoreSimulator() {
#if defined(__APPLE__)
static llvm::once_flag g_load_core_sim_flag;
llvm::call_once(g_load_core_sim_flag, [this] {
const std::string core_sim_path(GetCoreSimulatorPath().GetPath());
if (core_sim_path.size())
dlopen(core_sim_path.c_str(), RTLD_LAZY);
});
#endif
}
#if defined(__APPLE__)
CoreSimulatorSupport::Device PlatformAppleSimulator::GetSimulatorDevice() {
if (!m_device.hasValue()) {
const CoreSimulatorSupport::DeviceType::ProductFamilyID dev_id =
CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone;
m_device = CoreSimulatorSupport::DeviceSet::GetAvailableDevices(
GetDeveloperDirectory())
.GetFanciest(dev_id);
}
if (m_device.hasValue())
return m_device.getValue();
else
return CoreSimulatorSupport::Device();
}
#endif

View File

@@ -0,0 +1,72 @@
//===-- PlatformAppleSimulator.h --------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformAppleSimulator_h_
#define liblldb_PlatformAppleSimulator_h_
// C Includes
// C++ Includes
#include <mutex>
// Other libraries and framework includes
// Project includes
#include "PlatformDarwin.h"
#include "PlatformiOSSimulatorCoreSimulatorSupport.h"
#include "lldb/Utility/FileSpec.h"
#include "llvm/ADT/Optional.h"
class PlatformAppleSimulator : public PlatformDarwin {
public:
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
static void Initialize();
static void Terminate();
//------------------------------------------------------------
// Class Methods
//------------------------------------------------------------
PlatformAppleSimulator();
virtual ~PlatformAppleSimulator();
lldb_private::Status
LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
void GetStatus(lldb_private::Stream &strm) override;
lldb_private::Status ConnectRemote(lldb_private::Args &args) override;
lldb_private::Status DisconnectRemote() override;
lldb::ProcessSP DebugProcess(lldb_private::ProcessLaunchInfo &launch_info,
lldb_private::Debugger &debugger,
lldb_private::Target *target,
lldb_private::Status &error) override;
protected:
std::mutex m_core_sim_path_mutex;
llvm::Optional<lldb_private::FileSpec> m_core_simulator_framework_path;
llvm::Optional<CoreSimulatorSupport::Device> m_device;
lldb_private::FileSpec GetCoreSimulatorPath();
void LoadCoreSimulator();
#if defined(__APPLE__)
CoreSimulatorSupport::Device GetSimulatorDevice();
#endif
private:
DISALLOW_COPY_AND_ASSIGN(PlatformAppleSimulator);
};
#endif // liblldb_PlatformAppleSimulator_h_

View File

@@ -0,0 +1,395 @@
//===-- PlatformAppleTVSimulator.cpp ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "PlatformAppleTVSimulator.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/Support/FileSystem.h"
using namespace lldb;
using namespace lldb_private;
//------------------------------------------------------------------
// Static Variables
//------------------------------------------------------------------
static uint32_t g_initialize_count = 0;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
void PlatformAppleTVSimulator::Initialize() {
PlatformDarwin::Initialize();
if (g_initialize_count++ == 0) {
PluginManager::RegisterPlugin(
PlatformAppleTVSimulator::GetPluginNameStatic(),
PlatformAppleTVSimulator::GetDescriptionStatic(),
PlatformAppleTVSimulator::CreateInstance);
}
}
void PlatformAppleTVSimulator::Terminate() {
if (g_initialize_count > 0) {
if (--g_initialize_count == 0) {
PluginManager::UnregisterPlugin(PlatformAppleTVSimulator::CreateInstance);
}
}
PlatformDarwin::Terminate();
}
PlatformSP PlatformAppleTVSimulator::CreateInstance(bool force,
const ArchSpec *arch) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_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>";
log->Printf("PlatformAppleTVSimulator::%s(force=%s, arch={%s,%s})",
__FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
}
bool create = force;
if (create == false && arch && arch->IsValid()) {
switch (arch->GetMachine()) {
case llvm::Triple::x86_64: {
const llvm::Triple &triple = arch->GetTriple();
switch (triple.getVendor()) {
case llvm::Triple::Apple:
create = true;
break;
#if defined(__APPLE__)
// Only accept "unknown" for the vendor if the host is Apple and
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownArch:
create = !arch->TripleVendorWasSpecified();
break;
#endif
default:
break;
}
if (create) {
switch (triple.getOS()) {
case llvm::Triple::TvOS:
break;
#if defined(__APPLE__)
// Only accept "unknown" for the OS if the host is Apple and
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownOS:
create = !arch->TripleOSWasSpecified();
break;
#endif
default:
create = false;
break;
}
}
} break;
default:
break;
}
}
if (create) {
if (log)
log->Printf("PlatformAppleTVSimulator::%s() creating platform",
__FUNCTION__);
return PlatformSP(new PlatformAppleTVSimulator());
}
if (log)
log->Printf("PlatformAppleTVSimulator::%s() aborting creation of platform",
__FUNCTION__);
return PlatformSP();
}
lldb_private::ConstString PlatformAppleTVSimulator::GetPluginNameStatic() {
static ConstString g_name("tvos-simulator");
return g_name;
}
const char *PlatformAppleTVSimulator::GetDescriptionStatic() {
return "Apple TV simulator platform plug-in.";
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformAppleTVSimulator::PlatformAppleTVSimulator()
: PlatformDarwin(true), m_sdk_dir_mutex(), m_sdk_directory() {}
//------------------------------------------------------------------
/// Destructor.
///
/// The destructor is virtual since this class is designed to be
/// inherited from by the plug-in instance.
//------------------------------------------------------------------
PlatformAppleTVSimulator::~PlatformAppleTVSimulator() {}
void PlatformAppleTVSimulator::GetStatus(Stream &strm) {
Platform::GetStatus(strm);
const char *sdk_directory = GetSDKDirectoryAsCString();
if (sdk_directory)
strm.Printf(" SDK Path: \"%s\"\n", sdk_directory);
else
strm.PutCString(" SDK Path: error: unable to locate SDK\n");
}
Status PlatformAppleTVSimulator::ResolveExecutable(
const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp,
const FileSpecList *module_search_paths_ptr) {
Status error;
// Nothing special to do here, just use the actual file and architecture
ModuleSpec resolved_module_spec(module_spec);
// If we have "ls" as the exe_file, resolve the executable loation based on
// the current path variables
// TODO: resolve bare executables in the Platform SDK
// if (!resolved_exe_file.Exists())
// resolved_exe_file.ResolveExecutableLocation ();
// Resolve any executable within a bundle on MacOSX
// TODO: verify that this handles shallow bundles, if not then implement one
// ourselves
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
if (resolved_module_spec.GetFileSpec().Exists()) {
if (resolved_module_spec.GetArchitecture().IsValid()) {
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
NULL, NULL, NULL);
if (exe_module_sp && exe_module_sp->GetObjectFile())
return error;
exe_module_sp.reset();
}
// No valid architecture was specified or the exact ARM slice wasn't
// found so ask the platform for the architectures that we should be
// using (in the correct order) and see if we can find a match that way
StreamString arch_names;
ArchSpec platform_arch;
for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
idx, resolved_module_spec.GetArchitecture());
++idx) {
// Only match x86 with x86 and x86_64 with x86_64...
if (!module_spec.GetArchitecture().IsValid() ||
module_spec.GetArchitecture().GetCore() ==
resolved_module_spec.GetArchitecture().GetCore()) {
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
NULL, NULL, NULL);
// Did we find an executable using one of the
if (error.Success()) {
if (exe_module_sp && exe_module_sp->GetObjectFile())
break;
else
error.SetErrorToGenericError();
}
if (idx > 0)
arch_names.PutCString(", ");
arch_names.PutCString(platform_arch.GetArchitectureName());
}
}
if (error.Fail() || !exe_module_sp) {
if (resolved_module_spec.GetFileSpec().Readable()) {
error.SetErrorStringWithFormat(
"'%s' doesn't contain any '%s' platform architectures: %s",
resolved_module_spec.GetFileSpec().GetPath().c_str(),
GetPluginName().GetCString(), arch_names.GetString().str().c_str());
} else {
error.SetErrorStringWithFormat(
"'%s' is not readable",
resolved_module_spec.GetFileSpec().GetPath().c_str());
}
}
} else {
error.SetErrorStringWithFormat("'%s' does not exist",
module_spec.GetFileSpec().GetPath().c_str());
}
return error;
}
static FileSpec::EnumerateDirectoryResult
EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft,
const FileSpec &file_spec) {
if (ft == llvm::sys::fs::file_type::directory_file) {
const char *filename = file_spec.GetFilename().GetCString();
if (filename &&
strncmp(filename, "AppleTVSimulator", strlen("AppleTVSimulator")) ==
0) {
::snprintf((char *)baton, PATH_MAX, "%s", filename);
return FileSpec::eEnumerateDirectoryResultQuit;
}
}
return FileSpec::eEnumerateDirectoryResultNext;
}
const char *PlatformAppleTVSimulator::GetSDKDirectoryAsCString() {
std::lock_guard<std::mutex> guard(m_sdk_dir_mutex);
if (m_sdk_directory.empty()) {
const char *developer_dir = GetDeveloperDirectory();
if (developer_dir) {
char sdks_directory[PATH_MAX];
char sdk_dirname[PATH_MAX];
sdk_dirname[0] = '\0';
snprintf(sdks_directory, sizeof(sdks_directory),
"%s/Platforms/AppleTVSimulator.platform/Developer/SDKs",
developer_dir);
FileSpec simulator_sdk_spec;
bool find_directories = true;
bool find_files = false;
bool find_other = false;
FileSpec::EnumerateDirectory(sdks_directory, find_directories, find_files,
find_other, EnumerateDirectoryCallback,
sdk_dirname);
if (sdk_dirname[0]) {
m_sdk_directory = sdks_directory;
m_sdk_directory.append(1, '/');
m_sdk_directory.append(sdk_dirname);
return m_sdk_directory.c_str();
}
}
// Assign a single NULL character so we know we tried to find the device
// support directory and we don't keep trying to find it over and over.
m_sdk_directory.assign(1, '\0');
}
// We should have put a single NULL character into m_sdk_directory
// or it should have a valid path if the code gets here
assert(m_sdk_directory.empty() == false);
if (m_sdk_directory[0])
return m_sdk_directory.c_str();
return NULL;
}
Status PlatformAppleTVSimulator::GetSymbolFile(const FileSpec &platform_file,
const UUID *uuid_ptr,
FileSpec &local_file) {
Status error;
char platform_file_path[PATH_MAX];
if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path))) {
char resolved_path[PATH_MAX];
const char *sdk_dir = GetSDKDirectoryAsCString();
if (sdk_dir) {
::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", sdk_dir,
platform_file_path);
// First try in the SDK and see if the file is in there
local_file.SetFile(resolved_path, true);
if (local_file.Exists())
return error;
// Else fall back to the actual path itself
local_file.SetFile(platform_file_path, true);
if (local_file.Exists())
return error;
}
error.SetErrorStringWithFormat(
"unable to locate a platform file for '%s' in platform '%s'",
platform_file_path, GetPluginName().GetCString());
} else {
error.SetErrorString("invalid platform file argument");
}
return error;
}
Status PlatformAppleTVSimulator::GetSharedModule(
const ModuleSpec &module_spec, lldb_private::Process *process,
ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,
ModuleSP *old_module_sp_ptr, bool *did_create_ptr) {
// For AppleTV, the SDK files are all cached locally on the host
// system. So first we ask for the file in the cached SDK,
// then we attempt to get a shared module for the right architecture
// with the right UUID.
Status error;
ModuleSpec platform_module_spec(module_spec);
const FileSpec &platform_file = module_spec.GetFileSpec();
error = GetSymbolFile(platform_file, module_spec.GetUUIDPtr(),
platform_module_spec.GetFileSpec());
if (error.Success()) {
error = ResolveExecutable(platform_module_spec, module_sp,
module_search_paths_ptr);
} else {
const bool always_create = false;
error = ModuleList::GetSharedModule(
module_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr,
did_create_ptr, always_create);
}
if (module_sp)
module_sp->SetPlatformFileSpec(platform_file);
return error;
}
uint32_t PlatformAppleTVSimulator::FindProcesses(
const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
ProcessInstanceInfoList all_osx_process_infos;
// First we get all OSX processes
const uint32_t n = Host::FindProcesses(match_info, all_osx_process_infos);
// Now we filter them down to only the TvOS triples
for (uint32_t i = 0; i < n; ++i) {
const ProcessInstanceInfo &proc_info =
all_osx_process_infos.GetProcessInfoAtIndex(i);
if (proc_info.GetArchitecture().GetTriple().getOS() == llvm::Triple::TvOS) {
process_infos.Append(proc_info);
}
}
return process_infos.GetSize();
}
bool PlatformAppleTVSimulator::GetSupportedArchitectureAtIndex(uint32_t idx,
ArchSpec &arch) {
static const ArchSpec platform_arch(
HostInfo::GetArchitecture(HostInfo::eArchKind64));
if (idx == 0) {
arch = platform_arch;
if (arch.IsValid()) {
arch.GetTriple().setOS(llvm::Triple::TvOS);
return true;
}
}
return false;
}

View File

@@ -0,0 +1,99 @@
//===-- PlatformAppleTVSimulator.h ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformAppleTVSimulator_h_
#define liblldb_PlatformAppleTVSimulator_h_
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "PlatformDarwin.h"
class PlatformAppleTVSimulator : public PlatformDarwin {
public:
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
static lldb::PlatformSP CreateInstance(bool force,
const lldb_private::ArchSpec *arch);
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetDescriptionStatic();
//------------------------------------------------------------
// Class Methods
//------------------------------------------------------------
PlatformAppleTVSimulator();
virtual ~PlatformAppleTVSimulator();
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
lldb_private::ConstString GetPluginName() override {
return GetPluginNameStatic();
}
uint32_t GetPluginVersion() override { return 1; }
//------------------------------------------------------------
// lldb_private::Platform functions
//------------------------------------------------------------
lldb_private::Status ResolveExecutable(
const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr) override;
const char *GetDescription() override { return GetDescriptionStatic(); }
void GetStatus(lldb_private::Stream &strm) override;
virtual lldb_private::Status
GetSymbolFile(const lldb_private::FileSpec &platform_file,
const lldb_private::UUID *uuid_ptr,
lldb_private::FileSpec &local_file);
lldb_private::Status
GetSharedModule(const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr,
bool *did_create_ptr) override;
uint32_t
FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info,
lldb_private::ProcessInstanceInfoList &process_infos) override;
bool GetSupportedArchitectureAtIndex(uint32_t idx,
lldb_private::ArchSpec &arch) override;
void
AddClangModuleCompilationOptions(lldb_private::Target *target,
std::vector<std::string> &options) override {
return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
target, options, PlatformDarwin::SDKType::iPhoneSimulator);
}
protected:
std::mutex m_sdk_dir_mutex;
std::string m_sdk_directory;
std::string m_build_update;
const char *GetSDKDirectoryAsCString();
private:
DISALLOW_COPY_AND_ASSIGN(PlatformAppleTVSimulator);
};
#endif // liblldb_PlatformAppleTVSimulator_h_

View File

@@ -0,0 +1,396 @@
//===-- PlatformAppleWatchSimulator.cpp -------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "PlatformAppleWatchSimulator.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
using namespace lldb;
using namespace lldb_private;
//------------------------------------------------------------------
// Static Variables
//------------------------------------------------------------------
static uint32_t g_initialize_count = 0;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
void PlatformAppleWatchSimulator::Initialize() {
PlatformDarwin::Initialize();
if (g_initialize_count++ == 0) {
PluginManager::RegisterPlugin(
PlatformAppleWatchSimulator::GetPluginNameStatic(),
PlatformAppleWatchSimulator::GetDescriptionStatic(),
PlatformAppleWatchSimulator::CreateInstance);
}
}
void PlatformAppleWatchSimulator::Terminate() {
if (g_initialize_count > 0) {
if (--g_initialize_count == 0) {
PluginManager::UnregisterPlugin(
PlatformAppleWatchSimulator::CreateInstance);
}
}
PlatformDarwin::Terminate();
}
PlatformSP PlatformAppleWatchSimulator::CreateInstance(bool force,
const ArchSpec *arch) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_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>";
log->Printf("PlatformAppleWatchSimulator::%s(force=%s, arch={%s,%s})",
__FUNCTION__, force ? "true" : "false", arch_name, triple_cstr);
}
bool create = force;
if (create == false && arch && arch->IsValid()) {
switch (arch->GetMachine()) {
case llvm::Triple::x86_64: {
const llvm::Triple &triple = arch->GetTriple();
switch (triple.getVendor()) {
case llvm::Triple::Apple:
create = true;
break;
#if defined(__APPLE__)
// Only accept "unknown" for the vendor if the host is Apple and
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownArch:
create = !arch->TripleVendorWasSpecified();
break;
#endif
default:
break;
}
if (create) {
switch (triple.getOS()) {
case llvm::Triple::WatchOS:
break;
#if defined(__APPLE__)
// Only accept "unknown" for the OS if the host is Apple and
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownOS:
create = !arch->TripleOSWasSpecified();
break;
#endif
default:
create = false;
break;
}
}
} break;
default:
break;
}
}
if (create) {
if (log)
log->Printf("PlatformAppleWatchSimulator::%s() creating platform",
__FUNCTION__);
return PlatformSP(new PlatformAppleWatchSimulator());
}
if (log)
log->Printf(
"PlatformAppleWatchSimulator::%s() aborting creation of platform",
__FUNCTION__);
return PlatformSP();
}
lldb_private::ConstString PlatformAppleWatchSimulator::GetPluginNameStatic() {
static ConstString g_name("watchos-simulator");
return g_name;
}
const char *PlatformAppleWatchSimulator::GetDescriptionStatic() {
return "Apple Watch simulator platform plug-in.";
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformAppleWatchSimulator::PlatformAppleWatchSimulator()
: PlatformDarwin(true), m_sdk_directory() {}
//------------------------------------------------------------------
/// Destructor.
///
/// The destructor is virtual since this class is designed to be
/// inherited from by the plug-in instance.
//------------------------------------------------------------------
PlatformAppleWatchSimulator::~PlatformAppleWatchSimulator() {}
void PlatformAppleWatchSimulator::GetStatus(Stream &strm) {
Platform::GetStatus(strm);
const char *sdk_directory = GetSDKDirectoryAsCString();
if (sdk_directory)
strm.Printf(" SDK Path: \"%s\"\n", sdk_directory);
else
strm.PutCString(" SDK Path: error: unable to locate SDK\n");
}
Status PlatformAppleWatchSimulator::ResolveExecutable(
const ModuleSpec &module_spec, lldb::ModuleSP &exe_module_sp,
const FileSpecList *module_search_paths_ptr) {
Status error;
// Nothing special to do here, just use the actual file and architecture
ModuleSpec resolved_module_spec(module_spec);
// If we have "ls" as the exe_file, resolve the executable loation based on
// the current path variables
// TODO: resolve bare executables in the Platform SDK
// if (!resolved_exe_file.Exists())
// resolved_exe_file.ResolveExecutableLocation ();
// Resolve any executable within a bundle on MacOSX
// TODO: verify that this handles shallow bundles, if not then implement one
// ourselves
Host::ResolveExecutableInBundle(resolved_module_spec.GetFileSpec());
if (resolved_module_spec.GetFileSpec().Exists()) {
if (resolved_module_spec.GetArchitecture().IsValid()) {
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
NULL, NULL, NULL);
if (exe_module_sp && exe_module_sp->GetObjectFile())
return error;
exe_module_sp.reset();
}
// No valid architecture was specified or the exact ARM slice wasn't
// found so ask the platform for the architectures that we should be
// using (in the correct order) and see if we can find a match that way
StreamString arch_names;
ArchSpec platform_arch;
for (uint32_t idx = 0; GetSupportedArchitectureAtIndex(
idx, resolved_module_spec.GetArchitecture());
++idx) {
// Only match x86 with x86 and x86_64 with x86_64...
if (!module_spec.GetArchitecture().IsValid() ||
module_spec.GetArchitecture().GetCore() ==
resolved_module_spec.GetArchitecture().GetCore()) {
error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
NULL, NULL, NULL);
// Did we find an executable using one of the
if (error.Success()) {
if (exe_module_sp && exe_module_sp->GetObjectFile())
break;
else
error.SetErrorToGenericError();
}
if (idx > 0)
arch_names.PutCString(", ");
arch_names.PutCString(platform_arch.GetArchitectureName());
}
}
if (error.Fail() || !exe_module_sp) {
if (resolved_module_spec.GetFileSpec().Readable()) {
error.SetErrorStringWithFormat(
"'%s' doesn't contain any '%s' platform architectures: %s",
resolved_module_spec.GetFileSpec().GetPath().c_str(),
GetPluginName().GetCString(), arch_names.GetString().str().c_str());
} else {
error.SetErrorStringWithFormat(
"'%s' is not readable",
resolved_module_spec.GetFileSpec().GetPath().c_str());
}
}
} else {
error.SetErrorStringWithFormat("'%s' does not exist",
module_spec.GetFileSpec().GetPath().c_str());
}
return error;
}
static FileSpec::EnumerateDirectoryResult
EnumerateDirectoryCallback(void *baton, llvm::sys::fs::file_type ft,
const FileSpec &file_spec) {
if (ft == llvm::sys::fs::file_type::directory_file) {
const char *filename = file_spec.GetFilename().GetCString();
if (filename &&
strncmp(filename, "AppleWatchSimulator",
strlen("AppleWatchSimulator")) == 0) {
::snprintf((char *)baton, PATH_MAX, "%s", filename);
return FileSpec::eEnumerateDirectoryResultQuit;
}
}
return FileSpec::eEnumerateDirectoryResultNext;
}
const char *PlatformAppleWatchSimulator::GetSDKDirectoryAsCString() {
std::lock_guard<std::mutex> guard(m_sdk_dir_mutex);
if (m_sdk_directory.empty()) {
const char *developer_dir = GetDeveloperDirectory();
if (developer_dir) {
char sdks_directory[PATH_MAX];
char sdk_dirname[PATH_MAX];
sdk_dirname[0] = '\0';
snprintf(sdks_directory, sizeof(sdks_directory),
"%s/Platforms/AppleWatchSimulator.platform/Developer/SDKs",
developer_dir);
FileSpec simulator_sdk_spec;
bool find_directories = true;
bool find_files = false;
bool find_other = false;
FileSpec::EnumerateDirectory(sdks_directory, find_directories, find_files,
find_other, EnumerateDirectoryCallback,
sdk_dirname);
if (sdk_dirname[0]) {
m_sdk_directory = sdks_directory;
m_sdk_directory.append(1, '/');
m_sdk_directory.append(sdk_dirname);
return m_sdk_directory.c_str();
}
}
// Assign a single NULL character so we know we tried to find the device
// support directory and we don't keep trying to find it over and over.
m_sdk_directory.assign(1, '\0');
}
// We should have put a single NULL character into m_sdk_directory
// or it should have a valid path if the code gets here
assert(m_sdk_directory.empty() == false);
if (m_sdk_directory[0])
return m_sdk_directory.c_str();
return NULL;
}
Status PlatformAppleWatchSimulator::GetSymbolFile(const FileSpec &platform_file,
const UUID *uuid_ptr,
FileSpec &local_file) {
Status error;
char platform_file_path[PATH_MAX];
if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path))) {
char resolved_path[PATH_MAX];
const char *sdk_dir = GetSDKDirectoryAsCString();
if (sdk_dir) {
::snprintf(resolved_path, sizeof(resolved_path), "%s/%s", sdk_dir,
platform_file_path);
// First try in the SDK and see if the file is in there
local_file.SetFile(resolved_path, true);
if (local_file.Exists())
return error;
// Else fall back to the actual path itself
local_file.SetFile(platform_file_path, true);
if (local_file.Exists())
return error;
}
error.SetErrorStringWithFormat(
"unable to locate a platform file for '%s' in platform '%s'",
platform_file_path, GetPluginName().GetCString());
} else {
error.SetErrorString("invalid platform file argument");
}
return error;
}
Status PlatformAppleWatchSimulator::GetSharedModule(
const ModuleSpec &module_spec, lldb_private::Process *process,
ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr,
ModuleSP *old_module_sp_ptr, bool *did_create_ptr) {
// For AppleWatch, the SDK files are all cached locally on the host
// system. So first we ask for the file in the cached SDK,
// then we attempt to get a shared module for the right architecture
// with the right UUID.
Status error;
ModuleSpec platform_module_spec(module_spec);
const FileSpec &platform_file = module_spec.GetFileSpec();
error = GetSymbolFile(platform_file, module_spec.GetUUIDPtr(),
platform_module_spec.GetFileSpec());
if (error.Success()) {
error = ResolveExecutable(platform_module_spec, module_sp,
module_search_paths_ptr);
} else {
const bool always_create = false;
error = ModuleList::GetSharedModule(
module_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr,
did_create_ptr, always_create);
}
if (module_sp)
module_sp->SetPlatformFileSpec(platform_file);
return error;
}
uint32_t PlatformAppleWatchSimulator::FindProcesses(
const ProcessInstanceInfoMatch &match_info,
ProcessInstanceInfoList &process_infos) {
ProcessInstanceInfoList all_osx_process_infos;
// First we get all OSX processes
const uint32_t n = Host::FindProcesses(match_info, all_osx_process_infos);
// Now we filter them down to only the WatchOS triples
for (uint32_t i = 0; i < n; ++i) {
const ProcessInstanceInfo &proc_info =
all_osx_process_infos.GetProcessInfoAtIndex(i);
if (proc_info.GetArchitecture().GetTriple().getOS() ==
llvm::Triple::WatchOS) {
process_infos.Append(proc_info);
}
}
return process_infos.GetSize();
}
bool PlatformAppleWatchSimulator::GetSupportedArchitectureAtIndex(
uint32_t idx, ArchSpec &arch) {
static const ArchSpec platform_arch(
HostInfo::GetArchitecture(HostInfo::eArchKind64));
if (idx == 0) {
arch = platform_arch;
if (arch.IsValid()) {
arch.GetTriple().setOS(llvm::Triple::WatchOS);
return true;
}
}
return false;
}

View File

@@ -0,0 +1,99 @@
//===-- PlatformAppleWatchSimulator.h ---------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformAppleWatchSimulator_h_
#define liblldb_PlatformAppleWatchSimulator_h_
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "PlatformDarwin.h"
class PlatformAppleWatchSimulator : public PlatformDarwin {
public:
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
static lldb::PlatformSP CreateInstance(bool force,
const lldb_private::ArchSpec *arch);
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetDescriptionStatic();
//------------------------------------------------------------
// Class Methods
//------------------------------------------------------------
PlatformAppleWatchSimulator();
virtual ~PlatformAppleWatchSimulator();
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
lldb_private::ConstString GetPluginName() override {
return GetPluginNameStatic();
}
uint32_t GetPluginVersion() override { return 1; }
//------------------------------------------------------------
// lldb_private::Platform functions
//------------------------------------------------------------
lldb_private::Status ResolveExecutable(
const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr) override;
const char *GetDescription() override { return GetDescriptionStatic(); }
void GetStatus(lldb_private::Stream &strm) override;
virtual lldb_private::Status
GetSymbolFile(const lldb_private::FileSpec &platform_file,
const lldb_private::UUID *uuid_ptr,
lldb_private::FileSpec &local_file);
lldb_private::Status
GetSharedModule(const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr,
bool *did_create_ptr) override;
uint32_t
FindProcesses(const lldb_private::ProcessInstanceInfoMatch &match_info,
lldb_private::ProcessInstanceInfoList &process_infos) override;
bool GetSupportedArchitectureAtIndex(uint32_t idx,
lldb_private::ArchSpec &arch) override;
void
AddClangModuleCompilationOptions(lldb_private::Target *target,
std::vector<std::string> &options) override {
return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
target, options, PlatformDarwin::SDKType::iPhoneSimulator);
}
protected:
std::mutex m_sdk_dir_mutex;
std::string m_sdk_directory;
std::string m_build_update;
const char *GetSDKDirectoryAsCString();
private:
DISALLOW_COPY_AND_ASSIGN(PlatformAppleWatchSimulator);
};
#endif // liblldb_PlatformAppleWatchSimulator_h_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,145 @@
//===-- PlatformDarwin.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformDarwin_h_
#define liblldb_PlatformDarwin_h_
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
#include "lldb/Utility/FileSpec.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include <string>
#include <tuple>
class PlatformDarwin : public PlatformPOSIX {
public:
PlatformDarwin(bool is_host);
~PlatformDarwin() override;
//------------------------------------------------------------
// lldb_private::Platform functions
//------------------------------------------------------------
lldb_private::Status
ResolveSymbolFile(lldb_private::Target &target,
const lldb_private::ModuleSpec &sym_spec,
lldb_private::FileSpec &sym_file) override;
lldb_private::FileSpecList LocateExecutableScriptingResources(
lldb_private::Target *target, lldb_private::Module &module,
lldb_private::Stream *feedback_stream) override;
lldb_private::Status
GetSharedModule(const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr,
bool *did_create_ptr) override;
size_t GetSoftwareBreakpointTrapOpcode(
lldb_private::Target &target,
lldb_private::BreakpointSite *bp_site) override;
lldb::BreakpointSP
SetThreadCreationBreakpoint(lldb_private::Target &target) override;
bool ModuleIsExcludedForUnconstrainedSearches(
lldb_private::Target &target, const lldb::ModuleSP &module_sp) override;
bool ARMGetSupportedArchitectureAtIndex(uint32_t idx,
lldb_private::ArchSpec &arch);
bool x86GetSupportedArchitectureAtIndex(uint32_t idx,
lldb_private::ArchSpec &arch);
int32_t GetResumeCountForLaunchInfo(
lldb_private::ProcessLaunchInfo &launch_info) override;
void CalculateTrapHandlerSymbolNames() override;
bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update,
lldb_private::Process *process = nullptr) override;
bool SupportsModules() override { return true; }
lldb_private::ConstString
GetFullNameForDylib(lldb_private::ConstString basename) override;
lldb_private::FileSpec LocateExecutable(const char *basename) override;
lldb_private::Status
LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
static std::tuple<uint32_t, uint32_t, uint32_t, llvm::StringRef>
ParseVersionBuildDir(llvm::StringRef str);
protected:
void ReadLibdispatchOffsetsAddress(lldb_private::Process *process);
void ReadLibdispatchOffsets(lldb_private::Process *process);
virtual lldb_private::Status GetSharedModuleWithLocalCache(
const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr, bool *did_create_ptr);
enum class SDKType {
MacOSX = 0,
iPhoneSimulator,
iPhoneOS,
};
static bool SDKSupportsModules(SDKType sdk_type, uint32_t major,
uint32_t minor, uint32_t micro);
static bool SDKSupportsModules(SDKType desired_type,
const lldb_private::FileSpec &sdk_path);
struct SDKEnumeratorInfo {
lldb_private::FileSpec found_path;
SDKType sdk_type;
};
static lldb_private::FileSpec::EnumerateDirectoryResult
DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,
const lldb_private::FileSpec &spec);
static lldb_private::FileSpec
FindSDKInXcodeForModules(SDKType sdk_type,
const lldb_private::FileSpec &sdks_spec);
static lldb_private::FileSpec
GetSDKDirectoryForModules(PlatformDarwin::SDKType sdk_type);
void
AddClangModuleCompilationOptionsForSDKType(lldb_private::Target *target,
std::vector<std::string> &options,
SDKType sdk_type);
const char *GetDeveloperDirectory();
lldb_private::Status
FindBundleBinaryInExecSearchPaths (const lldb_private::ModuleSpec &module_spec, lldb_private::Process *process,
lldb::ModuleSP &module_sp, const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr, bool *did_create_ptr);
std::string m_developer_directory;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformDarwin);
};
#endif // liblldb_PlatformDarwin_h_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,209 @@
//===-- PlatformDarwinKernel.h ----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformDarwinKernel_h_
#define liblldb_PlatformDarwinKernel_h_
#include "lldb/Utility/ConstString.h"
#if defined(__APPLE__) // This Plugin uses the Mac-specific
// source/Host/macosx/cfcpp utilities
// C Includes
// C++ Includes
// Other libraries and framework includes
#include "lldb/Utility/FileSpec.h"
#include "llvm/Support/FileSystem.h"
// Project includes
#include "PlatformDarwin.h"
class PlatformDarwinKernel : public PlatformDarwin {
public:
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
static lldb::PlatformSP CreateInstance(bool force,
const lldb_private::ArchSpec *arch);
static void DebuggerInitialize(lldb_private::Debugger &debugger);
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetDescriptionStatic();
//------------------------------------------------------------
// Class Methods
//------------------------------------------------------------
PlatformDarwinKernel(lldb_private::LazyBool is_ios_debug_session);
virtual ~PlatformDarwinKernel();
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
lldb_private::ConstString GetPluginName() override {
return GetPluginNameStatic();
}
uint32_t GetPluginVersion() override { return 1; }
//------------------------------------------------------------
// lldb_private::Platform functions
//------------------------------------------------------------
const char *GetDescription() override { return GetDescriptionStatic(); }
void GetStatus(lldb_private::Stream &strm) override;
lldb_private::Status
GetSharedModule(const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr,
bool *did_create_ptr) override;
bool GetSupportedArchitectureAtIndex(uint32_t idx,
lldb_private::ArchSpec &arch) override;
bool SupportsModules() override { return false; }
void CalculateTrapHandlerSymbolNames() override;
protected:
// Map from kext bundle ID ("com.apple.filesystems.exfat") to FileSpec for the
// kext bundle on
// the host ("/System/Library/Extensions/exfat.kext/Contents/Info.plist").
typedef std::multimap<lldb_private::ConstString, lldb_private::FileSpec>
BundleIDToKextMap;
typedef BundleIDToKextMap::iterator BundleIDToKextIterator;
typedef std::vector<lldb_private::FileSpec> KernelBinaryCollection;
// Array of directories that were searched for kext bundles (used only for
// reporting to user)
typedef std::vector<lldb_private::FileSpec> DirectoriesSearchedCollection;
typedef DirectoriesSearchedCollection::iterator DirectoriesSearchedIterator;
// Populate m_search_directories and m_search_directories_no_recursing vectors
// of directories
void CollectKextAndKernelDirectories();
void GetUserSpecifiedDirectoriesToSearch();
static void AddRootSubdirsToSearchPaths(PlatformDarwinKernel *thisp,
const std::string &dir);
void AddSDKSubdirsToSearchPaths(const std::string &dir);
static lldb_private::FileSpec::EnumerateDirectoryResult
FindKDKandSDKDirectoriesInDirectory(void *baton, llvm::sys::fs::file_type ft,
const lldb_private::FileSpec &file_spec);
void SearchForKextsAndKernelsRecursively();
static lldb_private::FileSpec::EnumerateDirectoryResult
GetKernelsAndKextsInDirectoryWithRecursion(
void *baton, llvm::sys::fs::file_type ft,
const lldb_private::FileSpec &file_spec);
static lldb_private::FileSpec::EnumerateDirectoryResult
GetKernelsAndKextsInDirectoryNoRecursion(
void *baton, llvm::sys::fs::file_type ft,
const lldb_private::FileSpec &file_spec);
static lldb_private::FileSpec::EnumerateDirectoryResult
GetKernelsAndKextsInDirectoryHelper(void *baton, llvm::sys::fs::file_type ft,
const lldb_private::FileSpec &file_spec,
bool recurse);
static void AddKextToMap(PlatformDarwinKernel *thisp,
const lldb_private::FileSpec &file_spec);
// Returns true if there is a .dSYM bundle next to the kext, or next to the
// binary inside the kext.
static bool
KextHasdSYMSibling(const lldb_private::FileSpec &kext_bundle_filepath);
// Returns true if there is a .dSYM bundle next to the kernel
static bool
KernelHasdSYMSibling(const lldb_private::FileSpec &kext_bundle_filepath);
lldb_private::Status
ExamineKextForMatchingUUID(const lldb_private::FileSpec &kext_bundle_path,
const lldb_private::UUID &uuid,
const lldb_private::ArchSpec &arch,
lldb::ModuleSP &exe_module_sp);
// Most of the ivars are assembled under FileSpec::EnumerateDirectory calls
// where the
// function being called for each file/directory must be static. We'll pass a
// this pointer
// as a baton and access the ivars directly. Toss-up whether this should just
// be a struct
// at this point.
public:
BundleIDToKextMap m_name_to_kext_path_map_with_dsyms; // multimap of
// CFBundleID to
// FileSpec on local
// filesystem, kexts
// with dSYMs next to
// them
BundleIDToKextMap m_name_to_kext_path_map_without_dsyms; // multimap of
// CFBundleID to
// FileSpec on local
// filesystem, kexts
// without dSYMs next
// to them
DirectoriesSearchedCollection
m_search_directories; // list of directories we search for kexts/kernels
DirectoriesSearchedCollection
m_search_directories_no_recursing; // list of directories we search for
// kexts/kernels, no recursion
KernelBinaryCollection m_kernel_binaries_with_dsyms; // list of kernel
// binaries we found on
// local filesystem,
// without dSYMs next to
// them
KernelBinaryCollection m_kernel_binaries_without_dsyms; // list of kernel
// binaries we found
// on local
// filesystem, with
// dSYMs next to them
lldb_private::LazyBool m_ios_debug_session;
DISALLOW_COPY_AND_ASSIGN(PlatformDarwinKernel);
};
#else // __APPLE__
// Since DynamicLoaderDarwinKernel is compiled in for all systems, and relies on
// PlatformDarwinKernel for the plug-in name, we compile just the plug-in name
// in
// here to avoid issues. We are tracking an internal bug to resolve this issue
// by
// either not compiling in DynamicLoaderDarwinKernel for non-apple builds, or to
// make
// PlatformDarwinKernel build on all systems. PlatformDarwinKernel is currently
// not
// compiled on other platforms due to the use of the Mac-specific
// source/Host/macosx/cfcpp utilities.
class PlatformDarwinKernel {
static lldb_private::ConstString GetPluginNameStatic();
};
#endif // __APPLE__
#endif // liblldb_PlatformDarwinKernel_h_

View File

@@ -0,0 +1,347 @@
//===-- PlatformMacOSX.cpp --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "PlatformMacOSX.h"
#include "lldb/Host/Config.h"
// C++ Includes
#include <sstream>
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
using namespace lldb;
using namespace lldb_private;
static uint32_t g_initialize_count = 0;
void PlatformMacOSX::Initialize() {
PlatformDarwin::Initialize();
if (g_initialize_count++ == 0) {
#if defined(__APPLE__)
PlatformSP default_platform_sp(new PlatformMacOSX(true));
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
Platform::SetHostPlatform(default_platform_sp);
#endif
PluginManager::RegisterPlugin(PlatformMacOSX::GetPluginNameStatic(false),
PlatformMacOSX::GetDescriptionStatic(false),
PlatformMacOSX::CreateInstance);
}
}
void PlatformMacOSX::Terminate() {
if (g_initialize_count > 0) {
if (--g_initialize_count == 0) {
PluginManager::UnregisterPlugin(PlatformMacOSX::CreateInstance);
}
}
PlatformDarwin::Terminate();
}
PlatformSP PlatformMacOSX::CreateInstance(bool force, const ArchSpec *arch) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_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>";
log->Printf("PlatformMacOSX::%s(force=%s, arch={%s,%s})", __FUNCTION__,
force ? "true" : "false", arch_name, triple_cstr);
}
// The only time we create an instance is when we are creating a remote
// macosx platform
const bool is_host = false;
bool create = force;
if (create == false && arch && arch->IsValid()) {
const llvm::Triple &triple = arch->GetTriple();
switch (triple.getVendor()) {
case llvm::Triple::Apple:
create = true;
break;
#if defined(__APPLE__)
// Only accept "unknown" for vendor if the host is Apple and
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownArch:
create = !arch->TripleVendorWasSpecified();
break;
#endif
default:
break;
}
if (create) {
switch (triple.getOS()) {
case llvm::Triple::Darwin: // Deprecated, but still support Darwin for
// historical reasons
case llvm::Triple::MacOSX:
break;
#if defined(__APPLE__)
// Only accept "vendor" for vendor if the host is Apple and
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownOS:
create = !arch->TripleOSWasSpecified();
break;
#endif
default:
create = false;
break;
}
}
}
if (create) {
if (log)
log->Printf("PlatformMacOSX::%s() creating platform", __FUNCTION__);
return PlatformSP(new PlatformMacOSX(is_host));
}
if (log)
log->Printf("PlatformMacOSX::%s() aborting creation of platform",
__FUNCTION__);
return PlatformSP();
}
lldb_private::ConstString PlatformMacOSX::GetPluginNameStatic(bool is_host) {
if (is_host) {
static ConstString g_host_name(Platform::GetHostPlatformName());
return g_host_name;
} else {
static ConstString g_remote_name("remote-macosx");
return g_remote_name;
}
}
const char *PlatformMacOSX::GetDescriptionStatic(bool is_host) {
if (is_host)
return "Local Mac OS X user platform plug-in.";
else
return "Remote Mac OS X user platform plug-in.";
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformMacOSX::PlatformMacOSX(bool is_host) : PlatformDarwin(is_host) {}
//------------------------------------------------------------------
/// Destructor.
///
/// The destructor is virtual since this class is designed to be
/// inherited from by the plug-in instance.
//------------------------------------------------------------------
PlatformMacOSX::~PlatformMacOSX() {}
ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
ModuleSP exe_module_sp(target.GetExecutableModule());
if (exe_module_sp) {
ObjectFile *objfile = exe_module_sp->GetObjectFile();
if (objfile) {
std::string xcode_contents_path;
std::string default_xcode_sdk;
FileSpec fspec;
uint32_t versions[2];
if (objfile->GetSDKVersion(versions, sizeof(versions))) {
if (HostInfo::GetLLDBPath(ePathTypeLLDBShlibDir, fspec)) {
std::string path;
xcode_contents_path = fspec.GetPath();
size_t pos = xcode_contents_path.find("/Xcode.app/Contents/");
if (pos != std::string::npos) {
// LLDB.framework is inside an Xcode app bundle, we can locate the
// SDK from here
xcode_contents_path.erase(pos + strlen("/Xcode.app/Contents/"));
} else {
xcode_contents_path.clear();
// Use the selected Xcode
int status = 0;
int signo = 0;
std::string output;
const char *command = "xcrun -sdk macosx --show-sdk-path";
lldb_private::Status error = RunShellCommand(
command, // shell command to run
NULL, // current working directory
&status, // Put the exit status of the process in here
&signo, // Put the signal that caused the process to exit in
// here
&output, // Get the output from the command and place it in this
// string
3); // Timeout in seconds to wait for shell program to finish
if (status == 0 && !output.empty()) {
size_t first_non_newline = output.find_last_not_of("\r\n");
if (first_non_newline != std::string::npos)
output.erase(first_non_newline + 1);
default_xcode_sdk = output;
pos = default_xcode_sdk.find("/Xcode.app/Contents/");
if (pos != std::string::npos)
xcode_contents_path = default_xcode_sdk.substr(
0, pos + strlen("/Xcode.app/Contents/"));
}
}
}
if (!xcode_contents_path.empty()) {
StreamString sdk_path;
sdk_path.Printf("%sDeveloper/Platforms/MacOSX.platform/Developer/"
"SDKs/MacOSX%u.%u.sdk",
xcode_contents_path.c_str(), versions[0],
versions[1]);
fspec.SetFile(sdk_path.GetString(), false);
if (fspec.Exists())
return ConstString(sdk_path.GetString());
}
if (!default_xcode_sdk.empty()) {
fspec.SetFile(default_xcode_sdk, false);
if (fspec.Exists())
return ConstString(default_xcode_sdk);
}
}
}
}
return ConstString();
}
Status PlatformMacOSX::GetSymbolFile(const FileSpec &platform_file,
const UUID *uuid_ptr,
FileSpec &local_file) {
if (IsRemote()) {
if (m_remote_platform_sp)
return m_remote_platform_sp->GetFileWithUUID(platform_file, uuid_ptr,
local_file);
}
// Default to the local case
local_file = platform_file;
return Status();
}
lldb_private::Status
PlatformMacOSX::GetFileWithUUID(const lldb_private::FileSpec &platform_file,
const lldb_private::UUID *uuid_ptr,
lldb_private::FileSpec &local_file) {
if (IsRemote() && m_remote_platform_sp) {
std::string local_os_build;
#if !defined(__linux__)
HostInfo::GetOSBuildString(local_os_build);
#endif
std::string remote_os_build;
m_remote_platform_sp->GetOSBuildString(remote_os_build);
if (local_os_build.compare(remote_os_build) == 0) {
// same OS version: the local file is good enough
local_file = platform_file;
return Status();
} else {
// try to find the file in the cache
std::string cache_path(GetLocalCacheDirectory());
std::string module_path(platform_file.GetPath());
cache_path.append(module_path);
FileSpec module_cache_spec(cache_path, false);
if (module_cache_spec.Exists()) {
local_file = module_cache_spec;
return Status();
}
// bring in the remote module file
FileSpec module_cache_folder =
module_cache_spec.CopyByRemovingLastPathComponent();
// try to make the local directory first
Status err(
llvm::sys::fs::create_directory(module_cache_folder.GetPath()));
if (err.Fail())
return err;
err = GetFile(platform_file, module_cache_spec);
if (err.Fail())
return err;
if (module_cache_spec.Exists()) {
local_file = module_cache_spec;
return Status();
} else
return Status("unable to obtain valid module file");
}
}
local_file = platform_file;
return Status();
}
bool PlatformMacOSX::GetSupportedArchitectureAtIndex(uint32_t idx,
ArchSpec &arch) {
#if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
return ARMGetSupportedArchitectureAtIndex(idx, arch);
#else
return x86GetSupportedArchitectureAtIndex(idx, arch);
#endif
}
lldb_private::Status PlatformMacOSX::GetSharedModule(
const lldb_private::ModuleSpec &module_spec, Process *process,
lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr, bool *did_create_ptr) {
Status error = GetSharedModuleWithLocalCache(
module_spec, module_sp, module_search_paths_ptr, old_module_sp_ptr,
did_create_ptr);
if (module_sp) {
if (module_spec.GetArchitecture().GetCore() ==
ArchSpec::eCore_x86_64_x86_64h) {
ObjectFile *objfile = module_sp->GetObjectFile();
if (objfile == NULL) {
// We didn't find an x86_64h slice, fall back to a x86_64 slice
ModuleSpec module_spec_x86_64(module_spec);
module_spec_x86_64.GetArchitecture() = ArchSpec("x86_64-apple-macosx");
lldb::ModuleSP x86_64_module_sp;
lldb::ModuleSP old_x86_64_module_sp;
bool did_create = false;
Status x86_64_error = GetSharedModuleWithLocalCache(
module_spec_x86_64, x86_64_module_sp, module_search_paths_ptr,
&old_x86_64_module_sp, &did_create);
if (x86_64_module_sp && x86_64_module_sp->GetObjectFile()) {
module_sp = x86_64_module_sp;
if (old_module_sp_ptr)
*old_module_sp_ptr = old_x86_64_module_sp;
if (did_create_ptr)
*did_create_ptr = did_create;
return x86_64_error;
}
}
}
}
if (!module_sp) {
error = FindBundleBinaryInExecSearchPaths (module_spec, process, module_sp, module_search_paths_ptr, old_module_sp_ptr, did_create_ptr);
}
return error;
}

View File

@@ -0,0 +1,92 @@
//===-- PlatformMacOSX.h ----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformMacOSX_h_
#define liblldb_PlatformMacOSX_h_
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "PlatformDarwin.h"
class PlatformMacOSX : public PlatformDarwin {
public:
PlatformMacOSX(bool is_host);
~PlatformMacOSX() override;
//------------------------------------------------------------
// Class functions
//------------------------------------------------------------
static lldb::PlatformSP CreateInstance(bool force,
const lldb_private::ArchSpec *arch);
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic(bool is_host);
static const char *GetDescriptionStatic(bool is_host);
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
lldb_private::ConstString GetPluginName() override {
return GetPluginNameStatic(IsHost());
}
uint32_t GetPluginVersion() override { return 1; }
lldb_private::Status
GetSharedModule(const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr,
bool *did_create_ptr) override;
const char *GetDescription() override {
return GetDescriptionStatic(IsHost());
}
lldb_private::Status
GetSymbolFile(const lldb_private::FileSpec &platform_file,
const lldb_private::UUID *uuid_ptr,
lldb_private::FileSpec &local_file);
lldb_private::Status
GetFile(const lldb_private::FileSpec &source,
const lldb_private::FileSpec &destination) override {
return PlatformDarwin::GetFile(source, destination);
}
lldb_private::Status
GetFileWithUUID(const lldb_private::FileSpec &platform_file,
const lldb_private::UUID *uuid_ptr,
lldb_private::FileSpec &local_file) override;
bool GetSupportedArchitectureAtIndex(uint32_t idx,
lldb_private::ArchSpec &arch) override;
lldb_private::ConstString
GetSDKDirectory(lldb_private::Target &target) override;
void
AddClangModuleCompilationOptions(lldb_private::Target *target,
std::vector<std::string> &options) override {
return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
target, options, PlatformDarwin::SDKType::MacOSX);
}
private:
DISALLOW_COPY_AND_ASSIGN(PlatformMacOSX);
};
#endif // liblldb_PlatformMacOSX_h_

View File

@@ -0,0 +1,250 @@
//===-- PlatformRemoteAppleTV.cpp -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
// C++ Includes
#include <string>
#include <vector>
// Other libraries and framework includes
// Project includes
#include "PlatformRemoteAppleTV.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
using namespace lldb;
using namespace lldb_private;
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformRemoteAppleTV::PlatformRemoteAppleTV()
: PlatformRemoteDarwinDevice () {}
//------------------------------------------------------------------
// Static Variables
//------------------------------------------------------------------
static uint32_t g_initialize_count = 0;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
void PlatformRemoteAppleTV::Initialize() {
PlatformDarwin::Initialize();
if (g_initialize_count++ == 0) {
PluginManager::RegisterPlugin(PlatformRemoteAppleTV::GetPluginNameStatic(),
PlatformRemoteAppleTV::GetDescriptionStatic(),
PlatformRemoteAppleTV::CreateInstance);
}
}
void PlatformRemoteAppleTV::Terminate() {
if (g_initialize_count > 0) {
if (--g_initialize_count == 0) {
PluginManager::UnregisterPlugin(PlatformRemoteAppleTV::CreateInstance);
}
}
PlatformDarwin::Terminate();
}
PlatformSP PlatformRemoteAppleTV::CreateInstance(bool force,
const ArchSpec *arch) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_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>";
log->Printf("PlatformRemoteAppleTV::%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::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
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownArch:
create = !arch->TripleVendorWasSpecified();
break;
#endif
default:
break;
}
if (create) {
switch (triple.getOS()) {
case llvm::Triple::TvOS: // This is the right triple value for Apple TV
// debugging
break;
default:
create = false;
break;
}
}
} break;
default:
break;
}
}
if (create) {
if (log)
log->Printf("PlatformRemoteAppleTV::%s() creating platform",
__FUNCTION__);
return lldb::PlatformSP(new PlatformRemoteAppleTV());
}
if (log)
log->Printf("PlatformRemoteAppleTV::%s() aborting creation of platform",
__FUNCTION__);
return lldb::PlatformSP();
}
lldb_private::ConstString PlatformRemoteAppleTV::GetPluginNameStatic() {
static ConstString g_name("remote-tvos");
return g_name;
}
const char *PlatformRemoteAppleTV::GetDescriptionStatic() {
return "Remote Apple TV platform plug-in.";
}
bool PlatformRemoteAppleTV::GetSupportedArchitectureAtIndex(uint32_t idx,
ArchSpec &arch) {
ArchSpec system_arch(GetSystemArchitecture());
const ArchSpec::Core system_core = system_arch.GetCore();
switch (system_core) {
default:
switch (idx) {
case 0:
arch.SetTriple("arm64-apple-tvos");
return true;
case 1:
arch.SetTriple("armv7s-apple-tvos");
return true;
case 2:
arch.SetTriple("armv7-apple-tvos");
return true;
case 3:
arch.SetTriple("thumbv7s-apple-tvos");
return true;
case 4:
arch.SetTriple("thumbv7-apple-tvos");
return true;
default:
break;
}
break;
case ArchSpec::eCore_arm_arm64:
switch (idx) {
case 0:
arch.SetTriple("arm64-apple-tvos");
return true;
case 1:
arch.SetTriple("armv7s-apple-tvos");
return true;
case 2:
arch.SetTriple("armv7-apple-tvos");
return true;
case 3:
arch.SetTriple("thumbv7s-apple-tvos");
return true;
case 4:
arch.SetTriple("thumbv7-apple-tvos");
return true;
default:
break;
}
break;
case ArchSpec::eCore_arm_armv7s:
switch (idx) {
case 0:
arch.SetTriple("armv7s-apple-tvos");
return true;
case 1:
arch.SetTriple("armv7-apple-tvos");
return true;
case 2:
arch.SetTriple("thumbv7s-apple-tvos");
return true;
case 3:
arch.SetTriple("thumbv7-apple-tvos");
return true;
default:
break;
}
break;
case ArchSpec::eCore_arm_armv7:
switch (idx) {
case 0:
arch.SetTriple("armv7-apple-tvos");
return true;
case 1:
arch.SetTriple("thumbv7-apple-tvos");
return true;
default:
break;
}
break;
}
arch.Clear();
return false;
}
void PlatformRemoteAppleTV::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
{
dirnames.clear();
dirnames.push_back("tvOS DeviceSupport");
}
std::string PlatformRemoteAppleTV::GetPlatformName ()
{
return "AppleTVOS.platform";
}

View File

@@ -0,0 +1,77 @@
//===-- PlatformRemoteAppleTV.h ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformRemoteAppleTV_h_
#define liblldb_PlatformRemoteAppleTV_h_
// C Includes
// C++ Includes
#include <string>
// Other libraries and framework includes
// Project includes
#include "lldb/Utility/FileSpec.h"
#include "llvm/Support/FileSystem.h"
#include "PlatformRemoteDarwinDevice.h"
class PlatformRemoteAppleTV : public PlatformRemoteDarwinDevice {
public:
PlatformRemoteAppleTV();
~PlatformRemoteAppleTV() override = default;
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
static lldb::PlatformSP CreateInstance(bool force,
const lldb_private::ArchSpec *arch);
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetDescriptionStatic();
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
lldb_private::ConstString GetPluginName() override {
return GetPluginNameStatic();
}
uint32_t GetPluginVersion() override { return 1; }
//------------------------------------------------------------
// lldb_private::Platform functions
//------------------------------------------------------------
const char *GetDescription() override { return GetDescriptionStatic(); }
bool GetSupportedArchitectureAtIndex(uint32_t idx,
lldb_private::ArchSpec &arch) override;
protected:
//------------------------------------------------------------
// lldb_private::PlatformRemoteDarwinDevice functions
//------------------------------------------------------------
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
std::string GetPlatformName () override;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformRemoteAppleTV);
};
#endif // liblldb_PlatformRemoteAppleTV_h_

View File

@@ -0,0 +1,307 @@
//===-- PlatformRemoteAppleWatch.cpp ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
// C++ Includes
#include <string>
#include <vector>
// Other libraries and framework includes
// Project includes
#include "PlatformRemoteAppleWatch.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
using namespace lldb;
using namespace lldb_private;
//------------------------------------------------------------------
// Static Variables
//------------------------------------------------------------------
static uint32_t g_initialize_count = 0;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
void PlatformRemoteAppleWatch::Initialize() {
PlatformDarwin::Initialize();
if (g_initialize_count++ == 0) {
PluginManager::RegisterPlugin(
PlatformRemoteAppleWatch::GetPluginNameStatic(),
PlatformRemoteAppleWatch::GetDescriptionStatic(),
PlatformRemoteAppleWatch::CreateInstance);
}
}
void PlatformRemoteAppleWatch::Terminate() {
if (g_initialize_count > 0) {
if (--g_initialize_count == 0) {
PluginManager::UnregisterPlugin(PlatformRemoteAppleWatch::CreateInstance);
}
}
PlatformDarwin::Terminate();
}
PlatformSP PlatformRemoteAppleWatch::CreateInstance(bool force,
const ArchSpec *arch) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_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>";
log->Printf("PlatformRemoteAppleWatch::%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::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
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownArch:
create = !arch->TripleVendorWasSpecified();
break;
#endif
default:
break;
}
if (create) {
switch (triple.getOS()) {
case llvm::Triple::WatchOS: // This is the right triple value for Apple
// Watch debugging
break;
default:
create = false;
break;
}
}
} break;
default:
break;
}
}
#if defined(__APPLE__) && \
(defined(__arm__) || defined(__arm64__) || defined(__aarch64__))
// If lldb is running on a watch, this isn't a RemoteWatch environment; it's a
// local system environment.
if (force == false) {
create = false;
}
#endif
if (create) {
if (log)
log->Printf("PlatformRemoteAppleWatch::%s() creating platform",
__FUNCTION__);
return lldb::PlatformSP(new PlatformRemoteAppleWatch());
}
if (log)
log->Printf("PlatformRemoteAppleWatch::%s() aborting creation of platform",
__FUNCTION__);
return lldb::PlatformSP();
}
lldb_private::ConstString PlatformRemoteAppleWatch::GetPluginNameStatic() {
static ConstString g_name("remote-watchos");
return g_name;
}
const char *PlatformRemoteAppleWatch::GetDescriptionStatic() {
return "Remote Apple Watch platform plug-in.";
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformRemoteAppleWatch::PlatformRemoteAppleWatch()
: PlatformRemoteDarwinDevice() {}
bool PlatformRemoteAppleWatch::GetSupportedArchitectureAtIndex(uint32_t idx,
ArchSpec &arch) {
ArchSpec system_arch(GetSystemArchitecture());
const ArchSpec::Core system_core = system_arch.GetCore();
switch (system_core) {
default:
switch (idx) {
case 0:
arch.SetTriple("arm64-apple-watchos");
return true;
case 1:
arch.SetTriple("armv7k-apple-watchos");
return true;
case 2:
arch.SetTriple("armv7s-apple-watchos");
return true;
case 3:
arch.SetTriple("armv7-apple-watchos");
return true;
case 4:
arch.SetTriple("thumbv7k-apple-watchos");
return true;
case 5:
arch.SetTriple("thumbv7-apple-watchos");
return true;
case 6:
arch.SetTriple("thumbv7s-apple-watchos");
return true;
default:
break;
}
break;
case ArchSpec::eCore_arm_arm64:
switch (idx) {
case 0:
arch.SetTriple("arm64-apple-watchos");
return true;
case 1:
arch.SetTriple("armv7k-apple-watchos");
return true;
case 2:
arch.SetTriple("armv7s-apple-watchos");
return true;
case 3:
arch.SetTriple("armv7-apple-watchos");
return true;
case 4:
arch.SetTriple("thumbv7k-apple-watchos");
return true;
case 5:
arch.SetTriple("thumbv7-apple-watchos");
return true;
case 6:
arch.SetTriple("thumbv7s-apple-watchos");
return true;
default:
break;
}
break;
case ArchSpec::eCore_arm_armv7k:
switch (idx) {
case 0:
arch.SetTriple("armv7k-apple-watchos");
return true;
case 1:
arch.SetTriple("armv7s-apple-watchos");
return true;
case 2:
arch.SetTriple("armv7-apple-watchos");
return true;
case 3:
arch.SetTriple("thumbv7k-apple-watchos");
return true;
case 4:
arch.SetTriple("thumbv7-apple-watchos");
return true;
case 5:
arch.SetTriple("thumbv7s-apple-watchos");
return true;
default:
break;
}
break;
case ArchSpec::eCore_arm_armv7s:
switch (idx) {
case 0:
arch.SetTriple("armv7s-apple-watchos");
return true;
case 1:
arch.SetTriple("armv7k-apple-watchos");
return true;
case 2:
arch.SetTriple("armv7-apple-watchos");
return true;
case 3:
arch.SetTriple("thumbv7k-apple-watchos");
return true;
case 4:
arch.SetTriple("thumbv7-apple-watchos");
return true;
case 5:
arch.SetTriple("thumbv7s-apple-watchos");
return true;
default:
break;
}
break;
case ArchSpec::eCore_arm_armv7:
switch (idx) {
case 0:
arch.SetTriple("armv7-apple-watchos");
return true;
case 1:
arch.SetTriple("armv7k-apple-watchos");
return true;
case 2:
arch.SetTriple("thumbv7k-apple-watchos");
return true;
case 3:
arch.SetTriple("thumbv7-apple-watchos");
return true;
default:
break;
}
break;
}
arch.Clear();
return false;
}
void PlatformRemoteAppleWatch::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
{
dirnames.clear();
dirnames.push_back("watchOS DeviceSupport");
}
std::string PlatformRemoteAppleWatch::GetPlatformName ()
{
return "WatchOS.platform";
}

View File

@@ -0,0 +1,82 @@
//===-- PlatformRemoteAppleWatch.h ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformRemoteAppleWatch_h_
#define liblldb_PlatformRemoteAppleWatch_h_
// C Includes
// C++ Includes
#include <string>
#include <vector>
// Other libraries and framework includes
// Project includes
#include "lldb/Utility/FileSpec.h"
#include "PlatformRemoteDarwinDevice.h"
#include "llvm/Support/FileSystem.h"
class PlatformRemoteAppleWatch : public PlatformRemoteDarwinDevice {
public:
PlatformRemoteAppleWatch();
~PlatformRemoteAppleWatch() override = default;
//------------------------------------------------------------
// Class Functions
//------------------------------------------------------------
static lldb::PlatformSP CreateInstance(bool force,
const lldb_private::ArchSpec *arch);
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetDescriptionStatic();
//------------------------------------------------------------
// lldb_private::Platform functions
//------------------------------------------------------------
const char *GetDescription() override { return GetDescriptionStatic(); }
//------------------------------------------------------------
// lldb_private::PluginInterface functions
//------------------------------------------------------------
lldb_private::ConstString GetPluginName() override {
return GetPluginNameStatic();
}
uint32_t GetPluginVersion() override { return 1; }
//------------------------------------------------------------
// lldb_private::Platform functions
//------------------------------------------------------------
bool GetSupportedArchitectureAtIndex(uint32_t idx,
lldb_private::ArchSpec &arch) override;
protected:
//------------------------------------------------------------
// lldb_private::PlatformRemoteDarwinDevice functions
//------------------------------------------------------------
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
std::string GetPlatformName () override;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformRemoteAppleWatch);
};
#endif // liblldb_PlatformRemoteAppleWatch_h_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,118 @@
//===-- PlatformRemoteDarwinDevice.h -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_PlatformRemoteDarwinDevice_h_
#define liblldb_PlatformRemoteDarwinDevice_h_
// C Includes
// C++ Includes
#include <string>
// Other libraries and framework includes
// Project includes
#include "PlatformDarwin.h"
#include "lldb/Utility/FileSpec.h"
#include "llvm/Support/FileSystem.h"
class PlatformRemoteDarwinDevice : public PlatformDarwin {
public:
PlatformRemoteDarwinDevice();
~PlatformRemoteDarwinDevice() override;
//------------------------------------------------------------
// lldb_private::Platform functions
//------------------------------------------------------------
lldb_private::Status ResolveExecutable(
const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr) override;
void GetStatus(lldb_private::Stream &strm) override;
virtual lldb_private::Status
GetSymbolFile(const lldb_private::FileSpec &platform_file,
const lldb_private::UUID *uuid_ptr,
lldb_private::FileSpec &local_file);
lldb_private::Status
GetSharedModule(const lldb_private::ModuleSpec &module_spec,
lldb_private::Process *process, lldb::ModuleSP &module_sp,
const lldb_private::FileSpecList *module_search_paths_ptr,
lldb::ModuleSP *old_module_sp_ptr,
bool *did_create_ptr) override;
void
AddClangModuleCompilationOptions(lldb_private::Target *target,
std::vector<std::string> &options) override {
return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
target, options, PlatformDarwin::SDKType::iPhoneOS);
}
protected:
struct SDKDirectoryInfo {
SDKDirectoryInfo(const lldb_private::FileSpec &sdk_dir_spec);
lldb_private::FileSpec directory;
lldb_private::ConstString build;
uint32_t version_major;
uint32_t version_minor;
uint32_t version_update;
bool user_cached;
};
typedef std::vector<SDKDirectoryInfo> SDKDirectoryInfoCollection;
std::mutex m_sdk_dir_mutex;
SDKDirectoryInfoCollection m_sdk_directory_infos;
std::string m_device_support_directory;
std::string m_device_support_directory_for_os_version;
std::string m_build_update;
uint32_t m_last_module_sdk_idx;
uint32_t m_connected_module_sdk_idx;
bool UpdateSDKDirectoryInfosIfNeeded();
const char *GetDeviceSupportDirectory();
const char *GetDeviceSupportDirectoryForOSVersion();
const SDKDirectoryInfo *GetSDKDirectoryForLatestOSVersion();
const SDKDirectoryInfo *GetSDKDirectoryForCurrentOSVersion();
static lldb_private::FileSpec::EnumerateDirectoryResult
GetContainedFilesIntoVectorOfStringsCallback(
void *baton, llvm::sys::fs::file_type ft,
const lldb_private::FileSpec &file_spec);
uint32_t FindFileInAllSDKs(const char *platform_file_path,
lldb_private::FileSpecList &file_list);
bool GetFileInSDK(const char *platform_file_path, uint32_t sdk_idx,
lldb_private::FileSpec &local_file);
uint32_t FindFileInAllSDKs(const lldb_private::FileSpec &platform_file,
lldb_private::FileSpecList &file_list);
uint32_t GetConnectedSDKIndex();
// Get index of SDK in SDKDirectoryInfoCollection by its pointer and return
// UINT32_MAX if that SDK not found.
uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info);
virtual void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) = 0;
virtual std::string GetPlatformName () = 0;
private:
DISALLOW_COPY_AND_ASSIGN(PlatformRemoteDarwinDevice);
};
#endif // liblldb_PlatformRemoteDarwinDevice_h_

View File

@@ -0,0 +1,165 @@
//===-- PlatformRemoteiOS.cpp -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "PlatformRemoteiOS.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleList.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Host.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
using namespace lldb;
using namespace lldb_private;
//------------------------------------------------------------------
// Static Variables
//------------------------------------------------------------------
static uint32_t g_initialize_count = 0;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
void PlatformRemoteiOS::Initialize() {
PlatformDarwin::Initialize();
if (g_initialize_count++ == 0) {
PluginManager::RegisterPlugin(PlatformRemoteiOS::GetPluginNameStatic(),
PlatformRemoteiOS::GetDescriptionStatic(),
PlatformRemoteiOS::CreateInstance);
}
}
void PlatformRemoteiOS::Terminate() {
if (g_initialize_count > 0) {
if (--g_initialize_count == 0) {
PluginManager::UnregisterPlugin(PlatformRemoteiOS::CreateInstance);
}
}
PlatformDarwin::Terminate();
}
PlatformSP PlatformRemoteiOS::CreateInstance(bool force, const ArchSpec *arch) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_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>";
log->Printf("PlatformRemoteiOS::%s(force=%s, arch={%s,%s})", __FUNCTION__,
force ? "true" : "false", arch_name, triple_cstr);
}
bool create = force;
if (create == false && arch && arch->IsValid()) {
switch (arch->GetMachine()) {
case llvm::Triple::arm:
case llvm::Triple::aarch64:
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
// it "unknown" wasn't specified (it was just returned because it
// was NOT specified)
case llvm::Triple::UnknownArch:
create = !arch->TripleVendorWasSpecified();
break;
#endif
default:
break;
}
if (create) {
switch (triple.getOS()) {
case llvm::Triple::Darwin: // Deprecated, but still support Darwin for
// historical reasons
case llvm::Triple::IOS: // This is the right triple value for iOS
// debugging
break;
default:
create = false;
break;
}
}
} break;
default:
break;
}
}
if (create) {
if (log)
log->Printf("PlatformRemoteiOS::%s() creating platform", __FUNCTION__);
return lldb::PlatformSP(new PlatformRemoteiOS());
}
if (log)
log->Printf("PlatformRemoteiOS::%s() aborting creation of platform",
__FUNCTION__);
return lldb::PlatformSP();
}
lldb_private::ConstString PlatformRemoteiOS::GetPluginNameStatic() {
static ConstString g_name("remote-ios");
return g_name;
}
const char *PlatformRemoteiOS::GetDescriptionStatic() {
return "Remote iOS platform plug-in.";
}
//------------------------------------------------------------------
/// Default Constructor
//------------------------------------------------------------------
PlatformRemoteiOS::PlatformRemoteiOS()
: PlatformRemoteDarwinDevice() {}
bool PlatformRemoteiOS::GetSupportedArchitectureAtIndex(uint32_t idx,
ArchSpec &arch) {
return ARMGetSupportedArchitectureAtIndex(idx, arch);
}
void PlatformRemoteiOS::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
{
dirnames.clear();
dirnames.push_back("iOS DeviceSupport");
}
std::string PlatformRemoteiOS::GetPlatformName ()
{
return "iPhoneOS.platform";
}

Some files were not shown because too many files have changed in this diff Show More