bug-gdb
[Top][All Lists]
Advanced

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

problem calling static


From: Benoit Hudson
Subject: problem calling static
Date: Fri, 15 Jun 2001 21:53:09 -0400

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

Attachment: g++verbose
Description: Text document


reply via email to

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