Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@sifive.com>
To: andrew.burgess@embecosm.com
Cc: gdb-patches@sourceware.org, andrew.burgess@embecosm.com
Subject: Re: [PATCH] gdb: Ensure compiler doesn't optimise variable out in test
Date: Thu, 30 Aug 2018 00:22:00 -0000	[thread overview]
Message-ID: <mhng-c147d665-ff40-415d-98a2-1eea608c9e54@palmer-si-x1c4> (raw)
In-Reply-To: <20180829180259.2718-1-andrew.burgess@embecosm.com>

On Wed, 29 Aug 2018 11:02:59 PDT (-0700), andrew.burgess@embecosm.com wrote:
> In the test gdb.base/funcargs.exp, there's this function:
>
>     void recurse (SVAL a, int depth)
>     {
>       a.s = a.i = a.l = --depth;
>       if (depth == 0)
>         hitbottom ();
>       else
>         recurse (a, depth);
>     }
>
> The test script places a breakpoint in hitbottom, and runs the
> executable which calls recurse with an initial depth of 4.
>
> When GDB hits the breakpoint in hitbottom the testscript performs a
> backtrace, and examines 'a' at each level.
>
> The problem is that 'a' is not live after either the call to
> 'hitbottom' or the call to 'recurse', and as a result the test fails.
>
> In the particular case I was looking at GCC for RISC-V 32-bit, the
> variable 'a' is on the stack and GCC selects the register $ra (the
> return address register) to hold the pointer to 'a'.  This is fine,
> because, by the time the $ra register is needed to hold a return
> address (calling hitbottom or recurse) then 'a' is dead.
>
> In this patch I propose that a use of 'a' is added after the calls to
> hitbottom and recurse, this should cause the compiler to keep 'a'
> around, which should ensure GDB can find it.
>
> gdb/testsuite/ChangeLog:
>
> 	* gdb.base/funcargs.c (use_a): New function.
> 	(recurse): Call use_a.
> ---
>  gdb/testsuite/ChangeLog           | 5 +++++
>  gdb/testsuite/gdb.base/funcargs.c | 7 +++++++
>  2 files changed, 12 insertions(+)
>
> diff --git a/gdb/testsuite/gdb.base/funcargs.c b/gdb/testsuite/gdb.base/funcargs.c
> index 600792f0a7e..515631f5491 100644
> --- a/gdb/testsuite/gdb.base/funcargs.c
> +++ b/gdb/testsuite/gdb.base/funcargs.c
> @@ -424,6 +424,10 @@ void hitbottom ()
>  {
>  }
>
> +void use_a (SVAL a)
> +{
> +}
> +
>  void recurse (SVAL a, int depth)
>  {
>    a.s = a.i = a.l = --depth;
> @@ -431,6 +435,9 @@ void recurse (SVAL a, int depth)
>      hitbottom ();
>    else
>      recurse (a, depth);
> +
> +  /* Ensure A is not discarded after the above calls.  */
> +  use_a (a);
>  }
>
>  void test_struct_args ()

Isn't the compiler still free to kill "a" here because it can see into use_a() 
and therefor inline it?  I'd expected it to choose to inline use_a(), as doing 
nothing is always cheaper than calling a function.


  parent reply	other threads:[~2018-08-30  0:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-29 18:03 Andrew Burgess
2018-08-29 18:27 ` Tom Tromey
2018-08-30  0:22 ` Palmer Dabbelt [this message]
2018-08-30  2:31   ` Tom Tromey
2018-08-30  7:06     ` Ruslan Kabatsayev
2018-08-30  8:12   ` Andrew Burgess
2018-08-30 15:11     ` Tom Tromey

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=mhng-c147d665-ff40-415d-98a2-1eea608c9e54@palmer-si-x1c4 \
    --to=palmer@sifive.com \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /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