Skip to main content

[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




From:
Daniel Gong <daniel.gong.fudan@xxxxxxxxx>
To:
"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
implementation
Sent by:
jdt-debug-dev-bounces@xxxxxxxxxxx






On Fri, Jun 18, 2010 at 9:30 PM, Darin Wright <Darin_Wright@xxxxxxxxxx>
wrote:
>
> Thanks Darin. The problem is the EventQueue's remove() method keeps
> waiting after the vm started when running with JDT's JDI while it
> runs well with Sun's JDI
>

The spec for the remove() method is "Waits forever for the next available
event."


Yes I know that. So the problem is supposed to that the next available
event never comes.

Found here:

http://java.sun.com/javase/6/docs/jdk/api/jpda/jdi/com/sun/jdi/event/EventQueue.html#remove()


Perhaps you need to resume the VM after startup to get it running (the
connection parameters indicate it will suspend on startup).

I've tried this and it fails as well. Furthermore, as I said before, this
code runs perfectly well with Sun's JDI...


Darin
_______________________________________________
jdt-debug-dev mailing list
jdt-debug-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jdt-debug-dev


Best wishes
Daniel Gong
_______________________________________________
jdt-debug-dev mailing list
jdt-debug-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jdt-debug-dev



_______________________________________________
jdt-debug-dev mailing list
jdt-debug-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jdt-debug-dev


Back to the top