Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: qiyaoltc@gmail.com (Yao Qi)
Cc: gdb-patches@sourceware.org (gdb-patches@sourceware.org)
Subject: Re: [RFC 2/3] Record function descriptor address instead of function address in value
Date: Fri, 28 Oct 2016 18:41:00 -0000	[thread overview]
Message-ID: <20161028184117.EE80810B927@oc8523832656.ibm.com> (raw)
In-Reply-To: <CAH=s-PN7hn9+mTmDmjJC3UpkQuocebbBCaDSgCMwZKH2Sz6cpQ@mail.gmail.com> from "Yao Qi" at Oct 28, 2016 05:09:57 PM

Yao Qi wrote:
> On Mon, Oct 17, 2016 at 4:51 PM, Ulrich Weigand <uweigand@de.ibm.com> wrote:
> > ... and therefore this function cannot really be implemented on ppc64
> > in a fully-general way.  In particular, when running stripped binaries
> > or code that is otherwise without symbols (e.g. JITted code etc.), this
> > conversion may not be possible.
> 
> I don't expect convert_from_func_addr working in general, due to the
> reasons you mentioned.  convert_from_func_addr is only used when
> symbol (from debug information) is available.  If we want to GDB
> handle such complex expression evaluation correctly, debug
> information is required.

OK, that makes sense.  If we have a symbol from debug information,
we probably should also have the msymbol.

> > B.t.w. note that there is already a similar function that attempts this
> > conversion (ppc-sysv-tdep.c:convert_code_addr_to_desc_addr), but it is
> > currently only used during inferior function calls, so it is not so
> > critical if it fails.  (With your change, that function may actually
> > no longer be necessary at that place since values should already point
> > to function descriptors ...)
> >
> 
> Yes, convert_from_func_addr is similar to convert_code_addr_to_desc_addr.
> I removed convert_code_addr_to_desc_addr, but it breaks ifunc
> inferior call in my experiment, because ifunc resolver gets the function
> address rather than function descriptor address, we still need
> convert_code_addr_to_desc_addr to get function descriptor address.

Huh?  The ifunc resolver is supposed to return a function pointer,
which will be a descriptor address on ppc64.  Aha, it seems the
problem is in GDB's implementaton of elf_gnu_ifunc_resolve_addr,
which calls gdbarch_convert_from_func_ptr_addr -- it really
shouldn't do this, we should keep descriptors as long as possible.

> > Your code already *mostly* does that, with the exception of symbol
> > addresses.  I'm wondering whether we shouldn't push the change one
> > step further back and already store descriptor addresses in
> > SYMBOL_VALUE_ADDRESS.  Note that this is currently already handled
> > somewhat inconsistenly on ppc64: msymbols already point to the
> > descriptor, and so do symbols read from stabs debug info; only
> > symbols read from DWARF debug info actually point to the code
> > address.
> 
> I tried what you suggested, but failed.  SYMBOL_VALUE_ADDRESS
> is used to get variable address, rather than function's address.  We
> get function address from block (BLOCK_START), and get block
> from symbol (SYMBOL_BLOCK_VALUE).  There is no good way to
> store function descriptor address in symbol.

OK, I see.  Doing the conversion when looking up the symbol address
should be fine, then.

> How about doing this in a followup patch as an enhancement?  My
> priority is to get this RFC acceptable, and make PPC64/ARM/MIPS
> works well.  Propagate descriptor address and bug fixes can be done
> later.

Sure.

> > Those are a bit annoying.  I think the underlying problem is that operati=
> ons
> > like "disass" or "x/i" really don't work on "values" in the original sense
> > but rather on "PC addresses".  Maybe it would make sense to have those
> > function enable a special "mode" in the expression evaluator that would
> > change the conversion of functions to function pointers to use the code
> > address instead of the descriptor address?
> >
> 
> I think about the special "mode" in the expression evaluation, but I
> suspect that there is a case in a single expression, function address
> is expected in some symbol, and descriptor address is expected in
> some other symbol, like,
> 
> int func (int i) { return i;}
> 
> (gdb) x/i func + func (1)
> 
> the "func" is expected to be function address and the second "func"
> is expected to be function descriptor address.  I had a heuristics that
> VALUE means function address if we do a pointer add with long type
> (valarith.c:value_ptradd).  It works fine.

I see.  This is a bit odd in that evaluating "main" would then return
a descriptor while "main + 1" would return a code address, which
means the caller is never really sure which one it gets.

I think the problem you describe above could still be made to work
with the special evalution mode, you'd just have to reset the mode
to the default when recursing into certain expression nodes, like
e.g. when evaluating the function operand of a OP_FUNCALL node.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com


  reply	other threads:[~2016-10-28 18:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14 10:53 [PATCH 0/3] Fix gdb.base/func-ptrs.exp fails in ppc64 and arm thumb mode Yao Qi
2016-10-14 10:53 ` [RFC 3/3] Update test cases Yao Qi
2016-10-14 10:53 ` [RFC 2/3] Record function descriptor address instead of function address in value Yao Qi
2016-10-14 17:35   ` Simon Marchi
2016-10-17 11:40     ` Yao Qi
2016-10-17 15:40       ` Simon Marchi
2016-10-17 15:51   ` Ulrich Weigand
2016-10-18  2:27     ` Maciej W. Rozycki
2016-10-18 13:03       ` Yao Qi
2016-10-28 16:20       ` Yao Qi
2017-10-03 18:12         ` Maciej W. Rozycki
2017-10-04 21:25           ` Yao Qi
2016-10-28 16:10     ` Yao Qi
2016-10-28 18:41       ` Ulrich Weigand [this message]
2016-10-14 10:53 ` [PATCH 1/3] Use get_var_address in test cases Yao Qi

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=20161028184117.EE80810B927@oc8523832656.ibm.com \
    --to=uweigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    /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