Fix !N and !-N commands and add a test case.

<rdar://problem/31713267>

llvm-svn: 300785
This commit is contained in:
Jim Ingham 2017-04-19 23:21:04 +00:00
parent aa0cec7d6d
commit aab5be0505
3 changed files with 52 additions and 3 deletions

View File

@ -0,0 +1,45 @@
"""
Make sure the !N and !-N commands work properly.
"""
from __future__ import print_function
import os
import time
import re
import lldb
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *
class TestHistoryRecall(TestBase):
mydir = TestBase.compute_mydir(__file__)
# If your test case doesn't stress debug info, the
# set this to true. That way it won't be run once for
# each debug info format.
NO_DEBUG_INFO_TESTCASE = True
def test_history_recall(self):
"""Test the !N and !-N functionality of the command interpreter."""
self.sample_test()
def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
def sample_test(self):
interp = self.dbg.GetCommandInterpreter()
result = lldb.SBCommandReturnObject()
interp.HandleCommand("command history", result, True)
interp.HandleCommand("platform list", result, True)
interp.HandleCommand("!0", result, False)
self.assertTrue(result.Succeeded(), "!0 command did not work: %s"%(result.GetError()))
self.assertTrue("command history" in result.GetOutput(), "!0 didn't rerun command history")
interp.HandleCommand("!-1", result, False)
self.assertTrue(result.Succeeded(), "!-1 command did not work: %s"%(result.GetError()))
self.assertTrue("host:" in result.GetOutput(), "!-1 didn't rerun platform list.")

View File

@ -50,7 +50,11 @@ class CommandObjectCommandsHistory : public CommandObjectParsed {
public:
CommandObjectCommandsHistory(CommandInterpreter &interpreter)
: CommandObjectParsed(interpreter, "command history",
"Dump the history of commands in this session.",
"Dump the history of commands in this session.\n"
"Commands in the history list can be run again "
"using \"!<INDEX>\". \"!-<OFFSET>\" will re-run "
"the command that is <OFFSET> commands from the end"
" of the list (counting the current command).",
nullptr),
m_options() {}

View File

@ -47,13 +47,13 @@ CommandHistory::FindString(llvm::StringRef input_str) const {
size_t idx = 0;
if (input_str.front() == '-') {
if (input_str.drop_front(2).getAsInteger(0, idx))
if (input_str.drop_front(1).getAsInteger(0, idx))
return llvm::None;
if (idx >= m_history.size())
return llvm::None;
idx = m_history.size() - idx;
} else {
if (input_str.drop_front().getAsInteger(0, idx))
if (input_str.getAsInteger(0, idx))
return llvm::None;
if (idx >= m_history.size())
return llvm::None;