[Lldb-commits] [lldb] bdcad0a - convert LLDBSwigPythonCallTypeScript to ArgInfo::max_positional_args
Lawrence D'Anna via lldb-commits
lldb-commits at lists.llvm.org
Sat Oct 19 00:04:39 PDT 2019
Author: Lawrence D'Anna
Date: 2019-10-19T07:05:39Z
New Revision: bdcad0aca0a05145364ee153a8f54af4aea2c445
URL: https://github.com/llvm/llvm-project/commit/bdcad0aca0a05145364ee153a8f54af4aea2c445
DIFF: https://github.com/llvm/llvm-project/commit/bdcad0aca0a05145364ee153a8f54af4aea2c445.diff
LOG: convert LLDBSwigPythonCallTypeScript to ArgInfo::max_positional_args
Summary:
This patch converts another user of ArgInfo::count over to
use ArgInfo::max_positional_args instead. I also add a test
to make sure both documented signatures for python type formatters
work.
Reviewers: JDevlieghere, clayborg, labath, jingham
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D69153
llvm-svn: 375334
Added:
Modified:
lldb/packages/Python/lldbsuite/test/commands/expression/formatters/TestFormatters.py
lldb/packages/Python/lldbsuite/test/commands/expression/formatters/formatters.py
lldb/scripts/Python/python-wrapper.swig
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/commands/expression/formatters/TestFormatters.py b/lldb/packages/Python/lldbsuite/test/commands/expression/formatters/TestFormatters.py
index b13d6555f33b..011dabce6e9d 100644
--- a/lldb/packages/Python/lldbsuite/test/commands/expression/formatters/TestFormatters.py
+++ b/lldb/packages/Python/lldbsuite/test/commands/expression/formatters/TestFormatters.py
@@ -74,6 +74,21 @@ def cleanup():
# EXPR-TYPES-NEW-FOO-NEXT: }
# EXPR-TYPES-NEW-FOO-NEXT: }
+
+ self.runCmd("type summary add -F formatters.foo_SummaryProvider3 foo")
+ self.filecheck("expression foo1", __file__, '-check-prefix=EXPR-FOO1opts')
+ # EXPR-FOO1opts: (foo) $
+ # EXPR-FOO1opts-SAME: a = 12
+ # EXPR-FOO1opts-SAME: a_ptr = {{[0-9]+}} -> 13
+ # EXPR-FOO1opts-SAME: i = 24
+ # EXPR-FOO1opts-SAME: i_ptr = {{[0-9]+}} -> 25
+ # EXPR-FOO1opts-SAME: b_ref = {{[0-9]+}}
+ # EXPR-FOO1opts-SAME: h = 27
+ # EXPR-FOO1opts-SAME: k = 29
+ # EXPR-FOO1opts-SAME: WITH_OPTS
+
+ self.runCmd("type summary delete foo")
+
self.runCmd("type summary add -F formatters.foo_SummaryProvider foo")
self.expect("expression new int(12)",
diff --git a/lldb/packages/Python/lldbsuite/test/commands/expression/formatters/formatters.py b/lldb/packages/Python/lldbsuite/test/commands/expression/formatters/formatters.py
index dae84988af9e..ac2888bd203f 100644
--- a/lldb/packages/Python/lldbsuite/test/commands/expression/formatters/formatters.py
+++ b/lldb/packages/Python/lldbsuite/test/commands/expression/formatters/formatters.py
@@ -1,3 +1,5 @@
+import lldb
+
def foo_SummaryProvider(valobj, dict):
a = valobj.GetChildMemberWithName('a')
a_ptr = valobj.GetChildMemberWithName('a_ptr')
@@ -15,3 +17,8 @@ def foo_SummaryProvider(valobj, dict):
', i_ptr = ' + str(i_ptr.GetValueAsUnsigned(0)) + ' -> ' + str(i_ptr.Dereference().GetValueAsUnsigned(0)) + \
', b_ref = ' + str(b_ref.GetValueAsUnsigned(0)) + \
', h = ' + str(h.GetValueAsUnsigned(0)) + ' , k = ' + str(k.GetValueAsUnsigned(0))
+
+def foo_SummaryProvider3(valobj, dict, options):
+ if not isinstance(options, lldb.SBTypeSummaryOptions):
+ raise Exception()
+ return foo_SummaryProvider(valobj, dict) + ", WITH_OPTS"
\ No newline at end of file
diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig
index c50f9d1fab92..277b8657d344 100644
--- a/lldb/scripts/Python/python-wrapper.swig
+++ b/lldb/scripts/Python/python-wrapper.swig
@@ -163,14 +163,19 @@ LLDBSwigPythonCallTypeScript
}
PythonObject result;
- auto argc = pfunc.GetNumArguments();
- // if the third argument is supported, or varargs are allowed
+ auto argc = pfunc.GetArgInfo();
+ if (!argc) {
+ llvm::consumeError(argc.takeError());
+ return false;
+ }
+
PythonObject value_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_value));
PythonObject options_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_options));
- if (argc.count == 3 || argc.has_varargs)
- result = pfunc(value_arg,dict,options_arg);
- else
+
+ if (argc.get().max_positional_args < 3)
result = pfunc(value_arg,dict);
+ else
+ result = pfunc(value_arg,dict,options_arg);
retval = result.Str().GetString().str();
More information about the lldb-commits
mailing list