This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

incorrect address of class member


I'm sorry if this is the wrong mailing list. I am having a problem with
gdb but I don't know if it falls into the category of a bug report yet.

The following code illustrates the problem. The expected output of this
little program is the string "Flag value is 1" being printed in the
terminal. It works but when I debug it with gdb, I see unexpected
things. It appears as if gdb is getting confused about how the memory is
being allocated for the Blah class object. The address of the mFlag
member is reported by gdb to be 0xd7ffb00c when it should be 0xf7ffb00c.
If gdb is using the wrong address for the mFlag member, it explains why
the gdb print command is returning the wrong value for the mFlag member.

I hope to learn why this is happening, if it can be fixed by configuring
gdb properly and/or if this falls into the category of a gdb bug.

#include "stdio.h"
class Blah
        Blah(): mFlag(0) {}
        void setFlag( int value ) {
            mFlag = value;
        void printFlag() {
            printf( "Flag value is %d\n", mFlag );
        int mHugeArray[0x08000001];
        int mFlag;

int main( int argc, char* argv[] )
    Blah* foo = new Blah();
    return 0;

Some relevant details:
> uname -a
Linux XXX 2.6.9-89.0.3.ELsmp #1 SMP Sat Jun 13 07:02:28 EDT 2009 x86_64
x86_64 x86_64 GNU/Linux
> cat /etc/redhat-release 
Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
> g++ --version
g++ (GCC) 3.4.6

This is my g++ command line and results for running the little program:
> g++ -g -m32 gdb_problem.cpp
> ./a.out 
Flag value is 1

This is a transcript of my gdb session:
> gdb a.out 
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu"...
(gdb) b Blah::setFlag
Breakpoint 1 at 0x80489cb: file gdb_problem.cpp, line 7.
(gdb) run
Starting program: /home/dplumb/tmp/a.out 

Breakpoint 1, Blah::setFlag (this=0xd7ffb008, value=1) at
7                   mFlag = value;
(gdb) p mFlag
$1 = 0
(gdb) p &mFlag
$2 = (int *) 0xd7ffb00c
(gdb) x 0xd7ffb008+0x20000004
0xf7ffb00c:     0x00000000
(gdb) p /x sizeof(*this)
$3 = 0x20000008
(gdb) next
8               }
(gdb) p mFlag
$4 = 0
(gdb) x 0xd7ffb008+0x20000004
0xf7ffb00c:     0x00000001


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]