I have a piece of code that writes to a global floating point variable that is stored in a particular memory address. The variable is initialized to zero. The program I am writing is still in development, so the code that writes to the variable is
global_var += 0 * function(local_var);
I.e. The code increments the variable by zero every loop. There is no other code that writes to this variable.
However, this variable changes to a random number at random intervals. This leads me to believe that I have a memory issue elsewhere in my program; one that is unintentionally writing to that memory address.
I have used stack-painting to check that this is not a stack overflow issue. Also I think it would be noticeable if the stack was overflowing onto the global data (it is a single address that is being overwritten, not an entire region of memory).
I have used the watchpoint tool in Kinetis Design Studio to have the program break whenever the variable is written to. This was not useful here as the variable is constantly being written to its previous value. I tried to use the "Condition" field when setting the watchpoint, however I was unable to find any documentation on how to use the feature, and the KDS release notes say that conditional breakpoints don't work anyway.
I have also tried changing the code so that it is not constantly being written to by my line of code so I could use a watchpoint. However, this slightly changes the program structure, causing the memory issue to move to a different area of memory. As such, it becomes much more difficult to find.
Are there any tools or methods that I could use that I am missing here? Changing the code causes the issue to be moved to a different area of memory, so it appears that poor-mans debugging is out of the question.