From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80078.outbound.protection.outlook.com [40.107.8.78]) by sourceware.org (Postfix) with ESMTPS id 9B6B4384D16E for ; Wed, 15 Jun 2022 10:15:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B6B4384D16E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=QeqU8dp9dljj+t1zxAsC05I0ORkA8FPVDq/pQRj+z/Mn7utdGm8+RBsY4Tj2eMMYz3BojIN7dll04iSJuGUCWFbVK07HQEEIB/DWlI7CUXZkmAXQXCX/RyPOUlv19/EHbIK/G7I2WyxT3cyO6BGPiNN54ObsQ5qSMd+V9u44viQmj1JgSxIlgbbS/7Xl2G0DE0pLLpf8pdm6b+7XoA4h/5EcZQ0vAOmA7fwIXLCbBC8HcWNn36EhJdNpJIqYkdY/3OTKWCGKRkAf6sDCnCeThtSKaa7LhfNCnyWA96eAtaHESl+kLbiXmlT7VmjahJB3TSPqQq7Q4aklL0BV9P1dRQ== 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=aKmrt2wll4QJXxPlI+c2DvChAE7W+Ttx5yUgN4sTUtc=; b=WOxY9Fm2qFZGjnEwZd6J3+FJqqBWQrRtv3W3SXkPNeF+JMN+Gyz3trAHCwVItN20fhnEu0wm3zHtD1XuDtF5Z32wzn4SxQ8SWwFjMY1NMPPsxs81Wr+TwUJna40bRfPpXjdoZuZ8+Lt925xjKa+DPETvEA+A1MWNq2Ep/I9lW/r2DKI3rWAiuk+eryx7B5oJ3B6pXtZXmpGsn2jJYNIT+Nium6b0hjISwvM5Nk1yof0vbC4ff/zIWY3iQex5i0omPs9vbXk94ZwOulLQtKitd1G5YdogSvceAgUfE6mjtgECjASbsxBshCfrFNl4LYTILPj8l+dkuiBrT5gyYwrlFA== 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 DB6PR1001CA0008.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:b7::18) by DBBPR08MB4806.eurprd08.prod.outlook.com (2603:10a6:10:db::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.16; Wed, 15 Jun 2022 10:15:36 +0000 Received: from DBAEUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:b7:cafe::4f) by DB6PR1001CA0008.outlook.office365.com (2603:10a6:4:b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.14 via Frontend Transport; Wed, 15 Jun 2022 10:15:36 +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 DBAEUR03FT033.mail.protection.outlook.com (100.127.142.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.14 via Frontend Transport; Wed, 15 Jun 2022 10:15:36 +0000 Received: ("Tessian outbound 6f53897bcd4e:v120"); Wed, 15 Jun 2022 10:15:36 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 92996778c1fadd51 X-CR-MTA-TID: 64aa7808 Received: from 8f4be3d6a672.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DB4C053A-9BD4-4190-AA94-C2A5EA4CBB1C.1; Wed, 15 Jun 2022 10:15:29 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 8f4be3d6a672.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 15 Jun 2022 10:15:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZypHJmpoMJVEzIVStCo7T8oK08Mt5tVb8iAQ3sgVFdg7JmIh/Pr4XN+JTLDAwDIMqVY9sAgiTnvolwPRftP6zthj1zV6WGW7R/zhKrGcxIRVKC6BQEsIlVfHCUaDDyx8OPHFWYweVdtM2bxcB1z6gvvMIih7R0Qj2HfAMhmnXN+aqzvIKMpx5PV6uFylkjzhKxZprUUzCbJMrNEwGLsAuHFBeADSOPj+eaiFgNEztLteGs9lnx+iN6H94XWBN1XzxT/iCYE6YoXJMMhOUcgYhBCqFQTCZqa5+QEpmhFxHHj+g2D1K797Lsu7F/2JjUPSXK5CO1DbeMz4rN8U2VG0tQ== 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=aKmrt2wll4QJXxPlI+c2DvChAE7W+Ttx5yUgN4sTUtc=; b=YjjCygdY+tI0ljviDAxlMz1WaGno8A9ldbLSGM8LWMg7+I5qZx4GEBBTM4ZyDXhuvTuuhvfiUewdVwsb5sEK7hZP1FlW5BtWODe+QTUYoFZEZ2hFBjR2o4+tCM1fr3hhFu4fs1cOq0yj9NVq8DxlvUuBNXGug/REy9faEUOyca1abe2WMx/NbXMu5Kuqxf6HQ+gR8b7Ifmys5o7ziHnWpXLrS67JGdS1OwDigw86xg1PaixFot2EqwEeFj43H7wIMgeGJkuMNKjgobaCEj2Iw9j4soHZQKYX+Q+YVqsM8PlRzEM7X8jTMwNaoPRD9Z2HCIM4CDyCO+/Kg2tCpt/u4g== 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 DB8PR08MB5017.eurprd08.prod.outlook.com (2603:10a6:10:ef::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.15; Wed, 15 Jun 2022 10:15:27 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::d9c0:539c:a641:5735]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::d9c0:539c:a641:5735%2]) with mapi id 15.20.5332.022; Wed, 15 Jun 2022 10:15:27 +0000 Message-ID: Date: Wed, 15 Jun 2022 11:15:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 2/3] gdb/arm: Track msp and psp Content-Language: en-US To: Torbjorn SVENSSON , Yvan Roux , gdb-patches@sourceware.org References: <20220614145606.GB12000@gnbcxd0114.gnb.st.com> <20220614150032.GD12000@gnbcxd0114.gnb.st.com> <65771da9-0ff9-170c-f682-337ae0296884@arm.com> <20220615092819.GB26132@gnbcxd0114.gnb.st.com> <296a457a-9c4e-b900-86b5-13a8171a72ed@foss.st.com> From: Luis Machado In-Reply-To: <296a457a-9c4e-b900-86b5-13a8171a72ed@foss.st.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: LO2P265CA0255.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8a::27) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: d8193a15-4813-4cfa-7c67-08da4eb7fd9a X-MS-TrafficTypeDiagnostic: DB8PR08MB5017:EE_|DBAEUR03FT033:EE_|DBBPR08MB4806:EE_ X-Microsoft-Antispam-PRVS: 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: tgo/nMkjB4NYvU+gZoXouB35uTIg+iS+SXh/zR8FAbvOcys3OJgmYuivYGVpOZAtI3toV5fiyJyEgJ1ewAI+ZCir5cEy/BqiOGm4aPlSa/tfgo+4sUjeqEk48Y+BST2+MTEaPonjJhEl2lkdqGDqRTkikdWsAb2i6jFhrlRVndCym/k4l/uKDPY01Ooz/vwUccjsfEfD0bsetlIB6VEVihnHUgCOoqXSkkki4oesCSNSUdP/jedgKA3strOtzxNz5ZGYemY9j3tu2UNT9ChQxGnHY7vjIw8Zli7PwIBJvguICYLpBfw+UIwdoCIUPMLQxPzHx/zVWaDDb5VGNLmhUdRngRQ/elXI7vXBsYmdSEchYC6rlKujy3IJ72lTMYJwwPeHLclYzyvkbC/NdiMhlCPGrd/G/nNa2d8TUIhohto3EnwfRR4Xx3VcOFp0ncfThdh7qD/zMX106NQQXzU8CoTLjgKWbQ6GkDEiXPb1xAFmBLGj6FgrUGzUiq5H1MAPE402lzAotS9Zm+QbI/3ltq/v/BtqhgKWa0nygpDBAv4igUGbLhEpcAHtRfJAs5VyB6bFkhwQwCd6RgsmzxrpA+8qcX0c+19ZTRuFpojiJK4f5v6rlXyZutcgZcqdPCmWgV9vPVCNGjwpUMF1kdaxthjAX5W0yBxlwl1Tl6Otrjkh1+rezypy+nd5iwivaMRIA9VsYIAYJN01FvST/2UaR4JMDbtz1TJ9OSBIKO9WUfZKGYd3Z3mJAnLdsLBDFI5ndJ1aRp16nf7q73WlEG5qMZjrJcZ0krvT3xlUJKCAK96pVBma8fYCXpi3lDV0Gu/8 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)(186003)(31696002)(316002)(36756003)(2616005)(44832011)(38100700002)(5660300002)(8936002)(83380400001)(66556008)(110136005)(8676002)(2906002)(508600001)(6486002)(966005)(66946007)(26005)(6506007)(66476007)(6512007)(53546011)(31686004)(86362001)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5017 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: DBAEUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 5f985d81-afdf-479d-6319-08da4eb7f7c6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9bf9wwBajDVyfYPt7qgUpVu/FD4M1VRLMHlKdlfpR7vzXGogeK/kyiGd4xK/R8nGqVE8DFkoBUINvVFVX/BM48f/OllP1Pj1Hx95k1RxzTg6S9UZAXGxLufitE66uSDa6gZSJ/+mPWxHDREb9uSG+fLo+i3kUTznsy0PvdnvlRJp8cC9pP1UOlWio9kWvEGiCD1mTBbPt+zuOAtEz1YMHNe4O8bR8GvBim5nS9iMWLBdpgCL+55dEiRVFnngUaoSPhGcsTVjjTVulEnvkb4ehEP/C8LpuNU3PKaPiYauhcljHB5amFXqn3z4r1HEZRQw86+CZcrnjuNLudjCX5YWU51FEz9JBUh6hZwQ1/mq7Re77F+vYIlbeceUt+qMzrwEm9Z4gvbRATlH66gf0/boSffZQyunGpC+gwo3ecoSuhCc/pkAP1CVIhQ27/tAhR8kW1SFV3vCTNfPsXlhQVl05whxwfZPLXpvCklBKA4x7lbh3JLhCR0K9cL+SoNkTbNjtk0hx0ycGHj3+s5Ko9ZZQ40tHVR8dxDY1WTC2fwKFS38LSJd2p2eH4QKkVEBPf11ExTTh87VrgnUaU2GBWOW3z+gm4PO0ssZ5JFdOLjKva21mZVgT+3PGwyWR2uYOgAH3WhsGE06Qz2tWZzwezfTQW6ehvWuPCjUJEaOCARD6KVh0VPmpjNAeh8gPIpST3tbxsJAa6lH0fCpyqv57mIaFcWBaDSs6GUktLNdsPX4TXVF1zZDmgt95oREa/T58Z3Da21rAgPXri0XnVZp27mWpPi7GhyOCsJ4Bj/ZzR4bAQTQf7DWu988/ahq42rtKDfMUdsSk3Vq9EeOV0jADWi8Iw== 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)(46966006)(40470700004)(36840700001)(508600001)(966005)(82310400005)(2906002)(6486002)(81166007)(8676002)(110136005)(26005)(53546011)(44832011)(40460700003)(70586007)(86362001)(31686004)(6506007)(6512007)(70206006)(36860700001)(36756003)(356005)(316002)(31696002)(186003)(336012)(2616005)(5660300002)(8936002)(47076005)(83380400001)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2022 10:15:36.6931 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8193a15-4813-4cfa-7c67-08da4eb7fd9a 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: DBAEUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4806 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, BODY_8BITS, 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: Wed, 15 Jun 2022 10:15:43 -0000 On 6/15/22 10:46, Torbjorn SVENSSON wrote: > > > On 2022-06-15 11:28, Yvan Roux wrote: >> On Wed, Jun 15, 2022 at 09:57:22AM +0100, Luis Machado wrote: >>> On 6/14/22 16:00, Yvan Roux wrote: >>>> For Arm Cortex-M33 with security extensions, there are 4 different >>>> stack pointers (msp_s, msp_ns, psp_s, psp_ns).  To be compatible >>>> with earlier Cortex-M derivates, the msp and psp registers are >>>> aliases for one of the 4 real stack pointer registers. >>>> >>>> These are the combinations that exist: >>>> sp -> msp -> msp_s >>>> sp -> msp -> msp_ns >>>> sp -> psp -> psp_s >>>> sp -> psp -> psp_ns >>>> >>>> This means that when the GDB client is to show the value of "msp", >>>> the value should always be equal to either "msp_s" or "msp_ns". >>>> Same goes for "psp". >>>> >>>> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29121 >>>> >>>> Signed-off-by: Torbj�rn SVENSSON >>>> Signed-off-by: Yvan Roux >>>> --- >>>>    gdb/arm-tdep.c | 18 ++++++++++++++++++ >>>>    1 file changed, 18 insertions(+) >>>> >>>> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c >>>> index 1df57f5b5c8..e497dd1b3b8 100644 >>>> --- a/gdb/arm-tdep.c >>>> +++ b/gdb/arm-tdep.c >>>> @@ -288,6 +288,8 @@ struct arm_prologue_cache >>>>      /* Active stack pointer.  */ >>>>      int active_sp_regnum; >>>> +  int active_msp_regnum; >>>> +  int active_psp_regnum; >>>>      /* The frame base for this frame is just prev_sp - frame size. >>>>         FRAMESIZE is the distance from the frame pointer to the >>>> @@ -345,11 +347,23 @@ arm_cache_init (struct arm_prologue_cache *cache, struct frame_info *frame) >>>>      if (tdep->have_sec_ext) >>>>        { >>>> +      CORE_ADDR msp_val = get_frame_register_unsigned (frame, tdep->m_profile_msp_regnum); >>>> +      CORE_ADDR psp_val = get_frame_register_unsigned (frame, tdep->m_profile_psp_regnum); >>>> + >>>>          arm_cache_init_sp (tdep->m_profile_msp_s_regnum, &cache->msp_s, cache, frame); >>>>          arm_cache_init_sp (tdep->m_profile_psp_s_regnum, &cache->psp_s, cache, frame); >>>>          arm_cache_init_sp (tdep->m_profile_msp_ns_regnum, &cache->msp_ns, cache, frame); >>>>          arm_cache_init_sp (tdep->m_profile_psp_ns_regnum, &cache->psp_ns, cache, frame); >>>> +      if (msp_val == cache->msp_s) >>>> +    cache->active_msp_regnum = tdep->m_profile_msp_s_regnum; >>>> +      else if (msp_val == cache->msp_ns) >>>> +    cache->active_msp_regnum = tdep->m_profile_msp_ns_regnum; >>>> +      if (psp_val == cache->psp_s) >>>> +    cache->active_psp_regnum = tdep->m_profile_psp_s_regnum; >>>> +      else if (psp_val == cache->psp_ns) >>>> +    cache->active_psp_regnum = tdep->m_profile_psp_ns_regnum; >>>> + >>>>          /* Use MSP_S as default stack pointer.  */ >>>>          if (cache->active_sp_regnum == ARM_SP_REGNUM) >>>>          cache->active_sp_regnum = tdep->m_profile_msp_s_regnum; >>>> @@ -384,6 +398,10 @@ arm_cache_get_sp_register (struct arm_prologue_cache *cache, >>>>        return cache->psp_s; >>>>          if (regnum == tdep->m_profile_psp_ns_regnum) >>>>        return cache->psp_ns; >>>> +      if (regnum == tdep->m_profile_msp_regnum) >>>> +    return arm_cache_get_sp_register (cache, tdep, cache->active_msp_regnum); >>>> +      if (regnum == tdep->m_profile_psp_regnum) >>>> +    return arm_cache_get_sp_register (cache, tdep, cache->active_psp_regnum); >>>>        } >>>>      else if (tdep->is_m) >>>>        { >>> >>> Just so I understand this correctly, the problem is that we're not keeping the aliases in sync >>> all the time, so sp/msp/psp and the 4 other registers are going out-of-sync. >>> >>> Also, although SP will be either msp or psp, we can have distinct and valid msp/psp values, right? >> >> Yes that's it, it the info provided by Torbjorn in the BZ, we can see: >> >> #2  >> info r >> ... >> sp             0x30017f30          0x30017f30 >> ... >> msp            0x30017f18          0x30017f18 >> psp            0x0                 0x0 >> msp_ns         0x2002ffd8          0x2002ffd8 >> psp_ns         0xfffffffc          0xfffffffc >> msp_s          0x30017f18          0x30017f18 >> psp_s          0x0                 0x0 >> >> where msp is in sync with msp_s and psp with psp_s but SP value is different >> > > To add a bit more context; GDB does not really use the register msp (or psp) internally, but they are part of the set of registers that are provided by the target.xml file. As a result, they will be part of the set of registers that is printed using the "info r" command. > Without this particular patch, GDB will hit the assert in the bottom of the arm_cache_get_sp_register function. Thanks for the explanation. Yvan, would you please add this to the commit message as well? Otherwise, this series is OK.