Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Debugging Global Variables

DZone's Guide to

Debugging Global Variables

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.


If I’m debugging my application in Eclipse or CodeWarrior, it shows in the Variables view the local and global variables of the current Thread and stack frame only:

Debug View with Variables View

Debug View with Variables View

This makes sense as this is usually where my focus is. And this is good from a performance point of view: The debugger does not need to read a lot of other variables from the target which I’m not interested in. But the question is: how to show the variables which are in other files if I really need to look at them?

Add Global Variable

To see as other variables, I use the context menu ‘Add Global Variables…‘ in the Variables view. There is as well a toolbar icon which does the same:

Add Global Variables

Add Global Variables

This opens a dialog with a list of all global variables present in my application:

Add Globals Dialog

Add Globals Dialog

Filtering and Wildcards

I can enter a filter string to be applied. That helps to narrow down the list if I do not remember the exact name:

Add Globals with Filter

Add Globals with Filter

Filter for Files

A powerful trick is to filter for variables in files. For this the format <variableName>#<fileName> is used:

Add Globals with File Filter

Add Globals with File Filter

Summary

Debugging and inspecting variables outside of the current thread or stackframe can be done with ‘Add Globals’ in the Variables view. That dialog has powerful filtering including a way to filter for variables in files.

Happy Global Debugging :-)

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}