From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10004 invoked by alias); 21 Nov 2014 11:35:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 9990 invoked by uid 89); 21 Nov 2014 11:35:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Nov 2014 11:35:04 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1XrmUP-0000Oa-11 from Yao_Qi@mentor.com ; Fri, 21 Nov 2014 03:35:01 -0800 Received: from GreenOnly (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.181.6; Fri, 21 Nov 2014 03:35:00 -0800 From: Yao Qi To: Patrick Palka CC: Subject: Re: [PATCH 1/2] Fix C++ virtual method pointer resolution References: <1411355243-10812-1-git-send-email-patrick@parcs.ath.cx> Date: Fri, 21 Nov 2014 11:35:00 -0000 In-Reply-To: <1411355243-10812-1-git-send-email-patrick@parcs.ath.cx> (Patrick Palka's message of "Sun, 21 Sep 2014 23:07:23 -0400") Message-ID: <87k32og51t.fsf@codesourcery.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2014-11/txt/msg00507.txt.bz2 Patrick Palka writes: Hi, Sorry for the delayed review... > The issue lies in the initial creation of the virtual method pointer as > seen by GDB. In gnuv3_make_method_ptr() we fail to shift the vtable > offset when storing the first word of a virtual method pointer. This is > important because functions that read this first word (namely the > callers of gnuv3_decode_method_ptr()) expect that the vtable offset is a > multiple of "sizeof (vtable_ptrdiff_t)". Also it ensures that the vbit > tag does not collide with the bits used to store the actual offset. > > So when writing the virtual method pointer contents we need to shift the > vtable offset so as to be in symmetry with what the readers of the > vtable offset do -- which is, xor the vbit tag and then shift back the > offset. (The prominent readers of the vtable offset are > gnuv3_print_method_ptr() and gnuv3_method_ptr_to_value().) I am not familiar with how gdb handle c++ virtual method, but your analysis looks right to me. I spend the whole day reading c++ abi, but still don't know how to connect the abi with the code here :( > diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c > index d5ed355..ccb0be6 100644 > --- a/gdb/gnu-v3-abi.c > +++ b/gdb/gnu-v3-abi.c > @@ -683,7 +683,12 @@ gnuv3_make_method_ptr (struct type *type, gdb_byte *= contents, >=20=20 > if (!gdbarch_vbit_in_delta (gdbarch)) > { > - store_unsigned_integer (contents, size, byte_order, value | is_vir= tual); > + if (is_virtual !=3D 0) > + { > + value =3D value * TYPE_LENGTH (vtable_ptrdiff_type (gdbarch)); We need to hoist this shift out of "if" block, so that the path goes to "else" branch can be covered too. Otherwise, fails in gdb.cp/method-ptr.exp can't be fixed on arm-linux target (on which vbit_in_delta is zero). > + > +get_debug_format > + > +if ![test_debug_format "DWARF 2"] { > + return 0 > +} Why do we need to check test_debug_format here? --=20 Yao (=E9=BD=90=E5=B0=A7)