From patchwork Fri Jul 5 09:16:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 93409 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FA50382E6BE for ; Fri, 5 Jul 2024 09:17:05 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn20811.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1a::811]) by sourceware.org (Postfix) with ESMTPS id 79241384386C for ; Fri, 5 Jul 2024 09:16:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79241384386C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=hotmail.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hotmail.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 79241384386C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f400:7e1a::811 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1720171003; cv=pass; b=vn78E/p0G0KQge5JsvIIAJ8Zpj6YdhhmAek04KJuGrIii2vzPl4WC4618icO/0A0W0XINzdBzLOaZIdzC7VukI4hlzhrGXW6u9dQvzDh8C94QJ6jChwDCrj3KkAeAwseQRhUO0nDwKIeDtUnOc5v0tZ1jnx8FuIztLEKMTp5ozQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1720171003; c=relaxed/simple; bh=cL7fv1yLzEIDcM3CvJTD8SYhis79uyVmFTMy92BbpA0=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=OiM1yd9+EJBA1kUkwWEvyBv3+eOg3OT0FQtlBaGxTgpvLb/wzBfakWesadCQbveXTQqeYrQe6UvJp+St6SNVkj98kSo6QwfPylEXBOKxxEriIBA0TBmuPgn/4WkdFXeJSGnFls9HtMtMYPn6hphxviuDdbX8DswiGWqqvKaaFbA= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cYZXlv4fP9V2SFYdujzkSPsGefA4lp7jwVW57bmZFNSyIPJgpkNSHDj4zO3VlvxJBaQK8yGRfo3qSr3oYRMO+n9wRP3woct1ZS1c5+OxTlgb46XKYJ7sjxj1dqkIrSjf5R+RqYKqOydI0TeB1qXrKkA2lLWk9y1VAYWWqGPvD0qRInB2wzgf9rXFQrPaREcUl1T6NGlo64bgE0aqtmRXg2XgG6Sz7R4/YvCHkppPRGI+2+BiX9v5tmi0JQ5lw+zQt2kXhNTrVJyoP8G91HNw/yQltd29T7bjLU61qCbS2kG+V534STRJNaz9MnprjZdmTLBQdpcl3ManJSbl+2+PbQ== 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=wIXMuAs0hhZfupkusJhh6UvvjV8SEtQz90tTvbIAoEg=; b=K0a/euRgOLLCpeiEq/0d7wjsFNxaL2OD6glXvOMaCJG0gYXe2pC+ImHMgZE/MXgN6N6pYV+RWlkUfiKgvSE2SDllutiEl2o/N9rRapnyjKGa/I5uJCThGZaK2B/ga6K+golv+SgRGrl2tPlmBHNgMfra+c8Vp0KlG5/nePinNgkhNlGas1WbNQv9a7W0tVTaEMa5J+khqq0K8IamHOkppSSHh1lDkyJNH8JW0u2ys8I64hqeJcF2v5bpsvuIy/wsE9EEso9XqH4haz29Kfo7OtnoakFbf6tcTlCcbng1iHmJ6BHYoWDeJusrJkY33dEa4VTppQcbeBHHavZ22UYQIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=HOTMAIL.DE; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wIXMuAs0hhZfupkusJhh6UvvjV8SEtQz90tTvbIAoEg=; b=iJuSa2LWeHJkhtKw/XSLKpeoFjuuaxYoOakpOLIKCs3a7+cBdIbe94N8x4jFMIO7JDyzvgnfGEwESEn1NY4/9mPTzLPxglJUY0f6JT4Ewma+SHyYXbaPyaR/wWk5jrDKKrcQR4Ip90joJptN02kruYD6+tJtKu7EfMqNUHSn86DSL7X70xsSB6CGz4BgwzNOQvSMCqiRONmo+Y9P8ONJz9C/Cmvejj/VNuIP1AXCMEJgmuXyBI/6/zE/PglbK1/C0/62ADj1PXynC1QCV6PwHPPodMxvLd5F70zgRQEl6SzAIubRVZo2BGAo7qppcs+HBIFka5zoK5gdZwgn5YnQGA== Received: from AS8P193MB1285.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:333::21) by GV1P193MB2344.EURP193.PROD.OUTLOOK.COM (2603:10a6:150:2c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.29; Fri, 5 Jul 2024 09:16:39 +0000 Received: from AS8P193MB1285.EURP193.PROD.OUTLOOK.COM ([fe80::e65d:5dd2:5662:c61f]) by AS8P193MB1285.EURP193.PROD.OUTLOOK.COM ([fe80::e65d:5dd2:5662:c61f%6]) with mapi id 15.20.7741.029; Fri, 5 Jul 2024 09:16:39 +0000 Message-ID: Date: Fri, 5 Jul 2024 11:16:11 +0200 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "gdb-patches@sourceware.org" From: Bernd Edlinger Subject: [PATCH v3 1/3] Fix handling of DW_AT_entry_pc of inlined subroutines X-TMN: [qTgpLd9lSWVnmZgu6xZWwEBRal5WsrWizj5fzJNl7LzYuBSvt3uTwBoNGl2u52zo] X-ClientProxiedBy: FR5P281CA0039.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f3::18) To AS8P193MB1285.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:333::21) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P193MB1285:EE_|GV1P193MB2344:EE_ X-MS-Office365-Filtering-Correlation-Id: 33786e7c-4f04-4962-d5ff-08dc9cd32d15 X-Microsoft-Antispam: BCL:0; ARA:14566002|19110799003|8060799006|461199028|3412199025|440099028; X-Microsoft-Antispam-Message-Info: ixNtsvcA8ecKpJ4iOir7Ut2PETwZXAXH/YZkmxIAgjfoNzkjyAZiAeBwp9p7AauUQw//pEEF7VgyHZIERHiXrmhsgqbocfotXtcrrK+5ifklqdSyRbNP29vG/2yGdGZOfqh6nRU4v0RKVElgH4OpA5tQETEfIS5X+ogrjel8wxT6DWCSbc1zC8Q/ixtRRhp9xKDplKBUAxIvxcHDNhdQXxnxfhGaMDZbg3doYxSqSIc22Rr/VLfhDp9OhsHXmu/pa5mCVwgmojDkXnvge+y2b//mR/Kec2tRSKCAscoSfdF/WMj2CupJYmPC6HrJBNY/MrJqrHNitfWvAMGGNWMTG67ruBAfnJvlhCZ9RMJ6WgiRI/DRCTD7ivSRD7wBlIYYj2o2jVZQmp6UJB9WTzodFVJTJ1ScJ3zJsou6XONSk40u8sfB8FNK3fMXfDdGPy7tgN489lYds9MmeVvj4No4LCNLBfo8CNi7/PxmDfN+XY+4aq0sL6ocfGADdpO2aCSoxO8NaaIN3epP7vxV4QRL8ReJTmJ6a/IBDS6ukbP6u8PqJ+rspfScFohxXfU32lxgXzzUd164n7o2F2haSkRC03hJO86739NWCmNgKKzsADPDF5ufari2wttCZN+iDKmAExIFAivvK36ggAanSPJTCg== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rRKkXxCmwzF7z0GSHdWN5Z1V9tUg?= =?utf-8?q?iGSlrfz+5D+N496JYsvuj/9xpv4D+5hJa4Vc/dF8RTgzs+v61+suSFcYVxVNysM6v?= =?utf-8?q?HgGxRL4dyH5WI9tPRfMrWxBiyMOskmLhk+VOrb5DKSpJMomnq4SIOqJjZdRKdsIu0?= =?utf-8?q?jrRKHrzLv9Lq+yrnh46AHOQ5itmzDWdT0BLAvF647bfnF7yMQnfIIhRNW28gkzk92?= =?utf-8?q?pd6j1bp67kSx5SmmmzUs/WjZqVU2aC6gQ8UYcSADBqlRqiLVuLCmRN0niRLDhcSN6?= =?utf-8?q?Vi9ql97MLRGXlwQccra3jMB7HIImYgJdQvd6lYC1nhiqzaZZ5XY2uNmAC305qktuE?= =?utf-8?q?rQYNPGKnvlN9+RdlSW6BeueoipgzTQctMC7+PzquNMV+FWbiDbRBTN6a1P576UljT?= =?utf-8?q?yA5bmg2Fb/1vB9F9/cPNlv43aOlYfyrVv3HLWvmdcZu+xHFqg1GMTHmPpbfrK2YGm?= =?utf-8?q?XKDqZTo9GGEPtJSAFDbys21ofFLmsRu4V2D5ocE1wRBSxgYi37G0zotS7JQN5DOcW?= =?utf-8?q?veIoVaQ/WfO2vuWvxg1IUnWyK7F5T8mvJjK5bEXykVVdM2n+egApQn5TPnn4CDPTK?= =?utf-8?q?j7HAQXF/Cg2Xfr5G4NqsBl9zDJg3K8SsJPnKo4pOC031MZt8RBa+tgQDGFc8w2Yrm?= =?utf-8?q?Vw2wDKA4HzESgec9bi4nhEKdgWFmULzvVggjPb04U9aihmBewVn7Iwseza+IF3uvG?= =?utf-8?q?FStS9MsmeN+K85ToJpGe3DkqlxgjfJOCLC9/uI0k+Q5kB2h5k/nju6tk+xb2NW2gK?= =?utf-8?q?+AkuOdvvHNUuoaDcHBybHdNAW1fratINX0Jh9oWKduSLC08gChn5CXqZLXsorH55N?= =?utf-8?q?cO7fJA2J8QM25vVp35FDmAO7GYHtza94RUd+P4OwRI3MkW1WrYOK6uJRnP8+3QGY8?= =?utf-8?q?6R3RKHBzSw9p5xNPyN58ZpaEmqCODa1c3TXJfQGhDiT8XLSHlz/TnUDBX/H2+GTXE?= =?utf-8?q?E3K2uG8RWz4amY9PO0Gha4BL/eObBsOwsGMH3qFwMsu8JdlSCaIbuFv4YV/0JqLQp?= =?utf-8?q?aTrF76giY103RrU4/FQugQU/owyO9fQsN4DOf4VV9y6TFJ1P8FXQpeU8kRNd23xCq?= =?utf-8?q?QBITljycr0xI+2KTERqDW5lio4yH4yuqY/ncCLPPaNmBrhOoRaTfz6EvsGPLXheyV?= =?utf-8?q?PoZ9A7jqDNfAqQIZfAzCJTPo1aexE02fEZJV6vqwyWu7lIHpISX1FQWaUseInSArt?= =?utf-8?q?qljjelyAKkuRRdEcdGrDchiWBF4UWomIfoRiuob29oST4rv7Gd0Jv9xQszPCEMLOF?= =?utf-8?q?kGUEZdiCenbdWmL+?= X-OriginatorOrg: sct-15-20-7741-18-msonline-outlook-01732.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 33786e7c-4f04-4962-d5ff-08dc9cd32d15 X-MS-Exchange-CrossTenant-AuthSource: AS8P193MB1285.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2024 09:16:39.0398 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1P193MB2344 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org It may happen that the inline entry point is not the start address of the first sub-range of an inline function. But the PC for a breakpoint on an inlined subroutine is always the start address of the first sub-range. This patch moves the sub-range starting at the entry point to the first position of the block list. Therefore the breakpoint on an inlined function changes in rare cases from the start address of the first sub-range to the real entry point. There should always be a subrange that starts at the entry point, even if that is an empty sub-range. --- gdb/dwarf2/read.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 71237d0fba8..60fd8b45eb5 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -11246,6 +11246,16 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block, if (die->tag != DW_TAG_compile_unit) ranges_offset += cu->gnu_ranges_base; + CORE_ADDR entry_pc = (CORE_ADDR) -1; + if (die->tag == DW_TAG_inlined_subroutine) + { + attr = dwarf2_attr (die, DW_AT_entry_pc, cu); + if (attr != nullptr) + { + entry_pc = per_objfile->relocate (attr->as_address ()); + } + } + std::vector blockvec; dwarf2_ranges_process (ranges_offset, cu, die->tag, [&] (unrelocated_addr start, unrelocated_addr end) @@ -11255,6 +11265,8 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block, cu->get_builder ()->record_block_range (block, abs_start, abs_end - 1); blockvec.emplace_back (abs_start, abs_end); + if (entry_pc == abs_start && blockvec.size () > 1) + std::swap (blockvec[0], blockvec[blockvec.size () - 1]); }); block->set_ranges (make_blockranges (objfile, blockvec)); From patchwork Fri Jul 5 09:17:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 93410 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A50F382E6BA for ; Fri, 5 Jul 2024 09:18:26 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn20828.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1a::828]) by sourceware.org (Postfix) with ESMTPS id C06D83844033 for ; Fri, 5 Jul 2024 09:17:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C06D83844033 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=hotmail.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hotmail.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C06D83844033 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f400:7e1a::828 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1720171076; cv=pass; b=xuuKov7zIXl7DUTtBdTSdD6OD7cO8WKg4ujAfAMOhJpHm5AdrdaEA92xyfrvml9hTnOwxcz3JaI5aQ4ISidY1G1+ciNC8ASTPDIj5ptuclBW5s4iHHco7Bgh/FoMJMJVPE5EsNgBjuDqhVGrCBVnNnoNaWa4IFU771nxf2XfSDY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1720171076; c=relaxed/simple; bh=Lo6eXghjM18rt07OHp/luuP9jajCVBpJAtNwqEg3DJo=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=xfxdQuUKsxVu+zg0SdGqChLRlmOdAXL+kbdwC28A+QM7ehBZV66CZwi4ebSqVld5gUaEbVHiTLI2kfYn+ZppbZuk+qnTcvC70iqOWLQeu3kgsi9K7c1Yv8hSCt9GKlsh98PxZ6tlARt+xN6YndvlbxeVOiIleafjv4fkkshkEBg= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E/7o80TwY2j0K+HeCZs3/r0yWfmrhALEUut8zH3+bMWKgnKVYfkquM67oExNIt3J/pAmnO/ylk1rGT0ON92THcXVNcE21GTekq0W8NEDyLsnhgfzKaS85svuzqxj+YbIKrFvuI0RZBVOKvc8EuYIuOkIXgsA2ZARx5VFjB/vQZ0Cqk/jEvZv0w8gg5AF9ze8jQR959e72fkVH3+uV+BybTR+b7JURQV68+yqsAHHZQNaI1yXGHE8j87eiH8z2vD9dwGxPm6rEXB+II2icteDuOImB9ITBoBDkCOY8YMJHB56v6cqhGPOyVsYWRIcm/OzFFN0vyo47q/B5rETIlO4qA== 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=x/lJsaahhURzbGlqUUATlDk13jSIjv/FbDbUFYdzies=; b=LNGypk9tcU3hOOKrzCpgeMt/BBLXywumM93LGRSlYx7ZtLiBmjMdZiWwN/mi7TfIpdAFICkBHUUhxyt42wRaPkkdng9PJV6dB4VTi+v3PETeXTF7TQ7vdH9ls5pf3m1ctDJT6GiwHrJrMtVqr0Z0Bz4bHhuxhnq9o6wWpvxnV0rC/OGuFJYS8kQ/tdla65vsnzlop/I5D650tOZF/iL5LET1CINIvMg8AIaqQ5uwhxGq9RjdyeOFdO2BuI/l6KFgE5XCpUpPhSRIjKd0+8ZuwwQbAlwTiEQUCbOZDh3wB0FZCfRD+MK7ywGpd1SV/0kCnIbyRucTqtGaF/vu6DeytA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=HOTMAIL.DE; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x/lJsaahhURzbGlqUUATlDk13jSIjv/FbDbUFYdzies=; b=Y8VkfLPVt7pDIm0S24bU38tkPWfXML+xLD47TNWu2DsiCZ5k/Ri5KVEMHX+xny5dBmm9mfQpYsjttaxEWi4ezDJsD6VK4jKCGck6T9gyB0QQ33twn6aKIH4fh9LrL2MtRMyPE8TVF+XBp2fMIpZrFahSAUbFucfERvowo86RMrHEU++xZzAaXSIssUb6+QxIb79KXmIBviiUlRae1A+t/hnfNyWVvk0p83W/GB0TcwHakvZFtPt1NbGd8xtVKQEZDS/ZjAmI8ILMTY+QDSkmT7ITKNGT5v/I4p673DfHcjRFP3f/JP0ReHhquvsrARlZrk9RQCCVubmmX6bXLQ24Gg== Received: from AS8P193MB1285.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:333::21) by GV1P193MB2344.EURP193.PROD.OUTLOOK.COM (2603:10a6:150:2c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7698.29; Fri, 5 Jul 2024 09:17:43 +0000 Received: from AS8P193MB1285.EURP193.PROD.OUTLOOK.COM ([fe80::e65d:5dd2:5662:c61f]) by AS8P193MB1285.EURP193.PROD.OUTLOOK.COM ([fe80::e65d:5dd2:5662:c61f%6]) with mapi id 15.20.7741.029; Fri, 5 Jul 2024 09:17:43 +0000 Message-ID: Date: Fri, 5 Jul 2024 11:17:15 +0200 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "gdb-patches@sourceware.org" From: Bernd Edlinger Subject: [PATCH v3 2/3] Introduce a new line table flag is_weak X-TMN: [9kOVKVARCf/G/E40Jj7VrlARjYu9okBwzVeVzCXLSxRL7tVzYiBZ85c9RZH6VJA4] X-ClientProxiedBy: FR5P281CA0032.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f3::6) To AS8P193MB1285.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:333::21) X-Microsoft-Original-Message-ID: <30bb326d-c955-4d14-88a1-08f486567aa0@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P193MB1285:EE_|GV1P193MB2344:EE_ X-MS-Office365-Filtering-Correlation-Id: f6ac8748-196e-4210-f81d-08dc9cd35366 X-Microsoft-Antispam: BCL:0; ARA:14566002|19110799003|8060799006|461199028|3412199025|440099028; X-Microsoft-Antispam-Message-Info: 384msQ0nElxbe2vCNkCG85lVYs3SPCpeTHgtuqkOl2WR27xubIAjZDC4sLCFo75b+ocQDmYI9aRBQmkiH1Xd/OwmyVzZZlb26cJH90zAVrlO3eybL3VHWudyhZ7BxlKok9kbxr5+b1wicaQ8j7Bu1UT3l10NuZfMbovrB1UL8HUB5clCmZCoDje2GOdMaHYpLVl5mJC2VhpP9lI+eo4b6hTEMVtpixy2qsZc/K6TSRY9CnDVdh9a1MvGb0HHC4OLoXfqbU9o3CgN76OcbkZrifx2gCnGysjJ+LO1K+CqOj8NxxTmaKkcmkHNJUZp/UQQ12D7ATQRklu3PZq4PkT9uC3mP9EvOHKDh4aZxx6xGUN360NGcMS2YsTCNHQRKZHw2kcIRbWFoi6o43VjKyWBP1lR3nUb8nySuSK5w0cy+zHs1dPLLM+kjXbTj0oTGnY3hnLra3WFJ8V8jmC3GfuQj4STthS62eQ1IaDpffKhSlCD1f3FJywmNMlih8dN77OkBY669xXM63so7fmcIX7u9VMwE476rWeLdf+q/caSFgfEz11sA6kqMED2M4RWjhSHgbzzb/waWX6x53MnmIyQ2Ex1rid88aLDf6+v0xxXh3uHnBaA9Z9c/TZG0FYpejl4jBfGN2R1/07hsYcW4/rlbw== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?gsPSwmbeQhyM3Jk2fII9zBpDTxwe?= =?utf-8?q?qdjHT8tkAYMYt6ug65MAtfkBnKHCBVizFBZx8vMb3HUGWAA8eHCj6weKkcpkLjL3U?= =?utf-8?q?MM4AEYMJ26yQ4IEMc4HHqhK/KkU82GOkPlNaVX67b5LKzFZ+V/OoFUGV3mOvl6pxb?= =?utf-8?q?fBYnvYFaVR6VuNRPDjsRloUFisDxWankw09aQFDsQKDVumfWc03BD6qIfr2CxRv6P?= =?utf-8?q?q5hr2EHTZruSGpBNLuhv8gLZjBhPPmd5DqJ5Dp2aNfHviXsLRQ2k89mHn7M2joCR7?= =?utf-8?q?yK983Pub9lOomQmJMeltyHQGNuE8TzLlM2MB5B0SZCfMEJK6l8I1qbsg5AcAS1uja?= =?utf-8?q?6LYKSlfYUMpd1O0qRZ+jsU5KUJpY+GSYbP3Mdequa/8lSQ3SrwcQcqGMLAJ11JxB6?= =?utf-8?q?1dPRsuznGpyZ7vgj6ce3Kw8LBRLfIDHJI26EBjI3VWqWmUMVuluRI1ZjNaMrwp1HH?= =?utf-8?q?2/Vs0Fcv71r/1/81l+eX475BBviB46yRtUkcl9twVfyZBYvGIoXlenQPEoG6TOAPl?= =?utf-8?q?lYQEePoBWswn6uy1GNUPyGGK2Kn6Gfhf4/4O3zdNbWSCUkct9eSFoZsTpfqfGZ16h?= =?utf-8?q?C7+L4YJto04ajYFHV1U/RsF4fRhXmO8DILfL6Ij3WKC70temgc9G598zKIWCUnXbK?= =?utf-8?q?cQ3iekL1TI2c9Oj93Z3vxaq104yKgtA8NXinLWAm636geqoXclFRGW0vHHq6gt/5U?= =?utf-8?q?+jCLwK3cbV5Z9JE9eBpiiYSDhliih8SnBGvhTNathAo4uQAKwviNY6eftqgRfLpRB?= =?utf-8?q?YQfoDsps59ql4dF9QzyppSxClY0hMqvm07PV0ipuHNZ9xODoiQnoCKj+eM7hsmWiH?= =?utf-8?q?c1/oMfaJXCEZVy62mbR2Y0wiKl0ElNONCPB52RWL1rwT4g4ufhSRoDaCqww5jZKui?= =?utf-8?q?nq+vlb3rJpn2tRmLhjegB/OZHq/492yhaK/DZLEXl79QT7qUY8OBPE2p4R+xC8/3G?= =?utf-8?q?A+iI5d2L4MXFL+HvbS/DJzZxwAT1YyKlYLY35NFscJMs5RaEx9nLQHFJ6GTdWP1kt?= =?utf-8?q?PZEvzNmzyk8GN8XxqbM2YA6F7PC+p+A7x1owrmQSlhorotW0tEElZFN+NdHGEQX+y?= =?utf-8?q?gTuXy5ZmKwHJr2iiAVLs1GY+KCHsrG/O94Xh5y7WwI4aIVpwUmCoN+0txm5qkQBOX?= =?utf-8?q?3DmkJoFlD7dHGwi8hbTVcO4W5RNl5lBP7hNEJqZDf4lVhi0rHdNL6YFil4KZisZ9a?= =?utf-8?q?P9tySz4/ltrrhJTC1EcFCQGQ48iKgcXMtUfPSSK6WmWRv4yHBuf9g2Blug+VdjGxd?= =?utf-8?q?mSdQm+VMiWbhE6aY?= X-OriginatorOrg: sct-15-20-7741-18-msonline-outlook-01732.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: f6ac8748-196e-4210-f81d-08dc9cd35366 X-MS-Exchange-CrossTenant-AuthSource: AS8P193MB1285.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2024 09:17:43.3156 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1P193MB2344 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This introduces a new line table flag is_weak. The line entries at the end of a subroutine range, use this to indicate that they may possibly be part of the previous subroutine. When there is a sequence of line entries at the same address where an inline range ends, and the last item has is_stmt = 0, we force all previous items to have is_weak = 1. Additionally this adds a "fake" end sequence to the record_line function, that is line number -1. That will be used in the next patch. Finally this adds a handling for empty ranges to record_block_range. Currently this function is not called with empty ranges, but that will be used in the next patch. There should be no functional changes after this commit. --- gdb/buildsym.c | 106 ++++++++++++++++--- gdb/buildsym.h | 3 + gdb/jit.c | 1 + gdb/symmisc.c | 6 +- gdb/symtab.h | 5 + gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp | 2 +- gdb/xcoffread.c | 1 + 7 files changed, 109 insertions(+), 15 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 1c762ad81bf..9bf2fff6e29 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -413,6 +413,16 @@ buildsym_compunit::record_block_range (struct block *block, || end_inclusive + 1 != block->end ()) m_pending_addrmap_interesting = true; + if (block->inlined_p ()) + { + m_inline_end_vector.push_back (end_inclusive + 1); + if (end_inclusive + 1 == start) + { + end_inclusive = start; + m_pending_addrmap_interesting = true; + } + } + m_pending_addrmap.set_empty (start, end_inclusive, block); } @@ -627,19 +637,16 @@ buildsym_compunit::record_line (struct subfile *subfile, int line, { m_have_line_numbers = true; - /* Normally, we treat lines as unsorted. But the end of sequence - marker is special. We sort line markers at the same PC by line - number, so end of sequence markers (which have line == 0) appear - first. This is right if the marker ends the previous function, - and there is no padding before the next function. But it is - wrong if the previous line was empty and we are now marking a - switch to a different subfile. We must leave the end of sequence - marker at the end of this group of lines, not sort the empty line - to after the marker. The easiest way to accomplish this is to - delete any empty lines from our table, if they are followed by - end of sequence markers. All we lose is the ability to set - breakpoints at some lines which contain no instructions - anyway. */ + /* The end of sequence marker is special. We need to delete any + previous lines at the same PC, otherwise these lines may cause + problems since they might be at the same address as the following + function. For instance suppose a function calls abort there is no + reason to emit a ret after that point (no joke). + So the label may be at the same address where the following + function begins. There is also a fake end of sequence marker (-1) + that we emit internally when switching between different CUs + In this case, duplicate line table entries shall not be deleted. + We simply set the is_weak marker in this case. */ if (line == 0) { std::optional last_line; @@ -659,15 +666,84 @@ buildsym_compunit::record_line (struct subfile *subfile, int line, if (!last_line.has_value () || *last_line == 0) return; } + else if (line == -1) + { + line = 0; + auto e = subfile->line_vector_entries.end (); + while (e > subfile->line_vector_entries.begin ()) + { + e--; + if (e->unrelocated_pc () != pc) + break; + e->is_weak = 1; + } + } linetable_entry &e = subfile->line_vector_entries.emplace_back (); e.line = line; e.is_stmt = (flags & LEF_IS_STMT) != 0; + e.is_weak = false; e.set_unrelocated_pc (pc); e.prologue_end = (flags & LEF_PROLOGUE_END) != 0; e.epilogue_begin = (flags & LEF_EPILOGUE_BEGIN) != 0; } + +/* Patch the is_stmt bits at the given inline end address. + The line table has to be already sorted. */ + +static void +patch_inline_end_pos (struct subfile *subfile, struct objfile *objfile, + CORE_ADDR end) +{ + std::vector &items = subfile->line_vector_entries; + int a = 2, b = items.size () - 1; + + /* We need at least two items with pc = end in the table. + The lowest usable items are at pos 0 and 1, the highest + usable items are at pos b - 2 and b - 1. */ + if (a > b + || end < items[1].pc (objfile) + || end > items[b - 2].pc (objfile)) + return; + + /* Look for the first item with pc > end in the range [a,b]. + The previous element has pc = end or there is no match. + We set a = 2, since we need at least two consecutive elements + with pc = end to do anything useful. + We set b = items.size () - 1, since we are not interested + in the last element which should be an end of sequence + marker with line = 0 and is_stmt = true. */ + while (a < b) + { + int c = (a + b) / 2; + + if (end < items[c].pc (objfile)) + b = c; + else + a = c + 1; + } + + a--; + if (items[a].pc (objfile) != end || items[a].is_stmt) + return; + + /* When there is a sequence of line entries at the same address + where an inline range ends, and the last item has is_stmt = 0, + we force all previous items to have is_weak = true as well. */ + do + { + /* We stop at the first line entry with a different address, + or when we see an end of sequence marker. */ + a--; + if (items[a].pc (objfile) != end || items[a].line == 0) + break; + + items[a].is_weak = true; + } + while (a > 0); +} + /* Subroutine of end_compunit_symtab to simplify it. Look for a subfile that matches the main source file's basename. If there is only one, and @@ -892,6 +968,10 @@ buildsym_compunit::end_compunit_symtab_with_blockvector relationships, this is why std::stable_sort is used. */ std::stable_sort (subfile->line_vector_entries.begin (), subfile->line_vector_entries.end ()); + + for (int i = 0; i < m_inline_end_vector.size (); i++) + patch_inline_end_pos (subfile, m_objfile, + m_inline_end_vector[i]); } /* Allocate a symbol table if necessary. */ diff --git a/gdb/buildsym.h b/gdb/buildsym.h index c1eed247d25..edf76c8b17c 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -446,6 +446,9 @@ struct buildsym_compunit /* Pending symbols that are local to the lexical context. */ struct pending *m_local_symbols = nullptr; + + /* Pending inline end range addresses. */ + std::vector m_inline_end_vector; }; diff --git a/gdb/jit.c b/gdb/jit.c index 797be95a8da..2f714268920 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -495,6 +495,7 @@ jit_symtab_line_mapping_add_impl (struct gdb_symbol_callbacks *cb, (unrelocated_addr (map[i].pc)); stab->linetable->item[i].line = map[i].line; stab->linetable->item[i].is_stmt = true; + stab->linetable->item[i].is_weak = false; } } diff --git a/gdb/symmisc.c b/gdb/symmisc.c index b4e0360041e..567ec270f3c 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -265,6 +265,8 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) gdb_puts (paddress (gdbarch, l->item[i].pc (objfile)), outfile); if (l->item[i].is_stmt) gdb_printf (outfile, "\t(stmt)"); + if (l->item[i].is_weak) + gdb_printf (outfile, "\t(weak)"); gdb_printf (outfile, "\n"); } } @@ -973,12 +975,13 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data) /* Leave space for 6 digits of index and line number. After that the tables will just not format as well. */ struct ui_out *uiout = current_uiout; - ui_out_emit_table table_emitter (uiout, 7, -1, "line-table"); + ui_out_emit_table table_emitter (uiout, 8, -1, "line-table"); uiout->table_header (6, ui_left, "index", _("INDEX")); uiout->table_header (6, ui_left, "line", _("LINE")); uiout->table_header (18, ui_left, "rel-address", _("REL-ADDRESS")); uiout->table_header (18, ui_left, "unrel-address", _("UNREL-ADDRESS")); uiout->table_header (7, ui_left, "is-stmt", _("IS-STMT")); + uiout->table_header (7, ui_left, "is-weak", _("IS-WEAK")); uiout->table_header (12, ui_left, "prologue-end", _("PROLOGUE-END")); uiout->table_header (14, ui_left, "epilogue-begin", _("EPILOGUE-BEGIN")); uiout->table_body (); @@ -999,6 +1002,7 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data) uiout->field_core_addr ("unrel-address", objfile->arch (), CORE_ADDR (item->unrelocated_pc ())); uiout->field_string ("is-stmt", item->is_stmt ? "Y" : ""); + uiout->field_string ("is-weak", item->is_weak ? "Y" : ""); uiout->field_string ("prologue-end", item->prologue_end ? "Y" : ""); uiout->field_string ("epilogue-begin", item->epilogue_begin ? "Y" : ""); uiout->text ("\n"); diff --git a/gdb/symtab.h b/gdb/symtab.h index a5631a27b5e..9b2b297fb3a 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1656,6 +1656,9 @@ struct linetable_entry /* True if this PC is a good location to place a breakpoint for LINE. */ bool is_stmt : 1; + /* True if this PC is at a subroutine range end. */ + bool is_weak : 1; + /* True if this location is a good location to place a breakpoint after a function prologue. */ bool prologue_end : 1; @@ -2412,6 +2415,8 @@ struct symtab_and_line /* If the line number information is valid, then this indicates if this line table entry had the is-stmt flag set or not. */ bool is_stmt = false; + /* True if this PC is at a subroutine range end. */ + bool is_weak = false; /* The probe associated with this symtab_and_line. */ probe *prob = NULL; diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp index 1a3d53c2116..403bc6b3f72 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp @@ -168,7 +168,7 @@ gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \ -re ".*linetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" { exp_continue } - -re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+REL-ADDRESS\[ \t\]+UNREL-ADDRESS\[ \t\]+IS-STMT\[ \t\]PROLOGUE-END\[ \t\]EPILOGUE-BEGIN *\r\n" { + -re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+REL-ADDRESS\[ \t\]+UNREL-ADDRESS\[ \t\]+IS-STMT\[ \t\]IS-WEAK\[ \t\]PROLOGUE-END\[ \t\]EPILOGUE-BEGIN *\r\n" { exp_continue } } diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 639dd5b8adc..1642bc12dfb 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -431,6 +431,7 @@ arrange_linetable (std::vector &old_linetable) linetable_entry &e = fentries.emplace_back (); e.line = ii; e.is_stmt = true; + e.is_weak = false; e.set_unrelocated_pc (old_linetable[ii].unrelocated_pc ()); } } From patchwork Fri Jul 5 09:18:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 93412 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C0C533882656 for ; Fri, 5 Jul 2024 09:19:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05olkn20801.outbound.protection.outlook.com [IPv6:2a01:111:f403:2e13::801]) by sourceware.org (Postfix) with ESMTPS id 52D86384403E for ; Fri, 5 Jul 2024 09:18:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52D86384403E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=hotmail.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hotmail.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 52D86384403E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:2e13::801 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1720171137; cv=pass; b=IRFPfTBgFFn3z7G2V/txQTE6IRyH+OPuKVZa42H08YGGsv4qECQBNTQ0gEIF3sNiuupJL1DzEq89EGUyldiTrY6zwi+k76ha88koKlrLJakbBIY0BPfxUlGpWFs56TRDjv+4QLUSYH4hzRDDXSLpweDEBXy7VRcyGkxcjcZTAZY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1720171137; c=relaxed/simple; bh=S3dYK13uaqqPsmp+WJ3ugtUsWN/0+U8ohjfu/Suliio=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=frQFvdwITzD9atHmp3au8y2A7czfWJxGhf+IGKhPDP+JLkSa6juR0uVVTXTX+jY9l3ZqQB3U+c90/w3722FP4w+WSB4pyzmiIwsn0RZEVnn7mlErbtQuS5KgsG4e2ef2Q5/UaLS7hZLfsok8cXHsYuzRVEiZMRHuc5+mmjjpo4E= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NfBxyMKEAiuViIm6UPRCbAnTd0pSJ859a6C2PzZtY+JwiNRwb20J/GTi2UJQlpr9qiYUIOWtzEKzCXLOT+uZFDW8DDFgO9UWJ6Z3h4tlB92QgyYogb37Js4h40cNwqbB7iMPJEjHP5684hboCe+oNMNtt9AOAcmA19pEiMG+IS6/T12VlKgaBDHCPBx/5aelD1FMLgVp+XyO7r5Bt1Zusi8LRQa3ljUmbpeTf1gi+02FdlohE7GZMyaq38fd+BjhrN47gJeHx6xn4CbskoqGvDTke4EMH9y2Hr1G0Im8LBLcNnB5doM5N1XgIHsLPXyMzQWvTTBhJuHs8U6lVuP3Lw== 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=Hup6FaFKkIQvSbDXtOvDMRB4oY53JGW82BILZNrOwcM=; b=b2V4ZpODYGbBu9LCHSYrGL/Qa5PqlwEhbDi/hdkhPRTu7VDK1HVC6gk2VAsJQdBwjAprpIujMFq5z5LEExqoU/EmJE1quBB2lv0rRT3dsx4FTQ+Uvrekr1KEXpIR84u6/PozRNt4sq30uQISBoqFYcM+sZZjeuHjlB0c++Cg3z995XvrN61AO6heLKevQDyRNlJe19Kkxx9FJ+9hN3+7kv+YWGYlM5ogs3XeHx6fNduJ5dWsYKkrFE6VqsrzNobnHgNXmvYwcCwMZ2KU2TP/bNLe685yqOCjyMzUvenyyrGs9h5xTPbitOJXKM6ufy0dJmf43Qdsj9+4Je6Bn7FHOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=HOTMAIL.DE; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Hup6FaFKkIQvSbDXtOvDMRB4oY53JGW82BILZNrOwcM=; b=RhNXiVeN1C5MYupzr1LZr//jXKwkfMhOj5sstCJy3ySlQ95xBvFi+2b3rfdcepG3c6LfDCRQDohxyj4aX/D2rZFlvgrx3GUQlbjwyzSiXLTRFhupxF67m+DI18rWRSBtXApwX6nHa6R8hCV7b/jmE2Sy9snxlejIblMGfVX19Q9kcje7weiBwxyJWcq/8S+f+DAk6SHUlPVSjcGTz3zsuuRjR43KVooskeRvtCsiojSjdzCI5ch1YYuliFajEydKpK4BTr9r7eE299d73kgnbZxlXKFSZmj4xd2OFZNdXAslhw2Ak4g8nlrl4fhHjY0A4yg4u2y1MPMFMNyrgjasrg== Received: from AS8P193MB1285.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:333::21) by DBAP193MB0955.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:1c8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.27; Fri, 5 Jul 2024 09:18:47 +0000 Received: from AS8P193MB1285.EURP193.PROD.OUTLOOK.COM ([fe80::e65d:5dd2:5662:c61f]) by AS8P193MB1285.EURP193.PROD.OUTLOOK.COM ([fe80::e65d:5dd2:5662:c61f%6]) with mapi id 15.20.7741.029; Fri, 5 Jul 2024 09:18:47 +0000 Message-ID: Date: Fri, 5 Jul 2024 11:18:20 +0200 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "gdb-patches@sourceware.org" From: Bernd Edlinger Subject: [PATCH v3 3/3] Fix range end handling of inlined subroutines X-TMN: [cGSaESGFSE3EqsmMOdrrD24zclShzQk4RnoKsfGLPQO7R3ybBrJTbfduzMcKP9IP] X-ClientProxiedBy: FR0P281CA0155.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:b3::18) To AS8P193MB1285.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:333::21) X-Microsoft-Original-Message-ID: <728b3736-50b3-4102-971d-b1988f067aa6@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P193MB1285:EE_|DBAP193MB0955:EE_ X-MS-Office365-Filtering-Correlation-Id: 3365f5e3-d504-4bde-ac5a-08dc9cd379bf X-Microsoft-Antispam: BCL:0; ARA:14566002|19110799003|461199028|8060799006|440099028|4302099013|3412199025|1602099012; X-Microsoft-Antispam-Message-Info: TQlOJHmx1QTb55h+mx6SA/3lCRi+Ac4NxC/gsSOSbJ3bio7hqkHzC7O0R1Z9gzhQTC1lptllMNAcvgF+yAMoKO9GXDC+R9R0FiD22Egmcaf3Q4jlpjF7idF5PRcXkjrZvsUOKmLrYOQQPFKswwn87LSCZcJjdgRyOwo/4upba8JLRQI+iHAUG0WD9JmThpZCFAmxtLCgO+j1KHP86/DJPp50hMWpm1Vk3lwwbnu85+uz498Vii1QXJfDwA+MfXxlBsnd904KE7vpqrcts6/5684rEzlR/wIUlhC7Z6E/U3WX+I4BVgXRkmrt7Q6kvP5nZXNWoi+MxGwjw1FzNsWkZ19QGwjtOHEfcL9d6Z0/QpG/Vs2TDpvZ9lwXOOnJayHkFgvH9mQDGVEy9N7OrWljM3xJrdrK6WGna/GSTct3npLB6kmz1IAOq6KaaVbC4c9ICl7eZ83kFsQqoPkjAh3Bgv1PVKbg/BETCR4zkGJRB24kO2/9dkOPoGlDxlkAJX7aDXW4AfoNoABCABdiN7Li+oVT35ImTdKIpHQK/7xwLTjmfDYMmQsWm+tfwE03KuPLq4579PffJNw+OClyAVxI2yNXvelMre57hzGMRwZFbz9aij+AkH7VUiOYb8CelPtsxlxLN/beMJTZynN66EURKJCeFP/GivDtUXgeUqMrvbKaQob/5KEUkpcMnYhei4/C3hnLJfNukhWOLvvzdzt6CSqKyMpCkqFugoIrWt+wxh+JkhY46lnZ7XiBgfGtf11o X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?S+tPVNTvzmQRPw6d/hLQo2jxawAm?= =?utf-8?q?JY+PqDFqJUIs6Pn3df1IcZ7lgaK/Dv2yxbRvrqPog/cQWVBxt1lMVcRuiNgepHxe7?= =?utf-8?q?GAYHf9jHagSVc61IDQ0cZdAmHs3uMzAIY89uxowee3wTq5RuG92doVMO91P3qrh5y?= =?utf-8?q?P1O28x1fT22QJskEMylObzlXkPJiuSAVzmu4oZawST9WQ9/h6DzYMi8fGGz87n3zG?= =?utf-8?q?yUV9cgSUOuwFAsQEN3LTqYwzt36cmJUXm2T4NmToDr/QFa4ka/7VWUFvYsnH7g3Zf?= =?utf-8?q?CvkG8bKm0zu2t8/TDu+LEA2rM777hl5VKmmu9gErIiusXij4V+ddj1URPx6osLrYB?= =?utf-8?q?Thv+tasvp/oKpR40gQqgLmueLzNV1r2MHyaun/QLzV2OtmBC3dVYxN0L1QkUUsSK6?= =?utf-8?q?7erOSV3MJ1PJKwBTHcnWAw4K1Ka6RXrJdlKJ5H7zd8UnVPnWJHd8mz/yXVlHJuD5t?= =?utf-8?q?bb9S/B2AanHyp1Pl8q/THz6zFvAxotokFaQynJt7hMCyHB/jvHVUVLp+TaZ6kwrwX?= =?utf-8?q?uzUridmxZpxZTgBBNoHk09EL8BZpPixt9jhinnJSRzMlICaA7tuC/GuBVB+8Ze3aG?= =?utf-8?q?WFKwaRysoltA1QrDXjUq3GZ3nyk8SplSXXDpECqEexIac+u7ZOnK/2cWhuC8Q6KU7?= =?utf-8?q?xtg0FRXPdCQFz4hsvFBZhNCRFVqvsGIBsjp1Dythug6NIprevx/7KsdfeTaeCHjpd?= =?utf-8?q?14C2LDmo+2pwsjQWghF9/CB0bCi7ioDfrTSnPd3Eun4j2OhyfLK2mxU+TeZY6BiBX?= =?utf-8?q?EdEm3FqYW8ujFCA46g/PqzpI7tFJlzGnLiGa5veOEv07jdv3EA92mACBAx3aQ2EZz?= =?utf-8?q?cRrJLEG9HEJenMZWYTqFqkF1WyvSW1Adnkhi3a3H4nqrUVfPvKVFUqz8OyGcuwsH0?= =?utf-8?q?+TzZgLrPPNLhQjcmiyny52T43kBK+qlIsxw1IiUgTUgnj1o3ZPTFQxXMia+mupmBU?= =?utf-8?q?eCldB+CBwIXlbzNPuzor3Y9ze+E4KflhV7oTiJL8GXSWgIJjmbGb3hHM5CHcasW1/?= =?utf-8?q?HDoPJvJU09jmYEY9bzadQvZ2I3Jm2DJIm4B4fChCUMi1MoDKvnxCYIID/Rjs1rlJ5?= =?utf-8?q?w7NPDL5M92EtAXTboX8sAf4+duuHstbsh/zPLy8qYsgNajMzROBsq1TZ5Wl4Jnk6l?= =?utf-8?q?NcOvTNgK+7II0AZiDAJN/jGwonn3N+HpdVrPYUi+fHfxKk/+LuT9QzIMoCLHytPhZ?= =?utf-8?q?A7MINmpyuBESgrzXJ6Zb+Esk6ZXqdXFU2h0MaVuszbGQLlmh2azqoAMOKm4y84puZ?= =?utf-8?q?9F0GvPilVNPJpAJw?= X-OriginatorOrg: sct-15-20-7741-18-msonline-outlook-01732.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 3365f5e3-d504-4bde-ac5a-08dc9cd379bf X-MS-Exchange-CrossTenant-AuthSource: AS8P193MB1285.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2024 09:18:47.6038 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAP193MB0955 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org Currently there is a problem when debugging optimized code when the inferior stops at an inline sub-range end PC. It is unclear if that location is from the inline function or from the calling function. Therefore the call stack is often wrong. This patch detects the "weak" line table entries which are likely part of the previous inline block, and if we have such a location, it assumes the location belongs to the previous block. Additionally it may happen that the infrun machinery steps from one inline range to another inline range of the same inline function. That can look like jumping back and forth from the calling program to the inline function, while really the inline function just jumps from a hot to a cold section of the code, i.e. error handling. Additionally it may happen that one inline sub-range is empty or the inline is completely empty. But filtering that information away is not the right solution, since although there is no actual code from the inline, it is still possible that variables from an inline function can be inspected here. The issue with the empty ranges is also discussed here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94474 Conceptually this patch uses a heuristic to work around a deficiency in the dwarf-4 and dwarf-5 rnglists structure. There should be a location view number for each inline sub-range begin PC and end PC, similar to the DW_AT_GNU_entry_view which is the location view for the inline entry point. --- gdb/block.c | 15 +- gdb/dwarf2/read.c | 77 ++----- gdb/infcmd.c | 3 +- gdb/infrun.c | 30 ++- gdb/symtab.c | 17 +- gdb/testsuite/gdb.base/empty-inline.c | 39 ++++ gdb/testsuite/gdb.base/empty-inline.exp | 56 +++++ gdb/testsuite/gdb.cp/empty-inline.cc | 33 +++ gdb/testsuite/gdb.cp/empty-inline.exp | 50 +++++ gdb/testsuite/gdb.cp/step-and-next-inline.cc | 6 +- gdb/testsuite/gdb.cp/step-and-next-inline.exp | 194 +++++++----------- 11 files changed, 322 insertions(+), 198 deletions(-) create mode 100644 gdb/testsuite/gdb.base/empty-inline.c create mode 100644 gdb/testsuite/gdb.base/empty-inline.exp create mode 100644 gdb/testsuite/gdb.cp/empty-inline.cc create mode 100644 gdb/testsuite/gdb.cp/empty-inline.exp diff --git a/gdb/block.c b/gdb/block.c index 511689c9738..d9c4435c9e2 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -197,7 +197,20 @@ blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section, return NULL; if (pblock) - *pblock = b; + { + struct symtab_and_line sal = find_pc_sect_line (pc, section, 0); + if (sal.line != 0 && sal.pc == pc && sal.is_weak) + { + const struct block *b2 = find_block_in_blockvector (bl, pc - 1); + const struct block *b0 = b; + while (b0->superblock () && !b0->function ()) + b0 = b0->superblock (); + if (b0->contains (b2)) + b = b2; + } + *pblock = b; + } + return bl; } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 60fd8b45eb5..e40679611fe 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -10733,10 +10733,6 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu, return false; } - /* Empty range entries have no effect. */ - if (range_beginning == range_end) - continue; - /* Only DW_RLE_offset_pair needs the base address added. */ if (rlet == DW_RLE_offset_pair) { @@ -10855,10 +10851,6 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag, return 0; } - /* Empty range entries have no effect. */ - if (range_beginning == range_end) - continue; - range_beginning = (unrelocated_addr) ((CORE_ADDR) range_beginning + (CORE_ADDR) *base); range_end = (unrelocated_addr) ((CORE_ADDR) range_end @@ -11080,8 +11072,8 @@ dwarf2_get_pc_bounds (struct die_info *die, unrelocated_addr *lowpc, if (ret == PC_BOUNDS_NOT_PRESENT || ret == PC_BOUNDS_INVALID) return ret; - /* partial_die_info::read has also the strict LOW < HIGH requirement. */ - if (high <= low) + /* partial_die_info::read has also the same low < high requirement. */ + if (low > high || (low == high && die->tag != DW_TAG_inlined_subroutine)) return PC_BOUNDS_INVALID; /* When using the GNU linker, .gnu.linkonce. sections are used to @@ -18027,21 +18019,9 @@ class lnp_state_machine /* Additional bits of state we need to track. */ - /* The last file that we called dwarf2_start_subfile for. - This is only used for TLLs. */ - unsigned int m_last_file = 0; /* The last file a line number was recorded for. */ struct subfile *m_last_subfile = NULL; - /* The address of the last line entry. */ - unrelocated_addr m_last_address; - - /* Set to true when a previous line at the same address (using - m_last_address) had LEF_IS_STMT set in m_flags. This is reset to false - when a line entry at a new address (m_address different to - m_last_address) is processed. */ - bool m_stmt_at_address = false; - /* When true, record the lines we decode. */ bool m_currently_recording_lines = true; @@ -18199,7 +18179,8 @@ dwarf_record_line_1 (struct gdbarch *gdbarch, struct subfile *subfile, static void dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile, - unrelocated_addr address, struct dwarf2_cu *cu) + unrelocated_addr address, struct dwarf2_cu *cu, + bool end_sequence) { if (subfile == NULL) return; @@ -18212,7 +18193,8 @@ dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile, paddress (gdbarch, (CORE_ADDR) address)); } - dwarf_record_line_1 (gdbarch, subfile, 0, address, LEF_IS_STMT, cu); + dwarf_record_line_1 (gdbarch, subfile, end_sequence ? 0 : -1, address, + LEF_IS_STMT, cu); } void @@ -18240,38 +18222,17 @@ lnp_state_machine::record_line (bool end_sequence) /* For now we ignore lines not starting on an instruction boundary. But not when processing end_sequence for compatibility with the previous version of the code. */ - else if (m_op_index == 0 || end_sequence) - { - /* When we switch files we insert an end maker in the first file, - switch to the second file and add a new line entry. The - problem is that the end marker inserted in the first file will - discard any previous line entries at the same address. If the - line entries in the first file are marked as is-stmt, while - the new line in the second file is non-stmt, then this means - the end marker will discard is-stmt lines so we can have a - non-stmt line. This means that there are less addresses at - which the user can insert a breakpoint. - - To improve this we track the last address in m_last_address, - and whether we have seen an is-stmt at this address. Then - when switching files, if we have seen a stmt at the current - address, and we are switching to create a non-stmt line, then - discard the new line. */ - bool file_changed - = m_last_subfile != m_cu->get_builder ()->get_current_subfile (); - bool ignore_this_line - = ((file_changed && !end_sequence && m_last_address == m_address - && ((m_flags & LEF_IS_STMT) == 0) - && m_stmt_at_address) - || (!end_sequence && m_line == 0)); - - if ((file_changed && !ignore_this_line) || end_sequence) + else if ((m_op_index == 0 && m_line != 0) || end_sequence) + { + if (m_last_subfile != m_cu->get_builder ()->get_current_subfile () + || end_sequence) { dwarf_finish_line (m_gdbarch, m_last_subfile, m_address, - m_currently_recording_lines ? m_cu : nullptr); + m_currently_recording_lines ? m_cu : nullptr, + end_sequence || (m_flags & LEF_IS_STMT) != 0); } - if (!end_sequence && !ignore_this_line) + if (!end_sequence) { linetable_entry_flags lte_flags = m_flags; if (producer_is_codewarrior (m_cu)) @@ -18291,15 +18252,6 @@ lnp_state_machine::record_line (bool end_sequence) m_last_line = m_line; } } - - /* Track whether we have seen any IS_STMT true at m_address in case we - have multiple line table entries all at m_address. */ - if (m_last_address != m_address) - { - m_stmt_at_address = false; - m_last_address = m_address; - } - m_stmt_at_address |= (m_flags & LEF_IS_STMT) != 0; } lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch, @@ -18313,8 +18265,7 @@ lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch, This is currently used by MIPS code, cf. `mips_adjust_dwarf2_line'. */ m_address ((unrelocated_addr) gdbarch_adjust_dwarf2_line (arch, 0, 0)), - m_flags (lh->default_is_stmt ? LEF_IS_STMT : (linetable_entry_flags) 0), - m_last_address (m_address) + m_flags (lh->default_is_stmt ? LEF_IS_STMT : (linetable_entry_flags) 0) { } diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 71514d5ba66..7598c9e3032 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -996,7 +996,8 @@ prepare_one_step (thread_info *tp, struct step_command_fsm *sm) if (sym->aclass () == LOC_BLOCK) { const block *block = sym->value_block (); - if (block->end () < tp->control.step_range_end) + if (block->end () < tp->control.step_range_end + && block->end () > tp->control.step_range_start) tp->control.step_range_end = block->end (); } } diff --git a/gdb/infrun.c b/gdb/infrun.c index 1f32a63ad54..097b42c4e92 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8114,6 +8114,31 @@ process_event_stop_test (struct execution_control_state *ecs) return; } + /* Handle the case when subroutines have multiple ranges. + When we step from one part to the next part of the same subroutine, + all subroutine levels are skipped again which begin here. + Compensate for this by removing all skipped subroutines, + which were already executing from the user's perspective. */ + + if (get_stack_frame_id (frame) + == ecs->event_thread->control.step_stack_frame_id + && inline_skipped_frames (ecs->event_thread) + && ecs->event_thread->control.step_frame_id.artificial_depth > 0 + && ecs->event_thread->control.step_frame_id.code_addr_p) + { + const struct block *prev, *curr; + int depth = 0; + prev = block_for_pc (ecs->event_thread->control.step_frame_id.code_addr); + curr = block_for_pc (ecs->event_thread->stop_pc ()); + while (curr && curr->inlined_p () && !curr->contains (prev)) + { + depth ++; + curr = curr->superblock (); + } + while (inline_skipped_frames (ecs->event_thread) > depth) + step_into_inline_frame (ecs->event_thread); + } + /* Look for "calls" to inlined functions, part one. If the inline frame machinery detected some skipped call sites, we have entered a new inline function. */ @@ -8172,6 +8197,8 @@ process_event_stop_test (struct execution_control_state *ecs) infrun_debug_printf ("stepping through inlined function"); if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL + || ecs->event_thread->stop_pc () != stop_pc_sal.pc + || !stop_pc_sal.is_stmt || inline_frame_is_marked_for_skip (false, ecs->event_thread)) keep_going (ecs); else @@ -8220,7 +8247,8 @@ process_event_stop_test (struct execution_control_state *ecs) end_stepping_range (ecs); return; } - else if (*curr_frame_id == original_frame_id) + else if (get_stack_frame_id (frame) + == ecs->event_thread->control.step_stack_frame_id) { /* We are not at the start of a statement, and we have not changed frame. diff --git a/gdb/symtab.c b/gdb/symtab.c index 41d71beec2a..957fe971d3c 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3290,7 +3290,10 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) 0) instead of a real line. */ if (prev && prev->line - && (!best || prev->unrelocated_pc () > best->unrelocated_pc ())) + && (!best || prev->unrelocated_pc () > best->unrelocated_pc () + || (prev->unrelocated_pc () == best->unrelocated_pc () + && (best->pc (objfile) == pc + ? !best->is_stmt : best->is_weak)))) { best = prev; best_symtab = iter_s; @@ -3309,7 +3312,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) && (tmp - 1)->unrelocated_pc () == tmp->unrelocated_pc () && (tmp - 1)->line != 0 && !tmp->is_stmt) --tmp; - if (tmp->is_stmt) + if (tmp->is_stmt && (tmp->pc (objfile) == pc || !tmp->is_weak)) best = tmp; } @@ -3333,18 +3336,14 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) We used to return alt->line - 1 here, but that could be anywhere; if we don't have line number info for this PC, don't make some up. */ - val.pc = pc; - } - else if (best->line == 0) - { - /* If our best fit is in a range of PC's for which no line - number info is available (line number is zero) then we didn't - find any valid line information. */ + if (notcurrent) + pc++; val.pc = pc; } else { val.is_stmt = best->is_stmt; + val.is_weak = best->is_weak; val.symtab = best_symtab; val.line = best->line; val.pc = best->pc (objfile); diff --git a/gdb/testsuite/gdb.base/empty-inline.c b/gdb/testsuite/gdb.base/empty-inline.c new file mode 100644 index 00000000000..4ecb3ff14a3 --- /dev/null +++ b/gdb/testsuite/gdb.base/empty-inline.c @@ -0,0 +1,39 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 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 . */ + +static int test0 (void) +{ + asm (""); /* line 20 */ + return 1; /* line 21 */ +} + +int __attribute__((noinline, noclone)) +#ifdef __CET__ + __attribute__((nocf_check)) +#endif +test1 (int x) +{ + asm (""); + return x+1; /* line 31 */ +} + +int +main() +{ test1 (test0 ()); /* line 36 */ + test1 (test0 ()); /* line 37 */ + return 0; /* line 38 */ +} diff --git a/gdb/testsuite/gdb.base/empty-inline.exp b/gdb/testsuite/gdb.base/empty-inline.exp new file mode 100644 index 00000000000..0d9cfe922cf --- /dev/null +++ b/gdb/testsuite/gdb.base/empty-inline.exp @@ -0,0 +1,56 @@ +# Copyright 2024 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 . + +standard_testfile .c + +if [get_compiler_info] { + return -1 +} + +if { [test_compiler_info gcc*] && ![supports_statement_frontiers] } { + return -1 +} + +global srcfile testfile + +set options {debug nowarnings optimize=-O2} +if { [supports_statement_frontiers] } { + lappend options additional_flags=-gstatement-frontiers +} + +if { [prepare_for_testing "failed to prepare" $binfile \ + $srcfile $options] } { + return -1 +} + +if ![runto_main] { + return +} + +gdb_test "frame 0" "\\s*\\#0\\s+main.*${srcfile}:36.*" "in main" +gdb_test_multiple "step" "step into test0" { + -re ".*test0.*${srcfile}:20.*$::gdb_prompt $" { + gdb_test "step" ".*line 21.*" $gdb_test_name + } + -re ".*test0.*${srcfile}:21.*$::gdb_prompt $" { + pass $gdb_test_name + } +} +gdb_test "frame 1" "\\s*\\#1\\s+main.*${srcfile}:36.*" "frame1" +gdb_test "step" ".*test1.*${srcfile}:31.*" "step into test1" +gdb_test "frame 1" "\\s*\\#1.*in main.*${srcfile}:36.*" "frame2" +gdb_test "step" ".*main.*${srcfile}:37.*" "step back to main" +gdb_test "next" ".*return 0;.*" "step over test0+1" +gdb_test "frame 0" "\\s*\\#0\\s+main.*${srcfile}:38.*" "in main again" diff --git a/gdb/testsuite/gdb.cp/empty-inline.cc b/gdb/testsuite/gdb.cp/empty-inline.cc new file mode 100644 index 00000000000..a960d5f7ec0 --- /dev/null +++ b/gdb/testsuite/gdb.cp/empty-inline.cc @@ -0,0 +1,33 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 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 . */ + +/* PR 25987 */ +struct MyClass; +struct ptr { + MyClass* get() { return t; } /* line 21 */ + MyClass* t; +}; +struct MyClass { void call(); }; +void MyClass::call() { + *(volatile char*)-1 = 1; /* line 26 */ +} +static void intermediate(ptr p) { + p.get()->call(); /* line 29 */ +} +int main() { + intermediate(ptr{new MyClass}); +} diff --git a/gdb/testsuite/gdb.cp/empty-inline.exp b/gdb/testsuite/gdb.cp/empty-inline.exp new file mode 100644 index 00000000000..7848c963f59 --- /dev/null +++ b/gdb/testsuite/gdb.cp/empty-inline.exp @@ -0,0 +1,50 @@ +# Copyright 2024 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 . + +# PR 25987 +standard_testfile .cc + +if {![supports_statement_frontiers]} { + return -1 +} + +set options {c++ debug nowarnings optimize=-Og} +lappend options additional_flags=-gstatement-frontiers +if { [prepare_for_testing "failed to prepare" $testfile \ + $srcfile $options] } { + return -1 +} + +if ![runto_main] { + return +} + +gdb_test "bt" "\\s*\\#0\\s+main.*" "in main" +#break at the empty inline function ptr::get +gdb_test "b get" ".*" "break at get" +gdb_test "c" ".*" "continue to get" +#call frame 1 is at line 29 +gdb_test "bt" [multi_line "\\s*\\#0\\s+ptr::get\[^\r\]*${srcfile}:21" \ + "\\s*\\#1\\s+intermediate\[^\r\]*${srcfile}:29" \ + ".*"] \ + "at get" +#print a local value here +gdb_test "p t" ".*(\\\$1 = \\(MyClass \\*\\) 0x|value has been optimized out).*" "print t" +gdb_test "c" ".*SIGSEGV.*" "continue to SIGSEGV" +#call frame 1 is at line 29 +gdb_test "bt" [multi_line "\\s*\\#0\\s+\[^\r\]*MyClass::call\[^\r\]*${srcfile}:26" \ + "\\s*\\#1\\s+0x\[^\r\]*intermediate\[^\r\]*${srcfile}:29" \ + ".*"] \ + "at call" diff --git a/gdb/testsuite/gdb.cp/step-and-next-inline.cc b/gdb/testsuite/gdb.cp/step-and-next-inline.cc index ac92206fd7f..7f8ead878ec 100644 --- a/gdb/testsuite/gdb.cp/step-and-next-inline.cc +++ b/gdb/testsuite/gdb.cp/step-and-next-inline.cc @@ -47,8 +47,7 @@ tree_check (tree *t, int i) int __attribute__((noinline, noclone)) get_alias_set (tree *t) -{ - if (t != NULL +{ if (t != NULL && TREE_TYPE (t).z != 1 && TREE_TYPE (t).z != 2 && TREE_TYPE (t).z != 3) @@ -60,7 +59,6 @@ tree xx; int main() -{ - get_alias_set (&xx); /* Beginning of main */ +{ get_alias_set (&xx); return 0; } // main diff --git a/gdb/testsuite/gdb.cp/step-and-next-inline.exp b/gdb/testsuite/gdb.cp/step-and-next-inline.exp index 446cd825947..c9fa77f98e0 100644 --- a/gdb/testsuite/gdb.cp/step-and-next-inline.exp +++ b/gdb/testsuite/gdb.cp/step-and-next-inline.exp @@ -15,7 +15,7 @@ standard_testfile .cc -if {[test_compiler_info gcc*] && ![supports_statement_frontiers] } { +if { [test_compiler_info gcc*] && ![supports_statement_frontiers] } { return -1 } @@ -24,13 +24,6 @@ if {[test_compiler_info gcc*] && ![supports_statement_frontiers] } { proc do_test { use_header } { global srcfile testfile - if { $use_header } { - # This test will not pass due to poor debug information - # generated by GCC (at least upto 10.x). See - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94474 - return - } - set options {c++ debug nowarnings optimize=-O2} if { [supports_statement_frontiers] } { lappend options additional_flags=-gstatement-frontiers @@ -53,128 +46,29 @@ proc do_test { use_header } { with_test_prefix $prefix { - set main_location [gdb_get_line_number "Beginning of main" $srcfile] - - if ![runto $main_location qualified] { + if ![runto_main] { return } gdb_test "bt" "\\s*\\#0\\s+main.*" "in main" - set line1 {\t\{} - set line2 {\t if \(t != NULL} - gdb_test_multiple "step" "step into get_alias_set" { - -re -wrap $line1 { - gdb_test "next" $line2 $gdb_test_name - } - -re -wrap $line2 { - pass $gdb_test_name - } - } + gdb_test "step" ".*" "step into get_alias_set" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 1" - - # It's possible that this first failure (when not using a header - # file) is GCC's fault, though the remaining failures would best - # be fixed by adding location views support (though it could be - # that some easier heuristic could be figured out). Still, it is - # not certain that the first failure wouldn't also be fixed by - # having location view support, so for now it is tagged as such. - set have_kfail [expr [test_compiler_info gcc*] && !$use_header] - - set ok 1 - gdb_test_multiple "next" "next step 1" { - -re -wrap "if \\(t->x != i\\)" { - set ok 0 - send_gdb "next\n" - exp_continue - } - -re -wrap ".*TREE_TYPE.* != 1" { - if { $ok } { - pass $gdb_test_name - } else { - if { $have_kfail } { - setup_kfail "*-*-*" symtab/25507 - } - fail $gdb_test_name - } - } - } + gdb_test "next" ".*TREE_TYPE.*" "next step 1" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 2" - - set ok 1 - gdb_test_multiple "next" "next step 2" { - -re -wrap "return x;" { - set ok 0 - send_gdb "next\n" - exp_continue - } - -re -wrap ".*TREE_TYPE.* != 2" { - if { $ok } { - pass $gdb_test_name - } else { - if { $have_kfail } { - setup_kfail "*-*-*" symtab/25507 - } - fail $gdb_test_name - } - } - } + gdb_test "next" ".*TREE_TYPE.*" "next step 2" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 3" - - set ok 1 - gdb_test_multiple "next" "next step 3" { - -re -wrap "return x;" { - set ok 0 - send_gdb "next\n" - exp_continue - } - -re -wrap ".*TREE_TYPE.* != 3\\)" { - if { $ok } { - pass $gdb_test_name - } else { - if { $have_kfail } { - setup_kfail "*-*-*" symtab/25507 - } - fail $gdb_test_name - } - } - } + gdb_test "next" ".*TREE_TYPE.*" "next step 3" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 4" - - set ok 1 - gdb_test_multiple "next" "next step 4" { - -re -wrap "(if \\(t != NULL|\} // get_alias_set)" { - send_gdb "next\n" - exp_continue - } - -re -wrap "return x;" { - set ok 0 - send_gdb "next\n" - exp_continue - } - -re -wrap "return 0.*" { - if { $ok } { - pass $gdb_test_name - } else { - if { $have_kfail } { - setup_kfail "*-*-*" symtab/25507 - } - fail $gdb_test_name - } - } - } + gdb_test "next" ".*" "next step 4" gdb_test "bt" \ "\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \ "not in inline 5" - if {!$use_header} { - # With the debug from GCC 10.x (and earlier) GDB is currently - # unable to successfully complete the following tests when we - # are not using a header file. - kfail symtab/25507 "stepping tests" + if ![test_compiler_info gcc*] { return } @@ -194,22 +88,84 @@ proc do_test { use_header } { gdb_test "step" ".*if \\(t->x != i\\).*" "step 2" gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \ "in inline 1 pass 2" - gdb_test "step" ".*TREE_TYPE.*" "step 3" + gdb_test "step" ".*return x.*" "step 3" + gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \ + "return from inline 1 pass 2" + gdb_test "step" ".*TREE_TYPE.*" "step 4" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 2 pass 2" - gdb_test "step" ".*if \\(t->x != i\\).*" "step 4" + gdb_test "step" ".*if \\(t->x != i\\).*" "step 5" gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \ "in inline 2 pass 2" - gdb_test "step" ".*TREE_TYPE.*" "step 5" + gdb_test "step" ".*return x.*" "step 6" + gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \ + "return from inline 2 pass 2" + gdb_test "step" ".*TREE_TYPE.*" "step 7" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 3 pass 2" - gdb_test "step" ".*if \\(t->x != i\\).*" "step 6" + gdb_test "step" ".*if \\(t->x != i\\).*" "step 8" gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \ "in inline 3 pass 2" - gdb_test "step" "return 0.*" "step 7" + gdb_test "step" ".*return x.*" "step 9" + gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \ + "return from inline 3 pass 2" + gdb_test "step" "return 0.*" "step 10" gdb_test "bt" \ "\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \ "not in inline 4 pass 2" + + clean_restart ${executable} + + if ![runto_main] { + return + } + + gdb_test "bt" "\\s*\\#0\\s+main.*" "in main pass 3" + gdb_test "step" ".*" "step into get_alias_set pass 3" + gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ + "in get_alias_set pass 3" + gdb_test "step" ".*TREE_TYPE.*" "step 1 pass 3" + gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ + "not in inline 1 pass 3" + gdb_test "step" ".*if \\(t->x != i\\).*" "step 2 pass 3" + gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \ + "in inline 1 pass 3" + gdb_test_multiple "p t->x = 2" "change value pass 3" { + -re ".*value has been optimized out.*$::gdb_prompt $" { + gdb_test "p xx.x = 2" ".* = 2.*" $gdb_test_name + } + -re ".* = 2.*$::gdb_prompt $" { + pass $gdb_test_name + } + } + gdb_test "step" ".*abort.*" "step 3, pass 3" + gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \ + "abort from inline 1 pass 3" + + clean_restart ${executable} + + if ![runto_main] { + return + } + + gdb_test "bt" "\\s*\\#0\\s+main.*" "in main pass 4" + gdb_test "skip tree_check" ".*" "skip tree_check pass 4" + gdb_test "step" ".*" "step into get_alias_set pass 4" + gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ + "in get_alias_set pass 4" + gdb_test "step" ".*TREE_TYPE.*" "step 1 pass 4" + gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ + "not in inline 1 pass 4" + gdb_test "step" ".*TREE_TYPE.*" "step 2 pass 4" + gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ + "not in inline 2 pass 4" + gdb_test "step" ".*TREE_TYPE.*" "step 3 pass 4" + gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ + "not in inline 3 pass 4" + gdb_test "step" "return 0.*" "step 4 pass 4" + gdb_test "bt" \ + "\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \ + "not in inline 4 pass 4" } }