Files
llvm-tms34010/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedPlatformPythonInterface.cpp
T
Med Ismail Bennani 1b4a578a9f [lldb/Interpreter] Plumb ScriptedMetadata through scripted plugin CreatePluginObject (NFC) (#198425)
Replace the (class_name, args_sp) parameter pair on CreatePluginObject
across the scripted plugin interfaces (ScriptedThread, OperatingSystem,
ScriptedBreakpoint, ScriptedFrameProvider, ScriptedProcess, and the
underlying ScriptedPythonInterface template) with a single `const
ScriptedMetadata &`. Callers (OperatingSystemPython, ScriptedThread,
ScriptedProcess, BreakpointResolverScripted, ScriptedFrameProvider) pass
their existing ScriptedMetadata directly, removing the need to re-bundle
class_name and args at every call site.

ScriptedBreakpoint, ScriptedFrameProvider and ScriptedProcess no longer
carry a redundant `args_sp` parameter; their callers fold those args
into the metadata, and the Python overrides reconstruct a
StructuredDataImpl from the metadata's args dict for the dispatched
call.

ScriptedInterface gains an `m_scripted_metadata` member and a
`GetScriptedMetadata()` accessor; ScriptedPythonInterface populates it
when CreatePluginObject is invoked so subclasses can later report which
script class is in play.

Hook/StopHook/ThreadPlan public interfaces keep their existing `args_sp`
parameter for now; subsequent commits consolidate that.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2026-05-20 13:07:31 -07:00

101 lines
3.4 KiB
C++

//===-- 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-python.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.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) {}
llvm::Expected<StructuredData::GenericSP>
ScriptedPlatformPythonInterface::CreatePluginObject(
llvm::StringRef class_name, ExecutionContext &exe_ctx,
StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {
ExecutionContextRefSP exe_ctx_ref_sp =
std::make_shared<ExecutionContextRef>(exe_ctx);
ScriptedMetadata scripted_metadata(class_name, args_sp);
return ScriptedPythonInterface::CreatePluginObject(
scripted_metadata, script_obj, exe_ctx_ref_sp, args_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);
}
void ScriptedPlatformPythonInterface::Initialize() {
PluginManager::RegisterPlugin(
GetPluginNameStatic(), "Mock platform and interact with its processes.",
CreateInstance, eScriptLanguagePython, {});
}
void ScriptedPlatformPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}