From 2a6dbedf5a923512ba8b5c2d192b5fc8bb1210fd Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 23 Feb 2022 11:52:20 -0800 Subject: [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 --- lldb/source/Interpreter/CommandReturnObject.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lldb/source/Interpreter/CommandReturnObject.cpp') 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. -- cgit v1.2.3