bashdb-4.2-0.8/0000755000175000017500000000000011565106266010116 500000000000000bashdb-4.2-0.8/lib/0000755000175000017500000000000011565106266010664 500000000000000bashdb-4.2-0.8/lib/journal.sh0000644000175000017500000000472511543617000012607 00000000000000# -*- shell-script -*- # Things related to variable journaling. # # Copyright (C) 2002, 2003, 2004, 2006, 2008, 2009, # 2010, 2011 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # We use a journal file to save variable state so that we can pass # values set in a subshell or nested shell back. This typically # includes debugger information, e.g. breakpoints and state. This file # is just code (usually assignment statements) that get eval'd. # The file to save the journal information. typeset _Dbg_journal=$(_Dbg_tempname journal) # append a command into journal file and then run the command. _Dbg_write_journal_eval() { _Dbg_write_journal "$@" eval "$@" } # append a command into journal file and then run the command. _Dbg_write_journal_var() { typeset var_name="$1" typeset val typeset val_cmd="val='\${$var_name}'" eval "$val_cmd" _Dbg_write_journal "${var_name}='${val}'" } _Dbg_write_journal_avar() { typeset decl_str; decl_str=$(declare -p $1) typeset -a decl_a decl_a=($decl_str) typeset -a decl_a2 decl_a2=${decl_a[@]:2} _Dbg_write_journal ${decl_a2[@]} } # Append a command into journal file. But we only need to do # if we are in a subshell. _Dbg_write_journal() { if (( BASH_SUBSHELL != 0 )) ; then echo "$@" >> ${_Dbg_journal} 2>/dev/null fi # return $? } # Remove all journal files. _Dbg_erase_journals() { [[ -f $_Dbg_journal ]] && rm ${_Dbg_journal} 2>/dev/null return $? } # read in or "source" in journal file which will set variables. _Dbg_source_journal() { if [ -r $_Dbg_journal ] ; then . $_Dbg_journal (( BASH_SUBSHELL == 0 )) && _Dbg_erase_journals fi } if [ ! -f _Dbg_journal ] ; then typeset -i _Dbg_QUIT_LEVELS=0 _Dbg_write_journal "_Dbg_QUIT_LEVELS=0" fi bashdb-4.2-0.8/lib/columnize.sh0000644000175000017500000001014211557213411013133 00000000000000# -*- shell-script -*- # Copyright (C) 2008, 2010, 2011 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # # Code ported from my Ruby code which is in turn ported from a routine # from Python. # columnize a blank-delmited string $1 with maximum column width $2, # separate columns with $3. The column width defaults to 80 and the # column separator is two spaces. However if we are using ksh93t or # greater, then $1 is where the return value is to go and the other # parameters are shifted by 1: $2 contains the list to columnize and # $3 the maximum width, etc. columnize() { typeset -i displaywidth=${1:-80} (($# < 2)) && typeset colsep=' ' || typeset colsep="$2" typeset -i list_size=${#list[@]} if ((list_size == 0)) ; then columnized=('') return fi if ((1 == list_size)); then columnized=("${list[0]}") return fi # Consider arranging list in 1 rows total, then 2 rows... # Stop when at the smallest number of rows which # can be arranged less than the display width. typeset -i nrows=0 typeset -i ncols=0 typeset -a colwidths=() typeset -i i=0 for (( i=0; i= list_size)); then break fi typeset item="${list[j]}" ((colwidth < ${#item})) && colwidth=${#item} done colwidths+=($colwidth) ((totwidth+=colwidth + ${#colsep})) if ((totwidth > displaywidth)); then break fi done if ((totwidth <= displaywidth)); then break fi done # The smallest number of rows computed and the # max widths for each column has been obtained. # Now we just have to format each of the # rows. for (( row=0; row= list_size)); then item='' else item="${list[i]}" fi texts[$text_size]="$item" ((text_size++)) done while (( text_size > 0 )) && [[ ${texts[text_size-1]} == '' ]] ; do ((text_size--)) unset texts[$text_size] done text_row='' text_cell='' for (( col=0; col # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # Code adapted from my pydb code to do the same thing. #================ VARIABLE INITIALIZATIONS ====================# # associates a command list to breakpoint numbers typeset -ai _Dbg_brkpt_commands_start=() typeset -ai _Dbg_brkpt_commands_end=() # The text strings for the *all* breakpoints. To get breakpoints for # breakpoint i, this goies from _Dbg_brkpt_commands_start[i] to # _Dbg_brkpt_commands_end[i] # typeset -a _Dbg_brkpt_commands=() # For each breakpoint number, tells if the prompt must be displayed after # execing the command list typeset -ai _Dbg_brkpt_commands_doprompt=() # For each breakpoint number, tells if the stack trace must be # displayed after execing the cmd list typeset -ai _Dbg_brkpt_commands_silent=() typeset -i _Dbg_brkpt_commands_current=-1 # True while in the process of defining a command list _Dbg_brkpt_commands_defining=0 # The breakpoint number for which we are defining a list _Dbg_brkpt_commands_bnum=0 # Call every command that was set for the current active breakpoint # (if there is one) Returns True if the normal interaction function # must be called, False otherwise _Dbg_bp_commands() { local currentbp=$1 local lastcmd_back=$_Dbg_brkpt_lastcmd ## _Dbg_brkpt_setup(frame, None) ??? FIXME Probably not needed local -i i local -i start=${_Dbg_brkpt_commands_start[$currentbp]} local -i end=${_Dbg_brkpt_commands_end[$currentbp]} for (( i=start ; (( i < end )) ; i++ )) ; do local -a line=(${_Dbg_brkpt_commands[$i]}) _Dbg_onecmd ${line[*]} _Dbg_brkpt_lastcmd=$lastcmd_back if (( _Dbg_brkpt_commands_doprompt[$currentbp] )) ; then ###??? What's this _Dbg_process_commands return 0 fi done return 1 } bashdb-4.2-0.8/lib/term-highlight.py0000755000175000017500000000740011535300364014066 00000000000000#!/usr/bin/env python # from pydbgr.api import debug # debug() from pygments import highlight from pygments.lexers import BashLexer from pygments.formatters import TerminalFormatter from pygments.token import Keyword, Name, Comment, String, Error, \ Number, Operator, Generic, Token, Whitespace from tempfile import mktemp import os, sys #: Map token types to a tuple of color values for light and dark #: backgrounds. TERMINAL_COLORS = { Token: ('', ''), Whitespace: ('lightgray', 'darkgray'), Comment: ('brown', 'darkgray'), Comment.Preproc: ('teal', 'turquoise'), Keyword: ('*darkgreen*', 'blue'), Keyword.Type: ('teal', 'turquoise'), Operator.Word: ('purple', 'fuchsia'), Name.Builtin: ('teal', 'turquoise'), Name.Function: ('darkgreen', 'green'), Name.Namespace: ('_teal_', '_turquoise_'), Name.Class: ('_darkgreen_', '_green_'), Name.Exception: ('teal', 'turquoise'), Name.Decorator: ('darkgray', 'lightgray'), Name.Variable: ('darkblue', 'blue'), Name.Constant: ('darkblue', 'blue'), Name.Attribute: ('teal', 'turquoise'), Name.Tag: ('blue', 'blue'), String: ('brown', 'brown'), Number: ('black', 'blue'), Generic.Deleted: ('red', 'red'), Generic.Inserted: ('darkgreen', 'green'), Generic.Heading: ('**', '**'), Generic.Subheading: ('*purple*', '*fuchsia*'), Generic.Error: ('red', 'red'), Error: ('_red_', '_red_'), } def syntax_highlight_file(input_filename, to_stdout = False, color_file=None): if to_stdout: outfile = sys.stdout out_filename = None else: basename = os.path.basename(input_filename) out_filename=mktemp('.term', basename + '_') try: outfile = open(out_filename, 'w') except IOError, (errno, strerror): print "I/O in opening debugger output file %s" % out_filename print "error(%s): %s" % (errno, strerror) sys.exit(1) except: print "Unexpected error in opening output file %s" % out_filename sys.exit(1) pass pass if input_filename: try: infile = open(input_filename) except IOError, (errno, strerror): print "I/O in opening debugger input file %s" % input_filename print "error(%s): %s" % (errno, strerror) sys.exit(2) except: print "Unexpected error in opening output file %s" % out_filename sys.exit(2) pass pass else: infile = sys.stdin pass formatter = TerminalFormatter() if color_file and os.path.isfile(color_file): try: execfile(color_file) except: sys.exit(10) pass pass formatter.colorscheme = TERMINAL_COLORS for code_line in infile.readlines(): line = highlight(code_line, BashLexer(), formatter).strip("\r\n") outfile.write(line + "\n") # print line, pass outfile.close if out_filename: print out_filename sys.exit(0) pass if __name__=='__main__': color_file = None to_stdout = False if len(sys.argv) == 1: to_stdout = True filename = None elif len(sys.argv) == 2: filename = sys.argv[1] elif len(sys.argv) == 3: filename = sys.argv[1] color_file = sys.argv[2] else: print "usage: $0 [FILE [color-file]]" sys.exit(3) pass syntax_highlight_file(filename, to_stdout, color_file) pass bashdb-4.2-0.8/lib/save-restore.sh0000644000175000017500000001233011565105370013551 00000000000000# -*- shell-script -*- # save-restore.sh - saves, sets and restores debugger vars on hook entry # # Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, # 2011 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # Does things to after on entry of after an eval to set some debugger # internal settings function _Dbg_set_debugger_internal { IFS="$_Dbg_space_IFS"; PS4='+ dbg (${BASH_SOURCE}:${LINENO}[$BASH_SUBSHELL]): ${FUNCNAME[0]}\n' } function _Dbg_restore_user_vars { IFS="$_Dbg_space_IFS"; set -$_Dbg_old_set_opts IFS="$_Dbg_old_IFS"; PS4="$_Dbg_old_PS4" } _Dbg_save_args() { # Save values of $1 $2 $3 when debugged program was stopped # We use the loop below rather than _Dbg_set_args="(@)" because # we want to preserve embedded blanks in the arguments. typeset -i _Dbg_n=${#@} typeset -i _Dbg_i typeset -i _Dbg_arg_max=${#_Dbg_arg[@]} # If there has been a shift since the last time we entered, # it is possible that _Dbg_arg will contain too many values. # So remove those that have disappeared. for (( _Dbg_i=_Dbg_arg_max; _Dbg_i > _Dbg_n ; _Dbg_i-- )) ; do unset _Dbg_arg[$_Dbg_i] done # Populate _Dbg_arg with $1, $2, etc. for (( _Dbg_i=1 ; _Dbg_n > 0; _Dbg_n-- )) ; do _Dbg_arg[$_Dbg_i]="$1" ((_Dbg_i++)) shift done unset _Dbg_arg[0] # Get rid of line number; makes array count # correct; also listing all _Dbg_arg works # like $*. } # Do things for debugger entry. Set some global debugger variables # Remove trapping ourselves. # We assume that we are nested two calls deep from the point of debug # or signal fault. If this isn't the constant 2, then consider adding # a parameter to this routine. function _Dbg_set_debugger_entry { # Nuke DEBUG trap trap '' DEBUG # How many function are on the stack that are part of the debugger? # Normally this gets called from the trace hook. so this routine plus # the trace hook should are on the FUNCNAME stack and should be ignored typeset -li discard_top_fn_count=${1:-2} _Dbg_cur_fn=${FUNCNAME[$discard_top_fn_count]} _Dbg_frame_last_lineno=${BASH_LINENO[1]} ((_Dbg_frame_last_lineno < 1)) && let _Dbg_frame_last_lineno=1 _Dbg_old_IFS="$IFS" _Dbg_old_PS4="$PS4" ((_Dbg_stack_size = ${#FUNCNAME[@]} + 1 - discard_top_fn_count)) _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") # Read in the journal to pick up variable settings that might have # been left from a subshell. _Dbg_source_journal if (( _Dbg_QUIT_LEVELS > 0 )) ; then _Dbg_do_quit $_Dbg_debugged_exit_code fi } function _Dbg_set_to_return_from_debugger { _Dbg_stop_reason='' _Dbg_listline=0 # FIXME: put in a frame setup routine and remove from set_entry _Dbg_last_lineno=${_Dbg_frame_last_lineno} if (( $1 != 0 )) ; then _Dbg_last_bash_command="$_Dbg_bash_command" _Dbg_last_source_file="$_Dbg_frame_last_filename" else _Dbg_last_lineno=${BASH_LINENO[1]} _Dbg_last_source_file=${BASH_SOURCE[2]:-$_Dbg_bogus_file} _Dbg_last_bash_command="**unsaved _bashdb command**" fi if (( _Dbg_restore_debug_trap )) ; then trap '_Dbg_debug_trap_handler 0 "$BASH_COMMAND" "$@"' DEBUG else trap - DEBUG fi _Dbg_restore_user_vars } _Dbg_save_state() { _Dbg_statefile=$(_Dbg_tempname statefile) echo '' > $_Dbg_statefile _Dbg_save_breakpoints _Dbg_save_actions _Dbg_save_watchpoints _Dbg_save_display _Dbg_save_Dbg_set echo "unset DBG_RESTART_FILE" >> $_Dbg_statefile echo "rm $_Dbg_statefile" >> $_Dbg_statefile export DBG_RESTART_FILE="$_Dbg_statefile" _Dbg_write_journal "export DBG_RESTART_FILE=\"$_Dbg_statefile\"" } _Dbg_save_Dbg_set() { declare -p _Dbg_set_basename >> $_Dbg_statefile declare -p _Dbg_set_debug >> $_Dbg_statefile declare -p _Dbg_edit >> $_Dbg_statefile declare -p _Dbg_set_listsize >> $_Dbg_statefile declare -p _Dbg_prompt_str >> $_Dbg_statefile declare -p _Dbg_set_show_command >> $_Dbg_statefile } _Dbg_restore_state() { typeset statefile=$1 . $1 } # Things we do when coming back from a nested shell. # "shell", and "debug" create nested shells. _Dbg_restore_from_nested_shell() { rm -f $_Dbg_shell_temp_profile 2>&1 >/dev/null if [[ -r $_Dbg_restore_info ]] ; then . $_Dbg_restore_info rm $_Dbg_restore_info fi } bashdb-4.2-0.8/lib/hook.sh0000644000175000017500000002266711561306175012112 00000000000000# -*- shell-script -*- # hook.sh - Debugger trap hook # # Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. typeset _Dbg_RESTART_COMMAND='' # This is set to 1 if you want to debug debugger routines, i.e. routines # which start _Dbg_. But you better should know what you are doing # if you do this or else you may get into a recursive loop. typeset -i _Dbg_set_debug=0 # 1 if we are debugging the debugger typeset _Dbg_stop_reason='' # The reason we are in the debugger. # Set to 0 to clear "trap DEBUG" after entry typeset -i _Dbg_restore_debug_trap=1 # Are we inside the middle of a "skip" command? If so this gets copied # to _Dbg_continue_rc which controls the return code from the trap. typeset -i _Dbg_inside_skip=0 # If _Dbg_continue_rc is not less than 0, continue execution of the # program. As specified by the shopt extdebug option. See extdebug of # "The Shopt Builtin" in the bash info guide. The information # summarized is: # # - A return code 2 is special and means return from a function or # "source" command immediately # # - A nonzero return indicate the next statement should not be run. # Typically we use 1 for that value. # - A set return code 0 continues execution. typeset -i _Dbg_continue_rc=-1 # ===================== FUNCTIONS ======================================= # We come here after before statement is run. This is the function named # in trap SIGDEBUG. # Note: We have to be careful here in naming "local" variables. In contrast # to other places in the debugger, because of the read/eval loop, they are # in fact seen by those using the debugger. So in contrast to other "local"s # in the debugger, we prefer to preface these with _Dbg_. _Dbg_debug_trap_handler() { ### The below is also copied below in _Dbg_sig_handler... ### Should put common stuff into a function. # Consider putting the following line(s) in a routine. # Ditto for the restore environment typeset -i _Dbg_debugged_exit_code=$? _Dbg_old_set_opts=$- shopt -s extdebug # Turn off line and variable trace listing if were not in our own debug # mode, and set our own PS4 for debugging inside the debugger (( !_Dbg_set_debug )) && set +x +v +u # If we are in our own routines -- these start with _bashdb -- then # return. if [[ ${FUNCNAME[1]} == _Dbg_* ]] && (( !_Dbg_set_debug )); then _Dbg_set_to_return_from_debugger 0 return 0 fi # Sets _Dbg_frame_last_lineno and _Dbg_frame_last_filename among # other things. _Dbg_set_debugger_entry _Dbg_continue_rc=_Dbg_inside_skip # Shift off "RETURN"; we do not need that any more. shift _Dbg_bash_command=$1 shift _Dbg_save_args "$@" # if in step mode, decrement counter if ((_Dbg_step_ignore > 0)) ; then ((_Dbg_step_ignore--)) _Dbg_write_journal "_Dbg_step_ignore=$_Dbg_step_ignore" # Can't return here because we may want to stop for another # reason. fi # look for watchpoints. typeset -i _Dbg_i for (( _Dbg_i=0; _Dbg_i < _Dbg_watch_max ; _Dbg_i++ )) ; do if [ -n "${_Dbg_watch_exp[$_Dbg_i]}" ] \ && [[ ${_Dbg_watch_enable[_Dbg_i]} != 0 ]] ; then typeset new_val=$(_Dbg_get_watch_exp_eval $_Dbg_i) typeset old_val=${_Dbg_watch_val[$_Dbg_i]} if [[ $old_val != $new_val ]] ; then ((_Dbg_watch_count[_Dbg_i]++)) _Dbg_msg "Watchpoint $_Dbg_i: ${_Dbg_watch_exp[$_Dbg_i]} changed:" _Dbg_msg " old value: '$old_val'" _Dbg_msg " new value: '$new_val'" _Dbg_watch_val[$_Dbg_i]=$new_val _Dbg_hook_enter_debugger 'on a watch trigger' return $_Dbg_continue_rc fi fi done typeset full_filename full_filename=$(_Dbg_is_file "$_Dbg_frame_last_filename") if [[ -r $full_filename ]] ; then _Dbg_file2canonic[$_Dbg_frame_last_filename]="$full_filename" fi # Run applicable action statement if ((_Dbg_action_count > 0)) ; then _Dbg_hook_action_hit "$full_filename" fi # Determine if we stop or not. # Check breakpoints. if ((_Dbg_brkpt_count > 0)) ; then if _Dbg_hook_breakpoint_hit "$full_filename"; then if ((_Dbg_step_force)) ; then typeset _Dbg_frame_previous_file="$_Dbg_frame_last_filename" typeset -i _Dbg_frame_previous_lineno="$_Dbg_frame_last_lineno" fi ## FIXME: should probably add this (from zshdb): ## _Dbg_frame_save_frames 1 ((_Dbg_brkpt_counts[_Dbg_brkpt_num]++)) _Dbg_write_journal \ "_Dbg_brkpt_counts[$_Dbg_brkpt_num]=${_Dbg_brkpt_counts[_Dbg_brkpt_num]}" if (( _Dbg_brkpt_onetime[_Dbg_brkpt_num] == 1 )) ; then _Dbg_stop_reason='at a breakpoint that has since been deleted' _Dbg_delete_brkpt_entry $_Dbg_brkpt_num else _Dbg_msg \ "Breakpoint $_Dbg_brkpt_num hit (${_Dbg_brkpt_counts[_Dbg_brkpt_num]} times)." _Dbg_stop_reason="at breakpoint $_Dbg_brkpt_num" fi # We're sneaky and check commands_end because start could # legitimately be 0. if (( _Dbg_brkpt_commands_end[$_Dbg_brkpt_num] )) ; then # Run any commands associated with this breakpoint _Dbg_bp_commands $_Dbg_brkpt_num fi _Dbg_hook_enter_debugger "$_Dbg_stop_reason" _Dbg_set_to_return_from_debugger 1 return $_Dbg_continue_rc fi fi # Check if step mode and number steps to ignore. if ((_Dbg_step_ignore == 0)); then if ((_Dbg_step_force)) ; then if (( _Dbg_last_lineno == _Dbg_frame_last_lineno )) \ && [[ $_Dbg_last_source_file == $_Dbg_frame_last_filename ]] ; then _Dbg_set_to_return_from_debugger 1 return $_Dbg_continue_rc fi fi _Dbg_hook_enter_debugger 'after being stepped' return $_Dbg_continue_rc elif (( ${#FUNCNAME[@]} == _Dbg_return_level )) ; then # here because a trap RETURN _Dbg_return_level=0 _Dbg_hook_enter_debugger 'on a return' return $_Dbg_continue_rc elif (( -1 == _Dbg_return_level )) ; then # here because we are fielding a signal. _Dbg_hook_enter_debugger 'on fielding signal' return $_Dbg_continue_rc elif ((_Dbg_set_linetrace==1)) ; then if ((_Dbg_set_linetrace_delay)) ; then sleep $_Dbg_linetrace_delay fi _Dbg_print_linetrace # FIXME: DRY code. _Dbg_set_to_return_from_debugger 1 _Dbg_last_lineno=${BASH_LINENO[0]} return $_Dbg_continue_rc fi _Dbg_set_to_return_from_debugger 1 return $_Dbg_continue_rc } _Dbg_hook_action_hit() { typeset full_filename="$1" typeset lineno=$_Dbg_frame_last_lineno # FIXME: combine with _Dbg_unset_action typeset -a linenos [[ -z $full_filename ]] && return 1 eval "linenos=(${_Dbg_action_file2linenos[$full_filename]})" typeset -a action_nos eval "action_nos=(${_Dbg_action_file2action[$full_filename]})" typeset -i _Dbg_i # Check action within full_filename for ((_Dbg_i=0; _Dbg_i < ${#linenos[@]}; _Dbg_i++)); do if (( linenos[_Dbg_i] == lineno )) ; then (( _Dbg_action_num = action_nos[_Dbg_i] )) stmt="${_Dbg_action_stmt[$_Dbg_action_num]}" . ${_Dbg_libdir}/dbg-set-d-vars.inc eval "$stmt" # We've reset some variables like IFS and PS4 to make eval look # like they were before debugger entry - so reset them now. _Dbg_set_debugger_internal return 0 fi done return 1 } # Return 0 if we are at a breakpoint position or 1 if not. # Sets _Dbg_brkpt_num to the breakpoint number found. _Dbg_hook_breakpoint_hit() { typeset full_filename="$1" typeset lineno=$_Dbg_frame_last_lineno # FIXME: combine with _Dbg_unset_brkpt typeset -a linenos [[ -z $full_filename ]] && return 1 [[ -z ${_Dbg_brkpt_file2linenos[$full_filename]} ]] && return 1 eval "linenos=(${_Dbg_brkpt_file2linenos[$full_filename]})" typeset -a brkpt_nos eval "brkpt_nos=(${_Dbg_brkpt_file2brkpt[$full_filename]})" typeset -i i # Check breakpoints within full_filename for ((i=0; i < ${#linenos[@]}; i++)); do if (( linenos[i] == lineno )) ; then # Got a match, but is the breakpoint enabled? (( _Dbg_brkpt_num = brkpt_nos[i] )) if ((_Dbg_brkpt_enable[_Dbg_brkpt_num] )) ; then return 0 fi fi done return 1 } # Go into the command loop _Dbg_hook_enter_debugger() { _Dbg_stop_reason="$1" [[ 'noprint' != $2 ]] && _Dbg_print_location_and_command _Dbg_process_commands _Dbg_set_to_return_from_debugger 1 return $_Dbg_continue_rc } # Cleanup routine: erase temp files before exiting. _Dbg_cleanup() { [[ -f $_Dbg_evalfile ]] && rm -f $_Dbg_evalfile 2>/dev/null set +u if [[ -n $_Dbg_EXECUTION_STRING ]] && [[ -r $_Dbg_script_file ]] ; then rm $_Dbg_script_file fi _Dbg_erase_journals _Dbg_restore_user_vars } # Somehow we can't put this in _Dbg_cleanup and have it work. # I am not sure why. _Dbg_cleanup2() { [[ -f $_Dbg_evalfile ]] && rm -f $_Dbg_evalfile 2>/dev/null _Dbg_erase_journals trap - EXIT } bashdb-4.2-0.8/lib/frame.sh0000644000175000017500000001440111565104723012226 00000000000000# -*- shell-script -*- # Call Stack routines # # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. #================ VARIABLE INITIALIZATIONS ====================# # _Dbg_stack_size: the number of entries on the call stack at the time # the hook was entered. Note that bash updates the stack inside the # debugger so it is important to save this value on entry. Also # note that the most recent entries are pushed or at position 0. # Thus to get position 0 of the debugged program we need to ignore leading # any debugger frames. typeset -i _Dbg_stack_size # Where are we in stack? This can be changed by "up", "down" or # "frame" commands. 0 means the most recent stack frame with respect # to the debugged program and _Dbg_stack_size is the # least-recent. Note that inside the debugger the stack is still # updated. On debugger entry, the value is set to 0 typeset -i _Dbg_stack_pos # Save the last-entered frame for to determine stopping when # "set force" or step+ is in effect. typeset _Dbg_frame_last_filename='' typeset -i _Dbg_frame_last_lineno=0 #======================== FUNCTIONS ============================# function _Dbg_frame_adjust { (($# != 2)) && return 255 typeset -i count=$1 typeset -i signum=$2 typeset -i retval _Dbg_frame_int_setup $count || return 2 typeset -i pos if (( signum==0 )) ; then if (( count < 0 )) ; then ((pos = _Dbg_stack_size + count - 1)) else ((pos = count)) fi else ((pos=_Dbg_stack_pos+(count*signum))) fi if (( pos < 0 )) ; then _Dbg_errmsg 'Would be beyond bottom-most (most recent) entry.' return 1 elif (( pos >= _Dbg_stack_size - 1 )) ; then _Dbg_errmsg 'Would be beyond top-most (least recent) entry.' return 1 fi typeset -i adjusted_pos adjusted_pos=$(_Dbg_frame_adjusted_pos $pos) _Dbg_stack_pos=$pos ## DEBUG ## typeset -p pos ## typeset -p adjusted_pos ## typeset -p BASH_LINENO ## typeset -p BASH_SOURCE _Dbg_listline="${BASH_LINENO[adjusted_pos-1]}" _Dbg_frame_last_filename="${BASH_SOURCE[adjusted_pos]}" typeset filename; filename="$(_Dbg_file_canonic "$_Dbg_frame_last_filename")" _Dbg_frame_print '->' $_Dbg_stack_pos '' "$filename" $_Dbg_listline '' _Dbg_print_location_and_command "$_Dbg_listline" return 0 } # Tests for a signed integer parameter and set global retval # if everything is okay. Retval is set to 1 on error _Dbg_frame_int_setup() { _Dbg_not_running && return 1 eval "$_seteglob" if [[ $1 != '' && $1 != $_Dbg_signed_int_pat ]] ; then _Dbg_errmsg "Bad integer parameter: $1" eval "$_resteglob" return 1 fi eval "$_resteglob" return 0 } # Turn position $1 which uses 0 to represent the most-recent stack entry # into which may have additional internal debugger frames pushed on. function _Dbg_frame_adjusted_pos { if (($# != 1)) ; then echo -n '-1' return 1 fi typeset -i pos ((pos=${#FUNCNAME[@]} - _Dbg_stack_size + $1)) echo -n $pos return 0 } # Creates a parameter string for return in non-local variable # _Dbg_parm_str. This is obtained from BASH_ARGC and BASH_ARGV. On # entry, _Dbg_next_argc, and _Dbg_next_argv should be set. These # variables and _Dbg_parm_str are updated on exit. _Dbg_next_argc is # and integer index into BASH_ARGC and _Dbg_next_argv is and index # into BASH_ARGV. On return _Dbg_frame_fn_param_str() { (($# == 0)) || return 1 _Dbg_is_int "$_Dbg_next_argc" || return 2 _Dbg_is_int "$_Dbg_next_argv" || return 3 # add 1 to argument count to compensate for this call (of zero # parameters) and at the same time we update _Dbg_next_argc for the # next call. # ((_Dbg_next_argc++)) typeset -i arg_count=BASH_ARGC[$_Dbg_next_argc] if ((arg_count == 0)) ; then _Dbg_parm_str='' else typeset -i i _Dbg_parm_str="\"${BASH_ARGV[$_Dbg_next_argv+arg_count-1]}\"" for (( i=1; i <= arg_count-1; i++ )) ; do _Dbg_parm_str+=", \"${BASH_ARGV[$_Dbg_next_argv+arg_count-i-1]}\"" done ((_Dbg_next_argv+=arg_count)) fi return 0 } _Dbg_frame_set_fn_param() { (($# == 1)) || return 1 typeset -i skip_count=$1 # Set to ignore this call in computation _Dbg_next_argc=1 _Dbg_next_argv=1 typeset -i i for (( i=1; i <= skip_count; i++ )) ; do typeset -i arg_count=${BASH_ARGC[$i]} ((_Dbg_next_argv+=arg_count)) done # After this function returns argv will be one greater. So adjust # for that now. ((_Dbg_next_argc=skip_count)) ((_Dbg_next_argv--)) ## Debug: ## typeset -p BASH_ARGC ## typeset -p BASH_ARGV ## typeset -p FUNCNAME ## typeset -p _Dbg_next_argc ## typeset -p _Dbg_next_argv } # Print "##" or "->" depending on whether or not $1 (POS) is a number # between 0 and _Dbg_stack_size-1. For POS, 0 is the top-most # (newest) entry. For _Dbg_stack_pos, 0 is the bottom-most entry. # 0 is returnd on success, nonzero on failure. function _Dbg_frame_prefix { typeset prefix='??' typeset -i rc=0 if (($# == 1)) ; then typeset -i pos=$1 if ((pos < 0)) ; then rc=2 elif ((pos >= _Dbg_stack_size)) ; then rc=3 elif (( pos == _Dbg_stack_pos )) ; then prefix='->' else prefix='##' fi else rc=1 fi echo -n $prefix return $rc } # Print one line in a call stack function _Dbg_frame_print { typeset prefix=$1 typeset -i pos=$2 typeset fn=$3 typeset filename="$4" typeset -i line=$5 typeset args="$6" typeset callstr=$fn [[ -n $args ]] && callstr="$callstr($args)" _Dbg_msg "$prefix$pos in file \`$filename' at line $line" } bashdb-4.2-0.8/lib/processor.sh0000644000175000017500000003065111565104723013160 00000000000000# -*- shell-script -*- # dbg-processor.sh - Top-level debugger commands # # Copyright (C) 2008, 2009, 2010, 2011 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # Are we inside the middle of a "skip" command? typeset -i _Dbg_inside_skip=0 # Hooks that get run on each command loop typeset -A _Dbg_cmdloop_hooks _Dbg_cmdloop_hooks['display']='_Dbg_eval_all_display' # Can be bash's "read" builtin or a command-completing "read" builtin # provided by this debugger. typeset _Dbg_read_fn; _Dbg_read_fn='read' # A variable holding a space is set so it can be used in a "set prompt" command # ("read" in the main command loop will remove a trailing space so we need # another way to allow a user to enter spaces in the prompt.) typeset _Dbg_space=' ' # Should we allow editing of debugger commands? # The value should either be '-e' or ''. And if it is # on, the edit style indicates what style edit keystrokes. typeset _Dbg_edit='-e' typeset _Dbg_edit_style='emacs' # or vi set -o $_Dbg_edit_style # What do we use for a debugger prompt? Technically we don't need to # use the above $bashdb_space in the assignment below, but we put it # in to suggest to a user that this is how one gets a spaces into the # prompt. typeset _Dbg_prompt_str='$_Dbg_debugger_name${_Dbg_less}${#_Dbg_history[@]}${_Dbg_greater}$_Dbg_space' # The arguments in the last "x" command. typeset _Dbg_last_x_args='' # The canonical name of last command run. typeset _Dbg_last_cmd='' # A list of debugger command input-file descriptors. # Duplicate standard input typeset -i _Dbg_fdi ; exec {_Dbg_fdi}<&0 typeset -i _Dbg_fd_last=0 # keep a list of source'd command files. If the entry is "" then we are # interactive. typeset -a _Dbg_cmdfile; _Dbg_cmdfile=('') # A list of debugger command input-file descriptors. typeset -a _Dbg_fd; _Dbg_fd=($_Dbg_fdi) typeset _Dbg_prompt_output # ===================== FUNCTIONS ======================================= # The main debugger command reading loop. # # Note: We have to be careful here in naming "local" variables. In contrast # to other places in the debugger, because of the read/eval loop, they are # in fact seen by those using the debugger. So in contrast to other "local"s # in the debugger, we prefer to preface these with _Dbg_. function _Dbg_process_commands { # THIS SHOULD BE DONE IN dbg-sig.sh, but there's a bug in BASH in # trying to change "trap RETURN" inside a "trap RETURN" handler.... # Turn off return trapping. Not strictly necessary, since it *should* be # covered by the _Dbg_ test below if we've named functions correctly. # However turning off the RETURN trap should reduce unnecessary # trap RETURN calls. _Dbg_inside_skip=0 _Dbg_step_ignore=-1 # Nuke any prior step ignore counts _Dbg_continue_rc=-1 # Don't continue exectuion unless told to do so. _Dbg_write_journal "_Dbg_step_ignore=$_Dbg_step_ignore" typeset key # Evaluate all hooks for key in ${!_Dbg_cmdloop_hooks[@]} ; do ${_Dbg_cmdloop_hooks[$key]} done # Loop over all pending open input file descriptors while (( _Dbg_fd_last > 0)) ; do # Set up prompt to show shell and subshell levels. typeset _Dbg_greater='' typeset _Dbg_less='' typeset result # Used by copies to return a value. if _Dbg_copies '>' $_Dbg_DEBUGGER_LEVEL ; then _Dbg_greater=$result _Dbg_less=${result//>/<} fi if _Dbg_copies ')' $BASH_SUBSHELL ; then _Dbg_greater="${result}${_Dbg_greater}" _Dbg_less="${_Dbg_less}${result//)/(}" fi # Loop over debugger commands. But before reading a debugger # command, we need to make sure IFS is set to spaces to ensure our # two variables (command name and rest of the arguments) are set # correctly. Saving the IFS and setting it to the "normal" value # of space should be done in the DEBUG signal handler entry. # Also, we need to make sure the prompt output is # redirected to the debugger terminal. Both of these things may # have been changed by the debugged program for its own # purposes. Furthermore, were we *not* to redirect our stderr # below, we may mess up what the debugged program expects to see # in in stderr by adding our debugger prompt. # if no tty, no prompt _Dbg_prompt_output=${_Dbg_tty:-/dev/null} eval "local _Dbg_prompt=$_Dbg_prompt_str" _Dbg_preloop typeset _Dbg_cmd typeset args typeset rc while : ; do set -o history _Dbg_input_desc=${_Dbg_fd[_Dbg_fd_last]} if ((_Dbg_set_read_completion)) ; then _Dbg_read_fn='readc' else _Dbg_read_fn='read' fi if ! $_Dbg_read_fn $_Dbg_edit -p "$_Dbg_prompt" _Dbg_cmd args \ <&$_Dbg_input_desc 2>>$_Dbg_prompt_output ; then set +o history break fi # FIXME: until I figure out to fix builtin readc, this happens # on command completion: if [[ $_Dbg_cmd =~ ' ' && -z $args ]] ; then typeset -a ary; IFS=' ' ary=( $_Dbg_cmd ) _Dbg_cmd=${ary[0]} unset ary[0] args="${ary[@]}" fi set +o history if (( _Dbg_brkpt_commands_defining )) ; then case $_Dbg_cmd in silent ) _Dbg_brkpt_commands_silent[$_Dbg_brkpt_commands_current]=1 continue ;; end ) _Dbg_brkpt_commands_defining=0 #### ??? TESTING ## local -i cur=$_Dbg_brkpt_commands_current ## local -i start=${_Dbg_brkpt_commands_start[$cur]} ## local -i end=${_Dbg_brkpt_commands_end[$cur]} ## local -i i ## echo "++ brkpt: $cur, start: $start, end: $end " ## for (( i=start; (( i < end )) ; i++ )) ; do ## echo ${_Dbg_brkpt_commands[$i]} ## done eval "_Dbg_prompt=$_Dbg_prompt_str" continue ;; *) _Dbg_brkpt_commands[${#_Dbg_brkpt_commands[@]}]="$_Dbg_cmd $args" (( _Dbg_brkpt_commands_end[$_Dbg_brkpt_commands_current]++ )) continue ;; esac rc=$? else _Dbg_onecmd "$_Dbg_cmd" "$args" _Dbg_postcmd fi ((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc if (( _Dbg_brkpt_commands_defining )) ; then _Dbg_prompt='>' else eval "_Dbg_prompt=$_Dbg_prompt_str" fi done # while read $_Dbg_edit -p ... unset _Dbg_fd[_Dbg_fd_last--] done # Loop over all open pending file descriptors # EOF hit. Same as quit without arguments _Dbg_msg '' # Cause since EOF may not have put in. _Dbg_do_quit } # Run a debugger command "annotating" the output _Dbg_annotation() { typeset label="$1" shift _Dbg_do_print "$label" $* _Dbg_do_print '' } # Run a single command # Parameters: _Dbg_cmd and args # _Dbg_onecmd() { typeset full_cmd=$@ typeset _Dbg_orig_cmd="$1" typeset expanded_alias; _Dbg_alias_expand "$_Dbg_orig_cmd" typeset _Dbg_cmd="$expanded_alias" shift typeset _Dbg_args="$@" # Set default next, step or skip command if [[ -z $_Dbg_cmd ]]; then _Dbg_cmd=$_Dbg_last_next_step_cmd _Dbg_args=$_Dbg_last_next_step_args full_cmd="$_Dbg_cmd $_Dbg_args" fi # If "set trace-commands" is "on", echo the the command if [[ $_Dbg_set_trace_commands == 'on' ]] ; then _Dbg_msg "+$full_cmd" fi local dq_cmd=$(_Dbg_esc_dq "$_Dbg_cmd") local dq_args=$(_Dbg_esc_dq "$_Dbg_args") # _Dbg_write_journal_eval doesn't work here. Don't really understand # how to get it to work. So we do this in two steps. _Dbg_write_journal \ "_Dbg_history[${#_Dbg_history[@]}]=\"$dq_cmd $dq_args\"" _Dbg_history[${#_Dbg_history[@]}]="$_Dbg_cmd $_Dbg_args" _Dbg_hi=${#_Dbg_history[@]} history -s -- "$full_cmd" typeset -i _Dbg_redo=1 while (( _Dbg_redo )) ; do _Dbg_redo=0 [[ -z $_Dbg_cmd ]] && _Dbg_cmd=$_Dbg_last_cmd if [[ -n $_Dbg_cmd ]] ; then typeset -i found=0 typeset found_cmd if [[ -n ${_Dbg_debugger_commands[$_Dbg_cmd]} ]] ; then found=1 found_cmd=$_Dbg_cmd else # Look for a unique abbreviation typeset -i count=0 typeset list; list="${!_Dbg_debugger_commands[@]}" for try in $list ; do if [[ $try =~ ^$_Dbg_cmd ]] ; then found_cmd=$try ((count++)) fi done ((found=(count==1))) fi if ((found)); then ${_Dbg_debugger_commands[$found_cmd]} $_Dbg_args IFS=$_Dbg_space_IFS; eval "_Dbg_prompt=$_Dbg_prompt_str" ((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc continue fi fi case $_Dbg_cmd in # Comment line [#]* ) _Dbg_history_remove_item _Dbg_last_cmd='#' ;; # list current line . ) _Dbg_list $_Dbg_frame_last_filename $_Dbg_frame_last_lineno 1 _Dbg_last_cmd='list' ;; # Search forwards for pattern /* ) _Dbg_do_search $_Dbg_cmd _Dbg_last_cmd='search' ;; # Search backwards for pattern [?]* ) _Dbg_do_reverse $_Dbg_cmd _Dbg_last_cmd="reverse" ;; # Change Directory cd ) # Allow for tilde expansion. We also allow expansion of # variables like $HOME which gdb doesn't allow. That's life. local cd_command="cd $_Dbg_args" eval $cd_command _Dbg_do_pwd _Dbg_last_cmd='cd' ;; # complete comp | compl | comple | complet | complete ) _Dbg_do_complete $_Dbg_args _Dbg_last_cmd='complete' ;; # Set up a script for debugging into. debug ) _Dbg_do_debug $_Dbg_args # Skip over the execute statement which presumably we ran above. _Dbg_do_next_skip 'skip' 1 IFS="$_Dbg_old_IFS"; return 1 _Dbg_last_cmd='debug' ;; # Delete all breakpoints. D | deletea | deleteal | deleteall ) _Dbg_clear_all_brkpt _Dbg_last_cmd='deleteall' ;; # return from function/source without finishing executions return ) ;; # run shell command. Has to come before ! below. shell | '!!' ) eval $_Dbg_args ;; # Send signal to process si | sig | sign | signa | signal ) _Dbg_do_signal $_Dbg_args _Dbg_last_cmd='signal' ;; # single-step 'step+' | 'step-' ) _Dbg_do_step "$_Dbg_cmd" $_Dbg_args return 0 ;; # # toggle execution trace # to | tog | togg | toggl | toggle ) # _Dbg_do_trace # ;; # List all breakpoints and actions. L ) _Dbg_do_list_brkpt _Dbg_list_watch _Dbg_list_action ;; # Remove all actions A ) _Dbg_do_clear_all_actions $_Dbg_args ;; # List debugger command history H ) _Dbg_history_remove_item _Dbg_do_history_list $_Dbg_args ;; # S List subroutine names S ) _Dbg_do_list_functions $_Dbg_args ;; # Dump variables V ) _Dbg_do_info_variables "$_Dbg_args" ;; # Has to come after !! of "shell" listed above # Run an item from the command history \!* | history ) _Dbg_do_history $_Dbg_args ;; '' ) # Redo last_cmd if [[ -n $_Dbg_last_cmd ]] ; then _Dbg_cmd=$_Dbg_last_cmd _Dbg_redo=1 fi ;; * ) if (( _Dbg_set_autoeval )) ; then _Dbg_do_eval $_Dbg_cmd $_Dbg_args else _Dbg_undefined_cmd "$_Dbg_cmd" _Dbg_history_remove_item # local -a last_history=(`history 1`) # history -d ${last_history[0]} fi ;; esac done # while (( $_Dbg_redo )) IFS=$_Dbg_space_IFS; eval "_Dbg_prompt=$_Dbg_prompt_str" } _Dbg_preloop() { if ((_Dbg_set_annotate)) ; then _Dbg_annotation 'breakpoints' _Dbg_do_info breakpoints # _Dbg_annotation 'locals' _Dbg_do_backtrace 3 _Dbg_annotation 'stack' _Dbg_do_backtrace 3 fi } _Dbg_postcmd() { if ((_Dbg_set_annotate)) ; then case $_Dbg_last_cmd in break | tbreak | disable | enable | condition | clear | delete ) _Dbg_annotation 'breakpoints' _Dbg_do_info breakpoints ;; up | down | frame ) _Dbg_annotation 'stack' _Dbg_do_backtrace 3 ;; * ) esac fi } bashdb-4.2-0.8/lib/sig.sh0000644000175000017500000002102111561306417011712 00000000000000# -*- shell-script -*- # Signal handling routines # # Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2010, 2011 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # ==================== VARIABLES ======================================= # The "set" options in effect ($-) before debugger was invoked. typeset _Dbg_old_setopts # Place to save debugged program's exit handler, if any. typeset _Dbg_old_EXIT_handler='' typeset -i _Dbg_QUIT_ON_QUIT=0 # Return code that debugged program reports typeset -i _Dbg_program_exit_code=0 ############################################################ ## Signal arrays: These are indexed by the signal number. ## ############################################################ # Should we print that a signal was intercepted? # Each entry is "print" or "noprint" or null. typeset -a _Dbg_sig_print; _Dbg_sig_print=() # Should we reentry the debugger command loop on receiving the signal? # Each entry is "stop" or "nostop" or null. typeset -a _Dbg_sig_stop; _Dbg_sig_stop=() # Should we show a traceback on receiving the signal? # Each entry is "stack" or "nostack" or null. typeset -a _Dbg_sig_show_stack; _Dbg_sig_show_stack=() # Should pass the signal to the user program?? # Each entry is the trap handler with some variables substituted. typeset -a _Dbg_sig_passthrough; _Dbg_sig_passthrough=() # Should pass the signal to the user program?? # Each entry is the trap handler with some variables substituted. typeset -i _Dbg_return_level=0 # Place to save values of $1, $2, etc. typeset -a _Dbg_arg; _Dbg_arg=() # Save value of handler variable _Dbg_old_$sig _Dbg_save_handler() { typeset -r sig=$1 typeset old_handler='' old_handler_test=$(trap -p $sig) if [[ -n $old_handler ]] ; then typeset -a old_hand_a old_hand_a=($old_handler) old_handler=$(_Dbg_subst_handler_var ${old_hand_a[2]}) typeset -r decl_cmd="typeset -r _Dbg_old_${sig}_handler='$old_handler'" eval $decl_cmd fi } # Adjust handler variables to take into account the fact that when we # call the handler we will have added another call before the user's # handler. _Dbg_subst_handler_var() { typeset -i i typeset result='' for arg in $* ; do case $arg in '$LINENO' ) arg='${BASH_LINENO[0]}' ;; '${BASH_SOURCE[0]}' ) arg='${BASH_SOURCE[1]}' ;; '${FUNCNAME[0]}' ) arg='${FUNCNAME[1]}' ;; '${BASH_LINENO[0]}' ) arg='${BASH_LINENO[1]}' ;; esac if [[ $result == '' ]] ; then result=$arg else result="$result $arg" fi done echo $result } # Debugger exit handler. Don't really exit - but go back the debugger # command loop _Dbg_exit_handler() { # Consider putting the following line(s) in a routine. # Ditto for the restore environment typeset -i _Dbg_debugged_exit_code=$? # Turn off line and variable trace listing; allow unset parameter expansion. set +x +v +u if [[ ${_Dbg_sig_print[0]} == "print" ]] ; then # Note: use the same message that gdb does for this. _Dbg_msg "Program received signal EXIT (0)..." if [[ ${_Dbg_sig_show_stack[0]} == "showstack" ]] ; then _Dbg_do_backtrace 0 fi fi if [[ $_Dbg_old_EXIT_handler != '' ]] ; then eval $_Dbg_old_EXIT_handler fi # If we've set the QUIT signal handler not to stop, or we've in the # middle of leaving so many (subshell) levels or we have set to # leave quietly on termination, then do it! if [[ ${_Dbg_sig_stop[0]} != "stop" ]] \ || (( _Dbg_QUIT_LEVELS != 0 )) \ || (( _Dbg_QUIT_ON_QUIT )) ; then _Dbg_do_quit # We don't return from here. fi # We've tested for all the quitting conditions above. # Even though this is an exit handler, don't exit! typeset term_msg="normally" if [[ $_Dbg_debugged_exit_code != 0 ]] ; then term_msg="with code $_Dbg_debugged_exit_code" fi # If we tried to exit from inside a subshell, we only want to enter # the command loop if don't have any pending subshells. if (( BASH_SUBSHELL == 0 )) ; then _Dbg_msg \ "Debugged program terminated $term_msg. Use q to quit or R to restart." _Dbg_running=0 while : ; do _Dbg_process_commands done fi } # Generic signal handler. We consult global array _Dbg_sig_* for how # to handle this signal. # Since the command loop may be called we need to be careful about # using variable names that would be exposed to the user. _Dbg_sig_handler() { # Consider putting the following line(s) in a routine. # Ditto for the restore environment typeset -i _Dbg_debugged_exit_code=$? _Dbg_old_set_opts=$- # Turn off line and variable trace listing if were not in our own debug # mode, and set our own PS4 for debugging inside the debugger (( !_Dbg_set_debug )) && set +x +v +u shopt -s extdebug # This is the signal number. E.g. 15 is SIGTERM typeset -r -i _Dbg_signum=$1 if [[ ${_Dbg_sig_print[$_Dbg_signum]} == "print" ]] || \ [[ ${_Dbg_sig_stop[$_Dbg_signum]} == "stop" ]] ; then typeset -r name=$(_Dbg_signum2name $_Dbg_signum) # Note: use the same message that gdb does for this. _Dbg_msg "Program received signal $name ($_Dbg_signum)..." if [[ ${_Dbg_sig_show_stack[$_Dbg_signum]} == "showstack" ]] ; then _Dbg_stack_pos=0 ((_Dbg_stack_size = ${#FUNCNAME[@]})) _Dbg_do_backtrace fi fi if [[ ${_Dbg_sig_stop[$_Dbg_signum]} == "stop" ]] ; then ### The below duplicates what is above in _Dbg_debug_trap handler ### Should put common stuff into a function. shift # signum _Dbg_save_args "$@" _Dbg_set_debugger_entry _Dbg_hook_enter_debugger 'on receiving a signal' 'noprint' return $_Dbg_continue_rc elif (( _Dbg_sig_old_handler[_Dbg_signum] )) ; then eval ${_Dbg_sig_old_handler[$_Dbg_signum]} fi _Dbg_set_to_return_from_debugger 1 return $_Dbg_debugged_exit_code } _Dbg_err_handler() { if [[ $_Dbg_old_ERR_handler != '' ]] ; then eval $_Dbg_old_ERR_handler fi _Dbg_msg "Error occured at ${BASH_SOURCE[1]}:${BASH_LINENO[1]}" _Dbg_process_commands } # Echo the name for a given signal number $1. The resulting name # is in _Dbg_return _Dbg_signum2name() { typeset -i -r signum=$1; builtin kill -l $signum 2>/dev/null return $? } # Return the signal number for a given signal name $1. The resulting number # is in _Dbg_return _Dbg_name2signum() { typeset -r signame=$1; builtin kill -l $signame 2>/dev/null return $? } _Dbg_subexit_handler() { # Read in the journal to pick up variable settings that might have # been left from a subshell. if [[ ${FUNCNAME[1]} == _Dbg_* ]] && (( !_Dbg_set_debug )); then return 0 fi _Dbg_source_journal if (( _Dbg_QUIT_LEVELS > 0 )) ; then _Dbg_do_quit $_Dbg_debugged_exit_code fi } # Set up generic trap handler. Arguments are: # NAME print showstack stop passthrough _Dbg_init_trap() { typeset -r name=$1 typeset -i -r signum=$(_Dbg_name2signum $name) _Dbg_sig_print[$signum]=$2; _Dbg_sig_show_stack[$signum]=$3; _Dbg_sig_stop[$signum]=$4; # Work out passthrough later... # if [[ $5 == "pass*" ]] ; then # get existing trap from env. # _Dbg_sig_show_passthrough[$signum]=....; # if (( signum == 0 )) ; then trap '_Dbg_exit_handler "$BASH_COMMAND"' EXIT else typeset trap_cmd="trap '_Dbg_sig_handler $signum \"\$BASH_COMMAND\" \"\$@\"' $name" eval $trap_cmd fi } _Dbg_init_default_traps() { _Dbg_init_trap EXIT "noprint" "nostack" "stop" _Dbg_init_trap ILL "print" "showstack" "stop" _Dbg_init_trap INT "print" "showstack" "stop" _Dbg_init_trap QUIT "print" "showstack" "stop" _Dbg_init_trap TERM "print" "showstack" "stop" _Dbg_init_trap TRAP "print" "showstack" "stop" } bashdb-4.2-0.8/lib/hist.sh0000644000175000017500000001001711562432171012100 00000000000000# -*- shell-script -*- # hist.sh - Bourne Again Shell Debugger history routines # # Copyright (C) 2002, 2003, 2006, 2007, 2008, 2011 Rocky Bernstein # # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with This program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. typeset -i _Dbg_hi_last_stop=0 typeset -i _Dbg_hi=0 # Current next history entry to store into. typeset -a _Dbg_history; _Dbg_history=() typeset -i _Dbg_set_history=1 typeset -i _Dbg_history_length=${HISTSIZE:-256} # gdb's default value typeset _Dbg_histfile=${HOME:-.}/.kshdb_hist # Set to rerun history item, or print history if command is of the form # !n:p. If command is "history" then $1 is number of history item. # the history command index to run is returned or $_Dbg_hi if # there's nothing to run. # Return value in $history_num _Dbg_history_parse() { history_num=$1 ((history_num < 0)) && ((history_num=${#_Dbg_history[@]}-1+$1)) _Dbg_hi=${#_Dbg_history[@]} [[ -z $history_num ]] && let history_num=$_Dbg_hi-1 if [[ $_Dbg_cmd == h* ]] ; then if [[ $history_num != $int_pat ]] ; then if [[ $history_num == -$int_pat ]] ; then history_num=$_Dbg_hi+$history_num else _Dbg_msg "Invalid history number skipped: $history_num" history_num=-1 fi fi else # Handle ! form. May need to parse number out number and modifier # case $_Dbg_cmd in # \!\-${int_pat}:p ) # typeset -a word1 # word1=($(_Dbg_split '!' $_Dbg_cmd)) # local -a word2 # word2=($(_Dbg_split ':' ${word1[0]})) # typeset -i num=_Dbg_hi+${word2[0]} # _Dbg_do_history_list $num $num # history_num=-1 # ;; # [!]${int_pat}:p ) # local -a word1 # word1=($(_Dbg_split '!' $_Dbg_cmd)) # local -a word2 # word2=($(_Dbg_split ':' ${word1[0]})) # _Dbg_do_history_list ${word2[0]} ${word2[0]} # history_num=-1 # ;; # \!\-$int_pat ) # local -a word # word=($(_Dbg_split '!' $_Dbg_cmd)) # history_num=$_Dbg_hi+${word[0]} # ;; # \!$int_pat ) # local -a word # word=($(_Dbg_split '!' $_Dbg_cmd)) # history_num=${word[0]} # ;; # '!' ) # if [[ $history_num != $int_pat ]] ; then # if [[ $history_num == -$int_pat ]] ; then # history_num=$_Dbg_hi+$history_num # else # _Dbg_msg "Invalid history number skipped: $history_num" # history_num=-1 # fi # fi # ;; # * ) # _Dbg_msg "Invalid history number skipped: $_Dbg_cmd" # history_num=-1 # esac : fi } _Dbg_history_read() { if [[ -r $_Dbg_histfile ]] ; then history -r $_Dbg_histfile typeset -a last_history; last_history=($(history 1)) typeset -i max_history=${last_history[0]} if (( max_history > _Dbg_history_length )) ; then max_history=$_Dbg_history_length fi local OLD_HISTTIMEFORMAT=${HISTTIMEFORMAT} local hist HISTTIMEFORMAT='' local -i i for (( i=1; (( i <= max_history )) ; i++ )) ; do last_history=($(history $i)) hist=${last_history}[1] # _Dbg_history[$i]=$hist done HISTTIMEFORMAT=${OLD_HISTTIMEFORMAT} fi } # Save history file _Dbg_history_write() { (( _Dbg_history_length > 0 && _Dbg_set_history)) \ && history -w $_Dbg_histfile } # Remove the last command from the history list. _Dbg_history_remove_item() { _Dbg_hi=${#_Dbg_history[@]}-1 unset _Dbg_history[$_Dbg_hi] } # _Dbg_history_read bashdb-4.2-0.8/lib/fns.sh0000644000175000017500000001564311563752733011743 00000000000000# -*- shell-script -*- # fns.sh - Debugger Utility Functions # # Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. typeset -a _Dbg_yn; _Dbg_yn=("n" "y") # Return $2 copies of $1. If successful, $? is 0 and the return value # is in result. Otherwise $? is 1 and result '' function _Dbg_copies { result='' (( $# < 2 )) && return 1 typeset -r string="$1" typeset -i count=$2 || return 2 (( count > 0 )) || return 3 builtin printf -v result "%${count}s" ' ' || return 3 result=${result// /$string} return 0 } # _Dbg_defined returns 0 if $1 is a defined variable or nonzero otherwise. _Dbg_defined() { (( 0 == $# )) && return 1 typeset -p "$1" &> /dev/null } # Add escapes to a string $1 so that when it is read back via "$1" # it is the same as $1. function _Dbg_esc_dq { builtin printf "%q\n" "$1" } # We go through the array indirection below because bash (but not ksh) # gives syntax errors when this is put in place. typeset -a _Dbg_eval_re; _Dbg_eval_re=( '^[ \t]*(if|elif)[ \t]+([^;]*)((;[ \t]*then?)?|$)' '^[ \t]*return[ \t]+(.*)$' '^[ \t]*while[ \t]+([^;]*)((;[ \t]*do?)?|$)' '^[ \t]*[A-Za-z_][A-Za-z_0-9[]*[]-+]?=(.*$)' ) # Removes "[el]if" .. "; then" or "while" .. "; do" or "return .." # leaving resumably the expression part. This function is called by # the eval? command where we want to evaluate the expression part in # a source line of code _Dbg_eval_extract_condition() { orig="$1" if [[ $orig =~ ${_Dbg_eval_re[0]} ]] ; then extracted=${BASH_REMATCH[2]} elif [[ $orig =~ ${_Dbg_eval_re[1]} ]] ; then extracted="echo ${BASH_REMATCH[1]}" elif [[ $orig =~ ${_Dbg_eval_re[2]} ]] ; then extracted=${BASH_REMATCH[1]} elif [[ $orig =~ ${_Dbg_eval_re[3]} ]] ; then extracted="echo ${BASH_REMATCH[1]}" else extracted=$orig fi } # Print "on" or "off" depending on whether $1 is true (0) or false # (nonzero). function _Dbg_onoff { typeset onoff='off.' (( $1 != 0 )) && onoff='on.' builtin echo $onoff } # Set $? to $1 if supplied or the saved entry value of $?. function _Dbg_set_dol_q { return ${1:-$_Dbg_debugged_exit_code} } # Split $2 using $1 as the split character. We accomplish this by # temporarily resetting the variable IFS (input field separator). # # Example: # typeset -a a=($(_Dbg_split ':' "file:line")) # a[0] will have file and a{1] will have line. function _Dbg_split { typeset old_IFS=$IFS typeset new_ifs=${1:-' '} shift typeset -r text="$*" typeset -a array IFS="$new_ifs" array=( $text ) echo ${array[@]} IFS=$old_IFS } # _get_function echoes a list of all of the functions. # if $1 is nonzero, system functions, i.e. those whose name starts with # an underscore (_), are included in the search. # FIXME add parameter search pattern. _Dbg_get_functions() { typeset -i include_system=${1:-0} typeset pat=${2:-.*} typeset -a fns_a fns_a=( $(declare -F) ) typeset -a ret_fns=() typeset -i i typeset -i invert=0; if [[ $pat == !* ]] ; then # Remove leading ! pat=#{$pat#!} invert=1 fi # Iterate skipping over consecutive single tokens "declare" and "-F" for (( i=2; (( i < ${#fns_a[@]} )) ; i += 3 )) ; do typeset fn="${fns_a[$i]}" [[ $fn == _* ]] && (( ! include_system )) && continue if [[ $fn =~ $pat ]] ; then [[ $invert == 0 ]] && ret_fns[${#ret_fns[@]}]=$fn else [[ $invert != 0 ]] && ret_fns[${#ret_fns[@]}]=$fn fi done echo ${ret_fns[@]} } # _Dbg_is_function returns 0 if $1 is a defined function or nonzero otherwise. # if $2 is nonzero, system functions, i.e. those whose name starts with # an underscore (_), are included in the search. _Dbg_is_function() { (( 0 == $# )) && return 1 typeset needed_fn=$1 typeset -i include_system=${2:-0} [[ ${needed_fn:0:1} == '_' ]] && ((!include_system)) && { return 1 } declare -F $needed_fn >/dev/null 2>&1 return $? } # Return 0 if set -x tracing is on _Dbg_is_traced() { # Is "x" in set options? if [[ $- == *x* ]] ; then return 0 else return 1 fi } # Common routine for setup of commands that take a single # linespec argument. We assume the following variables # which we store into: # filename, line_number, full_filename function _Dbg_linespec_setup { typeset linespec=${1:-''} if [[ -z $linespec ]] ; then _Dbg_errmsg "Invalid line specification, null given" fi typeset -a word eval "word=($(_Dbg_parse_linespec $linespec))" if [[ ${#word[@]} == 0 ]] ; then _Dbg_errmsg "Invalid line specification: $linespec" return fi filename="${word[2]}" typeset -ri is_function=${word[1]} line_number=${word[0]} full_filename=$(_Dbg_is_file "$filename") if (( is_function )) ; then if [[ -z $full_filename ]] ; then _Dbg_readin "$filename" full_filename=$(_Dbg_is_file "$filename") fi fi } # Parse linespec in $1 which should be one of # int # file:line # function-num # Return triple (line, is-function?, filename,) # We return the filename last since that can have embedded blanks. function _Dbg_parse_linespec { typeset linespec=$1 eval "$_seteglob" case "$linespec" in # line number only - use _Dbg_frame_last_filename for filename $int_pat ) echo "$linespec 0 \"$_Dbg_frame_last_filename\"" ;; # file:line [^:][^:]*[:]$int_pat ) # Split the POSIX way typeset line_word=${linespec##*:} typeset file_word=${linespec%${line_word}} file_word=${file_word%?} echo "$line_word 0 \"$file_word\"" ;; # Function name or error * ) if _Dbg_is_function $linespec $_Dbg_set_debug ; then local -a word=( $(declare -F $linespec) ) if [[ 0 == $? && ${#word[@]} > 2 ]]; then builtin echo "${word[1]} 1 ${word[2]}" else builtin echo '' fi else builtin echo '' fi ;; esac } # usage _Dbg_set_ftrace [-u] funcname [funcname...] # Sets or unsets a function for stopping by setting # the -t or +t property to the function declaration. # function _Dbg_set_ftrace { typeset opt=-t tmsg="enabled" func if [[ $1 == -u ]]; then opt=+t tmsg="disabled" shift fi for func; do declare -f $opt $func # _Dbg_msg "Tracing $tmsg for function $func" done } bashdb-4.2-0.8/lib/action.sh0000644000175000017500000001331411535300364012407 00000000000000# -*- shell-script -*- # # Copyright (C) 2010, 2011 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. #================ VARIABLE INITIALIZATIONS ====================# # Number of actions. typeset -i _Dbg_action_count=0 # 1/0 if enabled or not typeset -a _Dbg_action_enable; _Dbg_action_enable=() # filename of action $i typeset -a _Dbg_action_file; _Dbg_action_file=() # Line number of action $i typeset -a _Dbg_action_line; _Dbg_action_line=() # statement to run when line is hit typeset -a _Dbg_action_stmt; _Dbg_action_stmt=() # Needed because we can't figure out what the max index is and arrays # can be sparse. typeset -i _Dbg_action_max=0 # Maps a resolved filename to a list of action entries. typeset -A _Dbg_action_file2action; _Dbg_action_file2action=() # Maps a resolved filename to a list of action line numbers in that file typeset -A _Dbg_action_file2linenos; _Dbg_action_file2linenos=() # Note: we loop over possibly sparse arrays with _Dbg_brkpt_max by adding one # and testing for an entry. Could add yet another array to list only # used indices. Zsh is kind of primitive. #========================= FUNCTIONS ============================# function _Dbg_save_actions { typeset -p _Dbg_action_line >> $_Dbg_statefile typeset -p _Dbg_action_file >> $_Dbg_statefile typeset -p _Dbg_action_enable >> $_Dbg_statefile typeset -p _Dbg_action_stmt >> $_Dbg_statefile typeset -p _Dbg_action_max >> $_Dbg_statefile typeset -p _Dbg_action_file2linenos >> $_Dbg_statefile typeset -p _Dbg_action_file2action >> $_Dbg_statefile } # list actions _Dbg_list_action() { if [ ${#_Dbg_action_line[@]} != 0 ]; then _Dbg_msg "Actions at following places:" typeset -i i _Dbg_msg "Num Enb Stmt file:line" for (( i=1; (( i <= _Dbg_action_max )) ; i++ )) ; do if [[ -n ${_Dbg_action_line[$i]} ]] ; then typeset source_file=${_Dbg_action_file[$i]} source_file=$(_Dbg_adjust_filename "$source_file") _Dbg_printf "%-3d %3d %-18s %s:%s" $i ${_Dbg_action_enable[$i]} \ "${_Dbg_action_stmt[$i]}" \ $source_file ${_Dbg_action_line[$i]} fi done else _Dbg_msg "No actions have been set." fi } # Internal routine to a set action unconditonally. _Dbg_set_action() { (( $# != 3 )) && return 1 typeset source_file source_file=$(_Dbg_expand_filename "$1") $(_Dbg_is_int $2) || return 1 typeset -ri lineno=$2 typeset -r stmt=$3 # Increment action_max here because we are 1-origin ((_Dbg_action_max++)) ((_Dbg_action_count++)) _Dbg_action_line[$_Dbg_action_max]=$lineno _Dbg_action_file[$_Dbg_action_max]="$source_file" _Dbg_action_stmt[$_Dbg_action_max]="$stmt" _Dbg_action_enable[$_Dbg_action_max]=1 typeset dq_source_file typeset dq_source_file=$(_Dbg_esc_dq "$source_file") typeset dq_stmt=$(_Dbg_esc_dq "$stmt") _Dbg_write_journal "_Dbg_action_line[$_Dbg_action_max]=$lineno" _Dbg_write_journal "_Dbg_action_file[$_Dbg_action_max]=\"$dq_source_file\"" _Dbg_write_journal "_Dbg_action_stmt[$_Dbg_action_max]=\"$dq_stmt\"" _Dbg_write_journal "_Dbg_action_enable[$_Dbg_action_max]=1" # Add line number with a leading and trailing space. Delimiting the # number with space helps do a string search for the line number. _Dbg_action_file2linenos[$source_file]+=" $lineno " _Dbg_action_file2action[$source_file]+=" $_Dbg_action_max " source_file=$(_Dbg_adjust_filename "$source_file") _Dbg_msg "Action $_Dbg_action_max set in file ${source_file}, line $lineno." _Dbg_write_journal "_Dbg_action_max=$_Dbg_action_max" return 0 } # Internal routine to delete an action by file/line. # 0 is returned if we were able to unset the action. # Nonzero is returned otherwize. _Dbg_unset_action() { (( $# == 2 )) || return 1 typeset -r filename="$1" $(_Dbg_is_int "$2") || return 1 typeset -i lineno=$2 typeset fullname fullname=$(_Dbg_expand_filename "$filename") # FIXME: combine with something? typeset -a linenos eval "linenos=(${_Dbg_action_file2linenos[$fullname]})" typeset -a action_nos eval "action_nos=(${_Dbg_action_file2action[$fullname]})" typeset -i i for ((i=0; i < ${#linenos[@]}; i++)); do if (( linenos[i] == lineno )) ; then # Got a match, find action entry number typeset -i action_num (( action_num = action_nos[i] )) _Dbg_unset_action_arrays $action_num unset linenos[i] _Dbg_action_file2linenos[$fullname]=${linenos[@]} return 0 fi done _Dbg_errmsg "No action found in file ${filename}, line $lineno." return 1 } # Internal routine to unset the actual action arrays # 0 is returned if successful _Dbg_unset_action_arrays() { (( $# != 1 )) && return 1 typeset -i del=$1 _Dbg_write_journal_eval "unset _Dbg_action_enable[$del]" _Dbg_write_journal_eval "unset _Dbg_action_file[$del]" _Dbg_write_journal_eval "unset _Dbg_action_line[$del]" _Dbg_write_journal_eval "unset _Dbg_action_stmt[$del]" ((_Dbg_action_count--)) return 0 } bashdb-4.2-0.8/lib/display.sh0000644000175000017500000000551211535300364012600 00000000000000# -*- shell-script -*- # display.sh - Bourne Again Shell Debugger display routines # # Copyright (C) 2010 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this Program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. #================ VARIABLE INITIALIZATIONS ====================# # Display data structures typeset -a _Dbg_disp_exp; _Dbg_display_exp=() # Watchpoint expressions typeset -ia _Dbg_disp_enable; _Dbg_display_enable=() # 1/0 if enabled or not typeset -i _Dbg_disp_max=0 # Needed because we can't figure out what # the max index is and arrays can be sparse #========================= FUNCTIONS ============================# _Dbg_save_display() { typeset -p _Dbg_disp_exp >> $_Dbg_statefile typeset -p _Dbg_disp_enable >> $_Dbg_statefile typeset -p _Dbg_disp_max >> $_Dbg_statefile } # Enable/disable display by entry numbers. _Dbg_disp_enable_disable() { if (($# < 2)) ; then _Dbg_errmsg "Expecting at least two parameters. Got: ${#}." return 1 fi typeset -i on=$1 typeset en_dis=$2 shift; shift typeset to_go="$@" typeset i eval "$_seteglob" for i in $to_go ; do case $i in $int_pat ) _Dbg_enable_disable_display $on $en_dis $i ;; * ) _Dbg_errmsg "Invalid entry number $i skipped" ;; esac done eval "$_resteglob" return 0 } _Dbg_eval_all_display() { typeset -i i for (( i=0; i < _Dbg_disp_max ; i++ )) ; do if [ -n "${_Dbg_disp_exp[$i]}" ] \ && [[ ${_Dbg_disp_enable[i]} != 0 ]] ; then _Dbg_printf_nocr "%2d: %s = " $i "${_Dbg_disp_exp[i]}" typeset -i _Dbg_show_eval_rc; _Dbg_show_eval_rc=0 _Dbg_do_eval "_Dbg_msg ${_Dbg_disp_exp[i]}" fi done } # Enable/disable display(s) by entry numbers. _Dbg_enable_disable_display() { typeset -i on=$1 typeset en_dis=$2 typeset -i i=$3 if [ -n "${_Dbg_disp_exp[$i]}" ] ; then if [[ ${_Dbg_disp_enable[$i]} == $on ]] ; then _Dbg_errmsg "Display entry $i already ${en_dis}, so nothing done." else _Dbg_write_journal_eval "_Dbg_disp_enable[$i]=$on" _Dbg_msg "Display entry $i $en_dis." fi else _Dbg_errmsg "Display entry $i doesn't exist, so nothing done." fi } bashdb-4.2-0.8/lib/info.sh0000644000175000017500000000672011562717067012104 00000000000000# -*- shell-script -*- # info.sh - info help Routines # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008, 2011 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. typeset -r _Dbg_info_cmds='args breakpoints display files functions line program signals source stack terminal variables warranty' _Dbg_info_help() { local -r info_cmd=$1 local label=$2 if [[ -z $info_cmd ]] ; then local thing _Dbg_msg \ 'List of info subcommands: ' for thing in $_Dbg_info_cmds ; do _Dbg_info_help $thing 1 done return fi case $info_cmd in ar | arg | args ) _Dbg_msg \ "info args -- Argument variables (e.g. \$1, \$2, ...) of the current stack frame." return 0 ;; b | br | bre | brea | 'break' | breakp | breakpo | breakpoints | \ w | wa | wat | watc | 'watch' | watchp | watchpo | watchpoints ) _Dbg_msg \ 'info breakpoints -- Status of user-settable breakpoints' return 0 ;; disp | displ | displa | display ) _Dbg_msg \ 'info display -- Show all display expressions' return 0 ;; fi | file| files | sources ) _Dbg_msg \ 'info files -- Source files in the program' return 0 ;; fu | fun| func | funct | functi | functio | function | functions ) _Dbg_msg \ 'info functions -- All function names' return 0 ;; l | li| lin | line ) _Dbg_msg \ 'info line -- list current line number and and file name' return 0 ;; p | pr | pro | prog | progr | progra | program ) _Dbg_msg \ 'info program -- Execution status of the program.' return 0 ;; h | ha | han | hand | handl | handle | \ si | sig | sign | signa | signal | signals ) _Dbg_msg \ 'info signals -- What debugger does when program gets various signals' return 0 ;; so | sou | sourc | source ) _Dbg_msg \ 'info source -- Information about the current source file' return 0 ;; st | sta | stac | stack ) _Dbg_msg \ 'info stack -- Backtrace of the stack' return 0 ;; te | ter | term | termi | termin | termina | terminal | tt | tty ) _Dbg_msg \ 'info terminal -- Print terminal device' return 0 ;; tr|tra|trac|trace|tracep | tracepo | tracepoi | tracepoint | tracepoints ) _Dbg_msg \ 'info tracepoints -- Status of tracepoints' return 0 ;; v | va | var | vari | varia | variab | variabl | variable | variables ) _Dbg_msg \ 'info variables -- All global and static variable names' return 0 ;; w | wa | war | warr | warra | warran | warrant | warranty ) _Dbg_msg \ 'info warranty -- Various kinds of warranty you do not have' return 0 ;; * ) _Dbg_errmsg \ "Undefined info command: \"$info_cmd\". Try \"help info\"." esac } bashdb-4.2-0.8/lib/stepping.sh0000644000175000017500000000311311535300364012757 00000000000000# -*- shell-script -*- # stepping routines # # Copyright (C) 2010 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. _Dbg_next_skip_common() { _Dbg_inside_skip=$1 _Dbg_last_next_step_cmd="$_Dbg_cmd" _Dbg_last_next_step_args=$2 _Dbg_not_running && return 3 typeset count=${2:-1} if [[ $count == [0-9]* ]] ; then let _Dbg_step_ignore=${count:-1} else _Dbg_errmsg "Argument ($count) should be a number or nothing." _Dbg_step_ignore=1 return 1 fi # Do we step debug into functions called or not? if (( _Dbg_inside_skip == 0 )) ; then _Dbg_old_set_opts="$_Dbg_old_set_opts +o functrace" else _Dbg_old_set_opts="$_Dbg_old_set_opts -o functrace" fi _Dbg_write_journal_eval "_Dbg_old_set_opts='$_Dbg_old_set_opts'" _Dbg_write_journal "_Dbg_step_ignore=$_Dbg_step_ignore" # set -x _Dbg_continue_rc=$_Dbg_inside_skip return 0 } bashdb-4.2-0.8/lib/Makefile.am0000644000175000017500000000034111561105567012635 00000000000000pkgdatadir = ${datadir}/@PACKAGE@/lib pkgdata_DATA = $(wildcard *.sh) term-highlight.py install-data-hook: chmod +x $(DESTDIR)$(pkgdatadir)/term-highlight.py EXTRA_DIST = $(pkgdata_DATA) MOSTLYCLEANFILES = *.orig *.rej bashdb-4.2-0.8/lib/help.sh0000644000175000017500000002720011565104723012065 00000000000000# -*- shell-script -*- # help.sh - Debugger Help Routines # # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # A place to put help command text typeset -A _Dbg_command_help export _Dbg_command_help typeset -a _Dbg_command_names_sorted=() # List of debugger commands. # FIXME: for now we are attaching this to _Dbg_help_add which # is whe this is here. After moving somewhere more appropriate, relocate # the definition. typeset -A _Dbg_debugger_commands # Add help text $2 for command $1 function _Dbg_help_add { (($# < 2)) || (($# > 4)) && return 1 typeset -i add_command; add_command=${3:-1} _Dbg_command_help[$1]="$2" (( add_command )) && _Dbg_debugger_commands[$1]="_Dbg_do_$1" if (($# == 4)); then complete -F "$4" "$1" fi return 0 } # Add help text $3 for in subcommand $1 under key $2 function _Dbg_help_add_sub { add_command=${4:-1} (($# != 3)) && (($# != 4)) && return 1 eval "_Dbg_command_help_$1[$2]=\"$3\"" if (( add_command )) ; then eval "_Dbg_debugger_${1}_commands[$2]=\"_Dbg_do_${1}_${2}\"" fi return 0 } _Dbg_help_sort_command_names() { ((${#_Dbg_command_names_sorted} > 0 )) && return 0 typeset -a list list=("${!_Dbg_command_help[@]}") sort_list 0 ${#list[@]}-1 _Dbg_sorted_command_names=("${list[@]}") } _Dbg_help_set() { typeset subcmd if (( $# == 0 )) ; then typeset -a list list=("${!_Dbg_command_help_set[@]}") sort_list 0 ${#list[@]}-1 for subcmd in ${list[@]}; do _Dbg_help_set $subcmd 1 done return 0 fi subcmd="$1" typeset label="$2" if [[ -n "${_Dbg_command_help_set[$subcmd]}" ]] ; then if [[ -z $label ]] ; then _Dbg_msg "${_Dbg_command_help_set[$subcmd]}" return 0 else label=$(builtin printf "set %-12s-- " $subcmd) fi fi case $subcmd in ar | arg | args ) _Dbg_msg \ "${label}Set argument list to give program when restarted." return 0 ;; an | ann | anno | annot | annota | annotat | annotate ) if [[ -z $label ]] ; then typeset post_label=' 0 == normal; 1 == fullname (for use when running under emacs).' fi _Dbg_msg \ "${label}Set annotation level.$post_label" return 0 ;; autoe | autoev | autoeva | autoeval ) _Dbg_help_set_onoff 'autoeval' 'autoeval' \ "Evaluate unrecognized commands" return 0 ;; autol | autoli | autolis | autolist ) typeset onoff="on." [[ -z ${_Dbg_cmdloop_hooks['list']} ]] && onoff='off.' _Dbg_msg \ "${label}Run list command is ${onoff}" return 0 ;; b | ba | bas | base | basen | basena | basenam | basename ) _Dbg_help_set_onoff 'basename' 'basename' \ "Set short filenames (the basename) in debug output" return 0 ;; deb|debu|debug ) _Dbg_help_set_onoff 'debug' 'debug' \ "Set debugging the debugger" return 0 ;; di|dif|diff|diffe|differe|differen|different ) typeset onoff=${1:-'on'} (( _Dbg_set_different )) && onoff='on.' _Dbg_msg \ "${label}Set to stop at a different line is" $onoff return 0 ;; do|doll|dolla|dollar|dollar0 ) _Dbg_msg "${label}Set \$0" return 0 ;; e | ed | edi | edit | editi | editin | editing ) _Dbg_msg_nocr \ "${label}Set editing of command lines as they are typed is " if [[ -z $_Dbg_edit ]] ; then _Dbg_msg 'off.' else _Dbg_msg 'on.' fi return 0 ;; high | highl | highlight ) _Dbg_msg_nocr \ "${label}Set syntax highlighting of source listings is " if [[ -z $_Dbg_edit ]] ; then _Dbg_msg 'off.' else _Dbg_msg 'on.' fi return 0 ;; his | hist | history ) _Dbg_msg_nocr \ "${label}Set record command history is " if [[ -z $_Dbg_set_edit ]] ; then _Dbg_msg 'off.' else _Dbg_msg 'on.' fi ;; si | siz | size ) eval "$_seteglob" if [[ -z $2 ]] ; then _Dbg_errmsg "Argument required (integer to set it to.)." elif [[ $2 != $int_pat ]] ; then _Dbg_errmsg "Integer argument expected; got: $2" eval "$_resteglob" return 1 fi eval "$_resteglob" _Dbg_write_journal_eval "_Dbg_history_length=$2" return 0 ;; lin | line | linet | linetr | linetra | linetrac | linetrace ) typeset onoff='off.' (( _Dbg_set_linetrace )) && onoff='on.' _Dbg_msg \ "${label}Set tracing execution of lines before executed is" $onoff if (( _Dbg_set_linetrace )) ; then _Dbg_msg \ "set linetrace delay -- delay before executing a line is" $_Dbg_set_linetrace_delay fi return 0 ;; lis | list | lists | listsi | listsiz | listsize ) _Dbg_msg \ "${label}Set number of source lines $_Dbg_debugger_name will list by default." ;; p | pr | pro | prom | promp | prompt ) _Dbg_msg \ "${label}${_Dbg_debugger_name}'s prompt is:\n" \ " \"$_Dbg_prompt_str\"." return 0 ;; sho|show|showc|showco|showcom|showcomm|showcomma|showcomman|showcommand ) [[ -n $label ]] && label='set showcommand -- ' _Dbg_msg \ "${label}Set showing the command to execute is $_Dbg_set_show_command." return 0 ;; t|tr|tra|trac|trace|trace-|tracec|trace-co|trace-com|trace-comm|trace-comma|trace-comman|trace-command|trace-commands ) _Dbg_msg \ "${label}Set showing debugger commands is $_Dbg_set_trace_commands." return 0 ;; wi|wid|widt|width ) _Dbg_msg \ "${label}Set maximum width of lines is $_Dbg_set_linewidth." return 0 ;; * ) _Dbg_errmsg \ "There is no \"set $subcmd\" command." esac } _Dbg_help_show() { if (( $# == 0 )) ; then typeset -a list list=("${!_Dbg_command_help_show[@]}") sort_list 0 ${#list[@]}-1 typeset subcmd for subcmd in ${list[@]}; do _Dbg_help_show $subcmd 1 done return 0 fi typeset subcmd=$1 typeset label="$2" if [[ -n "${_Dbg_command_help_show[$subcmd]}" ]] ; then if [[ -z $label ]] ; then _Dbg_msg "${_Dbg_command_help_show[$subcmd]}" return 0 else label=$(builtin printf "show %-12s-- " $subcmd) fi fi case $subcmd in al | ali | alia | alias | aliase | aliases ) _Dbg_msg \ "${label}Show list of aliases currently in effect." return 0 ;; ar | arg | args ) _Dbg_msg \ "${label}Show argument list to give program on restart." return 0 ;; an | ann | anno | annot | annota | annotat | annotate ) _Dbg_msg \ "${label}Show annotation_level" return 0 ;; autoe | autoev | autoeva | autoeval ) _Dbg_msg \ "${label}Show if we evaluate unrecognized commands." return 0 ;; autol | autoli | autolis | autolist ) _Dbg_msg \ "${label}Run list before command loop?" return 0 ;; b | ba | bas | base | basen | basena | basenam | basename ) _Dbg_msg \ "${label}Show if we are are to show short or long filenames." return 0 ;; com | comm | comma | comman | command | commands ) _Dbg_msg \ "${label}commands [+|n] -- Show the history of commands you typed. You can supply a command number to start with, or a + to start after the previous command number shown. A negative number indicates the number of lines to list." ;; cop | copy| copyi | copyin | copying ) _Dbg_msg \ "${label}Conditions for redistributing copies of debugger." ;; d|de|deb|debu|debug) _Dbg_msg \ "${label}Show if we are set to debug the debugger." return 0 ;; different | force) _Dbg_msg \ "${label}Show if debugger stops at a different line." return 0 ;; dir|dire|direc|direct|directo|director|directori|directorie|directories) _Dbg_msg \ "${label}Show file directories searched for listing source." ;; editing ) _Dbg_msg \ "${label}Show editing of command lines and edit style." ;; highlight ) _Dbg_msg \ "${label}Show if we syntax highlight source listings." return 0 ;; history ) _Dbg_msg \ "${label}Show if we are recording command history." return 0 ;; lin | line | linet | linetr | linetra | linetrac | linetrace ) _Dbg_msg \ "${label}Show whether to trace lines before execution." ;; lis | list | lists | listsi | listsiz | listsize ) _Dbg_msg \ "${label}Show number of source lines debugger will list by default." ;; p | pr | pro | prom | promp | prompt ) _Dbg_msg \ "${label}Show debugger prompt." return 0 ;; t|tr|tra|trac|trace|trace-|trace-c|trace-co|trace-com|trace-comm|trace-comma|trace-comman|trace-command|trace-commands ) _Dbg_msg \ 'show trace-commands -- Show if we are echoing debugger commands' return 0 ;; wa | war | warr | warra | warran | warrant | warranty ) _Dbg_msg \ "${label}Various kinds of warranty you do not have." return 0 ;; width ) _Dbg_msg \ "${label}maximum width of a line." return 0 ;; * ) _Dbg_msg \ "Undefined show command: \"$subcmd\". Try \"help show\"." esac } bashdb-4.2-0.8/lib/shell.sh0000644000175000017500000000455211561306216012246 00000000000000# -*- shell-script -*- # shell.sh - helper routines for 'shell' debugger command # # Copyright (C) 2011 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. _Dbg_shell_temp_profile=$(_Dbg_tempname profile) _Dbg_shell_append_typesets() { typeset -a words typeset -p | while read -a words ; do [[ declare != ${words[0]} ]] && continue var_name=${words[2]%%=*} ((0 == _Dbg_set_debug)) && [[ $var_name =~ ^_Dbg_ ]] && continue flags=${words[1]} if [[ $flags =~ ^-.*x ]]; then # Skip exported varables continue elif [[ $flags =~ -.*r ]]; then # handle read-only variables echo "typeset -p ${var_name} &>/dev/null || $(typeset -p ${var_name})" elif [[ ${flags:0:1} == '-' ]] ; then echo $(typeset -p ${var_name} 2>/dev/null) fi done >>$_Dbg_shell_temp_profile } _Dbg_shell_append_fn_typesets() { typeset -a words typeset -pf | while read -a words ; do [[ declare != ${words[0]} ]] && continue fn_name=${words[2]%%=*} ((0 == _Dbg_set_debug)) && [[ $fn_name =~ ^_Dbg_ ]] && continue flags=${words[1]} echo $(typeset -pf ${fn_name} 2>/dev/null) done >>$_Dbg_shell_temp_profile } _Dbg_shell_new_shell_profile() { typeset -i _Dbg_o_vars; _Dbg_o_vars=${1:-1} typeset -i _Dbg_o_fns; _Dbg_o_fns=${2:-1} echo '# debugger shell profile' > $_Dbg_shell_temp_profile ((_Dbg_o_vars)) && _Dbg_shell_append_typesets # Add where file to allow us to restore info and # Routine use can call to mark which variables should persist typeset -p _Dbg_restore_info >> $_Dbg_shell_temp_profile echo "source ${_Dbg_libdir}/data/shell.sh" >> $_Dbg_shell_temp_profile ((_Dbg_o_fns)) && _Dbg_shell_append_fn_typesets } bashdb-4.2-0.8/lib/setshow.sh0000644000175000017500000000421411562372457012641 00000000000000# setshow.sh - Helper routines for help/set/show # # Copyright (C) 2010, 2011 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # Sets variable _Dbg_$2 to value $1 and then runs _Dbg_do_show $2. _Dbg_set_onoff() { typeset onoff=${1:-'off'} typeset cmdname=$2 case $onoff in on | 1 ) _Dbg_write_journal_eval "_Dbg_set_${cmdname}=1" ;; off | 0 ) _Dbg_write_journal_eval "_Dbg_set_${cmdname}=0" ;; * ) _Dbg_msg "\"on\" or \"off\" expected." return 1 esac _Dbg_do_show $cmdname return 0 } _Dbg_show_onoff() { typeset cmd="$1" typeset msg="$2" typeset label="$3" [[ -n $label ]] && label=$(printf "%-12s: " $subcmd) typeset onoff='off.' typeset value eval "value=\$_Dbg_set_${cmd}" (( value )) && onoff='on.' _Dbg_msg \ "${label}$msg is" $onoff return 0 } _Dbg_help_set_onoff() { typeset subcmd="$1" typeset label="$2" typeset msg="$3" typeset -i variable_value eval_cmd="variable_value=\${_Dbg_set_$subcmd}" eval $eval_cmd [[ -n $label ]] && label=$(builtin printf "set %-12s-- " $subcmd) typeset onoff="off." (( variable_value != 0 )) && onoff='on.' _Dbg_msg \ "${label}${msg} is" $onoff return 0 } # Demo it if [[ ${BASH_SOURCE[0]} == $0 ]] ; then _Dbg_msg() { echo $* } typeset -i _Dbg_foo for i in 0 1 ; do _Dbg_foo=$i _Dbg_help_set_onoff "foo" "foo" "Set short xx" typeset -p _Dbg_set_foo done fi bashdb-4.2-0.8/lib/file.sh0000644000175000017500000000720511565104723012057 00000000000000# -*- shell-script -*- # Things related to file handling. # # Copyright (C) 2002, 2003, 2004, 2006, 2008, 2009, 2010 Rocky Bernstein # rocky@gnu.org # # 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 # Software Foundation; either version 2, or (at your option) any later # version. # # bashdb is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with bashdb; see the file COPYING. If not, write to the Free Software # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. # Directory search patch for unqualified file names typeset -a _Dbg_dir _Dbg_dir=('\$cdir' '\$cwd' ) # _Dbg_cdir is the directory in which the script is located. [[ -z ${_Dbg_cdir} ]] && typeset _Dbg_cdir=${_Dbg_source_file%/*} [[ -z ${_Dbg_cdir} ]] && typeset _Dbg_cdir=$(pwd) # Either fill out or strip filename as determined by "basename_only" # and annotate settings _Dbg_adjust_filename() { typeset -r filename="$1" if (( _Dbg_set_annotate == 1 )) ; then echo $(_Dbg_resolve_expand_filename $filename) elif ((_Dbg_set_basename)) ; then echo ${filename##*/} else echo $filename fi } # Canonicalize $1. For now if _Dbg_set_basename is set we just want # the basename of that. function _Dbg_file_canonic { if (( $# != 1 )) ; then echo '??' return 1 fi typeset filename="$1" (( _Dbg_set_basename )) && filename=${filename##*/} echo $filename return 0 } # $1 contains the name you want to glob. return 0 if exists and is # readable or 1 if not. # The result will be in variable $filename which is assumed to be # local'd by the caller _Dbg_glob_filename() { printf -v filename "%q" "$1" typeset cmd="filename=$filename" eval $cmd [[ -r $filename ]] } # # Resolve $1 to a full file name which exists. First see if filename has been # mentioned in a debugger "file" command. If not and the file name # is a relative name use _Dbg_dir to substitute a relative directory name. # function _Dbg_resolve_expand_filename { if (( $# == 0 )) ; then _Dbg_errmsg \ "Internal debug error _Dbg_resolve_expand_filename(): null file to find" echo '' return 1 fi typeset find_file="$1" # Is this one of the files we've that has been specified in a debugger # "FILE" command? typeset found_file found_file="${_Dbg_file2canonic[$find_file]}" if [[ -n $found_file ]] ; then echo "$found_file" return 0 fi if [[ ${find_file:0:1} == '/' ]] ; then # Absolute file name full_find_file=$(_Dbg_expand_filename "$find_file") echo "$full_find_file" return 0 elif [[ ${find_file:0:1} == '.' ]] ; then # 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 full_find_file=$(_Dbg_expand_filename "$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]}" if [[ $basename == '\$cdir' ]] ; then basename=$_Dbg_cdir elif [[ $basename == '\$cwd' ]] ; then basename=$(pwd) fi if [[ -f "$basename/$find_file" ]] ; then echo "$basename/$find_file" return 0 fi done fi echo '' return 1 } bashdb-4.2-0.8/lib/subcmd.sh0000644000175000017500000000346611561120016012407 00000000000000# -*- shell-script -*- # subcmd.sh - Debugger Help Routines # # Copyright (C) 2011 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # Command completion for a subcommand typeset -A _Dbg_next_complete _Dbg_complete_subcmd() { # echo "level 0 called with comp_line: $COMP_LINE , comp_point: $COMP_POINT" typeset -a words; typeset subcmds IFS=' ' words=( $COMP_LINE ) if (( ${#words[@]} == 1 )); then eval "subcmds=\${!_Dbg_debugger_$1_commands[@]}" COMPREPLY=( $subcmds ) elif (( ${#words[@]} == 2 )) ; then eval "subcmds=\${!_Dbg_debugger_$1_commands[@]}" typeset commands="${!_Dbg_command_help[@]}" COMPREPLY=( $(compgen -W "$subcmds" "${words[1]}" ) ) if (( ${#COMPREPLY[@]} == 1 )) && [[ ${COMPREPLY[0]} == ${words[1]} ]] then IFS=' ' typeset canon_line; canon_line="${words[@]}" if [[ -n ${_Dbg_next_complete[$canon_line]} && \ $COMP_LINE =~ ' '$ ]] ; then ${_Dbg_next_complete[$canon_line]} fi fi elif [[ -n ${_Dbg_next_complete[$COMP_LINE]} ]] ; then ${_Dbg_next_complete[$COMP_LINE]} else COMPREPLY=() fi } _Dbg_complete_onoff() { COMPREPLY=(on off) } bashdb-4.2-0.8/lib/alias.sh0000644000175000017500000000416111535300364012223 00000000000000# -*- shell-script -*- # Copyright (C) 2008, 2010, 2011 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; see the file COPYING. If not, write to the Free Software # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. # Command aliases are stored here. typeset -A _Dbg_aliases # Add an new alias in the alias table _Dbg_alias_add() { (( $# != 2 )) && return 1 _Dbg_aliases[$1]="$2" return 0 } # Remove alias $1 from our list of command aliases. _Dbg_alias_remove() { (( $# != 1 )) && return 1 unset "_Dbg_aliases[$1]" return 0 } # Expand alias $1. The result is set in variable expanded_alias which # could be declared local in the caller. _Dbg_alias_expand() { (( $# != 1 )) && return 1 expanded_alias="$1" [[ -z "$1" ]] && return 0 [[ -n ${_Dbg_aliases[$1]} ]] && expanded_alias=${_Dbg_aliases[$1]} return 0 } # Echo the index in _Dbg_command_names if found. Return # 0 if found and 1 if not there. _Dbg_alias_find_index() { typeset find_name=$1 typeset -i i for ((i=0; i <= _Dbg_alias_max_index; i++)) ; do [[ ${_Dbg_alias_names[i]} == "$find_name" ]] && echo $i && return 0 done return 1 } # Return in help_aliases an array of strings that are aliases # of $1 _Dbg_alias_find_aliased() { (($# != 1)) && return 255 typeset find_name=$1 aliases_found='' typeset -i i for alias in ${!_Dbg_aliases[@]} ; do if [[ ${_Dbg_aliases[$alias]} == "$find_name" ]] ; then [[ -n $aliases_found ]] && aliases_found+=', ' aliases_found+="$alias" fi done return 0 } bashdb-4.2-0.8/lib/msg.sh0000644000175000017500000001011411563752733011727 00000000000000# -*- shell-script -*- # # Copyright (C) 2002, 2003, 2004, 2006, 2008, 2009 Rocky Bernstein # # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. _Dbg_ansi_term_bold="" _Dbg_ansi_term_italic="" _Dbg_ansi_term_underline="" _Dbg_ansi_term_normal="" # Called when a dangerous action is about to be done to make sure it's # okay. `prompt' is printed, and "yes", or "no" is solicited. The # user response is returned in variable $_Dbg_response and $? is set # to 0. _Dbg_response is set to 'error' and $? set to 1 on an error. # _Dbg_confirm() { if (( $# < 1 || $# > 2 )) ; then _Dbg_response='error' return 0 fi _Dbg_confirm_prompt=$1 typeset _Dbg_confirm_default=${2:-'no'} while : ; do if ! read $_Dbg_edit -p "$_Dbg_confirm_prompt" _Dbg_response args \ <&$_Dbg_input_desc 2>>$_Dbg_prompt_output ; then break fi case "$_Dbg_response" in 'y' | 'yes' | 'yeah' | 'ya' | 'ja' | 'si' | 'oui' | 'ok' | 'okay' ) _Dbg_response='y' return 0 ;; 'n' | 'no' | 'nope' | 'nyet' | 'nein' | 'non' ) _Dbg_response='n' return 0 ;; *) if [[ $_Dbg_response =~ '^[ \t]*$' ]] ; then set +x return 0 else _Dbg_msg "I don't understand \"$_Dbg_response\"." _Dbg_msg "Please try again entering 'yes' or 'no'." _Dbg_response='' fi ;; esac done } # Print an error message function _Dbg_errmsg { typeset -r prefix='**' if (( _Dbg_set_highlight )) ; then _Dbg_msg "$prefix ${_Dbg_ansi_term_underline}$@${_Dbg_ansi_term_normal}" else _Dbg_msg "$prefix $@" fi } # Print an error message without the ending carriage return function _Dbg_errmsg_no_cr { typeset -r prefix='**' _Dbg_msg_no_cr "$prefix $@" } # print message to output device function _Dbg_msg { if (( _Dbg_logging )) ; then builtin echo -e "$@" >>$_Dbg_logfid fi if (( ! _Dbg_logging_redirect )) ; then if [[ -n $_Dbg_tty ]] ; then builtin echo -e "$@" >>$_Dbg_tty else builtin echo -e "$@" fi fi } # print message to output device without a carriage return at the end function _Dbg_msg_nocr { if (( _Dbg_logging )) ; then builtin echo -n -e "$@" >>$_Dbg_logfid fi if (( ! _Dbg_logging_redirect )) ; then if [[ -n $_Dbg_tty ]] ; then builtin echo -n -e "$@" >>$_Dbg_tty else builtin echo -n -e "$@" fi fi } # print message to output device function _Dbg_printf { _Dbg_printf_nocr "$@" _Dbg_msg '' } # print message to output device without a carriage return at the end function _Dbg_printf_nocr { typeset format=$1 shift if (( _Dbg_logging )) ; then builtin printf "$format" "$@" >>$_Dbg_logfid fi if (( ! _Dbg_logging_redirect )) ; then if [[ -n $_Dbg_tty ]] ; then builtin printf "$format" "$@" >>$_Dbg_tty else builtin printf "$format" "$@" fi fi } # print message to output device function _Dbg_section { if (( _Dbg_set_highlight )) ; then _Dbg_msg "$prefix ${_Dbg_ansi_term_bold}$@${_Dbg_ansi_term_normal}" else _Dbg_msg "$prefix $@" fi } # Common funnel for "Undefined command" message _Dbg_undefined_cmd() { if (( $# == 2 )) ; then _Dbg_errmsg "Undefined $1 subcommand \"$2\". Try \"help $1\"." else _Dbg_errmsg "Undefined command \"$1\". Try \"help\"." fi } bashdb-4.2-0.8/lib/list.sh0000644000175000017500000001550611535300364012112 00000000000000# -*- shell-script -*- # debugger source-code listing routines # # Copyright (C) 2002, 2003, 2004, 2006, 2008, 2009, 2010, 2011 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # List search commands/routines # Last search pattern used. typeset _Dbg_last_search_pat # The current line to be listed. A 0 value indicates we should set # from _Dbg_frame_last_lineno typeset -i _Dbg_listline=0 typeset _Dbg_source_line # Print source line in standard format for line $1 of filename $2. If # $2 is omitted, use _Dbg_frame_last_filename, if $1 is omitted use # _Dbg_frame_last_lineno. 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}): ${line_number}:\t${_Dbg_source_line}" # 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 # currently at. if [[ $_Dbg_set_show_command == "on" ]] ; then _Dbg_msg "$_Dbg_bash_command" elif [[ $_Dbg_last_lineno == $_Dbg_frame_last_lineno ]] \ && [[ $_Dbg_last_source_file == $_Dbg_frame_last_filename ]] \ && [[ $_Dbg_last_bash_command != $_Dbg_bash_command \ && $_Dbg_set_show_command == "auto" ]] ; then _Dbg_msg "$_Dbg_bash_command" fi } # Print Linetrace output. We also handle output if linetrace expand # is in effect. _Dbg_print_linetrace() { typeset line_number=${1:-$_Dbg_frame_last_lineno} typeset filename=${2:-"$_Dbg_frame_last_filename"} # Remove main + sig-handler + print_lintrace FUNCNAMES. typeset -i depth=${#FUNCNAME[@]}-3 # If called from bashdb script rather than via "bash --debugger", # we are artificially nested one deeper because of the bashdb call. if [[ -n $_Dbg_script ]] ; then ((depth--)) fi (( depth < 0 )) && return _Dbg_get_source_line $line_number "$filename" filename=$(_Dbg_adjust_filename "$filename") _Dbg_msg "(${filename}:${line_number}): level $_Dbg_DEBUGGER_LEVEL, subshell $BASH_SUBSHELL, depth $depth:\t${_Dbg_source_line}" # if (( _Dbg_linetrace_expand )) ; then # # typeset expanded_source_line # # # Replace all double quotes (") with and an escape (\") # # typeset esc_source_line="${_Dbg_source_line//\"/\\\"}" # _Dbg_do_eval "expanded_source_line=\"$esc_source_line\"" 2>/dev/null # _Dbg_do_eval "expanded_source_line=\"$_Dbg_bash_command\"" 2>/dev/null # _Dbg_msg "+ ${expanded_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 # currently at. if [[ $_Dbg_set_show_command == "on" ]] ; then _Dbg_msg "$_Dbg_bash_command" elif (( _Dbg_last_lineno == _Dbg_frame_last_lineno )) \ && [[ $_Dbg_last_source_file == $_Dbg_frame_last_filename ]] \ && [[ $_Dbg_last_bash_command != $_Dbg_bash_command \ && $_Dbg_set_show_command == "auto" ]] ; then _Dbg_msg "$_Dbg_bash_command" fi } # Parse $1 $2, $3, and optional $4 setting $filename, $_Dbg_start_line and # $end_line. $2 is the maximimum number of lines. If $3 or $4 are # less than 0, they are interpreted as line numbers counting from the # end. If $3 is '.' use _Dbg_frame_last_lineno. If $4 is given and is # greater than $3 then use that as an ending line. If $4 is less than # $3, then it is a line count. And if $4 omitted, use the line count # $_Dbg_set_listsize. if $2 is omitted, use global variable # $_Dbg_frame_last_lineno. _Dbg_parse_list_args() { typeset -i max_line (($# < 3 || $# > 5)) && return 1 typeset -i center_line center_line=$2 max_line=$2 filename="$3" # Parse start line $3 yielding _Dbg_listline if [[ $4 == '.' ]]; then ((_Dbg_listline=_Dbg_frame_last_lineno)) elif [[ $4 == '-' ]]; then ((_Dbg_listline=_Dbg_listline-2*_Dbg_set_listsize)) elif [[ -n $4 ]] ; then if (($4 < 0)) ; then ((_Dbg_listline=$2+$4+1)) else ((_Dbg_listline=$4)) fi elif (( 0 == _Dbg_listline )) ; then _Dbg_listline=$_Dbg_frame_last_lineno fi (( _Dbg_listline==0 && _Dbg_listline++ )) typeset -i count ((count=${5:-_Dbg_set_listsize})) ((count < 0)) && ((count=$2+$5+1)) if [[ -z $5 ]] || ((count < _Dbg_listline)) ; then ((center_line)) && ((_Dbg_listline-=count/2)) ((_Dbg_listline<=0)) && ((_Dbg_listline=1)) ((end_line=_Dbg_listline+count-1)) else ((end_line=count)) fi return 0 } # list lines starting. See _Dbg_parse_list_args for how $2, $3, and $4 # are interpreted. Note though that they are called as $1, $2, $3 there. _Dbg_list() { (($# < 3 || $# > 5)) && return 1 typeset filename filename=$2 typeset end_line _Dbg_readin_if_new "$filename" typeset -i max_line max_line=$(_Dbg_get_maxline "$filename") if (( $? != 0 )) ; then _Dbg_errmsg "internal error getting number of lines in $filename" return 1 fi _Dbg_parse_list_args "$max_line" "$@" if (( _Dbg_listline > max_line )) ; then _Dbg_errmsg \ "Line number $_Dbg_listline out of range;" \ "$filename has $max_line lines." return 1 fi (( end_line > max_line )) && ((end_line=max_line)) typeset frame_fullfile frame_fullfile=${_Dbg_file2canonic[$_Dbg_frame_last_filename]} for (( ; _Dbg_listline <= end_line ; _Dbg_listline++ )) ; do typeset prefix=' ' _Dbg_get_source_line $_Dbg_listline "$filename" (( _Dbg_listline == _Dbg_frame_last_lineno )) \ && [[ $fullname == $frame_fullfile ]] && prefix=' => ' _Dbg_printf "%3d:%s%s" $_Dbg_listline "$prefix" "$_Dbg_source_line" done return 0 } _Dbg_list_columns() { typeset colsep=' ' (($# > 0 )) && { colsep="$1"; shift; } typeset -i linewidth # 2 below is the initial prefix if (($# > 0 )) ; then ((linewidth=$1-2)); shift else ((linewidth=_Dbg_set_linewidth-2)) fi (($# != 0)) && return 1 typeset -a columnized; columnize $linewidth "$colsep" typeset -i i for ((i=0; i<${#columnized[@]}; i++)) ; do _Dbg_msg " ${columnized[i]}" done } bashdb-4.2-0.8/lib/break.sh0000644000175000017500000003533511564571702012235 00000000000000# -*- shell-script -*- # break.sh - Debugger Break and Watch routines # # Copyright (C) 2002, 2003, 2006, 2007, 2008, 2009, 2010, 2011 Rocky Bernstein # # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. #================ VARIABLE INITIALIZATIONS ====================# typeset -a _Dbg_keep _Dbg_keep=('keep' 'del') # Note: we loop over possibly sparse arrays with _Dbg_brkpt_max by adding one # and testing for an entry. Could add yet another array to list only # used indices. Bash is kind of primitive. # Line number of breakpoint $i typeset -a _Dbg_brkpt_line; _Dbg_brkpt_line=() # Number of breakpoints. typeset -i _Dbg_brkpt_count=0 # filename of breakpoint $i typeset -a _Dbg_brkpt_file; _Dbg_brkpt_file=() # 1/0 if enabled or not typeset -a _Dbg_brkpt_enable; _Dbg_brkpt_enable=() # Number of times hit typeset -a _Dbg_brkpt_counts; _Dbg_brkpt_counts=() # Is this a onetime break? typeset -a _Dbg_brkpt_onetime; _Dbg_brkpt_onetime=() # Condition to eval true in order to stop. typeset -a _Dbg_brkpt_cond; _Dbg_brkpt_cond=() # Needed because we can't figure out what the max index is and arrays # can be sparse. typeset -i _Dbg_brkpt_max=0 # Maps a resolved filename to a list of beakpoint line numbers in that file typeset -A _Dbg_brkpt_file2linenos; _Dbg_brkpt_file2linenos=() # Maps a resolved filename to a list of breakpoint entries. typeset -A _Dbg_brkpt_file2brkpt; _Dbg_brkpt_file2brkpt=() # Note: we loop over possibly sparse arrays with _Dbg_brkpt_max by adding one # and testing for an entry. Could add yet another array to list only # used indices. Bash is kind of primitive. # Watchpoint data structures typeset -a _Dbg_watch_exp=() # Watchpoint expressions typeset -a _Dbg_watch_val=() # values of watchpoint expressions typeset -ai _Dbg_watch_arith=() # 1 if arithmetic expression or not. typeset -ai _Dbg_watch_count=() # Number of times hit typeset -ai _Dbg_watch_enable=() # 1/0 if enabled or not typeset -i _Dbg_watch_max=0 # Needed because we can't figure out what # the max index is and arrays can be sparse typeset _Dbg_watch_pat="${int_pat}[wW]" #========================= FUNCTIONS ============================# _Dbg_save_breakpoints() { typeset file typeset -p _Dbg_brkpt_line >> $_Dbg_statefile typeset -p _Dbg_brkpt_file >> $_Dbg_statefile typeset -p _Dbg_brkpt_cond >> $_Dbg_statefile typeset -p _Dbg_brkpt_count >> $_Dbg_statefile typeset -p _Dbg_brkpt_enable >> $_Dbg_statefile typeset -p _Dbg_brkpt_onetime >> $_Dbg_statefile typeset -p _Dbg_brkpt_max >> $_Dbg_statefile typeset -p _Dbg_brkpt_file2linenos >> $_Dbg_statefile typeset -p _Dbg_brkpt_file2brkpt >> $_Dbg_statefile } _Dbg_save_watchpoints() { typeset -p _Dbg_watch_exp >> $_Dbg_statefile typeset -p _Dbg_watch_val >> $_Dbg_statefile typeset -p _Dbg_watch_arith >> $_Dbg_statefile typeset -p _Dbg_watch_count >> $_Dbg_statefile typeset -p _Dbg_watch_enable >> $_Dbg_statefile typeset -p _Dbg_watch_max >> $_Dbg_statefile } # Start out with general break/watchpoint functions first... # Enable/disable breakpoint or watchpoint by entry numbers. _Dbg_enable_disable() { if (($# <= 2)) ; then _Dbg_errmsg "_Dbg_enable_disable error - need at least 2 args, got $#" return 1 fi typeset -i on=$1 typeset en_dis=$2 shift; shift if [[ $1 == 'display' ]] ; then shift typeset to_go="$@" typeset i eval "$_seteglob" for i in $to_go ; do case $i in $int_pat ) _Dbg_enable_disable_display $on $en_dis $i ;; * ) _Dbg_errmsg "Invalid entry number skipped: $i" esac done eval "$_resteglob" return 0 elif [[ $1 == 'action' ]] ; then shift typeset to_go="$@" typeset i eval "$_seteglob" for i in $to_go ; do case $i in $int_pat ) _Dbg_enable_disable_action $on $en_dis $i ;; * ) _Dbg_errmsg "Invalid entry number skipped: $i" esac done eval "$_resteglob" return 0 fi typeset to_go="$@" typeset i eval "$_seteglob" for i in $to_go ; do case $i in $_Dbg_watch_pat ) _Dbg_enable_disable_watch $on $en_dis ${del:0:${#del}-1} ;; $int_pat ) _Dbg_enable_disable_brkpt $on $en_dis $i ;; * ) _Dbg_errmsg "Invalid entry number skipped: $i" esac done eval "$_resteglob" return 0 } # Print a message regarding how many times we've encountered # breakpoint number $1 if the number of times is greater than 0. # Uses global array _Dbg_brkpt_counts. function _Dbg_print_brkpt_count { typeset -i i; i=$1 if (( _Dbg_brkpt_counts[i] != 0 )) ; then if (( _Dbg_brkpt_counts[i] == 1 )) ; then _Dbg_printf "\tbreakpoint already hit 1 time" else _Dbg_printf "\tbreakpoint already hit %d times" ${_Dbg_brkpt_counts[$i]} fi fi } #======================== BREAKPOINTS ============================# # clear all brkpts _Dbg_clear_all_brkpt() { _Dbg_write_journal_eval "_Dbg_brkpt_file2linenos=()" _Dbg_write_journal_eval "_Dbg_brkpt_file2brkpt=()" _Dbg_write_journal_eval "_Dbg_brkpt_line=()" _Dbg_write_journal_eval "_Dbg_brkpt_cond=()" _Dbg_write_journal_eval "_Dbg_brkpt_file=()" _Dbg_write_journal_eval "_Dbg_brkpt_enable=()" _Dbg_write_journal_eval "_Dbg_brkpt_counts=()" _Dbg_write_journal_eval "_Dbg_brkpt_onetime=()" _Dbg_write_journal_eval "_Dbg_brkpt_count=0" } # Internal routine to a set breakpoint unconditonally. _Dbg_set_brkpt() { (( $# < 3 || $# > 4 )) && return 1 typeset source_file source_file=$(_Dbg_expand_filename "$1") typeset -ri lineno=$2 typeset -ri is_temp=$3 typeset -r condition=${4:-1} # Increment brkpt_max here because we are 1-origin ((_Dbg_brkpt_max++)) ((_Dbg_brkpt_count++)) _Dbg_brkpt_line[$_Dbg_brkpt_max]=$lineno _Dbg_brkpt_file[$_Dbg_brkpt_max]="$source_file" _Dbg_brkpt_cond[$_Dbg_brkpt_max]="$condition" _Dbg_brkpt_onetime[$_Dbg_brkpt_max]=$is_temp _Dbg_brkpt_counts[$_Dbg_brkpt_max]=0 _Dbg_brkpt_enable[$_Dbg_brkpt_max]=1 typeset dq_source_file dq_source_file=$(_Dbg_esc_dq "$source_file") typeset dq_condition=$(_Dbg_esc_dq "$condition") _Dbg_write_journal_eval "_Dbg_brkpt_line[$_Dbg_brkpt_max]=$lineno" _Dbg_write_journal_eval "_Dbg_brkpt_file[$_Dbg_brkpt_max]=\"$dq_source_file\"" _Dbg_write_journal "_Dbg_brkpt_cond[$_Dbg_brkpt_max]=\"$dq_condition\"" _Dbg_write_journal "_Dbg_brkpt_onetime[$_Dbg_brkpt_max]=$is_temp" _Dbg_write_journal "_Dbg_brkpt_counts[$_Dbg_brkpt_max]=\"0\"" _Dbg_write_journal "_Dbg_brkpt_enable[$_Dbg_brkpt_max]=1" # Add line number with a leading and trailing space. Delimiting the # number with space helps do a string search for the line number. _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") if (( is_temp == 0 )) ; then _Dbg_msg "Breakpoint $_Dbg_brkpt_max set in file ${source_file}, line $lineno." else _Dbg_msg "One-time breakpoint $_Dbg_brkpt_max set in file ${source_file}, line $lineno." fi _Dbg_write_journal "_Dbg_brkpt_max=$_Dbg_brkpt_max" return 0 } # Internal routine to unset the actual breakpoint arrays # 0 is returned if successful _Dbg_unset_brkpt_arrays() { (( $# != 1 )) && return 1 typeset -i del=$1 _Dbg_write_journal_eval "unset _Dbg_brkpt_line[$del]" _Dbg_write_journal_eval "unset _Dbg_brkpt_counts[$del]" _Dbg_write_journal_eval "unset _Dbg_brkpt_file[$del]" _Dbg_write_journal_eval "unset _Dbg_brkpt_enable[$del]" _Dbg_write_journal_eval "unset _Dbg_brkpt_cond[$del]" _Dbg_write_journal_eval "unset _Dbg_brkpt_onetime[$del]" ((_Dbg_brkpt_count--)) return 0 } # Internal routine to delete a breakpoint by file/line. # We return the number of breakponts found or zer if we didn't find # a breakpoint function _Dbg_unset_brkpt { (( $# != 2 )) && return 0 typeset filename=$1 typeset -i lineno=$2 typeset -i found=0 typeset fullname fullname=$(_Dbg_expand_filename "$filename") # FIXME: combine with _Dbg_hook_breakpoint_hit typeset -a linenos eval "linenos=(${_Dbg_brkpt_file2linenos[$fullname]})" typeset -a brkpt_nos eval "brkpt_nos=(${_Dbg_brkpt_file2brkpt[$fullname]})" typeset -i i for ((i=0; i <= ${#linenos[@]}; i++)); do if (( linenos[i] == lineno )) ; then # Got a match, find breakpoint entry number typeset -i brkpt_num (( brkpt_num = brkpt_nos[i] )) _Dbg_unset_brkpt_arrays $brkpt_num unset linenos[i] _Dbg_brkpt_file2linenos[$fullname]=${linenos[@]} (( found ++ )) fi done if (( found == 0 )) ; then filename=$(_Dbg_file_canonic "$filename") _Dbg_errmsg "No breakpoint found at $filename, line ${lineno}." fi return $found } # Routine to a delete breakpoint by entry number: $1. # Returns whether or not anything was deleted. function _Dbg_delete_brkpt_entry { (( $# == 0 )) && return 0 typeset -r del="$1" typeset -i i typeset -i found=0 if [[ -z ${_Dbg_brkpt_file[$del]} ]] ; then _Dbg_errmsg "No breakpoint number $del." return 0 fi typeset source_file=${_Dbg_brkpt_file[$del]} typeset -i lineno=${_Dbg_brkpt_line[$del]} typeset -i try typeset new_lineno_val='' typeset new_brkpt_nos='' typeset -i i=-1 typeset -a brkpt_nos brkpt_nos=(${_Dbg_brkpt_file2brkpt[$source_file]}) for try in ${_Dbg_brkpt_file2linenos[$source_file]} ; do ((i++)) if (( brkpt_nos[i] == del )) ; then if (( try != lineno )) ; then _Dbg_errmsg 'internal brkpt structure inconsistency' return 0 fi _Dbg_unset_brkpt_arrays $del ((found++)) else new_lineno_val+=" $try " new_brkpt_nos+=" ${brkpt_nos[$i]} " fi done if (( found > 0 )) ; then if (( ${#new_lineno_val[@]} == 0 )) ; then # Remove array entirely _Dbg_write_journal_eval "unset '_Dbg_brkpt_file2linenos[$source_file]'" _Dbg_write_journal_eval "unset '_Dbg_brkpt_file2brkpt[$source_file]'" else # Replace array entries with reduced set. _Dbg_write_journal_eval "_Dbg_brkpt_file2linenos[$source_file]=\"${new_lineno_val}\"" _Dbg_write_journal_eval "_Dbg_brkpt_file2brkpt[$source_file]=\"$new_brkpt_nos\"" set +x fi fi return $found } # Enable/disable aciton(s) by entry numbers. function _Dbg_enable_disable_action { (($# != 3)) && return 1 typeset -i on=$1 typeset en_dis=$2 typeset -i i=$3 if [[ -n "${_Dbg_brkpt_file[$i]}" ]] ; then if [[ ${_Dbg_action_enable[$i]} == $on ]] ; then _Dbg_errmsg "Breakpoint entry $i already ${en_dis}, so nothing done." return 1 else _Dbg_write_journal_eval "_Dbg_brkpt_enable[$i]=$on" _Dbg_msg "Action entry $i $en_dis." return 0 fi else _Dbg_errmsg "Action entry $i doesn't exist, so nothing done." return 1 fi } # Enable/disable breakpoint(s) by entry numbers. function _Dbg_enable_disable_brkpt { (($# != 3)) && return 1 typeset -i on=$1 typeset en_dis=$2 typeset -i i=$3 if [[ -n "${_Dbg_brkpt_file[$i]}" ]] ; then if [[ ${_Dbg_brkpt_enable[$i]} == $on ]] ; then _Dbg_errmsg "Breakpoint entry $i already ${en_dis}, so nothing done." return 1 else _Dbg_write_journal_eval "_Dbg_brkpt_enable[$i]=$on" _Dbg_msg "Breakpoint entry $i $en_dis." return 0 fi else _Dbg_errmsg "Breakpoint entry $i doesn't exist, so nothing done." return 1 fi } #======================== WATCHPOINTS ============================# _Dbg_get_watch_exp_eval() { typeset -i i=$1 typeset new_val if [[ $(eval echo \"${_Dbg_watch_exp[$i]}\") == "" ]]; then new_val='' elif (( _Dbg_watch_arith[$i] == 1 )) ; then . ${_Dbg_libdir}/dbg-set-d-vars.inc eval let new_val=\"${_Dbg_watch_exp[$i]}\" else . ${_Dbg_libdir}/dbg-set-d-vars.inc eval new_val="${_Dbg_watch_exp[$i]}" fi echo $new_val } # Enable/disable watchpoint(s) by entry numbers. _Dbg_enable_disable_watch() { typeset -i on=$1 typeset en_dis=$2 typeset -i i=$3 if [ -n "${_Dbg_watch_exp[$i]}" ] ; then if [[ ${_Dbg_watch_enable[$i]} == $on ]] ; then _Dbg_msg "Watchpoint entry $i already $en_dis so nothing done." else _Dbg_write_journal_eval "_Dbg_watch_enable[$i]=$on" _Dbg_msg "Watchpoint entry $i $en_dis." fi else _Dbg_msg "Watchpoint entry $i doesn't exist so nothing done." fi } _Dbg_list_watch() { if [ ${#_Dbg_watch_exp[@]} != 0 ]; then typeset i=0 j _Dbg_msg "Num Type Enb Expression" for (( i=0; (( i < _Dbg_watch_max )); i++ )) ; do if [ -n "${_Dbg_watch_exp[$i]}" ] ;then _Dbg_printf '%-3d watchpoint %-4s %s' $i \ ${_Dbg_yn[${_Dbg_watch_enable[$i]}]} \ "${_Dbg_watch_exp[$i]}" _Dbg_print_brkpt_count ${_Dbg_watch_count[$i]} fi done else _Dbg_msg "No watch expressions have been set." fi } _Dbg_delete_watch_entry() { typeset -i del=$1 if [ -n "${_Dbg_watch_exp[$del]}" ] ; then _Dbg_write_journal_eval "unset _Dbg_watch_exp[$del]" _Dbg_write_journal_eval "unset _Dbg_watch_val[$del]" _Dbg_write_journal_eval "unset _Dbg_watch_enable[$del]" _Dbg_write_journal_eval "unset _Dbg_watch_count[$del]" else _Dbg_msg "Watchpoint entry $del doesn't exist so nothing done." fi } _Dbg_clear_watch() { if (( $# < 1 )) ; then typeset _Dbg_prompt_output=${_Dbg_tty:-/dev/null} read $_Dbg_edit -p "Delete all watchpoints? (y/n): " \ <&$_Dbg_input_desc 2>>$_Dbg_prompt_output if [[ $REPLY == [Yy]* ]] ; then _Dbg_write_journal_eval unset _Dbg_watch_exp[@] _Dbg_write_journal_eval unset _Dbg_watch_val[@] _Dbg_write_journal_eval unset _Dbg_watch_enable[@] _Dbg_write_journal_eval unset _Dbg_watch_count[@] _Dbg_msg "All Watchpoints have been cleared" fi return 0 fi eval "$_seteglob" if [[ $1 == $int_pat ]]; then _Dbg_write_journal_eval "unset _Dbg_watch_exp[$1]" _msg "Watchpoint $i has been cleared" else _Dbg_list_watch _basdhb_msg "Please specify a numeric watchpoint number" fi eval "$_resteglob" } bashdb-4.2-0.8/lib/validate.sh0000644000175000017500000000340311535300364012721 00000000000000# -*- shell-script -*- # validate.sh - some input validation routines # # Copyright (C) 2010, 2011 # Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. # _Dbg_is_function returns 0 if $1 is a defined function or nonzero otherwise. # if $2 is nonzero, system functions, i.e. those whose name starts with # an underscore (_), are included in the search. _Dbg_is_function() { (( 0 == $# )) && return 1 typeset needed_fn=$1 typeset -i include_system=${2:-0} [[ ${needed_fn:0:1} == '_' ]] && ((!include_system)) && { return 1 } declare -F $needed_fn >/dev/null 2>&1 return $? } # _Dbg_is_int returns 0 if $1 is an integer or nonzero otherwise. _Dbg_is_int() { (( 1 == $# )) || return 1 typeset rc=1 eval "$_seteglob" [[ $1 == $int_pat ]] && rc=0 eval "$_resteglob" return $rc } # _Dbg_is_signed_int returns 0 if $1 is an integer or nonzero otherwise. _Dbg_is_signed_int() { (( 1 == $# )) || return 1 typeset rc=1 eval "$_seteglob" [[ $1 == $_Dbg_signed_int_pat ]] && rc=0 eval "$_resteglob" return $rc } bashdb-4.2-0.8/lib/dbg-call.sh0000644000175000017500000000322111221051765012573 00000000000000# -*- shell-script -*- # This program needs to be SOURCE'd and is not called as an executable # Copyright (C) 2006, 2007, 2008 Rocky Bernstein rocky@gnu.org # # 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 # Software Foundation; either version 2, or (at your option) any later # version. # # bashdb is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with bashdb; see the file COPYING. If not, write to the Free Software # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. # # Enter the debugger at the calling stack frame. This is useful to # hard-code a breakpoint at a given point in a program, even if the code # is not otherwise being debugged. # Leaving this the debugger terminates the program. # Any parameters after the first one are exec'd. In this way you can # force specific options to get set. _Dbg_debugger() { set -o functrace if (( $# > 0 )) ; then step_ignore=$1 shift else typeset step_ignore=${_Dbg_step_ignore:-''} fi while (( $# > 0 )) ; do eval $1 shift done if [[ -z $_Dbg_set_trace_init ]] ; then _Dbg_set_trace_init=1 _Dbg_step_ignore=${step_ignore:-0} _Dbg_write_journal "_Dbg_step_ignore=0" else _Dbg_step_ignore=${1:-1} fi trap '_Dbg_debug_trap_handler 0 "$BASH_COMMAND" "$@"' DEBUG } bashdb-4.2-0.8/lib/sort.sh0000644000175000017500000000267211221051765012126 00000000000000# Sort global array, $list, starting from $1 to up to $2. 0 is # returned if everything went okay, and nonzero if there was an error. # We use the recursive quicksort of Tony Hoare with inline array # swapping to partition the array. The partition item is the middle # array item. String comparison is used. The sort is not stable. sort_list() { (($# != 2)) && return 1 typeset -i left=$1 ((left < 0)) || (( 0 == ${#list[@]})) && return 2 typeset -i right=$2 ((right >= ${#list[@]})) && return 3 typeset -i i=$left; typeset -i j=$right typeset -i mid; ((mid= (left+right) / 2)) typeset partition_item; partition_item="${list[$mid]}" typeset temp while ((j > i)) ; do item=${list[i]} while [[ "${list[$i]}" < "$partition_item" ]] ; do ((i++)) done while [[ "${list[$j]}" > "$partition_item" ]] ; do ((j--)) done if ((i <= j)) ; then temp="${list[$i]}"; list[$i]="${list[$j]}"; list[$j]="$temp" ((i++)) ((j--)) fi done ((left < j)) && sort_list $left $j ((right > i)) && sort_list $i $right return 0 } if [[ $0 == *sorting.sh ]] ; then [[ -n $ZSH_VERSION ]] && setopt ksharrays typeset -a list list=() sort_list -1 0 typeset -p list list=('one') typeset -p list sort_list 0 0 typeset -p list list=('one' 'two' 'three') sort_list 0 2 typeset -p list list=(4 3 2 1) sort_list 0 3 typeset -p list fi bashdb-4.2-0.8/lib/run.sh0000644000175000017500000000162611221051765011741 00000000000000# -*- shell-script -*- # Copyright (C) 2008 Rocky Bernstein rocky@gnu.org # # 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 # Software Foundation; either version 2, or (at your option) any later # version. # # bashdb is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with bashdb; see the file COPYING. If not, write to the Free Software # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. _Dbg_not_running () { if (( ! _Dbg_running )) ; then _Dbg_errmsg 'The program is not being run.' return 0 fi return 1 } bashdb-4.2-0.8/lib/complete.sh0000644000175000017500000000607511561201554012750 00000000000000# -*- shell-script -*- # complete.sh - gdb-like command completion handling # # Copyright (C) 2006, 2011 Rocky Bernstein # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place, Suite 330, Boston, # MA 02111 USA. typeset -a _Dbg_matches; _Dbg_matches=() # Print a list of completions in global variable _Dbg_matches # for 'subcmd' that start with 'text'. # We get the list of completions from _Dbg._*subcmd*_cmds. # If no completion, we return the empty list. _Dbg_subcmd_complete() { subcmd=$1 text=$2 _Dbg_matches=() typeset list='' if [[ $subcmd == 'set' ]] ; then # Newer style list=${!_Dbg_command_help_set[@]} elif [[ $subcmd == 'show' ]] ; then # Newer style list=${!_Dbg_command_help_show[@]} else # FIXME: Older style - eventually update these. cmd="list=\$_Dbg_${subcmd}_cmds" eval $cmd fi local -i last=0 for word in $list ; do # See if $word contains $text at the beginning. We use the string # strip operatior '#' and check that some part of $word was stripped if [[ ${word#$text} != $word ]] ; then _Dbg_matches[$last]="$subcmd $word" ((last++)) fi done # return _Dbg_matches } if enable -f ${_Dbg_libdir}/builtin/readc readc 2>/dev/null ; then _Dbg_set_read_completion=1 # Turn on programmable completion shopt -s progcomp set -o emacs bind 'set show-all-if-ambiguous on' # bind 'set completion-ignore-case on' # COMP_WORDBREAKS=${COMP_WORDBREAKS//:} #bind 'TAB:dynamic-complete-history' bind 'TAB:menu-complete' _Dbg_set_read_completion=1 fi _Dbg_complete_brkpt_range() { COMPREPLY=() typeset -i i typeset -i j=0 for (( i=1; i <= _Dbg_brkpt_max; i++ )) ; do if [[ -n ${_Dbg_brkpt_line[$i]} ]] ; then ((COMPREPLY[j]+=i)) ((j++)) fi done } _Dbg_complete_num_range() { COMPREPLY=() typeset -i i typeset -i j=0 for ((i=$1; i<=$2; i++)) ; do ((COMPREPLY[j]+=i)) ((j++)) done } _Dbg_complete_level0() { # echo "level 0 called with comp_line: $COMP_LINE , comp_point: $COMP_POINT" if (( COMP_POINT > 0)) ; then typeset commands="${!_Dbg_command_help[@]}" COMPREPLY=( $(compgen -W "$commands" "$COMP_LINE") ) else COMPREPLY=( ${!_Dbg_command_help[@]} ) fi } _Dbg_complete_level_0_init() { complete -D -F _Dbg_complete_level0 } #;;; Local Variables: *** #;;; mode:shell-script *** #;;; eval: (sh-set-shell "bash") *** #;;; End: *** bashdb-4.2-0.8/lib/filecache.sh0000644000175000017500000002051311565104723013040 00000000000000# -*- shell-script -*- # filecache.sh - cache file information # # Copyright (C) 2008, 2009, 2010, 2011 Rocky Bernstein # # # 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 the Free Software Foundation; either version 2, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; see the file COPYING. If not, write to the Free Software # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. typeset _Dbg_bogus_file=' A really bogus file' # Maps a name into its canonic form which can then be looked up in filenames typeset -A _Dbg_file2canonic _Dbg_file2canonic=() # Information about a file. typeset -A _Dbg_fileinfo # Keys are the canonic expanded filename. _Dbg_filenames[filename] is # name of variable which contains text. typeset -A _Dbg_filenames _Dbg_filecache_reset() { _Dbg_filenames=() _Dbg_fileinfo=() _Dbg_file2canonic=() } _Dbg_filecache_reset # Check that line $2 is not greater than the number of lines in # file $1 _Dbg_check_line() { (( $# != 2 )) && return 1 typeset -i line_number=$1 typeset filename="$2" typeset -i max_line max_line=$(_Dbg_get_maxline "$filename") if (( $? != 0 )) ; then _Dbg_errmsg "internal error getting number of lines in $filename" return 1 fi if (( line_number > max_line )) ; then (( _Dbg_set_basename )) && filename=${filename##*/} _Dbg_errmsg "Line $line_number is too large." \ "File $filename has only $max_line lines." return 1 fi return 0 } # 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 "See 'info files' for a list of known files and" _Dbg_errmsg "'load' to read in a file." } # Print the maximum line of filename $1. $1 is expected to be # read in already and therefore stored in _Dbg_file2canonic. function _Dbg_get_maxline { (( $# != 1 )) && return -1 _Dbg_set_source_array_var "$1" || return $? typeset -r line_count_cmd="line_count=\${#$_Dbg_source_array_var[@]}" eval $line_count_cmd eval "typeset last_line; last_line=\${${_Dbg_source_array_var}[$line_count]}" # If the file had a final newline the last line of the data read in # is the empty string. We want to count the last line whether or # not it had a newline. typeset -i last_not_null=0 # [[ -z $last_line ]] && last_line_is_null=1 || last_line_is_null=0 ((line_count=line_count-last_line_is_null)) echo $line_count return $? } # Return text for source line for line $1 of filename $2 in variable # $_Dbg_source_line. # If $2 is omitted, use _Dbg_frame_filename, if $1 is omitted use # _Dbg_frame_last_lineno. The return value is put in _Dbg_source_line. _Dbg_get_source_line() { typeset -i lineno if (( $# == 0 )); then lineno=$_Dbg_frame_last_lineno else lineno=$1 shift fi typeset filename if (( $# == 0 )) ; then filename="$_Dbg_frame_last_filename" else filename="$1" fi _Dbg_readin_if_new "$filename" if (( _Dbg_set_highlight )) ; then eval "_Dbg_source_line=\${$_Dbg_highlight_array_var[lineno]}" else eval "_Dbg_source_line=\${$_Dbg_source_array_var[$lineno]}" fi } # _Dbg_is_file echoes the full filename if $1 is a filename found in files # '' is echo'd if no file found. Return 0 (in $?) if found, 1 if not. function _Dbg_is_file { if (( $# == 0 )) ; then _Dbg_errmsg "Internal debug error _Dbg_is_file(): null file to find" echo '' return 1 fi typeset find_file="$1" typeset try_find_file if [[ -z $find_file ]] ; then _Dbg_errmsg "Internal debug error _Dbg_is_file(): file argument null" echo '' return 1 fi if [[ ${find_file:0:1} == '/' ]] ; then # Absolute file name try_find_file=$(_Dbg_expand_filename "$find_file") if [[ -n ${_Dbg_filenames[$try_find_file]} ]] ; then echo "$try_find_file" return 0 fi elif [[ ${find_file:0:1} == '.' ]] ; then # Relative file name try_find_file=$(_Dbg_expand_filename "${_Dbg_init_cwd}/$find_file") # FIXME: turn into common subroutine if [[ -n ${_Dbg_filenames[$try_find_file]} ]] ; then echo "$try_find_file" return 0 fi 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]}" if [[ $basename == '\$cdir' ]] ; then basename=$_Dbg_cdir elif [[ $basename == '\$cwd' ]] ; then basename=$(pwd) fi try_find_file="$basename/$find_file" if [[ -f "$try_find_file" ]] ; then echo "$try_find_file" return 0 fi done fi echo '' return 1 } # Read $1 into _Dbg_source_*n* array where *n* is an entry in # _Dbg_filenames. Variable _Dbg_source_array_var will be set to # _Dbg_source_*n* and filename will be saved in array # _Dbg_filenames. fullname is set to the expanded filename # 0 is returned if everything went ok. function _Dbg_readin { typeset filename if (($# != 0)) ; then filename="$1" else _Dbg_frame_file filename="$_Dbg_frame_filename" fi typeset -i line_count=0 typeset -i next; next=${#_Dbg_filenames[@]} _Dbg_source_array_var="_Dbg_source_${next}" if (( _Dbg_set_highlight )) ; then _Dbg_highlight_array_var="_Dbg_highlight_${next}" fi typeset filevar typeset source_array typeset -ri NOT_SMALLFILE=1000 if [[ -z $filename ]] || [[ $filename == "$_Dbg_bogus_file" ]] ; then eval "${_Dbg_source_array_var}[0]=\"$Dbg_EXECUTION_STRING\"" else fullname=$(_Dbg_resolve_expand_filename "$filename") if [[ -r $fullname ]] ; then typeset -r progress_prefix="Reading $filename" _Dbg_file2canonic[$filename]="$fullname" _Dbg_file2canonic[$fullname]="$fullname" # Use readarray which speeds up reading greatly. typeset -ri BIGFILE=30000 if wc -l < /dev/null >/dev/null 2>&1 ; then line_count=$(wc -l < "${fullname}") if (( line_count >= NOT_SMALLFILE )) ; then _Dbg_msg_nocr "${progress_prefix} " fi fi builtin readarray -t -O 1 -c $BIGFILE \ -C "_Dbg_progess_show \"${progress_prefix}\" ${line_count}" \ $_Dbg_source_array_var < "$fullname" if (( _Dbg_set_highlight )) ; then highlight_cmd="${_Dbg_libdir}/lib/term-highlight.py $fullname" tempfile=$($highlight_cmd 2>/dev/null) if (( 0 == $? )) ; then builtin readarray -t -O 1 -c $BIGFILE \ -C "_Dbg_progess_show \"${progress_prefix}\" ${line_count}" \ $_Dbg_highlight_array_var < "$tempfile" fi [[ -r $tempfile ]] && rm $tempfile fi (( line_count > BIGFILE)) && _Dbg_progess_done else return 1 fi fi typeset -r line_count_cmd="line_count=\${#${_Dbg_source_array_var[@]}}" eval $line_count_cmd (( line_count >= NOT_SMALLFILE )) && _Dbg_msg "done." # Add $filename to list of all filenames _Dbg_filenames[$fullname]=$_Dbg_source_array_var; return 0 } # Read in file $1 unless it has already been read in. # 0 is returned if everything went ok. _Dbg_readin_if_new() { (( $# != 1 )) && return 1 typeset filename="$1" _Dbg_set_source_array_var "$filename" if [[ -z "$fullname" ]] ; then _Dbg_readin "$filename" typeset rc=$? set +xv (( $? != 0 )) && return $rc [[ -z $fullname ]] && return 1 _Dbg_set_source_array_var "$filename" || return $? fi return 0 } # Set _Dbg_source_array_var to the variable that contains file lines # for $1. Variable "fullname" will contain the expanded full filename for $1. # 0 is returned if everything went ok. _Dbg_set_source_array_var() { (( $# != 1 )) && return 1 typeset filename="$1" [[ -z $filename ]] && return 2 fullname=${_Dbg_file2canonic[$filename]} [[ -z $fullname ]] && [[ -n ${_Dbg_filenames[$filename]} ]] && { fullname="$filename" } [[ -z $fullname ]] && return 2 _Dbg_source_array_var=${_Dbg_filenames[$fullname]} [[ -z $_Dbg_source_array_var ]] && return 2 return 0 } bashdb-4.2-0.8/lib/cmd-hooks.sh0000644000175000017500000000003611535300364013013 00000000000000typeset -A _Dbg_cmdloop_hooks bashdb-4.2-0.8/lib/Makefile.in0000644000175000017500000002742711565104742012662 00000000000000# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, # 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, # Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = lib DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = SOURCES = DIST_SOURCES = am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__installdirs = "$(DESTDIR)$(pkgdatadir)" DATA = $(pkgdata_DATA) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) pkgdatadir = ${datadir}/@PACKAGE@/lib ACLOCAL = @ACLOCAL@ ALT_PACKAGE_NAME = @ALT_PACKAGE_NAME@ AMTAR = @AMTAR@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BASHVERS = @BASHVERS@ BASH_SRC = @BASH_SRC@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CMDLINE_INVOKED = @CMDLINE_INVOKED@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DBGR_MAIN = @DBGR_MAIN@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DIFF = @DIFF@ DIFF_OPTS = @DIFF_OPTS@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GIT2CL = @GIT2CL@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INTERPRETER_NAME = @INTERPRETER_NAME@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ PIC = @PIC@ PKGDATADIR = @PKGDATADIR@ RANLIB = @RANLIB@ RELSTATUS = @RELSTATUS@ RM = @RM@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ SH_PROG = @SH_PROG@ STRIP = @STRIP@ VERSION = @VERSION@ WL = @WL@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ pkgdata_DATA = $(wildcard *.sh) term-highlight.py EXTRA_DIST = $(pkgdata_DATA) MOSTLYCLEANFILES = *.orig *.rej all: all-am .SUFFIXES: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu lib/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu lib/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-pkgdataDATA: $(pkgdata_DATA) @$(NORMAL_INSTALL) test -z "$(pkgdatadir)" || $(MKDIR_P) "$(DESTDIR)$(pkgdatadir)" @list='$(pkgdata_DATA)'; test -n "$(pkgdatadir)" || list=; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgdatadir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgdatadir)" || exit $$?; \ done uninstall-pkgdataDATA: @$(NORMAL_UNINSTALL) @list='$(pkgdata_DATA)'; test -n "$(pkgdatadir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(pkgdatadir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(pkgdatadir)" && rm -f $$files tags: TAGS TAGS: ctags: CTAGS CTAGS: distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(DATA) installdirs: for dir in "$(DESTDIR)$(pkgdatadir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ `test -z '$(STRIP)' || \ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -f Makefile distclean-am: clean-am distclean-generic dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-pkgdataDATA @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) install-data-hook install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-pkgdataDATA .MAKE: install-am install-data-am install-strip .PHONY: all all-am check check-am clean clean-generic clean-libtool \ distclean distclean-generic distclean-libtool distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-data-hook install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-info install-info-am install-man \ install-pdf install-pdf-am install-pkgdataDATA install-ps \ install-ps-am install-strip installcheck installcheck-am \ installdirs maintainer-clean maintainer-clean-generic \ mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \ ps ps-am uninstall uninstall-am uninstall-pkgdataDATA install-data-hook: chmod +x $(DESTDIR)$(pkgdatadir)/term-highlight.py # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: bashdb-4.2-0.8/configure.ac0000644000175000017500000002561211564571702012332 00000000000000# Configure script for bash debugger (bashdb) dnl Process this file with autoconf to produce a configure script. # Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011 # Rocky Bernstein # 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 # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to the # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA. dnl TENTATIVE: dnl Use same version as in main bash configure.in define(DEBUGGER, bashdb) define(POSIXSHELL, bash) define(OK_BASH_VERS, 4.2) define(relstatus, 0.8) AC_INIT([bashdb],[OK_BASH_VERS-relstatus],[bashdb-devel@lists.sourceforge.net]) # From fish's configure.ac # # List of output variables produced by this configure script # AC_SUBST(BASHVERS) AC_SUBST(RELSTATUS) AC_ARG_WITH(bashdb-main, AC_HELP_STRING([--with-bashdb-main], [location of bashdb-main.inc]), BASHDB_MAIN=$withval) # See if we build set0.c AC_ARG_WITH(bash-src, AC_HELP_STRING([--with-bash-src], [location of bash OK_BASH_VERS source code]), BASH_SRC=$withval) AC_SUBST(BASH_SRC) AC_PROG_CC if test x"$BASH_SRC" != x ; then if test ! -d $BASH_SRC ; then AC_MSG_ERROR([bash source directory ($BASH_SRC) doesn't seem to be a directory]) else AM_PROG_CC_C_O dnl We run a C compiler to get macro EXEEXT set and possibly readarray.c. PIC=$lt_prog_compiler_pic_CXX WL=$lt_prog_compiler_wl_CXX build_set0=$BASH_SRC AC_CHECK_HEADERS(unistd.h string.h,, [AC_MSG_WARN([Missing some C headers. Disabling set0]) build_set0=]) fi fi AM_CONDITIONAL(BUILD_BUILTINS, test x"$build_set0" != x) AM_PROG_LIBTOOL PIC=$lt_prog_compiler_pic_CXX WL=$lt_prog_compiler_wl_CXX AC_SUBST(PIC) AC_SUBST(WL) AC_SUBST(DIFF) AC_SUBST(DIFF_OPTS) CMDLINE_INVOKED='$0 == ${BASH_SOURCE}' AC_SUBST(CMDLINE_INVOKED) AM_MAINTAINER_MODE AM_CONFIG_HEADER(config.h) AC_DEFINE([PACKAGE], [bashdb], [Bash Debugger]) AC_DEFINE([VERSION], [OK_BASH_VERS-relstatus], [version string]) dnl make sure we are using a recent autoconf version AC_PREREQ(2.53) AC_ARG_PROGRAM AM_INIT_AUTOMAKE([no-define]) AC_BASHDB_PACKAGE([bashdb]) # Brought over from bash/configure.in to substitute OK_BASH_VERS # and RELSTATUS in bashdb.in and version.texi BASHVERS=OK_BASH_VERS RELSTATUS=relstatus AC_CONFIG_SRCDIR(DEBUGGER.in) if test x$ac_srcdir = x ; then ac_srcdir=. fi AM_MISSING_PROG(GIT2CL, git2cl, $missing_dir) AC_PROG_LN_S AC_PATH_PROG(RM, rm, true) ## --with-bash can be used to tell the bashdb script and the regression ## test which bash to run. It can be omitted too in which case we'll ## look for a bash binary. AC_ARG_WITH(POSIXSHELL, AC_HELP_STRING([--with-POSIXSHELL], [location of POSIXSHELL program]), SH_PROG=$withval) if test "$SH_PROG" = "yes" || test "$SH_PROG" = "no" || test -z "$SH_PROG" then AC_PATH_PROG(SH_PROG, POSIXSHELL, no) fi if test "$SH_PROG" = no; then AC_MSG_ERROR([I didn't find the DEBUGGER executable.\ You might want to use the --with-DEBUGGER option.]) fi bash_version=`$SH_PROG --version` [bash_major=`$SH_PROG -c 'echo ${BASH_VERSINFO[0]}'`] [bash_minor=`$SH_PROG -c 'echo ${BASH_VERSINFO[1]}'`] bash_4_or_greater=no case "${bash_major}.${bash_minor}" in 'OK_BASH_VERS' | '4.1') bash_4_or_greater=yes ;; *) AC_MSG_WARN([You have Bash $bash_version installed.]) AC_MSG_ERROR([This package is only known to work with Bash 4.1 or 4.2.]) ;; esac AC_ARG_WITH(dbg-main, AC_HELP_STRING([--with-dbg-main], [location of dbg-main.sh]), DBGR_MAIN=$withval) AC_SUBST(DBGR_MAIN) if test -z "$DBGR_MAIN" ; then DBGR_MAIN=`strings $SH_PROG$EXEEXT | grep bashdb-main.inc` if test -z "$DBGR_MAIN" ; then AC_MSG_ERROR([I didn't find bashdb-main.inc in your bash. If you have the right version of bash, set it with the --with-dbg-main option]) fi fi # Create a suitable transform ( without the $ -> $$ escaping added # because of $program_transform_name being used in a Makefile # This transform is needed because bashdb must be executed by the # bashdb-bash regardless if a program transform has taken place ac_transform=`echo "$program_transform_name" | sed 's/\\$\\$/\\$/g'` # Fully expanded name of bash executable to be substituted into # bashdb.This allow us to move this package into any suitable location # by using --prefix as an option to configure. AC_SUBST_DIR(INTERPRETER_NAME,"${bindir}/"`echo bash | sed "$ac_transform"`) # WARNING: The configure-correct name for architecture-independent # directory (the place for the bash source for the debugger) is # datadir. The automake file seem to want to use pkgdatadir instead. # I'm not sure how to get these to agree. # Also, I'd like to set the default to the name that's been coded # inside of the bash program rather than some autoconf standard; I # don't know how to change the autoconf default that which is # determined dynamically below. # Get the fully expanded name of pkgdatadir. This is used in bashdb.in # and dbg-main.sh.in and for installing debugger files. pkgdatadir=$datadir/DEBUGGER AC_SUBST_DIR(PKGDATADIR, $pkgdatadir) dnl We use a diff in regression testing AC_PATH_PROG(DIFF, diff, no) DIFF_OPTS= if test "$DIFF" = no ; then AC_PATH_PROG(DIFF, cmp, no) else dnl Try for GNU diff options. # MSDOG output uses \r\n rather than \n in tests for diff_opt in -w --unified -b ; do if $DIFF $diff_opt $0 $0 > /dev/null 2>&1; then AC_MSG_RESULT([adding $diff_opt to diff in regression tests]) DIFF_OPTS="$DIFF_OPTS $diff_opt" fi done fi #Makefiles AC_CONFIG_FILES([ \ Makefile \ builtin/Makefile \ command/Makefile \ command/info_sub/Makefile \ command/set_sub/Makefile \ command/show_sub/Makefile \ data/Makefile \ doc/Makefile \ init/Makefile \ lib/Makefile \ test/Makefile \ test/data/Makefile \ test/example/Makefile \ test/integration/Makefile \ test/unit/Makefile \ test/unit/require_me.sh \ ]) # Additional files needing substitution of values (not Makefiles). AC_CONFIG_FILES([bashdb], [chmod +x DEBUGGER]) AC_CONFIG_FILES([test/example/bugIFS.sh], [chmod +x test/example/bugIFS.sh]) AC_CONFIG_FILES([test/example/hanoi.sh], [chmod +x test/example/hanoi.sh]) AC_CONFIG_FILES([test/example/interrupt.sh], [chmod +x test/example/interrupt.sh]) AC_CONFIG_FILES([test/example/bug-args.sh], [chmod +x test/example/bug-args.sh]) AC_CONFIG_FILES([test/unit/test-action.sh], [chmod +x test/unit/test-action.sh]) AC_CONFIG_FILES([test/unit/test-alias.sh], [chmod +x test/unit/test-alias.sh]) AC_CONFIG_FILES([test/unit/test-bashdb-trace.sh], [chmod +x test/unit/test-bashdb-trace.sh]) AC_CONFIG_FILES([test/unit/test-break.sh], [chmod +x test/unit/test-break.sh]) AC_CONFIG_FILES([test/unit/test-cmd-complete.sh], [chmod +x test/unit/test-cmd-complete.sh]) AC_CONFIG_FILES([test/unit/test-columns.sh], [chmod +x test/unit/test-columns.sh]) AC_CONFIG_FILES([test/unit/test-eval.sh], [chmod +x test/unit/test-eval.sh]) AC_CONFIG_FILES([test/unit/test-file.sh], [chmod +x test/unit/test-file.sh]) AC_CONFIG_FILES([test/unit/test-filecache.sh], [chmod +x test/unit/test-filecache.sh]) AC_CONFIG_FILES([test/unit/test-get-sourceline.sh], [chmod +x test/unit/test-get-sourceline.sh]) AC_CONFIG_FILES([test/unit/test-fns.sh], [chmod +x test/unit/test-fns.sh]) AC_CONFIG_FILES([test/unit/test-frame.sh], [chmod +x test/unit/test-frame.sh]) AC_CONFIG_FILES([test/unit/test-lib-list.sh], [chmod +x test/unit/test-lib-list.sh]) AC_CONFIG_FILES([test/unit/test-msg.sh], [chmod +x test/unit/test-msg.sh]) AC_CONFIG_FILES([test/unit/test-io.sh], [chmod +x test/unit/test-io.sh]) AC_CONFIG_FILES([test/unit/test-pre.sh], [chmod +x test/unit/test-pre.sh]) AC_CONFIG_FILES([test/unit/test-require.sh], [chmod +x test/unit/test-require.sh]) AC_CONFIG_FILES([test/unit/test-run.sh], [chmod +x test/unit/test-run.sh]) AC_CONFIG_FILES([test/unit/test-save-restore.sh], [chmod +x test/unit/test-save-restore.sh]) AC_CONFIG_FILES([test/unit/test-set0.sh], [chmod +x test/unit/test-set0.sh]) AC_CONFIG_FILES([test/unit/test-sort.sh], [chmod +x test/unit/test-sort.sh]) AC_CONFIG_FILES([test/unit/test-validate.sh], [chmod +x test/unit/test-validate.sh]) AC_CONFIG_FILES([test/integration/test-bug-step-subshell], [chmod +x test/integration/test-bug-step-subshell]) AC_CONFIG_FILES([test/integration/test-debug], [chmod +x test/integration/test-debug]) AC_CONFIG_FILES([test/integration/test-delete], [chmod +x test/integration/test-delete]) AC_CONFIG_FILES([test/integration/test-export], [chmod +x test/integration/test-export]) AC_CONFIG_FILES([test/integration/test-misc], [chmod +x test/integration/test-misc]) AC_CONFIG_FILES([test/integration/test-setshow], [chmod +x test/integration/test-setshow]) AC_CONFIG_FILES([test/integration/test-info-args], [chmod +x test/integration/test-info-args]) AC_CONFIG_FILES([test/integration/test-sig], [chmod +x test/integration/test-sig]) AC_CONFIG_FILES([ \ bashdb-main.inc \ bashdb-trace \ doc/macros.texi \ test/integration/check-common.sh \ ]) AC_CONFIG_COMMANDS([default],[[ # Keep old dates on these files to prevent rebuilding. touch -cr $ac_srcdir/configure.ac doc/bashdb.1 touch -cr $ac_srcdir/configure.ac doc/bashdb-man.html if test -e $ac_srcdir/doc/version-bashdb.texi ; then echo timestamp > $ac_srcdir/doc/stamp-vti touch -cr $ac_srcdir/configure.ac $ac_srcdir/doc/version-bashdb.texi \ $ac_srcdir/doc/stamp-vti \ $ac_srcdir/doc/bashdb.info* fi ]],[[]]) AC_OUTPUT echo echo "=========================================================" echo "Bash version: $bash_version" echo "Location: $SH_PROG" if test x"$build_set0" != x; then echo "We will try to build the set0 builtin to set variable \$0" echo "using source located at ${BASH_SRC}." elif test "$bash_4_or_greater" = no ; then echo 'We will not try to build the set $0 builtin.' fi bashdb-4.2-0.8/doc/0000755000175000017500000000000011565106266010663 500000000000000bashdb-4.2-0.8/doc/fdl.texi0000644000175000017500000004401311221051765012235 00000000000000@c -*-texinfo-*- @node GNU Free Documentation License @appendix GNU Free Documentation License @center Version 1.1, March 2000 @display Copyright (C) 2000 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @end display @sp 1 @enumerate 0 @item PREAMBLE The purpose of this License is to make a manual, textbook, or other written document ``free'' in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of ``copyleft'', which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference. @sp 1 @item APPLICABILITY AND DEFINITIONS This License applies to any manual or other work that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. The ``Document'', below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as ``you.'' A ``Modified Version'' of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A ``Secondary Section'' is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (For example, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them. The ``Invariant Sections'' are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. The ``Cover Texts'' are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A ``Transparent'' copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, whose contents can be viewed and edited directly and straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup has been designed to thwart or discourage subsequent modification by readers is not Transparent. A copy that is not ``Transparent'' is called ``Opaque.'' Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML designed for human modification. Opaque formats include PostScript, PDF, proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML produced by some word processors for output purposes only. The ``Title Page'' means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, ``Title Page'' means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. @sp 1 @item VERBATIM COPYING You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies. @sp 1 @item COPYING IN QUANTITY If you publish printed copies of the Document numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a publicly-accessible computer-network location containing a complete Transparent copy of the Document, free of added material, which the general network-using public has access to download anonymously at no charge using public-standard network protocols. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document. @sp 1 @item MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version: A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.@* B. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has less than five).@* C. State on the Title page the name of the publisher of the Modified Version, as the publisher.@* D. Preserve all the copyright notices of the Document.@* E. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.@* F. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.@* G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.@* H. Include an unaltered copy of this License.@* I. Preserve the section entitled ``History'', and its title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section entitled ``History'' in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.@* J. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the ``History'' section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.@* K. In any section entitled ``Acknowledgements'' or ``Dedications'', preserve the section's title, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.@* L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.@* M. Delete any section entitled ``Endorsements.'' Such a section may not be included in the Modified Version.@* N. Do not retitle any existing section as ``Endorsements'' or to conflict in title with any Invariant Section.@* @sp 1 If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section entitled ``Endorsements'', provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. @sp 1 @item COMBINING DOCUMENTS You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections entitled ``History'' in the various original documents, forming one section entitled ``History''; likewise combine any sections entitled ``Acknowledgements'', and any sections entitled ``Dedications.'' You must delete all sections entitled ``Endorsements.'' @sp 1 @item COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document. @sp 1 @item AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, does not as a whole count as a Modified Version of the Document, provided no compilation copyright is claimed for the compilation. Such a compilation is called an ``aggregate'', and this License does not apply to the other self-contained works thus compiled with the Document, on account of their being thus compiled, if they are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one quarter of the entire aggregate, the Document's Cover Texts may be placed on covers that surround only the Document within the aggregate. Otherwise they must appear on covers around the whole aggregate. @sp 1 @item TRANSLATION Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License provided that you also include the original English version of this License. In case of a disagreement between the translation and the original English version of this License, the original English version will prevail. @sp 1 @item TERMINATION You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. @sp 1 @item FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License ``or any later version'' applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. @end enumerate @unnumberedsec ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: @smallexample @group Copyright (C) @var{year} @var{your name}. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being @var{list their titles}, with the Front-Cover Texts being @var{list}, and with the Back-Cover Texts being @var{list}. A copy of the license is included in the section entitled "GNU Free Documentation License." @end group @end smallexample If you have no Invariant Sections, write ``with no Invariant Sections'' instead of saying which ones are invariant. If you have no Front-Cover Texts, write ``no Front-Cover Texts'' instead of ``Front-Cover Texts being @var{list}''; likewise for Back-Cover Texts. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software. bashdb-4.2-0.8/doc/gpl.texi0000644000175000017500000004464211221051765012262 00000000000000@ignore @c Set file name and title for man page. @setfilename gpl @settitle GNU General Public License @c man begin SEEALSO gfdl(7), fsf-funding(7). @c man end @c man begin COPYRIGHT Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @c man end @end ignore @node Copying @c man begin DESCRIPTION @appendix GNU GENERAL PUBLIC LICENSE @center Version 2, June 1991 @display Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @end display @unnumberedsec Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software---to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. @iftex @unnumberedsec TERMS AND CONDITIONS FOR COPYING,@*DISTRIBUTION AND MODIFICATION @end iftex @ifnottex @center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION @end ifnottex @enumerate 0 @item This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The ``Program'', below, refers to any such program or work, and a ``work based on the Program'' means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term ``modification''.) Each licensee is addressed as ``you''. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. @item You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. @item You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: @enumerate a @item You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. @item You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. @item If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) @end enumerate These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. @item You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: @enumerate a @item Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, @item Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, @item Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) @end enumerate The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. @item You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. @item You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. @item Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. @item If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. @item If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. @item The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and ``any later version'', you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. @item If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. @iftex @heading NO WARRANTY @end iftex @ifnottex @center NO WARRANTY @end ifnottex @item BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. @item IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. @end enumerate @iftex @heading END OF TERMS AND CONDITIONS @end iftex @ifnottex @center END OF TERMS AND CONDITIONS @end ifnottex @page @unnumberedsec How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the ``copyright'' line and a pointer to where the full notice is found. @smallexample @var{one line to give the program's name and a brief idea of what it does.} Copyright (C) @var{year} @var{name of author} 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 the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @end smallexample Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: @smallexample Gnomovision version 69, Copyright (C) @var{year} @var{name of author} Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. @end smallexample The hypothetical commands @samp{show w} and @samp{show c} should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than @samp{show w} and @samp{show c}; they could even be mouse-clicks or menu items---whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a ``copyright disclaimer'' for the program, if necessary. Here is a sample; alter the names: @smallexample Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. @var{signature of Ty Coon}, 1 April 1989 Ty Coon, President of Vice @end smallexample This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. @c man end bashdb-4.2-0.8/doc/macros.texi.in0000644000175000017500000000043011221051765013354 00000000000000@c A simple macro for optional variables. @macro ovar{varname} @r{[}@var{\varname\}@r{]} @end macro @macro DDD {} @acronym{DDD} @end macro @macro BASH {} @acronym{@value{BASH}} @end macro @macro DBG {} @value{DBG} @end macro @set libdir @prefix@/lib @set bindir @prefix@/bin bashdb-4.2-0.8/doc/bashdb.texi0000644000175000017500000050126211535300364012717 00000000000000\input texinfo @c -*-texinfo-*- @c Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009 @c Rocky Bernstein for the Free Software Foundation @c @c TODO: @c - add examples for commands @c - clean up/improve sample session @c - help text is inaccurate and formatted too much to right. @c @c Sets version and release names and dates. Frees us from changing @c this file when a new release comes along. @c %**start of header @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use @c of @set vars. However, you can override filename with makeinfo -o. @setfilename bashdb.info @c @c Name of Bash program. Used in running text. @c @c Name of debugger program. Used also for prompt string. @set BASH @acronym{BASH} @set DBG the @value{BASH} debugger @set dBGP The @value{BASH} debugger @set DDD @acronym{DDD} @set Emacs @sc{gnu} Emacs @settitle @value{BASH} Debugger @setchapternewpage odd @c %**end of header @include version.texi @include macros.texi @c Karl Berry informs me that this will add straight quotes in @c typewriter text. @c See the "Inserting Quote Characters" node in the Texinfo manual @set txicodequoteundirected @set txicodequotebacktick @iftex @c @smallbook @c @cropmarks @end iftex @finalout @c readline appendices use @vindex, @findex and @ftable, @c annotate.texi and gdbmi use @findex. @c @syncodeindex vr cp @c @syncodeindex fn cp @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER. @c This is a dir.info fragment to support semi-automated addition of @c manuals to an info tree. @dircategory Programming & development tools. @direntry * Bashdb - the bash debugger: (bashdb). The @sc{bash} debugger @end direntry @ifinfo This file documents the @sc{bash} debugger @value{BASH}. This is the @value{EDITION} Edition, @value{UPDATED}, of @cite{Debugging with BASHDB: the @sc{gnu} Source-Level Debugger} for BASH Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009 Rocky Bernstein for the Free Software Foundation. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or @ifset DEBIANHASBECOMEREASONABLE @c From Matthias Klose a Debian maintainer on @c Sat, 23 Aug 2003 14:24:44 +0200 @c @c I personally see the invariant sections as the thing in the @c GFDL, which hinders me in uploading the package to the archives. @c I don't have any problem, if some other Debian developer makes a @c bashdb package built from separate sources. @c @c I am aware that Debian ships other packages containing documentation @c covered by the GFDL (and one of them for which I do the packaging as @c well), but I won't add a new package, which I maintain. So before an @c upload of a bashdb package built from the bash sources either @c @c @c - Debian has a position on the GFDL, which allows inclusion @c @c - the bashdb manual does not have invariant sections, or is @c relicensed, or dual licensed. @c any later version published by the Free Software Foundation; with the Invariant Sections being ``Free Software'' and ``Free Software Needs Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' and with the Back-Cover Texts as in (a) below. (a) The Free Software Foundation's Back-Cover Text is: ``You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.'' @end ifset @ifclear DEBIANHASBECOMEREASONABLE any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. @end ifclear @end ifinfo @titlepage @title Debugging with BASHDB @sp 1 @subtitle @value{EDITION} Edition, for BASH @subtitle @value{UPDATED-MONTH} @author Rocky Bernstein @page @tex {\parskip=0pt \hfill (Send bugs and comments on bashdb to bug-bashdb\@sourceforge.net.)\par \hfill {\it Debugging with BASH}\par \hfill \TeX{}info \texinfoversion\par } @end tex @vskip 0pt plus 1filll Copyright @copyright{} 2002, 2003, 2004, 2006, 2007, 2008, 2009 Rocky Bernstein for the Free Software Foundation. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or @ifset DEBIANHASBECOMEREASONABLE @c From Matthias Klose a Debian maintainer on @c Sat, 23 Aug 2003 14:24:44 +0200 @c @c I personally see the invariant sections as the thing in the @c GFDL, which hinders me in uploading the package to the archives. @c I don't have any problem, if some other Debian developer makes a @c bashdb package built from separate sources. @c @c I am aware that Debian ships other packages containing documentation @c covered by the GFDL (and one of them for which I do the packaging as @c well), but I won't add a new package, which I maintain. So before an @c upload of a bashdb package built from the bash sources either @c @c @c - Debian has a position on the GFDL, which allows inclusion @c @c - the bashdb manual does not have invariant sections, or is @c relicensed, or dual licensed. @c @c any later version published by the Free Software Foundation; with the Invariant Sections being ``Free Software'' and ``Free Software Needs Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' and with the Back-Cover Texts as in (a) below. (a) The Free Software Foundation's Back-Cover Text is: ``You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.'' @end ifset @ifclear DEBIANHASBECOMEREASONABLE any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. @end ifclear @end titlepage @page @ifnottex @node Top, Summary, (dir), (dir) @top Debugging with @DBG This file describes @value{DBG}, the @sc{bash} symbolic debugger. This is the @value{EDITION} Edition, @value{UPDATED}, for BASH. Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009 Rocky Bernstein @menu * Summary:: Overview of Debugger with a sample session * Invocation:: Getting in and out * Running:: Script setup inside the BASH debugger * Debugger Command Reference:: BASH debugger command reference * Front Ends:: Using the Debugger from a front-end user interface * BASH Debugger Bugs:: Reporting bugs * History and Acknowledgments:: History and Acknowledgments Appendices * Copying:: GNU General Public License says how you can copy and share bashdb * GNU Free Documentation License:: The license for this documentation Indexes (nodes containing large menus) * Function Index:: An item for each function name. * Command Index:: An item for each command name. * Variable Index:: An item for each documented variable. * General Index:: An item for each concept. @end menu @end ifnottex @contents @node Summary @chapter Summary of the BASH Debugger The purpose of a debugger such as @DBG is to allow you to see what is going on ``inside'' a bash script while it executes. @DBG can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: @itemize @bullet @item Start your script, specifying anything that might affect its behavior. @item Make your script stop on specified conditions. @item Examine what has happened, when your script has stopped. @item Change things in your script, so you can experiment with correcting the effects of one bug and go on to learn about another. @end itemize Although you can use the @acronym{BASH} debugger to debug scripts written in @acronym{BASH}, it can also be used just as a front-end for learning more about programming in @acronym{BASH}. As an additional aid, the debugger can be used within the context of an existing script with its functions and variables that have already been initialized; fragments of the existing can be experimented with by entering them inside the debugger. @menu * Sample Session:: A Sample BASH Debugger session * Interactive Line Tracing Session:: Interactive Line Tracing Session @end menu @node Sample Session @section A Sample BASH Debugger Session You can use this manual at your leisure to read all about @value{DBG}. However, a handful of commands are enough to get started using the debugger. This chapter illustrates those commands. @iftex In this sample session, we emphasize user input like this: @b{input}, to make it easier to pick out from the surrounding output. @end iftex Below we will debug a script that contains a function to compute the factorial of a number: fact(0) is 1 and fact(n) is n*fact(n-1). @smallexample $ @b{bashdb -L . /tmp/fact.sh} Bourne-Again Shell Debugger, release bash-@value{VERSION} Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009 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. (/tmp/fact.sh:9): 9: echo fact 0 is: `fact 0` bashdb<0> @b{-} 1: #!/usr/local/bin/bash 2: fact() @{ 3: ((n==0)) && echo 1 && return 4: ((nm1=n-1)) 5: ((result=n*`fact $nm1`)) 6: echo $result 7: @} 8: 9:==> echo fact 0 is: `fact 0` bashdb<1> @b{list} 10: echo fact 3 is: $(fact 3) @end smallexample @noindent The command invocation uses the option ``-L .'' Here we assume that the @command{bashdb} script and the debugger files are in the same location. If you are running from the source code, this will be the case. However if bashdb has been installed this probably won't be true and here you probably don't need to use ``-L .'' Instead you would type simply @code{bashdb /tmp/fact.sh}. Position information consists of a filename and line number, e.g. @code{(/tmp/fact.sh:9)} and is given parenthesis. This position format is similar to that used by the Perl debugger and is also in the same format used by my GNU make debugger (@url{http://bashdb.sourceforge.net/remake}) the Extended Python Debugger @url{http://remake.sourceforge.net/pydb}, and one for Ruby (@url{http://bashdb.sorceforge.net/ruby-debug.html}). GNU Emacs and DDD can parse this and in fact the same regular expression is used on the 3 debuggers. The first debugger command we gave @kbd{-}, we listed a window of lines @emph{before} where we were executing. Because the window, 10 lines, is larger than the number of lines to the top of the file we printed only 9 lines here. The next command, @code{list}, starts from the current line and again wants to print 10 lines but because there are only one remaining line, that is what is printed. @smallexample @cartouche bashdb<2> @b{step} (/tmp/fact.sh:9): fact 0 9: echo fact 0 is: `fact 0` bashdb<(3)> @b{@key{RET}} 2: fact() @{ bashdb<(4)> @b{@key{RET}} 3: ((n==0)) && echo 1 && return bashdb<(5)> @b{print $n} bashdb<(6)> @end cartouche @end smallexample Ooops... The variable @kbd{n} isn't initialized.@footnote{Recall that variables in @value{BASH} don't need to be declared before they are referred to and that the default value would be the a null value which here prints as an empty string.} The first @kbd{step} command steps the script one instruction. It may seem odd that the line printed is exactly the same one as before. What has happened though is that we've ``stepped'' into the subshell needed to run @kbd{`fact 0`}; we haven't however started running anything inside that subshell yet though. To indicate that which piece of the multi-part line @code{echo fact 0 is: `fact 0`} we show that part all by itself @kbd{fact 0}. If nothing is shown then it means we are running the beginning statement or in this case the outermost statement. To indicate that we are now nested in a subshell, notice that the command number, starting with 3, or the third command entered, now appears in parenthesis. Each subshell nesting adds a set of parenthesis. The first @kbd{step} command steps the script one instruction; it didn't advance the line number, 9, at all. That is because we were stopping before the command substitution or backtick is to take place. The second command we entered was just hitting the return key; bashdb remembers that you entered @code{step} previously, so it runs the step rather than @kbd{next}, the other alternative when you hit @key{RET}. Step one more instruction and we are just before running the first statement of the function. Next, we print the value of the variable @kbd{n}. Notice we need to add a preceding dollar simple to get the substitution or value of n. As we will see later, if the @kbd{pe} command were used this would not be necessary. We now modify the file to add an assignment to local variable @kbd{n} and restart. @smallexample @cartouche bashdb<6> @b{restart} Restarting with: /usr/local/bin/bashdb -L . fact.sh (/tmp/fact.sh:10): 10: echo fact 0 is: `fact 0` bashdb<0> @b{list 1} 1: #!/usr/local/bin/bash 2: fact() @{ 3: local -i n=$@{1:0@} 4: ((n==0)) && echo 1 && return 5: ((nm1=n-1)) 6: ((result=n*`fact $nm1`)) 7: echo $result 8: @} 9: 10:==> echo fact 0 is: `fact 0` bashdb<1> @b{s 3} (/tmp/fact.sh:3): 3: local -i n=$@{1:0@} bashdb<(2)> @b{step} (/tmp/fact.sh:4): 4: ((n==0)) && echo 1 && return bashdb<(3)> @b{print $n} print $n 0 @end cartouche @end smallexample @noindent This time we use the @code{list} debugger command to list the lines in the file. From before we know it takes three @code{step} commands before we get into the fact() function, so we add a count onto the @code{step} command. Notice we abbreviate @code{step} with @code{s}; we could have done likewise and abbreviated @code{list} with @code{l}. @smallexample @cartouche bashdb<(4)> @b{@key{RET}} (/tmp/fact.sh:4): 4: ((n==0)) && echo 1 && return echo 1 bashdb<(5)> @b{@key{RET}} (/tmp/fact.sh:4): 4: ((n==0)) && echo 1 && return return @end cartouche @end smallexample @noindent Again we just use @key{RET} to repeat the last @code{step} commands. And again the fact that we are staying on the same line 4 means that the next condition in the line is about to be executed. Notice that we see the command (@code{echo 1} or @code{return}) listed when we stay on the same line which has multiple stopping points in it. Given the information above, we know that the value echo'ed on return will be 1. @smallexample @cartouche bashdb<(6)> @b{@key{RET}} fact 0 is: 1 (/tmp/fact.sh:12): 12: echo fact 3 is: $(fact 3) bashdb<(7)> @b{break 5} Breakpoint 1 set in file fact.sh, line 5. bashdb<(8)> @b{continue} @end cartouche @end smallexample @noindent We saw that we could step with a count into the function fact(). However above took another approach: we set a stopping point or ``breakpoint'' at line 5 to get us a little ways into the fact() subroutine. Just before line 5 is to executed, we will get back into the debugger. The @code{continue} command just resumes execution until the next stopping point which has been set up in some way. @smallexample @cartouche (/tmp/fact.sh:5): 5: ((nm1=n-1)) Breakpoint 1 hit(1 times). bashdb<(8)> @b{x n-1} 2 bashdb<(9)> @b{s} (/tmp/fact.sh:5): 6: ((result=n*`fact $nm1`)) bashdb<(10)> @b{c} fact.sh: line 6: ((: result=n*: syntax error: operand expected (error token is "*") bashdb<(7)> @b{R} Restarting with: bash --debugger fact.sh 11: echo fact 0 is: `fact 0` bashdb<0> @b{l fact} 2: fact () 3: @{ 4: local -i n=$@{1:0@}; 5: (( "n==0" )) && echo 1 && return; 6: (( nm1=n-1 )); 7: ((fact_nm1=`fact $nm1`)) 8: (( "result=n*fact_nm1" )); 9: echo $result 10: @} @end cartouche @end smallexample @noindent In addition to listing by line numbers, we can also list giving a function name. Below, instead of setting a breakpoint at line 5 and running ``@code{continue}'' as we did above, we try something slightly shorter and slightly different. We give the line number on the ``continue'' statement. This is a little different in that a one-time break is made on line 5. Once that statement is reached the breakpoint is removed. @smallexample @cartouche bashdb<1> @b{continue 5} One-time breakpoint 1 set in file fact.sh, line 5. fact 0 is: 1 (/tmp/fact.sh:5): 5: ((nm1=n-1)) bashdb<(2)> @b{s} 6: ((fact_nm1=`fact $nm1`)) bashdb<(3)> @b{s} 2: fact() @{ bashdb<(4)> @b{T} ->0 in file `fact.sh' at line 2 ##1 fact("3") called from file `fact.sh' at line 12 ##2 source("fact.sh") called from file `/usr/local/bin/bashdb' at line 154 ##3 main("fact.sh") called from file `/usr/local/bin/bashdb' at line 0 bashdb<(5)> @b{c} fact 3 is: 6 Debugged program terminated normally. Use q to quit or R to restart. @end cartouche @end smallexample @noindent When we stop at line 5 above, we have already run fact(0) and output the correct results. The output from the program ``fact 0 is: 1'' is intermixed with the debugger output. The @code{T} command above requests call stack output and this confirms that we are not in the fact(0) call but in the fact(3) call. There are 4 lines listed in the stack trace even though there is just one call from the main program. The top line of the trace doesn't really represent a call, it's just where we currently are in the program. That last line is an artifact of invoking bash from the bashdb script rather than running @code{bash --debugger}. The last message in the output above @samp{Debugged program exited normally.} is from @value{DBG}; it indicates script has finished executing. We can end our bashdb session with the bashdb @code{quit} command. Above we did our debugging session on the command line. If you are a GNU Emacs user, you can do your debugging inside that. Also there is a(nother) GUI interface called DDD that supports @value{DBG}. @node Interactive Line Tracing Session @section Interactive Line Tracing Session @anchor{PS4} @cindex @code{$PS4} One of the things I had found disappointing about the default @code{set -x} tracing behavior is that no position information is given in the trace output, in particular the line number and the file name. However with the introduction in Bash 3.0 of the introspection variables, also needed to support the debugger, one can set @code{$PS4} to rectify this. (I became of this in a defunct blog @url{http://raz.cx/blog/2005/08/handy-bash-debugging-trick.html}.) Here's what I use: @smallexample PS4='($@{BASH_SOURCE@}:$@{LINENO@}): $@{FUNCNAME[0]@} - [$@{SHLVL@},$@{BASH_SUBSHELL@}, $?] ' @end smallexample Note that the string is in single quotes, not double quotes and there is a newline in the string. By using single quotes, variables which have a dollar in front of them in the string are expanded in the current environment of the line that is about to be run rather than at the time the variable @code{PS4} is set. You might want to add this in your shell's start-up script, e.g., @code{.bashrc}, or @code{.profile}. There is also facility inside the bash debugger showing position information when tracing a script. Here's a simple session. @smallexample @b{/usr/local/bin/bashdb /tmp/fact.sh} Bourne-Again Shell Debugger, release bash-@value{VERSION} Copyright 2002, 2003, 2004, 2006, 2007, 2008 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. (/tmp/fact.sh:11): 11: echo fact 0 is: `fact 0` bashdb<0> @b{set linetrace on} bashdb<1> @b{cont} (/tmp/fact.sh:11): level 1, subshell 1, depth 0: echo fact 0 is: `fact 0` fact 0 (/tmp/fact.sh:2): level 1, subshell 1, depth 1: fact() @{ (/tmp/fact.sh:3): level 1, subshell 1, depth 1: local -i n=$@{1:0@} (/tmp/fact.sh:4): level 1, subshell 1, depth 1: ((n==0)) && echo 1 && return (/tmp/fact.sh:4): level 1, subshell 1, depth 1: ((n==0)) && echo 1 && return echo 1 (/tmp/fact.sh:4): level 1, subshell 1, depth 1: ((n==0)) && echo 1 && return return fact 0 is: 1 (/tmp/fact.sh:13): level 1, subshell 0, depth 0: echo fact 3 is: $(fact 3) (/tmp/fact.sh:13): level 1, subshell 1, depth 0: echo fact 3 is: $(fact 3) fact 3 (/tmp/fact.sh:2): level 1, subshell 1, depth 1: fact() @{ (/tmp/fact.sh:3): level 1, subshell 1, depth 1: local -i n=$@{1:0@} (/tmp/fact.sh:4): level 1, subshell 1, depth 1: ((n==0)) && echo 1 && return (/tmp/fact.sh:5): level 1, subshell 1, depth 1: ((nm1=n-1)) (/tmp/fact.sh:6): level 1, subshell 1, depth 1: ((fact_nm1=`fact $nm1`)) (/tmp/fact.sh:6): level 1, subshell 2, depth 1: ((fact_nm1=`fact $nm1`)) fact $nm1 (/tmp/fact.sh:2): level 1, subshell 2, depth 2: fact() @{ ... level 1, subshell 4, depth 4: fact() @{ (/tmp/fact.sh:3): level 1, subshell 4, depth 4: local -i n=$@{1:@} (/tmp/fact.sh:4): level 1, subshell 4, depth 4: ((n==0)) && echo 1 && return (/tmp/fact.sh:4): level 1, subshell 4, depth 4: ((n==0)) && echo 1 && return echo 1 (/tmp/fact.sh:4): level 1, subshell 4, depth 4: ((n==0)) && echo 1 && return return (/tmp/fact.sh:7): level 1, subshell 3, depth 3: ((result=n*fact_nm1)) (/tmp/fact.sh:8): level 1, subshell 3, depth 3: echo $result (/tmp/fact.sh:7): level 1, subshell 2, depth 2: ((result=n*fact_nm1)) (/tmp/fact.sh:8): level 1, subshell 2, depth 2: echo $result (/tmp/fact.sh:7): level 1, subshell 1, depth 1: ((result=n*fact_nm1)) (/tmp/fact.sh:8): level 1, subshell 1, depth 1: echo $result fact 3 is: 6 (/usr/local/bin/bashdb:260): level 1, subshell 0, depth -1: Debugged program terminated normally. Use q to quit or R to restart. bashdb<2> @end smallexample An explanation of the output. The @emph{level} is how many invocations of @value{BASH} are in effect before the statement shown is executed. The @emph{subshell} is how many subshells you are nested in. Subshells are used by command substitution---@code{`..'} and @code{$(...)}---as well as arithmetic expressions @code{((...))}. The @emph{depth} is the function depth or how many calls you are nested in. A ``source'' command also increases this depth. Notice also that in contrast to @code{set -x} tracing, the line shown is exactly as you entered it in the source. So if you indented statements in a meaningful way, it will help you understand the statement nesting level. But as before, if a line contains multiple statements, you are @emph{not} executing the first statement in the line and @code{set showcommand} is not turned off (by default it is on), that statement is shown in addition below the multi-statement line. Such an example can be seen right at the beginning where @code{fact 0} is shown. If what you want to do is trace the @emph{entire} script as was done above (and not stop in the debugger when the script is over), you can get the same effect by using the @code{-X} or @code{--trace} option on the @code{bashdb} command: @smallexample @b{/usr/local/bin/bashdb -X /tmp/fact.sh} Bourne-Again Shell Debugger, release bash-@value{VERSION} Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009 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. (/usr/local/bin/bashdb:272): level 1, subshell 0, depth -1: . $_source_file (/tmp/fact.sh:11): level 1, subshell 0, depth 0: echo fact 0 is: `fact 0` (/tmp/fact.sh:11): level 1, subshell 1, depth 0: echo fact 0 is: `fact 0` fact 0 (/tmp/fact.sh:2): level 1, subshell 1, depth 1: fact() @{ (/tmp/fact.sh:3): level 1, subshell 1, depth 1: local -i n=$@{1:0@} ... level 1, subshell 2, depth 2: echo $result (/tmp/fact.sh:7): level 1, subshell 1, depth 1: ((result=n*fact_nm1)) (/tmp/fact.sh:8): level 1, subshell 1, depth 1: echo $result fact 3 is: 6 (/usr/local/bin/bashdb:285): level 1, subshell 0, depth -1: @end smallexample If you issue a break (e.g.@: send a @code{SIGINT} signal) while the program is running you will go into the debugger (assuming your program doesn't trap @code{SIGINT}). @node Invocation @chapter Getting in and out This chapter discusses how to start @value{DBG}, and how to get out of it. The essentials are: @itemize @bullet @item type @samp{bash --debugger @emph{script-name}} or @samp{bashdb @emph{script-name}} to start @value{DBG}. Or... @item type @samp{bashdb -c @emph{command string}} to give a string to run under the debugger. Or .. @item modify your program to enter the debugger at a particular point: @code{source ../bashdb-trace} and @code{_Dbg_debugger}. @item type @kbd{quit} or @kbd{C-d} inside the debugger to exit. @end itemize There are also two front-ends available as well. One can also enter the debugger inside emacs via the command @code{M-x bashdb} after loading Emacs' Grand Unified Debugger, @code{gud}. See @ref{Emacs,,Using the BASH debugger from @value{Emacs}}. And there is support in a @value{DDD} for bash. @menu * Starting the BASH debugger:: How to enter the BASH debugger * Quitting the BASH debugger:: How to leave the BASH debugger * Calling from Program:: Calling the debugger from inside your program @end menu @node Starting the BASH debugger @section Starting the BASH debugger @emph{Note: it is important to use a debugger-enabled bash. You will get an error message if the debugger is run under a version of BASH that does not have debugging support.} As mentioned above, one can enter @DBG via Emacs or DDD. However you don't have to use either of these. And these still need a way on their own to get things started. There are in fact two @emph{other} ways to start @value{DBG}. The first way is to pass the @samp{--debugger} option to bash with the name of your script the scripts arguments following that, or with a command string (@code{-c}). @example bash --debugger @var{script} @var{script-arguments...} bash --debugger -c @var{command-string}... @end example This calls a debugger initialization script. It works much like a @acronym{BASH} login profile which may set variables and define functions. But this shell profile is customized for debugging and as such arranges for itself to get called before each statement is executed. Although there are some problems at present in I/O redirection that the method described next doesn't have, it is expected that over time more features will be enabled in bash when the @samp{--debugger} option is in effect. By default, both debugging in Emacs via GUD (@ref{Emacs,,Using the BASH debugger under Emacs}) and debugging via @value{DDD} work via this method. The form @samp{bash --debugger -c ...} can be used to get into the debugger without having to give a script name to debug. Sometimes you may want to do this just to see how the debugger works: try some debugger commands or maybe get online help. If you run @code{ddd --bash} without giving a script name, it in fact uses this form. In order for the @samp{--debugger} option to work however, you must have the debugger scripts installed in a place where @DBG can find them. For this reason, in developing @value{DBG}, I use a second method more often; it doesn't require the bash debugger to be installed. This method uses another script called @code{bashdb} which allows for giving its own options, the final option is signaled by adding @code{--}). After this, the name of the script to debugged and any the arguments to pass to that script are given. Using this method, one would start the debugger like this: @example bash @var{path-to-bashdb}/bashdb @var{bashdb-options} -- @var{script} @var{script-arguments...} @end example If you don't need to pass dash options to your program which might get confused with the debugger options, then you don't need to add the @code{--}.@footnote{And in the interest of full disclosure, although this was not shown in the example it is possible to add the @code{--} @emph{after} the script name to be debugged but before the first program option with a dash.} As with the first method, @code{bash} should be a debugger-enabled bash. If @code{bashdb} has the path to bash in it at the top (e.g.@: via @code{#!}), and @code{bashdb} can be found in your program-search path, then this might be equivalent to the above: @example bashdb @var{bashdb-options} -- @var{script} @var{script-arguments...} @end example There are two or three disadvantages however of running a debugger this way. First @code{$0} will have the value @code{bashdb} rather than the script you are trying to run. For some scripts this may change the behavior of the debugged script. Second a traceback will contain additional lines showing the ``source''-ing of the debugged script from @code{bashdb}. And third, although this way works better than the first method, over time this way may come into disuse. An option that you'll probably need to use if bashdb isn't installed but run out of the source code directory is @samp{-L} which specifies the directory that contains the debugger script files. You can further control how bashdb starts up by using command-line options. bashdb itself can remind you of the options available. @noindent Type @example bashdb -h @end example @noindent to display all available options and briefly describe their use. When the bash debugger is invoked either by the @code{bashdb} front-end script or @code{bash --debugging}, the first argument that does not have an associated option flag for @code{bashdb} or @code{bash} (as the case may be) is used as the name a the script file to be debugged, and any following options get passed the debugged script. Options for the @code{bashdb} front-end are shown in the following list. @menu * Options for the bashdb script:: Options you can pass in starting bashdb @end menu @node Options for the bashdb script @subsection Command-line options for @code{bashdb} script You can run @DBG in various alternative modes---for example, in batch mode or quiet mode. @table @code @item -h | --help @cindex @code{-h} @cindex @code{--help} This option causes @value{DBG} to print some basic help and exit. @item -V | --version @cindex @code{-V} This option causes @DBG to print its version number, no-warranty blurb, and exit. @item -A | --annodate @var{level} @cindex @code{-A} @cindex @code{--annotate} Add additional output which allows front-ends to track what's going on without having to poll for such vital information. The default annotation level is 0 (none). If you are running inside GNU Emacs using the Emacs code from this package, an annotation level 3 when set will allow for automatic tracking of frames and breakpoints. @xref{Annotate}. @item -c | --command @var{cmd} @cindex @code{-c} @cindex @code{--command} Run the string instead of running a script @item -B | --basename @cindex @code{-B} @cindex @code{--basename} This option causes @DBG to print its version number and no-warranty blurb, and exit. @item -n | --nx | --no-init @cindex @code{-n} @cindex @code{--nx} @cindex @code{--no-init} Do not execute commands found in any initialization files. Normally, @acronym{BASH} executes the commands in these files after all the command options and arguments have been processed. @xref{Command Files,,Command files}. @item -q | --quiet @cindex @code{-q} @cindex @code{--quiet} ``Quiet''. Do not print the introductory and copyright messages. These messages are also suppressed in batch mode. @item -t | --terminal | --tty @var{tty} @cindex @code{-t} @cindex @code{--terminal} @cindex @code{--tty} ``Terminal output''. Set the file or terminal that you want debugger command output to go to. Note that the debugger output is independent of the debugged script output. @item -x | --eval-command @cindex @code{-x} @cindex @code{--eval-command} @var{cmdfile} execute debugger commands from @var{cmdfile}. @item -L | --library @var{directory} @cindex @code{-L} @cindex @code{--library} Set directory where debugger files reside to @var{directory}. The default location is @code{../lib/bashdb} relative to the place that the bashdb script is located. For example if bashdb is located in @code{@value{bindir}/bashdb}, the default library location will be @code{@value{libdir}/bashdb} which may or may not exist. If it doesn't you'll get an error when you run bashdb. Only if the default location is incorrect, should you need to use the @code{-L} option. @item -T | --tempdir @var{directory} @cindex @code{-T} @cindex @code{--tempdir} Set directory to use for writing temporary files. @end table @node Quitting the BASH debugger @section Quitting the BASH debugger @cindex interrupt An interrupt (often @kbd{C-c}) does not exit from @value{DBG}, but rather terminates the action of any @DBG command that is in progress and returns to @value{DBG} command level. Inside a debugger command interpreter, use @code{quit} command (@pxref{Quit, ,Quitting the BASH debugger}). There way to terminate the debugger is to use the @code{kill} command. This does more forceful @code{kill -9}. It can be used in cases where @code{quit} doesn't work. @node Calling from Program @section Calling the BASH debugger from inside your program Running a program from the debugger adds a bit of overhead and slows down your program quite a bit. Addressing this better would mean some serious changes to @value{BASH} internals, and judging from experience in other languages there still the slowdown is still noticeable. If you have a @code{configure} script generated by autoconf, and you want to stop in the middle of the script, it can take quite a while. Furthermore, by necessity, debuggers change the operation of the program they are debugging. And this can lead to unexpected and unwanted differences. It has happened so often that the term ``Heisenbugs'' (see @url{http://en.wikipedia.org/wiki/Heisenbug}) was coined to describe the situation where the addition of the use of a debugger (among other possibilities) changes behavior of the program so that the bug doesn't manifest itself anymore. There is another way to get into the debugger aside from calling @code{bashdb} from the outset, and this adds no overhead or slowdown until you reach the point at which you want to start debugging. However for this method you must change the script. Because the debugger isn't involved before the first call, there is no overhead; the script will run at the same speed as if there were no debugger up to the point where it is first invoked. @menu * Debugging a Running Shell Script:: * Program-Controlled Line Tracing:: @end menu @node Debugging a Running Shell Script @subsection Debugging a Running Shell Script In this section we'll show how to modify your script so that it enters the debugger when you send it a signal, and then we will show how you can call the debugger directly. In either case, you'll need to modify the script to load some the debugger code. The name of file to load is @code{bashdb-trace} and it is located in the directory where the other bash debugger files live. For example on GNU/Linux if it is in directory @code{/usr/local/share/bashdb}, you would first add to a @value{BASH} script the line: @smallexample source /usr/local/share/bashdb/bashdb-trace @end smallexample Although I said that running under the debugger adds overhead which slows down you program, the above command in of itself will @emph{not} cause any slowdown. If possible, it's best to put this somewhere in the main-line code rather than in a function or in a subshell. If it is put in a function of subshell and you step outside of that, some of the global variables set up in @code{bashdb-trace} may be lost. One the other hand if you know your debugging will be confined to just the scope of the @code{source} command there is no problem. Here's a complete example. In file @file{debugit.sh} @smallexample # This is my extra debug hook source @emph{/usr/share/bashdb/bashdb-trace} # adjust location echo $$ while : ; do date=$(date) echo "$date" sleep 2 done @end smallexample Now run: @smallexample $ @b{bash ./debugit.sh} Bourne-Again Shell Debugger, release bash-3.1-0.08 Copyright 2002, 2003, 2004, 2006 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. 9435 Thu Jun 19 02:43:06 EDT 2008 Thu Jun 19 02:43:08 EDT 2008 @end smallexample Sent it an "interrupt" signal @smallexample @b{kill -INT 9435} @end smallexample And back to the running program: @smallexample Program received signal SIGINT (2)... ->0 in file `./debugit.sh' at line 251 # not sure where 251 came from! ##1 main() called from file `./debugit.sh' at line 0 bashdb<0> where ->0 in file `./debugit.sh' at line 9 # but this line number is now right ##1 main() called from file `./debugit.sh' at line 0 bashdb<1> @b{list 1} 1: # Set up some interrupt handlers to go into the debugger 2: source /usr/share/bashdb/bashdb-trace 3: 4: echo $$ 5: while : ; do 6: date=$(date) 7: echo "$date" 8: sleep 2 9:==>done bashdb<2> @b{step} (./debugit.sh:5): 5: while : ; do bashdb<3> @b{step} (./debugit.sh:6): 6: date=$(date) bashdb<4> @b{continue -} @end smallexample The command @code{continue -} not only continues execution but it removes the debug trap allowing the program to run at full speed. It is suitable only if there are no breakpoints that you care to stop at. By default, @code{bashdb-trace} sets up a handler for the @samp{INT} exception. If you down't want this or you want enter the debugger on a different signal to be use, @code{_Dbg_handler}. With this function you can specify whether to show a call stack, stop (enter the debugger) and/or print an indication that the a signal was seen. Here are some examples: @smallexample _Dbg_handler INT print showstack nostop # this is the default _Dbg_handler INT # same thing _Dbg_hander # same thing _Dbg_handler HUP print stop # stop in debugger when getting @end smallexample @subsubsection Explicit Debugging Calls. As we saw in the last section @code{bashdb-trace} installs some signal handlers. However you can make an explicit call to the debugger @smallexample _Dbg_debugger @end smallexample Let's show an example of that. We'll even do it under a condition: @smallexample for ((i=1; i<=10; i++)) ; (( 5 == i )) && @{ _Dbg_debugger @} date=$(date) echo "$date" sleep 2 done @end smallexample The debugger will be called on the 5th iteration of this loop, when @code{i} has the value 5. You can also supply the number of statements to skip and the options to @code{_Dbg_debugger} just as you would to the debugger itself. All of the options listed in @ref{Options for the bashdb script} can be used with the exception of @code{-c} (run a command) and of course you don't supply the name of a @value{BASH} script. For example to stop at the next line and suppress the banner you could use @code{_Dbg_debugger 1 -q} in the above example. @node Program-Controlled Line Tracing @subsection Program-Controlled Line Tracing You can also turn on and off line tracing. Here's an example @smallexample source @emph{path-to-program}/bashdb-trace # modify location ... _Dbg_linetrace_on for i in `seq 10` ; do echo $i done _Dbg_linetrace_off _Dbg_QUIT_ON_QUIT=1 @end smallexample The @code{_Dbg_QUIT_ON_QUIT} variable make sure the program doesn't stay inside the debugger after it quits. It can also be set earlier in the program. Again @code{} is whatever path needed to located @code{}. For example it might be @code{} on some GNU/Linux installations. @node Running @chapter Script Setup inside the BASH Debugger @menu * Starting:: Starting your script * Command Files:: Command files * Arguments:: Your script's arguments * Input/Output:: Your script's input and output * Script/Debugger Interaction:: Keeping out of each other's harm @end menu @need 2000 @node Starting @section Starting your script @cindex starting @cindex running After invoking the debugger you should be on the first stoppable line of your program to be debugged. At this point you can issue debugger commands to set breakpoints (@pxref{Set Breaks, ,Setting breakpoints}), or watchpoints (@pxref{Set Watchpoints, ,Setting watchpoints}), or start continue the execution of the program (@pxref{Resuming Execution, ,Resuming Execution}). @table @code @kindex restart @ovar{args} @kindex run @r{(@code{restart})} @kindex R @r{(@code{restart})} @item restart @ovar{args} @itemx run @ovar{args} @itemx R @ovar{args} Use the @code{restart} command to restart your script under @value{DBG}. Without any arguments, the script name and parameters from the last invocation are used. @value{dBGP} tries to maintain the settings, watchpoints, breakpoints, actions and so on. Internally it uses line numbers and filenames to record he position of interesting places in your porgram; so if your program changes some or all of these numbers may be off. Environment variable @code{DBG_RESTART_FILE} is and a temporary file are used to signal a restart, so you shouldn't uset @code{DBG_RESTART_FILE} (or any environment variable starting with @code{BASHDB_}. @end table @node Command Files @section Command files @cindex command files A command file for @DBG is a file of lines that are @DBG commands. Comments (lines starting with @kbd{#}) may also be included. An empty line in a command file does nothing; it does not mean to repeat the last command, as it would from the terminal. @cindex init file @cindex @file{.bashdbinit} @cindex @file{bashdb.ini} When you start @value{DBG}, it automatically executes commands from its @dfn{init files}, normally called @file{.bashdbinit}@footnote{The DJGPP port of @DBG uses the name @file{bashdb.ini} instead, due to the limitations of file names imposed by DOS filesystems.}. During startup, @DBG does the following: @enumerate @item Reads the init file (if any) in your home directory@footnote{On DOS/Windows systems, the home directory is the one pointed to by the @code{HOME} environment variable.}. @item Processes command line options and operands. @item Reads the init file (if any) in the current working directory. @item Reads command files specified by the @samp{-x} option. @end enumerate The init file in your home directory can set options (such as @samp{set complaints}) that affect subsequent processing of command line options and operands. Init files are not executed if you use the @samp{-x} option (@pxref{Options for the bashdb script, ,bashdb script options}). @cindex init file name On some configurations of @value{DBG}, the init file is known by a different name (these are typically environments where a specialized form of @DBG may need to coexist with other forms, hence a different name for the specialized version's init file). These are the environments with special init file names: You can also request the execution of a command file with the @code{source} command: @table @code @kindex source @item source @var{filename} Execute the command file @var{filename}. @end table The lines in a command file are executed sequentially. They are not printed as they are executed. If there is an error, execution proceeds to the next command in the file. @node Arguments @section Your script's arguments @cindex arguments (to your script) The arguments to your script can be specified by the arguments of the @code{restart} command. They are passed to a shell, which expands wildcard characters and performs redirection of I/O, and thence to your script. @code{restart} with no arguments uses the same arguments used by the previous @code{restart}, or those set by the @code{set args} command.. @table @code @kindex set args @item set args Specify the arguments to be used if your program is rerun. If @code{set args} has no arguments, @code{restart} executes your program with no arguments. Once you have run your program with arguments, using @code{set args} before the next @code{restart} is the only way to run it again without arguments. @kindex show args @item show args Show the arguments to give your program when it is started. @end table @node Input/Output @section Your script's input and output @cindex redirection @cindex I/O @cindex terminal By default, the script you run under the @acronym{BASH} debugger does input and output to the same terminal that @acronym{BASH} uses. Before running the script to be debugged, the debugger records the tty that was in effect. All of its output is then written to that. However you can change this when using the @samp{bashdb} script using the @samp{-t} option. @table @code @kindex info terminal @item info terminal Displays information recorded by @DBG about the terminal modes your program is using. @end table @kindex tty @cindex controlling terminal Another way to specify where your script should do input and output is with the @code{tty} command. This command accepts a file name as argument, and causes this file to be the default for future @code{restart} commands. It also resets the controlling terminal for the child process, for future @code{restart} commands. For example, @example tty /dev/ttyb @end example @noindent directs that processes started with subsequent @code{restart} commands default to do input and output on the terminal @file{/dev/ttyb} and have that as their controlling terminal. An explicit redirection in @code{restart} overrides the @code{tty} command's effect on the input/output device, but not its effect on the controlling terminal. When you use the @code{tty} command or redirect input in the @code{restart} command, only the input @emph{for your script} is affected. The input for @DBG still comes from your terminal. @node Script/Debugger Interaction @section Script/Debugger Interaction @value{dBGP} and your program live in the same variable space so to speak. @acronym{BASH} does not have a notion of module scoping or lexical hiding (yet) as is found in modern programming langauges and in modern versions of the Korn shell. This then imposes some additional care and awareness. Most of the variables and functions used inside @DBG start @code{_Dbg_}, so please don't use variables or functions with these names in your program. @emph{Note: there are some other variables that begin with just an underscore (@code{_}); over time these will be phased out. But until then, avoid those or consult what is used by the debugger. Run @samp{bashdb --debugger -c "declare -p"} to list all the variables in use including those used by the debugger.} A number of environment variables are also reserved for use; these start with @code{DBG_}. For example: @env{DBG_INPUT}, @env{DBG_LEVEL} and, @env{_Dbg_QUIT_ON_QUIT} (@pxref{Debug, ,Debug}), @env{DBG_RESTART_FILE} (@pxref{Starting, ,Starting}), to name a few. Finally, there are some @acronym{BASH} environment dynamic variables and these start with @env{BASH_}. For example @env{BASH_SUBSHELL} (@pxref{Debug, ,Debug}), @env{BASH_COMMAND} (@pxref{Command Display, ,Command Display}), @env{BASH_LINENO}, and @env{BASH_SOURCE} to name a few. Inside the debugger some variables may be redefined. In particular @code{IFS} and @code{PS4}, and various dollar variables @code{$?}, @code{$1}, @code{$2}, etc. The values before entering the debugger are saved and those variables have their old values restroed when leaving the debugger. However you may notice these difference in various debugger commands. For example @code{examine PS4} might not return the same value as @code{eval declare -p PS4}. The former is picking the debugger value while the @code{eval} is careful to restore the value to what it was before entering the debugger. In order to do its work @value{dBGP} sets up a @code{DEBUG} trap. Consequently a script shouldn't reset this or the debugger will lose control. @value{dBGP} also sets up an @code{EXIT} handler so that it can gain control after the script finishes. Another signal intercepted is the an interrupt or @code{INT} signal. For more information about signal handling, @pxref{Signals, ,Signals} @node Debugger Command Reference @chapter BASH Debugger Command Reference You can abbreviate the long name of @DBG command to the first few letters of the command name, if that abbreviation is unambiguous; and you can repeat the @code{next} or @code{step} commands by typing just @key{RET}. Some commands which require a parameter, such as @code{print} remember the argument that was given to them. @menu * Command Syntax:: How to give commands to the BASH debugger * Help:: How to ask for help (help) * Quit:: Leaving the debugger (quit, kill) * Stopping:: Stopping and continuing (break, watch, step, cont...) * Stack:: Examining the stack frame (where, up, down, frame) * List:: Printing source files (list) * Edit:: Editing source files (edit) * Search:: Searching source files (/pat/ ?pat?) * Data:: Examining data (print, examine, info variables) * Auto Display:: Executing expressions on stop (display, undisplay) * Evaluation/Execution:: Arbitrary execution (eval, eval? shell) * Interfacing to the OS:: Interfacing to the OS (cd, pwd) * Information and Settings:: Status and Debugger settings (info, show) * Controlling bashdb:: Controlling bashdb (annotate, file, prompt, history...) @end menu @node Command Syntax @section Command syntax A @acronym{BASH} debugger command is a single line of input. There is no limit on how long it can be. It starts with a command name, which is followed by arguments whose meaning depends on the command name. For example, the command @code{step} accepts an argument which is the number of times to step, as in @samp{step 5}. You can also use the @code{step} command with no arguments. Some commands do not allow any arguments. @cindex repeating next/step commands @kindex RET @r{(repeat last command)} A blank line as input to @DBG (typing just @key{RET}) means to repeat the previous next or step command. @kindex # @r{(a comment)} @cindex comment Any text from a @kbd{#} to the end of the line is a comment; it does nothing. This is useful mainly in command files (@pxref{Command Files,,Command files}). @node Help @section Getting help (@samp{help}) @cindex online documentation Once inside the @acronym{BASH} debugger, you can always ask it for information on its commands, using the command @code{help}. @table @code @kindex h @r{(@code{help})} @item help @itemx h You can use @code{help} (abbreviated @code{h}) with no arguments to display a short list of named classes of commands: @end table @flushleft @smallexample bashdb<0> @b{help} Available commands: action debug eval help print set step- untrace alias delete examine history pwd shell step+ up backtrace disable export info quit show tbreak watch break display file kill restart signal trace watche commands down finish list return skip tty condition edit frame load reverse source unalias continue enable handle next search step undisplay Readline command line editing (emacs/vi mode) is available. Type "help" followed by command name for full documentation. @end smallexample @end flushleft @c the above line break eliminates huge line overfull... @table @code @item help @var{command} With a command name as @code{help} argument, the @acronym{BASH} debugger displays short information on how to use that command. @example bashdb<0> @b{help list} list [START|.|FN] [COUNT] -- List lines of a script. START is the starting line or dot (.) for current line. Subsequent list commands continue from the last line listed. If a function name is given list the text of the function. If COUNT is omitted, use the setting LISTSIZE. Use "set listsize" to change this setting. Aliases for list: l @end example In addition to @code{help}, you can use the debugger command @code{info} to inquire about the state of your script, or the state of @DBG itself. The listings under @code{info} in the Index point to all the sub-commands. @xref{Command Index}. @end table @c @group @table @code @kindex info @kindex i @r{(@code{info})} @item info This command (abbreviated @code{i}) is for describing the state of your program. For example, you can list the arguments given to your script with @code{info args}, or list the breakpoints you have set with @code{info breakpoints}. You can get a complete list of the @code{info} sub-commands with @w{@code{help info}}. @example bashdb<0> @b{help info} List of info subcommands: info args -- Argument variables (e.g. $1, $2, ...) of the current stack frame. info breakpoints -- Status of user-settable breakpoints info display -- Show all display expressions info files -- Source files in the program info functions -- All function names info line -- list current line number and and file name info program -- Execution status of the program. info signals -- What debugger does when program gets various signals info source -- Information about the current source file info stack -- Backtrace of the stack info terminal -- Print terminal device info variables -- All global and static variable names info warranty -- Various kinds of warranty you do not have Aliases for info: i bashdb<1> @b{info source} Current script file is parm.sh Located in /tmp/parm.sh Contains 34 lines. @end example @end table @node Quit @section Quitting the BASH debugger (@samp{quit}, @samp{kill}) @table @code @kindex quit @r{[}@var{expression} @ovar{subshell-levels}@r{]} @kindex q @r{(@code{quit})} @item quit @ovar{expression} @item quit @r{[}@var{expression} @ovar{subshell-levels}@r{]} @itemx q To exit @value{DBG}, use the @code{quit} command (abbreviated @code{q}), or type an end-of-file character (usually @kbd{C-d}). If you do not supply @var{expression}, @DBG will try to terminate normally or with exit code 0. Otherwise it will terminate using the result of @var{expression} as the exit code. A simple @code{quit} tries to terminate all nested subshells that may be in effect. If you are nested a subshell, this is normally indicated in a debugger prompt by the number of parentheses that the history number is inside --- no parenthesis means there is no subshell in effect. The dynamic variable @env{BASH_SUBSHELL} also contains the number of subshells in effect. If you want only to terminate some number of subshells but not all of them, you can give a count of the number of subshells to leave after the return-code expression. To leave just one level of subshell @code{return} does almost the same thing. (See @pxref{Returning, ,Returning}) There is a subtle difference between the two though: @code{return} will leave you at the beginning of the next statement while @code{quit} may leave you at the place the subshell was invoked which may be in the middle of another command such as an assingment statement or condition test. If the environment variable @code{_Dbg_QUIT_ON_QUIT} is set, when the program terminates, the debugger will also terminate too. This may be useful if you are debugging a script which calls another script and you want this inner script just to return to the outer script. @item kill @kindex k @r{(@code{kill})} @itemx k In situations where @code{quit} doesn't work we provide an alternative and more forceful quit command: @code{kill}. This sends to the OS non-maskable KILL signal with the debugger process number. No cleanup of temporary files is done by the program. @end table @node Stopping @section Stopping and Resuming Execution One important use of a debugger is to stop your program @emph{before} it terminates so that if your script might run into trouble, you can investigate and find out why. However should your script accidently continue to termination, @DBG has arranged for it not to leave the debugger without your explicit instruction. That way, you can restart the program using the same command arguments. Inside @value{DBG}, your script may stop for any of several reasons, such as a signal, a breakpoint, or reaching a new line after a debugger command such as @code{step}. You may then examine and change variables, set new breakpoints or remove old ones, and then continue execution. @menu * Breakpoints:: Breakpoints, watchpoints (break, tbreak, watch, watche, clear) * Resuming Execution:: Resuming execution (continue, step, next, skip, finish, return, debug) * Signals:: Signals @end menu @node Breakpoints @subsection Breakpoints, watchpoints (@samp{break}, @samp{tbreak}, @samp{watch}, @samp{watche}...) @cindex breakpoints A @dfn{breakpoint} makes your script stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your script stops. You specify the place where your script should stop with the @code{break} command and its variants (@pxref{Set Breaks, ,Setting breakpoints}). These commands allow own to specify the location by line number and file name or function name. @cindex watchpoints @cindex breakpoint on variable modification A @dfn{watchpoint} is a special breakpoint that stops your script when the value of an expression changes. There is a different command to set watchpoints (@pxref{Set Watchpoints, ,Setting watchpoints}). But aside from that, you can manage a watchpoint like any other breakpoint: you delete enable, and disable both breakpoints and watchpoints using the same commands. You can arrange to have values from your program displayed automatically whenever @value{BASH} stops at a breakpoint. @xref{Auto Display,, Automatic display}. @cindex breakpoint numbers @cindex numbers for breakpoints @value{dBGP} assigns a number to each breakpoint when you create it; these numbers are successive integers starting with one. In many of the commands for controlling various features of breakpoints you use the breakpoint number to say which breakpoint you want to change. Each breakpoint may be @dfn{enabled} or @dfn{disabled}; if disabled, it has no effect on your script until you enable it again. @cindex watchpoints numbers @cindex numbers for watchpoints Watchpoint numbers however are distinguished from breakpoint numbers by virtue of their being suffixed with the either an upper- or lower-case `W'. For example, to enable breakpoint entry 0 along with watchpoint entry 1 you would write @samp{enable 1 2w}, the ``2w'' refers to the watchpoint; ``2W'' would work just as well. @ifset FINISHED @cindex breakpoint ranges @cindex ranges of breakpoints Some @DBG commands accept a range of breakpoints on which to operate. A breakpoint range is either a single breakpoint number, like @samp{5}, or two such numbers, in increasing order, separated by a hyphen, like @samp{5-7}. When a breakpoint range is given to a command, all breakpoint in that range are operated on. @end ifset @menu * Set Breaks:: Setting breakpoints (break, tbreak) * Set Watchpoints:: Setting watchpoints (watch, watche) * Break Commands:: Breakpoint command lists (command) * Delete Breaks:: Deleting breakpoints (delete, clear) * Disabling:: Disabling breakpoints (disable, enable) * Conditions:: Break conditions (condition) @end menu @node Set Breaks @subsubsection Setting breakpoints (@samp{break} @samp{tbreak}) @kindex break @kindex b @r{(@code{break})} @cindex latest breakpoint Breakpoints are set with the @code{break} command (abbreviated @code{b}). @table @code @item break @var{function} Set a breakpoint at entry to function @var{function}. @item break @var{linenum} Set a breakpoint at line @var{linenum} in the current source file. The current source file is the last file whose source text was printed. The breakpoint will stop your script just before it executes any of the code on that line. @item break @var{filename}:@var{linenum} Set a breakpoint at line @var{linenum} in source file @var{filename}; @var{filename} has to be one of the files previously read in and has to be specified exactly as the name used when read in. For a list of read-in files, use the @samp{info files} command. @ifset FINISHED @item break When called without any arguments, @code{break} sets a breakpoint at the next instruction to be executed in the selected stack frame (@pxref{Stack, ,Examining the Stack Frame}). In any selected frame but the innermost, this makes your script stop as soon as control returns to that frame. If you use @code{break} without an argument in the innermost frame, @DBG stops the next time it reaches the current location; this may be useful inside loops. @end ifset @item break @dots{} if @var{cond} Set a breakpoint with condition @var{cond}; evaluate the expression @var{cond} each time the breakpoint is reached, and stop only if the value is nonzero---that is, if @var{cond} evaluates as true. The expression is evaluated via the @code{let} builtin funtion. @samp{@dots{}} stands for one of the possible arguments described above (or no argument) specifying where to break. The word ``if'' is often optional and is necessary only @samp{@dots{}} is omitted. @xref{Conditions, ,Break conditions}, for more information on breakpoint conditions. Examples: @example bashdb<0> @b{break fn1} Breakpoint 1 set in file parm.sh, line 3. bashdb<1> @b{break 28} Breakpoint 2 set in file parm.sh, line 28. bashdb<2> @b{break parm.sh:29} Breakpoint 3 set in file parm.sh, line 29. bashdb<3> @b{break 28 if x==5} Breakpoint 4 set in file parm.sh, line 28. @end example @kindex tbreak @item tbreak @var{args} Set a breakpoint enabled only for one stop. @var{args} are the same as for the @code{break} command, and the breakpoint is set in the same way, but the breakpoint is automatically deleted after the first time your program stops there. @xref{Disabling, ,Disabling breakpoints}. @kindex info breakpoints @cindex @code{$_} and @code{info breakpoints} @item info breakpoints @ovar{n} @itemx info break @ovar{n} @itemx info watchpoints @ovar{n} Print a table of all breakpoints, watchpoints set and not deleted, with the following columns for each breakpoint: @table @emph @item Breakpoint Numbers (@samp{Num}) @item Enabled or Disabled (@samp{Enb}) Enabled breakpoints are marked with @samp{1}. @samp{0} marks breakpoints that are disabled (not enabled). @item Count The number of times that breakpoint or watchpoint has been hit. @item File and Line (@samp{file:line}) The filename and line number inside that file where of breakpoint in the script. The file and line are separated with a colon. @item Condition A condition (an arithmetic expression) which when true causes the breakpoint to take effect. @end table @noindent If a breakpoint is conditional, @code{info break} shows the condition on the line following the affected breakpoint; breakpoint commands, if any, are listed after that. @noindent @code{info break} displays a count of the number of times the breakpoint has been hit. @code{info break} with a breakpoint number @var{n} as argument lists only that breakpoint. Examples: @example bashdb<4> @b{info break} Breakpoints at following places: Num Type Disp Enb What 1 breakpoint keep y parm.sh:3 2 breakpoint keep y parm.sh:28 3 breakpoint keep y parm.sh:29 4 breakpoint keep y parm.sh:28 No watch expressions have been set. bashdb<5> @b{info break 4} Num Type Disp Enb What 4 breakpoint keep y parm.sh:28 No watch expressions have been set. @end example @end table @ifset FINISHED This is especially useful in conjunction with the @code{ignore} command. You can ignore a large number of breakpoint hits, look at the breakpoint info to see how many times the breakpoint was hit, and then run again, ignoring one less than that number. This will get you quickly to the last hit of that breakpoint. @end ifset @DBG allows you to set any number of breakpoints at the same place in your script. There is nothing silly or meaningless about this. When the breakpoints are conditional, this is even useful (@pxref{Conditions, ,Break conditions}). @node Set Watchpoints @subsubsection Setting watchpoints (@samp{watch}, @samp{watche}) @cindex setting watchpoints You can use a watchpoint to stop execution whenever the value of an expression changes, without having to predict a particular place where this may happen. As with the @code{print} (@pxref{Data,,Examining Data}), the idiosyncracies of a @acronym{BASH} or any POSIX shell derivative suggest using two commands. The @code{watch} command is just for a single variables; the @code{watche} command uses the builtin ``let'' command to evaluate an expression. If the variable you are tracking can take a string value, issuing something like @samp{watch foo} will not have the desired effect---any string assignment to @code{foo} will have a value 0 when it is assigned via ``let.'' @table @code @kindex watch @item watch @var{var} Set a watchpoint for a variable. @DBG will break when the value of @var{var} changes. In this command do not add a leading dollar symbol to @var{var}. @item watche @var{expr} Set a watchpoint for an expression via the builtin ``let'' command. @DBG will break when @var{expr} is written into by the program and its value changes. Not that this may not work for tracking arbitrary string value changes. For that use @code{watch} described earlier. @end table @node Break Commands @subsubsection Breakpoint command lists (@samp{commands}) @table @code @kindex commands @kindex end @item commands @r{[}@var{bnum}@r{]} @itemx @dots{} @var{command-list} @dots{} @itemx end Specify a list of commands for breakpoint number @var{bnum}. The commands themselves appear on the following lines. Type a line containing just @code{end} to terminate the commands. To remove all commands from a breakpoint, type @code{commands} and follow it immediately with @code{end}; that is, give no commands. With no @var{bnum} argument, @code{commands} refers to the last breakpoint, watchpoint, or catchpoint set (not to the breakpoint most recently encountered). @end table Pressing @key{RET} as a means of repeating the last debugger command is disabled within a @var{command-list}. You can use breakpoint commands to start your program up again. Simply use the @code{continue} command, or @code{step}, or any other command that resumes execution. Any other commands in the command list, after a command that resumes execution, are ignored. This is because any time you resume execution (even with a simple @code{next} or @code{step}), you may encounter another breakpoint---which could have its own command list, leading to ambiguities about which list to execute. @kindex silent If the first command you specify in a command list is @code{silent}, the usual message about stopping at a breakpoint is not printed. This may be desirable for breakpoints that are to print a specific message and then continue. If none of the remaining commands print anything, you see no sign that the breakpoint was reached. @code{silent} is meaningful only at the beginning of a breakpoint command list. The commands @code{echo}, @code{output}, and @code{printf} allow you to print precisely controlled output, and are often useful in silent breakpoints. For example, here is how you could use breakpoint commands to print the value of @code{x} at entry to @code{foo} whenever @code{x} is positive. @smallexample break foo if x>0 commands silent printf "x is %d\n",x cont end @end smallexample One application for breakpoint commands is to compensate for one bug so you can test for another. Put a breakpoint just after the erroneous line of code, give it a condition to detect the case in which something erroneous has been done, and give it commands to assign correct values to any variables that need them. End with the @code{continue} command so that your program does not stop, and start with the @code{silent} command so that no output is produced. Here is an example: @smallexample break 403 commands silent set x = y + 4 cont end @end smallexample @node Delete Breaks @subsubsection Deleting breakpoints (@samp{clear}, @samp{delete}) @cindex clearing breakpoints, watchpoints @cindex deleting breakpoints, watchpoints It may desirable to eliminate a breakpoint or watchpoint once it has done its job and you no longer want your script to stop there. This is called @dfn{deleting} the breakpoint. A breakpoint that has been deleted no longer exists; it is forgotten. With the @code{clear} command you can delete breakpoints according to where they are in your script. With the @code{delete} command you can delete individual breakpoints, or watchpoints by specifying their breakpoint numbers. @emph{Note: as described below under the ``clear'' command, ``d'' is an alias for ``clear'', not ``delete''. } It is not necessary to delete a breakpoint to proceed past it. @DBG automatically ignores breakpoints on the first instruction to be executed when you continue execution. @table @code @kindex clear @kindex d @r{(@code{clear})} @item clear Delete any breakpoints at the next instruction to be executed in the selected stack frame (@pxref{Selection, ,Selecting a frame}). When the innermost frame is selected, this is a good way to delete a breakpoint where your script just stopped. It may seem odd that we have an alias ``d'' for ``clear.'' It so happens that Perl's debugger use ``d'' for its delete command and the delete concept in Perl's debugger corresponds to ``clear'' in GDB. (Perl doesn't have a notion of breakpoint entry numbers). So in order to be compatible with both debugger interfaces, ``d'' is used as an alias for ``clear.'' Clear? @item clear @var{function} @itemx clear @var{filename}:@var{function} Delete any breakpoints set at entry to the function @var{function}. @item clear @var{linenum} @itemx d @var{linenum} @ifset FINISHED @itemx clear @var{filename}:@var{linenum} @end ifset Delete any breakpoints set at or within the code of the specified line. @cindex delete breakpoints @kindex delete @kindex de @r{(@code{delete})} @item delete @ovar{breakpoints} Delete the breakpoints, watchpoints specified as arguments. If no argument is specified, delete all breakpoints (@DBG asks confirmation, unless you have @code{set confirm off}). You can abbreviate this command as @code{de}. Note that for compatibility with Perl's debugger, @code{d} means something else: @code{clear}. @end table @node Disabling @subsubsection Disabling breakpoints (@samp{disable}, @samp{enable}) Rather than deleting a breakpoint or watchpoint, you might prefer to @dfn{disable} it. This makes the breakpoint inoperative as if it had been deleted, but remembers the information on the breakpoint so that you can @dfn{enable} it again later. You disable and enable breakpoints, watchpoints, and catchpoints with the @code{enable} and @code{disable} commands, optionally specifying one or more breakpoint numbers as arguments. Use @code{info break} or @code{info watch} to print a list of breakpoints, watchpoints, and catchpoints if you do not know which numbers to use. A breakpoint, watchpoint, or catchpoint can have any of four different states of enablement: @itemize @bullet @item Enabled. The breakpoint stops your program. A breakpoint set with the @code{break} command starts out in this state. @item Disabled. The breakpoint has no effect on your program. @item Enabled once. The breakpoint stops your program, but then becomes disabled. @item Enabled for deletion. The breakpoint stops your program, but immediately after it does so it is deleted permanently. A breakpoint set with the @code{tbreak} command starts out in this state. @end itemize You can use the following commands to enable or disable breakpoints, watchpoints, and catchpoints: @table @code @kindex disable breakpoints @kindex disable @kindex dis @r{(@code{disable})} @item disable @ovar{breakpoints} Disable the specified breakpoints---or all breakpoints, if none are listed. A disabled breakpoint has no effect but is not forgotten. All options such as ignore-counts, conditions and commands are remembered in case the breakpoint is enabled again later. You may abbreviate @code{disable} as @code{dis}. @kindex enable breakpoints @kindex enable @item enable @ovar{breakpoints} Enable the specified breakpoints (or all defined breakpoints). They become effective once again in stopping your program. @end table @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is @c confusing: tbreak is also initially enabled. Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks, ,Setting breakpoints}), breakpoints that you set are initially enabled; subsequently, they become disabled or enabled only when you use one of the commands above. (The command @code{until} can set and delete a breakpoint of its own, but it does not change the state of your other breakpoints; see @ref{Resuming Execution, ,Resuming Execution}.) @node Conditions @subsubsection Break conditions (@samp{condition}) @cindex conditional breakpoints @cindex breakpoint conditions The simplest sort of breakpoint breaks every time your script reaches a specified place. You can also specify a @dfn{condition} for a breakpoint. A condition is just a @acronym{BASH} expression. Break conditions can be specified when a breakpoint is set, by using @samp{if} in the arguments to the @code{break} command. @xref{Set Breaks, ,Setting breakpoints}. A breakpoint with a condition evaluates the expression each time your script reaches it, and your script stops only if the condition is @emph{true}. They can also be changed at any time with the @code{condition} command. @cindex one-time breakpoints There is also a notion of a ``one-time'' breakpoint which gets deleted as soon as it is hit, so that that breakpoint is executed once only. Conditions are also accepted for watchpoints; you may not need them, since a watchpoint is inspecting the value of an expression anyhow---but it might be simpler, say, to just set a watchpoint on a variable name, and specify a condition that tests whether the new value is an interesting one. @ifset FINISHED You can also use the @code{if} keyword with the @code{watch} command. The @code{catch} command does not recognize the @code{if} keyword; @code{condition} is the only way to impose a further condition on a catchpoint. @end ifset @table @code @kindex condition @item condition @var{bnum} @var{expression} Specify @var{expression} as the break condition for breakpoint @var{bnum}. After you set a condition, breakpoint @var{bnum} stops your program only if the value of @var{expression} is true (nonzero). @item condition @var{bnum} Remove the condition from breakpoint number @var{bnum}. It becomes an ordinary unconditional breakpoint. @end table @ifset FINISHED When you use @code{condition}, @DBG checks @var{expression} immediately for syntactic correctness, and to determine whether symbols in it have referents in the context of your breakpoint. If @var{expression} uses symbols not referenced in the context of the breakpoint, @DBG prints an error message: @example No symbol "foo" in current context. @end example @end ifset @noindent @acronym{BASH} does not actually evaluate @var{expression} at the time the @code{condition} command (or a command that sets a breakpoint with a condition, like @code{break if @dots{}}) is given, however. Examples; @example condition 1 x>5 # Stop on breakpoint 0 only if x>5 is true. condition 1 # Change that! Unconditinally stop on breakpoint 1. @end example @node Resuming Execution @subsection Resuming Execution (@samp{step}, @samp{next}, @samp{finish}, @samp{skip}, @samp{continue}, @samp{debug}, @samp{return}) A typical technique for using stepping is to set a breakpoint (@pxref{Breakpoints, ,Breakpoints; watchpoints}) at the beginning of the function or the section of your script where a problem is believed to lie, run your script until it stops at that breakpoint, and then step through the suspect area, examining the variables that are interesting, until you see the problem happen. @cindex stepping @cindex continuing @cindex resuming execution @dfn{Continuing} means resuming program execution until your script completes normally. In contrast, @dfn{stepping} means executing just one more ``step'' of your script, where ``step'' may mean either one line of source code. Either when continuing or when stepping, your script may stop even sooner, due to a breakpoint or a signal. @menu * Step:: running the next statement (step) * Next:: running the next statement skipping over functions (next) * Finish:: running until the return of a function or ``source'' (finish) * Skip:: skipping the next statement (skip) * Continue:: continuing execution (continue) * Debug:: debugging into another program (debug) * Returning:: returning @end menu @node Step @subsubsection Step (@samp{step}) @table @code @kindex step @kindex s @r{(@code{step})} @item step@ovar{+|-} @ovar{count} Continue running your script until control reaches a different source line, then stop it and return control to @value{DBG}. An default alias alias for this is @code{s}. The @code{step} command only stops at the first instruction of a source line. This prevents the multiple stops that could otherwise occur in @code{switch} statements, @code{for} loops, etc. @code{step} continues to stop if a function that has debugging information is called within the line. In other words, @code{step} @emph{steps inside} any functions called within the line. Sometimes you want to step ensure that the next line is different from the one you currently are on. To do this, add the @code{+} suffix. And if you find you want to do this all of the time there is a setting @code{force} that will have this be the default behavior. On the other hand if you want to be explicit about not having this behavior even when @code{force} is in effect add the @code{-} suffix. With a count, continue running as in @code{step}, but do so @var{count} times. If a breakpoint is reached, or a signal not related to stepping occurs before @var{count} steps, stepping stops right away. @end table @node Next @subsubsection Next (@samp{next}) @table @code @kindex next @kindex n @r{(@code{next})} @item next @ovar{count} Continue to the next source line in the current (innermost) stack frame. This is similar to @code{step}, but function calls that appear within the line of code are executed without stopping. Execution stops when control reaches a different line of code at the original stack level that was executing when you gave the @code{next} command. This command is abbreviated @code{n}. An argument @var{count} is a repeat count, as for @code{step}. @end table @node Finish @subsubsection Finish (@samp{finish}) @table @code @kindex finish @item finish Continue running until just after function returns. @emph{Currently, the line shown on a return is the function header, unless the @code{return} builtin function is executed in which case it is the line number of the @code{return} function.} Contrast this with the @code{return} command (@pxref{Returning, ,Returning from a function}) and the @code{quit} (@pxref{Quitting the BASH debugger, ,Quitting the BASH debugger}). @end table @node Skip @subsubsection Skip (@samp{skip}) @table @code @kindex skip @item skip @ovar{count} Skip execution of the next source line. This may be useful if you have an action that ``fixes'' existing code in the script. The @code{debug} command internally uses the @code{skip} command to skip over existing non-debugged invocation that was presumably just run. @end table @node Continue @subsubsection Continue (@samp{continue}) @table @code @kindex continue @kindex c @r{(@code{continue})} @item continue @ovar{- | line-specification} @itemx c @ovar{line-specification} Resume program execution, at the address where your script last stopped; any breakpoints set at that address are bypassed. The optional argument @var{line-specification} allows you to specify a location (a line number, function, or filename linenumber combination) to set a one-time breakpoint which is deleted when that breakpoint is reached. Should the program stop before that breakpoint is reached, in a listing of the breakpoints you will see this entry with the condition 9999 which indicates a one-time breakpoint. If instead of a line specification you enter @code{-}, debugging will be turned of after continuing causing the program to run at full speed. @end table To resume execution at a different place, you can use @code{return} (@pxref{Returning, ,Returning from a function}) to go back to the calling function or sourced script. If you are nested inside a subshell, @code{quit} with a value for the number of subshells to exit also functions like a return. @node Debug @subsubsection Debug (@samp{debug}) @table @code @kindex debug @item debug @ovar{script-name} Debug into @var{script-name}. If no name is given the current source line is used. In either case the options are prepended to cause the debugger to run. The nesting level of the debugger is saved inside environment variable @code{_Dbg_DEBUGGER_LEVEL}. The debugger prompt indicates the level of nesting by enclosing the history in that many nestings of @code{<>} symbols. @end table @node Returning @subsubsection Returning from a function, sourced file, or subshell (@samp{return}) @table @code @cindex returning from a function, sourced file or subshell @kindex return @item return You can cancel execution of a function call or a subshell with the @code{return} command. @end table The @code{return} command does not resume execution; it leaves the program stopped in the state that would exist if the function had just returned. See also the @code{quit} command (@ref{Quit, ,Quitting the BASH debugger}). In some situations @code{return} is similar to @code{quit}: in particular when the script is @emph{not} currenlty inside in a function and the number of subshells in effect is 0, or when a subshell count of 1 is given on the @code{quit} command. In contrast, the @code{finish} command (@pxref{Finish, ,Finish}) resumes execution until the selected stack frame returns naturally. @node Signals @subsection Signals (@samp{handle}, @samp{info handle}, @samp{signal}) @cindex signals @menu * handle:: Specify which signals to handle and show what's been set * signal:: Send a signal to your program @end menu A signal is an asynchronous event that can happen in a program. The operating system defines the possible kinds of signals, and gives each kind a name and a number. For example, in Unix @code{SIGINT} is the signal a program gets when you type an interrupt character (often @kbd{C-c}); @code{SIGALRM} occurs when the alarm clock timer goes off (which happens only if your program has requested an alarm). Some signal handlers are installed and changed for @value{DBG}'s normal use: @code{SIGDEBUG} and @code{SIGEXIT}. @code{SIGDEBUG} is used by the debugger to potentially stop your program before execution of each statement occurs, and @code{SIGEXIT} is used to catch your program just before it is set to leave so you have the option of restarting the program with the same options (and not leave the debugger) or let the program quit. Signal handlers that the debugged script might have installed are saved and called before the corresponding debugger handler. Thus, the debugged program should work roughly in the same fashion as when it is not debugged. However there are some call-stack variables which inevitably will differ. To try to hedge this a little so the behaviour is the same, @value{DBG} will modify arguments to the traps if it finds one of the call-stack that change as a result of the debugger being in place. In particluar @env{$LINENO} will get replaced with @env{$@{BASH_LINENO[0]@}}; also @env{$@{BASH_LINENO[0]@}} and @env{$@{BASH_SOURCE[0]@}} get replaced with @env{$@{BASH_LINENO[1]@}} and @env{$@{BASH_SOURCE[1]@}} respectively. The debugger also installs an interrupt handler @code{SIGINT} so that errant programs can be interrupted and you can find out where the program was when you interrupted it. @cindex fatal signals Some signals, including @code{SIGALRM}, are a normal part of the functioning of your program. Others, such as @code{SIGSEGV}, indicate errors; these signals are @dfn{fatal} (they kill your program immediately) if the program has not specified in advance some other way to handle the signal. @code{SIGINT} does not indicate an error in your program, but it is normally fatal so it can carry out the purpose of the interrupt: to kill the program. @acronym{BASH} has the ability to detect any occurrence of a signal in your program. You can tell @acronym{BASH} in advance what to do for each kind of signal. @cindex handling signals Normally, @acronym{BASH} is set up to let the non-erroneous signals like @code{SIGALRM} be silently passed to your program (so as not to interfere with their role in the program's functioning) but to stop your program immediately whenever an error signal happens. You can change these settings with the @code{handle} command. @node handle @subsubsection Intercepting Signals (@samp{handle}, @samp{info handle}) @table @code @kindex handle @item handle @var{signal} @var{keywords}@dots{} Change the way @acronym{BASH} handles signal @var{signal}. @var{signal} can be the number of a signal or its name (with or without the @samp{SIG} at the beginning). The @var{keywords} say what change to make. @kindex info signals @item info signals @itemx info handle Print a table of all the kinds of signals and how @acronym{BASH} has been told to handle each one. You can use this to see the signal numbers of all the defined types of signals. @code{info handle} is an alias for @code{info signals}. @end table @c @group The keywords allowed by the @code{handle} command can be abbreviated. Their full names are: @table @code @item stop @acronym{BASH} should stop your program when this signal happens. This implies the @code{print} keyword as well. @item nostop @acronym{BASH} should not stop your program when this signal happens. It may still print a message telling you that the signal has come in. @item print @acronym{BASH} should print a message when this signal happens. @item noprint @acronym{BASH} should not mention the occurrence of the signal at all. @item stack @acronym{BASH} should print a stack trace when this signal happens. @item nostack @acronym{BASH} should not print a stack trace when this signal occurs. @ifset FINISHED @item pass @itemx noignore @acronym{BASH} should allow your program to see this signal; your program can handle the signal, or else it may terminate if the signal is fatal and not handled. @code{pass} and @code{noignore} are synonyms. @item nopass @itemx ignore @acronym{BASH} should not allow your program to see this signal. @code{nopass} and @code{ignore} are synonyms. @end ifset @end table @c @end group @ifset FINISHED When a signal stops your program, the signal is not visible to the program until you continue. Your program sees the signal then, if @code{pass} is in effect for the signal in question @emph{at that time}. In other words, after @acronym{BASH} reports a signal, you can use the @code{handle} command with @code{pass} or @code{nopass} to control whether your program sees that signal when you continue. The default is set to @code{nostop}, @code{noprint}, @code{pass} for non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the erroneous signals. @end ifset @node signal @subsubsection Sending your program a signal (@samp{signal}) @table @code @kindex signal @item signal @r{@var{signal-name} | @var{signal-number}} You can use the @code{signal} command send a signal to your program. Supply either the signal name, e.g.@: @code{SIGINT}, or the signal number @code{15}. @end table @node Stack @section Examining the Stack Frame (@samp{where}, @samp{frame}, @samp{up}, @samp{down}) When your script has stopped, one thing you'll probably want to know is where it stopped and some idea of how it got there. @cindex call stack Each time your script performs a function call (either as part of a command substitution or not), or `source's a file, information about this action is saved. The call stack then is this a history of the calls that got you to the point that you are currently stopped at. @cindex selected frame One of the stack frames is @dfn{selected} by @DBG and many @DBG commands refer implicitly to the selected frame. In particular, whenever you ask @DBG to list lines without giving a line number or location the value is found in the selected frame. There are special @DBG commands to select whichever frame you are interested in. @xref{Selection, ,Selecting a frame}. When your program stops, @acronym{BASH} automatically selects the currently executing frame and describes it briefly, similar to the @code{frame} command. @menu * Frames:: Stack frames * Backtrace:: Backtraces (where) * Selection:: Selecting a frame (up, down, frame) @end menu @node Frames @subsection Stack frames @cindex frame, definition @cindex stack frame The call stack is divided up into contiguous pieces called @dfn{stack frames}, or @dfn{frames} for short; each frame is the data associated with one call to one function. The frame contains the line number of the caller of the function, the source-file name that the line refers to a function name (which could be the built-in name ``source'').. @cindex initial frame @cindex outermost frame @cindex innermost frame When your script is started, the stack has only one frame, that of the function @code{main}. This is called the @dfn{initial} frame or the @dfn{outermost} frame. Each time a function is called, a new frame is made. Each time a function returns, the frame for that function invocation is eliminated. If a function is recursive, there can be many frames for the same function. The frame for the function in which execution is actually occurring is called the @dfn{innermost} frame. This is the most recently created of all the stack frames that still exist. @cindex frame number @value{DBG} assigns numbers to all existing stack frames, starting with zero for the innermost frame, one for the frame that called it, and so on upward. These numbers do not really exist in your script; they are assigned by @value{DBG} to give you a way of designating stack frames in @value{DBG} commands. @node Backtrace @subsection Backtraces (@samp{where}) @cindex backtraces @cindex tracebacks @cindex stack traces A backtrace is essentially the same as the call stack: a summary of how your script got where it is. It shows one line per frame, for many frames, starting with the place that you sare stopped at (frame zero), followed by its caller (frame one), and on up the stack. @table @code @kindex backtrace @kindex bt @r{(@code{backtrace})} @item backtrace @itemx bt @itemx where @itemx T Print a backtrace of the entire stack: one line per frame for all frames in the stack. @item backtrace @var{n} @itemx bt @var{n} @itemx where @var{n} @itemx T @var{n} Similar, but print only the innermost @var{n} frames. @ifset FINISHED @item backtrace -@var{n} @itemx bt -@var{n} @itemx where -@var{n} @itemx T -@var{n} Similar, but print only the outermost @var{n} frames. @end ifset @end table @kindex where The names @code{where} and @code{T} are additional aliases for @code{backtrace}. Each line in the backtrace shows the frame number and the function name, the source file name and line number, as well as the function name. Here is an example of a backtrace taken a program in the regression-tests @file{parm.sh}. @smallexample @group % ../bashdb -n -L .. parm.sh Bourne-Again Shell Debugger, release @value{VERSION} Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009 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. (./parm.sh:21): 21: fn1 5 bashdb<0> @b{continue fn3} One-time breakpoint 1 set in file ./parm.sh, line 17. fn2: testing 1 2 3 (./parm.sh:17): 17: fn3() @{ bashdb<1> @b{where} ->0 in file `./parm.sh' at line 14 ##1 fn3() called from file `./parm.sh' at line 14 ##2 fn2("testing 1", "2 3") called from file `parm.sh' at line 5 ##3 fn1("0") called from file `parm.sh' at line 9 ##4 fn1("1") called from file `parm.sh' at line 9 ##5 fn1("2") called from file `parm.sh' at line 9 ##6 fn1("3") called from file `parm.sh' at line 9 ##7 fn1("4") called from file `parm.sh' at line 9 ##8 fn1("5") called from file `parm.sh' at line 21 ##9 source("parm.sh") called from file `bashdb' at line 143 ##10 main("-n", "-L", "..", "parm.sh") called from file `bashdb' at line 0 @end group @end smallexample @noindent The display for ``frame'' zero isn't a frame at all, although it has the same information minus a function name; it just indicates that your script has stopped at the code for line @code{14} of @code{./parm.sh}. @node Selection @subsection Selecting a frame (@samp{up}, @samp{down}, @samp{frame}) Commands for listing source code in your script work on whichever stack frame is selected at the moment. Here are the commands for selecting a stack frame; all of them finish by printing a brief description of the stack frame just selected. @table @code @kindex up @ovar{n} @item up @ovar{n} Move @var{n} frames up the stack. For positive numbers @var{n}, this advances toward the outermost frame, to higher frame numbers, to frames that have existed longer. Using a negative @var{n} is the same as issuing a @code{down} command of the absolute value of the @var{n}. Using zero for @var{n} does no frame adjustment, but since the current position is redisplayed, it may trigger a resyncronization if there is a front end also watching over things. @var{n} defaults to one. You may appreviate @code{up} as @code{u}. @kindex down @kindex do @r{(@code{down})} @item down @ovar{n} Move @var{n} frames down the stack. For positive numbers @var{n}, this advances toward the innermost frame, to lower frame numbers, to frames that were created more recently. Using a negative @var{n} is the same as issuing a @code{up} command of the absolute value of the @var{n}. Using zero for @var{n} does no frame adjustment, but since the current position is redisplayed, it may trigger a resyncronization if there is a front end also watching over things. @var{n} defaults to one. You may abbreviate @code{down} as @code{do}. @end table All of these commands end by printing two lines of output describing the frame. The first line shows the frame number, the function name, the arguments, and the source file and line number of execution in that frame. The second line shows the text of that source line. @need 100 For example: @smallexample @group bashdb<8> @b{up} 19: sourced_fn bashdb<8> @b{T} ##0 in file `./bashtest-sourced' at line 8 ->1 sourced_fn() called from file `bashtest-sourced' at line 19 ##2 source() called from file `bashdb-test1' at line 23 ##3 fn2() called from file `bashdb-test1' at line 33 ##4 fn1() called from file `bashdb-test1' at line 42 ##5 main() called from file `bashdb-test1' at line 0 @end group @end smallexample After such a printout, the @code{list} command with no arguments prints ten lines centered on the point of execution in the frame. @xref{List, ,Printing source lines}. @table @code @kindex frame @cindex current stack frame @item frame @var{args} The @code{frame} command allows you to move from one stack frame to another, and to print the stack frame you select. @var{args} is the the stack frame number; @code{frame 0} then will always show the current and most recent stack frame. If a negative number is given, counting is from the other end of the stack frame, so @code{frame -1} shows the least-recent, outermost or most ``main'' stack frame. Without an argument, @code{frame} prints the current stack frame. Since the current position is redisplayed, it may trigger a resyncronization if there is a front end also watching over things. @end table @node List @section Examining Source Files (@samp{list}) @value{DBG} can print parts of your script's source. When your script stops, @value{DBG} spontaneously prints the line where it stopped. Likewise, when you select a stack frame (@pxref{Selection, ,Selecting a frame}), @value{DBG} prints the line where execution in that frame has stopped. You can print other portions of source files by explicit command. If you use @value{DBG} through its @value{Emacs} interface, you may prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using @value{DBG} under @value{Emacs}}. @kindex list @kindex l @r{(@code{list})} To print lines from a source file, use the @code{list} command (abbreviated @code{l}). By default, ten lines are printed. There are several ways to specify what part of the file you want to print. Here are the forms of the @code{list} command most commonly used: @table @code @item list @var{linenum} @itemx l @var{linenum} Print lines centered around line number @var{linenum} in the current source file. @item list @var{function} @itemx l @var{function} Print the text of @var{function}. @item list @itemx l Print more lines. If the last lines printed were printed with a @code{list} command, this prints lines following the last lines printed; however, if the last line printed was a solitary line printed as part of displaying a stack frame (@pxref{Stack, ,Examining the Stack}), this prints lines centered around that line. @item list - @itemx l - Print lines just before the lines last printed. @end table By default, @value{DBG} prints ten source lines with any of these forms of the @code{list} command. You can change this using @code{set listsize}: @table @code @kindex set listsize @item set listsize @var{count} Make the @code{list} command display @var{count} source lines (unless the @code{list} argument explicitly specifies some other number). @kindex show listsize @item show listsize Display the number of lines that @code{list} prints. @end table Repeating a @code{list} command with @key{RET} discards the argument, so it is equivalent to typing just @code{list}. This is more useful than listing the same lines again. An exception is made for an argument of @samp{-}; that argument is preserved in repetition so that each repetition moves up in the source file. @cindex linespec In general, the @code{list} command expects you to supply a @dfn{linespecs}. Linespecs specify source lines; there are several ways of writing them, but the effect is always to specify some source line. Here is a complete description of the possible arguments for @code{list}: @table @code @item list @var{linespec} Print lines centered around the line specified by @var{linespec}. @item list @var{first} @var{increment} Print @var{increment} lines starting from @var{first} @item list @var{first} Print lines starting with @var{first}. @item list - Print lines just before the lines last printed. @item list . Print lines after where the script is stopped. @item list As described in the preceding table. @end table Here are the ways of specifying a single source line---all the kinds of linespec. @table @code @item @var{number} Specifies line @var{number} of the current source file. When a @code{list} command has two linespecs, this refers to the same source file as the first linespec. @item @var{filename}:@var{number} Specifies line @var{number} in the source file @var{filename}. @item @var{function} Specifies the line that function @var{function} is listed on. @ifset FINISHED @item @var{filename}:@var{function} Specifies the line of function @var{function} in the file @var{filename}. You only need the file name with a function name to avoid ambiguity when there are identically named functions in different source files. @end ifset @end table @node Edit @section Editing Source files (@samp{edit}) To edit the lines in a source file, use the @code{edit} command. The editing program of your choice is invoked with the current line set to the active line in the program. Alternatively, you can give a line specification to specify what part of the file you want to print if you want to see other parts of the program. You can customize to use any editor you want by using the @code{EDITOR} environment variable. The only restriction is that your editor (say @code{ex}), recognizes the following command-line syntax: @smallexample ex +@var{number} file @end smallexample The optional numeric value +@var{number} specifies the number of the line in the file where to start editing. For example, to configure @value{DBG} to use the @code{vi} editor, you could use these commands with the @code{sh} shell: @smallexample EDITOR=/usr/bin/vi export EDITOR gdb @dots{} @end smallexample or in the @code{csh} shell, @smallexample setenv EDITOR /usr/bin/vi gdb @dots{} @end smallexample @table @code @kindex edit @ovar{line-specification} @item edit @ovar{line specification} Edit line specification using the editor specified by the @code{EDITOR} environment variable. @end table @node Search @section Searching source files (@samp{search}, @samp{reverse}, @samp{/.../}, @samp{?..?}) @cindex searching @kindex reverse-search There are two commands for searching through the current source file for a @acronym{BASH} extended pattern-matching expression. @table @code @kindex search @kindex forward @item forward @var{bash-pattern} @itemx search @var{bash-pattern} The command @samp{forward @var{bash-pattern}} checks each line, starting with the one following the current line, for a match for @var{bash-pattern} which is an extended bash pattern-matching expression. It lists the line that is found. You can use the synonym @samp{search @var{bash-pattern}} or abbreviate the command name as @code{fo} or @code{/@var{pat}/}. @item reverse @var{bash-pattern} The command @samp{reverse @var{bash-pattern}} checks each line, starting with the one before the last line listed and going backward, for a match for @var{bash-pattern}. It lists the line that is found. You can abbreviate this command as @code{rev} or @code{?@var{bash-pattern}?}. @end table @node Data @section Examining Data (@samp{print}, @samp{examine}, @samp{info variables}) @cindex printing data @cindex examining data @kindex print One way to examine string data in your script is with the @code{print} command (abbreviated @code{p}). However a more versatile print command is @code{x}; it can print variable and function definitions and can do arithmetic computations. Finally, the most general method would be via @code{eval echo}. @table @code @kindex print @kindex p @r{(@code{print})} @item print @var{expr} Use @code{print} to display strings as you would from @code{echo}. And as such, variable names to be substituted have to be preceded with a dollar sign. As with echo, filename expansion, e.g.@: tilde expansion, is performed on unquoted strings. So for example if you want to print a *, you would write @samp{print "*"}, not @samp{print *}. If you want to have the special characters dollars sign appear, use a backslash. @smallexample @group bashdb<0> @b{print the value of x is $x} the value of x is 22 bashdb<1> @b{p The home directory for root is ~root} The home directory for root is /root bashdb<2> @b{p '*** You may have won $$$ ***'} *** You may have won $$$ *** bashdb<3> # Note the use of the single quotes. bashdb<3> # Compare what happens with double quotes or no quotes @end group @end smallexample @item print @itemx p If you omit @var{expr}, @value{DBG} displays the last expression again. @item x @var{variable1} @ovar{variable2...} @item x @var{expr} @kindex x @r{(@code{examine})} @kindex examine This is a smarter, more versatile ``print'' command, and although sometimes it might not be what you want, and you may want to resort to either @code{print} or @code{eval echo...}. As with @code{print}, if you omit @var{expr}, @value{DBG} displays the last expression again. The @code{x} command first checks if @var{expr} is variable or a list of variables delimited by spaces. If it is, the definition(s) and value(s) of each printed via @acronym{BASH}'s @code{declare -p} command. This will show the variable's attributes such as if it is read only or if it is an integer. If the variable is an array, that is show and the array values are printed. If instead @var{expr} is a function, the function definition is printed via @acronym{BASH}'s @code{declare -f} command. If @var{expr} was neither a variable nor an expression, then we try to get a value via @code{let}. And if this returns an error, as a last resort we call @code{print} and give what it outputs. Since @code{let} may be used internally and since (to my thinking) @code{let} does funny things, the results may seem odd unless you understand the sequence tried above and how @code{let} works. For ``example if the variable @code{foo} has value 5, then @samp{x foo} shows the definition of foo with value 5, and @samp{x foo+5} prints 10 as expected. So far so good. However if @code{foo} is has the value @samp{alpha}, @samp{x foo+5} prints 5 because @code{let} has converted the string @samp{alpha} into the numeric value 0. So @samp{p foo+5} will simply print ``foo+5''; if you want the value of ``foo'' substituted inside a string, for example you expect ``the value of foo is $foo'' to come out ``the value of foo is 5'', then the right command to use is @code{print} rather than @code{x}, making sure you add the dollar onto the beginning of the variable. @smallexample @group bashdb<0> @b{examine x y} declare -- x="22" declare -- y="23" bashdb<1> @b{examine x+y} 45 bashdb<2> @b{x fn1} fn1 () @{ echo "fn1 here"; x=5; fn3 @} bashdb<2> @b{x FUNCNAME} declare -a FUNCNAME='([0]="_Dbg_cmd_x" [1]="_Dbg_cmdloop" [2]="_Dbg_debug_trap_handler" [3]="main")' @end group @end smallexample @item V @ovar{!}@ovar{pattern} @kindex V @r{(@code{info variables})} @kindex info variables If you want to all list variables and values or a set of variables by pattern, use this command. @smallexample @group bashdb<0> @b{V dq*} dq_args="dq_*" dq_cmd="V" bashdb<1> @b{V FUNCNAME} FUNCNAME='([0]="_Dbg_cmd_list_variables" [1]="_Dbg_cmdloop" [2]="_Dbg_debug_trap_handler" [3]="main")' @end group @end smallexample @end table @node Auto Display @section Automatic display (@samp{display}, @samp{undisplay}) @cindex automatic display @cindex display of expressions If you find that you want to print the value of an expression frequently (to see how it changes), you might want to add it to the @dfn{automatic display list} so that @value{DBG} evaluates a statement each time your program stops. Each expression added to the list is given a number to identify it; to remove an expression from the list, you specify that number. The automatic display looks like this: @example 2 (echo $x): 38 @end example @noindent This display shows item numbers, expressions and their current values. @table @code @kindex display @item display @var{expr} Add the expression @var{expr} to the list of expressions to display each time your program stops. @item display Display the current values of the expressions on the list, just as is done when your program stops. @kindex delete display @kindex undisplay @var{dnums}@dots{} @item undisplay @var{dnums}@dots{} @itemx delete display @var{dnums}@dots{} Remove item numbers @var{dnums} from the list of expressions to display. @code{undisplay} does not repeat if you press @key{RET} after using it. (Otherwise you would just get the error @samp{No display number @dots{}}.) @kindex disable display @item disable display @var{dnums}@dots{} Disable the display of item numbers @var{dnums}. A disabled display item is not printed automatically, but is not forgotten. It may be enabled again later. @kindex enable display @item enable display @var{dnums}@dots{} Enable display of item numbers @var{dnums}. It becomes effective once again in auto display of its expression, until you specify otherwise. @kindex info display @item info display Print the list of expressions previously set up to display automatically, each one with its item number, but without showing the values. This includes disabled expressions, which are marked as such. It also includes expressions which would not be displayed right now because they refer to automatic variables not currently available. @end table @node Evaluation/Execution @section Running Arbitrary BASH and Shell commands (@samp{eval}, @samp{shell}) The two most general commands and most ``low-level'' are @code{eval} and @code{shell}. @table @code @item eval @r{[} bash-code @r{]} @itemx e @kindex e @r{(@code{eval})} @kindex eval In contrast to the commands of the last section the most general way to examine data is through @code{eval}. But you do much more with this; you can change the values of variables, since, you are just evaluating @acronym{BASH} code. If you expect output, you should arrange that in the command, such as via @code{echo} or @code{printf}. For example, to print the value of @var{foo}, you would type @samp{e echo $foo}. This is bit longer than @samp{p $foo} or (when possible) @samp{x foo}. However suppose you wanted to find out how the builtin test operator @samp{[} works with the @samp{-z} test condition. You could use @code{eval} to do this such as @samp{e [ -z "$foo"] && echo "yes"}. @item eval I find I sometimes want to run the line that's about to be executed to see if I want to step into methods that are called. For example: @smallexample (/etc/apparmor/functions:24): PROFILES="/etc/apparmor.d" bashdb<2> @end smallexample I had been cutting and pasting the command as shown, but realized I could do better if I made a command for this. So that's what I've done. If you run the @samp{eval} command without any arguments, it will run the command that is about to be run. @smallexample (/etc/apparmor/functions:24): PROFILES="/etc/apparmor.d" bashdb<2> eval eval: PROFILES="/etc/apparmor.d" $? is 0 bashdb<3> @end smallexample This was working fine, until I started coming across tests inside @code{if}, @code{elsif}, @code{case}, @code{return} or @code{while} blocks. For example: @smallexample (/etc/init.d/apparmor:70): if [ "$1" = "recache" ] @end smallexample Suppose I want to know which branch I'm going to take before taking the branch. That way I might even be able to change which way to go by changing the test before it runs in the debugged program. (In the above example, I could print $1 @smallexample bashdb<2> pr $1 status @end smallexample But I'm lazy. I'd rather let the debugger do the work for me: @smallexample bashdb<1> eval? eval: [ "$1" = "recache" ] $? is 1 @end smallexample If you alias eval with a name that ends in ? it will strip off any leading @code{if}, @code{case}, @code{while}, @code{elsif}, or @code{return}. @kindex !! @r{(@code{shell})} @cindex shell escape @item !! @var{command string} If you need to execute occasional shell commands during your debugging session, there is no need to leave or suspend @value{DBG}; you can just use the @code{shell} command or its alias @code{!!}. Invoke a shell to execute @var{command string}. @kindex shell @r{(@code{shell})} @cindex nested shell @item shell Although the debugger allows one to evaluate arbitrary @acronym{BASH} code using @code{eval}, or via the @code{set autoeval} mode, sometimes you might prefer to work inside a @acronym{BASH} shell to see variables, experiment, issue commands (using the currently-set up environment), and even change variables and functions. For this we, the debugger @code{shell} command, enters a nested shell session. But before it does this, it saves out variable and function definitions in the current context of the running program. That way, you have access to those. This however creates a new problem: getting changes you make reflected back into the running program. Right now any variable you change can be flagged to have its value re-read when the shell exits. This is done using the @code{save_var} function inside the nested shell. @code{save_var} takes a list of variable names. Here is an example session @smallexample bashdb /etc/init.d/apparmor status bashdb debugger, release 4.2-0.6 Copyright 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010 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. ... (/etc/init.d/apparmor:35): . /etc/apparmor/functions bashdb<1> s (/etc/apparmor/functions:24): PROFILES="/etc/apparmor.d" bashdb<2> s (/etc/apparmor/functions:25): PARSER="/sbin/apparmor_parser" bashdb<3> shell bashdb $ typeset -p PROFILES typeset -p PROFILES typeset PROFILES=/etc/apparmor.d bashdb $ PROFILES='Hi, Mom!' bashdb $ save_vars PROFILES bashdb $ (/etc/apparmor/functions:25): PARSER="/sbin/apparmor_parser" bashdb<4> x PROFILES typeset PROFILES='Hi, Mom!' @end smallexample Note that inside the nested shell the we have set the prompt has been set to @code{bashdb $ }. @end table @node Interfacing to the OS @section Interfacing to the OS (@samp{cd}, @samp{pwd}) @table @code @kindex cd @ovar{directory} @cindex change working directory @item cd Set working directory to @var{directory} for debugger and program being debugged. Tilde expansion, variable and filename expansion is performed on @var{directory}. If no directory is given, we print out the current directory which is really the same things as running @code{pwd}. Note that @code{gdb} is a little different in that it peforms tilde expansion but not filename or variable expansion and the directory argument is not optional as it is here. @kindex pwd @cindex print working directory @item pwd Prints the working directory as the program sees things. @end table @node Information and Settings @section Status and Debugger Settings (@samp{info}, @samp{show}) @menu * Info:: Showing information about the program being debugged * Show:: Show information about the debugger @end menu In addition to @code{help}, you can use the @acronym{BASH} commands @code{info} and @code{show} to inquire about the state of your program, or the state of @acronym{BASH} itself. Each command supports many topics of inquiry; here we introduce each of them in the appropriate context. The listings under @code{info} and under @code{show} in the Index point to all the sub-commands. @xref{Command Index}. @node Info @subsection Showing information about the program being debugged (@samp{info}) @c @group This @code{info} command (abbreviated @code{i}) is for describing the state of your program. For example, you can list the current @code{$1}, @code{$2} parameters with @code{info args}, or list the breakpoints you have set with @code{info breakpoints} or @code{info watchpoints}. You can get a complete list of the @code{info} sub-commands with @w{@code{help info}}. @table @code @kindex info args @item info args Argument variables (e.g.@: $1, $2, ...) of the current stack frame. @kindex info breakpoints @item info breakpoints Status of user-settable breakpoints @kindex info display @item info display Show all display expressions @kindex info files @item info files Source files in the program @kindex info functions @item info functions All function names @kindex info line @item info line list current line number and and file name @kindex info program @item info program Execution status of the program. @kindex info signals @item info signals What debugger does when program gets various signals @kindex info source @item info source Information about the current source file @kindex info stack @item info stack Backtrace of the stack @kindex info terminal @item info terminal Print terminal device @kindex info variables @item info variables All global and static variable names @end table @c @end group @node Show @subsection Show information about the debugger (@samp{show}) In contrast to @code{info}, @code{show} is for describing the state of @acronym{BASH} itself. You can change most of the things you can @code{show}, by using the related command @code{set}; The distinction between @code{info} and @code{show} however is a bit fuzzy and is kept here to try to follow the GDB interface. For example, to list the arguments given to your script use @code{show args}; @code{info args} does something different. Here are three miscellaneous @code{show} subcommands, all of which are exceptional in lacking corresponding @code{set} commands: @table @code @kindex show version @cindex version number @item show version Show what version of @acronym{BASH} is running. You should include this information in @acronym{BASH} bug-reports. If multiple versions of @acronym{BASH} are in use at your site, you may need to determine which version of @acronym{BASH} you are running; as @acronym{BASH} evolves, new commands are introduced, and old ones may wither away. Also, many system vendors ship variant versions of @value{BASH}, and there are variant versions of @acronym{BASH} in @sc{gnu}/Linux distributions as well. The version number is the same as the one announced when you start @value{BASH}. @kindex show copying @item show copying Display information about permission for copying @value{BASH}. @item show linetrace Show if line tracing is enabled. See also @ref{Line Tracing}. @item show logging Show summary information of logging variables which can be set via @code{set logging}. See also @ref{Logging}. @item show logging file Show the current logging file. @item show logging overwrite Show whether logging overwrites or appends to the log file. @kindex show warranty @item show warranty Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty, if your version of @DBG comes with one. @end table @node Controlling bashdb @section Controlling bashdb (@samp{set}, @samp{file}, @samp{prompt}, @samp{history}...) You can alter the way @acronym{BASH} interacts with you in various ways given below. @menu * Alias:: Debugger Command aliases * Annotate:: Annotation Level (set annotate) * Autoeval:: Evaluate unrecognized commands * Autolist:: Run a list command on every stop * Basename:: Show basenames of file names only (set basename) * Debugger:: Allow debugging the debugger (set debugger) * File:: Specifying a Script-File Associaton (set file) * Line Tracing:: Show position information (set linetrace) * Logging:: Specifying where to write debugger output * Prompt:: Prompt (set prompt, show prompt) * Editing:: Command editing (set editing, show editing) * Command-Tracing:: Showing commands as they run (set/show trace-commands) * Command Display:: Command display (set showcommand) * History:: Command history (history, !, H) * Command Completion:: Command completion (complete) @end menu @node Alias @subsection Debugger Command Aliases (@samp{alias}) @table @code @kindex alias @var{name} @var{command} @item alias @var{name} @var{command} Add @var{name} as an alias for @var{command} @kindex unalias @var{name} @var{command} Remove @var{name} as an alias for @var{command} @item unalias @var{name} @var{command} @end table @node Annotate @subsection Annotation Level (@samp{set annotate}) @table @code @kindex set annotate @item set annotate @var{integer} The annotation level controls how much information @value{DBG} prints in its prompt; right new it just controls whether we show full filenames in output or the base part of the filename without path information. Level 0 is the normal, level 1 is for use when @value{DBG} is run as a subprocess of @value{Emacs} of @value{DDD}, level 2 is the maximum annotation suitable for programs that control @value{DBG}. @end table @node Autoeval @subsection Set/Show auto-eval (@samp{set autoeval}) @table @code @kindex set autoeval @r{[} on | 1 | off | 0 @r{]} @item set autoeval @r{[} on | 1 | off | 0 @r{]} Specify that debugger input that isn't recognized as a command should be passed to Ruby for evaluation (using the current debugged program namespace). Note however that we @emph{first} check input to see if it is a debugger command and @emph{only} if it is not do we consider it as Ruby code. This means for example that if you have variable called @code{n} and you want to see its value, you could use @code{p n}, because just entering @code{n} will be interpreted as the debugger ``next'' command. When autoeval is set on, you'll get a different error message when you invalid commands are encountered. Here's a session fragment to show the difference @smallexample bashdb<1> @b{stepp} Unknown command bashdb<2> @b{set autoeval on} autoeval is on. bashdb<3> @b{stepp} NameError Exception: undefined local variable or method `stepp' for ... @end smallexample @kindex show autoeval @item show args Shows whether Ruby evaluation of debugger input should occur or not. @end table @node Autolist @subsection Set/Show listing on stop (@samp{set autolist}) @table @code @kindex set autolist @r{[} on | 1 | off | 0 @r{]} @item set autolist @r{[} on | 1 | off | 0 @r{]} When set runs a ``list'' command on each stop in the debugger. @end table @node Basename @subsection File basename (@samp{set basename}) @table @code @kindex set basename @item set basename @r{[} on | 1 @r{]} When set on, source filenames are shown as the shorter ``basename'' only. (Directory paths are omitted). This is useful in running the regression tests and may useful in showing debugger examples as in this text. You may also just want less verbose filename display. @item set basename @r{[} off | 0 @r{]} Source filenames are shown as with their full path. This is the default. @end table @node Debugger @subsection Allow Debugging the debugger (@samp{set debugger}) @table @code @kindex set debugger @item set debugger @r{[} on | 1 @r{]} Allow the possibility of debugging this debugger. Somewhat of an arcane thing to do. For gurus, and even he doesn't use it all that much. @item set debugger @r{[} off | 0 @r{]} Don't allow debugging into the debugger. This is the default. @end table @node File @subsection Specifying a Script-File Association (@samp{file}) Sometimes @value{DBG} gets confused about where to find the script source file for the name reported to it by bash. To resolve relative file names that bash supplies via @env{BASH_SOURCE}, @value{DBG} uses the current working directory when the debugged script was started as well as the current working directory now (which might be different if a ``cd'' command was issued to change the working directory). However somethimes this doesn't work and there is a way to override this. @table @code @kindex file @item file @var{script-file} Directs @value{DBG} to use @var{script-file} whenever bash would have it refers to the filename given in @env{BASH_SOURCE}. The filename specified in @env{BASH_SOURCE} that gets overriden is shown when is this command is issued. @end table @node Line Tracing @subsection Show position information as statements are executed (@samp{set linetrace}) @value{BASH} has ``@code{set -x}'' tracing to show commands as they are run. However missing from this is file and line position information. So the debugger compensates here for what I think is deficiency of @value{BASH} by providing this information. The downside is that this tracing is slower than the built-in tracing of @value{BASH}. The status of whether line tracing is enabled can be show via @code{show linetrace}. @table @code @kindex set linetrace @item set linetrace @r{[} on | 1 @r{]} Turn on line tracing. @item set linetrace @r{[} off | 0 @r{]} Turn off line tracing. @end table @node Logging @subsection Logging output (@samp{set logging}, @samp{set logging file}...) You may want to save the output of the debugger commands to a file. There are several commands to control the debuggers's logging. @table @code @item set logging Prints @code{set logging} usage. @kindex set logging @item set logging @r{[} on | 1 @r{]} Enable or Disable logging. @item set logging file @var{filename} Change the name of the current logfile. The default logfile is @file{bashdb.txt}. @item set logging overwrite @r{[} on | 1 @r{]} By default, the debugger will append to the logfile. Set @code{overwrite} if you want @code{set logging on} to overwrite the logfile instead. @item set logging redirect @r{[} on | 1 @r{]} By default, the debugger output will go to both the terminal and the logfile. Set @code{redirect} if you want output to go only to the log file. @item show logging Show the current values of the logging settings. @end table @node Prompt @subsection Prompt (@samp{set prompt}, @samp{show prompt}) @cindex prompt @value{dBGP} indicates its readiness to read a command by printing a string called the @dfn{prompt}. This string is normally: @example bashdb$@{_Dbg_less@}$@{#_Dbg_history[@@]@}$@{_Dbg_greater@}$_Dbg_space @end example When variables inside the the prompt string are evaluated, the above becomes something like @samp{bashdb<5>} if this is the fifth command executed or perhaps @samp{bashdb<<2>>} if you have called the debugger from inside a debugger session and this is the second command inside the debugger session or perhaps @samp{bashdb<(6)>} if you entered a subshell after the fifth command. You can change the prompt string with the @code{set prompt} command, although it is not normally advisable to do so without understanding the implications. If you are using the @value{DDD} GUI, it changes the changes the prompt and should not do so. In certain other circumstances (such as writing a GUI like @value{DDD}), it may be is useful to change the prompt. @emph{Note:} @code{set prompt} does not add a space for you after the prompt you set. This allows you to set a prompt which ends in a space or a prompt that does not. Furthermore due to a implementation limitation (resulting from a limitation of the bash built-in function ``read''), to put a space at the end of the prompt use the @samp{$_Dbg_space} variable. @table @code @kindex set prompt @item set prompt @var{newprompt} Directs @value{DBG} to use @var{newprompt} as its prompt string henceforth. @emph{Warning: changing the prompt can @value{DDD}'s ability to understand when the debugger is waiting for input.} @kindex show prompt @item show prompt Prints a line of the form: @samp{bashdb's prompt is: @var{your-prompt}} @end table @node Editing @subsection Command editing (@samp{set editing}, @samp{show editing}) @cindex readline @cindex command line editing @value{DBG} reads its input commands through bash which uses via the @dfn{readline} interface. This @sc{gnu} library provides consistent behavior for programs which provide a command line interface to the user. Advantages are @value{Emacs}-style or @dfn{vi}-style inline editing of commands, @code{csh}-like history substitution, and a storage and recall of command history across debugging sessions. You may control the behavior of command line editing in @acronym{BASH} with the command @code{set}. @table @code @kindex set editing @cindex editing @item set editing @itemx set editing @r{[} on | 1 @r{]} Enable command line editing (enabled by default). @item set editing @r{[} off | 0 @r{]} Disable command line editing. @kindex show editing @item show editing Show whether command line editing is enabled. @end table @node Command-Tracing @subsection Debugger Commands Tracing (@samp{set trace-commands}, @samp{show trace-commands}) @cindex tracing debugger commands If you need to debug user-defined commands or sourced files you may find it useful to enable @dfn{command tracing}. In this mode each command will be printed as it is executed, prefixed with one or more @samp{+} symbols, the quantity denoting the call depth of each command. @table @code @kindex set trace-commands @cindex command scripts, debugging @item set trace-commands on Enable command tracing. @item set trace-commands off Disable command tracing. @item show trace-commands Display the current state of command tracing. @end table @node Command Display @subsection Command Display (@samp{set showcommand}) The debugger normally lists the line number and source line of the for the statement to be next executed. Often this line contains one expression or one statement and it is clear from this line what's going to happen. However @acronym{BASH} allows many expressions or statements to be put on a single source line; some lines contain several units of execution. Some examples of this behavior are listed below: @smallexample x=1; y=2; x=3 (( x > 5 )) && x=5 y=`echo *` @end smallexample In the first line of the example above, we have three assignment statements on a single line. In the second line of the example above we have a statement which gets run only if a condition tests true. And in the third line of the example above, we have a command that gets run and then the output of that is substituted in an assignemnt statement. If you were single stepping inside the debugger, each line might get listed more than once before each of the actions that might get performed. (In the case of the conditional statement, the line gets listed only once when the condition is false.) In order to assist understanding where you are, the enhanced version of @acronym{BASH} maintains a dynamic variable @env{BASH_COMMAND} that contains piece of code next to be run (or is currently being run). The debugger has arranged to save this and can display this information or not. This is controlled by @code{set showcommand}. @table @code @kindex set showcommand @item set showcommand @r{[}auto | on | 1 | off | 0 @r{]} controls whether or not to show the saved @env{BASH_COMMAND} for the command next to be executed. @end table When the value is @code{auto} the following heuristic is used to determine whether or not to display the saved @env{BASH_COMMAND}. If the last time you stopped you were at the same place and the command string has changed, then show the command. When the value @code{on} is used, the debugger always shows @env{BASH_COMMAND} and when @code{off} is used, the debugger nevers shows @env{BASH_COMMAND}. Note that listing the text of the source line is independent of whether or not the command is also listed. Some examples: @smallexample set showcommand auto @b{This is the default} set showcommand on @b{Always show the next command to be executed} set showcommand off @b{Never show the next command to be executed} @end smallexample @node History @subsection Command history (@samp{H}, @samp{history}, @samp{!}) @value{dBGP} can keep track of the commands you type during your debugging sessions, so that you can be certain of precisely what happened. If the prompt has not been changed (see @ref{Prompt, ,Prompt}), the history number that will be in use next is by default listed in the debugger prompt. Invalid commands and history commands are not saved on the history stack. @table @code @kindex H @r{[}@var{start-number} @ovar{end-number}@r{]} @item H @r{[}@var{start-number} @ovar{end-number}@r{]} @item H @ovar{-count} @itemx !@r{[}-@r{]}@var{n}:p You can list what is in the history stack with @code{H}. Debugger commands in ths history stack are listed from most recent to least recent. If no @var{start-number} is given we start with the most recently executed command and end with the first entry in the history stack. If @var{start-number} is given, that history number is listed first. If @var{end-number} is given, that history number is listed last. If a single negative number is given list that many history commands. An alternate form is @code{!@emph{n}:p} or @code{!-@emph{n}:p} where @emph{n} is an integer. If a minus sign is used, @emph{n} is taken as the count to go back from the end rather than as a absolute history number. In contrast @code{H}, this form only prints a @emph{single} history item. Some examples: @smallexample H @b{List entire history} H -2 @b{List the last two history items} !-2:p @b{List a single history item starting at the same place as above} H 5 @b{List history from history number 5 to the begining (number 0)} H 5 0 @b{Same as above} H 5 3 @b{List history from history number 5 down to history number 3} !5:p @b{List a single history item 5} @end smallexample @kindex history @r{[}-@r{]}@r{[}@var{n}@r{]} @kindex !@r{[}-@r{]}@var{n} @r{(@code{history})} @item history @r{[}@r{[}-@r{]}@var{n}@r{]} @itemx !@r{[}-@r{]}@var{n} Use this command to reexecute a given history number. If no number is given, the last debugger command in the history is executed. An alternate form is @code{!@emph{n}} or @code{!-@emph{n}} where @emph{n} is an integer. If a minus sign is used in in either form, @emph{n} is taken as the count to go back from the end rather than as a absolute history number. @end table Use these commands to manage the @value{DBG} command history facility. @table @code @ifset FINISHED @cindex history substitution @cindex history file @kindex set history filename @kindex GDBHISTFILE @item set history filename @var{fname} Set the name of the @acronym{BASH} command history file to @var{fname}. This is the file where @acronym{BASH} reads an initial command history list, and where it writes the command history from this session when it exits. You can access this list through history expansion or through the history command editing characters listed below. This file defaults to the value of the environment variable @code{GDBHISTFILE}, or to @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable is not set. @end ifset @cindex history save @kindex set history save @item set history save @itemx set history save @r{[} on | 1 @r{]} Record command history in a file, whose name may be specified with the @code{set history filename} command. By default, this option is enabled. @item set history save @r{[} off | 0 @r{]} Stop recording command history in a file. @cindex history size @kindex set history size @item set history size @var{size} Set the number of commands which @acronym{BASH} keeps in its history list. This defaults to the value of the environment variable @code{HISTSIZE}, or to 256 if this variable is not set. @end table @ifset FINISHED @cindex history expansion History expansion assigns special meaning to the character @kbd{!}. Since @kbd{!} is also the logical not operator in C, history expansion is off by default. If you decide to enable history expansion with the @code{set history expansion on} command, you may sometimes need to follow @kbd{!} (when it is used as logical not, in an expression) with a space or a tab to prevent it from being expanded. The readline history facilities do not attempt substitution on the strings @kbd{!=} and @kbd{!(}, even when history expansion is enabled. The commands to control history expansion are: @end ifset @table @code @ifset FINISHED @kindex set history expansion @item set history expansion on @itemx set history expansion Enable history expansion. History expansion is off by default. @item set history expansion off Disable history expansion. The readline code comes with more complete documentation of editing and history expansion features. Users unfamiliar with @value{Emacs} or @code{vi} may wish to read it. @end ifset @c @group @kindex show history @item show history @ifset FINISHED @itemx show history filename @itemx show history expansion @end ifset @itemx show history save @itemx show history size These commands display the state of the @acronym{BASH} history parameters. @code{show history} by itself displays all states. @c @end group @end table @table @code @kindex shows @item show commands Display the last ten commands in the command history. @item show commands @var{n} Print ten commands centered on command number @var{n}. @item show commands + Print ten commands just after the commands last printed. @end table @node Command Completion @subsection Command Completion (@samp{complete}) The @code{complete @var{args}} command lists all the possible completions for the beginning of a command. We can also show completions for @code{set}, @code{show} and @code{info} subcommands. Use @var{args} to specify the beginning of the command you want completed. For example: @smallexample complete d @end smallexample @noindent results in: @smallexample @group d debug delete disable display deleteall down @end group @end smallexample And @smallexample complete set a @end smallexample @noindent results in: @smallexample @group set args set annotate @end group @end smallexample @noindent This is intended for use by front-ends such as @sc{gnu} Emacs and @sc{ddd}. @node Front Ends @chapter Using @value{DBG} from a front-end user interface There are some front-ends that can use @value{DBG} as a back-end debugger. @menu * Emacs:: Using @value{DBG} from @value{Emacs} * DDD:: Using @value{DBG} from @value{DDD} @end menu @node Emacs @section Using @value{DBG} from @value{Emacs} @cindex Emacs @cindex @value{Emacs} A special interface allows you to use @value{Emacs} to view (and edit) the source files for the program you are debugging with @value{DBG}. However you must be using @value{Emacs} version 23 or greater. (@code{M-x show-emacs-version} inside @value{Emacs} will tell you what version you are running.) The project emacs-dbgr at @url{https://github.com/rocky/emacs-dbgr} has the code. This project handles other debuggers, not just @code{bashdb}. Alas, steps need to be taken to make it easier to install. The load the code @kbd{M-x load-libarary dbgr}. To use this interface, use the command @kbd{M-x dbgr-bashdb} in @sc{gnu} Emacs. There is also am Emacs lisp command alias called @kbd{bashdb}. However it is possible ther will be a conflict with older code that we used to provide in this package. When you run @kbd{dbgr-bashdb} you are prompted for the executable file you want to debug as an argument. The @kbd{dbgr-bashdb} command starts @value{DBG} as a subprocess of Emacs, with input and output through a newly created Emacs buffer. Using @value{DBG} under Emacs is just like using @value{DBG} normally except for two things: @itemize @bullet @item All ``terminal'' input and output goes through the GNU Emacs buffer. @end itemize This applies both to @value{DBG} commands and their output, and to the input and output done by the program you are debugging. This is useful because it means that you can copy the text of previous commands and input them again; you can even use parts of the output in this way. All the facilities of GNU Emacs' Shell mode are available for interacting with your script. In particular, you can send signals the usual way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a stop. @menu * GUD:: Commands from the GUD buffer * Emacs Source:: Commands from the source script * Emacs Shell:: @value{DBG} from a @value{Emacs} Shell @end menu @node GUD @subsection Commands from the GUD buffer @itemize @bullet @item @value{DBG} displays source code through Emacs. @end itemize Each time @value{DBG} displays a stack frame, Emacs automatically finds the source file for that frame and puts an arrow (@samp{=>}) at the left margin of the current line. Emacs uses a separate buffer for source display, and splits the screen to show both your @value{DBG} session and the source. Explicit @value{DBG} @code{list} or search commands still produce output as usual, but you probably have no reason to use them from GNU Emacs. @quotation @emph{Warning:} If the directory where your script resides is not your current directory, it can be easy to confuse Emacs about the location of the source files, in which case the auxiliary display buffer does not appear to show your source. @value{DBG} can find programs by searching your environment's @code{PATH} variable, so the @value{DBG} input and output session proceeds normally; but Emacs does not get enough information back from @value{DBG} to locate the source files in this situation. To avoid this problem, either start @value{DBG} mode from the directory where your script resides, or specify an absolute file name when prompted for the @kbd{M-x gdb} argument. A similar confusion can result if you use the @value{DBG} @code{file} command to switch to debugging a program in some other location, from an existing @value{DBG} buffer in Emacs. @end quotation By default, @kbd{M-x bashdb} calls the @code{bash --debugger}. If you need to call @value{DBG} by a different name (for example, if you keep several configurations around, with different names) you can set the Emacs variable @code{gud-bashdb-command-name}; for example, @example (setq gud-bashdb-command-name "bash --debugger") @end example @noindent (preceded by @kbd{M-:} or @kbd{ESC :}, or typed in the @code{*scratch*} buffer, or in your @file{.emacs} file) makes Emacs call the program named ``@code{bash-debugger}'' instead. In the @value{DBG} I/O buffer, you can use the Emacs commands listed below in addition to the standard Shell mode commands. The I/O buffer name name is usually @code{*gud-}@emph{script-name}@code{*}, where @emph{script-name} is the name of the script you are debugging. Many of the commands listed below are also bound to a second key sequence which also can be used in the also be used in the source script. These are listed in @ref{Emacs Source}. @table @kbd @item C-h m Describe the features of Emacs' @value{DBG} Mode. @item C-c C-f Execute until exit from the selected stack frame. The Same as @value{DBG} @code{finish} command. The @value{Emacs} command name is @code{gud-finish} and @code{C-x C-a f C-f} is an alternate binding which also can be used in the source script. @xref{Finish}. @item C-c C-l Resynchronize the current position with the source window. The @value{Emacs} command name is @code{gud-refresh} and @code{C-x C-a C-l} is an alternate binding which also can be used in the source script. @item C-c C-n Execute to next source line in this function, skipping all function calls. Same as @value{DBG} @code{next} command. The @value{Emacs} command name is @code{gud-next} and @code{C-x C-a n} is an alternate binding which also can be used in the source script. @xref{Next}. With a numeric argument, run that many times. @xref{Arguments, , Numeric Arguments, Emacs, The @value{Emacs} Manual}. @item C-c C-r Continue execution of your script Same as @value{DBG} @code{continue} command. The @value{Emacs} command name is @code{gud-cont} and @code{C-x C-a C-r} is an alternate binding which also can be used in the source script. See @ref{Continue}. @item C-c C-s Step one source line. Same as @value{DBG} @code{step} command. The @value{Emacs} command name is @code{gud-step} and @code{C-x C-a C-s} is an alternate binding which can be used in the source script. @xref{Step}. With a numeric argument, run that many times. @xref{Arguments, , Numeric Arguments, Emacs, The @value{Emacs} Manual}. @item C-c > Go down a stack frame. Same as @value{DBG} @code{down}. With a numeric argument, go down that many stack frames. @xref{Arguments, , Numeric Arguments, Emacs, The @value{Emacs} Manual}. The @value{Emacs} command name is @code{gud-down} and @code{C-x C-a >} is an alternate binding which can be used in the source script. @item C-c < Go up a stack frame. With a numeric argument, go up that many stack frames. Same @value{DBG} @code{up} command. @xref{Arguments, , Numeric Arguments, Emacs, The @value{Emacs} Manual}. The @value{Emacs} command name is @code{gud-up} and @code{C-x C-a <} is an alternate binding which can be used in the source script. @item C-c a Shows argument variables (e.g.@: @code{$1}, @code{$2}) of the current stack frame. Same as @value{DBG} @code{info args} command. The @value{Emacs} command name is @code{gud-args} and @code{C-x C-a a} is an alternate binding which also can be used in the source script. @item C-c R Restart or run the script. Same as @value{DBG} @code{run} command. The @value{Emacs} command name is @code{gud-finish} and @code{C-x C-a R} is an alternate binding which also can be used in the source script. @item C-c T Show stack trace. Same as @value{DBG} @code{where} command. The @value{Emacs} command name is @code{gud-where} and @code{C-x C-a T} is an alternate binding which can be used in the source script. @xref{Backtrace}. @end table In any source file, the Emacs command @kbd{C-x SPC} (@code{gud-break}) tells @value{DBG} to set a breakpoint on the source line point is on. If you accidentally delete the source-display buffer, an easy way to get it back is to type the command @code{frame} in the @value{DBG} buffer, to request a frame display; when you run under Emacs, this recreates the source buffer if necessary to show you the context of the current frame. The source files displayed in Emacs are in ordinary Emacs buffers which are visiting the source files in the usual way. You can edit the files with these buffers if you wish; but keep in mind that @value{DBG} communicates with Emacs in terms of line numbers. If you add or delete lines from the text, the line numbers that @value{DBG} knows cease to correspond properly with the code. @xref{Debugger Operation, , , Emacs, The @value{Emacs} Manual}. @node Emacs Source @subsection Commands from the source script @table @kbd @item C-x SPC tells @value{DBG} to set a breakpoint on the source line point is on. (@code{gud-break}) @item C-x C-a t @code{gud-linetrace} @item C-x C-a C-f Restart or run the script. Same as @value{DBG} @code{run} command. The @value{Emacs} command name is @code{gud-finish}. In the corresponding I/O buffer, @code{C-c R} is an alternate binding. @item C-x C-a T Show stack trace. Same as @value{DBG} @code{where} command. In the corresponding I/O buffer, @code{C-c T} is an alternate binding. @xref{Backtrace}. @item C-x C-a < Go up a stack frame. With a numeric argument, go up that many stack frames. Same @value{DBG} @code{up} command. @xref{Arguments, , Numeric Arguments, Emacs, The @value{Emacs} Manual}. The @value{Emacs} command name is @code{gud-up}. In the corresponding I/O buffer, @code{C-c <} is an alternate binding. @item C-x C-a > Go down a stack frame. Same as @value{DBG} @code{down}. With a numeric argument, go down that many stack frames. @xref{Arguments, , Numeric Arguments, Emacs, The @value{Emacs} Manual}. The @value{Emacs} command name is @code{gud-down}. In the corresponding I/O buffer, @code{C-c >} is an alternate binding. @item C-x C-a C-t @code{gud-tbreak} @item C-x C-a C-s Step one source line. Same as @value{DBG} @code{step} command. @xref{Step}. With a numeric argument, run that many times. @xref{Arguments, , Numeric Arguments, Emacs, The @value{Emacs} Manual}. The @value{Emacs} command name is @code{gud-step}. In the corresponding I/O buffer, @code{C-c C-s} is an alternate binding. @item C-x C-a C-e @code{gud-statement} @item C-x C-a R Restart or run the script. Same as @value{DBG} @code{run} command. The @value{Emacs} command name is @code{gud-run}. In the corresponding I/O buffer, @code{C-c R} is an alternate binding. @item C-x C-a C-d Delete breakpoint. @code{gud-remove} @item C-x C-a C-p @code{gud-print} @item C-x C-a C-n Execute to next source line in this function, skipping all function calls. Same as @value{DBG} @code{next} command. With a numeric argument, run that many times. @xref{Arguments, , Numeric Arguments, Emacs, The @value{Emacs} Manual}. The @value{Emacs} command name is @code{gud-next}. In the corresponding I/O buffer, @code{C-c C-n} is an alternate binding. @item C-x C-a f C-f @code{gud-finish} @item C-x C-a C-r Continue execution of your script Same as @value{DBG} @code{continue} command. The @value{Emacs} command name is @code{gud-cont}. In the corresponding I/O buffer, @code{C-c C-r} is an alternate binding. See @ref{Continue}. @item C-x C-a C-b @code{gud-break} @item C-x C-a a @code{gud-args} Shows argument variables (e.g.@: @code{$1}, @code{$2}) of the current stack frame. Same as @value{DBG} @code{info args} command. The @value{Emacs} command name is @code{gud-args}. In the corresponding I/O buffer, @code{C-c a} is an alternate binding which also can be used in the source script. @item C-x C-a C-l Move to current position in this source window. The @value{Emacs} command name is @code{gud-refresh}. In the corresponding I/O buffer, @code{C-c C-l} is an alternate binding. @end table @node Emacs Shell @subsection @value{DBG} from a @value{Emacs} Shell It is also possible in GNU emacs to use a regular (``comint'') shell and set a mode to watch for @value{DBG} prompts. @xref{Interactive Shell, , Shell, Emacs, The @value{Emacs} Manual}. To run bash in a shell in Emacs but track source lines this, issue the the command (from M-x) @code{turn-on-bashdbtrack}. There is some overhead involved in scanning output, so if you are not debugging bash programs you probably want to turn this off which can be done via the M-x @code{turn-off-bashdbtrack} command. @node DDD @section Using @value{DBG} from @value{DDD} @cindex DDD @value{DBG} support is rather new in @value{DDD}. As a programming language, @value{DBG} is not feature rich: there are no record structures or hash tables (yet), no pointers, package variable scoping or methods. So much of the data display and visualization features of @value{DDD} are disabled. As with any scripting or interpreted language (e.g.@: Perl), one can't step by a single machine-language instruction. So the ddd Stepi/Nexti commands are disabled. Some @value{BASH} settings are essential for @value{DDD} to work correctly. These settings with their correct values are: @example set annotate 1 set prompt set prompt bashdb$_Dbg_less$_Dbg_greater$_Dbg_space @end example @value{DDD} sets these values automatically when invoking @value{BASH}; if these values are changed, there may be some malfunctions. Pay special attention when the prompt has extra angle brackets (a nested shell) or has any parenthesis (is in a subshell). Quitting may merely exit out of one of these nested (sub)shells rather than leave the program. @node BASH Debugger Bugs @chapter Reporting Bugs @cindex bugs @cindex reporting bugs Your bug reports play an essential role in making the @acronym{BASH} debugger reliable. Reporting a bug may help you by bringing a solution to your problem, or it may not. But in any case the principal function of a bug report is to help the entire community by making the next version of @value{DBG} work better. Bug reports are your contribution to the maintenance of @value{DBG}. In order for a bug report to serve its purpose, you must include the information that enables us to fix the bug. @menu * Bug Criteria:: Have you found a bug? * Bug Reporting:: How to report bugs @end menu @node Bug Criteria @section Have you found a bug? @cindex bug criteria If you are not sure whether you have found a bug, here are some guidelines: @itemize @bullet @cindex fatal signal @cindex debugger crash @cindex crash of debugger @item If the debugger gets a fatal signal, for any input whatever, that is a @value{DBG} bug. Reliable debuggers never crash. @cindex error on valid input @item If @value{DBG} produces an error message for valid input, that is a bug. (Note that if you're cross debugging, the problem may also be somewhere in the connection to the target.) @cindex invalid input @item If @value{DBG} does not produce an error message for invalid input, that is a bug. However, you should note that your idea of ``invalid input'' might be our idea of ``an extension'' or ``support for traditional practice''. @item If you are an experienced user of debugging tools, your suggestions for improvement of @value{DBG} are welcome in any case. @end itemize @node Bug Reporting @section How to report bugs @cindex bug reports @cindex BASH debugger bugs, reporting Bug reports can sent via the sourceforge bug tracking mechansim at @url{http://sourceforge.net/tracker/?group_id=61395&atid=497159}. Of course patches are very much welcome too. Those can also be sent via the same mechanism. The fundamental principle of reporting bugs usefully is this: @strong{report all the facts}. If you are not sure whether to state a fact or leave it out, state it! Often people omit facts because they think they know what causes the problem and assume that some details do not matter. Thus, you might assume that the name of the variable you use in an example does not matter. Well, probably it does not, but one cannot be sure. Perhaps the bug is a stray memory reference which happens to fetch from the location where that name is stored in memory; perhaps, if the name were different, the contents of that location would fool the debugger into doing the right thing despite the bug. Play it safe and give a specific, complete example. That is the easiest thing for you to do, and the most helpful. Keep in mind that the purpose of a bug report is to enable us to fix the bug. It may be that the bug has been reported previously, but neither you nor we can know that unless your bug report is complete and self-contained. Sometimes people give a few sketchy facts and ask, ``Does this ring a bell?'' Those bug reports are useless, and we urge everyone to @emph{refuse to respond to them} except to chide the sender to report bugs properly. To enable us to fix the bug, you should include all these things: @itemize @bullet @item The version of @value{DBG}. @value{DBG} announces it if you start with no arguments; you can also print it at any time using @code{version} command. Without this, we will not know whether there is any point in looking for the bug in the current version of @value{DBG}. @item The type of machine you are using, and the operating system name and version number. @item What compiler (and its version) was used to compile BASH---e.g. ``gcc 3.4''. @item The command arguments you gave the compiler to compile your example and observe the bug. For example, did you use @samp{-O}? To guarantee you will not omit something important, list them all. A copy of the Makefile (or the output from make) is sufficient. If we were to try to guess the arguments, we would probably guess wrong and then we might not encounter the bug. @item A complete input script, and all necessary source files, that will reproduce the bug. @item A description of what behavior you observe that you believe is incorrect. For example, ``It gets a fatal signal.'' Of course, if the bug is that @value{DBG} gets a fatal signal, then we will certainly notice it. But if the bug is incorrect output, we might not notice unless it is glaringly wrong. You might as well not give us a chance to make a mistake. Even if the problem you experience is a fatal signal, you should still say so explicitly. Suppose something strange is going on, such as, your copy of @value{DBG} is out of synch, or you have encountered a bug in the C library on your system. (This has happened!) Your copy might crash and ours would not. If you told us to expect a crash, then when ours fails to crash, we would know that the bug was not happening for us. If you had not told us to expect a crash, then we would not be able to draw any conclusion from our observations. @item If you wish to suggest changes to the @value{DBG} source, send us context diffs. If you even discuss something in the @value{DBG} source, refer to it by context, not by line number. The line numbers in our development sources will not match those in your sources. Your line numbers would convey no useful information to us. @end itemize Here are some things that are not necessary: @itemize @bullet @item A description of the envelope of the bug. Often people who encounter a bug spend a lot of time investigating which changes to the input file will make the bug go away and which changes will not affect it. This is often time consuming and not very useful, because the way we will find the bug is by running a single example under the debugger with breakpoints, not by pure deduction from a series of examples. We recommend that you save your time for something else. Of course, if you can find a simpler example to report @emph{instead} of the original one, that is a convenience for us. Errors in the output will be easier to spot, running under the debugger will take less time, and so on. However, simplification is not vital; if you do not want to do this, report the bug anyway and send us the entire test case you used. @item A patch for the bug. A patch for the bug does help us if it is a good one. But do not omit the necessary information, such as the test case, on the assumption that a patch is all we need. We might see problems with your patch and decide to fix the problem another way, or we might not understand it at all. Sometimes with a program as complicated as @value{DBG} it is very hard to construct an example that will make the program follow a certain path through the code. If you do not send us the example, we will not be able to construct one, so we will not be able to verify that the bug is fixed. And if we cannot understand what bug you are trying to fix, or why your patch should be an improvement, we will not install it. A test case will help us to understand. @item A guess about what the bug is or what it depends on. Such guesses are usually wrong. Even we cannot guess right about such things without first using the debugger to find the facts. @end itemize @node History and Acknowledgments @chapter History and Acknowledgments The suggestion for a debugger for a Bourne-like shell came from the book ``Learning the Korn Shell'', by Bill Rosenblatt Copyright (C) 1993 by O'Reilly and Associates, Inc. Others such as Cigy Cyriac, Chet Ramey, Rocky Bernstein, and Gary V. Vaughan expanded and improved on that. However Bourne-Shell debuggers rely on a signal mechanism (@code{SIGDEBUG}) to call a debugger routine. In the Korn shell as well as @sc{bash} in versions prior to 2.05, there was a fundamental flaw: the routine that you registered in the trap, got called @emph{after} the statement was executed. It takes little imagination to realize that this is a bit too late to find and correct errors, especially if the offending command happens to do serious damage like remove filesystems or reboot a server. As a horrible hack, these debuggers added one to the line number that was just executed on the wishful thinking that this would then be the line of next statement to execute. Sometimes this was correct, but it was too often wrong, such as in loops and conditionals, comments, or commands that are continued on the next line. Another failing of these debuggers was the inability to debug into functions or into sourced files, provide a stack trace, dynamically skip a statement to be run, unconditionally trace into a function or subshell, or stop when a subroutine, sourced file, or subshell completed. In truth, the crux of the problem lay in debugging support in BASH. Given that there was limited bash debugging support, it is not surprising that these debuggers could not do any of the things listed above and could debug only a single shell in a single source file: lines could be listed only from a single text, breakpoints were set into the text which was in fact a copy of the script name prepended with debugger routines. In version 2.04 of BASH, Rocky Bernstein started hacking on BASH to add call-stack information, source file information, allow for debugging into functions and for reporting line numbers in functions as relative to the file rather than the beginning of a function whose origin line number was not accessible from BASH. He started changing the user commands in bashdb to be like other more-advanced debuggers, in particular @code{perl5db} and @code{gdb}. However he gave up on this project when realizing that stopping before a line was crucial. A patch for this was nontrivial and wildly changed semantics. Furthermore the chance of getting his other patches into BASH was was not going to happen in version 2.04. In version 2.05, the fundamental necessary change to the semantics of @code{SIGDEBUG} trap handling (suggested at least two years earlier) was made. Also, version 2.05 changed the line-number reporting in a function to be relative to the beginning of the file rather than the beginning of a function---sometimes. Rocky then picked up where he left off and this then became this debugger. A complete rewrite of the debugger, some of which started in 2.04 was undertaken. Debugger internals were changed to support multiple file names, save and restore the calling environment (such as variables @code{$1} and @code{$?}) and install debugger signal handlers. Work was also done on the BASH in conjunction with the debugger to save stack trace information, provide a means for stopping after a routine finished, debugging into a subshell and so on. And a number of changes were made to BASH just to improve the accuracy of the line number reporting which is crucial in a debugger. This documentation was modified from the GNU Debugger (GDB) Reference manual. @quotation Additions to this section are particularly welcome. If you or your friends (or enemies, to be evenhanded) have been unfairly omitted from this list, we would like to add your names! @end quotation The following have contributed directly or indrectly to bashdb: Rocky Bernstein (initial full-featured bashdb with stack tracing and multi-file support) Masatake YAMATO (help to merge Rocky's hack to the official bash source tree) Bill Rosenblatt (kshdb), Michael Loukides (kshdb), Cigy Cyriac (proto bashdb), Chet Ramey (proto bashdb), and Gary V. Vaughan (proto bashdb). Authors of per5ldb: Ray Lischner, Johan Vromans, and Ilya Zakharevich. Authors of GDB: Richard Stallman, Andrew Cagney, Jim Blandy, Jason Molenda, Stan Shebs, Fred Fish, Stu Grossman, John Gilmore, Jim Kingdon, and Randy Smith (to name just a few). Authors of GUD: Eric S. Raymond. @c The readline documentation is distributed with the readline code @c and consists of the two following files: @c rluser.texinfo @c inc-hist.texinfo @c Use -I with makeinfo to point to the appropriate directory, @c environment var TEXINPUTS with TeX. @c @include rluser.texinfo @c @include hsuser.texinfo @include gpl.texi @include fdl.texi @node Function Index @unnumbered Function Index @printindex fn @node Command Index @unnumbered Command Index @printindex ky @node Variable Index @unnumbered Variable Index @printindex vr @node General Index @unnumbered General Index @printindex cp @tex % I think something like @colophon should be in texinfo. In the % meantime: \long\def\colophon{\hbox to0pt{}\vfill \centerline{The body of this manual is set in} \centerline{\fontname\tenrm,} \centerline{with headings in {\bf\fontname\tenbf}} \centerline{and examples in {\tt\fontname\tentt}.} \centerline{{\it\fontname\tenit\/},} \centerline{{\bf\fontname\tenbf}, and} \centerline{{\sl\fontname\tensl\/}} \centerline{are used for emphasis.}\vfill} \page\colophon % Blame: doc@cygnus.com, 1991. @end tex @bye bashdb-4.2-0.8/doc/copyright.texi0000644000175000017500000000326211221051765013501 00000000000000Copyright (C) 2002, 2003, 2004, 2006 Rocky Bernstein. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or @ifset DEBIANHASBECOMEREASONABLE @c From Matthias Klose a Debian maintainer on @c Sat, 23 Aug 2003 14:24:44 +0200 @c @c I personally see the invariant sections as the thing in the @c GFDL, which hinders me in uploading the package to the archives. @c I don't have any problem, if some other Debian developer makes a @c bashdb package built from separate sources. @c @c I am aware that Debian ships other packages containing documentation @c covered by the GFDL (and one of them for which I do the packaging as @c well), but I won't add a new package, which I maintain. So before an @c upload of a bashdb package built from the bash sources either @c @c @c - Debian has a position on the GFDL, which allows inclusion @c @c - the bashdb manual does not have invariant sections, or is @c relicensed, or dual licensed. @c any later version published by the Free Software Foundation; with the Invariant Sections being ``Free Software'' and ``Free Software Needs Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' and with the Back-Cover Texts as in (a) below. (a) The Free Software Foundation's Back-Cover Text is: ``You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.'' @end ifset @ifclear DEBIANHASBECOMEREASONABLE any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. @end ifclear bashdb-4.2-0.8/doc/Makefile.am0000644000175000017500000000414611221051765012634 00000000000000############################################################################## # $Id: Makefile.am,v 1.5 2009/06/22 22:41:10 rockyb Exp $ # Copyright (C) 2003, 2009 Rocky Bernstein # 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 # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## EXT=1 man1_MANS = @PACKAGE@.$(EXT) # bashdb.texi and bashdb.info are derived but are included to # make "make distcheck" work. EXTRA_DIST = $(man1_MANS) macros.texi \ @PACKAGE@.info @PACKAGE@-man.pod @PACKAGE@-man.html info_TEXINFOS = bashdb.texi bashdb_TEXINFOS = fdl.texi gpl.texi copyright.texi all: $(INFO_DEPS) $(man1_MANS) html man: $(man1_MANS) html: @PACKAGE@.html @PACKAGE@-man.html @PACKAGE@.html: @PACKAGE@.texi texi2html $(srcdir)/@PACKAGE@.texi || true @PACKAGE@-man.html: @PACKAGE@-man.pod pod2html --infile=$(srcdir)/@PACKAGE@-man.pod --outfile=$@ $(man1_MANS): @PACKAGE@-man.pod pod2man --release=$(PACKAGE_VERSION) --name=@PACKAGE@ --center="GNU Tools" --section=$(EXT) $(srcdir)/@PACKAGE@-man.pod >$@ %.ps.gz: %.ps gzip -9c $< > $@ .texi.pdf: $(TEXI2PDF) -I $(srcdir) $< .texi.dvi: $(TEXI2DVI) -I $(srcdir) $< .dvi.ps: test -d $(docdir) || mkdir $(docdir) $(DVIPS) $< -o $@ .texi.html: texi2html $< || true .texi.txt: makeinfo --no-headers $< > $@ all-formats: pdf dvi txt ps html MOSTLYCLEANFILES = @PACKAGE@.tgs @PACKAGE@.ps.gz @PACKAGE@.pdf @PACKAGE@.html @PACKAGE@_toc.html @PACKAGE@_foot.html $(man1_MANS) @PACKAGE@-man.html bashdb-4.2-0.8/doc/bashdb-man.html0000644000175000017500000002445011564571702013472 00000000000000 bashdb - bash debugger script


NAME

bashdb - bash debugger script


SYNOPSIS

bashdb [options] [--] script-name [script options]

bashdb [options] -c execution-string

bash --debugger [bash-options...] script-name [script options]


DESCRIPTION

bashdb is a bash script to which arranges for another bash script to be debugged.

The debugger has a similar command interface as gdb.

The way this script arranges debugging to occur is by including (or actually "source"-ing) some debug-support code and then sourcing the given script or command string.

One problem with sourcing a debugged script is that the program name stored in $0 will be bashdb rather than the name of the script to be debugged. The debugged script will appear in a call stack not as the top item but as the item below bashdb. If this is of concern, use the last form given above, bash --debugger script-name [script-options].

If you used bashdb script and need to pass options to the script to be debugged, add -- before the script name. That will tell bashdb not to try to process any further options.

See the reference manual http://bashdb.sourceforge.net/bashdb.html for how to to call the debugger from inside your program or arrange for the debugger to get called when your program is sent a signal.


OPTIONS

-h | --help

Print a usage message on standard error and exit with a return code of 100.

-A | --annotation level

Sets to output additional stack and status information which allows front-ends such as emacs to track what's going on without polling.

This is needed in for regression testing. Using this option is equivalent to issuing:

  set annotation LEVEL

inside the debugger.

-B | --basename

In places where a filename appears in debugger output give just the basename only. This is needed in for regression testing. Using this option is equivalent to issuing:

  set basename on

inside the debugger.

-n | nx

Normally the debugger will read debugger commands in ~/.bashdbinit if that file exists before accepting user interaction. .bashdbinit is analogus to Perl's .perldb or GNU gdb's .gdbinit: a user might want to create such a debugger profile to add various user-specific customizations.

Using the -n option this initialization file will not be read. This is useful in regression testing or in tracking down a problem with one's .bashdbinit profile.

-c command-string

Instead of specifying the name of a script file, one can give an execution string that is to be debugged. Use this option to do that.

If you invoke the debugger via bash --debugger, the filename that will appear in source listing or in a call stack trace will be the artifical name *BOGUS*.

-q | --quiet

Do not print introductory version and copyright information. This is again useful in regression testing where we don't want to include a changeable copyright date in the regression-test matching.

-x debugger-cmdfile

Run the debugger commands debugger-cmdfile before accepting user input. These commands are read however after any .bashdbinit commands. Again this is useful running regression-testing debug scripts.

-L | --library debugger-library

The debugger needs to source or include a number of functions and these reside in a library. If this option is not given the default location of library is relative to the installed bashdb script: ../lib/bashdb.

-T | --tempdir temporary-file-directory

The debugger needs to make use of some temporary filesystem storage to save persistent information across a subshell return or in order to evaluate an expression. The default directory is /tmp but you can use this option to set the directory where debugger temporary files will be created.

-t | --tty tty-name

Debugger output usually goes to a terminal rather than stdout or stdin which the debugged program may use. Determination of the tty or pseudo-tty is normally done automatically. However if you want to control where the debugger output goes, use this option.

-V | --version

Show version number and no-warranty and exit with return code 1.

-X | --trace

Similar to "set -x" line tracing except that by default the location of each line, the bash level, and subshell level are printed. You might be able to get something roughly similar if you set PS4 as follows

    export PS4='(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]}\n'

In contrast however to "set -x" tracing, indentation of the original program is also preserved in the source output. And if you interrupt the program with a break (a SIGINT signal), you will go into the debugger (assuming your program doesn't trap SIGINT).


BUGS

The bashdb script and --debugger option assume a version of bash with debugging support. That is you can't debug bash scripts using the standard-issue version 2.05b bash or earlier versions. In versions after 3.0, debugging should have been enabled when bash was built. (I think this is usually the case though.) If you try to run the bashdb script on such as shell, may get the message:

  Sorry, you need to use a debugger-enabled version of bash.

Debugging startup time can be slow especially on large bash scripts. Scripts created by GNU autoconf are at thousands of lines line and it is not uncommon for them to be tens of thousands of lines.

There is a provision to address this problem by including a fast file-to-array read routine (readarray), but the bashdb package has to be compiled in a special way which needs access to the bash source code and objects.

Another reason of the debugger slowness is that the debugger has to intercept every line and check to see if some action is to be taken for this and this is all in bash code. A better and faster architecture would be for the debugger to register a list of conditions or stopping places inside the bash code itself and have it arrange to call the debugger only when a condition requiring the debugger arises. Checks would be faster as this would be done in C code and access to internal structures would make this more efficient.


SEE ALSO


AUTHOR

The current version is maintained (or not) by Rocky Bernstein.


COPYRIGHT

  Copyright (C) 2003, 2006, 2007 Rocky Bernstein
  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
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

$Id: bashdb-man.pod,v 1.10 2009/06/22 22:41:10 rockyb Exp $

bashdb-4.2-0.8/doc/bashdb-man.pod0000644000175000017500000001675711221051765013313 00000000000000=pod =head1 NAME bashdb - bash debugger script =head1 SYNOPSIS B [I] [--] I [I