zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: trace information for sourced files
@ 2008-08-12 19:46 Peter Stephenson
  2008-08-12 19:58 ` Rocky Bernstein
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2008-08-12 19:46 UTC (permalink / raw)
  To: Zsh hackers list

This enables the trace information for sourced files.  Again, the key is
to make sure the information reflects the calling context.

I'm not sure what to put in $funcsourcetrace since there is no separate
point of definition from that of the caller in this case.  As we need
something to keep the array lengths consistent, I've simply put in the
same information as in $functrace.  Arguably it should be something
special.

Note that I will be away for holiday in two parts after tomorrow.

Index: Doc/Zsh/mod_parameter.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_parameter.yo,v
retrieving revision 1.9
diff -u -r1.9 mod_parameter.yo
--- Doc/Zsh/mod_parameter.yo	11 Aug 2008 19:22:54 -0000	1.9
+++ Doc/Zsh/mod_parameter.yo	12 Aug 2008 19:39:43 -0000
@@ -173,6 +173,9 @@
 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).
+Trace information is also shown for files that have been executed
+by the tt(source) or tt(.) builtins; in this case it
+is identical to that provided by the tt(functrace) parameter.
 )
 vindex(funcstack)
 item(tt(funcstack))(
@@ -185,5 +188,7 @@
 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()
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.92
diff -u -r1.92 init.c
--- Src/init.c	11 Aug 2008 19:22:54 -0000	1.92
+++ Src/init.c	12 Aug 2008 19:39:43 -0000
@@ -1100,16 +1100,17 @@
     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 = oldlineno;
+       fstack.lineno = oldlineno;
+       fstack.filename = fstack.caller;
+       fstack.prev = funcstack;
+       funcstack = &fstack;
+    }
     
     if (prog) {
 	pushheap();
@@ -1118,7 +1119,7 @@
 	popheap();
     } else
 	loop(0, 0);		     /* loop through the file to be sourced  */
-    /* funcstack = funcstack->prev; */
+    funcstack = funcstack->prev;
     sourcelevel--;
 
     trap_state = otrap_state;
Index: Test/V06parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/V06parameter.ztst,v
retrieving revision 1.2
diff -u -r1.2 V06parameter.ztst
--- Test/V06parameter.ztst	11 Aug 2008 19:29:26 -0000	1.2
+++ Test/V06parameter.ztst	12 Aug 2008 19:39:43 -0000
@@ -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 + ./functrace.zsh:22


-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: PATCH: trace information for sourced files
  2008-08-12 19:46 PATCH: trace information for sourced files Peter Stephenson
@ 2008-08-12 19:58 ` Rocky Bernstein
  2008-08-12 20:27   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Rocky Bernstein @ 2008-08-12 19:58 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

Thanks. Comments in line.

On Tue, Aug 12, 2008 at 3:46 PM, Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
> This enables the trace information for sourced files.  Again, the key is
> to make sure the information reflects the calling context.
>
> I'm not sure what to put in $funcsourcetrace since there is no separate
> point of definition from that of the caller in this case.

How about "source" or ".". Down the line one may want to record the
number of parameters passed, and here I note that zsh allows passing
parameters in a source command.

 As we need
> something to keep the array lengths consistent, I've simply put in the
> same information as in $functrace.  Arguably it should be something
> special.
>
> Note that I will be away for holiday in two parts after tomorrow.

Interesting. I'll be out for the next week as well. Lemme know when
this is committed to CVS and so I can make the updates to zshdb.

Many thanks.


>
> Index: Doc/Zsh/mod_parameter.yo
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_parameter.yo,v
> retrieving revision 1.9
> diff -u -r1.9 mod_parameter.yo
> --- Doc/Zsh/mod_parameter.yo    11 Aug 2008 19:22:54 -0000      1.9
> +++ Doc/Zsh/mod_parameter.yo    12 Aug 2008 19:39:43 -0000
> @@ -173,6 +173,9 @@
>  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).
> +Trace information is also shown for files that have been executed
> +by the tt(source) or tt(.) builtins; in this case it
> +is identical to that provided by the tt(functrace) parameter.
>  )
>  vindex(funcstack)
>  item(tt(funcstack))(
> @@ -185,5 +188,7 @@
>  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()
> Index: Src/init.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/init.c,v
> retrieving revision 1.92
> diff -u -r1.92 init.c
> --- Src/init.c  11 Aug 2008 19:22:54 -0000      1.92
> +++ Src/init.c  12 Aug 2008 19:39:43 -0000
> @@ -1100,16 +1100,17 @@
>     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 = oldlineno;
> +       fstack.lineno = oldlineno;
> +       fstack.filename = fstack.caller;
> +       fstack.prev = funcstack;
> +       funcstack = &fstack;
> +    }
>
>     if (prog) {
>        pushheap();
> @@ -1118,7 +1119,7 @@
>        popheap();
>     } else
>        loop(0, 0);                  /* loop through the file to be sourced  */
> -    /* funcstack = funcstack->prev; */
> +    funcstack = funcstack->prev;
>     sourcelevel--;
>
>     trap_state = otrap_state;
> Index: Test/V06parameter.ztst
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Test/V06parameter.ztst,v
> retrieving revision 1.2
> diff -u -r1.2 V06parameter.ztst
> --- Test/V06parameter.ztst      11 Aug 2008 19:29:26 -0000      1.2
> +++ Test/V06parameter.ztst      12 Aug 2008 19:39:43 -0000
> @@ -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 + ./functrace.zsh:22
>
>
> --
> Peter Stephenson <p.w.stephenson@ntlworld.com>
> Web page now at http://homepage.ntlworld.com/p.w.stephenson/
>


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

* Re: PATCH: trace information for sourced files
  2008-08-12 19:58 ` Rocky Bernstein
@ 2008-08-12 20:27   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2008-08-12 20:27 UTC (permalink / raw)
  To: Zsh hackers list

On Tue, 12 Aug 2008 15:58:03 -0400
"Rocky Bernstein" <rocky.bernstein@gmail.com> wrote:
> > I'm not sure what to put in $funcsourcetrace since there is no separate
> > point of definition from that of the caller in this case.
> 
> How about "source" or ".". Down the line one may want to record the
> number of parameters passed, and here I note that zsh allows passing
> parameters in a source command.

OK, I've committed it so that the funcsourcetrace element shows up as
"source:0".

I had a look at providing the text for debug traps but it wasn't as
trivial as I'd hoped so that may have to wait.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

end of thread, other threads:[~2008-08-12 20:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-12 19:46 PATCH: trace information for sourced files Peter Stephenson
2008-08-12 19:58 ` Rocky Bernstein
2008-08-12 20:27   ` Peter Stephenson

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