Skip to content

Commit

Permalink
Save more file information from initial call...
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rocky committed Dec 15, 2024
1 parent f93e14b commit f41e58a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 16 deletions.
9 changes: 9 additions & 0 deletions bashdb.in
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ if [[ -n $_Dbg_script_file ]] ; then
fi
typeset _Dbg_dollar_0="$0"

# 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"
14 changes: 7 additions & 7 deletions lib/hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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--))
Expand Down Expand Up @@ -146,13 +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"
_Dbg_file2canonic["${BASH_SOURCE[1]}"]="$_Dbg_full_filename"
fi

# Run applicable action statement
if ((_Dbg_action_count > 0)) ; then
_Dbg_hook_action_hit "$_Dbg_full_filename"
Expand Down
2 changes: 1 addition & 1 deletion test/data/brkpt2.right
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Num Type Enb Expression
breakpoint already hit 1 time
No actions have been set.
+cont
FUNCNAME[2]: source called from bashdb at line 107
FUNCNAME[2]: source called from bashdb at line 116
Breakpoint 6 hit (3 times).
(dbg-test1.sub:11):
11: local -i j=i+1
Expand Down
2 changes: 1 addition & 1 deletion test/data/bug-break.right
Original file line number Diff line number Diff line change
Expand Up @@ -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 107
##2 source("fib.sh") called from file `bashdb' at line 116
##3 main() called from file `bashdb' at line 0
+delete 1
Deleted breakpoint 1
Expand Down
2 changes: 1 addition & 1 deletion test/data/bug-source.right
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 107
FUNCNAME[2]: source called from bashdb at line 116
FUNCNAME[3]: main called from bashdb at line 0
(dbg-test1.sh:35):
35: exit 0;
Expand Down
2 changes: 1 addition & 1 deletion test/data/tbreak.right
Original file line number Diff line number Diff line change
Expand Up @@ -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 107
FUNCNAME[2]: source called from bashdb at line 116
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
Expand Down
8 changes: 4 additions & 4 deletions test/data/watch1.right
Original file line number Diff line number Diff line change
Expand Up @@ -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:106):
106: set -o functrace
(bashdb:115):
115: set -o functrace
+# 2nd part of Restart test
+l>
106: => set -o functrace
107: . "$_Dbg_script_file"
115: => set -o functrace
116: . "$_Dbg_script_file"
+info watch
Num Type Enb Expression
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test-file.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

Expand Down

0 comments on commit f41e58a

Please sign in to comment.