summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/history/TestHistoryRecall.py45
-rw-r--r--lldb/source/Commands/CommandObjectCommands.cpp6
-rw-r--r--lldb/source/Interpreter/CommandHistory.cpp4
3 files changed, 52 insertions, 3 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/history/TestHistoryRecall.py b/lldb/packages/Python/lldbsuite/test/functionalities/history/TestHistoryRecall.py
new file mode 100644
index 00000000000..90bd64901ee
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/history/TestHistoryRecall.py
@@ -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.")
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index 102010e8e6f..e39c0330b65 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -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() {}
diff --git a/lldb/source/Interpreter/CommandHistory.cpp b/lldb/source/Interpreter/CommandHistory.cpp
index 0fa25ed806f..ca5c90692b6 100644
--- a/lldb/source/Interpreter/CommandHistory.cpp
+++ b/lldb/source/Interpreter/CommandHistory.cpp
@@ -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;
OpenPOWER on IntegriCloud