Skip to content

Commit 248cb7d

Browse files
jansorgrocky
andauthored
Sync bash-4.4 with bash-5.2 (#57)
* Make -S --style option work... And bump copyright * Resolve filenames in `backtrace` command (#54) * Resolve file paths in "backtrace" * Save mapping when doing the "load" command; resolve the filename in the "backtrace" command * Add a test for the "load" command --------- Co-authored-by: Joachim Ansorg <github@ja-dev.eu> * Save more file information from initial call... In particular, resolve the initial source directory and store that as _Dbg_init_dir. Resolve the name of main bash program and add that to canonicalized filenames. * Update bashdb.in Co-authored-by: Joachim Ansorg <github@ja-dev.eu> * Update lib/hook.sh Co-authored-by: Joachim Ansorg <github@ja-dev.eu> * Update bashdb.in Co-authored-by: Joachim Ansorg <github@ja-dev.eu> * Add more places we resolve/expand files In some cases though automatic file loading no longer happens. In particular, on "list" and "break" commands. * One more quoted statement. --------- Co-authored-by: rocky <rb@dustyfeet.com> Co-authored-by: R. Bernstein <rocky@users.noreply.github.com>
1 parent beb6106 commit 248cb7d

22 files changed

Lines changed: 189 additions & 117 deletions

bashdb.in

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Top-level debugger program. This program may be initially invoked.
44
#
55
# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008,
6-
# 2009, 2010, 2011 Rocky Bernstein <rocky@gnu.org>
6+
# 2009, 2010, 2011, 2019 Rocky Bernstein <rocky@gnu.org>
77
#
88
# This program is free software; you can redistribute it and/or
99
# modify it under the terms of the GNU General Public License as
@@ -62,6 +62,7 @@ _Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; };
6262
# supplied over any of the above guesses. Go over options and parse
6363
# just the library option.
6464
typeset -xa _Dbg_script_args; _Dbg_script_args=("$@")
65+
6566
typeset -i _Dbg_i
6667
for ((_Dbg_i=0; _Dbg_i<${#_Dbg_script_args[@]}-1; _Dbg_i++)) ; do
6768
typeset _Dbg_script_arg=${_Dbg_script_args[$_Dbg_i]}
@@ -94,6 +95,16 @@ if [[ ! -r "$_Dbg_main" ]] ; then
9495
fi
9596

9697
. "${_Dbg_libdir}/@PACKAGE@-part2.sh"
98+
99+
# Resolve and save mapping for main script, and resolve
100+
# the starting directory.
101+
_Dbg_full_filename="$(_Dbg_is_file "$_Dbg_script_file")"
102+
_Dbg_file2canonic["${_Dbg_script_file}"]="$_Dbg_full_filename"
103+
# Note: expand_filename is expanding a *directory* here, not a filename.
104+
# This might cause a problem in the future if _Dbg_expand_filename becomes
105+
# more specific about this aspect.
106+
_Dbg_init_cwd="$(_Dbg_expand_filename "${_Dbg_script_file%/*}")"
107+
97108
trap '_Dbg_debug_trap_handler 0 "$BASH_COMMAND" "$@"' DEBUG
98109
set -o functrace
99110
. "$_Dbg_script_file"

command/backtrace.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# gdb-like "backtrace" debugger command
33
#
44
# Copyright (C) 2002-2006, 2008, 2010-2011, 2018-2019
5-
# Rocky Bernstein <rocky@gnu.org>
5+
# 2024 Rocky Bernstein <rocky@gnu.org>
66
#
77
# This program is free software; you can redistribute it and/or
88
# modify it under the terms of the GNU General Public License as
@@ -129,7 +129,8 @@ function _Dbg_do_backtrace {
129129
if (( frame_start == 0 )) ; then
130130
((count--)) ;
131131
adjusted_pos=$(_Dbg_frame_adjusted_pos 0)
132-
filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}")
132+
filename="$(_Dbg_resolve_expand_filename "${BASH_SOURCE[$adjusted_pos]}")"
133+
filename="$(_Dbg_adjust_filename "$filename")"
133134
_Dbg_frame_print $(_Dbg_frame_prefix 0) '0' '' "$filename" "$_Dbg_frame_last_lineno" ''
134135
fi
135136

@@ -153,8 +154,6 @@ function _Dbg_do_backtrace {
153154
adjusted_pos=$(_Dbg_frame_adjusted_pos $i)
154155
_Dbg_msg_nocr $(_Dbg_frame_prefix $i)$i ${FUNCNAME[$adjusted_pos-1]}
155156

156-
typeset parms=''
157-
158157
# Print out parameter list.
159158
if (( 0 != ${#BASH_ARGC[@]} )) ; then
160159
_Dbg_frame_fn_param_str
@@ -170,7 +169,8 @@ function _Dbg_do_backtrace {
170169
else
171170
lineno=${BASH_LINENO[$adjusted_pos-1]}
172171
fi
173-
filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}")
172+
filename="$(_Dbg_resolve_expand_filename "${BASH_SOURCE[$adjusted_pos]}")"
173+
filename="$(_Dbg_adjust_filename "$filename")"
174174
_Dbg_msg "($_Dbg_parm_str) called from file \`$filename'" "at line $lineno"
175175
if (( show_source )) ; then
176176
_Dbg_get_source_line $lineno "${BASH_SOURCE[$adjusted_pos]}"

command/break.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ _Dbg_do_break_common() {
102102
(( $? == 0 )) && \
103103
_Dbg_set_brkpt "$full_filename" "$line_number" $is_temp "$condition"
104104
fi
105+
elif [[ -z "$full_filename" ]]; then
106+
_Dbg_errmsg "I can't resolve filename from $linespec"
107+
return 2
105108
else
106109
_Dbg_file_not_read_in "$full_filename"
107-
return 2
110+
return 3
108111
fi
109112
return 0
110113
}

command/load.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Debugger load SCRIPT command.
33
#
44
# Copyright (C) 2002-2006, 2008, 2010-2011, 2018-2019 Rocky
5-
# Bernstein <rocky@gnu.org>
5+
# 2024 Bernstein <rocky@gnu.org>
66
#
77
# This program is free software; you can redistribute it and/or
88
# modify it under the terms of the GNU General Public License as
@@ -52,7 +52,13 @@ _Dbg_do_load() {
5252
done
5353

5454
_Dbg_readin "$_Dbg_full_filename"
55-
_Dbg_msg "File $_Dbg_full_filename loaded."
55+
if (( _Dbg_set_basename )) ; then
56+
_Dbg_msg "File $_Dbg_filename loaded."
57+
else
58+
_Dbg_msg "File $_Dbg_full_filename loaded."
59+
fi
60+
_Dbg_file2canonic["${_Dbg_filename}"]="$_Dbg_full_filename"
61+
5662
else
5763
_Dbg_errmsg "Couldn't resolve or read $_Dbg_filename"
5864
return 3

command/set_sub/style.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
2626
for file in help alias ; do source "$top_dir/lib/${file}.sh"; done
2727
fi
2828

29-
typeset -x _Dbg_pygments_styles=''
30-
31-
if (( _Dbg_working_term_highlight )) ; then
32-
_Dbg_pygments_styles=$("${_Dbg_libdir}/lib/term-highlight.py" -L)
33-
fi
34-
3529
_Dbg_complete_style() {
3630
COMPREPLY=( $_Dbg_pygments_styles off )
3731
}

configure.ac

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
dnl Process this file with autoconf to produce a configure script.
33

44
# Copyright (C) 2002-2012,
5-
# 2014-2019, 2023 Rocky Bernstein <rocky@gnu.org>
5+
# 2014-2019, 2023-2024 Rocky Bernstein <rocky@gnu.org>
66

77
# This program is free software; you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
@@ -254,6 +254,8 @@ AC_CONFIG_FILES([test/unit/test-cmd-info-variables.sh],
254254
[chmod +x test/unit/test-cmd-info-variables.sh])
255255
AC_CONFIG_FILES([test/unit/test-cmd-eval.sh],
256256
[chmod +x test/unit/test-cmd-eval.sh])
257+
AC_CONFIG_FILES([test/unit/test-cmd-load.sh],
258+
[chmod +x test/unit/test-cmd-load.sh])
257259
AC_CONFIG_FILES([test/unit/test-columns.sh],
258260
[chmod +x test/unit/test-columns.sh])
259261
AC_CONFIG_FILES([test/unit/test-eval.sh],

init/opts.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- shell-script -*-
22
# debugger command options processing. The bane of programming.
33
#
4-
# Copyright (C) 2008-2012, 2014-2019, 2021 Rocky Bernstein <rocky@gnu.org>
4+
# Copyright (C) 2008-2012, 2014-2019, 2021, 2023-2024
5+
# Rocky Bernstein <rocky@gnu.org>
56
#
67
# This program is free software; you can redistribute it and/or
78
# modify it under the terms of the GNU General Public License as
@@ -94,9 +95,11 @@ if ( pygmentize --version || pygmentize -V ) 2>/dev/null 1>/dev/null ; then
9495
fi
9596

9697
typeset -ix _Dbg_working_term_highlight
98+
typeset -x _Dbg_pygments_styles=''
9799

98100
if "${_Dbg_libdir}/lib/term-highlight.py" -V 2>/dev/null 1>/dev/null ; then
99101
_Dbg_working_term_highlight=1
102+
_Dbg_pygments_styles=$("${_Dbg_libdir}/lib/term-highlight.py" -L)
100103
else
101104
_Dbg_working_term_highlight=0
102105
fi
@@ -132,7 +135,7 @@ _Dbg_parse_options() {
132135
typeset -i _Dbg_highlight_enabled=1
133136
typeset OPTLARG OPTLERR OPTLPENDING opt
134137

135-
while getopts_long A:Bc:x:hL:nqTt:Yy:VX opt \
138+
while getopts_long A:Bc:x:hL:nqS:T:t:Yy:VX opt \
136139
annotate required_argument \
137140
basename no_argument \
138141
command required_argument \
@@ -146,6 +149,7 @@ _Dbg_parse_options() {
146149
no-init no_argument \
147150
nx no_argument \
148151
quiet no_argument \
152+
style required_argument \
149153
tempdir required_argument \
150154
tty required_argument \
151155
terminal required_argument \
@@ -177,8 +181,8 @@ _Dbg_parse_options() {
177181
esac
178182

179183
if (( ! _Dbg_have_working_pygmentize )) ; then
180-
printf "Can't run pygmentize. --highlight forced off" >&2
181-
_Dbg_highlight_enabled=0
184+
printf "Can't run pygmentize. --highlight forced off." >&2
185+
_Dbg_highlight_enabled=0
182186
_Dbg_set_highlight=''
183187
fi
184188
;;
@@ -197,6 +201,15 @@ _Dbg_parse_options() {
197201
_Dbg_o_nx=1 ;;
198202
q | quiet )
199203
_Dbg_o_quiet=1 ;;
204+
S | style )
205+
if (( ! _Dbg_have_working_pygmentize )) ; then
206+
printf "Can't run pygmentize. --style option ignored." >&2
207+
elif [[ "${_Dbg_pygments_styles#*$OPTLARG}" != "$_Dbg_pygments_styles" ]] ; then
208+
_Dbg_set_style="$OPTLARG"
209+
else
210+
printf "Can't find style ${OPTLARG}; --style option ignored." >&1
211+
fi
212+
;;
200213
tempdir)
201214
_Dbg_tmpdir=$OPTLARG ;;
202215
terminal | tty )
@@ -230,7 +243,7 @@ _Dbg_parse_options() {
230243
[[ -n $_Dbg_release ]] ; then
231244
echo "$_Dbg_shell_name debugger, $_Dbg_debugger_name, release $_Dbg_release"
232245
printf '
233-
Copyright 2002-2004, 2006-2012, 2014, 2016-2019, 2021 Rocky Bernstein
246+
Copyright 2002-2004, 2006-2012, 2014, 2016-2019, 2021, 2023-2024 Rocky Bernstein
234247
This is free software, covered by the GNU General Public License, and you are
235248
welcome to change it and/or distribute copies of it under certain conditions.
236249

lib/file.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function _Dbg_resolve_expand_filename {
9696
# Relative file name
9797
full_find_file=$(_Dbg_expand_filename "${_Dbg_init_cwd}/$find_file")
9898
if [[ -z "$full_find_file" ]] || [[ ! -r $full_find_file ]]; then
99-
# Try using cwd rather that Dbg_init_cwd
99+
# Try using cwd rather than Dbg_init_cwd
100100
full_find_file=$(_Dbg_expand_filename "$find_file")
101101
fi
102102
echo "$full_find_file"
@@ -106,14 +106,14 @@ function _Dbg_resolve_expand_filename {
106106
typeset -i n=${#_Dbg_dir[@]}
107107
typeset -i i
108108
for (( i=0 ; i < n; i++ )) ; do
109-
typeset basename="${_Dbg_dir[i]}"
110-
if [[ "$basename" == '\$cdir' ]] ; then
111-
basename=$_Dbg_cdir
112-
elif [[ "$basename" == '\$cwd' ]] ; then
113-
basename=$(pwd)
109+
typeset dirname="${_Dbg_dir[i]}"
110+
if [[ "$dirname" == '\$cdir' ]] ; then
111+
dirname="$_Dbg_cdir"
112+
elif [[ "$dirname" == '\$cwd' ]] ; then
113+
dirname="$(pwd)"
114114
fi
115-
if [[ -f "$basename/$find_file" ]] ; then
116-
echo "$basename/$find_file"
115+
if [[ -f "$dirname/$find_file" ]] ; then
116+
echo "$dirname/$find_file"
117117
return 0
118118
fi
119119
done

lib/fns.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ function _Dbg_linespec_setup {
197197
typeset -ri is_function=${word[1]}
198198
line_number=${word[0]}
199199
full_filename=$(_Dbg_is_file "$filename")
200+
if [[ -z "$full_filename" ]] ; then
201+
full_filename="$(_Dbg_resolve_expand_filename "$filename")"
202+
fi
200203

201204
if (( is_function )) ; then
202205
if [[ -z "$full_filename" ]] ; then

lib/hook.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# hook.sh - Debugger trap hook
33
#
44
# Copyright (C) 2002-2011, 2014, 2017-2019
5-
# Rocky Bernstein <rocky@gnu.org>
5+
# 2024 Rocky Bernstein <rocky@gnu.org>
66
#
77
# This program is free software; you can redistribute it and/or
88
# modify it under the terms of the GNU General Public License as
@@ -119,6 +119,13 @@ _Dbg_debug_trap_handler() {
119119

120120
_Dbg_save_args "$@"
121121

122+
typeset _Dbg_full_filename
123+
_Dbg_full_filename="$(_Dbg_is_file "${BASH_SOURCE[1]}")"
124+
if [[ -r "$_Dbg_full_filename" ]] ; then
125+
_Dbg_file2canonic["${BASH_SOURCE[1]}"]="$_Dbg_full_filename"
126+
fi
127+
128+
122129
# if in step mode, decrement counter
123130
if ((_Dbg_step_ignore > 0)) ; then
124131
((_Dbg_step_ignore--))
@@ -146,12 +153,6 @@ _Dbg_debug_trap_handler() {
146153
fi
147154
done
148155

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"
153-
fi
154-
155156
# Run applicable action statement
156157
if ((_Dbg_action_count > 0)) ; then
157158
_Dbg_hook_action_hit "$_Dbg_full_filename"

0 commit comments

Comments
 (0)