Skip to content

Commit

Permalink
[lldb] Treat remote macOS debugging like any other remote darwin plat…
Browse files Browse the repository at this point in the history
…form

Extract remote debugging logic from PlatformMacOSX and move it into
PlatformRemoteMacOSX so it can benefit from all the logic necessary for
remote debugging.

Until now, remote macOS debugging was treated almost identical to local
macOS debugging. By moving in into its own class, we can have it inherit
from PlatformRemoteDarwinDevice and all the functionality it provides,
such as looking at the correct DeviceSupport directory.

rdar://68167374

Differential revision: https://reviews.llvm.org/D92452
  • Loading branch information
JDevlieghere committed Dec 3, 2020
1 parent 9c955b7 commit dd2054d
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 166 deletions.
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Platform/MacOSX/CMakeLists.txt
Expand Up @@ -10,11 +10,12 @@ list(APPEND PLUGIN_PLATFORM_MACOSX_SOURCES
PlatformDarwin.cpp
PlatformDarwinKernel.cpp
PlatformMacOSX.cpp
PlatformRemoteiOS.cpp
PlatformRemoteAppleBridge.cpp
PlatformRemoteAppleTV.cpp
PlatformRemoteAppleWatch.cpp
PlatformRemoteDarwinDevice.cpp
PlatformRemoteAppleBridge.cpp
PlatformRemoteMacOSX.cpp
PlatformRemoteiOS.cpp
)

list(APPEND PLUGIN_PLATFORM_MACOSX_DARWIN_ONLY_SOURCES
Expand Down
161 changes: 16 additions & 145 deletions lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "PlatformMacOSX.h"
#include "PlatformRemoteMacOSX.h"
#include "PlatformRemoteiOS.h"
#if defined(__APPLE__)
#include "PlatformAppleSimulator.h"
Expand Down Expand Up @@ -44,6 +45,7 @@ static uint32_t g_initialize_count = 0;
void PlatformMacOSX::Initialize() {
PlatformDarwin::Initialize();
PlatformRemoteiOS::Initialize();
PlatformRemoteMacOSX::Initialize();
#if defined(__APPLE__)
PlatformAppleSimulator::Initialize();
PlatformDarwinKernel::Initialize();
Expand All @@ -54,12 +56,12 @@ void PlatformMacOSX::Initialize() {

if (g_initialize_count++ == 0) {
#if defined(__APPLE__)
PlatformSP default_platform_sp(new PlatformMacOSX(true));
PlatformSP default_platform_sp(new PlatformMacOSX());
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
Platform::SetHostPlatform(default_platform_sp);
#endif
PluginManager::RegisterPlugin(PlatformMacOSX::GetPluginNameStatic(false),
PlatformMacOSX::GetDescriptionStatic(false),
PluginManager::RegisterPlugin(PlatformMacOSX::GetPluginNameStatic(),
PlatformMacOSX::GetDescriptionStatic(),
PlatformMacOSX::CreateInstance);
}
}
Expand All @@ -78,98 +80,28 @@ void PlatformMacOSX::Terminate() {
PlatformDarwinKernel::Terminate();
PlatformAppleSimulator::Terminate();
#endif
PlatformRemoteMacOSX::Initialize();
PlatformRemoteiOS::Terminate();
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>";

LLDB_LOGF(log, "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 && 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::UnknownVendor:
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) {
LLDB_LOGF(log, "PlatformMacOSX::%s() creating platform", __FUNCTION__);
return PlatformSP(new PlatformMacOSX(is_host));
}

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

return PlatformSP();
lldb_private::ConstString PlatformMacOSX::GetPluginNameStatic() {
static ConstString g_host_name(Platform::GetHostPlatformName());
return g_host_name;
}

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() {
return "Local Mac OS X user platform plug-in.";
}

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.";
PlatformSP PlatformMacOSX::CreateInstance(bool force, const ArchSpec *arch) {
// The only time we create an instance is when we are creating a remote
// macosx platform which is handled by PlatformRemoteMacOSX.
return PlatformSP();
}

/// Default Constructor
PlatformMacOSX::PlatformMacOSX(bool is_host) : PlatformDarwin(is_host) {}
PlatformMacOSX::PlatformMacOSX() : PlatformDarwin(true) {}

ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
ModuleSP exe_module_sp(target.GetExecutableModule());
Expand Down Expand Up @@ -206,67 +138,6 @@ ConstString PlatformMacOSX::GetSDKDirectory(lldb_private::Target &target) {
return {};
}

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 == remote_os_build) {
// 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);
if (FileSystem::Instance().Exists(module_cache_spec)) {
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 (FileSystem::Instance().Exists(module_cache_spec)) {
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__)
Expand Down
22 changes: 5 additions & 17 deletions lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
Expand Up @@ -13,7 +13,7 @@

class PlatformMacOSX : public PlatformDarwin {
public:
PlatformMacOSX(bool is_host);
PlatformMacOSX();

// Class functions
static lldb::PlatformSP CreateInstance(bool force,
Expand All @@ -23,13 +23,13 @@ class PlatformMacOSX : public PlatformDarwin {

static void Terminate();

static lldb_private::ConstString GetPluginNameStatic(bool is_host);
static lldb_private::ConstString GetPluginNameStatic();

static const char *GetDescriptionStatic(bool is_host);
static const char *GetDescriptionStatic();

// lldb_private::PluginInterface functions
lldb_private::ConstString GetPluginName() override {
return GetPluginNameStatic(IsHost());
return GetPluginNameStatic();
}

uint32_t GetPluginVersion() override { return 1; }
Expand All @@ -41,26 +41,14 @@ class PlatformMacOSX : public PlatformDarwin {
llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
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);
const char *GetDescription() override { return GetDescriptionStatic(); }

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;

Expand Down

0 comments on commit dd2054d

Please sign in to comment.