From patchwork Mon Dec 30 21:36:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 103790 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 95EE53858C98 for ; Mon, 30 Dec 2024 21:37:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95EE53858C98 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=KPJw6454 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 80F123858D20 for ; Mon, 30 Dec 2024 21:36:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80F123858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 80F123858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735594604; cv=none; b=HZitTt/d9ksr20p19ysG51jcY2X8kpdJi3AtM9fmh0GaskYJf6sw+5WIwR3APkM5+vUx2Ut1/j+NiJQLx7gh/EAuNVc6XN2ZaazIDzmQTSRxo+rZZJ3dtZapUrsBVCCAUOjmsQ1hrSLMKXX4WuU1zkFkl8ljR+pTy3qGkmWI3VQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735594604; c=relaxed/simple; bh=FD0bREdW10f/GNs5S02m9yttIIBcvh87SZUqXfvIW7U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZR07Wu817yi6kyewNd/orDlMMPUXwrCZ07rUJTI9Q7rDx7cG4qt+0mxsQ0bqcOuJ3cMKAQHOgea9DVb8lSxrZ4JNC3P1tzfSVgBXgAUKoaHT8sV3RlnWgpWw3wN8Aeb2LD2svQND6+H2Elb2sA/iFsbOve7IO5zmvU38jPJAy8k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80F123858D20 Received: from eig-obgw-6004a.ext.cloudfilter.net ([10.0.30.197]) by cmsmtp with ESMTPS id S1LxtkIubnNFGSNRLtp8jZ; Mon, 30 Dec 2024 21:36:44 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id SNRKtaQcKWdNZSNRLtXcqm; Mon, 30 Dec 2024 21:36:43 +0000 X-Authority-Analysis: v=2.4 cv=FtTO/Hrq c=1 sm=1 tr=0 ts=6773126b a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=RZcAm9yDv7YA:10 a=ItBw4LHWJt0A:10 a=CCpqsmhAAAAA:8 a=mDV3o1hIAAAA:8 a=D41XPXvmZvbqfV1Ck-4A:9 a=ul9cdbp4aOFLsgKbc677:22 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=0piQ2RllvTshFKkb+9GOH+cFHbOUn02NseMKsY4k4Kg=; b=KPJw6454lXwI7d8vThYkn96uVY YEPNBntao7+6c/ofocGWoh0bgkbLGtW5Ixufb2bxQoUvCkpR0DzfRz/StFg3VjJRCYxFpZMlyYplZ NuezxbrIagOn2XY1IV1tucXQT; Received: from 97-122-113-155.hlrn.qwest.net ([97.122.113.155]:52046 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1tSNRK-003Opf-1M; Mon, 30 Dec 2024 14:36:42 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix C++ template function matching in cooked index Date: Mon, 30 Dec 2024 14:36:32 -0700 Message-ID: <20241230213632.618184-1-tom@tromey.com> X-Mailer: git-send-email 2.46.1 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.113.155 X-Source-L: No X-Exim-ID: 1tSNRK-003Opf-1M X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-113-155.hlrn.qwest.net (localhost.localdomain) [97.122.113.155]:52046 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfNMRyZDoywpAr93nER9DKnjrpdWqzOvthPSq6biqTy1SE5ZJisnU2c2vz+MDpDPHXMpwLrA3qstgnT7Tz+8M17A/U1buWSDjgG+NOzEe45u2stjmptxv KwVc1Gfobb3IPEmWZbzc+JONfNSVKlyhwCIl9LfC1YFM2IxlChsFhfC0rrRLDlvQOkdZEgxmuigB4WqAji/TVKp7OZFRh3zLByE= X-Spam-Status: No, score=-3019.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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 In commit 64a97606 ("Support template lookups in strncmp_iw_with_mode"), gdb was changed so that a command like "break func" would match instantiations like "func>". The new indexer does not support this and so this is a regression. This went unnoticed because gdb.linespec.cpcompletion.exp puts all these functions into the main file, and this CU is expanded early. This patch fixes the bug by changing the cooked index entry comparison function. It also updates the test to fail without this fix. Regression tested on x86-64 Fedora 40. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32482 --- gdb/dwarf2/cooked-index.c | 51 +++++++++++---------- gdb/testsuite/gdb.linespec/cpcompletion.cc | 23 ++++++++++ gdb/testsuite/gdb.linespec/cpcompletion.exp | 5 +- gdb/testsuite/gdb.linespec/cpls.cc | 2 +- 4 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 gdb/testsuite/gdb.linespec/cpcompletion.cc diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index d776f2f9bca..e024c78cf51 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -93,39 +93,37 @@ int cooked_index_entry::compare (const char *stra, const char *strb, comparison_mode mode) { - auto munge = [] (char c) -> unsigned char + auto munge = [] (char c) constexpr -> unsigned char { - /* We want to sort '<' before any other printable character. - So, rewrite '<' to something just before ' '. */ + /* Treat '<' as if it ended the string. This lets something + like "func" match "func>". See the "Breakpoints in + template functions" section in the manual. */ if (c == '<') - return '\x1f'; + return '\0'; return TOLOWER ((unsigned char) c); }; - while (*stra != '\0' - && *strb != '\0' - && (munge (*stra) == munge (*strb))) + unsigned char a = munge (*stra); + unsigned char b = munge (*strb); + + while (a != '\0' && b != '\0' && a == b) { - ++stra; - ++strb; + a = munge (*++stra); + b = munge (*++strb); } - unsigned char c1 = munge (*stra); - unsigned char c2 = munge (*strb); - - if (c1 == c2) + if (a == b) return 0; /* When completing, if STRB ends earlier than STRA, consider them as - equal. When comparing, if STRB ends earlier and STRA ends with - '<', consider them as equal. */ - if (mode == COMPLETE || (mode == MATCH && c1 == munge ('<'))) + equal. */ + if (mode == COMPLETE || (mode == MATCH && a == munge ('<'))) { - if (c2 == '\0') + if (b == '\0') return 0; } - return c1 < c2 ? -1 : 1; + return a < b ? -1 : 1; } #if GDB_SELF_TEST @@ -155,33 +153,36 @@ test_compare () mode_complete) == 0); SELF_CHECK (cooked_index_entry::compare ("name", "name<>", - mode_compare) < 0); + mode_compare) == 0); SELF_CHECK (cooked_index_entry::compare ("name<>", "name", mode_compare) == 0); SELF_CHECK (cooked_index_entry::compare ("name", "name<>", - mode_complete) < 0); + mode_complete) == 0); SELF_CHECK (cooked_index_entry::compare ("name<>", "name", mode_complete) == 0); SELF_CHECK (cooked_index_entry::compare ("name", "name", mode_compare) == 0); SELF_CHECK (cooked_index_entry::compare ("name", "name", - mode_compare) > 0); + mode_compare) == 0); SELF_CHECK (cooked_index_entry::compare ("name", "name", mode_complete) == 0); SELF_CHECK (cooked_index_entry::compare ("name", "name", - mode_complete) > 0); + mode_complete) == 0); SELF_CHECK (cooked_index_entry::compare ("name>", "name>", mode_compare) == 0); + SELF_CHECK (cooked_index_entry::compare ("name", + "name>", + mode_compare) == 0); SELF_CHECK (cooked_index_entry::compare ("name", "name>", - mode_compare) < 0); + mode_compare) == 0); SELF_CHECK (cooked_index_entry::compare ("name>", "name", mode_compare) == 0); SELF_CHECK (cooked_index_entry::compare ("name>", "name 0); + mode_compare) == 0); SELF_CHECK (cooked_index_entry::compare ("name>", "name", - mode_sort) < 0); + mode_sort) == 0); SELF_CHECK (cooked_index_entry::compare ("func", "func1", mode_sort) < 0); } diff --git a/gdb/testsuite/gdb.linespec/cpcompletion.cc b/gdb/testsuite/gdb.linespec/cpcompletion.cc new file mode 100644 index 00000000000..5b050d3814f --- /dev/null +++ b/gdb/testsuite/gdb.linespec/cpcompletion.cc @@ -0,0 +1,23 @@ +/* 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 . */ + +extern int not_really_main (); + +int main () +{ + return not_really_main (); +} diff --git a/gdb/testsuite/gdb.linespec/cpcompletion.exp b/gdb/testsuite/gdb.linespec/cpcompletion.exp index 09bd9a25d77..2293238d011 100644 --- a/gdb/testsuite/gdb.linespec/cpcompletion.exp +++ b/gdb/testsuite/gdb.linespec/cpcompletion.exp @@ -18,14 +18,14 @@ load_lib completion-support.exp load_lib data-structures.exp -standard_testfile cpls.cc cpls2.cc cpls-hyphen.cc +standard_testfile cpcompletion.cc cpls.cc cpls2.cc cpls-hyphen.cc set opts {} lappend opts debug lappend opts additional_flags=-std=c++11 if {[prepare_for_testing "failed to prepare" $testfile \ - [list $srcfile $srcfile2 $srcfile3] $opts]} { + [list $srcfile $srcfile2 $srcfile3 $srcfile4] $opts]} { return -1 } @@ -666,6 +666,7 @@ proc_with_prefix template-function-foo {} { $completion_list check_setting_bp_fails "$cmd_prefix foo" should give any function with one parameter of any type # of A. While the parameter list in the template should be ignored, # the function's argument list should not be ignored. diff --git a/gdb/testsuite/gdb.linespec/cpls.cc b/gdb/testsuite/gdb.linespec/cpls.cc index 9f24e47fb92..0ab7ad3e195 100644 --- a/gdb/testsuite/gdb.linespec/cpls.cc +++ b/gdb/testsuite/gdb.linespec/cpls.cc @@ -486,7 +486,7 @@ file_constrained_test_cpls_function (int i) int -main () +not_really_main () { template2_struct_inst.template2_fn (); template_struct_int.template_overload_fn(0);