mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-23 04:24:49 +02:00
8211736: jdb doesn't print prompt when breakpoint is hit and suspend policy is STOP_EVENT_THREAD
Reviewed-by: cjplummer, amenkov, gadams, jcbeyler
This commit is contained in:
parent
77ad5f6fa3
commit
c2bc749866
4 changed files with 158 additions and 25 deletions
|
@ -100,6 +100,17 @@ public class TTY implements EventNotifier {
|
||||||
public void breakpointEvent(BreakpointEvent be) {
|
public void breakpointEvent(BreakpointEvent be) {
|
||||||
Thread.yield(); // fetch output
|
Thread.yield(); // fetch output
|
||||||
MessageOutput.lnprint("Breakpoint hit:");
|
MessageOutput.lnprint("Breakpoint hit:");
|
||||||
|
// Print breakpoint location and prompt if suspend policy is
|
||||||
|
// SUSPEND_NONE or SUSPEND_EVENT_THREAD. In case of SUSPEND_ALL
|
||||||
|
// policy this is handled by vmInterrupted() method.
|
||||||
|
int suspendPolicy = be.request().suspendPolicy();
|
||||||
|
switch (suspendPolicy) {
|
||||||
|
case EventRequest.SUSPEND_EVENT_THREAD:
|
||||||
|
case EventRequest.SUSPEND_NONE:
|
||||||
|
printBreakpointLocation(be);
|
||||||
|
MessageOutput.printPrompt();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -227,6 +238,10 @@ public class TTY implements EventNotifier {
|
||||||
Commands.locationString(loc)});
|
Commands.locationString(loc)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void printBreakpointLocation(BreakpointEvent be) {
|
||||||
|
printLocationWithSourceLine(be.thread().name(), be.location());
|
||||||
|
}
|
||||||
|
|
||||||
private void printCurrentLocation() {
|
private void printCurrentLocation() {
|
||||||
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo();
|
||||||
StackFrame frame;
|
StackFrame frame;
|
||||||
|
@ -239,8 +254,13 @@ public class TTY implements EventNotifier {
|
||||||
if (frame == null) {
|
if (frame == null) {
|
||||||
MessageOutput.println("No frames on the current call stack");
|
MessageOutput.println("No frames on the current call stack");
|
||||||
} else {
|
} else {
|
||||||
Location loc = frame.location();
|
printLocationWithSourceLine(threadInfo.getThread().name(), frame.location());
|
||||||
printBaseLocation(threadInfo.getThread().name(), loc);
|
}
|
||||||
|
MessageOutput.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printLocationWithSourceLine(String threadName, Location loc) {
|
||||||
|
printBaseLocation(threadName, loc);
|
||||||
// Output the current source line, if possible
|
// Output the current source line, if possible
|
||||||
if (loc.lineNumber() != -1) {
|
if (loc.lineNumber() != -1) {
|
||||||
String line;
|
String line;
|
||||||
|
@ -256,8 +276,6 @@ public class TTY implements EventNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MessageOutput.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printLocationOfEvent(LocatableEvent theEvent) {
|
private void printLocationOfEvent(LocatableEvent theEvent) {
|
||||||
printBaseLocation(theEvent.thread().name(), theEvent.location());
|
printBaseLocation(theEvent.thread().name(), theEvent.location());
|
||||||
|
|
90
test/jdk/com/sun/jdi/JdbStopThreadTest.java
Normal file
90
test/jdk/com/sun/jdi/JdbStopThreadTest.java
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018, 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.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8211736
|
||||||
|
* @summary Tests that the breakpoint location and prompt are printed in the debugger output
|
||||||
|
* when breakpoint is hit and suspend policy is set to SUSPEND_EVENT_THREAD or SUSPEND_NONE
|
||||||
|
*
|
||||||
|
* @library /test/lib
|
||||||
|
* @run compile -g JdbStopThreadTest.java
|
||||||
|
* @run main/othervm JdbStopThreadTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
import jdk.test.lib.process.OutputAnalyzer;
|
||||||
|
import lib.jdb.JdbCommand;
|
||||||
|
import lib.jdb.JdbTest;
|
||||||
|
|
||||||
|
class JdbStopThreadTestTarg {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
test();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void test() {
|
||||||
|
Thread thread = Thread.currentThread();
|
||||||
|
print(thread); // @1 breakpoint
|
||||||
|
String str = "test";
|
||||||
|
print(str); // @2 breakpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void print(Object obj) {
|
||||||
|
System.out.println(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class JdbStopThreadTest extends JdbTest {
|
||||||
|
public static void main(String argv[]) {
|
||||||
|
new JdbStopThreadTest().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private JdbStopThreadTest() {
|
||||||
|
super(DEBUGGEE_CLASS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String DEBUGGEE_CLASS = JdbStopThreadTestTarg.class.getName();
|
||||||
|
private static final String PATTERN1_TEMPLATE = "^Breakpoint hit: \"thread=main\", " +
|
||||||
|
"JdbStopThreadTestTarg\\.test\\(\\), line=%LINE_NUMBER.*\\R%LINE_NUMBER\\s+print\\(thread\\);.*\\R>\\s";
|
||||||
|
private static final String PATTERN2_TEMPLATE = "^Breakpoint hit: \"thread=main\", " +
|
||||||
|
"JdbStopThreadTestTarg\\.test\\(\\), line=%LINE_NUMBER.*\\R%LINE_NUMBER\\s+print\\(str\\);.*\\R>\\s";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void runCases() {
|
||||||
|
// Test suspend policy SUSPEND_EVENT_THREAD
|
||||||
|
int bpLine1 = parseBreakpoints(getTestSourcePath("JdbStopThreadTest.java"), 1).get(0);
|
||||||
|
jdb.command(JdbCommand.stopThreadAt(DEBUGGEE_CLASS, bpLine1));
|
||||||
|
String pattern1 = PATTERN1_TEMPLATE.replaceAll("%LINE_NUMBER", String.valueOf(bpLine1));
|
||||||
|
// Run to breakpoint #1
|
||||||
|
jdb.command(JdbCommand.run().waitForPrompt(pattern1, true));
|
||||||
|
new OutputAnalyzer(jdb.getJdbOutput()).shouldMatch(pattern1);
|
||||||
|
|
||||||
|
|
||||||
|
// Test suspend policy SUSPEND_NONE
|
||||||
|
jdb.command(JdbCommand.thread(1));
|
||||||
|
int bpLine2 = parseBreakpoints(getTestSourcePath("JdbStopThreadTest.java"), 2).get(0);
|
||||||
|
jdb.command(JdbCommand.stopGoAt(DEBUGGEE_CLASS, bpLine2));
|
||||||
|
String pattern2 = PATTERN2_TEMPLATE.replaceAll("%LINE_NUMBER", String.valueOf(bpLine2));
|
||||||
|
jdb.command(JdbCommand.cont().allowExit());
|
||||||
|
new OutputAnalyzer(jdb.getJdbOutput()).shouldMatch(pattern2);
|
||||||
|
}
|
||||||
|
}
|
|
@ -150,10 +150,11 @@ public class Jdb implements AutoCloseable {
|
||||||
# i.e., the > prompt comes out AFTER the prompt we we need to wait for.
|
# i.e., the > prompt comes out AFTER the prompt we we need to wait for.
|
||||||
*/
|
*/
|
||||||
// compile regexp once
|
// compile regexp once
|
||||||
private final String promptPattern = "[a-zA-Z0-9_-][a-zA-Z0-9_-]*\\[[1-9][0-9]*\\] [ >]*$";
|
private final static String promptPattern = "[a-zA-Z0-9_-][a-zA-Z0-9_-]*\\[[1-9][0-9]*\\] [ >]*$";
|
||||||
private final Pattern promptRegexp = Pattern.compile(promptPattern);
|
final static Pattern PROMPT_REGEXP = Pattern.compile(promptPattern);
|
||||||
|
|
||||||
public List<String> waitForPrompt(int lines, boolean allowExit) {
|
public List<String> waitForPrompt(int lines, boolean allowExit) {
|
||||||
return waitForPrompt(lines, allowExit, promptRegexp);
|
return waitForPrompt(lines, allowExit, PROMPT_REGEXP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// jdb prompt when debuggee is not started and is not suspended after breakpoint
|
// jdb prompt when debuggee is not started and is not suspended after breakpoint
|
||||||
|
@ -183,19 +184,27 @@ public class Jdb implements AutoCloseable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<String> reply = outputHandler.get();
|
List<String> reply = outputHandler.get();
|
||||||
|
if ((promptRegexp.flags() & Pattern.MULTILINE) > 0) {
|
||||||
|
String replyString = reply.stream().collect(Collectors.joining(lineSeparator));
|
||||||
|
if (promptRegexp.matcher(replyString).find()) {
|
||||||
|
logJdb(reply);
|
||||||
|
return outputHandler.reset();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (String line : reply.subList(Math.max(0, reply.size() - lines), reply.size())) {
|
for (String line : reply.subList(Math.max(0, reply.size() - lines), reply.size())) {
|
||||||
if (promptRegexp.matcher(line).find()) {
|
if (promptRegexp.matcher(line).find()) {
|
||||||
logJdb(reply);
|
logJdb(reply);
|
||||||
return outputHandler.reset();
|
return outputHandler.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!jdb.isAlive()) {
|
if (!jdb.isAlive()) {
|
||||||
// ensure we get the whole output
|
// ensure we get the whole output
|
||||||
reply = outputHandler.reset();
|
reply = outputHandler.reset();
|
||||||
logJdb(reply);
|
logJdb(reply);
|
||||||
if (!allowExit) {
|
if (!allowExit) {
|
||||||
throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
|
throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
|
||||||
+ " seconds, looking for '" + promptPattern + "', in " + lines + " lines");
|
+ " seconds, looking for '" + promptRegexp.pattern() + "', in " + lines + " lines");
|
||||||
}
|
}
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +212,7 @@ public class Jdb implements AutoCloseable {
|
||||||
// timeout
|
// timeout
|
||||||
logJdb(outputHandler.get());
|
logJdb(outputHandler.get());
|
||||||
throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
|
throw new RuntimeException("waitForPrompt timed out after " + (timeout/1000)
|
||||||
+ " seconds, looking for '" + promptPattern + "', in " + lines + " lines");
|
+ " seconds, looking for '" + promptRegexp.pattern() + "', in " + lines + " lines");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> command(JdbCommand cmd) {
|
public List<String> command(JdbCommand cmd) {
|
||||||
|
@ -223,7 +232,7 @@ public class Jdb implements AutoCloseable {
|
||||||
throw new RuntimeException("Unexpected IO error while writing command '" + cmd.cmd + "' to jdb stdin stream");
|
throw new RuntimeException("Unexpected IO error while writing command '" + cmd.cmd + "' to jdb stdin stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
return waitForPrompt(1, cmd.allowExit);
|
return waitForPrompt(1, cmd.allowExit, cmd.waitForPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> command(String cmd) {
|
public List<String> command(String cmd) {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
package lib.jdb;
|
package lib.jdb;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,6 +119,8 @@ import java.util.stream.Collectors;
|
||||||
public class JdbCommand {
|
public class JdbCommand {
|
||||||
final String cmd;
|
final String cmd;
|
||||||
boolean allowExit = false;
|
boolean allowExit = false;
|
||||||
|
// Default pattern to wait for command to complete
|
||||||
|
Pattern waitForPattern = Jdb.PROMPT_REGEXP;
|
||||||
|
|
||||||
public JdbCommand(String cmd) {
|
public JdbCommand(String cmd) {
|
||||||
this.cmd = cmd;
|
this.cmd = cmd;
|
||||||
|
@ -128,6 +131,11 @@ public class JdbCommand {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JdbCommand waitForPrompt(String pattern, boolean isMultiline) {
|
||||||
|
waitForPattern = Pattern.compile(pattern, isMultiline ? Pattern.MULTILINE : 0);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static JdbCommand run(String ... params) {
|
public static JdbCommand run(String ... params) {
|
||||||
return new JdbCommand("run " + Arrays.stream(params).collect(Collectors.joining(" ")));
|
return new JdbCommand("run " + Arrays.stream(params).collect(Collectors.joining(" ")));
|
||||||
|
@ -145,10 +153,18 @@ public class JdbCommand {
|
||||||
public static JdbCommand stopAt(String targetClass, int lineNum) {
|
public static JdbCommand stopAt(String targetClass, int lineNum) {
|
||||||
return new JdbCommand("stop at " + targetClass + ":" + lineNum);
|
return new JdbCommand("stop at " + targetClass + ":" + lineNum);
|
||||||
}
|
}
|
||||||
|
public static JdbCommand stopThreadAt(String targetClass, int lineNum) {
|
||||||
|
return new JdbCommand("stop thread at " + targetClass + ":" + lineNum);
|
||||||
|
}
|
||||||
|
public static JdbCommand stopGoAt(String targetClass, int lineNum) {
|
||||||
|
return new JdbCommand("stop go at " + targetClass + ":" + lineNum);
|
||||||
|
}
|
||||||
public static JdbCommand stopIn(String targetClass, String methodName) {
|
public static JdbCommand stopIn(String targetClass, String methodName) {
|
||||||
return new JdbCommand("stop in " + targetClass + "." + methodName);
|
return new JdbCommand("stop in " + targetClass + "." + methodName);
|
||||||
}
|
}
|
||||||
|
public static JdbCommand thread(int threadNumber) {
|
||||||
|
return new JdbCommand("thread " + threadNumber);
|
||||||
|
}
|
||||||
// clear <class id>:<line> -- clear a breakpoint at a line
|
// clear <class id>:<line> -- clear a breakpoint at a line
|
||||||
public static JdbCommand clear(String targetClass, int lineNum) {
|
public static JdbCommand clear(String targetClass, int lineNum) {
|
||||||
return new JdbCommand("clear " + targetClass + ":" + lineNum);
|
return new JdbCommand("clear " + targetClass + ":" + lineNum);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue