Skip to content

Commit

Permalink
Disable clone breakpoints trace point events
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored and ko1 committed Sep 25, 2023
1 parent 3d822a1 commit d93e108
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1739,15 +1739,19 @@ def on_load iseq, src
# check breakpoints
if file_path
@bps.find_all do |_key, bp|
LineBreakpoint === bp && bp.path_is?(file_path)
LineBreakpoint === bp && bp.path_is?(file_path) && (iseq.first_lineno..iseq.last_line).cover?(bp.line)
end.each do |_key, bp|
if !bp.iseq
bp.try_activate iseq
elsif reloaded
@bps.delete bp.key # to allow duplicate
if nbp = LineBreakpoint.copy(bp, iseq)
add_bp nbp
end

# When we delete a breakpoint from the @bps hash, we also need to deactivate it or else its tracepoint event
# will continue to be enabled and we'll suspend on ghost breakpoints
bp.delete

nbp = LineBreakpoint.copy(bp, iseq)
add_bp nbp
end
end
else # !file_path => file_path is not existing
Expand Down
28 changes: 28 additions & 0 deletions test/console/break_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,34 @@ def test_break_on_reloaded_file
type 'c'
end
end

def test_removing_breakpoint_on_reloaded_file
code = <<~'DEBUG_CODE'
1| require 'tempfile'
2| tf = Tempfile.new('debug_gem_test', mode: File::TRUNC)
3| tf.write(<<~RUBY)
4| def foo
5| "hello"
6| end
7| RUBY
8| tf.close
9| load tf.path
10| alias bar foo
11| debugger do: "b #{tf.path}:2"
12| bar
13| load tf.path
14| bar
15| load tf.path
16| bar
DEBUG_CODE

debug_code code do
type "c"
assert_line_num 2

type "c"
end
end
end

class BreakAtLineTest < ConsoleTestCase
Expand Down

0 comments on commit d93e108

Please sign in to comment.