Tuesday, January 20, 2009

Eclipse Debugger, part V

The third view that is extremely important for me while debugging is the Expressions view. This view allows to monitor the value of (as the name says) any expressions.

How to add expressions?
Just select the expression in the Java editor while debugging and choose Watch option from the context menu. The expression will immediately appear in the Expressions view.
You can also right click in the Expressions view and choose Add Watch Expression... option.

How to edit expressions?
If you have already some expressions added you can easily edit them by right clicking on the expression and choosing Edit Watch Expression.
What is important is that you can put any expression in this view - not only the ones that are in the code - if you want to check some hypothetical value then you can do that!

The are also some other interesting options in the context menu:
  • you can copy expressions to the clipboard
  • you can remove expressions
  • you can look for expressions
  • you can enable/disable expressions
  • you can reevaluate expressions

In the view's toolbar you will find options to:
  • show type names - shows the type names of the evaluated expressions
  • show logical structures - while browsing the evaluated value of the expression you can look at its logical structure. e.g. instead of looking into the internals of the Map object:

    you can see the logical structure of the map:



  • create new watch expression (the 3rd way to do this)
  • remove/remove all expressions from the view
Like in the Variables view, here you can also find interesting possibilities to:
  • change the layout
  • show constants
  • show static variables
  • show qualified names
  • show null array entries
  • show references
This view can be really helpful, especially when you want to see how the values of particular expression change while debugging the code.

1 comment:

Anton Shaykin said...

Thanks for this article. I'm a fairly new Eclipse user, so I wasn't able to find this view myself and started to think that Eclipse doesn't have this feature but I'm glad I found it thanks to your post :)