[all-commits] [llvm/llvm-project] a69ecb: Add the ability to define a Python based command t...

jimingham via All-commits all-commits at lists.llvm.org
Tue Feb 13 11:09:59 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a69ecb2420f644e31f18fcc61a07b3ca627e8939
      https://github.com/llvm/llvm-project/commit/a69ecb2420f644e31f18fcc61a07b3ca627e8939
  Author: jimingham <jingham at apple.com>
  Date:   2024-02-13 (Tue, 13 Feb 2024)

  Changed paths:
    M lldb/bindings/python/CMakeLists.txt
    M lldb/bindings/python/python-wrapper.swig
    M lldb/examples/python/cmdtemplate.py
    A lldb/examples/python/templates/parsed_cmd.py
    M lldb/include/lldb/Interpreter/CommandObject.h
    M lldb/include/lldb/Interpreter/ScriptInterpreter.h
    M lldb/source/Commands/CommandObjectCommands.cpp
    M lldb/source/Commands/Options.td
    M lldb/source/Interpreter/CommandObject.cpp
    M lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
    M lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
    M lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
    A lldb/test/API/commands/command/script/add/TestAddParsedCommand.py
    A lldb/test/API/commands/command/script/add/test_commands.py
    M lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

  Log Message:
  -----------
  Add the ability to define a Python based command that uses CommandObjectParsed (#70734)

This allows you to specify options and arguments and their definitions
and then have lldb handle the completions, help, etc. in the same way
that lldb does for its parsed commands internally.

This feature has some design considerations as well as the code, so I've
also set up an RFC, but I did this one first and will put the RFC
address in here once I've pushed it...

Note, the lldb "ParsedCommand interface" doesn't actually do all the
work that it should. For instance, saying the type of an option that has
a completer doesn't automatically hook up the completer, and ditto for
argument values. We also do almost no work to verify that the arguments
match their definition, or do auto-completion for them. This patch
allows you to make a command that's bug-for-bug compatible with built-in
ones, but I didn't want to stall it on getting the auto-command checking
to work all the way correctly.

As an overall design note, my primary goal here was to make an interface
that worked well in the script language. For that I needed, for
instance, to have a property-based way to get all the option values that
were specified. It was much more convenient to do that by making a
fairly bare-bones C interface to define the options and arguments of a
command, and set their values, and then wrap that in a Python class
(installed along with the other bits of the lldb python module) which
you can then derive from to make your new command. This approach will
also make it easier to experiment.

See the file test_commands.py in the test case for examples of how this
works.




More information about the All-commits mailing list