Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Debugging functions zsh



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



Messages sorted by: Reverse Date, Date, Thread, Author