From: Yao Qi <yao@codesourcery.com>
To: Patrick Palka <patrick@parcs.ath.cx>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH 1/2] Fix C++ virtual method pointer resolution
Date: Fri, 21 Nov 2014 11:35:00 -0000 [thread overview]
Message-ID: <87k32og51t.fsf@codesourcery.com> (raw)
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")
Patrick Palka <patrick@parcs.ath.cx> 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,
>
> if (!gdbarch_vbit_in_delta (gdbarch))
> {
> - store_unsigned_integer (contents, size, byte_order, value | is_virtual);
> + if (is_virtual != 0)
> + {
> + value = 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?
--
Yao (齐尧)
next prev parent reply other threads:[~2014-11-21 11:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-22 3:07 Patrick Palka
2014-09-30 21:49 ` Patrick Palka
2014-11-16 3:57 ` Patrick Palka
2014-11-21 11:35 ` Yao Qi [this message]
2014-11-21 13:37 ` Patrick Palka
2014-11-21 13:37 ` Yao Qi
2014-11-21 13:51 ` Patrick Palka
2014-11-21 14:53 ` Patrick Palka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k32og51t.fsf@codesourcery.com \
--to=yao@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=patrick@parcs.ath.cx \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox