Skip to content

Commit

Permalink
Enable "step back <n>" while replay
Browse files Browse the repository at this point in the history
  • Loading branch information
ono-max committed Oct 29, 2022
1 parent 3fec2d9 commit 9c81db8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
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
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

0 comments on commit 9c81db8

Please sign in to comment.