Skip to content

Commit 59f416b

Browse files
committed
Less pollution with global variables in hooks
1 parent d1d256f commit 59f416b

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

lib/hook.sh

+34-34
Original file line numberDiff line numberDiff line change
@@ -132,36 +132,36 @@ _Dbg_debug_trap_handler() {
132132
for (( _Dbg_i=0; _Dbg_i < _Dbg_watch_max ; _Dbg_i++ )) ; do
133133
if [ -n "${_Dbg_watch_exp[$_Dbg_i]}" ] \
134134
&& [[ ${_Dbg_watch_enable[_Dbg_i]} != 0 ]] ; then
135-
typeset new_val=$(_Dbg_get_watch_exp_eval $_Dbg_i)
136-
typeset old_val=${_Dbg_watch_val[$_Dbg_i]}
137-
if [[ $old_val != $new_val ]] ; then
135+
typeset _Dbg_new_val=$(_Dbg_get_watch_exp_eval $_Dbg_i)
136+
typeset _Dbg_old_val=${_Dbg_watch_val[$_Dbg_i]}
137+
if [[ $_Dbg_old_val != $_Dbg_new_val ]] ; then
138138
((_Dbg_watch_count[_Dbg_i]++))
139139
_Dbg_msg "Watchpoint $_Dbg_i: ${_Dbg_watch_exp[$_Dbg_i]} changed:"
140-
_Dbg_msg " old value: '$old_val'"
141-
_Dbg_msg " new value: '$new_val'"
142-
_Dbg_watch_val[$_Dbg_i]=$new_val
140+
_Dbg_msg " old value: '$_Dbg_old_val'"
141+
_Dbg_msg " new value: '$_Dbg_new_val'"
142+
_Dbg_watch_val[$_Dbg_i]=$_Dbg_new_val
143143
_Dbg_hook_enter_debugger 'on a watch trigger'
144144
return $_Dbg_continue_rc
145145
fi
146146
fi
147147
done
148148

149-
typeset full_filename
150-
full_filename=$(_Dbg_is_file "$_Dbg_frame_last_filename")
151-
if [[ -r $full_filename ]] ; then
152-
_Dbg_file2canonic[$_Dbg_frame_last_filename]="$full_filename"
149+
typeset _Dbg_full_filename
150+
_Dbg_full_filename=$(_Dbg_is_file "$_Dbg_frame_last_filename")
151+
if [[ -r "$_Dbg_full_filename" ]] ; then
152+
_Dbg_file2canonic["$_Dbg_frame_last_filename"]="$_Dbg_full_filename"
153153
fi
154154

155155
# Run applicable action statement
156156
if ((_Dbg_action_count > 0)) ; then
157-
_Dbg_hook_action_hit "$full_filename"
157+
_Dbg_hook_action_hit "$_Dbg_full_filename"
158158
fi
159159

160160
# Determine if we stop or not.
161161

162162
# Check breakpoints.
163163
if ((_Dbg_brkpt_count > 0)) ; then
164-
if _Dbg_hook_breakpoint_hit "$full_filename"; then
164+
if _Dbg_hook_breakpoint_hit "$_Dbg_full_filename"; then
165165
if ((_Dbg_step_force)) ; then
166166
typeset _Dbg_frame_previous_file="$_Dbg_frame_last_filename"
167167
typeset -i _Dbg_frame_previous_lineno="$_Dbg_frame_last_lineno"
@@ -228,21 +228,21 @@ _Dbg_debug_trap_handler() {
228228
}
229229

230230
_Dbg_hook_action_hit() {
231-
typeset full_filename="$1"
232-
typeset lineno=$_Dbg_frame_last_lineno
231+
typeset _Dbg_full_filename="$1"
232+
typeset _Dbg_lineno=$_Dbg_frame_last_lineno
233233

234234
# FIXME: combine with _Dbg_unset_action
235-
typeset -a linenos
236-
[[ -z "$full_filename" ]] && return 1
237-
eval "linenos=(${_Dbg_action_file2linenos["$full_filename"]})"
238-
typeset -a action_nos
239-
eval "action_nos=(${_Dbg_action_file2action["$full_filename"]})"
235+
typeset -a _Dbg_linenos
236+
[[ -z "$_Dbg_full_filename" ]] && return 1
237+
eval "_Dbg_linenos=(${_Dbg_action_file2linenos["$_Dbg_full_filename"]})"
238+
typeset -a _Dbg_action_nos
239+
eval "_Dbg_action_nos=(${_Dbg_action_file2action["$_Dbg_full_filename"]})"
240240

241241
typeset -i _Dbg_i
242242
# Check action within full_filename
243-
for ((_Dbg_i=0; _Dbg_i < ${#linenos[@]}; _Dbg_i++)); do
244-
if (( linenos[_Dbg_i] == lineno )) ; then
245-
(( _Dbg_action_num = action_nos[_Dbg_i] ))
243+
for ((_Dbg_i=0; _Dbg_i < ${#_Dbg_linenos[@]}; _Dbg_i++)); do
244+
if (( _Dbg_linenos[_Dbg_i] == _Dbg_lineno )) ; then
245+
(( _Dbg_action_num = _Dbg_action_nos[_Dbg_i] ))
246246
stmt="${_Dbg_action_stmt[$_Dbg_action_num]}"
247247
. "${_Dbg_libdir}/set-d-vars.sh"
248248
eval "$stmt"
@@ -258,22 +258,22 @@ _Dbg_hook_action_hit() {
258258
# Return 0 if we are at a breakpoint position or 1 if not.
259259
# Sets _Dbg_brkpt_num to the breakpoint number found.
260260
_Dbg_hook_breakpoint_hit() {
261-
typeset full_filename="$1"
262-
typeset lineno=$_Dbg_frame_last_lineno
261+
typeset _Dbg_full_filename="$1"
262+
typeset _Dbg_lineno=$_Dbg_frame_last_lineno
263263

264264
# FIXME: combine with _Dbg_unset_brkpt
265-
typeset -a linenos
266-
[[ -z "$full_filename" ]] && return 1
267-
[[ -z "${_Dbg_brkpt_file2linenos["$full_filename"]}" ]] && return 1
268-
eval "linenos=(${_Dbg_brkpt_file2linenos["$full_filename"]})"
269-
typeset -a brkpt_nos
270-
eval "brkpt_nos=(${_Dbg_brkpt_file2brkpt["$full_filename"]})"
271-
typeset -i i
265+
typeset -a _Dbg_linenos
266+
[[ -z "$_Dbg_full_filename" ]] && return 1
267+
[[ -z "${_Dbg_brkpt_file2linenos["$_Dbg_full_filename"]}" ]] && return 1
268+
eval "_Dbg_linenos=(${_Dbg_brkpt_file2linenos["$_Dbg_full_filename"]})"
269+
typeset -a _Dbg_brkpt_nos
270+
eval "_Dbg_brkpt_nos=(${_Dbg_brkpt_file2brkpt["$_Dbg_full_filename"]})"
271+
typeset -i _Dbg_i
272272
# Check breakpoints within full_filename
273-
for ((i=0; i < ${#linenos[@]}; i++)); do
274-
if (( linenos[i] == lineno )) ; then
273+
for ((_Dbg_i=0; _Dbg_i < ${#_Dbg_linenos[@]}; _Dbg_i++)); do
274+
if (( _Dbg_linenos[_Dbg_i] == _Dbg_lineno )) ; then
275275
# Got a match, but is the breakpoint enabled and condition met?
276-
(( _Dbg_brkpt_num = brkpt_nos[i] ))
276+
(( _Dbg_brkpt_num = _Dbg_brkpt_nos[_Dbg_i] ))
277277
if ((_Dbg_brkpt_enable[_Dbg_brkpt_num] )); then
278278

279279
if ( eval "((${_Dbg_brkpt_cond[_Dbg_brkpt_num]}))" || eval "${_Dbg_brkpt_cond[_Dbg_brkpt_num]}" ) 2>/dev/null; then

0 commit comments

Comments
 (0)