Skip to content

Commit 6e3c7b8

Browse files
authored
[lldb] Make step/s alias for new _regexp-step (#153984)
Introduces `_regexp-step`, a step command which additionally allows for stepping into a target function. This change updates `step` and `s` to be aliases for `_regexp-step`. The existing `sif` alias ("Step Into Function") is not well known amongst users. This change updates `step` and `s` to also work like `sif`, taking an optional function name. This is implemented to not break uses of `step` or `s` with a flag, for example running `step -r func_to_avoid` works as expected.
1 parent 0037c20 commit 6e3c7b8

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void CommandInterpreter::Initialize() {
335335
AddAlias("ni", cmd_obj_sp);
336336
}
337337

338-
cmd_obj_sp = GetCommandSPExact("thread step-in");
338+
cmd_obj_sp = GetCommandSPExact("_regexp-step");
339339
if (cmd_obj_sp) {
340340
AddAlias("s", cmd_obj_sp);
341341
AddAlias("step", cmd_obj_sp);
@@ -946,6 +946,27 @@ void CommandInterpreter::LoadCommandDictionary() {
946946
jump_regex_cmd_sp;
947947
}
948948
}
949+
950+
std::shared_ptr<CommandObjectRegexCommand> step_regex_cmd_sp(
951+
new CommandObjectRegexCommand(
952+
*this, "_regexp-step",
953+
"Single step, optionally to a specific function.",
954+
"\n"
955+
"_regexp-step // Single step\n"
956+
"_regexp-step <function-name> // Step into the named function\n",
957+
0, false));
958+
if (step_regex_cmd_sp) {
959+
if (step_regex_cmd_sp->AddRegexCommand("^[[:space:]]*$",
960+
"thread step-in") &&
961+
step_regex_cmd_sp->AddRegexCommand("^[[:space:]]*(-.+)$",
962+
"thread step-in %1") &&
963+
step_regex_cmd_sp->AddRegexCommand(
964+
"^[[:space:]]*(.+)[[:space:]]*$",
965+
"thread step-in --end-linenumber block --step-in-target %1")) {
966+
m_command_dict[std::string(step_regex_cmd_sp->GetCommandName())] =
967+
step_regex_cmd_sp;
968+
}
969+
}
949970
}
950971

951972
int CommandInterpreter::GetCommandNamesMatchingPartialString(

lldb/test/API/lang/c/step-target/TestStepTarget.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,33 @@ def test_with_end_line_deeper(self):
8383
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343")
8484
def test_with_command_and_block(self):
8585
"""Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
86+
self.do_command_and_block()
87+
self.do_command_and_block(True)
8688

89+
def do_command_and_block(self, use_regexp_step=False):
8790
thread = self.get_to_start()
8891

89-
result = lldb.SBCommandReturnObject()
90-
self.dbg.GetCommandInterpreter().HandleCommand(
91-
'thread step-in -t "lotsOfArgs" -e block', result
92-
)
93-
self.assertTrue(result.Succeeded(), "thread step-in command succeeded.")
92+
if use_regexp_step:
93+
self.expect("s lotsOfArgs")
94+
else:
95+
self.expect('thread step-in -t "lotsOfArgs" -e block')
9496

9597
frame = thread.frames[0]
9698
self.assertEqual(frame.name, "lotsOfArgs", "Stepped to lotsOfArgs.")
9799

98100
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr32343")
99101
def test_with_command_and_block_and_bad_name(self):
100102
"""Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
103+
self.do_with_command_and_block_and_bad_name()
104+
self.do_with_command_and_block_and_bad_name(True)
101105

106+
def do_with_command_and_block_and_bad_name(self, use_regexp_step=False):
102107
thread = self.get_to_start()
103108

104-
result = lldb.SBCommandReturnObject()
105-
self.dbg.GetCommandInterpreter().HandleCommand(
106-
'thread step-in -t "lotsOfArgsssss" -e block', result
107-
)
108-
self.assertTrue(result.Succeeded(), "thread step-in command succeeded.")
109+
if use_regexp_step:
110+
self.expect("s lotsOfArgsssss")
111+
else:
112+
self.expect('thread step-in -t "lotsOfArgsssss" -e block')
109113

110114
frame = thread.frames[0]
111115

0 commit comments

Comments
 (0)