I'm having gdb-5.0 act oddly in the following code: 
    class A {
        public:
            A() { }
        private:
            static unsigned u2u(unsigned);
    };

    unsigned A::u2u(unsigned u) {
        return u/2;
    }

    int main() {
        A a;
        return 0;
    }

I attached g++ --verbose ; the same happens with 2.95.3

Then I do:
    > gdb foo
    GNU gdb 5.0
    Copyright 2000 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "sparc-sun-solaris2.8"...
    (gdb) b main
    Breakpoint 1 at 0x1063c: file foo.cpp, line 13.
    (gdb) run
    Starting program: /home/bhudson/livingstone/mba/cpp/foo 

    Breakpoint 1, main () at foo.cpp:13
    13          A a;
    (gdb) p A::u2u(10)
    $1 = 5
    (gdb) b A::A
    Breakpoint 2 at 0x10708: file foo.cpp, line 3.
    (gdb) c
    Continuing.

    Breakpoint 2, A::A (this=0xffbef82f) at foo.cpp:3
    3               A() { }
    (gdb) p A::u2u(10)
    $2 = 5
    (gdb) p u2u(10)
    $3 = 2145352727
    (gdb) p this
    $4 = (A *) 0xffbef82f
    (gdb) p (unsigned)this
    $5 = 4290705455
    (gdb) p $5/2
    $6 = 2145352727


So it seems gdb isn't quite always picking up that u2u is static.

Worse, if I quit gdb and start again, and do everything above except trying
the fully-qualified name, gdb crashes (SEGV).  That doesn't happen if I
just type 'run' again.

So the workaround is easy enough: when calling a static function, provide
the fully-qualified name.  It's just a pain in the ass.

        -- Benoît
> g++ foo.cpp -o foo -g --verbose
Reading specs from /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 
-D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dsparc -Dsun -Dunix -D__svr4__ 
-D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun 
-D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -g -D__GCC_NEW_VARARGS__ 
-Acpu(sparc) -Amachine(sparc) foo.cpp /var/tmp/cckWNkDv.ii
GNU CPP version 2.95.2 19991024 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/../../../../include/g++-3
 /opt/sfw/include
 
/opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/../../../../sparc-sun-solaris2.8/include
 /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/cc1plus /var/tmp/cckWNkDv.ii -quiet 
-dumpbase foo.cc -g -version -o /var/tmp/cc4wqecS.s
GNU C++ version 2.95.2 19991024 (release) (sparc-sun-solaris2.8) compiled by GNU C 
version 2.95.2 19991024 (release).
 /usr/ccs/bin/as -V -Qy -s -o /var/tmp/cc8raJXj.o /var/tmp/cc4wqecS.s
/usr/ccs/bin/as: Sun WorkShop 6 99/08/18
 /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/collect2 -V -Y 
P,/usr/ccs/lib:/usr/lib -Qy -o foo 
/opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/crt1.o 
/opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/crti.o /usr/ccs/lib/values-Xa.o 
/opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/crtbegin.o 
-L/opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2 -L/opt/sfw/sparc-sun-solaris2.8/lib 
-L/usr/ccs/bin -L/usr/ccs/lib -L/opt/sfw/lib /var/tmp/cc8raJXj.o -lstdc++ -lm -lgcc 
-lc -lgcc /opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/crtend.o 
/opt/sfw/lib/gcc-lib/sparc-sun-solaris2.8/2.95.2/crtn.o
ld: Software Generation Utilities - Solaris-ELF (4.0)

Reply via email to