From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140059.outbound.protection.outlook.com [40.107.14.59]) by sourceware.org (Postfix) with ESMTPS id DBA39385E02E for ; Mon, 14 Mar 2022 13:45:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DBA39385E02E Received: from DU2PR04CA0161.eurprd04.prod.outlook.com (2603:10a6:10:2b0::16) by VE1PR08MB5181.eurprd08.prod.outlook.com (2603:10a6:803:10d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Mon, 14 Mar 2022 13:45:28 +0000 Received: from DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2b0:cafe::9b) by DU2PR04CA0161.outlook.office365.com (2603:10a6:10:2b0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.26 via Frontend Transport; Mon, 14 Mar 2022 13:45:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT044.mail.protection.outlook.com (10.152.21.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Mon, 14 Mar 2022 13:45:28 +0000 Received: ("Tessian outbound 341d209a0e52:v113"); Mon, 14 Mar 2022 13:45:28 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 49d202544495bedc X-CR-MTA-TID: 64aa7808 Received: from f8db7cf800ae.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DB94490B-346D-4655-A871-FBD41B8C01B1.1; Mon, 14 Mar 2022 13:45:20 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f8db7cf800ae.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 14 Mar 2022 13:45:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cP76MJ/DdMBUjtgnl1vHgN2u92Tvito9YsrXliOlP17xHguh+FuHKxE59+e9Jya6+TRARKRTGzcfls5lr2ChYajXd+C1XKA630daMPvqi/Kf7dNNXhUnfOFOWSylUtPFGreefEQ/OC6ebPGhcnWrKt+aqEtp+UrRjMrCyIyHydawpyG5E2YeFYinjdYPZwX0FK/0Lv8H7C0Y5nGOWtMurPgCB3bgnI5/BS0dIUW6SvxlD3qpnZwe1xrE6/MsXoXC5zE295d2EbeAMO5kJYaRvyFG3uFPnulII3HI50vPeu+rAy8qqgLZK9bnMC+sgFpSw8TV0WoCJItBs9dsY/FJ0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z/rLIT08FxCBbkI/O9lVRCdXX9ttpyrQkzABgsRAmtw=; b=HTumlJunk0KLn0/AFzmXPgXOOzKc8KxFDIdH0FtRpr1P9Wu8Yxv+ATKb4OpInCb47mZdsp4RGm8Toa0toJOuQOgJnJjxMKBMAlozrgP1Wrr8QijetfjEetDwkWg4B5AnI2bGcPgkv3WJFno8gygecivY1mEwnxxbGFgRbsqNJmfOWlQ/4slX9Pq/tetKKLy/NVBe9XkRXbI23cCFIv8oB9ZFQZueNDk1NkgQ/++4N/GifbsR/ubfc31dkg0ytES8jFh3gk3MO8DjZuoG4p2du6KDAs3M/vBJ7ILB38+apZHS6WJwKw3t1JoagzkWcVF9VY5NgaNW95CXJe0BfuwLUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by AM9PR08MB6274.eurprd08.prod.outlook.com (2603:10a6:20b:2d5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Mon, 14 Mar 2022 13:45:18 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::4d3d:c632:297e:1dcc]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::4d3d:c632:297e:1dcc%5]) with mapi id 15.20.5061.028; Mon, 14 Mar 2022 13:45:17 +0000 Message-ID: <6f59c258-b315-b4b7-fc87-98c4c1aac913@arm.com> Date: Mon, 14 Mar 2022 13:45:16 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] PowerPC, add support for printing non-trivial C++ object for the finish command. Content-Language: en-US To: Tom Tromey , Carl Love via Gdb-patches Cc: Ulrich Weigand , Rogerio Alves References: <28ce795ca489f69829207b2a7a535cf7f77f6dd8.camel@us.ibm.com> <87a6dslkip.fsf@tromey.com> From: Luis Machado In-Reply-To: <87a6dslkip.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0153.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::21) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 8ee1aa09-c686-4a0f-ff7f-08da05c0e668 X-MS-TrafficTypeDiagnostic: AM9PR08MB6274:EE_|DB5EUR03FT044:EE_|VE1PR08MB5181:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: f7W6RrMk108sIVJMpVHDIs2shky1+7yWvr6g2ydikgzmE6iCd685ZCHYhI44vMSdKzG7mKZHYD1+3VjP9BBoIVll62FHvqp9kp3r3KuwhA9D+HhGfxwKbLAWJyEsx192Cn36DGjGyUOOqPB8xxcoVmgl3WbP8N76R31za8rvnUwhSBMGq8fGUrWooP/YgwZMpVW6V1ohCMWxnMtbsblnjfoqaJAdNMC4mFxGIIbru7RewtnINJRSvLIwk33/Oj92p7iSPErHXWg9eWaeMB2bqC8xH/QwyHbCbu+gx6en5/RMbbV09ziEFcvgJPKrDOKlspQ4KuUgFRy50skJ2m0CgNHZ7LsuozDzKVTSTMcmiyZ07SYL9yJt+g5ruBWEtEpcWqzLOHdRkLXfO9vPLsham1w16ho4lWwjJa+9aFnMGjAD2XrQQfKPTjGQKQ3gRN/PVdJzDQcmR0hs5N5gVvL6yonkbpuek9MQpU8/GgEWyB6wEpeddDpNjOq8XMnY2fN9kqySXxBIHUWriRQwH/l25XhqNHIvxKei1crPgPcpEKdvKVCXp+lygPY2gVpfWCjuiS0mfKmk3pKDSdJORt1sUpYkMeV6Ypycnu3bq69YF1b7C1tRLBipXbttjdzF0h8TJFACUwr7efIoMR+qtRygSjuR1MFeznazB/hM4PRhsg4WrvWLthohxkquDGJ1aIqA+C77+RbkUI7q29R7ykrh14Il2bYXILNtjrRs2SDZUJd6GIYmbYu6g9P9tYSxugb+zBpAGMxpnR3Aibfo0Bkgk8fL/H3+l/Qf/SXLs0SskDLTNeuAawK1m42i+dwOmftp8lpLrozo3Lz+5AZv0PkznA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB3919.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(84970400001)(86362001)(316002)(38100700002)(31696002)(6486002)(54906003)(110136005)(5660300002)(2906002)(4326008)(8676002)(66476007)(66556008)(66946007)(44832011)(2616005)(36756003)(508600001)(6506007)(6512007)(186003)(26005)(53546011)(31686004)(8936002)(2004002)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6274 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: f8f00abd-e973-4575-f816-08da05c0e015 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 17G605t+1X7NvLFJiVXPH5x5DR30hsvOwJMd7fIEE6OSZWt6OeJR7AQ/IPWEb/Vdk2BRx45uXAI8eVvZaNbJFi3KmZKIvzk2qTVEQlk3rW/SQ7hwJlhgEtwolV2DBVYwuRCsY1wnynf5OMORL3bJvFgvbm2HL+ZiMhJj3BV9AhFhP1ATETmkuc5FQ4ZgufmxY4Zhk7Z8ziybopy7anQNr0+ZlIkDUdHfxAZCHI3M/fKjjTSWXaEqqjObC6apIDDWI0sCM3zUVmA9LKThzk798oY1g2oAG8XKridQ1LZhan1/zmjNrOL7x0TCe22CLV22KxUiGqrVZp7Dhe5YXOKM+JOO82X1LkWMGy0ua5l/Htm4C847PP6ik0ZRdDaWyHq9vqzIGsSNMQkqMrqWqbTtPy5oMVgFO9RP34rzKS5UdbVuKpJCxRHclygMxK5H+19LdKJkAAtxj11yDOLYBEHLMVu/6RGSWqREExE4AvnGgBlPKh9MTC7/pBg/iY6Bs3zZ99oRwBeWT6X939aHoPz3oDuY6fEhvOktLPcgTfkklyAY5xW6AV6nVvx1G3niPcrrLf0/MVPu8I4z6wfWqsgz3YS6yuV3LSWlXBDolQEYA65jUbpoG6/zT/fwsIgN5Jemjv2iHWpk8iP4BLSzc6l8z9HFL2Gxj6CuXcoZsuN6r+UFd30flcUcQLvquGpnw4V93UsiVVoi9ZnPC35UyXYjXPyoaQImyRu0BjkdFLiP+gTRC9wdadno/K0u6lJkBOgJTNj/tIFst5E3lNZ0yxsC39HUuCtLa+Kac9aNEv9bEfokShRhk5XKkde96H8jLJoc X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(6506007)(8936002)(40460700003)(86362001)(54906003)(316002)(6486002)(31696002)(356005)(31686004)(81166007)(5660300002)(44832011)(2906002)(110136005)(26005)(186003)(336012)(2616005)(36860700001)(82310400004)(53546011)(6512007)(508600001)(8676002)(70586007)(70206006)(4326008)(84970400001)(47076005)(36756003)(2004002)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2022 13:45:28.3762 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ee1aa09-c686-4a0f-ff7f-08da05c0e668 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT044.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5181 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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:45:35 -0000 On 3/14/22 13:40, Tom Tromey via Gdb-patches wrote: >>>>>> "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. 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 > 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"