From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2057.outbound.protection.outlook.com [40.107.7.57]) by sourceware.org (Postfix) with ESMTPS id B8B623858C2A for ; Wed, 29 Nov 2023 11:44:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8B623858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B8B623858C2A Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.7.57 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1701258299; cv=pass; b=pvmyifxfTcO5IP4Ts/xnhcKs27orQ6/UD+jT9qtjjDw+ZZQ7jxcJnOPNmanon+CUxCJSWn9v05KQi5VosmWOkJPdxR2J/c6v58MiC+bjgOsJbnYTXyQOuyxzIrTtwkTPmp7A4OkVVrTrQRkTEUj4+9FcGu3IfsYYArOlwJgUHhU= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1701258299; c=relaxed/simple; bh=nIWZetET17mcveUFoSL2cfnXgr0W6kuXH3curd3bk1Q=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=nIhkFNe5pJ1tKyAc72PmSYsf+X0HvnUZLHBaUBmPdmlFgSEe6S30NmE7zhwNLoosMEalJw23IFm9ApCd1vV1Z/XWTtdRukG51Vf37Iz8H2AzltULxXQeBXDABKO4dv/NcyiFOFtiQ/rHvFQ8RXbOSUFPO0E6iB23XqxPzzmdZeo= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=SBU0SL1isvwA9rQwkoMa2p/JEFhtM9MMXye6o93+DrqSHQtSEns5aIz0jBpGn3NbF91mGFwdiqsnpKaj9ZMJquEZyDqWCpZwiMmCcrZVCfVStbY5eDp8BO2YA7nDDaOIjJS8Ewwy8fapltXtc2W/KMmU3UJX9NOzUlVMw6MS+sU1Lnbtf9YTsILoX4moStT5L7K243Y5QRa9ha/vGR7GtPOoXgpYQDsLznKKMz9mBuUrTBSBe1JK9HiT37eG157YfjjlxYvJy/xWbUjOq7+axW4cqnd22EdqiG2We5wsEQU9PYzC0gMWCeTdPeYmW8tjnl1UT2/x33iru3oQW4+Lsw== 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=dyfcWUKzwGIE1/Pt+niGOYZo6NGZrW2Noe3blVE3nQ4=; b=P2HGWJhNzaa6jEVXEjrTu5pzrbnkvJM1gI1We8RHwtMmtClU3TqwR8z/tWVvx7YKB4EJntK9Jz1XO0bgol8HOJe7Y/dbSt8Ezant2XBhN5e4RC7bhiOtY/YXCog5cY527vnp495g7PNRw0Tc8EWBJlCU9mwJn6G1gKssMpuaqLZMr/R3efyaI3l66VUKlYY5h2TZE7Ng/uInU9+Lsq5uqapYKwxR60r9N9YQBDykQ/nsefXO4KSEMSZa9S0Gn1vZCSHw5A9NTIJb9p3OMXtb/pmmx9N+q5MSgM2fmZPb+keGG8/rMiLSpNzEgmuYx3cqO109xu57lAuj+ouAT8QS1g== 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]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dyfcWUKzwGIE1/Pt+niGOYZo6NGZrW2Noe3blVE3nQ4=; b=iceadMEo5d41QFeJUMmTyL9wwSf925gk/+XTx30ZrzzMGJbzzzeI8uvEABQfg8VNnxCuKspVZiugtuN+T+jJ8YDr7/zCbrxAt6qI3mnUBQcqWlALsCZ/2yxnh/m5in3JVbjoVyENepprN7bAvQ8oQ+qnhJq/SwmNKkzbu26ZHNo= Received: from AM8P190CA0006.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:219::11) by AS2PR08MB8363.eurprd08.prod.outlook.com (2603:10a6:20b:546::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.28; Wed, 29 Nov 2023 11:44:52 +0000 Received: from AM4PEPF00027A66.eurprd04.prod.outlook.com (2603:10a6:20b:219:cafe::71) by AM8P190CA0006.outlook.office365.com (2603:10a6:20b:219::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.29 via Frontend Transport; Wed, 29 Nov 2023 11:44:52 +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 AM4PEPF00027A66.mail.protection.outlook.com (10.167.16.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.17 via Frontend Transport; Wed, 29 Nov 2023 11:44:51 +0000 Received: ("Tessian outbound 20615a7e7970:v228"); Wed, 29 Nov 2023 11:44:51 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d336a2392a22a1d6 X-CR-MTA-TID: 64aa7808 Received: from d90aeff072c5.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2F2ABD50-1556-44E4-BAE0-4E0ACD9B4DC2.1; Wed, 29 Nov 2023 11:44:44 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d90aeff072c5.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 29 Nov 2023 11:44:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YhYfufRktk0tZ72F9ZB3yFR92n/ltU4FurQ7J/c2WxfnHxAKgfOqyDRffRDayTb4pTtPLyAxbHY+XvliikWPMXMVo+CXpyKar+uVPN2FrcVAf5KLQAUUOc0m5SlSavBo2DfsVMYAhhcXaSlMn4hNYsTZh1Gn1TbRJFhFgYUQns0oJk7Z5N0btcaLxWIiW0I5Ae8pYSlfuvEB/dkQfKhs75pBDwv63D3pdU7542oS0EyEXx6IpWsK/eBSS5pVWWmDMdyjoNJ5EgPA4ndffIBiYNIugydy0CF2vtw7G26heqAci9+G0k05IbIiVydoNvx3NxHKdHAWgq2mKEIFozQvDw== 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=dyfcWUKzwGIE1/Pt+niGOYZo6NGZrW2Noe3blVE3nQ4=; b=QUTPOcrBuOuZlMhrt5YCqmJxDGYWFZh9+NtyzI3TkErKKJtEP3ROeM/SGNbd22m8Vgo0YsO84qVoWJHKo5RwIUj341yUJvmRXPSbtmdDbTVpWJxhD71/7VeEz3+vlRe5517ZUGwI2qnCjo28cutI+Gp+EPnxNei8y1uoYW80ipvxbnVScw+F2IWR4HGBK4jNuNfyYXySfCeymRtSjo+z5KEQQYuY3rGTnM8VlfpbQ3nGNOEcOTXINr9IzN9++NnXqXUMQa8NSoxTQbtdVClcgeIJUrnKN5wdknWR1RfOTy9QUTzFb20V3mo428vTSb2xK+ObqMB2/uvB70tZxRCR+Q== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dyfcWUKzwGIE1/Pt+niGOYZo6NGZrW2Noe3blVE3nQ4=; b=iceadMEo5d41QFeJUMmTyL9wwSf925gk/+XTx30ZrzzMGJbzzzeI8uvEABQfg8VNnxCuKspVZiugtuN+T+jJ8YDr7/zCbrxAt6qI3mnUBQcqWlALsCZ/2yxnh/m5in3JVbjoVyENepprN7bAvQ8oQ+qnhJq/SwmNKkzbu26ZHNo= 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 AS8PR08MB9575.eurprd08.prod.outlook.com (2603:10a6:20b:619::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.28; Wed, 29 Nov 2023 11:44:40 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::e05e:c012:f1f9:eb51]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::e05e:c012:f1f9:eb51%4]) with mapi id 15.20.7046.015; Wed, 29 Nov 2023 11:44:40 +0000 Message-ID: Date: Wed, 29 Nov 2023 11:44:38 +0000 User-Agent: Mozilla Thunderbird Subject: Re: [ PATCH 2/3] Fix GDB reverse execution behavior Content-Language: en-US To: Carl Love , blarsen@redhat.com, Ulrich Weigand , gdb-patches@sourceware.org Cc: Pedro Alves , Tom Tromey , Simon Marchi References: <890101c23dd5fa60fcbf9d4b299cb2a533c260b7.camel@linux.ibm.com> <1e702d8f-e5b4-4719-b1e7-42210f350305@arm.com> <643afce1-ab9b-4e8b-bcbb-5738dc409a28@arm.com> <9e17008084c34f953f5318933436ec703250120a.camel@linux.ibm.com> <92a751d1-a4b9-4c21-821e-a1dc67207516@arm.com> <13eec917a51ca680ed8577bb3aa020b73b43f911.camel@linux.ibm.com> From: Luis Machado In-Reply-To: <13eec917a51ca680ed8577bb3aa020b73b43f911.camel@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO0P123CA0009.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:354::14) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|AS8PR08MB9575:EE_|AM4PEPF00027A66:EE_|AS2PR08MB8363:EE_ X-MS-Office365-Filtering-Correlation-Id: ca48ac17-195e-4c5d-1d42-08dbf0d09952 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: WNIVqhLq7BkoUZoPgnaEMCVQSnvi6oFoz15bFHfRG3OWhefZ/ajYrNq9VblgIXPbUDMHk5CU1shKZrL1q8ZT8/Q1Ivfv7JUlgoAmVfoQxP2uBGhkH1uqd509Ei7aZVmuR+nUqnJ6xF1g8HgkGwIqgPc+Qn5Y/Tu5wDLmGbPMIVEsnQRE9V2lGi7QZD9iVLeb7h6cGlFPG89L5k8+jFLLnI/VomqPJ+bCmPjxc0TYUPCeBeG/EliH/Wn8Ic4RPOIizzMj4drbmAR3mDO2JyQQCV6GL6NzlwGlmEH2hDeBO59+uDsep4ACWs2tz30kaAjLM3mhZvZakUWmidUb8vlYA5V1V+jXuSQd5PfPA2yagOuicX35nCbM/lYaYfjtpYt6sxqE9csJhlC4Xs8WORabVVtOu67/QISXTdh4pyo1D3PspsOGkHaB0OlPuQ5zLEvetvDj2/h0t1C5uIauH+Sz4z8Y2WIgwW5vnaQBsZahBxEjp4/ezwPomUkB5hJm83PDXZOuuKKVfX0DIqPB7lMTtCpJV+1hQNlCYJKa1snX3gHm5t9lKyx6kAtd960bRmDG21CVFcixim2m4NPUptvLcNt3PklFyxjsGjakeaqXzmwOxGY0+fG57mFJBHO+QvtTTjzqPbGLXF3d+Zuh/bslXMrwDlf7A/u/d/0K8HIwMSdyL/An0BPMN8tFCKWXDsI8Vv2tpwH8rHehhF2Wi9uuFg== 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:(13230031)(39860400002)(366004)(396003)(346002)(136003)(376002)(230273577357003)(230173577357003)(230922051799003)(1800799012)(64100799003)(451199024)(186009)(83380400001)(38100700002)(31686004)(8936002)(6486002)(44832011)(8676002)(53546011)(4326008)(86362001)(6506007)(54906003)(66946007)(110136005)(66476007)(66556008)(31696002)(5660300002)(478600001)(316002)(30864003)(2906002)(84970400001)(36756003)(6512007)(41300700001)(26005)(2616005)(66899024)(2004002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9575 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: AM4PEPF00027A66.eurprd04.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 34994cf0-9cea-4904-aec6-08dbf0d09296 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ElQfnUuG4eEz0kWDSbUeh545jAJXiMuXPr+FfDE0NsRx96s8T98omn0OWAksxfIEiLh371kloK/HFOZjpR+vRCoFrQjAmNWlhhbHMRCkoe1oD/hTtg/fT5wIEeyK+oittp7m8aG8YSgZ81icNmIogpWv1fzIWs7XQLL/QvJ0GbCoebbmdLeykAG5wGa4vXUuNQUNdbOMg22S1/snESobBDJA6yRnllbqQM2aVcQFuJj1atgqfkgewmdY5l3ZeXirHfdfIgNI3wczSpkOMKtMMrvILON+gAitP2DAC1At3SNC9VubatPFcmvojmQv+u1AHt8V0g7o9LIuh1a5Aezt56MWvILRwRBTMlSbiZYUo/ESjOMKUbdIz7L29jWkuLmXzAKUIRECIFDWeh+ZlvuJWdIzGboHDkCCRTIb5gTc1ROIbDGb/ZRbbjx2U0wr1GrIvoZSvoZZSpo7zyIb0Tv6udKufInTeu8KEqgfC2mc/7xrvYlDGbUflAs0NOWvLDi4kPdSj05E0XTzg4MOJ4inJfzanwfKCwmT5Y4SSbyxGnjG42H0SVmtRIj8NzEmv1FnD1Fd+RVhqf+c5p+pe8oc0tffb2fhHzLyBBlac2t1v9mcGlkzdCLR6zBuRI/3ltF08nd31xwa7nqWBDoe15HBilfoMis4TOOMmQg3Db+HOTOEOCZxBgA+QY4fgsTHqebSSFln57HLQPFQ5w306Z4nxB/Lg/TUeQQksjh30bwSyDFbixu3eyRZNGgrLB6HDZJMipaeaUAP/oqqeERl1XPVA1ZY0m3ywyIEiEwcwilGXbJXYncWQ2+8f+w0/ls1wIac 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:(13230031)(4636009)(376002)(136003)(346002)(396003)(39860400002)(230922051799003)(230173577357003)(230273577357003)(451199024)(82310400011)(1800799012)(186009)(64100799003)(46966006)(36840700001)(40470700004)(26005)(83380400001)(31686004)(6486002)(81166007)(47076005)(82740400003)(6512007)(336012)(6506007)(8936002)(4326008)(356005)(70206006)(316002)(53546011)(478600001)(36860700001)(110136005)(54906003)(44832011)(31696002)(8676002)(5660300002)(86362001)(70586007)(30864003)(40480700001)(2906002)(36756003)(41300700001)(84970400001)(2616005)(107886003)(40460700003)(66899024)(2004002)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2023 11:44:51.8591 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca48ac17-195e-4c5d-1d42-08dbf0d09952 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: AM4PEPF00027A66.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8363 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,KAM_SHORT,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 List-Id: On 11/22/23 23:33, Carl Love wrote: > GDB maintainers: > > The following patch fixes issues on PowerPC and AArch64 with the > reverse-step and reverse-next instructions when there are multiple > assignment statements on the same line. > > The patch adds a function to search the line table to find the address > of the first instruction of the line. When setting up the > reverse stepping range, the function is called to make sure the start > of the range corresponds to the address of the first instruction for > the line. > > The following patch fixes the execution of the reverse-step and > reverse-next commands for both senarios of multiple statements on the > same line for PowerPC and aarch64-linux. The patch does not change the > behavior on other architectures such as X86-64 where the issue does not > occur when executing in reverse. > > The patch adds a new test case gdb.reverse/map-to-same-line.exp to > verify the fix. > > The patch has been tested on PowerPC and Intel X86 and AArch64 with no > new regression failures. > > Please let me know if the patch is acceptable for mainline. Thanks. > > Carl > ------------------------------------------------ > > PowerPC and aarch64: Fix reverse stepping failure > > When running GDB's testsuite on aarch64-linux/Ubuntu 20.04 (also spotted on > the ppc backend), there are failures in gdb.reverse/solib-precsave.exp and > gdb.reverse/solib-reverse.exp. > > The failure happens around the following code: > > 38 b[1] = shr2(17); /* middle part two */ > 40 b[0] = 6; b[1] = 9; /* generic statement, end part two */ > 42 shr1 ("message 1\n"); /* shr1 one */ > > Normal execution: > > - step from line 38 will land on line 40. > - step from line 40 will land on line 42. > > Reverse execution: > - step from line 42 will land on line 40. > - step from line 40 will land on line 40. > - step from line 40 will land on line 38. > > The problem here is that line 40 contains two contiguous but distinct > PC ranges in the line table, like so: > > Line 40 - [0x7ec ~ 0x7f4] > Line 40 - [0x7f4 ~ 0x7fc] > > The two distinct ranges are generated because GCC started outputting source > column information, which GDB doesn't take into account at the moment. > > When stepping forward from line 40, we skip both of these ranges and land on > line 42. When stepping backward from line 42, we stop at the start PC of the > second (or first, going backwards) range of line 40. > > Since we've reached ecs->event_thread->control.step_range_start, we stop > stepping backwards. > > The above issues were fixed by introducing a new function that looks for > adjacent PC ranges for the same line, until we notice a line change. Then > we take that as the start PC of the range. The new start PC for the range > is used for the control.step_range_start when setting up a step range. > > The test case gdb.reverse/map-to-same-line.exp is added to test the fix > for the above reverse step issues. > > Patch has been tested on PowerPC, X86 and AArch64 with no regressions. > --- > gdb/infrun.c | 57 +++++++ > gdb/symtab.c | 50 ++++++ > gdb/symtab.h | 17 ++ > gdb/testsuite/gdb.reverse/map-to-same-line.c | 58 +++++++ > .../gdb.reverse/map-to-same-line.exp | 153 ++++++++++++++++++ > 5 files changed, 335 insertions(+) > create mode 100644 gdb/testsuite/gdb.reverse/map-to-same-line.c > create mode 100644 gdb/testsuite/gdb.reverse/map-to-same-line.exp > > diff --git a/gdb/infrun.c b/gdb/infrun.c > index 62b306ff347..27251d3023e 100644 > --- a/gdb/infrun.c > +++ b/gdb/infrun.c > @@ -116,6 +116,8 @@ static struct async_event_handler *infrun_async_inferior_event_token; > /* Stores whether infrun_async was previously enabled or disabled. > Starts off as -1, indicating "never enabled/disabled". */ > static int infrun_is_async = -1; > +static CORE_ADDR update_line_range_start (CORE_ADDR pc, > + struct execution_control_state *ecs); > > /* See infrun.h. */ > > @@ -7279,6 +7281,27 @@ handle_signal_stop (struct execution_control_state *ecs) > process_event_stop_test (ecs); > } > > +/* Return the address for the beginning of the line. */ > + > +CORE_ADDR > +update_line_range_start (CORE_ADDR pc, struct execution_control_state *ecs) > +{ > + /* The line table may have multiple entries for the same source code line. > + Given the PC, check the line table and return the PC that corresponds > + to the line table entry for the source line that PC is in. */ > + CORE_ADDR start_line_pc = ecs->event_thread->control.step_range_start; > + std::optional real_range_start; > + > + /* Call find_line_range_start to get the smallest address in the > + linetable for multiple Line X entries in the line table. */ > + real_range_start = find_line_range_start (pc); > + > + if (real_range_start.has_value ()) > + start_line_pc = *real_range_start; > + > + return start_line_pc; > +} > + > /* Come here when we've got some debug event / signal we can explain > (IOW, not a random signal), and test whether it should cause a > stop, or whether we should resume the inferior (transparently). > @@ -8093,6 +8116,29 @@ process_event_stop_test (struct execution_control_state *ecs) > > if (stop_pc_sal.is_stmt) > { > + if (execution_direction == EXEC_REVERSE) > + { > + /* We are stepping backwards make sure we have reached the > + beginning of the line. */ > + CORE_ADDR stop_pc = ecs->event_thread->stop_pc (); > + CORE_ADDR start_line_pc > + = update_line_range_start (stop_pc, ecs); > + > + if (stop_pc != start_line_pc) > + { > + /* Have not reached the beginning of the source code line. > + Set a step range. Execution should stop in any function > + calls we execute back into before reaching the beginning > + of the line. */ > + ecs->event_thread->control.step_range_start > + = start_line_pc; > + ecs->event_thread->control.step_range_end = stop_pc; > + set_step_info (ecs->event_thread, frame, stop_pc_sal); > + keep_going (ecs); > + return; > + } > + } > + > /* We are at the start of a statement. > > So stop. Note that we don't stop if we step into the middle of a > @@ -8155,6 +8201,17 @@ process_event_stop_test (struct execution_control_state *ecs) > set_step_info (ecs->event_thread, frame, stop_pc_sal); > > infrun_debug_printf ("keep going"); > + > + if (execution_direction == EXEC_REVERSE) > + { > + CORE_ADDR stop_pc = ecs->event_thread->stop_pc (); > + > + /* Make sure the stop_pc is set to the beginning of the line. */ > + if (stop_pc != ecs->event_thread->control.step_range_start) > + ecs->event_thread->control.step_range_start > + = update_line_range_start (stop_pc, ecs); > + } > + > keep_going (ecs); > } > > diff --git a/gdb/symtab.c b/gdb/symtab.c > index 5ec56f4f2af..70ef7d56878 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -73,6 +73,7 @@ > #include "gdbsupport/gdb_string_view.h" > #include "gdbsupport/pathstuff.h" > #include "gdbsupport/common-utils.h" > +#include > > /* Forward declarations for local functions. */ > > @@ -3311,6 +3312,55 @@ find_pc_line (CORE_ADDR pc, int notcurrent) > return sal; > } > > +/* Compare two symtab_and_line entries. Return true if both have > + the same line number and the same symtab pointer. That means we > + are dealing with two entries from the same line and from the same > + source file. > + > + Return false otherwise. */ > + > +static bool > +sal_line_symtab_matches_p (const symtab_and_line &sal1, > + const symtab_and_line &sal2) > +{ > + return sal1.line == sal2.line && sal1.symtab == sal2.symtab; > +} > + > +/* See symtah.h. */ > + > +std::optional > +find_line_range_start (CORE_ADDR pc) > +{ > + struct symtab_and_line current_sal = find_pc_line (pc, 0); > + > + if (current_sal.line == 0) > + return {}; > + > + struct symtab_and_line prev_sal = find_pc_line (current_sal.pc - 1, 0); > + > + /* If the previous entry is for a different line, that means we are already > + at the entry with the start PC for this line. */ > + if (!sal_line_symtab_matches_p (prev_sal, current_sal)) > + return current_sal.pc; > + > + /* Otherwise, keep looking for entries for the same line but with > + smaller PC's. */ > + bool done = false; > + CORE_ADDR prev_pc; > + while (!done) > + { > + prev_pc = prev_sal.pc; > + > + prev_sal = find_pc_line (prev_pc - 1, 0); > + > + /* Did we notice a line change? If so, we are done searching. */ > + if (!sal_line_symtab_matches_p (prev_sal, current_sal)) > + done = true; > + } > + > + return prev_pc; > +} > + > /* See symtab.h. */ > > struct symtab * > diff --git a/gdb/symtab.h b/gdb/symtab.h > index 8dfc873b1c9..9ef09e22902 100644 > --- a/gdb/symtab.h > +++ b/gdb/symtab.h > @@ -38,6 +38,7 @@ > #include "gdb-demangle.h" > #include "split-name.h" > #include "frame.h" > +#include > > /* Opaque declarations. */ > struct ui_file; > @@ -2359,6 +2360,22 @@ extern struct symtab_and_line find_pc_line (CORE_ADDR, int); > extern struct symtab_and_line find_pc_sect_line (CORE_ADDR, > struct obj_section *, int); > > +/* Given PC, and assuming it is part of a range of addresses that is part of > + a line, go back through the linetable and find the starting PC of that > + line. > + > + For example, suppose we have 3 PC ranges for line X: > + > + Line X - [0x0 - 0x8] > + Line X - [0x8 - 0x10] > + Line X - [0x10 - 0x18] > + > + If we call the function with PC == 0x14, we want to return 0x0, as that is > + the starting PC of line X, and the ranges are contiguous. > +*/ > + > +extern std::optional find_line_range_start (CORE_ADDR pc); > + > /* Wrapper around find_pc_line to just return the symtab. */ > > extern struct symtab *find_pc_line_symtab (CORE_ADDR); > diff --git a/gdb/testsuite/gdb.reverse/map-to-same-line.c b/gdb/testsuite/gdb.reverse/map-to-same-line.c > new file mode 100644 > index 00000000000..3086e849231 > --- /dev/null > +++ b/gdb/testsuite/gdb.reverse/map-to-same-line.c > @@ -0,0 +1,58 @@ > +/* Copyright 2023 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +/* The purpose of this test is to create a DWARF line table that contains two > + or more entries for the same line. When stepping (forwards or backwards), > + GDB should step over the entire line and not just a particular entry in > + the line table. */ > + > +int > +main (void) > +{ /* TAG: main prologue */ > + asm ("main_label: .globl main_label"); > + int i = 1, j = 2, k; > + float f1 = 2.0, f2 = 4.1, f3; > + const char *str_1 = "foo", *str_2 = "bar", *str_3; > + > + asm ("line1: .globl line1"); > + k = i; f3 = f1; str_3 = str_1; /* TAG: line 1 */ > + > + asm ("line2: .globl line2"); > + k = j; f3 = f2; str_3 = str_2; /* TAG: line 2 */ > + > + asm ("line3: .globl line3"); > + k = i; f3 = f1; str_3 = str_1; /* TAG: line 3 */ > + > + asm ("line4: .globl line4"); > + k = j; f3 = f2; str_3 = str_2; /* TAG: line 4 */ > + > + asm ("line5: .globl line5"); > + k = i; f3 = f1; str_3 = str_1; /* TAG: line 5 */ > + > + asm ("line6: .globl line6"); > + k = j; f3 = f2; str_3 = str_2; /* TAG: line 6 */ > + > + asm ("line7: .globl line7"); > + k = i; f3 = f1; str_3 = str_1; /* TAG: line 7 */ > + > + asm ("line8: .globl line8"); > + k = j; f3 = f2; str_3 = str_2; /* TAG: line 8 */ > + > + asm ("main_return: .globl main_return"); > + k = j; f3 = f2; str_3 = str_2; /* TAG: main return */ > + > + asm ("end_of_sequence: .globl end_of_sequence"); > + return 0; /* TAG: main return */ > +} > diff --git a/gdb/testsuite/gdb.reverse/map-to-same-line.exp b/gdb/testsuite/gdb.reverse/map-to-same-line.exp > new file mode 100644 > index 00000000000..63f8c9c76b3 > --- /dev/null > +++ b/gdb/testsuite/gdb.reverse/map-to-same-line.exp > @@ -0,0 +1,153 @@ > +# Copyright 2023 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# When stepping (forwards or backwards), GDB should step over the entire line > +# and not just a particular entry in the line table. This test was added to > +# verify the find_line_range_start function properly sets the step range for a > +# line that consists of multiple statements, i.e. multiple entries in the line > +# table. This test creates a DWARF line table that contains two entries for > +# the same line to do the needed testing. > + > +# This test can only be run on targets which support DWARF-2 and use gas. > +load_lib dwarf.exp > +require dwarf2_support > + > +# The DWARF assembler requires the gcc compiler. > +require is_c_compiler_gcc > + > +# This test suitable only for process that can do reverse execution > +require supports_reverse > + > +standard_testfile .c .S > + > +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { > + return -1 > +} > + > +set asm_file [standard_output_file $srcfile2] > +Dwarf::assemble $asm_file { > + global srcdir subdir srcfile > + declare_labels integer_label L > + > + # Find start address and length of program > + lassign [function_range main [list ${srcdir}/${subdir}/$srcfile]] \ > + main_start main_len > + set main_end "$main_start + $main_len" > + > + cu {} { > + compile_unit { > + {language @DW_LANG_C} > + {name map-to-same-line.c} > + {stmt_list $L DW_FORM_sec_offset} > + {low_pc 0 addr} > + } { > + subprogram { > + {external 1 flag} > + {name main} > + {low_pc $main_start addr} > + {high_pc $main_len DW_FORM_data4} > + } > + } > + } > + > + lines {version 2 default_is_stmt 1} L { > + include_dir "${srcdir}/${subdir}" > + file_name "$srcfile" 1 > + > + # Generate the line table program with distinct source lines being > + # mapped to the same line entry. Line 1, 5 and 8 contain 1 statement > + # each. Line 2 contains 2 statements. Line 3 contains 3 statements. > + program { > + DW_LNE_set_address $main_start > + line [gdb_get_line_number "TAG: main prologue"] > + DW_LNS_copy > + DW_LNE_set_address line1 > + line [gdb_get_line_number "TAG: line 1" ] > + DW_LNS_copy > + DW_LNE_set_address line2 > + line [gdb_get_line_number "TAG: line 2" ] > + DW_LNS_copy > + DW_LNE_set_address line3 > + line [gdb_get_line_number "TAG: line 2" ] > + DW_LNS_copy > + DW_LNE_set_address line4 > + line [gdb_get_line_number "TAG: line 3" ] > + DW_LNS_copy > + DW_LNE_set_address line5 > + line [gdb_get_line_number "TAG: line 3" ] > + DW_LNS_copy > + DW_LNE_set_address line6 > + line [gdb_get_line_number "TAG: line 3" ] > + DW_LNS_copy > + DW_LNE_set_address line7 > + line [gdb_get_line_number "TAG: line 5" ] > + DW_LNS_copy > + DW_LNE_set_address line8 > + line [gdb_get_line_number "TAG: line 8" ] > + DW_LNS_copy > + DW_LNE_set_address main_return > + line [gdb_get_line_number "TAG: main return"] > + DW_LNS_copy > + DW_LNE_set_address end_of_sequence > + DW_LNE_end_sequence > + } > + } > +} > + > +if { [prepare_for_testing "failed to prepare" ${testfile} \ > + [list $srcfile $asm_file] {nodebug} ] } { > + return -1 > +} > + > +if { ![runto_main] } { > + return > +} > + > +# Print the line table > +gdb_test_multiple "maint info line-table ${testfile}" "" { > + -re "\r\n$decimal\[ \t\]+$decimal\[ \t\]+($hex)\[ \t\]+Y\[^\r\n\]*" { > + lappend is_stmt $expect_out(1,string) > + exp_continue > + } > + -re -wrap "" { > + } > +} > + > +# Do the reverse-step and reverse-next tests > +foreach_with_prefix cmd {step next} { > + gdb_test_no_output "record" "turn on process record, test $cmd" > + > + set bp_main_return [gdb_get_line_number "TAG: main return" $srcfile] > + gdb_breakpoint $srcfile:$bp_main_return > + gdb_continue_to_breakpoint "run to end of main, reverse-$cmd test" ".*$srcfile:$bp_main_return.*" > + gdb_test "display \$pc" ".*pc =.*" "display pc, reverse-$cmd test" > + > + # At this point, GDB has already recorded the execution up until the return > + # statement. Reverse and test if GDB transitions between lines in the > + # expected order. It should reverse-step or reverse-next across lines 8, > + # 5, 3, 2 and 1. > + foreach line {8 5 3 2 1} { > + gdb_test "reverse-$cmd" ".*TAG: line $line.*" "reverse $cmd to line $line" > + } > + > + if {$cmd =="step"} { > + ## Clean restart, test reverse-next command > + clean_restart ${testfile} > + > + if { ![runto_main] } { > + return > + } > + } > +} I have re-tested this patch on aarch64-linux and arm-linux. I don't see any regressions and it fixes the failures I see for aarch64-linux. The tests also pass for arm-linux, although we seem to have acquired some regressions from a previous commit. I'm OK with the code as-is. I'd rather have some feedback from other maintainers. Tested-By: Luis Machado Reviewed-By: Luis Machado