From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cc5rMgibm2qz5isAWB0awg (envelope-from ) for ; Sat, 05 Sep 2026 00:31:04 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=XeN0n9vq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C4B051E091; Sat, 05 Sep 2026 00:31:04 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 452F91E091 for ; Sat, 05 Sep 2026 00:31:03 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D21454BA2E0F for ; Sat, 5 Sep 2026 04:31:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D21454BA2E0F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=XeN0n9vq Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 5F0324BB58FD for ; Sat, 5 Sep 2026 04:29:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F0324BB58FD Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F0324BB58FD Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788582565; cv=none; b=hkDtCMY4M7vnZQwEzbzFhcSQtulkIJ6afcRiUPcRA6EA2aKIaLkxQVqepBp6dVL1nmGrVJxnINvFsMPOXaY3hOm61QlMEHOZo+2BW8QuI6Q1w48FvyHn3iY1EFDxhBjAM1IO1h9Ba5izmR/ORVmTRRCClc9sqJqRYUm3NxyStN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788582565; c=relaxed/simple; bh=ado2xq6w9uFnk+XCyldBzhccL5/aTpoUCtmunwm1pjk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oYPx8PLTg2ruq9FY8D7p0GYB4qfg6A0dc0qVew85U0qdl4lr3euRMmyEjfiJ+pyqmYeqY8hIEv0O3rpk80vK/GtXzjikgHp4HyJovSjenbNDrPGkQYqlecP8W4c2W07udAbfi+e+5MljClmhgwdv8rQt8Pgj19Hl0vr1sC95WOY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=XeN0n9vq DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F0324BB58FD Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 6854TIEK082670 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 5 Sep 2026 00:29:23 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 6854TIEK082670 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1788582564; bh=XlltLBO9mNref+4jU2uldg9FQvo7QfRBD9l4Yq/yyoE=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=XeN0n9vqiGmlFPATl6+bmUE8rylu7j1/iTKqVBbaMLszXfGWb1vvP2aZ9or8uLS2h JHVGkI8UwlaNz1JagwKursZwRyoE/qEOaSfd8k3XYlPvkZhGZVS1nAYUB/RVry6d9y CtbZEuxiRL3ZLN6o/LIBmBbyPbCsinSS50FM6G9Dh6i4vP2cpRu20SzjvhsKJuIxns 0wfmfXpUdN+bO5EtDHeUlD42KoR3mRBLDubbcWPS4nPHCDsLtIZTtbHM7qaRz1If/b cCPdPVeUzyhkkEu2Qjj9qEtLFMZHsXXrI+JtGgs3yWtJyZYV+hk7ZNuqHNmTH1isLa MsaI8a5UwP2xQ== Received: by simark.ca (Postfix) id 249F31E16F; Sat, 05 Sep 2026 00:23:59 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2 05/19] gdb: move parser output post-processing to a script Date: Sat, 5 Sep 2026 00:23:08 -0400 Message-ID: <20260905042353.1702204-6-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260905042353.1702204-1-simon.marchi@polymtl.ca> References: <20260905042353.1702204-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 5 Sep 2026 04:29:18 +0000 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~public-inbox=simark.ca@sourceware.org From: Simon Marchi The output of bison and flex needs some post-processing before being compiled. It is currently done by a sed invocation inlined in each of the two pattern rules, which is kind of hard to read and modify. Additionally, a following patch adds the generation of header files for parsers, and those will need the same post processing. Moving the code to a dedicated script makes re-use easier. Move the code to post-process-parser-output.sh, which takes the name of the parser generator (flex or bison), just to know which substitutions to do, as well as the name of the parser file. Make the Makefile rules depend on the script, so that the parsers are regenerated when it changes. Change-Id: I15f43184034aff33d242052db79586980ec2dac0 --- gdb/Makefile.in | 38 ++++++------------ gdb/post-process-parser-output.sh | 66 +++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 27 deletions(-) create mode 100755 gdb/post-process-parser-output.sh diff --git a/gdb/Makefile.in b/gdb/Makefile.in index dec887ff6095..80b2f8573294 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2693,38 +2693,22 @@ po/$(PACKAGE).pot: force %.c: %.y %.c: %.l -%-gen.c: %.y +# Post-process a file produced by a parser generator, see the script +# for details. +POST_PROCESS_PARSER_OUTPUT_SH = $(srcdir)/post-process-parser-output.sh +POST_PROCESS_PARSER_OUTPUT = $(SHELL) $(POST_PROCESS_PARSER_OUTPUT_SH) + +%-gen.c: %.y $(POST_PROCESS_PARSER_OUTPUT_SH) $(ECHO_YACC) $(SHELL) $(YLWRAP) $< y.tab.c $@.tmp -- \ $(YACC) $(YFLAGS) || (rm -f $@.tmp; false) - @sed -e '/extern.*malloc/d' \ - -e '/extern.*realloc/d' \ - -e '/extern.*free/d' \ - -e '/include.*malloc.h/d' \ - -e 's/\([^x]\)malloc/\1xmalloc/g' \ - -e 's/\([^x]\)realloc/\1xrealloc/g' \ - -e 's/\([ \t;,(]\)free\([ \t]*[&(),]\)/\1xfree\2/g' \ - -e 's/\([ \t;,(]\)free$$/\1xfree/g' \ - -e '/^#line.*y.tab.c/d' \ - -e "s/YYSTYPE/$(subst -,_,$*)_YYSTYPE/g" \ - -e "s/yyalloc/$(subst -,_,$*)_yyalloc/g" \ - -e "s/yysymbol_kind_t/$(subst -,_,$*)_yysymbol_kind_t/g" \ - < $@.tmp > $@.new && \ + @$(POST_PROCESS_PARSER_OUTPUT) bison $* < $@.tmp > $@.new && \ rm -f $@.tmp && \ mv $@.new $@ -%-gen.c: %.l +%-gen.c: %.l $(POST_PROCESS_PARSER_OUTPUT_SH) $(ECHO_LEX) $(FLEX) -t $< > $@.tmp || (rm -f $@.tmp; false) - @sed -e '/extern.*malloc/d' \ - -e '/extern.*realloc/d' \ - -e '/extern.*free/d' \ - -e '/include.*malloc.h/d' \ - -e 's/\([^x]\)malloc/\1xmalloc/g' \ - -e 's/\([^x]\)realloc/\1xrealloc/g' \ - -e 's/\([ \t;,(]\)free\([ \t]*[&(),]\)/\1xfree\2/g' \ - -e 's/\([ \t;,(]\)free$$/\1xfree/g' \ - -e 's/yy_flex_xrealloc/yyxrealloc/g' \ - < $@.tmp > $@.new && \ - rm -f $@.tmp && \ - mv $@.new $@ + @$(POST_PROCESS_PARSER_OUTPUT) flex $* < $@.tmp > $@.new && \ + rm -f $@.tmp && \ + mv $@.new $@ # XML rules diff --git a/gdb/post-process-parser-output.sh b/gdb/post-process-parser-output.sh new file mode 100755 index 000000000000..a0cf6b464c4b --- /dev/null +++ b/gdb/post-process-parser-output.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +# Copyright (C) 2026 Free Software Foundation, Inc. +# +# This file is part of GDB. +# +# 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 . + +# Post-process a file produced by flex or bison/byacc, reading it from +# standard input and writing the result to standard output. +# +# Usage: +# +# ./post-process-parser-output.sh GENERATOR NAME < INPUT > OUTPUT +# +# Where GENERATOR is "bison" (regardless of whether we're using the actual +# bison or byacc) or "flex", and NAME is the name of the parser (e.g. +# "cp-name-parser"), used to make the global symbols names bison produces +# unique. + +set -e + +generator="$1" + +# Convert e.g. "cp-name-parser" to "cp_name_parser". +name=$(echo "$2" | sed -e 's/-/_/g') + +common=' +/extern.*malloc/d +/extern.*realloc/d +/extern.*free/d +/include.*malloc.h/d +s/\([^x]\)malloc/\1xmalloc/g +s/\([^x]\)realloc/\1xrealloc/g +s/\([ \t;,(]\)free\([ \t]*[&(),]\)/\1xfree\2/g +s/\([ \t;,(]\)free$/\1xfree/g +' + +case "$generator" in + bison) + sed -e "$common" \ + -e '/^#line.*y.tab.c/d' \ + -e "s/YYSTYPE/${name}_YYSTYPE/g" \ + -e "s/yyalloc/${name}_yyalloc/g" \ + -e "s/yysymbol_kind_t/${name}_yysymbol_kind_t/g" + ;; + flex) + sed -e "$common" \ + -e 's/yy_flex_xrealloc/yyxrealloc/g' + ;; + *) + echo "$0: unknown parser generator \"$generator\"" >&2 + exit 1 + ;; +esac -- 2.55.0