Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
17c0c4e
commit 8ab5c2d
Showing
4 changed files
with
53 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
lldb/packages/Python/lldbsuite/test/functionalities/command_script/decorated.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import print_function | ||
|
||
import lldb | ||
|
||
|
||
@lldb.command() | ||
def decorated1(debugger, args, exe_ctx, result, dict): | ||
""" | ||
Python command defined by @lldb.command | ||
""" | ||
print("hello from decorated1", file=result) | ||
|
||
|
||
@lldb.command(doc="Python command defined by @lldb.command") | ||
def decorated2(debugger, args, exe_ctx, result, dict): | ||
""" | ||
This docstring is overridden. | ||
""" | ||
print("hello from decorated2", file=result) | ||
|
||
|
||
@lldb.command() | ||
def decorated3(debugger, args, result, dict): | ||
""" | ||
Python command defined by @lldb.command | ||
""" | ||
print("hello from decorated3", file=result) | ||
|
||
|
||
@lldb.command("decorated4") | ||
def _decorated4(debugger, args, exe_ctx, result, dict): | ||
""" | ||
Python command defined by @lldb.command | ||
""" | ||
print("hello from decorated4", file=result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters