Skip to content

Commit 07a8f9b

Browse files
committed
[lldb] Make step/s alias for new _regexp-step
Introduces `_regexp-step`, a regex command which allows for stepping into a target function. This change updates `step` and `s` to be aliases for `_regexp-step`. The existing `sif` command ("Step Into Function") is not well known amongst users. This change makes `step` and `s` 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 aa96e20 commit 07a8f9b

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 21 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,26 @@ 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("^$", "thread step-in") &&
960+
step_regex_cmd_sp->AddRegexCommand("^[[:space:]]*(-.*)$",
961+
"thread step-in %1") &&
962+
step_regex_cmd_sp->AddRegexCommand(
963+
"^[[:space:]]*(.+)[[:space:]]*$",
964+
"thread step-in --end-linenumber block --step-in-target %1")) {
965+
m_command_dict[std::string(step_regex_cmd_sp->GetCommandName())] =
966+
step_regex_cmd_sp;
967+
}
968+
}
949969
}
950970

951971
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)