Debugging static variables, especially ‘static locals’ is sometimes challenging. Especially ‘static local’ debugging depends on the compiler capability how they are encoded in to the object file. I have found out that at least with CodeWarrior for MCU and ARM/Kinetis this works straight forward. Only ‘Watch Expressions’ need special attention.
I’m using following piece of source code to illustrate this:
static int static_global = 0; static portTASK_FUNCTION(Task1, pvParameters) { static int static_local = 0; (void)pvParameters; /* parameter not used */ for(;;) { static_global+=2; staticLocal++; LED1_Neg(); FRTOS1_vTaskDelay(100/portTICK_RATE_MS); } }
This code has a global static variable ‘static_global‘ and a static local variable named ‘static_local‘. ‘Static locals’ are special: they are like global variables, but with function scope.
Variables View
By default, the debugger will show me the global variables of the currently debugged source file. How to see my variables from another module? The answer is in Debugging Global Variables: I use the context menu ‘Add Global Variables…‘ in the Variables view, and I get a dialog where I can search and add my global variables:
This adds my two static variables to the view:
Expressions View
Eclipse has an Expressions view which allows me to enter an expression and to ‘watch’ it. However, if I try this it with my static variables, this does not work?
But there is a way to find out: I use the ‘Watch‘ context menu in the Variables view:
This will add it to the Expressions view:
Ahhhh! And here is the secret: I need to qualify my static variable to watch it in the Expressions view: ““FileName”::variableName”!
Now it is easy as well to use a bit more complex expression as taking the address of a static local variable:
Happy Watching 🙂
Reblogged this on Sutoprise Avenue, A SutoCom Source.
LikeLike