zsh-workers
 help / color / mirror / code / Atom feed
* emulate & xtrace
@ 2012-02-23 11:01 Peter Stephenson
  2012-02-23 16:45 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2012-02-23 11:01 UTC (permalink / raw)
  To: Zsh Hackers' List

I'm thinking (post 4.3.17) of trying to make the "emulate" command leave
on the "xtrace" option if running inside a function and the nearest
enclosing function has "functions -t" set.  Before I look at this, can
anybody see if this is a bad idea?  (Obviously "unsetopt xtrace" still
does what you expect).

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: emulate & xtrace
  2012-02-23 11:01 emulate & xtrace Peter Stephenson
@ 2012-02-23 16:45 ` Bart Schaefer
  2012-02-29 15:52   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2012-02-23 16:45 UTC (permalink / raw)
  To: Zsh Hackers' List

On Feb 23, 11:01am, Peter Stephenson wrote:
}
} I'm thinking (post 4.3.17) of trying to make the "emulate" command leave
} on the "xtrace" option if running inside a function and the nearest
} enclosing function has "functions -t" set.  Before I look at this, can
} anybody see if this is a bad idea?  (Obviously "unsetopt xtrace" still
} does what you expect).

I'd almost be inclined to leave xtrace alone regardess of functions -t
but I don't see any harm in doing it the way you've described.  Note
that emulate already leaves xtrace unchanged without the -R option:

torch% setopt xtrace; emulate zsh -c 'print $options[xtrace]' 
+Src/zsh:9> emulate zsh -c 'print $options[xtrace]'
+(eval):1> print on
on

torch% setopt xtrace; emulate -R zsh -c 'print $options[xtrace]'              
+Src/zsh:8> emulate -R zsh -c 'print $options[xtrace]'
off

There may be a few of other options that might get similar treatment,
e.g., DEBUG_BEFORE_CMD and EVAL_LINENO (which is out of alpha order in
zsh.h, by the way), HUP and RCS, possibly ERR_EXIT and ERR_RETURN.
Are there good reasons to reset those even with "emulate -R"?  (It's
a bit tougher with those last two.)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: emulate & xtrace
  2012-02-23 16:45 ` Bart Schaefer
@ 2012-02-29 15:52   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2012-02-29 15:52 UTC (permalink / raw)
  To: Zsh Hackers' List

On Thu, 23 Feb 2012 08:45:29 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Feb 23, 11:01am, Peter Stephenson wrote:
> } I'm thinking (post 4.3.17) of trying to make the "emulate" command leave
> } on the "xtrace" option if running inside a function and the nearest
> } enclosing function has "functions -t" set.  Before I look at this, can
> } anybody see if this is a bad idea?  (Obviously "unsetopt xtrace" still
> } does what you expect).
> 
> I'd almost be inclined to leave xtrace alone regardess of functions -t
> but I don't see any harm in doing it the way you've described.

This is easy, but I'm in two minds about whether to trace back through
the shell's execution stack to find the nearest enclosing function, or
to decree that if you have "source", ".", or "eval" inside the function
then an "emulate" in those won't have this behaviour.  I've done the
latter because it was slightly simpler to implement, but I could be
convinced otherwise: after all, the emulate is not local to those other
commands so it's other effects propagate back.

Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.136
diff -p -u -r1.136 builtins.yo
--- Doc/Zsh/builtins.yo	3 Jun 2011 19:54:44 -0000	1.136
+++ Doc/Zsh/builtins.yo	29 Feb 2012 15:47:14 -0000
@@ -366,6 +366,13 @@ noderef(Compatibility)
 )\
 .
 
+If the tt(emulate) command occurs inside a function that has been
+marked for execution tracing with tt(functions -t) then the tt(xtrace)
+option will be turned on regardless of emulation mode or other options.
+Note that code executed inside the function by the tt(.), tt(source), or
+tt(eval) commands is not considered to be running directly from the
+function, hence does not provoke this behaviour.
+
 If the tt(-R) option is given, all options
 are reset to their default value corresponding to the specified emulation
 mode, except for certain options describing the interactive
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.59
diff -p -u -r1.59 options.c
--- Src/options.c	8 Jan 2012 16:02:55 -0000	1.59
+++ Src/options.c	29 Feb 2012 15:47:14 -0000
@@ -523,6 +523,20 @@ emulate(const char *zsh_name, int fully)
     if (fully)
 	emulation |= EMULATE_FULLY;
     installemulation();
+
+    if (funcstack && funcstack->tp == FS_FUNC) {
+	/*
+	 * We are inside a function.  Decide if it's traced.
+	 * Pedantic note: the function in the function table isn't
+	 * guaranteed to be what we're executing, but it's
+	 * close enough.
+	 */
+	Shfunc shf = (Shfunc)shfunctab->getnode(shfunctab, funcstack->name);
+	if (shf && (shf->node.flags & PM_TAGGED)) {
+	    /* Tracing is on, so set xtrace */
+	    opts[XTRACE] = 1;
+	}
+    }
 }
 
 /* setopt, unsetopt */

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-29 16:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-23 11:01 emulate & xtrace Peter Stephenson
2012-02-23 16:45 ` Bart Schaefer
2012-02-29 15:52   ` Peter Stephenson

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).