I have an application, written in C, that runs on a Coldfire processor.
I need to force it to use the RAM for all the local variables (declared in the functions) instead of use the registers; in order to debug the application properly.
How can I do it?
Edit for more informations
Sometimes, in the main application, I get an error due to a wrong return value from the functions. This happens seldom, I put a check and a breakpoint before the return instruction but many variables use the same register and I cannot have a clear overview on the situation when the error happens. If I move the program counter at the beginning of the function and go step by step the result is correct. Probably there is something wrong with the management of the registers and I want to discover what it is.
Thank you in advance, regards.
The normal way to do this for debugging purposes is something like
#ifdef DEBUG_RELEASE
volatile uint8_t x;
#else
uint8_t x;
#endif
When done debugging, you can remove all compiler switches. But they are good to have, so that you don't leave any debug code behind by accident (very common problem).
On most compilers, the above is enough to force variables into a RAM locations. If it isn't, you can go one step further still:
volatile uint8_t x;
volatile uint8_t* dummy = &x;
Now x
must get allocated in RAM because its address was used.
Note: if you are using the Codewarrior compiler, it came with various versions that had optimizations enabled by default. You might have to disable various optimizations manually for debugging.