kastiglione created this revision.
kastiglione added reviewers: clayborg, granata.enrico.

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`.

Additionally, the implementation was updated to:

- Remove inner class
- Remove use of `inspect` module
- Remove `*args` and `**kwargs`


https://reviews.llvm.org/D48658

Files:
  scripts/Python/python-extensions.swig


Index: scripts/Python/python-extensions.swig
===================================================================
--- scripts/Python/python-extensions.swig
+++ scripts/Python/python-extensions.swig
@@ -839,29 +839,18 @@
 
 %pythoncode %{
 
-def command(*args, **kwargs):
+def command(command_name, 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__
+        command = "command script add -f %s.%s %s" % (function.__module__, 
function.__name__, command_name)
+        lldb.debugger.HandleCommand(command)
+        if doc:
+            function.__doc__ = doc
+        return function
+
     return callable
 
 class declaration(object):


Index: scripts/Python/python-extensions.swig
===================================================================
--- scripts/Python/python-extensions.swig
+++ scripts/Python/python-extensions.swig
@@ -839,29 +839,18 @@
 
 %pythoncode %{
 
-def command(*args, **kwargs):
+def command(command_name, 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__
+        command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name)
+        lldb.debugger.HandleCommand(command)
+        if doc:
+            function.__doc__ = doc
+        return function
+
     return callable
 
 class declaration(object):
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to