aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Interpreter/CommandObject.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-29[LLDB] [NFC] - Remove duplicate #include headers from the files of lldb dir ↵Akash Agrawal1-1/+0
& few other files (#141478) A few files of lldb dir & few other files had duplicate headers included. This patch removes those redundancies. --------- Co-authored-by: Akash Agrawal <akashag@qti.qualcomm.com>
2025-05-04[lldb] Remove unused local variables (NFC) (#138457)Kazu Hirata1-3/+0
2025-01-31[lldb] Use llvm::Error instead of CommandReturnObject for error reporting ↵Jonas Devlieghere1-7/+14
(#125125) Use `llvm::Error` instead of `CommandReturnObject` for error reporting. The command return objects were populated with errors but never displayed. With this patch they're at least logged.
2025-01-30[lldb] Remove another unused CommandReturnObject variable (NFC)Jonas Devlieghere1-1/+0
2024-10-11Support inline diagnostics in CommandReturnObject (#110901)Adrian Prantl1-10/+1
and implement them for dwim-print (a.k.a. `p`) as an example. The next step will be to expose them as structured data in SBCommandReturnObject.
2024-09-05[lldb] Make conversions from llvm::Error explicit with Status::FromEr… ↵Adrian Prantl1-1/+1
(#107163) …ror() [NFC]
2024-07-31[lldb] Unify the way we get the Target in CommandObject (#101208)Jonas Devlieghere1-11/+17
Currently, CommandObjects are obtaining a target in a variety of ways. Often the command incorrectly operates on the selected target. As an example, when a breakpoint command is running, the current target is passed into the command but the target that hit the breakpoint is not the selected target. In other places we use the CommandObject's execution context, which is frozen during the execution of the command, and comes with its own limitations. Finally, we often want to fall back to the dummy target if no real target is available. Instead of having to guess how to get the target, this patch introduces one helper function in CommandObject to get the most relevant target. In order of priority, that's the target from the command object's execution context, from the interpreter's execution context, the selected target or the dummy target. rdar://110846511
2024-02-27Start to clean up the process of defining command arguments. (#83097)jimingham1-8/+31
Partly, there's just a lot of unnecessary boiler plate. It's also possible to define combinations of arguments that make no sense (e.g. eArgRepeatPlus followed by eArgRepeatPlain...) but these are never checked since we just push_back directly into the argument definitions. This commit is step 1 of this cleanup - do the obvious stuff. In it, all the simple homogenous argument lists and the breakpoint/watchpoint ID/Range types, are set with common functions. This is an NFC change, it just centralizes boiler plate. There's no checking yet because you can't get a single argument wrong. The end goal is that all argument definition goes through functions and m_arguments is hidden so that you can't define inconsistent argument sets.
2024-02-20Add the RegisterCompleter to eArgTypeRegisterName in g_argument_table (#82428)jimingham1-0/+37
This is a follow-on to: https://github.com/llvm/llvm-project/pull/82085 The completer for register names was missing from the argument table. I somehow missed that the only register completer test was x86_64, so that test broke. I added the completer in to the right slot in the argument table, and added a small completions test that just uses the alias register names. If we end up having a platform that doesn't define register names, we'll have to skip this test there, but it should add a sniff test for register completion that will run most everywhere.
2024-02-19Revert "Centralize the handling of completion for simple argument lists. ↵Shubham Sandeep Rastogi1-37/+0
(#82085)" This reverts commit 21631494b068d9364b8dc8f18e59adee9131a0a5. Reverted because of greendragon failure: ******************** TEST 'lldb-api :: functionalities/completion/TestCompletion.py' FAILED ******************** Script:
2024-02-19Centralize the handling of completion for simple argument lists. (#82085)jimingham1-0/+37
Most commands were adding argument completion handling by themselves, resulting in a lot of unnecessary boilerplate. In many cases, this could be done generically given the argument definition and the entries in the g_argument_table. I'm going to address this in a couple passes. In this first pass, I added handling of commands that have only one argument list, with one argument type, either single or repeated, and changed all the commands that are of this sort (and don't have other bits of business in their completers.) I also added some missing connections between arg types and completions to the table, and added a RemoteFilename and RemotePath to use in places where we were using the Remote completers. Those arguments used to say they were "files" but they were in fact remote files. I also added a module arg type to use where we were using the module completer. In that case, we should call the argument module.
2024-02-13Add the ability to define a Python based command that uses ↵jimingham1-0/+17
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.
2024-02-05Add commands frequency to statistics dump (#80375)jeffreytan811-0/+1
Adding command interpreter statistics into "statistics dump" command so that we can track the command usage frequency for telemetry purpose. This is useful to answer questions like what is the most frequently used lldb commands across all our users. --------- Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2023-10-25[lldb] Part 1 of 2 - Refactor `CommandObject::Execute(...)` return `void` ↵Pete Lawrence1-7/+5
(not `bool`) (#69989) [lldb] Part 1 of 2 - Refactor `CommandObject::Execute(...)` to return `void` instead of ~~`bool`~~ Justifications: - The code doesn't ultimately apply the `true`/`false` return values. - The methods already pass around a `CommandReturnObject`, typically with a `result` parameter. - Each command return object already contains: - A more precise status - The error code(s) that apply to that status Part 2 refactors the `CommandObject::DoExecute(...)` method. - See [https://github.com/llvm/llvm-project/pull/69991](https://github.com/llvm/llvm-project/pull/69991) rdar://117378957
2023-05-04[lldb] Move Core/FileSpecList -> Utility/FileSpecList (NFC)Jonas Devlieghere1-1/+1
There's no reason for FileSpecList to live in lldb/Core while FileSpec lives in lldb/Utility. Move FileSpecList next to FileSpec.
2023-03-24Fix backtick handling in parsed commands.Jim Ingham1-4/+8
https://reviews.llvm.org/D146779
2022-09-14Revert "Revert "Be more careful to maintain quoting information when parsing ↵Jim Ingham1-1/+1
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 Ingham1-1/+1
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 Ingham1-1/+1
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-24[LLDB] Clean up after command failsZequan Wu1-0/+1
`CommandObject::CheckRequirements()` requires m_exe_ctx being cleaned up. Differential Revision: https://reviews.llvm.org/D132397
2022-07-14[lldb] Print the enum values and their description in the help outputJonas Devlieghere1-1/+21
Print the enum values and their description in the help output for argument values. Until now, there was no way to get these values and their description. Example output: (lldb) help <description-verbosity> <description-verbosity> -- How verbose the output of 'po' should be. compact : Only show the description string full : Show the full output, including persistent variable's name and type Differential revision: https://reviews.llvm.org/D129707
2022-07-14[lldb] Refactor command option enum values (NFC)Jonas Devlieghere1-407/+9
Refactor the command option enum values and the command argument table to connect the two. This has two benefits: - We guarantee that two options that use the same argument type have the same accepted values. - We can print the enum values and their description in the help output. (D129707) Differential revision: https://reviews.llvm.org/D129703
2022-07-12[lldb] Make the g_arguments_data constexpr and fix the static assertJonas Devlieghere1-10/+11
This fixes the static assert that's meant to keep the g_arguments_data table in sync with the CommandArgumentType enumeration. Indeed, the assert didn't fire even though the current code is missing an entry. This patches fixes that as well. Differential revision: https://reviews.llvm.org/D129529
2022-06-27Have CommandObjectParsed check for "commands that take no arguments".Jim Ingham1-0/+9
This is currently being done in an ad hoc way, and so for some commands it isn't being checked. We have the info to make this check, since commands are supposed to add their arguments to the m_arguments field of the CommandObject. This change uses that info to check whether the command received arguments in error. A handful of commands weren't defining their argument types, I also had to fix them. And a bunch of commands were checking for arguments by hand, so I removed those checks in favor of the CommandObject one. That also meant I had to change some tests that were checking for the ad hoc error outputs. Differential Revision: https://reviews.llvm.org/D128453
2022-06-24[lldb] Add support for specifying a log handlerJonas Devlieghere1-1/+2
This patch adds a new flag to `log enable`, allowing the user to specify a custom log handler. In addition to the default (stream) handler, this allows using the circular log handler (which logs to a fixed size, in-memory circular buffer) as well as the system log handler (which logs to the operating system log). Differential revision: https://reviews.llvm.org/D128323
2022-05-16[lldb][NFC] Make cmd a reference in GenerateOptionUsageDavid Spickett1-3/+3
Nowhere in lldb do we call this with a null pointer. If we did, the first line of the function would fault anyway. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D125218
2021-11-26[lldb] Fix 'memory write' to not allow specifying values when writing file ↵Venkata Ramanaiah Nalamothu1-0/+3
contents Currently the 'memory write' command allows specifying the values when writing the file contents to memory but the values are actually ignored. This patch fixes that by erroring out when values are specified in such cases. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D114544
2021-10-18Add a "command container" hierarchy to allow users to add container nodes.Jim Ingham1-1/+1
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-06-25[lldb] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-4/+4
2021-06-23[lldb] Remove CommandReturnObject's SetError(StringRef)David Spickett1-1/+1
Replacing existing uses with AppendError. SetError is also part of the SBI API. This remains but instead of calling the underlying SetError it will call AppendError. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D104768
2021-06-22[lldb] Remove more redundant SetStatus(eReturnStatusFailed)David Spickett1-4/+0
Mostly by converting uses of GetErrorStream to AppendError, so that the call to SetStatus is implicit. Some remain where it isn't certain that you'll have a message to set, or you want the output to be on stdout. One place in CommandObjectWatchpoint previously didn't set the status to failed at all. However it's pretty obvious that it should do so. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D104697
2021-06-20Add a corefile style option to process save-core; skinny corefilesJason Molenda1-1/+2
Add a new feature to process save-core on Darwin systems -- for lldb to create a user process corefile with only the dirty (modified memory) pages included. All of the binaries that were used in the corefile are assumed to still exist on the system for the duration of the use of the corefile. A new --style option to process save-core is added, so a full corefile can be requested if portability across systems, or across time, is needed for this corefile. debugserver can now identify the dirty pages in a memory region when queried with qMemoryRegionInfo, and the size of vm pages is given in qHostInfo. Create a new "all image infos" LC_NOTE for Mach-O which allows us to describe all of the binaries that were loaded in the process -- load address, UUID, file path, segment load addresses, and optionally whether code from the binary was executing on any thread. The old "read dyld_all_image_infos and then the in-memory Mach-O load commands to get segment load addresses" no longer works when we only have dirty memory. rdar://69670807 Differential Revision: https://reviews.llvm.org/D88387
2021-05-26[lldb][NFC] Use C++ versions of the deprecated C standard library headersRaphael Isemann1-2/+2
The C headers are deprecated so as requested in D102845, this is replacing them all with their (not deprecated) C++ equivalent. Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D103084
2021-02-28[lldb/Interpreter][NFC] Remove explicit default initialization of members ↵Tatyana Krasnukha1-2/+1
and base classes According to clang-tidy's readability-redundant-member-init.
2021-02-28[lldb/Interpreter][NFC] Replace default constructors/destructors bodies with ↵Tatyana Krasnukha1-2/+0
"=default"
2020-11-18[trace][intel-pt] Scaffold the 'thread trace start | stop' commandsWalter Erquinigo1-0/+9
Depends on D90490. The stop command is simple and invokes the new method Trace::StopTracingThread(thread). On the other hand, the start command works by delegating its implementation to a CommandObject provided by the Trace plugin. This is necessary because each trace plugin needs different options for this command. There's even the chance that a Trace plugin can't support live tracing, but instead supports offline decoding and analysis, which means that "thread trace dump instructions" works but "thread trace start" doest. Because of this and a few other reasons, it's better to have each plugin provide this implementation. Besides, I'm using the GetSupportedTraceType method introduced in D90490 to quickly infer what's the trace plug-in that works for the current process. As an implementation note, I moved CommandObjectIterateOverThreads to its header so that I can use it from the IntelPT plugin. Besides, the actual start and stop logic for intel-pt is not part of this diff. Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D90729
2020-11-09[lldb] Make GetSelectedOrDummyTarget return the target by reference (NFC)Jonas Devlieghere1-2/+2
Return references from GetDummyTarget and GetSelectedOrDummyTarget. This matches how the APIs are already used in practice.
2020-08-24[lldb] type category name common completionGongyu Deng1-1/+1
1. Added a new common completion TypeCategoryNames to provide a list of category names for completion; 2. Applied the completion to these commands: type category delete/enable/disable/list/define; 3. Added a related test case; 4. Bound the completion to the arguments of the type 'eArgTypeName'. Reviewed By: teemperor, JDevlieghere Differential Revision: https://reviews.llvm.org/D84124
2020-08-24[lldb] common completion for process pids and process namesGongyu Deng1-2/+2
1. Added two common completions: `ProcessIDs` and `ProcessNames`, which are refactored from their original dedicated option completions; 2. Removed the dedicated option completion functions of `process attach` and `platform process attach`, so that they can use arg-type-bound common completions instead; 3. Bound `eArgTypePid` to the pid completion, `eArgTypeProcessName` to the process name completion in `CommandObject.cpp`; 4. Added a related test case. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D80700
2020-08-20[lldb] tab completion for breakpoint namesGongyu Deng1-1/+1
1. created a common completion for breakpoint names; 2. bound the breakpoint name common completion with eArgTypeBreakpointName; 3. implemented the dedicated completion for breakpoint read -N. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D80693
2020-08-11[lldb] tab completion for `target modules load -u`Gongyu Deng1-1/+2
1. Added a common completion ModuleUUIDs to provide a list of the UUIDs of modules for completion; 2. Added a new enumeration item eArgTypeModuleUUID to CommandArgumentType which is set as the option argument type of OptionGroupUUID; 3. Applied the module UUID completion to the argument of the type eArgTypeModuleUUID in lldb/source/Interpreter/CommandObject.cpp; 4. Added an related test case in lldb/test/API/functionalities/completion/TestCompletion.py.
2020-08-11[lldb] move the frame index completion into a common completion and apply it ↵Gongyu Deng1-1/+1
to `thread backtrace -s` Commands frame select and thread backtrace -s can be completed in the same way. Moved the dedicated completion of frame select into a common completion and apply it to the both commands, along with the test modified.
2020-08-11[lldb] type language common completionGongyu Deng1-1/+1
1. Added a new common completion TypeLanguages to provide a list of supporting languages; 2. Bound the completion to eArgTypeLanguage; 3. Added a related test case.
2020-08-11[lldb] tab completion for `disassemble -F`Gongyu Deng1-1/+1
1.Added a new common completion DisassemblyFlavors; 2. Bound DisassemblyFlavors to argument of type eArgTypeDisassemblyFlavor in CommandObject.cpp; 3. Added a related test case.
2020-07-20Add an option (-y) to "break set" and "source list" that uses the sameJim Ingham1-0/+1
file:line:column form that we use to print out locations. Since we print them this way it makes sense we also accept that form. Differential Revision: https://reviews.llvm.org/D83975
2020-06-15[lldb] Remove indentation before help output.Jonas Devlieghere1-4/+3
This patch remove the indentation before the command help output. Supposedly it was meant to be aligned with the different subcommands. Differential revision: https://reviews.llvm.org/D81783
2020-06-12[lldb] Remove unnecessary c_str() in OutputFormattedHelpText calls (NFC)Jonas Devlieghere1-4/+3
2020-06-09[lldb/Interpreter] Support color in CommandReturnObjectJonas Devlieghere1-1/+1
Color the error: and warning: part of the CommandReturnObject output, similar to how an error is printed from the driver when colors are enabled. Differential revision: https://reviews.llvm.org/D81058
2020-05-27[lldb] Tab completion for process plugin nameGongyu Deng1-1/+1
Summary: 1. Added tab completion to `process launch -p`, `process attach -P`, `process connect -p`; 2. Bound the plugin name common completion as the default completion for `eArgTypePlugin` arguments. Reviewers: teemperor, JDevlieghere Tags: #lldb Differential Revision: https://reviews.llvm.org/D79929
2020-05-27[lldb] Fix a potential bug that may cause assert failure in ↵Raphael Isemann1-2/+2
CommandObject::CheckRequirements Summary: `CommandObject::CheckRequirements` requires cleaning up `m_exe_ctx` between commands. Function `HandleOptionCompletion` returns without cleaning up `m_exe_ctx` could cause assert failure in later `CheckRequirements`. Reviewers: teemperor, JDevlieghere Reviewed By: teemperor Tags: #lldb Differential Revision: https://reviews.llvm.org/D80447