diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2022-02-23 11:52:20 -0800 |
|---|---|---|
| committer | Jonas Devlieghere <jonas@devlieghere.com> | 2022-02-23 12:34:14 -0800 |
| commit | 2a6dbedf5a923512ba8b5c2d192b5fc8bb1210fd (patch) | |
| tree | 09ad1d05010f4c1c51498ca79a53a140cb381641 /lldb/source/Interpreter/CommandReturnObject.cpp | |
| parent | 222e8610f1372783e49405fec9208000b0b39bdb (diff) | |
[lldb] Fix (unintentional) recursion in CommandObjectRegexCommand
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
Diffstat (limited to 'lldb/source/Interpreter/CommandReturnObject.cpp')
| -rw-r--r-- | lldb/source/Interpreter/CommandReturnObject.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lldb/source/Interpreter/CommandReturnObject.cpp b/lldb/source/Interpreter/CommandReturnObject.cpp index 1b1e6996764c..798dced0f1c6 100644 --- a/lldb/source/Interpreter/CommandReturnObject.cpp +++ b/lldb/source/Interpreter/CommandReturnObject.cpp @@ -109,6 +109,11 @@ void CommandReturnObject::SetError(const Status &error, AppendError(error.AsCString(fallback_error_cstr)); } +void CommandReturnObject::SetError(llvm::Error error) { + if (error) + AppendError(llvm::toString(std::move(error))); +} + // Similar to AppendError, but do not prepend 'Status: ' to message, and don't // append "\n" to the end of it. |
