From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11881 invoked from network); 31 Aug 2008 19:46:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 31 Aug 2008 19:46:52 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 69646 invoked from network); 31 Aug 2008 19:46:38 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 31 Aug 2008 19:46:38 -0000 Received: (qmail 28378 invoked by alias); 31 Aug 2008 19:46:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25571 Received: (qmail 28359 invoked from network); 31 Aug 2008 19:46:29 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 31 Aug 2008 19:46:29 -0000 Received: from mtaout02-winn.ispmail.ntl.com (mtaout02-winn.ispmail.ntl.com [81.103.221.48]) by bifrost.dotsrc.org (Postfix) with ESMTP id 4C94D801E2B4 for ; Sun, 31 Aug 2008 21:46:25 +0200 (CEST) Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20080831194625.RIYD21103.mtaout02-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Sun, 31 Aug 2008 20:46:25 +0100 Received: from pws-pc ([81.107.43.40]) by aamtaout03-winn.ispmail.ntl.com with ESMTP id <20080831194624.QCDH29597.aamtaout03-winn.ispmail.ntl.com@pws-pc> for ; Sun, 31 Aug 2008 20:46:24 +0100 Date: Sun, 31 Aug 2008 20:46:16 +0100 From: Peter Stephenson To: "Zsh hackers list" Subject: Re: line number reporting weirdnesses Message-ID: <20080831204616.17363a96@pws-pc> In-Reply-To: <20080831165518.5714d07a@pws-pc> References: <6cd6de210808300749yf3cc8d4gadc62d8f7f96ec15@mail.gmail.com> <20080831165518.5714d07a@pws-pc> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.11; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV 0.92.1/8122/Sun Aug 31 03:04:56 2008 on bifrost X-Virus-Status: Clean On Sun, 31 Aug 2008 16:55:18 +0100 Peter Stephenson wrote: > On Sat, 30 Aug 2008 10:49:03 -0400 > "Rocky Bernstein" wrote: > > Second the line number in an assignment statement is basically the > > line of the string token which spans several lines. Possibly it might > > be more helpful to give the line number of the LHS token. > > I agree, but that means we need to remember the line number at the start > of the last parsed token instead of after. Circumstantial evidence suggests this can be done in pretty much the obvious way. I've more or less convinced myself that the new variable should be valid every time we grab a token and that we can't build up a parse tree without doing that, in which case this does the trick. I confirmed interactively that it's necessary to save and restore toklineno on the lexical stack: you can get recursive calls when parsing strings. Unfortunately I don't know of a non-interactive test for this. As well as adding a test for the main feature, I've moved all debug tests into a different test file. This saves me about 10 seconds every time I run it. Your experiences with the debugger are almost certainly the best test for this beyond the test suite, so I'll commit this as soon as I get this message back. Index: Src/lex.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/lex.c,v retrieving revision 1.45 diff -u -r1.45 lex.c --- Src/lex.c 8 Mar 2008 01:20:50 -0000 1.45 +++ Src/lex.c 31 Aug 2008 19:43:41 -0000 @@ -46,6 +46,17 @@ /**/ mod_export int tokfd; +/* + * Line number at which the first character of a token was found. + * We always set this in gettok(), which is always called from + * yylex() unless we have reached an error. So it is always + * valid when parsing. It is not useful during execution + * of the parsed structure. + */ + +/**/ +zlong toklineno; + /* lexical analyzer error flag */ /**/ @@ -211,6 +222,7 @@ unsigned char *cstack; int csp; + zlong toklineno; }; static struct lexstack *lstack = NULL; @@ -269,6 +281,7 @@ ls->ecsoffs = ecsoffs; ls->ecssub = ecssub; ls->ecnfunc = ecnfunc; + ls->toklineno = toklineno; cmdsp = 0; inredir = 0; hdocs = NULL; @@ -333,6 +346,7 @@ ecssub = lstack->ecssub; ecnfunc = lstack->ecnfunc; hlinesz = lstack->hlinesz; + toklineno = lstack->toklineno; errflag = 0; ln = lstack->next; @@ -661,6 +675,7 @@ beginning: tokstr = NULL; while (iblank(c = hgetc()) && !lexstop); + toklineno = lineno; if (lexstop) return (errflag) ? LEXERR : ENDINPUT; isfirstln = 0; Index: Src/parse.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/parse.c,v retrieving revision 1.71 diff -u -r1.71 parse.c --- Src/parse.c 11 Aug 2008 19:22:54 -0000 1.71 +++ Src/parse.c 31 Aug 2008 19:43:42 -0000 @@ -721,7 +721,7 @@ par_pline(int *complex) { int p; - zlong line = lineno; + zlong line = toklineno; p = ecadd(0); Index: Test/.distfiles =================================================================== RCS file: /cvsroot/zsh/zsh/Test/.distfiles,v retrieving revision 1.23 diff -u -r1.23 .distfiles --- Test/.distfiles 31 Aug 2008 13:35:28 -0000 1.23 +++ Test/.distfiles 31 Aug 2008 19:43:43 -0000 @@ -17,6 +17,7 @@ C02cond.ztst C03traps.ztst C04funcdef.ztst +C05debug.ztst D01prompt.ztst D02glob.ztst D03procsubst.ztst Index: Test/C03traps.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/C03traps.ztst,v retrieving revision 1.16 diff -u -r1.16 C03traps.ztst --- Test/C03traps.ztst 31 Aug 2008 16:01:16 -0000 1.16 +++ Test/C03traps.ztst 31 Aug 2008 19:43:43 -0000 @@ -350,94 +350,6 @@ >trap >Working 0 - unsetopt DEBUG_BEFORE_CMD - debug-trap-bug1() { - setopt localtraps - print "print bug file here" >bug-file - print "print this is line one - print this is line two - print this is line three - print and this is line fifty-nine." >bug-file2 - function debug_trap_handler { - print $functrace[1] - do_bug - } - function do_bug { - . ./bug-file - } - trap 'echo EXIT hit' EXIT - trap 'debug_trap_handler' DEBUG - . ./bug-file2 - } - debug-trap-bug1 -0: Relationship between traps and sources ->debug-trap-bug1:15 ->bug file here ->this is line one ->./bug-file2:1 ->bug file here ->this is line two ->./bug-file2:2 ->bug file here ->this is line three ->./bug-file2:3 ->bug file here ->and this is line fifty-nine. ->./bug-file2:4 ->bug file here ->debug-trap-bug1:16 ->bug file here ->EXIT hit - - cat >zsh-trapreturn-bug2 <<-'HERE' - cmd='./fdasfsdafd' - [[ -x $cmd ]] && rm $cmd - set -o DEBUG_BEFORE_CMD - trap '[[ $? -ne 0 ]] && exit 0' DEBUG - $cmd # invalid command - # Failure - exit 10 - HERE - $ZTST_testdir/../Src/zsh -f ./zsh-trapreturn-bug2 -0: trapreturn handling bug is properly fixed -?./zsh-trapreturn-bug2:5: no such file or directory: ./fdasfsdafd - - fn() { - setopt localtraps localoptions debugbeforecmd - trap '(( LINENO == 4 )) && setopt errexit' DEBUG - print $LINENO three - print $LINENO four - print $LINENO five - [[ -o errexit ]] && print "Hey, ERREXIT is set!" - } - fn -1:Skip line from DEBUG trap ->3 three ->5 five - - # Assignments are a special case, since they use a simpler - # wordcode type, so we need to test skipping them separately. - fn() { - setopt localtraps localoptions debugbeforecmd - trap '(( LINENO == 4 )) && setopt errexit' DEBUG - x=three - x=four - print $LINENO $x - [[ -o errexit ]] && print "Hey, ERREXIT is set!" - } - fn -1:Skip assignment from DEBUG trap ->5 three - - fn() { - setopt localtraps localoptions debugbeforecmd - trap 'print $LINENO' DEBUG - [[ a = a ]] && print a is ok - } - fn -0:line numbers of complex sublists ->3 ->a is ok %clean Index: Test/C05debug.ztst =================================================================== RCS file: Test/C05debug.ztst diff -N Test/C05debug.ztst --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Test/C05debug.ztst 31 Aug 2008 19:43:43 -0000 @@ -0,0 +1,114 @@ +%prep + + setopt localtraps + +%test + + unsetopt DEBUG_BEFORE_CMD + debug-trap-bug1() { + setopt localtraps + print "print bug file here" >bug-file + print "print this is line one + print this is line two + print this is line three + print and this is line fifty-nine." >bug-file2 + function debug_trap_handler { + print $functrace[1] + do_bug + } + function do_bug { + . ./bug-file + } + trap 'echo EXIT hit' EXIT + trap 'debug_trap_handler' DEBUG + . ./bug-file2 + } + debug-trap-bug1 +0: Relationship between traps and sources +>debug-trap-bug1:15 +>bug file here +>this is line one +>./bug-file2:1 +>bug file here +>this is line two +>./bug-file2:2 +>bug file here +>this is line three +>./bug-file2:3 +>bug file here +>and this is line fifty-nine. +>./bug-file2:4 +>bug file here +>debug-trap-bug1:16 +>bug file here +>EXIT hit + + cat >zsh-trapreturn-bug2 <<-'HERE' + cmd='./fdasfsdafd' + [[ -x $cmd ]] && rm $cmd + set -o DEBUG_BEFORE_CMD + trap '[[ $? -ne 0 ]] && exit 0' DEBUG + $cmd # invalid command + # Failure + exit 10 + HERE + $ZTST_testdir/../Src/zsh -f ./zsh-trapreturn-bug2 +0: trapreturn handling bug is properly fixed +?./zsh-trapreturn-bug2:5: no such file or directory: ./fdasfsdafd + + fn() { + setopt localtraps localoptions debugbeforecmd + trap '(( LINENO == 4 )) && setopt errexit' DEBUG + print $LINENO three + print $LINENO four + print $LINENO five + [[ -o errexit ]] && print "Hey, ERREXIT is set!" + } + fn +1:Skip line from DEBUG trap +>3 three +>5 five + + # Assignments are a special case, since they use a simpler + # wordcode type, so we need to test skipping them separately. + fn() { + setopt localtraps localoptions debugbeforecmd + trap '(( LINENO == 4 )) && setopt errexit' DEBUG + x=three + x=four + print $LINENO $x + [[ -o errexit ]] && print "Hey, ERREXIT is set!" + } + fn +1:Skip assignment from DEBUG trap +>5 three + + fn() { + setopt localtraps localoptions debugbeforecmd + trap 'print $LINENO' DEBUG + [[ a = a ]] && print a is ok + } + fn +0:line numbers of complex sublists +>3 +>a is ok + + fn() { + setopt localtraps localoptions debugbeforecmd + trap 'print $LINENO' DEBUG + print before + x=' first + second + third' + print $x + } + fn +0:line numbers of multiline assignments +>3 +>before +>4 +>7 +> first +> second +> third + -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/