From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1910 invoked by alias); 29 Feb 2012 16:53:50 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30303 Received: (qmail 23722 invoked from network); 29 Feb 2012 16:53:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Wed, 29 Feb 2012 15:52:57 +0000 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: emulate & xtrace Message-ID: <20120229155257.204ea6fd@pwslap01u.europe.root.pri> In-Reply-To: <120223084529.ZM11820@torch.brasslantern.com> References: <20120223110123.18448510@pwslap01u.europe.root.pri> <120223084529.ZM11820@torch.brasslantern.com> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.101.10.170] X-Scanned-By: MailControl 7.6.6 (www.mailcontrol.com) on 10.68.0.135 On Thu, 23 Feb 2012 08:45:29 -0800 Bart Schaefer 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 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