2
|
1 |
/*
|
715
|
2 |
* Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package com.sun.tools.example.debug.bdi;
|
|
27 |
|
|
28 |
import com.sun.jdi.*;
|
|
29 |
import com.sun.jdi.event.*;
|
|
30 |
import com.sun.jdi.request.*;
|
|
31 |
import com.sun.jdi.connect.*;
|
|
32 |
import com.sun.tools.example.debug.expr.ExpressionParser;
|
|
33 |
import com.sun.tools.example.debug.expr.ParseException;
|
|
34 |
|
|
35 |
import java.io.*;
|
|
36 |
import java.util.*;
|
|
37 |
|
|
38 |
import com.sun.tools.example.debug.event.*;
|
|
39 |
|
|
40 |
import javax.swing.SwingUtilities;
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Move this towards being only state and functionality
|
|
44 |
* that spans across Sessions (and thus VMs).
|
|
45 |
*/
|
|
46 |
public class ExecutionManager {
|
|
47 |
|
|
48 |
private Session session;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* Get/set JDI trace mode.
|
|
52 |
*/
|
|
53 |
int traceMode = VirtualMachine.TRACE_NONE;
|
|
54 |
|
|
55 |
////////////////// Listener registration //////////////////
|
|
56 |
|
|
57 |
// Session Listeners
|
|
58 |
|
|
59 |
Vector<SessionListener> sessionListeners = new Vector<SessionListener>();
|
|
60 |
|
|
61 |
public void addSessionListener(SessionListener listener) {
|
|
62 |
sessionListeners.add(listener);
|
|
63 |
}
|
|
64 |
|
|
65 |
public void removeSessionListener(SessionListener listener) {
|
|
66 |
sessionListeners.remove(listener);
|
|
67 |
}
|
|
68 |
|
|
69 |
// Spec Listeners
|
|
70 |
|
|
71 |
Vector<SpecListener> specListeners = new Vector<SpecListener>();
|
|
72 |
|
|
73 |
public void addSpecListener(SpecListener cl) {
|
|
74 |
specListeners.add(cl);
|
|
75 |
}
|
|
76 |
|
|
77 |
public void removeSpecListener(SpecListener cl) {
|
|
78 |
specListeners.remove(cl);
|
|
79 |
}
|
|
80 |
|
|
81 |
// JDI Listeners
|
|
82 |
|
|
83 |
Vector<JDIListener> jdiListeners = new Vector<JDIListener>();
|
|
84 |
|
|
85 |
/**
|
|
86 |
* Adds a JDIListener
|
|
87 |
*/
|
|
88 |
public void addJDIListener(JDIListener jl) {
|
|
89 |
jdiListeners.add(jl);
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Adds a JDIListener - at the specified position
|
|
94 |
*/
|
|
95 |
public void addJDIListener(int index, JDIListener jl) {
|
|
96 |
jdiListeners.add(index, jl);
|
|
97 |
}
|
|
98 |
|
|
99 |
/**
|
|
100 |
* Removes a JDIListener
|
|
101 |
*/
|
|
102 |
public void removeJDIListener(JDIListener jl) {
|
|
103 |
jdiListeners.remove(jl);
|
|
104 |
}
|
|
105 |
|
|
106 |
// App Echo Listeners
|
|
107 |
|
|
108 |
private Vector<OutputListener> appEchoListeners = new Vector<OutputListener>();
|
|
109 |
|
|
110 |
public void addApplicationEchoListener(OutputListener l) {
|
|
111 |
appEchoListeners.addElement(l);
|
|
112 |
}
|
|
113 |
|
|
114 |
public void removeApplicationEchoListener(OutputListener l) {
|
|
115 |
appEchoListeners.removeElement(l);
|
|
116 |
}
|
|
117 |
|
|
118 |
// App Output Listeners
|
|
119 |
|
|
120 |
private Vector<OutputListener> appOutputListeners = new Vector<OutputListener>();
|
|
121 |
|
|
122 |
public void addApplicationOutputListener(OutputListener l) {
|
|
123 |
appOutputListeners.addElement(l);
|
|
124 |
}
|
|
125 |
|
|
126 |
public void removeApplicationOutputListener(OutputListener l) {
|
|
127 |
appOutputListeners.removeElement(l);
|
|
128 |
}
|
|
129 |
|
|
130 |
// App Error Listeners
|
|
131 |
|
|
132 |
private Vector<OutputListener> appErrorListeners = new Vector<OutputListener>();
|
|
133 |
|
|
134 |
public void addApplicationErrorListener(OutputListener l) {
|
|
135 |
appErrorListeners.addElement(l);
|
|
136 |
}
|
|
137 |
|
|
138 |
public void removeApplicationErrorListener(OutputListener l) {
|
|
139 |
appErrorListeners.removeElement(l);
|
|
140 |
}
|
|
141 |
|
|
142 |
// Diagnostic Listeners
|
|
143 |
|
|
144 |
private Vector<OutputListener> diagnosticsListeners = new Vector<OutputListener>();
|
|
145 |
|
|
146 |
public void addDiagnosticsListener(OutputListener l) {
|
|
147 |
diagnosticsListeners.addElement(l);
|
|
148 |
}
|
|
149 |
|
|
150 |
public void removeDiagnosticsListener(OutputListener l) {
|
|
151 |
diagnosticsListeners.removeElement(l);
|
|
152 |
}
|
|
153 |
|
|
154 |
/////////// End Listener Registration //////////////
|
|
155 |
|
|
156 |
//### We probably don't want this public
|
|
157 |
public VirtualMachine vm() {
|
|
158 |
return session == null ? null : session.vm;
|
|
159 |
}
|
|
160 |
|
|
161 |
void ensureActiveSession() throws NoSessionException {
|
|
162 |
if (session == null) throw new NoSessionException();
|
|
163 |
}
|
|
164 |
|
|
165 |
public EventRequestManager eventRequestManager() {
|
|
166 |
return vm() == null ? null : vm().eventRequestManager();
|
|
167 |
}
|
|
168 |
|
|
169 |
/**
|
|
170 |
* Get JDI trace mode.
|
|
171 |
*/
|
|
172 |
public int getTraceMode(int mode) {
|
|
173 |
return traceMode;
|
|
174 |
}
|
|
175 |
|
|
176 |
/**
|
|
177 |
* Set JDI trace mode.
|
|
178 |
*/
|
|
179 |
public void setTraceMode(int mode) {
|
|
180 |
traceMode = mode;
|
|
181 |
if (session != null) {
|
|
182 |
session.setTraceMode(mode);
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
/**
|
|
187 |
* Determine if VM is interrupted, i.e, present and not running.
|
|
188 |
*/
|
|
189 |
public boolean isInterrupted() /* should: throws NoSessionException */ {
|
|
190 |
// ensureActiveSession();
|
|
191 |
return session.interrupted;
|
|
192 |
}
|
|
193 |
|
|
194 |
/**
|
|
195 |
* Return a list of ReferenceType objects for all
|
|
196 |
* currently loaded classes and interfaces.
|
|
197 |
* Array types are not returned.
|
|
198 |
*/
|
|
199 |
public List<ReferenceType> allClasses() throws NoSessionException {
|
|
200 |
ensureActiveSession();
|
|
201 |
return vm().allClasses();
|
|
202 |
}
|
|
203 |
|
|
204 |
/**
|
|
205 |
* Return a ReferenceType object for the currently
|
|
206 |
* loaded class or interface whose fully-qualified
|
|
207 |
* class name is specified, else return null if there
|
|
208 |
* is none.
|
|
209 |
*
|
|
210 |
* In general, we must return a list of types, because
|
|
211 |
* multiple class loaders could have loaded a class
|
|
212 |
* with the same fully-qualified name.
|
|
213 |
*/
|
|
214 |
public List<ReferenceType> findClassesByName(String name) throws NoSessionException {
|
|
215 |
ensureActiveSession();
|
|
216 |
return vm().classesByName(name);
|
|
217 |
}
|
|
218 |
|
|
219 |
/**
|
|
220 |
* Return a list of ReferenceType objects for all
|
|
221 |
* currently loaded classes and interfaces whose name
|
|
222 |
* matches the given pattern. The pattern syntax is
|
|
223 |
* open to some future revision, but currently consists
|
|
224 |
* of a fully-qualified class name in which the first
|
|
225 |
* component may optionally be a "*" character, designating
|
|
226 |
* an arbitrary prefix.
|
|
227 |
*/
|
|
228 |
public List<ReferenceType> findClassesMatchingPattern(String pattern)
|
|
229 |
throws NoSessionException {
|
|
230 |
ensureActiveSession();
|
|
231 |
List<ReferenceType> result = new ArrayList<ReferenceType>(); //### Is default size OK?
|
|
232 |
if (pattern.startsWith("*.")) {
|
|
233 |
// Wildcard matches any leading package name.
|
|
234 |
pattern = pattern.substring(1);
|
51
|
235 |
for (ReferenceType type : vm().allClasses()) {
|
2
|
236 |
if (type.name().endsWith(pattern)) {
|
|
237 |
result.add(type);
|
|
238 |
}
|
|
239 |
}
|
|
240 |
return result;
|
|
241 |
} else {
|
|
242 |
// It's a class name.
|
|
243 |
return vm().classesByName(pattern);
|
|
244 |
}
|
|
245 |
}
|
|
246 |
|
|
247 |
/*
|
|
248 |
* Return a list of ThreadReference objects corresponding
|
|
249 |
* to the threads that are currently active in the VM.
|
|
250 |
* A thread is removed from the list just before the
|
|
251 |
* thread terminates.
|
|
252 |
*/
|
|
253 |
|
|
254 |
public List<ThreadReference> allThreads() throws NoSessionException {
|
|
255 |
ensureActiveSession();
|
|
256 |
return vm().allThreads();
|
|
257 |
}
|
|
258 |
|
|
259 |
/*
|
|
260 |
* Return a list of ThreadGroupReference objects corresponding
|
|
261 |
* to the top-level threadgroups that are currently active in the VM.
|
|
262 |
* Note that a thread group may be empty, or contain no threads as
|
|
263 |
* descendents.
|
|
264 |
*/
|
|
265 |
|
|
266 |
public List<ThreadGroupReference> topLevelThreadGroups() throws NoSessionException {
|
|
267 |
ensureActiveSession();
|
|
268 |
return vm().topLevelThreadGroups();
|
|
269 |
}
|
|
270 |
|
|
271 |
/*
|
|
272 |
* Return the system threadgroup.
|
|
273 |
*/
|
|
274 |
|
|
275 |
public ThreadGroupReference systemThreadGroup()
|
|
276 |
throws NoSessionException {
|
|
277 |
ensureActiveSession();
|
51
|
278 |
return vm().topLevelThreadGroups().get(0);
|
2
|
279 |
}
|
|
280 |
|
|
281 |
/*
|
|
282 |
* Evaluate an expression.
|
|
283 |
*/
|
|
284 |
|
|
285 |
public Value evaluate(final StackFrame f, String expr)
|
|
286 |
throws ParseException,
|
|
287 |
InvocationException,
|
|
288 |
InvalidTypeException,
|
|
289 |
ClassNotLoadedException,
|
|
290 |
NoSessionException,
|
|
291 |
IncompatibleThreadStateException {
|
|
292 |
ExpressionParser.GetFrame frameGetter = null;
|
|
293 |
ensureActiveSession();
|
|
294 |
if (f != null) {
|
|
295 |
frameGetter = new ExpressionParser.GetFrame() {
|
|
296 |
public StackFrame get() /* throws IncompatibleThreadStateException */ {
|
|
297 |
return f;
|
|
298 |
}
|
|
299 |
};
|
|
300 |
}
|
|
301 |
return ExpressionParser.evaluate(expr, vm(), frameGetter);
|
|
302 |
}
|
|
303 |
|
|
304 |
|
|
305 |
/*
|
|
306 |
* Start a new VM.
|
|
307 |
*/
|
|
308 |
|
|
309 |
public void run(boolean suspended,
|
|
310 |
String vmArgs,
|
|
311 |
String className,
|
|
312 |
String args) throws VMLaunchFailureException {
|
|
313 |
|
|
314 |
endSession();
|
|
315 |
|
|
316 |
//### Set a breakpoint on 'main' method.
|
|
317 |
//### Would be cleaner if we could just bring up VM already suspended.
|
|
318 |
if (suspended) {
|
|
319 |
//### Set breakpoint at 'main(java.lang.String[])'.
|
|
320 |
List<String> argList = new ArrayList<String>(1);
|
|
321 |
argList.add("java.lang.String[]");
|
|
322 |
createMethodBreakpoint(className, "main", argList);
|
|
323 |
}
|
|
324 |
|
|
325 |
String cmdLine = className + " " + args;
|
|
326 |
|
|
327 |
startSession(new ChildSession(this, vmArgs, cmdLine,
|
|
328 |
appInput, appOutput, appError,
|
|
329 |
diagnostics));
|
|
330 |
}
|
|
331 |
|
|
332 |
/*
|
|
333 |
* Attach to an existing VM.
|
|
334 |
*/
|
|
335 |
public void attach(String portName) throws VMLaunchFailureException {
|
|
336 |
endSession();
|
|
337 |
|
|
338 |
//### Changes made here for connectors have broken the
|
|
339 |
//### the 'Session' abstraction. The 'Session.attach()'
|
|
340 |
//### method is intended to encapsulate all of the various
|
|
341 |
//### ways in which session start-up can fail. (maddox 12/18/98)
|
|
342 |
|
|
343 |
/*
|
|
344 |
* Now that attaches and launches both go through Connectors,
|
|
345 |
* it may be worth creating a new subclass of Session for
|
|
346 |
* attach sessions.
|
|
347 |
*/
|
|
348 |
VirtualMachineManager mgr = Bootstrap.virtualMachineManager();
|
51
|
349 |
AttachingConnector connector = mgr.attachingConnectors().get(0);
|
2
|
350 |
Map<String, Connector.Argument> arguments = connector.defaultArguments();
|
51
|
351 |
arguments.get("port").setValue(portName);
|
2
|
352 |
|
|
353 |
Session newSession = internalAttach(connector, arguments);
|
|
354 |
if (newSession != null) {
|
|
355 |
startSession(newSession);
|
|
356 |
}
|
|
357 |
}
|
|
358 |
|
|
359 |
private Session internalAttach(AttachingConnector connector,
|
|
360 |
Map<String, Connector.Argument> arguments) {
|
|
361 |
try {
|
|
362 |
VirtualMachine vm = connector.attach(arguments);
|
|
363 |
return new Session(vm, this, diagnostics);
|
|
364 |
} catch (IOException ioe) {
|
|
365 |
diagnostics.putString("\n Unable to attach to target VM: " +
|
|
366 |
ioe.getMessage());
|
|
367 |
} catch (IllegalConnectorArgumentsException icae) {
|
|
368 |
diagnostics.putString("\n Invalid connector arguments: " +
|
|
369 |
icae.getMessage());
|
|
370 |
}
|
|
371 |
return null;
|
|
372 |
}
|
|
373 |
|
|
374 |
private Session internalListen(ListeningConnector connector,
|
|
375 |
Map<String, Connector.Argument> arguments) {
|
|
376 |
try {
|
|
377 |
VirtualMachine vm = connector.accept(arguments);
|
|
378 |
return new Session(vm, this, diagnostics);
|
|
379 |
} catch (IOException ioe) {
|
|
380 |
diagnostics.putString(
|
|
381 |
"\n Unable to accept connection to target VM: " +
|
|
382 |
ioe.getMessage());
|
|
383 |
} catch (IllegalConnectorArgumentsException icae) {
|
|
384 |
diagnostics.putString("\n Invalid connector arguments: " +
|
|
385 |
icae.getMessage());
|
|
386 |
}
|
|
387 |
return null;
|
|
388 |
}
|
|
389 |
|
|
390 |
/*
|
|
391 |
* Connect via user specified arguments
|
|
392 |
* @return true on success
|
|
393 |
*/
|
|
394 |
public boolean explictStart(Connector connector, Map<String, Connector.Argument> arguments)
|
|
395 |
throws VMLaunchFailureException {
|
|
396 |
Session newSession = null;
|
|
397 |
|
|
398 |
endSession();
|
|
399 |
|
|
400 |
if (connector instanceof LaunchingConnector) {
|
|
401 |
// we were launched, use ChildSession
|
|
402 |
newSession = new ChildSession(this, (LaunchingConnector)connector,
|
|
403 |
arguments,
|
|
404 |
appInput, appOutput, appError,
|
|
405 |
diagnostics);
|
|
406 |
} else if (connector instanceof AttachingConnector) {
|
|
407 |
newSession = internalAttach((AttachingConnector)connector,
|
|
408 |
arguments);
|
|
409 |
} else if (connector instanceof ListeningConnector) {
|
|
410 |
newSession = internalListen((ListeningConnector)connector,
|
|
411 |
arguments);
|
|
412 |
} else {
|
|
413 |
diagnostics.putString("\n Unknown connector: " + connector);
|
|
414 |
}
|
|
415 |
if (newSession != null) {
|
|
416 |
startSession(newSession);
|
|
417 |
}
|
|
418 |
return newSession != null;
|
|
419 |
}
|
|
420 |
|
|
421 |
/*
|
|
422 |
* Detach from VM. If VM was started by debugger, terminate it.
|
|
423 |
*/
|
|
424 |
public void detach() throws NoSessionException {
|
|
425 |
ensureActiveSession();
|
|
426 |
endSession();
|
|
427 |
}
|
|
428 |
|
|
429 |
private void startSession(Session s) throws VMLaunchFailureException {
|
|
430 |
if (!s.attach()) {
|
|
431 |
throw new VMLaunchFailureException();
|
|
432 |
}
|
|
433 |
session = s;
|
|
434 |
EventRequestManager em = vm().eventRequestManager();
|
|
435 |
ClassPrepareRequest classPrepareRequest = em.createClassPrepareRequest();
|
|
436 |
//### We must allow the deferred breakpoints to be resolved before
|
|
437 |
//### we continue executing the class. We could optimize if there
|
|
438 |
//### were no deferred breakpoints outstanding for a particular class.
|
|
439 |
//### Can we do this with JDI?
|
|
440 |
classPrepareRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
|
|
441 |
classPrepareRequest.enable();
|
|
442 |
ClassUnloadRequest classUnloadRequest = em.createClassUnloadRequest();
|
|
443 |
classUnloadRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
|
|
444 |
classUnloadRequest.enable();
|
|
445 |
ThreadStartRequest threadStartRequest = em.createThreadStartRequest();
|
|
446 |
threadStartRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
|
|
447 |
threadStartRequest.enable();
|
|
448 |
ThreadDeathRequest threadDeathRequest = em.createThreadDeathRequest();
|
|
449 |
threadDeathRequest.setSuspendPolicy(EventRequest.SUSPEND_NONE);
|
|
450 |
threadDeathRequest.enable();
|
|
451 |
ExceptionRequest exceptionRequest =
|
|
452 |
em.createExceptionRequest(null, false, true);
|
|
453 |
exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
|
|
454 |
exceptionRequest.enable();
|
|
455 |
validateThreadInfo();
|
|
456 |
session.interrupted = true;
|
|
457 |
notifySessionStart();
|
|
458 |
}
|
|
459 |
|
|
460 |
void endSession() {
|
|
461 |
if (session != null) {
|
|
462 |
session.detach();
|
|
463 |
session = null;
|
|
464 |
invalidateThreadInfo();
|
|
465 |
notifySessionDeath();
|
|
466 |
}
|
|
467 |
}
|
|
468 |
|
|
469 |
/*
|
|
470 |
* Suspend all VM activity.
|
|
471 |
*/
|
|
472 |
|
|
473 |
public void interrupt() throws NoSessionException {
|
|
474 |
ensureActiveSession();
|
|
475 |
vm().suspend();
|
|
476 |
//### Is it guaranteed that the interrupt has happened?
|
|
477 |
validateThreadInfo();
|
|
478 |
session.interrupted = true;
|
|
479 |
notifyInterrupted();
|
|
480 |
}
|
|
481 |
|
|
482 |
/*
|
|
483 |
* Resume interrupted VM.
|
|
484 |
*/
|
|
485 |
|
|
486 |
public void go() throws NoSessionException, VMNotInterruptedException {
|
|
487 |
ensureActiveSession();
|
|
488 |
invalidateThreadInfo();
|
|
489 |
session.interrupted = false;
|
|
490 |
notifyContinued();
|
|
491 |
vm().resume();
|
|
492 |
}
|
|
493 |
|
|
494 |
/*
|
|
495 |
* Stepping.
|
|
496 |
*/
|
|
497 |
void clearPreviousStep(ThreadReference thread) {
|
|
498 |
/*
|
|
499 |
* A previous step may not have completed on this thread;
|
|
500 |
* if so, it gets removed here.
|
|
501 |
*/
|
|
502 |
EventRequestManager mgr = vm().eventRequestManager();
|
51
|
503 |
for (StepRequest request : mgr.stepRequests()) {
|
2
|
504 |
if (request.thread().equals(thread)) {
|
|
505 |
mgr.deleteEventRequest(request);
|
|
506 |
break;
|
|
507 |
}
|
|
508 |
}
|
|
509 |
}
|
|
510 |
|
|
511 |
private void generalStep(ThreadReference thread, int size, int depth)
|
|
512 |
throws NoSessionException {
|
|
513 |
ensureActiveSession();
|
|
514 |
invalidateThreadInfo();
|
|
515 |
session.interrupted = false;
|
|
516 |
notifyContinued();
|
|
517 |
|
|
518 |
clearPreviousStep(thread);
|
|
519 |
EventRequestManager reqMgr = vm().eventRequestManager();
|
|
520 |
StepRequest request = reqMgr.createStepRequest(thread,
|
|
521 |
size, depth);
|
|
522 |
// We want just the next step event and no others
|
|
523 |
request.addCountFilter(1);
|
|
524 |
request.enable();
|
|
525 |
vm().resume();
|
|
526 |
}
|
|
527 |
|
|
528 |
public void stepIntoInstruction(ThreadReference thread)
|
|
529 |
throws NoSessionException {
|
|
530 |
generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_INTO);
|
|
531 |
}
|
|
532 |
|
|
533 |
public void stepOverInstruction(ThreadReference thread)
|
|
534 |
throws NoSessionException {
|
|
535 |
generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_OVER);
|
|
536 |
}
|
|
537 |
|
|
538 |
public void stepIntoLine(ThreadReference thread)
|
|
539 |
throws NoSessionException,
|
|
540 |
AbsentInformationException {
|
|
541 |
generalStep(thread, StepRequest.STEP_LINE, StepRequest.STEP_INTO);
|
|
542 |
}
|
|
543 |
|
|
544 |
public void stepOverLine(ThreadReference thread)
|
|
545 |
throws NoSessionException,
|
|
546 |
AbsentInformationException {
|
|
547 |
generalStep(thread, StepRequest.STEP_LINE, StepRequest.STEP_OVER);
|
|
548 |
}
|
|
549 |
|
|
550 |
public void stepOut(ThreadReference thread)
|
|
551 |
throws NoSessionException {
|
|
552 |
generalStep(thread, StepRequest.STEP_MIN, StepRequest.STEP_OUT);
|
|
553 |
}
|
|
554 |
|
|
555 |
/*
|
|
556 |
* Thread control.
|
|
557 |
*/
|
|
558 |
|
|
559 |
public void suspendThread(ThreadReference thread) throws NoSessionException {
|
|
560 |
ensureActiveSession();
|
|
561 |
thread.suspend();
|
|
562 |
}
|
|
563 |
|
|
564 |
public void resumeThread(ThreadReference thread) throws NoSessionException {
|
|
565 |
ensureActiveSession();
|
|
566 |
thread.resume();
|
|
567 |
}
|
|
568 |
|
|
569 |
public void stopThread(ThreadReference thread) throws NoSessionException {
|
|
570 |
ensureActiveSession();
|
|
571 |
//### Need an exception now. Which one to use?
|
|
572 |
//thread.stop();
|
|
573 |
}
|
|
574 |
|
|
575 |
/*
|
|
576 |
* ThreadInfo objects -- Allow query of thread status and stack.
|
|
577 |
*/
|
|
578 |
|
|
579 |
private List<ThreadInfo> threadInfoList = new LinkedList<ThreadInfo>();
|
|
580 |
//### Should be weak! (in the value, not the key)
|
|
581 |
private HashMap<ThreadReference, ThreadInfo> threadInfoMap = new HashMap<ThreadReference, ThreadInfo>();
|
|
582 |
|
|
583 |
public ThreadInfo threadInfo(ThreadReference thread) {
|
|
584 |
if (session == null || thread == null) {
|
|
585 |
return null;
|
|
586 |
}
|
51
|
587 |
ThreadInfo info = threadInfoMap.get(thread);
|
2
|
588 |
if (info == null) {
|
|
589 |
//### Should not hardcode initial frame count and prefetch here!
|
|
590 |
//info = new ThreadInfo(thread, 10, 10);
|
|
591 |
info = new ThreadInfo(thread);
|
|
592 |
if (session.interrupted) {
|
|
593 |
info.validate();
|
|
594 |
}
|
|
595 |
threadInfoList.add(info);
|
|
596 |
threadInfoMap.put(thread, info);
|
|
597 |
}
|
|
598 |
return info;
|
|
599 |
}
|
|
600 |
|
|
601 |
void validateThreadInfo() {
|
|
602 |
session.interrupted = true;
|
51
|
603 |
for (ThreadInfo threadInfo : threadInfoList) {
|
|
604 |
threadInfo.validate();
|
2
|
605 |
}
|
|
606 |
}
|
|
607 |
|
|
608 |
private void invalidateThreadInfo() {
|
|
609 |
if (session != null) {
|
|
610 |
session.interrupted = false;
|
51
|
611 |
for (ThreadInfo threadInfo : threadInfoList) {
|
|
612 |
threadInfo.invalidate();
|
2
|
613 |
}
|
|
614 |
}
|
|
615 |
}
|
|
616 |
|
|
617 |
void removeThreadInfo(ThreadReference thread) {
|
51
|
618 |
ThreadInfo info = threadInfoMap.get(thread);
|
2
|
619 |
if (info != null) {
|
|
620 |
info.invalidate();
|
|
621 |
threadInfoMap.remove(thread);
|
|
622 |
threadInfoList.remove(info);
|
|
623 |
}
|
|
624 |
}
|
|
625 |
|
|
626 |
/*
|
|
627 |
* Listen for Session control events.
|
|
628 |
*/
|
|
629 |
|
|
630 |
private void notifyInterrupted() {
|
|
631 |
Vector l = (Vector)sessionListeners.clone();
|
|
632 |
EventObject evt = new EventObject(this);
|
|
633 |
for (int i = 0; i < l.size(); i++) {
|
|
634 |
((SessionListener)l.elementAt(i)).sessionInterrupt(evt);
|
|
635 |
}
|
|
636 |
}
|
|
637 |
|
|
638 |
private void notifyContinued() {
|
|
639 |
Vector l = (Vector)sessionListeners.clone();
|
|
640 |
EventObject evt = new EventObject(this);
|
|
641 |
for (int i = 0; i < l.size(); i++) {
|
|
642 |
((SessionListener)l.elementAt(i)).sessionContinue(evt);
|
|
643 |
}
|
|
644 |
}
|
|
645 |
|
|
646 |
private void notifySessionStart() {
|
|
647 |
Vector l = (Vector)sessionListeners.clone();
|
|
648 |
EventObject evt = new EventObject(this);
|
|
649 |
for (int i = 0; i < l.size(); i++) {
|
|
650 |
((SessionListener)l.elementAt(i)).sessionStart(evt);
|
|
651 |
}
|
|
652 |
}
|
|
653 |
|
|
654 |
private void notifySessionDeath() {
|
|
655 |
/*** noop for now
|
|
656 |
Vector l = (Vector)sessionListeners.clone();
|
|
657 |
EventObject evt = new EventObject(this);
|
|
658 |
for (int i = 0; i < l.size(); i++) {
|
|
659 |
((SessionListener)l.elementAt(i)).sessionDeath(evt);
|
|
660 |
}
|
|
661 |
****/
|
|
662 |
}
|
|
663 |
|
|
664 |
/*
|
|
665 |
* Listen for input and output requests from the application
|
|
666 |
* being debugged. These are generated only when the debuggee
|
|
667 |
* is spawned as a child of the debugger.
|
|
668 |
*/
|
|
669 |
|
|
670 |
private Object inputLock = new Object();
|
|
671 |
private LinkedList<String> inputBuffer = new LinkedList<String>();
|
|
672 |
|
|
673 |
private void resetInputBuffer() {
|
|
674 |
synchronized (inputLock) {
|
|
675 |
inputBuffer = new LinkedList<String>();
|
|
676 |
}
|
|
677 |
}
|
|
678 |
|
|
679 |
public void sendLineToApplication(String line) {
|
|
680 |
synchronized (inputLock) {
|
|
681 |
inputBuffer.addFirst(line);
|
|
682 |
inputLock.notifyAll();
|
|
683 |
}
|
|
684 |
}
|
|
685 |
|
|
686 |
private InputListener appInput = new InputListener() {
|
|
687 |
public String getLine() {
|
|
688 |
// Don't allow reader to be interrupted -- catch and retry.
|
|
689 |
String line = null;
|
|
690 |
while (line == null) {
|
|
691 |
synchronized (inputLock) {
|
|
692 |
try {
|
|
693 |
while (inputBuffer.size() < 1) {
|
|
694 |
inputLock.wait();
|
|
695 |
}
|
51
|
696 |
line = inputBuffer.removeLast();
|
2
|
697 |
} catch (InterruptedException e) {}
|
|
698 |
}
|
|
699 |
}
|
|
700 |
// We must not be holding inputLock here, as the listener
|
|
701 |
// that we call to echo a line might call us re-entrantly
|
|
702 |
// to provide another line of input.
|
|
703 |
// Run in Swing event dispatcher thread.
|
|
704 |
final String input = line;
|
|
705 |
SwingUtilities.invokeLater(new Runnable() {
|
|
706 |
public void run() {
|
|
707 |
echoInputLine(input);
|
|
708 |
}
|
|
709 |
});
|
|
710 |
return line;
|
|
711 |
}
|
|
712 |
};
|
|
713 |
|
|
714 |
private static String newline = System.getProperty("line.separator");
|
|
715 |
|
|
716 |
private void echoInputLine(String line) {
|
|
717 |
Vector l = (Vector)appEchoListeners.clone();
|
|
718 |
for (int i = 0; i < l.size(); i++) {
|
|
719 |
OutputListener ol = (OutputListener)l.elementAt(i);
|
|
720 |
ol.putString(line);
|
|
721 |
ol.putString(newline);
|
|
722 |
}
|
|
723 |
}
|
|
724 |
|
|
725 |
private OutputListener appOutput = new OutputListener() {
|
|
726 |
public void putString(String string) {
|
|
727 |
Vector l = (Vector)appOutputListeners.clone();
|
|
728 |
for (int i = 0; i < l.size(); i++) {
|
|
729 |
((OutputListener)l.elementAt(i)).putString(string);
|
|
730 |
}
|
|
731 |
}
|
|
732 |
};
|
|
733 |
|
|
734 |
private OutputListener appError = new OutputListener() {
|
|
735 |
public void putString(String string) {
|
|
736 |
Vector l = (Vector)appErrorListeners.clone();
|
|
737 |
for (int i = 0; i < l.size(); i++) {
|
|
738 |
((OutputListener)l.elementAt(i)).putString(string);
|
|
739 |
}
|
|
740 |
}
|
|
741 |
};
|
|
742 |
|
|
743 |
private OutputListener diagnostics = new OutputListener() {
|
|
744 |
public void putString(String string) {
|
|
745 |
Vector l = (Vector)diagnosticsListeners.clone();
|
|
746 |
for (int i = 0; i < l.size(); i++) {
|
|
747 |
((OutputListener)l.elementAt(i)).putString(string);
|
|
748 |
}
|
|
749 |
}
|
|
750 |
};
|
|
751 |
|
|
752 |
///////////// Spec Request Creation/Deletion/Query ///////////
|
|
753 |
|
|
754 |
private EventRequestSpecList specList = new EventRequestSpecList(this);
|
|
755 |
|
|
756 |
public BreakpointSpec
|
|
757 |
createSourceLineBreakpoint(String sourceName, int line) {
|
|
758 |
return specList.createSourceLineBreakpoint(sourceName, line);
|
|
759 |
}
|
|
760 |
|
|
761 |
public BreakpointSpec
|
|
762 |
createClassLineBreakpoint(String classPattern, int line) {
|
|
763 |
return specList.createClassLineBreakpoint(classPattern, line);
|
|
764 |
}
|
|
765 |
|
|
766 |
public BreakpointSpec
|
|
767 |
createMethodBreakpoint(String classPattern,
|
51
|
768 |
String methodId, List<String> methodArgs) {
|
2
|
769 |
return specList.createMethodBreakpoint(classPattern,
|
|
770 |
methodId, methodArgs);
|
|
771 |
}
|
|
772 |
|
|
773 |
public ExceptionSpec
|
|
774 |
createExceptionIntercept(String classPattern,
|
|
775 |
boolean notifyCaught,
|
|
776 |
boolean notifyUncaught) {
|
|
777 |
return specList.createExceptionIntercept(classPattern,
|
|
778 |
notifyCaught,
|
|
779 |
notifyUncaught);
|
|
780 |
}
|
|
781 |
|
|
782 |
public AccessWatchpointSpec
|
|
783 |
createAccessWatchpoint(String classPattern, String fieldId) {
|
|
784 |
return specList.createAccessWatchpoint(classPattern, fieldId);
|
|
785 |
}
|
|
786 |
|
|
787 |
public ModificationWatchpointSpec
|
|
788 |
createModificationWatchpoint(String classPattern, String fieldId) {
|
|
789 |
return specList.createModificationWatchpoint(classPattern,
|
|
790 |
fieldId);
|
|
791 |
}
|
|
792 |
|
|
793 |
public void delete(EventRequestSpec spec) {
|
|
794 |
specList.delete(spec);
|
|
795 |
}
|
|
796 |
|
|
797 |
void resolve(ReferenceType refType) {
|
|
798 |
specList.resolve(refType);
|
|
799 |
}
|
|
800 |
|
|
801 |
public void install(EventRequestSpec spec) {
|
|
802 |
specList.install(spec, vm());
|
|
803 |
}
|
|
804 |
|
51
|
805 |
public List<EventRequestSpec> eventRequestSpecs() {
|
2
|
806 |
return specList.eventRequestSpecs();
|
|
807 |
}
|
|
808 |
}
|