participate


Debugging Tools and Techniques - JDI: How do I manually create a breakpoint?
<<   Back to Forum  |   Give us Feedback
This topic has 2 replies on 1 page.
Bjoern.Eilers
Posts:4
Registered: 7/22/05
JDI: How do I manually create a breakpoint?   
Jul 22, 2005 3:55 AM

 
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
 
riejo
Posts:42
Registered: 11/16/02
Re: JDI: How do I manually create a breakpoint?   
Jul 22, 2005 6:35 AM (reply 1 of 2)  (In reply to original post )

 
Hi Bjoern!

Breakpoints -in general- work for specific code locations. A location is made up from several things.
(0) the type: class or interface
(1) the class
(2) the method
(3) the actual location (code offset) in that method
The JDWP uses a 17byte location array for stuff like that. To ease the whole breakpoint story the JDI offers you all location of a method. See List<Location> allLineLocations() in com.sun.jdi.Method.

Well, you have to take these steps:
(1) Get the reference of a class (hint: ClassPrepareEvent)
(2) Select a method of that class and retrieve the locations
(3) Pick a location and set your breakpoint

Hope that could help you
 
Bjoern.Eilers
Posts:4
Registered: 7/22/05
Re: JDI: How do I manually create a breakpoint?   
Jul 25, 2005 6:11 AM (reply 2 of 2)  (In reply to #1 )

 
Hi Johannes,

thanks for your reply - especially the hint regarding the ClassPrepareEvent. That was exactly what I was looking for.

Best regards,
Bjoern
 
This topic has 2 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums