Skip to content

Commit 802f98c

Browse files
committed
Save more file infomation from initial call...
In parituclar, resolve the initial source directory and stor that as _Dbg_init_dir. Resolve name of main bash program and add that to canonicalized filenames.
1 parent f93e14b commit 802f98c

File tree

9 files changed

+26
-17
lines changed

9 files changed

+26
-17
lines changed

bashdb.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ if [[ -n $_Dbg_script_file ]] ; then
102102
fi
103103
typeset _Dbg_dollar_0="$0"
104104

105+
# Resolve and save mapping for main script, and resolve
106+
# the starting directory.
107+
_Dbg_full_filename=$(_Dbg_is_file "$_Dbg_script_file")
108+
_Dbg_file2canonic["${_Dbg_script_file}"]="$_Dbg_full_filename"
109+
# Note: expand_filename is expanding a *directory* here, not a filename.
110+
# This might cause a problem in the future if _Dbg_expand_filename becomes
111+
# more specific about this aspect.
112+
_Dbg_init_cwd=$(_Dbg_expand_filename "${_Dbg_script_file%/*}")
113+
105114
trap '_Dbg_debug_trap_handler 0 "$BASH_COMMAND" "$@"' DEBUG
106115
set -o functrace
107116
. "$_Dbg_script_file"

lib/file.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function _Dbg_resolve_expand_filename {
9696
full_find_file=$(_Dbg_expand_filename "${_Dbg_init_cwd}/$find_file")
9797
if [[ -z "$full_find_file" ]] || [[ ! -r $full_find_file ]]; then
9898
# Try using cwd rather that Dbg_init_cwd
99-
full_find_file=$(_Dbg_expand_filename "$find_file")
99+
full_find_file=$(_Dbg_expand_filename "$find_file")s
100100
fi
101101
echo "$full_find_file"
102102
return 0

lib/hook.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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,13 +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-
_Dbg_file2canonic["${BASH_SOURCE[1]}"]="$_Dbg_full_filename"
154-
fi
155-
156156
# Run applicable action statement
157157
if ((_Dbg_action_count > 0)) ; then
158158
_Dbg_hook_action_hit "$_Dbg_full_filename"

test/data/brkpt2.right

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Num Type Enb Expression
248248
breakpoint already hit 1 time
249249
No actions have been set.
250250
+cont
251-
FUNCNAME[2]: source called from bashdb at line 107
251+
FUNCNAME[2]: source called from bashdb at line 116
252252
Breakpoint 6 hit (3 times).
253253
(dbg-test1.sub:11):
254254
11: local -i j=i+1

test/data/bug-break.right

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ i=1 result=Breakpoint 1 hit (1 times).
1717
+bt
1818
->0 in file `fib.sh' at line 5
1919
##1 fibonacci("1") called from file `fib.sh' at line 18
20-
##2 source("fib.sh") called from file `bashdb' at line 107
20+
##2 source("fib.sh") called from file `bashdb' at line 116
2121
##3 main() called from file `bashdb' at line 0
2222
+delete 1
2323
Deleted breakpoint 1

test/data/bug-source.right

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SOURCED BASH_SOURCE[0] dbg-test1.sub
1515
SOURCED FN LINENO 5
1616
FUNCNAME[0]: sourced_fn called from dbg-test1.sub at line 22
1717
FUNCNAME[1]: source called from dbg-test1.sh at line 34
18-
FUNCNAME[2]: source called from bashdb at line 107
18+
FUNCNAME[2]: source called from bashdb at line 116
1919
FUNCNAME[3]: main called from bashdb at line 0
2020
(dbg-test1.sh:35):
2121
35: exit 0;

test/data/tbreak.right

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ SOURCED BASH_SOURCE[0] dbg-test1.sub
4848
SOURCED FN LINENO 5
4949
FUNCNAME[0]: sourced_fn called from dbg-test1.sub at line 22
5050
FUNCNAME[1]: source called from dbg-test1.sh at line 34
51-
FUNCNAME[2]: source called from bashdb at line 107
51+
FUNCNAME[2]: source called from bashdb at line 116
5252
FUNCNAME[3]: main called from bashdb at line 0
5353
Debugged program terminated normally. Use q to quit or R to restart.
5454
+### Try some commands that require a running debugger

test/data/watch1.right

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ Restarting with: /src/external-vcs/sourceforge/bashdb/bashdb -B --no-highlight -
6666
Watchpoint 2: $x changed:
6767
old value: '22'
6868
new value: ''
69-
(bashdb:106):
70-
106: set -o functrace
69+
(bashdb:115):
70+
115: set -o functrace
7171
+# 2nd part of Restart test
7272
+l>
73-
106: => set -o functrace
74-
107: . "$_Dbg_script_file"
73+
115: => set -o functrace
74+
116: . "$_Dbg_script_file"
7575
+info watch
7676
Num Type Enb Expression
7777
------------------------------

test/unit/test-file.sh.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test_file_resolve_expand_filename()
9191
filename=$(_Dbg_resolve_expand_filename ./fdafdsa)
9292
assertEquals '0' $?
9393
typeset -i size=${#filename}
94-
assertEquals '/fdafdsa' "${filename:$size-8}"
94+
assertEquals 'fdafdsas' "${filename:$size-8}"
9595
assertNotEquals '.' "${filename:$size-1}"
9696
}
9797

0 commit comments

Comments
 (0)