Skip to content

Commit bc90612

Browse files
author
Nicolas Laurent
committed
properly ignore internal frames, but not builtins
1 parent e74d4b7 commit bc90612

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

src/main/java/org/truffleruby/language/CallStackManager.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,9 @@ public boolean ignoreFrame(Node callNode, RootCallTarget callTarget) {
228228
}
229229
}
230230

231-
if (rootNode instanceof InternalRootNode) {
232-
return true;
233-
}
234-
235-
236-
if (callNode.getEncapsulatingSourceSection() == null) {
237-
return true;
238-
}
239-
240-
return false;
231+
return rootNode != null && rootNode.isInternal() && !BacktraceFormatter.isCore(context, rootNode.getSourceSection())
232+
|| rootNode instanceof InternalRootNode
233+
|| callNode.getEncapsulatingSourceSection() == null;
241234
}
242235

243236
}

src/main/java/org/truffleruby/language/backtrace/Backtrace.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,22 @@ public Activation[] getActivations(Throwable truffleException) {
214214
final RubyContext context = RubyLanguage.getCurrentContext();
215215
final CallStackManager callStackManager = context.getCallStack();
216216

217-
int i = 0;
217+
int elementCount = 0;
218+
int activationCount = 0;
218219
for (TruffleStackTraceElement stackTraceElement : stackTrace) {
219-
if (i < omitted) {
220-
++i;
221-
continue;
222-
}
223-
224-
assert i != 0 || stackTraceElement.getLocation() == location;
220+
assert elementCount != 0 || stackTraceElement.getLocation() == location;
225221
final Node callNode = stackTraceElement.getLocation();
222+
++elementCount;
226223

227224
if (callStackManager.ignoreFrame(callNode, stackTraceElement.getTarget())) {
228225
continue;
229226
}
230227

228+
if (activationCount < omitted) {
229+
++activationCount;
230+
continue;
231+
}
232+
231233
final RootNode rootNode = stackTraceElement.getTarget().getRootNode();
232234
final String methodName;
233235
if (rootNode instanceof RubyRootNode) {
@@ -243,17 +245,17 @@ public Activation[] getActivations(Throwable truffleException) {
243245
activations.add(new Activation(callNode, methodName));
244246
}
245247

246-
i++;
248+
activationCount++;
247249
}
248250

249251
// If there are activations with a InternalMethod but no caller information above in the
250252
// stack, then all of these activations are internal as they are not called from user code.
251253
while (!activations.isEmpty() && activations.get(activations.size() - 1).getCallNode() == null) {
252254
activations.remove(activations.size() - 1);
253-
--i;
255+
--activationCount;
254256
}
255257

256-
this.totalUnderlyingActivations = i;
258+
this.totalUnderlyingActivations = activationCount;
257259
return this.activations = activations.toArray(new Activation[activations.size()]);
258260
}
259261

@@ -306,10 +308,10 @@ public DynamicObject getBacktraceLocations(int length, Node node) {
306308
: ArrayHelpers.createEmptyArray(context);
307309
}
308310

309-
// NOTE (norswap, 18 Dec 2019)
310-
// TruffleStackTrace#getStackTrace (hence Backtrace#getActivations too) does not
311-
// always respect TruffleException#getStackTraceElementLimit(), so we need to use Math#min.
312-
// The reason: it doesn't count frames whose RootNode is internal towards the limit.
311+
// NOTE (norswap, 08 Jan 2020)
312+
// It used to be that TruffleException#getStackTraceElementLimit() wasn't respected
313+
// due to a mishandling of internal frames. That's why we used Math.min and not just
314+
// length. Leaving it in just in case.
313315
final int locationsLength = length < 0
314316
? activationsLength + 1 + length
315317
: Math.min(activationsLength, length);

0 commit comments

Comments
 (0)