forked from OSchip/llvm-project
Fix a thinko in the parsing of substitutions in CommandObjectRegexCommand.
The old code incorrectly calculated the start position for the search for the third (and subsequent) instance of a particular substitution pattern (e.g. %1). I also added a few test cases for this parsing covering this failure.
This commit is contained in:
parent
f2026f5d6e
commit
3c45476923
|
@ -43,7 +43,7 @@ bool CommandObjectRegexCommand::DoExecute(llvm::StringRef command,
|
|||
percent_var, idx)) != std::string::npos;) {
|
||||
new_command.erase(percent_var_idx, percent_var_len);
|
||||
new_command.insert(percent_var_idx, match_str);
|
||||
idx += percent_var_idx + match_str.size();
|
||||
idx = percent_var_idx + match_str.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
"""
|
||||
This tests some simple examples of parsing regex commands
|
||||
"""
|
||||
|
||||
import os
|
||||
import lldb
|
||||
import lldbsuite.test.lldbutil as lldbutil
|
||||
from lldbsuite.test.lldbtest import *
|
||||
|
||||
|
||||
class TestCommandRegexParsing(TestBase):
|
||||
|
||||
mydir = TestBase.compute_mydir(__file__)
|
||||
|
||||
NO_DEBUG_INFO_TESTCASE = True
|
||||
|
||||
def test_sample_rename_this(self):
|
||||
"""Try out some simple regex commands, make sure they parse correctly."""
|
||||
self.runCmd("command regex one-substitution 's/(.+)/echo-cmd %1-first %1-second %1-third/'")
|
||||
self.expect("one-substitution ASTRING",
|
||||
substrs = ["ASTRING-first", "ASTRING-second", "ASTRING-third"])
|
||||
|
||||
self.runCmd("command regex two-substitution 's/([^ ]+) ([^ ]+)/echo-cmd %1-first %2-second %1-third %2-fourth/'")
|
||||
self.expect("two-substitution ASTRING BSTRING",
|
||||
substrs = ["ASTRING-first", "BSTRING-second", "ASTRING-third", "BSTRING-fourth"])
|
||||
|
||||
def setUp(self):
|
||||
# Call super's setUp().
|
||||
TestBase.setUp(self)
|
||||
self.runCmd("command script import " + os.path.join(self.getSourceDir(), "echo_command.py"))
|
||||
self.runCmd("command script add echo-cmd -f echo_command.echo_command")
|
|
@ -0,0 +1,6 @@
|
|||
import lldb
|
||||
|
||||
def echo_command(debugger, args, result, dict):
|
||||
result.Print(args+'\n')
|
||||
result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
|
||||
return True
|
Loading…
Reference in New Issue