From: "Rocky Bernstein" <rocky.bernstein@gmail.com>
To: zsh-workers@sunsite.dk
Subject: Re: Weird exit caused in a trap DEBUG which sources a file.
Date: Fri, 1 Aug 2008 11:21:50 -0400 [thread overview]
Message-ID: <6cd6de210808010821g3117fe62y82bd580811dbba8a@mail.gmail.com> (raw)
In-Reply-To: <20080801143747.19b65086@news01>
Comments in line.
On Fri, Aug 1, 2008 at 9:37 AM, Peter Stephenson <pws@csr.com> wrote:
> On Fri, 1 Aug 2008 08:29:29 -0400
> "Rocky Bernstein" <rocky.bernstein@gmail.com> wrote:
>> Looks like the crucial change that makes zsh 4.3.5-dev and current SVN
>> sources fail is an extra source after the trap DEBUG:
>
> Thanks, this is what I needed.
No, thank you! I just tried the patch and it works fine.
So there's no mystery. I've been porting the bash debugger code to
zsh. So far, print/eval, stepping and some stack frame commands work.
But this is far from ready for general consumption.
Part of this is a more general effort at writing about POSIX shells
which I give maybe a 50% chance of happening.
>
> The source code wasn't handling the variable that indicates a trap has told
> us to return from a function properly. The variable is only primed for
> action if negative. That's the init.c hunk.
>
> The signals.c hunk is to save and restore trapreturn for nested trap
> handlers. I'm not sure it's necessary; I am sure it's not wrong and
> prevents hostages to fortune.
Not sure the additional code is necessary or that nested trap handlers
are necessary? I'm pretty sure you mean the former. Nested trap
handlers are useful.
>
> The hairy trap tests still pass, which is good; it would be better to add
> this as a test, too, which shouldn't be too hard as there's nothing here
> that depends on external behaviour.
>
> I've documented the variable trapreturn better.
Thanks. It seems weird that trapreturn is is initialised to -1 for a
function trap and
-2 for a non-function trap and decremented for subsequent function
calls. Because this means that trapreturn for a for a function trap
that calls a function would have the same value as for a non-function
trap.
>
> Index: Src/exec.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
> retrieving revision 1.135
> diff -u -r1.135 exec.c
> --- Src/exec.c 31 Jul 2008 08:44:21 -0000 1.135
> +++ Src/exec.c 1 Aug 2008 13:29:06 -0000
> @@ -64,7 +64,23 @@
> /**/
> mod_export int errflag;
>
> -/* Status of return from a trap */
> +/*
> + * Status of return from a trap.
> + * This is only active if we are inside a trap, else its value
> + * is irrelevant. It is initialised to -1 for a function trap and
> + * -2 for a non-function trap and if negative is decremented as
> + * we go deeper into functions and incremented as we come back up.
> + * The value is used to decide if an explicit "return" should cause
> + * a return from the caller of the trap; it does this by setting
> + * trapreturn to a status (i.e. a non-negative value).
> + *
> + * In summary, trapreturn is
> + * - zero unless we are in a trap
> + * - negative in a trap unless it has triggered. Code uses this
> + * to detect an active trap.
> + * - non-negative in a trap once it was triggered. It should remain
> + * non-negative until restored after execution of the trap.
> + */
>
> /**/
> int trapreturn;
> Index: Src/init.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/init.c,v
> retrieving revision 1.87
> diff -u -r1.87 init.c
> --- Src/init.c 31 Jul 2008 08:44:21 -0000 1.87
> +++ Src/init.c 1 Aug 2008 13:29:06 -0000
> @@ -191,7 +191,7 @@
> exit(lastval);
> if (((!interact || sourcelevel) && errflag) || retflag)
> break;
> - if (trapreturn) {
> + if (trapreturn >= 0) {
> lastval = trapreturn;
> trapreturn = 0;
> }
> Index: Src/signals.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/signals.c,v
> retrieving revision 1.47
> diff -u -r1.47 signals.c
> --- Src/signals.c 31 Jul 2008 08:44:21 -0000 1.47
> +++ Src/signals.c 1 Aug 2008 13:29:06 -0000
> @@ -1085,6 +1085,7 @@
> int trapret = 0;
> int obreaks = breaks;
> int oretflag = retflag;
> + int otrapreturn = trapreturn;
> int isfunc;
> int traperr;
>
> @@ -1183,6 +1184,7 @@
> trapret = trapreturn + 1;
> }
> traperr = errflag;
> + trapreturn = otrapreturn;
> execrestore();
> lexrestore();
>
>
> --
> Peter Stephenson <pws@csr.com> Software Engineer
> CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
> Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
>
next prev parent reply other threads:[~2008-08-01 15:22 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-31 2:38 Rocky Bernstein
2008-07-31 9:01 ` Peter Stephenson
2008-07-31 10:05 ` Rocky Bernstein
2008-08-01 12:29 ` Rocky Bernstein
2008-08-01 13:37 ` Peter Stephenson
2008-08-01 15:21 ` Rocky Bernstein [this message]
2008-08-01 15:31 ` Peter Stephenson
2008-08-02 11:21 ` Rocky Bernstein
2008-08-03 10:42 ` Peter Stephenson
2008-08-03 11:28 ` Rocky Bernstein
2008-08-03 11:50 ` Peter Stephenson
2008-08-05 11:18 ` Rocky Bernstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6cd6de210808010821g3117fe62y82bd580811dbba8a@mail.gmail.com \
--to=rocky.bernstein@gmail.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).