[Insight-users] Problems to debug with (k)gdb

Gavin Baker gavinb+xtk at cs.mu.OZ.AU
Wed Sep 28 06:00:13 EDT 2005


Hi Martin,

On Sat, Sep 24, 2005 at 10:39:02AM +0000, Martin Kavec wrote:

> [...]
> This is not, however, the case for my filter. The execution stops at the 
> breakpoint, but it jumps around if I step to next, next ... line. I have 
> compiled all ITK, NeighborhoodIterators4, and my filter with -O2 -ggdb -pipe 
> -Wall flags and yet, this strange behavior.

That sounds very much like the debugger is being a bit confused because the
code is optimized.  I suggest you first remove the "-O2" flag to turn off
optimization (at least in your own code), rebuild and try the debugger
again.

>From the GCC manual (note in parcitular the second point):

    GCC allows you to use -g with -O.  The shortcuts taken by optimized
    code may occasionally produce surprising results: some variables
    you declared may not exist at all; flow of control may briefly move
    where you did not expect it; some statements may not be executed
    because they compute constant results or their values were already
    at hand; some statements may execute in different places because
    they were moved out of loops.

    Nevertheless it proves possible to debug optimized output.  This
    makes it reasonable to use the optimizer for programs that might
    have bugs.

Let us know if you are still having problems.

Regards,

  :: Gavin

-- 
Gavin Baker                                      Complex Systems Group
http://www.cs.mu.oz.au/~gavinb             The University of Melbourne


More information about the Insight-users mailing list