10#include "lldb/Host/Config.h"
19#include "../lldb-python.h"
21#include "../SWIGPythonBridge.h"
22#include "../ScriptInterpreterPythonImpl.h"
35using Locker = ScriptInterpreterPythonImpl::Locker;
37ScriptedProcessPythonInterface::ScriptedProcessPythonInterface(
38 ScriptInterpreterPythonImpl &interpreter)
41llvm::Expected<StructuredData::GenericSP>
42ScriptedProcessPythonInterface::CreatePluginObject(
46 std::make_shared<ExecutionContextRef>(exe_ctx);
48 return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,
49 exe_ctx_ref_sp, sd_impl);
55 Dispatch<StructuredData::DictionarySP>(
"get_capabilities",
error);
57 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
67 std::make_shared<ProcessAttachInfo>(attach_info);
68 return GetStatusFromMethod(
"attach", attach_info_sp);
71Status ScriptedProcessPythonInterface::Launch() {
72 return GetStatusFromMethod(
"launch");
75Status ScriptedProcessPythonInterface::Resume() {
77 return GetStatusFromMethod(
"resume",
true);
80std::optional<MemoryRegionInfo>
81ScriptedProcessPythonInterface::GetMemoryRegionContainingAddress(
83 auto mem_region = Dispatch<std::optional<MemoryRegionInfo>>(
84 "get_memory_region_containing_address",
error, address);
87 return ErrorWithMessage<MemoryRegionInfo>(LLVM_PRETTY_FUNCTION,
97 Dispatch<StructuredData::DictionarySP>(
"get_threads_info",
error);
99 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
106bool ScriptedProcessPythonInterface::CreateBreakpoint(
lldb::addr_t addr,
110 Dispatch(
"create_breakpoint", py_error, addr,
error);
116 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
120 return obj->GetBooleanValue();
127 "read_memory_at_address", py_error, address, size,
error);
136lldb::offset_t ScriptedProcessPythonInterface::WriteMemoryAtAddress(
140 Dispatch(
"write_memory_at_address", py_error, addr, data_sp,
error);
142 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
156 Dispatch<StructuredData::ArraySP>(
"get_loaded_images",
error);
158 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, array,
165lldb::pid_t ScriptedProcessPythonInterface::GetProcessID() {
169 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
176bool ScriptedProcessPythonInterface::IsAlive() {
180 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
184 return obj->GetBooleanValue();
187std::optional<std::string>
188ScriptedProcessPythonInterface::GetScriptedThreadPluginName() {
192 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
196 return obj->GetStringValue().str();
200ScriptedProcessPythonInterface::CreateScriptedThreadInterface() {
201 return m_interpreter.CreateScriptedThreadInterface();
207 Dispatch<StructuredData::DictionarySP>(
"get_process_metadata",
error);
209 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,
216void ScriptedProcessPythonInterface::Initialize() {
217 const std::vector<llvm::StringRef> ci_usages = {
218 "process attach -C <script-name> [-k key -v value ...]",
219 "process launch -C <script-name> [-k key -v value ...]"};
220 const std::vector<llvm::StringRef> api_usages = {
221 "SBAttachInfo.SetScriptedProcessClassName",
222 "SBAttachInfo.SetScriptedProcessDictionary",
224 "SBLaunchInfo.SetScriptedProcessClassName",
225 "SBLaunchInfo.SetScriptedProcessDictionary",
227 PluginManager::RegisterPlugin(
228 GetPluginNameStatic(), llvm::StringRef(
"Mock process state"),
229 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
232void ScriptedProcessPythonInterface::Terminate() {
233 PluginManager::UnregisterPlugin(CreateInstance);
static llvm::raw_ostream & error(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool Fail() const
Test for error condition.
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< Array > ArraySP
#define LLDB_INVALID_OFFSET
#define LLDB_INVALID_PROCESS_ID
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ProcessAttachInfo > ProcessAttachInfoSP
std::shared_ptr< lldb_private::ScriptedThreadInterface > ScriptedThreadInterfaceSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP