zsh-users
 help / color / mirror / code / Atom feed
* Debugging functions zsh
@ 2006-09-05 10:08 sac
  2006-09-05 12:01 ` Phil Pennock
  0 siblings, 1 reply; 2+ messages in thread
From: sac @ 2006-09-05 10:08 UTC (permalink / raw)
  To: Zsh users list

Hi,

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.

Thanks,
sac.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Debugging functions zsh
  2006-09-05 10:08 Debugging functions zsh sac
@ 2006-09-05 12:01 ` Phil Pennock
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Pennock @ 2006-09-05 12:01 UTC (permalink / raw)
  To: sac; +Cc: Zsh users list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-09-05 12:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-05 10:08 Debugging functions zsh sac
2006-09-05 12:01 ` Phil Pennock

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).