Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Help me track down a tough bug? (probably funcfiletrace, subshells and possibly I/O redirection)



On Tue, 30 Sep 2008 13:59:43 -0400
"Rocky Bernstein" <rocky.bernstein@xxxxxxxxx> wrote:
> My mistake. You are correct. This bug was introduced in paring down
> the program and removing an initial truncate output (leaving the
> subsequent append outputs). And I now see the answer to why output was
> disappearing in the subshell which was my initial concern.

OK, so it seems there's currently nothing for me to look at here.

> Any thoughts on marking subshell level inside one of the stack traces
> or having return inside trap DEBUG with a negative number cause an
> immediate return?

You can already force a return from the enclosing function from trap '...'
DEBUG just by executing "return".  You can use return from within enclosing
functions to trigger this, e.g.

  fn() {
    return 3
  }
  trap 'fn || return $?' DEBUG

(if you need to return status 0, offset the status return value from fn by
1 and use 'fn || return $(( $? - 1 ))').  For example

  foo() {
    emulate -L zsh
    trap '[[ $ZSH_DEBUG_CMD == *bar* ]] && return 1' DEBUG
    echo foo
    echo bar
  }

when executed (with DEBUG_BEFORE_CMD assumed set by default) prints "foo"
but not "bar" and should return status 1 from foo.  However --- Surprise!
--- there's a bug and although it does return from foo the status gets
lost.  The fix is below.

Let us know either if this isn't working properly or you need something
more specific.

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.158
diff -u -r1.158 exec.c
--- Src/exec.c	29 Sep 2008 21:46:58 -0000	1.158
+++ Src/exec.c	1 Oct 2008 11:24:43 -0000
@@ -1091,7 +1091,8 @@
 	    exiting = donetrap;
 	    ret = lastval;
 	    dotrap(SIGDEBUG);
-	    lastval = ret;
+	    if (!retflag)
+		lastval = ret;
 	    donetrap = exiting;
 	    noerrexit = oldnoerrexit;
 	    /*
@@ -1230,7 +1231,8 @@
 	    exiting = donetrap;
 	    ret = lastval;
 	    dotrap(SIGDEBUG);
-	    lastval = ret;
+	    if (!retflag)
+		lastval = ret;
 	    donetrap = exiting;
 	    noerrexit = oldnoerrexit;
 	    opts[ERREXIT] = oerrexit_opt;
Index: Test/C05debug.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C05debug.ztst,v
retrieving revision 1.2
diff -u -r1.2 C05debug.ztst
--- Test/C05debug.ztst	5 Sep 2008 09:05:23 -0000	1.2
+++ Test/C05debug.ztst	1 Oct 2008 11:24:43 -0000
@@ -137,3 +137,13 @@
 >9: 'fn2'
 >0: 'echo wow'
 >wow
+
+  foo() {
+    emulate -L zsh; setopt debugbeforecmd
+    trap '[[ $ZSH_DEBUG_CMD == *bar* ]] && return 2' DEBUG
+    echo foo
+    echo bar
+  }
+  foo
+2:Status of forced return from eval-style DEBUG trap
+>foo


-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author