< prev index next >
src/jdk.jdi/share/classes/com/sun/tools/example/debug/tty/TTY.java
Print this page
@@ -97,11 +97,29 @@
}
@Override
public void breakpointEvent(BreakpointEvent be) {
Thread.yield(); // fetch output
+ 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
public void fieldWatchEvent(WatchpointEvent fwe) {
Field field = fwe.field();
@@ -144,18 +162,23 @@
/*
* These can be very numerous, so be as efficient as possible.
* If we are stopping here, then we will see the normal location
* info printed.
*/
+ 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();
+ }
}
@Override
public boolean methodExitEvent(MethodExitEvent me) {
Thread.yield(); // fetch output
@@ -167,10 +190,12 @@
if (mmm == null || mmm.equals(meMethod)) {
// Either we are not tracing a specific method, or we are
// and we are exitting that method.
+ 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()) {
@@ -182,10 +207,13 @@
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
// code disables the request so we don't hit it again.
if (false) {
// This is a one shot deal; we don't want to stop
@@ -226,23 +254,35 @@
new Object [] {threadName,
Commands.locationString(loc)});
}
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();
} catch (IncompatibleThreadStateException exc) {
MessageOutput.println("<location unavailable>");
return;
}
if (frame == null) {
MessageOutput.println("No frames on the current call stack");
} else {
- Location loc = frame.location();
- printBaseLocation(threadInfo.getThread().name(), loc);
+ 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());
@@ -254,12 +294,10 @@
new Object [] {loc.lineNumber(),
line});
}
}
}
- MessageOutput.println();
- }
private void printLocationOfEvent(LocatableEvent theEvent) {
printBaseLocation(theEvent.thread().name(), theEvent.location());
}
< prev index next >