Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save more file information from initial call... #56

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
5 changes: 4 additions & 1 deletion command/break.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion command/load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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
Expand Down
2 changes: 1 addition & 1 deletion lib/file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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"
Expand Down
3 changes: 3 additions & 0 deletions lib/fns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is quoting needed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with quoting and it doesn't seem to hurt. Personally, I find the quotes within quotes confusing, and more generally the multiple substitution passes weird, but this is bash after all.

So I've now made the change.

fi

if (( is_function )) ; then
if [[ -z "$full_filename" ]] ; then
Expand Down
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
3 changes: 1 addition & 2 deletions test/data/bug-source.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/data/bug-source.right
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ 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;
+# 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
Expand Down
11 changes: 6 additions & 5 deletions test/data/list.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ 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...
list fn1
list bogus
#########################################################
### Testing '.'
l .
#
l .
#
# Should see lines up to current execution line.
### Trying '-'...
l -
Expand Down
70 changes: 35 additions & 35 deletions test/data/list.right
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -68,73 +70,71 @@
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
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
+show listsize
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...
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
Loading