Skip to content

Commit ea383be

Browse files
committed
Prevent ghost breakpoints by making sure we can't have dangling tracepoints
Any time we disable a breakpoint or re-set the `tp` instance variable, we need to make sure any previous trace points are disabled or else they might continue to suspend execution even after breakpoint removal
1 parent 1450ad0 commit ea383be

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/debug/breakpoint.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ def initialize path, line, cond: nil, oneshot: false, hook_call: true, command:
162162
def setup
163163
return unless @type
164164

165+
# There are scenarios where `setup` is invoked more than once. If we don't disable any possible previous trace
166+
# point events, then we will update the `@tp` reference with a new instance but the previous one will still be
167+
# activated, leading to the debugger suspending in breakpoints that were previously removed
168+
disable
169+
165170
@tp = TracePoint.new(@type) do |tp|
166171
if @cond
167172
next unless safe_eval tp.binding, @cond

lib/debug/session.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,11 +1747,15 @@ def on_load iseq, src
17471747
end.each do |_key, bp|
17481748
if !bp.iseq
17491749
bp.try_activate iseq
1750-
elsif reloaded
1750+
elsif reloaded && (iseq.first_lineno..iseq.last_line).cover?(bp.line)
17511751
@bps.delete bp.key # to allow duplicate
1752-
if nbp = LineBreakpoint.copy(bp, iseq)
1753-
add_bp nbp
1754-
end
1752+
1753+
# When we delete a breakpoint from the @bps hash, we also need to deactivate it or else its tracepoint event
1754+
# will continue to be enabled and we'll suspend on ghost breakpoints
1755+
bp.delete
1756+
1757+
nbp = LineBreakpoint.copy(bp, iseq)
1758+
add_bp nbp
17551759
end
17561760
end
17571761
else # !file_path => file_path is not existing

0 commit comments

Comments
 (0)