From patchwork Sat Nov 5 09:44:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Vanek X-Patchwork-Id: 59993 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 EE8BA3857C75 for ; Sat, 5 Nov 2022 09:46:06 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp00.avonet.cz (smtp00.avonet.cz [217.112.162.55]) by sourceware.org (Postfix) with ESMTP id 44492385841E for ; Sat, 5 Nov 2022 09:45:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 44492385841E 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 4N4CKH5gx2z1xqS; Sat, 5 Nov 2022 10:45:23 +0100 (CET) From: Tomas Vanek To: gdb-patches@sourceware.org Subject: [RFC PATCH 5/5] HACK frame inner than comparison for Arm M-profile sec ext Date: Sat, 5 Nov 2022 10:44:36 +0100 Message-Id: <1667641476-31602-5-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.5 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 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: , Cc: Tomas Vanek Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" !!This change is not intended to be merged to the GDB code!! Arm M-profile can use two stacks or four stack with the security extension. core_addr_lessthan() used in set_gdbarch_inner_than() can break stack unwinding with a false warning "previous frame inner to this frame (corrupt stack?)" when the active stack is switched to another one located below the first one. Unfortunately the settable comparison function used in set_gdbarch_inner_than() takes just lhs and rhs addresses as arguments. Therefore the possibility to avoid the comparison of addresses from two different stack is very limited or impossible. This hack abuses the internal RAM mapping to non-secure and secure/callable areas used in STM32L5 device to prevent false unwinding fails when switching secure/non-secure mode. How to solve the problem correctly? Please advise... Add a settable value "set arm unwind-inner-check 0" to switch off the inner frame check on user request? Rework frame_id_inner() and gdbarch to allow a smarter comparator with access to frame details? Signed-off-by: Tomas Vanek --- gdb/arm-tdep.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 4fac09b..1c683ca 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -876,6 +876,16 @@ class target_arm_instruction_reader : public arm_instruction_reader } } +static int +arm_m_sec_ext_inner_than (CORE_ADDR lhs, CORE_ADDR rhs) +{ + if ((lhs & 0xfff00000) == 0x20000000 + && (rhs & 0xfff00000) == 0x30000000) + return false; + + return (lhs < rhs); +} + /* Remove useless bits from addresses in a running program. */ static CORE_ADDR arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val) @@ -10725,7 +10735,9 @@ enum arm_vfp_cprc_base_type set_gdbarch_skip_trampoline_code (gdbarch, arm_skip_stub); /* The stack grows downward. */ - set_gdbarch_inner_than (gdbarch, core_addr_lessthan); + set_gdbarch_inner_than (gdbarch, have_sec_ext ? + arm_m_sec_ext_inner_than : + core_addr_lessthan); /* Breakpoint manipulation. */ set_gdbarch_breakpoint_kind_from_pc (gdbarch, arm_breakpoint_kind_from_pc);