From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20252 invoked from network); 29 Sep 2008 02:32:56 -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,WEIRD_PORT autolearn=no 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; 29 Sep 2008 02:32:56 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 64226 invoked from network); 29 Sep 2008 02:32:44 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 29 Sep 2008 02:32:44 -0000 Received: (qmail 26609 invoked by alias); 29 Sep 2008 02:32:30 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25765 Received: (qmail 26584 invoked from network); 29 Sep 2008 02:32:27 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 29 Sep 2008 02:32:27 -0000 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.180]) by bifrost.dotsrc.org (Postfix) with ESMTP id 5A4BA8030847 for ; Mon, 29 Sep 2008 04:32:20 +0200 (CEST) Received: by wa-out-1112.google.com with SMTP id m28so992077wag.29 for ; Sun, 28 Sep 2008 19:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=HWgvuBv0qGrL9HT6ZyOl5oyRawNjW5DuYo6f2sZMjxY=; b=P3IU9hH7IDMg18p+ndfVoU4TRRwVDsT47Ld1PO+fFvXNzeRRqDSCV23JEJiSgZGkpP YFaGXbXp6QiQEiGcFT5DU04/J2KidR4e5aJjEoKQMn2syaMmgupjHcG8BUoHxeZOfS5g nIEDXeQ2C0oiqUMg/VuBcjJrtumJdjiXY/HFA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=doJ8W3H7rHZREP9KqYUMFNxGO+2c9gI/61DEHa9Narz4SziV788o6fC/RbWu/RXGup vMbfaU956ealtn1ObVsUJxBTkx8R5XJ/QiY4Gqj/cHRIJmTnhT6y4fYfNSQUOGJHfK7a ym188v0n6SBJdYYcm3bAbvw5Zqk+geB1ibFRQ= Received: by 10.114.211.1 with SMTP id j1mr4995929wag.103.1222655539227; Sun, 28 Sep 2008 19:32:19 -0700 (PDT) Received: by 10.114.159.2 with HTTP; Sun, 28 Sep 2008 19:32:19 -0700 (PDT) Message-ID: <6cd6de210809281932u2e04a844l219d1db5a7568a73@mail.gmail.com> Date: Sun, 28 Sep 2008 22:32:19 -0400 From: "Rocky Bernstein" To: "Peter Stephenson" Subject: Re: Help me track down a tough bug? (probably funcfiletrace, subshells and possibly I/O redirection) Cc: "Zsh hackers list" In-Reply-To: <20080928221651.6ee7f671@pws-pc> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6cd6de210809281219i4bf1ed18mefa45b967fa835a6@mail.gmail.com> <20080928221651.6ee7f671@pws-pc> X-Virus-Scanned: ClamAV 0.92.1/8350/Mon Sep 29 02:22:11 2008 on bifrost X-Virus-Status: Clean In general I think this will help. Not just because it helps the debugger. Later (* * * * below) I'll elaborate on this. But in short, either this patch doesn't solve this particular problem or I hand-applied the patch incorrectly. (A cut and paste to a file caused many rejections by "patch", so I did the rest by hand. It's possible I missed something. Running the regression test caused a failures in E01options.ztst with an eval and $LINENO, and another in C05debug.ztst with debug-trap-bug, but I think this is to be expected. ) When I run zsh with those patches on this program: ( x=$(print $LINENO); print $x ) I still get 1. Is that what one gets with the patch applied? Note that there are other problems encountered that not explained by that patch. In particular, it doesn't explain the position zshdb2.sh:6 in the output that went: ./command/eval.sh:4 ./command/eval.sh:22 ./lib/processor.sh:67 ./lib/processor.sh:16 ./zshdb2.sh:6 ./testing.sh:1 ./zshdb2.sh:34 The correct position there is ./zshdb2.sh:9 which does appear earlier. Also it doesn't explain the missing funcfiletrace output which could be explained if somehow if zsh didn't think there were any function calls. Finally there is a history bug, but for that's something probably totally different and likely just a bug in the debugger code. * * * * Let me see if I understand the situation correctly: there is an internal routine called parse_string() which can be called though eval as well as backtick. For eval, one can argue its the right thing, but for backtick seeing 1 as the value of $LINENO might be a bit odd. zsh is not the only programming language where this issue comes up. I've seen it in Python and Ruby. In both, when eval'ing a string, the line number is reset to 1 and the filename is something bogus. In the Python debugger, pydb, what I do is search for such eval functions in the traceback and use the line number of the thing that called that instead. I can't do that here because "eval" or "backtick" or "parse_string" doesn't appear as a function call in funcstack or any of the other arrays, It might be cool to put somewhere in funcstack or funcfiletrace the ZSH_SUBSHELL value. Ruby is a little nicer here (and that generally seems to be the case). By default, the line number is reset, but if you want you can supply a line number and file name as the optional final parameters. However Ola Blini has observed that really the surrounding context should be the default; he calls the workaround an "anti-pattern." See: http://ola-bini.blogspot.com/search/label/eval On Sun, Sep 28, 2008 at 5:16 PM, Peter Stephenson wrote: > On Sun, 28 Sep 2008 15:19:37 -0400 > "Rocky Bernstein" wrote: >> There is what looks to me a bug in the recent funcfiletrace that I've >> been trying to isolate. >> >> #!/usr/local/bin/zsh >> # Test debugger handling of subshells >> ( >> x=$(print 5; print 6) >> ) >> (/tmp/zshdb/testing.sh:1): >> print 5 # In a 2nd subshell, backtick >> zshdb<((7))> where # ((..)) indicates this. >> >> What's wrong is that we aren't on line 1 of testing.sh. > > exec.c:parse_string() resets the line number for every invocation. > That's fine for eval, where we've fixed this up explicitly, but doesn't > work in the call from exec.c:getoutput() which is the case here. > Obviously that's not consistent with the fact that it doesn't have its > own file; we don't do the special eval handling of reconstructing the > file location in this case. > > The reason (...) is different is it's parsed straight away when the > shell reads it in; it's not stored as a string argument to be looked at > again later. > > It's possible we can simply get away with not resetting the line number > in any case without its own entry on the function stack. That's about > the simplest fix, but changes the meaning of line numbers in all string > evaluations apart from eval, trap and functions, where we have the > special handling. I'm coming round to the view that this is nonetheless > the best way of salvaging consistency of the debugging environment. > Have a go at this and see if it looks sensible. > > Index: Src/builtin.c > =================================================================== > RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v > retrieving revision 1.209 > diff -u -r1.209 builtin.c > --- Src/builtin.c 27 Sep 2008 19:57:33 -0000 1.209 > +++ Src/builtin.c 28 Sep 2008 21:11:21 -0000 > @@ -4781,7 +4781,7 @@ > } else > fpushed = 0; > > - prog = parse_string(zjoin(argv, ' ', 1)); > + prog = parse_string(zjoin(argv, ' ', 1), 1); > if (prog) { > if (wc_code(*prog->prog) != WC_LIST) { > /* No code to execute */ > @@ -5781,7 +5781,7 @@ > arg = *argv++; > if (!*arg) > prog = &dummy_eprog; > - else if (!(prog = parse_string(arg))) { > + else if (!(prog = parse_string(arg, 1))) { > zwarnnam(name, "couldn't parse trap command"); > return 1; > } > Index: Src/exec.c > =================================================================== > RCS file: /cvsroot/zsh/zsh/Src/exec.c,v > retrieving revision 1.156 > diff -u -r1.156 exec.c > --- Src/exec.c 26 Sep 2008 09:11:29 -0000 1.156 > +++ Src/exec.c 28 Sep 2008 21:11:22 -0000 > @@ -188,17 +188,21 @@ > > /**/ > mod_export Eprog > -parse_string(char *s) > +parse_string(char *s, int reset_lineno) > { > Eprog p; > - zlong oldlineno = lineno; > + zlong oldlineno; > > lexsave(); > inpush(s, INP_LINENO, NULL); > strinbeg(0); > - lineno = 1; > + if (reset_lineno) { > + oldlineno = lineno; > + lineno = 1; > + } > p = parse_list(); > - lineno = oldlineno; > + if (reset_lineno) > + lineno = oldlineno; > if (tok == LEXERR && !lastval) > lastval = 1; > strinend(); > @@ -954,7 +958,7 @@ > Eprog prog; > > pushheap(); > - if ((prog = parse_string(s))) > + if ((prog = parse_string(s, 0))) > execode(prog, dont_change_job, exiting); > popheap(); > } > @@ -3445,7 +3449,7 @@ > pid_t pid; > char *s; > > - if (!(prog = parse_string(cmd))) > + if (!(prog = parse_string(cmd, 0))) > return NULL; > > if ((s = simple_redir_name(prog, REDIR_READ))) { > @@ -3566,7 +3570,7 @@ > return NULL; > } > *str = '\0'; > - if (str[1] || !(prog = parse_string(cmd + 2))) { > + if (str[1] || !(prog = parse_string(cmd + 2, 0))) { > zerr("parse error in process substitution"); > return NULL; > } > @@ -4453,7 +4457,7 @@ > d = metafy(d, rlen, META_REALLOC); > > scriptname = dupstring(s); > - r = parse_string(d); > + r = parse_string(d, 1); > scriptname = oldscriptname; > > if (fname) > Index: Src/glob.c > =================================================================== > RCS file: /cvsroot/zsh/zsh/Src/glob.c,v > retrieving revision 1.65 > diff -u -r1.65 glob.c > --- Src/glob.c 11 May 2008 19:55:21 -0000 1.65 > +++ Src/glob.c 28 Sep 2008 21:11:23 -0000 > @@ -3329,7 +3329,7 @@ > { > Eprog prog; > > - if ((prog = parse_string(str))) { > + if ((prog = parse_string(str, 0))) { > int ef = errflag, lv = lastval, ret; > > unsetparam("reply"); > Index: Src/parse.c > =================================================================== > RCS file: /cvsroot/zsh/zsh/Src/parse.c,v > retrieving revision 1.75 > diff -u -r1.75 parse.c > --- Src/parse.c 24 Sep 2008 19:19:56 -0000 1.75 > +++ Src/parse.c 28 Sep 2008 21:11:24 -0000 > @@ -2831,7 +2831,7 @@ > close(fd); > file = metafy(file, flen, META_REALLOC); > > - if (!(prog = parse_string(file)) || errflag) { > + if (!(prog = parse_string(file, 1)) || errflag) { > errflag = 0; > close(dfd); > zfree(file, flen); > Index: Src/Modules/parameter.c > =================================================================== > RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v > retrieving revision 1.49 > diff -u -r1.49 parameter.c > --- Src/Modules/parameter.c 11 Sep 2008 17:14:39 -0000 1.49 > +++ Src/Modules/parameter.c 28 Sep 2008 21:11:24 -0000 > @@ -279,7 +279,7 @@ > > val = metafy(val, strlen(val), META_REALLOC); > > - prog = parse_string(val); > + prog = parse_string(val, 1); > > if (!prog || prog == &dummy_eprog) { > zwarn("invalid function definition", value); > Index: Src/Modules/zpty.c > =================================================================== > RCS file: /cvsroot/zsh/zsh/Src/Modules/zpty.c,v > retrieving revision 1.38 > diff -u -r1.38 zpty.c > --- Src/Modules/zpty.c 15 May 2008 15:51:01 -0000 1.38 > +++ Src/Modules/zpty.c 28 Sep 2008 21:11:24 -0000 > @@ -299,7 +299,7 @@ > if (!ineval) > scriptname = "(zpty)"; > > - prog = parse_string(zjoin(args, ' ', 1)); > + prog = parse_string(zjoin(args, ' ', 1), 0); > if (!prog) { > errflag = 0; > scriptname = oscriptname; > Index: Src/Modules/zutil.c > =================================================================== > RCS file: /cvsroot/zsh/zsh/Src/Modules/zutil.c,v > retrieving revision 1.23 > diff -u -r1.23 zutil.c > --- Src/Modules/zutil.c 6 Jul 2007 21:52:40 -0000 1.23 > +++ Src/Modules/zutil.c 28 Sep 2008 21:11:25 -0000 > @@ -251,7 +251,7 @@ > if (eval) { > int ef = errflag; > > - eprog = parse_string(zjoin(vals, ' ', 1)); > + eprog = parse_string(zjoin(vals, ' ', 1), 0); > errflag = ef; > > if (!eprog) > > > -- > Peter Stephenson > Web page now at http://homepage.ntlworld.com/p.w.stephenson/ >