From patchwork Thu Jan 25 21:35:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Love X-Patchwork-Id: 84759 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 640E8385800D for ; Thu, 25 Jan 2024 21:36:04 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 7D8B13858C53 for ; Thu, 25 Jan 2024 21:35:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D8B13858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7D8B13858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706218540; cv=none; b=jB0pUrQAW8zRjE4UkPphsjywtMYj9Tt8nl4a00+0LKPVjaYajpfAub5wxq/Lywlx+9Df4dumSsfxZT0CoYDLV60vnRFOcODkL7Ahx9tRymO1wFm2cE/Bi4PIxR99zGlVVcTlCXpWGM/6+6P9nGDdZ11d6xRx9vuwOmmlL9kYdhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706218540; c=relaxed/simple; bh=05cAf8MVDIBMrr/5Bk4Frgb8hq4IkZLUgFHq4f1Oim0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=L5PZKqrCuxh43ibQV1rB3fq8WGiUXc3B4BkZSL0uM89/WspoXqq9Cfe5utsUs0gbn8Pl0eR0H+Ol82z24l80MugUmD9tIg3287Nre1PPnah2zLzr5WzIKO4Uqg4W1jbjHMzf1hr/IYSQ5AwBPo7QOEH/gYnpvA9svqKGeuaSIuI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40PLN7bo018394 for ; Thu, 25 Jan 2024 21:35:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : to : from : subject : content-type : content-transfer-encoding; s=pp1; bh=N5Qb3iB45ClQG59L5QBnjbyB2c+ebbkAobpBhGjo+ys=; b=BjZBSSiiRF97FZ63mIx0m9nH8M5y2ccp6El57t1hbih+2bDONoTVKpmv0YFuprXqTehi m7T3kupVMfiBa4j8S+/BNOb5cWfrvtwOSGnzUFgTEf2RdjyXbu7CtGsrILiS5z9Lf+5h iF8t2EmiMlLTRJgvWPmLc1dSvbZ4PCC4EvW1BsNxb6uuOsInQjoJ1tPB7dgq+m24xmUr 4YinSAtSXnQkCiKeB4Be85SqkQZod1luG4MeYzkhKWZH1ukolTupJzwLhVcfErqW/Amr aRKX3TNkSVZaWa/mhXi0MIsLSHNoTmJAMUeXUNFZv/as8FuuGZmuV0pZ+FnE3whV+8sW Dw== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3vuygjgah1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 25 Jan 2024 21:35:37 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 40PJKDlf022412 for ; Thu, 25 Jan 2024 21:35:37 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([172.16.1.69]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3vrt0men32-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 25 Jan 2024 21:35:37 +0000 Received: from smtpav03.wdc07v.mail.ibm.com (smtpav03.wdc07v.mail.ibm.com [10.39.53.230]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 40PLZYhs7930388 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Jan 2024 21:35:34 GMT Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BBF185805C; Thu, 25 Jan 2024 21:35:34 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E6EF58054; Thu, 25 Jan 2024 21:35:34 +0000 (GMT) Received: from [9.67.177.45] (unknown [9.67.177.45]) by smtpav03.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 25 Jan 2024 21:35:34 +0000 (GMT) Message-ID: Date: Thu, 25 Jan 2024 13:35:33 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Ulrich Weigand , gdb-patches@sourceware.org, Carl Love From: Carl Love Subject: [PATCH] rs6000, unwind-on-each-instruction fix. X-TM-AS-GCONF: 00 X-Proofpoint-GUID: FxrrBzACjQs35FWhll-D8M_LS2Xuzj8y X-Proofpoint-ORIG-GUID: FxrrBzACjQs35FWhll-D8M_LS2Xuzj8y X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-25_14,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 malwarescore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 mlxlogscore=695 mlxscore=0 adultscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401250156 X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org GDB maintainers: The unwind-on-each-instruction test currently has 10 failures on Power. The test fails when executing the various tests for the instructions in the epilogue part of a function. The function rs6000_epilogue_frame_cache is called when executing the instructions in the epilogue. The function assumes thatthe stack and the general purpose registers (gpr) and link register (LR) have all been restored to their values on entry to the function. The assumption is not correct. Only the stack pointer (SP), stored in gpr1, has been restored. The LR and the other gprs, specifically gpr31 which is also used to store the SP, may not have been restored. This patch adds code to update the rs6000_frame_cache in function rs6000_epilogue_frame_cache with the rules to properly unroll the gprs and LR to their values on entry to the function thus fixing the various test failures. The patch fixes all 10 regression failures for the test. The patch has been tested on Power 9 and Power 10 with no additional regression test failures. Please let me know if this patch is acceptable to GDB mainline. Carl -------------------------------------------------- rs6000, unwind-on-each-instruction fix. The function rs6000_epilogue_frame_cache assumes the LR and gprs have been restored. In fact register r31 and the link register, lr, may not have been restored yet. This patch adds support to store the lr and gpr register unrolling rules in the cache. The LR and GPR values can now be unrolled correctly. Patch fixes all 10 regresion test failures for the unwind-on-each-insn.exp. --- gdb/rs6000-tdep.c | 53 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c index cc91250d5fe..e831c3748b5 100644 --- a/gdb/rs6000-tdep.c +++ b/gdb/rs6000-tdep.c @@ -3858,6 +3858,8 @@ rs6000_epilogue_frame_cache (frame_info_ptr this_frame, void **this_cache) struct rs6000_frame_cache *cache; struct gdbarch *gdbarch = get_frame_arch (this_frame); ppc_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + struct rs6000_framedata fdata; + int wordsize = tdep->wordsize; if (*this_cache) return (struct rs6000_frame_cache *) *this_cache; @@ -3868,17 +3870,56 @@ rs6000_epilogue_frame_cache (frame_info_ptr this_frame, void **this_cache) try { - /* At this point the stack looks as if we just entered the - function, and the return address is stored in LR. */ - CORE_ADDR sp, lr; + /* At this point the stack looks as if we just entered the function. + The SP (r1) has been restored but the LR and r31 may not have been + restored yet. Need to update the register unrolling information in + the cache for the LR and the saved gprs. */ + CORE_ADDR sp; + CORE_ADDR func = 0, pc = 0; - sp = get_frame_register_unsigned (this_frame, gdbarch_sp_regnum (gdbarch)); - lr = get_frame_register_unsigned (this_frame, tdep->ppc_lr_regnum); + func = get_frame_func (this_frame); + cache->pc = func; + pc = get_frame_pc (this_frame); + skip_prologue (gdbarch, func, pc, &fdata); + + /* SP is in r1 and it has been restored. Get the current value. */ + sp = get_frame_register_unsigned (this_frame, + gdbarch_sp_regnum (gdbarch)); cache->base = sp; cache->initial_sp = sp; - cache->saved_regs[gdbarch_pc_regnum (gdbarch)].set_value (lr); + /* Store the unwinding rules for the gpr registers that have not been + restored yet, specifically r31. + + if != -1, fdata.saved_gpr is the smallest number of saved_gpr. + All gpr's from saved_gpr to gpr31 are saved (except during the + prologue). */ + + if (fdata.saved_gpr >= 0) + { + int i; + CORE_ADDR gpr_addr = cache->base + fdata.gpr_offset; + + for(i = fdata.saved_gpr; i < ppc_num_gprs; i++) + { + if (fdata.gpr_mask & (1U << i)) + cache->saved_regs[tdep->ppc_gp0_regnum + i].set_addr (gpr_addr); + gpr_addr += wordsize; + } + } + + /* Store the lr unwinding rules. */ + if (fdata.lr_offset != 0) + cache->saved_regs[tdep->ppc_lr_regnum].set_addr (cache->base + + fdata.lr_offset); + + else if (fdata.lr_register != -1) + cache->saved_regs[tdep->ppc_lr_regnum].set_realreg (fdata.lr_register); + + /* The PC is found in the link register. */ + cache->saved_regs[gdbarch_pc_regnum (gdbarch)] = + cache->saved_regs[tdep->ppc_lr_regnum]; } catch (const gdb_exception_error &ex) {