Skip to content

Commit cd460df

Browse files
committed
Lots of little fixes...
* Go over stepping code and RsT help; remove dup step fn. * Remove "set force". * Clean up hanoi.sh example program Some work towards adding a "return" statement. ksh might have a bug here though.
1 parent d4cd04c commit cd460df

15 files changed

Lines changed: 167 additions & 162 deletions

File tree

command/next.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- shell-script -*-
2-
# stepping.cmd - gdb-like "next" debugger command
2+
# next.sh - gdb-like "next" debugger command
33
#
44
# Copyright (C) 2008, 2009, 2010, 2011 Rocky Bernstein <rocky@gnu.org>
55
#
@@ -19,34 +19,47 @@
1919
# MA 02111 USA.
2020

2121
_Dbg_help_add next \
22-
"next [COUNT]
22+
"**next** [*count*]
2323
24-
Single step a statement COUNT times ignoring functions.
24+
Step over a statement *count* times ignoring functions.
2525
26-
If COUNT is given, stepping occurs that many times before
27-
stopping. Otherwise COUNT is one. COUNT an be an arithmetic
26+
If *count* is given, stepping occurs that many times before
27+
stopping. Otherwise *count* is one. *count* can be an arithmetic
2828
expression.
2929
30-
In contrast to \"step\", functions and source\'d files are not stepped
30+
In contrast to **step**, functions and source\'d files are not stepped
3131
into.
3232
33-
See also \"step\" \"skip\", \"next-\" \"next+\", and \"set force\"."
33+
See also:
34+
---------
35+
36+
**step**, **skip**, **next-** **next+**, and **set different**."
3437

3538
_Dbg_help_add 'next+' \
36-
"next+ -- Next stepping ensuring a different line after the step.
39+
"**next+**
40+
41+
Step over stepping ensuring a different line after the step.
3742
38-
In contrast to \"next\", we ensure that the file and line position is
43+
In contrast to **next**, we ensure that the file and line position is
3944
different from the last one just stopped at.
4045
41-
See also \"next-\", \"next\" and \"set force\"."
46+
See also:
47+
---------
48+
49+
**next-**, **next** and **set different**." 0
4250

4351
_Dbg_help_add 'next-' \
44-
"next- -- Next stepping a statement without the \`set force' setting.
52+
"**next-**
53+
54+
Step over stepping a statement without the **set different** setting.
4555
4656
Set step force may have been set on. step- ensures we turn that off for
4757
this command.
4858
49-
See also \"next+\", \"next\" and \"set force\"."
59+
See also:
60+
---------
61+
62+
**next+**, **next**, and **set different**." 0
5063

5164
# Next command
5265
# $1 is command next+, next-, or next

command/set.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ _Dbg_do_set() {
5858
fi
5959

6060
case $subcmd in
61-
force )
62-
_Dbg_set_onoff "$1" 'different'
63-
;;
6461
inferior-tty )
6562
_Dbg_set_tty $@
6663
;;

command/set_sub/different.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- shell-script -*-
22
# "set different" debugger command
33
#
4-
# Copyright (C) 2011 Rocky Bernstein <rocky@gnu.org>
4+
# Copyright (C) 2011, 2019 Rocky Bernstein <rocky@gnu.org>
55
#
66
# This program is free software; you can redistribute it and/or
77
# modify it under the terms of the GNU General Public License as
@@ -19,9 +19,14 @@
1919
# MA 02111 USA.
2020

2121
_Dbg_help_add_sub set different \
22-
'set different [on|off]
22+
'**set different** [**off**|**on**]
2323
24-
When set, stop at a different line from the last one stopped.' 1
24+
Set to stop at a different line
25+
26+
See also:
27+
---------
28+
29+
**show different**' 1
2530

2631
_Dbg_do_set_different() {
2732
_Dbg_set_onoff "$1" 'different'

command/skip.sh

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- shell-script -*-
2-
# stepping.cmd - gdb-like "skip" debugger commands
2+
# skip.sh - gdb-like "skip" debugger command
33
#
4-
# Copyright (C) 2008, 2009, 2010, 2011 Rocky Bernstein <rocky@gnu.org>
4+
# Copyright (C) 2008-2011, 2019 Rocky Bernstein <rocky@gnu.org>
55
#
66
# This program is free software; you can redistribute it and/or
77
# modify it under the terms of the GNU General Public License as
@@ -19,13 +19,32 @@
1919
# MA 02111 USA.
2020

2121
_Dbg_help_add skip \
22-
"skip [COUNT]
22+
"**skip** [*count*]
2323
24-
Skip (don't run) the next COUNT command(s).
24+
Skip (don't run) the next *count* command(s).
2525
26-
If COUNT is given, stepping occurs that many times before
27-
stopping. Otherwise COUNT is one. COUNT an be an arithmetic
28-
expression. See also \"next\" and \"step\"."
26+
If *count* is given, stepping occurs that many times before
27+
stopping. Otherwise *count* is one. *count* can be an arithmetic
28+
expression.
29+
30+
Note that skipping doesn't change the value of \$?. This has
31+
consequences in some compound statements that test on \$?. For example
32+
in:
33+
34+
if grep foo bar.txt ; then
35+
echo not skipped
36+
fi
37+
38+
Skipping the *if* statement will, in effect, skip running the *grep*
39+
command. Since the return code is 0 when skipped, the *if* body is
40+
entered. Similarly the same thing can happen in a *while* statement
41+
test.
42+
43+
See also:
44+
---------
45+
46+
**continue**, **next**, and **step**.
47+
"
2948

3049
# Return 0 if we should skip. Nonzero if there was an error.
3150
# $1 is an optional additional count.
@@ -46,38 +65,9 @@ _Dbg_do_skip() {
4665
# We're cool. Do the skip.
4766
_Dbg_write_journal "_Dbg_skip_ignore=$_Dbg_skip_ignore"
4867

49-
# Set to do a stepping stop after skipping
68+
# Set to do a stepping stop after skipping. Note: skip != step.
5069
_Dbg_step_ignore=0
5170
_Dbg_write_journal "_Dbg_step_ignore=$_Dbg_step_ignore"
71+
5272
return 0
5373
}
54-
55-
_Dbg_help_add 'step' \
56-
"step [COUNT]
57-
58-
Single step a statement COUNT times.
59-
60-
If COUNT is given, stepping occurs that many times before
61-
stopping. Otherwise COUNT is one. COUNT an be an arithmetic
62-
expression.
63-
64-
In contrast to \"next\", functions and source\'d files are stepped
65-
into.
66-
67-
See also \"next\", \"skip\", \"step-\" \"step+\", and \"set force\"."
68-
69-
_Dbg_help_add 'step+' \
70-
"step+ -- Single step a statement ensuring a different line after the step.
71-
72-
In contrast to \"step\", we ensure that the file and line position is
73-
different from the last one just stopped at.
74-
75-
See also \"step-\" and \"set force\"."
76-
77-
_Dbg_help_add 'step-' \
78-
"step- -- Single step a statement without the \`step force' setting.
79-
80-
Set step force may have been set on. step- ensures we turn that off for
81-
this command.
82-
83-
See also \"step\" and \"set force\"."

command/step.sh

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- shell-script -*-
2-
# stepping.cmd - gdb-like "step" and "skip" debugger commands
2+
# step.sh - gdb-like "step" and "skip" debugger commands
33
#
4-
# Copyright (C) 2008, 2009, 2010, 2011 Rocky Bernstein <rocky@gnu.org>
4+
# Copyright (C) 2008-2011, 2019 Rocky Bernstein <rocky@gnu.org>
55
#
66
# This program is free software; you can redistribute it and/or
77
# modify it under the terms of the GNU General Public License as
@@ -21,48 +21,57 @@
2121
# Number of statements to skip before entering the debugger if greater than 0
2222
typeset -i _Dbg_skip_ignore=0
2323

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

2727
# if positive, the frame level we want to stop at next
2828
typeset -i _Dbg_return_level=-1
2929

30-
# The default behavior of "set different".
31-
typeset -i _Dbg_set_different=0
30+
# The default behavior of "set different".
31+
typeset -i _Dbg_set_different=0
3232

3333
_Dbg_help_add 'step' \
34-
"step [COUNT]
34+
"**step** [*count*]
3535
36-
Single step a statement COUNT times.
36+
Single step a statement *count* times.
3737
38-
If COUNT is given, stepping occurs that many times before
39-
stopping. Otherwise COUNT is one. COUNT an be an arithmetic
38+
If *count* is given, stepping occurs that many times before
39+
stopping. Otherwise *count* is one. *count* an be an arithmetic
4040
expression.
4141
4242
In contrast to \"next\", functions and source\'d files are stepped
4343
into.
4444
45-
See also \"next\", \"skip\", \"step-\" \"step+\", and \"set different\"."
45+
See also:
46+
---------
47+
48+
**next**, **skip**, **step-** **step+**, and **set different**."
4649

4750
_Dbg_help_add 'step+' \
48-
"step+ [COUNT]
51+
"**step+**
4952
5053
Single step a statement ensuring a different line after the step.
5154
52-
In contrast to \"step\", we ensure that the file and line position is
55+
In contrast to **step**, we ensure that the file and line position is
5356
different from the last one just stopped at.
5457
55-
See also \"step-\" and \"set different\"."
58+
See also:
59+
---------
60+
61+
**step-** and **set different**."
5662

5763
_Dbg_help_add 'step-' \
58-
"step- [COUNT]
64+
"**step-**
5965
60-
Single step a statement without the \`step different' setting.
66+
Single step a statement without the \`step force' setting.
6167
62-
Set step different may have been set on. step- ensures we turn that off for
68+
Set step force may have been set on. step- ensures we turn that off for
6369
this command.
6470
65-
See also \"step\" and \"set different\"."
71+
See also:
72+
---------
73+
74+
**step** and **set different**." 0
6675

6776
# Step command
6877
# $1 is command step+, step-, or step

docs/commands/running/step.rst

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,16 @@
44
Step (step into)
55
----------------
66

7-
**step** [ **+** | **-** | **<** | **>** | **!** ] [*event*...] [*count*]
7+
**step** [ **+** | **-** [*count*]
88

99
Execute the current line, stopping at the next event.
1010

1111
With an integer argument, step that many times.
1212

13-
*event* is list of an event name which is one of: `call`,
14-
`return`, `line`, `exception` `c-call`, `c-return` or `c-exception`.
15-
If specified, only those stepping events will be considered. If no
16-
list of event names is given, then any event triggers a stop when the
17-
count is 0.
18-
19-
There is however another way to specify a *single* event, by
20-
suffixing one of the symbols `<`, `>`, or `!` after the command or on
21-
an alias of that. A suffix of `+` on a command or an alias forces a
22-
move to another line, while a suffix of `-` disables this requirement.
23-
A suffix of `>` will continue until the next call. (`finish` will run
24-
run until the return for that call.)
13+
You can Set an event, by suffixing one of the symbols `+`, `-`,
14+
or after the command or on an alias of that. A suffix of `+` on a
15+
command or an alias forces a move to another line, while a suffix of
16+
`-` disables this requirement.
2517

2618
If no suffix is given, the debugger setting `different-line`
2719
determines this behavior.
@@ -34,11 +26,9 @@ Examples:
3426
step # step 1 event, *any* event
3527
step 1 # same as above
3628
step 5/5+0 # same as above
37-
step line # step only line events
38-
step call # step only call events
39-
step> # same as above
40-
step call line # Step line *and* call events
29+
step+
30+
step-
4131

4232
.. seealso::
4333

44-
:ref:`next <next>` command. :ref:`skip <skip>`, :ref:`jump <jump>` (there's no `hop` yet), :ref:`continue <continue>`, and :ref:`finish <finish>` provide other ways to progress execution.
34+
:ref:`next <next>` command. :ref:`skip <skip>`, and :ref:`continue <continue>` provide other ways to progress execution.

lib/hook.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ function _Dbg_trap_handler {
142142
fi
143143

144144
_Dbg_hook_enter_debugger 'after being stepped'
145-
return $?
145+
typeset -i rc=$?
146+
if ((_Dbg_return_from_fn > 0)) ; then
147+
_Dbg_return_from_fn=0
148+
return 255 # 255 indicates return statement.
149+
fi
150+
return $rc
146151

147152
fi
148153
if ((_Dbg_set_linetrace)) ; then
@@ -154,6 +159,10 @@ function _Dbg_trap_handler {
154159
_Dbg_print_location_and_command
155160
fi
156161
_Dbg_set_to_return_from_debugger
162+
if ((_Dbg_return_from_fn > 0)) ; then
163+
_Dbg_return_from_fn=0
164+
return 255 # 255 indicates return statement.
165+
fi
157166
return 0
158167
}
159168

lib/processor.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function _Dbg_process_commands {
113113
_Dbg_onecmd "$_Dbg_cmd" "$args"
114114
rc=$?
115115
# _Dbg_postcmd
116-
(( rc > 0 && rc != 255 )) && return $rc
116+
(( rc > 0 && rc != 254 )) && return $rc
117117
done
118118
unset _Dbg_fd[_Dbg_fd_last]
119119
((_Dbg_fd_last--))
@@ -185,7 +185,9 @@ _Dbg_onecmd() {
185185
${_Dbg_debugger_commands[$_Dbg_cmd]} $_Dbg_args
186186
IFS=$_Dbg_space_IFS;
187187
# eval "_Dbg_prompt=$_Dbg_prompt_str"
188-
((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc
188+
if ((_Dbg_continue_rc >= 0)); then
189+
return $_Dbg_continue_rc
190+
fi
189191
continue
190192
fi
191193
fi
@@ -273,13 +275,13 @@ _Dbg_onecmd() {
273275

274276
* )
275277
if (( _Dbg_set_autoeval )) ; then
276-
! _Dbg_do_eval $_Dbg_cmd $args && return 255
278+
! _Dbg_do_eval $_Dbg_cmd $args && return 254
277279
else
278280
_Dbg_undefined_cmd $_Dbg_cmd
279281
# _Dbg_remove_history_item
280282
# typeset -a last_history=(`history 1`)
281283
# history -d ${last_history[0]}
282-
return 255
284+
return 254
283285
fi
284286
;;
285287
esac

lib/save-restore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function _Dbg_set_to_return_from_debugger {
7474
# _Dbg_last_ksh_command="**unsaved _kshdb command**"
7575
# fi
7676

77-
_Dbg_restore_user_vars
77+
_Dbg_restore_user_vars
7878
}
7979

8080
_Dbg_save_state() {

0 commit comments

Comments
 (0)