-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-51385] Debugger API to ignore unavailable source sections.
PullRequest: graal/16612
- Loading branch information
Showing
15 changed files
with
464 additions
and
22 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...src/com/oracle/truffle/tools/chromeinspector/test/UnavailableSectionInspectDebugTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package com.oracle.truffle.tools.chromeinspector.test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Test; | ||
|
||
import org.graalvm.polyglot.Source; | ||
|
||
import com.oracle.truffle.api.debug.test.SuspensionFilterTest; | ||
import com.oracle.truffle.api.test.polyglot.ProxyLanguage; | ||
|
||
/** | ||
* Test that we do not suspend on unavailable source sections. | ||
*/ | ||
public class UnavailableSectionInspectDebugTest { | ||
|
||
@Test | ||
public void testNoStopInUnavailable() throws InterruptedException { | ||
ProxyLanguage.setDelegate(SuspensionFilterTest.createSectionAvailabilityTestLanguage()); | ||
InspectorTester tester = InspectorTester.start(true, false, false); | ||
|
||
tester.sendMessage("{\"id\":1,\"method\":\"Runtime.enable\"}"); | ||
assertEquals("{\"result\":{},\"id\":1}", tester.getMessages(true).trim()); | ||
tester.sendMessage("{\"id\":2,\"method\":\"Debugger.enable\"}"); | ||
tester.receiveMessages( | ||
"{\"result\":{\"debuggerId\":\"UniqueDebuggerId.", "},\"id\":2}\n"); | ||
tester.sendMessage("{\"id\":3,\"method\":\"Runtime.runIfWaitingForDebugger\"}"); | ||
// @formatter:off The default formatting makes unnecessarily big indents and illogical line breaks | ||
assertTrue(tester.compareReceivedMessages( | ||
"{\"result\":{},\"id\":3}\n" + | ||
"{\"method\":\"Runtime.executionContextCreated\",\"params\":{\"context\":{\"origin\":\"\",\"name\":\"test\",\"id\":1}}}\n")); | ||
// @formatter:on | ||
|
||
long cid = tester.getContextId(); | ||
int cmdId = 1; | ||
String[] hashes = new String[]{"fc4f434affffffffffffffffffffffffffffffff", "daaab888ffffffffffffffffffffffffffffffff"}; | ||
for (int i = 0; i < 3; i++) { | ||
String sourceName = i + ".test"; | ||
// Create RootWithUnavailableSection.sectionAvailability = i: | ||
Source source = Source.newBuilder(ProxyLanguage.ID, Integer.toString(i), sourceName).buildLiteral(); | ||
tester.eval(source); | ||
// @formatter:off | ||
if (i < 2) { // No Source when SourceSection is null | ||
assertTrue(tester.compareReceivedMessages( | ||
"{\"method\":\"Debugger.scriptParsed\",\"params\":{\"endLine\":0,\"scriptId\":\"" + i + "\",\"endColumn\":1,\"startColumn\":0,\"startLine\":0,\"length\":1," + | ||
"\"executionContextId\":" + cid + ",\"url\":\"" + sourceName + "\",\"hash\":\"" + hashes[i] + "\"}}\n")); | ||
} | ||
if (i == 0) { | ||
assertTrue(tester.compareReceivedMessages( | ||
"{\"method\":\"Debugger.paused\",\"params\":{\"reason\":\"other\",\"hitBreakpoints\":[]," + | ||
"\"callFrames\":[{\"callFrameId\":\"0\"," + | ||
"\"returnValue\":{\"description\":\"42\",\"type\":\"number\",\"value\":42}," + | ||
"\"functionName\":\"\"," + | ||
"\"scopeChain\":[]," + | ||
"\"this\":null," + | ||
"\"location\":{\"scriptId\":\"" + i + "\",\"columnNumber\":1,\"lineNumber\":0}," + | ||
"\"url\":\"" + sourceName + "\"}]}}\n")); | ||
cmdId++; | ||
tester.sendMessage("{\"id\":" + cmdId + ",\"method\":\"Debugger.stepOver\"}"); | ||
assertTrue(tester.compareReceivedMessages( | ||
"{\"result\":{},\"id\":" + cmdId + "}\n" + | ||
"{\"method\":\"Debugger.resumed\"}\n")); | ||
} | ||
// @formatter:on | ||
} | ||
// Wait for evals to finish, since there may be no protocol communication from some of them. | ||
tester.finishNoGC(); | ||
// Reset the delegate so that we can GC the tested Engine | ||
ProxyLanguage.setDelegate(new ProxyLanguage()); | ||
tester.finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...uffle.tools.dap.test/src/com/oracle/truffle/tools/dap/test/UnavailableSectionDAPTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package com.oracle.truffle.tools.dap.test; | ||
|
||
import org.junit.Test; | ||
|
||
import org.graalvm.polyglot.Source; | ||
|
||
import com.oracle.truffle.api.debug.test.SuspensionFilterTest; | ||
import com.oracle.truffle.api.test.polyglot.ProxyLanguage; | ||
|
||
/** | ||
* Test that we do not suspend on unavailable source sections. | ||
*/ | ||
public class UnavailableSectionDAPTest { | ||
|
||
@Test | ||
public void testNoStopInUnavailable() throws Exception { | ||
ProxyLanguage.setDelegate(SuspensionFilterTest.createSectionAvailabilityTestLanguage()); | ||
DAPTester tester = DAPTester.start(true, null); | ||
|
||
tester.sendMessage( | ||
"{\"command\":\"initialize\",\"arguments\":{\"clientID\":\"DAPTester\",\"clientName\":\"DAP Tester\",\"adapterID\":\"graalvm\",\"pathFormat\":\"path\",\"linesStartAt1\":true,\"columnsStartAt1\":true," + | ||
"\"supportsVariableType\":true,\"supportsVariablePaging\":true,\"supportsRunInTerminalRequest\":true,\"locale\":\"en-us\",\"supportsProgressReporting\":true},\"type\":\"request\",\"seq\":1}"); | ||
tester.compareReceivedMessages( | ||
"{\"event\":\"initialized\",\"type\":\"event\"}", | ||
"{\"success\":true,\"type\":\"response\",\"body\":{\"supportsConditionalBreakpoints\":true,\"supportsLoadedSourcesRequest\":true,\"supportsFunctionBreakpoints\":true,\"supportsExceptionInfoRequest\":true," + | ||
"\"supportsBreakpointLocationsRequest\":true,\"supportsHitConditionalBreakpoints\":true,\"supportsLogPoints\":true,\"supportsSetVariable\":true,\"supportsConfigurationDoneRequest\":true," + | ||
"\"exceptionBreakpointFilters\":[{\"filter\":\"all\",\"label\":\"All Exceptions\"},{\"filter\":\"uncaught\",\"label\":\"Uncaught Exceptions\"}]},\"request_seq\":1,\"command\":\"initialize\"}"); | ||
tester.sendMessage( | ||
"{\"command\":\"attach\",\"arguments\":{\"type\":\"graalvm\",\"request\":\"attach\",\"name\":\"Attach\",\"port\":9229,\"protocol\":\"debugAdapter\"},\"type\":\"request\",\"seq\":2}"); | ||
tester.compareReceivedMessages("{\"event\":\"output\",\"body\":{\"output\":\"Debugger attached.\",\"category\":\"stderr\"},\"type\":\"event\"}", | ||
"{\"success\":true,\"type\":\"response\",\"request_seq\":2,\"command\":\"attach\"}"); | ||
tester.sendMessage("{\"command\":\"configurationDone\",\"type\":\"request\",\"seq\":5}"); | ||
tester.compareReceivedMessages("{\"success\":true,\"type\":\"response\",\"request_seq\":5,\"command\":\"configurationDone\",\"seq\":5}"); | ||
|
||
int seq = 6; | ||
for (int i = 0; i < 3; i++) { | ||
String sourceName = i + ".test"; | ||
// Create RootWithUnavailableSection.sectionAvailability = i: | ||
Source source = Source.newBuilder(ProxyLanguage.ID, Integer.toString(i), sourceName).buildLiteral(); | ||
tester.eval(source); | ||
if (i == 0) { | ||
tester.compareReceivedMessages("{\"event\":\"thread\",\"body\":{\"threadId\":1,\"reason\":\"started\"},\"type\":\"event\",\"seq\":" + (seq++) + "}"); | ||
} | ||
if (i < 2) { // No Source when SourceSection is null | ||
String sourceJson = "{\"sourceReference\":" + (i + 1) + ",\"name\":\"" + sourceName + "\"}"; | ||
tester.compareReceivedMessages( | ||
"{\"event\":\"loadedSource\",\"body\":{\"reason\":\"new\",\"source\":" + sourceJson + "},\"type\":\"event\",\"seq\":" + (seq++) + "}"); | ||
} | ||
if (i == 0) { | ||
tester.compareReceivedMessages( | ||
"{\"event\":\"stopped\",\"body\":{\"threadId\":1,\"reason\":\"debugger_statement\",\"description\":\"Paused on debugger statement\"},\"type\":\"event\",\"seq\":" + | ||
(seq++) + "}"); | ||
tester.sendMessage("{\"command\":\"next\",\"arguments\":{\"threadId\":1},\"type\":\"request\",\"seq\":7}"); | ||
tester.compareReceivedMessages( | ||
"{\"success\":true,\"type\":\"response\",\"request_seq\":7,\"command\":\"next\",\"seq\":" + (seq++) + "}"); | ||
tester.compareReceivedMessages( | ||
"{\"event\":\"continued\",\"body\":{\"threadId\":1,\"allThreadsContinued\":false},\"type\":\"event\",\"seq\":" + (seq++) + "}"); | ||
} | ||
} | ||
tester.finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.