[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
Fri Apr 29 11:12:14 PDT 2022

This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa7470a1b313: Add a paragraph showing how to use container commands. (authored by jingham).

Changed prior to commit:

  rG LLVM Github Monorepo




Index: lldb/docs/use/python-reference.rst
--- lldb/docs/use/python-reference.rst
+++ lldb/docs/use/python-reference.rst
@@ -644,6 +644,51 @@
   -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.426128.patch
Type: text/x-patch
Size: 2263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220429/52567802/attachment.bin>

More information about the lldb-commits mailing list