Hello,
first of all, please excuse if my English is not the best...
I am trying to manually create a breakpoint in a VM that is launched via the sun.com.jdi.CommandLineLaunch connector. I wish to create this break-point at the start of the main(String[]) method of my Test class. For this, as far as I understand, I need to get the Location of Test.main. However, this is where I fail - I do not see how to create this Location object. I would really appreciate it if one of you could point me into the right direction.
This is the current state of my code:
public void runDebugSession() {
// get command line connector from list of available connectors
Connector connector = null;
List<Connector> connectors = Bootstrap.virtualMachineManager()
.allConnectors();
for (Connector c : connectors) {
if (c.name().equals("com.sun.jdi.CommandLineLaunch"))
connector = c;
}
// set arguments for this connector.
Map<String, Connector.Argument> arguments = connector.defaultArguments();
Connector.Argument main = arguments.get("main");
Connector.Argument options = arguments.get("options");
Connector.Argument suspend = arguments.get("suspend");
main.setValue("mypck.Test arg1");
options.setValue("-cp {myclasspath}");
LaunchingConnector launcher = (LaunchingConnector) connector;
VirtualMachine vm = null;
try {
vm = launcher.launch(arguments);
vm.suspend();
} catch (Exception e) {
System.exit(0);
}
Process process = vm.process();
EventRequestManager erm = vm.eventRequestManager();
BreakPointRequest breakPoint = erm.createBreakpointRequest(/* how do I get the correct location? */);
boolean doLoop = true;
EventQueue eventQueue = vm.eventQueue();
vm.resume();
while (doLoop) {
EventSet eventSet = null;
try {
eventSet = eventQueue.remove();
} catch (InterruptedException e) {
e.printStackTrace();
System.exit(0);
}
EventIterator eventIterator = eventSet.eventIterator();
while (eventIterator.hasNext()) {
Event event = eventIterator.nextEvent();
if (event instanceof BreakpointEvent) {
// handle break point event in here
}
vm.resume();
}
}
}
Thank you for your held in advance and best regards,
Bjoern