File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -1739,15 +1739,19 @@ def on_load iseq, src
17391739 # check breakpoints
17401740 if file_path
17411741 @bps . find_all do |_key , bp |
1742- LineBreakpoint === bp && bp . path_is? ( file_path )
1742+ LineBreakpoint === bp && bp . path_is? ( file_path ) && ( iseq . first_lineno .. iseq . last_line ) . cover? ( bp . line )
17431743 end . each do |_key , bp |
17441744 if !bp . iseq
17451745 bp . try_activate iseq
17461746 elsif reloaded
17471747 @bps . delete bp . key # to allow duplicate
1748- if nbp = LineBreakpoint . copy ( bp , iseq )
1749- add_bp nbp
1750- end
1748+
1749+ # When we delete a breakpoint from the @bps hash, we also need to deactivate it or else its tracepoint event
1750+ # will continue to be enabled and we'll suspend on ghost breakpoints
1751+ bp . delete
1752+
1753+ nbp = LineBreakpoint . copy ( bp , iseq )
1754+ add_bp nbp
17511755 end
17521756 end
17531757 else # !file_path => file_path is not existing
Original file line number Diff line number Diff line change @@ -873,6 +873,34 @@ def test_break_on_reloaded_file
873873 type 'c'
874874 end
875875 end
876+
877+ def test_removing_breakpoint_on_reloaded_file
878+ code = <<~'DEBUG_CODE'
879+ 1| require 'tempfile'
880+ 2| tf = Tempfile.new('debug_gem_test', mode: File::TRUNC)
881+ 3| tf.write(<<~RUBY)
882+ 4| def foo
883+ 5| "hello"
884+ 6| end
885+ 7| RUBY
886+ 8| tf.close
887+ 9| load tf.path
888+ 10| alias bar foo
889+ 11| debugger do: "b #{tf.path}:2"
890+ 12| bar
891+ 13| load tf.path
892+ 14| bar
893+ 15| load tf.path
894+ 16| bar
895+ DEBUG_CODE
896+
897+ debug_code code do
898+ type "c"
899+ assert_line_num 2
900+
901+ type "c"
902+ end
903+ end
876904 end
877905
878906 class BreakAtLineTest < ConsoleTestCase
You can’t perform that action at this time.
0 commit comments