Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh DEBUG mode only change (ie: no effect to any normal s...



details:   https://anonhg.NetBSD.org/src/rev/d5b21e07200c
branches:  trunk
changeset: 324240:d5b21e07200c
user:      kre <kre%NetBSD.org@localhost>
date:      Sun Jul 22 20:38:06 2018 +0000

description:
DEBUG mode only change (ie: no effect to any normal shell).

Add tracing of pattern matching (aid in debugging various issues.)

diffstat:

 bin/sh/expand.c |  30 +++++++++++++++++++++++-------
 bin/sh/shell.h  |   5 +++--
 bin/sh/show.c   |   5 +++--
 bin/sh/trap.c   |  12 +++++++-----
 4 files changed, 36 insertions(+), 16 deletions(-)

diffs (186 lines):

diff -r 502b11412e16 -r d5b21e07200c bin/sh/expand.c
--- a/bin/sh/expand.c   Sun Jul 22 20:37:57 2018 +0000
+++ b/bin/sh/expand.c   Sun Jul 22 20:38:06 2018 +0000
@@ -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 @@
        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 @@
        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 @@
                case '\0':
                        if (*q != '\0')
                                goto backtrack;
+                       VTRACE(DBG_MATCH, ("match\n"));
                        return 1;
                case CTLESC:
                        if (squoted && *q == CTLESC)
@@ -1719,8 +1723,10 @@
                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 @@
                                        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 @@
                                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 @@
                         * 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 @@
        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);
diff -r 502b11412e16 -r d5b21e07200c bin/sh/shell.h
--- a/bin/sh/shell.h    Sun Jul 22 20:37:57 2018 +0000
+++ b/bin/sh/shell.h    Sun Jul 22 20:38:06 2018 +0000
@@ -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 @@
 #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 */
diff -r 502b11412e16 -r d5b21e07200c bin/sh/show.c
--- a/bin/sh/show.c     Sun Jul 22 20:37:57 2018 +0000
+++ b/bin/sh/show.c     Sun Jul 22 20:38:06 2018 +0000
@@ -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 @@
        { '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 */
diff -r 502b11412e16 -r d5b21e07200c bin/sh/trap.c
--- a/bin/sh/trap.c     Sun Jul 22 20:37:57 2018 +0000
+++ b/bin/sh/trap.c     Sun Jul 22 20:38:06 2018 +0000
@@ -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 @@
                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;
        }
 }



Home | Main Index | Thread Index | Old Index