So I'm trying to work myself into JDI. I was already successful hooking my debugger application into my debugee program by first starting the debuggee with VM commands:
-agentlib:jdwp=transport=dt_socket,server=y,address=8000
and then launching my debugger which establishes a connection by the use of an attaching connector:
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
AttachingConnector ac = vmm.attachingConnectors().get(0);
Map<String, Connector.Argument> env = ac.defaultArguments();
env.get("port").setValue("8000");
env.get("hostname").setValue("localhost");
VirtualMachine vm = ac.attach(env);
But now I want my debugger application to start the debuggee program itself. I understand one must use the launching connector in that case. So I tried this:
VirtualMachineManager vmm = Bootstrap.virtualMachineManager();
LaunchingConnector lc = vmm.launchingConnectors().get(0);
Map<String, Connector.Argument> env = lc.defaultArguments();
env.get("main").setValue("p.DebugDummy");
env.get("suspend").setValue("true");
env.get("home").setValue("C:/Program Files/Java/jdk1.7.0_51");
VirtualMachine vm = lc.launch(env);
However, when I start this application, my debugee program does not get launched. I get no exceptions or anything, despite of having a bunch of follow-up code to the code showed above; stuff like:
// A single implementor of this interface exists in a particuar VM
EventRequestManager mgr = vm.eventRequestManager();
// suspend VM
vm.suspend();
// lookup main thread
ThreadReference mainThread = null;
List<ThreadReference> threads = vm.allThreads();
for (ThreadReference thread : threads) {
if ("main".equals(thread.name())) {
mainThread = thread;
break;
}
}
// resume
vm.resume();
mainThread.resume();
// There is one instance of EventQueue assigned to a particular
// VirtualMachine.
EventQueue eventQueue = vm.eventQueue();
// Waits for start event.
WAIT_FOR_START: do {
EventSet eventSet = eventQueue.remove();
EventIterator eventIterator = eventSet.eventIterator();
while (eventIterator.hasNext()) {
Event event = eventIterator.next();
if (event instanceof VMStartEvent) {
System.out.println("VMStartEvent.");
break WAIT_FOR_START;
}
}
} while (true);
System.out.println("GO...");
It all runs just fine?! I do get no exceptions and all the sysouts (GO... etc). I find that quite strange -- obviously it finds a main thread and a VMStartEvent. But I guess my debugger is doing this all to itself or something? I'm afraid I didn't really grasp what all these method calls do.
So my question: Why does my debuggee program not launch?
As you can see above I did setup the "main" argument to:
env.get("main").setValue("p.DebugDummy");
My debugger application is in that same package (p). So that should be correct? But obviously I'm doing something wrong here. Any ideas?
Thank you!