Skip to content

Commit

Permalink
Changes for debug input/output (hacked)
Browse files Browse the repository at this point in the history
  • Loading branch information
ext-michal.rogalinski committed Oct 10, 2018
1 parent c34dd7a commit 3400eae
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion command/eval.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ _Dbg_do_eval() {
typeset -i _Dbg_rc
if [[ -t $_Dbg_fdi ]] ; then
_Dbg_set_dol_q $_Dbg_debugged_exit_code
. $_Dbg_evalfile >&${_Dbg_fdi}
. $_Dbg_evalfile >>"$_Dbg_tty"
else
_Dbg_set_dol_q $_Dbg_debugged_exit_code
. $_Dbg_evalfile
Expand Down
17 changes: 10 additions & 7 deletions lib/msg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ _Dbg_confirm() {
if [[ -t $_Dbg_fdi ]]; then
vared -e -h -p "$_Dbg_confirm_prompt" _Dbg_response <&${_Dbg_fdi} || break
else
read "?$_Dbg_confirm_prompt" _Dbg_response <&${_Dbg_fdi} || break
read "?$_Dbg_confirm_prompt" _Dbg_response <&${_Dbg_fdi} >>$_Dbg_prompt_output || break
fi

case "$_Dbg_response" in
Expand Down Expand Up @@ -86,17 +86,19 @@ function _Dbg_errmsg_no_cr {
}

function _Dbg_msg {
if [[ -n $_Dbg_fdi ]] && [[ -t $_Dbg_fdi ]] ; then
builtin print -- "$@" >&${_Dbg_fdi}
#if [[ -n "$_Dbg_tty" ]] && [[ -t "$_Dbg_tty" ]] ; then
if [[ -n "$_Dbg_tty" ]] ; then
builtin print -- "$@" >> "$_Dbg_tty"
else
builtin print -- "$@"
fi

}

function _Dbg_msg_nocr {
if [[ -n $_Dbg_fdi ]] && [[ -t $_Dbg_fdi ]] ; then
builtin echo -n "$@" >&${_Dbg_fdi}
#if [[ -n "$_Dbg_tty" ]] && [[ -t "$_Dbg_tty" ]] ; then
if [[ -n "$_Dbg_tty" ]] ; then
builtin echo -n "$@" >>"$_Dbg_tty"
else
builtin echo -n "$@"
fi
Expand All @@ -117,8 +119,9 @@ function _Dbg_printf_nocr {
builtin printf "$format" "$@" >>$_Dbg_logfid
fi
if (( ! _Dbg_logging_redirect )) ; then
if [[ -n $_Dbg_fdi ]] && [[ -t $_Dbg_fdi ]] ; then
builtin printf "$format" "$@" >&${_Dbg_fdi}
#if [[ -n $_Dbg_fdi ]] && [[ -t $_Dbg_fdi ]] ; then
if [[ -n "$_Dbg_tty" ]] ; then
builtin printf "$format" "$@" >>"$_Dbg_tty"
else
builtin printf "$format" "$@"
fi
Expand Down
23 changes: 12 additions & 11 deletions lib/processor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function _Dbg_process_commands {
${hook}
done

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

# Loop over all pending open input file descriptors
while (( ${#_Dbg_fd[@]} > 0 )) ; do
Expand Down Expand Up @@ -124,21 +125,21 @@ function _Dbg_process_commands {
((_Dbg_cmd_num++))
if ((0 == _Dbg_in_vared)) && [[ -t $_Dbg_fdi ]]; then
_Dbg_in_vared=1
vared -e -h -p "$_Dbg_prompt" line <&${_Dbg_fdi} || break
vared -e -h -p "$_Dbg_prompt" line 2>>$_Dbg_prompt_output <&${_Dbg_fdi} || break
_Dbg_in_vared=0
else
if ((1 == _Dbg_in_vared)) ; then
_Dbg_msg "Unable to echo characters in input below"
_Dbg_msg "Unable to echo characters in input below"
fi
if [[ -z ${_Dbg_cmdfile[-1]} ]] ; then
read -u ${_Dbg_fdi} "?$_Dbg_prompt" line || break
read -u ${_Dbg_fdi} "?$_Dbg_prompt" line 2>>$_Dbg_prompt_output || break
else
read -u ${_Dbg_fdi} line || break
read -u ${_Dbg_fdi} line || break
fi
fi
_Dbg_onecmd "$line"
rc=$?
_Dbg_postcmd
_Dbg_onecmd "$line"
rc=$?
_Dbg_postcmd
((_Dbg_continue_rc >= 0)) && return $_Dbg_continue_rc

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

(( rc > 0 )) && return $rc
(( rc > 0 )) && return $rc

line=''
done # read "?$_Dbg_prompt" ...
Expand Down Expand Up @@ -207,8 +208,8 @@ _Dbg_onecmd() {
fi

if [[ -n ${_Dbg_debugger_commands[$expanded_alias]} ]] ; then
${_Dbg_debugger_commands[$expanded_alias]} $args
return $?
${_Dbg_debugger_commands[$expanded_alias]} $args
return $?
fi

# The below are command names that are just a little irregular
Expand Down Expand Up @@ -254,7 +255,7 @@ _Dbg_onecmd() {
* )
if (( _Dbg_set_autoeval )) ; then
if [[ -t $_Dbg_fdi ]] ; then
if ! _Dbg_do_eval $_Dbg_cmd $args >&${_Dbg_fdi} 2>&1 ; then
if ! _Dbg_do_eval $_Dbg_cmd $args >>"$_Dbg_tty" 2>&1 ; then
return -1
fi
else
Expand Down
4 changes: 2 additions & 2 deletions lib/tty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
function _Dbg_open_if_tty {
_Dbg_new_fd=-1
(( $# != 1 )) && return 1
[[ ! -r $1 ]] || [[ ! -w $1 ]] && return 1
[[ ! -w $1 ]] && return 1
typeset -i r=1
# Code modelled off of code from David Korn:
{
if exec {_Dbg_new_fd} <> $1 ; then
if exec ${_Dbg_new_fd} > $1 ; then
if [[ -t $_Dbg_new_fd ]] ; then
r=0
else
Expand Down

0 comments on commit 3400eae

Please sign in to comment.