Permalink
Browse files

Allow unique abbreviations of commands in "help". Expand help for "en…

…able" and "disable" and give error message when no args. Sync with bashdb
  • Loading branch information...
1 parent e17a7d2 commit f869432559f73022d4facc43a63fe908830f47c3 @rocky committed May 17, 2011
Showing with 92 additions and 45 deletions.
  1. +5 −2 NEWS
  2. +11 −3 command/disable.sh
  3. +12 −3 command/enable.sh
  4. +63 −36 command/help.sh
  5. +1 −1 command/untrace.sh
View
7 NEWS
@@ -6,9 +6,12 @@ Version 0.06
* "info functions"
* "condition"
* "complete"
-- Remove hard-wiring of info, set, and show commands.
+- Remove hard-wiring of "info", "set", and "show" commands.
- Expand help text for various commands
-- Fix bugs in 'trace' and 'shell' commands
+- Debugger commands can be the smallest unique prefix
+- Fix bugs in 'trace', 'untrace' and 'shell' commands
+- "set debugging" is not "set debug" to match gdb
+- Unit tests are faster and have less white space but more useful information
Version 0.05
2011-3-15 Ron Frankel release
View
@@ -19,10 +19,18 @@
# MA 02111 USA.
_Dbg_help_add disable \
-'disable {n}... -- Disable breakpoint entry/entries.' 1
+'disable BPNUM1 [BPNUM2 ...]
+
+Disable breakpoint BPNUM.
+
+See also "enable" and "info break".' 1 _Dbg_complete_brkpt_range
# Disable breakpoint(s)/watchpoint(s) by entry number(s).
_Dbg_do_disable() {
- _Dbg_enable_disable 0 'disabled' $@
- return $?
+ if (($# == 0)) ; then
+ _Dbg_errmsg 'Expecting breakpoint/watchpoint numbers. Got none.'
+ return 1
+ fi
+ _Dbg_enable_disable 0 'disabled' $@
+ return $?
}
View
@@ -19,10 +19,19 @@
# MA 02111 USA.
_Dbg_help_add enable \
-'enable {N}... -- Enable breakpoint entry/entries.' 1
+'enable BPNUM1 [BPNUM2 ...]
+
+Enables breakpoints BPNUM1, BPNUM2... Breakpoints numbers are given as a space-
+separated list numbers.
+
+See also "disable" and "info break".' 1 _Dbg_complete_brkpt_range
# Enable breakpoint(s)/watchpoint(s) by entry number(s).
_Dbg_do_enable() {
- _Dbg_enable_disable 1 'enabled' $@
- return $?
+ if (($# == 0)) ; then
+ _Dbg_errmsg 'Expecting breakpoint/watchpoint numbers. Got none.'
+ return 1
+ fi
+ _Dbg_enable_disable 1 'enabled' $@
+ return $?
}
View
@@ -25,7 +25,18 @@ if [[ $0 == ${.sh.file##*/} ]] ; then
fi
_Dbg_help_add help \
-'help -- Print list of commands.' 1
+'help [COMMAND [SUBCOMMAND ..]]
+
+If no arguments are given, print a list of command names.
+With a command name give help for that command. For many commands
+you can get further detailed help by listing the subcommand name.
+
+Examples:
+
+help
+help up
+help set
+help set args' 1 _Dbg_complete_help
_Dbg_do_help() {
if ((0==$#)) ; then
@@ -36,44 +47,60 @@ _Dbg_do_help() {
_Dbg_msg 'Readline command line editing (emacs/vi mode) is available.'
_Dbg_msg 'Type "help" followed by command name for full documentation.'
return 0
- else
- typeset dbg_cmd="$1"
- if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then
- _Dbg_msg "${_Dbg_command_help[$dbg_cmd]}"
- else
- _Dbg_alias_expand $dbg_cmd
- typeset dbg_cmd="$expanded_alias"
- if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then
- _Dbg_msg "${_Dbg_command_help[$dbg_cmd]}"
- else
- case $dbg_cmd in
- i | in | inf | info )
- _Dbg_info_help $2
- ;;
- sh | sho | show )
- _Dbg_help_show $2
- ;;
- se | set )
- _Dbg_help_set $2
- ;;
- * )
- _Dbg_errmsg "Undefined command: \"$dbg_cmd\". Try \"help\"."
- return 1 ;;
- esac
- fi
- fi
- aliases_found=''
- _Dbg_alias_find_aliased "$dbg_cmd"
- if [[ -n $aliases_found ]] ; then
- _Dbg_msg ''
- _Dbg_msg "Aliases for $dbg_cmd: $aliases_found"
- fi
- return 0
- fi
+ else
+ typeset dbg_cmd="$1"
+ if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then
+ _Dbg_msg "${_Dbg_command_help[$dbg_cmd]}"
+ else
+ _Dbg_alias_expand $dbg_cmd
+ dbg_cmd="$expanded_alias"
+ if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then
+ _Dbg_msg "${_Dbg_command_help[$dbg_cmd]}"
+ else
+ case $dbg_cmd in
+ i | in | inf | info )
+ _Dbg_info_help $2
+ ;;
+ sh | sho | show )
+ _Dbg_help_show $2
+ ;;
+ se | set )
+ _Dbg_help_set $2
+ ;;
+ * )
+ # Look for a unique abbreviation
+ typeset -i count=0
+ typeset found_cmd
+ typeset list; list="${!_Dbg_command_help[@]}"
+ for try in $list ; do
+ if [[ $try =~ ^$dbg_cmd ]] ; then
+ found_cmd=$try
+ ((count++))
+ fi
+ done
+ ((found=(count==1)))
+ if ((found)); then
+ _Dbg_msg "${_Dbg_command_help[$found_cmd]}"
+ else
+ _Dbg_errmsg "Undefined command: \"$dbg_cmd\". Try \"help\"."
+ return 1
+ fi
+ ;;
+ esac
+ fi
+ fi
+ aliases_found=''
+ _Dbg_alias_find_aliased "$dbg_cmd"
+ if [[ -n $aliases_found ]] ; then
+ _Dbg_msg ''
+ _Dbg_msg "Aliases for $dbg_cmd: $aliases_found"
+ fi
+ return 2
+ fi
}
-_Dbg_alias_add '?' help
_Dbg_alias_add 'h' help
+_Dbg_alias_add '?' help
# Demo it.
if [[ $0 == ${.sh.file##*/} ]] ; then
View
@@ -30,7 +30,7 @@ function _Dbg_do_untrace {
_Dbg_errmsg "untrace: missing or invalid function name."
return 2
fi
- _Dbg_is_function "$fn" || {
+ _Dbg_is_function "$fn" $_Dbg_set_debug || {
_Dbg_errmsg "untrace: function \"$fn\" is not a function."
return 3
}

0 comments on commit f869432

Please sign in to comment.