Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Eclipse Plug-in Development Beginner's Guide

You're reading from   Eclipse Plug-in Development Beginner's Guide Extend and customize Eclipse

Arrow left icon
Product type Paperback
Published in Aug 2016
Publisher
ISBN-13 9781783980697
Length 458 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alex Blewitt Alex Blewitt
Author Profile Icon Alex Blewitt
Alex Blewitt
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Creating Your First Plug-in 2. Creating Views with SWT FREE CHAPTER 3. Creating JFace Viewers 4. Interacting with the User 5. Working with Preferences 6. Working with Resources 7. Creating Eclipse 4 Applications 8. Migrating to Eclipse 4.x 9. Styling Eclipse 4 Applications 10. Creating Features, Update Sites, Applications, and Products 11. Automated Testing of Plug-ins 12. Automated Builds with Tycho 13. Contributing to Eclipse A. Using OSGi Services to Dynamically Wire Applications B. Pop Quiz Answers Index

Time for action – debugging a plug-in

Debugging an Eclipse plug-in is much the same as running an Eclipse plug-in, except that breakpoints can be used, the state of the program can be updated, and variables and minor changes to the code can be made. 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 target Eclipse instance by navigating to Debug | Debug As | Eclipse Application, or by clicking on debug Time for action – debugging a plug-in in the toolbar.

  1. Click on the hello world icon in the target 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 first line of the execute method.
  3. Add a breakpoint by double-clicking in the vertical ruler (the grey/blue bar on the left of the editor), or by pressing Ctrl + Shift + B (or Cmd + Shift + B on macOS). A blue dot representing the breakpoint will appear in the ruler:
    Time for action – debugging a plug-in
  4. Click on the hello world icon in the target 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 target Eclipse is unresponsive. Any clicks on the target Eclipse application will be ignored, and it will show a busy cursor.

  5. In 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 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 that led to a breakpoint, the debugger was revealed, allowing the local variables to be inspected.

When in the debugger, there are several ways to step through the code:

  • Step Over: This allows stepping over line by line in the method
  • Step Into: This follows the method calls recursively as execution unfolds

    Note

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

  • Step Return: This jumps to the end of a method
  • Drop to Frame: This returns to a stack frame in the thread to re-run an operation
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image