From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16623 invoked from network); 5 Sep 2006 12:01:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 5 Sep 2006 12:01:38 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 19537 invoked from network); 5 Sep 2006 12:01:30 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 Sep 2006 12:01:30 -0000 Received: (qmail 19295 invoked by alias); 5 Sep 2006 12:01:19 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10680 Received: (qmail 19286 invoked from network); 5 Sep 2006 12:01:18 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 5 Sep 2006 12:01:18 -0000 Received: (qmail 17858 invoked from network); 5 Sep 2006 12:01:18 -0000 Received: from parhelion.firedrake.org (193.201.200.77) by a.mx.sunsite.dk with SMTP; 5 Sep 2006 12:01:17 -0000 Received: from phil by parhelion.firedrake.org with local (Exim 4.50 #1 (Debian)) id 1GKZcC-0002rK-5q; Tue, 05 Sep 2006 13:01:16 +0100 Date: Tue, 5 Sep 2006 14:01:16 +0200 From: Phil Pennock To: sac Cc: Zsh users list Subject: Re: Debugging functions zsh Message-ID: <20060905120116.GA8039@parhelion.globnix.org> Mail-Followup-To: sac , Zsh users list References: <20060905100823.10860.qmail@web8412.mail.in.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060905100823.10860.qmail@web8412.mail.in.yahoo.com> Sender: Phil Pennock On 2006-09-05 at 03:08 -0700, sac wrote: > When we want to debug a script, we use the -x flag, > like `zsh -x script_name', and we get all the > variables that are set etc. > How do we debug a function, which is sourced from a > script, other than putting print statements manually > here and there. % setopt xtrace % my_func % unsetopt xtrace This debugs everything the shell does, including precmd() evaluation and so on, thus there will be a little bit extra in the function. Alternatively, you can mark the function as traced. The "typeset" command won't blank the function when you call it like this: % typeset -f -t my_func This may be more useful if the function is being called from other functions. However, the trace tagging needs to happen _after_ the function is defined. % typeset -f -t fred % function fred { print "Foo: $*" } % fred wibble Foo: wibble % typeset -f -t fred % fred wibble +fred:0> print 'Foo: wibble' Foo: wibble % See zshoptions(1)/XTRACE and zshbuiltins(1)/typeset. -Phil