From aab5be050596d6423d1f48c89cb5e57321bc3931 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Wed, 19 Apr 2017 23:21:04 +0000 Subject: [PATCH] Fix !N and !-N commands and add a test case. llvm-svn: 300785 --- .../functionalities/history/TestHistoryRecall.py | 45 ++++++++++++++++++++++ lldb/source/Commands/CommandObjectCommands.cpp | 6 ++- lldb/source/Interpreter/CommandHistory.cpp | 4 +- 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 lldb/packages/Python/lldbsuite/test/functionalities/history/TestHistoryRecall.py 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 0000000..90bd649 --- /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 102010e..e39c033 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 \"!\". \"!-\" will re-run " + "the command that is 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 0fa25ed..ca5c906 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; -- 2.7.4