zsh-workers
 help / color / mirror / code / Atom feed
From: "Rocky Bernstein" <rocky.bernstein@gmail.com>
To: "Peter Stephenson" <p.w.stephenson@ntlworld.com>
Cc: "Zsh hackers list" <zsh-workers@sunsite.dk>
Subject: Re: PATCH: trace information for sourced files
Date: Tue, 12 Aug 2008 15:58:03 -0400	[thread overview]
Message-ID: <6cd6de210808121258n5bd7b65fr225ea73e4dbfc0c5@mail.gmail.com> (raw)
In-Reply-To: <8933.1218570362@pws-pc>

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/
>


  reply	other threads:[~2008-08-12 19:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-12 19:46 Peter Stephenson
2008-08-12 19:58 ` Rocky Bernstein [this message]
2008-08-12 20:27   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6cd6de210808121258n5bd7b65fr225ea73e4dbfc0c5@mail.gmail.com \
    --to=rocky.bernstein@gmail.com \
    --cc=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).