Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable "step back <n>" while replay #754

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1061,12 +1061,14 @@ def step_command type, arg
else
leave_subsession [:step, type, arg&.to_i]
end
when /\Aback\z/, /\Areset\z/
when /\A(back)\z/, /\A(back)\s+(\d+)\z/, /\A(reset)\z/
if type != :in
@ui.puts "only `step #{arg}` is supported."
:retry
else
request_tc [:step, arg.to_sym]
type = $1.to_sym
iter = $2&.to_i
request_tc [:step, type, iter]
end
else
@ui.puts "Unknown option: #{arg}"
Expand Down
10 changes: 7 additions & 3 deletions lib/debug/thread_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,12 @@ def wait_next_action_
break

when :back
iter = iter || 1
if @recorder&.can_step_back?
unless @recorder.backup_frames
@recorder.backup_frames = @target_frames
end
@recorder.step_back
@recorder.step_back iter
raise SuspendReplay
else
puts "Can not step back more."
Expand Down Expand Up @@ -1201,8 +1202,11 @@ def enabled?
@tp_recorder.enabled?
end

def step_back
@index += 1
def step_back iter
@index += iter
if @index > @log.size
@index = @log.size
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When n of "step back " is larger than current @index, @index will be size of log.

end
end

def step_forward
Expand Down
68 changes: 68 additions & 0 deletions test/console/record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,74 @@ def test_1629263892
end
end

class StepBackWithNumWhileReplayTest < ConsoleTestCase
def program
<<~RUBY
1| def a
2| return b()
3| end
4|
5| def b
6| return 1
7| end
8|
9| a()
10| a()
11| a()
12| a()
13| a()
14| a()
RUBY
end

def test_1663648816
debug_code(program) do
type 'b 11'
type 'record on'
type 'c'
assert_line_num 11
type 'step back 2' # multiple whitespaces
assert_line_num 6
type 'step back 2'
assert_line_num 10
type 'q!'
end
end
end

class StepBackWhenNumberIsLargetThanLogIndex < ConsoleTestCase
def program
<<~RUBY
1| def a
2| return b()
3| end
4|
5| def b
6| return 1
7| end
8|
9| a()
10| a()
11| a()
12| a()
13| a()
14| a()
RUBY
end

def test_1663648816
debug_code(program) do
type 'b 11'
type 'record on'
type 'c'
assert_line_num 11
type 'step back 100'
assert_line_num 5
type 'q!'
end
end
end

class RecordOnAfterStoppingOnceTest < ConsoleTestCase
def program
<<~RUBY
Expand Down