aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Interpreter/CommandInterpreter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-12-12[lldb] Make CommandInterpreter's execution context the same as debugger's one.Tatyana Krasnukha1-68/+68
Currently, the interpreter's context is not updated until a command is executed. This has resulted in the behavior of SB-interface functions and some commands depends on previous user actions. The interpreter's context can stay uninitialized, point to a currently selected target, or point to one of previously selected targets. This patch removes any usages of CommandInterpreter::UpdateExecutionContext. CommandInterpreter::HandleCommand* functions still may override context temporarily, but now they always restore it before exiting. CommandInterpreter saves overriden contexts to the stack, that makes nesting commands possible. Added test reproduces one of the issues. Without this fix, the last assertion fails because interpreter's execution context is empty until running "target list", so, the value of the global property was updated instead of process's local instance. Differential Revision: https://reviews.llvm.org/D92164
2020-11-09[lldb] Make GetSelectedOrDummyTarget return the target by reference (NFC)Jonas Devlieghere1-8/+4
Return references from GetDummyTarget and GetSelectedOrDummyTarget. This matches how the APIs are already used in practice.
2020-10-29Mark the execution of stop-hooks as non-interactive.Jim Ingham1-0/+2
The intention is not to allow stop-hook commands to query the user, so this is correct. It also works around a deadlock in switching to the Python Session to execute python based commands in the stop hook when the Debugger stdin is backed by a FILE *. Differential Revision: https://reviews.llvm.org/D90332
2020-10-27[lldb] Support Python imports relative the to the current file being sourcedJonas Devlieghere1-0/+10
Make it possible to use a relative path in command script import to the location of the file being sourced. This allows the user to put Python scripts next to LLDB command files and importing them without having to specify an absolute path. To enable this behavior pass `-c` to `command script import`. The argument can only be used when sourcing the command from a file. rdar://68310384 Differential revision: https://reviews.llvm.org/D89334
2020-09-21Add a "Trace" plug-in to LLDB to add process trace support in stages.Walter Erquinigo1-0/+2
This is the first in a series of patches that will adds a new processor trace plug-in to LLDB. The idea for this first patch to to add the plug-in interface with simple commands for the trace files that can "load" and "dump" the trace information. We can test the functionality and ensure people are happy with the way things are done and how things are organized before moving on to adding more functionality. Processor trace information can be view in a few different ways: - post mortem where a trace is saved off that can be viewed later in the debugger - gathered while a process is running and allow the user to step back in time (with no variables, memory or registers) to see how each thread arrived at where it is currently stopped. This patch attempts to start with the first solution of loading a trace file after the fact. The idea is that we will use a JSON file to load the trace information. JSON allows us to specify information about the trace like: - plug-in name in LLDB - path to trace file - shared library load information so we can re-create a target and symbolicate the information in the trace - any other info that the trace plug-in will need to be able to successfully parse the trace information - cpu type - version info - ??? A new "trace" command was added at the top level of the LLDB commmands: - "trace load" - "trace dump" I did this because if we load trace information we don't need to have a process and we might end up creating a new target for the trace information that will become active. If anyone has any input on where this would be better suited, please let me know. Walter Erquinigo will end up filling in the Intel PT specific plug-in so that it works and is tested once we can agree that the direction of this patch is the correct one, so please feel free to chime in with ideas on comments! Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D85705
2020-09-03[lldb/Interpreter] Fix language detection for the REPL InitFileMed Ismail Bennani1-10/+8
Previously, before loading the REPL language-specific init file, lldb checked the selected target language in which case it returned an unknown language type with the REPL target. Instead, the patch calls `Language::GetLanguagesSupportingREPLs` and look for the first element of that set. In case lldb was not configured with a REPL language, then, it will just stop sourcing the REPL init file and fallback to the original logic (continuing with the default init file). rdar://65836048 Differential Revision: https://reviews.llvm.org/D87076 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-09-01[lldb] Move ScriptCommand and RegexCommand under Commands (NFC)Jonas Devlieghere1-3/+2
Move the CommandObjectScript and CommandObjectRegexCommand under Commands where all the other CommandObject implementations live. Although neither implementations currently use the TableGen-generated CommandOptions.inc, this move would have been necessary anyway if they were to in the future.
2020-09-02[lldb/interpreter] Improve REPL init file compatibilityMed Ismail Bennani1-7/+7
This patch changes the command interpreter sourcing logic for the REPL init file. Instead of looking for a arbitrary file name, it standardizes the REPL init file name to match to following scheme: `.lldbinit-<language>-repl` This will make the naming more homogenous and the sourcing logic future-proof. rdar://65836048 Differential Revision: https://reviews.llvm.org/D86987 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-08-22[lldb] Extract reproducer providers & co into their own header.Jonas Devlieghere1-0/+1
Extract all the provider related logic from Reproducer.h and move it into its own header ReproducerProvider.h. These classes are seeing most of the development these days and this reorganization reduces incremental compilation from ~520 to ~110 files when making changes to the new header.
2020-08-20[lldb] Provide GetHomeDirectory wrapper in Host::FileSystem (NFC)Jonas Devlieghere1-2/+2
Provider a wrapper around llvm::sys::path::home_directory in the FileSystem class. This will make it possible for the reproducers to intercept the call in a central place.
2020-08-20[lldb/interpreter] Add REPL-specific init fileMed Ismail Bennani1-3/+31
This patch adds the infrastructure to have language specific REPL init files. It's the foundation work to a following patch that will introduce Swift REPL init file. When lldb is launched with the `--repl` option, it will look for a REPL init file in the home directory and source it. This overrides the default `~/.lldbinit`, which content might make the REPL behave unexpectedly. If the REPL init file doesn't exists, lldb will fall back to the default init file. rdar://65836048 Differential Revision: https://reviews.llvm.org/D86242 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-08-14[lldb] Display autosuggestion part in gray if there is one possible suggestionShu Anzai1-0/+13
This is relanding D81001. The patch originally failed as on newer editline versions it seems CC_REFRESH will move the cursor to the start of the line via \r and then back to the original position. On older editline versions like the one used by default on macOS, CC_REFRESH doesn't move the cursor at all. As the patch changed the way we handle tab completion (previously we did REDISPLAY but now we're doing CC_REFRESH), this caused a few completion tests to receive this unexpected cursor movement in the output stream. This patch updates those tests to also accept output that contains the specific cursor movement commands (\r and then \x1b[XC). lldbpexpect.py received an utility method for generating the cursor movement escape sequence. Original summary: I implemented autosuggestion if there is one possible suggestion. I set the keybinds for every character. When a character is typed, Editline::TypedCharacter is called. Then, autosuggestion part is displayed in gray, and you can actually input by typing C-k. Editline::Autosuggest is a function for finding completion, and it is like Editline::TabCommand now, but I will add more features to it. Testing does not work well in my environment, so I can't confirm that it goes well, sorry. I am dealing with it now. Reviewed By: teemperor, JDevlieghere, #lldb Differential Revision: https://reviews.llvm.org/D81001
2020-08-12Revert "[lldb] Display autosuggestion part in gray if there is one possible ↵Raphael Isemann1-13/+0
suggestion" This reverts commit 246afe0cd17fce935a01171f3cca548e02523e5c. This broke the following tests on Linux it seems: lldb-api :: commands/expression/multiline-completion/TestMultilineCompletion.py lldb-api :: iohandler/completion/TestIOHandlerCompletion.py
2020-08-12[lldb] Display autosuggestion part in gray if there is one possible suggestionShu Anzai1-0/+13
I implemented autosuggestion if there is one possible suggestion. I set the keybinds for every character. When a character is typed, Editline::TypedCharacter is called. Then, autosuggestion part is displayed in gray, and you can actually input by typing C-k. Editline::Autosuggest is a function for finding completion, and it is like Editline::TabCommand now, but I will add more features to it. Testing does not work well in my environment, so I can't confirm that it goes well, sorry. I am dealing with it now. Reviewed By: teemperor, JDevlieghere, #lldb Differential Revision: https://reviews.llvm.org/D81001
2020-07-27[lldb][NFC] Use a StringRef for AddRegexCommand::AddRegexCommand parametersRaphael Isemann1-8/+3
Summary: This way we can get rid of this 1024 char buffer workaround. Reviewers: #lldb, labath Reviewed By: labath Subscribers: JDevlieghere Differential Revision: https://reviews.llvm.org/D84528
2020-07-27[lldb] Modernize away some snprintf callsRaphael Isemann1-8/+2
Reviewers: #lldb, JDevlieghere Reviewed By: #lldb, JDevlieghere Subscribers: JDevlieghere Differential Revision: https://reviews.llvm.org/D84530
2020-07-23[lldb/interpreter] Move the history subcommand to session (NFCI)Med Ismail Bennani1-0/+5
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-07-22[lldb] Cleanup CommandObject registration (NFC)Jonas Devlieghere1-45/+30
- Remove the spurious argument to `CommandObjectScript`. - Use make_shared instead of bare `new`. - Move code duplication behind a macro. Differential revision: https://reviews.llvm.org/D84336
2020-07-22[lldb/interpreter] Fix formatting in CommandInterpreter.cpp (NFC)Med Ismail Bennani1-1/+2
This patch addresses some formatting issues introduced by commit 5bb742b10dafd595223172ae985687765934ebe9 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-07-22[lldb/interpreter] Add ability to save lldb session to a fileMed Ismail Bennani1-1/+67
This patch introduce a new feature that allows the users to save their debugging session's transcript (commands + outputs) to a file. It differs from the reproducers since it doesn't require to capture a session preemptively and replay the reproducer file in lldb. The user can choose the save its session manually using the session save command or automatically by setting the interpreter.save-session-on-quit on their init file. To do so, the patch adds a Stream object to the CommandInterpreter that will hold the input command from the IOHandler and the CommandReturnObject output and error. This way, that stream object accumulates passively all the interactions throughout the session and will save them to disk on demand. The user can specify a file path where the session's transcript will be saved. However, it is optional, and when it is not provided, lldb will create a temporary file name according to the session date and time. rdar://63347792 Differential Revision: https://reviews.llvm.org/D82155 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-07-20[lldb] Fix redundant newline in AppendError calls.Jonas Devlieghere1-1/+1
AppendError always appends a newline to the given argument, while AppendErrorWithFormat does not. I've updated the calls to remove the extra newline.
2020-07-20[lldb] Remove redundant WithFormat suffixes (NFC)Jonas Devlieghere1-2/+2
Replace calls to FooWithFormat() with calls to Foo() when only one argument is provided and the given string doesn't need to be formatted.
2020-06-19[lldb] Replace std::isprint/isspace with llvm's locale-independent versionRaphael Isemann1-2/+2
Summary: LLVM is using its own isPrint/isSpace implementation that doesn't change depending on the current locale. LLDB should do the same to prevent that internal logic changes depending on the set locale. Reviewers: JDevlieghere, labath, mib, totally_not_teemperor Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D82175
2020-06-09[lldb/Interpreter] Support color in CommandReturnObjectJonas Devlieghere1-3/+3
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-26Be more specific about auto * vs auto for po alias.Eric Christopher1-1/+1
2020-05-23Revert "[lldb/Interpreter] Fix another eExpressionThreadVanished warning"Jonas Devlieghere1-5/+0
This reverts commit f2ffa33c79d3d0636d6c8eb7b5b7bcf8db7b397b. My local checkout was behind and Eric already took care of it in the meantime.
2020-05-23[lldb/Interpreter] Fix another eExpressionThreadVanished warningJonas Devlieghere1-0/+5
Fixes warning: enumeration value 'eExpressionThreadVanished' not handled in switch [-Wswitch] in CommandInterpreter.cpp.
2020-05-22Handle eExpressionThreadVanished in error switch to handleEric Christopher1-0/+5
covered switch warning.
2020-05-15[lldb/Commands] Add ability to run shell command on the host.Med Ismail Bennani1-0/+10
This patch introduces the `(-h|--host)` option to the `platform shell` command. It allows the user to run shell commands from the host platform (always available) without putting lldb in the background. Since the default behaviour of `platform shell` is to run the command of the selected platform, having such a choice can be quite handy when debugging remote targets, for instances. This patch also introduces a `shell` alias, to improve the command discoverability and make it more convenient to use for the user. rdar://62856024 Differential Revision: https://reviews.llvm.org/D79659 Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
2020-05-05[lldb/Driver] Exit with a non-zero exit code in case of error in batch mode.Jonas Devlieghere1-1/+3
We have the option to stop running commands in batch mode when an error occurs. When that happens we should exit the driver with a non-zero exit code. Differential revision: https://reviews.llvm.org/D78825
2020-05-01[lldb/CommandInterpreter] Fix typo in CommandInterpreterResult::IsResultJonas Devlieghere1-1/+1
A missing `=` turned a comparison into an assignment.
2020-05-01[lldb/CommandInterpreter] Add CommandInterpreterRunResult (NFC)Jonas Devlieghere1-8/+10
This patch adds a new class CommandInterpreterRunResult which will be backing the SBCommandInterpreterRunResult. It keeps track of the number of errors as well as the result which is an enum, as proposed by Pavel in D79120. The command interpreter now populates the results directly, instead of its own member variables. Differential revision: https://reviews.llvm.org/D79209
2020-04-30[lldb/CommandInterpreter] Move everything into CommandInterpreterRunOptionsJonas Devlieghere1-4/+3
This implements Greg's suggestion from D78825 to include "auto handle events" and "spawn thread" in CommandInterpreterRunOptions. This change is in preparation for adding a new overload for RunCommandInterpreter that takes only SBCommandInterpreterRunOptions and returns SBCommandInterpreterRunResults. Differential revision: https://reviews.llvm.org/D79108
2020-03-06[lldb] Update the current execution context at the beginning of tab completionsGongyu Deng1-0/+2
Summary: Fix a bug that tab completions won't synchronous the current execution context. ( Thanks for Jim's explanation! ) Reviewers: teemperor, labath, jingham Reviewed By: jingham Subscribers: jingham, labath Tags: #lldb Differential Revision: https://reviews.llvm.org/D75597
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-36/+46
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-27[lldb/Commands] Make column available through _regexp-breakJonas Devlieghere1-1/+11
Update _regexp-break to interpret main.c:8:21 as: breakpoint set --line 8 --column 21 Differential revision: https://reviews.llvm.org/D73314
2020-01-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann1-1/+1
Summary: A *.cpp file header in LLDB (and in LLDB) should like this: ``` //===-- TestUtilities.cpp -------------------------------------------------===// ``` However in LLDB most of our source files have arbitrary changes to this format and these changes are spreading through LLDB as folks usually just use the existing source files as templates for their new files (most notably the unnecessary editor language indicator `-*- C++ -*-` is spreading and in every review someone is pointing out that this is wrong, resulting in people pointing out that this is done in the same way in other files). This patch removes most of these inconsistencies including the editor language indicators, all the different missing/additional '-' characters, files that center the file name, missing trailing `===//` (mostly caused by clang-format breaking the line). Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere Reviewed By: JDevlieghere Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D73258
2020-01-16[lldb/Debugger] Rename ExecuteIOHandlers to RunIOHandlers (NFC)Jonas Devlieghere1-1/+1
This improves consistency among the related methods.
2020-01-15[lldb/Debugger] Rename IO handler methods to be more meaningful (NFC)Jonas Devlieghere1-5/+5
Make it clear form the method names whether they are synchronous or asynchronous.
2020-01-14[lldb/CommandInterpreter] Remove flag that's always true (NFC)Jonas Devlieghere1-12/+4
The 'asynchronously' argument to both GetLLDBCommandsFromIOHandler and GetPythonCommandsFromIOHandler is true for all call sites. This commit simplifies the API by dropping it and giving the baton a default argument.
2019-12-12[lldb/CMake] Rename LLDB_DISABLE_LIBEDIT to LLDB_ENABLE_LIBEDITJonas Devlieghere1-1/+1
This matches the naming scheme used by LLVM. Differential revision: https://reviews.llvm.org/D71380
2019-12-10[lldb/Host] Use Host/Config.h entries instead of a global define.Jonas Devlieghere1-2/+3
As suggested by Pavel in a code review: > Can we replace this (and maybe python too, while at it) with a > Host/Config.h entry? A global definition means that one has to > recompile everything when these change in any way, whereas in > practice only a handful of files need this.. Differential revision: https://reviews.llvm.org/D71280
2019-12-04Add help text for parray and poarray aliases.Jason Molenda1-4/+17
2019-11-05[lldb][NFC] Give some parameters in CommandInterpreter more descriptive namesRaphael Isemann1-6/+6
2019-09-27remove File::SetStream(), make new files instead.Lawrence D'Anna1-13/+14
Summary: This patch removes File::SetStream() and File::SetDescriptor(), and replaces most direct uses of File with pointers to File. Instead of calling SetStream() on a file, we make a new file and replace it. My ultimate goal here is to introduce a new API class SBFile, which has full support for python io.IOStream file objects. These can redirect read() and write() to python code, so lldb::Files will need a way to dispatch those methods. Additionally it will need some form of sharing and assigning files, as a SBFile will be passed in and assigned to the main IO streams of the debugger. In my prototype patch queue, I make File itself copyable and add a secondary class FileOps to manage the sharing and dispatch. In that case SBFile was a unique_ptr<File>. (here: https://github.com/smoofra/llvm-project/tree/files) However in review, Pavel Labath suggested that it be shared_ptr instead. (here: https://reviews.llvm.org/D67793) In order for SBFile to use shared_ptr<File>, everything else should as well. If this patch is accepted, I will make SBFile use a shared_ptr I will remove FileOps from future patches and use subclasses of File instead. Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67891 llvm-svn: 373090
2019-09-26Convert FileSystem::Open() to return Expected<FileUP>Lawrence D'Anna1-7/+7
Summary: This patch converts FileSystem::Open from this prototype: Status Open(File &File, const FileSpec &file_spec, ...); to this one: llvm::Expected<std::unique_ptr<File>> Open(const FileSpec &file_spec, ...); This is beneficial on its own, as llvm::Expected is a more modern and recommended error type than Status. It is also a necessary step towards https://reviews.llvm.org/D67891, and further developments for lldb_private::File. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67996 llvm-svn: 373003
2019-09-26Don't stop execution in batch mode when process stops with SIGINT or SIGSTOPTatyana Krasnukha1-51/+59
Summary: Usually, SIGINT and SIGSTOP don't imply a crash, e.g. SIGSTOP is sent on process launch and attach on some platforms. Differential Revision: https://reviews.llvm.org/D67776 llvm-svn: 372961
2019-09-25[lldb][NFC] Add CompletionRequest::AppendEmptyArgumentRaphael Isemann1-3/+1
This is the only legitimate use we currently have for modifying a CompletionRequest. Add a utility function for this purpose and remove the remaining setters which go against the idea of having an immutable CompletionRequest. llvm-svn: 372858
2019-09-24[lldb] Remove redundant argument lists in CompletionRequestRaphael Isemann1-1/+1
We currently have two lists in the CompletionRequest that we inherited from the old API: The complete list of arguments ignoring where the user requested completion and the list of arguments that stops at the cursor. Having two lists of arguments is confusing and can lead to subtle errors, so let's remove the complete list until we actually need it. llvm-svn: 372692
2019-09-23[lldb] Make cursor index in CompletionRequest unsignedRaphael Isemann1-2/+2
The fact that index==-1 means "no arguments" is not obvious and only used in one place from what I can tell. Also fixes several warnings about using the cursor index as if it was a size_t when comparing. Not fully NFC as we now also correctly update the partial argument list when injecting the fake empty argument in the CompletionRequest constructor. llvm-svn: 372566