Debugging Global Variables

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 šŸ™‚

5 thoughts on “Debugging Global Variables

    • It all depends on what the compiler writes for these static locals into the object files. I have seen that compilers are using different names (like varName.1 for a static variable names ‘varName’), or marking it like a ‘true local’ variable. That way the debugger shows it if you are in that function, but not outside. Which is unfortunate. I have logged a feature request on that subject, so hopefully this will be addressed. But here is how I workaround this: I’m using the Expressions view, and add a new expression like *(short*)(0x180) where 0x180 is the address of my static local variable. Again, I have not found a way how to use a symbolic name, but this works for me.

      Like

      • Thanks! Taking about Expressions, could they be automatically refreshed when target is running as with variables? And what about the “Add Visualization” menu item when right-clicking a variable in Variables View?

        Like

        • The Expressions view currently does not support automatic refresh while the target is running. At least not in 10.2, but I could imagine that this could get implemented in a future version. The “Add Visualization” is a feature for the Freescale DSC controllers. I have not played with this yet, but now I think I need to reserve some time for this on the week-end if I can :-).

          Like

  1. Pingback: Watching Static Variables | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.