From: "David Plumb" <David.Plumb@intellon.com>
To: <gdb@sourceware.org>
Subject: incorrect address of class member
Date: Wed, 12 Aug 2009 13:35:00 -0000 [thread overview]
Message-ID: <5630E8542965844685CBA4EB1C4785048EA900@cdnpostal.Intellon.com> (raw)
Hi,
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
{
public:
Blah(): mFlag(0) {}
void setFlag( int value ) {
mFlag = value;
}
void printFlag() {
printf( "Flag value is %d\n", mFlag );
}
private:
int mHugeArray[0x08000001];
int mFlag;
};
int main( int argc, char* argv[] )
{
Blah* foo = new Blah();
foo->setFlag(1);
foo->printFlag();
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
<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"...
(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
gdb_problem.cpp:7
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
Thanks!
David
next reply other threads:[~2009-08-12 13:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-12 13:35 David Plumb [this message]
2009-08-12 13:47 ` Daniel Jacobowitz
2009-08-12 14:23 ` Tom Tromey
2009-08-12 19:19 ` Tom Tromey
2009-08-12 19:26 ` David Plumb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5630E8542965844685CBA4EB1C4785048EA900@cdnpostal.Intellon.com \
--to=david.plumb@intellon.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox