From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id A5AB93858D3C for ; Fri, 11 Mar 2022 22:26:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A5AB93858D3C Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22BKRK0V036707 for ; Fri, 11 Mar 2022 22:26:36 GMT Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 3eqg9sxdcu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 11 Mar 2022 22:26:36 +0000 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22BMDHA5017505 for ; Fri, 11 Mar 2022 22:26:35 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma01dal.us.ibm.com with ESMTP id 3emgamke32-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 11 Mar 2022 22:26:35 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22BMQWB514811646 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 11 Mar 2022 22:26:32 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 44E44C6062; Fri, 11 Mar 2022 22:26:32 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E33E4C605D; Fri, 11 Mar 2022 22:26:31 +0000 (GMT) Received: from li-e362e14c-2378-11b2-a85c-87d605f3c641.ibm.com (unknown [9.211.79.233]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 11 Mar 2022 22:26:31 +0000 (GMT) Message-ID: <28ce795ca489f69829207b2a7a535cf7f77f6dd8.camel@us.ibm.com> Subject: [PATCH] PowerPC, add support for printing non-trivial C++ object for the finish command. From: Carl Love To: gdb-patches@sourceware.org, Ulrich Weigand Cc: Rogerio Alves , Will Schmidt , cel@us.ibm.com Date: Fri, 11 Mar 2022 14:26:31 -0800 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-18.el8) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 0eS8dHK89QPFxn_ly_yn_jwJ1v0DTnrU X-Proofpoint-ORIG-GUID: 0eS8dHK89QPFxn_ly_yn_jwJ1v0DTnrU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-11_09,2022-03-11_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 spamscore=0 clxscore=1015 impostorscore=0 suspectscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203110112 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: Fri, 11 Mar 2022 22:26:38 -0000 GDB maintainers: The following patch fixes an issue on Powerpc where the function return value for a C++ program prints garbage when the function return type is a class object. The fix is based on an x86-64 patch for the same issue. The patch has been tested on Power 10 with no regressions. Please let me know if this patch is acceptable for mainline. Thanks. Carl Love --------------------------------------------------- PowerPC, add support for printing non-trivial C++ object for the finish command. This patch fixes five testcase failures in gdb/cpp/non-trival-retval.exp. The testcases that fail were added by commit: commit b1718fcdd1d2a5c514f8ee504ba07fb3f42b8608 Author: Andrew Burgess Date: Mon Dec 13 16:56:16 2021 +0000 gdb: on x86-64 non-trivial C++ objects are returned in memory Fixes PR gdb/28681. It was observed that after using the `finish` command an incorrect value was displayed in some cases. Specifically, this behaviour was observed on an x86-64 target. The commit adds new tests for printing the return value of a C++ function. The return value of the function is a C++ Class. The current PowerPC code is looking for the return value in register r3. The return value is actually in memory as described in the commit message for x86-64 above. The fix for Powerpc is based on the fix in the above commit plus examining how x86-64 handles the value in function amd64_return_value in file gdb/amd64-tdep.c. --- gdb/ppc-sysv-tdep.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c index 9a3b02f028d..50277e7bdd1 100644 --- a/gdb/ppc-sysv-tdep.c +++ b/gdb/ppc-sysv-tdep.c @@ -2035,6 +2035,20 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function, return RETURN_VALUE_REGISTER_CONVENTION; } + /* If the object is a non-trivial C++ object the object is in memory. */ + if (!language_pass_by_reference (valtype).trivially_copyable) + { + if (readbuf) + { + ULONGEST addr; + int regnum = tdep->ppc_gp0_regnum + 3; + + regcache_raw_read_unsigned (regcache, regnum, &addr); + read_memory (addr, readbuf, TYPE_LENGTH (valtype)); + } + return RETURN_VALUE_ABI_RETURNS_ADDRESS; + } + /* In the ELFv2 ABI, aggregate types of up to 16 bytes are returned in registers r3:r4. */ if (tdep->elf_abi == POWERPC_ELF_V2 -- 2.32.0