Permalink
Browse files

break.sh: use functions for better localization

  • Loading branch information...
1 parent 4e6b244 commit 3f41480aa006669e2f382596bcf4f48cab056603 @rocky committed Jun 10, 2009
Showing with 64 additions and 24 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 command/Makefile.am
  3. +2 −1 configure.ac
  4. +5 −1 dbg-trace.sh.in
  5. +8 −9 lib/break.sh
  6. +9 −2 lib/msg.sh
  7. +23 −5 lib/processor.sh
  8. +1 −0 test/unit/.gitignore
  9. +1 −2 test/unit/Makefile.am
  10. +4 −4 test/unit/test-break.sh.in
  11. +6 −0 test/unit/test-msg.sh.in
View
@@ -13,5 +13,6 @@
/install-sh
/kshdb
/kshdb-*.tar.gz
+/kshdb-*.tar.bz2
/kshdb-trace
/missing
View
@@ -3,8 +3,12 @@ pkgdata_DATA = \
alias.sh \
break.sh \
continue.sh \
+ delete.sh \
+ disable.sh \
edit.sh \
+ enable.sh \
eval.sh \
+ examine.sh \
frame.sh \
help.sh \
info.sh \
View
@@ -108,13 +108,14 @@ AC_CONFIG_FILES([test/unit/test-columns.sh],
[chmod +x test/unit/test-columns.sh])
AC_CONFIG_FILES([test/unit/test-dbg-opts.sh],
[chmod +x test/unit/test-dbg-opts.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-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-journal.sh],
[chmod +x test/unit/test-journal.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-run.sh], [chmod +x test/unit/test-run.sh])
AC_CONFIG_FILES([test/unit/test-save-restore.sh],
View
@@ -1,7 +1,7 @@
# -*- shell-script -*-
# This program needs to be SOURCE'd and is not called as an executable
#
-# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
+# Copyright (C) 2008, 2009 Rocky Bernstein rocky@gnu.org
#
# kshdb 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
@@ -73,3 +73,7 @@ fi
set -${_Dbg_trace_old_set_opts}
unset _Dbg_trace_old_set_opts
+
+_Dbg_debugger() {
+ trap '_Dbg_hook $? "$@"' DEBUG
+}
View
@@ -1,6 +1,6 @@
# -*- shell-script -*-
#
-# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
+# Copyright (C) 2008, 2009 Rocky Bernstein rocky@gnu.org
#
# kshdb is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
@@ -76,7 +76,7 @@ _Dbg_save_breakpoints() {
# Start out with general break/watchpoint functions first...
# Enable/disable breakpoint or watchpoint by entry numbers.
-_Dbg_enable_disable() {
+function _Dbg_enable_disable {
if (($# == 0)) ; then
_Dbg_errmsg "Expecting a list of breakpoint/watchpoint numbers. Got none."
return 1
@@ -194,7 +194,7 @@ _Dbg_set_brkpt() {
}
# Internal routine to unset the actual breakpoint arrays
-_Dbg_unset_brkpt_arrays() {
+function _Dbg_unset_brkpt_arrays {
(( $# != 1 )) && return 1
typeset -i del=$1
_Dbg_write_journal_eval "_Dbg_brkpt[$del].lineno=0"
@@ -208,7 +208,7 @@ _Dbg_unset_brkpt_arrays() {
# Internal routine to delete a breakpoint by file/line.
# The number of breakpoints unset returned.
-_Dbg_unset_brkpt() {
+function _Dbg_unset_brkpt {
(( $# != 2 )) && return 0
typeset filename="$1"
typeset -i lineno=$2
@@ -239,13 +239,13 @@ _Dbg_unset_brkpt() {
# Routine to a delete breakpoint by entry number: $1.
# Returns whether or not anything was deleted.
-_Dbg_delete_brkpt_entry() {
+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
+ if [[ -z ${_Dbg_brkpt[$del]} ]] ; then
_Dbg_errmsg "No breakpoint number $del."
return 0
fi
@@ -254,7 +254,7 @@ _Dbg_delete_brkpt_entry() {
typeset -i try
typeset -a new_lineno_val; new_lineno_val=()
typeset -a new_brkpt_nos; new_brkpt_nos=()
- typeset -i i
+ typeset -i i=-1
brkpt_nos=(${_Dbg_brkpt_file2brkpt[$source_file]})
for try in ${_Dbg_brkpt_file2linenos[$source_file]} ; do
((i++))
@@ -279,12 +279,11 @@ _Dbg_delete_brkpt_entry() {
_Dbg_write_journal_eval "_Dbg_brkpt_file2brkpt[$source_file]=${new_brkpt_nos}"
fi
fi
-
return $found
}
# Enable/disable breakpoint(s) by entry numbers.
-_Dbg_enable_disable_brkpt() {
+function _Dbg_enable_disable_brkpt {
(($# != 3)) && return 1
typeset -i on=$1
typeset en_dis=$2
View
@@ -1,7 +1,6 @@
# -*- shell-script -*-
-# dbg-fns.inc - Debugger Utility Functions
#
-# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
+# Copyright (C) 2008, 2009 Rocky Bernstein rocky@gnu.org
#
# kshdb 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
@@ -68,3 +67,11 @@ function _Dbg_printf_nocr {
fi
}
+# Common funnel for "Undefined command" message
+_Dbg_undefined_cmd() {
+ if (( $# == 2 )) ; then
+ _Dbg_msg "Undefined $1 subcommand \"$2\". Try \"help $1\"."
+ else
+ _Dbg_msg "Undefined command \"$1\". Try \"help\"."
+ fi
+}
View
@@ -1,5 +1,5 @@
# -*- shell-script -*-
-# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
+# Copyright (C) 2008, 2009 Rocky Bernstein rocky@gnu.org
#
# kshdb 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
@@ -71,7 +71,7 @@ function _Dbg_process_commands {
_Dbg_onecmd "$_Dbg_cmd" "$args"
rc=$?
# _Dbg_postcmd
- (( $rc > 0 )) && return $rc
+ (( rc > 0 && rc != 255 )) && return $rc
done
unset _Dbg_fd[_Dbg_fd_last--]
@@ -135,6 +135,18 @@ _Dbg_onecmd() {
fi
;;
+ # Delete breakpoints by entry numbers.
+ delete )
+ _Dbg_do_delete $args
+ _Dbg_last_cmd='delete'
+ ;;
+
+ # Disable breakpoints
+ disable )
+ _Dbg_do_disable $args
+ _Dbg_last_cmd='disable'
+ ;;
+
# Move call stack down
down )
_Dbg_do_down $@
@@ -147,6 +159,12 @@ _Dbg_onecmd() {
_Dbg_last_cmd='edit'
;;
+ # enable breakpoints or watchpoints
+ enable )
+ _Dbg_do_enable $args
+ _Dbg_last_cmd='enable'
+ ;;
+
# evaluate as shell command
eval )
_Dbg_do_eval $@
@@ -258,13 +276,13 @@ _Dbg_onecmd() {
* )
if (( _Dbg_autoeval )) ; then
- ! _Dbg_do_eval $_Dbg_cmd $args && return -1
+ ! _Dbg_do_eval $_Dbg_cmd $args && return 255
else
- _Dbg_msg "Undefined command: \"$_Dbg_cmd\". Try \"help\"."
+ _Dbg_undefined_cmd $_Dbg_cmd
# _Dbg_remove_history_item
# typeset -a last_history=(`history 1`)
# history -d ${last_history[0]}
- return -1
+ return 255
fi
;;
esac
View
@@ -5,6 +5,7 @@
/test-break.sh
/test-columns.sh
/test-dbg-opts.sh
+/test-file.sh
/test-filecache.sh
/test-fns.sh
/test-frame.sh
View
@@ -5,11 +5,11 @@ TESTS = test-alias.sh \
test-break.sh \
test-columns.sh \
test-dbg-opts.sh \
+ test-file.sh \
test-filecache.sh \
test-fns.sh \
test-frame.sh \
test-journal.sh \
- test-io.sh \
test-pre.sh \
test-run.sh \
test-save-restore.sh \
@@ -29,7 +29,6 @@ EXTRA_DIST = $(TESTS) $(check_DATA) \
test-fns.sh.in \
test-frame.sh.in \
test-journal.sh.in \
- test-io.sh.in \
test-pre.sh.in \
test-run.sh.in \
test-save-restore.sh.in \
@@ -25,16 +25,16 @@ test_breakpoint()
# Test parameter count checking for _Dbg_set_brkpt
_Dbg_set_brkpt
- assertNotEquals '0' "$?"
+ assertNotEquals '_Dbg_set_brkpt no parms - should be bad' '0' "$?"
_Dbg_set_brkpt 1 2 3 4 5
- assertNotEquals '0' "$?"
+ assertNotEquals '_Dbg_set_brkpt parms - should be good' '0' "$?"
- assertEquals 0 $_Dbg_brkpt_count
+ assertEquals '$_Dbg_brkpt_count should be 0' 0 $_Dbg_brkpt_count
# This should work
_Dbg_set_brkpt test.sh 5 0
assertEquals 'Breakpoint 1 set in file test.sh, line 5.' "${msgs[-1]}"
- assertEquals 1 $_Dbg_brkpt_count
+ assertEquals '$_Dbg_brkpt_count should be 1' 1 $_Dbg_brkpt_count
msgs=()
# Test parameter count checking for _Dbg_unset_brkpt
View
@@ -16,6 +16,12 @@ test_msg()
assertEquals 'fo ' "$msg"
}
+test_undefined()
+{
+ typeset msg=$(_Dbg_undefined_cmd foo bar)
+ assertEquals 'Undefined foo command "bar". Try "help".' "$msg"
+}
+
top_srcdir=@top_srcdir@
. ${top_srcdir}/lib/msg.sh

0 comments on commit 3f41480

Please sign in to comment.