avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Debug with AVRStudio4?


From: Russell Shaw
Subject: Re: [avr-gcc-list] Debug with AVRStudio4?
Date: Thu, 08 Sep 2005 10:33:54 +1000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050802 Debian/1.7.10-1

Joerg Wunsch wrote:
Russell Shaw <address@hidden> wrote:

When you use gdb on code that has been optimized with -O2, the
source highlighter bar jumps all over the place making it hard to
follow the code.

Sure.  Get used to it...

No amount of getting used to it makes it easier.

With -O0, the bar follows every source line as you'd imagine.

Sure.  No optimization.  Completely different code written by the
compiler.  Not just "a bit different", it's completely different.

But it should show the same algorithmic logic regardless of
optimization. Therefore, the logical behaviour should be completely
the same, even if the end assembler is different.

The purpose of the debugger is to verify that ones own imagination
of the program logic agrees with what you have created in reality.

Yes, but how would you do that on a completely different problem?

Your program logic shouldn't change just because of optimization.

Simple example: you forgot to mark a variable "volatile" that is
modified by an interrupt routine.  Sure, your imagination of the
program logic would work fine, and the debugger seems to support this.
Yet, it's still your code that is at fault, and only the optimizer
will show you that.  There can be more sophisticated examples found
like this one.  Lastly, once your skill level of ``mortal C'' is good
enough, I'd say you most of the time won't make much of those simple
mistakes anymore that could easily be found with optimization turned
off.

New code is much easier to verify with -O0, to get it doing what you
want at all. If the program behaviour is then different running without
the debugger and with -O2, then you debug with -O2 enabled.

I rather live with the debugger's code pointer jumping around, than
wasting my time in debugging something that's not gonna be ``The Real
Thing'', only in order to find that I'll eventually have to debug it
again once optimization was enabled.

I always find that the time saved in debugging initially with -O0, then
-02 if neccessary, is more than trying to debug only in -O2.

With a program verified with -O0, if it behaves differently
with -O2, you *know* there's an optimizer issue, or your code
needs to be modified to account for the effects of optimization.

In 99.99 % it'll be the latter, only 0.01 % account on true optimizer
bugs.  It's by several orders of magnitude more likely that you
trigger an Internal Compiler Error (ICE) in GCC than an optimizer bug.

99% of the time, my code compiled with -O0 works identically with -O2,
but slightly faster or more compact. I haven't got any ICE yet.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]