Module Name: src Committed By: kre Date: Sun Jul 22 20:38:06 UTC 2018
Modified Files: src/bin/sh: expand.c shell.h show.c trap.c Log Message: DEBUG mode only change (ie: no effect to any normal shell). Add tracing of pattern matching (aid in debugging various issues.) To generate a diff of this commit: cvs rdiff -u -r1.124 -r1.125 src/bin/sh/expand.c cvs rdiff -u -r1.25 -r1.26 src/bin/sh/shell.h cvs rdiff -u -r1.47 -r1.48 src/bin/sh/show.c cvs rdiff -u -r1.41 -r1.42 src/bin/sh/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/expand.c diff -u src/bin/sh/expand.c:1.124 src/bin/sh/expand.c:1.125 --- src/bin/sh/expand.c:1.124 Fri Jul 20 22:47:26 2018 +++ src/bin/sh/expand.c Sun Jul 22 20:38:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: expand.c,v 1.124 2018/07/20 22:47:26 kre Exp $ */ +/* $NetBSD: expand.c,v 1.125 2018/07/22 20:38:06 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #else -__RCSID("$NetBSD: expand.c,v 1.124 2018/07/20 22:47:26 kre Exp $"); +__RCSID("$NetBSD: expand.c,v 1.125 2018/07/22 20:38:06 kre Exp $"); #endif #endif /* not lint */ @@ -1457,6 +1457,7 @@ expmeta(char *enddir, char *name) int atend; int matchdot; + CTRACE(DBG_EXPAND|DBG_MATCH, ("expmeta(\"%s\")\n", name)); metaflag = 0; start = name; for (p = name ; ; p++) { @@ -1697,6 +1698,8 @@ patmatch(const char *pattern, const char char c; wchar_t wc, wc2; + VTRACE(DBG_MATCH, ("patmatch(P=\"%s\", W=\"%s\"%s): ", + pattern, string, squoted ? ", SQ" : "")); p = pattern; q = string; bt_p = NULL; @@ -1706,6 +1709,7 @@ patmatch(const char *pattern, const char case '\0': if (*q != '\0') goto backtrack; + VTRACE(DBG_MATCH, ("match\n")); return 1; case CTLESC: if (squoted && *q == CTLESC) @@ -1719,8 +1723,10 @@ patmatch(const char *pattern, const char case '?': if (squoted && *q == CTLESC) q++; - if (*q++ == '\0') + if (*q++ == '\0') { + VTRACE(DBG_MATCH, ("?fail\n")); return 0; + } break; case '*': c = *p; @@ -1732,8 +1738,10 @@ patmatch(const char *pattern, const char if (squoted && *q == CTLESC && q[1] == c) break; - if (*q == '\0') + if (*q == '\0') { + VTRACE(DBG_MATCH, ("*fail\n")); return 0; + } if (squoted && *q == CTLESC) q++; q++; @@ -1786,8 +1794,10 @@ patmatch(const char *pattern, const char p++; } found = 0; - if (*q == '\0') + if (*q == '\0') { + VTRACE(DBG_MATCH, ("[]fail\n")); return 0; + } chr = (unsigned char)*q++; c = *p++; do { @@ -1837,10 +1847,14 @@ backtrack: * of the string), go back to the last '*' seen and * have it match one additional character. */ - if (bt_p == NULL) + if (bt_p == NULL) { + VTRACE(DBG_MATCH, ("BTP fail\n")); return 0; - if (*bt_q == '\0') + } + if (*bt_q == '\0') { + VTRACE(DBG_MATCH, ("BTQ fail\n")); return 0; + } bt_q++; p = bt_p; q = bt_q; @@ -1953,6 +1967,8 @@ casematch(union node *pattern, char *val int result; char *p; + CTRACE(DBG_MATCH, ("casematch(P=\"%s\", W=\"%s\")\n", + pattern->narg.text, val)); setstackmark(&smark); argbackq = pattern->narg.backquote; STARTSTACKSTR(expdest); Index: src/bin/sh/shell.h diff -u src/bin/sh/shell.h:1.25 src/bin/sh/shell.h:1.26 --- src/bin/sh/shell.h:1.25 Wed Jul 26 03:44:43 2017 +++ src/bin/sh/shell.h Sun Jul 22 20:38:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: shell.h,v 1.25 2017/07/26 03:44:43 kre Exp $ */ +/* $NetBSD: shell.h,v 1.26 2018/07/22 20:38:06 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -189,10 +189,11 @@ extern int ShNest; #define DBG_ARITH (1LL << 15) /* a */ #define DBG_HISTORY (1LL << 16) /* h */ #define DBG_SIG (1LL << 17) /* s */ +#define DBG_MATCH (1LL << 18) /* g (glob) */ /* * reserved extras: b=builtins l=alias - * still free: d g k n q u y + * still free: d k n q u y */ /* use VTRACE(DBG_ALWAYS, (...)) to test this one */ Index: src/bin/sh/show.c diff -u src/bin/sh/show.c:1.47 src/bin/sh/show.c:1.48 --- src/bin/sh/show.c:1.47 Fri Jun 30 23:00:40 2017 +++ src/bin/sh/show.c Sun Jul 22 20:38:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: show.c,v 1.47 2017/06/30 23:00:40 kre Exp $ */ +/* $NetBSD: show.c,v 1.48 2018/07/22 20:38:06 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)show.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: show.c,v 1.47 2017/06/30 23:00:40 kre Exp $"); +__RCSID("$NetBSD: show.c,v 1.48 2018/07/22 20:38:06 kre Exp $"); #endif #endif /* not lint */ @@ -1070,6 +1070,7 @@ static struct debug_flag { { 'c', DBG_CMDS }, /* command searching, ... */ { 'e', DBG_EVAL }, /* evaluation of the parse tree */ { 'f', DBG_REDIR }, /* file descriptors & redirections */ + { 'g', DBG_MATCH }, /* pattern matching (glob) */ { 'h', DBG_HISTORY }, /* history & cmd line editing */ { 'i', DBG_INPUT }, /* shell input routines */ { 'j', DBG_JOBS }, /* job control, structures */ Index: src/bin/sh/trap.c diff -u src/bin/sh/trap.c:1.41 src/bin/sh/trap.c:1.42 --- src/bin/sh/trap.c:1.41 Wed Jul 5 19:47:11 2017 +++ src/bin/sh/trap.c Sun Jul 22 20:38:06 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: trap.c,v 1.41 2017/07/05 19:47:11 kre Exp $ */ +/* $NetBSD: trap.c,v 1.42 2018/07/22 20:38:06 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)trap.c 8.5 (Berkeley) 6/5/95"; #else -__RCSID("$NetBSD: trap.c,v 1.41 2017/07/05 19:47:11 kre Exp $"); +__RCSID("$NetBSD: trap.c,v 1.42 2018/07/22 20:38:06 kre Exp $"); #endif #endif /* not lint */ @@ -523,9 +523,11 @@ dotrap(void) savestatus=exitstatus; CTRACE(DBG_TRAP|DBG_SIG, ("dotrap %d: \"%s\"\n", i, trap[i] ? trap[i] : "-NULL-")); - tr = savestr(trap[i]); /* trap code may free trap[i] */ - evalstring(tr, 0); - ckfree(tr); + if ((tr = trap[i]) != NULL) { + tr = savestr(tr); /* trap code may free trap[i] */ + evalstring(tr, 0); + ckfree(tr); + } exitstatus=savestatus; } }