83 @Override 84 public void threadStartEvent(ThreadStartEvent e) { 85 } 86 87 @Override 88 public void threadDeathEvent(ThreadDeathEvent e) { 89 } 90 91 @Override 92 public void classPrepareEvent(ClassPrepareEvent e) { 93 } 94 95 @Override 96 public void classUnloadEvent(ClassUnloadEvent e) { 97 } 98 99 @Override 100 public void breakpointEvent(BreakpointEvent be) { 101 Thread.yield(); // fetch output 102 MessageOutput.lnprint("Breakpoint hit:"); 103 } 104 105 @Override 106 public void fieldWatchEvent(WatchpointEvent fwe) { 107 Field field = fwe.field(); 108 ObjectReference obj = fwe.object(); 109 Thread.yield(); // fetch output 110 111 if (fwe instanceof ModificationWatchpointEvent) { 112 MessageOutput.lnprint("Field access encountered before after", 113 new Object [] {field, 114 fwe.valueCurrent(), 115 ((ModificationWatchpointEvent)fwe).valueToBe()}); 116 } else { 117 MessageOutput.lnprint("Field access encountered", field.toString()); 118 } 119 } 120 121 @Override 122 public void stepEvent(StepEvent se) { 210 Thread.yield(); // fetch output 211 printCurrentLocation(); 212 for (String cmd : monitorCommands) { 213 StringTokenizer t = new StringTokenizer(cmd); 214 t.nextToken(); // get rid of monitor number 215 executeCommand(t); 216 } 217 MessageOutput.printPrompt(); 218 } 219 220 @Override 221 public void receivedEvent(Event event) { 222 } 223 224 private void printBaseLocation(String threadName, Location loc) { 225 MessageOutput.println("location", 226 new Object [] {threadName, 227 Commands.locationString(loc)}); 228 } 229 230 private void printCurrentLocation() { 231 ThreadInfo threadInfo = ThreadInfo.getCurrentThreadInfo(); 232 StackFrame frame; 233 try { 234 frame = threadInfo.getCurrentFrame(); 235 } catch (IncompatibleThreadStateException exc) { 236 MessageOutput.println("<location unavailable>"); 237 return; 238 } 239 if (frame == null) { 240 MessageOutput.println("No frames on the current call stack"); 241 } else { 242 Location loc = frame.location(); 243 printBaseLocation(threadInfo.getThread().name(), loc); 244 // Output the current source line, if possible 245 if (loc.lineNumber() != -1) { 246 String line; 247 try { 248 line = Env.sourceLine(loc, loc.lineNumber()); 249 } catch (java.io.IOException e) { 250 line = null; 251 } 252 if (line != null) { 253 MessageOutput.println("source line number and line", 254 new Object [] {loc.lineNumber(), 255 line}); 256 } 257 } 258 } 259 MessageOutput.println(); 260 } 261 262 private void printLocationOfEvent(LocatableEvent theEvent) { 263 printBaseLocation(theEvent.thread().name(), theEvent.location()); 264 } 265 266 void help() { 267 MessageOutput.println("zz help text"); 268 } 269 270 private static final String[][] commandList = { 271 /* 272 * NOTE: this list must be kept sorted in ascending ASCII 273 * order by element [0]. Ref: isCommand() below. 274 * 275 *Command OK when OK when 276 * name disconnected? readonly? 277 *------------------------------------ 278 */ 279 {"!!", "n", "y"}, 280 {"?", "y", "y"}, 281 {"bytecodes", "n", "y"}, | 83 @Override 84 public void threadStartEvent(ThreadStartEvent e) { 85 } 86 87 @Override 88 public void threadDeathEvent(ThreadDeathEvent e) { 89 } 90 91 @Override 92 public void classPrepareEvent(ClassPrepareEvent e) { 93 } 94 95 @Override 96 public void classUnloadEvent(ClassUnloadEvent e) { 97 } 98 99 @Override 100 public void breakpointEvent(BreakpointEvent be) { 101 Thread.yield(); // fetch output 102 MessageOutput.lnprint("Breakpoint hit:"); 103 // Print current location and prompt if suspend policy is SUSPEND_EVENT_THREAD. 104 // In case of SUSPEND_ALL policy this is handled by vmInterrupted() method. 105 if (be.request().suspendPolicy() == EventRequest.SUSPEND_EVENT_THREAD) { 106 printCurrentLocation(ThreadInfo.getThreadInfo(be.thread())); 107 MessageOutput.printPrompt(); 108 } 109 } 110 111 @Override 112 public void fieldWatchEvent(WatchpointEvent fwe) { 113 Field field = fwe.field(); 114 ObjectReference obj = fwe.object(); 115 Thread.yield(); // fetch output 116 117 if (fwe instanceof ModificationWatchpointEvent) { 118 MessageOutput.lnprint("Field access encountered before after", 119 new Object [] {field, 120 fwe.valueCurrent(), 121 ((ModificationWatchpointEvent)fwe).valueToBe()}); 122 } else { 123 MessageOutput.lnprint("Field access encountered", field.toString()); 124 } 125 } 126 127 @Override 128 public void stepEvent(StepEvent se) { 216 Thread.yield(); // fetch output 217 printCurrentLocation(); 218 for (String cmd : monitorCommands) { 219 StringTokenizer t = new StringTokenizer(cmd); 220 t.nextToken(); // get rid of monitor number 221 executeCommand(t); 222 } 223 MessageOutput.printPrompt(); 224 } 225 226 @Override 227 public void receivedEvent(Event event) { 228 } 229 230 private void printBaseLocation(String threadName, Location loc) { 231 MessageOutput.println("location", 232 new Object [] {threadName, 233 Commands.locationString(loc)}); 234 } 235 236 private void printCurrentLocation(ThreadInfo threadInfo) { 237 StackFrame frame; 238 try { 239 frame = threadInfo.getCurrentFrame(); 240 } catch (IncompatibleThreadStateException exc) { 241 MessageOutput.println("<location unavailable>"); 242 return; 243 } 244 if (frame == null) { 245 MessageOutput.println("No frames on the current call stack"); 246 } else { 247 Location loc = frame.location(); 248 printBaseLocation(threadInfo.getThread().name(), loc); 249 // Output the current source line, if possible 250 if (loc.lineNumber() != -1) { 251 String line; 252 try { 253 line = Env.sourceLine(loc, loc.lineNumber()); 254 } catch (java.io.IOException e) { 255 line = null; 256 } 257 if (line != null) { 258 MessageOutput.println("source line number and line", 259 new Object [] {loc.lineNumber(), 260 line}); 261 } 262 } 263 } 264 MessageOutput.println(); 265 } 266 267 private void printCurrentLocation() { 268 printCurrentLocation(ThreadInfo.getCurrentThreadInfo()); 269 } 270 271 private void printLocationOfEvent(LocatableEvent theEvent) { 272 printBaseLocation(theEvent.thread().name(), theEvent.location()); 273 } 274 275 void help() { 276 MessageOutput.println("zz help text"); 277 } 278 279 private static final String[][] commandList = { 280 /* 281 * NOTE: this list must be kept sorted in ascending ASCII 282 * order by element [0]. Ref: isCommand() below. 283 * 284 *Command OK when OK when 285 * name disconnected? readonly? 286 *------------------------------------ 287 */ 288 {"!!", "n", "y"}, 289 {"?", "y", "y"}, 290 {"bytecodes", "n", "y"}, |