Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Siva Chandra <sivachandra@google.com>
To: Ulrich Weigand <uweigand@de.ibm.com>
Cc: gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 0/2] Make chained function calls in expressions work
Date: Wed, 01 Oct 2014 18:26:00 -0000	[thread overview]
Message-ID: <CAGyQ6gzyVwgQk_EkLSHLss0JcMUEcKt4oWVZwjh5V0N-zV=Zyw@mail.gmail.com> (raw)
In-Reply-To: <CAGyQ6gz3ZqmYE3Zhb_gckauwU6HbGazyWPEOs-cvHrE3b4TUiA@mail.gmail.com>

On Wed, Oct 1, 2014 at 11:05 AM, Siva Chandra <sivachandra@google.com> wrote:
> On Wed, Oct 1, 2014 at 6:15 AM, Ulrich Weigand <uweigand@de.ibm.com> wrote:
>>> On Fri, Sep 26, 2014 at 6:29 AM, Siva Chandra <sivachandra@google.com> wrote:
>>> > This patch series enables having chained function calls in
>>> > expressions. An example of a chained function call is shown in PR
>>> > c++/11606. It has an example of a chain of two function calls. This
>>> > patch series enables chains of any number of function calls.
>>> >
>>> > Currently, an inferior function call is handled via
>>> > call_function_by_hand. The value returned by the inferior function is
>>> > copied into a GDB value whose lval_type is not_lval. Its contents are
>>> > stored within the value irrespective of whether the return value is in
>>> > inferior memory or in a register. Consequently, any subsequent
>>> > function call in the expression which requires this value's address as
>>> > an argument throws an error as the value is not in inferior memory.
>>> >
>>> > This patch series keeps most of the current flow intact, except that
>>> > the value returned by the inferior function is made to be a new
>>> > lval_type called lval_mirrored_on_inferior_stack. These values have a
>>> > mirrored value of lval_type lval_memory which reside on the inferior
>>> > stack. They reside on the stack only for the duration for which the
>>> > expression is evaluated. This enables value_address to return the
>>> > address of the stack mirror instead of throwing an error.
>>
>> I'm wondering if there isn't a simpler way to solve this issue: couldn't
>> you instead during preparation of the second call_function_by_hand simply
>> allocate extra space on the stack and copy not_lval values whose address
>> needs to be taken there?   This would avoid adding the new lval type, all
>> the extra state to track mirrored values during an expression, and would
>> actually allow you to pass *other* not_lval values to inferior calls too
>> (not just those originating from another inferior call).
>
> I did think about this route. However, look at the comment at
> eval.c:1405. It has an argument for why we should not in general copy
> function args on to the stack.
>
> My patches here target return values of functions. Though return
> values end up being function arguments in a chained function call
> expression, IMO return values do not suffer from the same problem
> pointed to in the comment from above.
>
> 1. If a function returns a reference, creating a copy of the reference
> on the stack and passing it around for the duration the expression is
> being evaluated should not be a problem.
> 2. If a function returns a value, then it is either returned on the
> stack or in a register. My patches do not really disturb the case of a
> value being returned on stack. Even when values are returned in
> registers, intermediate return values are only temporaries and holding
> onto their addresses in some stateful entity will be an error.

A tangential point, GDB does not call destructors on these temporaries
which IMO is an error. That is why, in my 2/2, you will notice that
the expression's state is holding onto all the return value
temporaries in a vector instead of just the last one created; In a
future pass, I would like to implement invoking the destructors on
these temporaries after the expression result is evaluated.

Thanks,
Siva Chandra


  reply	other threads:[~2014-10-01 18:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-26 13:29 Siva Chandra
2014-10-01  0:42 ` Siva Chandra
2014-10-01 13:15   ` Ulrich Weigand
2014-10-01 18:05     ` Siva Chandra
2014-10-01 18:26       ` Siva Chandra [this message]
2014-10-20 16:01         ` Ulrich Weigand
2014-10-20 19:56           ` Siva Chandra
2014-10-21 11:15             ` Ulrich Weigand
2014-10-21 20:30               ` Siva Chandra
2014-10-21 21:07                 ` Siva Chandra
2014-10-22 17:00                 ` Ulrich Weigand
2014-10-23 15:07                   ` Siva Chandra
2014-10-23 16:09                     ` Ulrich Weigand
2014-10-23 23:31                       ` Siva Chandra
2014-10-09  0:02   ` Siva Chandra
2014-10-15 13:43     ` Siva Chandra

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='CAGyQ6gzyVwgQk_EkLSHLss0JcMUEcKt4oWVZwjh5V0N-zV=Zyw@mail.gmail.com' \
    --to=sivachandra@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=uweigand@de.ibm.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