diff options
Diffstat (limited to 'lldb/source/Plugins')
5 files changed, 259 insertions, 1 deletions
diff --git a/lldb/source/Plugins/Process/Scripted/CMakeLists.txt b/lldb/source/Plugins/Process/Scripted/CMakeLists.txt new file mode 100644 index 000000000000..0a3b3bc538a3 --- /dev/null +++ b/lldb/source/Plugins/Process/Scripted/CMakeLists.txt @@ -0,0 +1,21 @@ +lldb_tablegen(ScriptedProcessOptions.inc -gen-lldb-option-defs + SOURCE ScriptedProcessOptions.td + TARGET LLDBPluginScriptedProcessOptionGen) + +add_lldb_library(lldbPluginScriptedProcess PLUGIN + ScriptedProcess.cpp + + LINK_LIBS + lldbCore + lldbTarget + lldbUtility + lldbPluginProcessUtility + LINK_COMPONENTS + BinaryFormat + Object + Support + ) + +add_dependencies(lldbPluginScriptedProcess + LLDBPluginScriptedProcessOptionGen +) diff --git a/lldb/source/Plugins/Process/Scripted/ScriptedProcessOptions.td b/lldb/source/Plugins/Process/Scripted/ScriptedProcessOptions.td new file mode 100644 index 000000000000..55ea06e6de65 --- /dev/null +++ b/lldb/source/Plugins/Process/Scripted/ScriptedProcessOptions.td @@ -0,0 +1,7 @@ +include "../../../Commands/OptionsBase.td" + +let Command = "process scripted load" in { + def scripted_process_shlib : Option<"shlib", "S">, Arg<"ShlibName">, + Completion<"Module">, + Desc<"Name of the Python module that holds the scripted porcess.">; +} diff --git a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp index 6f03825cd6cd..ae57051a60b0 100644 --- a/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp +++ b/lldb/source/Plugins/Process/mach-core/ProcessMachCore.cpp @@ -27,8 +27,8 @@ #include "lldb/Utility/Log.h" #include "lldb/Utility/State.h" -#include "ProcessMachCore.h" #include "Plugins/Process/Utility/StopInfoMachException.h" +#include "ProcessMachCore.h" #include "ThreadMachCore.h" // Needed for the plug-in names for the dynamic loaders. diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 6b53bd3a2edc..cc645edd4220 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -2148,6 +2148,198 @@ ScriptInterpreterPythonImpl::CreateScriptCommandObject(const char *class_name) { return StructuredData::GenericSP(new StructuredPythonObject(ret_val)); } +#pragma mark ScriptedProcessInterface + +// StructuredData::GenericSP +// ScriptInterpreterPythonImpl::ScriptedProcess_CreatePluginObject( +// const char +// *class_name, +// lldb::ProcessSP +// process_sp) { +// if (class_name == nullptr || class_name[0] == '\0') +// return StructuredData::GenericSP(); +// +// if (!process_sp) +// return StructuredData::GenericSP(); +// +// void *ret_val; +// +// { +// Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, +// Locker::FreeLock); +// ret_val = LLDBSWIGPythonCreateOSPlugin( +// class_name, +// m_dictionary_name.c_str(), +// process_sp); +// } +// +// return StructuredData::GenericSP(new StructuredPythonObject(ret_val)); +//} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_Create( + StructuredData::ObjectSP scripted_process_object_sp, lldb::pid_t pid, + lldb::addr_t context) { + Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); + + static char callee_name[] = "create_process"; + std::string param_format; + param_format += GetPythonValueFormatString(pid); + param_format += GetPythonValueFormatString(context); + + if (!scripted_process_object_sp) + return StructuredData::DictionarySP(); + + StructuredData::Generic *generic = scripted_process_object_sp->GetAsGeneric(); + if (!generic) + return nullptr; + + PythonObject implementor(PyRefType::Borrowed, + (PyObject *)generic->GetValue()); + + if (!implementor.IsAllocated()) + return StructuredData::DictionarySP(); + + PythonObject pmeth(PyRefType::Owned, + PyObject_GetAttrString(implementor.get(), callee_name)); + + if (PyErr_Occurred()) + PyErr_Clear(); + + if (!pmeth.IsAllocated()) + return StructuredData::DictionarySP(); + + if (PyCallable_Check(pmeth.get()) == 0) { + if (PyErr_Occurred()) + PyErr_Clear(); + return StructuredData::DictionarySP(); + } + + if (PyErr_Occurred()) + PyErr_Clear(); + + // right now we know this function exists and is callable.. + PythonObject py_return(PyRefType::Owned, + PyObject_CallMethod(implementor.get(), callee_name, + ¶m_format[0], pid, context)); + + // if it fails, print the error but otherwise go on + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } + + if (py_return.get()) { + PythonDictionary result_dict(PyRefType::Borrowed, py_return.get()); + return result_dict.CreateStructuredDictionary(); + } + return StructuredData::DictionarySP(); +} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_GetNumMemoryRegions( + StructuredData::ObjectSP scripted_process_object_sp) { + Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock); + + static char callee_name[] = "get_num_memory_regions"; + + if (!scripted_process_object_sp) + return StructuredData::DictionarySP(); + + StructuredData::Generic *generic = scripted_process_object_sp->GetAsGeneric(); + if (!generic) + return nullptr; + PythonObject implementor(PyRefType::Borrowed, + (PyObject *)generic->GetValue()); + + if (!implementor.IsAllocated()) + return StructuredData::DictionarySP(); + + PythonObject pmeth(PyRefType::Owned, + PyObject_GetAttrString(implementor.get(), callee_name)); + + if (PyErr_Occurred()) + PyErr_Clear(); + + if (!pmeth.IsAllocated()) + return StructuredData::DictionarySP(); + + if (PyCallable_Check(pmeth.get()) == 0) { + if (PyErr_Occurred()) + PyErr_Clear(); + return StructuredData::DictionarySP(); + } + + if (PyErr_Occurred()) + PyErr_Clear(); + + // right now we know this function exists and is callable.. + PythonObject py_return( + PyRefType::Owned, + PyObject_CallMethod(implementor.get(), callee_name, nullptr)); + + // if it fails, print the error but otherwise go on + if (PyErr_Occurred()) { + PyErr_Print(); + PyErr_Clear(); + } + + if (py_return.get()) { + PythonDictionary result(PyRefType::Borrowed, py_return.get()); + return result.CreateStructuredDictionary(); + } + return StructuredData::DictionarySP(); +} + +lldb::MemoryRegionInfoSP +ScriptInterpreterPythonImpl::ScriptedProcess_GetMemoryRegionAtIndex( + StructuredData::ObjectSP scripted_process_object_sp, size_t index) { + return nullptr; +} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_GetNumThreads( + StructuredData::ObjectSP scripted_process_object_sp) { + return nullptr; +} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_GetThreadAtIndex( + StructuredData::ObjectSP scripted_process_object_sp, size_t index) { + return nullptr; +} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_GetRegisterForThread( + StructuredData::ObjectSP scripted_process_object_sp) { + return nullptr; +} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_ReadMemoryAtAddress( + StructuredData::ObjectSP scripted_process_object_sp, lldb::addr_t address, + size_t size) { + return nullptr; +} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_GetLoadedImages( + StructuredData::ObjectSP scripted_process_object_sp) { + return nullptr; +} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_CanDebug( + StructuredData::ObjectSP scripted_process_object_sp) { + return nullptr; +} + +StructuredData::DictionarySP +ScriptInterpreterPythonImpl::ScriptedProcess_IsAlive( + StructuredData::ObjectSP scripted_process_object_sp) { + return nullptr; +} + bool ScriptInterpreterPythonImpl::GenerateTypeScriptFunction( const char *oneliner, std::string &output, const void *name_token) { StringList input; diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h index 45dad4217005..17a8fc5ca6d3 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -74,6 +74,44 @@ public: StructuredData::GenericSP CreateScriptCommandObject(const char *class_name) override; + StructuredData::DictionarySP ScriptedProcess_CreatePluginObject( + StructuredData::ObjectSP scripted_process_object_sp, lldb::pid_t pid, + lldb::addr_t context); + + StructuredData::DictionarySP + ScriptedProcess_Create(StructuredData::ObjectSP scripted_process_object_sp, + lldb::pid_t pid, lldb::addr_t context) override; + + StructuredData::DictionarySP ScriptedProcess_GetNumMemoryRegions( + StructuredData::ObjectSP scripted_process_object_sp) override; + + lldb::MemoryRegionInfoSP ScriptedProcess_GetMemoryRegionAtIndex( + StructuredData::ObjectSP scripted_process_object_sp, + size_t index) override; + + StructuredData::DictionarySP ScriptedProcess_GetNumThreads( + StructuredData::ObjectSP scripted_process_object_sp) override; + + StructuredData::DictionarySP ScriptedProcess_GetThreadAtIndex( + StructuredData::ObjectSP scripted_process_object_sp, + size_t index) override; + + StructuredData::DictionarySP ScriptedProcess_GetRegisterForThread( + StructuredData::ObjectSP scripted_process_object_sp) override; + + StructuredData::DictionarySP ScriptedProcess_ReadMemoryAtAddress( + StructuredData::ObjectSP scripted_process_object_sp, lldb::addr_t address, + size_t size) override; + + StructuredData::DictionarySP ScriptedProcess_GetLoadedImages( + StructuredData::ObjectSP scripted_process_object_sp) override; + + StructuredData::DictionarySP ScriptedProcess_CanDebug( + StructuredData::ObjectSP scripted_process_object_sp) override; + + StructuredData::DictionarySP ScriptedProcess_IsAlive( + StructuredData::ObjectSP scripted_process_object_sp) override; + StructuredData::ObjectSP CreateScriptedThreadPlan(const char *class_name, StructuredDataImpl *args_data, |