From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2051.outbound.protection.outlook.com [40.107.22.51]) by sourceware.org (Postfix) with ESMTPS id CB3793856DD3 for ; Tue, 9 Aug 2022 16:15:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB3793856DD3 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=BRzGd9CjBbhqsBQNYDGkGrf9KPEaB1MBI4hzD7wh3C6ACciLBwzeVXtTajJdkmLmml7IpigbVnxSpmUXx8GcXFyVwazuVON7GbeB+R+2nkcZHxfpaXTJN2Wy5Mc+jCvmnkvqrARZkYFa3yMCNg5oXpaYNfyEvcsja3mfAmcE6X8SGMmC0d3JOqcY3j7z/dr7Xahdgu/1E3K1ELRzeEIhnqPeyZAelaZuRniHoMGQxT2kzlCHhuN2ZypkviKK41CaPiqolG3bMTQuvmy6EoCOFyfnkzbpFq7z/ttrRc54voBzOnwfKBKi44uYQkfqHXg3dkpQF1q+hdYQszj8ib/S7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+s65tP+LCyy2dPALhPk7jZLQu7PcphUvfOWnCsdXyMA=; b=Nl88CXJntVdY23ASjuPQXdh7JOvjfBFpAhn1U6/ZvBWJw4vKbIdAYwXMWulYl+AZ0aNAAr0u95FwpSk+kwvI1TBlO7rKr7WOfGaLi97JKGJxVyvjBFYKyCj23Bkr9i5ltxvt8+ZD/60LKh1DXIa7XFu2oCtmzX2kfapb3S6QsG1QBj+kpz4mc8TszEIIQpgycUKd5Cg7c4z277BXh/V1ZaBUwPV/kx8i8B1+uLXJ9PXvAb7uk8LAXQr/wR/8O8PTXazWfEIU/jpAg6wvT8kPSMXkJjRkCMpojiWu8hp/WedhBsbUv+ifVH7i3tGEKdpcSZYU8tEi4FHfgSp2z9z1Fw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB7PR02CA0026.eurprd02.prod.outlook.com (2603:10a6:10:52::39) by VI1PR0802MB2398.eurprd08.prod.outlook.com (2603:10a6:800:af::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.17; Tue, 9 Aug 2022 16:15:43 +0000 Received: from DBAEUR03FT006.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:52:cafe::cb) by DB7PR02CA0026.outlook.office365.com (2603:10a6:10:52::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.21 via Frontend Transport; Tue, 9 Aug 2022 16:15:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT006.mail.protection.outlook.com (100.127.142.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16 via Frontend Transport; Tue, 9 Aug 2022 16:15:43 +0000 Received: ("Tessian outbound fa99bf31ee7d:v123"); Tue, 09 Aug 2022 16:15:42 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 6e2f392fced5873b X-CR-MTA-TID: 64aa7808 Received: from 3713ec3f44db.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D86DF76C-C403-4194-B3BF-A5991C62B5AA.1; Tue, 09 Aug 2022 16:15:35 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3713ec3f44db.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 09 Aug 2022 16:15:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SYsa4Jrki6jgyfg+rrqoiuB5uOKlJgnxp2xI1UCE5HCIXEzl4/H5m0xnzZAQjexac1tLUEx6m3dOAOsxJfJSVEWPgkD7Y0WmxMgPVnv9CGRTn/6KtYfqdKXY0xeQb86l3oZvUdo3PwIv+luscAPZ3OyfzXULTsEwG9bgL0WnehlNXruU9z3ozIjKuf7tctrwDc+jxkdvxExO/hOc/OutkVijxbCroWntAKjqJ6d28+SRiL9F6BVTO5oF8mG4BNZonWZKv7DOTOKctF+GD0PI6I+pR/fd9qPmFCZiMaUORt//mlvdOVjePWkRbIyBEjXOKYbMhbkElQyFZi4JH4tA8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+s65tP+LCyy2dPALhPk7jZLQu7PcphUvfOWnCsdXyMA=; b=KN++iGKmisQZynfOeKyZvgt7vHfgbA8Aymh9CLuAvtcYAVaB3MtoRJFJtvLoVr9a+JoH3pGthJdpLID9htfdXpOP8Ef2szk/23riaB1Refu1E6G5AXcO3pXhir4kJfEBzk6hSlOm08nOHpfbIkwiSlqadZq5/MbO0/AyfYZJvEeoFoxfz9A0Z8k48VVgtBeBtRQpwqQ8GGPNH/DE0YeGL3JUFfNV6uhOlMZQSUKL3IF1WnlExBnLUe4SE7lI4Nw7EhdNHc63PlBc0L39wkKUch9qDDsUTzIUl2AloVpTGnhUIJAXe9/zzMThytD+uxOQODKyrzEaQdnlz2niYnc8tA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by AM9PR08MB6999.eurprd08.prod.outlook.com (2603:10a6:20b:41a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.16; Tue, 9 Aug 2022 16:15:33 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::cc64:9170:b12d:de8]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::cc64:9170:b12d:de8%4]) with mapi id 15.20.5504.019; Tue, 9 Aug 2022 16:15:33 +0000 Message-ID: <136b08eb-3680-b166-2ad8-1d8acdff6b34@arm.com> Date: Tue, 9 Aug 2022 17:15:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2] gdb/arm: Cleanup of arm_m_exception_cache Content-Language: en-US To: =?UTF-8?Q?Torbj=c3=b6rn_SVENSSON?= , gdb-patches@sourceware.org References: <20220809153006.3249562-1-torbjorn.svensson@foss.st.com> From: Luis Machado In-Reply-To: <20220809153006.3249562-1-torbjorn.svensson@foss.st.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: LO4P265CA0250.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:350::12) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 10eb6f00-8fa9-4948-626e-08da7a2268b1 X-MS-TrafficTypeDiagnostic: AM9PR08MB6999:EE_|DBAEUR03FT006:EE_|VI1PR0802MB2398:EE_ x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: NgTGtn9fl9+RHH3uslsuxaUv6B1eW5R1HvzuTSitW8h+VNT7+3iiw2X+YzbCYsD+6bgIWDVugDP+rERnTxKIxgtPAb3E9RlRhIOnwykKZgmTRH58zunRyT4D7I1Ec99ttWmnngRv24vBu5fXybePtpYGfIDP0tw7aJt4Je1+kDqlwIafqMV+vzVPm+GzVQyOQAhH7TPHhGGVz1I9fBVCrmjqwuyGpmsxU+T73sEcBaSHglDEC8O5TNYFtHbaxNXJWocbMg7HIG64U6Xr2MoZuTNiikdHTSoj94/GPCtD6oYAaDjHL8s7BpqHP7xRsk1XOfOtvogLVRf5PMOrRVRqALDnuPxOEBPa3TiCnNpchylXyf7HMK0J6l6FUPSIbCIcrBlOjHT0pIukycBxeIwW4OwPl0gEKfDNUOfL4MA8rb9ijhhVrAaFpBoIGAEaC+T6SQGCjBNFqoT24vr5u6lUDLMpQVHh58n7F4XYNyxQU3GjOFM8evyDlcnYC/rptJCvIuvvXnmc57f77b10VRGp0y2YNPQ+YcAoHLZ0re76N3iBHpQmZsT1xDy3crFKzHUVxnC+anNCv/hHIZ6KfBzi3UQ/NrY+AB8oLTx/rYhMmeMXXkwuiJtprdJXaLu/b5H39zPQz+GumToWD5M3DngDfiDhnXZREiq4/CxCZVjsuJ0rJ92RpMj9KmIZMwEcKO0oPT056sR5buPXZILks/CLKfVsHwL2bhSHxxHICjaLVDg0miuodx4wZjp1j84uQFwO4f47u7ApM2p1cfPjOVFaqzBbMNyzQnJiB0OqNeAGZI+rzaMlpXQ/7NcVtQ5myvbCRYx24Deflcp/Ky0tem9TDA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB3919.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(136003)(376002)(39860400002)(396003)(346002)(66556008)(8676002)(36756003)(31686004)(66476007)(66946007)(5660300002)(31696002)(6486002)(8936002)(86362001)(316002)(478600001)(83380400001)(38100700002)(41300700001)(44832011)(6506007)(53546011)(2906002)(30864003)(2616005)(26005)(66574015)(6512007)(186003)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6999 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT006.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 08573cb6-7eaf-4030-5550-08da7a2262b3 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MhzzOhM6w07F8VSOQo6Tww0hKllPbNujT/VkBl9hjClnjiFcSFHyUKZFzYSjhTH80VYjTM8HrHTHcR/h9vcUsb0XfrPTMJC/oaP1znHc+r0cFdvWdsDGiaau+0t5BPDEAkf5ZE1b1fnOfEipdfbZ7qZPl8IyWKvyWnn2q+rVtZgRuZhpHViPqxBKIkXNBD3a4FgtvPcPpIfmY/QkyR6V9Hq5RG6uFZcfRk1zZrVekIg7dq3DYwnyIBuNAHB2dqNBnW6OCuRI45PtcuviMxOVe+EH5JR7XvXGPMQyxS/Ha8t+I3FS87N1BV0fxYAfVr5qv3DCNcRohS7P1sJCh90Z4wrdmok0ZbQjzGwlUpbNmtz7xtgys/NMixcSGD4ZKHie4z7ucLHCkaZKxH5J/1FT5ZX9tstvZEr/9RjlMfV6NZVj8V24sq5idBteNv6X4MZFwIj5Q0f/7wllxf9aX5DxyJ7IsX2hURJbvTuwZGoHyh8b+QLlQLNYl72berbX88iHEYyKCpirNqA3XweQ6D0Ye097t2n57/+zcD/tFQz1Jz2WSvtXkyp12CLJqxerr0IxvZHm1L4cxd+6SZvd7VMokgftwjNw9U+UBjxJfrGhM9t+dWcVJ0FOsTlaL+GqUTDjGPSDgZJUeVwJRHJDEwkwO/xQzYSafxBbt2FpXuGcHZCG0xIuv/Cgsx2FnyeEv+KkKXCczAbAT5P7iO+ruBHZ5FgULQhbm9e3epGRoYdh+sPYn0KaGsjgiFdzwYZ4MdBurYMTUMJbmAirjBtq4xXbDBhKgEUw1JuH+1iD1gBQF0MM9jNobyuNUEy4HTqF7SNo9h1hWu/fLA9AqsESnM3xGg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(396003)(376002)(136003)(346002)(46966006)(40470700004)(36840700001)(82310400005)(186003)(2616005)(70586007)(47076005)(66574015)(44832011)(336012)(70206006)(8676002)(8936002)(83380400001)(30864003)(2906002)(41300700001)(40480700001)(478600001)(6512007)(31686004)(36756003)(6506007)(6486002)(53546011)(26005)(5660300002)(81166007)(36860700001)(86362001)(31696002)(40460700003)(316002)(356005)(82740400003)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2022 16:15:43.0122 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10eb6f00-8fa9-4948-626e-08da7a2268b1 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT006.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2398 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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: Tue, 09 Aug 2022 16:15:57 -0000 On 8/9/22 16:30, Torbjörn SVENSSON wrote: > With this change, only valid content of LR is accepted for the current > target. If the content for LR is anything but EXC_RETURN or FNC_RETURN > will cause GDB to assert since it's an invalid state for the unwinder. > FNC_RETURN pattern requires Security Extensions to be enabled or GDB > will assert due to the bad state of the unwinder. > > Signed-off-by: Torbjörn SVENSSON > --- > gdb/arm-tdep.c | 380 ++++++++++++++++++++++++++----------------------- > 1 file changed, 204 insertions(+), 176 deletions(-) > > diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c > index cf8b610a381..299c416fe52 100644 > --- a/gdb/arm-tdep.c > +++ b/gdb/arm-tdep.c > @@ -3346,19 +3346,7 @@ arm_m_exception_cache (struct frame_info *this_frame) > { > struct gdbarch *gdbarch = get_frame_arch (this_frame); > arm_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); > - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); > struct arm_prologue_cache *cache; > - CORE_ADDR lr; > - CORE_ADDR sp; > - CORE_ADDR unwound_sp; > - uint32_t sp_r0_offset = 0; > - LONGEST xpsr; > - uint32_t exc_return; > - bool fnc_return; > - uint32_t extended_frame_used; > - bool secure_stack_used = false; > - bool default_callee_register_stacking = false; > - bool exception_domain_is_secure = false; > > cache = FRAME_OBSTACK_ZALLOC (struct arm_prologue_cache); > arm_cache_init (cache, this_frame); > @@ -3367,8 +3355,8 @@ arm_m_exception_cache (struct frame_info *this_frame) > describes which bits in LR that define which stack was used prior > to the exception and if FPU is used (causing extended stack frame). */ > > - lr = get_frame_register_unsigned (this_frame, ARM_LR_REGNUM); > - sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM); > + CORE_ADDR lr = get_frame_register_unsigned (this_frame, ARM_LR_REGNUM); > + CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM); > > /* ARMv7-M Architecture Reference "A2.3.1 Arm core registers" > states that LR is set to 0xffffffff on reset. ARMv8-M Architecture > @@ -3381,9 +3369,22 @@ arm_m_exception_cache (struct frame_info *this_frame) > return cache; > } > > - fnc_return = (((lr >> 24) & 0xff) == 0xfe); > - if (tdep->have_sec_ext && fnc_return) > + /* Check FNC_RETURN indicator bits (24-31). */ > + bool fnc_return = (((lr >> 24) & 0xff) == 0xfe); > + if (fnc_return) > { > + /* FNC_RETURN is only valid for targets with Security Extension. */ > + if (!tdep->have_sec_ext) > + { > + error (_("While unwinding an exception frame, found unexpected Link " > + "Register value 0x%lx. This should not happen and may be " You should use the %s format here and use phex to turn the 32-bit value to hex. Also, since this is checking explicitly for a value and the Security Extension, we should add that to the error message to make it more obvious what is failing. "While unwinding an exception frame, found unexpected Link Register value %s that requires the security extension, but the extension was not found or is disabled. This should not happen and may be caused by corrupt data or a bug in GDB." > + "caused by corrupt data or a bug in GDB."), lr); > + > + /* Terminate any further stack unwinding by referring to self. */ > + arm_cache_set_active_sp_value (cache, tdep, sp); > + return cache; Since you errored out, there's no use returning or executing any other statements after error. > + } > + > if (!arm_unwind_secure_frames) > { > warning (_("Non-secure to secure stack unwinding disabled.")); > @@ -3393,7 +3394,7 @@ arm_m_exception_cache (struct frame_info *this_frame) > return cache; > } > > - xpsr = get_frame_register_unsigned (this_frame, ARM_PS_REGNUM); > + ULONGEST xpsr = get_frame_register_unsigned (this_frame, ARM_PS_REGNUM); > if ((xpsr & 0xff) != 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); > @@ -3401,7 +3402,7 @@ arm_m_exception_cache (struct frame_info *this_frame) > /* Thread mode: This is the normal mode that programs run in. */ > arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_psp_s_regnum); > > - unwound_sp = arm_cache_get_prev_sp_value (cache, tdep); > + CORE_ADDR unwound_sp = arm_cache_get_prev_sp_value (cache, tdep); > > /* Stack layout for a function call from Secure to Non-Secure state > (ARMv8-M section B3.16): > @@ -3426,17 +3427,23 @@ arm_m_exception_cache (struct frame_info *this_frame) > } > > /* Check EXC_RETURN indicator bits (24-31). */ > - exc_return = (((lr >> 24) & 0xff) == 0xff); > + bool exc_return = (((lr >> 24) & 0xff) == 0xff); > if (exc_return) > { > + int sp_regnum; > + bool secure_stack_used = false; > + bool default_callee_register_stacking = false; > + bool exception_domain_is_secure = false; > + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); > + > /* Check EXC_RETURN bit SPSEL if Main or Thread (process) stack used. */ > - bool process_stack_used = ((lr & (1 << 2)) != 0); > + bool process_stack_used = (bit (lr,2) != 0); > > if (tdep->have_sec_ext) > { > - secure_stack_used = ((lr & (1 << 6)) != 0); > - default_callee_register_stacking = ((lr & (1 << 5)) != 0); > - exception_domain_is_secure = ((lr & (1 << 0)) == 0); > + secure_stack_used = (bit (lr,6) != 0); Could you please address the formatting issues? space before `(`, space after `,` > + default_callee_register_stacking = (bit (lr,5) != 0);> + exception_domain_is_secure = (bit (lr,0) == 0); > > /* Unwinding from non-secure to secure can trip security > measures. In order to avoid the debugger being > @@ -3456,187 +3463,208 @@ arm_m_exception_cache (struct frame_info *this_frame) > { > if (secure_stack_used) > /* Secure thread (process) stack used, use PSP_S as SP. */ > - arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_psp_s_regnum); > + sp_regnum = tdep->m_profile_psp_s_regnum; > else > /* Non-secure thread (process) stack used, use PSP_NS as SP. */ > - arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_psp_ns_regnum); > + sp_regnum = tdep->m_profile_psp_ns_regnum; > } > else > { > if (secure_stack_used) > /* Secure main stack used, use MSP_S as SP. */ > - arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_msp_s_regnum); > + sp_regnum = tdep->m_profile_msp_s_regnum; > else > /* Non-secure main stack used, use MSP_NS as SP. */ > - arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_msp_ns_regnum); > + sp_regnum = tdep->m_profile_msp_ns_regnum; > } > } > else > { > if (process_stack_used) > /* Thread (process) stack used, use PSP as SP. */ > - arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_psp_regnum); > + sp_regnum = tdep->m_profile_psp_regnum; > else > /* Main stack used, use MSP as SP. */ > - arm_cache_switch_prev_sp (cache, tdep, tdep->m_profile_msp_regnum); > - } > - } > - > - /* Fetch the SP to use for this frame. */ > - unwound_sp = arm_cache_get_prev_sp_value (cache, tdep); > - > - /* Exception entry context stacking are described in ARMv8-M (section B3.19) > - and ARMv7-M (sections B1.5.6 and B1.5.7) Architecture Reference Manuals. > - > - The following figure shows the structure of the stack frame when Security > - and Floating-point extensions are present. > - > - SP Offsets > - Without With > - Callee Regs Callee Regs > - (Secure -> Non-Secure) > - +-------------------+ > - 0xA8 | | 0xD0 > - +===================+ --+ <-- Original SP > - 0xA4 | S31 | 0xCC | > - +-------------------+ | > - ... | Additional FP context > - +-------------------+ | > - 0x68 | S16 | 0x90 | > - +===================+ --+ > - 0x64 | Reserved | 0x8C | > - +-------------------+ | > - 0x60 | FPSCR | 0x88 | > - +-------------------+ | > - 0x5C | S15 | 0x84 | FP context > - +-------------------+ | > - ... | > - +-------------------+ | > - 0x20 | S0 | 0x48 | > - +===================+ --+ > - 0x1C | xPSR | 0x44 | > - +-------------------+ | > - 0x18 | Return address | 0x40 | > - +-------------------+ | > - 0x14 | LR(R14) | 0x3C | > - +-------------------+ | > - 0x10 | R12 | 0x38 | State context > - +-------------------+ | > - 0x0C | R3 | 0x34 | > - +-------------------+ | > - ... | > - +-------------------+ | > - 0x00 | R0 | 0x28 | > - +===================+ --+ > - | R11 | 0x24 | > - +-------------------+ | > - ... | > - +-------------------+ | Additional state context > - | R4 | 0x08 | when transitioning from > - +-------------------+ | Secure to Non-Secure > - | Reserved | 0x04 | > - +-------------------+ | > - | Magic signature | 0x00 | > - +===================+ --+ <-- New SP */ > - > - /* With the Security extension, the hardware saves R4..R11 too. */ > - if (exc_return && tdep->have_sec_ext && secure_stack_used > - && (!default_callee_register_stacking || exception_domain_is_secure)) > - { > - /* Read R4..R11 from the integer callee registers. */ > - cache->saved_regs[4].set_addr (unwound_sp + 0x08); > - cache->saved_regs[5].set_addr (unwound_sp + 0x0C); > - cache->saved_regs[6].set_addr (unwound_sp + 0x10); > - cache->saved_regs[7].set_addr (unwound_sp + 0x14); > - cache->saved_regs[8].set_addr (unwound_sp + 0x18); > - cache->saved_regs[9].set_addr (unwound_sp + 0x1C); > - cache->saved_regs[10].set_addr (unwound_sp + 0x20); > - cache->saved_regs[11].set_addr (unwound_sp + 0x24); > - sp_r0_offset = 0x28; > - } > - > - /* The hardware saves eight 32-bit words, comprising xPSR, > - ReturnAddress, LR (R14), R12, R3, R2, R1, R0. See details in > - "B1.5.6 Exception entry behavior" in > - "ARMv7-M Architecture Reference Manual". */ > - cache->saved_regs[0].set_addr (unwound_sp + sp_r0_offset); > - cache->saved_regs[1].set_addr (unwound_sp + sp_r0_offset + 0x04); > - cache->saved_regs[2].set_addr (unwound_sp + sp_r0_offset + 0x08); > - cache->saved_regs[3].set_addr (unwound_sp + sp_r0_offset + 0x0C); > - cache->saved_regs[ARM_IP_REGNUM].set_addr (unwound_sp + sp_r0_offset + 0x10); > - cache->saved_regs[ARM_LR_REGNUM].set_addr (unwound_sp + sp_r0_offset + 0x14); > - cache->saved_regs[ARM_PC_REGNUM].set_addr (unwound_sp + sp_r0_offset + 0x18); > - cache->saved_regs[ARM_PS_REGNUM].set_addr (unwound_sp + sp_r0_offset + 0x1C); > - > - /* Check EXC_RETURN bit FTYPE if extended stack frame (FPU regs stored) > - type used. */ > - extended_frame_used = ((lr & (1 << 4)) == 0); > - if (exc_return && extended_frame_used) > - { > - int i; > - int fpu_regs_stack_offset; > - ULONGEST fpccr; > - > - /* Read FPCCR register. */ > - gdb_assert (safe_read_memory_unsigned_integer (FPCCR, > - ARM_INT_REGISTER_SIZE, > - byte_order, &fpccr)); > - bool fpccr_ts = bit (fpccr,26); > - > - /* This code does not take into account the lazy stacking, see "Lazy > - context save of FP state", in B1.5.7, also ARM AN298, supported > - by Cortex-M4F architecture. > - To fully handle this the FPCCR register (Floating-point Context > - Control Register) needs to be read out and the bits ASPEN and LSPEN > - could be checked to setup correct lazy stacked FP registers. > - This register is located at address 0xE000EF34. */ > - > - /* Extended stack frame type used. */ > - fpu_regs_stack_offset = unwound_sp + sp_r0_offset + 0x20; > - for (i = 0; i < 8; i++) > - { > - cache->saved_regs[ARM_D0_REGNUM + i].set_addr (fpu_regs_stack_offset); > - fpu_regs_stack_offset += 8; > - } > - cache->saved_regs[ARM_FPSCR_REGNUM].set_addr (unwound_sp + sp_r0_offset + 0x60); > - fpu_regs_stack_offset += 4; > + sp_regnum = tdep->m_profile_msp_regnum; > + } > + > + /* Set the active SP regnum. */ > + arm_cache_switch_prev_sp (cache, tdep, sp_regnum); > + > + /* Fetch the SP to use for this frame. */ > + CORE_ADDR unwound_sp = arm_cache_get_prev_sp_value (cache, tdep); > + > + /* Exception entry context stacking are described in ARMv8-M (section > + B3.19) and ARMv7-M (sections B1.5.6 and B1.5.7) Architecture Reference > + Manuals. > + > + The following figure shows the structure of the stack frame when > + Security and Floating-point extensions are present. > + > + SP Offsets > + Without With > + Callee Regs Callee Regs > + (Secure -> Non-Secure) > + +-------------------+ > + 0xA8 | | 0xD0 > + +===================+ --+ <-- Original SP > + 0xA4 | S31 | 0xCC | > + +-------------------+ | > + ... | Additional FP context > + +-------------------+ | > + 0x68 | S16 | 0x90 | > + +===================+ --+ > + 0x64 | Reserved | 0x8C | > + +-------------------+ | > + 0x60 | FPSCR | 0x88 | > + +-------------------+ | > + 0x5C | S15 | 0x84 | FP context > + +-------------------+ | > + ... | > + +-------------------+ | > + 0x20 | S0 | 0x48 | > + +===================+ --+ > + 0x1C | xPSR | 0x44 | > + +-------------------+ | > + 0x18 | Return address | 0x40 | > + +-------------------+ | > + 0x14 | LR(R14) | 0x3C | > + +-------------------+ | > + 0x10 | R12 | 0x38 | State context > + +-------------------+ | > + 0x0C | R3 | 0x34 | > + +-------------------+ | > + ... | > + +-------------------+ | > + 0x00 | R0 | 0x28 | > + +===================+ --+ > + | R11 | 0x24 | > + +-------------------+ | > + ... | > + +-------------------+ | Additional state > + | R4 | 0x08 | context when > + +-------------------+ | transitioning from > + | Reserved | 0x04 | Secure to Non-Secure > + +-------------------+ | > + | Magic signature | 0x00 | > + +===================+ --+ <-- New SP */ > + > + uint32_t sp_r0_offset = 0; > + > + /* With the Security extension, the hardware saves R4..R11 too. */ > + if (tdep->have_sec_ext && secure_stack_used > + && (!default_callee_register_stacking || exception_domain_is_secure)) > + { > + /* Read R4..R11 from the integer callee registers. */ > + cache->saved_regs[4].set_addr (unwound_sp + 0x08); > + cache->saved_regs[5].set_addr (unwound_sp + 0x0C); > + cache->saved_regs[6].set_addr (unwound_sp + 0x10); > + cache->saved_regs[7].set_addr (unwound_sp + 0x14); > + cache->saved_regs[8].set_addr (unwound_sp + 0x18); > + cache->saved_regs[9].set_addr (unwound_sp + 0x1C); > + cache->saved_regs[10].set_addr (unwound_sp + 0x20); > + cache->saved_regs[11].set_addr (unwound_sp + 0x24); > + sp_r0_offset = 0x28; > + } > + > + /* The hardware saves eight 32-bit words, comprising xPSR, > + ReturnAddress, LR (R14), R12, R3, R2, R1, R0. See details in > + "B1.5.6 Exception entry behavior" in > + "ARMv7-M Architecture Reference Manual". */ > + cache->saved_regs[0].set_addr (unwound_sp + sp_r0_offset); > + cache->saved_regs[1].set_addr (unwound_sp + sp_r0_offset + 0x04); > + cache->saved_regs[2].set_addr (unwound_sp + sp_r0_offset + 0x08); > + cache->saved_regs[3].set_addr (unwound_sp + sp_r0_offset + 0x0C); > + cache->saved_regs[ARM_IP_REGNUM].set_addr (unwound_sp + sp_r0_offset > + + 0x10); > + cache->saved_regs[ARM_LR_REGNUM].set_addr (unwound_sp + sp_r0_offset > + + 0x14); > + cache->saved_regs[ARM_PC_REGNUM].set_addr (unwound_sp + sp_r0_offset > + + 0x18); > + cache->saved_regs[ARM_PS_REGNUM].set_addr (unwound_sp + sp_r0_offset > + + 0x1C); > + > + /* Check EXC_RETURN bit FTYPE if extended stack frame (FPU regs stored) > + type used. */ > + bool extended_frame_used = (bit (lr,4) == 0); > + if (extended_frame_used) > + { > + ULONGEST fpccr; > + > + /* Read FPCCR register. */ > + gdb_assert (safe_read_memory_unsigned_integer (FPCCR, > + ARM_INT_REGISTER_SIZE, > + byte_order, &fpccr)); > + bool fpccr_ts = bit (fpccr,26); Space after `,` > + > + /* This code does not take into account the lazy stacking, see "Lazy > + context save of FP state", in B1.5.7, also ARM AN298, supported > + by Cortex-M4F architecture. > + To fully handle this the FPCCR register (Floating-point Context > + Control Register) needs to be read out and the bits ASPEN and > + LSPEN could be checked to setup correct lazy stacked FP registers. > + This register is located at address 0xE000EF34. */ > + > + /* Extended stack frame type used. */ > + CORE_ADDR addr = unwound_sp + sp_r0_offset + 0x20; > + for (int i = 0; i < 8; i++) > + { > + cache->saved_regs[ARM_D0_REGNUM + i].set_addr (addr); > + addr += 8; > + } > + cache->saved_regs[ARM_FPSCR_REGNUM].set_addr (unwound_sp > + + sp_r0_offset + 0x60); > + > + if (tdep->have_sec_ext && !default_callee_register_stacking > + && fpccr_ts) > + { > + /* Handle floating-point callee saved registers. */ > + addr = unwound_sp + sp_r0_offset + 0x68; > + for (int i = 8; i < 16; i++) > + { > + cache->saved_regs[ARM_D0_REGNUM + i].set_addr (addr); > + addr += 8; > + } > > - if (tdep->have_sec_ext && !default_callee_register_stacking && fpccr_ts) > - { > - /* Handle floating-point callee saved registers. */ > - fpu_regs_stack_offset = unwound_sp + sp_r0_offset + 0x68; > - for (i = 8; i < 16; i++) > + arm_cache_set_active_sp_value (cache, tdep, > + unwound_sp + sp_r0_offset + 0xA8); > + } > + else > { > - cache->saved_regs[ARM_D0_REGNUM + i].set_addr (fpu_regs_stack_offset); > - fpu_regs_stack_offset += 8; > + /* Offset 0x64 is reserved. */ > + arm_cache_set_active_sp_value (cache, tdep, > + unwound_sp + sp_r0_offset + 0x68); > } > - > - arm_cache_set_active_sp_value (cache, tdep, > - unwound_sp + sp_r0_offset + 0xA8); > } > else > { > - /* Offset 0x64 is reserved. */ > + /* Standard stack frame type used. */ > arm_cache_set_active_sp_value (cache, tdep, > - unwound_sp + sp_r0_offset + 0x68); > + unwound_sp + sp_r0_offset + 0x20); > } > - } > - else > - { > - /* Standard stack frame type used. */ > - arm_cache_set_active_sp_value (cache, tdep, > - unwound_sp + sp_r0_offset + 0x20); > + > + /* If bit 9 of the saved xPSR is set, then there is a four-byte > + 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 (bit (xpsr,9) != 0) > + { > + CORE_ADDR new_sp = arm_cache_get_prev_sp_value (cache, tdep) + 4; > + arm_cache_set_active_sp_value (cache, tdep, new_sp); > + } > + > + return cache; > } > > - /* If bit 9 of the saved xPSR is set, then there is a four-byte > - aligner between the top of the 32-byte stack frame and the > - previous context's stack pointer. */ > - if (safe_read_memory_integer (unwound_sp + sp_r0_offset + 0x1C, 4, > - byte_order, &xpsr) > - && (xpsr & (1 << 9)) != 0) > - arm_cache_set_active_sp_value (cache, tdep, > - arm_cache_get_prev_sp_value (cache, tdep) + 4); > + error (_("While unwinding an exception frame, found unexpected Link Register " > + "value 0x%lx. This should not happen and may be caused by corrupt " > + "data or a bug in GDB."), lr); Same comment about using %s and phex as opposed to %lx. What does this case have that is different from the previous error? Does it contain an unrecognized LR value? If so, we should mention that explicitly to make it as helpful to the user as possible. > > + /* Terminate any further stack unwinding by referring to self. */ > + arm_cache_set_active_sp_value (cache, tdep, sp); > return cache; This is dead code now. Nothing gets executed after error (). > } >