From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2084.outbound.protection.outlook.com [40.107.104.84]) by sourceware.org (Postfix) with ESMTPS id 6E3F93839406 for ; Thu, 9 Jun 2022 13:04:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E3F93839406 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=FmgC2rushggGfoTwTQKdPg2JbX0ZqP7PQ5kmFrPGMTurJq/1YTmdQ1q+KnWrRPCAXssDDY7/H+Kc6mjH3G389v0lQCJ/wYP1b99XHqU1FTnvIx6c0gQ0Yj65U0WF2bzULSVx5xZ4Z2BqZ2PEaV1vlC4ZzNDuNC2GpWLUcFcVXnIfOansGADzj/QCstqp0Sn0PCOp5sbicPiZxl3vFYjfCKxMsJtZY9/PWH+GAS2p9Vuk6rA+SXlYsgZg6Tu8QKO3U5FiP2oW6Ak2SFKnjLx7+9IP95GyAn5dODuYQAmQRIeSyJdC1tSBBILCUVbirLgPVJHc0XKwXPHpmbkK0kfQvQ== 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=ybbaB+D7723+CTkPbptKSbn1/hENz6CsXDoXH2zGwUo=; b=LDVHehWRGnr1dFUxpCV77tdLjTaWrPMlY18qQn9Y0vvJCd/COijJUlu8INctvV2U3mvRhiqqcsuSgZZsaZCyON5NlOqaiCHKNlQckRWr7+/tX2b6WEYAZbym/y9n6Q4NL8dR1jovkcAKcUzX6iyaf7lSGP6W0J1DYUEu7MSJqOEFTfsdvoAxFBMNDYRf+JU3I99xXSgujj6KxF8CuLwyNaWVwq/6RXs15GyG3RmjUw01b3jueGErcbwVg9JINBla9QfZIRIKDEJXvvkzbtXSMKEs0SNGYQED+qOjg2Cdukdkmw5fEVQi0+igJ2fuU69wRiYuglFgDkKkzcWK4wq+iA== 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] dmarc=[1, 1, header.from=arm.com]) Received: from DB6PR0601CA0007.eurprd06.prod.outlook.com (2603:10a6:4:7b::17) by AM6PR08MB3493.eurprd08.prod.outlook.com (2603:10a6:20b:4a::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12; Thu, 9 Jun 2022 13:04:41 +0000 Received: from DBAEUR03FT061.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:7b:cafe::cd) by DB6PR0601CA0007.outlook.office365.com (2603:10a6:4:7b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12 via Frontend Transport; Thu, 9 Jun 2022 13:04:41 +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 DBAEUR03FT061.mail.protection.outlook.com (100.127.143.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.12 via Frontend Transport; Thu, 9 Jun 2022 13:04:41 +0000 Received: ("Tessian outbound 5b5a41c043d3:v120"); Thu, 09 Jun 2022 13:04:41 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: bf5ac491242ae91b X-CR-MTA-TID: 64aa7808 Received: from f17650319dd9.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7084758C-28DF-4F42-B75A-4AE2F5390419.1; Thu, 09 Jun 2022 13:04:34 +0000 Received: from EUR03-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f17650319dd9.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 09 Jun 2022 13:04:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ITO47n8iye9H1rZngBwRBApTY128lkR3UxfCX4ISkCtlNaqC4ULmGeF/2ZY7k9EsLtJPyAJr1WeuBIlFlLkOn9vqm2BvvtMTvxYSKXPIQVVrjxzZ9p7jJR8C/kX/5fU0ibIMrE1/9IpORkMnDN8+EgaoQB70p6av61QaiTC/QcXfLkTLZ5+fHICxyuHCt95outbn3rCYChBvO8xM2YpgetQpFsbpELDTqBbwbY0JBPUEgLax6C/pnFZfkv6LIkYqHSTeyoWrvqvg9gqEXCtdQIFY6gwsOmpa7U0CZhAdF+t+NOwxjDlAJ1q1GI+EtEt9DDLKEvvR4nnYeP9UxkZh6A== 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=ybbaB+D7723+CTkPbptKSbn1/hENz6CsXDoXH2zGwUo=; b=SGh612a5j0ohvuQ67iFt3FNPjvcPy1erSldgQEu4zv5mhdumTskvFBEx76IIRBXPJvMk5HHlbZX6/14bK98a66+9vWY1xVGz/LNnvrN1PC3gRMjmwwgJs5Qckcg4qQPdCVCp8x9jb7QZa2Cc76US4yrluxN1Yjd7NXaBjbYkJZpxH4meEOQ1PKMdobahJk1QagOaEU/3jvbQxLzf2RanNxej5yqJlDSCRfsO1CuDt5KGMfQdCAtRP+DrEgsvwU4ghEo9xrAw5L9bDI3MJs0unFKggKUWPbzA6qOs0MOkbl4U2SA0vJTG7Sn4euCG037IVHgJH8rj2A4gsda/MoK8KA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB9PR02CA0030.eurprd02.prod.outlook.com (2603:10a6:10:1d9::35) by AM5PR0802MB2577.eurprd08.prod.outlook.com (2603:10a6:203:a1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.16; Thu, 9 Jun 2022 13:04:31 +0000 Received: from DBAEUR03FT045.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1d9:cafe::43) by DB9PR02CA0030.outlook.office365.com (2603:10a6:10:1d9::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.13 via Frontend Transport; Thu, 9 Jun 2022 13:04:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT045.mail.protection.outlook.com (100.127.142.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5332.12 via Frontend Transport; Thu, 9 Jun 2022 13:04:31 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.27; Thu, 9 Jun 2022 13:04:30 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.27; Thu, 9 Jun 2022 13:04:30 +0000 Received: from e129171.arm.com (10.57.38.254) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Thu, 9 Jun 2022 13:04:30 +0000 From: Luis Machado To: CC: , , , , Subject: [PATCH, v6] Fix reverse stepping multiple contiguous PC ranges over the line table Date: Thu, 9 Jun 2022 14:04:21 +0100 Message-ID: <20220609130421.245260-1-luis.machado@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 792be026-becb-4fab-e6c1-08da4a189e0b X-MS-TrafficTypeDiagnostic: AM5PR0802MB2577:EE_|DBAEUR03FT061:EE_|AM6PR08MB3493: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: V3z8ttEgnjCHYEOrKxSagxSNcTU+UboRuZ6wbiqayJB/K9DYgZYZIaB6YOvlegCygG60Ql9yyuzJXh91oMfWC/3VHwaVUX9kLsIOUs77v/5TGIQupDjMWsbTD9mabqsipPIIEl1rVdCcmAlXFnj9EpndgaJFQPpH7FDDmT37x590qYa13KrUc32Mzjwksh2+SKjNAXGT+a4hEOX6u5BZM84jFqRQr4aVlJKNU2STo8pN372SsHjPuRCxV4R1CcJNNiMiOz6NOxYtKnnuolrmyKhl40xHXUcVh7b6KWcUCIrzXmQ3RkEf62OgLz0TWLME+FanIhWgrRjSFjf5y1w9fk4SG1UlSkNoSgsykXnfIpe+zoXzo/98z9NmYZTwto88oc8b2Y9Z3ZhgK3dyDYPbjv6IAvYgx0bM/QxwWUt8gDmLGnsV2otm4yZJ6OqqznSRqFwO7FNN3Vl751j9cpZPAwuJkR/wzY1xxmcGi8gRJRzQMyWMwsx8RdFWRp4fJo964Vak6Q7kJHC4sgqOjwhJ7Aqtxx9gQtTs7ZIbqK8uq8eZSceaLak5dcVRhB7iuQ7VojceJAyHfafijZ59/2MyuWMmQnxtHtwWnVVfQXVFXyIlDFC3FIV3sQ3r2HAKRr4UJmqA4CuMy6vcLl2B8hjN34RmHkoSFezy/qD5RDi8XpzTCdGmg1FotoWpbf580LZLjT/v1HZYUZh5S7nhvZD3tyBHS9fgN6nNEg+IaWf+353oqYKdRHGNfWjf0YRiRqGfy8ZmuOsvk9RwWBnjzrjONYjQDPJcL6TS/7kIc3SDztw31VgjM9ENc6T3xxCfZrKCsb7P+qhSnKxH7O/FlOZO6Zi0D+rUAQzuRNkhZYp2Ykw= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7696005)(356005)(4326008)(30864003)(47076005)(426003)(70586007)(70206006)(8676002)(82310400005)(1076003)(36860700001)(5660300002)(2616005)(186003)(8936002)(336012)(81166007)(83380400001)(26005)(2906002)(6666004)(36756003)(44832011)(84970400001)(86362001)(316002)(54906003)(508600001)(6916009)(40460700003)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2577 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT061.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 353bbe8b-38a0-4ace-91a7-08da4a189804 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F5SV8Ii898FbF3X3nU9BItsgObMe0gE2WxJekpyRmup4Rd891mQBysl/RlhqVaAj/TxQ9NgFsg5YdoFUJzLMZ68xewy+/543yQy1jRM5vnoJ5pj8+YkE7PAJC9TQgM1I/CVXRddFalHwruD2Clz/acUA13aiKadozrBOTbYW81ti90joeDmmsD96f43ctwc5h91jzcXAY9V4dMKSuduDxEzWREjEyYW0DWNs5NlMyMcOnuzBWDW4ElWHqf7vi+u4iYp9hOGazmRs2tbMm6nDUuX67pfh8CxDt/08R6IYxnZiERufGbIStaz8sQUvXzddamk4qy57hQirqXE+1W7AMttsriSsgkriPoECIvQtSu621jtHW11iQq2+unTR5e/yfmcx7qfhay9ZStuLq1tbyw260dDoT69FEFl7hR7TNyQD/GUIXF/oMr2BW8Ifapv7F8cyCoSyxKFmp6zRUkkMd0UyBVklOilnVOdG3N4tU0bSTV68Fdxl9lc9JyrF+HqgQAoCdtOI1IoSUnD2c5tF2XOq4VuNLr7A4HakskiH1UxtgCPXgIe0ciE43uGYo4gNS985+ToK/Zld2rWYubkdDcDz7fbwDrP6tM9uwqTgabYyyLGsEo10oxhfCyETlpys2QEkhD6vKmC5IWCMfDjtJQJ+vVCrNA1N5TVX5I1/uGZbTLpL94UHdA9K9SQiESYR9RbQ3TT0Y7k3lBr1Knt7zv5y9vfLvO+FcDIPSQ0UydWiG7ResaLy8/RfgK1Lj4hBdemiFDPt3xWxUvuVH7Jvgkkwckl6+bgPgXrgKJAAH4AraOAVNdZBmL41j7oJBf2/ 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:(13230001)(4636009)(40470700004)(46966006)(36840700001)(70206006)(4326008)(2906002)(83380400001)(6666004)(508600001)(5660300002)(8676002)(8936002)(70586007)(84970400001)(30864003)(36860700001)(44832011)(81166007)(36756003)(316002)(26005)(186003)(40460700003)(86362001)(2616005)(82310400005)(47076005)(336012)(54906003)(1076003)(426003)(7696005)(6916009)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2022 13:04:41.7597 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 792be026-becb-4fab-e6c1-08da4a189e0b 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: DBAEUR03FT061.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3493 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_DMARC_NONE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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: Thu, 09 Jun 2022 13:04:49 -0000 Sending as a clean new thread. v6: - Fix misc typos and augment the commit message. - Updated source file comments. v5: - Updated test case comments on the purpose of the test. - Add test to check system supports record-replay. - Removed now unnecessary record test when activating record. v4: - Updated testcase to make it a bit longer so it can exercise reverse-stepping multiple times. - Cleaned up debugging prints. v3: - Updated testcase. The format for writing the DWARF program body in the testcase expect file changed. See commit gdb/testsuite/dwarf: simplify line number program syntax (commit d4c4a2298cad06ca71cfef725f5248f68205f0be) v2: - Check if both the line and symtab match for a particular line table entry. -- When running GDB's testsuite on aarch64-linux/Ubuntu 20.04 (also spotted on the ppc backend), I noticed some 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. These GCC changes came into effect with commits 497b7c47042d542ae48d10badf0c3d0088f6f798 and and 0029b929c9719a9794492915206314308fbdf03a. 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. This happens because we have this check in infrun.c:process_event_stop_test: /* When stepping backward, stop at beginning of line range (unless it's the function entry point, in which case keep going back to the call point). */ CORE_ADDR stop_pc = ecs->event_thread->stop_pc (); if (stop_pc == ecs->event_thread->control.step_range_start && stop_pc != ecs->stop_func_start && execution_direction == EXEC_REVERSE) end_stepping_range (ecs); else keep_going (ecs); Since we've reached ecs->event_thread->control.step_range_start, we stop stepping backwards. The right thing to do is to look 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. Another solution I thought about is to merge the contiguous ranges when we are reading the line tables. Though I'm not sure if we really want to process that data as opposed to keeping it as the compiler created, and then working around that. In any case, the following patch addresses this problem. Validated on aarch64-linux and x86_64/Ubuntu 20.04/18.04. Carl Love has verified that it does fix a similar issue on ppc. Ubuntu 18.04 doesn't actually run into these failures because the compiler doesn't generate distinct PC ranges for the same line. I see similar failures on x86_64 in the gdb.reverse tests (gdb.reverse/step-reverse.exp and gdb.reverse/step-reverse.exp). Those are also fixed by this patch. The included testcase (based on a test Carl wrote) exercises this problem for Arm, ppc and x86. It shows full passes with the patch applied. Co-authored-by: Carl Love --- gdb/infrun.c | 22 ++- gdb/symtab.c | 49 ++++++ gdb/symtab.h | 16 ++ gdb/testsuite/gdb.reverse/map-to-same-line.c | 54 +++++++ .../gdb.reverse/map-to-same-line.exp | 141 ++++++++++++++++++ 5 files changed, 281 insertions(+), 1 deletion(-) 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 02c98b50c8c..e9e14e58745 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -6917,11 +6917,31 @@ process_event_stop_test (struct execution_control_state *ecs) have software watchpoints). */ ecs->event_thread->control.may_range_step = 1; + /* When we are stepping inside a particular line range, in reverse, + and we are sitting at the first address of that range, we need to + check if this address also shows up in another line range as the + end address. + + If so, we need to check what line such a step range points to. + If it points to the same line as the current step range, that + means we need to keep going in order to reach the first address + of the line range. We repeat this until we eventually get to the + first address of a particular line we're stepping through. */ + CORE_ADDR range_start = ecs->event_thread->control.step_range_start; + if (execution_direction == EXEC_REVERSE) + { + gdb::optional real_range_start + = find_line_range_start (ecs->event_thread->stop_pc ()); + + if (real_range_start.has_value ()) + range_start = *real_range_start; + } + /* When stepping backward, stop at beginning of line range (unless it's the function entry point, in which case keep going back to the call point). */ CORE_ADDR stop_pc = ecs->event_thread->stop_pc (); - if (stop_pc == ecs->event_thread->control.step_range_start + if (stop_pc == range_start && stop_pc != ecs->stop_func_start && execution_direction == EXEC_REVERSE) end_stepping_range (ecs); diff --git a/gdb/symtab.c b/gdb/symtab.c index 8564986f66d..9625ad7aa8a 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3390,6 +3390,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. */ + +gdb::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 with the search. */ + 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 ac902a4cbbe..500faf7d93b 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2286,6 +2286,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 gdb::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..89a1898bdc2 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/map-to-same-line.c @@ -0,0 +1,54 @@ +/* Copyright 2022 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 source file provides dummy code that is only meant to force the + compiler to generate instructions for the various labels. The TAG markers + are used by the testcase to generate DWARF information and line tables. */ + +int +main () +{ /* 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"); + 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..fd958ba114b --- /dev/null +++ b/gdb/testsuite/gdb.reverse/map-to-same-line.exp @@ -0,0 +1,141 @@ +# Copyright 2022 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 multiple entries +# for the same line to do the needed testing. + +load_lib dwarf.exp + +# This test can only be run on targets which support DWARF-2 and use gas. +if {![dwarf2_support]} { + unsupported "dwarf2 support required for this test" + return 0 +} + +if [get_compiler_info] { + return -1 +} + +# The DWARF assembler requires the gcc compiler. +if {!$gcc_compiled} { + unsupported "gcc is required for this test" + return 0 +} + +# This test suitable only for process record-replay +if ![supports_process_record] { + return +} + +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_end_sequence + } + } +} + +if { [prepare_for_testing "failed to prepare" ${testfile} \ + [list $srcfile $asm_file] {nodebug} ] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Activate process record/replay +gdb_test_no_output "record" "turn on process record" + +gdb_test "tbreak main_return" "Temporary breakpoint .*" "breakpoint at return" +gdb_test "continue" "Temporary breakpoint .*" "run to end of main" + +# At this point, GDB has already recorded the execution up until the return +# statement. Reverse-step and test if GDB transitions between lines in the +# expected order. It should reverse-step across lines 8, 5, 3, 2 and 1. +foreach line {8 5 3 2 1} { + gdb_test "reverse-step" ".*TAG: line $line.*" "reverse step to line $line" +} -- 2.25.1