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

Re: PATCH: trace information for sourced files



Thanks. Comments in line.

On Tue, Aug 12, 2008 at 3:46 PM, Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> 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@xxxxxxxxxxxx>
> Web page now at http://homepage.ntlworld.com/p.w.stephenson/
>



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