From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2088.outbound.protection.outlook.com [40.107.21.88]) by sourceware.org (Postfix) with ESMTPS id 96EB53858CDA for ; Wed, 29 Nov 2023 11:46:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96EB53858CDA 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 96EB53858CDA Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.21.88 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1701258395; cv=pass; b=bcE8I6c7P2vZHyEB+N3Gr9mPgLWmfyj5QBefxIFp3tZ7B8FMy0Ow99EO/ERJNDQ1dxhRJfF2TcRs3T/Z2MRpLq15xxm/Ztcg9m+Owblf6Zfw7G6eem+6SBdhN1PDzu59R6GzdXV2JSiypUGru6/yPM3Acyyn3cj8gAtwPlymPvk= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1701258395; c=relaxed/simple; bh=1AzjlsXRWvNHrWpASWYpAEsu6LCASvR/Do9E0pnXDbc=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:Subject:To:From: MIME-Version; b=XpIaQaZ0fOdo1dP9JS+/zkTv6AwK7Bo7XhKAc4XDj4fuXFVoIdHNWb9qAHtSXuq7ydKmQ8mvhKvnn0Gi/FE4hpeAIcmSVEUXViBTCoFq6SM/KUdOjIhbCq3EdoV1nd1fF/BcCBKz62ZWxyqb55igGcvZKOR1BiGcwqvTb7Dkckw= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=HyuGrs4DiEUkSE5txU+3E3YRUFej+Av2adZ9MYeZoByLQqEO+CS5G+gFSsixIv0/CXam8YUQBmb5om6VgOfqf1qU/S0rpVkTO4/fjGq87fbCOx+geM/WN1NhpMnlSOnI1FDNHQS1nvfYx982r0NAEbCNh0oLavTWNcOBh3RfPchHDxt35+a7LWqrhtuxF+s2G7gHKDb6/MSb/8Y1SwmOE+5sMFnlhW2luk5hMx2uVnVHO6uLkma2O59XP64PrRlvYgAFWmdqZIAlYI57AkHGjEqV4aJ8YL/0fDHBOaImOJ3KkGX2xgGJ0m8zCMvUv3aY6BUB0XH1LJU12I9MrangAw== 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=fd06YOsCFGtz4QTbWlzVX8PhCMmuZKrwp2G3yNZzarM=; b=dP89kpSVxmf2EkHiHSW7tOI+xtf145g0EUW9y8FW+gWn4gTy72VsnEoCoMzm15KqdJJwuC/YJdSqJLe8W4Mo3P/58+cvhKW5HuP9Tt7QmlwzTeHDJ1AP6eIghThPAFrggETgbbNp39HvmMEvj6b2KBXapCdccd64tOOkHsViQvfTg/P8gTT8Kd6vu4E6L/+NclNt++rL9QHsVUI6cC/9VcL+LDsl0IvwLxxwK+j1enMR77ex91e17RAphlpM+Enb6/KFstSjb1ePZNPkJblm6LQsrvakMB4TbnsIp1uaSTQ6c4LmZ79z1UULVxtwODtxvZ6KMOGNVCpCjf74nbXrgw== 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=fd06YOsCFGtz4QTbWlzVX8PhCMmuZKrwp2G3yNZzarM=; b=HlhFm4TJk+NNm82pecgroFk5qUehYyjlFJlLKcf7S9ipUfXpqDFTNqQH2DT0ESIljpI0OujVjPUbs3PfSumOVpS/HiNJdjVuNz//RalaPRDX/JomjHt2tCvnF+6piFR/bg+pfFdCqF6PLUvKObZJrTvNQNzgq3TKKyVbccaIPAA= Received: from DU2PR04CA0271.eurprd04.prod.outlook.com (2603:10a6:10:28c::6) by DB8PR08MB5513.eurprd08.prod.outlook.com (2603:10a6:10:f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.23; Wed, 29 Nov 2023 11:46:28 +0000 Received: from DU6PEPF00009529.eurprd02.prod.outlook.com (2603:10a6:10:28c:cafe::84) by DU2PR04CA0271.outlook.office365.com (2603:10a6:10:28c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.28 via Frontend Transport; Wed, 29 Nov 2023 11:46:28 +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 DU6PEPF00009529.mail.protection.outlook.com (10.167.8.10) 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:46:28 +0000 Received: ("Tessian outbound 8289ea11ec17:v228"); Wed, 29 Nov 2023 11:46:28 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2be92bca89ce477b X-CR-MTA-TID: 64aa7808 Received: from 7be47bc1bec9.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7B58DFA2-1727-4665-8BD1-4CF617BEB314.1; Wed, 29 Nov 2023 11:46:22 +0000 Received: from EUR03-AM7-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 7be47bc1bec9.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 29 Nov 2023 11:46:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UuKedkz4PxqyfIP4+fBldWCn9towUnPBLaPYugm2btd78Luk44c3d9qBu9xngxwgLAB4rpQ3418KVyGC0RzVcrRCwxKQUwoP/A9Ra767aLTXL7tfg+XMLXKQ4GjJNAhfhhTajXiy1MT4CZJx2OJxTaPC1nOsITJbzqoJzb11U8QMS43BlglMXVZmnKx4jExNx6PCvVgOZHEUuAIzNCdoxPjcWsjKGKGAngDZ4V2O6gxwu5x3/6McIc8sd9M2Ydut9VkwMdB7xthd8F4UYKHZpbgcZ5fWiyVZaOPJsXejvKcMIgaQ9ka4nloscw5AhVGjvL5ZN3xMTUifJ61v9/gs7Q== 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=fd06YOsCFGtz4QTbWlzVX8PhCMmuZKrwp2G3yNZzarM=; b=e7qmSiyVmP3FOTPZuZNX8i8PAXhjdY0XT33BfNczJ5XcqZ75tctRssADN26ce3NXv5IESorPOZRRliJHszxw8e5SFf0KhKdLPEsctTRvyYtFFSFz0f2ZBsRDJdNTdz/XBvu7ZMhB7x93Kt/zVTIbV/mIxwE9KY8vl3u5PjRFy6WpPrlGo7w/V5Pz9MJE71vRiy+9mVLzgwou+XykZLRoTMZcZkuhKeK81asURlDqzcE0RPNZ4cXJq70g2lYx0kb6SkEcvjcoiL6YYDr117OcKY/XORWISk8kFscIZwFoIwGAKziI80eVqjYcQGCVX+fHOghqBo+khnbC6HJJ3JOJsA== 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=fd06YOsCFGtz4QTbWlzVX8PhCMmuZKrwp2G3yNZzarM=; b=HlhFm4TJk+NNm82pecgroFk5qUehYyjlFJlLKcf7S9ipUfXpqDFTNqQH2DT0ESIljpI0OujVjPUbs3PfSumOVpS/HiNJdjVuNz//RalaPRDX/JomjHt2tCvnF+6piFR/bg+pfFdCqF6PLUvKObZJrTvNQNzgq3TKKyVbccaIPAA= 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:46:19 +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:46:19 +0000 Message-ID: <9070e173-74e7-4e35-9be3-98a95be8615d@arm.com> Date: Wed, 29 Nov 2023 11:46:18 +0000 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/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> From: Luis Machado In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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_|DU6PEPF00009529:EE_|DB8PR08MB5513:EE_ X-MS-Office365-Filtering-Correlation-Id: 1268678d-98fa-4c6f-edcd-08dbf0d0d300 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: zxsVmlAo8fYN3nUMj9fupEvDxpeJUo/8urIBL5WEZZoPi2gYPKhOVwWRgpb8zqZ/qOx38FSsL2GUfwv7M67yRu4SZidHDl8N+h6T/ikcvol1t5PRPeLSlBtvrSzL76UhIwUkCoHv3J1mM/vreGunxlbO1yFYy1uS8PSiUKqVuoeWQSPMpVN/36khYAR1mzlwcRdroN6icAnxZhmch2hcWULRH2fVgQJaxoauTWNe2OJsMWlWD7xHkxadsGR2b2GDWZf8F/7xXRD8rhDq8Yyoo+kQGSqBEf2UNs30BRugfsH1RxmIKFi3wXmTP6HQa6N4tPcTbauHyMglXa1Dbjj8wCZHJSGRgKdpkFG+pQX58cIfLz536ngFMS5sa7VhJF3yBhAF3LKBuD0H13HXMnyYpwhnXJM8//rxHUbevjt3PSnq8x8wqPstcrUwhyUSxfCwQCW2eaaH97+sRyKoqn0QM0S3yiZM0GWX38tguNMr9lLavH2QDaXFN5fl5Z3wjk/zuplo8zQtK7o3EjF5NdfO3SMekLtMZjgn1E/PkHSWvgP5GDNAqaLKsPJKTBXb1F94jB9EdpuRO268BP7nf4qxgy57qYm89MpWQpu4khT90xV1AmkXkOPooms4MyQN/nzRwBW00KAF49q9WN2lHF0uygUlhNd0VV81qjb9tiAqRzgnmFVJqjXCnWJddHTGzrKj 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)(230922051799003)(1800799012)(64100799003)(451199024)(186009)(83380400001)(38100700002)(31686004)(8936002)(6486002)(44832011)(8676002)(53546011)(4326008)(86362001)(6506007)(54906003)(66946007)(110136005)(66476007)(66556008)(31696002)(5660300002)(966005)(478600001)(316002)(30864003)(2906002)(84970400001)(36756003)(6512007)(41300700001)(26005)(2616005)(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: DU6PEPF00009529.eurprd02.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1c0078a3-10b5-4571-9cc8-08dbf0d0cd5a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: isVa7gENYrhqGZ0B+gwKfez4NA8sksqZov6Pk32D4Wi8dPjqLESVIIRmtT93DFDpAGDiLEWzPMqhq0pC0AN/8O9XZdg6iutAsyWCDiLVssVzJp2uHO0TfkYTFg9yftkuODKGoAi2PPCWK+M4dKo2GL3f6thHlyxQKF36LrxVyRSqeNJr/49g+23o64kxXfyyygl5uF4RFkSuGr46lFCXjpVHXZwrBYPJYC40czVHrleXWq6I0ySUUMvzgLZzU4xD5S/ZH9xklbuLue/PcJVUDjHOb8x0xw3QmPCMDTQiNxQTkwdkhz28SlymFyw5mSaQsUx7fuj9x5uyiDqF/FA87djo8WT0TvysOJ+edhd0tT5GW2W+AhvuUWf1sTUwg9/wtuGvmZG5ncI6X9GY5bGo3dpyvDkmj5OFu+rhWgg0oeS8TbxmCdHadR0PuxFoD25+uFpu6+3ZnTJyFfpMpYh1E8s7W5yRZ4ErSec6kXIVhldfmWyU2dDJwetOFvKZ5wW+A/hN96lp9gg8URxX3FGf0LatsjzQ1MmMV9OpeVyEDogOLy+udfIHvbtv3CDFo4NzxEV8RfW5+nP2y3lIZa3wpf2rargBKzXQQ5HtryNPZlsVV7iJ75Z9fXqHIF9t8Id9uYp1KKrXv2vXie2AM6oAOlF61H2BFu7KYMev6s/qPFmijjKfBunC1ra4hT1q/Uu6cjD/M4RLzALCOJd0jUSuQo8Fs03mr+3nsR0Y0euFnrLK1+s3D2dC5o6UXEPKftcJs4HXEZHtgaS+hmvNcwrmFEwRl/nDTePvH9iuZCe/FkU67cNVPs0oHJCuqEIDVXtG 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)(346002)(136003)(396003)(39860400002)(230922051799003)(82310400011)(186009)(1800799012)(64100799003)(451199024)(46966006)(40470700004)(36840700001)(47076005)(356005)(41300700001)(31696002)(44832011)(2616005)(107886003)(86362001)(8676002)(8936002)(5660300002)(4326008)(40480700001)(2906002)(84970400001)(30864003)(26005)(110136005)(31686004)(6506007)(81166007)(478600001)(316002)(70206006)(70586007)(40460700003)(6486002)(966005)(53546011)(54906003)(336012)(36860700001)(83380400001)(36756003)(82740400003)(6512007)(2004002)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2023 11:46:28.6818 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1268678d-98fa-4c6f-edcd-08dbf0d0d300 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: DU6PEPF00009529.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5513 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_ASCII_DIVIDERS,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 changes the behavior of GDB when executing the next > command in reverse over a line that contains multiple function calls on > the same source code line. Currently, GDB stops in the middle of the > line not at the beginning of the line. This patch causes GDB to stop > at the beginning of the line. The incorrect behavior was pointed out > by Pedro Alves in > https://sourceware.org/pipermail/gdb-patches/2023-January/196110.html > > A new testcase, func-map-to-same-line.exp, is added to verify the > behavior of GDB. > > The fix requires updating two testcases, gdb/testsuite/gdb.mi/mi- > reverse.exp and gdb.reverse/finish-reverse-next.exp. The testcases > have to issue two reverse next instructions to reach the previous > source code line. With this patch, they only require a single reverse > next instruction to reach the previous line. > > The patch has been tested on PowerPC and X86-64 with no regression > errors. > > Please let me know if the patch is acceptable for mainline. Thanks. > > Carl > ---------------------------------------------------- > > Fix GDB reverse-step and reverse-next command behavior > > Currently GDB when executing in reverse over multiple statements in a single > line of source code, GDB stops in the middle of the line. Thus requiring > multiple commands to reach the previous line. GDB should stop at the first > instruction of the line, not in the middle of the line. > > The following description of the incorrect behavior was taken from an > earlier message by Pedro Alves : > > https://sourceware.org/pipermail/gdb-patches/2023-January/196110.html > > --------------------------------- > > The source line looks like: > > func1 (); func2 (); > > in the test case: > > (gdb) list 1 > 1 void func1 () > 2 { > 3 } > 4 > 5 void func2 () > 6 { > 7 } > 8 > 9 int main () > 10 { > 11 func1 (); func2 (); > 12 } > > compiled with: > > $ gcc reverse.c -o reverse -g3 -O0 > $ gcc -v > ... > gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) > > Now let's debug it with target record, using current gdb git master > (f3d8ae90b236), > > $ gdb ~/reverse > GNU gdb (GDB) 14.0.50.20230124-git > ... > Reading symbols from /home/pedro/reverse... > (gdb) start > Temporary breakpoint 1 at 0x1147: file reverse.c, line 11. > Starting program: /home/pedro/reverse > [Thread debugging using libthread_db enabled] > Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". > > Temporary breakpoint 1, main () at reverse.c:11 > 11 func1 (); func2 (); > (gdb) record > > (gdb) disassemble /s > Dump of assembler code for function main: > reverse.c: > 10 { > 0x000055555555513f <+0>: endbr64 > 0x0000555555555143 <+4>: push %rbp > 0x0000555555555144 <+5>: mov %rsp,%rbp > > 11 func1 (); func2 (); > => 0x0000555555555147 <+8>: mov $0x0,%eax > 0x000055555555514c <+13>: call 0x555555555129 > 0x0000555555555151 <+18>: mov $0x0,%eax > 0x0000555555555156 <+23>: call 0x555555555134 > 0x000055555555515b <+28>: mov $0x0,%eax > > 12 } > 0x0000555555555160 <+33>: pop %rbp > 0x0000555555555161 <+34>: ret > End of assembler dump. > > (gdb) n > 12 } > > So far so good, a "next" stepped over the whole of line 11 and stopped at > line 12. > > Let's confirm where we are now: > > (gdb) disassemble /s > Dump of assembler code for function main: > reverse.c: > 10 { > 0x000055555555513f <+0>: endbr64 > 0x0000555555555143 <+4>: push %rbp > 0x0000555555555144 <+5>: mov %rsp,%rbp > > 11 func1 (); func2 (); > 0x0000555555555147 <+8>: mov $0x0,%eax > 0x000055555555514c <+13>: call 0x555555555129 > 0x0000555555555151 <+18>: mov $0x0,%eax > 0x0000555555555156 <+23>: call 0x555555555134 > 0x000055555555515b <+28>: mov $0x0,%eax > > 12 } > => 0x0000555555555160 <+33>: pop %rbp > 0x0000555555555161 <+34>: ret > End of assembler dump. > > Good, we're at the first instruction of line 12. > > Now let's undo the "next", with "reverse-next": > > (gdb) reverse-next > 11 func1 (); func2 (); > > Seemingly stopped at line 11. Let's see exactly where: > > (gdb) disassemble /s > Dump of assembler code for function main: > reverse.c: > 10 { > 0x000055555555513f <+0>: endbr64 > 0x0000555555555143 <+4>: push %rbp > 0x0000555555555144 <+5>: mov %rsp,%rbp > > 11 func1 (); func2 (); > 0x0000555555555147 <+8>: mov $0x0,%eax > 0x000055555555514c <+13>: call 0x555555555129 > => 0x0000555555555151 <+18>: mov $0x0,%eax > 0x0000555555555156 <+23>: call 0x555555555134 > 0x000055555555515b <+28>: mov $0x0,%eax > > 12 } > 0x0000555555555160 <+33>: pop %rbp > 0x0000555555555161 <+34>: ret > End of assembler dump. > (gdb) > > And lo, we stopped in the middle of line 11! That is a bug, we should have > stepped back all the way to the beginning of the line. The "reverse-next" > should have fully undone the prior "next" command. > > -------------------- > > This patch fixes the incorrect GDB behavior by ensuring that GDB stops at > the first instruction in the line. > > The test case gdb.reverse/func-map-to-same-line.exp is added to testsuite > to verify this fix when the line table information is and is not available. > --- > gdb/infcmd.c | 13 ++ > gdb/testsuite/gdb.mi/mi-reverse.exp | 5 +- > .../gdb.reverse/finish-reverse-next.exp | 40 ++--- > .../gdb.reverse/func-map-to-same-line.c | 37 +++++ > .../gdb.reverse/func-map-to-same-line.exp | 140 ++++++++++++++++++ > 5 files changed, 201 insertions(+), 34 deletions(-) > create mode 100644 gdb/testsuite/gdb.reverse/func-map-to-same-line.c > create mode 100644 gdb/testsuite/gdb.reverse/func-map-to-same-line.exp > > diff --git a/gdb/infcmd.c b/gdb/infcmd.c > index cf8cd527955..1415fe55163 100644 > --- a/gdb/infcmd.c > +++ b/gdb/infcmd.c > @@ -975,6 +975,19 @@ prepare_one_step (thread_info *tp, struct step_command_fsm *sm) > &tp->control.step_range_start, > &tp->control.step_range_end); > > + if (execution_direction == EXEC_REVERSE) > + { > + symtab_and_line sal = find_pc_line (pc, 0); > + symtab_and_line sal_start > + = find_pc_line (tp->control.step_range_start, 0); > + > + if (sal.line == sal_start.line) > + /* Executing in reverse, the step_range_start address is in > + the same line. We want to stop in the previous line so > + move step_range_start before the current line. */ > + tp->control.step_range_start--; > + } > + > /* There's a problem in gcc (PR gcc/98780) that causes missing line > table entries, which results in a too large stepping range. > Use inlined_subroutine info to make the range more narrow. */ > diff --git a/gdb/testsuite/gdb.mi/mi-reverse.exp b/gdb/testsuite/gdb.mi/mi-reverse.exp > index baa53a495d7..0630b8b6c7f 100644 > --- a/gdb/testsuite/gdb.mi/mi-reverse.exp > +++ b/gdb/testsuite/gdb.mi/mi-reverse.exp > @@ -96,11 +96,8 @@ proc test_controlled_execution_reverse {} { > "reverse finish from callme" > > # Test exec-reverse-next > - # It takes two steps to get back to the previous line, > - # as the first step moves us to the start of the current line, > - # and the one after that moves back to the previous line. > > - mi_execute_to "exec-next --reverse 2" \ > + mi_execute_to "exec-next --reverse" \ > "end-stepping-range" "main" "" \ > "basics.c" $line_main_hello "" \ > "reverse next to get over the call to do_nothing" > diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-next.exp b/gdb/testsuite/gdb.reverse/finish-reverse-next.exp > index 1f53b649a7d..6488f66b107 100644 > --- a/gdb/testsuite/gdb.reverse/finish-reverse-next.exp > +++ b/gdb/testsuite/gdb.reverse/finish-reverse-next.exp > @@ -76,14 +76,10 @@ gdb_continue_to_breakpoint \ > repeat_cmd_until "stepi" "CALL VIA LEP" "{" "stepi into function1 call" "100" > > # The reverse-finish command should stop on the function call instruction > -# which is the last instruction in the source code line. A reverse-next > -# instruction should then stop at the first instruction in the same source > -# code line. Another revers-next instruction stops at the previous source > -# code line. > +# which is the last instruction in the source code line. Another reverse-next > +# instruction stops at the previous source code line. > gdb_test "reverse-finish" ".*function1 \\(a, b\\); // CALL VIA LEP.*" \ > "reverse-finish function1 LEP call from LEP " > -gdb_test "reverse-next" ".*function1 \\(a, b\\); // CALL VIA LEP" \ > - "reverse next 1 LEP entry point function call from LEP" > gdb_test "reverse-next" ".*b = 5;.*" "reverse next 2, at b = 5, call from LEP" > > > @@ -109,14 +105,10 @@ gdb_continue_to_breakpoint \ > gdb_test "step" ".*int ret = 0;.*" "step test 1" > > # The reverse-finish command should stop on the function call instruction > -# which is the last instruction in the source code line. A reverse-next > -# instruction should then stop at the first instruction in the same source > -# code line. Another revers-next instruction stops at the previous source > -# code line. > +# which is the last instruction in the source code line. Another reverse-next > +# instruction stops at the previous source code line. > gdb_test "reverse-finish" ".*function1 \\(a, b\\); // CALL VIA LEP.*" \ > "reverse-finish function1 LEP call from function body" > -gdb_test "reverse-next" ".*function1 \\(a, b\\); // CALL VIA LEP.*" \ > - "reverse next 1 LEP from function body" > gdb_test "reverse-next" ".*b = 5;.*" \ > "reverse next 2 at b = 5, from function body" > > @@ -144,14 +136,10 @@ gdb_continue_to_breakpoint \ > repeat_cmd_until "stepi" "CALL VIA GEP" "{" "stepi into funp call" > > # The reverse-finish command should stop on the function call instruction > -# which is the last instruction in the source code line. A reverse-next > -# instruction should then stop at the first instruction in the same source > -# code line. Another revers-next instruction stops at the previous source > -# code line. > +# which is the last instruction in the source code line. Another reverse-next > +# instruction stops at the previous source code line. > gdb_test "reverse-finish" ".*funp \\(a, b\\);.*" \ > "function1 GEP call call from GEP" > -gdb_test "reverse-next" ".*funp \\(a, b\\);.*" \ > - "reverse next 1 GEP entry point function call from GEP" > gdb_test "reverse-next" ".*b = 50;.*" "reverse next 2 at b = 50, call from GEP" > > gdb_test "reverse-continue" ".*" "setup for test 4" > @@ -180,14 +168,10 @@ repeat_cmd_until "stepi" "CALL VIA GEP" "{" "stepi into funp call again" > gdb_test "stepi" "{" "stepi to between GEP and LEP" > > # The reverse-finish command should stop on the function call instruction > -# which is the last instruction in the source code line. A reverse-next > -# instruction should then stop at the first instruction in the same source > -# code line. Another revers-next instruction stops at the previous source > -# code line. > +# which is the last instruction in the source code line. Another reverse-next > +# instruction stops at the previous source code line. > gdb_test "reverse-finish" ".*funp \\(a, b\\);.*" \ > "function1 GEP call call from GEP again" > -gdb_test "reverse-next" ".*funp \\(a, b\\);.*" \ > - "reverse next 1 GEP entry point function call from GEP again" > gdb_test "reverse-next" ".*b = 50;.*" \ > "reverse next 2 at b = 50, call from GEP again" > > @@ -212,13 +196,9 @@ gdb_continue_to_breakpoint \ > gdb_test "step" ".*int ret = 0;.*" "step test 2" > > # The reverse-finish command should stop on the function call instruction > -# which is the last instruction in the source code line. A reverse-next > -# instruction should then stop at the first instruction in the same source > -# code line. Another revers-next instruction stops at the previous source > -# code line. > +# which is the last instruction in the source code line. Another reverse-next > +# instruction stops at the previous source code line. > gdb_test "reverse-finish" ".*funp \\(a, b\\);.*" \ > "reverse-finish function1 GEP call, from function body " > -gdb_test "reverse-next" ".*funp \\(a, b\\);.*" \ > - "reverse next 1 GEP call from function body" > gdb_test "reverse-next" ".*b = 50;.*" \ > "reverse next 2 at b = 50 from function body" > diff --git a/gdb/testsuite/gdb.reverse/func-map-to-same-line.c b/gdb/testsuite/gdb.reverse/func-map-to-same-line.c > new file mode 100644 > index 00000000000..17fe17af267 > --- /dev/null > +++ b/gdb/testsuite/gdb.reverse/func-map-to-same-line.c > @@ -0,0 +1,37 @@ > +/* 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 . > + > + This test is used to test the reverse-step and reverse-next instruction > + execution for a source line that contains multiple function calls. */ > + > +void > +func1 (void) > +{ > +} /* END FUNC1 */ > + > +void > +func2 (void) > +{ > +} /* END FUNC2 */ > + > +int > +main (void) > +{ > + int a, b; > + a = 1; > + b = 2; > + func1 (); func2 (); > + a = a + b; /* START REVERSE TEST */ > +} > diff --git a/gdb/testsuite/gdb.reverse/func-map-to-same-line.exp b/gdb/testsuite/gdb.reverse/func-map-to-same-line.exp > new file mode 100644 > index 00000000000..1b23233b43e > --- /dev/null > +++ b/gdb/testsuite/gdb.reverse/func-map-to-same-line.exp > @@ -0,0 +1,140 @@ > +# 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 . */ > + > +# This file is part of the GDB testsuite. It tests reverse stepping. > +# Lots of code borrowed from "step-test.exp". > + > +# This test checks to make sure there is no regression failures for > +# the reverse-next command when stepping back over two functions in > +# the same line. > + > +require supports_reverse > + > +# This test uses the gcc no-column-info command which was added in gcc 7.1. > + > +proc run_tests {} { > + global testfile > + > + clean_restart ${testfile} > + > + if { ![runto_main] } { > + return > + } > + > + with_test_prefix "next-test" { > + gdb_test_no_output "record" "turn on process record" > + > + # This regression test verifies the reverse-step and reverse-next > + # commands work properly when executing backwards thru a source line > + # containing two function calls on the same source line, i.e. > + # func1 (); func2 ();. This test is compiled so the dwarf info > + # does not contain the line table information. > + > + # Test 1, reverse-next command > + # Set breakpoint at the line after the function calls. > + set bp_start_reverse_test [gdb_get_line_number "START REVERSE TEST"] > + > + gdb_breakpoint $bp_start_reverse_test temporary > + > + # Continue to break point for reverse-next test. > + # Command definition: reverse-next [count] > + # Run backward to the beginning of the previous line executed in > + # the current (innermost) stack frame. If the line contains > + # function calls,they will be “un-executed” without stopping. space after comma. > + # Starting from the first line of a function, reverse-next will > + # take you back to the caller of that function, before the > + # function was called, just as the normal next command would take > + # you from the last line of a function back to its return to its > + # caller 2. > + > + gdb_continue_to_breakpoint \ > + "stopped at command reverse-next test start location" \ > + ".*$bp_start_reverse_test\r\n.*" > + > + # The reverse-next should step all the way back to the beginning of > + # the line, i.e. at the beginning of the func1 call. > + gdb_test "reverse-next" ".*func1 \\(\\); func2 \\(\\);.*" \ > + " reverse-next to line with two functions" > + > + # We should be stopped at the first instruction of the line. A > + # reverse-step should step back and stop at the beginning of the > + # previous line b = 2, i.e. not in func1 (). > + gdb_test "reverse-stepi" ".*b = 2;.*" \ > + "reverse-stepi to previous line b = 2" > + } > + > + # Setup for test 2 > + clean_restart ${testfile} > + > + if { ![runto_main] } { > + return > + } > + > + with_test_prefix "step-test" { > + gdb_test_no_output "record" "turn on process record" > + > + # Test 2, reverse-step command > + # Set breakpoint at the line after the function calls. > + gdb_breakpoint $bp_start_reverse_test temporary > + > + # Continue to the start of the reverse-step test. > + # Command definition: reverse-step [count] > + # Run the program backward until control reaches the start of a > + # different source line; then stop it, and return control to gdb. > + # Like the step command, reverse-step will only stop at the > + # beginning of a source line. It “un-executes” the previously > + # executed source line. If the previous source line included calls > + # to debuggable functions, reverse-step will step (backward) into > + # the called function, stopping at the beginning of the last > + # statement in the called function (typically a return statement). > + # Also, as with the step command, if non-debuggable functions are > + # called, reverse-step will run thru them backward without > + # stopping. > + > + gdb_continue_to_breakpoint \ > + "stopped at command reverse-step test start location" \ > + ".*$bp_start_reverse_test\r\n.*" > + > + # The first reverse step should take us call of func2 (). > + gdb_test "reverse-step" ".*END FUNC2.*" \ > + "reverse-step into func2 " > + > + # The second reverse step should take us into func1 (). > + gdb_test "reverse-step" ".*END FUNC1.*" \ > + "reverse-step into func1 " > + > + # The third reverse step should take us call of func1 (). > + gdb_test "reverse-step" ".*func1 \\(\\); func2 \\(\\);.*" \ > + "reverse-step to line func1(); func2(), at call for func1 " > + # We should be stopped at the first instruction of the line. A > + # reversee stepi should take us to b = 2 (). > + gdb_test "reverse-stepi" ".*b = 2;.*" \ > + "reverse-stepi to line b = 2 " > + } > +} > + > +standard_testfile .c > + > +# test with and without gcc column info enabled > +foreach_with_prefix column_info_flag {column-info no-column-info} { > + set options [list debug $column_info_flag] > + > + if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ > + $options]} { > + return -1 > + } > + > + run_tests > +} I haven't followed the discussions around this bug, but it looks like something that was already there, and not a regression I suppose. In any case, I've tested this on aarch64-linux and arm-linux. Works as expected and the code looks OK to me. Tested-By: Luis Machado Reviewed-By: Luis Machado