From 3929fc8641faa9c80d6593ee4b9634b0dd7a632d Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Mon, 12 Dec 2016 13:11:16 +0100 Subject: [PATCH] more resilient Utils.dumpFrame --- .../com/oracle/truffle/r/runtime/Utils.java | 84 +++++++++++-------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java index 2562d2a0cb..f4f61fb5ed 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java @@ -550,48 +550,58 @@ public final class Utils { } private static void dumpFrame(StringBuilder str, CallTarget callTarget, Frame frame, boolean printFrameSlots, boolean isVirtual) { - if (str.length() > 0) { - str.append("\n"); - } - Frame unwrapped = RArguments.unwrap(frame); - if (!RArguments.isRFrame(unwrapped)) { - if (unwrapped.getArguments().length == 0) { - str.append("<empty frame>"); - } else { - str.append("<unknown frame>"); - } - } else { - if (callTarget.toString().equals("<promise>")) { - /* these have the same depth as the next frame, and add no useful info. */ - return; - } - RCaller call = RArguments.getCall(unwrapped); - if (call != null) { - String callSrc = call.isValidCaller() ? RContext.getRRuntimeASTAccess().getCallerSource(call) : "<invalid call>"; - int depth = RArguments.getDepth(unwrapped); - str.append("Frame(d=").append(depth).append("): ").append(callTarget).append(isVirtual ? " (virtual)" : ""); - str.append(" (called as: ").append(callSrc).append(')'); + try { + CompilerAsserts.neverPartOfCompilation(); + if (str.length() > 0) { + str.append("\n"); } - if (printFrameSlots) { - FrameDescriptor frameDescriptor = unwrapped.getFrameDescriptor(); - for (FrameSlot s : frameDescriptor.getSlots()) { - str.append("\n ").append(s.getIdentifier()).append(" = "); - Object value = unwrapped.getValue(s); - try { - if (value instanceof RAbstractContainer && ((RAbstractContainer) value).getLength() > 32) { - str.append('<').append(value.getClass().getSimpleName()).append(" with ").append(((RAbstractContainer) value).getLength()).append(" elements>"); - } else { - String text = String.valueOf(value); - str.append(text.length() < 256 ? text : text.substring(0, 256) + "..."); + Frame unwrapped = RArguments.unwrap(frame); + if (!RArguments.isRFrame(unwrapped)) { + if (unwrapped.getArguments().length == 0) { + str.append("<empty frame>"); + } else { + str.append("<unknown frame>"); + } + } else { + if (callTarget.toString().equals("<promise>")) { + /* these have the same depth as the next frame, and add no useful info. */ + return; + } + RCaller call = RArguments.getCall(unwrapped); + if (call != null) { + String callSrc = call.isValidCaller() ? RContext.getRRuntimeASTAccess().getCallerSource(call) : "<invalid call>"; + int depth = RArguments.getDepth(unwrapped); + str.append("Frame(d=").append(depth).append("): ").append(callTarget).append(isVirtual ? " (virtual)" : ""); + str.append(" (called as: ").append(callSrc).append(')'); + } + if (printFrameSlots) { + FrameDescriptor frameDescriptor = unwrapped.getFrameDescriptor(); + for (FrameSlot s : frameDescriptor.getSlots()) { + str.append("\n ").append(s.getIdentifier()).append(" = "); + Object value; + try { + value = unwrapped.getValue(s); + } catch (Throwable t) { + str.append("<exception ").append(t.getClass().getSimpleName()).append(" while acquiring slot ").append(s.getIdentifier()).append(">"); + continue; + } + try { + if (value instanceof RAbstractContainer && ((RAbstractContainer) value).getLength() > 32) { + str.append('<').append(value.getClass().getSimpleName()).append(" with ").append(((RAbstractContainer) value).getLength()).append(" elements>"); + } else { + String text = String.valueOf(value); + str.append(text.length() < 256 ? text : text.substring(0, 256) + "..."); + } + } catch (Throwable t) { + // RLanguage values may not react kindly to getLength() calls + str.append("<exception ").append(t.getClass().getSimpleName()).append(" while printing value of type ").append( + value == null ? "null" : value.getClass().getSimpleName()).append('>'); } - } catch (Throwable t) { - // RLanguage values may not react kindly to getLength() calls - str.append("<exception ").append(t.getClass().getSimpleName()).append(" while printing value of type ").append( - value == null ? "null" : value.getClass().getSimpleName()).append( - '>'); } } } + } catch (Throwable t) { + str.append("<exception ").append(t.getMessage()).append(" ").append(t.getClass().getSimpleName()).append("<"); } } -- GitLab