I have a very strange (at least, to me) behavior of gdb:
when I step through some code, and print the value of a simple int
variable, I get different results, depending on whether I link
one of my libraries or not.

Here is the little sample program:

    #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>
    int main( void )
    {
        unsigned int c = 4;
        c = static_cast<unsigned int>( logf( c*c ) );
        printf("c=%d\n", c );
        return 0;
    }

This is how I compile/link it:

    /usr/bin/g++ -ansi -DOSG_DEBUG -DOSG_BUILD_DLL -DOSG_WITH_GLUT
    -DOSG_WITH_QT -g3 -ggdb3 -Wall -W  -D_GNU_SOURCE
    -I/usr/local/include/OpenSG -o obj/linux2_gcc_dbg/q.o -c q.cpp

    /usr/bin/g++ -g3 -ggdb3 -L/usr/X11R6/lib -L/usr/local/lib/OpenSG
    obj/linux2_gcc_dbg/q.o  -lOSGBase -lOSGSystem -lglut -lGLU -lGL -lXmu
    -lXi -lXt -lX11 -o q

Now, when I step through the program, I get this:

    (gdb) b 8
    Breakpoint 1 at 0x8048686: file q.cpp, line 8.
    (gdb) r
    Starting program: /work/vd3/kelvin/Coll/test/q
    Breakpoint 1, main () at q.cpp:8
    8               unsigned int c = 4;
    (gdb) n
    9               c = static_cast<unsigned int>( logf( c*c ) );
    (gdb) p c
    $4 = 4
    (gdb) n
    10              printf("c=%d\n", c );
    (gdb) p c
    $5 = 0
    (gdb) n
    c=0
    12              return 0;

The funny thing is, when I omit the libraries OSGBase OSGSystem,
I get the correct behavior ("c=2") even when I step through
the program as above!
This is even more funny, because those libraries are actually
not used in the little example above!

All this happens under RedHat 7.1 with g++ 2.96 and
GNU gdb Red Hat Linux 7.x (5.0rh-15) (MI_OUT).

Any ideas?

Thanks a lot in advance,
Gab.

-- 
/---------------------------------------------------------------------\
| And what if all of animated nature                                  |
| Be but organic Harps diversely fram'd,                              |
| That tremble into thought, as o'er them sweeps                      |
| Plastic and vast, one intellectual breeze,                          |
| At once the Soul of each, and God of all?  (Samuel Taylor Coleridge)|
|                                                                     |
| [EMAIL PROTECTED]                 __@/'  [EMAIL PROTECTED] |
| web.informatik.uni-bonn.de/~zach    __@/'   www.gabrielzachmann.org |
\---------------------------------------------------------------------/

_______________________________________________
Bug-gdb mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-gdb

Reply via email to