From: "Eregon (Benoit Daloze) via ruby-core" Date: 2023-01-24T14:35:00+00:00 Subject: [ruby-core:112009] [Ruby master Feature#15778] Expose an API to pry-open the stack frames in Ruby Issue #15778 has been updated by Eregon (Benoit Daloze). gsamokovarov (Genadi Samokovarov) wrote in #note-16: > What if we settle for an API and implement and test it first in the `debug` gem? The `debug` gem does need/has similar functionality for post-mortem debugging. That way, gems like `web-console` can depend on the `debug` standard gem which I would expect more people to have, instead of using custom C extension. Other tooling can get debug APIs from the `debug` gem as well. It seems like a good place to start because we can test the APIs in real project and get real feedback. One concern I have about that is currently the `debug` gem only supports CRuby, and uses some CRuby-private APIs under RubyVM (I filed https://github.com/ruby/debug/issues/887). I think that should be fixed at some point as I don't think the usages of RubyVM are critical in the `debug` gem, but that work is not done and it's hard to be sure until then. I would advise to use https://github.com/banister/debug_inspector instead of the `debug` gem if you need this functionality. That's a gem literally just to expose that API. It should work fine on TruffleRuby since TruffleRuby support the debug_inspector C API, I'll make a PR there. Not sure about JRuby, but JRuby devs could probably add support in that gem too. ---------------------------------------- Feature #15778: Expose an API to pry-open the stack frames in Ruby https://bugs.ruby-lang.org/issues/15778#change-101442 * Author: gsamokovarov (Genadi Samokovarov) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) ---------------------------------------- Hello, I'm the maintainer of the web-console (https://github.com/rails/web-console/) gem, where one of our features is to jump between the frames in which an error occurred. To accomplish this, I currently use the Debug Inspector CRuby API. I think we should expose this functionality in Rubyland, so tools like web-console don't need to resort to C code for this. This also makes it quite harder for me to support different implementations like JRuby or TruffleRuby as everyone is having a different way to create Ruby Binding objects that represent the frames. Here the API ideas: Add `Thread::Backtrace::Location#binding` method that can create a binding for a specific caller of the current frame. We can reuse the existing `Kernel.caller_locations` method to generate the array of `Thread::Backtrace::Location` objects. We can optionally have the `Kernel.caller_locations(debug: true)` argument if we cannot generate the bindings lazily on the VM that can instruct the VM to do the slower operation. - `Thread::Backtrace::Location#binding` returns `Binding|nil`. Nil result may mean that the current location is a C frame or a JITted/optimized frame and we cannot debug it. We can also expose the DebugInspector API directly, as done in the https://github.com/banister/debug_inspector gem, but for tools like web-console, we'd need to map the bindings with the backtrace, as we cannot generate Bindings for every frame (C frames) and this needs to be done in application code, so I think the `Thread::Backtrace::Location#binding` is the better API for Ruby-land. Such API can help us eventually write most of our debuggers in Ruby as right now we don't have a way to do Post-Mortem debugging without native code or even start our debuggers without monkey-patching `Binding`. I have presented this idea in a RubyKaigi's 2019 talk called "Writing Debuggers in Plain Ruby", you can check-out the slides for more context: http://kaigi-debuggers-in-ruby.herokuapp.com. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/