bug-gdb
[Top][All Lists]
Advanced

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

gdb prints different results w and w/o some lib


From: Gabriel Zachmann
Subject: gdb prints different results w and w/o some lib
Date: 4 Sep 2001 11:58:55 GMT
User-agent: slrn/0.9.7.0 (Linux)

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)|
|                                                                     |
| address@hidden                 __@/'  address@hidden |
| web.informatik.uni-bonn.de/~zach    __@/'   www.gabrielzachmann.org |
\---------------------------------------------------------------------/



reply via email to

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