summaryrefslogtreecommitdiff
path: root/lldb/test/API/commands/command
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
2025-09-04[lldb] Correct style of error messages (#156774)Jonas Devlieghere
The LLVM Style Guide says the following about error and warning messages [1]: > [T]o match error message styles commonly produced by other tools, > start the first sentence with a lowercase letter, and finish the last > sentence without a period, if it would end in one otherwise. I often provide this feedback during code review, but we still have a bunch of places where we have inconsistent error message, which bothers me as a user. This PR identifies a handful of those places and updates the messages to be consistent. [1] https://llvm.org/docs/CodingStandards.html#error-and-warning-messages
2025-06-26[lldb][test] Remove debug code from TestCommandScriptAlias.pyDavid Spickett
Also fixes our Windows on Arm bot.
2025-06-25[lldb] Fix qEcho message handling. (#145675)eleviant
This fixes issues found in e066f35c6981c720e3a7e5883efc40c861b3b7, which was later reverted. The problem was with "k" message which was sent with sync_on_timeout flag set to true, so lldb was waiting for response, which is currently not being sent by lldb-server. Not waiting for response at all seems to be not a solution, because on MAC OS X lldb waits for response from "k" to gracefully kill inferior.
2025-05-28[lldb] Run TestFrameLanguageCommands.py only on Darwin (#141866)Dave Lee
Tests using ObjC do not readily run on Linux.
2025-05-28[lldb] Fix TestFrameLanguageCommands.py build (#141829)Dave Lee
The use of `-lobjc` resulted in this test failing to build on Linux. The flag is not necessary, this removes the flag with the expectation it will fix the test on Linux.
2025-05-28[lldb] Expose language plugin commands based based on language of current ↵Dave Lee
frame (#136766) Use the current frame's language to lookup commands provided by language plugins. This means commands like `language {objc,cplusplus} <command>` can be used directly, without using the `language <lang>` prefix. For example, when stopped on a C++ frame, `demangle _Z1fv` will run `language cplusplus demangle _Z1fv`. rdar://149882520
2025-02-28[lldb] fix(lldb/**.py): fix invalid escape sequences (#94034)Eisuke Kawashima
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
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-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-06-26[lldb] fix(lldb/**.py): fix comparison to True/False (#94039)Eisuke Kawashima
from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations): > Comparisons to singletons like None should always be done with is or is not, never the equality operators. Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
2024-02-28Fix interactive use of "command script add". (#83350)jimingham
There was a think-o in a previous commit that made us only able to define 1 line commands when using command script add interactively. There was also no test for this feature, so I fixed the think-o and added a test.
2024-02-15[lldb] Fix Python test formatting (NFC)Jonas Devlieghere
2024-02-13Move the parsed_cmd conversion def's to module level functions.Jim Ingham
Python3.9 does not allow you to put a reference to a class staticmethod in a table and call it from there. Python3.10 and following do allow this, but we still support 3.9. staticmethod was slightly cleaner, but this will do.
2024-02-13Temporarily skip this test for Python 3.9.Jim Ingham
When the parsed command python code is run on 3.9, I get: File ".../lib/python3.9/site-packages/lldb/plugins/parsed_cmd.py", line 124, in translate_value return cls.translators[value_type](value) TypeError: 'staticmethod' object is not callable But this works correctly in Python 3.10 on macOS and Linux. I'm guessing something changed between those versions, and I'll have to do something to work around the difference. But I'm going to skip the test on 3.9 while I figure that out.
2024-02-13Used std::vector::reserve when I meant std::vector::resize.Jim Ingham
The Linux std has more asserts enabled by default, so it complained, even though this worked on Darwin...
2024-02-13Temporarily disable the TestAddParsedCommand.py while I figure outJim Ingham
why it's crashing on the x86_64 Debian Linux worker.
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-12-21[lldb] Add actionable feedback when overwriting a command fails (#76030)Felipe de Azevedo Piovezan
If adding a user commands fails because a command with the same name already exists, we only say that "force replace is not set" without telling the user _how_ to set it. There are two ways to do so; this commit changes the error message to mention both.
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-05-08[lldb] Prevent mutation of CommandAlias::GetOptionArgumentsDave Lee
Fix a mutation of `CommandAlias::m_option_args_sp`, which resulted in cases where aliases would fail to run on second, and subsequent times. For example, an alias such as: ``` command alias p1 p 1 ``` When run the second time, the following error would be reported to the user: ``` error: expression failed to parse: error: <user expression 1>:1:1: expression is not assignable -- 1 ^ ~ ``` To fix this, `CommandAlias::Desugar` now constructs options to a freshly constructed vector, rather than by appending to the results of `GetOptionArguments`. rdar://107770836 Differential Revision: https://reviews.llvm.org/D150078
2023-03-24Don't expect what newlines look like - never works on Windows.Jim Ingham
2023-03-24Fix backtick handling in parsed commands.Jim Ingham
https://reviews.llvm.org/D146779
2023-02-28Fix typos in the test command for D144929Jim Ingham
2023-02-28Add SBCommandInterpreter::UserCommandExists parallel to CommandExists.Jim Ingham
The latter only checks built-in commands. I also added some docs to make the distinction clear and a test. Differential Revision: https://reviews.llvm.org/D144929
2023-02-14Report a useful error when someone passes an incorrect python class name.Jim Ingham
2022-11-09Handle aliasing a non-top-level command.Jim Ingham
This didn't work previously because we had to check whether the incoming command was an alias command, but if it wasn't we still used the result of that lookup - which was by the command's node name. That fails for non-top-level commands. In this case, the resolution is pretty simple since we already have the node's CommandObject, so all we needed to do was turn it into a shared pointer, for which I added enable_shared_from_this to the CommandObject. Differential Revision: https://reviews.llvm.org/D137662
2022-09-14Revert "Revert "Be more careful to maintain quoting information when parsing ↵Jim Ingham
commands."" This reverts commit ac05bc0524c66c74278b26742896a4c634c034cf. I had incorrectly removed one set of checks in the option handling in Options::ParseAlias because I couldn't see what it is for. It was a bit obscure, but it handled the case where you pass "-something=other --" as the input_line, which caused the built-in "run" alias not to return the right value for IsDashDashCommand, causing TestHelp.py to fail.
2022-09-13Revert "Be more careful to maintain quoting information when parsing commands."Jim Ingham
This reverts commit 6c089b2af5d8d98f66b27b67f70958f520820a76. This was causing the test test_help_run_hides_options from TestHelp.py to fail on Linux and Windows (but the test succeeds on macOS). The decision to print option information is determined by CommandObjectAlias::IsDashDashCommand which was changed, but only by replacing an inline string constant with a const char * CommandInterpreter::g_argument which has the same string value. I can't see why this would fail, I'll have to spin up a vm to see if I can repo there.
2022-09-13Be more careful to maintain quoting information when parsing commands.Jim Ingham
This is particularly a problem for alias construction, where you might want to have a backtick surrounded option in the alias. Before this patch: command alias expression -Z \`argc\` -- argv for instance would be rendered as: expression -Z argc -- argv and would fail to work. Differential Revision: https://reviews.llvm.org/D133045
2022-08-15[LLDB] Remove __future__ imports from testsDavid Spickett
Not needed now that we require python 3. Reviewed By: kastiglione, JDevlieghere Differential Revision: https://reviews.llvm.org/D131761
2022-08-11[lldb] Remove uses of six module (NFC)Dave Lee
With lldb (& llvm) requiring Python 3.6+, use of the `six` module can be removed. Differential Revision: https://reviews.llvm.org/D131304
2022-07-18When the module path for `command script import` is invalid, echo the path.Jim Ingham
We were just emitting "invalid module" w/o saying which module. That's not particularly helpful. Differential Revision: https://reviews.llvm.org/D129338
2022-06-30Fix TestCommandScript.py for Arm/WindowsMuhammad Omair Javaid
TestCommandScript.py fails on Arm/Windows due following issues: https://llvm.org/pr56288 https://llvm.org/pr56292 LLDB fails to skip prologue and also step over library function or nodebug functions fails due to PDB/DWARF mismatch. This patch replace function breakpoint with line breakpoint so that we can expect LLDB to stop on desired line. Also replace dwarf with PDB debug info for this test only.
2022-06-17[lldb][tests] Automatically call compute_mydir (NFC)Dave Lee
Eliminate boilerplate of having each test manually assign to `mydir` by calling `compute_mydir` in lldbtest.py. Differential Revision: https://reviews.llvm.org/D128077
2022-04-05Fix a mistyping introduced with the new container command.Jim Ingham
I also added a call to help in the test which was crashing before the test, and not after.
2022-03-31Add a setting to not require --overwrite to overwrite commands.Jim Ingham
Protecting against accidental overwriting of commands is good, but having to pass a flag to overwrite the command when developing your commands is pretty annoying. This adds a setting to defeat the protection so you can do this once at the start of your session and not have to worry about it again. Differential Revision: https://reviews.llvm.org/D122680
2022-01-21[lldb] Allow aliases to aliases of raw input commandsDave Lee
Allow users to create aliases for aliases to raw input commands. That probably sounds convoluted, so here's an example: ``` command alias some-setup env SOMEVAR=SOMEVALUE ``` This an alias based on `env`, which itself is an alias for `_regex-env`. `_regex-env` is a `command regex` command, which takes raw input. The above `some-setup` alias fails with: ``` error: Unable to create requested alias. ``` This change allows such aliases to be created. lldb already supports aliases to aliases for parsed commands. Differential Revision: https://reviews.llvm.org/D117259
2022-01-09[lldb] Compute fully qualified command names in FindCommandsForAproposDave Lee
Fixes incomplete command names in `apropos` results. The full command names given by `apropos` have come from command name string literals given to `CommandObject` constructors. For most commands, this has been accurate, but some commands have incorrect strings. This results in `apropos` output that doesn't tell the user the full command name they might want learn more about. These strings can be fixed. There's a seperate issue that can't be fixed as easily: plugin commands. With the way they're implemented, plugin commands have to exclude the root command from their command name string. To illustrate, the `language objc` subcommand has to set its command name string to "objc", which results in apropos printing results as `objc ...` instead of `language objc ...`. To fix both of these issues, this commit changes `FindCommandsForApropos` to derive the fully qualified command name using the keys of subcommand maps. Differential Revision: https://reviews.llvm.org/D116491 (cherry picked from commit b3bfd595a548cd85b12e4e83729436cb73b26f29)
2022-01-04[lldb/python] Fix dangling Event and CommandReturnObject referencesPavel Labath
Unlike the rest of our SB objects, SBEvent and SBCommandReturnObject have the ability to hold non-owning pointers to their non-SB counterparts. This makes it hard to ensure the SB objects do not become dangling once their backing object goes away. While we could make these two objects behave like others, that would require plubming even more shared pointers through our internal code (Event objects are mostly prepared for it, CommandReturnObject are not). Doing so seems unnecessarily disruptive, given that (unlike for some of the other objects) I don't see any good reason why would someone want to hold onto these objects after the function terminates. For that reason, this patch implements a different approach -- the SB objects will still hold non-owning pointers, but they will be reset to the empty/default state as soon as the function terminates. This python code will not crash if the user decides to store these objects -- but the objects themselves will be useless/empty. Differential Revision: https://reviews.llvm.org/D116162
2021-12-20[lldb/python] Fix (some) dangling pointers in our glue codePavel Labath
This starts to fix the other half of the lifetime problems in this code -- dangling references. SB objects created on the stack will go away when the function returns, which is a problem if the python code they were meant for stashes a reference to them somewhere. Most of the time this goes by unnoticed, as the code rarely has a reason to store these, but in case it does, we shouldn't respond by crashing. This patch fixes the management for a couple of SB objects (Debugger, Frame, Thread). The SB objects are now created on the heap, and their ownership is immediately passed on to SWIG, which will ensure they are destroyed when the last python reference goes away. I will handle the other objects in separate patches. I include one test which demonstrates the lifetime issue for SBDebugger. Strictly speaking, one should create a test case for each of these objects and each of the contexts they are being used. That would require figuring out how to persist (and later access) each of these objects. Some of those may involve a lot of hoop-jumping (we can run python code from within a frame-format string). I don't think that is necessary/worth it since the new wrapper functions make it very hard to get this wrong. Differential Revision: https://reviews.llvm.org/D115925
2021-11-17[lldb/test] Added lldbutil function to test a breakpointSYNOPSYS\georgiev
Testing the breakpoint itself rather than the lldb string. Differential Revision: https://reviews.llvm.org/D111899
2021-10-18Add a "command container" hierarchy to allow users to add container nodes.Jim Ingham
The point is to allow users with a related set of script based commands to organize their commands in a hierarchy in the command set, rather than having to have only top-level commands. Differential Revision: https://reviews.llvm.org/D110298
2021-09-30[lldb] Remove support for replaying the test suite from a reproducerJonas Devlieghere
This patch removes the infrastructure to replay the test suite from a reproducer, as well as the modifications made to the individual tests.
2021-09-29Add the --relative-to-command-file to "command source" so you canJim Ingham
have linked command files in a source tree and get to them all from one main command file. Differential Revision: https://reviews.llvm.org/D110601
2021-07-27Fix a thinko in the parsing of substitutions in CommandObjectRegexCommand.Jim Ingham
The old code incorrectly calculated the start position for the search for the third (and subsequent) instance of a particular substitution pattern (e.g. %1). I also added a few test cases for this parsing covering this failure.
2020-11-10[lldb] [test] Rename '.categories' to 'categories'Michał Górny
Make category-specifying files visible. There is really no good reason to keep them hidden, and having them visible increases the chances that someone will actually spot them. Differential Revision: https://reviews.llvm.org/D91065
2020-07-23[lldb/interpreter] Move the history subcommand to session (NFCI)Med Ismail Bennani
This patch moves the `history` subcommand from the `command` to `session` command. I think it makes more sense to have it there because as the `command` usage suggests, it should be used to manage custom LLDB commands. However, `history` is essentially tied to a debugging session and holds all the commands (not specifically custom ones). This also makes it more discoverable by adding an alias for it (mimicking the shell builtin). Differential Revision: https://reviews.llvm.org/D84307 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-05-27[lldb/Reproducers] Differentiate active and passive replay unexpected packet.Jonas Devlieghere
2020-04-21[lldb/Test] Add skipIfReproducer for tests that diverge during replayJonas Devlieghere
Add the skipIfReproducer decorator to the remaining tests that fail to replay because the GDB remote packets diverge during replay. This is *not* expected and should be fixed, but figuring out exactly what caused the divergence has proven pretty difficult to track down. I've marked these tests as skipped for now so we can get clean results and detect new regressions. I have no evidence to believe that these failures have the same root cause, so I've not assigned them a PR.