Skip to content
Merged
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
13 changes: 12 additions & 1 deletion bashdb.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Top-level debugger program. This program may be initially invoked.
#
# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008,
# 2009, 2010, 2011 Rocky Bernstein <rocky@gnu.org>
# 2009, 2010, 2011, 2019 Rocky Bernstein <rocky@gnu.org>
#
# 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 @@ -62,6 +62,7 @@ _Dbg_assign_libdir() { typeset prefix="@prefix@"; _Dbg_libdir="@PKGDATADIR@"; };
# supplied over any of the above guesses. Go over options and parse
# just the library option.
typeset -xa _Dbg_script_args; _Dbg_script_args=("$@")

typeset -i _Dbg_i
for ((_Dbg_i=0; _Dbg_i<${#_Dbg_script_args[@]}-1; _Dbg_i++)) ; do
typeset _Dbg_script_arg=${_Dbg_script_args[$_Dbg_i]}
Expand Down Expand Up @@ -94,6 +95,16 @@ if [[ ! -r "$_Dbg_main" ]] ; then
fi

. "${_Dbg_libdir}/@PACKAGE@-part2.sh"

# 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"
10 changes: 5 additions & 5 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 <rocky@gnu.org>
# 2024 Rocky Bernstein <rocky@gnu.org>
#
# 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 @@ -129,7 +129,8 @@ function _Dbg_do_backtrace {
if (( frame_start == 0 )) ; then
((count--)) ;
adjusted_pos=$(_Dbg_frame_adjusted_pos 0)
filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}")
filename="$(_Dbg_resolve_expand_filename "${BASH_SOURCE[$adjusted_pos]}")"
filename="$(_Dbg_adjust_filename "$filename")"
_Dbg_frame_print $(_Dbg_frame_prefix 0) '0' '' "$filename" "$_Dbg_frame_last_lineno" ''
fi

Expand All @@ -153,8 +154,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 +169,8 @@ function _Dbg_do_backtrace {
else
lineno=${BASH_LINENO[$adjusted_pos-1]}
fi
filename=$(_Dbg_file_canonic "${BASH_SOURCE[$adjusted_pos]}")
filename="$(_Dbg_resolve_expand_filename "${BASH_SOURCE[$adjusted_pos]}")"
filename="$(_Dbg_adjust_filename "$filename")"
_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
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
10 changes: 8 additions & 2 deletions command/load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Debugger load SCRIPT command.
#
# Copyright (C) 2002-2006, 2008, 2010-2011, 2018-2019 Rocky
# Bernstein <rocky@gnu.org>
# 2024 Bernstein <rocky@gnu.org>
#
# 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 @@ -52,7 +52,13 @@ _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
_Dbg_errmsg "Couldn't resolve or read $_Dbg_filename"
return 3
Expand Down
6 changes: 0 additions & 6 deletions command/set_sub/style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
for file in help alias ; do source "$top_dir/lib/${file}.sh"; done
fi

typeset -x _Dbg_pygments_styles=''

if (( _Dbg_working_term_highlight )) ; then
_Dbg_pygments_styles=$("${_Dbg_libdir}/lib/term-highlight.py" -L)
fi

_Dbg_complete_style() {
COMPREPLY=( $_Dbg_pygments_styles off )
}
Expand Down
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
dnl Process this file with autoconf to produce a configure script.

# Copyright (C) 2002-2012,
# 2014-2019, 2023 Rocky Bernstein <rocky@gnu.org>
# 2014-2019, 2023-2024 Rocky Bernstein <rocky@gnu.org>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -254,6 +254,8 @@ AC_CONFIG_FILES([test/unit/test-cmd-info-variables.sh],
[chmod +x test/unit/test-cmd-info-variables.sh])
AC_CONFIG_FILES([test/unit/test-cmd-eval.sh],
[chmod +x test/unit/test-cmd-eval.sh])
AC_CONFIG_FILES([test/unit/test-cmd-load.sh],
[chmod +x test/unit/test-cmd-load.sh])
AC_CONFIG_FILES([test/unit/test-columns.sh],
[chmod +x test/unit/test-columns.sh])
AC_CONFIG_FILES([test/unit/test-eval.sh],
Expand Down
23 changes: 18 additions & 5 deletions init/opts.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- shell-script -*-
# debugger command options processing. The bane of programming.
#
# Copyright (C) 2008-2012, 2014-2019, 2021 Rocky Bernstein <rocky@gnu.org>
# Copyright (C) 2008-2012, 2014-2019, 2021, 2023-2024
# Rocky Bernstein <rocky@gnu.org>
#
# 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 @@ -94,9 +95,11 @@ if ( pygmentize --version || pygmentize -V ) 2>/dev/null 1>/dev/null ; then
fi

typeset -ix _Dbg_working_term_highlight
typeset -x _Dbg_pygments_styles=''

if "${_Dbg_libdir}/lib/term-highlight.py" -V 2>/dev/null 1>/dev/null ; then
_Dbg_working_term_highlight=1
_Dbg_pygments_styles=$("${_Dbg_libdir}/lib/term-highlight.py" -L)
else
_Dbg_working_term_highlight=0
fi
Expand Down Expand Up @@ -132,7 +135,7 @@ _Dbg_parse_options() {
typeset -i _Dbg_highlight_enabled=1
typeset OPTLARG OPTLERR OPTLPENDING opt

while getopts_long A:Bc:x:hL:nqTt:Yy:VX opt \
while getopts_long A:Bc:x:hL:nqS:T:t:Yy:VX opt \
annotate required_argument \
basename no_argument \
command required_argument \
Expand All @@ -146,6 +149,7 @@ _Dbg_parse_options() {
no-init no_argument \
nx no_argument \
quiet no_argument \
style required_argument \
tempdir required_argument \
tty required_argument \
terminal required_argument \
Expand Down Expand Up @@ -177,8 +181,8 @@ _Dbg_parse_options() {
esac

if (( ! _Dbg_have_working_pygmentize )) ; then
printf "Can't run pygmentize. --highlight forced off" >&2
_Dbg_highlight_enabled=0
printf "Can't run pygmentize. --highlight forced off." >&2
_Dbg_highlight_enabled=0
_Dbg_set_highlight=''
fi
;;
Expand All @@ -197,6 +201,15 @@ _Dbg_parse_options() {
_Dbg_o_nx=1 ;;
q | quiet )
_Dbg_o_quiet=1 ;;
S | style )
if (( ! _Dbg_have_working_pygmentize )) ; then
printf "Can't run pygmentize. --style option ignored." >&2
elif [[ "${_Dbg_pygments_styles#*$OPTLARG}" != "$_Dbg_pygments_styles" ]] ; then
_Dbg_set_style="$OPTLARG"
else
printf "Can't find style ${OPTLARG}; --style option ignored." >&1
fi
;;
tempdir)
_Dbg_tmpdir=$OPTLARG ;;
terminal | tty )
Expand Down Expand Up @@ -230,7 +243,7 @@ _Dbg_parse_options() {
[[ -n $_Dbg_release ]] ; then
echo "$_Dbg_shell_name debugger, $_Dbg_debugger_name, release $_Dbg_release"
printf '
Copyright 2002-2004, 2006-2012, 2014, 2016-2019, 2021 Rocky Bernstein
Copyright 2002-2004, 2006-2012, 2014, 2016-2019, 2021, 2023-2024 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

Expand Down
16 changes: 8 additions & 8 deletions lib/file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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 All @@ -106,14 +106,14 @@ function _Dbg_resolve_expand_filename {
typeset -i n=${#_Dbg_dir[@]}
typeset -i i
for (( i=0 ; i < n; i++ )) ; do
typeset basename="${_Dbg_dir[i]}"
if [[ "$basename" == '\$cdir' ]] ; then
basename=$_Dbg_cdir
elif [[ "$basename" == '\$cwd' ]] ; then
basename=$(pwd)
typeset dirname="${_Dbg_dir[i]}"
if [[ "$dirname" == '\$cdir' ]] ; then
dirname="$_Dbg_cdir"
elif [[ "$dirname" == '\$cwd' ]] ; then
dirname="$(pwd)"
fi
if [[ -f "$basename/$find_file" ]] ; then
echo "$basename/$find_file"
if [[ -f "$dirname/$find_file" ]] ; then
echo "$dirname/$find_file"
return 0
fi
done
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")"
fi

if (( is_function )) ; then
if [[ -z "$full_filename" ]] ; then
Expand Down
15 changes: 8 additions & 7 deletions 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 <rocky@gnu.org>
# 2024 Rocky Bernstein <rocky@gnu.org>
#
# 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 @@ -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,12 +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"
fi

# Run applicable action statement
if ((_Dbg_action_count > 0)) ; then
_Dbg_hook_action_hit "$_Dbg_full_filename"
Expand Down
Loading
Loading