Skip to content

Commit

Permalink
fix break line check algorithm
Browse files Browse the repository at this point in the history
If specify the break line on the method definition, it stops at
the beggining of method at called time (don't stop at method
definition timing).

The line check algorithm has a bug and this patch fix it.
  • Loading branch information
ko1 committed Nov 25, 2022
1 parent 64dae96 commit 6def10a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/debug/breakpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,10 @@ def try_activate root_iseq = nil

if !nearest || ((line - nline).abs < (line - nearest.line).abs)
nearest = NearestISeq.new(iseq, nline, events)
else
if @hook_call && nearest.iseq.first_lineno <= iseq.first_lineno
if (nearest.line > line && !nearest.events.include?(:RUBY_EVENT_CALL)) ||
(events.include?(:RUBY_EVENT_CALL))
nearest = NearestISeq.new(iseq, nline, events)
end
end
elsif @hook_call &&
nearest.line == iseq.first_line &&
events.include?(:RUBY_EVENT_CALL)
nearest = NearestISeq.new(iseq, nline, events)
end
end
end
Expand Down
85 changes: 85 additions & 0 deletions test/console/break_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -838,4 +838,89 @@ def test_break_on_realoded_file
end
end
end

class BreakAtLineTest < ConsoleTestCase
def program path
<<~RUBY
1| load #{path.dump}
RUBY
end

def extra_file
<<~RUBY
a = 1
class C
def m
p :m
end
end
RUBY
end

def test_break_on_line
with_extra_tempfile do |extra_file|
debug_code program(extra_file.path) do
type "break #{extra_file.path}:1"
type 'c'
assert_line_num 1
type 'c'
end
end
end

def program2
<<~RUBY
1| a = 1
2| b = 2 # braek 2, stop at 2
3| # break 3, stop at def
4| def foo # break 4, stop at 5 (in foo)
5| a = 2
6| end
7|
8| private def bar # break 8, stop at 9 (in bar)
9| a = 3
10| end
11|
12| foo
13| bar
RUBY
end

def test_break_on_line_2
debug_code program2 do
type 'b 2'
type 'c'
assert_line_num 2
type 'c'
end
end

def test_break_on_line_3
debug_code program2 do
type 'b 3'
type 'c'
assert_line_num 4
type 'c'
end
end

def test_break_on_line_4
debug_code program2 do
type 'b 4'
type 'c'
assert_line_num 5
type 'c'
end
end

def test_break_on_line_8
debug_code program2 do
type 'b 8'
type 'c'
assert_line_num 9
type 'c'
end
end
end
end

0 comments on commit 6def10a

Please sign in to comment.