Skip to content

Instantly share code, notes, and snippets.

@headius
Created January 24, 2020 17:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/39cafe3307db887285aba3000ad3c19f to your computer and use it in GitHub Desktop.
Save headius/39cafe3307db887285aba3000ad3c19f to your computer and use it in GitHub Desktop.
Using JDB to debug Ruby and JRuby code together
[] ~/projects/jruby $ jdb -Djruby.home=`pwd` -sourcepath `pwd` -classpath lib/jruby.jar
Initializing jdb ...
> stop at blah:1
Deferring breakpoint blah:1.
It will be set after the class is loaded.
> run org.jruby.Main blah.rb
run org.jruby.Main blah.rb
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started: Set deferred breakpoint blah:1
Breakpoint hit: "thread=main", blah.RUBY$script(), line=1 bci=23
1 def foo
main[1] list
1 => def foo
2 puts 1
3 end
4
5 foo
main[1] step
>
Step completed: "thread=main", org.jruby.runtime.Helpers.restoreScope(), line=1,772 bci=0
main[1] list
Source file not found: Helpers.java
main[1] use core/src/main/java
main[1] list
1,768 return descriptor;
1,769 }
1,770
1,771 public static StaticScope restoreScope(String descriptor, StaticScope enclosingScope) {
1,772 => String[] bits = descriptor.split(";");
1,773
1,774 StaticScope.Type type = StaticScope.Type.valueOf(bits[0]);
1,775 String file = bits[1];
1,776
1,777 String[] varNames = bits[2].split(",");
main[1]
@aryeh-looker
Copy link

aryeh-looker commented Oct 27, 2020

This is really great. Are there any known ways to get this when in a breakpoint in Java-land with IntelliJ?

@headius
Copy link
Author

headius commented Oct 28, 2020

Well the only real issue, I think, is that you can't add the system root as a source dir in an IntelliJ project, but the bytecode we generate uses full paths. I have been hoping to change that, however, by using a relative path. Maybe it's worth doing now?

@aryeh-looker
Copy link

Oh interesting — could be. I don't know enough about the IntelliJ guts, but glad to help in any way I can; this sounds tentatively right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment