Hi all,
I'm having a very troubling problem when debugging with the new version of µvision (4.11) that I didn't have with the last I was on (it was 4.03 I think). When I debug code on various platforms (working on an STM32F103 and an NXPLPC1768, both CM3), I have a lot of variables that appears "Out of scope" in the watch window.
I'd like to add that I'm at optimization level 0, I tried default but it optimized more and I had even less variables visible, and that this problem did NOT happened with the previous version of the software.
Thank you in advance for you answers.
I can confirm this. Is support aware of this...?
Isn't that simply because ther are, in fact, out-of-scope?
If not, I think you need to explain more...
Admittedly, I did not look into this in depth (very busy today). I saw this happening with local variables and parameters delivered by value.
Obviously I forgot a certain amount of details, I'm taking about debugging within a simple method.
For instance the following method:
int testMethod(int a) { if (a > 0) return 1; else return 0; }
Well if i put a breakpoint within this, at any position, I would sometimes see 'a', but most times, the debbugger will say it's out of scope.
And local variables will, by definition, be out-of-scope at all times except when you're actually in the particular block to which they are local!
Have you looked at the assembler produced (and single stepped through that)?
The parameter 'a' is almost certainly being passed in a register, so it's life (as far as the debugger is concerned) would be very short.
This is an example of it happening, take a look at the local watch on the right:
tof.canardpc.com/.../d134f819-2031-4cf2-8cb7-66dc78f5675e.jpg
And the assembly code:
tof.canardpc.com/.../8f91307a-5b3c-4f7d-9a65-7b6b8c1dc520.jpg
I very much suspect that is the root of the problem!
With a trivial function like that, the actual body could possibly be implemented as just one or two machine instructions - and it can be hard to line that up precisely with 'C' source lines.
Hence you might think you're "in" the function (so the variables should be in-scope), but the debugger thinks you're not quite "in" it yet - or just on the way "out" of it - so the variables are out-of-scope...
I understand your point but: - when debugging the same method with gdb I can see the variables (not the same compiler obviously but still...), - this did not happen with the previous version of µvision
Are there at lot of work when migrating a program to GDB, the GNU Project debugger?
The optimizer removed the variable bar since you do not do anything with it. It is initialized but left unused, so all code related to the variable is removed.
You can either
volatile unsigned char bar;
Reza_ab said:the variable bar
I see no such variable in any of the nine-year-old posts.
Reza_ab said:stops the compiler from optimizing
Not entirely true - it prevents certain optimisations.
That makes sense. Thanks for a practical solution!