oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.01k stars 184 forks source link

Debugging truffleruby with RubyMine / debase gem #2817

Open AhlamHani opened 1 year ago

AhlamHani commented 1 year ago

I tried to follow those debugging guidelines, they are not really helpful

https://github.com/oracle/truffleruby/blob/master/doc/contributor/debugging.md

I maybe not getting the context of this document or understanding it correctly! but I couldn't find out yet how to run debugging with rubymine on trufflerruby or GraalVM and I feel like that document is outdated, RubyMine uses debase gem to debug, but the author of debase said, it's not for trufflerruby! https://github.com/ruby-debug/debase/issues/76#issuecomment-1333213129

also another ticket was opened since 2019 about debase but no answers! https://github.com/oracle/truffleruby/issues/1861

is there any tool to debug truffleruby like MRI ?? either using debase (RubyMine) debugger or at least a terminal debugger !

nirvdrum commented 1 year ago

The document you linked to is from the contributor guide. It's about debugging the TruffleRuby runtime for those developing TruffleRuby. I'll update #1861, but it looks like it was just overlooked. The debase gem, in its current form, will not work. Ruby does not have a standard debugger interface, so tools like debase are implemented as native extensions that dig into CRuby's internals. TruffleRuby does implement much of the CRuby native extension API, but we can't meaningfully implement things that are CRuby-specific.

To get the debase gem working, we'd have to implement a new backend for it that matches the Ruby API for the gem, but uses TruffleRuby's debugging interface. It's unfortunate that RubyMine doesn't currently support TruffleRuby. Ideally, RubyMine would add a new implementation of its debugger to work with the Truffle instrumentation framework. That's how RubyMine handles JRuby for instance, as debase won't work on JRuby either.

You simply won't be able to debug applications in RubyMine with TruffleRuby today. We do have support for Visual Studio Code through the GraalVM Tools for Java extension. The extension name is misleading (for historical reasons), but I think will be renamed soon. I know switching tools isn't ideal. One big benefit of using the VS Code extension, however, is that you can also debug native extensions in the same process. I.e., you'll be able to step from Ruby code directly into C code and back out again.

eregon commented 1 year ago

As @nirvdrum said, and from https://github.com/oracle/truffleruby/issues/1861#issuecomment-1369879140:

debase relies on debase-ruby_core_source, i.e., implementation details which are not supposed to be used even for CRuby. So it does not seem reasonable or possible to get debase to work on anything but CRuby.

To debug TruffleRuby with RubyMine, the missing piece is the Debug Adapter Protocol in RubyMine/IntelliJ. Until then VSCode can be used, see https://www.graalvm.org/latest/tools/vscode/graalvm-extension/polyglot-runtime/#debugging-ruby

We should update https://github.com/oracle/truffleruby/blob/master/doc/user/debugging.md and https://github.com/oracle/truffleruby/blob/master/doc/user/tools.md to link to that.

eregon commented 1 year ago

I have filed an issue on the RubyMine tracker: https://youtrack.jetbrains.com/issue/RUBY-30772 Please vote or comment on it to share your interest.