[Bug exp/12142] New: Wrong member address in huge classes

alla.veytsal at gmail dot com sourceware-bugzilla@sourceware.org
Wed Oct 20 07:52:00 GMT 2010


           Summary: Wrong member address in huge classes
           Product: gdb
           Version: 7.1
            Status: NEW
          Severity: normal
          Priority: P2
         Component: exp
        AssignedTo: unassigned@sourceware.org
        ReportedBy: alla.veytsal@gmail.com

Created attachment 5072
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5072
The source code to reproduce the bug

If a class has very big member, addresses of members located after it are
reported incorrectly by gdb.

In the attached main.cpp file, I define class A with two members: bigArr and v.
I provide method 'show()' to check the addresses of the members.

I compile this code with the following command:
/pkg/gnu-gcc-/4.1.2/x86_64-linux/bin/g++ -ggdb3 main.cpp

(using gcc 4.1.2)
on Linux Redhat 5 machine

=> cat /etc/redhat-release
Red Hat Enterprise Linux Client release 5.3 (Tikanga)

The code is compiled to 64-bit executable.

file a.out
a.out: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux
2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

When I run this under gdb 7.1 (64-bit) I get the following.

=> /pkg/gnu-gdb-/7.1/x86_64-linux/bin/gdb a.out
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
Reading symbols from /home/cad_shop/alla/rocoo/users/liat/a.out...done.
(gdb) b main
Breakpoint 1 at 0x4009e0: file main.cpp, line 29.
(gdb) r
Starting program: /home/cad_shop/alla/rocoo/users/liat/a.out

Breakpoint 1, main (argc=1, argv=0x7fffffffdfd8) at main.cpp:29
29        A* d = new A;
(gdb) n
30        d->show();
(gdb) s
A::show (this=0x2aaaab008010) at main.cpp:18
18        cout << "this=" <<this << endl;
(gdb) n
19        cout <<"v=" << v << endl;
20        cout << "addr of this->v=" << &this->v << endl;
addr of this->v=0x2aaac0188010
21        cout << "addr of this->bigArr=" << this->bigArr << endl;
(gdb) p &this->v
$1 = (int *) 0x2aaaa0188010
(gdb) p this->v
Cannot access memory at address 0x2aaaa0188010
(gdb) c
addr of this->bigArr=0x2aaaab008010

Program exited normally.
(gdb) q

The address of 'v' member is wrong and, as a result, gdb can not print the
value of this member.

If I reduce the size of bigArr by 2x, I get correct behaviour of gdb.

I see similar behaviour with older versions of gdb and with 32-bit compilation.

Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the Gdb-prs mailing list