From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16178 invoked by alias); 30 Sep 2013 08:16:35 -0000 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 Received: (qmail 16162 invoked by uid 89); 30 Sep 2013 08:16:34 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Sep 2013 08:16:34 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8U8GU3o025158 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 30 Sep 2013 04:16:31 -0400 Received: from host2.jankratochvil.net (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8U8GQDT021180 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Mon, 30 Sep 2013 04:16:29 -0400 Date: Mon, 30 Sep 2013 08:16:00 -0000 From: Jan Kratochvil To: hex Cc: gdb@sourceware.org Subject: Re: Could GDB get offset of a field in virtual base class through NULL pointer Message-ID: <20130930081626.GA15265@host2.jankratochvil.net> References: <20130928183852.GA12891@host2.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2013-09/txt/msg00033.txt.bz2 On Sun, 29 Sep 2013 03:59:54 +0200, hex wrote: > > I do not see what it should do. In the following case &(((B *)&OBJECT)->a) > > prints once 12 and once 16 for different OBJECT so what it should print for 0? > > > > class X:public virtual A,public B {}; > > class C { > > public: > > int c; > > }; > > class Y:public virtual A,public C,public B {}; > > #include > > int main() { > > X x; > > Y y; > > std::cout << (char *)&(((B *)&x)->a)-(char *)&x << std::endl; > > std::cout << (char *)&(((B *)&y)->a)-(char *)&y << std::endl; > > } > > > > If we use &(((B *)0)->a), we are likely to get offset of 'a' in class > B. If GDB could > support this specific case, we do not need a real object to get the offset. This would apply if you had s/virtual A/A/. But with the inheritance of A being virtual the memory location of A inside the whole object instance is "random", it does not depend on B but it depends on X or Y. Specifically it depends on virtual tables used for the specific instance, the virtual tables specify the location of A. This is what I am trying to show you in the example above. The same expression (char *)&(((B *)&OBJECT)->a) produces different result depending on which OBJECT you pass there. Therefore which result should produce passing 0 instead of &OBJECT there? It cannot be a single number. Jan Kratochvil