From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92682 invoked by alias); 8 Oct 2018 21:42:40 -0000 Mailing-List: contact gdb-testers-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-testers-owner@sourceware.org Received: (qmail 92261 invoked by uid 89); 8 Oct 2018 21:42:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 spammy=pan, Pan, searches, Finding X-HELO: kwanyin.sergiodj.net Received: from kwanyin.sergiodj.net (HELO kwanyin.sergiodj.net) (158.69.185.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 08 Oct 2018 21:42:38 +0000 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [binutils-gdb] Finding data member in virtual base class From: sergiodj+buildbot@sergiodj.net To: gdb-testers@sourceware.org Message-Id: <9f6b697b0efd4ba4e2cb21ac17d2b18a23f81abd@gdb-build> Date: Mon, 08 Oct 2018 21:42:00 -0000 X-SW-Source: 2018-q4/txt/msg00948.txt.bz2 *** TEST RESULTS FOR COMMIT 9f6b697b0efd4ba4e2cb21ac17d2b18a23f81abd *** Author: Weimin Pan Branch: master Commit: 9f6b697b0efd4ba4e2cb21ac17d2b18a23f81abd Finding data member in virtual base class This patch fixes the original problem - printing member in a virtual base, using various expressions, do not yield the same value. Simple test case below demonstrates the problem: % cat t.cc struct base { int i; }; typedef base tbase; struct derived: virtual tbase { void func() { } }; int main() { derived().func(); } % g++ -g t.cc % gdb a.out (gdb) break derived::func (gdb) run (gdb) p i $1 = 0 (gdb) p base::i $3 = 0 (gdb) p derived::i $4 = 4196392 To fix the problem, add function get_baseclass_offset() which searches recursively for the base class along the class hierarchy. If the base is virtual, it uses "vptr" in virtual class object, which indexes to its derived class's vtable, to get and returns the baseclass offset. If the base is non-virtual, it returns the accumulated offset of its parent classes. The offset is then added to the address of the class object to access its member in value_struct_elt_for_reference().