debug_inspector icon indicating copy to clipboard operation
debug_inspector copied to clipboard

Use an offset to hide extra frames on TruffleRuby?

Open eregon opened this issue 2 years ago • 0 comments

Currently:

$ ruby -v -rdebug_inspector -e 'tap { 1.times { DebugInspector.open { |dc| pp dc.backtrace_locations; p dc.frame_binding(1) } } }'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
["-e:1:in `open'",
 "-e:1:in `block (2 levels) in <main>'",
 "-e:1:in `times'",
 "-e:1:in `block in <main>'",
 "<internal:kernel>:90:in `tap'",
 "-e:1:in `<main>'"]
#<Binding:0x00007fa9fa275dc0>
$ ruby -v -rdebug_inspector -e 'tap { 1.times { DebugInspector.open { |dc| pp dc.backtrace_locations; p dc.frame_binding(3) } } }'
truffleruby 24.0.0-dev-4cd14c48, like ruby 3.2.2, GraalVM CE Native [x86_64-linux]
["/home/eregon/.rubies/truffleruby-dev/lib/truffle/truffle/cext.rb:1750:in `rb_ensure'",
 "exception.c:107:in `rb_ensure'",
 "/home/eregon/.rubies/truffleruby-dev/lib/truffle/truffle/cext_ruby.rb:40:in `open'",
 "-e:1:in `block (2 levels) in <main>'",
 "<internal:core> core/integer.rb:148:in `times'",
 "-e:1:in `block in <main>'",
 "<internal:core> core/kernel.rb:517:in `tap'",
 "-e:1:in `<main>'"]
#<Binding:0xbf8>

So there are 2 more frames on TruffleRuby due to the call to rb_ensure() which is actually part of the stacktrace, unlike on CRuby.

We could potentially try to apply an offset in this C extension to hide this. OTOH, people might want to filter the open call and maybe even some callers, in which case such filtering code would work for both without any changes. Example of such filtering: https://github.com/banister/debug_inspector/blob/582251ce778213e4f5fc18478905b0b3404994de/test/basic_test.rb#L5-L7

eregon avatar Dec 12 '23 13:12 eregon