From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32228 invoked by alias); 12 Aug 2009 13:35:47 -0000 Received: (qmail 32073 invoked by uid 22791); 12 Aug 2009 13:35:45 -0000 X-SWARE-Spam-Status: No, hits=0.5 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_13,RDNS_DYNAMIC,SPF_PASS,TVD_RCVD_IP X-Spam-Check-By: sourceware.org Received: from 240.35.234.216.sta.connection.ca (HELO torgateway02.Intellon.com) (216.234.35.240) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Aug 2009 13:35:41 +0000 Received: from Intellon.com [192.168.10.14] by torgateway02.Intellon.com - Websense Email Security (6.1.1); Wed, 12 Aug 2009 09:35:39 -0400 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: incorrect address of class member Date: Wed, 12 Aug 2009 13:35:00 -0000 Message-ID: <5630E8542965844685CBA4EB1C4785048EA900@cdnpostal.Intellon.com> From: "David Plumb" To: X-SEF-7853D99-ADF1-478E-8894-213D316B8FFA: 1 X-SEF-Processed: 6_1_1_105__2009_08_12_09_35_39 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-08/txt/msg00082.txt.bz2 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 =3D value; } void printFlag() { printf( "Flag value is %d\n", mFlag ); } private: int mHugeArray[0x08000001]; int mFlag; }; int main( int argc, char* argv[] ) { Blah* foo =3D 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=20 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=20 Flag value is 1 This is a transcript of my gdb session: > gdb a.out=20 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 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=20 Breakpoint 1, Blah::setFlag (this=3D0xd7ffb008, value=3D1) at gdb_problem.cpp:7 7 mFlag =3D value; (gdb) p mFlag $1 =3D 0 (gdb) p &mFlag $2 =3D (int *) 0xd7ffb00c (gdb) x 0xd7ffb008+0x20000004 0xf7ffb00c: 0x00000000 (gdb) p /x sizeof(*this) $3 =3D 0x20000008 (gdb) next 8 } (gdb) p mFlag $4 =3D 0 (gdb) x 0xd7ffb008+0x20000004 0xf7ffb00c: 0x00000001 Thanks! David