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 debug logging simpler



details:   https://anonhg.NetBSD.org/src/rev/a235706ff093
branches:  trunk
changeset: 1014684:a235706ff093
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Sep 28 22:23:35 2020 +0000

description:
make(1): make debug logging simpler

This avoids referring to the debug_file variable in many places where
this implementation detail is not necessary.

diffstat:

 usr.bin/make/arch.c   |  12 ++++----
 usr.bin/make/compat.c |  14 +++++-----
 usr.bin/make/dir.c    |  25 +++++++++----------
 usr.bin/make/job.c    |  30 ++++++++++------------
 usr.bin/make/make.c   |  61 +++++++++++++++++++++++-----------------------
 usr.bin/make/make.h   |  25 +++++++++++++-----
 usr.bin/make/meta.c   |  31 +++++++++++------------
 usr.bin/make/parse.c  |  19 +++++++------
 usr.bin/make/suff.c   |  50 +++++++++++++++++++-------------------
 usr.bin/make/targ.c   |  66 +++++++++++++++++++++++++-------------------------
 usr.bin/make/var.c    |  44 ++++++++++++++++-----------------
 11 files changed, 191 insertions(+), 186 deletions(-)

diffs (truncated from 1047 to 300 lines):

diff -r c0918093531e -r a235706ff093 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Mon Sep 28 21:11:05 2020 +0000
+++ b/usr.bin/make/arch.c       Mon Sep 28 22:23:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.125 2020/09/28 20:46:11 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.126 2020/09/28 22:23:35 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.125 2020/09/28 20:46:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.126 2020/09/28 22:23:35 rillig Exp $");
 
 #ifdef TARGET_MACHINE
 #undef MAKE_MACHINE
@@ -612,7 +612,7 @@
                if (fseek(arch, -elen, SEEK_CUR) != 0)
                        goto badarch;
                if (DEBUG(ARCH) || DEBUG(MAKE)) {
-                   fprintf(debug_file, "ArchStat: Extended format entry for %s\n", memName);
+                   debug_printf("ArchStat: Extended format entry for %s\n", memName);
                }
            }
 #endif
@@ -840,7 +840,7 @@
                }
                ename[elen] = '\0';
                if (DEBUG(ARCH) || DEBUG(MAKE)) {
-                   fprintf(debug_file, "ArchFind: Extended format entry for %s\n", ename);
+                   debug_printf("ArchFind: Extended format entry for %s\n", ename);
                }
                if (strncmp(ename, member, len) == 0) {
                        /* Found as extended name */
@@ -1114,7 +1114,7 @@
            modTimeTOC = (int)strtol(arhPtr->ar_date, NULL, 10);
 
            if (DEBUG(ARCH) || DEBUG(MAKE)) {
-               fprintf(debug_file, "%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
+               debug_printf("%s modified %s...", RANLIBMAG, Targ_FmtTime(modTimeTOC));
            }
            oodate = (gn->cmgn == NULL || gn->cmgn->mtime > modTimeTOC);
        } else {
@@ -1122,7 +1122,7 @@
             * A library w/o a table of contents is out-of-date
             */
            if (DEBUG(ARCH) || DEBUG(MAKE)) {
-               fprintf(debug_file, "No t.o.c....");
+               debug_printf("No t.o.c....");
            }
            oodate = TRUE;
        }
diff -r c0918093531e -r a235706ff093 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Mon Sep 28 21:11:05 2020 +0000
+++ b/usr.bin/make/compat.c     Mon Sep 28 22:23:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.157 2020/09/28 20:46:11 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.158 2020/09/28 22:23:35 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.157 2020/09/28 20:46:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.158 2020/09/28 22:23:35 rillig Exp $");
 
 static GNode       *curTarg = NULL;
 static void CompatInterrupt(int);
@@ -403,19 +403,19 @@
        if (status != 0) {
            if (DEBUG(ERROR)) {
                const char *cp;
-               fprintf(debug_file, "\n*** Failed target:  %s\n*** Failed command: ",
-                   gn->name);
+               debug_printf("\n*** Failed target:  %s\n*** Failed command: ",
+                            gn->name);
                for (cp = cmd; *cp; ) {
                    if (ch_isspace(*cp)) {
-                       fprintf(debug_file, " ");
+                       debug_printf(" ");
                        while (ch_isspace(*cp))
                            cp++;
                    } else {
-                       fprintf(debug_file, "%c", *cp);
+                       debug_printf("%c", *cp);
                        cp++;
                    }
                }
-               fprintf(debug_file, "\n");
+               debug_printf("\n");
            }
            printf("*** Error code %d", status);
        }
diff -r c0918093531e -r a235706ff093 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Mon Sep 28 21:11:05 2020 +0000
+++ b/usr.bin/make/dir.c        Mon Sep 28 22:23:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.151 2020/09/28 20:46:11 rillig Exp $ */
+/*     $NetBSD: dir.c,v 1.152 2020/09/28 22:23:35 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -136,7 +136,7 @@
 #include "job.h"
 
 /*     "@(#)dir.c      8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: dir.c,v 1.151 2020/09/28 20:46:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.152 2020/09/28 22:23:35 rillig Exp $");
 
 #define DIR_DEBUG0(text) DEBUG0(DIR, text)
 #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
@@ -755,9 +755,9 @@
     StringListNode *ln;
     for (ln = words->first; ln != NULL; ln = ln->next) {
        const char *word = ln->datum;
-       fprintf(debug_file, "%s ", word);
+       debug_printf("%s ", word);
     }
-    fprintf(debug_file, "\n");
+    debug_printf("\n");
 }
 
 /*-
@@ -1713,17 +1713,16 @@
 {
     CachedDirListNode *ln;
 
-    fprintf(debug_file, "#*** Directory Cache:\n");
-    fprintf(debug_file,
-           "# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n",
-           hits, misses, nearmisses, bigmisses,
-           percentage(hits, hits + bigmisses + nearmisses));
-    fprintf(debug_file, "# %-20s referenced\thits\n", "directory");
+    debug_printf("#*** Directory Cache:\n");
+    debug_printf("# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n",
+                hits, misses, nearmisses, bigmisses,
+                percentage(hits, hits + bigmisses + nearmisses));
+    debug_printf("# %-20s referenced\thits\n", "directory");
 
     for (ln = openDirectories->first; ln != NULL; ln = ln->next) {
        CachedDir *dir = ln->datum;
-       fprintf(debug_file, "# %-20s %10d\t%4d\n", dir->name, dir->refCount,
-               dir->hits);
+       debug_printf("# %-20s %10d\t%4d\n", dir->name, dir->refCount,
+                    dir->hits);
     }
 }
 
@@ -1733,6 +1732,6 @@
     SearchPathNode *node;
     for (node = path->first; node != NULL; node = node->next) {
        const CachedDir *dir = node->datum;
-       fprintf(debug_file, "%s ", dir->name);
+       debug_printf("%s ", dir->name);
     }
 }
diff -r c0918093531e -r a235706ff093 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Mon Sep 28 21:11:05 2020 +0000
+++ b/usr.bin/make/job.c        Mon Sep 28 22:23:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.250 2020/09/28 20:46:11 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.251 2020/09/28 22:23:35 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.250 2020/09/28 20:46:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.251 2020/09/28 22:23:35 rillig Exp $");
 
 # define STATIC static
 
@@ -356,9 +356,9 @@
 {
     Job *job;
 
-    fprintf(debug_file, "job table @ %s\n", where);
+    debug_printf("job table @ %s\n", where);
     for (job = job_table; job < job_table_end; job++) {
-       fprintf(debug_file, "job %d, status %d, flags %d, pid %d\n",
+       debug_printf("job %d, status %d, flags %d, pid %d\n",
            (int)(job - job_table), job->job_state, job->flags, job->pid);
     }
 }
@@ -524,10 +524,8 @@
     act.sa_flags = 0;
     (void)sigaction(signo, &act, NULL);
 
-    if (DEBUG(JOB)) {
-       (void)fprintf(debug_file,
-                      "JobPassSig passing signal %d to self.\n", signo);
-    }
+    if (DEBUG(JOB))
+       debug_printf("JobPassSig passing signal %d to self.\n", signo);
 
     (void)kill(getpid(), signo);
 
@@ -631,7 +629,7 @@
     }
 
 #define DBPRINTF(fmt, arg) if (DEBUG(JOB)) {   \
-       (void)fprintf(debug_file, fmt, arg);    \
+       debug_printf(fmt, arg);                 \
     }                                          \
    (void)fprintf(job->cmdFILE, fmt, arg);      \
    (void)fflush(job->cmdFILE);
@@ -1176,12 +1174,12 @@
     if (DEBUG(JOB)) {
        int i;
 
-       (void)fprintf(debug_file, "Running %s %sly\n", job->node->name, "local");
-       (void)fprintf(debug_file, "\tCommand: ");
+       debug_printf("Running %s %sly\n", job->node->name, "local");
+       debug_printf("\tCommand: ");
        for (i = 0; argv[i] != NULL; i++) {
-           (void)fprintf(debug_file, "%s ", argv[i]);
+           debug_printf("%s ", argv[i]);
        }
-       (void)fprintf(debug_file, "\n");
+       debug_printf("\n");
     }
 
     /*
@@ -1328,8 +1326,8 @@
      * Now the job is actually running, add it to the table.
      */
     if (DEBUG(JOB)) {
-       fprintf(debug_file, "JobExec(%s): pid %d added to jobs table\n",
-               job->node->name, job->pid);
+       debug_printf("JobExec(%s): pid %d added to jobs table\n",
+                    job->node->name, job->pid);
        job_table_dump("job started");
     }
     JobSigUnlock(&mask);
@@ -2510,7 +2508,7 @@
            }
            job->job_suspended = 0;
            if (KILLPG(job->pid, SIGCONT) != 0 && DEBUG(JOB)) {
-               fprintf(debug_file, "Failed to send SIGCONT to %d\n", job->pid);
+               debug_printf("Failed to send SIGCONT to %d\n", job->pid);
            }
        }
        if (job->job_state == JOB_ST_FINISHED)
diff -r c0918093531e -r a235706ff093 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Mon Sep 28 21:11:05 2020 +0000
+++ b/usr.bin/make/make.c       Mon Sep 28 22:23:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.152 2020/09/28 20:46:11 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.153 2020/09/28 22:23:35 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
 #include    "job.h"
 
 /*     "@(#)make.c     8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: make.c,v 1.152 2020/09/28 20:46:11 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.153 2020/09/28 22:23:35 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked = 1;
@@ -128,7 +128,7 @@
 MAKE_ATTR_DEAD static void
 make_abort(GNode *gn, int line)
 {
-    fprintf(debug_file, "make_abort from line %d\n", line);
+    debug_printf("make_abort from line %d\n", line);
     Targ_PrintNode(gn, 2);
     Targ_PrintNodes(toBeMade, 2);
     Targ_PrintGraph(3);
@@ -211,9 +211,9 @@
        (void)Dir_MTime(gn, 1);
        if (DEBUG(MAKE)) {
            if (gn->mtime != 0) {
-               fprintf(debug_file, "modified %s...", Targ_FmtTime(gn->mtime));
+               debug_printf("modified %s...", Targ_FmtTime(gn->mtime));
            } else {
-               fprintf(debug_file, "non-existent...");
+               debug_printf("non-existent...");
            }
        }
     }
@@ -264,11 +264,11 @@
         */
        if (DEBUG(MAKE)) {
            if (gn->type & OP_FORCE) {
-               fprintf(debug_file, "! operator...");
+               debug_printf("! operator...");
            } else if (gn->type & OP_PHONY) {
-               fprintf(debug_file, ".PHONY node...");
+               debug_printf(".PHONY node...");
            } else {
-               fprintf(debug_file, ".EXEC node...");
+               debug_printf(".EXEC node...");



Home | Main Index | Thread Index | Old Index