From 01f5d0a2741ed45f3c85493e88daafc2091259a9 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 12 Aug 2008 20:25:14 +0000 Subject: 25443 (tweaked): allow $functrace to show sourced files --- ChangeLog | 6 ++++++ Doc/Zsh/mod_parameter.yo | 5 +++++ Src/init.c | 23 ++++++++++++----------- Test/V06parameter.ztst | 8 +++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a4d06f96..b14cdde4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-08-12 Peter Stephenson + + * 25443 (tweaked): Doc/Zsh/mod_parameter.yo, + Src/Modules/parameter.c, Test/V06parameter.ztst: allow + $functrace to show sourced files. + 2008-08-12 Peter Stephenson * unposted: Completion/Solaris/Command/.distfiles, diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo index d3ace6df0..0e096c968 100644 --- a/Doc/Zsh/mod_parameter.yo +++ b/Doc/Zsh/mod_parameter.yo @@ -173,6 +173,9 @@ or `var(name) tt(LPAR()RPAR())' started. In the case of an autoloaded function in native zsh format where only the body of the function occurs in the file the line number is reported as zero. The format of each element is var(filename)tt(:)var(lineno). +For files that have been executed by the tt(source) or tt(.) builtins +(in which case there is no separate definition) the trace information is +shown as tt(source:0). ) vindex(funcstack) item(tt(funcstack))( @@ -185,5 +188,7 @@ item(tt(functrace))( This array contains the names and line numbers of the callers corresponding to the functions currently being executed. The format of each element is var(name)tt(:)var(lineno). +Callers are also shown for sourced files; the caller is the point +where the tt(source) or tt(.) command was executed. ) enditem() diff --git a/Src/init.c b/Src/init.c index 2f84fc445..d3c8e2266 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1100,16 +1100,17 @@ source(char *s) trap_state = TRAP_STATE_INACTIVE; sourcelevel++; - /* { */ - /* struct funcstack fstack; */ - /* fstack.name = dupstring("source"); */ - /* fstack.caller = dupstring(scriptfilename); */ - /* fstack.flineno = oldlineno; */ - /* fstack.lineno = oldlineno; */ - /* fstack.filename = NULL; */ - /* fstack.prev = funcstack; */ - /* funcstack = &fstack; */ - /* } */ + { + struct funcstack fstack; + fstack.name = dupstring("source"); + fstack.caller = dupstring(old_scriptfilename ? old_scriptfilename : + "zsh"); + fstack.flineno = 0; + fstack.lineno = oldlineno; + fstack.filename = fstack.name; + fstack.prev = funcstack; + funcstack = &fstack; + } if (prog) { pushheap(); @@ -1118,7 +1119,7 @@ source(char *s) popheap(); } else loop(0, 0); /* loop through the file to be sourced */ - /* funcstack = funcstack->prev; */ + funcstack = funcstack->prev; sourcelevel--; trap_state = otrap_state; diff --git a/Test/V06parameter.ztst b/Test/V06parameter.ztst index 6442adb12..ce6dacee9 100644 --- a/Test/V06parameter.ztst +++ b/Test/V06parameter.ztst @@ -1,5 +1,8 @@ %test + print 'print In sourced file + print $LINENO + $functrace + $funcsourcetrace + ' >sourcedfile print -r -- 'print Started functrace.zsh module_path=(./Modules) print $LINENO + $functrace + $funcsourcetrace @@ -20,7 +23,8 @@ autoload autofn : autofn - autofn' >functrace.zsh + autofn + . ./sourcedfile' >functrace.zsh $ZTST_testdir/../Src/zsh +Z -f ./functrace.zsh 0:Function tracing >Started functrace.zsh @@ -31,3 +35,5 @@ >2 + ./functrace.zsh:20 + ./autofn:0 >Inside autofn >2 + ./functrace.zsh:21 + ./autofn:0 +>In sourced file +>2 + ./functrace.zsh:22 + source:0 -- cgit 1.4.1