Skip to content

Commit

Permalink
Clean up before a kill -9. And some code clean ups.
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Mar 27, 2011
1 parent a34b453 commit 73a9baf
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 81 deletions.
2 changes: 2 additions & 0 deletions command/Makefile.am
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
SUBDIRS = info_sub set_sub show_sub SUBDIRS = info_sub set_sub show_sub


MOSTLYCLEANFILES = *.orig *.rej

pkgdatadir = ${datadir}/@PACKAGE@/command pkgdatadir = ${datadir}/@PACKAGE@/command
pkgdata_DATA = \ pkgdata_DATA = \
alias.sh \ alias.sh \
Expand Down
52 changes: 29 additions & 23 deletions command/kill.sh
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- shell-script -*- # -*- shell-script -*-
# gdb-like "kill" debugger command # gdb-like "kill" debugger command
# #
# Copyright (C) 2009 Rocky Bernstein rocky@gnu.org # Copyright (C) 2009, 2011 Rocky Bernstein <rocky@gnu.org>
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as # modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -29,26 +29,32 @@ The signal is sent to process \$\$ (which is $$ right now).
Also similar is the \"signal\" command." 1 Also similar is the \"signal\" command." 1


function _Dbg_do_kill { _Dbg_do_kill() {
if (($# > 1)); then if (($# > 1)); then
_Dbg_errmsg "Got $# parameters, but need 0 or 1." _Dbg_errmsg "Got $# parameters, but need 0 or 1."
return 1 return 1
fi fi
typeset _Dbg_prompt_output=${_Dbg_tty:-/dev/null} typeset _Dbg_prompt_output=${_Dbg_tty:-/dev/null}
typeset signal='-9' typeset signal='-9'
(($# == 1)) && signal="$1" (($# == 1)) && signal="$1"


if [[ ${signal:0:1} != '-' ]] ; then if [[ ${signal:0:1} != '-' ]] ; then
_Dbg_errmsg "Kill signal ($signal} should start with a '-'" _Dbg_errmsg "Kill signal ($signal) should start with a '-'"
return 1 return 2
fi fi


_Dbg_confirm "Send kill signal ${signal} which may terminate the debugger? (y/N): " 'N' _Dbg_confirm "Send kill signal ${signal} which may terminate the debugger? (y/N): " 'N'


if [[ $_Dbg_response == 'y' ]] ; then if [[ $_Dbg_response == [yY] ]] ; then
kill $signal $$ case $signal in
else -9 | -SEGV )
_Dbg_msg "Kill not done - not confirmed." _Dbg_cleanup2
fi ;;
return 0 esac
kill $signal $$
else
_Dbg_msg "Kill not done - not confirmed."
return 3
fi
return 0
} }
63 changes: 32 additions & 31 deletions kshdb.in
Original file line number Original file line Diff line number Diff line change
@@ -1,22 +1,23 @@
#!@SH_PROG@ #!@SH_PROG@
# -*- shell-script -*- # -*- shell-script -*-
# kshdb - top-level debugger program. # top-level debugger program.
# #
# Copyright (C) 2008, 2009 Rocky Bernstein rocky@gnu.org # Copyright (C) 2008, 2009, 2011 Rocky Bernstein <rocky@gnu.org>
# #
# kshdb is free software; you can redistribute it and/or modify it under # This program is free software; you can redistribute it and/or
# the terms of the GNU General Public License as published by the Free # modify it under the terms of the GNU General Public License as
# Software Foundation; either version 2, or (at your option) any later # published by the Free Software Foundation; either version 2, or
# version. # (at your option) any later version.
# #
# kshdb is distributed in the hope that it will be useful, but WITHOUT ANY # This program is distributed in the hope that it will be useful,
# WARRANTY; without even the implied warranty of MERCHANTABILITY or # but WITHOUT ANY WARRANTY; without even the implied warranty of
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# for more details. # General Public License for more details.
# #
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License
# with kshdb; see the file COPYING. If not, write to the Free Software # along with This program; see the file COPYING. If not, write to
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. # the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
# MA 02111 USA.


# This routine gets called via the -c or --command option and its sole # This routine gets called via the -c or --command option and its sole
# purpose is to capture the command string such as via "x $*" or # purpose is to capture the command string such as via "x $*" or
Expand Down Expand Up @@ -55,17 +56,17 @@ typeset -i _Dbg_i
for ((_Dbg_i=0; $_Dbg_i<${#_Dbg_script_args[@]}-1; _Dbg_i++)) ; do for ((_Dbg_i=0; $_Dbg_i<${#_Dbg_script_args[@]}-1; _Dbg_i++)) ; do
typeset arg=${_Dbg_script_args[$_Dbg_i]} typeset arg=${_Dbg_script_args[$_Dbg_i]}
if [[ $arg == '-L' || $arg == '--libdir' ]] ; then if [[ $arg == '-L' || $arg == '--libdir' ]] ; then
((_Dbg_i++)) ((_Dbg_i++))
_Dbg_libdir="${_Dbg_script_args[$_Dbg_i]}" _Dbg_libdir="${_Dbg_script_args[$_Dbg_i]}"
break break
fi fi
done done


if [[ ! -d $_Dbg_libdir ]] && [[ ! -d $_Dbg_libdir ]] ; then if [[ ! -d $_Dbg_libdir ]] && [[ ! -d $_Dbg_libdir ]] ; then
echo "${_Dbg_pname}: Can't read debugger library directory '${_Dbg_libdir}'." echo "${_Dbg_pname}: Can't read debugger library directory '${_Dbg_libdir}'."
echo "${_Dbg_pname}: Perhaps kshdb is installed wrong (if its installed)." >&2 echo "${_Dbg_pname}: Perhaps @PACKAGE@ is installed wrong (if its installed)." >&2
echo "${_Dbg_pname}: Try running kshdb using -L (with a different directory)." >&2 echo "${_Dbg_pname}: Try running @PACKAGE@ using -L (with a different directory)." >&2
echo "${_Dbg_pname}: Run kshdb --help for a list and explanation of options." >&2 echo "${_Dbg_pname}: Run @PACKAGE@ --help for a list and explanation of options." >&2
exit 1 exit 1
fi fi


Expand Down Expand Up @@ -99,13 +100,13 @@ fi
if (( ${#_Dbg_script_args[@]} > 0 )) ; then if (( ${#_Dbg_script_args[@]} > 0 )) ; then
_Dbg_script_file="${_Dbg_script_args[0]}" _Dbg_script_file="${_Dbg_script_args[0]}"
case ${_Dbg_script_file:0:1} in case ${_Dbg_script_file:0:1} in
'.' | '/' ) '.' | '/' )
# Leave alone # Leave alone
;; ;;
* ) * )
# Make . explicit. # Make . explicit.
_Dbg_script_file="./${_Dbg_script_file}" _Dbg_script_file="./${_Dbg_script_file}"
_Dbg_script_args[0]="$_Dbg_script_file" _Dbg_script_args[0]="$_Dbg_script_file"
esac esac
# FIXME: # FIXME:
# shift _Dbg_script_args # shift _Dbg_script_args
Expand All @@ -130,12 +131,12 @@ while : ; do
trap '' DEBUG trap '' DEBUG
_Dbg_msg_nocr 'Program terminated.' _Dbg_msg_nocr 'Program terminated.'
if (( !o_no_quit )); then if (( !o_no_quit )); then
_Dbg_msg "Type 's' to restart." _Dbg_msg "Type 's' to restart."
_Dbg_process_commands _Dbg_process_commands
_Dbg_step_ignore=2 _Dbg_step_ignore=2
# _Dbg_msg "Type 's' or 'R' to restart." # _Dbg_msg "Type 's' or 'R' to restart."
else else
_Dbg_msg '' _Dbg_msg ''
break break
fi fi
done done
51 changes: 26 additions & 25 deletions lib/journal.sh
Original file line number Original file line Diff line number Diff line change
@@ -1,21 +1,22 @@
# -*- shell-script -*- # -*- shell-script -*-
# Things related to variable journaling. # Things related to variable journaling.
# #
# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org # Copyright (C) 2008, 2011 Rocky Bernstein <rocky@gnu.org>
# #
# kshdb is free software; you can redistribute it and/or modify it under # This program is free software; you can redistribute it and/or
# the terms of the GNU General Public License as published by the Free # modify it under the terms of the GNU General Public License as
# Software Foundation; either version 2, or (at your option) any later # published by the Free Software Foundation; either version 2, or
# version. # (at your option) any later version.
# #
# kshdb is distributed in the hope that it will be useful, but WITHOUT ANY # This program is distributed in the hope that it will be useful,
# WARRANTY; without even the implied warranty of MERCHANTABILITY or # but WITHOUT ANY WARRANTY; without even the implied warranty of
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# for more details. # General Public License for more details.
# #
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License
# with kshdb; see the file COPYING. If not, write to the Free Software # along with this program; see the file COPYING. If not, write to
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. # 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 # 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 # values set in a subshell or nested shell back. This typically
Expand All @@ -27,26 +28,26 @@ typeset _Dbg_journal=$(_Dbg_tempname journal)


# append a command into journal file and then run the command. # append a command into journal file and then run the command.
_Dbg_write_journal_eval() { _Dbg_write_journal_eval() {
_Dbg_write_journal "$@" _Dbg_write_journal "$@"
eval "$@" eval "$@"
} }


# append a command into journal file and then run the command. # append a command into journal file and then run the command.
_Dbg_write_journal_var() { _Dbg_write_journal_var() {
typeset var_name=$1 typeset var_name="$1"
typeset val typeset val
typeset val_cmd="$val=\${$var_name}" typeset val_cmd="$val=\${$var_name}"
eval $val_cmd eval "$val_cmd"
_Dbg_write_journal "${var_name}=${val}" _Dbg_write_journal "${var_name}=${val}"
} }


_Dbg_write_journal_avar() { _Dbg_write_journal_avar() {
typeset decl_str=$(declare -p $1) typeset decl_str; decl_str=$(declare -p $1)
typeset -a decl_a typeset -a decl_a
decl_a=($decl_str) decl_a=($decl_str)
typeset -a decl_a2 typeset -a decl_a2
decl_a2=${decl_a[@]:2} decl_a2=${decl_a[@]:2}
_Dbg_write_journal ${decl_a2[@]} _Dbg_write_journal ${decl_a2[@]}
} }


# Append a command into journal file. But we only need to do # Append a command into journal file. But we only need to do
Expand Down
2 changes: 1 addition & 1 deletion test/data/restart.cmd
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ list
step step
step step
break 5 break 5
restart -B -q -L ../.. -x ../../test/data/restart2.cmd ../../test/example/restart.sh restart -B -n -q -L ../.. -x ../../test/data/restart2.cmd ../../test/example/restart.sh
# We never get here # We never get here
print You should not see this. print You should not see this.
quit quit
2 changes: 1 addition & 1 deletion test/data/restart.right
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cd /
y=2 y=2
+break 5 +break 5
Breakpoint 1 set in file restart.sh, line 5. Breakpoint 1 set in file restart.sh, line 5.
+run -B -q -L ... restart.sh +run -B -n -q -L ... restart.sh
Restarting with ... restart.sh Restarting with ... restart.sh
(restart.sh:4): (restart.sh:4):
x=1 x=1
Expand Down

0 comments on commit 73a9baf

Please sign in to comment.