zsh-users
 help / color / mirror / code / Atom feed
From: Phil Pennock <phil.pennock@globnix.org>
To: sac <sac_urs@yahoo.co.in>
Cc: Zsh users list <zsh-users@sunsite.dk>
Subject: Re: Debugging functions zsh
Date: Tue, 5 Sep 2006 14:01:16 +0200	[thread overview]
Message-ID: <20060905120116.GA8039@parhelion.globnix.org> (raw)
In-Reply-To: <20060905100823.10860.qmail@web8412.mail.in.yahoo.com>

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


      reply	other threads:[~2006-09-05 12:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-05 10:08 sac
2006-09-05 12:01 ` Phil Pennock [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060905120116.GA8039@parhelion.globnix.org \
    --to=phil.pennock@globnix.org \
    --cc=sac_urs@yahoo.co.in \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).