--- old/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java 2018-10-16 20:53:04.000000000 -0700 +++ new/src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java 2018-10-16 20:53:04.000000000 -0700 @@ -99,7 +99,25 @@ @Override public void breakpointEvent(BreakpointEvent be) { Thread.yield(); // fetch output - MessageOutput.lnprint("Breakpoint hit:"); + MessageOutput.startBuffering(); + try { + MessageOutput.lnprint("Breakpoint hit:"); + // Print current location if suspend policy is SUSPEND_NONE and + // current location and prompt if suspend policy is 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: + printCurrentLocation(ThreadInfo.getThreadInfo(be.thread())); + MessageOutput.printPrompt(); + break; + case EventRequest.SUSPEND_NONE: + printBreakpointLocation(be); + break; + } + } finally { + MessageOutput.stopBuffering(); + } } @Override @@ -146,13 +164,18 @@ * If we are stopping here, then we will see the normal location * info printed. */ - if (me.request().suspendPolicy() != EventRequest.SUSPEND_NONE) { - // We are stopping; the name will be shown by the normal mechanism - MessageOutput.lnprint("Method entered:"); - } else { - // We aren't stopping, show the name - MessageOutput.print("Method entered:"); - printLocationOfEvent(me); + MessageOutput.startBuffering(); + try { + if (me.request().suspendPolicy() != EventRequest.SUSPEND_NONE) { + // We are stopping; the name will be shown by the normal mechanism + MessageOutput.lnprint("Method entered:"); + } else { + // We aren't stopping, show the name + MessageOutput.print("Method entered:"); + printLocationOfEvent(me); + } + } finally { + MessageOutput.stopBuffering(); } } @@ -169,20 +192,25 @@ // Either we are not tracing a specific method, or we are // and we are exitting that method. - if (me.request().suspendPolicy() != EventRequest.SUSPEND_NONE) { - // We will be stopping here, so do a newline - MessageOutput.println(); - } - if (Env.vm().canGetMethodReturnValues()) { - MessageOutput.print("Method exitedValue:", me.returnValue() + ""); - } else { - MessageOutput.print("Method exited:"); - } + MessageOutput.startBuffering(); + try { + if (me.request().suspendPolicy() != EventRequest.SUSPEND_NONE) { + // We will be stopping here, so do a newline + MessageOutput.println(); + } + if (Env.vm().canGetMethodReturnValues()) { + MessageOutput.print("Method exitedValue:", me.returnValue() + ""); + } else { + MessageOutput.print("Method exited:"); + } - if (me.request().suspendPolicy() == EventRequest.SUSPEND_NONE) { - // We won't be stopping here, so show the method name - printLocationOfEvent(me); + if (me.request().suspendPolicy() == EventRequest.SUSPEND_NONE) { + // We won't be stopping here, so show the method name + printLocationOfEvent(me); + } + } finally{ + MessageOutput.stopBuffering(); } // In case we want to have a one shot trace exit some day, this @@ -228,7 +256,14 @@ } private void printCurrentLocation() { - ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); + printCurrentLocation(ThreadInfo.getCurrentThreadInfo()); + } + + private void printBreakpointLocation(BreakpointEvent be) { + printLocationWithSourceLine(be.thread().name(), be.location()); + } + + private void printCurrentLocation(ThreadInfo threadInfo) { StackFrame frame; try { frame = threadInfo.getCurrentFrame(); @@ -239,26 +274,29 @@ if (frame == null) { MessageOutput.println("No frames on the current call stack"); } else { - Location loc = frame.location(); - printBaseLocation(threadInfo.getThread().name(), loc); - // Output the current source line, if possible - if (loc.lineNumber() != -1) { - String line; - try { - line = Env.sourceLine(loc, loc.lineNumber()); - } catch (java.io.IOException e) { - line = null; - } - if (line != null) { - MessageOutput.println("source line number and line", - new Object [] {loc.lineNumber(), - line}); - } - } + printLocationWithSourceLine(threadInfo.getThread().name(), frame.location()); } MessageOutput.println(); } + private void printLocationWithSourceLine(String threadName, Location loc) { + printBaseLocation(threadName, loc); + // Output the current source line, if possible + if (loc.lineNumber() != -1) { + String line; + try { + line = Env.sourceLine(loc, loc.lineNumber()); + } catch (java.io.IOException e) { + line = null; + } + if (line != null) { + MessageOutput.println("source line number and line", + new Object [] {loc.lineNumber(), + line}); + } + } + } + private void printLocationOfEvent(LocatableEvent theEvent) { printBaseLocation(theEvent.thread().name(), theEvent.location()); }