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 () in the toolbar.
- Click on the Hello World icon in the test Eclipse to display the dialog, as before, and click on OK to dismiss it.
In the host Eclipse, open the
SampleHandler
class and go to theexecute()
method.- 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 representing the breakpoint will appear in the ruler:
- Click on the Hello World icon in the test Eclipse to display the dialog, and the debugger will pause the thread at the breakpoint in the host Eclipse:
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
).- Click on Step Over or press F6, and window will be added to the list of available variables:
- When ready to continue, click on Resume or press F8 to keep running.
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 – allows stepping over line-by-line in the method
- Step Into – follow the method calls recursively as execution unfolds
- Step Return – jump to the end of a method
- Drop to Frame – return to a stack frame in the thread to re-run an operation