From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1069 invoked from network); 14 Jan 2007 19:14:48 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 14 Jan 2007 19:14:48 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 35494 invoked from network); 14 Jan 2007 19:14:41 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 14 Jan 2007 19:14:41 -0000 Received: (qmail 24050 invoked by alias); 14 Jan 2007 19:14:38 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23104 Received: (qmail 24040 invoked from network); 14 Jan 2007 19:14:37 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 14 Jan 2007 19:14:37 -0000 Received: (qmail 35179 invoked from network); 14 Jan 2007 19:14:37 -0000 Received: from mtaout01-winn.ispmail.ntl.com (81.103.221.47) by a.mx.sunsite.dk with SMTP; 14 Jan 2007 19:14:28 -0000 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com with ESMTP id <20070114191423.RAXH9447.mtaout01-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com>; Sun, 14 Jan 2007 19:14:23 +0000 Received: from pwslaptop.csr.com ([81.107.41.185]) by aamtaout01-winn.ispmail.ntl.com with SMTP id <20070114191423.HSV219.aamtaout01-winn.ispmail.ntl.com@pwslaptop.csr.com>; Sun, 14 Jan 2007 19:14:23 +0000 Date: Sun, 14 Jan 2007 19:14:18 +0000 From: Peter Stephenson To: nwsgpamachine@alcatel-lucent.com, zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: "trap ... DEBUG" to execute before (instead of after) each Message-Id: <20070114191418.6974b2d1.p.w.stephenson@ntlworld.com> In-Reply-To: <200701112232.l0BMWX4G003770@pwslaptop.csr.com> References: <200701100744.l0A7il227749@nwsgpa.ih.lucent.com> <200701112232.l0BMWX4G003770@pwslaptop.csr.com> X-Mailer: Sylpheed version 2.2.10 (GTK+ 2.10.4; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 11 Jan 2007 22:32:33 +0000 Peter Stephenson wrote: > nwsgpamachine@alcatel-lucent.com wrote: > > Dear Peter, > > !! The BIG problem is that the patched version does not report > > !! LINENO values correctly. > > Yes, I forgot about the line number stuff which isn't particularly well > implemented at the moment. I think the following (relatively straightforward) change should do the trick. The reason I think it's OK is that it sets up the line number right at the start of each top-level chunk of code, so it should cover all possible cases. The line number is still updated for each pipeline, which is what you'd see if you were doing debugging at a lower level (or printing the line number). The difference is that code like "foo && bar" only invokes the DEBUG trap once, but updates the line number for both "foo" and "bar". There may be other simplifications or rearrangements but I couldn't see anything crying out to be changed. The zsh.h changes are simply making definitions clearer; there's no functional change, and hence no incompatibility in compiled wordcode. Please let me know if you notice any more line numbering oddities... there have been a number over the years and it looks like you're in a good position to notice them. Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.108 diff -u -r1.108 exec.c --- Src/exec.c 9 Jan 2007 21:59:31 -0000 1.108 +++ Src/exec.c 14 Jan 2007 19:01:12 -0000 @@ -866,6 +866,35 @@ code = *state->pc++; while (wc_code(code) == WC_LIST && !breaks && !retflag) { int donedebug; + + ltype = WC_LIST_TYPE(code); + csp = cmdsp; + + if ((!intrap || trapisfunc) && !ineval) { + /* + * Ensure we have a valid line number for debugging, + * unless we are in an evaluated trap in which case + * we retain the line number from the context. + * This was added for DEBUGBEFORECMD but I've made + * it unconditional to keep dependencies to a minimum. + * + * The line number is updated for individual pipelines. + * This isn't necessary for debug traps since they only + * run once per sublist. + */ + wordcode code2 = *state->pc, lnp1 = 0; + if (ltype & Z_SIMPLE) { + lnp1 = code2; + } else if (wc_code(code2) == WC_SUBLIST) { + if (WC_SUBLIST_FLAGS(code2) == WC_SUBLIST_SIMPLE) + lnp1 = state->pc[2]; + else + lnp1 = WC_PIPE_LINENO(state->pc[1]); + } + if (lnp1) + lineno = lnp1 - 1; + } + if (sigtrapped[SIGDEBUG] && isset(DEBUGBEFORECMD)) { exiting = donetrap; ret = lastval; @@ -881,9 +910,6 @@ } else donedebug = 0; - ltype = WC_LIST_TYPE(code); - csp = cmdsp; - if (ltype & Z_SIMPLE) { next = state->pc + WC_LIST_SKIP(code); execsimple(state); Index: Src/zsh.h =================================================================== RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v retrieving revision 1.107 diff -u -r1.107 zsh.h --- Src/zsh.h 9 Jan 2007 21:59:31 -0000 1.107 +++ Src/zsh.h 14 Jan 2007 19:01:14 -0000 @@ -703,8 +703,9 @@ #define WC_LIST_TYPE(C) wc_data(C) #define Z_END (1<<4) #define Z_SIMPLE (1<<5) -#define WC_LIST_SKIP(C) (wc_data(C) >> 6) -#define WCB_LIST(T,O) wc_bld(WC_LIST, ((T) | ((O) << 6))) +#define WC_LIST_FREE (6) /* Next bit available in integer */ +#define WC_LIST_SKIP(C) (wc_data(C) >> WC_LIST_FREE) +#define WCB_LIST(T,O) wc_bld(WC_LIST, ((T) | ((O) << WC_LIST_FREE))) #define WC_SUBLIST_TYPE(C) (wc_data(C) & ((wordcode) 3)) #define WC_SUBLIST_END 0 @@ -714,8 +715,10 @@ #define WC_SUBLIST_COPROC 4 #define WC_SUBLIST_NOT 8 #define WC_SUBLIST_SIMPLE 16 -#define WC_SUBLIST_SKIP(C) (wc_data(C) >> 5) -#define WCB_SUBLIST(T,F,O) wc_bld(WC_SUBLIST, ((T) | (F) | ((O) << 5))) +#define WC_SUBLIST_FREE (5) /* Next bit available in integer */ +#define WC_SUBLIST_SKIP(C) (wc_data(C) >> WC_SUBLIST_FREE) +#define WCB_SUBLIST(T,F,O) wc_bld(WC_SUBLIST, \ + ((T) | (F) | ((O) << WC_SUBLIST_FREE))) #define WC_PIPE_TYPE(C) (wc_data(C) & ((wordcode) 1)) #define WC_PIPE_END 0 -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/