This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

u16 locals not showing properly in IAR debugger

Hello,

i am having a strange problem where i can't see a u16 local variable in the IAR debugger (IAR 5.40.3, CC430). I have some pretty simple code:

u8 byte = 0xAB; // IAR debugger, locals shows this value fine once set

u16 word = 0xABBA; // IAR debugger, locals shows this value fine once set

u8 byte = *data; // IAR debugger, locals shows this value fine once set

u8 word_h = *data; // IAR debugger, locals shows this value fine once set

u8 word_l = *(data+1); // IAR debugger, locals shows this value fine once set

u16 word = word_h << 8; //IAR debugger shows "<error>"

word |= word_l; //IAR debugger shows "<error>"

u16 word = *data; //IAR debugger shows "<error>"





any idea what might cause this? 

Thanks in advance,
-r

UPDATE: it seems the "Auto" window shows the proper values but the "Locals" doesn't. See screenshot


  • When that happens to me that is because  the compiler is using a register to store the variable, instead of RAM. In CCS the watch function does not seem to understand that the memory location is a register so it says that the memory location is undefined. And I have to open up the register window in order to see the variable. You have to look at the disasssembler output to see what is happening.

     Sometimes if I set the compiler to the lowest setting for optimization it will then use a RAM memory location. Or I define it as static to force it for debug.

  • indeed, the compiler optimized code by not assigning any ram (stack) location to local variables which are not used, or get a value once that never changes, or are used only for a short time. These vartiables may be turned into registers, may share the same register or may be considered a constant. The debugger, however, does not know about these optimizations.
    The compile rmay even change the moment when these variables are initialized.

    If using a debugger, you should disable all optimizations, so the code is compiled in exactly the order it is written, and variables are created and used as the source code shows.
    Once the program is running, optimizations can be enabled for saving space or gaining speed. And another test run is necessary to ensure that the optimization doesn't break anything (usually due to shakey timings, but sometimes due to a compiler bug)

    p.s.: Defining local variables static turns them in disguised global variables. Globally allocated but unknown ouside the code block they are defined in)

  • Hello and thanks for the reply. I have indeed tried to define them static but that does not change the behavior of the IAR debugger, still don't see them. Also, i should have stated this in the original post, my project compiles with optimizations OFF. 

    Meanwhile, i have replicated this project in CCS and was able to debug what i needed as i find the variable display of the debugger in CCS more robust. I especially like the ability to look at pointers as arrays, very handy. 

    So for now, i haven't found a solution to this problem in IAR which as a side-effect gave me a chance to look at CCS, which i had planned for a long time and i like what i see.

    Unfortunately i ran into another problem with CCS (see other post from me) where i am unable to program the BSL memory with CCS, which is too bad.

    Thanks for all the replies so far,

    -r

**Attention** This is a public forum