Skip to content

Commit aa7470a

Browse files
committed
Add a paragraph showing how to use container commands.
Differential Revision: https://reviews.llvm.org/D124028
1 parent f735b3a commit aa7470a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lldb/docs/use/python-reference.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,51 @@ Now we can load the module into LLDB and use it
644644
-rw-r--r--@ 1 someuser wheel 6148 Jan 19 17:27 .DS_Store
645645
-rw------- 1 someuser wheel 7331 Jan 19 15:37 crash.log
646646

647+
You can also make "container" commands to organize the commands you are adding to
648+
lldb. Most of the lldb built-in commands structure themselves this way, and using
649+
a tree structure has the benefit of leaving the one-word command space free for user
650+
aliases. It can also make it easier to find commands if you are adding more than
651+
a few of them. Here's a trivial example of adding two "utility" commands into a
652+
"my-utilities" container:
653+
654+
::
655+
656+
#!/usr/bin/env python
657+
658+
import lldb
659+
660+
def first_utility(debugger, command, result, internal_dict):
661+
print("I am the first utility")
662+
663+
def second_utility(debugger, command, result, internal_dict):
664+
print("I am the second utility")
665+
666+
# And the initialization code to add your commands
667+
def __lldb_init_module(debugger, internal_dict):
668+
debugger.HandleCommand('command container add -h "A container for my utilities" my-utilities')
669+
debugger.HandleCommand('command script add -f my_utilities.first_utility -h "My first utility" my-utilities first')
670+
debugger.HandleCommand('command script add -f my_utilities.second_utility -h "My second utility" my-utilities second')
671+
print('The "my-utilities" python command has been installed and its subcommands are ready for use.')
672+
673+
Then your new commands are available under the my-utilities node:
674+
675+
::
676+
677+
(lldb) help my-utilities
678+
A container for my utilities
679+
680+
Syntax: my-utilities
681+
682+
The following subcommands are supported:
683+
684+
first -- My first utility Expects 'raw' input (see 'help raw-input'.)
685+
second -- My second utility Expects 'raw' input (see 'help raw-input'.)
686+
687+
For more help on any particular subcommand, type 'help <command> <subcommand>'.
688+
(lldb) my-utilities first
689+
I am the first utility
690+
691+
647692
A more interesting template has been created in the source repository that can
648693
help you to create lldb command quickly:
649694

0 commit comments

Comments
 (0)