From patchwork Sun Apr 21 17:00:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88815 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 BDC50384AB6F for ; Sun, 21 Apr 2024 17:01:13 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id 74D003858D33 for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 74D003858D33 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 74D003858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; cv=none; b=hz4id644V+86R1olbEV2o9zpiLKx+66bs/aS1nK+KgTgaarwvvkXGKErDJLHQS8oAp4ug+NSasSXPdnvHzvFgHKtzqkPZIEhyMJic4gDXFcqo9YKaC3xfFGLJO0w0L5mGUH3qRIPitF98i9iEzrE5mwUQmFqtfXskP/axiqqU1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; c=relaxed/simple; bh=stc/VN+df0vOZk8qNpTtoa89cz/3jP4G3gz+1te3jFU=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=eCRuf0l3DR62rdyrpJB4YAgHpJ14bxLGtldHXblkGiOkk0YSzT/9Oxf+wcrI/Lhjricc7G/NFmW98+52WeVaSuncXjo4IRVi7OxshUs1ogzxifISrMnOO2ivF7rq5T+/xndOpoZAzvlhILvdyPxUySlhvPaiA5MBtmHKUjcRqyI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTPS id yZqkr6kMyHXmAyaXsr1W0Q; Sun, 21 Apr 2024 17:00:04 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXrrHUTOqaR9yaXrrFQmt; Sun, 21 Apr 2024 17:00:03 +0000 X-Authority-Analysis: v=2.4 cv=MqZU6Xae c=1 sm=1 tr=0 ts=66254613 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=oYOYw8Ultr3lYnx_CakA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=YezpLC9zPUxKKus0p/zvBygdwOJIK7EvTnZpH9TkjOo=; b=MxJcW5kfvvMHFNL5Bow0K3/kYU qfDTf5kasWIgq7xbfglD0V57l7B87bODwZ6FR/VWz5Ric1te20i0JR5sMzNItv62wvLL+AGn/fII/ DwHzmCqDg9FJAttPVR13+V456; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXq-003wVC-1t for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:02 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:01 -0600 Subject: [PATCH 01/10] Remove test code from cp-name-parser.y MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-1-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXq-003wVC-1t X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfGAdfnGFHmzHMvXCRxjavv5TzJIZrMzeZX/xjQRrkLMA+vK0fuvoMRDyLV6EPekds+mJ2Nw4XbX9Wwwq9pjvbiK0MuCmA1GhBJt1n+SKAtKkkwxq8eDe RCx2fpzyCK4EPM8IX5TGwlJuJRfMMaijorgYVE7MzOQsF1WRvX9YWC2BbPUItIO9ZdeUcSMP4Lejxbz3kLaMGwaHfBQenkDBWrw= X-Spam-Status: No, score=-3021.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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 This removes the current test 'main' from cp-name-parser.y. There aren't any tests using this, and nowadays it would be better as a unit test. --- gdb/Makefile.in | 15 +----- gdb/cp-name-parser.y | 135 --------------------------------------------------- gdb/yy-remap.h | 4 -- 3 files changed, 1 insertion(+), 153 deletions(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 23894ea4a4d..2f7fc1ca249 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2147,16 +2147,6 @@ uninstall: force $(CONFIG_UNINSTALL) rm -f $(DESTDIR)$(bindir)/$$transformed_name @$(MAKE) DO=uninstall "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do -# The C++ name parser can be built standalone for testing. -test-cp-name-parser.o: cp-name-parser.c - $(COMPILE) -DTEST_CPNAMES cp-name-parser.c - $(POSTCOMPILE) - -test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY) - $(ECHO_CXXLD) $(CC_LD) $(INTERNAL_LDFLAGS) \ - -o test-cp-name-parser$(EXEEXT) test-cp-name-parser.o \ - $(LIBIBERTY) - # We do this by grepping through sources. If that turns out to be too slow, # maybe we could just require every .o file to have an initialization routine # of a given name (top.o -> _initialize_top, etc.). @@ -2168,7 +2158,6 @@ test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY) # computing the list of source files from the list of object files. INIT_FILES_FILTER_OUT = \ - cp-name-parser.o \ init.o \ version.o \ xml-builtin.o \ @@ -2244,7 +2233,6 @@ clean mostlyclean: $(CONFIG_CLEAN) rm -f init.c stamp-init version.c stamp-version rm -f gdb$(EXEEXT) core make.log rm -f gdb[0-9]$(EXEEXT) - rm -f test-cp-name-parser$(EXEEXT) rm -f xml-builtin.c stamp-xml rm -f $(DEPDIR)/* for i in $(CONFIG_SRC_SUBDIR); do \ @@ -2677,8 +2665,7 @@ endif # A list of all the objects we might care about in this build, for # dependency tracking. -all_object_files = gdb.o $(LIBGDB_OBS) gdbtk-main.o \ - test-cp-name-parser.o +all_object_files = gdb.o $(LIBGDB_OBS) gdbtk-main.o # All the .deps files to include. all_deps_files = $(foreach dep,$(patsubst %.o,%.Po,$(all_object_files)),\ diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 87f13445bba..9f4561a36b4 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -171,11 +171,6 @@ cpname_state::d_grab () #define INT_SIGNED (1 << 4) #define INT_UNSIGNED (1 << 5) -/* Enable yydebug for the stand-alone parser. */ -#ifdef TEST_CPNAMES -# define YYDEBUG 1 -#endif - /* Helper functions. These wrap the demangler tree interface, handle allocation from our global store, and return the allocated component. */ @@ -2051,133 +2046,3 @@ cp_demangled_name_to_comp (const char *demangled_name, return result; } - -#ifdef TEST_CPNAMES - -static void -cp_print (struct demangle_component *result) -{ - char *str; - size_t err = 0; - - str = gdb_cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, result, 64, &err); - if (str == NULL) - return; - - fputs (str, stdout); - - free (str); -} - -static char -trim_chars (char *lexptr, char **extra_chars) -{ - char *p = (char *) symbol_end (lexptr); - char c = 0; - - if (*p) - { - c = *p; - *p = 0; - *extra_chars = p + 1; - } - - return c; -} - -/* When this file is built as a standalone program, xmalloc comes from - libiberty --- in which case we have to provide xfree ourselves. */ - -void -xfree (void *ptr) -{ - if (ptr != NULL) - { - /* Literal `free' would get translated back to xfree again. */ - CONCAT2 (fr,ee) (ptr); - } -} - -/* GDB normally defines internal_error itself, but when this file is built - as a standalone program, we must also provide an implementation. */ - -void -internal_error (const char *file, int line, const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - fprintf (stderr, "%s:%d: internal error: ", file, line); - vfprintf (stderr, fmt, ap); - exit (1); -} - -int -main (int argc, char **argv) -{ - char *str2, *extra_chars, c; - char buf[65536]; - int arg; - - arg = 1; - if (argv[arg] && strcmp (argv[arg], "--debug") == 0) - { - yydebug = 1; - arg++; - } - - if (argv[arg] == NULL) - while (fgets (buf, 65536, stdin) != NULL) - { - buf[strlen (buf) - 1] = 0; - /* Use DMGL_VERBOSE to get expanded standard substitutions. */ - c = trim_chars (buf, &extra_chars); - str2 = cplus_demangle (buf, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE); - if (str2 == NULL) - { - printf ("Demangling error\n"); - if (c) - printf ("%s%c%s\n", buf, c, extra_chars); - else - printf ("%s\n", buf); - continue; - } - - std::string errmsg; - std::unique_ptr result - = cp_demangled_name_to_comp (str2, &errmsg); - if (result == NULL) - { - fputs (errmsg.c_str (), stderr); - fputc ('\n', stderr); - continue; - } - - cp_print (result->tree); - - free (str2); - if (c) - { - putchar (c); - fputs (extra_chars, stdout); - } - putchar ('\n'); - } - else - { - std::string errmsg; - std::unique_ptr result - = cp_demangled_name_to_comp (argv[arg], &errmsg); - if (result == NULL) - { - fputs (errmsg.c_str (), stderr); - fputc ('\n', stderr); - return 0; - } - cp_print (result->tree); - putchar ('\n'); - } - return 0; -} - -#endif diff --git a/gdb/yy-remap.h b/gdb/yy-remap.h index d52a59d11b9..e32ce394339 100644 --- a/gdb/yy-remap.h +++ b/gdb/yy-remap.h @@ -93,8 +93,4 @@ # define YYDEBUG 1 /* Default to yydebug support */ #endif -#ifndef TEST_CPNAMES -# define YYFPRINTF parser_fprintf -#endif - #endif /* YY_REMAP_H */ From patchwork Sun Apr 21 17:00:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88812 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 264AD385842D for ; Sun, 21 Apr 2024 17:00:36 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id 9B0083858D28 for ; Sun, 21 Apr 2024 17:00:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B0083858D28 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 9B0083858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; cv=none; b=wGrRV/jYnwvXRyQRBPHPC74kFqEL3zb4LdNtxmF1h8MyF7Bdi6/XhF7/AqBl1AMCI9pWuYbJ0Ppy0A5RzXXNSCl5uwa4SV+qFzeLUqv8vEu+wQQWp7nQeBxWMHBNqCzxBk9WuT7eqhy4tXQ9jS6bPP1n+9JEmydrfPFtpcvqxtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; c=relaxed/simple; bh=rzA7W2OPLL6icsiyVKp7u3kF0xbBqB2zAL/cbX5ljP8=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=RPTdOa8eYe2SoQhgL6L8WzR/KSH36FzPt9hS8seeD3FpC7q8fsRO7c4auMRImFqb3YBgv+V5V/QnwmG3epSyzwMFWnPuRZv4/AjOkMesaKvkldqvT1W+rZCL1FJOdEzS3oOc9ikx1ZJTFTjrmDOzA4ZuUQWKxDGTJQrGnZDQJIc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6002a.ext.cloudfilter.net ([10.0.30.222]) by cmsmtp with ESMTPS id yZvzrEQKOQr4SyaXsrn4r8; Sun, 21 Apr 2024 17:00:04 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXrrPsPgiKqRyaXrrylJ2; Sun, 21 Apr 2024 17:00:03 +0000 X-Authority-Analysis: v=2.4 cv=I9quR8gg c=1 sm=1 tr=0 ts=66254613 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=ToalVDDbPj6qE0ikdkEA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WKvGjUaWKCs3Ln4Ie3apdjy5p3qUi1Bn73whWhytuDE=; b=fdknly6BkOlQKW353wdFFLkdsN 0JKz2QIlzjqW7R9tpV4xLcLBFVPU50H7ob9QoqTvbjfodbOmUEzbGJzGzdFEyCKUYCbWw7HOqai4v YqPN7EC3uKG67bF+HD6KxiYrZ; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXq-003wVC-2u for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:02 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:02 -0600 Subject: [PATCH 02/10] Allow initialization functions in .y files MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-2-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXq-003wVC-2u X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfJAhCcvv0juDrxRKcshuPxnCcMPLnGhYn47nF9SBRnHlAkT3gu4AfAbah9BfqMOP0YE+2ACrrxuQEC/cmHFgSDLEG69NVa48Ws5L6jZEn5/WGNgeJgf+ QhZvXLyUsUf4MZzZIvt+hAHg3D1gcwmcElmwgKtX5Y4ESLOxqf5Z/7VXEWZ/SfyRmrm+0eY4NFryb2wjxw3mTsg43J2n1FVBmko= X-Spam-Status: No, score=-3021.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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 If you add an initialization function to a .y file, it will not show up in init.c, because if the yacc output is in the build tree, it won't be found. This patch changes the Makefile to be more robust in this situation. --- gdb/Makefile.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 2f7fc1ca249..b51a294ed88 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2172,7 +2172,9 @@ INIT_FILES = \ init.c: stamp-init; @true stamp-init: $(INIT_FILES) config.status $(srcdir)/make-init-c $(ECHO_INIT_C) - $(SILENCE) $(srcdir)/make-init-c $(addprefix $(srcdir)/,$(INIT_FILES)) > init.c-tmp + $(SILENCE) $(srcdir)/make-init-c \ + $(filter-out config.status $(srcdir)/make-init-c,$^) \ + > init.c-tmp $(SILENCE) $(SHELL) $(srcdir)/../move-if-change init.c-tmp init.c $(SILENCE) echo stamp > stamp-init From patchwork Sun Apr 21 17:00:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88813 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 6CB4A3858427 for ; Sun, 21 Apr 2024 17:00:44 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by sourceware.org (Postfix) with ESMTPS id 71FF93858D32 for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71FF93858D32 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 71FF93858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; cv=none; b=oYbn3uGkXJeFZc2o8f59Dy8D9fXYPWIgeRzilxEnVU3Z/HecMBGdKpNTtYcsmbCCsKB1EZHXYOnp2L+iDKyPkzTGG8ChBVVPBpQgdGmdrrJ3kR3NBmjMiD7V7efHP3d+oVzRh0nWi14cASXTltaSS54bMTnVVtlJx1/TGURXnhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; c=relaxed/simple; bh=M33kCx4IkqgWOdDFeqqEc0pgKkiu+FkIGhjmnkE84DE=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=KsgrW0l6L+Fvv1FDqFw2jXvRSQxfuQ/XseVmNKYfxVRIVJgFSAuo6o3jmpvneSSBLFuV8c6YUklkVEQSxuQBuIlonrMl/Fq5HZ8o5MfrXckUnM5yZV5SxwoYLAUuppPzwh2EUxHfj5O8YtFupvuvaYXvsDTMJtPM5+9y+/bpr9w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6009a.ext.cloudfilter.net ([10.0.30.184]) by cmsmtp with ESMTPS id yZz2rdCrJtf2QyaXsr8MA2; Sun, 21 Apr 2024 17:00:04 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXrrMmwunNCOyaXrrqNra; Sun, 21 Apr 2024 17:00:03 +0000 X-Authority-Analysis: v=2.4 cv=DKCJ4TNb c=1 sm=1 tr=0 ts=66254613 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=bIOnnnKIXOO2lmqm6MUA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=J0j3eF3oob432FfBCeu7fYv3MYcdi4xmeETvrSFv7j0=; b=piD0Im8zpR3RFT2gPnGoUw8q7z U5Amc6grD+0f3+3f4zsH9pNeoFgD1AOURspjajuM0o4UwOD+Mk5WQXeKakl2cf2AmkOfBvZ4DKldn 8LU7j6tUYV/jIGReTvXa7O0A9; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXr-003wVC-0i for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:03 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:03 -0600 Subject: [PATCH 03/10] Clean up demangle_parse_info MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-3-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXr-003wVC-0i X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfI1n/hsdVIPKoa5HsUNHYIz0UWO4J8EaCZ0rx9Eq973M1YXFDMoyLWIeMKgtswxPQ1yR8GYvX1IHqfJY5AvQ2DY6exJDQbVawU/s+8RWFfS1xVYGNyQQ RVtJyHZuSEZlT0+oWa6lgWX3LTwpxU6VHzDkOLpQLm2ZmuN/c9jtYkWBta5i9OK0BD3PvbxwWII0ke56PKWA6qjTZPd7RqaDKNA= X-Spam-Status: No, score=-3021.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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 This changes demangle_parse_info to use inline initializers and to remove some manual memory management. --- gdb/cp-name-parser.y | 12 ------------ gdb/cp-support.h | 8 ++++---- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 9f4561a36b4..2f73be35f37 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -1959,15 +1959,6 @@ cp_comp_to_string (struct demangle_component *result, int estimated_len) return gdb::unique_xmalloc_ptr (res); } -/* Constructor for demangle_parse_info. */ - -demangle_parse_info::demangle_parse_info () -: info (NULL), - tree (NULL) -{ - obstack_init (&obstack); -} - /* Destructor for demangle_parse_info. */ demangle_parse_info::~demangle_parse_info () @@ -1980,9 +1971,6 @@ demangle_parse_info::~demangle_parse_info () free (info); info = next; } - - /* Free any memory allocated during typedef replacement. */ - obstack_free (&obstack, NULL); } /* Merge the two parse trees given by DEST and SRC. The parse tree diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 4015126154b..d0bedcd7b80 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -58,18 +58,18 @@ struct using_direct; struct demangle_parse_info { - demangle_parse_info (); + demangle_parse_info () = default; ~demangle_parse_info (); /* The memory used during the parse. */ - struct demangle_info *info; + struct demangle_info *info = nullptr; /* The result of the parse. */ - struct demangle_component *tree; + struct demangle_component *tree = nullptr; /* Any temporary memory used during typedef replacement. */ - struct obstack obstack; + auto_obstack obstack; }; From patchwork Sun Apr 21 17:00:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88818 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 564CB384AB5D for ; Sun, 21 Apr 2024 17:01:36 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id 77E573858D34 for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77E573858D34 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 77E573858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; cv=none; b=rzd5BSmfYnh8vPTetpD3XAExviCAAxO8duTKY1Lv/ROQCbDZNQ6Ft74kJpPOVUQIOK1PmZm0DKeUKlqS+8gI/nsdckfcBqArTf78wK6PqihbQFMXk0h0fS1ouDH/JhmdQCKba/0bLrgTiXKdt6TxuVII5ywiPzsR9gYREC1httU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; c=relaxed/simple; bh=3v29XyiZuuW/mfPv6sHEjYkMTna4IRPwMc+hAWooquY=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=sJiC7SL/1epQAEXbYGa35XCttD60TYZkIlV/HsoAHpvihusPlFYiYxFt7Xyotmn28y0TEsryYHx4LHeNlDrpMhfIW1A7Umou6gH/U1jq5ZFFY6rqTShWy7xxtBoLtWXRBs7jIiVfjMonup/ha8Qej3LGN8BqxspxxMOrbrScyiI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6002a.ext.cloudfilter.net ([10.0.30.222]) by cmsmtp with ESMTPS id yPDar5BaSHXmAyaXsr1W0j; Sun, 21 Apr 2024 17:00:04 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXrrPsRUiKqRyaXsrylKB; Sun, 21 Apr 2024 17:00:04 +0000 X-Authority-Analysis: v=2.4 cv=I9quR8gg c=1 sm=1 tr=0 ts=66254614 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=s53vAFbfyyM1y-YKfssA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ZMQ5AVvo8eTnGbQqjNHNpuD2o+K8J0a6A03beNRp6so=; b=shuJo0+9ADa90BhWmV58x+/Neu fxy+eiBzeR76AN8iEos+TsY0qBFLTsh/T5+e/rdnNnFKrzJV2eis9DGPOdS8Vb6uf42CQU3WEZmfF Qqv0S/7qgf5nHtHKNfma2Jw4Q; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXr-003wVC-1V for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:03 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:04 -0600 Subject: [PATCH 04/10] Change storage of demangle_component MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-4-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXr-003wVC-1V X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfPeNkiJHuRUhxf7eRjxUJy6PxbBHBbO6q9rbj0b+impHl70VU2PCMOtckNcLc//qEPSQ+qmJ0geMnnaYRW5u+iRG3wtNFQuMA0nnqs2Na4UzoWF8oBDE CqrN5OY6ncn2pfVcEt8Q9GiGqcSZfnb/33lLLA9RoTafZfyxqOiEC3sk8SrfGtVm1/gJl3Cea8tCyxx3N67nYV39XFcGVXRSYrc= X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT 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 changes demangle_component objects to be stored on the obstack that is part of demangle_info. It also arranges for a demangle_info object to be kept alive by cp_merge_demangle_parse_infos. This way, other data on the obstack can be kept while an "outer" demangle_info needs it. Acked-By: John Baldwin --- gdb/cp-name-parser.y | 78 +++++----------------------------------------------- gdb/cp-support.c | 2 +- gdb/cp-support.h | 15 ++++------ 3 files changed, 14 insertions(+), 81 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 2f73be35f37..6003ed0b01e 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -48,17 +48,6 @@ #define GDB_YY_REMAP_PREFIX cpname #include "yy-remap.h" -/* The components built by the parser are allocated ahead of time, - and cached in this structure. */ - -#define ALLOC_CHUNK 100 - -struct demangle_info { - int used; - struct demangle_info *next; - struct demangle_component comps[ALLOC_CHUNK]; -}; - %} %union @@ -92,7 +81,7 @@ struct cpname_state const char *lexptr, *prev_lexptr, *error_lexptr, *global_errmsg; - struct demangle_info *demangle_info; + demangle_parse_info *demangle_info; /* The parse tree created by the parser is stored here after a successful parse. */ @@ -136,23 +125,7 @@ struct cpname_state struct demangle_component * cpname_state::d_grab () { - struct demangle_info *more; - - if (demangle_info->used >= ALLOC_CHUNK) - { - if (demangle_info->next == NULL) - { - more = XNEW (struct demangle_info); - more->next = NULL; - demangle_info->next = more; - } - else - more = demangle_info->next; - - more->used = 0; - demangle_info = more; - } - return &demangle_info->comps[demangle_info->used++]; + return obstack_new (&demangle_info->obstack); } /* Flags passed to d_qualify. */ @@ -1933,20 +1906,6 @@ yyerror (cpname_state *state, const char *msg) state->global_errmsg = msg ? msg : "parse error"; } -/* Allocate a chunk of the components we'll need to build a tree. We - generally allocate too many components, but the extra memory usage - doesn't hurt because the trees are temporary and the storage is - reused. More may be allocated later, by d_grab. */ -static struct demangle_info * -allocate_info (void) -{ - struct demangle_info *info = XNEW (struct demangle_info); - - info->next = NULL; - info->used = 0; - return info; -} - /* See cp-support.h. */ gdb::unique_xmalloc_ptr @@ -1959,20 +1918,6 @@ cp_comp_to_string (struct demangle_component *result, int estimated_len) return gdb::unique_xmalloc_ptr (res); } -/* Destructor for demangle_parse_info. */ - -demangle_parse_info::~demangle_parse_info () -{ - /* Free any allocated chunks of memory for the parse. */ - while (info != NULL) - { - struct demangle_info *next = info->next; - - free (info); - info = next; - } -} - /* Merge the two parse trees given by DEST and SRC. The parse tree in SRC is attached to DEST at the node represented by TARGET. @@ -1986,21 +1931,14 @@ demangle_parse_info::~demangle_parse_info () void cp_merge_demangle_parse_infos (struct demangle_parse_info *dest, struct demangle_component *target, - struct demangle_parse_info *src) + std::unique_ptr src) { - struct demangle_info *di; - /* Copy the SRC's parse data into DEST. */ *target = *src->tree; - di = dest->info; - while (di->next != NULL) - di = di->next; - di->next = src->info; - - /* Clear the (pointer to) SRC's parse data so that it is not freed when - cp_demangled_parse_info_free is called. */ - src->info = NULL; + + /* Make sure SRC is owned by DEST. */ + dest->infos.push_back (std::move (src)); } /* Convert a demangled name to a demangle_component tree. On success, @@ -2018,10 +1956,8 @@ cp_demangled_name_to_comp (const char *demangled_name, state.error_lexptr = NULL; state.global_errmsg = NULL; - state.demangle_info = allocate_info (); - auto result = std::make_unique (); - result->info = state.demangle_info; + state.demangle_info = result.get (); if (yyparse (&state)) { diff --git a/gdb/cp-support.c b/gdb/cp-support.c index e6e811ddf50..4c64e4963e4 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -258,7 +258,7 @@ inspect_type (struct demangle_parse_info *info, if (i != NULL) { /* Merge the two trees. */ - cp_merge_demangle_parse_infos (info, ret_comp, i.get ()); + cp_merge_demangle_parse_infos (info, ret_comp, std::move (i)); /* Replace any newly introduced typedefs -- but not if the type is anonymous (that would lead to infinite diff --git a/gdb/cp-support.h b/gdb/cp-support.h index d0bedcd7b80..765c4435f41 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -58,18 +58,15 @@ struct using_direct; struct demangle_parse_info { - demangle_parse_info () = default; - - ~demangle_parse_info (); - - /* The memory used during the parse. */ - struct demangle_info *info = nullptr; - /* The result of the parse. */ struct demangle_component *tree = nullptr; - /* Any temporary memory used during typedef replacement. */ + /* Any memory used during processing. */ auto_obstack obstack; + + /* Any other objects referred to by this object, and whose storage + lifetime must be linked. */ + std::vector> infos; }; @@ -182,7 +179,7 @@ extern gdb::unique_xmalloc_ptr cp_comp_to_string extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *, struct demangle_component *, - struct demangle_parse_info *); + std::unique_ptr); /* The list of "maint cplus" commands. */ From patchwork Sun Apr 21 17:00:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88821 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 2A3A43858CDB for ; Sun, 21 Apr 2024 17:02:14 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id B9C8C3858CDB for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9C8C3858CDB 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 B9C8C3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; cv=none; b=IkYBCu+bu/QSfQQF9GxkJsYKtMNazUuLiEr7n664k/drhM55AwBAsWVKZZNHSMRYOqQLVPkNs68DyC57nsgY3B3srEJ9XfDr1tbLoWI8euFpLmJpK/crm3dODbSumyNq3W5oCeM0qkojBU4XTVoavpNEkkuSEF/TDSmCoVGpcvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; c=relaxed/simple; bh=SSgoKKki7ZchFUGwoO95hqydUNFpl1xK18Cyr5QBEBw=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=BmALAAabOMz8s8xehmC7mRk8esjK3PP9Mh8LPU3fBCGZWCiwY83k1kNXNLXgecAR6eMqLphx2HsC6Nx415lFUcuxDuohJorNPf692k/WQxxEJoy5Mz1qP1SpLvTmcuoMRxFZBHWbw1Al40tUB3335BkUacVISV2dJldQn8vWoto= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6010a.ext.cloudfilter.net ([10.0.30.248]) by cmsmtp with ESMTPS id yDljrxPcePM1hyaXsr0bYg; Sun, 21 Apr 2024 17:00:04 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXrrYqd4F4XpyaXsrsxcx; Sun, 21 Apr 2024 17:00:04 +0000 X-Authority-Analysis: v=2.4 cv=UpZlNfwB c=1 sm=1 tr=0 ts=66254614 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=82lU6H3CqPhDl4Y7wgwA:9 a=QEXdDO2ut3YA:10 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=tP7PFHG5YvheY7CBpDWR2TLOWxOOowuyXlh0o+siIGw=; b=vDtN9zMDhNX6pzzIfUfOYkrKG2 ICdbASrqH89f36asWsWjK/OJbzBq1QYMd6IngeWN51sTz5CTxqYkxRyVUBMEt6NpPolckekfIZhMF 4mb6kfHK34oWqdP/IPTh+6M3B; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXr-003wVC-25 for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:03 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:05 -0600 Subject: [PATCH 05/10] Fix C++ name canonicalizations of character literals MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-5-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXr-003wVC-25 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfB82lPRIgjYiXQ+H9gbVYauPXaVDFB2PXkn2oZw9nIL+9s4ccICYxT5cgsEVPic4t9fAUeBoOz8zh2qMtZry85JwLcrQ2/bSIZHSA5/mQ4JDdzDNAbu6 nHh515x8LOJTFDMRLqSiOExmveJomqoKoy9YMGXPFrxvs170rs8BbEHtXHzhd/hujLLhi02sIMGOulei8P+HLhniPyazL9mDco4= X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT 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 The names "void C<(char)1>::m()" and "void C<'\001'>::m()" should canonicalize to the same string, but currently they do not -- the former remains unchanged and the latter is transformed to "void C<(char)'\001'>::m()". This patch fixes the bug and also adds some unit tests. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16843 --- gdb/cp-name-parser.y | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 6003ed0b01e..6590194545f 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -44,6 +44,7 @@ #include "cp-support.h" #include "c-support.h" #include "parser-defs.h" +#include "gdbsupport/selftest.h" #define GDB_YY_REMAP_PREFIX cpname #include "yy-remap.h" @@ -1514,6 +1515,7 @@ yylex (YYSTYPE *lvalp, cpname_state *state) int c; int namelen; const char *tokstart; + char *copy; retry: state->prev_lexptr = state->lexptr; @@ -1544,6 +1546,10 @@ yylex (YYSTYPE *lvalp, cpname_state *state) return ERROR; } + /* We over-allocate here, but it doesn't really matter . */ + copy = (char *) obstack_alloc (&state->demangle_info->obstack, 30); + xsnprintf (copy, 30, "%d", c); + c = *state->lexptr++; if (c != '\'') { @@ -1551,15 +1557,10 @@ yylex (YYSTYPE *lvalp, cpname_state *state) return ERROR; } - /* FIXME: We should refer to a canonical form of the character, - presumably the same one that appears in manglings - the decimal - representation. But if that isn't in our input then we have to - allocate memory for it somewhere. */ lvalp->comp = state->fill_comp (DEMANGLE_COMPONENT_LITERAL, state->make_builtin_type ("char"), - state->make_name (tokstart, - state->lexptr - tokstart)); + state->make_name (copy, strlen (copy))); return INT; @@ -1970,3 +1971,39 @@ cp_demangled_name_to_comp (const char *demangled_name, return result; } + +#if GDB_SELF_TEST + +static void +should_be_the_same (const char *one, const char *two) +{ + gdb::unique_xmalloc_ptr cpone = cp_canonicalize_string (one); + gdb::unique_xmalloc_ptr cptwo = cp_canonicalize_string (two); + + if (cpone != nullptr) + one = cpone.get (); + if (cptwo != nullptr) + two = cptwo.get (); + + SELF_CHECK (strcmp (one, two) == 0); +} + +static void +canonicalize_tests () +{ + should_be_the_same ("short int", "short"); + should_be_the_same ("int short", "short"); + + should_be_the_same ("C<(char) 1>::m()", "C<(char) '\\001'>::m()"); +} + +#endif + +void _initialize_cp_name_parser (); +void +_initialize_cp_name_parser () +{ +#if GDB_SELF_TEST + selftests::register_test ("canonicalize", canonicalize_tests); +#endif +} From patchwork Sun Apr 21 17:00:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88814 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 A22943858C33 for ; Sun, 21 Apr 2024 17:01:11 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id C14EA3858C52 for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C14EA3858C52 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 C14EA3858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; cv=none; b=vA5TDgLW7d8Dm3/hP76uU9QPMNMOQ7oQLIE6Gr+mYeba/SsZlDcat2HmYwDRUFu0ta2+OqOzxaEM2YL+WqunJoYKbari7YvheQkQvhLmqBcCMq8zPRToXHvxHiQ4M5TbMYUFQShiI/iA26fcQ5VP+8Gije6Ec8SX/3QoLqHLb18= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; c=relaxed/simple; bh=jk09xPBomjNMBohbC8LQX13fRS7MCcpe6jRuhlDJgWI=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=rrRsoKPLC65fJmXXDITTX4VeJ0xrEiGE4Aj/gtQFgmmwG3MOQ65mvGl935Mbrf64uRpXWQHrloLaId25hOSiAr3T8zg1qzI/OnMlVuCATRxCv1eKEnxsQrAZQp3s2cBU+Abf2vHaYDS/y1gXSd1CYxbHobpZuBZaLt+A0NiJc9Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6007a.ext.cloudfilter.net ([10.0.30.247]) by cmsmtp with ESMTPS id yZz3rER6eQr4SyaXtrn4uI; Sun, 21 Apr 2024 17:00:05 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXsrRZebVdenyaXsrOcUU; Sun, 21 Apr 2024 17:00:04 +0000 X-Authority-Analysis: v=2.4 cv=M4FLKTws c=1 sm=1 tr=0 ts=66254614 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=lfCki52Dxz4U2axuugIA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=2q+c9an4fwKkMQZ7rEfu+HiQVY7UAtBG3rPdVKXedKQ=; b=sRO62RMJ0TChoV9BiW2/XwiOco kID5w+Mlee6KnqqSwpfpcLc2CMM6Nv0kUC+kveqVLQWLA/s242riHS4c3XCarBjrXhPfl/i3D8EeT 2GHZ4NcSRc9h4ZMzph4USJBvr; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXr-003wVC-2j for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:03 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:06 -0600 Subject: [PATCH 06/10] Remove some unnecessary allocations from cpname_state::parse_number MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-6-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXr-003wVC-2j X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfBRZcqDqTeTqawFLPCHOk5ku7eeo0w10sNxZRMjoVTC+CyPy1qPfBgUFozZOrqFJdAhKFMU0Hdd/oOny/oCi6a1yVTN/1/1XjMg0eZApd5rq6QwFGqLQ n8ADwrNPvCMACKvmZA+7T5zwhBbaYXeGrPnmJ5Qod4WescxC1Hse5hnl8lCvkAtmVjawAaugZHChAQ5WWfpuKaqLy35PmF8vVUc= X-Spam-Status: No, score=-3021.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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 cpname_state::parse_number allocates nodes for various types and then only uses one of them. This patch reduces the number of allocations by not performing the unnecessary ones. --- gdb/cp-name-parser.y | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 6590194545f..692fe84071c 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -1290,8 +1290,6 @@ cpname_state::parse_number (const char *p, int len, int parsed_float, /* Number of "L" suffixes encountered. */ int long_p = 0; - struct demangle_component *signed_type; - struct demangle_component *unsigned_type; struct demangle_component *type, *name; enum demangle_component_type literal_type; @@ -1362,25 +1360,26 @@ cpname_state::parse_number (const char *p, int len, int parsed_float, if (long_p == 0) { - unsigned_type = make_builtin_type ("unsigned int"); - signed_type = make_builtin_type ("int"); + if (unsigned_p) + type = make_builtin_type ("unsigned int"); + else + type = make_builtin_type ("int"); } else if (long_p == 1) { - unsigned_type = make_builtin_type ("unsigned long"); - signed_type = make_builtin_type ("long"); + if (unsigned_p) + type = make_builtin_type ("unsigned long"); + else + type = make_builtin_type ("long"); } else { - unsigned_type = make_builtin_type ("unsigned long long"); - signed_type = make_builtin_type ("long long"); + if (unsigned_p) + type = make_builtin_type ("unsigned long long"); + else + type = make_builtin_type ("long long"); } - if (unsigned_p) - type = unsigned_type; - else - type = signed_type; - name = make_name (p, len); lvalp->comp = fill_comp (literal_type, type, name); From patchwork Sun Apr 21 17:00:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88819 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 B07AA385841D for ; Sun, 21 Apr 2024 17:01:47 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id B51413858D39 for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B51413858D39 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 B51413858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; cv=none; b=V/lFBuqHoL748Xy1oizvwk5/sLBs7a8J1iLUvLJV3jbHQChb+QxsLkPjrSo94P+ZRwRn9Dsytx6vkEDBVTNSaOuWYi+VKVWLKnvYe8LJiPGs1kLugIAoFlUg+0AzStq6UlDq6WoRonOsqQlYk11c0nGLdbDYavEuwJgOAWpiXjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; c=relaxed/simple; bh=Qa6AuZ9edXNc9BpG1xdfF4qNwdx15RnMyEKRcz4Ugks=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=Qg5+27svmw5jrXYGKK5Bpi/kbvENYmwfXkn75epY3HErNmVULBTq7/X4Uhhf+OdSyBQqYpQP3qHa/uIAY4k5IFUpsAIgowr23sDyrnOdogHYcZr33dEzgiXIO2wpr07bGu1CMk9lArBylONym0fjQweIFqbPiHsKO9DbCAK2AW4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6005a.ext.cloudfilter.net ([10.0.30.201]) by cmsmtp with ESMTPS id yZhdrENwgQr4SyaXtrn4uL; Sun, 21 Apr 2024 17:00:05 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXsrTVaSHHoAyaXsrC89X; Sun, 21 Apr 2024 17:00:04 +0000 X-Authority-Analysis: v=2.4 cv=dskQCEg4 c=1 sm=1 tr=0 ts=66254614 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=ABabXlRsB_jgEnb4OYkA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hsImkwtAlxwlGxTgzGVm3CrkwpzVWyEkwEku06EOm7I=; b=wYxJtNP8y9nuQUQZVAO8xOC/0Q i9qHZTqcGyB1gVvDQywZCFgmgL+DSrVx/RQnHzLxz+NHuShWQEHrB5qYV264Ue0xREVP4mZM+nPfU 17QFSBMeyBWuSpqswAZB7J/X0; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXs-003wVC-0C for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:04 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:07 -0600 Subject: [PATCH 07/10] Fix C++ canonicalization of hex literals MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-7-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXs-003wVC-0C X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfJmIq3UB6ldosvuv19P0NdEody8t4jSzQeq3gcPP82xjChdL0tLfMRnU2HXHmF2yazEtinZtn0x6QcH1B9uJdRAHKWJGNOSoeAep3MoF9Yo1tJ2Jf8Vt 7PKMjpLvltTVCluc483rAC9wtmfSEx4lOB6xcK8JqY544QrKAPIKcYG/uqEA3S7ZyK3CC6o4+tY48tDGqpWl0x4HwUtVCK+O910= X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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 Currently names like "x::y::z<1>" and "x::y::z<0x01>" canonicalize to different things. I think it's nicer for them to be the same. Differences between types can be done using suffixes like "ll" and "u" -- it's not really possible to implement C++ rules in the canoncalizer, because no gdbarch is available. Possibly gdb should even drop the type here and just represent all integers the same way in names. --- gdb/cp-name-parser.y | 61 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 692fe84071c..de08f9c0728 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -1336,8 +1336,35 @@ cpname_state::parse_number (const char *p, int len, int parsed_float, return FLOAT; } - /* This treats 0x1 and 1 as different literals. We also do not - automatically generate unsigned types. */ + /* Note that we do not automatically generate unsigned types. This + can't be done because we don't have access to the gdbarch + here. */ + + int base = 10; + if (len > 1 && p[0] == '0') + { + if (p[1] == 'x' || p[1] == 'X') + { + base = 16; + p += 2; + len -= 2; + } + else if (p[1] == 'b' || p[1] == 'B') + { + base = 2; + p += 2; + len -= 2; + } + else if (p[1] == 'd' || p[1] == 'D' || p[1] == 't' || p[1] == 'T') + { + /* Apparently gdb extensions. */ + base = 10; + p += 2; + len -= 2; + } + else + base = 8; + } long_p = 0; unsigned_p = 0; @@ -1358,6 +1385,24 @@ cpname_state::parse_number (const char *p, int len, int parsed_float, break; } + /* Use gdb_mpz here in case a 128-bit value appears. */ + gdb_mpz value (0); + for (int off = 0; off < len; ++off) + { + int dig; + if (ISDIGIT (p[off])) + dig = p[off] - '0'; + else + dig = TOLOWER (p[off]) - 'a' + 10; + if (dig >= base) + return ERROR; + value *= base; + value += dig; + } + + std::string printed = value.str (); + const char *copy = obstack_strdup (&demangle_info->obstack, printed); + if (long_p == 0) { if (unsigned_p) @@ -1380,10 +1425,10 @@ cpname_state::parse_number (const char *p, int len, int parsed_float, type = make_builtin_type ("long long"); } - name = make_name (p, len); - lvalp->comp = fill_comp (literal_type, type, name); + name = make_name (copy, strlen (copy)); + lvalp->comp = fill_comp (literal_type, type, name); - return INT; + return INT; } static const char backslashable[] = "abefnrtv"; @@ -1994,6 +2039,12 @@ canonicalize_tests () should_be_the_same ("int short", "short"); should_be_the_same ("C<(char) 1>::m()", "C<(char) '\\001'>::m()"); + should_be_the_same ("x::y::z<1>", "x::y::z<0x01>"); + should_be_the_same ("x::y::z<1>", "x::y::z<01>"); + should_be_the_same ("x::y::z<(unsigned long long) 1>", "x::y::z<01ull>"); + should_be_the_same ("x::y::z<0b111>", "x::y::z<7>"); + should_be_the_same ("x::y::z<0b111>", "x::y::z<0t7>"); + should_be_the_same ("x::y::z<0b111>", "x::y::z<0D7>"); } #endif From patchwork Sun Apr 21 17:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88816 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 8522C384AB55 for ; Sun, 21 Apr 2024 17:01:24 +0000 (GMT) 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 90E363858D37 for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90E363858D37 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 90E363858D37 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=1713718809; cv=none; b=rJonQR/W5ZMYXIyMowkCB1EMvyBSrW9KzaSFfuDmZ8ebL/dLIygFZNl5ERDbt82qhrm3OL24DLmiqcDoGCckxFZ54WhzdrLWdQYZRjzjpB/0w43qsNAuC+JTou+27D40PMTVDGsfbQMrIbr0F+TtVEtUB+8HcrZA47QAO5L0LxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; c=relaxed/simple; bh=FUvd3E6NY/BaJD6gUap1v040VhTmbBmYpS5VUlxEZaY=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=Gf8CQke2LgwcFjpfIZRmVJaDHi68wl0+qKNXB1gFpeExnuiUnln+G+1Ezdlj2BNPyj39tczshVuHoSqSY3dRAz0AFZaTu0CgAlJxaZShtH0n6yphMene73g4Ew1RBgJQk9OQ5yuZ5oP1C5QxMyo+lg7ZjSrT7DPVVjD3cNN2zTs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTPS id yZwgrgioJl9dRyaXtroVJ3; Sun, 21 Apr 2024 17:00:05 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXsrHUYKqaR9yaXsrFQqV; Sun, 21 Apr 2024 17:00:05 +0000 X-Authority-Analysis: v=2.4 cv=MqZU6Xae c=1 sm=1 tr=0 ts=66254615 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=UccFzhUPhoxR2GDChe0A:9 a=QEXdDO2ut3YA:10 a=CBL1k2pHJFWxAFsS4eF9:22 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=grzSZ7Hz2NxyJ1RpjF3TgEstqVrqY1nov/OJGXJpgbU=; b=hkLu/FXoF+dssEKcPvgRU6EzX0 XosRVcRW39lWTxU6ubbP6OE8t/USyZFcgH4QItDcp/tj1sZ2R0YB75zRKtKElRs3iZxjRd7o7WHIg +ViU+Cfya6L1a3GYSiEZik7bx; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXs-003wVC-0k for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:04 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:08 -0600 Subject: [PATCH 08/10] Implement C++14 numeric separators MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-8-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXs-003wVC-0k X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 9 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfB5iqFnJ3g/4FlYXYhVA6Z4iW08HobEC5Zg7/gl+TxhZnWILsW29Z2gjopd+dQDGfcXIKjHXKKbgxbQLv2LWRYJsYVyr4UV02LcRavFjqsOYrYU/RYLj 9bL2hv181YJDdlh2S5HK+2nx0sDgyf4NdMUxXG/+1ngs29foo1jaBow+yKtfiDPavTstfBEyAoUOKekD9r2rtDOos58hBW75SOw= X-Spam-Status: No, score=-3021.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT 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 C++14 allows the use of the apostrophe as a numeric separator; that is, "23000" and "23'000" represent the same number. This patch implements this for gdb's C++ parser and the C++ name canonicalizer. I did this unconditionally for all C variants because I think it's unambiguous. For the name canonicalizer, there's at least one compiler that can emit constants with this form, see bug 30845. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23457 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30845 --- gdb/c-exp.y | 28 +++++++++++++++++++++++----- gdb/cp-name-parser.y | 31 ++++++++++++++++++++++++++----- gdb/testsuite/gdb.cp/misc.exp | 4 ++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 663c30f9517..69cea523abd 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2755,6 +2755,10 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) hex = 0; } + /* If the token includes the C++14 digits separator, we make a + copy so that we don't have to handle the separator in + parse_number. */ + std::optional no_tick; for (;; ++p) { /* This test includes !hex because 'e' is a valid hex digit @@ -2771,18 +2775,32 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) else if (((got_e && (p[-1] == 'e' || p[-1] == 'E')) || (got_p && (p[-1] == 'p' || p[-1] == 'P'))) && (*p == '-' || *p == '+')) - /* This is the sign of the exponent, not the end of the - number. */ - continue; + { + /* This is the sign of the exponent, not the end of + the number. */ + } + else if (*p == '\'') + { + if (!no_tick.has_value ()) + no_tick.emplace (tokstart, p); + continue; + } /* We will take any letters or digits. parse_number will complain if past the radix, or if L or U are not final. */ else if ((*p < '0' || *p > '9') && ((*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z'))) break; + if (no_tick.has_value ()) + no_tick->push_back (*p); } - toktype = parse_number (par_state, tokstart, p - tokstart, - got_dot | got_e | got_p, &yylval); + if (no_tick.has_value ()) + toktype = parse_number (par_state, no_tick->c_str (), + no_tick->length (), + got_dot | got_e | got_p, &yylval); + else + toktype = parse_number (par_state, tokstart, p - tokstart, + got_dot | got_e | got_p, &yylval); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index de08f9c0728..3c5dea2de1c 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -1686,6 +1686,10 @@ yylex (YYSTYPE *lvalp, cpname_state *state) hex = 0; } + /* If the token includes the C++14 digits separator, we make a + copy so that we don't have to handle the separator in + parse_number. */ + std::optional no_tick; for (;; ++p) { /* This test includes !hex because 'e' is a valid hex digit @@ -1703,16 +1707,31 @@ yylex (YYSTYPE *lvalp, cpname_state *state) got_dot = 1; else if (got_e && (p[-1] == 'e' || p[-1] == 'E') && (*p == '-' || *p == '+')) - /* This is the sign of the exponent, not the end of the - number. */ - continue; + { + /* This is the sign of the exponent, not the end of + the number. */ + } + /* C++14 allows a separator. */ + else if (*p == '\'') + { + if (!no_tick.has_value ()) + no_tick.emplace (tokstart, p); + continue; + } /* We will take any letters or digits. parse_number will complain if past the radix, or if L or U are not final. */ else if (! ISALNUM (*p)) break; + if (no_tick.has_value ()) + no_tick->push_back (*p); } - toktype = state->parse_number (tokstart, p - tokstart, got_dot|got_e, - lvalp); + if (no_tick.has_value ()) + toktype = state->parse_number (no_tick->c_str (), + no_tick->length (), + got_dot|got_e, lvalp); + else + toktype = state->parse_number (tokstart, p - tokstart, + got_dot|got_e, lvalp); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); @@ -2045,6 +2064,8 @@ canonicalize_tests () should_be_the_same ("x::y::z<0b111>", "x::y::z<7>"); should_be_the_same ("x::y::z<0b111>", "x::y::z<0t7>"); should_be_the_same ("x::y::z<0b111>", "x::y::z<0D7>"); + + should_be_the_same ("x::y::z<0xff'ff>", "x::y::z<65535>"); } #endif diff --git a/gdb/testsuite/gdb.cp/misc.exp b/gdb/testsuite/gdb.cp/misc.exp index 264294f857d..bcb20f85eee 100644 --- a/gdb/testsuite/gdb.cp/misc.exp +++ b/gdb/testsuite/gdb.cp/misc.exp @@ -114,3 +114,7 @@ gdb_test "print *(number_ref + v_bool_array)" "\\$\[0-9\]* = false" \ "integer reference addition with pointer" gdb_test "print *(v_bool_array - number_ref)" "\\$\[0-9\]* = false" \ "pointer subtraction with integer reference" + +# C++14 digit separator. +gdb_test "print 23'23" " = 2323" +gdb_test "print 2'3.5" " = 23.5" From patchwork Sun Apr 21 17:00:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88820 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 F28913858C3A for ; Sun, 21 Apr 2024 17:01:58 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 932AA3858C56 for ; Sun, 21 Apr 2024 17:00:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 932AA3858C56 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 932AA3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718812; cv=none; b=QNvwc8aT/mD6vf0S90m1jdV78lHh1TIPSakLrT7AYwZ6HsqLDbPLqmc5ZmmmeiwFml61ljOyvQoiKXJGMgnBePFXEeaNc3sV9JZSCZ5IdiYOVTXvJBfxIw4jEBi6GBw9D+Wgr8pX/UvV+U8fQkEQ3R40Gd05pKtDHZt5GcGP1j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718812; c=relaxed/simple; bh=UTEK0aixAq/OHKiNaH5l0VC/zRNR65kORWH3Tj98q2o=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=mc5fK7J9unV5Eb++nZqzjjA2Gc4ngEVAxj2ybBOkKmMS3jNTYmb6JELI6msdm349MbDE2Roa/OXeqFUIizb9NTw5JaEpy70A8g2TwEKK/3P1GWYbO2pdlkzcC/AGdmn6Knhir64P2fxnKQho3x3Ipx5ZI9cd4UmHboTGw05rfnY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6003a.ext.cloudfilter.net ([10.0.30.151]) by cmsmtp with ESMTPS id yUN2rzzgZPM1hyaXtr0baU; Sun, 21 Apr 2024 17:00:05 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXsrnKBQd4oeyaXtrpkM5; Sun, 21 Apr 2024 17:00:05 +0000 X-Authority-Analysis: v=2.4 cv=aYKqngot c=1 sm=1 tr=0 ts=66254615 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=EHerL0z3gyhmtD2HClQA:9 a=QEXdDO2ut3YA:10 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=x5CN1wXjZlb8zQnmVgh2gvQdFuK+sir0E1ObzI0HUmo=; b=YzVcRMJZqPDqVlvIwa2YqQ7S80 AizCEdkqGXc4UbesjYLxZGmFiPA+R7Knz+4GmjdndaqDH47L19dLVXF2KmGIGpWJvj5Hz2jbZgbj9 SCa6kEikoxvU9IarkBgKJamx3; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXs-003wVC-1R for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:04 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:09 -0600 Subject: [PATCH 09/10] Allow function types as template parameters in name canonicalizer MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-9-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXs-003wVC-1R X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 10 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfEHCU+vHMZ4Mt4alwu5jPQ88frsVZ3Nd4/wV7e03xJKT1RqKcNpJlaNFUNABandAT8I3MBSgJIzLupKGNUp0439XRdkQ0lSjG04qskRjzIisax1PdeF0 z24vRpz2pGPEQ7Id6deAuebiyvld/Wo0GOWJtJnLQ12IQ5s++sW40SjVsyodGXmlXW7HSctH2ED1rMK6948K8fSIl8NF3+KDv08= X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, 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 This adds function types as template parameters in the C++ name canonicalizer. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=11907 --- gdb/cp-name-parser.y | 4 ++++ gdb/cp-support.c | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 3c5dea2de1c..e820faa2db9 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -596,6 +596,7 @@ template_arg : typespec_2 | '&' '(' start ')' { $$ = state->fill_comp (DEMANGLE_COMPONENT_UNARY, state->make_operator ("&", 1), $3); } | exp + | function ; function_args : typespec_2 @@ -2066,6 +2067,9 @@ canonicalize_tests () should_be_the_same ("x::y::z<0b111>", "x::y::z<0D7>"); should_be_the_same ("x::y::z<0xff'ff>", "x::y::z<65535>"); + + should_be_the_same ("something", "something< void() >"); + should_be_the_same ("something", "something"); } #endif diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 4c64e4963e4..74a1b61ed68 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -2186,15 +2186,8 @@ test_cp_remove_params () CHECK_INCOMPL ("A::foo<(anonymous namespace)::B", "A::foo"); - /* Shouldn't this parse? Looks like a bug in - cp_demangled_name_to_comp. See PR c++/22411. */ -#if 0 CHECK ("A::foo::func(int)", "A::foo::func"); -#else - CHECK_INCOMPL ("A::foo::func(int)", - "A::foo"); -#endif CHECK_INCOMPL ("A::foo X-Patchwork-Id: 88817 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 8B3F6385842D for ; Sun, 21 Apr 2024 17:01:30 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id 8526B3858C53 for ; Sun, 21 Apr 2024 17:00:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8526B3858C53 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 8526B3858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; cv=none; b=EE89TB3T7eL0LiFhuO5wIjHKwzMcwNthzQhvOG8gbqqOpw8hYfE/vWKc6J2AO8CV5C/H9xY3FK4eqxV25IVPEpQqQSKab0oxN0dZW23sPd7vwOdXA3Shc9S/wPY6sJJv6EDl0jCnXGo5aTv3eGN6JLeclaR34p4CFJ6tqkYbzLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; c=relaxed/simple; bh=+UheuAoeJtkmX4q5NKUclXy2R9heWSXS06SnbeQ7sjw=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=B6XfUQlDlgYiIJAsVVApJCyBRFJWMXGiOdYIoQ/7A80GrbKFO22j50GHI6lXUYfZXrB4k2llAdxMH17gc0+6BfAjq42svNnntP4CZSQf/gq3Kp8IwYasKvpwgED3pWRnEmdQEonPz31nQhvSQbvhVhclEWdJbg/jWvnypcgP17w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6006a.ext.cloudfilter.net ([10.0.30.182]) by cmsmtp with ESMTPS id yZz2rrevms4yTyaXurHKIK; Sun, 21 Apr 2024 17:00:06 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXsrcdpSEKylyaXtrXLtB; Sun, 21 Apr 2024 17:00:05 +0000 X-Authority-Analysis: v=2.4 cv=Bombw5X5 c=1 sm=1 tr=0 ts=66254615 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=YEDQgCsy9Zrd67yb2cgA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=swTBnrlfGmRK/YCeDp5nlv9W1jedLbId3MI4cle2DDQ=; b=vOz7W46EfcTFZwW6USicpLoxmh 19MNgZNNsr3dUvLsVPgTqJnCO5uoXVy1pzI8Lc36UzdAYwRrj38/UdWEkD7259j1Q402ueZIyFYbd jienMuUgHkuvQwTVCAZS2e7UU; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXs-003wVC-24 for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:04 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:10 -0600 Subject: [PATCH 10/10] Add spaceship operator to cp-name-parser.y MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-10-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.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.86.252 X-Source-L: No X-Exim-ID: 1ryaXs-003wVC-24 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 11 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfECW/i03yv0hIhQgX7Lwfx7QGg4VEtXrZwlL7ys74utawQFuamATVpfZFLCTHHodfK03XqFrKzjc2q+JQ0QP7L71FQjOaaYyzTYVGuehjeZcnjOZIp4C MlqnmdjaUg17souB4bqudj6ORSm3nvCbdwenit3lK9o+Uf+sJnc4SVEtTQrr9vlrLioFLGVplw172819sjYyAAKFF+BpBb0393s= X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT 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 While debugging gdb, I saw this: During symbol reading: unexpected demangled name 'operator<=>, std::chrono::duration >' This happens because cp-name-parser.y does not handle the spaceship operator. This patch implements this. --- gdb/cp-name-parser.y | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index e820faa2db9..db5c349d212 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -297,7 +297,7 @@ static void yyerror (cpname_state *, const char *); %left '^' %left '&' %left EQUAL NOTEQUAL -%left '<' '>' LEQ GEQ +%left '<' '>' LEQ GEQ SPACESHIP %left LSH RSH %left '@' %left '+' '-' @@ -451,6 +451,8 @@ oper : OPERATOR NEW { $$ = state->make_operator ("<=", 2); } | OPERATOR GEQ { $$ = state->make_operator (">=", 2); } + | OPERATOR SPACESHIP + { $$ = state->make_operator ("<=>", 2); } | OPERATOR ANDAND { $$ = state->make_operator ("&&", 2); } | OPERATOR OROR @@ -1077,6 +1079,10 @@ exp : exp GEQ exp { $$ = state->d_binary (">=", $1, $3); } ; +exp : exp SPACESHIP exp + { $$ = state->d_binary ("<=>", $1, $3); } + ; + exp : exp '<' exp { $$ = state->d_binary ("<", $1, $3); } ; @@ -1783,6 +1789,7 @@ yylex (YYSTYPE *lvalp, cpname_state *state) return c; case '<': HANDLE_TOKEN3 ("<<=", ASSIGN_MODIFY); + HANDLE_TOKEN3 ("<=>", SPACESHIP); HANDLE_TOKEN2 ("<=", LEQ); HANDLE_TOKEN2 ("<<", LSH); state->lexptr++; @@ -2052,6 +2059,14 @@ should_be_the_same (const char *one, const char *two) SELF_CHECK (strcmp (one, two) == 0); } +static void +should_parse (const char *name) +{ + std::string err; + auto parsed = cp_demangled_name_to_comp (name, &err); + SELF_CHECK (parsed != nullptr); +} + static void canonicalize_tests () { @@ -2070,6 +2085,8 @@ canonicalize_tests () should_be_the_same ("something", "something< void() >"); should_be_the_same ("something", "something"); + + should_parse ("void whatever::operator<=>"); } #endif