From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by sourceware.org (Postfix) with ESMTPS id 6FB133858C56 for ; Thu, 13 Oct 2022 18:12:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FB133858C56 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29DDa8n0019805; Thu, 13 Oct 2022 20:12:05 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3k5v4n2rwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Oct 2022 20:12:05 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 284E310002A; Thu, 13 Oct 2022 20:12:00 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 1BEF225AEE8; Thu, 13 Oct 2022 20:12:00 +0200 (CEST) Received: from jkgcxl0002.jkg.st.com (10.75.127.47) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2375.31; Thu, 13 Oct 2022 20:11:57 +0200 From: =?UTF-8?q?Torbj=C3=B6rn=20SVENSSON?= To: CC: , , , =?UTF-8?q?Torbj=C3=B6rn=20SVENSSON?= Subject: [PATCH v4] gdb/arm: Stop unwinding on error, but do not assert Date: Thu, 13 Oct 2022 20:11:35 +0200 Message-ID: <20221013181135.688646-1-torbjorn.svensson@foss.st.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-13_08,2022-10-13_01,2022-06-22_01 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Oct 2022 18:12:13 -0000 When it's impossible to read the FPCCR and XPSR, the unwinding is unpredictable as the it's not possible to determine the correct frame size or padding. The only sane thing to do in this condition is to stop the unwinding. Example session wihtout this patch: (gdb) bt #0 SVC_Handler () at .../GPIO/GPIO_EXTI/Src/stm32f4xx_it.c:112 .../gdb/arm-tdep.c:3594: internal-error: arm_m_exception_cache: Assertion `safe_read_memory_unsigned_integer (FPCCR, ARM_INT_REGISTER_SIZE, byte_order, &fpccr)' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- 0x5583bfb2a157 gdb_internal_backtrace_1 ... --------------------- This is a bug, please report it. For instructions, see: . Aborted (core dumped) Example session with this patch: (gdb) bt #0 SVC_Handler () at .../GPIO/GPIO_EXTI/Src/stm32f4xx_it.c:112 warning: Could not fetch required FPCCR content. Further unwind is impossible. #1 (gdb) Signed-off-by: Torbjörn SVENSSON --- gdb/arm-tdep.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 041e6afefed..fa6b08e4a54 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -3591,9 +3591,14 @@ arm_m_exception_cache (frame_info_ptr this_frame) ULONGEST fpcar; /* Read FPCCR register. */ - gdb_assert (safe_read_memory_unsigned_integer (FPCCR, - ARM_INT_REGISTER_SIZE, - byte_order, &fpccr)); + if (!safe_read_memory_unsigned_integer (FPCCR, ARM_INT_REGISTER_SIZE, + byte_order, &fpccr)) + { + warning (_("Could not fetch required FPCCR content. Further " + "unwinding is impossible.")); + arm_cache_set_active_sp_value (cache, tdep, 0); + return cache; + } /* Read FPCAR register. */ if (!safe_read_memory_unsigned_integer (FPCAR, ARM_INT_REGISTER_SIZE, @@ -3669,9 +3674,16 @@ arm_m_exception_cache (frame_info_ptr this_frame) aligner between the top of the 32-byte stack frame and the previous context's stack pointer. */ ULONGEST xpsr; - gdb_assert (safe_read_memory_unsigned_integer (cache->saved_regs[ - ARM_PS_REGNUM].addr (), 4, - byte_order, &xpsr)); + if (!safe_read_memory_unsigned_integer (cache->saved_regs[ARM_PS_REGNUM] + .addr (), ARM_INT_REGISTER_SIZE, + byte_order, &xpsr)) + { + warning (_("Could not fetch required XPSR content. Further " + "unwinding is impossible.")); + arm_cache_set_active_sp_value (cache, tdep, 0); + return cache; + } + if (bit (xpsr, 9) != 0) { CORE_ADDR new_sp = arm_cache_get_prev_sp_value (cache, tdep) + 4; @@ -3689,6 +3701,27 @@ arm_m_exception_cache (frame_info_ptr this_frame) phex (lr, ARM_INT_REGISTER_SIZE)); } +/* Implementation of the stop_reason hook for arm_m_exception frames. */ + +static enum unwind_stop_reason +arm_m_exception_frame_unwind_stop_reason (frame_info_ptr this_frame, + void **this_cache) +{ + struct arm_prologue_cache *cache; + arm_gdbarch_tdep *tdep + = gdbarch_tdep (get_frame_arch (this_frame)); + + if (*this_cache == NULL) + *this_cache = arm_m_exception_cache (this_frame); + cache = (struct arm_prologue_cache *) *this_cache; + + /* If we've hit a wall, stop. */ + if (arm_cache_get_prev_sp_value (cache, tdep) == 0) + return UNWIND_OUTERMOST; + + return UNWIND_NO_REASON; +} + /* Implementation of function hook 'this_id' in 'struct frame_uwnind'. */ @@ -3798,7 +3831,7 @@ struct frame_unwind arm_m_exception_unwind = { "arm m exception", SIGTRAMP_FRAME, - default_frame_unwind_stop_reason, + arm_m_exception_frame_unwind_stop_reason, arm_m_exception_this_id, arm_m_exception_prev_register, NULL, -- 2.25.1