From patchwork Wed Dec 20 01:23:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 82538 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 6DD173861000 for ; Wed, 20 Dec 2023 01:24:18 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 2338D3858439 for ; Wed, 20 Dec 2023 01:24:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2338D3858439 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gentoo.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2338D3858439 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703035442; cv=none; b=X1uvyhwithIuV5SrCkgWbWbb0tJNn2NcP+f2tE0txtbMJ34mp/HIZ0xRzlP4FRcZ/jZ4qVOEH+hc05B474K4SpBgbUe2uE4GR4xgSHjp/hcwaOL+8iizqqWz/I7svWbHJggd6jdz0em5H14/RJwfZ9Wt9IxJunR9XoAHYVp1TqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703035442; c=relaxed/simple; bh=X69+lp1gfk/KWNa613DoZ2wCs6LW67lI6LD8UUgm8fc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=a2VKwQmfyWSmY8Vtb+ZUKbCJ/M0ZFiNUxt0DUAOfSLhwDroLKWPSXr3QnEwuFFLGUrgOm7GkvHHp0SwBQ84+BSaRhhi/JBEVKtWZ8su87gQ4BwrLejRUtGyf2YiT1an7OCdEFtGhE+8HFt0jQpHJNXnMdmCkCYb5g/1+GuYPgVE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by smtp.gentoo.org (Postfix, from userid 559) id A325034076D; Wed, 20 Dec 2023 01:23:59 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH 2/3] sim: common: add $LINENO rewriting support to genmloop scripts Date: Tue, 19 Dec 2023 20:23:53 -0500 Message-ID: <20231220012354.15032-2-vapier@gentoo.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220012354.15032-1-vapier@gentoo.org> References: <20231220012354.15032-1-vapier@gentoo.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 generated mloop files can trigger compile time warnings. It can be difficult to see/understand where the original code is coming from as all the diagnostics point to the generated output. Using #line pragmas, we can point people to the original source files. Unfortunately, this code is written in POSIX shell, and that lacks support for line number tracking. The $LINENO variable, even when available, can just be plain wrong. For example, when using dash and subshells, $LINENO can end up having negative values. Add a wrapper script that will uses awk to rewrite the $LINENO variable to the right value to avoid all that. Basically lineno.sh takes an input script, rewrites all uses of $LINENO into the actual line number (and $0 into the original file name), and then executes the temporary script. This commit doesn't actually add #line pragmas to any files. That comes next. --- sim/Makefile.in | 6 ++++-- sim/common/genmloop.sh | 49 ++++++++++++++++++++++++++---------------- sim/common/lineno.sh | 44 +++++++++++++++++++++++++++++++++++++ sim/common/local.mk | 6 ++++-- 4 files changed, 83 insertions(+), 22 deletions(-) create mode 100755 sim/common/lineno.sh diff --git a/sim/common/genmloop.sh b/sim/common/genmloop.sh index e6683def4637..73ff2fdc100e 100755 --- a/sim/common/genmloop.sh +++ b/sim/common/genmloop.sh @@ -142,6 +142,7 @@ infile="" prefix="unknown" outprefix="" outsuffix="" +lineno="" while test $# -gt 0 do @@ -166,6 +167,8 @@ do -cpu) shift ; cpu=$1 ;; -infile) shift ; infile=$1 ;; -shell) shift ; SHELL=$1 ;; + -awk) shift ; AWK=$1 ; export AWK ;; + -lineno) shift ; lineno=$1 ;; *) echo "unknown option: $1" >&2 ; exit 1 ;; esac shift @@ -199,6 +202,16 @@ PREFIX=`echo ${prefix} | tr "${lowercase}" "${uppercase}"` ########################################################################## +load_infile_section() { + if [ -n "${lineno}" ]; then + ${SHELL} ${lineno} \ + "${infile}" "${outprefix}mloop${outsuffix}.tmp" \ + "$@" + else + ${SHELL} ${infile} "$@" + fi +} + rm -f ${outprefix}eng${outsuffix}.hin exec 1>${outprefix}eng${outsuffix}.hin @@ -380,7 +393,7 @@ ATTRIBUTE_UNUSED static INLINE void EOF -${SHELL} $infile support +load_infile_section support ########################################################################## @@ -425,7 +438,7 @@ esac # Any initialization code before looping starts. # Note that this code may declare some locals. -${SHELL} $infile init +load_infile_section init if [ x$parallel = xread ] ; then cat << EOF @@ -466,7 +479,7 @@ cat << EOF /* begin full-exec-simple */ EOF -${SHELL} $infile full-exec-simple +load_infile_section full-exec-simple cat << EOF /* end full-exec-simple */ @@ -527,7 +540,7 @@ static INLINE SCACHE * /* begin extract-scache */ EOF -${SHELL} $infile extract-scache +load_infile_section extract-scache cat << EOF /* end extract-scache */ @@ -557,7 +570,7 @@ EOF # Any initialization code before looping starts. # Note that this code may declare some locals. -${SHELL} $infile init +load_infile_section init cat << EOF @@ -580,7 +593,7 @@ cat << EOF /* begin full-exec-scache */ EOF -${SHELL} $infile full-exec-scache +load_infile_section full-exec-scache cat << EOF /* end full-exec-scache */ @@ -618,7 +631,7 @@ EOF # Any initialization code before looping starts. # Note that this code may declare some locals. -${SHELL} $infile init +load_infile_section init cat << EOF @@ -647,7 +660,7 @@ cat << EOF /* begin fast-exec-scache */ EOF -${SHELL} $infile fast-exec-scache +load_infile_section fast-exec-scache cat << EOF /* end fast-exec-scache */ @@ -695,7 +708,7 @@ static INLINE SCACHE * /* begin extract-scache */ EOF -${SHELL} $infile extract-scache +load_infile_section extract-scache cat << EOF /* end extract-scache */ @@ -726,7 +739,7 @@ EOF # Any initialization code before looping starts. # Note that this code may declare some locals. -${SHELL} $infile init +load_infile_section init if [ x$parallel = xread ] ; then cat << EOF @@ -762,7 +775,7 @@ cat << EOF /* begin full-exec-scache */ EOF -${SHELL} $infile full-exec-scache +load_infile_section full-exec-scache cat << EOF /* end full-exec-scache */ @@ -798,7 +811,7 @@ EOF # Any initialization code before looping starts. # Note that this code may declare some locals. -${SHELL} $infile init +load_infile_section init if [ x$parallel = xread ] ; then cat << EOF @@ -841,7 +854,7 @@ cat << EOF /* begin fast-exec-scache */ EOF -${SHELL} $infile fast-exec-scache +load_infile_section fast-exec-scache cat << EOF /* end fast-exec-scache */ @@ -948,7 +961,7 @@ INLINE SEM_PC /* begin extract-pbb */ EOF -${SHELL} $infile extract-pbb +load_infile_section extract-pbb cat << EOF /* end extract-pbb */ @@ -1183,7 +1196,7 @@ esac # Any initialization code before looping starts. # Note that this code may declare some locals. -${SHELL} $infile init +load_infile_section init cat << EOF @@ -1226,7 +1239,7 @@ cat << EOF /* begin full-exec-pbb */ EOF -${SHELL} $infile full-exec-pbb +load_infile_section full-exec-pbb cat << EOF /* end full-exec-pbb */ @@ -1275,7 +1288,7 @@ esac # Any initialization code before looping starts. # Note that this code may declare some locals. -${SHELL} $infile init +load_infile_section init cat << EOF @@ -1318,7 +1331,7 @@ cat << EOF /* begin fast-exec-pbb */ EOF -${SHELL} $infile fast-exec-pbb +load_infile_section fast-exec-pbb cat << EOF /* end fast-exec-pbb */ diff --git a/sim/common/lineno.sh b/sim/common/lineno.sh new file mode 100755 index 000000000000..3332f375287f --- /dev/null +++ b/sim/common/lineno.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# Replace $LINENO on the fly. +# Copyright (C) 2023 Free Software Foundation, Inc. +# +# This file is part of the GNU simulators. +# +# 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 . + +# Since $LINENO is not reliable in shells/subshells, generate it on the fly. + +if [ $# -lt 2 ]; then + cat <&2 +Usage: $0