summaryrefslogtreecommitdiffstats
path: root/lldb/scripts/Python
diff options
context:
space:
mode:
authorDave Lee <davelee.com@gmail.com>2018-07-04 16:11:43 +0000
committerDave Lee <davelee.com@gmail.com>2018-07-04 16:11:43 +0000
commit8ab5c2db8a7345143fc994718303fda2a63f90c3 (patch)
tree2b6e3a230d1890e63b9bb049a773854357749a75 /lldb/scripts/Python
parent17c0c4e7424187c50c3189566aa3432cee7cdc9a (diff)
downloadbcm5719-llvm-8ab5c2db8a7345143fc994718303fda2a63f90c3.tar.gz
bcm5719-llvm-8ab5c2db8a7345143fc994718303fda2a63f90c3.zip
Fix and simplify lldb.command decorator
Summary: This change fixes one issue with `lldb.command`, and also reduces the implementation. The fix: a command function's docstring was not shown when running `help <command_name>`. This is because the docstring attached the source function is not propagated to the decorated function (`f.__call__`). By returning the original function, the docstring will be properly displayed by `help`. Also with this change, the command name is assumed to be the function's name, but can still be explicitly defined as previously. Additionally, the implementation was updated to: * Remove inner class * Remove use of `inspect` module * Remove `*args` and `**kwargs` Reviewers: clayborg Reviewed By: clayborg Subscribers: keith, xiaobai, lldb-commits Differential Revision: https://reviews.llvm.org/D48658 llvm-svn: 336287
Diffstat (limited to 'lldb/scripts/Python')
-rw-r--r--lldb/scripts/Python/python-extensions.swig27
1 files changed, 8 insertions, 19 deletions
diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig
index d79917b9215..5543bee95d4 100644
--- a/lldb/scripts/Python/python-extensions.swig
+++ b/lldb/scripts/Python/python-extensions.swig
@@ -839,29 +839,18 @@
%pythoncode %{
-def command(*args, **kwargs):
+def command(command_name=None, doc=None):
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):
- """The object that tracks adding the command to LLDB one time and handles
- calling the function on subsequent calls."""
- def __init__(self, function, command_name, doc = None):
- if doc:
- function.__doc__ = doc
- command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name)
- lldb.debugger.HandleCommand(command)
- self.function = function
- 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."""
- f = obj(function, *args, **kwargs)
- return f.__call__
+ """Registers an lldb command for the decorated function."""
+ command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name or function.__name__)
+ lldb.debugger.HandleCommand(command)
+ if doc:
+ function.__doc__ = doc
+ return function
+
return callable
class declaration(object):
OpenPOWER on IntegriCloud