[Lldb-commits] [PATCH] D124028: Add some docs on how to use container commands to the python reference doc
Jim Ingham via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 19 11:34:40 PDT 2022
jingham created this revision.
jingham added a reviewer: JDevlieghere.
Herald added a project: All.
jingham requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
I added this feature a while back but didn't put an example in the python reference so people could actually find it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D124028
Files:
lldb/docs/use/python-reference.rst
Index: lldb/docs/use/python-reference.rst
===================================================================
--- lldb/docs/use/python-reference.rst
+++ lldb/docs/use/python-reference.rst
@@ -644,6 +644,49 @@
-rw-r--r--@ 1 someuser wheel 6148 Jan 19 17:27 .DS_Store
-rw------- 1 someuser wheel 7331 Jan 19 15:37 crash.log
+You can also make "container" commands to organize the commands you are adding to
+lldb. Most of the lldb built-in commands structure themselves this way, and using
+a tree structure has the benefit of leaving the one-word command space free for user
+aliases. It can also make it easier to find commands if you are adding more than
+a few of them. Here's a trivial example of adding two "utility" commands into a
+"my-utilities" container:
+
+::
+
+ #!/usr/bin/env python
+
+ import lldb
+
+ def first_utility(debugger, command, result, internal_dict):
+ print("I am the first utility")
+
+ def second_utility(debugger, command, result, internal_dict):
+ print("I am the second utility")
+
+ # And the initialization code to add your commands
+ def __lldb_init_module(debugger, internal_dict):
+ debugger.HandleCommand('command container add -h "A container for my utilities" my-utilities')
+ debugger.HandleCommand('command script add -f my_utilities.first_utility -h "My first utility" my-utilities first')
+ debugger.HandleCommand('command script add -f my_utilities.second_utility -h "My second utility" my-utilities second')
+ print('The "my-utilities" python command has been installed and its subcommands are ready for use.')
+
+Then your new commands are available under the my-utilities node:
+
+::
+ (lldb) help my-utilities
+ A container for my utilities
+
+ Syntax: my-utilities
+
+ The following subcommands are supported:
+
+ first -- My first utility Expects 'raw' input (see 'help raw-input'.)
+ second -- My second utility Expects 'raw' input (see 'help raw-input'.)
+
+ For more help on any particular subcommand, type 'help <command> <subcommand>'.
+ (lldb) my-utilities first
+ I am the first utility
+
A more interesting template has been created in the source repository that can
help you to create lldb command quickly:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124028.423691.patch
Type: text/x-patch
Size: 2259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220419/2930b224/attachment.bin>
More information about the lldb-commits
mailing list