From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by sourceware.org (Postfix) with ESMTPS id 62452385E83E for ; Mon, 14 Mar 2022 13:40:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 62452385E83E Received: by mail-io1-xd34.google.com with SMTP id 195so18297555iou.0 for ; Mon, 14 Mar 2022 06:40:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=Gs+IYaspsjp5ngLlxHXm36PqL9YdSxvVbbboTcS4/qw=; b=iKhGtzEg+H812kZGEzjwpecctxfUrXVczhiFuqDVpNpH3S8+NxVUlexJvP0WwtkdPN LrdR7hODl4H+9UTmSF1+MjOmwSKK20Yvm/vqt2hCGfFguG3iu5uzvHWe+RCEWdfMeGYd asfd6HXVwNY0klXt4hh2rihIAfOhL2FSMXmVdH4HqvCLiG31s153L6Z2cNM98Nlhqsw9 qwrwKDsAEtqN99RovsoF7ekGGGozEDw3aTbf6E9MRQJd/sIeg9DEa19IiEXwgsnd0xdY rELscrBzL8YUtYxZl7HSnR1gDfm+2aWQ+FunseefnVir0Olt3xPN3MKkXk+O7qTVmIb6 Pwnw== X-Gm-Message-State: AOAM530mc0qxSF/uQ9avq4o6qf48O52Wm7D9sOjQRR1NAPWvVH6iSd2e HVSyvm2tweA/OqQjPEqmhcjXkA== X-Google-Smtp-Source: ABdhPJylrxXgzUE6XLfzReSYvB25CqsnLFDATDZO3K71ALtYBBwHio2un9JDFgL4/YC8dXLl0U8RlA== X-Received: by 2002:a05:6638:12c5:b0:319:b2ea:ed1 with SMTP id v5-20020a05663812c500b00319b2ea0ed1mr19673824jas.157.1647265247521; Mon, 14 Mar 2022 06:40:47 -0700 (PDT) Received: from murgatroyd (71-211-175-224.hlrn.qwest.net. [71.211.175.224]) by smtp.gmail.com with ESMTPSA id k15-20020a92c24f000000b002c79ec214f9sm2009880ilo.30.2022.03.14.06.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 06:40:47 -0700 (PDT) From: Tom Tromey To: Carl Love via Gdb-patches Cc: Ulrich Weigand , Carl Love , Rogerio Alves Subject: Re: [PATCH] PowerPC, add support for printing non-trivial C++ object for the finish command. References: <28ce795ca489f69829207b2a7a535cf7f77f6dd8.camel@us.ibm.com> X-Attribution: Tom Date: Mon, 14 Mar 2022 07:40:46 -0600 In-Reply-To: <28ce795ca489f69829207b2a7a535cf7f77f6dd8.camel@us.ibm.com> (Carl Love via Gdb-patches's message of "Fri, 11 Mar 2022 14:26:31 -0800") Message-ID: <87a6dslkip.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Mar 2022 13:40:50 -0000 >>>>> "Carl" == Carl Love via Gdb-patches 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. Anyway I tend to think your patch is fine. Tom commit 693bb3df1fdf2de96e5a6ce338712d6ba370d0c9 Author: Joel Brobecker 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 . */ + +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 . + +# 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"