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): in debug mode, print GNode details in ...



details:   https://anonhg.NetBSD.org/src/rev/98f94c9c2f8f
branches:  trunk
changeset: 1013305:98f94c9c2f8f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 24 20:15:51 2020 +0000

description:
make(1): in debug mode, print GNode details in symbols

A string like OP_DEPENDS|OP_OPTIONAL|OP_PRECIOUS is much easier to read
and understand than the bit pattern 00000089.

The implementation in enum.h looks really bloated and ugly, but using
this API is as simple and natural as possible.  That's the trade-off.

In enum.h, I thought about choosing the numbers in the macros such that
it is always possible to combine two of them in order to reach an
arbitrary number, because of the "part1, part2" in the ENUM__SPEC macro.
The powers of 2 are not these numbers, as 7 cannot be expressed as the
sum of two of them.  Neither are the fibonacci numbers since 12 cannot
be expressed as the sum of 2 fibonacci numbers.  I tried to find a
general pattern to generate these minimal 2-sum numbers, but failed.

diffstat:

 usr.bin/make/enum.c |   21 +++++++--
 usr.bin/make/enum.h |  107 ++++++++++++++++++++++++++++++++++-----------------
 usr.bin/make/make.c |   75 +++++++++++++++++++++++++++---------
 usr.bin/make/make.h |    3 +-
 usr.bin/make/targ.c |   10 ++--
 usr.bin/make/var.c  |   26 ++++++------
 6 files changed, 164 insertions(+), 78 deletions(-)

diffs (truncated from 432 to 300 lines):

diff -r 2279b43f5107 -r 98f94c9c2f8f usr.bin/make/enum.c
--- a/usr.bin/make/enum.c       Mon Aug 24 19:36:32 2020 +0000
+++ b/usr.bin/make/enum.c       Mon Aug 24 20:15:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: enum.c,v 1.3 2020/08/09 09:44:14 rillig Exp $  */
+/*     $NetBSD: enum.c,v 1.4 2020/08/24 20:15:51 rillig Exp $  */
 
 /*
  Copyright (c) 2020 Roland Illig <rillig%NetBSD.org@localhost>
@@ -28,11 +28,11 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: enum.c,v 1.3 2020/08/09 09:44:14 rillig Exp $";
+static char rcsid[] = "$NetBSD: enum.c,v 1.4 2020/08/24 20:15:51 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: enum.c,v 1.3 2020/08/09 09:44:14 rillig Exp $");
+__RCSID("$NetBSD: enum.c,v 1.4 2020/08/24 20:15:51 rillig Exp $");
 #endif
 #endif
 
@@ -44,8 +44,8 @@
 /* Convert a bitset into a string representation showing the names of the
  * individual bits, or optionally shortcuts for groups of bits. */
 const char *
-Enum_ToString(char *buf, size_t buf_size, int value,
-             const EnumToStringSpec *spec)
+Enum_FlagsToString(char *buf, size_t buf_size,
+                  int value, const EnumToStringSpec *spec)
 {
        const char *buf_start = buf;
        const char *sep = "";
@@ -81,3 +81,14 @@
        buf[0] = '\0';
        return buf_start;
 }
+
+/* Convert a fixed-value enum into a string representation. */
+const char *
+Enum_ValueToString(int value, const EnumToStringSpec *spec)
+{
+       for (; spec->es_name[0] != '\0'; spec++) {
+           if (value == spec->es_value)
+               return spec->es_name;
+       }
+       assert(!"unknown enum value");
+}
diff -r 2279b43f5107 -r 98f94c9c2f8f usr.bin/make/enum.h
--- a/usr.bin/make/enum.h       Mon Aug 24 19:36:32 2020 +0000
+++ b/usr.bin/make/enum.h       Mon Aug 24 20:15:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: enum.h,v 1.6 2020/08/23 09:28:52 rillig Exp $  */
+/*     $NetBSD: enum.h,v 1.7 2020/08/24 20:15:51 rillig Exp $  */
 
 /*
  Copyright (c) 2020 Roland Illig <rillig%NetBSD.org@localhost>
@@ -41,58 +41,95 @@
        const char *es_name;
 } EnumToStringSpec;
 
-const char *Enum_ToString(char *, size_t, int, const EnumToStringSpec *);
+const char *Enum_FlagsToString(char *, size_t, int, const EnumToStringSpec *);
+const char *Enum_ValueToString(int, const EnumToStringSpec *);
 
 #define ENUM__SEP "|"
 
 #define ENUM__JOIN_1(v1) \
        #v1
 #define ENUM__JOIN_2(v1, v2) \
-       #v1 ENUM__SEP ENUM__JOIN_1(v2)
-#define ENUM__JOIN_3(v1, v2, v3) \
-       #v1 ENUM__SEP ENUM__JOIN_2(v2, v3)
+       #v1 ENUM__SEP #v2
 #define ENUM__JOIN_4(v1, v2, v3, v4) \
-       #v1 ENUM__SEP ENUM__JOIN_3(v2, v3, v4)
-#define ENUM__JOIN_5(v1, v2, v3, v4, v5) \
-       #v1 ENUM__SEP ENUM__JOIN_4(v2, v3, v4, v5)
-#define ENUM__JOIN_6(v1, v2, v3, v4, v5, v6) \
-       #v1 ENUM__SEP ENUM__JOIN_5(v2, v3, v4, v5, v6)
-#define ENUM__JOIN_7(v1, v2, v3, v4, v5, v6, v7) \
-       #v1 ENUM__SEP ENUM__JOIN_6(v2, v3, v4, v5, v6, v7)
+       ENUM__JOIN_2(v1, v2) ENUM__SEP ENUM__JOIN_2(v3, v4)
 #define ENUM__JOIN_8(v1, v2, v3, v4, v5, v6, v7, v8) \
-       #v1 ENUM__SEP ENUM__JOIN_7(v2, v3, v4, v5, v6, v7, v8)
+       ENUM__JOIN_4(v1, v2, v3, v4) ENUM__SEP ENUM__JOIN_4(v5, v6, v7, v8)
+#define ENUM__JOIN_16(v01, v02, v03, v04, v05, v06, v07, v08, \
+                     v09, v10, v11, v12, v13, v14, v15, v16) \
+       ENUM__JOIN_8(v01, v02, v03, v04, v05, v06, v07, v08) ENUM__SEP \
+       ENUM__JOIN_8(v09, v10, v11, v12, v13, v14, v15, v16)
+#define ENUM__JOIN_32(v01, v02, v03, v04, v05, v06, v07, v08, \
+                     v09, v10, v11, v12, v13, v14, v15, v16, \
+                     v17, v18, v19, v20, v21, v22, v23, v24, \
+                     v25, v26, v27, v28, v29, v30, v31, v32) \
+       ENUM__JOIN_16(v01, v02, v03, v04, v05, v06, v07, v08, \
+                     v09, v10, v11, v12, v13, v14, v15, v16) ENUM__SEP \
+       ENUM__JOIN_16(v17, v18, v19, v20, v21, v22, v23, v24, \
+                     v25, v26, v27, v28, v29, v30, v31, v32)
+#define ENUM__JOIN(part1, part2) \
+       part1 ENUM__SEP part2
 
 #define ENUM__RTTI(typnam, specs, joined) \
        static const EnumToStringSpec typnam ## _ ## ToStringSpecs[] = specs; \
        enum { typnam ## _ ## ToStringSize = sizeof joined }
 
-#define ENUM__SPEC(v) { v, #v }
-
-#define ENUM__SPEC_3(v1, v2, v3) { \
-       ENUM__SPEC(v1), \
-       ENUM__SPEC(v2), \
-       ENUM__SPEC(v3), \
-       { 0, "" } }
-
-#define ENUM__SPEC_8(v1, v2, v3, v4, v5, v6, v7, v8) { \
-       ENUM__SPEC(v1), \
-       ENUM__SPEC(v2), \
-       ENUM__SPEC(v3), \
-       ENUM__SPEC(v4), \
-       ENUM__SPEC(v5), \
-       ENUM__SPEC(v6), \
-       ENUM__SPEC(v7), \
-       ENUM__SPEC(v8), \
-       { 0, "" } }
+#define ENUM__SPEC_1(v1) { v1, #v1 }
+#define ENUM__SPEC_2(v1, v2) \
+       ENUM__SPEC_1(v1), \
+       ENUM__SPEC_1(v2)
+#define ENUM__SPEC_4(v1, v2, v3, v4) \
+       ENUM__SPEC_2(v1, v2), \
+       ENUM__SPEC_2(v3, v4)
+#define ENUM__SPEC_8(v1, v2, v3, v4, v5, v6, v7, v8) \
+       ENUM__SPEC_4(v1, v2, v3, v4), \
+       ENUM__SPEC_4(v5, v6, v7, v8)
+#define ENUM__SPEC_16(v01, v02, v03, v04, v05, v06, v07, v08, \
+                     v09, v10, v11, v12, v13, v14, v15, v16) \
+       ENUM__SPEC_8(v01, v02, v03, v04, v05, v06, v07, v08), \
+       ENUM__SPEC_8(v09, v10, v11, v12, v13, v14, v15, v16)
+#define ENUM__SPEC(part1, part2) \
+       { part1, part2, { 0, "" } }
 
 #define ENUM_RTTI_3(typnam, v1, v2, v3) \
        ENUM__RTTI(typnam, \
-                 ENUM__SPEC_3(v1, v2, v3), \
-                 ENUM__JOIN_3(v1, v2, v3))
+           ENUM__SPEC(ENUM__SPEC_2(v1, v2), ENUM__SPEC_1(v3)), \
+           ENUM__JOIN_2(ENUM__JOIN_2(v1, v2), ENUM__JOIN_1(v3)))
 
 #define ENUM_RTTI_8(typnam, v1, v2, v3, v4, v5, v6, v7, v8) \
        ENUM__RTTI(typnam, \
-                 ENUM__SPEC_8(v1, v2, v3, v4, v5, v6, v7, v8), \
-                 ENUM__JOIN_8(v1, v2, v3, v4, v5, v6, v7, v8))
+           ENUM__SPEC( \
+               ENUM__SPEC_4(v1, v2, v3, v4), \
+               ENUM__SPEC_4(v5, v6, v7, v8)), \
+           ENUM__JOIN( \
+               ENUM__JOIN_4(v1, v2, v3, v4), \
+               ENUM__JOIN_4(v5, v6, v7, v8)))
+
+#define ENUM_RTTI_10(typnam, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) \
+       ENUM__RTTI(typnam, \
+           ENUM__SPEC( \
+               ENUM__SPEC_8(v1, v2, v3, v4, v5, v6, v7, v8), \
+               ENUM__SPEC_2(v9, v10)), \
+           ENUM__JOIN( \
+               ENUM__JOIN_8(v1, v2, v3, v4, v5, v6, v7, v8), \
+               ENUM__JOIN_2(v9, v10)))
+
+#define ENUM_RTTI_32( \
+    typnam, \
+    v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, \
+    v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, \
+    v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, \
+    v31, v32) \
+    ENUM__RTTI( \
+       typnam, \
+        ENUM__SPEC( \
+        ENUM__SPEC_16(v01, v02, v03, v04, v05, v06, v07, v08, \
+                     v09, v10, v11, v12, v13, v14, v15, v16), \
+        ENUM__SPEC_16(v17, v18, v19, v20, v21, v22, v23, v24, \
+                     v25, v26, v27, v28, v29, v30, v31, v32)), \
+       ENUM__JOIN_32( \
+           v01, v02, v03, v04, v05, v06, v07, v08, \
+           v09, v10, v11, v12, v13, v14, v15, v16, \
+           v17, v18, v19, v20, v21, v22, v23, v24, \
+           v25, v26, v27, v28, v29, v30, v31, v32))
 
 #endif
diff -r 2279b43f5107 -r 98f94c9c2f8f usr.bin/make/make.c
--- a/usr.bin/make/make.c       Mon Aug 24 19:36:32 2020 +0000
+++ b/usr.bin/make/make.c       Mon Aug 24 20:15:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.c,v 1.121 2020/08/22 22:57:53 rillig Exp $        */
+/*     $NetBSD: make.c,v 1.122 2020/08/24 20:15:51 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: make.c,v 1.121 2020/08/22 22:57:53 rillig Exp $";
+static char rcsid[] = "$NetBSD: make.c,v 1.122 2020/08/24 20:15:51 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)make.c     8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: make.c,v 1.121 2020/08/22 22:57:53 rillig Exp $");
+__RCSID("$NetBSD: make.c,v 1.122 2020/08/24 20:15:51 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -116,7 +116,7 @@
  */
 
 #include    "make.h"
-#include    "hash.h"
+#include    "enum.h"
 #include    "dir.h"
 #include    "job.h"
 
@@ -151,6 +151,42 @@
     abort();
 }
 
+ENUM_RTTI_8(GNodeMade,
+           UNMADE, DEFERRED, REQUESTED, BEINGMADE,
+           MADE, UPTODATE, ERROR, ABORTED);
+
+ENUM_RTTI_32(GNodeType,
+            OP_DEPENDS, OP_FORCE, OP_DOUBLEDEP, OP_OPMASK,
+            OP_OPTIONAL, OP_USE, OP_EXEC, OP_IGNORE,
+            OP_PRECIOUS, OP_SILENT, OP_MAKE, OP_JOIN,
+            OP_MADE, OP_SPECIAL, OP_USEBEFORE, OP_INVISIBLE,
+            OP_NOTMAIN, OP_PHONY, OP_NOPATH, OP_WAIT,
+            OP_NOMETA, OP_META, OP_NOMETA_CMP, OP_SUBMAKE,
+            OP_TRANSFORM, OP_MEMBER, OP_LIB, OP_ARCHV,
+            OP_HAS_COMMANDS, OP_SAVE_CMDS, OP_DEPS_FOUND, OP_MARK);
+
+ENUM_RTTI_10(GNodeFlags,
+            REMAKE, CHILDMADE, FORCE, DONE_WAIT,
+            DONE_ORDER, FROM_DEPEND, DONE_ALLSRC, CYCLE,
+            DONECYCLE, INTERNAL);
+
+void
+GNode_FprintDetails(FILE *f, const char *prefix, const GNode *gn,
+                   const char *suffix)
+{
+    char type_buf[GNodeType_ToStringSize];
+    char flags_buf[GNodeFlags_ToStringSize];
+
+    fprintf(f, "%smade %s, type %s, flags %s%s",
+           prefix,
+           Enum_ValueToString(gn->made, GNodeMade_ToStringSpecs),
+           Enum_FlagsToString(type_buf, sizeof type_buf,
+                              gn->type, GNodeType_ToStringSpecs),
+           Enum_FlagsToString(flags_buf, sizeof flags_buf,
+                              gn->flags, GNodeFlags_ToStringSpecs),
+           suffix);
+}
+
 /*-
  *-----------------------------------------------------------------------
  * Make_TimeStamp --
@@ -1156,15 +1192,15 @@
        /* not waiting for this one */
        return 0;
 
-    printf("    `%s%s' has .ORDER dependency against %s%s "
-               "(made %d, flags %x, type %x)\n",
-           gn->name, gn->cohort_num,
-           ogn->name, ogn->cohort_num, ogn->made, ogn->flags, ogn->type);
-    if (DEBUG(MAKE) && debug_file != stdout)
-       fprintf(debug_file, "    `%s%s' has .ORDER dependency against %s%s "
-                   "(made %d, flags %x, type %x)\n",
-               gn->name, gn->cohort_num,
-               ogn->name, ogn->cohort_num, ogn->made, ogn->flags, ogn->type);
+    printf("    `%s%s' has .ORDER dependency against %s%s ",
+           gn->name, gn->cohort_num, ogn->name, ogn->cohort_num);
+    GNode_FprintDetails(stdout, "(", ogn, ")\n");
+
+    if (DEBUG(MAKE) && debug_file != stdout) {
+       fprintf(debug_file, "    `%s%s' has .ORDER dependency against %s%s ",
+               gn->name, gn->cohort_num, ogn->name, ogn->cohort_num);
+       GNode_FprintDetails(debug_file, "(", ogn, ")\n");
+    }
     return 0;
 }
 
@@ -1191,12 +1227,13 @@
        case REQUESTED:
        case BEINGMADE:
            (*errors)++;
-           printf("`%s%s' was not built (made %d, flags %x, type %x)!\n",
-                   gn->name, gn->cohort_num, gn->made, gn->flags, gn->type);
-           if (DEBUG(MAKE) && debug_file != stdout)
-               fprintf(debug_file,
-                       "`%s%s' was not built (made %d, flags %x, type %x)!\n",



Home | Main Index | Thread Index | Old Index