[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Feature request: save/restore BASH_REMATCH across debug hook calls
From: |
Rocky Bernstein |
Subject: |
Feature request: save/restore BASH_REMATCH across debug hook calls |
Date: |
Wed, 16 Oct 2019 13:34:06 -0400 |
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.
- Feature request: save/restore BASH_REMATCH across debug hook calls,
Rocky Bernstein <=