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: add details about .for loop variables to ...



details:   https://anonhg.NetBSD.org/src/rev/962644e12852
branches:  trunk
changeset: 359536:962644e12852
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 08 23:52:26 2022 +0000

description:
make: add details about .for loop variables to stack traces

The stack traces are enabled with the debug logging option '-dp'.

diffstat:

 usr.bin/make/for.c                          |  23 +++++++++++++++++++++--
 usr.bin/make/nonints.h                      |   3 ++-
 usr.bin/make/parse.c                        |  10 ++++++----
 usr.bin/make/unit-tests/include-main.exp    |   6 +++---
 usr.bin/make/unit-tests/opt-debug-parse.exp |  16 ++++++++++++++--
 usr.bin/make/unit-tests/opt-debug-parse.mk  |  10 +++++++++-
 6 files changed, 55 insertions(+), 13 deletions(-)

diffs (164 lines):

diff -r 261ddf21f630 -r 962644e12852 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Sat Jan 08 23:41:43 2022 +0000
+++ b/usr.bin/make/for.c        Sat Jan 08 23:52:26 2022 +0000
@@ -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 @@
        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)
 {
diff -r 261ddf21f630 -r 962644e12852 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sat Jan 08 23:41:43 2022 +0000
+++ b/usr.bin/make/nonints.h    Sat Jan 08 23:52:26 2022 +0000
@@ -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 @@
 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);
diff -r 261ddf21f630 -r 962644e12852 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Jan 08 23:41:43 2022 +0000
+++ b/usr.bin/make/parse.c      Sat Jan 08 23:52:26 2022 +0000
@@ -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 @@
                        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
diff -r 261ddf21f630 -r 962644e12852 usr.bin/make/unit-tests/include-main.exp
--- a/usr.bin/make/unit-tests/include-main.exp  Sat Jan 08 23:41:43 2022 +0000
+++ b/usr.bin/make/unit-tests/include-main.exp  Sat Jan 08 23:52:26 2022 +0000
@@ -4,9 +4,9 @@
 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
diff -r 261ddf21f630 -r 962644e12852 usr.bin/make/unit-tests/opt-debug-parse.exp
--- a/usr.bin/make/unit-tests/opt-debug-parse.exp       Sat Jan 08 23:41:43 2022 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-parse.exp       Sat Jan 08 23:52:26 2022 +0000
@@ -2,7 +2,7 @@
 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: ${.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
diff -r 261ddf21f630 -r 962644e12852 usr.bin/make/unit-tests/opt-debug-parse.mk
--- a/usr.bin/make/unit-tests/opt-debug-parse.mk        Sat Jan 08 23:41:43 2022 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-parse.mk        Sat Jan 08 23:52:26 2022 +0000
@@ -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



Home | Main Index | Thread Index | Old Index