Re: ksh(1): preserve xtrace option

2017-01-16 Thread frantisek holop
Anton Lindqvist, 16 Jan 2017 10:02:
> > Hmm, I see now that my memory is false, ksh93 (available as port) does
> > trace into functions. Still, I'm undecided if we want to change our
> > ksh.
> 
> Any thoughts from others on changing the defaults?

just my 2 cents.
when many years ago i found out that ksh does not trace
into functions i also considered it a bug.

in the tools and languages i use, when a debug mode is
set, one is not expected to reconfirm that setting in
every entered function.  i think the "least surprising
result" would be to trace into functions, and disable
tracing in the particular function where tracing is not
desired...

as i personally want to see all debug output,
i always have a global set -x and local set -x's.
as such i am all for the change.

-f
-- 



Re: ksh(1): preserve xtrace option

2017-01-16 Thread Anton Lindqvist
On Fri, Jan 13, 2017 at 10:56:51AM +0100, Otto Moerbeek wrote:
> On Fri, Jan 13, 2017 at 10:20:19AM +0100, Otto Moerbeek wrote:
> 
> > On Fri, Jan 13, 2017 at 09:51:51AM +0100, Otto Moerbeek wrote:
> > 
> > > On Fri, Jan 13, 2017 at 09:46:54AM +0100, Anton Lindqvist wrote:
> > > 
> > > > Consider the following script which calculates the sum of the first N
> > > > integers recursively:
> > > > 
> > > > $ cat >sum.sh < > > > sum() {
> > > >   [ $1 -eq 0 ] && echo $2 || sum $(($1 - 1)) $(($2 + $1))
> > > > }
> > > > 
> > > > sum 5
> > > > !
> > > > 
> > > > Executing the script with the x option gives the following output:
> > > > 
> > > > $ sh -x sum.sh
> > > > + sum 5
> > > > 15
> > > > 
> > > > I would expect the recursive calls to be traced, similar to how GNU
> > > > bash/sh behaves. With the patch below applied the output is as expected:
> > > > 
> > > > $ sh -x sum.sh
> > > > + sum 5
> > > > + [ 5 -eq 0 ]
> > > > + sum 4 5
> > > > + [ 4 -eq 0 ]
> > > > + sum 3 9
> > > > + [ 3 -eq 0 ]
> > > > + sum 2 12
> > > > + [ 2 -eq 0 ]
> > > > + sum 1 14
> > > > + [ 1 -eq 0 ]
> > > > + sum 0 15
> > > > + [ 0 -eq 0 ]
> > > > + echo 15
> > > > 15
> > > > 
> > > > The patch make sure to assigns the TRACE flag to every user-defined
> > > > function if the x option is present. The piece of code that led me to
> > > > this:
> > > > 
> > > > $ sed -n 606,607p /usr/src/bin/ksh/exec.c
> > > > old_xflag = Flag(FXTRACE);
> > > > Flag(FXTRACE) = tp->flag & TRACE ? true : false;
> > > 
> > > Hmmm,
> > > 
> > > afaik -x has always been local to a function in ksh-like shells.
> > > To enable tracing within function call set -x in the fucntion te be 
> > > traced.
> > 
> > or set the trace attribute for a specific function:
> > 
> > typeset -ft sum

Thanks, didn't know.

> Hmm, I see now that my memory is false, ksh93 (available as port) does
> trace into functions. Still, I'm undecided if we want to change our
> ksh.

Any thoughts from others on changing the defaults?



Re: ksh(1): preserve xtrace option

2017-01-13 Thread Otto Moerbeek
On Fri, Jan 13, 2017 at 10:20:19AM +0100, Otto Moerbeek wrote:

> On Fri, Jan 13, 2017 at 09:51:51AM +0100, Otto Moerbeek wrote:
> 
> > On Fri, Jan 13, 2017 at 09:46:54AM +0100, Anton Lindqvist wrote:
> > 
> > > Consider the following script which calculates the sum of the first N
> > > integers recursively:
> > > 
> > > $ cat >sum.sh < > > sum() {
> > >   [ $1 -eq 0 ] && echo $2 || sum $(($1 - 1)) $(($2 + $1))
> > > }
> > > 
> > > sum 5
> > > !
> > > 
> > > Executing the script with the x option gives the following output:
> > > 
> > > $ sh -x sum.sh
> > > + sum 5
> > > 15
> > > 
> > > I would expect the recursive calls to be traced, similar to how GNU
> > > bash/sh behaves. With the patch below applied the output is as expected:
> > > 
> > > $ sh -x sum.sh
> > > + sum 5
> > > + [ 5 -eq 0 ]
> > > + sum 4 5
> > > + [ 4 -eq 0 ]
> > > + sum 3 9
> > > + [ 3 -eq 0 ]
> > > + sum 2 12
> > > + [ 2 -eq 0 ]
> > > + sum 1 14
> > > + [ 1 -eq 0 ]
> > > + sum 0 15
> > > + [ 0 -eq 0 ]
> > > + echo 15
> > > 15
> > > 
> > > The patch make sure to assigns the TRACE flag to every user-defined
> > > function if the x option is present. The piece of code that led me to
> > > this:
> > > 
> > > $ sed -n 606,607p /usr/src/bin/ksh/exec.c
> > > old_xflag = Flag(FXTRACE);
> > > Flag(FXTRACE) = tp->flag & TRACE ? true : false;
> > 
> > Hmmm,
> > 
> > afaik -x has always been local to a function in ksh-like shells.
> > To enable tracing within function call set -x in the fucntion te be traced.
> 
> or set the trace attribute for a specific function:
> 
> typeset -ft sum

Hmm, I see now that my memory is false, ksh93 (available as port) does
trace into functions. Still, I'm undecided if we want to change our
ksh.

-Otto

> > 
> > > 
> > > Index: exec.c
> > > ===
> > > RCS file: /cvs/src/bin/ksh/exec.c,v
> > > retrieving revision 1.68
> > > diff -u -p -r1.68 exec.c
> > > --- exec.c11 Dec 2016 17:49:19 -  1.68
> > > +++ exec.c12 Jan 2017 20:10:48 -
> > > @@ -796,6 +796,9 @@ define(const char *name, struct op *t)
> > >   if (t->u.ksh_func)
> > >   tp->flag |= FKSH;
> > >  
> > > + if (Flag(FXTRACE))
> > > + tp->flag |= TRACE;
> > > +
> > >   return 0;
> > >  }



Re: ksh(1): preserve xtrace option

2017-01-13 Thread Otto Moerbeek
On Fri, Jan 13, 2017 at 09:51:51AM +0100, Otto Moerbeek wrote:

> On Fri, Jan 13, 2017 at 09:46:54AM +0100, Anton Lindqvist wrote:
> 
> > Consider the following script which calculates the sum of the first N
> > integers recursively:
> > 
> > $ cat >sum.sh < > sum() {
> >   [ $1 -eq 0 ] && echo $2 || sum $(($1 - 1)) $(($2 + $1))
> > }
> > 
> > sum 5
> > !
> > 
> > Executing the script with the x option gives the following output:
> > 
> > $ sh -x sum.sh
> > + sum 5
> > 15
> > 
> > I would expect the recursive calls to be traced, similar to how GNU
> > bash/sh behaves. With the patch below applied the output is as expected:
> > 
> > $ sh -x sum.sh
> > + sum 5
> > + [ 5 -eq 0 ]
> > + sum 4 5
> > + [ 4 -eq 0 ]
> > + sum 3 9
> > + [ 3 -eq 0 ]
> > + sum 2 12
> > + [ 2 -eq 0 ]
> > + sum 1 14
> > + [ 1 -eq 0 ]
> > + sum 0 15
> > + [ 0 -eq 0 ]
> > + echo 15
> > 15
> > 
> > The patch make sure to assigns the TRACE flag to every user-defined
> > function if the x option is present. The piece of code that led me to
> > this:
> > 
> > $ sed -n 606,607p /usr/src/bin/ksh/exec.c
> > old_xflag = Flag(FXTRACE);
> > Flag(FXTRACE) = tp->flag & TRACE ? true : false;
> 
> Hmmm,
> 
> afaik -x has always been local to a function in ksh-like shells.
> To enable tracing within function call set -x in the fucntion te be traced.

or set the trace attribute for a specific function:

typeset -ft sum

> 
>   -Otto
> 
> > 
> > Index: exec.c
> > ===
> > RCS file: /cvs/src/bin/ksh/exec.c,v
> > retrieving revision 1.68
> > diff -u -p -r1.68 exec.c
> > --- exec.c  11 Dec 2016 17:49:19 -  1.68
> > +++ exec.c  12 Jan 2017 20:10:48 -
> > @@ -796,6 +796,9 @@ define(const char *name, struct op *t)
> > if (t->u.ksh_func)
> > tp->flag |= FKSH;
> >  
> > +   if (Flag(FXTRACE))
> > +   tp->flag |= TRACE;
> > +
> > return 0;
> >  }



Re: ksh(1): preserve xtrace option

2017-01-13 Thread Otto Moerbeek
On Fri, Jan 13, 2017 at 09:46:54AM +0100, Anton Lindqvist wrote:

> Consider the following script which calculates the sum of the first N
> integers recursively:
> 
> $ cat >sum.sh < sum() {
>   [ $1 -eq 0 ] && echo $2 || sum $(($1 - 1)) $(($2 + $1))
> }
> 
> sum 5
> !
> 
> Executing the script with the x option gives the following output:
> 
> $ sh -x sum.sh
> + sum 5
> 15
> 
> I would expect the recursive calls to be traced, similar to how GNU
> bash/sh behaves. With the patch below applied the output is as expected:
> 
> $ sh -x sum.sh
> + sum 5
> + [ 5 -eq 0 ]
> + sum 4 5
> + [ 4 -eq 0 ]
> + sum 3 9
> + [ 3 -eq 0 ]
> + sum 2 12
> + [ 2 -eq 0 ]
> + sum 1 14
> + [ 1 -eq 0 ]
> + sum 0 15
> + [ 0 -eq 0 ]
> + echo 15
> 15
> 
> The patch make sure to assigns the TRACE flag to every user-defined
> function if the x option is present. The piece of code that led me to
> this:
> 
> $ sed -n 606,607p /usr/src/bin/ksh/exec.c
> old_xflag = Flag(FXTRACE);
> Flag(FXTRACE) = tp->flag & TRACE ? true : false;

Hmmm,

afaik -x has always been local to a function in ksh-like shells.
To enable tracing within function call set -x in the fucntion te be traced.

-Otto

> 
> Index: exec.c
> ===
> RCS file: /cvs/src/bin/ksh/exec.c,v
> retrieving revision 1.68
> diff -u -p -r1.68 exec.c
> --- exec.c11 Dec 2016 17:49:19 -  1.68
> +++ exec.c12 Jan 2017 20:10:48 -
> @@ -796,6 +796,9 @@ define(const char *name, struct op *t)
>   if (t->u.ksh_func)
>   tp->flag |= FKSH;
>  
> + if (Flag(FXTRACE))
> + tp->flag |= TRACE;
> +
>   return 0;
>  }