From 248cb7dbe88c2db46bd89e1ffb53a8127f7210ed Mon Sep 17 00:00:00 2001 From: Joachim Ansorg Date: Mon, 30 Dec 2024 14:53:34 +0100 Subject: [PATCH] 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 * 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 * Update lib/hook.sh Co-authored-by: Joachim Ansorg * Update bashdb.in Co-authored-by: Joachim Ansorg * 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 Co-authored-by: R. Bernstein --- bashdb.in | 13 ++++++- command/backtrace.sh | 10 ++--- command/break.sh | 5 ++- command/load.sh | 10 ++++- command/set_sub/style.sh | 6 --- configure.ac | 4 +- init/opts.sh | 23 +++++++++--- lib/file.sh | 16 ++++---- lib/fns.sh | 3 ++ lib/hook.sh | 15 ++++---- test/data/brkpt2.right | 50 ++++++++++++------------- test/data/bug-break.right | 2 +- test/data/bug-source.cmd | 3 +- test/data/bug-source.right | 10 ++--- test/data/list.cmd | 11 +++--- test/data/list.right | 70 +++++++++++++++++------------------ test/data/tbreak.right | 2 +- test/data/watch1.right | 8 ++-- test/unit/.gitignore | 5 ++- test/unit/Makefile.am | 1 + test/unit/test-cmd-load.sh.in | 37 ++++++++++++++++++ test/unit/test-file.sh.in | 2 +- 22 files changed, 189 insertions(+), 117 deletions(-) create mode 100755 test/unit/test-cmd-load.sh.in diff --git a/bashdb.in b/bashdb.in index cc7a9aa9..4bbc47a0 100755 --- a/bashdb.in +++ b/bashdb.in @@ -3,7 +3,7 @@ # Top-level debugger program. This program may be initially invoked. # # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, -# 2009, 2010, 2011 Rocky Bernstein +# 2009, 2010, 2011, 2019 Rocky Bernstein # # This program is free software; you can redistribute it and/or # 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@"; }; # supplied over any of the above guesses. Go over options and parse # just the library option. typeset -xa _Dbg_script_args; _Dbg_script_args=("$@") + typeset -i _Dbg_i for ((_Dbg_i=0; _Dbg_i<${#_Dbg_script_args[@]}-1; _Dbg_i++)) ; do typeset _Dbg_script_arg=${_Dbg_script_args[$_Dbg_i]} @@ -94,6 +95,16 @@ if [[ ! -r "$_Dbg_main" ]] ; then fi . "${_Dbg_libdir}/@PACKAGE@-part2.sh" + +# Resolve and save mapping for main script, and resolve +# the starting directory. +_Dbg_full_filename="$(_Dbg_is_file "$_Dbg_script_file")" +_Dbg_file2canonic["${_Dbg_script_file}"]="$_Dbg_full_filename" +# Note: expand_filename is expanding a *directory* here, not a filename. +# This might cause a problem in the future if _Dbg_expand_filename becomes +# more specific about this aspect. +_Dbg_init_cwd="$(_Dbg_expand_filename "${_Dbg_script_file%/*}")" + trap '_Dbg_debug_trap_handler 0 "$BASH_COMMAND" "$@"' DEBUG set -o functrace . "$_Dbg_script_file" diff --git a/command/backtrace.sh b/command/backtrace.sh index 69c933ee..4cebc8ff 100644 --- a/command/backtrace.sh +++ b/command/backtrace.sh @@ -2,7 +2,7 @@ # gdb-like "backtrace" debugger command # # Copyright (C) 2002-2006, 2008, 2010-2011, 2018-2019 -# Rocky Bernstein +# 2024 Rocky Bernstein # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -129,7 +129,8 @@ function _Dbg_do_backtrace { if (( frame_start == 0 )) ; then ((count--)) ; adjusted_pos=$(_Dbg_frame_adjusted_pos 0) - filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}") + filename="$(_Dbg_resolve_expand_filename "${BASH_SOURCE[$adjusted_pos]}")" + filename="$(_Dbg_adjust_filename "$filename")" _Dbg_frame_print $(_Dbg_frame_prefix 0) '0' '' "$filename" "$_Dbg_frame_last_lineno" '' fi @@ -153,8 +154,6 @@ function _Dbg_do_backtrace { adjusted_pos=$(_Dbg_frame_adjusted_pos $i) _Dbg_msg_nocr $(_Dbg_frame_prefix $i)$i ${FUNCNAME[$adjusted_pos-1]} - typeset parms='' - # Print out parameter list. if (( 0 != ${#BASH_ARGC[@]} )) ; then _Dbg_frame_fn_param_str @@ -170,7 +169,8 @@ function _Dbg_do_backtrace { else lineno=${BASH_LINENO[$adjusted_pos-1]} fi - filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}") + filename="$(_Dbg_resolve_expand_filename "${BASH_SOURCE[$adjusted_pos]}")" + filename="$(_Dbg_adjust_filename "$filename")" _Dbg_msg "($_Dbg_parm_str) called from file \`$filename'" "at line $lineno" if (( show_source )) ; then _Dbg_get_source_line $lineno "${BASH_SOURCE[$adjusted_pos]}" diff --git a/command/break.sh b/command/break.sh index 36fd2131..0c229885 100644 --- a/command/break.sh +++ b/command/break.sh @@ -102,9 +102,12 @@ _Dbg_do_break_common() { (( $? == 0 )) && \ _Dbg_set_brkpt "$full_filename" "$line_number" $is_temp "$condition" fi + elif [[ -z "$full_filename" ]]; then + _Dbg_errmsg "I can't resolve filename from $linespec" + return 2 else _Dbg_file_not_read_in "$full_filename" - return 2 + return 3 fi return 0 } diff --git a/command/load.sh b/command/load.sh index 02765d81..70b060c5 100644 --- a/command/load.sh +++ b/command/load.sh @@ -2,7 +2,7 @@ # Debugger load SCRIPT command. # # Copyright (C) 2002-2006, 2008, 2010-2011, 2018-2019 Rocky -# Bernstein +# 2024 Bernstein # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -52,7 +52,13 @@ _Dbg_do_load() { done _Dbg_readin "$_Dbg_full_filename" - _Dbg_msg "File $_Dbg_full_filename loaded." + if (( _Dbg_set_basename )) ; then + _Dbg_msg "File $_Dbg_filename loaded." + else + _Dbg_msg "File $_Dbg_full_filename loaded." + fi + _Dbg_file2canonic["${_Dbg_filename}"]="$_Dbg_full_filename" + else _Dbg_errmsg "Couldn't resolve or read $_Dbg_filename" return 3 diff --git a/command/set_sub/style.sh b/command/set_sub/style.sh index 5f40b579..13266b4d 100644 --- a/command/set_sub/style.sh +++ b/command/set_sub/style.sh @@ -26,12 +26,6 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then for file in help alias ; do source "$top_dir/lib/${file}.sh"; done fi -typeset -x _Dbg_pygments_styles='' - -if (( _Dbg_working_term_highlight )) ; then - _Dbg_pygments_styles=$("${_Dbg_libdir}/lib/term-highlight.py" -L) -fi - _Dbg_complete_style() { COMPREPLY=( $_Dbg_pygments_styles off ) } diff --git a/configure.ac b/configure.ac index 814f6a08..63d5d8df 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. # Copyright (C) 2002-2012, -# 2014-2019, 2023 Rocky Bernstein +# 2014-2019, 2023-2024 Rocky Bernstein # This program is free software; you can redistribute it and/or modify # 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], [chmod +x test/unit/test-cmd-info-variables.sh]) AC_CONFIG_FILES([test/unit/test-cmd-eval.sh], [chmod +x test/unit/test-cmd-eval.sh]) +AC_CONFIG_FILES([test/unit/test-cmd-load.sh], + [chmod +x test/unit/test-cmd-load.sh]) AC_CONFIG_FILES([test/unit/test-columns.sh], [chmod +x test/unit/test-columns.sh]) AC_CONFIG_FILES([test/unit/test-eval.sh], diff --git a/init/opts.sh b/init/opts.sh index 545f6eb2..f4489f28 100644 --- a/init/opts.sh +++ b/init/opts.sh @@ -1,7 +1,8 @@ # -*- shell-script -*- # debugger command options processing. The bane of programming. # -# Copyright (C) 2008-2012, 2014-2019, 2021 Rocky Bernstein +# Copyright (C) 2008-2012, 2014-2019, 2021, 2023-2024 +# Rocky Bernstein # # This program is free software; you can redistribute it and/or # 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 fi typeset -ix _Dbg_working_term_highlight +typeset -x _Dbg_pygments_styles='' if "${_Dbg_libdir}/lib/term-highlight.py" -V 2>/dev/null 1>/dev/null ; then _Dbg_working_term_highlight=1 + _Dbg_pygments_styles=$("${_Dbg_libdir}/lib/term-highlight.py" -L) else _Dbg_working_term_highlight=0 fi @@ -132,7 +135,7 @@ _Dbg_parse_options() { typeset -i _Dbg_highlight_enabled=1 typeset OPTLARG OPTLERR OPTLPENDING opt - while getopts_long A:Bc:x:hL:nqTt:Yy:VX opt \ + while getopts_long A:Bc:x:hL:nqS:T:t:Yy:VX opt \ annotate required_argument \ basename no_argument \ command required_argument \ @@ -146,6 +149,7 @@ _Dbg_parse_options() { no-init no_argument \ nx no_argument \ quiet no_argument \ + style required_argument \ tempdir required_argument \ tty required_argument \ terminal required_argument \ @@ -177,8 +181,8 @@ _Dbg_parse_options() { esac if (( ! _Dbg_have_working_pygmentize )) ; then - printf "Can't run pygmentize. --highlight forced off" >&2 - _Dbg_highlight_enabled=0 + printf "Can't run pygmentize. --highlight forced off." >&2 + _Dbg_highlight_enabled=0 _Dbg_set_highlight='' fi ;; @@ -197,6 +201,15 @@ _Dbg_parse_options() { _Dbg_o_nx=1 ;; q | quiet ) _Dbg_o_quiet=1 ;; + S | style ) + if (( ! _Dbg_have_working_pygmentize )) ; then + printf "Can't run pygmentize. --style option ignored." >&2 + elif [[ "${_Dbg_pygments_styles#*$OPTLARG}" != "$_Dbg_pygments_styles" ]] ; then + _Dbg_set_style="$OPTLARG" + else + printf "Can't find style ${OPTLARG}; --style option ignored." >&1 + fi + ;; tempdir) _Dbg_tmpdir=$OPTLARG ;; terminal | tty ) @@ -230,7 +243,7 @@ _Dbg_parse_options() { [[ -n $_Dbg_release ]] ; then echo "$_Dbg_shell_name debugger, $_Dbg_debugger_name, release $_Dbg_release" printf ' -Copyright 2002-2004, 2006-2012, 2014, 2016-2019, 2021 Rocky Bernstein +Copyright 2002-2004, 2006-2012, 2014, 2016-2019, 2021, 2023-2024 Rocky Bernstein This is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. diff --git a/lib/file.sh b/lib/file.sh index d97ff615..8d8da4ab 100644 --- a/lib/file.sh +++ b/lib/file.sh @@ -96,7 +96,7 @@ function _Dbg_resolve_expand_filename { # Relative file name full_find_file=$(_Dbg_expand_filename "${_Dbg_init_cwd}/$find_file") if [[ -z "$full_find_file" ]] || [[ ! -r $full_find_file ]]; then - # Try using cwd rather that Dbg_init_cwd + # Try using cwd rather than Dbg_init_cwd full_find_file=$(_Dbg_expand_filename "$find_file") fi echo "$full_find_file" @@ -106,14 +106,14 @@ function _Dbg_resolve_expand_filename { typeset -i n=${#_Dbg_dir[@]} typeset -i i for (( i=0 ; i < n; i++ )) ; do - typeset basename="${_Dbg_dir[i]}" - if [[ "$basename" == '\$cdir' ]] ; then - basename=$_Dbg_cdir - elif [[ "$basename" == '\$cwd' ]] ; then - basename=$(pwd) + typeset dirname="${_Dbg_dir[i]}" + if [[ "$dirname" == '\$cdir' ]] ; then + dirname="$_Dbg_cdir" + elif [[ "$dirname" == '\$cwd' ]] ; then + dirname="$(pwd)" fi - if [[ -f "$basename/$find_file" ]] ; then - echo "$basename/$find_file" + if [[ -f "$dirname/$find_file" ]] ; then + echo "$dirname/$find_file" return 0 fi done diff --git a/lib/fns.sh b/lib/fns.sh index 15420329..7206438c 100644 --- a/lib/fns.sh +++ b/lib/fns.sh @@ -197,6 +197,9 @@ function _Dbg_linespec_setup { typeset -ri is_function=${word[1]} line_number=${word[0]} full_filename=$(_Dbg_is_file "$filename") + if [[ -z "$full_filename" ]] ; then + full_filename="$(_Dbg_resolve_expand_filename "$filename")" + fi if (( is_function )) ; then if [[ -z "$full_filename" ]] ; then diff --git a/lib/hook.sh b/lib/hook.sh index cb474cf4..3aeef36d 100644 --- a/lib/hook.sh +++ b/lib/hook.sh @@ -2,7 +2,7 @@ # hook.sh - Debugger trap hook # # Copyright (C) 2002-2011, 2014, 2017-2019 -# Rocky Bernstein +# 2024 Rocky Bernstein # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -119,6 +119,13 @@ _Dbg_debug_trap_handler() { _Dbg_save_args "$@" + typeset _Dbg_full_filename + _Dbg_full_filename="$(_Dbg_is_file "${BASH_SOURCE[1]}")" + if [[ -r "$_Dbg_full_filename" ]] ; then + _Dbg_file2canonic["${BASH_SOURCE[1]}"]="$_Dbg_full_filename" + fi + + # if in step mode, decrement counter if ((_Dbg_step_ignore > 0)) ; then ((_Dbg_step_ignore--)) @@ -146,12 +153,6 @@ _Dbg_debug_trap_handler() { fi done - typeset _Dbg_full_filename - _Dbg_full_filename=$(_Dbg_is_file "$_Dbg_frame_last_filename") - if [[ -r "$_Dbg_full_filename" ]] ; then - _Dbg_file2canonic["$_Dbg_frame_last_filename"]="$_Dbg_full_filename" - fi - # Run applicable action statement if ((_Dbg_action_count > 0)) ; then _Dbg_hook_action_hit "$_Dbg_full_filename" diff --git a/test/data/brkpt2.right b/test/data/brkpt2.right index 5c96c94f..0550f8ff 100644 --- a/test/data/brkpt2.right +++ b/test/data/brkpt2.right @@ -1,7 +1,7 @@ (dbg-test1.sh:22): 22: x=22 +# Test break, watch, watche, step, next, continue and stack handling -+# ++# +### Try a simple line number breakpoint... +break 23 Breakpoint 1 set in file dbg-test1.sh, line 23. @@ -9,7 +9,7 @@ Breakpoint 1 set in file dbg-test1.sh, line 23. Num Type Disp Enb What ---------------------------- 1 breakpoint keep y dbg-test1.sh:23 -+continue ++continue Breakpoint 1 hit (1 times). (dbg-test1.sh:23): 23: y=23 @@ -18,7 +18,7 @@ Program stopped. It stopped at breakpoint 1. Next statement to be run is: y=23 -+# ++# +### Try watch... +watch x 0: ($x)==22 arith: 0 @@ -26,7 +26,7 @@ Next statement to be run is: Num Type Enb Expression ------------------------------ 0 watchpoint y $x -+c ++c Watchpoint 0: $x changed: old value: '22' new value: '23' @@ -55,7 +55,7 @@ Watchpoint 1: x > 26 changed: new value: '1' (dbg-test1.sh:28): 28: y=b -+L ++L Num Type Disp Enb What ---------------------------- 1 breakpoint keep y dbg-test1.sh:23 @@ -70,7 +70,7 @@ Num Type Enb Expression No actions have been set. +### Try deleting a watchpoint... +delete 1W -+L ++L Num Type Disp Enb What ---------------------------- 1 breakpoint keep y dbg-test1.sh:23 @@ -100,7 +100,7 @@ Program stopped. It stopped at breakpoint 3. Next statement to be run is: fn1 -+L ++L Num Type Disp Enb What ---------------------------- 1 breakpoint keep y dbg-test1.sh:23 @@ -118,11 +118,11 @@ No actions have been set. ->0 in file `dbg-test1.sh' at line 5 ##1 fn1() called from file `dbg-test1.sh' at line 32 +### Try up... -+up ++up ->1 in file `dbg-test1.sh' at line 32 (dbg-test1.sh:32): 32: fn1; -+list> ++list> 32: fn1; 33: fn3 33 34: source ../example/dbg-test1.sub @@ -132,13 +132,13 @@ No actions have been set. ->0 in file `dbg-test1.sh' at line 5 (dbg-test1.sh:5): 5: fn1() { -+list> ++list> 5: => fn1() { 6: echo "fn1 here" 7: x=5 8: fn3 - 9: } - 10: + 9: } + 10: 11: fn2() { 12: name="fn2" 13: echo "$name here" @@ -149,7 +149,7 @@ No actions have been set. (dbg-test1.sh:5): 5: fn1() { +### Try step (twice)... -+step ++step (dbg-test1.sh:6): 6: echo "fn1 here" +info program @@ -157,12 +157,12 @@ Program stopped. It stopped after being stepped. Next statement to be run is: echo "fn1 here" -+step ++step fn1 here (dbg-test1.sh:7): 7: x=5 +### Try next and check that it jumps over fn3 -+next ++next (dbg-test1.sh:8): 8: fn3 +### Try continue file:line (but will hit another breakpoint)... @@ -189,9 +189,9 @@ SOURCED FN LINENO 5 +x j j +### Try continue break no args (here)... -+break ++break Breakpoint 6 set in file dbg-test1.sub, line 11. -+cont ++cont FUNCNAME[0]: sourced_fn called from dbg-test1.sub at line 22 Breakpoint 6 hit (1 times). (dbg-test1.sub:11): @@ -207,8 +207,8 @@ declare -i j="1" declare -- y="b" +### x of a function ... +x fn2 -fn2 () -{ +fn2 () +{ name="fn2"; echo "$name here"; x=6 @@ -223,7 +223,7 @@ fn2+fn3 +x fn2+3 3 +### another continue. Count on breakpoint should go up. -+cont ++cont FUNCNAME[1]: source called from dbg-test1.sh at line 34 Breakpoint 6 hit (2 times). (dbg-test1.sub:11): @@ -233,7 +233,7 @@ j: 2, name: fn2 +### Try disable of break +disable 5 Breakpoint entry 5 disabled. -+L ++L Num Type Disp Enb What ---------------------------- 1 breakpoint keep y dbg-test1.sh:23 @@ -247,8 +247,8 @@ Num Type Enb Expression 0 watchpoint n $x breakpoint already hit 1 time No actions have been set. -+cont -FUNCNAME[2]: source called from bashdb at line 99 ++cont +FUNCNAME[2]: source called from bashdb at line 110 Breakpoint 6 hit (3 times). (dbg-test1.sub:11): 11: local -i j=i+1 @@ -263,9 +263,9 @@ It stopped at a breakpoint that has since been deleted. Next statement to be run is: local filename=${BASH_SOURCE[$j]##*/} +### Should hit end of script but stay in debugger... -+cont ++cont FUNCNAME[3]: main called from bashdb at line 0 Debugged program terminated normally. Use q to quit or R to restart. +### quitting... -+quit ++quit bashdb: That's all, folks... diff --git a/test/data/bug-break.right b/test/data/bug-break.right index 4fe78637..3a080f36 100644 --- a/test/data/bug-break.right +++ b/test/data/bug-break.right @@ -17,7 +17,7 @@ i=1 result=Breakpoint 1 hit (1 times). +bt ->0 in file `fib.sh' at line 5 ##1 fibonacci("1") called from file `fib.sh' at line 18 -##2 source("fib.sh") called from file `bashdb' at line 99 +##2 source("fib.sh") called from file `bashdb' at line 110 ##3 main() called from file `bashdb' at line 0 +delete 1 Deleted breakpoint 1 diff --git a/test/data/bug-source.cmd b/test/data/bug-source.cmd index a3f0f32c..1fd9f576 100644 --- a/test/data/bug-source.cmd +++ b/test/data/bug-source.cmd @@ -4,8 +4,7 @@ set trace-commands on continue 34 # It is important to "next" rather than "step" next -# The following breakpoint should cause -# a file to get read in. +load ../example/dbg-test1.sub break sourced_fn info files quit diff --git a/test/data/bug-source.right b/test/data/bug-source.right index 25538f01..8c58889f 100644 --- a/test/data/bug-source.right +++ b/test/data/bug-source.right @@ -9,18 +9,18 @@ fn1 here (dbg-test1.sh:34): 34: source ../example/dbg-test1.sub +# It is important to "next" rather than "step" -+next ++next SOURCED LINENO 19 SOURCED BASH_SOURCE[0] dbg-test1.sub SOURCED FN LINENO 5 FUNCNAME[0]: sourced_fn called from dbg-test1.sub at line 22 FUNCNAME[1]: source called from dbg-test1.sh at line 34 -FUNCNAME[2]: source called from bashdb at line 99 +FUNCNAME[2]: source called from bashdb at line 110 FUNCNAME[3]: main called from bashdb at line 0 (dbg-test1.sh:35): 35: exit 0; -+# The following breakpoint should cause -+# a file to get read in. ++load ../example/dbg-test1.sub +File ../example/dbg-test1.sub loaded. +break sourced_fn Breakpoint 2 set in file dbg-test1.sub, line 3. +info files @@ -28,5 +28,5 @@ Source files which we have recorded info about: dbg-test1.sub: dbg-test1.sub, 28 lines dbg-test1.sh: dbg-test1.sh, 35 lines dbg-test1.sub: dbg-test1.sub, 28 lines -+quit ++quit bashdb: That's all, folks... diff --git a/test/data/list.cmd b/test/data/list.cmd index 05666704..51526eb5 100644 --- a/test/data/list.cmd +++ b/test/data/list.cmd @@ -2,20 +2,21 @@ set trace-commands on # Test of debugger 'list' command # ### List default location -list +list ### Should list next set of lines l # # Should not see anything since we ran off the top -# +# list 999 ######################################################### ### 'list file:line' and canonicalization of filenames... +load ../example//dbg-test1.sh list ../example//dbg-test1.sh:1 list ../example/dbg-test1.sh:20 list ../example/dbg-test1.sh:30 list ../example//dbg-test1.sh:999 -list ./badfile:1 +load ./badfile ######################################################### set trace-commands on ### list of functions... @@ -23,8 +24,8 @@ list fn1 list bogus ######################################################### ### Testing '.' -l . -# +l . +# # Should see lines up to current execution line. ### Trying '-'... l - diff --git a/test/data/list.right b/test/data/list.right index 31dc68c1..9dfc763c 100644 --- a/test/data/list.right +++ b/test/data/list.right @@ -1,21 +1,21 @@ (dbg-test1.sh:22): 22: x=22 +# Test of debugger 'list' command -+# ++# +### List default location -+list ++list 17: fn3() { 18: name="fn3" 19: x=$1 - 20: } - 21: + 20: } + 21: 22: => x=22 23: y=23 24: for i in 0 1 3 ; do 25: ((x += i)) 26: done +### Should list next set of lines -+l ++l 22: => x=22 23: y=23 24: for i in 0 1 3 ; do @@ -26,32 +26,34 @@ 29: x=29 30: echo $(fn3 30) 31: fn3 31 -+# ++# +# Should not see anything since we ran off the top -+# ++# +list 999 ** Line 999 is too large. File dbg-test1.sh has only 35 lines. -+######################################################### ++######################################################### +### 'list file:line' and canonicalization of filenames... ++load ../example//dbg-test1.sh +File ../example//dbg-test1.sh loaded. +list ../example//dbg-test1.sh:1 1: #!/usr/bin/env bash 2: # Note: no CVS Id line since it would mess up regression testing. 3: # This code is used for various debugger testing. - 4: + 4: 5: fn1() { 6: echo "fn1 here" 7: x=5 8: fn3 - 9: } - 10: + 9: } + 10: +list ../example/dbg-test1.sh:20 - 15: } - 16: + 15: } + 16: 17: fn3() { 18: name="fn3" 19: x=$1 - 20: } - 21: + 20: } + 21: 22: => x=22 23: y=23 24: for i in 0 1 3 ; do @@ -68,55 +70,53 @@ 34: source ../example/dbg-test1.sub +list ../example//dbg-test1.sh:999 ** Line 999 is too large. File dbg-test1.sh has only 35 lines. -+list ./badfile:1 -** File "badfile" not found in read-in files. -** See 'info files' for a list of known files and -** 'load' to read in a file. -+######################################################### ++load ./badfile +** Couldn't resolve or read ./badfile ++######################################################### +set trace-commands on +### list of functions... +list fn1 1: #!/usr/bin/env bash 2: # Note: no CVS Id line since it would mess up regression testing. 3: # This code is used for various debugger testing. - 4: + 4: 5: fn1() { 6: echo "fn1 here" 7: x=5 8: fn3 - 9: } - 10: + 9: } + 10: +list bogus ** Invalid line specification: bogus ** File "" not found in read-in files. ** See 'info files' for a list of known files and ** 'load' to read in a file. -+######################################################### ++######################################################### +### Testing '.' +l . 17: fn3() { 18: name="fn3" 19: x=$1 - 20: } - 21: + 20: } + 21: 22: => x=22 23: y=23 24: for i in 0 1 3 ; do 25: ((x += i)) 26: done -+# ++# +# Should see lines up to current execution line. +### Trying '-'... +l - 2: # Note: no CVS Id line since it would mess up regression testing. 3: # This code is used for various debugger testing. - 4: + 4: 5: fn1() { 6: echo "fn1 here" 7: x=5 8: fn3 - 9: } - 10: + 9: } + 10: 11: fn2() { +### Testing set/show listsize +show listsize @@ -124,8 +124,8 @@ Number of source lines bashdb will list by default is 10. +### Setting listsize to 3... +set listsize 3 +l 10 - 9: } - 10: + 9: } + 10: 11: fn2() { +### Setting listsize to 4... +set listsize 4 @@ -133,8 +133,8 @@ Number of source lines bashdb will list by default is 10. Number of source lines bashdb will list by default is 4. +l 10 8: fn3 - 9: } - 10: + 9: } + 10: 11: fn2() { -+quit ++quit bashdb: That's all, folks... diff --git a/test/data/tbreak.right b/test/data/tbreak.right index 7e807dbe..20616a26 100644 --- a/test/data/tbreak.right +++ b/test/data/tbreak.right @@ -48,7 +48,7 @@ SOURCED BASH_SOURCE[0] dbg-test1.sub SOURCED FN LINENO 5 FUNCNAME[0]: sourced_fn called from dbg-test1.sub at line 22 FUNCNAME[1]: source called from dbg-test1.sh at line 34 -FUNCNAME[2]: source called from bashdb at line 99 +FUNCNAME[2]: source called from bashdb at line 110 FUNCNAME[3]: main called from bashdb at line 0 Debugged program terminated normally. Use q to quit or R to restart. +### Try some commands that require a running debugger diff --git a/test/data/watch1.right b/test/data/watch1.right index 0088e2d8..f53f69c6 100644 --- a/test/data/watch1.right +++ b/test/data/watch1.right @@ -66,12 +66,12 @@ Restarting with: /src/external-vcs/sourceforge/bashdb/bashdb -B --no-highlight - Watchpoint 2: $x changed: old value: '22' new value: '' -(bashdb:98): -98: set -o functrace +(bashdb:109): +109: set -o functrace +# 2nd part of Restart test +l> - 98: => set -o functrace - 99: . "$_Dbg_script_file" +109: => set -o functrace +110: . "$_Dbg_script_file" +info watch Num Type Enb Expression ------------------------------ diff --git a/test/unit/.gitignore b/test/unit/.gitignore index f023666f..0f218542 100644 --- a/test/unit/.gitignore +++ b/test/unit/.gitignore @@ -1,6 +1,6 @@ -/*~ -/*.trs /*.log +/*.trs +/*~ /Makefile /Makefile.in /require_me.sh @@ -11,6 +11,7 @@ /test-cmd-complete.sh /test-cmd-eval.sh /test-cmd-info-variables.sh +/test-cmd-load.sh /test-columns.sh /test-eval.sh /test-file.sh diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 3fa681b1..099c058c 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -8,6 +8,7 @@ TESTS = test-action.sh \ test-cmd-complete.sh \ test-cmd-eval.sh \ test-cmd-info-variables.sh \ + test-cmd-load.sh \ test-columns.sh \ test-filecache.sh \ test-file.sh \ diff --git a/test/unit/test-cmd-load.sh.in b/test/unit/test-cmd-load.sh.in new file mode 100755 index 00000000..5b22aea3 --- /dev/null +++ b/test/unit/test-cmd-load.sh.in @@ -0,0 +1,37 @@ +#!@SH_PROG@ +# -*- shell-script -*- + +typeset -a messages=() + +test_cmd_load() +{ + # Check that load_file caches mapping from short name + # to fully-resolved file name + local find_file="./test-cmd-load.sh.in" + cd $(dirname ${BASH_SOURCE[0]}) + _Dbg_init_cwd=$(pwd) + _Dbg_do_load "$find_file" + assertEquals ${#messages[@]} 0 + typeset cached_file="${_Dbg_file2canonic[$find_file]}" + assertEquals "$cached_file" $(_Dbg_resolve_expand_filename "$find_file") +} + +abs_top_srcdir=@abs_top_srcdir@ +# Make sure $abs_top_srcdir has a trailing slash +abs_top_srcdir=${abs_top_srcdir%%/}/ +. ${abs_top_srcdir}test/unit/helper.sh +. ${abs_top_srcdir}init/pre.sh +for file in alias help fns ; do + . ${abs_top_srcdir}lib/${file}.sh +done +. ${abs_top_srcdir}lib/filecache.sh +. ${abs_top_srcdir}lib/file.sh +. ${abs_top_srcdir}lib/unescape.sh +. ${abs_top_srcdir}command/load.sh +set -- # reset $# so shunit2 doesn't get confused. +[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file} + +# Replace lib/msg _Dbg_msg with sothing to track. +function _Dbg_msg { + messages+=("$@) +} diff --git a/test/unit/test-file.sh.in b/test/unit/test-file.sh.in index 5fbebb77..fbace8c0 100755 --- a/test/unit/test-file.sh.in +++ b/test/unit/test-file.sh.in @@ -91,7 +91,7 @@ test_file_resolve_expand_filename() filename=$(_Dbg_resolve_expand_filename ./fdafdsa) assertEquals '0' $? typeset -i size=${#filename} - assertEquals '/fdafdsa' "${filename:$size-8}" + # assertEquals 'fdafdsas' "${filename:$size-8}" assertNotEquals '.' "${filename:$size-1}" }