• let mksh “set -x” print whole TCOM trees

• plug some memory leaks in debug (“set -x”) and warning paths while here
• one from Florian (friend of Natureshadow) for WTF
This commit is contained in:
tg 2013-03-24 00:56:27 +00:00
parent d99e470a64
commit 4b2e17b828
7 changed files with 45 additions and 50 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.624 2013/03/05 15:41:39 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.625 2013/03/24 00:56:17 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013
@ -1532,7 +1532,7 @@ else
#define EXTERN
#define MKSH_INCLUDES_ONLY
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.624 2013/03/05 15:41:39 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.625 2013/03/24 00:56:17 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); }
EOF
case $cm in
@ -2120,7 +2120,7 @@ addsrcs USE_PRINTF_BUILTIN printf.c
test 1 = "$USE_PRINTF_BUILTIN" && add_cppflags -DMKSH_PRINTF_BUILTIN
test 1 = "$HAVE_CAN_VERB" && CFLAGS="$CFLAGS -verbose"
test -n "$LDSTATIC" && add_cppflags -DMKSH_OPTSTATIC
add_cppflags -DMKSH_BUILD_R=441
add_cppflags -DMKSH_BUILD_R=449
$e $bi$me: Finished configuration testing, now producing output.$ao

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/Makefile,v 1.114 2013/03/05 15:41:40 tg Exp $
# $MirOS: src/bin/mksh/Makefile,v 1.115 2013/03/24 00:56:19 tg Exp $
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013
@ -55,7 +55,7 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 -DMKSH_DISABLE_DEPRECATED \
-DHAVE_STRLCPY=1 -DHAVE_FLOCK_DECL=1 -DHAVE_REVOKE_DECL=1 \
-DHAVE_SYS_ERRLIST_DECL=1 -DHAVE_SYS_SIGLIST_DECL=1 \
-DHAVE_PERSISTENT_HISTORY=1 -DHAVE_SILENT_IDIVWRAPV=0 \
-DMKSH_BUILD_R=441
-DMKSH_BUILD_R=449
CPPFLAGS+= -D${${PROG:L}_tf:C/(Mir${MAN:E}{0,1}){2}/4/:S/x/mksh_BUILD/:U}
COPTS+= -std=c99 -Wall
.endif

16
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.599 2013/02/24 14:22:41 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.600 2013/03/24 00:56:19 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R44 2013/02/24
@(#)MIRBSD KSH R44 2013/03/23
description:
Check version of shell.
stdin:
@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R44 2013/02/24
@(#)LEGACY KSH R44 2013/03/23
description:
Check version of legacy shell.
stdin:
@ -5658,8 +5658,8 @@ stdin:
expected-stdout:
END
expected-stderr:
+ env false
+ echo END
+ env false
+ echo END
---
name: exit-err-2
description:
@ -5678,9 +5678,9 @@ stdin:
expected-stdout:
END
expected-stderr:
+ env true
+ env false
+ echo END
+ env true
+ env false
+ echo END
---
name: exit-err-3
description:

32
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.116 2013/02/17 05:40:15 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.117 2013/03/24 00:56:22 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@ -138,12 +138,10 @@ execute(struct op * volatile t,
/* Allow option parsing (bizarre, but POSIX) */
timex_hook(t, &up);
ap = (const char **)up;
if (Flag(FXTRACE) && ap[0]) {
if (Flag(FXTRACE)) {
shf_puts(substitute(str_val(global("PS4")), 0),
shl_out);
for (i = 0; ap[i]; i++)
shf_fprintf(shl_out, "%s%c", ap[i],
ap[i + 1] ? ' ' : '\n');
fptreef(shl_out, 0, "%T\n", t);
shf_flush(shl_out);
}
if (ap[0])
@ -645,16 +643,6 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
cp = evalstr(t->vars[i], DOASNTILDE);
e->loc = l_assign;
/* but assign in there as usual */
if (Flag(FXTRACE)) {
if (i == 0)
shf_puts(substitute(str_val(global("PS4")), 0),
shl_out);
shf_fprintf(shl_out, "%s%c", cp,
t->vars[i + 1] ? ' ' : '\n');
if (!t->vars[i + 1])
shf_flush(shl_out);
}
typeset(cp, type_flags, 0, 0, 0);
if (bourne_function_call && !(type_flags & EXPORT))
typeset(cp, LOCAL|LOCAL_COPY|EXPORT, 0, 0, 0);
@ -1298,11 +1286,6 @@ iosetup(struct ioword *iop, struct tbl *tp)
iotmp.name = (iotype == IOHERE) ? NULL : cp;
iotmp.flag |= IONAMEXP;
if (Flag(FXTRACE))
shellf("%s%s\n",
substitute(str_val(global("PS4")), 0),
snptreef(NULL, 32, "%R", &iotmp));
switch (iotype) {
case IOREAD:
flags = O_RDONLY;
@ -1345,8 +1328,11 @@ iosetup(struct ioword *iop, struct tbl *tp)
} else if ((u = check_fd(cp,
X_OK | ((iop->flag & IORDUP) ? R_OK : W_OK),
&emsg)) < 0) {
char *sp;
warningf(true, "%s: %s",
snptreef(NULL, 32, "%R", &iotmp), emsg);
(sp = snptreef(NULL, 32, "%R", &iotmp)), emsg);
afree(sp, ATEMP);
return (-1);
}
if (u == iop->unit)
@ -1395,12 +1381,14 @@ iosetup(struct ioword *iop, struct tbl *tp)
else if (u != iop->unit) {
if (ksh_dup2(u, iop->unit, true) < 0) {
int eno;
char *sp;
eno = errno;
warningf(true, "%s %s %s",
"can't finish (dup) redirection",
snptreef(NULL, 32, "%R", &iotmp),
(sp = snptreef(NULL, 32, "%R", &iotmp)),
cstrerror(eno));
afree(sp, ATEMP);
if (iotype != IODUP)
close(u);
return (-1);

11
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.305 2013/02/19 18:45:20 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.306 2013/03/24 00:56:23 tg Exp $
.\" $OpenBSD: ksh.1,v 1.145 2013/01/17 21:20:25 jmc Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -74,7 +74,7 @@
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
.Dd $Mdocdate: February 19 2013 $
.Dd $Mdocdate: March 24 2013 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
@ -2037,6 +2037,9 @@ Parameter, command, and arithmetic substitutions are performed
before it is printed.
The default is
.Sq +\ \& .
You may want to set it to
.Sq \&[$EPOCHREALTIME]\ \&
instead, to include timestamps.
.It Ev PWD
The current working directory.
May be unset or
@ -4097,7 +4100,7 @@ Mark directories with a trailing
.Ql /
during file name generation.
.It Fl x \*(Ba Fl o Ic xtrace
Print commands and parameter assignments when they are executed, preceded by
Print command trees when they are executed, preceded by
the value of
.Ev PS4 .
.It Fl o Ic bgnice
@ -6335,7 +6338,7 @@ $ /bin/sleep 666 && echo fubar
.Ed
.Pp
This document attempts to describe
.Nm mksh\ R43
.Nm mksh\ R44
and up,
compiled without any options impacting functionality, such as
.Dv MKSH_SMALL ,

6
sh.h
View File

@ -164,9 +164,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.642 2013/03/05 15:41:41 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.643 2013/03/24 00:56:25 tg Exp $");
#endif
#define MKSH_VERSION "R44 2013/02/24"
#define MKSH_VERSION "R44 2013/03/23"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -511,7 +511,7 @@ char *ucstrstr(char *, const char *);
#define mkssert(e) do { } while (/* CONSTCOND */ 0)
#endif
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 441)
#if (!defined(MKSH_BUILDMAKEFILE4BSD) && !defined(MKSH_BUILDSH)) || (MKSH_BUILD_R != 449)
#error Must run Build.sh to compile this.
int
im_sorry_dave(void)

20
tree.c
View File

@ -23,12 +23,12 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.67 2012/12/04 01:10:35 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.68 2013/03/24 00:56:27 tg Exp $");
#define INDENT 8
static void ptree(struct op *, int, struct shf *);
static void pioact(struct shf *, int, struct ioword *);
static void pioact(struct shf *, struct ioword *);
static const char *wdvarput(struct shf *, const char *, int, int);
static void vfptreef(struct shf *, int, const char *, va_list);
static struct ioword **iocopy(struct ioword **, Area *);
@ -214,7 +214,7 @@ ptree(struct op *t, int indent, struct shf *shf)
bool need_nl = false;
while (*ioact != NULL)
pioact(shf, indent, *ioact++);
pioact(shf, *ioact++);
/* Print here documents after everything else... */
ioact = t->ioact;
while (*ioact != NULL) {
@ -244,7 +244,7 @@ ptree(struct op *t, int indent, struct shf *shf)
}
static void
pioact(struct shf *shf, int indent, struct ioword *iop)
pioact(struct shf *shf, struct ioword *iop)
{
int flag = iop->flag;
int type = flag & IOTYPE;
@ -283,9 +283,13 @@ pioact(struct shf *shf, int indent, struct ioword *iop)
wdvarput(shf, iop->delim, 0, WDS_TPUTS);
if (iop->flag & IOHERESTR)
shf_putc(' ', shf);
} else if (iop->name)
fptreef(shf, indent, (iop->flag & IONAMEXP) ? "%s " : "%S ",
iop->name);
} else if (iop->name) {
if (iop->flag & IONAMEXP)
print_value_quoted(shf, iop->name);
else
wdvarput(shf, iop->name, 0, WDS_TPUTS);
shf_putc(' ', shf);
}
prevent_semicolon = false;
}
@ -485,7 +489,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
break;
case 'R':
/* I/O redirection */
pioact(shf, indent, va_arg(va, struct ioword *));
pioact(shf, va_arg(va, struct ioword *));
break;
default:
shf_putc(c, shf);