Skip to content

Commit 4cc39b3

Browse files
committed
support reloaded breakpoints
When 'foo.rb' is reloaded, then already set breakponts on 'foo.rb' is also enabled on reloaded 'foo.rb'. Note that this is only for the line breakpoints. fix #662
1 parent 6725afa commit 4cc39b3

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

lib/debug/breakpoint.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,17 @@ def enable
131131
end
132132

133133
class LineBreakpoint < Breakpoint
134-
attr_reader :path, :line, :iseq
134+
attr_reader :path, :line, :iseq, :cond, :oneshot, :hook_call, :command
135135

136-
def initialize path, line, cond: nil, oneshot: false, hook_call: true, command: nil
136+
def self.copy bp, root_iseq
137+
nbp = LineBreakpoint.new bp.path, bp.line,
138+
cond: bp.cond, oneshot: bp.oneshot, hook_call: bp.hook_call,
139+
command: bp.command, skip_activate: true
140+
nbp.try_activate root_iseq
141+
nbp
142+
end
143+
144+
def initialize path, line, cond: nil, oneshot: false, hook_call: true, command: nil, skip_activate: false
137145
@line = line
138146
@oneshot = oneshot
139147
@hook_call = hook_call
@@ -146,7 +154,7 @@ def initialize path, line, cond: nil, oneshot: false, hook_call: true, command:
146154

147155
super(cond, command, path)
148156

149-
try_activate
157+
try_activate unless skip_activate
150158
@pending = !@iseq
151159
end
152160

lib/debug/session.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,7 @@ def in_subsession?
15891589

15901590
def on_load iseq, src
15911591
DEBUGGER__.info "Load #{iseq.absolute_path || iseq.path}"
1592+
15921593
file_path, reloaded = @sr.add(iseq, src)
15931594
@ui.event :load, file_path, reloaded
15941595

@@ -1601,6 +1602,17 @@ def on_load iseq, src
16011602
bp.try_activate iseq
16021603
end
16031604
end
1605+
1606+
if reloaded
1607+
@bps.find_all do |key, bp|
1608+
LineBreakpoint === bp && DEBUGGER__.compare_path(bp.path, file_path)
1609+
end.each do |_key, bp|
1610+
@bps.delete bp.key # to allow duplicate
1611+
if nbp = LineBreakpoint.copy(bp, iseq)
1612+
add_bp nbp
1613+
end
1614+
end
1615+
end
16041616
end
16051617

16061618
def resolve_path file

test/console/break_test.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,4 +748,44 @@ def test_the_path_option_supersede_skip_path_config
748748
end
749749
end
750750
end
751+
752+
class BreakAtLinesReloadTest < ConsoleTestCase
753+
def extra_file
754+
<<~RUBY
755+
def foo # 1
756+
a = 10 # 2
757+
b = 20 # 3
758+
c = 30 # 4
759+
end
760+
RUBY
761+
end
762+
763+
def program path
764+
<<~RUBY
765+
1| load #{path.dump}
766+
2| foo()
767+
3| load #{path.dump}
768+
4| foo()
769+
RUBY
770+
end
771+
772+
def test_break_on_realoded_file
773+
with_extra_tempfile do |extra_file|
774+
debug_code(program(extra_file.path)) do
775+
type "break #{extra_file.path}:2 do: p :xyzzy"
776+
type "break #{extra_file.path}:3"
777+
778+
type 'c'
779+
assert_line_num 3
780+
assert_line_text(/xyzzy/)
781+
782+
type 'c'
783+
assert_line_num 3 # should stop at reloaded file
784+
assert_line_text(/xyzzy/) # should do at line 2
785+
786+
type 'c'
787+
end
788+
end
789+
end
790+
end
751791
end

0 commit comments

Comments
 (0)