summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ScriptInterpreter/Python
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2019-10-03 22:50:18 +0000
committerJim Ingham <jingham@apple.com>2019-10-03 22:50:18 +0000
commit27a14f19c810f494adddb8aaff960336ab4492e7 (patch)
treea7eae222175b77917ee9ccfd1b0f21555d7118f4 /lldb/source/Plugins/ScriptInterpreter/Python
parent145cdad11925194ec41949b5c8f0cb037f9e7941 (diff)
downloadbcm5719-llvm-27a14f19c810f494adddb8aaff960336ab4492e7.tar.gz
bcm5719-llvm-27a14f19c810f494adddb8aaff960336ab4492e7.zip
Pass an SBStructuredData to scripted ThreadPlans on use.
This will allow us to write reusable scripted ThreadPlans, since you can use key/value pairs with known keys in the plan to parametrize its behavior. Differential Revision: https://reviews.llvm.org/D68366 llvm-svn: 373675
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp17
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h4
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp6
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h1
4 files changed, 26 insertions, 2 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index fedd8f66a1f..1862bbd9298 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -887,6 +887,23 @@ void PythonCallable::Reset(PyRefType type, PyObject *py_obj) {
PythonObject::Reset(PyRefType::Borrowed, result.get());
}
+PythonCallable::ArgInfo PythonCallable::GetNumInitArguments() const {
+ ArgInfo result = {0, false, false, false};
+ if (!IsValid())
+ return result;
+ PyObject *py_func_obj = m_py_obj;
+ if (!PyClass_Check(m_py_obj))
+ return result;
+
+ PythonObject __init__ = GetAttributeValue("__init__");
+ if (__init__.IsValid() ) {
+ auto __init_callable__ = __init__.AsType<PythonCallable>();
+ if (__init_callable__.IsValid())
+ return __init_callable__.GetNumArguments();
+ }
+ return result;
+}
+
PythonCallable::ArgInfo PythonCallable::GetNumArguments() const {
ArgInfo result = {0, false, false, false};
if (!IsValid())
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 8fd2be1460f..9e4a120f2ae 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -438,6 +438,10 @@ public:
void Reset(PyRefType type, PyObject *py_obj) override;
ArgInfo GetNumArguments() const;
+
+ // If the callable is a Py_Class, then find the number of arguments
+ // of the __init__ method.
+ ArgInfo GetNumInitArguments() const;
PythonObject operator()();
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index dc13ed71c42..e5000bfd4ae 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -97,6 +97,7 @@ LLDBSwigPythonCreateCommandObject(const char *python_class_name,
extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan(
const char *python_class_name, const char *session_dictionary_name,
+ StructuredDataImpl *args_data,
std::string &error_string,
const lldb::ThreadPlanSP &thread_plan_sp);
@@ -1845,7 +1846,8 @@ StructuredData::DictionarySP ScriptInterpreterPythonImpl::OSPlugin_CreateThread(
}
StructuredData::ObjectSP ScriptInterpreterPythonImpl::CreateScriptedThreadPlan(
- const char *class_name, std::string &error_str,
+ const char *class_name, StructuredDataImpl *args_data,
+ std::string &error_str,
lldb::ThreadPlanSP thread_plan_sp) {
if (class_name == nullptr || class_name[0] == '\0')
return StructuredData::ObjectSP();
@@ -1868,7 +1870,7 @@ StructuredData::ObjectSP ScriptInterpreterPythonImpl::CreateScriptedThreadPlan(
Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN);
ret_val = LLDBSwigPythonCreateScriptedThreadPlan(
class_name, python_interpreter->m_dictionary_name.c_str(),
- error_str, thread_plan_sp);
+ args_data, error_str, thread_plan_sp);
if (!ret_val)
return {};
}
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
index 9cf32059a50..1b3a1bf0ba4 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -78,6 +78,7 @@ public:
StructuredData::ObjectSP
CreateScriptedThreadPlan(const char *class_name,
+ StructuredDataImpl *args_data,
std::string &error_str,
lldb::ThreadPlanSP thread_plan) override;
OpenPOWER on IntegriCloud