Skip to content

Commit 6725afa

Browse files
committed
LineBreakpoint#try_activate accepts iseq
For the pending line breakpoint, `try_activate` is called when script is compiled and compiled iseq is available. We don't need to search in ObjectSpace on this case.
1 parent 093ef24 commit 6725afa

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

lib/debug/breakpoint.rb

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -216,42 +216,56 @@ def duplicable?
216216

217217
NearestISeq = Struct.new(:iseq, :line, :events)
218218

219-
def try_activate
220-
nearest = nil # NearestISeq
221-
222-
ObjectSpace.each_iseq{|iseq|
223-
if DEBUGGER__.compare_path((iseq.absolute_path || iseq.path), self.path) &&
224-
iseq.first_lineno <= self.line &&
225-
iseq.type != :ensure # ensure iseq is copied (duplicated)
219+
def iterate_iseq root_iseq
220+
if root_iseq
221+
is = [root_iseq]
222+
while iseq = is.pop
223+
yield iseq
224+
iseq.each_child do |child_iseq|
225+
is << child_iseq
226+
end
227+
end
228+
else
229+
ObjectSpace.each_iseq do |iseq|
230+
if DEBUGGER__.compare_path((iseq.absolute_path || iseq.path), self.path) &&
231+
iseq.first_lineno <= self.line &&
232+
iseq.type != :ensure # ensure iseq is copied (duplicated)
233+
yield iseq
234+
end
235+
end
236+
end
237+
end
226238

227-
iseq.traceable_lines_norec(line_events = {})
228-
lines = line_events.keys.sort
239+
def try_activate root_iseq = nil
240+
nearest = nil # NearestISeq
241+
iterate_iseq root_iseq do |iseq|
242+
iseq.traceable_lines_norec(line_events = {})
243+
lines = line_events.keys.sort
229244

230-
if !lines.empty? && lines.last >= line
231-
nline = lines.bsearch{|l| line <= l}
232-
events = line_events[nline]
245+
if !lines.empty? && lines.last >= line
246+
nline = lines.bsearch{|l| line <= l}
247+
events = line_events[nline]
233248

234-
next if events == [:RUBY_EVENT_B_CALL]
249+
next if events == [:RUBY_EVENT_B_CALL]
235250

236-
if @hook_call &&
237-
events.include?(:RUBY_EVENT_CALL) &&
238-
self.line == iseq.first_lineno
239-
nline = iseq.first_lineno
240-
end
251+
if @hook_call &&
252+
events.include?(:RUBY_EVENT_CALL) &&
253+
self.line == iseq.first_lineno
254+
nline = iseq.first_lineno
255+
end
241256

242-
if !nearest || ((line - nline).abs < (line - nearest.line).abs)
243-
nearest = NearestISeq.new(iseq, nline, events)
244-
else
245-
if @hook_call && nearest.iseq.first_lineno <= iseq.first_lineno
246-
if (nearest.line > line && !nearest.events.include?(:RUBY_EVENT_CALL)) ||
247-
(events.include?(:RUBY_EVENT_CALL))
248-
nearest = NearestISeq.new(iseq, nline, events)
249-
end
257+
if !nearest || ((line - nline).abs < (line - nearest.line).abs)
258+
nearest = NearestISeq.new(iseq, nline, events)
259+
else
260+
if @hook_call && nearest.iseq.first_lineno <= iseq.first_lineno
261+
if (nearest.line > line && !nearest.events.include?(:RUBY_EVENT_CALL)) ||
262+
(events.include?(:RUBY_EVENT_CALL))
263+
nearest = NearestISeq.new(iseq, nline, events)
250264
end
251265
end
252266
end
253267
end
254-
}
268+
end
255269

256270
if nearest
257271
activate_exact nearest.iseq, nearest.events, nearest.line

lib/debug/session.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ def on_load iseq, src
15981598

15991599
pending_line_breakpoints.each do |_key, bp|
16001600
if DEBUGGER__.compare_path(bp.path, (iseq.absolute_path || iseq.path))
1601-
bp.try_activate
1601+
bp.try_activate iseq
16021602
end
16031603
end
16041604
end

0 commit comments

Comments
 (0)