public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Luis Machado <luis.machado@arm.com>
To: Tom Tromey <tromey@adacore.com>,
	Carl Love via Gdb-patches <gdb-patches@sourceware.org>
Cc: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	Rogerio Alves <rogealve@br.ibm.com>
Subject: Re: [PATCH] PowerPC, add support for printing non-trivial C++ object for the finish command.
Date: Mon, 14 Mar 2022 13:45:16 +0000	[thread overview]
Message-ID: <6f59c258-b315-b4b7-fc87-98c4c1aac913@arm.com> (raw)
In-Reply-To: <87a6dslkip.fsf@tromey.com>

On 3/14/22 13:40, Tom Tromey via Gdb-patches wrote:
>>>>>> "Carl" == Carl Love via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Carl> The following patch fixes an issue on Powerpc where the function return
> Carl> value for a C++ program prints garbage when the function return type is
> Carl> a class object.  The fix is based on an x86-64 patch for the same
> Carl> issue.
> 
> Carl> The patch has been tested on Power 10 with no regressions.  Please let
> Carl> me know if this patch is acceptable for mainline.   Thanks.
> 
> FWIW, here at AdaCore, we carry a very similar patch for
> ppc-linux-tdep.c.  I've appended it.
> 
> I haven't really submitted this yet since I wanted to investigate the
> ABI difference that lead to the change.

I wonder if the test I pushed, gdb.base/retval-large-struct.exp, 
exercises the same case your attached testcase.

There may be more targets running into these issues, but it seems the 
testsuite wasn't exercising this particular case properly (or something 
else changed along the way).

> 
> Anyway I tend to think your patch is fine.
> 
> Tom
> 
> commit 693bb3df1fdf2de96e5a6ce338712d6ba370d0c9
> Author: Joel Brobecker <brobecker@adacore.com>
> Date:   Tue Jan 7 06:07:41 2020 -0500
> 
>      GDB on ppc-linux is unable to print return value when value is struct/union
>      
>      Consider the following C code:
>      
>          | struct S2 { short s1, s2; };
>          | struct S2 function_2 (void)
>          | {
>          |   struct S2 x = { 27, 28 };
>          |   return x;
>          | }
>      
>      When using the "finish" command from this function, GDB currently
>      says it cannot print the return value:
>      
>          | (gdb) finish
>          | Run till exit from #0  function_2 () at finish-struct.c:13
>          | 0x1000055c in main () at finish-struct.c:20
>          | 20    function_2 ();
>          | Value returned has type: struct S2. Cannot determine contents
>      
>      As it happens, the ABI being used on PowerPC Linux is such that
>      the address of the returned value is returned via register r3.
>      So we can print its contents.
>      
>      gdb/ChangeLog:
>      
>              * ppc-linux-tdep.c (ppc_linux_return_value): Fix handling
>              of return values which are either structs, unions, or vectors
>              with a size different from 8 or 16.
>      
>      gdb/testsuite/ChangeLog:
>      
>              * gdb.base/finish-struct.c: New file.
>              * gdb.base/finish-struct.exp: New files.
>      
>      Change-Id: I0b336739f6a1929c1b8910aeb87f2e4dfa504bef
>      TN: SC20-032
> 
> diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
> index 901b938f257..9e0d4902595 100644
> --- a/gdb/ppc-linux-tdep.c
> +++ b/gdb/ppc-linux-tdep.c
> @@ -254,7 +254,19 @@ ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
>          || TYPE_CODE (valtype) == TYPE_CODE_UNION)
>         && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
>   	   && TYPE_VECTOR (valtype)))
> -    return RETURN_VALUE_STRUCT_CONVENTION;
> +    {
> +      if (readbuf)
> +	{
> +	  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
> +	  ULONGEST addr;
> +
> +	  regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum + 3,
> +				      &addr);
> +	  read_memory (addr, readbuf, TYPE_LENGTH (valtype));
> +	}
> +
> +      return RETURN_VALUE_ABI_RETURNS_ADDRESS;
> +    }
>     else
>       return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
>   				      readbuf, writebuf);
> diff --git a/gdb/testsuite/gdb.base/finish-struct.c b/gdb/testsuite/gdb.base/finish-struct.c
> new file mode 100644
> index 00000000000..2af02a1a1a3
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/finish-struct.c
> @@ -0,0 +1,40 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2020 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +struct S1 { char c1, c2, c3, c4; };
> +
> +struct S2 { short s1, s2; };
> +
> +struct S1
> +function_1 (void)
> +{
> +  struct S1 x = { 'A', 'B', 'C', 'D' };
> +  return x;
> +}
> +
> +struct S2
> +function_2 (void)
> +{
> +  struct S2 x = { 27, 28 };
> +  return x;
> +}
> +
> +int main ()
> +{
> +  function_1 ();
> +  function_2 ();
> +}
> diff --git a/gdb/testsuite/gdb.base/finish-struct.exp b/gdb/testsuite/gdb.base/finish-struct.exp
> new file mode 100644
> index 00000000000..b4e6875e5a7
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/finish-struct.exp
> @@ -0,0 +1,47 @@
> +# Copyright 2020 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# This file is part of the gdb testsuite.  It is intended to test that
> +# gdb can correctly print arrays with indexes for each element of the
> +# array.
> +
> +standard_testfile .c
> +
> +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
> +    untested "failed to compile"
> +    return -1
> +}
> +
> +clean_restart ${binfile}
> +
> +gdb_breakpoint function_1
> +gdb_breakpoint function_2
> +
> +# Run the program until we reach the first breakpoint, which should be
> +# in function_1, and then test the "finish" command from there.
> +
> +gdb_run_cmd
> +gdb_test "" "Breakpoint \[0-9\]+,.*function_1.*" "run to function_1"
> +
> +gdb_test "finish" \
> +    " = {c1 = 65 'A', c2 = 66 'B', c3 = 67 'C', c4 = 68 'D'}" \
> +    "finish from function_1"
> +
> +# Continue the program's execution until reaching the breakpoint inside
> +# function_2, and then test the "finish" command from there.
> +
> +gdb_test "continue" "Breakpoint \[0-9\]+,.*function_2.*" "run to function_2"
> +
> +gdb_test "finish" " = {s1 = 27, s2 = 28}" "finish from function_2"


  reply	other threads:[~2022-03-14 13:45 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 22:26 Carl Love
2022-03-13  5:28 ` Joel Brobecker
2022-03-14 10:43 ` Luis Machado
2022-03-14 13:40 ` Tom Tromey
2022-03-14 13:45   ` Luis Machado [this message]
2022-03-14 14:58   ` Ulrich Weigand
     [not found]     ` <ce6c71356c4a58fcdfb655a6e50c3a24f812e66c.camel@us.ibm.com>
     [not found]       ` <d9f17525c9a03c20b54015a6a71c36cae50fe4e3.camel@de.ibm.com>
     [not found]         ` <6ca2276426343756e103995e07ff951d6e26837b.camel@us.ibm.com>
     [not found]           ` <939797b94ab71f3f7356747d84a1515939cb3dcc.camel@de.ibm.com>
     [not found]             ` <fccc34c438fda9a35b8a8565e0f5026237e7eab9.camel@us.ibm.com>
     [not found]               ` <bb5b9b137fc11886964113d4b524526b3c733f4a.camel@us.ibm.com>
     [not found]                 ` <1edb818bd2873a3fa5278f28131089d228a0a4f6.camel@de.ibm.com>
     [not found]                   ` <7c884a865d06890cb325225c65d7a52fdfbd20d2.camel@us.ibm.com>
     [not found]                     ` <846ca96309d2732d3db0e4c323a81105c098fa5f.camel@de.ibm.com>
     [not found]                       ` <5a858dd7b957ecf45cf5b00ffc140a839c8ef023.camel@us.ibm.com>
     [not found]                         ` <b634fecae5e33a3d1a278191c37f306a3b8622f2.camel@de.ibm.com>
     [not found]                           ` <25f2380ced176f58a8e3ea9b70c7e7786988d650.camel@us.ibm.com>
     [not found]                             ` <2b0481466e9ecc33d52c74c3a3b4babb05435f47.camel@de.ibm.com>
     [not found]                               ` <df3b049416ff666e7bd3e3a91e4ea90d34256ea5.camel@us.ibm.com>
     [not found]                                 ` <71370ce02bd57827d3b7958772b1594d3591bd16.camel@de.ibm.com>
     [not found]                                   ` <ec9dafb1671699b03b28ee4be528711c6988eaa5.camel@us.ibm.com>
     [not found]                                     ` <148d8d3efcc8d110119e566027bfd0c65dd02525.camel@de.ibm.com>
     [not found]                                       ` <eef62b295e97fc464c22f9d748ff818860137de9.camel@us.ibm.com>
     [not found]                                         ` <afd6fa576f479359618b1ee50b08be8932735da8.camel@de.ibm.com>
     [not found]                                           ` <cb6b19e9d287d2bae4b72627791f2a00af062c48.camel@us.ibm.com>
     [not found]                                             ` <ee7101f86b5c8581905c53347fa603dc23ddc2bd.camel@de.ibm.com>
     [not found]                                               ` <8decd662134d57e8caf43960a1cdc47723e2bfe3.camel@us.ibm.com>
     [not found]                                                 ` <f7cad695cf64540bad8c95cf5fd31691711d0eeb.camel@de.ibm.com>
     [not found]                                                   ` <79d82ed277308ed5ce312bff398e770ab234390a.camel@us.ibm.com>
     [not found]                                                     ` <63f21a897f452d81a73fb386cb99110a359ef0b7.camel@de.ibm.com>
     [not found]                                                       ` <be178bc4f356d7f1937458290cb5883eeee9eee1.camel@us.ibm.com>
     [not found]                                                         ` <dfd935e9414d3dd2c27d1e877d3718ae7510aa07.camel@de.ibm.com>
     [not found]                                                           ` <97275f61ef101a12cde8e5a45008ed8e479424eb.camel@us.ibm.com>
     [not found]                                                             ` <b629440707165f46fb466e48b0c95de3bfa334d2.camel@de.ibm.com>
     [not found]                                                               ` <191f5826b228a7614c084c9704b086851d418c78.camel@us.ibm.com>
     [not found]                                                                 ` <5405a79ecd6ed34646ad77eed0779063ee222d37.camel@de.ibm.com>
2022-10-06 16:36                                                                   ` [PATCH 0/2] PowerPC, fix support for printing the function return value for non-trivial values Carl Love
2022-10-18 18:55                                                                     ` [PATCH 0/2 version 2] " Carl Love
2022-10-06 16:37                                                                   ` [PATCH 2/2] " Carl Love
2022-10-08  4:36                                                                     ` Kevin Buettner
2022-10-12 17:01                                                                       ` Carl Love
2022-10-14  2:49                                                                     ` Kevin Buettner
2022-10-14  7:36                                                                       ` Bruno Larsen
2022-10-14 23:25                                                                         ` Carl Love
2022-10-14 23:23                                                                       ` Carl Love
2022-10-18  1:06                                                                         ` Kevin Buettner
2022-10-18 18:26                                                                           ` Carl Love
2022-10-18 18:55                                                                     ` [PATCH 2/2 ver 2] " Carl Love
2022-10-31 16:07                                                                       ` Carl Love
2022-11-07 14:56                                                                       ` Bruno Larsen
2022-11-07 19:53                                                                         ` Carl Love
2022-11-07 20:04                                                                       ` [PATCH 2/2 ver 3] " Carl Love
2022-11-14 16:47                                                                         ` Ulrich Weigand
2022-11-15  7:15                                                                           ` Tom de Vries
2022-11-15 10:16                                                                             ` Ulrich Weigand
2022-11-15 16:04                                                                               ` Carl Love
2022-11-15 16:55                                                                                 ` Simon Marchi
2022-11-15 23:46                                                                                   ` Carl Love
2022-11-15 17:24                                                                               ` Carl Love
2022-11-15 18:05                                                                                 ` Ulrich Weigand
2022-11-16  1:01                                                                                   ` Carl Love
2022-11-16  9:52                                                                                     ` Ulrich Weigand
2022-11-16 10:12                                                                                     ` Tom de Vries
2022-11-16 10:20                                                                                     ` Lancelot SIX
2022-11-16 15:56                                                                                       ` Carl Love
2022-11-16 20:55                                                                                       ` [PATCH] Change NULL to nullptr in gdb/infcmd.c and gdb/infrun.c Carl Love
2022-11-16 21:15                                                                                         ` Simon Marchi
     [not found]                                                               ` <5a34aaeab59f0099b915d1780c701284a6cf691e.camel@us.ibm.com>
     [not found]                                                                 ` <8aa882863b2f4cef38c22386387c5705bf63c3d5.camel@de.ibm.com>
2022-10-06 16:37                                                                   ` [PATCH 1/2] PowerPC, function ppc64_sysv_abi_return_value add missing return value convention Carl Love
2022-10-08  4:20                                                                     ` Kevin Buettner
2022-10-14 23:20                                                                       ` Carl Love
2022-10-18 18:55                                                                     ` [PATCH 1/2 ver 2] " Carl Love
2022-11-07 20:04                                                                       ` [PATCH 1/2 ver 3] " Carl Love
2022-11-14 16:45                                                                         ` Ulrich Weigand
2022-11-14 19:38                                                                           ` Carl Love

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=6f59c258-b315-b4b7-fc87-98c4c1aac913@arm.com \
    --to=luis.machado@arm.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=rogealve@br.ibm.com \
    --cc=tromey@adacore.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).