summaryrefslogtreecommitdiff
path: root/lldb/examples/python/cmdtemplate.py
AgeCommit message (Collapse)Author
2025-09-10Make flag-only options work in the ParsedCommand mode of adding commands ↵jimingham
(#157756) I neglected to add a test when I was writing tests for this, so of course it broke. This makes it work again and adds a test. rdar://159459160
2024-09-24Add the ability to define custom completers to the parsed_cmd template. ↵jimingham
(#109062) If your arguments or option values are of a type that naturally uses one of our common completion mechanisms, you will get completion for free. But if you have your own custom values or if you want to do fancy things like have `break set -s foo.dylib -n ba<TAB>` only complete on symbols in foo.dylib, you can use this new mechanism to achieve that.
2024-09-18Add docs and an example use of the scripted command get_flags API. (#109176)jimingham
The API is present, and we even have a test for it, but it isn't documented so no one probably knows you can set requirements for your scripted commands. This just adds docs and uses it appropriately in the `framestats` example command.
2024-07-03Add the ability for Script based commands to specify their "repeat command" ↵jimingham
(#94823) Among other things, returning an empty string as the repeat command disables auto-repeat, which can be useful for state-changing commands. There's one remaining refinement to this setup, which is that for parsed script commands, it should be possible to change an option value, or add a new option value that wasn't originally specified, then ask lldb "make this back into a command string". That would make doing fancy things with repeat commands easier. That capability isn't present in the lldb_private side either, however. So that's for a next iteration. I haven't added this to the docs on adding commands yet. I wanted to make sure this was an acceptable approach before I spend the time to do that.
2024-02-13Add the ability to define a Python based command that uses ↵jimingham
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.
2023-05-25[NFC][Py Reformat] Reformat python files in lldbJonas Devlieghere
This is an ongoing series of commits that are reformatting our Python code. Reformatting is done with `black` (23.1.0). If you end up having problems merging this commit because you have made changes to a python file, the best way to handle that is to run `git checkout --ours <yourfile>` and then reformat it with black. RFC: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style Differential revision: https://reviews.llvm.org/D151460
2023-01-12[lldb] Update custom commands to always be overrridenMed Ismail Bennani
This is a follow-up patch to 6f7835f309b9. As explained previously, when running from an IDE, it can happen that the IDE imports some lldb scripts by itself. If the user also tries to import these commands, lldb will show the following message: ``` error: cannot add command: user command exists and force replace not set ``` This message is confusing to the user, because it suggests that the command import failed and that the execution should stop. However, in this case, lldb will continue the execution with the command added previously by the user. To prevent that, this patch updates every first-party lldb-packaged custom commands to override commands that were pre-imported in lldb. Differential Revision: https://reviews.llvm.org/D140293 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2022-08-15[LLDB] Remove __future__ imports from examplesDavid Spickett
Not needed now that we require python 3. Reviewed By: kastiglione, JDevlieghere Differential Revision: https://reviews.llvm.org/D131772
2020-07-16Harmonize Python shebangserge-sans-paille
Differential Revision: https://reviews.llvm.org/D83857
2019-03-21Python 2/3 compatibility: from __future__ import print_functionSerge Guelton
Differential Revision: https://reviews.llvm.org/D59580 llvm-svn: 356695
2018-06-22Update cmdtemplate.py to use best pratices.Greg Clayton
Fixes include: - fix all lint errors - add code that will automatically register and LLDB command classes by detecting the classes and any classes that have a "register_lldb_command" function - automatically fill in the correct module name when registering commands - automatically fill in the class name when registering command llvm-svn: 335401
2017-10-31Modernize the example cmdtemplate.py.Jim Ingham
This version relies on a newer and more convenient way to use a class to implement a command. It has been in place since early 2015, so it should be pretty safe to use. llvm-svn: 317043
2016-09-06*** This commit represents a complete reformatting of the LLDB source codeKate Stone
*** to conform to clang-format’s LLVM style. This kind of mass change has *** two obvious implications: Firstly, merging this particular commit into a downstream fork may be a huge effort. Alternatively, it may be worth merging all changes up to this commit, performing the same reformatting operation locally, and then discarding the merge for this particular commit. The commands used to accomplish this reformatting were as follows (with current working directory as the root of the repository): find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} + find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ; The version of clang-format used was 3.9.0, and autopep8 was 1.2.4. Secondly, “blame” style tools will generally point to this commit instead of a meaningful prior commit. There are alternatives available that will attempt to look through this change and find the appropriate prior commit. YMMV. llvm-svn: 280751
2013-07-11Tweaks to the Python reference and example command to use the preferred ↵Enrico Granata
print style and the (finally available :-) SetError API llvm-svn: 186122
2013-05-09Providing a more interesting command template for LLDBEnrico Granata
This one actually exploits the SB API to obtain information about your inferior process llvm-svn: 181500
2013-02-25Being explicit about how ignoring optparse's exceptions is not a best principleEnrico Granata
llvm-svn: 176059
2013-02-21Mark the command as failed if parsing fails.Jim Ingham
llvm-svn: 175776
2012-09-13Modified the command template to include best practices.Greg Clayton
llvm-svn: 163773
2012-01-26Added a 'gdbremote' python module that adds two commands: start_gdb_log and ↵Greg Clayton
end_gdb_log. When this is imported into your lldb using the "command script import /path/to/gdbremote.py" these new commands are available within LLDB. 'start_gdb_log' will enable logging with timestamps for GDB remote packets, and 'stop_gdb_log' will then dump the details and also a lot of packet timing data. This allows us to accurately track what packets are taking up the most time when debugging (when using the ProcessGDBRemote debugging plug-in). Also udpated the comments at the top of the cmdtemplate.py to show how to correctly import the module from within LLDB. llvm-svn: 149030
2012-01-24Proof-reading the python docs.Jim Ingham
llvm-svn: 148768
2012-01-22Added a python FAQ page with detailed examples of how to add python functionsGreg Clayton
to breakpoints, creating new LLDB commands using python modules and also how to run scripts from the command line. llvm-svn: 148650