gdb/59: static members in a base class confuse gdb
Wed Jun 6 13:48:00 GMT 2001

>Number:         59
>Category:       gdb
>Synopsis:       static members in a base class confuse gdb
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 06 13:48:01 PDT 2001
>Release:        5.0 and 20010604
Linux kernel 2.4.2 ix86 / gcc 2.95.3 / glibc 2.2.3
There is a problem displaying the content of a derived object, when its parent has static members. GDB reports an error 'Cannot access memory at address xxxx'.

I have attached one source file to this bug report. It has essentially a 'main', and two classes: 'ClassB', that derives from 'ClassA'.

ClassA has one static member, and ClassB has two static members. Both class don't have any data member (it does not seem to affect the problem, anyway).

ClassA also has a virtual destructor, that ClassB overrides.

The static members, as well as the constructor and destructors, are all defined (nothing is unresolvable).

The main routine instantiates an object of type 'ClassB', that it deletes the line after.

Just compile, link, and load this program in gdb. Then place a breakpoint after the instantiation (before the destruction). When the program is run and gdb stops, gdb is unable to print the object, and reports 'Cannot access memory at address xxx'.

If you add one more static member in ClassA, making the count equal in both classes, the problem disappears.

Note that I had exactly the same problem running on a PowerPC.

Here is an excerpt from the procedure:
[jdboyer@samlinux JDB]$ gcc -g main.cpp -o test       
[jdboyer@samlinux JDB]$ gdb test
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 "i386-redhat-linux"...
(gdb) b main
Breakpoint 1 at 0x8049258: file main.cpp, line 48.
(gdb) r
Starting program: /projects/testStatic/JDB/test 

Breakpoint 1, main () at main.cpp:48
48	    ClassB *b = new ClassB();
(gdb) n
49	    delete b;
(gdb) p *b
Cannot access memory at address 0x909d46e



More information about the Gdb-prs mailing list