From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150044.outbound.protection.outlook.com [40.107.15.44]) by sourceware.org (Postfix) with ESMTPS id 8E129385841D for ; Mon, 17 Oct 2022 11:06:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8E129385841D ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=Q/RS+IGtPd65w+85sGioHtXfYv3bBWrFa0h2h1gNgc2zypA/9VAOKjYLKGthQnYGr4XOMSOxC8FGNH/cY7Xp7J2VezM8bLh3SjzkPGWIfAdW9lhyWFTES2q2yrozfvcZDZ82FtKgF4dv1yNw81IAHssj0Rx6H4TAgmgx7E4YXjm2ZSpDfPHVwqR71EaHW+eVy+H5Y/3c5wMarJ8jCrsmWMpJPvq3R2WQmPHTAorvepYLukcrakgmvGbNQv7cvjkGW8bT3oac0CC57j5qochJ9j7cNPwO2q7EIxCaQl4gqP102CGULTv7o+qW8ULKbqCvo/iARDQKbi7n1UZUv7Qh4w== 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=YT+b2wZ1PD7NSjAkDfarzNHLOg2rIs36Vk3qxthkeug=; b=eRDsI2qeWm0B6ZKGKAryY5l/P6woEEc8tL2ivKUk4LTrBvMd84PvDjRbssjl1VXMLroMeTR+302sUdcfq5nlvq4KEKd+/iB2Wl1cWXE5rMyfr0VttZ7eJgdC0mOVTDUkjwhyORJSmFs+vFRkS1h0iYB3PwGFPn5dOF3s90aRCMK2auHtH6NSMmOsrWfLtCnynO6ZblWwh21zAp21ilJ6NUY2vnJk1jPpF5p31eih+kG5U5Nj7OEuMQKaXkwd2yHGsLexWcRC70VIKPFvnPZ+y9mOvQLS2TzfwWXponvCpAL4BFBQ7TDm+h/mSJ34jEWsrs9tG2/ALBFYyoSmWxsKmw== 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 AS9PR04CA0157.eurprd04.prod.outlook.com (2603:10a6:20b:530::29) by AM8PR08MB5649.eurprd08.prod.outlook.com (2603:10a6:20b:1dd::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Mon, 17 Oct 2022 11:06:10 +0000 Received: from VI1EUR03FT048.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:530:cafe::63) by AS9PR04CA0157.outlook.office365.com (2603:10a6:20b:530::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.29 via Frontend Transport; Mon, 17 Oct 2022 11:06:10 +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 VI1EUR03FT048.mail.protection.outlook.com (100.127.144.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.10 via Frontend Transport; Mon, 17 Oct 2022 11:06:10 +0000 Received: ("Tessian outbound b4aebcc5bc64:v130"); Mon, 17 Oct 2022 11:06:10 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2bdd64d13f83e9b1 X-CR-MTA-TID: 64aa7808 Received: from 19eb09b0aedb.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 27CEA5B7-3248-4458-80CC-2A8D65CB2F5E.1; Mon, 17 Oct 2022 11:06:02 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 19eb09b0aedb.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 17 Oct 2022 11:06:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZOPux5yvNyi+/cH43gjSs0pWD8Efwt8YrkwR00JLuuR+4xrJoVmiktsuehY3hUH+DfNQzurSXLD6d/+e8szjhN0oeDAUSB5svzMAANx8tvbPqdqyZOHWggNjpFWWrsh1ADoqSg5fixqwHgHhcm5yE3ScmldZ8d+dG2j15TN0KFTKBR4izTz4po80r5HZ2Gnt8m9swnFHeJB64/MqiS75corfPcz3goMOzY5sgrWm/LZYGmtkTa4TfwvQnuigDVZMbV4jW3TX6BRXD/qLpgcORGCx8vb32qaRcouPekmXiszRLJUlYiXIWysOqgL26bnw9FCjqar62E67lctBg8DQkg== 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=YT+b2wZ1PD7NSjAkDfarzNHLOg2rIs36Vk3qxthkeug=; b=EQSxKjZ8esam182IjCayRJVqlr27fB5g67bGTiBHw9WodM7w2iNX9KTfqLLPIH1/8zqYZjaIn2iorB4rwUC4gydyPDotjWQVgUIWGAt76UrSuAEDE7pGAaAWasT6eoBBuYhn74H0yutA6eLhL1fXVavmHOkEQImyHs0qaIl1vMEtdlNV4AQe81FXqbjnLm5zRIwbHZjqJ9Ru8ckJzdDO4uTBXknvWfkwt8JLQLJ1pw/AfF+qnLvGgGbohQgZma58eVLSHFYK7kW2U36BwYO3RxJZyLLbnoiP50n8gAXqw1j16FR/3y8ZWiZqV4ltVKNV0NnmOOM+ir8atJoGnrrEMA== 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 AS8PR08MB6279.eurprd08.prod.outlook.com (2603:10a6:20b:294::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Mon, 17 Oct 2022 11:05:59 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::7f57:1601:9b18:7529]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::7f57:1601:9b18:7529%7]) with mapi id 15.20.5723.033; Mon, 17 Oct 2022 11:05:59 +0000 Message-ID: <615642c8-920c-fc1d-b5d9-0c5e480da94f@arm.com> Date: Mon, 17 Oct 2022 12:06:00 +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: Terminate frame unwinding in M-profile lockup state Content-Language: en-US To: Tomas Vanek , gdb-patches@sourceware.org References: From: Luis Machado In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: LO6P123CA0004.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:338::11) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|AS8PR08MB6279:EE_|VI1EUR03FT048:EE_|AM8PR08MB5649:EE_ X-MS-Office365-Filtering-Correlation-Id: 88f30069-d716-41f5-8cda-08dab02f9923 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: uJDyku0Gi6p482vLtkzKrtJf1fcLaZae2A+VBPcpk7aHneeyiPZJ+ynoMfPIqdfe1z4dknZroWL7agQbcQgjxpOEFyB4h8/kg8KzMDaeXpF/bXfQvIecJEnTLyaXthsDNc/NHyRQMrGBIwyU1bLX/er5RXRx3QkTtoCiryQyFq4V++LGxZXpW5mFDNEvg0lySm77wSSZk1/LyKaHgn51FIFzq2pyOTzOqRTPtnbMgWnU43cDNGeT2M/dBen5l+UJSVU5Vs583KIqM04Il4Kd8wlHeJ6VZqkabvIuXwfiA6E95vsxmglgXiJ+p3vU3UegvrosgXcp4CCnwjJ3+H1R/s3hohFECQtwiqe+b32P0bcJxSbS2QoAPf0jZEcL5FrEEX9BPe5zaiT28ldYRJb7K27epSAbTNfRvAfJtfH7arXiSe4OAujjDYFMQT3BL/VV2Z0hrjZyrt34MFxZtvwnZs0hTea0Yg0hLmcJYe7B+jvc239lWiaN+RvChNNyxfj+ZVOjmSJi0y1nA6DZ9HQof+4Wmc/pK/udOl9tcgNcWKSBCrWiFO+GIwvvuCH0+nZmNOPGTjgX2wblTL2Q1RNfYnRh1vW8/3oVF8sE0PGNIkqkAqwGfu6/7rkNkUurZ8pwk6DgEZoQWagYe5TiyU8GuwQr/TuS6TMnDeowp1j3U48e096G142ndSKhoE7UiS5UaYspC+MKbYF47fM/Ny0P552JXy/U8RKNMvUl72jLJu+H6nPb0o5tc6fn2c/hanxUdWsfkwilUCaGqL3VwiJrZU7kLa+tPpqLgTeEW5HYtFU= 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:(13230022)(4636009)(376002)(346002)(39860400002)(366004)(396003)(136003)(451199015)(66556008)(66476007)(66946007)(8676002)(6666004)(316002)(2616005)(186003)(2906002)(44832011)(86362001)(83380400001)(66574015)(31696002)(53546011)(26005)(41300700001)(6506007)(36756003)(5660300002)(6512007)(8936002)(31686004)(6486002)(478600001)(38100700002)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6279 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: VI1EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 4e076d07-3f4c-42b9-6034-08dab02f926d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o0I4u98Zu+r8MtP8tMuisc4E0Qbs79Z1JXBZx4l0jof76WFX+S27pRWU7q1wBCdk1RBCPz2eA4s1kSlRmCQeQCKx6hyaZ7ReVYCADsWwU0hzRit1MmKO26bDj5DJNwgy8iMUf2Swv8yMZaMIkTEGdJL0GblPa9bYwdwVvLkclr0kj12xID3iidxerz9AxzL4mhbdDTTx+P7SztGZJtd8cE2Eu5lGH5YiWFFaRMuZfrVUTW9wRH99gdITMAOucla7NgrLb5ymsoih6IZAgkR/0R1ddM/swFrxUHnRtzgG0W3p7ECV8c++OO5oB5uuzeNjuj4WmqG4nE6InjoMYMJSvAg+/cCXfLXSEDv6DGtEr2Sz9yQgcxGhWoWZlq0As6btih51yx/gWyadlpuHUcluxqV8ihcE0m1ZC6mBesOGcz1vBvDdECNxQy1h2ZAP2Drzpr20HpO6CExSHTAc3fu8/tes416aGQxWy+6iW/nvtr5dA+GGcCH+Y5kWc5G176p9hAzDSHq0S53GZI4FSse/EsENsemSoF86wBdgJTTi0gptaIxDomipG7ckAMDXU/fKDrZu3XReCfvt+DwZWal6524meQ/4w7G6odvf7V/hGxGCJxTZ0AAK9u4BfsVjtixrczn5R5fCt8jbzSdAlNf996fxgKdLaBTajU3EaHSbHfLGSiEmy46G7UB/LEOqUl8TtDccgQ8T5W3GEPKIvn9+EWE/yBIfYeagc/YMijVoVbQGppjYJXrOzSYynu/4VlrL485KdjwhU9Y//rPgQN9IqA== 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:(13230022)(4636009)(136003)(396003)(346002)(39860400002)(376002)(451199015)(46966006)(36840700001)(66574015)(47076005)(82310400005)(82740400003)(81166007)(356005)(36756003)(40480700001)(86362001)(31696002)(36860700001)(83380400001)(6666004)(70586007)(70206006)(316002)(31686004)(8676002)(44832011)(5660300002)(6486002)(186003)(2906002)(336012)(8936002)(2616005)(6506007)(41300700001)(478600001)(26005)(53546011)(6512007)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 11:06:10.4135 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88f30069-d716-41f5-8cda-08dab02f9923 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: VI1EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5649 X-Spam-Status: No, score=-10.9 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, 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: Mon, 17 Oct 2022 11:06:16 -0000 Hi, Just some general comments on the formatting. On 10/16/22 15:13, Tomas Vanek wrote: > In the lockup state the PC value of the the outer frame is irreversibly > lost. The other registers are intact so LR likely contains > PC of some frame next to the outer one, but we cannot analyze > the nearest outer frame without knowing its PC > therefore we do not know SP fixup for this frame. > > The frame unwinder possibly gets mad due to the wrong SP value. > To prevent problems terminate unwinding if PC contains the magic > value of the lockup state. > > Example session wihtout this change, > Cortex-M33 CPU in lockup, gdb 13.0.50.20221016-git: > ---------------- >   (gdb) c >   Continuing. > >   Program received signal SIGINT, Interrupt. >   0xeffffffe in ?? () >   (gdb) bt >   #0  0xeffffffe in ?? () >   #1  0x0c000a9c in HardFault_Handler () >       at C:/dvl/stm32l5trustzone/GPIO_IOToggle_TrustZone/Secure/Src/stm32l5xx_it.c:99 >   #2  0x2002ffd8 in ?? () >   Backtrace stopped: previous frame identical to this frame (corrupt stack?) >   (gdb) > ---------------- > The frame #1 is at correct PC taken from LR, #2 is a total nonsense. > > With the change: > ---------------- >   (gdb) c >   Continuing. > >   Program received signal SIGINT, Interrupt. >   warning: ARM M in lockup state, stack unwinding terminated. >   >   (gdb) bt >   #0  >   (gdb) > ---------------- > > There is a visible drawback of emitting a warning in a cache buildnig routine > as introduced in Torbjörn SVENSSON's True. We might need to move it somewhere else. Though it is not something we will have to repeat over and over. There is also the issue of communicating these warnings in a better way through the MI to IDE's. > [PATCH v4] gdb/arm: Stop unwinding on error, but do not assert > The warning is printed just once and not repeated on each backtrace command. > > V2 update: warning supressed for other frames than the innermost one. > > Signed-off-by: Tomas Vanek > --- >  gdb/arm-tdep.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- >  1 file changed, 52 insertions(+), 3 deletions(-) > > diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c > index b5facae..3fd4f0c 100644 > --- a/gdb/arm-tdep.c > +++ b/gdb/arm-tdep.c > @@ -724,9 +724,30 @@ class target_arm_instruction_reader : public arm_instruction_reader >    return 0; >  } > > +static inline bool > +arm_m_addr_is_lockup (CORE_ADDR addr) > +{ > +  switch (addr) > +    { > +      /* Values for Lockup state. > +     For more details see "B1.5.15 Unrecoverable exception cases" in > +     both ARMv6-M and ARMv7-M Architecture Reference Manuals, or > +     see "B4.32 Lockup" in ARMv8-M Architecture Reference Manual. */ > +      case 0xeffffffe: > +      case 0xfffffffe: > +      case 0xffffffff: > +    return 1; 1 -> true. > + > +      default: > +    /* Address is not magic.  */ > +    return 0; 0 -> false. > +    } > +} > + >  /* Determine if the address specified equals any of these magic return >     values, called EXC_RETURN, defined by the ARM v6-M, v7-M and v8-M > -   architectures. > +   architectures. Also include lockup magic PC value. > +   Check also for FNC_RETURN if we have v8-M security extension. > >     From ARMv6-M Reference Manual B1.5.8 >     Table B1-5 Exception return behavior > @@ -769,6 +790,9 @@ class target_arm_instruction_reader : public arm_instruction_reader >  static int >  arm_m_addr_is_magic (struct gdbarch *gdbarch, CORE_ADDR addr) >  { > +  if (arm_m_addr_is_lockup (addr)) > +    return 1; > + >    arm_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); >    if (tdep->have_sec_ext) >      { > @@ -3355,6 +3379,30 @@ struct frame_unwind arm_stub_unwind = { >       describes which bits in LR that define which stack was used prior >       to the exception and if FPU is used (causing extended stack frame).  */ > > +  /* In the lockup state PC contains a lockup magic value. > +     The PC value of the the next outer frame is irreversibly > +     lost. The other registers are intact so LR likely contains > +     PC of some frame next to the outer one, but we cannot analyze > +     the next outer frame without knowing its PC > +     therefore we do not know SP fixup for this frame. > +     Some heuristics to resynchronize SP might be possible (TODO?) Stating a heuristic is possible should be enough. We avoid adding TODO's. > +     For simplicity just terminate unwinding to prevent the unwinder > +     going mad.  */ > +  CORE_ADDR pc = get_frame_pc (this_frame); > +  if (arm_m_addr_is_lockup (pc)) > +    { > +      /* The lockup can be real just in the innermost frame > +     as the CPU is stopped and cannot create more frames. > +     If we hit lockup magic PC in the other frame, it is > +     just a sentinel at the top of stack: do not warn then.  */ > +      if (frame_relative_level (this_frame) == 0) > +    warning (_("ARM M in lockup state, stack unwinding terminated.")); > + > +      /* Terminate any further stack unwinding.  */ > +      arm_cache_set_active_sp_value (cache, tdep, 0); > +      return cache; > +    } > + >    CORE_ADDR lr = get_frame_register_unsigned (this_frame, ARM_LR_REGNUM); > >    /* ARMv7-M Architecture Reference "A2.3.1 Arm core registers" > @@ -3824,11 +3872,12 @@ struct frame_unwind arm_stub_unwind = { >    return arm_m_addr_is_magic (gdbarch, this_pc); >  } > > -/* Frame unwinder for M-profile exceptions.  */ > +/* Frame unwinder for M-profile exceptions, lockup > +   and secure/nonsecure interstate fnc calls.  */ fnc -> function? > >  struct frame_unwind arm_m_exception_unwind = >  { > -  "arm m exception", > +  "arm m exception lockup sec_fnc", >    SIGTRAMP_FRAME, >    arm_m_exception_frame_unwind_stop_reason, >    arm_m_exception_this_id,