Skip to content

Commit

Permalink
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -265,6 +265,7 @@ public class Options {
public static final Option<Boolean> TRUFFLE_EXCEPTIONS_PRINT_JAVA = bool(TRUFFLE, "truffle.exceptions.print_java", false, "Print Java exceptions at the point of translating them to Ruby exceptions.");
public static final Option<Boolean> TRUFFLE_EXCEPTIONS_PRINT_UNCAUGHT_JAVA = bool(TRUFFLE, "truffle.exceptions.print_uncaught_java", false, "Print uncaught Java exceptions at the point of translating them to Ruby exceptions.");
public static final Option<Boolean> TRUFFLE_BACKTRACES_HIDE_CORE_FILES = bool(TRUFFLE, "truffle.backtraces.hide_core_files", true, "Hide core source files in backtraces, like MRI does.");
public static final Option<Boolean> TRUFFLE_BACKTRACES_INTERLEAVE_JAVA = bool(TRUFFLE, "truffle.backtraces.interleave_java", false, "Interleave Java stacktraces into the Ruby backtrace.");
public static final Option<Integer> TRUFFLE_BACKTRACES_LIMIT = integer(TRUFFLE, "truffle.backtraces.limit", 9999, "Limit the size of Ruby backtraces.");
public static final Option<Boolean> TRUFFLE_BACKTRACES_OMIT_UNUSED = bool(TRUFFLE, "truffle.backtraces.omit_unused", true, "Omit backtraces that should be unused as they have pure rescue expressions.");
public static final Option<Boolean> TRUFFLE_INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC = bool(TRUFFLE, "truffle.set_trace_func.include_core_file_callers", false, "Include internal core library calls in set_trace_func output.");
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ public Object visitFrame(FrameInstance frameInstance) {

});

if (context.getOptions().EXCEPTIONS_STORE_JAVA) {
if (context.getOptions().EXCEPTIONS_STORE_JAVA || context.getOptions().BACKTRACES_INTERLEAVE_JAVA) {
if (javaThrowable == null) {
javaThrowable = new Exception();
}
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ public class Options {
public final boolean EXCEPTIONS_PRINT_JAVA = TRUFFLE_EXCEPTIONS_PRINT_JAVA.load();
public final boolean EXCEPTIONS_PRINT_UNCAUGHT_JAVA = TRUFFLE_EXCEPTIONS_PRINT_UNCAUGHT_JAVA.load();
public final boolean BACKTRACES_HIDE_CORE_FILES = TRUFFLE_BACKTRACES_HIDE_CORE_FILES.load();
public final boolean BACKTRACES_INTERLEAVE_JAVA = TRUFFLE_BACKTRACES_INTERLEAVE_JAVA.load();
public final int BACKTRACES_LIMIT = TRUFFLE_BACKTRACES_LIMIT.load();
public final boolean BACKTRACES_OMIT_UNUSED = TRUFFLE_BACKTRACES_OMIT_UNUSED.load();
public final boolean INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC = TRUFFLE_INCLUDE_CORE_FILE_CALLERS_IN_SET_TRACE_FUNC.load();
Original file line number Diff line number Diff line change
@@ -112,6 +112,10 @@ public List<String> formatBacktrace(RubyContext context, DynamicObject exception
}
}

if (backtrace.getJavaThrowable() != null && context.getOptions().BACKTRACES_INTERLEAVE_JAVA) {
return BacktraceInterleaver.interleave(lines, backtrace.getJavaThrowable().getStackTrace());
}

return lines;
}

1 comment on commit 9766552

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nirvdrum @pitr-ch @eregon @bjfish we've had this functionality for a while, but it wasn't easy to use via an option before

$ jt run -Xtruffle.backtraces.interleave_java=true ../test.rb 
$ /Users/chrisseaton/Documents/ruby/jruby/bin/jruby -X+T -Xtruffle.core.load_path=/Users/chrisseaton/Documents/ruby/jruby/truffle/src/main/ruby -Xtruffle.graal.warn_unless=false -Xtruffle.backtraces.interleave_java=true ../test.rb
        org.jruby.truffle.core.numeric.FixnumNodes$DivNode.div(FixnumNodes.java:258)
        org.jruby.truffle.core.numeric.FixnumNodesFactory$DivNodeFactory$DivNodeGen$Div0Node_.execute_(FixnumNodesFactory.java:3441)
        org.jruby.truffle.core.numeric.FixnumNodesFactory$DivNodeFactory$DivNodeGen$BaseNode_.acceptAndExecute(FixnumNodesFactory.java:3171)
        com.oracle.truffle.api.dsl.internal.SpecializationNode.uninitialized(SpecializationNode.java:407)
        org.jruby.truffle.core.numeric.FixnumNodesFactory$DivNodeFactory$DivNodeGen$UninitializedNode_.execute_(FixnumNodesFactory.java:3346)
        org.jruby.truffle.core.numeric.FixnumNodesFactory$DivNodeFactory$DivNodeGen$BaseNode_.execute(FixnumNodesFactory.java:3179)
        org.jruby.truffle.core.numeric.FixnumNodesFactory$DivNodeFactory$DivNodeGen.execute(FixnumNodesFactory.java:3094)
        org.jruby.truffle.language.control.SequenceNode.execute(SequenceNode.java:176)
        org.jruby.truffle.language.methods.ExceptionTranslatingNode.execute(ExceptionTranslatingNode.java:50)
        org.jruby.truffle.instrument.RubyWrapperNode.execute(RubyWrapperNode.java:61)
        org.jruby.truffle.language.RubyRootNode.execute(RubyRootNode.java:47)
/Users/chrisseaton/Documents/ruby/test.rb:6:in `/': divided by 0 (ZeroDivisionError)
        com.oracle.truffle.api.impl.DefaultCallTarget.call(DefaultCallTarget.java:84)
        com.oracle.truffle.api.impl.DefaultDirectCallNode.call(DefaultDirectCallNode.java:69)
        org.jruby.truffle.language.dispatch.CachedDispatchNode.call(CachedDispatchNode.java:100)
        org.jruby.truffle.language.dispatch.CachedUnboxedDispatchNode.executeDispatch(CachedUnboxedDispatchNode.java:83)
        org.jruby.truffle.language.dispatch.UnresolvedDispatchNode.executeDispatch(UnresolvedDispatchNode.java:101)
        org.jruby.truffle.language.dispatch.DispatchHeadNode.dispatch(DispatchHeadNode.java:44)
        org.jruby.truffle.language.dispatch.CallDispatchHeadNode.call(CallDispatchHeadNode.java:34)
        org.jruby.truffle.language.dispatch.RubyCallNode.execute(RubyCallNode.java:90)
        org.jruby.truffle.instrument.RubyWrapperNode.execute(RubyWrapperNode.java:61)
        org.jruby.truffle.language.control.SequenceNode.execute(SequenceNode.java:176)
        org.jruby.truffle.language.methods.CatchForMethodNode.execute(CatchForMethodNode.java:41)
        org.jruby.truffle.language.methods.ExceptionTranslatingNode.execute(ExceptionTranslatingNode.java:50)
        org.jruby.truffle.instrument.RubyWrapperNode.execute(RubyWrapperNode.java:61)
        org.jruby.truffle.language.RubyRootNode.execute(RubyRootNode.java:47)
    from /Users/chrisseaton/Documents/ruby/test.rb:6:in `bar'
        com.oracle.truffle.api.impl.DefaultCallTarget.call(DefaultCallTarget.java:84)
        com.oracle.truffle.api.impl.DefaultDirectCallNode.call(DefaultDirectCallNode.java:69)
        org.jruby.truffle.language.dispatch.CachedDispatchNode.call(CachedDispatchNode.java:100)
        org.jruby.truffle.language.dispatch.CachedSingletonDispatchNode.executeDispatch(CachedSingletonDispatchNode.java:88)
        org.jruby.truffle.language.dispatch.UnresolvedDispatchNode.executeDispatch(UnresolvedDispatchNode.java:101)
        org.jruby.truffle.language.dispatch.DispatchHeadNode.dispatch(DispatchHeadNode.java:44)
        org.jruby.truffle.language.dispatch.CallDispatchHeadNode.call(CallDispatchHeadNode.java:34)
        org.jruby.truffle.language.dispatch.RubyCallNode.execute(RubyCallNode.java:90)
        org.jruby.truffle.instrument.RubyWrapperNode.execute(RubyWrapperNode.java:61)
        org.jruby.truffle.language.control.SequenceNode.execute(SequenceNode.java:176)
        org.jruby.truffle.language.methods.CatchForMethodNode.execute(CatchForMethodNode.java:41)
        org.jruby.truffle.language.methods.ExceptionTranslatingNode.execute(ExceptionTranslatingNode.java:50)
        org.jruby.truffle.instrument.RubyWrapperNode.execute(RubyWrapperNode.java:61)
        org.jruby.truffle.language.RubyRootNode.execute(RubyRootNode.java:47)
    from /Users/chrisseaton/Documents/ruby/test.rb:2:in `foo'
        com.oracle.truffle.api.impl.DefaultCallTarget.call(DefaultCallTarget.java:84)
        com.oracle.truffle.api.impl.DefaultDirectCallNode.call(DefaultDirectCallNode.java:69)
        org.jruby.truffle.language.dispatch.CachedDispatchNode.call(CachedDispatchNode.java:100)
        org.jruby.truffle.language.dispatch.CachedSingletonDispatchNode.executeDispatch(CachedSingletonDispatchNode.java:88)
        org.jruby.truffle.language.dispatch.UnresolvedDispatchNode.executeDispatch(UnresolvedDispatchNode.java:101)
        org.jruby.truffle.language.dispatch.DispatchHeadNode.dispatch(DispatchHeadNode.java:44)
        org.jruby.truffle.language.dispatch.CallDispatchHeadNode.call(CallDispatchHeadNode.java:34)
        org.jruby.truffle.language.dispatch.RubyCallNode.execute(RubyCallNode.java:90)
        org.jruby.truffle.instrument.RubyWrapperNode.execute(RubyWrapperNode.java:61)
        org.jruby.truffle.language.control.SequenceNode.execute(SequenceNode.java:176)
        org.jruby.truffle.language.methods.CatchNextNode.execute(CatchNextNode.java:36)
        org.jruby.truffle.language.methods.CatchReturnAsErrorNode.execute(CatchReturnAsErrorNode.java:35)
        org.jruby.truffle.language.methods.CatchRetryAsErrorNode.execute(CatchRetryAsErrorNode.java:32)
        org.jruby.truffle.language.control.SequenceNode.execute(SequenceNode.java:176)
        org.jruby.truffle.language.exceptions.TopLevelRaiseHandler.execute(TopLevelRaiseHandler.java:41)
        org.jruby.truffle.instrument.RubyWrapperNode.execute(RubyWrapperNode.java:61)
        org.jruby.truffle.language.RubyRootNode.execute(RubyRootNode.java:47)
    from /Users/chrisseaton/Documents/ruby/test.rb:9:in `<main>'
FAILED (pid 5937 exit 1): /Users/chrisseaton/Documents/ruby/jruby/bin/jruby -X+T -Xtruffle.core.load_path=/Users/chrisseaton/Documents/ruby/jruby/truffle/src/main/ruby -Xtruffle.graal.warn_unless=false -Xtruffle.backtraces.interleave_java=true ../test.rb

Please sign in to comment.