summaryrefslogtreecommitdiff
path: root/lldb/source/Interpreter/CommandReturnObject.cpp
AgeCommit message (Collapse)Author
2025-11-19[NFC][lldb] move DiagnosticsRendering to Host (#168696)Charles Zablit
NFC patch which moves `DiagnosticsRendering` from `Utility` to `Host`. This refactoring is needed for https://github.com/llvm/llvm-project/pull/168603. It adds a method to check whether the current terminal supports Unicode or not. This will be OS dependent and a better fit for `Host`. Since `Utility` cannot depend on `Host`, `DiagnosticsRendering` must live in `Host` instead.
2025-01-30[lldb] Constify methods in CommandReturnObject (NFC)Jonas Devlieghere
There's no reason these methods cannot be `const`. Currently this prevents us from passing around a const ref. This patch is in preparation for #125006.
2024-12-20[lldb] Expose structured errors in SBError (#120784)Adrian Prantl
Building on top of previous work that exposed expression diagnostics via SBCommandReturnObject, this patch generalizes the support to expose any SBError as machine-readable structured data. One use-case of this is to allow IDEs to better visualize expression diagnostics. rdar://139997604
2024-11-02[lldb] Highlight "note:" in CommandReturnObject (#114610)Jonas Devlieghere
We have helpers to emit warnings and errors. Do the same thing for notes to they stand out more.
2024-10-14[lldb] Expose structured command diagnostics via the SBAPI. (#112109)Adrian Prantl
This allows IDEs to render LLDB expression diagnostics to their liking without relying on characterprecise ASCII art from LLDB. It is exposed as a versioned SBStructuredData object, since it is expected that this may need to be tweaked based on actual usage.
2024-10-12[lldb] Rename CommandReturnObject::Get.*Data -> Get.*String (#112062)Adrian Prantl
In a later commit, I want to add a method to access diagnostics as actual structured data, which will make these function names rather confusing.
2024-10-11Support inline diagnostics in CommandReturnObject (#110901)Adrian Prantl
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-10-02[lldb] Unify implementation of CommandReturnObject::SetError(NFC) (#110707)Adrian Prantl
This is a cleanup that moves the API towards value semantics.
2023-06-12Streamline expression parser error messages.Adrian Prantl
Currently the expression parser prints a mostly useless generic error before printing the compiler error: (lldb) p 1+x) error: expression failed to parse: error: <user expression 18>:1:3: use of undeclared identifier 'x' 1+x) ^ This is distracting and as far as I can tell only exists to work around the fact that the first "error: " is unconditionally injected by CommandReturnObject. The solution is not very elegant, but the result looks much better. (Partially addresses rdar://110492710) Differential Revision: https://reviews.llvm.org/D152590
2022-04-14[lldb] Show the DBGError if dsymForUUID can't find a dSYMJonas Devlieghere
Show the user the DBGError (if available) when dsymForUUID fails. rdar://90949180 Differential revision: https://reviews.llvm.org/D123743
2022-02-23[lldb] Fix (unintentional) recursion in CommandObjectRegexCommandJonas Devlieghere
Jim noticed that the regex command is unintentionally recursive. Let's use the following command regex as an example: (lldb) com regex humm 's/([^ ]+) ([^ ]+)/p %1 %2 %1 %2/' If we call it with arguments foo bar, thing behave as expected: (lldb) humm foo bar (...) foo bar foo bar However, if we include %2 in the arguments, things break down: (lldb) humm fo%2o bar (...) fobaro bar fobaro bar The problem is that the implementation of the substitution is too naive. It substitutes the %1 token into the target template in place, then does the %2 substitution starting with the resultant string. So if the previous substitution introduced a %2 token, it would get processed in the second sweep, etc. This patch addresses the issue by walking the command once and substituting the % variables in place. (lldb) humm fo%2o bar (...) fo%2o bar fo%2o bar Furthermore, this patch also reports an error if not enough variables were provided and add support for substituting %0. rdar://81236994 Differential revision: https://reviews.llvm.org/D120101
2021-12-03[NFC] const-ify some methods on CommandReturnObjectJordan Rupprecht
2021-06-23[lldb] Remove asserts in CommandReturnObject SetError and AppendErrorDavid Spickett
I added asserts to these in https://reviews.llvm.org/D104525. They are available (directly or otherwise) via the API so we should not assert. Restore the previous behaviour. If the message is empty, we return early before printing anything. For SetError don't assert that the error is a failure. The remaining assert is in AppendRawError which is not part of the API. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D104778
2021-06-23[lldb] Remove CommandReturnObject's SetError(StringRef)David Spickett
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-21[lldb] Assert that CommandResultObject error messages are not emptyDavid Spickett
The intention is now that AppendError/SetError/AppendRawError only be called with some message to show. This enforces that. For SetError with a Status and a fallback string first assert that the Status is a failure Status. Then it calls SetError(StringRef) which checks the message is valid. (which could be the fallback or the Status') Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D104525
2021-06-17[lldb] Set return object failed status even if error string is emptyDavid Spickett
The idea is now that AppendError<...> will set eReturnStatusFailed for you so you don't have to call SetStatus again. Previously if the error message was empty, the status wouldn't be set. I don't think there are any sitautions where the message is in fact empty but it potentially could be depending on where we get the string from. So let's set the status up front then return early if the message is empty. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D104380
2021-06-14Reland "[lldb] Set return status to failed when adding a command error"David Spickett
This reverts commit ac031c8db2ce454a9b08f23192ce698e8bde4447. SB API usage has been corrected.
2021-06-14Revert "[lldb] Set return status to failed when adding a command error" (and ↵David Spickett
fixups) This reverts commit f583029da3d6dbabe82f48b160227eb0120abd33, 0f94d68a2e15d50796439f20bcb508b95931d2ae and a2363c0cf9b6a9a81c76ac652da667f73845d38b. Due to test failures from incorrect SB API usage.
2021-06-14Reland "[lldb] Set return status to failed when adding a command error"David Spickett
This reverts commit db93e4e70aa453e5ba04ba0d9e01f581882b6c81. This modifies TestRegsters.py to account for Darwin showing AVX registers as part of "Floating Point Registers" instead of in a separate "Advanced Vector Extensions" category.
2021-06-09Revert "[lldb] Set return status to failed when adding a command error"David Spickett
This reverts commit e05b03cf4f45ac5ee63c59a3464e7d484884645c. While I investigate a register test failure: http://green.lab.llvm.org/green/blue/organizations/jenkins/lldb-cmake/detail/lldb-cmake/32693/pipeline/
2021-06-08[lldb] Don't print script output twice in HandleCommandJonas Devlieghere
When executing a script command in HandleCommand(s) we currently print its output twice You can see this issue in action when adding a breakpoint command: (lldb) b main Breakpoint 1: where = main.out`main + 13 at main.cpp:2:3, address = 0x0000000100003fad (lldb) break command add 1 -o "script print(\"Hey!\")" (lldb) r Process 76041 launched: '/tmp/main.out' (x86_64) Hey! (lldb) script print("Hey!") Hey! Process 76041 stopped The issue is caused by HandleCommands using a temporary CommandReturnObject and one of the commands (`script` in this case) setting an immediate output stream. This causes the result to be printed twice: once directly to the immediate output stream and once when printing the result of HandleCommands. This patch fixes the issue by introducing a new option to suppress immediate output for temporary CommandReturnObjects. Differential revision: https://reviews.llvm.org/D103349
2021-06-08[lldb] Set return status to failed when adding a command errorDavid Spickett
There is a common pattern: result.AppendError(...); result.SetStatus(eReturnStatusFailed); I found that some commands don't actually "fail" but only print "error: ..." because the second line got missed. This can cause you to miss a failed command when you're using the Python interface during testing. (and produce some confusing script results) I did not find any place where you would want to add an error without setting the return status, so just set eReturnStatusFailed whenever you add an error to a command result. This change does not remove any of the now redundant SetStatus. This should allow us to see if there are any tests that have commands unexpectedly fail with this change. (the test suite passes for me but I don't have access to all the systems we cover so there could be some corner cases) Some tests that failed on x86 and AArch64 have been modified to work with the new behaviour. Differential Revision: https://reviews.llvm.org/D103701
2021-02-28[lldb/Interpreter][NFC] Replace default constructors/destructors bodies with ↵Tatyana Krasnukha
"=default"
2021-02-24[lldb] Prevent double new lines behind errors/warning/messages from LLDB ↵Raphael Isemann
commands The current API for printing errors/warnings/messages from LLDB commands sometimes adds newlines behind the messages for the caller. However, this happens unconditionally so when the caller already specified a trailing newline in the error message (or is trying to print a generated error message that ends in a newline), LLDB ends up printing both the automatically added newline and the one that was in the error message string. This leads to all the randomly appearing new lines in error such as: ``` (lldb) command a error: 'command alias' requires at least two arguments (lldb) apropos a b error: 'apropos' must be called with exactly one argument. (lldb) why is there an empty line behind the second error? ``` This code adds a check that only appends the new line if the passed message doesn't already contain a trailing new line. Also removes the AppendRawWarning which had only one caller and doesn't serve any purpose now. Reviewed By: #lldb, mib Differential Revision: https://reviews.llvm.org/D96947
2020-06-09[lldb/Interpreter] Support color in CommandReturnObjectJonas Devlieghere
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-06-02[lldb/Interpreter] Remove redundant argument (NFC)Jonas Devlieghere
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
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-24[lldb][NFC] Fix all formatting errors in .cpp file headersRaphael Isemann
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
2019-09-26Don't stop execution in batch mode when process stops with SIGINT or SIGSTOPTatyana Krasnukha
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-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-11-11Remove header grouping comments.Jonas Devlieghere
This patch removes the comments grouping header includes. They were added after running IWYU over the LLDB codebase. However they add little value, are often outdates and burdensome to maintain. llvm-svn: 346626
2018-04-30Reflow paragraphs in comments.Adrian Prantl
This is intended as a clean up after the big clang-format commit (r280751), which unfortunately resulted in many of the comment paragraphs in LLDB being very hard to read. FYI, the script I used was: import textwrap import commands import os import sys import re tmp = "%s.tmp"%sys.argv[1] out = open(tmp, "w+") with open(sys.argv[1], "r") as f: header = "" text = "" comment = re.compile(r'^( *//) ([^ ].*)$') special = re.compile(r'^((([A-Z]+[: ])|([0-9]+ )).*)|(.*;)$') for line in f: match = comment.match(line) if match and not special.match(match.group(2)): # skip intentionally short comments. if not text and len(match.group(2)) < 40: out.write(line) continue if text: text += " " + match.group(2) else: header = match.group(1) text = match.group(2) continue if text: filled = textwrap.wrap(text, width=(78-len(header)), break_long_words=False) for l in filled: out.write(header+" "+l+'\n') text = "" out.write(line) os.rename(tmp, sys.argv[1]) Differential Revision: https://reviews.llvm.org/D46144 llvm-svn: 331197
2017-05-12Rename Error -> Status.Zachary Turner
This renames the LLDB error class to Status, as discussed on the lldb-dev mailing list. A change of this magnitude cannot easily be done without find and replace, but that has potential to catch unwanted occurrences of common strings such as "Error". Every effort was made to find all the obvious things such as the word "Error" appearing in a string, etc, but it's possible there are still some lingering occurences left around. Hopefully nothing too serious. llvm-svn: 302872
2017-02-02Move classes from Core -> Utility.Zachary Turner
This moves the following classes from Core -> Utility. ConstString Error RegularExpression Stream StreamString The goal here is to get lldbUtility into a state where it has no dependendencies except on itself and LLVM, so it can be the starting point at which to start untangling LLDB's dependencies. These are all low level and very widely used classes, and previously lldbUtility had dependencies up to lldbCore in order to use these classes. So moving then down to lldbUtility makes sense from both the short term and long term perspective in solving this problem. Differential Revision: https://reviews.llvm.org/D29427 llvm-svn: 293941
2016-11-16Don't allow direct access to StreamString's internal buffer.Zachary Turner
This is a large API change that removes the two functions from StreamString that return a std::string& and a const std::string&, and instead provide one function which returns a StringRef. Direct access to the underlying buffer violates the concept of a "stream" which is intended to provide forward only access, and makes porting to llvm::raw_ostream more difficult in the future. Differential Revision: https://reviews.llvm.org/D26698 llvm-svn: 287152
2016-11-12Make CommandReturnObject methods accept StringRefs.Zachary Turner
llvm-svn: 286728
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
2016-01-08Fix a glitch in the Driver's batch mode when used with "attach". Jim Ingham
Batch mode is supposed to stop execution and return control to the user when an exceptional stop occurs (crash, signal or instrumentation). But attach always stops with a SIGSTOP on OSX (maybe on Linux too?) which would short circuit the rest of the commands given. This change allows a command result object to indicate that it expected to leave the process stopped with an exceptional stop reason, and it is okay for batch mode to keep going. <rdar://problem/22243143> llvm-svn: 257120
2014-07-15Any commands that are executed through the public interface using ↵Greg Clayton
SBCommandInterpreter::HandleCommand() are assumed to be in non-interactive mode. Any commands that want interactivity (stdin) will need to be executed through the normal command interpreter using the debugger's in/out/err file handles, or by using "command source". Individual commands through the API will have their STDIN disabled. The STDOUT and STDERR will be redirected into the SBCommandReturnObject argument to SBCommandInterpreter::HandleCommand() as usual. This helps with a deadlock situation in an IDE (Xcode) where the IDE was managing the breakpoint actions by setting a breakpoint callback and doing things manually. <rdar://problem/17386271> llvm-svn: 213023
2014-04-20Switch NULL to C++11 nullptr in source/InterpreterEd Maste
Patch by Robert Matusewicz llvm-svn: 206711
2013-07-09Second attempt at getting the PyCallable changes in trunkEnrico Granata
Thanks to Daniel Malea for helping test this patch for Linux happiness! llvm-svn: 185965
2013-07-03Revert commits that cause broken builds on GCC buildbotsDaniel Malea
- build fails due to PyCallable template definition inside an extern "C" scope This commit reverts 185240, 184893 and 184608. llvm-svn: 185560
2013-06-25<rdar://problem/14266411>Enrico Granata
The semi-unofficial way of returning a status from a Python command was to return a string (e.g. return "no such variable was found") that LLDB would pick as a clue of an error having happened This checkin changes that: - SBCommandReturnObject now exports a SetError() call, which can take an SBError or a plain C-string - script commands now drop any return value and expect the SBCommandReturnObject ("return object") to be filled in appropriately - if you do nothing, a success will be assumed If your commands were relying on returning a value and having LLDB pick that up as an error, please change your commands to SetError() through the return object or expect changes in behavior llvm-svn: 184893
2013-05-01Change CommandReturnObject::AppendMessage to print an empty line ifJason Molenda
AppendMessage("") is called. This idiom is used in a handful of places right now (e.g. to put space between different threads in 'bt all') but the empty newline is being omitted instead of emitted. <rdar://problem/13753830> llvm-svn: 180841
2013-01-25<rdar://problem/13069948>Greg Clayton
Major fixed to allow reading files that are over 4GB. The main problems were that the DataExtractor was using 32 bit offsets as a data cursor, and since we mmap all of our object files we could run into cases where if we had a very large core file that was over 4GB, we were running into the 4GB boundary. So I defined a new "lldb::offset_t" which should be used for all file offsets. After making this change, I enabled warnings for data loss and for enexpected implicit conversions temporarily and found a ton of things that I fixed. Any functions that take an index internally, should use "size_t" for any indexes and also should return "size_t" for any sizes of collections. llvm-svn: 173463
2012-12-15Remove the “len” defaulted parameter from ↵Jim Ingham
CommandReturnObject::AppendMessage, AppendWarning and AppendError. Nobody was using them, and it meant if you accidentally used the AppendWarning when you meant AppendWarningWithFormat with an integer in the format string, it would compile and then return your string plus some unknown amount of junk. llvm-svn: 170266
2012-09-01Made it so changes to the prompt via "settings set prompt" get noticed by ↵Greg Clayton
the command line. Added the ability for OptionValueString objects to take flags. The only flag is currently for parsing escape sequences. Not the prompt string can have escape characters translate which will allow colors in the prompt. Added functions to Args that will parse the escape sequences in a string, and also re-encode the escape sequences for display. This was looted from other parts of LLDB (the Debugger::FormatString() function). llvm-svn: 163043
2011-12-19Work in progress for:Johnny Chen
rdar://problem/10577182 Audit lldb API impl for places where we need to perform a NULL check Add NULL checks for SBCommandReturnObject.AppendMessage(). llvm-svn: 146911
2011-11-15Added a new class to Process.h: ProcessAttachInfo. This class contains enoughGreg Clayton
info for us to attach by pid, or by name and will also allow us to eventually do a lot more powerful attaches. If you look at the options for the "platform process list" command, there are many options which we should be able to specify. This will allow us to do things like "attach to a process named 'tcsh' that has a parent process ID of 123", or "attach to a process named 'x' which has an effective user ID of 345". I finished up the --shell implementation so that it can be used without the --tty option in "process launch". The "--shell" option now can take an optional argument which is the path to the shell to use (or a partial name like "sh" which we will find using the current PATH environment variable). Modified the Process::Attach to use the new ProcessAttachInfo as the sole argument and centralized a lot of code that was in the "process attach" Execute function so that everyone can take advantage of the powerful new attach functionality. llvm-svn: 144615
2011-07-02Cleanup errors that come out of commands and make sure they all have newlinesGreg Clayton
_only_ in the resulting stream, not in the error objects (lldb_private::Error). lldb_private::Error objects should always just have an error string with no terminating newline characters or periods. Fixed an issue with GDB remote packet detection that could end up deadlocking if a full packet wasn't received in one chunk. Also modified the packet checking function to properly toss one or more bytes when it detects bad data. llvm-svn: 134357