From 64a0861b1c29aac3d25d6acb7541ed037305934c Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 23 Dec 2024 06:19:08 -0500 Subject: [PATCH] Add more places we resolve/expand files In some cases though automatic file loading no longer happens. In particular, on "list" and "break" commands. --- command/break.sh | 5 ++- command/load.sh | 6 +++- lib/file.sh | 2 +- lib/fns.sh | 3 ++ test/data/bug-source.cmd | 3 +- test/data/bug-source.right | 4 +-- test/data/list.cmd | 11 +++--- test/data/list.right | 70 +++++++++++++++++++------------------- 8 files changed, 57 insertions(+), 47 deletions(-) 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 d4b92c26..70b060c5 100644 --- a/command/load.sh +++ b/command/load.sh @@ -52,7 +52,11 @@ _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 diff --git a/lib/file.sh b/lib/file.sh index c08e5040..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" diff --git a/lib/fns.sh b/lib/fns.sh index 15420329..8e193c8c 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/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 704ce43d..8c58889f 100644 --- a/test/data/bug-source.right +++ b/test/data/bug-source.right @@ -19,8 +19,8 @@ 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 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...