How to do data breakpoints on local variables?

Comments

5 comments

  • Avatar
    Jon Elliott

    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

     

    0
    Comment actions Permalink
  • Avatar
    Albert McGilvra

    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?

    0
    Comment actions Permalink
  • Avatar
    Paul Curtis

    In general it's going to be extremely difficult to have data breakpoints placed on local variables.

    0
    Comment actions Permalink
  • Avatar
    Jon Elliott

    > 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.

    0
    Comment actions Permalink
  • Avatar
    Brian Myers

    One way around this issue would be to temporarily make the local variable in question "static". Thus it gets memory allocated to it (it's no longer on the stack). Just remember to un-do this when you're done with your debugging.

    0
    Comment actions Permalink

Please sign in to leave a comment.