ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: eregontp@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:94069] [Ruby master Feature#15778] Expose an API to pry-open the stack frames in Ruby
Date: Wed, 31 Jul 2019 09:37:29 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-80299.20190731093729.31bb2ef025010afd@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15778.20190420022749@ruby-lang.org

Issue #15778 has been updated by Eregon (Benoit Daloze).


ko1 (Koichi Sasada) wrote:
> I heard that one advantage that current `debug_inspector` gem has is we can declare the usage of this API in Gemfile. It means that we can avoid some kind of vulnerable feature in production explicitly.

I see. Although the `rb_debug_inspector_open()` C API is still there (and could be called, e.g., via Fiddle I imagine).

`Proc#binding` in Ruby also gives access to local variables potentially far from the current method.
Similarly, `TracePoint#binding` already allows to read values from all over the program.
That's why I think it's necessary to assume that the attacker cannot call arbitrary methods.

So I think having the `caller_locations(debug: true)` API is safe enough.
If the attacker can call `caller_locations` and pass it the extra :debug argument, then I think anyway all is already lost, they might as well #eval, #system, #exit, etc.

I'd like to introduce this new keyword argument for `caller_locations`, it's one of the main features missing, and hiding it in the C API is not much of a safety, but it makes it inconvenient to use, inefficient (see above) and not portable (e.g., cannot be implemented on JRuby as a C API).

----------------------------------------
Feature #15778: Expose an API to pry-open the stack frames in Ruby
https://bugs.ruby-lang.org/issues/15778#change-80299

* Author: gsamokovarov (Genadi Samokovarov)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
----------------------------------------
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/

  parent reply	other threads:[~2019-07-31  9:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15778.20190420022749@ruby-lang.org>
2019-04-20  2:27 ` [ruby-core:92338] [Ruby trunk Feature#15778] Expose an API to pry-open the stack frames in Ruby gsamokovarov
2019-04-20 10:21 ` [ruby-core:92340] " chris
2019-04-20 14:36 ` [ruby-core:92345] " eregontp
2019-04-20 14:43 ` [ruby-core:92346] " eregontp
2019-04-20 15:12 ` [ruby-core:92347] " chris
2019-04-20 15:49 ` [ruby-core:92348] " gsamokovarov
2019-04-24  7:46 ` [ruby-core:92397] " ko1
2019-04-26 13:55 ` [ruby-core:92420] " eregontp
2019-04-29 16:22 ` [ruby-core:92480] " gsamokovarov
2019-05-15  9:10 ` [ruby-core:92654] " eregontp
2019-07-14  6:05 ` [ruby-core:93746] [Ruby master " ko1
2019-07-31  9:37 ` eregontp [this message]
2019-08-29  6:24 ` [ruby-core:94647] " duerst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-80299.20190731093729.31bb2ef025010afd@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).