Skip to content

Commit 7d2cd69

Browse files
committed
Expand filename shown in backtrace
1 parent 19388d8 commit 7d2cd69

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

command/backtrace.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# gdb-like "backtrace" debugger command
33
#
44
# Copyright (C) 2002-2006, 2008, 2010-2011, 2018-2019
5-
# Rocky Bernstein <rocky@gnu.org>
5+
# 2024 Rocky Bernstein <rocky@gnu.org>
66
#
77
# This program is free software; you can redistribute it and/or
88
# modify it under the terms of the GNU General Public License as
@@ -124,12 +124,17 @@ function _Dbg_do_backtrace {
124124

125125
typeset filename
126126
typeset -i adjusted_pos
127-
# Position 0 is special in that get the line number not from the
128-
# stack but ultimately from LINENO which was saved in the hook call.
129127
if (( frame_start == 0 )) ; then
130128
((count--)) ;
131129
adjusted_pos=$(_Dbg_frame_adjusted_pos 0)
132-
filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}")
130+
filename="${BASH_SOURCE[$adjusted_pos]}"
131+
resolved_filename="${_Dbg_file2canonic[$filename]}"
132+
if [[ ! -z "${resolved_filename}" ]] ; then
133+
filename="$resolved_filename"
134+
else
135+
filename=$(_Dbg_file_canonic "$filename")
136+
fi
137+
133138
_Dbg_frame_print $(_Dbg_frame_prefix 0) '0' '' "$filename" "$_Dbg_frame_last_lineno" ''
134139
fi
135140

@@ -153,8 +158,6 @@ function _Dbg_do_backtrace {
153158
adjusted_pos=$(_Dbg_frame_adjusted_pos $i)
154159
_Dbg_msg_nocr $(_Dbg_frame_prefix $i)$i ${FUNCNAME[$adjusted_pos-1]}
155160

156-
typeset parms=''
157-
158161
# Print out parameter list.
159162
if (( 0 != ${#BASH_ARGC[@]} )) ; then
160163
_Dbg_frame_fn_param_str
@@ -170,7 +173,13 @@ function _Dbg_do_backtrace {
170173
else
171174
lineno=${BASH_LINENO[$adjusted_pos-1]}
172175
fi
173-
filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}")
176+
177+
filename="${BASH_SOURCE[$adjusted_pos]}"
178+
resolved_filename="${_Dbg_file2canonic[$filename]}"
179+
if [[ ! -z "${resolved_filename}" ]] ; then
180+
filename="$resolved_filename"
181+
fi
182+
174183
_Dbg_msg "($_Dbg_parm_str) called from file \`$filename'" "at line $lineno"
175184
if (( show_source )) ; then
176185
_Dbg_get_source_line $lineno "${BASH_SOURCE[$adjusted_pos]}"

lib/file.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- shell-script -*-
22
# Things related to file handling.
33
#
4-
# Copyright (C) 2002-2004, 2006, 2008-2010, 2014, 2018, 2020 Rocky
5-
# Bernstein rocky@gnu.org
4+
# Copyright (C) 2002-2004, 2006, 2008-2010, 2014, 2018, 2020
5+
# 2024 Bernstein rocky@gnu.org
66
#
77
# bashdb is free software; you can redistribute it and/or modify it under
88
# the terms of the GNU General Public License as published by the Free
@@ -98,21 +98,26 @@ function _Dbg_resolve_expand_filename {
9898
# Try using cwd rather that Dbg_init_cwd
9999
full_find_file=$(_Dbg_expand_filename "$find_file")
100100
fi
101+
if [[ ! -z "$full_find_file" ]]; then
102+
_Dbg_file2canonic["$find_file"]="$full_find_file"
103+
fi
101104
echo "$full_find_file"
102105
return 0
103106
else
104107
# Resolve file using _Dbg_dir
105108
typeset -i n=${#_Dbg_dir[@]}
106109
typeset -i i
107110
for (( i=0 ; i < n; i++ )) ; do
108-
typeset basename="${_Dbg_dir[i]}"
111+
typeset dirname="${_Dbg_dir[i]}"
109112
if [[ "$basename" == '\$cdir' ]] ; then
110-
basename=$_Dbg_cdir
113+
dirname=$_Dbg_cdir
111114
elif [[ "$basename" == '\$cwd' ]] ; then
112-
basename=$(pwd)
115+
dirname=$(pwd)
113116
fi
114-
if [[ -f "$basename/$find_file" ]] ; then
115-
echo "$basename/$find_file"
117+
if [[ -f "$dirname/$find_file" ]] ; then
118+
full_find_file="$dirname/$find_file"
119+
_Dbg_file2canonic["$find_file"]="$full_find_file"
120+
echo "$full_find_file"
116121
return 0
117122
fi
118123
done

lib/hook.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# hook.sh - Debugger trap hook
33
#
44
# Copyright (C) 2002-2011, 2014, 2017-2019
5-
# Rocky Bernstein <rocky@gnu.org>
5+
# 2024 Rocky Bernstein <rocky@gnu.org>
66
#
77
# This program is free software; you can redistribute it and/or
88
# modify it under the terms of the GNU General Public License as
@@ -150,6 +150,7 @@ _Dbg_debug_trap_handler() {
150150
_Dbg_full_filename=$(_Dbg_is_file "$_Dbg_frame_last_filename")
151151
if [[ -r "$_Dbg_full_filename" ]] ; then
152152
_Dbg_file2canonic["$_Dbg_frame_last_filename"]="$_Dbg_full_filename"
153+
_Dbg_file2canonic["${BASH_SOURCE[1]}"]="$_Dbg_full_filename"
153154
fi
154155

155156
# Run applicable action statement

0 commit comments

Comments
 (0)