* incorrect address of class member
@ 2009-08-12 13:35 David Plumb
2009-08-12 13:47 ` Daniel Jacobowitz
2009-08-12 14:23 ` Tom Tromey
0 siblings, 2 replies; 5+ messages in thread
From: David Plumb @ 2009-08-12 13:35 UTC (permalink / raw)
To: gdb
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
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: incorrect address of class member
2009-08-12 13:35 incorrect address of class member David Plumb
@ 2009-08-12 13:47 ` Daniel Jacobowitz
2009-08-12 14:23 ` Tom Tromey
1 sibling, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2009-08-12 13:47 UTC (permalink / raw)
To: David Plumb; +Cc: gdb
On Wed, Aug 12, 2009 at 09:35:38AM -0400, David Plumb wrote:
> 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.
Could you try a CVS snapshot of GDB? If this still happens, file a
bug.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: incorrect address of class member
2009-08-12 13:35 incorrect address of class member David Plumb
2009-08-12 13:47 ` Daniel Jacobowitz
@ 2009-08-12 14:23 ` Tom Tromey
2009-08-12 19:19 ` Tom Tromey
1 sibling, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2009-08-12 14:23 UTC (permalink / raw)
To: David Plumb; +Cc: gdb
>>>>> "David" == David Plumb <David.Plumb@intellon.com> writes:
David> I'm sorry if this is the wrong mailing list. I am having a problem with
David> gdb but I don't know if it falls into the category of a bug report yet.
No problem :)
David> If gdb is using the wrong address for the mFlag member, it explains why
David> the gdb print command is returning the wrong value for the mFlag member.
For this sort of thing, I think you can't tell if it is a gcc bug or a
gdb bug without digging below the surface. I compiled your program with
a somewhat newer gcc (I don't have 3.4 around any more), and I was still
able to reproduce it.
I think it is a gcc bug, because readelf shows:
<2><8e>: Abbrev Number: 7 (DW_TAG_member)
<8f> DW_AT_name : (indirect string, offset: 0xc8): mHugeArray
<93> DW_AT_decl_file : 1
<94> DW_AT_decl_line : 13
<95> DW_AT_type : <0xf2>
<99> DW_AT_data_member_location: 2 byte block: 23 0 (DW_OP_plus_uconst: 0)
<9c> DW_AT_accessibility: 3 (private)
<2><9d>: Abbrev Number: 7 (DW_TAG_member)
<9e> DW_AT_name : (indirect string, offset: 0x0): mFlag
<a2> DW_AT_decl_file : 1
<a3> DW_AT_decl_line : 14
<a4> DW_AT_type : <0x53>
<a8> DW_AT_data_member_location: 2 byte block: 23 0 (DW_OP_plus_uconst: 0)
<ab> DW_AT_accessibility: 3 (private)
... which, if I am reading this correctly, puts both mHugeArray and
mFlag at offset 0 -- see those DW_AT_data_member_location attributes.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-12 19:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-12 13:35 incorrect address of class member David Plumb
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox