summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/scripts/Python/python-extensions.swig13
-rw-r--r--lldb/scripts/Python/python-wrapper.swig2
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp26
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h1
4 files changed, 36 insertions, 6 deletions
diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig
index 1e43e53a514..487bf1e3599 100644
--- a/lldb/scripts/Python/python-extensions.swig
+++ b/lldb/scripts/Python/python-extensions.swig
@@ -810,6 +810,7 @@
def command(*args, **kwargs):
import lldb
+ import inspect
"""A decorator function that registers an LLDB command line
command that is bound to the function it is attached to."""
class obj(object):
@@ -821,11 +822,15 @@ def command(*args, **kwargs):
command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name)
lldb.debugger.HandleCommand(command)
self.function = function
- def __call__(self, *args, **kwargs):
- self.function(*args, **kwargs)
+ def __call__(self, debugger, command, exe_ctx, result, dict):
+ if len(inspect.getargspec(self.function).args) == 5:
+ self.function(debugger, command, exe_ctx, result, dict)
+ else:
+ self.function(debugger, command, result, dict)
def callable(function):
"""Creates a callable object that gets used."""
- return obj(function, *args, **kwargs)
+ f = obj(function, *args, **kwargs)
+ return f.__call__
return callable
class declaration(object):
@@ -1129,4 +1134,4 @@ def is_numeric_type(basic_type):
#if basic_type == eBasicTypeOther:
return (False,False)
-%} \ No newline at end of file
+%}
diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig
index 5d7bfaa8943..a92102e3283 100644
--- a/lldb/scripts/Python/python-wrapper.swig
+++ b/lldb/scripts/Python/python-wrapper.swig
@@ -610,7 +610,7 @@ LLDBSwigPythonCallCommand
PythonObject exe_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(exe_ctx_sb));
PythonObject cmd_retobj_arg(PyRefType::Owned, SBTypeToSWIGWrapper(&cmd_retobj_sb));
- if (argc.count == 5 || argc.has_varargs)
+ if (argc.count == 5 || argc.is_bound_method || argc.has_varargs)
pfunc(debugger_arg, PythonString(args), exe_ctx_arg, cmd_retobj_arg, dict);
else
pfunc(debugger_arg, PythonString(args), cmd_retobj_arg, dict);
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 02228df5147..1fdf4c70a5d 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -1109,13 +1109,37 @@ PythonCallable::Reset(PyRefType type, PyObject *py_obj)
PythonCallable::ArgInfo
PythonCallable::GetNumArguments() const
{
- ArgInfo result = { 0, false, false };
+ ArgInfo result = { 0, false, false, false };
if (!IsValid())
return result;
PyObject *py_func_obj = m_py_obj;
if (PyMethod_Check(py_func_obj))
+ {
py_func_obj = PyMethod_GET_FUNCTION(py_func_obj);
+ PythonObject im_self = GetAttributeValue("im_self");
+ if (im_self.IsValid() && !im_self.IsNone())
+ result.is_bound_method = true;
+ }
+ else
+ {
+ // see if this is a callable object with an __call__ method
+ if (!PyFunction_Check(py_func_obj))
+ {
+ PythonObject __call__ = GetAttributeValue("__call__");
+ if (__call__.IsValid())
+ {
+ auto __callable__ = __call__.AsType<PythonCallable>();
+ if (__callable__.IsValid())
+ {
+ py_func_obj = PyMethod_GET_FUNCTION(__callable__.get());
+ PythonObject im_self = GetAttributeValue("im_self");
+ if (im_self.IsValid() && !im_self.IsNone())
+ result.is_bound_method = true;
+ }
+ }
+ }
+ }
if (!py_func_obj)
return result;
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 2bcb967cef6..78245a98d0b 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -502,6 +502,7 @@ class PythonCallable : public PythonObject
public:
struct ArgInfo {
size_t count;
+ bool is_bound_method : 1;
bool has_varargs : 1;
bool has_kwargs : 1;
};
OpenPOWER on IntegriCloud