ast icon indicating copy to clipboard operation
ast copied to clipboard

.sh.command wonky inside subshell in kshdb

Open rocky opened this issue 4 years ago • 0 comments

Description of problem:

Inside kshdb which uses a trap DEBUG hook. .sh.command is sometimes getting corrupted with prior output

Ksh version:

2020.0.0-beta1-149-g286203fc

Steps to reproduce:

  1. Install kshdb
  2. Put the following program in /tmp/bug.sh
if [ "`id -u`" -eq 0 ]; then
    PS1='# '
fi
  1. Run kshdb stepping past the first line of the program

Actual results (with annotations):

$ kshdb /tmp/bug.sh
ksh debugger, kshdb, release 1.1.0

Copyright 2008-2011, 2018-2019 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

kshdb<1> step
(/tmp/bug.sh:1):
'[' $'(/tmp/bug.sh:1):\nid -u\n1000' -eq 0 ']'
      ^^^^^^^^^^^^^^ this extraneous string is in .sh.command and is coming from the prior prompt
kshdb<1> step
/usr/local/bin/kshdb[130]: /usr/local/bin/kshdb[1]: /usr/local/bin/kshdb[1]: [: (/tmp/bug.sh:1):
id -u
1000: arithmetic syntax error
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I'm guessing this is because .sh.command somehow got corrupted
(/usr/local/bin/kshdb:131):
trap '' DEBUG
kshdb<1> quit
kshdb: That's all, folks...
$

Expected results:

$ kshdb /tmp/bug.sh
ksh debugger, kshdb, release 1.1.0

Copyright 2008-2011, 2018-2019 Rocky Bernstein
This is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.

kshdb<1> step
(/tmp/bug.sh:1):
'[' `id -u` -eq 0 ']'
kshdb<1> step
(/usr/local/bin/kshdb:131):
trap '' DEBUG
kshdb<1> quit
kshdb: That's all, folks...
$

Additional info:

To show that .sh.command is corruped, you can put

typeset -p .sh.command

inside function _Dbg_print_command of kshdb/lib/gdb.sh

rocky avatar Nov 06 '19 23:11 rocky