Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/sh NFCI - DEBUG mode only change.
details: https://anonhg.NetBSD.org/src/rev/c22d58ca4687
branches: trunk
changeset: 996174:c22d58ca4687
user: kre <kre%NetBSD.org@localhost>
date: Tue Jan 22 13:48:28 2019 +0000
description:
NFCI - DEBUG mode only change.
Add tracing of lexical analyser operations. This is deliberately
kept out of the normal "all on" set as it makes a *lot* of noise
when enabled (especially in verbose mode) - but when needed, it
helps (evidence for which is coming soon).
As usual, no doc, you need the sources (and of course, a specially
built sh to even be able to enable it.)
diffstat:
bin/sh/parser.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
bin/sh/shell.h | 7 +-
bin/sh/show.c | 7 +-
3 files changed, 178 insertions(+), 17 deletions(-)
diffs (truncated from 756 to 300 lines):
diff -r 62b274364f91 -r c22d58ca4687 bin/sh/parser.c
--- a/bin/sh/parser.c Tue Jan 22 12:45:25 2019 +0000
+++ b/bin/sh/parser.c Tue Jan 22 13:48:28 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parser.c,v 1.162 2019/01/21 14:24:44 kre Exp $ */
+/* $NetBSD: parser.c,v 1.163 2019/01/22 13:48:28 kre Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95";
#else
-__RCSID("$NetBSD: parser.c,v 1.162 2019/01/21 14:24:44 kre Exp $");
+__RCSID("$NetBSD: parser.c,v 1.163 2019/01/22 13:48:28 kre Exp $");
#endif
#endif /* not lint */
@@ -63,6 +63,9 @@
#ifndef SMALL
#include "myhistedit.h"
#endif
+#ifdef DEBUG
+#include "nodenames.h"
+#endif
/*
* Shell command parser.
@@ -1072,6 +1075,9 @@
if (tokpushback) {
tokpushback = 0;
+ CTRACE(DBG_LEXER,
+ ("xxreadtoken() returns %s (%d) again\n",
+ tokname[lasttoken], lasttoken));
return lasttoken;
}
if (needprompt) {
@@ -1082,64 +1088,92 @@
startlinno = plinno;
for (;;) { /* until token or start of word found */
c = pgetc_macro();
+ CTRACE(DBG_LEXER, ("xxreadtoken() sees '%c' (%#.2x) ",
+ c&0xFF, c&0x1FF));
switch (c) {
case ' ': case '\t': case PFAKE:
+ CTRACE(DBG_LEXER, (" ignored\n"));
continue;
case '#':
while ((c = pgetc()) != '\n' && c != PEOF)
continue;
+ CTRACE(DBG_LEXER,
+ ("skipped comment to (not incl) \\n\n"));
pungetc();
continue;
case '\n':
plinno++;
+ CTRACE(DBG_LEXER, ("newline now @%d\n", plinno));
needprompt = doprompt;
RETURN(TNL);
case PEOF:
+ CTRACE(DBG_LEXER, ("EOF -> TEOF (return)\n"));
RETURN(TEOF);
case '&':
- if (pgetc_linecont() == '&')
+ if (pgetc_linecont() == '&') {
+ CTRACE(DBG_LEXER,
+ ("and another -> TAND (return)\n"));
RETURN(TAND);
+ }
pungetc();
+ CTRACE(DBG_LEXER, (" -> TBACKGND (return)\n"));
RETURN(TBACKGND);
case '|':
- if (pgetc_linecont() == '|')
+ if (pgetc_linecont() == '|') {
+ CTRACE(DBG_LEXER,
+ ("and another -> TOR (return)\n"));
RETURN(TOR);
+ }
pungetc();
+ CTRACE(DBG_LEXER, (" -> TPIPE (return)\n"));
RETURN(TPIPE);
case ';':
switch (pgetc_linecont()) {
case ';':
+ CTRACE(DBG_LEXER,
+ ("and another -> TENDCASE (return)\n"));
RETURN(TENDCASE);
case '&':
+ CTRACE(DBG_LEXER,
+ ("and '&' -> TCASEFALL (return)\n"));
RETURN(TCASEFALL);
default:
pungetc();
+ CTRACE(DBG_LEXER, (" -> TSEMI (return)\n"));
RETURN(TSEMI);
}
case '(':
+ CTRACE(DBG_LEXER, (" -> TLP (return)\n"));
RETURN(TLP);
case ')':
+ CTRACE(DBG_LEXER, (" -> TRP (return)\n"));
RETURN(TRP);
case '\\':
switch (pgetc()) {
case '\n':
startlinno = ++plinno;
+ CTRACE(DBG_LEXER, ("\\\n ignored, now @%d\n",
+ plinno));
if (doprompt)
setprompt(2);
else
setprompt(0);
continue;
case PEOF:
+ CTRACE(DBG_LEXER,
+ ("then EOF -> TEOF (return) '\\' dropped\n"));
RETURN(TEOF);
default:
+ CTRACE(DBG_LEXER, ("not \\\n or EOF: "));
pungetc();
break;
}
/* FALLTHROUGH */
default:
+ CTRACE(DBG_LEXER, ("getting a word\n"));
return readtoken1(c, BASESYNTAX, 0);
}
}
@@ -1359,6 +1393,8 @@
cleanup_state_stack(stack);
parsebackquote = 0;
handler = savehandler;
+ CTRACE(DBG_LEXER, ("parsebackq() err (%d), unwinding\n",
+ exception));
longjmp(handler->loc, 1);
}
INTOFF;
@@ -1380,7 +1416,8 @@
char *pstr;
int line1 = plinno;
- VTRACE(DBG_PARSE, ("parsebackq: repackaging `` as $( )"));
+ VTRACE(DBG_PARSE|DBG_LEXER,
+ ("parsebackq: repackaging `` as $( )"));
/*
* Because the entire `...` is read here, we don't
* need to bother the state stack. That will be used
@@ -1388,7 +1425,7 @@
*/
STARTSTACKSTR(out);
#ifdef DEBUG
- for (psavelen = 0;;psavelen++) {
+ for (psavelen = 0;;psavelen++) { /* } */
#else
for (;;) {
#endif
@@ -1397,44 +1434,58 @@
needprompt = 0;
}
pc = pgetc();
+ VTRACE(DBG_LEXER,
+ ("parsebackq() got '%c'(%#.2x) in `` %s", pc&0xFF,
+ pc&0x1FF, pc == '`' ? "terminator\n" : ""));
if (pc == '`')
break;
switch (pc) {
case '\\':
pc = pgetc();
+ VTRACE(DBG_LEXER, ("then '%c'(%#.2x) ",
+ pc&0xFF, pc&0x1FF));
#ifdef DEBUG
psavelen++;
#endif
if (pc == '\n') { /* keep \ \n for later */
plinno++;
+ VTRACE(DBG_LEXER, ("@%d ", plinno));
needprompt = doprompt;
}
if (pc != '\\' && pc != '`' && pc != '$'
- && (!ISDBLQUOTE() || pc != '"'))
+ && (!ISDBLQUOTE() || pc != '"')) {
+ VTRACE(DBG_LEXER, ("keep '\\' "));
STPUTC('\\', out);
+ }
break;
case '\n':
plinno++;
+ VTRACE(DBG_LEXER, ("@%d ", plinno));
needprompt = doprompt;
break;
case PEOF:
startlinno = line1;
+ VTRACE(DBG_LEXER, ("EOF\n", plinno));
synerror("EOF in backquote substitution");
break;
default:
break;
}
+ VTRACE(DBG_LEXER, (".\n", plinno));
STPUTC(pc, out);
}
STPUTC('\0', out);
- VTRACE(DBG_PARSE, (" read %d", psavelen));
+ VTRACE(DBG_LEXER, ("parsebackq() ``:"));
+ VTRACE(DBG_PARSE|DBG_LEXER, (" read %d", psavelen));
psavelen = out - stackblock();
- VTRACE(DBG_PARSE, (" produced %d\n", psavelen));
+ VTRACE(DBG_PARSE|DBG_LEXER, (" produced %d\n", psavelen));
if (psavelen > 0) {
pstr = grabstackstr(out);
+ CTRACE(DBG_LEXER,
+ ("parsebackq() reprocessing as $(%s)\n", pstr));
setinputstring(pstr, 1, line1);
}
}
@@ -1452,7 +1503,10 @@
saveprompt = 0;
lno = -plinno;
+ CTRACE(DBG_LEXER, ("parsebackq() parsing embedded command list\n"));
n = list(0);
+ CTRACE(DBG_LEXER, ("parsebackq() parsed $() (%d -> %d)\n", -lno,
+ lno + plinno));
lno += plinno;
if (oldstyle) {
@@ -1468,6 +1522,7 @@
* Start reading from old file again, ignoring any pushed back
* tokens left from the backquote parsing
*/
+ CTRACE(DBG_LEXER, ("parsebackq() back to previous input\n"));
popfile();
tokpushback = 0;
}
@@ -1514,10 +1569,12 @@
fd = (*out == '\0') ? -1 : number(out);
np = stalloc(sizeof(struct nfile));
+ VTRACE(DBG_LEXER, ("parseredir after '%s%c' ", out, c));
if (c == '>') {
if (fd < 0)
fd = 1;
c = pgetc_linecont();
+ VTRACE(DBG_LEXER, ("is '%c'(%#.2x) ", c&0xFF, c&0x1FF));
if (c == '>')
np->type = NAPPEND;
else if (c == '|')
@@ -1526,12 +1583,15 @@
np->type = NTOFD;
else {
np->type = NTO;
+ VTRACE(DBG_LEXER, ("unwanted ", c));
pungetc();
}
} else { /* c == '<' */
if (fd < 0)
fd = 0;
- switch (c = pgetc_linecont()) {
+ c = pgetc_linecont();
+ VTRACE(DBG_LEXER, ("is '%c'(%#.2x) ", c&0xFF, c&0x1FF));
+ switch (c) {
case '<':
if (sizeof (struct nfile) != sizeof (struct nhere)) {
np = stalloc(sizeof(struct nhere));
@@ -1542,6 +1602,8 @@
heredoc->here = np;
heredoc->startline = plinno;
if ((c = pgetc_linecont()) == '-') {
+ CTRACE(DBG_LEXER, ("and '%c'(%#.2x) ",
+ c & 0xFF, c & 0x1FF));
heredoc->striptabs = 1;
} else {
heredoc->striptabs = 0;
@@ -1559,12 +1621,16 @@
default:
np->type = NFROM;
+ VTRACE(DBG_LEXER, ("unwanted('%c'0#.2x)", c&0xFF,
+ c&0x1FF));
pungetc();
break;
}
}
np->nfile.fd = fd;
+ VTRACE(DBG_LEXER, (" ->%"PRIdsNT" fd=%d\n", NODETYPENAME(np->type),fd));
+
redirnode = np; /* this is the "value" of TRENODE */
}
@@ -1579,12 +1645,14 @@
unsigned int v;
Home |
Main Index |
Thread Index |
Old Index