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


Groups > gnu.bash.bug > #15515 > unrolled thread

Feature request: save/restore BASH_REMATCH across debug hook calls

Started byRocky Bernstein <rocky@gnu.org>
First post2019-10-16 13:34 -0400
Last post2019-10-16 13:34 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#15515 — Feature request: save/restore BASH_REMATCH across debug hook calls

FromRocky Bernstein <rocky@gnu.org>
Date2019-10-16 13:34 -0400
SubjectFeature request: save/restore BASH_REMATCH across debug hook calls
Message-ID<mailman.884.1571247268.9715.bug-bash@gnu.org>
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.

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web