Skip to content

Commit

Permalink
Allow **count** to "skip" command...
Browse files Browse the repository at this point in the history
Some minor doc fixes
  • Loading branch information
rocky committed Oct 26, 2019
1 parent d3f0050 commit 1717814
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 83 deletions.
27 changes: 22 additions & 5 deletions command/skip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
# MA 02111 USA.

_Dbg_help_add skip \
"**skip**
"**skip** [*count*]
Skip (don't run) the next command(s).
Skip (don't run) the next *count* command(s).
If *count* is given, stepping occurs that many times before
stopping. Otherwise *count* is one. *count* can be an arithmetic
expression.
Note that skipping doesn't change the value of \$?. This has
consequences in some compound statements that test on \$?. For example
Expand All @@ -31,19 +35,32 @@ in:
echo not skipped
fi
skipping the *if* statement will in effect skip running the *grep*
Skipping the *if* statement will, in effect, skip running the *grep*
command. Since the return code is 0 when skipped, the *if* body is
entered. Similarly the same thing can happen in a *while* statement
test.
See also:
---------
**next**, **step**, **continue*, and **finish**.
**continue**, **next**, and **step**.
"

_Dbg_do_skip() {
_Dbg_last_cmd='skip'
, _Dbg_skip=1

typeset count=${1:-1}

if [[ $count == [0-9]* ]] ; then
_Dbg_skip_ignore=${count:-1}
_Dbg_continue_rc=0
else
_Dbg_errmsg "'skip' argument ($count) should be a number or nothing."
return 0
fi

_Dbg_step_ignore=1
# We're cool. Do the skip.
_Dbg_write_journal "_Dbg_skip_ignore=$_Dbg_skip_ignore"
return $?
}
52 changes: 2 additions & 50 deletions command/stepping.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- shell-script -*-
# stepping.cmd - gdb-like "step" and "skip" debugger commands
#
# Copyright (C) 2008, 2010, 2016-2017 Rocky Bernstein [email protected]
# Copyright (C) 2008, 2010, 2016-2017, 2019 Rocky Bernstein [email protected]
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
Expand All @@ -18,9 +18,6 @@
# the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
# MA 02111 USA.

# Number of statements to skip before entering the debugger if greater than 0
typeset -i _Dbg_skip_ignore=0

# 1 if we need to ensure we stop on a different line?
typeset -i _Dbg_step_force=0

Expand All @@ -30,53 +27,8 @@ typeset -i _Dbg_return_level=-1
# The default behavior of step_force.
typeset -i _Dbg_set_different=0

_Dbg_help_add skip \
"**skip** [*count*]
Skip (don't run) the next *count* command(s).
If *count* is given, stepping occurs that many times before
stopping. Otherwise *count* is one. *count* can be an arithmetic
expression.
See also:
---------
**next** and **step**.
"

_Dbg_do_skip() {
_Dbg_do_skip_internal $@ && return 2
}

# Return 0 if we should skip. Nonzero if there was an error.
# $1 is an optional additional count.
_Dbg_do_skip_internal() {

_Dbg_not_running && return 1

_Dbg_last_cmd='skip'
typeset count=${1:-1}

if [[ $count == [0-9]* ]] ; then
_Dbg_skip_ignore=${count:-1}
((_Dbg_skip_ignore--)) # Remove one from the skip caused by this return
else
_Dbg_errmsg "Argument ($count) should be a number or nothing."
_Dbg_skip_ignore=0
return 3
fi
# We're cool. Do the skip.
_Dbg_write_journal "_Dbg_skip_ignore=$_Dbg_skip_ignore"

# Set to do a stepping stop after skipping
_Dbg_step_ignore=0
_Dbg_write_journal "_Dbg_step_ignore=$_Dbg_step_ignore"
return 0
}

_Dbg_help_add 'step' \
"**step** *count*
"**step** [*count*]
Single step a statement *count* times.
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ AC_CONFIG_FILES([test/example/hanoi.sh],
[chmod +x test/example/hanoi.sh])
AC_CONFIG_FILES([test/example/restart.sh],
[chmod +x test/example/restart.sh])
AC_CONFIG_FILES([test/example/skip.sh],
[chmod +x test/example/skip.sh])

AC_CONFIG_FILES([test/integration/test-action],
[chmod +x test/integration/test-action])
Expand Down
12 changes: 8 additions & 4 deletions docs/commands/running/skip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
Skip (skip over)
----------------

**skip**
**skip** [*count*]

Skip (don't run) the next command(s).
Skip (don't run) the next *count* command(s).

If *count* is given, stepping occurs that many times before
stopping. Otherwise *count* is one. *count* can be an arithmetic
expression.

Note that skipping doesn't change the value of \$?. This has
consequences in some compound statements that test on \$?. For example
Expand All @@ -16,11 +20,11 @@ in:
echo not skipped
fi

skipping the *if* statement will in effect skip running the *grep*
Skipping the *if* statement will, in effect, skip running the *grep*
command. Since the return code is 0 when skipped, the *if* body is
entered. Similarly the same thing can happen in a *while* statement
test.

.. seealso::

:ref:`next <next>` command. :ref:`step <step>`, :ref:`continue <continue>`, and :ref:`finish <finish>` provide other ways to progress execution.
:ref:`next <next>` command. :ref:`step <step>`, and :ref:`continue <continue>` provide other ways to progress execution.
13 changes: 8 additions & 5 deletions lib/hook.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- shell-script -*-
# -*- shell-script -*-
# hook.sh - Debugger trap hook
#
# Copyright (C) 2008, 2009, 2010, 2011, 2018
Expand Down Expand Up @@ -28,6 +28,9 @@ typeset -i _Dbg_QUIT_LEVELS=0 # Number of nested shells we have to exit
# Return code that debugged program reports
typeset -i _Dbg_program_exit_code=0

# Number of statements to skip before entering the debugger if greater than 0
typeset -i _Dbg_skip_ignore=0

# This is the main hook routine that gets called before every statement.
# It's the function called via trap DEBUG.
function _Dbg_trap_handler {
Expand Down Expand Up @@ -77,8 +80,9 @@ function _Dbg_trap_handler {
if ((! _Dbg_skipping_fn )) ; then
((_Dbg_skip_ignore--))
_Dbg_write_journal "_Dbg_skip_ignore=$_Dbg_skip_ignore"
_Dbg_set_to_return_from_debugger 2
return 2 # 2 indicates skip statement.
# Set to skip instruction
set -o errexit
return
fi
fi

Expand Down Expand Up @@ -231,8 +235,7 @@ _Dbg_hook_enter_debugger() {
_Dbg_print_location_and_command
_Dbg_process_commands
_Dbg_set_to_return_from_debugger $?
if (( $_Dbg_skip != 0 )) ; then
echo "Skipping..."
if (( $_Dbg_skip_ignore != 0 )) ; then
# Set to skip instruction
set -o errexit
fi
Expand Down
13 changes: 11 additions & 2 deletions test/data/skip.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
set trace-commands on
# Make sure autostep is off for next text
# Make sure autostep is off for tests
set force on
# Test that skip skips multiple statements
n
x x
skip fdafsdg
skip
where 1
x x
n
skip 2
x x
n
skip 1+2
c
quit
38 changes: 31 additions & 7 deletions test/data/skip.right
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
(stepping.sh:3):
for ((i=0; i<3; i++)) do print 1st loop $i done
+# Make sure autostep is off for next text
(skip.sh:3):
x=1
+# Make sure autostep is off for tests
+set force on
Show stepping forces a new line is on.
+# Test that skip skips multiple statements
+n
(skip.sh:4):
x=2
+x x
typeset -g x=1
+skip fdafsdg
** 'skip' argument (fdafsdg) should be a number or nothing.
+skip
(stepping.sh:4):
for ((i=0; i<3; i++)) do print 2nd loop $i done
+where 1
->0 in file `stepping.sh' at line 4
(skip.sh:6):
x=4
+x x
typeset -g x=1
+n
(skip.sh:7):
x=5
+skip 2
(skip.sh:10):
x=8
+x x
typeset -g x=4
+n
(skip.sh:11):
x=9
+skip 1+2
(skip.sh:15):
echo $x
+c
8
Program terminated. Type 's' or 'R' to restart.
+quit
zshdb: That's all, folks...
11 changes: 4 additions & 7 deletions test/data/step.cmd
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
set trace-commands on
# Make sure autostep is off for next text
# Make sure autostep is off for tests
set force off
show force
# Test that step+ skips multiple statements
step+
set force on
set force on
show force
# Same thing - skip loop
step
step
# Override force
step-
s-
# A null command should use the last step

step
step
# Try a null command the other way
s+

quit



2 changes: 1 addition & 1 deletion test/data/step.right
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(stepping.sh:3):
for ((i=0; i<3; i++)) do print 1st loop $i done
+# Make sure autostep is off for next text
+# Make sure autostep is off for tests
+set force off
Show stepping forces a new line is off.
+show force
Expand Down
1 change: 1 addition & 0 deletions test/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/Makefile.in
/hanoi.sh
/restart.sh
/skip.sh
3 changes: 2 additions & 1 deletion test/example/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ check_DATA = \
multi.sh \
nexting.sh \
restart.sh \
skip.sh \
stepping.sh \
subshell.sh

SOURCES=hanoi.sh.in restart.sh.in
SOURCES=hanoi.sh.in restart.sh.in skip.sh.in

EXTRA_DIST = $(check_DATA) $(SOURCES)
15 changes: 15 additions & 0 deletions test/example/skip.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!@SH_PROG@
# For testing skip
x=1
x=2
x=3
x=4
x=5
x=6
x=7
x=8
x=9
x=10
x=11
x=12
echo $x
2 changes: 1 addition & 1 deletion test/integration/test-skip.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ t=${0##*/}; TEST_NAME=$t[6,-1] # basename $0 with 'test-' stripped off

[ -z "$builddir" ] && builddir=$PWD
. ${builddir}/check-common.sh
run_test_check stepping
run_test_check

0 comments on commit 1717814

Please sign in to comment.