Debugging on Petal. Looking at most variables shows basically random values unless they are declared globally. If they are declared inside a method the values are wrong. Anyone else have this issue?
Probably not an issue, but the expected behavior. Local variables exist on the stack (or in MCU registers) when function is executed, otherwise you’re just looking at whatever is currently stored with the same address in memory. And even if variable is in current function’s scope, compiler may reuse its memory for other variables after original value is no longer used.
Well, I’m only talking about when it’s in scope. Also I have compiler optimizations turned off. Any system I’ve worked in in the past, if a field is out of scope it reports out of scope. If it’s in scope it reports the actual value. Here for example I’m in a For loop
“for (int index = 0; index < max; index++)”
Step into the loop and index == 0, a couple steps later index == -1928754723. Really?
So I declare index globally to the cpp file and it’s fine.
This means I have to keep moving fields globally if I want to know their value. Very bad.
Hmm, that’s weird. What’s your debugging setup? Software & hardware?
I’m debugging on Petal with the STLINK V3-Mini, and I’m on W10 in VS Code 1.6.
Hello,
I have the same issue. It’s very difficult to debug because the values of variables in the watch window are incorrect. I have to add #pragma GCC optimize ("O0")
at the beginning of the file and declare variables globally with the volatile
attribute to see the correct values. Does anyone have any solutions?
Thanks,
Philippe.