[Lldb-commits] [lldb] r184274 - Added a new decorator function in the "lldb" module that can register a command automatically. We have just a few kinks to work out for the Xcode workflow and we will be ready to switch over to using this. To use this, you can decorate your python function as:
Greg Clayton
gclayton at apple.com
Tue Jun 18 18:38:02 PDT 2013
Author: gclayton
Date: Tue Jun 18 20:38:02 2013
New Revision: 184274
URL: http://llvm.org/viewvc/llvm-project?rev=184274&view=rev
Log:
Added a new decorator function in the "lldb" module that can register a command automatically. We have just a few kinks to work out for the Xcode workflow and we will be ready to switch over to using this. To use this, you can decorate your python function as:
@lldb.command("new_command", "Documentation string for new_command...")
def new_command(debugger, command, result, dict):
....
No more need to register your command in the __lldb_init_module function!
Modified:
lldb/trunk/scripts/Python/python-extensions.swig
Modified: lldb/trunk/scripts/Python/python-extensions.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-extensions.swig?rev=184274&r1=184273&r2=184274&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-extensions.swig (original)
+++ lldb/trunk/scripts/Python/python-extensions.swig Tue Jun 18 20:38:02 2013
@@ -758,6 +758,26 @@
%pythoncode %{
+def command(*args, **kwargs):
+ from lldb import debugger
+ """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)
+ debugger.HandleCommand(command)
+ self.function = function
+ def __call__(self, *args, **kwargs):
+ self.function(*args, **kwargs)
+ def callable(function):
+ """Creates a callable object that gets used."""
+ return obj(function, *args, **kwargs)
+ return callable
+
class declaration(object):
'''A class that represents a source declaration location with file, line and column.'''
def __init__(self, file, line, col):
More information about the lldb-commits
mailing list