Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh Include redirections in trace output from "set -x"
details: https://anonhg.NetBSD.org/src/rev/a68be40cd27b
branches: trunk
changeset: 354827:a68be40cd27b
user: kre <kre%NetBSD.org@localhost>
date: Fri Jun 30 23:01:21 2017 +0000
description:
Include redirections in trace output from "set -x"
diffstat:
bin/sh/eval.c | 46 ++++++++++++++++++++++++++++++++----
bin/sh/redir.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
bin/sh/redir.h | 4 ++-
3 files changed, 112 insertions(+), 9 deletions(-)
diffs (218 lines):
diff -r c29657e4b9de -r a68be40cd27b bin/sh/eval.c
--- a/bin/sh/eval.c Fri Jun 30 23:00:40 2017 +0000
+++ b/bin/sh/eval.c Fri Jun 30 23:01:21 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: eval.c,v 1.150 2017/06/19 03:21:31 kre Exp $ */
+/* $NetBSD: eval.c,v 1.151 2017/06/30 23:01:21 kre Exp $ */
/*-
* Copyright (c) 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
#else
-__RCSID("$NetBSD: eval.c,v 1.150 2017/06/19 03:21:31 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.151 2017/06/30 23:01:21 kre Exp $");
#endif
#endif /* not lint */
@@ -276,9 +276,24 @@
break;
case NREDIR:
expredir(n->nredir.redirect);
+ if (xflag && n->nredir.redirect) {
+ union node *rn;
+
+ out2str(expandstr(ps4val(), line_number));
+ out2str("using redirections:");
+ for (rn = n->nredir.redirect; rn; rn = rn->nfile.next)
+ (void) outredir(&errout, rn, ' ');
+ out2str(" do\n");
+ flushout(&errout);
+ }
redirect(n->nredir.redirect, REDIR_PUSH | REDIR_KEEP);
evaltree(n->nredir.n, flags);
popredir();
+ if (xflag && n->nredir.redirect) {
+ out2str(expandstr(ps4val(), line_number));
+ out2str("done\n");
+ flushout(&errout);
+ }
break;
case NSUBSHELL:
evalsubshell(n, flags & ~EV_MORE);
@@ -422,7 +437,7 @@
f |= EV_MORE;
if (xflag) {
- out2str(ps4val());
+ out2str(expandstr(ps4val(), line_number));
out2str("for ");
out2str(n->nfor.var);
out2c('=');
@@ -505,6 +520,16 @@
int backgnd = (n->type == NBACKGND);
expredir(n->nredir.redirect);
+ if (xflag && n->nredir.redirect) {
+ union node *rn;
+
+ out2str(expandstr(ps4val(), line_number));
+ out2str("using redirections:");
+ for (rn = n->nredir.redirect; rn; rn = rn->nfile.next)
+ (void) outredir(&errout, rn, ' ');
+ out2str(" do subshell\n");
+ flushout(&errout);
+ }
INTOFF;
jp = makejob(n, 1);
if (forkshell(jp, n, backgnd ? FORK_BG : FORK_FG) == 0) {
@@ -517,6 +542,11 @@
}
exitstatus = backgnd ? 0 : waitforjob(jp);
INTON;
+ if (!backgnd && xflag && n->nredir.redirect) {
+ out2str(expandstr(ps4val(), line_number));
+ out2str("done subshell\n");
+ flushout(&errout);
+ }
}
@@ -771,8 +801,7 @@
setstackmark(&smark);
back_exitstatus = 0;
- if (cmd != NULL)
- line_number = cmd->ncmd.lineno;
+ line_number = cmd->ncmd.lineno;
arglist.lastp = &arglist.list;
varflag = 1;
@@ -830,7 +859,9 @@
/* Print the command if xflag is set. */
if (xflag) {
char sep = 0;
- out2str(ps4val());
+ union node *rn;
+
+ out2str(expandstr(ps4val(), line_number));
for (sp = varlist.list ; sp ; sp = sp->next) {
char *p;
@@ -859,6 +890,9 @@
out2shstr(sp->text);
sep = ' ';
}
+ for (rn = cmd->ncmd.redirect; rn; rn = rn->nfile.next)
+ if (outredir(&errout, rn, sep))
+ sep = ' ';
outc('\n', &errout);
flushout(&errout);
}
diff -r c29657e4b9de -r a68be40cd27b bin/sh/redir.c
--- a/bin/sh/redir.c Fri Jun 30 23:00:40 2017 +0000
+++ b/bin/sh/redir.c Fri Jun 30 23:01:21 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: redir.c,v 1.57 2017/05/29 22:21:00 kre Exp $ */
+/* $NetBSD: redir.c,v 1.58 2017/06/30 23:01:21 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: redir.c,v 1.57 2017/05/29 22:21:00 kre Exp $");
+__RCSID("$NetBSD: redir.c,v 1.58 2017/06/30 23:01:21 kre Exp $");
#endif
#endif /* not lint */
@@ -878,3 +878,70 @@
}
return 0;
}
+
+#undef MAX /* in case we inherited them from somewhere */
+#undef MIN
+
+#define MIN(a,b) (/*CONSTCOND*/((a)<=(b)) ? (a) : (b))
+#define MAX(a,b) (/*CONSTCOND*/((a)>=(b)) ? (a) : (b))
+
+ /* now make the compiler work for us... */
+#define MIN_REDIR MIN(MIN(MIN(MIN(NTO,NFROM), MIN(NTOFD,NFROMFD)), \
+ MIN(MIN(NCLOBBER,NAPPEND), MIN(NHERE,NXHERE))), NFROMTO)
+#define MAX_REDIR MAX(MAX(MAX(MAX(NTO,NFROM), MAX(NTOFD,NFROMFD)), \
+ MAX(MAX(NCLOBBER,NAPPEND), MAX(NHERE,NXHERE))), NFROMTO)
+
+static const char *redir_sym[MAX_REDIR - MIN_REDIR + 1] = {
+ [NTO - MIN_REDIR]= ">",
+ [NFROM - MIN_REDIR]= "<",
+ [NTOFD - MIN_REDIR]= ">&",
+ [NFROMFD - MIN_REDIR]= "<&",
+ [NCLOBBER - MIN_REDIR]= ">|",
+ [NAPPEND - MIN_REDIR]= ">>",
+ [NHERE - MIN_REDIR]= "<<",
+ [NXHERE - MIN_REDIR]= "<<",
+ [NFROMTO - MIN_REDIR]= "<>",
+};
+
+int
+outredir(struct output *out, union node *n, int sep)
+{
+ if (n == NULL)
+ return 0;
+ if (n->type < MIN_REDIR || n->type > MAX_REDIR ||
+ redir_sym[n->type - MIN_REDIR] == NULL)
+ return 0;
+
+ if (sep)
+ outc(sep, out);
+
+ /*
+ * ugly, but all redir node types have "fd" in same slot...
+ * (and code other places assumes it as well)
+ */
+ if ((redir_sym[n->type - MIN_REDIR][0] == '<' && n->nfile.fd != 0) ||
+ (redir_sym[n->type - MIN_REDIR][0] == '>' && n->nfile.fd != 1))
+ outfmt(out, "%d", n->nfile.fd);
+
+ outstr(redir_sym[n->type - MIN_REDIR], out);
+
+ switch (n->type) {
+ case NHERE:
+ outstr("'...'", out);
+ break;
+ case NXHERE:
+ outstr("...", out);
+ break;
+ case NTOFD:
+ case NFROMFD:
+ if (n->ndup.dupfd < 0)
+ outc('-', out);
+ else
+ outfmt(out, "%d", n->ndup.dupfd);
+ break;
+ default:
+ outstr(n->nfile.expfname, out);
+ break;
+ }
+ return 1;
+}
diff -r c29657e4b9de -r a68be40cd27b bin/sh/redir.h
--- a/bin/sh/redir.h Fri Jun 30 23:00:40 2017 +0000
+++ b/bin/sh/redir.h Fri Jun 30 23:01:21 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: redir.h,v 1.23 2017/04/29 15:14:28 kre Exp $ */
+/* $NetBSD: redir.h,v 1.24 2017/06/30 23:01:21 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -49,5 +49,7 @@
int to_upper_fd(int);
void register_sh_fd(int, void (*)(int, int));
void sh_close(int);
+struct output;
+int outredir(struct output *, union node *, int);
int max_user_fd; /* highest fd used by user */
Home |
Main Index |
Thread Index |
Old Index