Skip to content

Commit eacb727

Browse files
committed
Use InteropLibrary.getExecutableName() instead of RootNode.getName(). (GR-28025)
1 parent f14768f commit eacb727

File tree

9 files changed

+534
-44
lines changed

9 files changed

+534
-44
lines changed

tools/src/com.oracle.truffle.tools.chromeinspector.test/src/com/oracle/truffle/tools/chromeinspector/test/BuggyLanguageInspectDebugLegacyTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ private void testBuggyCalls(AtomicReference<ProxyLanguage> language, String pref
261261
"{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":" + endLine + ",\"scriptId\":\"1\",\"endColumn\":" + endColumn + ",\"startColumn\":0,\"startLine\":0,\"length\":" +
262262
source.getLength() + ",\"executionContextId\":" + id + ",\"url\":\"" + sourceURI + "\",\"hash\":\"" + hash + "\"}}\n"));
263263
skipConsoleMessages(tester);
264-
assertPaused(prefix + "2", haveScope, haveScope ? 4 : 2, sourceURI, 1);
264+
// When we have a buggy scope, getName fails as well because we ask for the root instance,
265+
// which is a part of legacy scope.
266+
assertPaused(haveScope ? prefix + "2" : "A TruffleException", haveScope, haveScope ? 4 : 2, sourceURI, 1);
265267
bugVerifier.verifyMessages(tester, 2);
266268
tester.sendMessage("{\"id\":100,\"method\":\"Debugger.resume\"}");
267269
assertTrue(tester.compareReceivedMessages(

tools/src/com.oracle.truffle.tools.chromeinspector/src/com/oracle/truffle/tools/chromeinspector/types/CallFrame.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.oracle.truffle.tools.utils.json.JSONObject;
2828

29+
import com.oracle.truffle.api.debug.DebugException;
2930
import com.oracle.truffle.api.debug.DebugStackFrame;
3031
import com.oracle.truffle.api.debug.SuspendAnchor;
3132
import com.oracle.truffle.api.source.SourceSection;
@@ -88,7 +89,11 @@ public RemoteObject getReturnValue() {
8889
private JSONObject createJSON() {
8990
JSONObject json = new JSONObject();
9091
json.put("callFrameId", Integer.toString(depth));
91-
json.put("functionName", frame.getName());
92+
try {
93+
json.put("functionName", frame.getName());
94+
} catch (DebugException ex) {
95+
json.put("functionName", ex.getLocalizedMessage());
96+
}
9297
json.put("location", location.toJSON());
9398
json.putOpt("functionLocation", (functionLocation != null) ? functionLocation.toJSON() : null);
9499
json.put("url", url);

truffle/src/com.oracle.truffle.api.debug.test/src/com/oracle/truffle/api/debug/test/DebugStackFrameTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import com.oracle.truffle.api.nodes.RootNode;
8282
import com.oracle.truffle.api.source.SourceSection;
8383
import com.oracle.truffle.api.test.polyglot.ProxyLanguage;
84+
import java.util.Arrays;
8485

8586
import org.graalvm.polyglot.Source;
8687

@@ -337,6 +338,61 @@ public void testAsynchronousStack() {
337338
expectDone();
338339
}
339340

341+
@Test
342+
public void testDynamicNames() {
343+
TestExecutableNamesLanguage language = new TestExecutableNamesLanguage(0, "staticName", "dynamicName1");
344+
ProxyLanguage.setDelegate(language);
345+
try (DebuggerSession session = tester.startSession()) {
346+
session.suspendNextExecution();
347+
Source source = Source.create(ProxyLanguage.ID, "");
348+
tester.startEval(source);
349+
expectSuspended((SuspendedEvent event) -> {
350+
DebugStackFrame frame = event.getTopStackFrame();
351+
assertEquals("dynamicName1", frame.getName());
352+
});
353+
}
354+
expectDone();
355+
}
356+
357+
@Test
358+
public void testDynamicNamesInDepth() {
359+
for (int depth = 0; depth < 5; depth++) {
360+
checkDynamicNames(depth, "staticName");
361+
checkDynamicNames(depth, "staticName", "dynamicName");
362+
checkDynamicNames(depth, "staticName", "dynamicName1", "dynamicName2");
363+
}
364+
}
365+
366+
private void checkDynamicNames(int depth, String rootName, String... executableNames) {
367+
TestExecutableNamesLanguage language = new TestExecutableNamesLanguage(depth, rootName, executableNames);
368+
ProxyLanguage.setDelegate(language);
369+
try (DebuggerSession session = tester.startSession()) {
370+
session.suspendNextExecution();
371+
Source source = Source.create(ProxyLanguage.ID, depth + rootName + Arrays.toString(executableNames));
372+
tester.startEval(source);
373+
if (executableNames.length == 0) {
374+
expectSuspended((SuspendedEvent event) -> {
375+
DebugStackFrame frame = event.getTopStackFrame();
376+
assertEquals("depth = " + depth, rootName, frame.getName());
377+
});
378+
} else {
379+
for (String executableName : executableNames) {
380+
final String name = executableName;
381+
expectSuspended((SuspendedEvent event) -> {
382+
Iterator<DebugStackFrame> framesIterator = event.getStackFrames().iterator();
383+
for (int d = depth; d > 0; d--) {
384+
framesIterator.next();
385+
}
386+
DebugStackFrame frame = framesIterator.next();
387+
assertEquals("depth = " + depth, name, frame.getName());
388+
session.suspendNextExecution();
389+
});
390+
}
391+
}
392+
}
393+
expectDone();
394+
}
395+
340396
private static SourceSection getFunctionSourceSection(DebugStackFrame frame) {
341397
// There are only function scopes in the InstrumentationTestLanguage
342398
assertTrue(frame.getScope().isFunctionScope());

0 commit comments

Comments
 (0)