Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15515

Feature request: save/restore BASH_REMATCH across debug hook calls

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Rocky Bernstein <rocky@gnu.org>
Newsgroups gnu.bash.bug
Subject Feature request: save/restore BASH_REMATCH across debug hook calls
Date Wed, 16 Oct 2019 13:34:06 -0400
Lines 35
Approved bug-bash@gnu.org
Message-ID <mailman.884.1571247268.9715.bug-bash@gnu.org> (permalink)
References <CANCp2gZjUeDUbRDVZzjqMVn1eWoRXRK+kTf_y-UHWTs5R6a79Q@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
X-Trace usenet.stanford.edu 1571247269 31828 209.51.188.17 (16 Oct 2019 17:34:29 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ZHzyhPe2ML0SFmiQqWklRRsuYJdRl9OAYk4s7wo4fZI=; b=qri3OWgxm+GZRxz4TllqpXCN3e0cz2fEvgr+FOBFpyNBDWp1my0fBegpUJbT5edeh/ XgPObVRSyOsRCo4TDKNFOV+drfuguJy3PzjogdqidT0blqClM1uIHLEfULg2OKNyGkTU khL+gfBz6B7TQXEE91JOQGbl4b8gK4bK5Ynm9OpQw5Ml1adb40uHv5aQSdnhmEOXeGT8 YSzLccEEtgLt0AgNmD3bMC3XZWDFNB8TaK4VRT8VDFyq+FuRl6EBIeEU9buydkfvfH/q ITQLV+qJiWEje8OGSNW1SWDUdAMuewmKv0DVZJooB9ZRgUeQ/tEiGG0JRWljp0AkOHpE BmdA==
X-Gm-Message-State APjAAAUmoC11bB3Wjw4pGEwpBHfjTAlq2E82KnCgk+sXEEwNHGvV2QOf 0lJJY82pUPrCZ9qDKJKEUv0mWv/pwMgpV+Tsv4KJ/pVM
X-Google-Smtp-Source APXvYqzcvnD+qL+VHATlEDpQs4KfuN5dDCfnkyiJ1mlvOyb8VnIHKoAbycPKLZ17YH7v/mO/kbGrEk6ajBoyWAGkNIw=
X-Received by 2002:a2e:97ca:: with SMTP id m10mr25076603ljj.168.1571247257233; Wed, 16 Oct 2019 10:34:17 -0700 (PDT)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy]
X-Received-From 209.85.208.180
X-Content-Filtered-By Mailman/MimeDel 2.1.23
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <CANCp2gZjUeDUbRDVZzjqMVn1eWoRXRK+kTf_y-UHWTs5R6a79Q@mail.gmail.com>
Xref csiph.com gnu.bash.bug:15515

Show key headers only | View raw


Current in bash 5.0 and earlier, the value of BASH_REMATCH might chanted
inside a debug hook.

Since BASH_REMATCH is read-only, resetting the value on hook return to the
debugged program is a bit tricky and fragile...

There are way to change a  bash readonly variable but that involve using
either gdb or having a custom plugin. See
https://stackoverflow.com/questions/17397069/unset-readonly-variable-in-bash

The way that bashdb currently resets BASH_REMATCH is to reissue the command
that caused the value to get initially set. That is fragile since this set
on exit between stepping from the time BASH_REMATCH was set until the time
it is last used. In between variables used in the regular expression may
have changed.

Here is the code bashdb currently uses
https://sourceforge.net/p/bashdb/code/ci/bash-5.0/tree/lib/hook.sh#l105 for
saving the value

   if (( ${#BASH_REMATCH[@]} > 0 )) && [[ "${_Dbg_bash_rematch[@]}" !=
"${BASH_REMATCH[@]}" ]]; then
        # Save a copy of the command string to be able to run to
restore read-only
	# variable BASH_REMATCH
	_Dbg_bash_rematch=${BASH_REMATCH[@]}
        _Dbg_last_rematch_args=( "$@" )
        _Dbg_last_rematch_command=$_Dbg_bash_command
        unset _Dbg_last_rematch_args[0]
    elif ((!${#BASH_REMATCH[@]} && ${#_Dbg_bash_rematch[@]})); then
        _Dbg_bash_rematch=()
        _Dbg_last_rematch_command=''
    fi

Restoring it is just as tricky. As I hope you see all of this is a bit fragile.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Feature request: save/restore BASH_REMATCH across debug hook calls Rocky Bernstein <rocky@gnu.org> - 2019-10-16 13:34 -0400

csiph-web