Skip to content

Commit b62a4d7

Browse files
committed
Use TracePoint.allow_reentry when available
This fixes compatibility with TracePoint users such as Zeitwerk Test script: ```ruby require 'fileutils' FileUtils.mkdir_p('/tmp/lib/foo') File.write('/tmp/lib/foo.rb', 'module Foo; end') File.write('/tmp/lib/foo/bar.rb', 'Foo::Bar = 1') require 'zeitwerk' loader = Zeitwerk::Loader.new loader.push_dir('/tmp/lib') loader.setup require 'debug' binding.break p Foo::Bar ``` before: ``` [8, 16] in /tmp/debug-zeitwerk.rb 8| loader = Zeitwerk::Loader.new 9| loader.push_dir('/tmp/lib') 10| loader.setup 11| 12| require 'debug' => 13| binding.break 14| p Foo::Bar 15| 16| p :done =>#0 <main> at /tmp/debug-zeitwerk.rb:13 (rdbg) p Foo::Bar # command eval error: uninitialized constant Foo::Bar (rdbg)//tmp/debug-zeitwerk.rb:1:in `<main>' => nil ``` after: ``` [8, 16] in /tmp/debug-zeitwerk.rb 8| loader = Zeitwerk::Loader.new 9| loader.push_dir('/tmp/lib') 10| loader.setup 11| 12| require 'debug' => 13| binding.break 14| p Foo::Bar 15| 16| p :done =>#0 <main> at /tmp/debug-zeitwerk.rb:13 (rdbg) p Foo::Bar # command => 1 ```
1 parent a21742d commit b62a4d7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/debug/thread_client.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,11 @@ def frame_eval src, re_raise: false
367367

368368
result = if b
369369
f, _l = b.source_location
370-
b.eval(src, "(rdbg)/#{f}")
370+
if TracePoint.respond_to?(:allow_reentry)
371+
TracePoint.allow_reentry { b.eval(src, "(rdbg)/#{f}") }
372+
else
373+
b.eval(src, "(rdbg)/#{f}")
374+
end
371375
else
372376
frame_self = current_frame.self
373377
instance_eval_for_cmethod(frame_self, src)
@@ -406,9 +410,9 @@ def show_src(frame_index: @current_frame_index,
406410
unless start_line
407411
if frame.show_line
408412
if dir > 0
409-
start_line = frame.show_line
413+
start_line = frame.show_line.lineno
410414
else
411-
end_line = frame.show_line - max_lines
415+
end_line = frame.show_line.lineno - max_lines
412416
start_line = [end_line - max_lines, 0].max
413417
end
414418
else

0 commit comments

Comments
 (0)