49 changes: 49 additions & 0 deletions lldb/include/lldb/Interpreter/ScriptedPlatformInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//===-- ScriptedPlatformInterface.h -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_INTERPRETER_SCRIPTEDPLATFORMINTERFACE_H
#define LLDB_INTERPRETER_SCRIPTEDPLATFORMINTERFACE_H

#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Interpreter/ScriptedInterface.h"

#include "lldb/lldb-private.h"

#include <string>

namespace lldb_private {
class ScriptedPlatformInterface : virtual public ScriptedInterface {
public:
StructuredData::GenericSP
CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp,
StructuredData::Generic *script_obj = nullptr) override {
return {};
}

virtual StructuredData::DictionarySP ListProcesses() { return {}; }

virtual StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) {
return {};
}

virtual Status AttachToProcess(lldb::ProcessAttachInfoSP attach_info) {
return Status("ScriptedPlatformInterface cannot attach to a process");
}

virtual Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) {
return Status("ScriptedPlatformInterface cannot launch process");
}

virtual Status KillProcess(lldb::pid_t pid) {
return Status("ScriptedPlatformInterface cannot kill process");
}
};
} // namespace lldb_private

#endif // LLDB_INTERPRETER_SCRIPTEDPLATFORMINTERFACE_H
22 changes: 15 additions & 7 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "lldb/Core/UserSettingsController.h"
#include "lldb/Host/File.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpec.h"
Expand Down Expand Up @@ -99,7 +100,8 @@ class Platform : public PluginInterface {

static void SetHostPlatform(const lldb::PlatformSP &platform_sp);

static lldb::PlatformSP Create(llvm::StringRef name);
static lldb::PlatformSP Create(llvm::StringRef name, const Debugger *debugger,
const ScriptedMetadata *metadata);

/// Augments the triple either with information from platform or the host
/// system (if platform is null).
Expand Down Expand Up @@ -974,7 +976,7 @@ class Platform : public PluginInterface {

class PlatformList {
public:
PlatformList() = default;
PlatformList(Debugger &debugger) : m_debugger(debugger) {}

~PlatformList() = default;

Expand Down Expand Up @@ -1029,13 +1031,16 @@ class PlatformList {
}
}

lldb::PlatformSP GetOrCreate(llvm::StringRef name);
lldb::PlatformSP GetOrCreate(llvm::StringRef name,
const ScriptedMetadata *metadata);
lldb::PlatformSP GetOrCreate(const ArchSpec &arch,
const ArchSpec &process_host_arch,
ArchSpec *platform_arch_ptr, Status &error);
ArchSpec *platform_arch_ptr, Status &error,
const ScriptedMetadata *metadata);
lldb::PlatformSP GetOrCreate(const ArchSpec &arch,
const ArchSpec &process_host_arch,
ArchSpec *platform_arch_ptr);
ArchSpec *platform_arch_ptr,
const ScriptedMetadata *metadata);

/// Get the platform for the given list of architectures.
///
Expand All @@ -1051,9 +1056,11 @@ class PlatformList {
/// given architecture.
lldb::PlatformSP GetOrCreate(llvm::ArrayRef<ArchSpec> archs,
const ArchSpec &process_host_arch,
std::vector<lldb::PlatformSP> &candidates);
std::vector<lldb::PlatformSP> &candidates,
const ScriptedMetadata *metadata);

lldb::PlatformSP Create(llvm::StringRef name);
lldb::PlatformSP Create(llvm::StringRef name,
const ScriptedMetadata *metadata);

/// Detect a binary in memory that will determine which Platform and
/// DynamicLoader should be used in this target/process, and update
Expand Down Expand Up @@ -1090,6 +1097,7 @@ class PlatformList {
private:
PlatformList(const PlatformList &) = delete;
const PlatformList &operator=(const PlatformList &) = delete;
Debugger &m_debugger;
};

class OptionGroupPlatformRSync : public lldb_private::OptionGroup {
Expand Down
5 changes: 5 additions & 0 deletions lldb/include/lldb/lldb-forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class PersistentExpressionState;
class Platform;
class Process;
class ProcessAttachInfo;
class ProcessLaunchInfo;
class ProcessInfo;
class ProcessInstanceInfo;
class ProcessInstanceInfoMatch;
Expand All @@ -180,6 +181,7 @@ class RichManglingContext;
class Scalar;
class ScriptInterpreter;
class ScriptInterpreterLocker;
class ScriptedPlatformInterface;
class ScriptedProcessInterface;
class ScriptedThreadInterface;
class ScriptedSyntheticChildren;
Expand Down Expand Up @@ -364,6 +366,7 @@ typedef std::shared_ptr<lldb_private::OptionValueProperties>
typedef std::shared_ptr<lldb_private::Platform> PlatformSP;
typedef std::shared_ptr<lldb_private::Process> ProcessSP;
typedef std::shared_ptr<lldb_private::ProcessAttachInfo> ProcessAttachInfoSP;
typedef std::shared_ptr<lldb_private::ProcessLaunchInfo> ProcessLaunchInfoSP;
typedef std::weak_ptr<lldb_private::Process> ProcessWP;
typedef std::shared_ptr<lldb_private::RegisterCheckpoint> RegisterCheckpointSP;
typedef std::shared_ptr<lldb_private::RegisterContext> RegisterContextSP;
Expand All @@ -377,6 +380,8 @@ typedef std::shared_ptr<lldb_private::RecognizedStackFrame>
typedef std::shared_ptr<lldb_private::ScriptSummaryFormat>
ScriptSummaryFormatSP;
typedef std::shared_ptr<lldb_private::ScriptInterpreter> ScriptInterpreterSP;
typedef std::unique_ptr<lldb_private::ScriptedPlatformInterface>
ScriptedPlatformInterfaceUP;
typedef std::unique_ptr<lldb_private::ScriptedProcessInterface>
ScriptedProcessInterfaceUP;
typedef std::shared_ptr<lldb_private::ScriptedThreadInterface>
Expand Down
6 changes: 4 additions & 2 deletions lldb/include/lldb/lldb-private-interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Value;
} // namespace llvm

namespace lldb_private {
class ScriptedMetadata;
typedef lldb::ABISP (*ABICreateInstance)(lldb::ProcessSP process_sp,
const ArchSpec &arch);
typedef std::unique_ptr<Architecture> (*ArchitectureCreateInstance)(
Expand Down Expand Up @@ -77,8 +78,9 @@ typedef lldb::StructuredDataPluginSP (*StructuredDataPluginCreateInstance)(
typedef Status (*StructuredDataFilterLaunchInfo)(ProcessLaunchInfo &launch_info,
Target *target);
typedef SystemRuntime *(*SystemRuntimeCreateInstance)(Process *process);
typedef lldb::PlatformSP (*PlatformCreateInstance)(bool force,
const ArchSpec *arch);
typedef lldb::PlatformSP (*PlatformCreateInstance)(
bool force, const ArchSpec *arch, const Debugger *debugger,
const ScriptedMetadata *metadata);
typedef lldb::ProcessSP (*ProcessCreateInstance)(
lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
const FileSpec *crash_file_path, bool can_connect);
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/API/SBDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,8 @@ SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) {
if (m_opaque_sp) {
if (platform_name_cstr && platform_name_cstr[0]) {
PlatformList &platforms = m_opaque_sp->GetPlatformList();
if (PlatformSP platform_sp = platforms.GetOrCreate(platform_name_cstr))
if (PlatformSP platform_sp = platforms.GetOrCreate(
platform_name_cstr, /*metadata = */ nullptr))
platforms.SetSelectedPlatform(platform_sp);
else
sb_error.ref().SetErrorString("platform not found");
Expand Down
29 changes: 28 additions & 1 deletion lldb/source/API/SBPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
//===----------------------------------------------------------------------===//

#include "lldb/API/SBPlatform.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBEnvironment.h"
#include "lldb/API/SBError.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBLaunchInfo.h"
#include "lldb/API/SBPlatform.h"
#include "lldb/API/SBStructuredData.h"
#include "lldb/API/SBUnixSignals.h"
#include "lldb/Host/File.h"
#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
Expand Down Expand Up @@ -292,7 +295,31 @@ SBPlatform::SBPlatform() { LLDB_INSTRUMENT_VA(this); }
SBPlatform::SBPlatform(const char *platform_name) {
LLDB_INSTRUMENT_VA(this, platform_name);

m_opaque_sp = Platform::Create(platform_name);
m_opaque_sp = Platform::Create(platform_name, /*debugger = */ nullptr,
/*metadata = */ nullptr);
}

SBPlatform::SBPlatform(const char *platform_name, const SBDebugger &debugger,
const char *script_name, const SBStructuredData &dict) {
LLDB_INSTRUMENT_VA(this, platform_name, debugger, script_name, dict);

if (!script_name || !dict.IsValid() || !dict.m_impl_up)
return;

StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();

if (!obj_sp)
return;

StructuredData::DictionarySP dict_sp =
std::make_shared<StructuredData::Dictionary>(obj_sp);
if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)
return;

const ScriptedMetadata metadata(script_name, dict_sp);

m_opaque_sp =
Platform::Create(platform_name, debugger.m_opaque_sp.get(), &metadata);
}

SBPlatform::SBPlatform(const SBPlatform &rhs) {
Expand Down
91 changes: 43 additions & 48 deletions lldb/source/Commands/CommandObjectPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,63 +139,58 @@ class OptionPermissions : public OptionGroup {
};

// "platform select <platform-name>"
class CommandObjectPlatformSelect : public CommandObjectParsed {
public:
CommandObjectPlatformSelect(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "platform select",
"Create a platform if needed and select it as the "
"current platform.",
"platform select <platform-name>", 0),
m_platform_options(
false) // Don't include the "--platform" option by passing false
{
m_option_group.Append(&m_platform_options, LLDB_OPT_SET_ALL, 1);
m_option_group.Finalize();
CommandArgumentData platform_arg{eArgTypePlatform, eArgRepeatPlain};
m_arguments.push_back({platform_arg});
}
CommandObjectPlatformSelect::CommandObjectPlatformSelect(
CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "platform select",
"Create a platform if needed and select it as the "
"current platform.",
"platform select <platform-name>", 0),
m_platform_options(
false) // Don't include the "--platform" option by passing false
{
m_option_group.Append(&m_platform_options, LLDB_OPT_SET_ALL, 1);
m_option_group.Append(&m_platform_options.m_class_options,
LLDB_OPT_SET_1 | LLDB_OPT_SET_2, LLDB_OPT_SET_ALL);
m_option_group.Finalize();
CommandArgumentData platform_arg{eArgTypePlatform, eArgRepeatPlain};
m_arguments.push_back({platform_arg});
}

~CommandObjectPlatformSelect() override = default;
void CommandObjectPlatformSelect::HandleCompletion(CompletionRequest &request) {
CommandCompletions::PlatformPluginNames(GetCommandInterpreter(), request,
nullptr);
}

void HandleCompletion(CompletionRequest &request) override {
CommandCompletions::PlatformPluginNames(GetCommandInterpreter(), request,
nullptr);
}
Options *CommandObjectPlatformSelect::GetOptions() { return &m_option_group; }

Options *GetOptions() override { return &m_option_group; }
bool CommandObjectPlatformSelect::DoExecute(Args &args,
CommandReturnObject &result) {
if (args.GetArgumentCount() == 1) {
const char *platform_name = args.GetArgumentAtIndex(0);
if (platform_name && platform_name[0]) {
const bool select = true;
m_platform_options.SetPlatformName(platform_name);
Status error;
ArchSpec platform_arch;
PlatformSP platform_sp(m_platform_options.CreatePlatformWithOptions(
m_interpreter, ArchSpec(), select, error, platform_arch));
if (platform_sp) {
GetDebugger().GetPlatformList().SetSelectedPlatform(platform_sp);

protected:
bool DoExecute(Args &args, CommandReturnObject &result) override {
if (args.GetArgumentCount() == 1) {
const char *platform_name = args.GetArgumentAtIndex(0);
if (platform_name && platform_name[0]) {
const bool select = true;
m_platform_options.SetPlatformName(platform_name);
Status error;
ArchSpec platform_arch;
PlatformSP platform_sp(m_platform_options.CreatePlatformWithOptions(
m_interpreter, ArchSpec(), select, error, platform_arch));
if (platform_sp) {
GetDebugger().GetPlatformList().SetSelectedPlatform(platform_sp);

platform_sp->GetStatus(result.GetOutputStream());
result.SetStatus(eReturnStatusSuccessFinishResult);
} else {
result.AppendError(error.AsCString());
}
platform_sp->GetStatus(result.GetOutputStream());
result.SetStatus(eReturnStatusSuccessFinishResult);
} else {
result.AppendError("invalid platform name");
result.AppendError(error.AsCString());
}
} else {
result.AppendError(
"platform create takes a platform name as an argument\n");
result.AppendError("invalid platform name");
}
return result.Succeeded();
} else {
result.AppendError(
"platform create takes a platform name as an argument\n");
}

OptionGroupOptions m_option_group;
OptionGroupPlatform m_platform_options;
};
return result.Succeeded();
}

// "platform list"
class CommandObjectPlatformList : public CommandObjectParsed {
Expand Down
18 changes: 18 additions & 0 deletions lldb/source/Commands/CommandObjectPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLDB_SOURCE_COMMANDS_COMMANDOBJECTPLATFORM_H

#include "lldb/Interpreter/CommandObjectMultiword.h"
#include "lldb/Interpreter/OptionGroupPlatform.h"

namespace lldb_private {

Expand All @@ -27,6 +28,23 @@ class CommandObjectPlatform : public CommandObjectMultiword {
operator=(const CommandObjectPlatform &) = delete;
};

class CommandObjectPlatformSelect : public CommandObjectParsed {
public:
CommandObjectPlatformSelect(CommandInterpreter &interpreter);

~CommandObjectPlatformSelect() override = default;

void HandleCompletion(CompletionRequest &request) override;

Options *GetOptions() override;

protected:
bool DoExecute(Args &args, CommandReturnObject &result) override;

OptionGroupOptions m_option_group;
OptionGroupPlatform m_platform_options;
};

} // namespace lldb_private

#endif // LLDB_SOURCE_COMMANDS_COMMANDOBJECTPLATFORM_H
2 changes: 1 addition & 1 deletion lldb/source/Core/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ Debugger::Debugger(lldb::LogOutputCallback log_callback, void *baton)
m_error_stream_sp(std::make_shared<StreamFile>(stderr, false)),
m_input_recorder(nullptr),
m_broadcaster_manager_sp(BroadcasterManager::MakeBroadcasterManager()),
m_terminal_state(), m_target_list(*this), m_platform_list(),
m_terminal_state(), m_target_list(*this), m_platform_list(*this),
m_listener_sp(Listener::MakeListener("lldb.Debugger")),
m_source_manager_up(), m_source_file_cache(),
m_command_interpreter_up(
Expand Down
8 changes: 6 additions & 2 deletions lldb/source/Interpreter/OptionGroupPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Target/Platform.h"

using namespace lldb;
Expand All @@ -22,8 +23,10 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(

PlatformSP platform_sp;

const ScriptedMetadata metadata(m_class_options);

if (!m_platform_name.empty()) {
platform_sp = platforms.Create(m_platform_name);
platform_sp = platforms.Create(m_platform_name, &metadata);
if (!platform_sp) {
error.SetErrorStringWithFormatv(
"unable to find a plug-in for the platform named \"{0}\"",
Expand All @@ -41,7 +44,8 @@ PlatformSP OptionGroupPlatform::CreatePlatformWithOptions(
}
}
} else if (arch.IsValid()) {
platform_sp = platforms.GetOrCreate(arch, {}, &platform_arch, error);
platform_sp =
platforms.GetOrCreate(arch, {}, &platform_arch, error, &metadata);
}

if (platform_sp) {
Expand Down
8 changes: 5 additions & 3 deletions lldb/source/Interpreter/ScriptInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ using namespace lldb_private;

ScriptInterpreter::ScriptInterpreter(
Debugger &debugger, lldb::ScriptLanguage script_lang,
lldb::ScriptedProcessInterfaceUP scripted_process_interface_up)
lldb::ScriptedProcessInterfaceUP scripted_process_interface_up,
lldb::ScriptedPlatformInterfaceUP scripted_platform_interface_up)
: m_debugger(debugger), m_script_lang(script_lang),
m_scripted_process_interface_up(
std::move(scripted_process_interface_up)) {}
m_scripted_process_interface_up(std::move(scripted_process_interface_up)),
m_scripted_platform_interface_up(
std::move(scripted_platform_interface_up)) {}

void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
std::vector<std::reference_wrapper<BreakpointOptions>> &bp_options_vec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel(Process *process,
process->SetCanRunCode(false);
PlatformSP platform_sp =
process->GetTarget().GetDebugger().GetPlatformList().Create(
PlatformDarwinKernel::GetPluginNameStatic());
PlatformDarwinKernel::GetPluginNameStatic(), /*metadata = */ nullptr);
if (platform_sp.get())
process->GetTarget().SetPlatform(platform_sp);
}
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ void PlatformAndroid::Terminate() {
PlatformLinux::Terminate();
}

PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch) {
PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
if (log) {
const char *arch_name;
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/Android/PlatformAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class PlatformAndroid : public platform_linux::PlatformLinux {
static void Terminate();

// lldb_private::PluginInterface functions
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static llvm::StringRef GetPluginNameStatic(bool is_host) {
return is_host ? Platform::GetHostPlatformName() : "remote-android";
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ LLDB_PLUGIN_DEFINE(PlatformFreeBSD)

static uint32_t g_initialize_count = 0;


PlatformSP PlatformFreeBSD::CreateInstance(bool force, const ArchSpec *arch) {
PlatformSP PlatformFreeBSD::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
arch ? arch->GetArchitectureName() : "<null>",
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class PlatformFreeBSD : public PlatformPOSIX {
static void Terminate();

// lldb_private::PluginInterface functions
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static llvm::StringRef GetPluginNameStatic(bool is_host) {
return is_host ? Platform::GetHostPlatformName() : "remote-freebsd";
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ LLDB_PLUGIN_DEFINE(PlatformLinux)

static uint32_t g_initialize_count = 0;


PlatformSP PlatformLinux::CreateInstance(bool force, const ArchSpec *arch) {
PlatformSP PlatformLinux::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
arch ? arch->GetArchitectureName() : "<null>",
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/Linux/PlatformLinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class PlatformLinux : public PlatformPOSIX {
static void Terminate();

// lldb_private::PluginInterface functions
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static llvm::StringRef GetPluginNameStatic(bool is_host) {
return is_host ? Platform::GetHostPlatformName() : "remote-linux";
Expand Down
12 changes: 9 additions & 3 deletions lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ struct PlatformiOSSimulator {
PluginManager::UnregisterPlugin(PlatformiOSSimulator::CreateInstance);
}

static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
static PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
if (shouldSkipSimulatorPlatform(force, arch))
return nullptr;

Expand Down Expand Up @@ -597,7 +599,9 @@ struct PlatformAppleTVSimulator {
PluginManager::UnregisterPlugin(PlatformAppleTVSimulator::CreateInstance);
}

static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
static PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
if (shouldSkipSimulatorPlatform(force, arch))
return nullptr;
return PlatformAppleSimulator::CreateInstance(
Expand Down Expand Up @@ -639,7 +643,9 @@ struct PlatformAppleWatchSimulator {
PlatformAppleWatchSimulator::CreateInstance);
}

static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
static PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
if (shouldSkipSimulatorPlatform(force, arch))
return nullptr;
return PlatformAppleSimulator::CreateInstance(
Expand Down
8 changes: 5 additions & 3 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ llvm::StringRef PlatformDarwin::GetDescriptionStatic() {
return "Darwin platform plug-in.";
}

PlatformSP PlatformDarwin::CreateInstance(bool force, const ArchSpec *arch) {
// We only create subclasses of the PlatformDarwin plugin.
return PlatformSP();
PlatformSP PlatformDarwin::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
// We only create subclasses of the PlatformDarwin plugin.
return PlatformSP();
}

#define LLDB_PROPERTIES_platformdarwin
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class PlatformDarwin : public PlatformPOSIX {

~PlatformDarwin() override;

static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static void DebuggerInitialize(lldb_private::Debugger &debugger);

Expand Down
8 changes: 5 additions & 3 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ void PlatformDarwinKernel::Terminate() {
PlatformDarwin::Terminate();
}

PlatformSP PlatformDarwinKernel::CreateInstance(bool force,
const ArchSpec *arch) {
PlatformSP
PlatformDarwinKernel::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
if (log) {
const char *arch_name;
Expand Down Expand Up @@ -968,7 +970,7 @@ bool PlatformDarwinKernel::LoadPlatformBinaryAndSetup(Process *process,

PlatformSP platform_sp =
process->GetTarget().GetDebugger().GetPlatformList().Create(
PlatformDarwinKernel::GetPluginNameStatic());
PlatformDarwinKernel::GetPluginNameStatic(), /*metadata = */ nullptr);
if (platform_sp)
process->GetTarget().SetPlatform(platform_sp);

Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class Stream;

class PlatformDarwinKernel : public PlatformDarwin {
public:
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static void DebuggerInitialize(Debugger &debugger);

Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ llvm::StringRef PlatformMacOSX::GetDescriptionStatic() {
return "Local Mac OS X user platform plug-in.";
}

PlatformSP PlatformMacOSX::CreateInstance(bool force, const ArchSpec *arch) {
PlatformSP PlatformMacOSX::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
// The only time we create an instance is when we are creating a remote
// macosx platform which is handled by PlatformRemoteMacOSX.
return PlatformSP();
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class PlatformMacOSX : public PlatformDarwinDevice {
public:
PlatformMacOSX();

static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static void Initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ void PlatformRemoteAppleBridge::Terminate() {
PlatformDarwin::Terminate();
}

PlatformSP PlatformRemoteAppleBridge::CreateInstance(bool force,
const ArchSpec *arch) {
PlatformSP
PlatformRemoteAppleBridge::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
if (log) {
const char *arch_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class PlatformRemoteAppleBridge : public PlatformRemoteDarwinDevice {
public:
PlatformRemoteAppleBridge();

static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static void Initialize();

Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ void PlatformRemoteAppleTV::Terminate() {
PlatformDarwin::Terminate();
}

PlatformSP PlatformRemoteAppleTV::CreateInstance(bool force,
const ArchSpec *arch) {
PlatformSP
PlatformRemoteAppleTV::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
if (log) {
const char *arch_name;
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class PlatformRemoteAppleTV : public PlatformRemoteDarwinDevice {
PlatformRemoteAppleTV();

// Class Functions
static lldb::PlatformSP CreateInstance(bool force,
const lldb_private::ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static void Initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ void PlatformRemoteAppleWatch::Terminate() {
PlatformDarwin::Terminate();
}

PlatformSP PlatformRemoteAppleWatch::CreateInstance(bool force,
const ArchSpec *arch) {
PlatformSP
PlatformRemoteAppleWatch::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
if (log) {
const char *arch_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class PlatformRemoteAppleWatch : public PlatformRemoteDarwinDevice {
public:
PlatformRemoteAppleWatch();

static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static void Initialize();

Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ void PlatformRemoteMacOSX::Terminate() {
PlatformDarwin::Terminate();
}

PlatformSP PlatformRemoteMacOSX::CreateInstance(bool force,
const ArchSpec *arch) {
PlatformSP
PlatformRemoteMacOSX::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
if (log) {
const char *arch_name;
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class PlatformRemoteMacOSX : public virtual PlatformRemoteDarwinDevice {
public:
PlatformRemoteMacOSX();

static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static void Initialize();

Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ void PlatformRemoteiOS::Terminate() {
PlatformDarwin::Terminate();
}

PlatformSP PlatformRemoteiOS::CreateInstance(bool force, const ArchSpec *arch) {
PlatformSP PlatformRemoteiOS::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
if (log) {
const char *arch_name;
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class PlatformRemoteiOS : public PlatformRemoteDarwinDevice {
public:
PlatformRemoteiOS();

static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static void Initialize();

Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ LLDB_PLUGIN_DEFINE(PlatformNetBSD)

static uint32_t g_initialize_count = 0;


PlatformSP PlatformNetBSD::CreateInstance(bool force, const ArchSpec *arch) {
PlatformSP PlatformNetBSD::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
arch ? arch->GetArchitectureName() : "<null>",
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class PlatformNetBSD : public PlatformPOSIX {
static void Terminate();

// lldb_private::PluginInterface functions
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static llvm::StringRef GetPluginNameStatic(bool is_host) {
return is_host ? Platform::GetHostPlatformName() : "remote-netbsd";
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ LLDB_PLUGIN_DEFINE(PlatformOpenBSD)

static uint32_t g_initialize_count = 0;


PlatformSP PlatformOpenBSD::CreateInstance(bool force, const ArchSpec *arch) {
PlatformSP PlatformOpenBSD::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
Log *log = GetLog(LLDBLog::Platform);
LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
arch ? arch->GetArchitectureName() : "<null>",
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class PlatformOpenBSD : public PlatformPOSIX {
static void Terminate();

// lldb_private::PluginInterface functions
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static llvm::StringRef GetPluginNameStatic(bool is_host) {
return is_host ? Platform::GetHostPlatformName() : "remote-openbsd";
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ Status PlatformPOSIX::ConnectRemote(Args &args) {
if (!m_remote_platform_sp)
m_remote_platform_sp =
platform_gdb_server::PlatformRemoteGDBServer::CreateInstance(
/*force=*/true, nullptr);
/*force=*/true, /*arch=*/nullptr, /*debugger=*/nullptr,
/*metadata=*/nullptr);

if (m_remote_platform_sp && error.Success())
error = m_remote_platform_sp->ConnectRemote(args);
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ void PlatformQemuUser::DebuggerInitialize(Debugger &debugger) {
}
}

PlatformSP PlatformQemuUser::CreateInstance(bool force, const ArchSpec *arch) {
PlatformSP PlatformQemuUser::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
if (force)
return PlatformSP(new PlatformQemuUser());
return nullptr;
Expand Down
4 changes: 3 additions & 1 deletion lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class PlatformQemuUser : public Platform {
}

private:
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);
static void DebuggerInitialize(Debugger &debugger);

PlatformQemuUser() : Platform(/*is_host=*/true) {}
Expand Down
11 changes: 7 additions & 4 deletions lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ LLDB_PLUGIN_DEFINE(PlatformWindows)

static uint32_t g_initialize_count = 0;

PlatformSP PlatformWindows::CreateInstance(bool force,
const lldb_private::ArchSpec *arch) {
PlatformSP PlatformWindows::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
// The only time we create an instance is when we are creating a remote
// windows platform
const bool is_host = false;
Expand Down Expand Up @@ -137,10 +138,12 @@ Status PlatformWindows::ConnectRemote(Args &args) {
"can't connect to the host platform '{0}', always connected",
GetPluginName());
} else {
if (!m_remote_platform_sp)
if (!m_remote_platform_sp) {
m_remote_platform_sp =
platform_gdb_server::PlatformRemoteGDBServer::CreateInstance(
/*force=*/true, nullptr);
/*force=*/true, /*arch=*/nullptr, /*debugger=*/nullptr,
/*metadata=*/nullptr);
}

if (m_remote_platform_sp) {
if (error.Success()) {
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Platform/Windows/PlatformWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class PlatformWindows : public RemoteAwarePlatform {
static void Terminate();

// lldb_private::PluginInterface functions
static lldb::PlatformSP CreateInstance(bool force,
const lldb_private::ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static llvm::StringRef GetPluginNameStatic(bool is_host) {
return is_host ? Platform::GetHostPlatformName() : "remote-windows";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ void PlatformRemoteGDBServer::Terminate() {
Platform::Terminate();
}

PlatformSP PlatformRemoteGDBServer::CreateInstance(bool force,
const ArchSpec *arch) {
PlatformSP
PlatformRemoteGDBServer::CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
bool create = force;
if (!create) {
create = !arch->TripleVendorWasSpecified() && !arch->TripleOSWasSpecified();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {

static void Terminate();

static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata);

static llvm::StringRef GetPluginNameStatic() { return "remote-gdb-server"; }

Expand Down
25 changes: 12 additions & 13 deletions lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupBoolean.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Utility/LLDBLog.h"
Expand Down Expand Up @@ -58,12 +59,11 @@ lldb::ProcessSP ScriptedProcess::CreateInstance(lldb::TargetSP target_sp,
!IsScriptLanguageSupported(target_sp->GetDebugger().GetScriptLanguage()))
return nullptr;

Status error;
ScriptedProcess::ScriptedProcessInfo scripted_process_info(
target_sp->GetProcessLaunchInfo());
ScriptedMetadata scripted_metadata(target_sp->GetProcessLaunchInfo());

auto process_sp = std::shared_ptr<ScriptedProcess>(new ScriptedProcess(
target_sp, listener_sp, scripted_process_info, error));
Status error;
auto process_sp = std::shared_ptr<ScriptedProcess>(
new ScriptedProcess(target_sp, listener_sp, scripted_metadata, error));

if (error.Fail() || !process_sp || !process_sp->m_script_object_sp ||
!process_sp->m_script_object_sp->IsValid()) {
Expand All @@ -79,12 +79,11 @@ bool ScriptedProcess::CanDebug(lldb::TargetSP target_sp,
return true;
}

ScriptedProcess::ScriptedProcess(
lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
const ScriptedProcess::ScriptedProcessInfo &scripted_process_info,
Status &error)
: Process(target_sp, listener_sp),
m_scripted_process_info(scripted_process_info) {
ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
lldb::ListenerSP listener_sp,
const ScriptedMetadata &scripted_metadata,
Status &error)
: Process(target_sp, listener_sp), m_scripted_metadata(scripted_metadata) {

if (!target_sp) {
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
Expand All @@ -104,8 +103,8 @@ ScriptedProcess::ScriptedProcess(
ExecutionContext exe_ctx(target_sp, /*get_process=*/false);

StructuredData::GenericSP object_sp = GetInterface().CreatePluginObject(
m_scripted_process_info.GetClassName().c_str(), exe_ctx,
m_scripted_process_info.GetArgsSP());
m_scripted_metadata.GetClassName(), exe_ctx,
m_scripted_metadata.GetArgsSP());

if (!object_sp || !object_sp->IsValid()) {
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
Expand Down
23 changes: 3 additions & 20 deletions lldb/source/Plugins/Process/scripted/ScriptedProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
#define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H

#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Status.h"
Expand All @@ -18,24 +19,7 @@
#include <mutex>

namespace lldb_private {

class ScriptedProcess : public Process {
protected:
class ScriptedProcessInfo {
public:
ScriptedProcessInfo(const ProcessLaunchInfo &launch_info) {
m_class_name = launch_info.GetScriptedProcessClassName();
m_args_sp = launch_info.GetScriptedProcessDictionarySP();
}

std::string GetClassName() const { return m_class_name; }
StructuredData::DictionarySP GetArgsSP() const { return m_args_sp; }

private:
std::string m_class_name;
StructuredData::DictionarySP m_args_sp;
};

public:
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
lldb::ListenerSP listener_sp,
Expand Down Expand Up @@ -90,8 +74,7 @@ class ScriptedProcess : public Process {

protected:
ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
const ScriptedProcess::ScriptedProcessInfo &launch_info,
Status &error);
const ScriptedMetadata &scripted_metadata, Status &error);

Status DoStop();

Expand All @@ -111,7 +94,7 @@ class ScriptedProcess : public Process {
static bool IsScriptLanguageSupported(lldb::ScriptLanguage language);

// Member variables.
const ScriptedProcessInfo m_scripted_process_info;
const ScriptedMetadata m_scripted_metadata;
lldb_private::ScriptInterpreter *m_interpreter = nullptr;
lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
//@}
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ ScriptedThread::Create(ScriptedProcess &process,
ExecutionContext exe_ctx(process);
StructuredData::GenericSP owned_script_object_sp =
scripted_thread_interface->CreatePluginObject(
thread_class_name, exe_ctx,
process.m_scripted_process_info.GetArgsSP(), script_object);
thread_class_name, exe_ctx, process.m_scripted_metadata.GetArgsSP(),
script_object);

if (!owned_script_object_sp)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_lldb_library(lldbPluginScriptInterpreterPython PLUGIN
ScriptedPythonInterface.cpp
ScriptedProcessPythonInterface.cpp
ScriptedThreadPythonInterface.cpp
ScriptedPlatformPythonInterface.cpp

LINK_LIBS
lldbBreakpoint
Expand Down
10 changes: 3 additions & 7 deletions lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data);
// Although these are scripting-language specific, their definition depends on
// the public API.

python::PythonObject LLDBSwigPythonCreateScriptedProcess(
python::PythonObject LLDBSwigPythonCreateScriptedObject(
const char *python_class_name, const char *session_dictionary_name,
const lldb::TargetSP &target_sp, const StructuredDataImpl &args_impl,
std::string &error_string);

python::PythonObject LLDBSwigPythonCreateScriptedThread(
const char *python_class_name, const char *session_dictionary_name,
const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
lldb::ExecutionContextRefSP exe_ctx_sp,
const lldb_private::StructuredDataImpl &args_impl,
std::string &error_string);

llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "PythonReadline.h"
#include "SWIGPythonBridge.h"
#include "ScriptInterpreterPythonImpl.h"
#include "ScriptedPlatformPythonInterface.h"
#include "ScriptedProcessPythonInterface.h"

#include "lldb/API/SBError.h"
Expand Down Expand Up @@ -413,6 +414,8 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
m_command_thread_state(nullptr) {
m_scripted_process_interface_up =
std::make_unique<ScriptedProcessPythonInterface>(*this);
m_scripted_platform_interface_up =
std::make_unique<ScriptedPlatformPythonInterface>(*this);

m_dictionary_name.append("_dict");
StreamString run_string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//===-- ScriptedPlatformPythonInterface.cpp -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "lldb/Host/Config.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

// LLDB Python header must be included first
#include "lldb-python.h"

#include "SWIGPythonBridge.h"
#include "ScriptInterpreterPythonImpl.h"
#include "ScriptedPlatformPythonInterface.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;
using Locker = ScriptInterpreterPythonImpl::Locker;

ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}

StructuredData::GenericSP ScriptedPlatformPythonInterface::CreatePluginObject(
llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
if (class_name.empty())
return {};

StructuredDataImpl args_impl(args_sp);
std::string error_string;

Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
Locker::FreeLock);

lldb::ExecutionContextRefSP exe_ctx_ref_sp =
std::make_shared<ExecutionContextRef>(exe_ctx);

PythonObject ret_val = LLDBSwigPythonCreateScriptedObject(
class_name.str().c_str(), m_interpreter.GetDictionaryName(),
exe_ctx_ref_sp, args_impl, error_string);

m_object_instance_sp =
StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));

return m_object_instance_sp;
}

StructuredData::DictionarySP ScriptedPlatformPythonInterface::ListProcesses() {
Status error;
StructuredData::DictionarySP dict_sp =
Dispatch<StructuredData::DictionarySP>("list_processes", error);

if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>(
LLVM_PRETTY_FUNCTION,
llvm::Twine("Null or invalid object (" +
llvm::Twine(error.AsCString()) + llvm::Twine(")."))
.str(),
error);
}

return dict_sp;
}

StructuredData::DictionarySP
ScriptedPlatformPythonInterface::GetProcessInfo(lldb::pid_t pid) {
Status error;
StructuredData::DictionarySP dict_sp =
Dispatch<StructuredData::DictionarySP>("get_process_info", error, pid);

if (!dict_sp || !dict_sp->IsValid() || error.Fail()) {
return ScriptedInterface::ErrorWithMessage<StructuredData::DictionarySP>(
LLVM_PRETTY_FUNCTION,
llvm::Twine("Null or invalid object (" +
llvm::Twine(error.AsCString()) + llvm::Twine(")."))
.str(),
error);
}

return dict_sp;
}

Status ScriptedPlatformPythonInterface::AttachToProcess(
ProcessAttachInfoSP attach_info) {
// FIXME: Pass `attach_info` to method call
return GetStatusFromMethod("attach_to_process");
}

Status ScriptedPlatformPythonInterface::LaunchProcess(
ProcessLaunchInfoSP launch_info) {
// FIXME: Pass `launch_info` to method call
return GetStatusFromMethod("launch_process");
}

Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) {
return GetStatusFromMethod("kill_process", pid);
}

#endif // LLDB_ENABLE_PYTHON
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===-- ScriptedPlatformPythonInterface.h -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H

#include "lldb/Host/Config.h"

#if LLDB_ENABLE_PYTHON

#include "ScriptedPythonInterface.h"
#include "lldb/Interpreter/ScriptedPlatformInterface.h"

namespace lldb_private {
class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
public ScriptedPythonInterface {
public:
ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);

StructuredData::GenericSP
CreatePluginObject(const llvm::StringRef class_name,
ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp,
StructuredData::Generic *script_obj = nullptr) override;

StructuredData::DictionarySP ListProcesses() override;

StructuredData::DictionarySP GetProcessInfo(lldb::pid_t) override;

Status AttachToProcess(lldb::ProcessAttachInfoSP attach_info) override;

Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) override;

Status KillProcess(lldb::pid_t pid) override;
};
} // namespace lldb_private

#endif // LLDB_ENABLE_PYTHON
#endif // LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTEDPLATFORMPYTHONINTERFACE_H
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ StructuredData::GenericSP ScriptedProcessPythonInterface::CreatePluginObject(
if (class_name.empty())
return {};

TargetSP target_sp = exe_ctx.GetTargetSP();
StructuredDataImpl args_impl(args_sp);
std::string error_string;

Locker py_lock(&m_interpreter, Locker::AcquireLock | Locker::NoSTDIN,
Locker::FreeLock);

PythonObject ret_val = LLDBSwigPythonCreateScriptedProcess(
class_name.str().c_str(), m_interpreter.GetDictionaryName(), target_sp,
args_impl, error_string);
lldb::ExecutionContextRefSP exe_ctx_ref_sp =
std::make_shared<ExecutionContextRef>(exe_ctx);

PythonObject ret_val = LLDBSwigPythonCreateScriptedObject(
class_name.str().c_str(), m_interpreter.GetDictionaryName(),
exe_ctx_ref_sp, args_impl, error_string);

m_object_instance_sp =
StructuredData::GenericSP(new StructuredPythonObject(std::move(ret_val)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ ScriptedPythonInterface::ScriptedPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedInterface(), m_interpreter(interpreter) {}

Status
ScriptedPythonInterface::GetStatusFromMethod(llvm::StringRef method_name) {
Status error;
Dispatch<Status>(method_name, error);

return error;
}

template <>
StructuredData::ArraySP
ScriptedPythonInterface::ExtractValueFromPythonObject<StructuredData::ArraySP>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ class ScriptedPythonInterface : virtual public ScriptedInterface {
return ExtractValueFromPythonObject<T>(py_return, error);
}

Status GetStatusFromMethod(llvm::StringRef method_name);
template <typename... Args>
Status GetStatusFromMethod(llvm::StringRef method_name, Args &&...args) {
Status error;
Dispatch<Status>(method_name, error, std::forward<Args>(args)...);

return error;
}

template <typename T> T Transform(T object) {
// No Transformation for generic usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ StructuredData::GenericSP ScriptedThreadPythonInterface::CreatePluginObject(
if (class_name.empty() && !script_obj)
return {};

ProcessSP process_sp = exe_ctx.GetProcessSP();
StructuredDataImpl args_impl(args_sp);
std::string error_string;

Expand All @@ -44,11 +43,13 @@ StructuredData::GenericSP ScriptedThreadPythonInterface::CreatePluginObject(

PythonObject ret_val;

if (!script_obj)
ret_val = LLDBSwigPythonCreateScriptedThread(
class_name.str().c_str(), m_interpreter.GetDictionaryName(), process_sp,
args_impl, error_string);
else
if (!script_obj) {
lldb::ExecutionContextRefSP exe_ctx_ref_sp =
std::make_shared<ExecutionContextRef>(exe_ctx);
ret_val = LLDBSwigPythonCreateScriptedObject(
class_name.str().c_str(), m_interpreter.GetDictionaryName(),
exe_ctx_ref_sp, args_impl, error_string);
} else
ret_val = PythonObject(PyRefType::Borrowed,
static_cast<PyObject *>(script_obj->GetValue()));

Expand Down
75 changes: 26 additions & 49 deletions lldb/source/Target/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,40 +164,6 @@ Platform::LocateExecutableScriptingResources(Target *target, Module &module,
return FileSpecList();
}

// PlatformSP
// Platform::FindPlugin (Process *process, ConstString plugin_name)
//{
// PlatformCreateInstance create_callback = nullptr;
// if (plugin_name)
// {
// create_callback =
// PluginManager::GetPlatformCreateCallbackForPluginName (plugin_name);
// if (create_callback)
// {
// ArchSpec arch;
// if (process)
// {
// arch = process->GetTarget().GetArchitecture();
// }
// PlatformSP platform_sp(create_callback(process, &arch));
// if (platform_sp)
// return platform_sp;
// }
// }
// else
// {
// for (uint32_t idx = 0; (create_callback =
// PluginManager::GetPlatformCreateCallbackAtIndex(idx)) != nullptr;
// ++idx)
// {
// PlatformSP platform_sp(create_callback(process, nullptr));
// if (platform_sp)
// return platform_sp;
// }
// }
// return PlatformSP();
//}

Status Platform::GetSharedModule(
const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
const FileSpecList *module_search_paths_ptr,
Expand Down Expand Up @@ -251,14 +217,15 @@ bool Platform::GetModuleSpec(const FileSpec &module_file_spec,
module_spec);
}

PlatformSP Platform::Create(llvm::StringRef name) {
PlatformSP Platform::Create(llvm::StringRef name, const Debugger *debugger,
const ScriptedMetadata *metadata) {
lldb::PlatformSP platform_sp;
if (name == GetHostPlatformName())
return GetHostPlatform();

if (PlatformCreateInstance create_callback =
PluginManager::GetPlatformCreateCallbackForPluginName(name))
return create_callback(true, nullptr);
return create_callback(true, nullptr, debugger, metadata);
return nullptr;
}

Expand Down Expand Up @@ -1967,19 +1934,20 @@ Args Platform::GetExtraStartupCommands() {
return {};
}

PlatformSP PlatformList::GetOrCreate(llvm::StringRef name) {
PlatformSP PlatformList::GetOrCreate(llvm::StringRef name,
const ScriptedMetadata *metadata) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
for (const PlatformSP &platform_sp : m_platforms) {
if (platform_sp->GetName() == name)
return platform_sp;
}
return Create(name);
return Create(name, metadata);
}

PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
const ArchSpec &process_host_arch,
ArchSpec *platform_arch_ptr,
Status &error) {
ArchSpec *platform_arch_ptr, Status &error,
const ScriptedMetadata *metadata) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
// First try exact arch matches across all platforms already created
for (const auto &platform_sp : m_platforms) {
Expand All @@ -2002,7 +1970,8 @@ PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
for (idx = 0;
(create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx));
++idx) {
PlatformSP platform_sp = create_callback(false, &arch);
PlatformSP platform_sp =
create_callback(false, &arch, &m_debugger, metadata);
if (platform_sp &&
platform_sp->IsCompatibleArchitecture(
arch, process_host_arch, ArchSpec::ExactMatch, platform_arch_ptr)) {
Expand All @@ -2014,7 +1983,8 @@ PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
for (idx = 0;
(create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx));
++idx) {
PlatformSP platform_sp = create_callback(false, &arch);
PlatformSP platform_sp =
create_callback(false, &arch, &m_debugger, metadata);
if (platform_sp && platform_sp->IsCompatibleArchitecture(
arch, process_host_arch, ArchSpec::CompatibleMatch,
platform_arch_ptr)) {
Expand All @@ -2029,16 +1999,19 @@ PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,

PlatformSP PlatformList::GetOrCreate(const ArchSpec &arch,
const ArchSpec &process_host_arch,
ArchSpec *platform_arch_ptr) {
ArchSpec *platform_arch_ptr,
const ScriptedMetadata *metadata) {
Status error;
if (arch.IsValid())
return GetOrCreate(arch, process_host_arch, platform_arch_ptr, error);
return GetOrCreate(arch, process_host_arch, platform_arch_ptr, error,
metadata);
return nullptr;
}

PlatformSP PlatformList::GetOrCreate(llvm::ArrayRef<ArchSpec> archs,
const ArchSpec &process_host_arch,
std::vector<PlatformSP> &candidates) {
std::vector<PlatformSP> &candidates,
const ScriptedMetadata *metadata) {
candidates.clear();
candidates.reserve(archs.size());

Expand Down Expand Up @@ -2067,7 +2040,9 @@ PlatformSP PlatformList::GetOrCreate(llvm::ArrayRef<ArchSpec> archs,

// Collect a list of candidate platforms for the architectures.
for (const ArchSpec &arch : archs) {
if (PlatformSP platform = GetOrCreate(arch, process_host_arch, nullptr))
if (PlatformSP platform = GetOrCreate(arch, process_host_arch,
/*platform_arch_ptr = */ nullptr,
/*metadata = */ nullptr))
candidates.push_back(platform);
}

Expand All @@ -2088,9 +2063,10 @@ PlatformSP PlatformList::GetOrCreate(llvm::ArrayRef<ArchSpec> archs,
return nullptr;
}

PlatformSP PlatformList::Create(llvm::StringRef name) {
PlatformSP PlatformList::Create(llvm::StringRef name,
const ScriptedMetadata *metadata) {
std::lock_guard<std::recursive_mutex> guard(m_mutex);
PlatformSP platform_sp = Platform::Create(name);
PlatformSP platform_sp = Platform::Create(name, &m_debugger, metadata);
m_platforms.push_back(platform_sp);
return platform_sp;
}
Expand All @@ -2104,7 +2080,8 @@ bool PlatformList::LoadPlatformBinaryAndSetup(Process *process,
(create_callback = PluginManager::GetPlatformCreateCallbackAtIndex(idx));
++idx) {
ArchSpec arch;
PlatformSP platform_sp = create_callback(true, &arch);
PlatformSP platform_sp =
create_callback(true, &arch, &m_debugger, /*metadata = */ nullptr);
if (platform_sp) {
if (platform_sp->LoadPlatformBinaryAndSetup(process, addr, notify))
return true;
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,8 @@ void Process::CompleteAttach() {
ArchSpec::CompatibleMatch, nullptr)) {
ArchSpec platform_arch;
platform_sp = GetTarget().GetDebugger().GetPlatformList().GetOrCreate(
target_arch, process_host_arch, &platform_arch);
target_arch, process_host_arch, &platform_arch,
/*metadata = */ nullptr);
if (platform_sp) {
GetTarget().SetPlatform(platform_sp);
GetTarget().SetArchitecture(platform_arch);
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,9 @@ bool Target::SetArchitecture(const ArchSpec &arch_spec, bool set_platform,
other, {}, ArchSpec::CompatibleMatch, nullptr)) {
ArchSpec platform_arch;
if (PlatformSP arch_platform_sp =
GetDebugger().GetPlatformList().GetOrCreate(other, {},
&platform_arch)) {
GetDebugger().GetPlatformList().GetOrCreate(
other, /*process_host_arch = */ {}, &platform_arch,
/*metadata = */ nullptr)) {
SetPlatform(arch_platform_sp);
if (platform_arch.IsValid())
other = platform_arch;
Expand Down
19 changes: 12 additions & 7 deletions lldb/source/Target/TargetList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ Status TargetList::CreateTargetInternal(
std::vector<ArchSpec> archs;
for (const ModuleSpec &spec : module_specs.ModuleSpecs())
archs.push_back(spec.GetArchitecture());
if (PlatformSP platform_for_archs_sp =
platform_list.GetOrCreate(archs, {}, candidates)) {
if (PlatformSP platform_for_archs_sp = platform_list.GetOrCreate(
archs, /*process_host_arch = */ {}, candidates,
/*metadata = */ nullptr)) {
platform_sp = platform_for_archs_sp;
} else if (candidates.empty()) {
error.SetErrorString("no matching platforms found for this file");
Expand Down Expand Up @@ -218,7 +219,9 @@ Status TargetList::CreateTargetInternal(
if (!prefer_platform_arch && arch.IsValid()) {
if (!platform_sp->IsCompatibleArchitecture(
arch, {}, ArchSpec::CompatibleMatch, nullptr)) {
platform_sp = platform_list.GetOrCreate(arch, {}, &platform_arch);
platform_sp =
platform_list.GetOrCreate(arch, /*process_host_arch = */ {},
&platform_arch, /*metadata = */ nullptr);
if (platform_sp)
platform_list.SetSelectedPlatform(platform_sp);
}
Expand All @@ -228,8 +231,9 @@ Status TargetList::CreateTargetInternal(
ArchSpec fixed_platform_arch;
if (!platform_sp->IsCompatibleArchitecture(
platform_arch, {}, ArchSpec::CompatibleMatch, nullptr)) {
platform_sp =
platform_list.GetOrCreate(platform_arch, {}, &fixed_platform_arch);
platform_sp = platform_list.GetOrCreate(
platform_arch, /*process_host_arch = */ {}, &fixed_platform_arch,
/*metadata = */ nullptr);
if (platform_sp)
platform_list.SetSelectedPlatform(platform_sp);
}
Expand Down Expand Up @@ -260,8 +264,9 @@ Status TargetList::CreateTargetInternal(Debugger &debugger,
if (arch.IsValid()) {
if (!platform_sp || !platform_sp->IsCompatibleArchitecture(
arch, {}, ArchSpec::CompatibleMatch, nullptr))
platform_sp =
debugger.GetPlatformList().GetOrCreate(specified_arch, {}, &arch);
platform_sp = debugger.GetPlatformList().GetOrCreate(
specified_arch, /*process_host_arch = */ {}, &arch,
/*metadata = */ nullptr);
}

if (!platform_sp)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os

import lldb
from lldb.plugins.scripted_platform import ScriptedPlatform

class MyScriptedPlatform(ScriptedPlatform):

def __init__(self, exe_ctx, args):
self.processes = {}

proc = {}
proc['name'] = 'a.out'
proc['arch'] = 'arm64-apple-macosx'
proc['pid'] = 420
proc['parent'] = 42
proc['uid'] = 501
proc['gid'] = 20
self.processes[420] = proc

def list_processes(self):
return self.processes

def get_process_info(self, pid):
return self.processes[pid]

def launch_process(self, launch_info):
return lldb.SBError()

def kill_process(self, pid):
return lldb.SBError()

def __lldb_init_module(debugger, dict):
if not 'SKIP_SCRIPTED_PLATFORM_SELECT' in os.environ:
debugger.HandleCommand(
"platform select scripted-platform -C %s.%s" % (__name__, MyScriptedPlatform.__name__))
else:
print("Name of the class that will manage the scripted platform: '%s.%s'"
% (__name__, MyScriptedPlatform.__name__))
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from lldb.plugins.scripted_process import ScriptedThread

class DummyScriptedProcess(ScriptedProcess):
def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
super().__init__(target, args)
def __init__(self, exe_ctx: lldb.SBExecutionContext, args : lldb.SBStructuredData):
super().__init__(exe_ctx, args)
self.threads[0] = DummyScriptedThread(self, None)

def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from lldb.plugins.scripted_process import ScriptedThread

class InvalidScriptedProcess(ScriptedProcess):
def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
super().__init__(target, args)
def __init__(self, exe_ctx: lldb.SBExecutionContext, args : lldb.SBStructuredData):
super().__init__(exe_ctx, args)
self.threads[0] = InvalidScriptedThread(self, None)

def get_memory_region_containing_address(self, addr: int) -> lldb.SBMemoryRegionInfo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def get_module_with_name(self, target, name):
return module
return None

def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
super().__init__(target, args)
def __init__(self, exe_ctx: lldb.SBExecutionContext, args : lldb.SBStructuredData):
super().__init__(exe_ctx, args)

self.corefile_target = None
self.corefile_process = None
Expand All @@ -25,7 +25,7 @@ def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
idx = self.backing_target_idx.GetIntegerValue(42)
if self.backing_target_idx.GetType() == lldb.eStructuredDataTypeString:
idx = int(self.backing_target_idx.GetStringValue(100))
self.corefile_target = target.GetDebugger().GetTargetAtIndex(idx)
self.corefile_target = self.target.GetDebugger().GetTargetAtIndex(idx)
self.corefile_process = self.corefile_target.GetProcess()
for corefile_thread in self.corefile_process:
structured_data = lldb.SBStructuredData()
Expand Down
3 changes: 2 additions & 1 deletion lldb/unittests/Core/DiagnosticEventTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class DiagnosticEventTest : public ::testing::Test {
[]() { Debugger::Initialize(nullptr); });
ArchSpec arch("x86_64-apple-macosx-");
Platform::SetHostPlatform(
PlatformRemoteMacOSX::CreateInstance(true, &arch));
PlatformRemoteMacOSX::CreateInstance(true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));
}
void TearDown() override {
PlatformMacOSX::Terminate();
Expand Down
13 changes: 9 additions & 4 deletions lldb/unittests/Expression/DWARFExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ TEST_F(DWARFExpressionMockProcessTest, DW_OP_deref) {

// Set up a mock process.
ArchSpec arch("i386-pc-linux");
Platform::SetHostPlatform(
platform_linux::PlatformLinux::CreateInstance(true, &arch));
Platform::SetHostPlatform(platform_linux::PlatformLinux::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));
lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);
lldb::TargetSP target_sp;
Expand Down Expand Up @@ -409,7 +410,9 @@ TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr) {
// Set up a wasm target
ArchSpec arch("wasm32-unknown-unknown-wasm");
lldb::PlatformSP host_platform_sp =
platform_linux::PlatformLinux::CreateInstance(true, &arch);
platform_linux::PlatformLinux::CreateInstance(true, &arch,
/*debugger=*/nullptr,
/*metadata=*/nullptr);
ASSERT_TRUE(host_platform_sp);
Platform::SetHostPlatform(host_platform_sp);
lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
Expand Down Expand Up @@ -488,7 +491,9 @@ TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr_index) {
// Set up a wasm target
ArchSpec arch("wasm32-unknown-unknown-wasm");
lldb::PlatformSP host_platform_sp =
platform_linux::PlatformLinux::CreateInstance(true, &arch);
platform_linux::PlatformLinux::CreateInstance(true, &arch,
/*debugger=*/nullptr,
/*metadata=*/nullptr);
ASSERT_TRUE(host_platform_sp);
Platform::SetHostPlatform(host_platform_sp);
lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
Expand Down
6 changes: 4 additions & 2 deletions lldb/unittests/Interpreter/TestCommandPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ void RunTest(CommandInterpreter &interp, const char *args, bool is_leaf,
TEST_F(VerifyUserMultiwordCmdPathTest, TestErrors) {
ArchSpec arch("x86_64-apple-macosx-");

Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));

Platform::SetHostPlatform(
PlatformRemoteMacOSX::CreateInstance(true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);

Expand Down
42 changes: 34 additions & 8 deletions lldb/unittests/Platform/PlatformAppleSimulatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,50 @@
#include "gtest/gtest.h"

#include "Plugins/Platform/MacOSX/PlatformAppleSimulator.h"
#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
#include "Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h"
#include "Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h"
#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
#include "TestingSupport/SubsystemRAII.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Platform.h"

using namespace lldb;
using namespace lldb_private;

static std::once_flag platform_initialize_flag;
static std::once_flag debugger_initialize_flag;

class PlatformAppleSimulatorTest : public ::testing::Test {
SubsystemRAII<FileSystem, HostInfo, PlatformAppleSimulator, PlatformRemoteiOS,
PlatformRemoteAppleTV, PlatformRemoteAppleWatch>
subsystems;

public:
void SetUp() override {
std::call_once(platform_initialize_flag,
[]() { PlatformMacOSX::Initialize(); });
std::call_once(debugger_initialize_flag,
[]() { Debugger::Initialize(nullptr); });
ArchSpec arch("x86_64-apple-macosx-");
Platform::SetHostPlatform(
PlatformRemoteMacOSX::CreateInstance(true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));
}
void TearDown() override { PlatformMacOSX::Terminate(); }

protected:
DebuggerSP m_debugger_sp = nullptr;
};

#ifdef __APPLE__

static void testSimPlatformArchHasSimEnvironment(llvm::StringRef name) {
auto platform_sp = Platform::Create(name);
auto platform_sp = Platform::Create(name, /*debugger=*/nullptr,
/*metadata=*/nullptr);
ASSERT_TRUE(platform_sp);
int num_arches = 0;

Expand Down Expand Up @@ -58,12 +81,13 @@ TEST_F(PlatformAppleSimulatorTest, TestHostPlatformToSim) {
};

for (auto sim : sim_platforms) {
PlatformList list;
PlatformList list(*m_debugger_sp.get());
ArchSpec arch = platform_arch;
arch.GetTriple().setOS(sim);
arch.GetTriple().setEnvironment(llvm::Triple::Simulator);

auto platform_sp = list.GetOrCreate(arch, {}, nullptr);
auto platform_sp = list.GetOrCreate(arch, {}, /*platform_arch_ptr=*/nullptr,
/*metadata=*/nullptr);
EXPECT_TRUE(platform_sp);
}
}
Expand All @@ -78,18 +102,20 @@ TEST_F(PlatformAppleSimulatorTest, TestPlatformSelectionOrder) {
llvm::Triple::WatchOS,
};

PlatformList list;
list.GetOrCreate("remote-ios");
list.GetOrCreate("remote-tvos");
list.GetOrCreate("remote-watchos");
PlatformList list(*m_debugger_sp.get());
list.GetOrCreate("remote-ios", /*metadata=*/nullptr);
list.GetOrCreate("remote-tvos", /*metadata=*/nullptr);
list.GetOrCreate("remote-watchos", /*metadata=*/nullptr);

for (auto sim : sim_platforms) {
ArchSpec arch = platform_arch;
arch.GetTriple().setOS(sim);
arch.GetTriple().setEnvironment(llvm::Triple::Simulator);

Status error;
auto platform_sp = list.GetOrCreate(arch, {}, nullptr, error);
auto platform_sp =
list.GetOrCreate(arch, {}, /*platform_arch_ptr=*/nullptr, error,
/*metadata=*/nullptr);
EXPECT_TRUE(platform_sp);
EXPECT_TRUE(platform_sp->GetName().contains("simulator"));
}
Expand Down
14 changes: 9 additions & 5 deletions lldb/unittests/Platform/PlatformSiginfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,19 @@ class PlatformSiginfoTest : public ::testing::Test {

switch (arch.GetTriple().getOS()) {
case llvm::Triple::FreeBSD:
platform_sp =
platform_freebsd::PlatformFreeBSD::CreateInstance(true, &arch);
platform_sp = platform_freebsd::PlatformFreeBSD::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr);
break;
case llvm::Triple::Linux:
platform_sp = platform_linux::PlatformLinux::CreateInstance(true, &arch);
platform_sp = platform_linux::PlatformLinux::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr);
break;
case llvm::Triple::NetBSD:
platform_sp =
platform_netbsd::PlatformNetBSD::CreateInstance(true, &arch);
platform_sp = platform_netbsd::PlatformNetBSD::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr);
break;
default:
llvm_unreachable("unknown ostype in triple");
Expand Down
42 changes: 30 additions & 12 deletions lldb/unittests/Platform/PlatformTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
#include "TestingSupport/SubsystemRAII.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
Expand All @@ -18,6 +19,8 @@
using namespace lldb;
using namespace lldb_private;

static std::once_flag debugger_initialize_flag;

class TestPlatform : public PlatformPOSIX {
public:
TestPlatform() : PlatformPOSIX(false) {}
Expand Down Expand Up @@ -59,7 +62,9 @@ class PlatformThumb : public TestPlatform {
PluginManager::UnregisterPlugin(PlatformThumb::CreateInstance);
}

static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
static PlatformSP CreateInstance(bool force, const ArchSpec *arch,
const Debugger *debugger,
const ScriptedMetadata *metadata) {
return std::make_shared<PlatformThumb>();
}

Expand All @@ -76,12 +81,21 @@ class PlatformTest : public ::testing::Test {
SubsystemRAII<FileSystem, HostInfo> subsystems;

protected:
PlatformList list;
PlatformList *list = nullptr;
DebuggerSP m_debugger_sp = nullptr;

void SetUp() override {
std::call_once(debugger_initialize_flag,
[]() { Debugger::Initialize(nullptr); });
list = new PlatformList(*m_debugger_sp.get());
}

void TearDown() override { delete list; }

void SetHostPlatform(const PlatformSP &platform_sp) {
Platform::SetHostPlatform(platform_sp);
ASSERT_EQ(Platform::GetHostPlatform(), platform_sp);
list.Append(platform_sp, /*set_selected=*/true);
list->Append(platform_sp, /*set_selected=*/true);
}
};

Expand All @@ -93,7 +107,8 @@ TEST_F(PlatformTest, GetPlatformForArchitecturesHost) {
std::vector<PlatformSP> candidates;

// The host platform matches all architectures.
PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
PlatformSP platform_sp =
list->GetOrCreate(archs, {}, candidates, /*metadata=*/nullptr);
ASSERT_TRUE(platform_sp);
EXPECT_EQ(platform_sp, Platform::GetHostPlatform());
}
Expand All @@ -106,13 +121,14 @@ TEST_F(PlatformTest, GetPlatformForArchitecturesSelected) {
std::vector<PlatformSP> candidates;

// The host platform matches no architectures.
PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
PlatformSP platform_sp =
list->GetOrCreate(archs, {}, candidates, /*metadata=*/nullptr);
ASSERT_FALSE(platform_sp);

// The selected platform matches all architectures.
const PlatformSP selected_platform_sp = std::make_shared<PlatformArm>();
list.Append(selected_platform_sp, /*set_selected=*/true);
platform_sp = list.GetOrCreate(archs, {}, candidates);
list->Append(selected_platform_sp, /*set_selected=*/true);
platform_sp = list->GetOrCreate(archs, {}, candidates, /*metadata=*/nullptr);
ASSERT_TRUE(platform_sp);
EXPECT_EQ(platform_sp, selected_platform_sp);
}
Expand All @@ -125,15 +141,16 @@ TEST_F(PlatformTest, GetPlatformForArchitecturesSelectedOverHost) {
std::vector<PlatformSP> candidates;

// The host platform matches one architecture.
PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
PlatformSP platform_sp =
list->GetOrCreate(archs, {}, candidates, /*metadata=*/nullptr);
ASSERT_TRUE(platform_sp);
EXPECT_EQ(platform_sp, Platform::GetHostPlatform());

// The selected and host platform each match one architecture.
// The selected platform is preferred.
const PlatformSP selected_platform_sp = std::make_shared<PlatformArm>();
list.Append(selected_platform_sp, /*set_selected=*/true);
platform_sp = list.GetOrCreate(archs, {}, candidates);
list->Append(selected_platform_sp, /*set_selected=*/true);
platform_sp = list->GetOrCreate(archs, {}, candidates, /*metadata=*/nullptr);
ASSERT_TRUE(platform_sp);
EXPECT_EQ(platform_sp, selected_platform_sp);
}
Expand All @@ -144,14 +161,15 @@ TEST_F(PlatformTest, GetPlatformForArchitecturesCandidates) {
SetHostPlatform(std::make_shared<PlatformIntel>());

const PlatformSP selected_platform_sp = std::make_shared<PlatformArm>();
list.Append(selected_platform_sp, /*set_selected=*/true);
list->Append(selected_platform_sp, /*set_selected=*/true);

const std::vector<ArchSpec> archs = {ArchSpec("thumbv7-apple-ps4"),
ArchSpec("thumbv7f-apple-ps4")};
std::vector<PlatformSP> candidates;

// The host platform matches one architecture.
PlatformSP platform_sp = list.GetOrCreate(archs, {}, candidates);
PlatformSP platform_sp =
list->GetOrCreate(archs, {}, candidates, /*metadata=*/nullptr);
ASSERT_TRUE(platform_sp);
EXPECT_EQ(platform_sp->GetName(), "thumb");

Expand Down
8 changes: 6 additions & 2 deletions lldb/unittests/Process/ProcessEventDataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ ThreadSP CreateThread(ProcessSP &process_sp, bool should_stop,
TEST_F(ProcessEventDataTest, DoOnRemoval) {
ArchSpec arch("x86_64-apple-macosx-");

Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
Platform::SetHostPlatform(
PlatformRemoteMacOSX::CreateInstance(true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);
Expand Down Expand Up @@ -182,7 +184,9 @@ TEST_F(ProcessEventDataTest, DoOnRemoval) {
TEST_F(ProcessEventDataTest, ShouldStop) {
ArchSpec arch("x86_64-apple-macosx-");

Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
Platform::SetHostPlatform(
PlatformRemoteMacOSX::CreateInstance(true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);
Expand Down
11 changes: 2 additions & 9 deletions lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,9 @@ lldb_private::LLDBSWIGPythonCreateOSPlugin(const char *python_class_name,
return python::PythonObject();
}

python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedProcess(
python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedObject(
const char *python_class_name, const char *session_dictionary_name,
const lldb::TargetSP &target_sp, const StructuredDataImpl &args_impl,
std::string &error_string) {
return python::PythonObject();
}

python::PythonObject lldb_private::LLDBSwigPythonCreateScriptedThread(
const char *python_class_name, const char *session_dictionary_name,
const lldb::ProcessSP &process_sp, const StructuredDataImpl &args_impl,
lldb::ExecutionContextRefSP exe_ctx_sp, const StructuredDataImpl &args_impl,
std::string &error_string) {
return python::PythonObject();
}
Expand Down
10 changes: 6 additions & 4 deletions lldb/unittests/Target/ExecutionContextTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ TEST_F(ExecutionContextTest, GetByteOrder) {
TEST_F(ExecutionContextTest, GetByteOrderTarget) {
ArchSpec arch("powerpc64-pc-linux");

Platform::SetHostPlatform(
platform_linux::PlatformLinux::CreateInstance(true, &arch));
Platform::SetHostPlatform(platform_linux::PlatformLinux::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);
Expand All @@ -94,8 +95,9 @@ TEST_F(ExecutionContextTest, GetByteOrderTarget) {
TEST_F(ExecutionContextTest, GetByteOrderProcess) {
ArchSpec arch("powerpc64-pc-linux");

Platform::SetHostPlatform(
platform_linux::PlatformLinux::CreateInstance(true, &arch));
Platform::SetHostPlatform(platform_linux::PlatformLinux::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);
Expand Down
5 changes: 3 additions & 2 deletions lldb/unittests/Target/StackFrameRecognizerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class StackFrameRecognizerTest : public ::testing::Test {
// Pretend Linux is the host platform.
platform_linux::PlatformLinux::Initialize();
ArchSpec arch("powerpc64-pc-linux");
Platform::SetHostPlatform(
platform_linux::PlatformLinux::CreateInstance(true, &arch));
Platform::SetHostPlatform(platform_linux::PlatformLinux::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));
}

void TearDown() override {
Expand Down
10 changes: 6 additions & 4 deletions lldb/unittests/Thread/ThreadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ TargetSP CreateTarget(DebuggerSP &debugger_sp, ArchSpec &arch) {
TEST_F(ThreadTest, SetStopInfo) {
ArchSpec arch("powerpc64-pc-linux");

Platform::SetHostPlatform(
platform_linux::PlatformLinux::CreateInstance(true, &arch));
Platform::SetHostPlatform(platform_linux::PlatformLinux::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);
Expand Down Expand Up @@ -126,8 +127,9 @@ TEST_F(ThreadTest, SetStopInfo) {
TEST_F(ThreadTest, GetPrivateStopInfo) {
ArchSpec arch("powerpc64-pc-linux");

Platform::SetHostPlatform(
platform_linux::PlatformLinux::CreateInstance(true, &arch));
Platform::SetHostPlatform(platform_linux::PlatformLinux::CreateInstance(
true, &arch, /*debugger=*/nullptr,
/*metadata=*/nullptr));

DebuggerSP debugger_sp = Debugger::CreateInstance();
ASSERT_TRUE(debugger_sp);
Expand Down