Skip to content

Breakpoint resolution problem #52

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

Draft
wants to merge 3 commits into
base: bash-5.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
23 changes: 16 additions & 7 deletions command/backtrace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# gdb-like "backtrace" debugger command
#
# Copyright (C) 2002-2006, 2008, 2010-2011, 2018-2019
# Rocky Bernstein <[email protected]>
# 2024 Rocky Bernstein <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -124,12 +124,17 @@ function _Dbg_do_backtrace {

typeset filename
typeset -i adjusted_pos
# Position 0 is special in that get the line number not from the
# stack but ultimately from LINENO which was saved in the hook call.
if (( frame_start == 0 )) ; then
((count--)) ;
adjusted_pos=$(_Dbg_frame_adjusted_pos 0)
filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}")
filename="${BASH_SOURCE[$adjusted_pos]}"
typeset -l resolved_filename="${_Dbg_file2canonic[$filename]}"
if [[ ! -z "${resolved_filename}" ]] ; then
filename="$resolved_filename"
else
filename=$(_Dbg_file_canonic "$filename")
fi

_Dbg_frame_print $(_Dbg_frame_prefix 0) '0' '' "$filename" "$_Dbg_frame_last_lineno" ''
fi

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

typeset parms=''

# Print out parameter list.
if (( 0 != ${#BASH_ARGC[@]} )) ; then
_Dbg_frame_fn_param_str
Expand All @@ -170,7 +173,13 @@ function _Dbg_do_backtrace {
else
lineno=${BASH_LINENO[$adjusted_pos-1]}
fi
filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}")

filename="${BASH_SOURCE[$adjusted_pos]}"
resolved_filename="${_Dbg_file2canonic[$filename]}"
if [[ ! -z "${resolved_filename}" ]] ; then
filename="$resolved_filename"
fi

_Dbg_msg "($_Dbg_parm_str) called from file \`$filename'" "at line $lineno"
if (( show_source )) ; then
_Dbg_get_source_line $lineno "${BASH_SOURCE[$adjusted_pos]}"
Expand Down
1 change: 1 addition & 0 deletions command/load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ _Dbg_do_load() {
done

_Dbg_readin "$_Dbg_full_filename"
_Dbg_file2canonic["${_Dbg_filename}"]="$_Dbg_full_filename"
_Dbg_msg "File $_Dbg_full_filename loaded."
else
_Dbg_errmsg "Couldn't resolve or read $_Dbg_filename"
Expand Down
7 changes: 4 additions & 3 deletions lib/break.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ _Dbg_set_brkpt() {
_Dbg_write_journal_eval "_Dbg_brkpt_file2linenos[\"$source_file\"]+=\" $lineno \""
_Dbg_write_journal_eval "_Dbg_brkpt_file2brkpt[\"$source_file\"]+=\" $_Dbg_brkpt_max \""

source_file=$(_Dbg_adjust_filename "$source_file")
resolved_source_file=$(_Dbg_adjust_filename "$source_file")
_Dbg_file2canonic["$source_file"]="$resolved_source_file"
if (( is_temp == 0 )) ; then
_Dbg_msg "Breakpoint $_Dbg_brkpt_max set in file ${source_file}, line $lineno."
_Dbg_msg "Breakpoint $_Dbg_brkpt_max set in file ${resolved_source_file}, line $lineno."
else
_Dbg_msg "One-time breakpoint $_Dbg_brkpt_max set in file ${source_file}, line $lineno."
_Dbg_msg "One-time breakpoint $_Dbg_brkpt_max set in file ${resolved_source_file}, line $lineno."
fi
_Dbg_write_journal "_Dbg_brkpt_max=$_Dbg_brkpt_max"
return 0
Expand Down
19 changes: 12 additions & 7 deletions lib/file.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- shell-script -*-
# Things related to file handling.
#
# Copyright (C) 2002-2004, 2006, 2008-2010, 2014, 2018, 2020 Rocky
# Bernstein [email protected]
# Copyright (C) 2002-2004, 2006, 2008-2010, 2014, 2018, 2020
# 2024 Bernstein [email protected]
#
# bashdb is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
Expand Down Expand Up @@ -98,21 +98,26 @@ function _Dbg_resolve_expand_filename {
# Try using cwd rather that Dbg_init_cwd
full_find_file=$(_Dbg_expand_filename "$find_file")
fi
if [[ ! -z "$full_find_file" ]]; then
_Dbg_file2canonic["$find_file"]="$full_find_file"
fi
echo "$full_find_file"
return 0
else
# Resolve file using _Dbg_dir
typeset -i n=${#_Dbg_dir[@]}
typeset -i i
for (( i=0 ; i < n; i++ )) ; do
typeset basename="${_Dbg_dir[i]}"
typeset dirname="${_Dbg_dir[i]}"
if [[ "$basename" == '\$cdir' ]] ; then
basename=$_Dbg_cdir
dirname="$_Dbg_cdir"
elif [[ "$basename" == '\$cwd' ]] ; then
basename=$(pwd)
dirname="$(pwd)"
fi
if [[ -f "$basename/$find_file" ]] ; then
echo "$basename/$find_file"
if [[ -f "$dirname/$find_file" ]] ; then
full_find_file="$dirname/$find_file"
_Dbg_file2canonic["$find_file"]="$full_find_file"
echo "$full_find_file"
return 0
fi
done
Expand Down
14 changes: 10 additions & 4 deletions lib/filecache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# filecache.sh - cache file information
#
# Copyright (C) 2008-2011, 2013-2015, 2018-2019 Rocky Bernstein
# <[email protected]>
# 2024 <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -63,7 +63,7 @@ _Dbg_check_line() {
# Error message for file not read in
function _Dbg_file_not_read_in {
typeset -r filename=$(_Dbg_adjust_filename "$1")
_Dbg_errmsg "File \"$filename\" not found in read-in files."
_Dbg_errmsg "File \"$filename\" ($1) not found in read-in files."
_Dbg_errmsg "See 'info files' for a list of known files and"
_Dbg_errmsg "'load' to read in a file."
}
Expand Down Expand Up @@ -106,7 +106,9 @@ _Dbg_get_source_line() {
filename="$1"
fi
_Dbg_readin_if_new "$filename"
if [[ -n $_Dbg_set_highlight ]] && [[ -n $_Dbg_highlight_array_var ]]; then
if [[ -z "$_Dbg_source_array_var" ]]; then
_Dbg_source_line="??"
elif [[ -n $_Dbg_set_highlight ]] && [[ -n $_Dbg_highlight_array_var ]]; then
eval "typeset -i count=\${#$_Dbg_highlight_array_var[@]}"
if (( count )) ; then
eval "_Dbg_source_line=\${$_Dbg_highlight_array_var[lineno]}"
Expand Down Expand Up @@ -244,7 +246,11 @@ function _Dbg_readin {
(( line_count >= NOT_SMALLFILE )) && _Dbg_msg "done."

# Add $filename to list of all filenames
_Dbg_filenames["$fullname"]=$_Dbg_source_array_var;
if [[ ! -z $fullname ]] ; then
_Dbg_filenames["$fullname"]=$_Dbg_source_array_var;
else
echo "XXX ${filename}"
fi
return 0
}

Expand Down
4 changes: 3 additions & 1 deletion lib/hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# hook.sh - Debugger trap hook
#
# Copyright (C) 2002-2011, 2014, 2017-2019
# Rocky Bernstein <[email protected]>
# 2024 Rocky Bernstein <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -148,8 +148,10 @@ _Dbg_debug_trap_handler() {

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
Expand Down
10 changes: 7 additions & 3 deletions lib/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ typeset _Dbg_source_line
function _Dbg_print_location_and_command {
typeset line_number=${1:-$_Dbg_frame_last_lineno}
typeset filename=${2:-$_Dbg_frame_last_filename}
_Dbg_get_source_line $line_number "$filename"
filename=$(_Dbg_adjust_filename "$filename")
_Dbg_msg "(${filename}:${line_number}):
if [[ -z "$filename" ]] ; then
_Dbg_msg "(??:${line_number}):"
else
_Dbg_get_source_line $line_number "$filename"
filename=$(_Dbg_adjust_filename "$filename")
_Dbg_msg "(${filename}:${line_number}):
${line_number}:\t${_Dbg_source_line}"
fi

# If we are at the same place in the file but the command has changed,
# then we have multiple commands on the line. So print which one we are
Expand Down
7 changes: 5 additions & 2 deletions lib/save-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ function _Dbg_set_debugger_entry {
_Dbg_stack_pos=_0
_Dbg_listline=_Dbg_frame_last_lineno
_Dbg_set_debugger_internal
_Dbg_frame_last_filename=${BASH_SOURCE[$discard_top_fn_count]:-$_Dbg_bogus_file}
_Dbg_frame_last_filename=$(_Dbg_resolve_expand_filename "$_Dbg_frame_last_filename")
typeset -l frame_last_filename=${BASH_SOURCE[$discard_top_fn_count]:-$_Dbg_bogus_file}
_Dbg_frame_last_filename=$(_Dbg_resolve_expand_filename "$frame_last_filename")
if [[ -z "$_Dbg_frame_last_filename" ]]; then
_Dbg_frame_last_filename="$frame_last_filename"
fi

# Read in the journal to pick up variable settings that might have
# been left from a subshell.
Expand Down
Loading