0
votes

I am developing a plugin for eclipse to make custom debug actions . My use case is, I will open debugger and set breakpoints, but when i access my ui ,the debugger should not stop at my breakpoints, instead it should store the value of the variable in that breakpoint to a file and keep resuming. (I will run a selenium test case and for each request i need the values in each breakpoint to be stored in a file for testing)..

As far as I understood I have added a breakpointListener which extends IJavaBreakPointListener and overriden the breakpointHit() method

    @Override
    public int breakpointHit(IJavaThread thread, IJavaBreakpoint breakpoint) {
        // TODO Auto-generated method stub
        System.out.println("Breakpoint has been hit!!!!!!!!!!!!!!");

        /**
           I need the value of the variable at this breakpoint
         **/


        return 0;
    }

and I have to add this listener to JDIDebugModel...

using

JDIDebugModel.addJavaBreakpointListener(listener);

But i dont know in which class I should put the addJavaBreakpointListener call.. This listener is never called ..

please help I'm stuck with this. Or do suggest alternate solutions for my use case

2

2 Answers

0
votes

You don't have to write Eclipse plugin to achieve that. You can use Breakpoint Properties. Find it in context menu when you right click on the breakpoint and enter something like this. Note Conditional and Suspend when true.

enter image description here

This will execute on every hit of the breakpoint and append a line to file.txt. You have access to all variables in the code snippet, so you can log what you want.

0
votes

Your approach is correct!. Just call the JDIDebugModel.addJavaBreakpointListener(listener); anywhere inside your custom plugin like a command handler, a toolbar action, a button action, etc. Since addJavaBreakpointListener() method is a static method, it will attach the listener wherever you call it. But make sure you attach the listener only once or it will execute your custom code multiple times. Also, make sure you add all the required plugins mentioned below in plugin.xml.

  1. org.eclipse.jdt.debug
  2. org.eclipse.jdt.core
  3. org.eclipse.debug.core