Time for action – debugging a plug-in

Debugging an Eclipse plug-in is almost the same as running an Eclipse plug-in, except that breakpoints can be used, and the state of the program can be updated, variables, and minor changes to the code can be done. Rather than debugging plug-ins individually, the entire Eclipse launch configuration is started in debug mode. That way, all the plug-ins can be debugged at the same time.

Although run mode is slightly faster, the added flexibility of being able to make changes makes debug mode much more attractive to use as a default.

Start the test Eclipse, by navigating to the Debug | Debug As | Eclipse Application menu, or by clicking on Debug (Time for action – debugging a plug-in) in the toolbar.

  1. Click on the Hello World icon Time for action – debugging a plug-in in the test Eclipse to display the dialog, as before, and click on OK to dismiss it.
  2. In the host Eclipse, open the SampleHandler class and go to the execute() method.
  3. Add a breakpoint by double-clicking in the vertical ruler (the gray/blue bar on the left of the editor), or by pressing Ctrl + Shift + B (or Cmd + Shift + B on OS X). A blue dot Time for action – debugging a plug-in representing the breakpoint will appear in the ruler:
    Time for action – debugging a plug-in
  4. Click on the Hello World icon Time for action – debugging a plug-in in the test Eclipse to display the dialog, and the debugger will pause the thread at the breakpoint in the host Eclipse:
    Time for action – debugging a plug-in

    Note

    The debugger perspective will open whenever a breakpoint is triggered and the program will be paused. While it is paused, the test Eclipse is unresponsive. Any clicks on the test Eclipse application will be ignored, and it will show a busy cursor.

  5. On the top-right, variables that are active in the line of code are shown. In this case, it's just the implicit variables (via this), any local variables (none, yet) as well as the parameter (in this case, event).
  6. Click on Step Over Time for action – debugging a plug-in or press F6, and window will be added to the list of available variables:
    Time for action – debugging a plug-in
  7. When ready to continue, click on Resume Time for action – debugging a plug-in or press F8 to keep running.

What just happened?

The built-in Eclipse debugger was used to launch Eclipse in debug mode. By triggering an action which led to a breakpoint, the debugger was revealed allowing the local variables to be introspected.

When in the debugger, there are several options available for stepping through the code:

  • Step Over What just happened? – allows stepping over line-by-line in the method
  • Step Into What just happened? – follow the method calls recursively as execution unfolds

    Note

    There is also a Run | Step into Selection menu item that does not have a toolbar icon. It can be invoked with Ctrl + F5 (Alt + F5 on OS X), and is used to step into a specific expression.

  • Step Return What just happened? – jump to the end of a method
  • Drop to Frame What just happened? – return to a stack frame in the thread to re-run an operation
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset