Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): make debugging code shorter



details:   https://anonhg.NetBSD.org/src/rev/ab515ff83254
branches:  trunk
changeset: 955421:ab515ff83254
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Sep 28 20:46:11 2020 +0000

description:
make(1): make debugging code shorter

diffstat:

 usr.bin/make/arch.c   |   30 +++---------
 usr.bin/make/compat.c |   20 +++-----
 usr.bin/make/cond.c   |   20 ++------
 usr.bin/make/dir.c    |   16 ++----
 usr.bin/make/for.c    |   13 ++---
 usr.bin/make/hash.c   |   22 +++------
 usr.bin/make/job.c    |   68 +++++++++--------------------
 usr.bin/make/main.c   |   10 +--
 usr.bin/make/make.c   |  115 ++++++++++++++++---------------------------------
 usr.bin/make/make.h   |   26 ++++++++++-
 usr.bin/make/meta.c   |   88 ++++++++++++++-----------------------
 usr.bin/make/parse.c  |   27 ++++-------
 usr.bin/make/suff.c   |   19 ++-----
 13 files changed, 178 insertions(+), 296 deletions(-)

diffs (truncated from 1227 to 300 lines):

diff -r a223f7b11d8f -r ab515ff83254 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Mon Sep 28 18:51:34 2020 +0000
+++ b/usr.bin/make/arch.c       Mon Sep 28 20:46:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.124 2020/09/27 21:35:16 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.125 2020/09/28 20:46:11 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -134,7 +134,7 @@
 #include    "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.124 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.125 2020/09/28 20:46:11 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -676,9 +676,7 @@
        strncmp(name, ARLONGNAMES2, sizeof(ARLONGNAMES2) - 1) == 0) {
 
        if (ar->fnametab != NULL) {
-           if (DEBUG(ARCH)) {
-               fprintf(debug_file, "Attempted to redefine an SVR4 name table\n");
-           }
+           DEBUG0(ARCH, "Attempted to redefine an SVR4 name table\n");
            return -1;
        }
 
@@ -690,9 +688,7 @@
        ar->fnamesize = size;
 
        if (fread(ar->fnametab, size, 1, arch) != 1) {
-           if (DEBUG(ARCH)) {
-               fprintf(debug_file, "Reading an SVR4 name table failed\n");
-           }
+           DEBUG0(ARCH, "Reading an SVR4 name table failed\n");
            return -1;
        }
        eptr = ar->fnametab + size;
@@ -701,10 +697,8 @@
                entry++;
                *ptr = '\0';
            }
-       if (DEBUG(ARCH)) {
-           fprintf(debug_file, "Found svr4 archive name table with %lu entries\n",
-                   (unsigned long)entry);
-       }
+       DEBUG1(ARCH, "Found svr4 archive name table with %lu entries\n",
+              (unsigned long)entry);
        return 0;
     }
 
@@ -713,22 +707,16 @@
 
     entry = (size_t)strtol(&name[1], &eptr, 0);
     if ((*eptr != ' ' && *eptr != '\0') || eptr == &name[1]) {
-       if (DEBUG(ARCH)) {
-           fprintf(debug_file, "Could not parse SVR4 name %s\n", name);
-       }
+        DEBUG1(ARCH, "Could not parse SVR4 name %s\n", name);
        return 2;
     }
     if (entry >= ar->fnamesize) {
-       if (DEBUG(ARCH)) {
-           fprintf(debug_file, "SVR4 entry offset %s is greater than %lu\n",
+       DEBUG2(ARCH, "SVR4 entry offset %s is greater than %lu\n",
                   name, (unsigned long)ar->fnamesize);
-       }
        return 2;
     }
 
-    if (DEBUG(ARCH)) {
-       fprintf(debug_file, "Replaced %s with %s\n", name, &ar->fnametab[entry]);
-    }
+    DEBUG2(ARCH, "Replaced %s with %s\n", name, &ar->fnametab[entry]);
 
     snprintf(name, MAXPATHLEN + 1, "%s", &ar->fnametab[entry]);
     return 1;
diff -r a223f7b11d8f -r ab515ff83254 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Mon Sep 28 18:51:34 2020 +0000
+++ b/usr.bin/make/compat.c     Mon Sep 28 20:46:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.156 2020/09/27 21:35:16 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.157 2020/09/28 20:46:11 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -99,7 +99,7 @@
 #include    "pathnames.h"
 
 /*     "@(#)compat.c   8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.156 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.157 2020/09/28 20:46:11 rillig Exp $");
 
 static GNode       *curTarg = NULL;
 static void CompatInterrupt(int);
@@ -301,8 +301,7 @@
     if (!doIt && NoExecute(gn)) {
        return 0;
     }
-    if (DEBUG(JOB))
-       fprintf(debug_file, "Execute: '%s'\n", cmd);
+    DEBUG1(JOB, "Execute: '%s'\n", cmd);
 
     if (useShell) {
        /*
@@ -532,18 +531,13 @@
         * exist and when we were modified last. The criteria for datedness
         * are defined by the Make_OODate function.
         */
-       if (DEBUG(MAKE)) {
-           fprintf(debug_file, "Examining %s...", gn->name);
-       }
+       DEBUG1(MAKE, "Examining %s...", gn->name);
        if (! Make_OODate(gn)) {
            gn->made = UPTODATE;
-           if (DEBUG(MAKE)) {
-               fprintf(debug_file, "up-to-date.\n");
-           }
+           DEBUG0(MAKE, "up-to-date.\n");
            goto cohorts;
-       } else if (DEBUG(MAKE)) {
-           fprintf(debug_file, "out-of-date.\n");
-       }
+       } else
+           DEBUG0(MAKE, "out-of-date.\n");
 
        /*
         * If the user is just seeing if something is out-of-date, exit now
diff -r a223f7b11d8f -r ab515ff83254 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Mon Sep 28 18:51:34 2020 +0000
+++ b/usr.bin/make/cond.c       Mon Sep 28 20:46:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.153 2020/09/27 21:35:16 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.154 2020/09/28 20:46:11 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.153 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.154 2020/09/28 20:46:11 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -312,10 +312,7 @@
     char *path;
 
     path = Dir_FindFile(arg, dirSearchPath);
-    if (DEBUG(COND)) {
-       fprintf(debug_file, "exists(%s) result is \"%s\"\n",
-               arg, path ? path : "");
-    }
+    DEBUG2(COND, "exists(%s) result is \"%s\"\n", arg, path ? path : "");
     if (path != NULL) {
        result = TRUE;
        free(path);
@@ -549,8 +546,7 @@
 static Token
 EvalCompareNum(double lhs, const char *op, double rhs)
 {
-    if (DEBUG(COND))
-       fprintf(debug_file, "lhs = %f, rhs = %f, op = %.2s\n", lhs, rhs, op);
+    DEBUG3(COND, "lhs = %f, rhs = %f, op = %.2s\n", lhs, rhs, op);
 
     switch (op[0]) {
     case '!':
@@ -585,10 +581,7 @@
        return TOK_ERROR;
     }
 
-    if (DEBUG(COND)) {
-       fprintf(debug_file, "lhs = \"%s\", rhs = \"%s\", op = %.2s\n",
-               lhs, rhs, op);
-    }
+    DEBUG3(COND, "lhs = \"%s\", rhs = \"%s\", op = %.2s\n", lhs, rhs, op);
     return (*op == '=') == (strcmp(lhs, rhs) == 0);
 }
 
@@ -987,8 +980,7 @@
 {
     Token res;
 
-    if (DEBUG(COND))
-       fprintf(debug_file, "CondParser_Eval: %s\n", par->p);
+    DEBUG1(COND, "CondParser_Eval: %s\n", par->p);
 
     res = CondParser_Expr(par, TRUE);
     if (res != TOK_FALSE && res != TOK_TRUE)
diff -r a223f7b11d8f -r ab515ff83254 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Mon Sep 28 18:51:34 2020 +0000
+++ b/usr.bin/make/dir.c        Mon Sep 28 20:46:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.150 2020/09/27 22:17:07 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.151 2020/09/28 20:46:11 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -136,17 +136,11 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.150 2020/09/27 22:17:07 rillig Exp $");
-
-#define DIR_DEBUG0(fmt) \
-    if (!DEBUG(DIR)) (void) 0; else fprintf(debug_file, fmt)
+MAKE_RCSID("$NetBSD: dir.c,v 1.151 2020/09/28 20:46:11 rillig Exp $");
 
-#define DIR_DEBUG1(fmt, arg1) \
-    if (!DEBUG(DIR)) (void) 0; else fprintf(debug_file, fmt, arg1)
-
-#define DIR_DEBUG2(fmt, arg1, arg2) \
-    if (!DEBUG(DIR)) (void) 0; else fprintf(debug_file, fmt, arg1, arg2)
-
+#define DIR_DEBUG0(text) DEBUG0(DIR, text)
+#define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
+#define DIR_DEBUG2(fmt, arg1, arg2) DEBUG2(DIR, fmt, arg1, arg2)
 
 /*
  *     A search path consists of a list of CachedDir structures. A CachedDir
diff -r a223f7b11d8f -r ab515ff83254 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Mon Sep 28 18:51:34 2020 +0000
+++ b/usr.bin/make/for.c        Mon Sep 28 20:46:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.88 2020/09/27 21:35:16 rillig Exp $  */
+/*     $NetBSD: for.c,v 1.89 2020/09/28 20:46:11 rillig Exp $  */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -61,7 +61,7 @@
 #include    "strlist.h"
 
 /*     "@(#)for.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: for.c,v 1.88 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.89 2020/09/28 20:46:11 rillig Exp $");
 
 typedef enum {
     FOR_SUB_ESCAPE_CHAR = 0x0001,
@@ -272,14 +272,12 @@
            continue;
 
        if (strncmp(ptr, "endfor", 6) == 0 && (ch_isspace(ptr[6]) || !ptr[6])) {
-           if (DEBUG(FOR))
-               (void)fprintf(debug_file, "For: end for %d\n", forLevel);
+           DEBUG1(FOR, "For: end for %d\n", forLevel);
            if (--forLevel <= 0)
                return FALSE;
        } else if (strncmp(ptr, "for", 3) == 0 && ch_isspace(ptr[3])) {
            forLevel++;
-           if (DEBUG(FOR))
-               (void)fprintf(debug_file, "For: new loop %d\n", forLevel);
+           DEBUG1(FOR, "For: new loop %d\n", forLevel);
        }
     }
 
@@ -436,8 +434,7 @@
 
     *ret_len = Buf_Len(&cmds);
     cmds_str = Buf_Destroy(&cmds, FALSE);
-    if (DEBUG(FOR))
-       (void)fprintf(debug_file, "For: loop body:\n%s", cmds_str);
+    DEBUG1(FOR, "For: loop body:\n%s", cmds_str);
 
     arg->sub_next += strlist_num(&arg->vars);
 
diff -r a223f7b11d8f -r ab515ff83254 usr.bin/make/hash.c
--- a/usr.bin/make/hash.c       Mon Sep 28 18:51:34 2020 +0000
+++ b/usr.bin/make/hash.c       Mon Sep 28 20:46:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.34 2020/09/27 21:35:16 rillig Exp $ */
+/*     $NetBSD: hash.c,v 1.35 2020/09/28 20:46:11 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -79,7 +79,7 @@
 #include "make.h"
 
 /*     "@(#)hash.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: hash.c,v 1.34 2020/09/27 21:35:16 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.35 2020/09/28 20:46:11 rillig Exp $");
 
 /*
  * Forward references to local procedures that are used before they're
@@ -174,9 +174,7 @@
        p = key;
        chainlen = 0;
 #ifdef DEBUG_HASH_LOOKUP
-       if (DEBUG(HASH))
-               fprintf(debug_file, "%s: %p h=%x key=%s\n", __func__,
-                   t, h, key);
+       DEBUG4(HASH, "%s: %p h=%x key=%s\n", __func__, t, h, key);
 #endif
        for (e = t->buckets[h & t->bucketsMask]; e != NULL; e = e->next) {
                chainlen++;
@@ -223,9 +221,7 @@
        p = key;
        chainlen = 0;



Home | Main Index | Thread Index | Old Index