llvm-project/lldb/unittests/Interpreter
Jonas Devlieghere 2a6dbedf5a
[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
2022-02-23 12:34:14 -08:00
..
CMakeLists.txt [lldb] Fix (unintentional) recursion in CommandObjectRegexCommand 2022-02-23 12:34:14 -08:00
TestCommandPaths.cpp Follow-on to fix a test from c5011aed9c. 2021-10-18 16:53:32 -07:00
TestCompletion.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
TestOptionArgParser.cpp
TestOptionValue.cpp Fix virtual-dtor warning a different way, since a virtual dtor is not required for this use case. 2021-03-01 09:25:26 -08:00
TestOptionValueFileColonLine.cpp [lldb] Make TestOptionValueFileColonLine work on Windows 2020-07-20 23:15:03 -07:00
TestRegexCommand.cpp [lldb] Fix (unintentional) recursion in CommandObjectRegexCommand 2022-02-23 12:34:14 -08:00