[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jdt-debug-dev] Different usage of eclipse jdi lib and sun implementation
|
Thanks Darin. Could you tell me what other eclipse libraries are required to use eclipse JDI?
Just to ensure that I've configured the running environment right.
Best wishes
Daniel Gong
On Fri, Jun 18, 2010 at 10:44 PM, Darin Wright
<Darin_Wright@xxxxxxxxxx> wrote:
This code works the same for me using Eclipse JDI and Sun JDI
implementations. To use the Eclipse JDI, change the Bootstrap import to:
import org.eclipse.jdi.Bootstrap;
=============================================================
import java.util.Map;
import com.sun.jdi.Bootstrap;
import com.sun.jdi.VirtualMachine;
import com.sun.jdi.connect.Connector;
import com.sun.jdi.connect.LaunchingConnector;
import com.sun.jdi.event.Event;
import com.sun.jdi.event.EventIterator;
import com.sun.jdi.event.EventQueue;
import com.sun.jdi.event.EventSet;
import com.sun.jdi.event.VMDeathEvent;
import com.sun.jdi.request.ClassPrepareRequest;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.EventRequestManager;
public class Main {
public static void main(String[] args) throws Exception{
LaunchingConnector launchingConnector = Bootstrap.
virtualMachineManager().defaultConnector();
Map<String, Connector.Argument> arguments =
launchingConnector.defaultArguments();
arguments.get("main").setValue("HelloWorld");
arguments.get("suspend").setValue("true");
VirtualMachine targetVM =
launchingConnector.launch(arguments);
Process VMProcess = targetVM.process();
// Register ClassPrepareRequest
EventRequestManager eventRequestManager =
targetVM.eventRequestManager();
ClassPrepareRequest classPrepareRequest =
eventRequestManager.createClassPrepareRequest();
classPrepareRequest.addClassFilter("HelloWorld");
classPrepareRequest.addCountFilter(1);
classPrepareRequest.setSuspendPolicy(EventRequest.
SUSPEND_ALL);
classPrepareRequest.enable();
// Enter event loop
eventLoop(targetVM);
VMProcess.destroy();
}
private static void eventLoop(VirtualMachine targetVM) throws
Exception {
EventQueue eventQueue = targetVM.eventQueue();
boolean vmExit = false;
while (true) {
if (vmExit == true) {
break;
}
EventSet eventSet = eventQueue.remove();
EventIterator eventIterator =
eventSet.eventIterator();
while (eventIterator.hasNext()) {
Event event = (Event)
eventIterator.next();
System.out.println(event);
vmExit = execute(event);
}
eventSet.resume();
}
}
private static boolean execute(Event event) {
if (event instanceof VMDeathEvent) {
return true;
}
return false;
}
}
=================================================
The output from the Sun implementation is:
VMStartEvent in thread main
ClassPrepareEvent in thread main
VMDeathEvent
The output from the Eclipse implementation is:
VMStartEvent: 0
ClassPrepareEvent: 3
VMDeathEvent: 0
Darin Wright
"Eclipse JDT Debug developers list." <jdt-debug-dev@xxxxxxxxxxx>
Date:
06/18/2010 09:24 AM
Subject:
Re: [jdt-debug-dev] Different usage of eclipse jdi lib and sun