Module Name: src
Committed By: rillig
Date: Sat Jan 8 23:52:26 UTC 2022
Modified Files:
src/usr.bin/make: for.c nonints.h parse.c
src/usr.bin/make/unit-tests: include-main.exp opt-debug-parse.exp
opt-debug-parse.mk
Log Message:
make: add details about .for loop variables to stack traces
The stack traces are enabled with the debug logging option '-dp'.
To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/usr.bin/make/for.c
cvs rdiff -u -r1.234 -r1.235 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.643 -r1.644 src/usr.bin/make/parse.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/include-main.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/opt-debug-parse.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/opt-debug-parse.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/for.c
diff -u src/usr.bin/make/for.c:1.160 src/usr.bin/make/for.c:1.161
--- src/usr.bin/make/for.c:1.160 Sat Jan 8 20:21:34 2022
+++ src/usr.bin/make/for.c Sat Jan 8 23:52:26 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.160 2022/01/08 20:21:34 rillig Exp $ */
+/* $NetBSD: for.c,v 1.161 2022/01/08 23:52:26 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
#include "make.h"
/* "@(#)for.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: for.c,v 1.160 2022/01/08 20:21:34 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.161 2022/01/08 23:52:26 rillig Exp $");
typedef struct ForLoop {
@@ -98,6 +98,25 @@ ForLoop_Free(ForLoop *f)
free(f);
}
+char *
+ForLoop_Details(ForLoop *f)
+{
+ size_t i, n = f->vars.len;
+ const char **vars = f->vars.items;
+ const Substring *items = f->items.words + f->nextItem - n;
+ Buffer buf;
+
+ Buf_Init(&buf);
+ for (i = 0; i < n; i++) {
+ if (i > 0)
+ Buf_AddStr(&buf, ", ");
+ Buf_AddStr(&buf, vars[i]);
+ Buf_AddStr(&buf, " = ");
+ Buf_AddBytesBetween(&buf, items[i].start, items[i].end);
+ }
+ return Buf_DoneData(&buf);
+}
+
static bool
ForLoop_ParseVarnames(ForLoop *f, const char **pp)
{
Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.234 src/usr.bin/make/nonints.h:1.235
--- src/usr.bin/make/nonints.h:1.234 Sat Jan 8 20:21:34 2022
+++ src/usr.bin/make/nonints.h Sat Jan 8 23:52:26 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.234 2022/01/08 20:21:34 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.235 2022/01/08 23:52:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -121,6 +121,7 @@ int For_Eval(const char *) MAKE_ATTR_USE
bool For_Accum(const char *, int *) MAKE_ATTR_USE;
void For_Run(int, int);
bool For_NextIteration(struct ForLoop *, Buffer *);
+char *ForLoop_Details(struct ForLoop *);
/* job.c */
void JobReapChild(pid_t, int, bool);
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.643 src/usr.bin/make/parse.c:1.644
--- src/usr.bin/make/parse.c:1.643 Sat Jan 8 23:41:43 2022
+++ src/usr.bin/make/parse.c Sat Jan 8 23:52:26 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.643 2022/01/08 23:41:43 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.644 2022/01/08 23:52:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -106,7 +106,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.643 2022/01/08 23:41:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.644 2022/01/08 23:52:26 rillig Exp $");
/*
* A file being read.
@@ -353,8 +353,10 @@ PrintStackTrace(void)
fname = realpath(fname, dirbuf);
if (entry->forLoop != NULL) {
- debug_printf("\tin .for loop from %s:%d\n",
- fname, entry->forHeadLineno);
+ char *details = ForLoop_Details(entry->forLoop);
+ debug_printf("\tin .for loop from %s:%d with %s\n",
+ fname, entry->forHeadLineno, details);
+ free(details);
} else {
int lineno =
i + 1 < n && entries[i + 1].forLoop != NULL
Index: src/usr.bin/make/unit-tests/include-main.exp
diff -u src/usr.bin/make/unit-tests/include-main.exp:1.9 src/usr.bin/make/unit-tests/include-main.exp:1.10
--- src/usr.bin/make/unit-tests/include-main.exp:1.9 Sat Jan 8 23:41:43 2022
+++ src/usr.bin/make/unit-tests/include-main.exp Sat Jan 8 23:52:26 2022
@@ -4,9 +4,9 @@ make: "include-sub.mk" line 4: sub-befor
make: "include-sub.mk" line 14: sub-before-for-ok
Parsing line 5: . info subsub-ok
make: "include-subsub.mk" line 5: subsub-ok
- in .for loop from include-sub.mk:31
- in .for loop from include-sub.mk:30
- in .for loop from include-sub.mk:29
+ in .for loop from include-sub.mk:31 with i = include
+ in .for loop from include-sub.mk:30 with i = nested
+ in .for loop from include-sub.mk:29 with i = deeply
in include-sub.mk:29
in include-main.mk:27
Parsing line 6: .MAKEFLAGS: -d0
Index: src/usr.bin/make/unit-tests/opt-debug-parse.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-parse.exp:1.6 src/usr.bin/make/unit-tests/opt-debug-parse.exp:1.7
--- src/usr.bin/make/unit-tests/opt-debug-parse.exp:1.6 Sat Jan 8 23:41:43 2022
+++ src/usr.bin/make/unit-tests/opt-debug-parse.exp Sat Jan 8 23:52:26 2022
@@ -2,7 +2,7 @@ Parse_PushInput: .for loop in opt-debug-
SetFilenameVars: ${.PARSEDIR} = `<curdir>' ${.PARSEFILE} = `opt-debug-parse.mk'
Parsing line 20: .info trace with multi-line .for loop head
make: "opt-debug-parse.mk" line 20: trace with multi-line .for loop head
- in .for loop from opt-debug-parse.mk:16
+ in .for loop from opt-debug-parse.mk:16 with var = value
in opt-debug-parse.mk:16
ParseEOF: returning to file opt-debug-parse.mk, line 22
SetFilenameVars: ${.PARSEDIR} = `<curdir>' ${.PARSEFILE} = `opt-debug-parse.mk'
@@ -12,6 +12,18 @@ SetFilenameVars: ${.PARSEDIR} = `/dev' $
SetFilenameVars: ${.INCLUDEDFROMDIR} = `<curdir>' ${.INCLUDEDFROMFILE} = `opt-debug-parse.mk'
ParseEOF: returning to file opt-debug-parse.mk, line 26
SetFilenameVars: ${.PARSEDIR} = `<curdir>' ${.PARSEFILE} = `opt-debug-parse.mk'
-Parsing line 27: .MAKEFLAGS: -d0
+Parse_PushInput: .for loop in opt-debug-parse.mk, line 30
+SetFilenameVars: ${.PARSEDIR} = `<curdir>' ${.PARSEFILE} = `opt-debug-parse.mk'
+Parsing line 31: .info trace
+make: "opt-debug-parse.mk" line 31: trace
+ in .for loop from opt-debug-parse.mk:30 with a = 1, b = 2, c = 3
+ in opt-debug-parse.mk:30
+Parsing line 31: .info trace
+make: "opt-debug-parse.mk" line 31: trace
+ in .for loop from opt-debug-parse.mk:30 with a = 4, b = 5, c = 6
+ in opt-debug-parse.mk:30
+ParseEOF: returning to file opt-debug-parse.mk, line 33
+SetFilenameVars: ${.PARSEDIR} = `<curdir>' ${.PARSEFILE} = `opt-debug-parse.mk'
+Parsing line 35: .MAKEFLAGS: -d0
ParseDependency(.MAKEFLAGS: -d0)
exit status 0
Index: src/usr.bin/make/unit-tests/opt-debug-parse.mk
diff -u src/usr.bin/make/unit-tests/opt-debug-parse.mk:1.5 src/usr.bin/make/unit-tests/opt-debug-parse.mk:1.6
--- src/usr.bin/make/unit-tests/opt-debug-parse.mk:1.5 Sat Jan 8 23:41:43 2022
+++ src/usr.bin/make/unit-tests/opt-debug-parse.mk Sat Jan 8 23:52:26 2022
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-parse.mk,v 1.5 2022/01/08 23:41:43 rillig Exp $
+# $NetBSD: opt-debug-parse.mk,v 1.6 2022/01/08 23:52:26 rillig Exp $
#
# Tests for the -dp command line option, which adds debug logging about
# makefile parsing.
@@ -24,6 +24,14 @@
# the line of the '.include' instead of the line following it.
.include "/dev/null"
+
+# In .for loops with multiple variables, the variable details are included in
+# the stack trace, just as with a single variable.
+.for a b c in 1 2 3 ${:U4 5 6}
+.info trace
+.endfor
+
+
.MAKEFLAGS: -d0
all: .PHONY