Skip to content

Commit 36eab46

Browse files
committed
[lldb/Interpreter] Add interpreter.repeat-previous-command setting
This patch introduces a new interpreter setting to prevent LLDB from re-executing the previous command when passing an empty command. This can be very useful when performing actions that requires a long time to complete. To preserve the original behaviour, the setting defaults to `true`. rdar://74983516 Differential Revision: https://reviews.llvm.org/D97999 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent f8b01d5 commit 36eab46

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

lldb/include/lldb/Interpreter/CommandInterpreter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ class CommandInterpreter : public Broadcaster,
504504
bool GetEchoCommentCommands() const;
505505
void SetEchoCommentCommands(bool enable);
506506

507+
bool GetRepeatPreviousCommand() const;
508+
507509
const CommandObject::CommandMap &GetUserCommands() const {
508510
return m_user_dict;
509511
}

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ bool CommandInterpreter::GetSpaceReplPrompts() const {
223223
nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
224224
}
225225

226+
bool CommandInterpreter::GetRepeatPreviousCommand() const {
227+
const uint32_t idx = ePropertyRepeatPreviousCommand;
228+
return m_collection_sp->GetPropertyAtIndexAsBoolean(
229+
nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
230+
}
231+
226232
void CommandInterpreter::Initialize() {
227233
LLDB_SCOPED_TIMER();
228234

@@ -1695,6 +1701,11 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
16951701
}
16961702

16971703
if (empty_command) {
1704+
if (!GetRepeatPreviousCommand()) {
1705+
result.SetStatus(eReturnStatusSuccessFinishNoResult);
1706+
return true;
1707+
}
1708+
16981709
if (m_command_history.IsEmpty()) {
16991710
result.AppendError("empty command");
17001711
result.SetStatus(eReturnStatusFailed);

lldb/source/Interpreter/InterpreterProperties.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ let Definition = "interpreter" in {
2929
Global,
3030
DefaultTrue,
3131
Desc<"If true, commands will be echoed even if they are pure comment lines.">;
32+
def RepeatPreviousCommand: Property<"repeat-previous-command", "Boolean">,
33+
Global,
34+
DefaultTrue,
35+
Desc<"If true, LLDB will repeat the previous command if no command was passed to the interpreter. If false, LLDB won't repeat the previous command but only return a new prompt.">;
3236
}

lldb/test/API/commands/settings/TestSettings.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,42 @@ def test_apropos_should_also_search_settings_description(self):
2525
"environment variables",
2626
"executable's environment"])
2727

28+
def test_set_interpreter_repeat_prev_command(self):
29+
"""Test the `interpreter.repeat-previous-command` setting."""
30+
self.build()
31+
32+
exe = self.getBuildArtifact("a.out")
33+
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
34+
setting = "interpreter.repeat-previous-command"
35+
36+
def cleanup(setting):
37+
self.runCmd(
38+
"settings clear %s" %
39+
setting, check=False)
40+
41+
# Execute the cleanup function during test case tear down.
42+
self.addTearDownHook(cleanup(setting))
43+
44+
# First, check for the setting default value.
45+
self.expect("setting show %s" % setting,
46+
substrs=["interpreter.repeat-previous-command (boolean) = true"])
47+
48+
# Then, invert the setting, and check that was set correctly
49+
self.runCmd("setting set %s false" % setting)
50+
self.expect("setting show %s" % setting,
51+
substrs=["interpreter.repeat-previous-command (boolean) = false"])
52+
53+
54+
ci = self.dbg.GetCommandInterpreter()
55+
self.assertTrue(ci.IsValid(), "Invalid command interpreter.")
56+
# Now, test the functionnality
57+
res = lldb.SBCommandReturnObject()
58+
ci.HandleCommand('breakpoint set -n main', res)
59+
self.assertTrue(res.Succeeded(), "Command failed.")
60+
ci.HandleCommand('', res)
61+
self.assertTrue(res.Succeeded(), "Empty command failed.")
62+
self.assertEqual(self.dbg.GetSelectedTarget().GetNumBreakpoints(), 1)
63+
2864
def test_append_target_env_vars(self):
2965
"""Test that 'append target.run-args' works."""
3066
# Append the env-vars.

0 commit comments

Comments
 (0)