From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19963 invoked by alias); 29 Sep 2013 01:59:58 -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 19750 invoked by uid 89); 29 Sep 2013 01:59:57 -0000 Received: from mail-ob0-f178.google.com (HELO mail-ob0-f178.google.com) (209.85.214.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 29 Sep 2013 01:59:57 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,NO_RELAYS autolearn=no version=3.3.2 X-HELO: mail-ob0-f178.google.com Received: by mail-ob0-f178.google.com with SMTP id uy5so4174600obc.23 for ; Sat, 28 Sep 2013 18:59:54 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.60.51.196 with SMTP id m4mr12898589oeo.1.1380419994786; Sat, 28 Sep 2013 18:59:54 -0700 (PDT) Received: by 10.60.45.207 with HTTP; Sat, 28 Sep 2013 18:59:54 -0700 (PDT) In-Reply-To: <20130928183852.GA12891@host2.jankratochvil.net> References: <20130928183852.GA12891@host2.jankratochvil.net> Date: Sun, 29 Sep 2013 01:59:00 -0000 Message-ID: Subject: Re: Could GDB get offset of a field in virtual base class through NULL pointer From: hex To: Jan Kratochvil Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-SW-Source: 2013-09/txt/msg00032.txt.bz2 >> GDB could print &(((B *)0)->a), but it could not print &(((B *)0)->a). > ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ > Those two expressions are the same and they really od not work: > > (gdb) p &(((B *)0)->a) > Cannot access memory at address 0x0 > Sorry, a mistake, I meant "GDB could print &(((B *)0)->b), but it could not print &(((B *)0)->a)." > 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.