From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp00.avonet.cz (smtp00.avonet.cz [217.112.162.55]) by sourceware.org (Postfix) with ESMTP id 6CF843858C54 for ; Sat, 5 Nov 2022 09:45:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6CF843858C54 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=fbl.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=fbl.cz Received: from ktus.lan (217-115-245-101.cust.avonet.cz [217.115.245.101]) by smtp00.avonet.cz (Postfix) with ESMTP id 4N4CKC2Qwgz1xrp; Sat, 5 Nov 2022 10:45:19 +0100 (CET) From: Tomas Vanek To: gdb-patches@sourceware.org Cc: Tomas Vanek Subject: [RFC PATCH 2/5] gdb/arm: PR 29716 Fix FNC_RETURN stack selection in exception unwinder Date: Sat, 5 Nov 2022 10:44:33 +0100 Message-Id: <1667641476-31602-2-git-send-email-vanekt@fbl.cz> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1667641476-31602-1-git-send-email-vanekt@fbl.cz> References: <1667641476-31602-1-git-send-email-vanekt@fbl.cz> X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,SPF_FAIL,SPF_HELO_NONE,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 List-Id: Unwinding of FNC_RETURN selected the process stack whenever zero IPSR indicated thread mode. This does not comply Arm v8-M Architecture Reference Manual B3.8 Stack pointer IDMLS "In Thread mode, CONTROL.SPSEL determines whether the PE uses the main or process stack" Check SPSEL bit of CONTROL_S register. For simplicity the CONTROL_S is not tracked for changes in the inner frames, the CONTROL_S value is passed unchanged from the innermost frame. Signed-off-by: Tomas Vanek --- gdb/arm-tdep.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 564ee43..4180277 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -3485,13 +3485,27 @@ struct frame_unwind arm_stub_unwind = { return cache; } - ULONGEST xpsr = get_frame_register_unsigned (this_frame, ARM_PS_REGNUM); - if ((xpsr & 0x1ff) != 0) - /* Handler mode: This is the mode that exceptions are handled in. */ - arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_msp_s_regnum); - else - /* Thread mode: This is the normal mode that programs run in. */ - arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_psp_s_regnum); + bool spsel = true; + if (tdep->m_profile_control_s_regnum >= 0) + { + ULONGEST control_s + = get_frame_register_unsigned (this_frame, + tdep->m_profile_control_s_regnum); + spsel = (control_s & (1 << 1)) != 0; + } + + bool s_process_stack = false; + if (spsel) + { + ULONGEST xpsr = get_frame_register_unsigned (this_frame, + ARM_PS_REGNUM); + s_process_stack = (xpsr & 0x1ff) == 0; + } + + arm_cache_switch_prev_sp (cache, tdep, + s_process_stack ? + tdep->m_profile_psp_s_regnum : + tdep->m_profile_msp_s_regnum); CORE_ADDR unwound_sp = arm_cache_get_prev_sp_value (cache, tdep); -- 1.9.1