Module Name:    src
Committed By:   rillig
Date:           Sat Aug  8 14:28:46 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: vardebug.exp vardebug.mk

Log Message:
make(1): extend debug logging to error values

The error marker var_Error is just an empty string.  In the debug log
this empty string was not distinguishable from an otherwise empty
string.

Having this distinction helps in understanding the exact data flow.


To generate a diff of this commit:
cvs rdiff -u -r1.430 -r1.431 src/usr.bin/make/var.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/vardebug.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/vardebug.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.430 src/usr.bin/make/var.c:1.431
--- src/usr.bin/make/var.c:1.430	Sat Aug  8 13:50:23 2020
+++ src/usr.bin/make/var.c	Sat Aug  8 14:28:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.430 2020/08/08 13:50:23 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.431 2020/08/08 14:28:46 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.430 2020/08/08 13:50:23 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.431 2020/08/08 14:28:46 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.430 2020/08/08 13:50:23 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.431 2020/08/08 14:28:46 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -3212,10 +3212,12 @@ ApplyModifiers(
 	if (DEBUG(VAR)) {
 	    char eflags_str[VarEvalFlags_ToStringSize];
 	    char vflags_str[VarFlags_ToStringSize];
+	    const char *q = st.newVal == var_Error ? "" : "\"";
+	    const char *newVal = st.newVal == var_Error ? "error" : st.newVal;
 
-	    VAR_DEBUG("Result of ${%s:%.*s} is \"%s\" "
+	    VAR_DEBUG("Result of ${%s:%.*s} is %s%s%s "
 		      "(eflags = %s, vflags = %s)\n",
-		      st.v->name, (int)(p - mod), mod, st.newVal,
+		      st.v->name, (int)(p - mod), mod, q, newVal, q,
 		      Enum_ToString(eflags_str, sizeof eflags_str, st.eflags,
 				    VarEvalFlags_ToStringSpecs),
 		      Enum_ToString(vflags_str, sizeof vflags_str, st.v->flags,

Index: src/usr.bin/make/unit-tests/vardebug.exp
diff -u src/usr.bin/make/unit-tests/vardebug.exp:1.4 src/usr.bin/make/unit-tests/vardebug.exp:1.5
--- src/usr.bin/make/unit-tests/vardebug.exp:1.4	Sat Aug  8 13:50:23 2020
+++ src/usr.bin/make/unit-tests/vardebug.exp	Sat Aug  8 14:28:46 2020
@@ -57,5 +57,12 @@ Result of ${:Mvalu[e]} is "value" (eflag
 Applying ${:U...} to "" (eflags = VARE_WANTRES, vflags = VAR_JUNK)
 Result of ${:UVAR} is "VAR" (eflags = VARE_WANTRES, vflags = VAR_JUNK|VAR_KEEP)
 Global:delete VAR
+Applying ${:U...} to "" (eflags = VARE_UNDEFERR|VARE_WANTRES, vflags = VAR_JUNK)
+Result of ${:Uvariable} is "variable" (eflags = VARE_UNDEFERR|VARE_WANTRES, vflags = VAR_JUNK|VAR_KEEP)
+Applying ${:u...} to "variable" (eflags = VARE_UNDEFERR|VARE_WANTRES, vflags = VAR_JUNK|VAR_KEEP)
+make: Unknown modifier 'u'
+Result of ${:unknown} is error (eflags = VARE_UNDEFERR|VARE_WANTRES, vflags = VAR_JUNK|VAR_KEEP)
+make: "vardebug.mk" line 44: Malformed conditional (${:Uvariable:unknown})
+make: "vardebug.mk" line 53: Malformed conditional (${UNDEFINED})
 Global:RELEVANT = no
-exit status 0
+exit status 1

Index: src/usr.bin/make/unit-tests/vardebug.mk
diff -u src/usr.bin/make/unit-tests/vardebug.mk:1.2 src/usr.bin/make/unit-tests/vardebug.mk:1.3
--- src/usr.bin/make/unit-tests/vardebug.mk:1.2	Sat Aug  8 12:22:10 2020
+++ src/usr.bin/make/unit-tests/vardebug.mk	Sat Aug  8 14:28:46 2020
@@ -1,4 +1,4 @@
-# $NetBSD: vardebug.mk,v 1.2 2020/08/08 12:22:10 rillig Exp $
+# $NetBSD: vardebug.mk,v 1.3 2020/08/08 14:28:46 rillig Exp $
 #
 # Demonstrates the debugging output for var.c.
 
@@ -39,6 +39,20 @@ VAR+=		3
 
 .undef ${:UVAR}			# Var_Delete
 
+# When ApplyModifiers results in an error, this appears in the debug log
+# as "is error", without surrounding quotes.
+.if ${:Uvariable:unknown}
+.endif
+
+# XXX: The error message is "Malformed conditional", which is wrong.
+# The condition is syntactically fine, it just contains an undefined variable.
+#
+# There is a specialized error message for "Undefined variable", but as of
+# 2020-08-08, that is not covered by any unit tests.  It might even be
+# unreachable.
+.if ${UNDEFINED}
+.endif
+
 RELEVANT=	no
 
 all:

Reply via email to