Skip to content

Commit 94434f5

Browse files
author
ext-michal.rogalinski
committed
Changes for debug input/output (hacked)
1 parent 9d27195 commit 94434f5

File tree

6 files changed

+47
-29
lines changed

6 files changed

+47
-29
lines changed

command/eval.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ _Dbg_do_eval() {
110110
typeset -i _Dbg_rc
111111
if [[ -t $_Dbg_fdi ]] ; then
112112
_Dbg_set_dol_q $_Dbg_debugged_exit_code
113-
. $_Dbg_evalfile >&${_Dbg_fdi}
113+
. $_Dbg_evalfile >>"$_Dbg_tty"
114114
else
115115
_Dbg_set_dol_q $_Dbg_debugged_exit_code
116116
. $_Dbg_evalfile

command/handle.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@
3636
# stack is printed. Prefacing these actions with \"no\" indicates not to
3737
# do the indicated action."
3838

39+
_Dbg_help_add handle \
40+
"**handle** *signal* *action*
41+
42+
Specify how to handle *signal*.
43+
44+
*signal* is a signal name like SIGSEGV, but numeric signals like 11
45+
(which is usually equivalent on \*nix systems) is okay too.
46+
47+
*action* is one of \"stop\", \"nostop\", \"print\", and
48+
\"noprint\". \"Stop\" indicates entering debugger if this signal
49+
happens. \"Print\" indicates printing a message if this signal is
50+
encountered. \"Stack\" is like \"print\" but except the entire call
51+
stack is printed. Prefacing these actions with \"no\" indicates not to
52+
do the indicated action."
53+
3954
_Dbg_do_handle() {
4055
typeset sig=$1
4156
typeset cmd=$2

dbg-pre.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
1313
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1414
# for more details.
15-
#
15+
#
1616
# You should have received a copy of the GNU General Public License along
1717
# with zshdb; see the file COPYING. If not, write to the Free Software
1818
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
@@ -44,7 +44,7 @@ typeset -i _Dbg_script=0
4444
# This function is overwritten by when lib/fns.sh gets loaded
4545
_Dbg_msg()
4646
{
47-
echo $*
47+
echo "$*"
4848
}
4949

5050
# Used by "show version" as well as --version
@@ -56,9 +56,9 @@ _Dbg_do_show_version()
5656
# Expand filename given as $1.
5757
# we echo the expanded name or return $1 unchanged if a bad filename.
5858
# Return is 0 if good or 1 if bad.
59-
# File globbing is handled.
60-
# Note we don't check that the file exists, just that the format is
61-
# valid; we do check that we can "search" the directory implied in the
59+
# File globbing is handled.
60+
# Note we don't check that the file exists, just that the format is
61+
# valid; we do check that we can "search" the directory implied in the
6262
# filename.
6363

6464
function _Dbg_expand_filename {
@@ -115,15 +115,14 @@ typeset -x _Dbg_init_cwd=$PWD
115115

116116
typeset -i _Dbg_running=1 # True we are not finished running the program
117117

118-
typeset -i _Dbg_brkpt_num=0 # If nonzero, the breakpoint number that we
118+
typeset -i _Dbg_brkpt_num=0 # If nonzero, the breakpoint number that we
119119
# are currently stopped at.
120120

121121
# Sets whether or not to display command before executing it.
122122
typeset _Dbg_set_trace_commands='off'
123123

124124
# Known normal IFS consisting of a space, tab and newline
125-
typeset -x _Dbg_space_IFS='
126-
'
125+
typeset -x _Dbg_space_IFS=$' \t\r\n'
127126

128127
# Number of statements to run before entering the debugger. Is used
129128
# intially to get out of sourced dbg-main.inc script and in top-level

lib/msg.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ _Dbg_confirm() {
4141
if [[ -t $_Dbg_fdi ]]; then
4242
vared -e -h -p "$_Dbg_confirm_prompt" _Dbg_response <&${_Dbg_fdi} || break
4343
else
44-
read "?$_Dbg_confirm_prompt" _Dbg_response <&${_Dbg_fdi} || break
44+
read "?$_Dbg_confirm_prompt" _Dbg_response <&${_Dbg_fdi} >>$_Dbg_prompt_output || break
4545
fi
4646

4747
case "$_Dbg_response" in
@@ -86,17 +86,19 @@ function _Dbg_errmsg_no_cr {
8686
}
8787

8888
function _Dbg_msg {
89-
if [[ -n $_Dbg_fdi ]] && [[ -t $_Dbg_fdi ]] ; then
90-
builtin print -- "$@" >&${_Dbg_fdi}
89+
#if [[ -n "$_Dbg_tty" ]] && [[ -t "$_Dbg_tty" ]] ; then
90+
if [[ -n "$_Dbg_tty" ]] ; then
91+
builtin print -- "$@" >> "$_Dbg_tty"
9192
else
9293
builtin print -- "$@"
9394
fi
9495

9596
}
9697

9798
function _Dbg_msg_nocr {
98-
if [[ -n $_Dbg_fdi ]] && [[ -t $_Dbg_fdi ]] ; then
99-
builtin echo -n "$@" >&${_Dbg_fdi}
99+
#if [[ -n "$_Dbg_tty" ]] && [[ -t "$_Dbg_tty" ]] ; then
100+
if [[ -n "$_Dbg_tty" ]] ; then
101+
builtin echo -n "$@" >>"$_Dbg_tty"
100102
else
101103
builtin echo -n "$@"
102104
fi
@@ -117,8 +119,9 @@ function _Dbg_printf_nocr {
117119
builtin printf "$format" "$@" >>$_Dbg_logfid
118120
fi
119121
if (( ! _Dbg_logging_redirect )) ; then
120-
if [[ -n $_Dbg_fdi ]] && [[ -t $_Dbg_fdi ]] ; then
121-
builtin printf "$format" "$@" >&${_Dbg_fdi}
122+
#if [[ -n $_Dbg_fdi ]] && [[ -t $_Dbg_fdi ]] ; then
123+
if [[ -n "$_Dbg_tty" ]] ; then
124+
builtin printf "$format" "$@" >>"$_Dbg_tty"
122125
else
123126
builtin printf "$format" "$@"
124127
fi

lib/processor.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function _Dbg_process_commands {
8484
${hook}
8585
done
8686

87+
_Dbg_prompt_output="${_Dbg_tty:-/dev/null}"
8788

8889
# Loop over all pending open input file descriptors
8990
while (( ${#_Dbg_fd[@]} > 0 )) ; do
@@ -124,21 +125,21 @@ function _Dbg_process_commands {
124125
((_Dbg_cmd_num++))
125126
if ((0 == _Dbg_in_vared)) && [[ -t $_Dbg_fdi ]]; then
126127
_Dbg_in_vared=1
127-
vared -e -h -p "$_Dbg_prompt" line <&${_Dbg_fdi} || break
128+
vared -e -h -p "$_Dbg_prompt" line 2>>$_Dbg_prompt_output <&${_Dbg_fdi} || break
128129
_Dbg_in_vared=0
129130
else
130131
if ((1 == _Dbg_in_vared)) ; then
131-
_Dbg_msg "Unable to echo characters in input below"
132+
_Dbg_msg "Unable to echo characters in input below"
132133
fi
133134
if [[ -z ${_Dbg_cmdfile[-1]} ]] ; then
134-
read -u ${_Dbg_fdi} "?$_Dbg_prompt" line || break
135+
read -u ${_Dbg_fdi} "?$_Dbg_prompt" line 2>>$_Dbg_prompt_output || break
135136
else
136-
read -u ${_Dbg_fdi} line || break
137+
read -u ${_Dbg_fdi} line || break
137138
fi
138139
fi
139-
_Dbg_onecmd "$line"
140-
rc=$?
141-
_Dbg_postcmd
140+
_Dbg_onecmd "$line"
141+
rc=$?
142+
_Dbg_postcmd
142143
((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc
143144

144145
# Add $line to the debugger history file unless there was an
@@ -156,7 +157,7 @@ function _Dbg_process_commands {
156157
fi
157158
fi
158159

159-
(( rc > 0 )) && return $rc
160+
(( rc > 0 )) && return $rc
160161

161162
line=''
162163
done # read "?$_Dbg_prompt" ...
@@ -207,8 +208,8 @@ _Dbg_onecmd() {
207208
fi
208209

209210
if [[ -n ${_Dbg_debugger_commands[$expanded_alias]} ]] ; then
210-
${_Dbg_debugger_commands[$expanded_alias]} $args
211-
return $?
211+
${_Dbg_debugger_commands[$expanded_alias]} $args
212+
return $?
212213
fi
213214

214215
# The below are command names that are just a little irregular
@@ -254,7 +255,7 @@ _Dbg_onecmd() {
254255
* )
255256
if (( _Dbg_set_autoeval )) ; then
256257
if [[ -t $_Dbg_fdi ]] ; then
257-
if ! _Dbg_do_eval $_Dbg_cmd $args >&${_Dbg_fdi} 2>&1 ; then
258+
if ! _Dbg_do_eval $_Dbg_cmd $args >>"$_Dbg_tty" 2>&1 ; then
258259
return -1
259260
fi
260261
else

lib/tty.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
function _Dbg_open_if_tty {
3131
_Dbg_new_fd=-1
3232
(( $# != 1 )) && return 1
33-
[[ ! -r $1 ]] || [[ ! -w $1 ]] && return 1
33+
[[ ! -w $1 ]] && return 1
3434
typeset -i r=1
3535
# Code modelled off of code from David Korn:
3636
{
37-
if exec {_Dbg_new_fd} <> $1 ; then
37+
if exec ${_Dbg_new_fd} > $1 ; then
3838
if [[ -t $_Dbg_new_fd ]] ; then
3939
r=0
4040
else

0 commit comments

Comments
 (0)