Skip to content

Commit

Permalink
Showing 1 changed file with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -39,30 +39,49 @@ public CallStackManager(RubyContext context) {
this.context = context;
}

private static final Object STOP_ITERATING = new Object();

@TruffleBoundary
public FrameInstance getCallerFrameIgnoringSend() {
final Memo<Boolean> firstFrame = new Memo<>(true);
FrameInstance callerFrame = Truffle.getRuntime().getCallerFrame();
if (callerFrame == null) {
return null;
}
InternalMethod method = getMethod(callerFrame);

if (method == null) { // Not a Ruby frame
return null;
} else if (!context.getCoreLibrary().isSend(method)) {
return callerFrame;
}

// Need to iterate further
final Object frame = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Object>() {
int depth = 0;

final FrameInstance fi = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<FrameInstance>() {
@Override
public FrameInstance visitFrame(FrameInstance frameInstance) {
if (firstFrame.get()) {
firstFrame.set(false);
public Object visitFrame(FrameInstance frameInstance) {
depth++;
if (depth < 2) {
return null;
}

final InternalMethod method = getMethod(frameInstance);
assert method != null;

if (!context.getCoreLibrary().isSend(method)) {
InternalMethod method = getMethod(frameInstance);
if (method == null) {
return STOP_ITERATING;
} else if (!context.getCoreLibrary().isSend(method)) {
return frameInstance;
} else {
return null;
}
}
});

return fi;
if (frame instanceof FrameInstance) {
return (FrameInstance) frame;
} else {
return null;
}
}

@TruffleBoundary
@@ -96,7 +115,7 @@ public Node visitFrame(FrameInstance frameInstance) {
}

private InternalMethod getMethod(FrameInstance frame) {
return RubyArguments.getMethod(frame.getFrame(FrameInstance.FrameAccess.READ_ONLY, true));
return RubyArguments.tryGetMethod(frame.getFrame(FrameInstance.FrameAccess.READ_ONLY, true));
}

public Backtrace getBacktrace(Node currentNode, Throwable javaThrowable) {

2 comments on commit e88b6c7

@chrisseaton
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should be testing the type of the frame by looking at the call node? At the moment we're sort of guessing what language the frame came from.

@eregon
Copy link
Member Author

@eregon eregon commented on e88b6c7 Jun 21, 2016

Choose a reason for hiding this comment

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

We could have a RubyArguments.isRubyFrame(), yes. But InternalMethod is defined by us so it can only be a Ruby frame if there is a method.

Please sign in to comment.