How to do data breakpoints on local variables?
If I enter the expression x == 4 in a data breakpoint, it works if x is a global but not if it's a local. Is there a way? Thanks.
-
You don't say what hardware you're targeting but generally speaking data breakpoints should work just as well on local variables as global variables.
What is possibly happening is that the local variable has been optimized away or into a register so there are no memory accesses, if this the case the data breakpoint won't work.
One other thing to consider with data breakpoints on local variables is that as the variables are stored on the stack so the variable's memory location is likely to be re-used or be in different locations between function calls.
Regards,
Jon Elliott
-
Jon,
Thanks for the reply. Target hardware is STM3210E. The code is the factorial example from the tutorial and the data breakpoint is set on the integer i. i cannot be optimized away, but I guess it could be put into a register. How can I tell? Anyway, the breakpoint icon (burgundy colored ball) has a question mark in it. Does that mean CW cannot resolve it? In general, can local vars serve as databreakpoints? I mean, if they are stack-based, how can the debugger resolve them?
-
> The code is the factorial example from the tutorial and the data breakpoint is set on the integer i. i cannot be optimized away, but I guess it could be put into a register. How can I tell?
Take a look at the disassembly.
> Anyway, the breakpoint icon (burgundy colored ball) has a question mark in it. Does that mean CW cannot resolve it?
If you hover over this icon, it should tell you the cause.
> I mean, if they are stack-based, how can the debugger resolve them?
It is the same as watching local variables in the watch window, if you are stopped within a function, the debugger can calculate the address of the variable.
Please sign in to leave a comment.
Comments
5 comments