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 v4] Make chained function calls in expressions work
Date: Tue, 04 Nov 2014 14:26:00 -0000	[thread overview]
Message-ID: <CAGyQ6gzmjJYTYfSmZi9qArdpKVu-vtkP7wG0dNjPPMboyp6fHg@mail.gmail.com> (raw)
In-Reply-To: <201411041338.sA4DcY9L011619@d06av02.portsmouth.uk.ibm.com>

On Tue, Nov 4, 2014 at 5:38 AM, Ulrich Weigand <uweigand@de.ibm.com> wrote:
> Yes, having an additional flag in struct expression would fix the safety
> issue.  Moving initialization to evalute_subexp if *pos == 0 would then
> no longer be safety issue, but simply enabling use of temporaries in more
> cases.

Since I have my code already setup in this fashion, I would prefer to
go this route unless you see an advantage of going with the solution
you suggest below.

> The other option I've been thinking of would be to move the whole handling
> of temporaries to infcall.c, by providing two functions there, e.g. called:
>
>   infcall_enable_on_stack_temporaries ()
>   infcall_cleanup_on_stack_temporaries ()
>
> These would use a new field in the inferior_thread () thread struct to
> store the vector of currently in use on-stack temporaries.  Any call to
> call_function_by_hand after infcall_enable_on_stack_temporaries (and
> before infcall_cleanup_on_stack_temporaries) on the same thread would
> be allowed to use temporaries.  [ There could be sanity checks like
> having call_function_by_hand verify that the current SP still equals
> the thread SP at the time infcall_enable_on_stack_temporaries was
> called.  Also, infrun could assert that a thread that has temporaries
> in use must only ever run during is_infcall, to catch missing cleanup
> calls.  ]
>ReadStringAndDumpToStream<StringElementType::ASCII> (ReadStringAndDumpToStreamOptions options)
> The only thing evaluate_expression would then need to do is to call
> infcall_enable_on_stack_temporaries and install a cleanup calling
> infcall_cleanup_on_stack_temporaries.

[...]

> So I'm thinking of the following sequence of events:
>
> - We call the first call_function_by_hand with a current sp value SP
>   (no pre-existing temporaries at this point).
> - We have to reserve the red zone, setting sp e.g. to SP - 256.
> - We now allocate a temporary, taking up e.g. SP - 256 .. SP - 512.
> - First call_function_by_hand returns.
> - We get a second call_function_by_hand call.
> - Now we have a temporary on the stack from  SP - 256 .. SP - 512,
>   so skip_current_expression_stack skips down to SP - 512.
> - *Now* code allocates the red zone again, setting SP to SP - 768.
>   Even though this is unnecessary; the red zone is actually already
>   there in the range SP ... SP - 256.
>
> Bascially, adding a red zone at any point other the original SP isget_xmethod_arg_types
> useless, since the only point of the red zone is to protect data that
> the original inferior code might have written to its stack immediately
> below the original SP.

Oops! Sorry, I misread my own code. You are right and I will fix it.

> You mean "Any two or more lines in code should be wrapped in braces, even
> if they are comments, as they look like separate statements"?  I don't think
> this is intended to apply to cases like the above where a single statement
> just had to split into multiple lines since it doesn't fit into one.
> This case will never "look like separate statements".  In any case, all
> the existing precedent in GDB does not have extra braces in that case.

Sorry for picking this. I point out because I was asked to put braces
for cases like this in the past. Example:
extension.c:get_xmethod_arg_types.


  reply	other threads:[~2014-11-04 14:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-25 14:24 Siva Chandra
2014-11-03 14:35 ` Siva Chandra
2014-11-03 14:43 ` Ulrich Weigand
2014-11-03 19:55   ` Siva Chandra
2014-11-03 21:22     ` Siva Chandra
2014-11-04 13:43       ` Ulrich Weigand
2014-11-04 15:08         ` Siva Chandra
2014-11-04 15:40           ` Ulrich Weigand
2014-11-04 13:38     ` Ulrich Weigand
2014-11-04 14:26       ` Siva Chandra [this message]
2014-11-04 14:59         ` Ulrich Weigand
2014-11-04 15:23           ` Siva Chandra
2014-11-04 15:40             ` Ulrich Weigand
2014-11-11 14:55               ` Siva Chandra
2014-11-11 15:00                 ` Siva Chandra
2014-11-11 15:21                   ` Ulrich Weigand
2014-11-11 17:05                     ` Siva Chandra
2014-11-12 16:08                     ` Doug Evans
2014-11-12 17:29                       ` Doug Evans
2014-11-13  3:00                       ` 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=CAGyQ6gzmjJYTYfSmZi9qArdpKVu-vtkP7wG0dNjPPMboyp6fHg@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