From patchwork Sun Feb 9 21:07:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 37831 Received: (qmail 37595 invoked by alias); 9 Feb 2020 21:07:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 37587 invoked by uid 89); 9 Feb 2020 21:07:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:10a6, yesterday, H*c:HHH X-HELO: EUR05-AM6-obe.outbound.protection.outlook.com Received: from mail-am6eur05olkn2093.outbound.protection.outlook.com (HELO EUR05-AM6-obe.outbound.protection.outlook.com) (40.92.91.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Feb 2020 21:07:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PzFrW0Qr9EzVuHsT+YlldxHzUSfmbUmPCzfNNQ0GWh5+BBkD+L2xMJ5fHTeJL88WEpJg40sLSLC07359TVtHhKiDiQbPnTJLSrATp/8OVswYMWTQxHxzwUKK1FNV/7NxFSkSInMqBVwhtwlFwuCZYgetmxSo8iQjZQfmtWXVKtf6aw6tHhpk2MTCo1PJzKyCBeoWhRytvbzoFs5PcRR98p0J5hWvfQIW1ccxh3F7s4P7hH9KcznhmDMOfz2QPEH0fs9oWUXfeh6ek7cHKGAdEQ0KT+JwK+AUNakmxYR5JrAJ7JHc5myLiaVgYz0Dq53DfstIEDIHIc9VVk/DmicQXQ== 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-SenderADCheck; bh=lDZ9tes+I+t1NCoUuce1crVVoHEjNvnFWeq5W88zkzY=; b=dqPCUc6EeuIld/zCZ/Zj9q0kbsuJipibLg49hQldM3xXojbZjrcOVu7FevEGawzzDi/atTRg3swTj/S2rQUJ8QjS7xeHunl6NGu2mzIXRcVIu1IjMnHaH79fuoOA+p0yFfftVHiHn8a8MU8axKkwVGe3owGSexx8sIaxf8Hsg/MiHk7u/MxmVtj+hzrH+WOU4ZOUFv3NZ8o+l4pbDEth8lzA850vhxeNMCZRvgHo1EmlIO0Ynt8+embJaoELa0VdV5KF6+YvNAXCWDQtvQCTj7R+YB+PuzwXbP7SZYQ7gLxQECRpoHF5LEIhy2AW1FhCYFnF+fDLYAPK7xqRlXcbYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from AM6EUR05FT042.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc11::34) by AM6EUR05HT239.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc11::353) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.21; Sun, 9 Feb 2020 21:07:33 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (10.233.240.51) by AM6EUR05FT042.mail.protection.outlook.com (10.233.241.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.21 via Frontend Transport; Sun, 9 Feb 2020 21:07:33 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd]) by AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::1956:d274:cab3:b4dd%6]) with mapi id 15.20.2707.028; Sun, 9 Feb 2020 21:07:33 +0000 Received: from [192.168.1.101] (92.77.140.102) by ZR0P278CA0052.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:1d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.21 via Frontend Transport; Sun, 9 Feb 2020 21:07:30 +0000 From: Bernd Edlinger To: Andrew Burgess , "gdb-patches@sourceware.org" Subject: [PATCH] Fix range end handling of inlined subroutines Date: Sun, 9 Feb 2020 21:07:32 +0000 Message-ID: References: <94e33268f64060fc887670f4ee5ed524050cbcc7.1580902412.git.andrew.burgess@embecosm.com> In-Reply-To: <94e33268f64060fc887670f4ee5ed524050cbcc7.1580902412.git.andrew.burgess@embecosm.com> x-microsoft-original-message-id: <7d51b8fb-1d9c-aace-c0e1-c0fa002590d9@hotmail.de> x-ms-exchange-antispam-messagedata: POcFSjuML35ZaZO+rW52Bp7EXUs0A8wmUFCf37e9TgTyLyIh9C52w8xi/vKm1DNoHtBmeNDH2ikStH4rHQdqV/u6qW/fg+EA3QgkfoLM6eORhMVvgmMcnGbzgwo4l0hwMg17cwTk3Zif4wSIZ56T3w== x-ms-exchange-transport-forked: True MIME-Version: 1.0 Hi, this is based on Andrew's patch here: https://sourceware.org/ml/gdb-patches/2020-02/msg00092.html This and adds a heuristic to fix the case where caller and callee reside in the same subfile, it uses the recorded is-stmt bits and locates end of range infos, including the previously ignored empty range, and adjusting is-stmt info at this same pc, when the last item is not-is-stmt, the previous line table entries are dubious and we reset the is-stmt bit there. This fixes the new test case in Andrew's patch. It understood, that this is just a heuristic approach, since we do not have exactly the data, which is needed to determine at which of the identical PCs in the line table the subroutine actually ends. So, this tries to be as conservative as possible, just changing what is absolutely necessary. This patch itself is preliminary, since the is-stmt patch needs to be rebased after the refactoring of dwarf2read.c from yesterday, so I will have to rebase this patch as well, but decided to wait for Andrew. Thanks Bernd. From d15f3346feb1ed5cbbc14e708f3f6b58d88bc0fe Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Sun, 9 Feb 2020 21:13:17 +0100 Subject: [PATCH] Fix range end handling of inlined subroutines Since the is_stmt is now handled, it became possible to locate dubious is_stmt line entries at the end of an inlined function, in the same subfile. If any is-stmt line is followed by a non-is-stmt, at the same PC as the inlined subroutine ends, clear the is-stmt there (except the line = 0 end marker, of course). This is about the best we can do at the moment, unless location view information are added to the block ranges debug info structure, and location views are implemented in gdb in general. gdb: 2020-02-09 Bernd Edlinger * buildsym.c (buildsym_compunit::record_inline_range_end): New function. * buildsym.h (buildsym_compunit::record_inline_range_end): Declare. * dwarf2read.c (dwarf2_rnglists_process, dwarf2_ranges_process): Don't ignore empty ranges here. (dwarf2_ranges_read): Ignore empty ranges here. (dwarf2_record_block_ranges): Pass end of range PC to record_inline_range_end for inline functions. gdb/testsuite: 2020-02-09 Bernd Edlinger * gdb.cp/next-inline.exp: Adjust test. --- gdb/buildsym.c | 23 +++++++++++++++++++++++ gdb/buildsym.h | 2 ++ gdb/dwarf2read.c | 22 +++++++++++++--------- gdb/testsuite/gdb.cp/next-inline.exp | 9 --------- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 7fd256f..381a7c8 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -732,6 +732,29 @@ buildsym_compunit::record_line (struct subfile *subfile, int line, } +/* Record a PC where a inlined subroutine ends. */ + +void +buildsym_compunit::record_inline_range_end (CORE_ADDR end) +{ + struct subfile *subfile; + + for (subfile = m_subfiles; subfile != NULL; subfile = subfile->next) + { + if (subfile->line_vector != NULL) + { + struct linetable_entry *items = subfile->line_vector->item; + int i; + + for (i = subfile->line_vector->nitems - 1; i > 0; i--) + if (items[i].pc == end && items[i - 1].pc == end + && !items[i].is_stmt && items[i - 1].line != 0) + items[i - 1].is_stmt = 0; + } + } +} + + /* Subroutine of end_symtab to simplify it. Look for a subfile that matches the main source file's basename. If there is only one, and if the main source file doesn't have any symbol or line number diff --git a/gdb/buildsym.h b/gdb/buildsym.h index c768a4c..3cf0f8b 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -190,6 +190,8 @@ struct buildsym_compunit void record_line (struct subfile *subfile, int line, CORE_ADDR pc, bool is_stmt); + void record_inline_range_end (CORE_ADDR end); + struct compunit_symtab *get_compunit_symtab () { return m_compunit_symtab; diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index cbee4ab..6919bf1 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -14407,10 +14407,6 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu, return false; } - /* Empty range entries have no effect. */ - if (range_beginning == range_end) - continue; - range_beginning += base; range_end += base; @@ -14521,10 +14517,6 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, return 0; } - /* Empty range entries have no effect. */ - if (range_beginning == range_end) - continue; - range_beginning += base; range_end += base; @@ -14564,6 +14556,10 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, retval = dwarf2_ranges_process (offset, cu, [&] (CORE_ADDR range_beginning, CORE_ADDR range_end) { + /* Empty range entries have no effect. */ + if (range_beginning == range_end) + return; + if (ranges_pst != NULL) { CORE_ADDR lowpc; @@ -14801,6 +14797,7 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block, struct gdbarch *gdbarch = get_objfile_arch (objfile); struct attribute *attr; struct attribute *attr_high; + bool inlined_subroutine = (die->tag == DW_TAG_inlined_subroutine); attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); if (attr_high) @@ -14816,7 +14813,10 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block, low = gdbarch_adjust_dwarf2_addr (gdbarch, low + baseaddr); high = gdbarch_adjust_dwarf2_addr (gdbarch, high + baseaddr); - cu->get_builder ()->record_block_range (block, low, high - 1); + if (inlined_subroutine) + cu->get_builder ()->record_inline_range_end (high); + if (low < high) + cu->get_builder ()->record_block_range (block, low, high - 1); } } @@ -14841,6 +14841,10 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block, end += baseaddr; start = gdbarch_adjust_dwarf2_addr (gdbarch, start); end = gdbarch_adjust_dwarf2_addr (gdbarch, end); + if (inlined_subroutine) + cu->get_builder ()->record_inline_range_end (end); + if (start == end) + return; cu->get_builder ()->record_block_range (block, start, end - 1); blockvec.emplace_back (start, end); }); diff --git a/gdb/testsuite/gdb.cp/next-inline.exp b/gdb/testsuite/gdb.cp/next-inline.exp index 0b2b22d..11d9e2e 100644 --- a/gdb/testsuite/gdb.cp/next-inline.exp +++ b/gdb/testsuite/gdb.cp/next-inline.exp @@ -42,24 +42,15 @@ proc do_test { use_header } { 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. - if {!$use_header} { setup_kfail "*-*-*" symtab/25507 } gdb_test "next" ".*TREE_TYPE.*" "next step 1" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 2" gdb_test "next" ".*TREE_TYPE.*" "next step 2" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 3" - if {!$use_header} { setup_kfail "*-*-*" symtab/25507 } gdb_test "next" ".*TREE_TYPE.*" "next step 3" gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \ "not in inline 4" - if {!$use_header} { setup_kfail "*-*-*" symtab/25507 } gdb_test "next" "return 0.*" "next step 4" gdb_test "bt" \ "\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \ -- 1.9.1