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: fix stack traces in -dp mode (since 2021-...



details:   https://anonhg.NetBSD.org/src/rev/261ddf21f630
branches:  trunk
changeset: 359535:261ddf21f630
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 08 23:41:43 2022 +0000

description:
make: fix stack traces in -dp mode (since 2021-01-26)

Previously, the stack traces omitted some lines that seemed to be
redundant.  As a result, the stack traces contained confusing line
numbers.

diffstat:

 usr.bin/make/parse.c                        |  20 +++++++++++++-------
 usr.bin/make/unit-tests/include-main.exp    |   3 ++-
 usr.bin/make/unit-tests/include-main.mk     |   4 ++--
 usr.bin/make/unit-tests/include-sub.mk      |   4 ++--
 usr.bin/make/unit-tests/opt-debug-parse.exp |  17 +++++++++--------
 usr.bin/make/unit-tests/opt-debug-parse.mk  |  13 +++++++------
 6 files changed, 35 insertions(+), 26 deletions(-)

diffs (160 lines):

diff -r 9d9c801ed011 -r 261ddf21f630 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Jan 08 23:30:41 2022 +0000
+++ b/usr.bin/make/parse.c      Sat Jan 08 23:41:43 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.642 2022/01/08 22:42:27 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.643 2022/01/08 23:41:43 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.642 2022/01/08 22:42:27 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.643 2022/01/08 23:41:43 rillig Exp $");
 
 /*
  * A file being read.
@@ -340,7 +340,9 @@
        n = includes.len;
        if (n == 0)
                return;
-       n--;                    /* This entry is already in the diagnostic. */
+
+       if (entries[n - 1].forLoop == NULL)
+               n--;            /* already in the diagnostic */
 
        for (i = n; i-- > 0;) {
                const IncludedFile *entry = entries + i;
@@ -350,12 +352,16 @@
                if (fname[0] != '/' && strcmp(fname, "(stdin)") != 0)
                        fname = realpath(fname, dirbuf);
 
-               if (entries[i + 1 < n ? i + 1 : i].forLoop == NULL)
-                       debug_printf("\tin .include from %s:%d\n",
-                           fname, entry->lineno);
-               if (entry->forLoop != NULL)
+               if (entry->forLoop != NULL) {
                        debug_printf("\tin .for loop from %s:%d\n",
                            fname, entry->forHeadLineno);
+               } else {
+                       int lineno =
+                           i + 1 < n && entries[i + 1].forLoop != NULL
+                               ? entries[i + 1].forHeadLineno
+                               : entry->lineno;
+                       debug_printf("\tin %s:%d\n", fname, lineno);
+               }
        }
 }
 
diff -r 9d9c801ed011 -r 261ddf21f630 usr.bin/make/unit-tests/include-main.exp
--- a/usr.bin/make/unit-tests/include-main.exp  Sat Jan 08 23:30:41 2022 +0000
+++ b/usr.bin/make/unit-tests/include-main.exp  Sat Jan 08 23:41:43 2022 +0000
@@ -7,7 +7,8 @@
        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 .include from include-main.mk:27
+       in include-sub.mk:29
+       in include-main.mk:27
 Parsing line 6: .MAKEFLAGS: -d0
 ParseDependency(.MAKEFLAGS: -d0)
 make: "include-sub.mk" line 38: sub-after-ok
diff -r 9d9c801ed011 -r 261ddf21f630 usr.bin/make/unit-tests/include-main.mk
--- a/usr.bin/make/unit-tests/include-main.mk   Sat Jan 08 23:30:41 2022 +0000
+++ b/usr.bin/make/unit-tests/include-main.mk   Sat Jan 08 23:41:43 2022 +0000
@@ -1,11 +1,11 @@
-# $NetBSD: include-main.mk,v 1.6 2021/01/22 00:44:55 rillig Exp $
+# $NetBSD: include-main.mk,v 1.7 2022/01/08 23:41:43 rillig Exp $
 #
 # Until 2020-09-05, the .INCLUDEDFROMFILE magic variable did not behave
 # as described in the manual page.
 #
 # The manual page says that it is the "filename of the file this Makefile
 # was included from", while before 2020-09-05 it was the "filename in which
-# the latest .include happened". See parse.c, function ParseSetIncludeFile.
+# the latest .include happened". See parse.c, function SetParseFile.
 #
 # Since 2020-09-05, the .INCLUDEDFROMDIR and .INCLUDEDFROMFILE variables
 # properly handle nested includes and even .for loops.
diff -r 9d9c801ed011 -r 261ddf21f630 usr.bin/make/unit-tests/include-sub.mk
--- a/usr.bin/make/unit-tests/include-sub.mk    Sat Jan 08 23:30:41 2022 +0000
+++ b/usr.bin/make/unit-tests/include-sub.mk    Sat Jan 08 23:41:43 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: include-sub.mk,v 1.8 2022/01/07 13:56:09 rillig Exp $
+# $NetBSD: include-sub.mk,v 1.9 2022/01/08 23:41:43 rillig Exp $
 
 .if ${.INCLUDEDFROMFILE} == "include-main.mk"
 .  info sub-before-ok
@@ -20,7 +20,7 @@
 # To see the variable 'includes' in action:
 #
 # Breakpoints:
-#      Parse_File              at "Vector_Push(&includes)"
+#      Parse_PushInput         at "Vector_Push(&includes)"
 #      HandleMessage           at entry
 # Watches:
 #      ((const IncludedFile *[10])(*includes.items))
diff -r 9d9c801ed011 -r 261ddf21f630 usr.bin/make/unit-tests/opt-debug-parse.exp
--- a/usr.bin/make/unit-tests/opt-debug-parse.exp       Sat Jan 08 23:30:41 2022 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-parse.exp       Sat Jan 08 23:41:43 2022 +0000
@@ -1,16 +1,17 @@
-Parse_PushInput: .for loop in opt-debug-parse.mk, line 13
+Parse_PushInput: .for loop in opt-debug-parse.mk, line 16
 SetFilenameVars: ${.PARSEDIR} = `<curdir>' ${.PARSEFILE} = `opt-debug-parse.mk'
-Parsing line 17: .info trace with multi-line .for loop head
-make: "opt-debug-parse.mk" line 17: trace with multi-line .for loop head
-       in .include from opt-debug-parse.mk:18
-ParseEOF: returning to file opt-debug-parse.mk, line 19
+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 opt-debug-parse.mk:16
+ParseEOF: returning to file opt-debug-parse.mk, line 22
 SetFilenameVars: ${.PARSEDIR} = `<curdir>' ${.PARSEFILE} = `opt-debug-parse.mk'
-Parsing line 24: .include "/dev/null"
+Parsing line 25: .include "/dev/null"
 Parse_PushInput: file /dev/null, line 1
 SetFilenameVars: ${.PARSEDIR} = `/dev' ${.PARSEFILE} = `null'
 SetFilenameVars: ${.INCLUDEDFROMDIR} = `<curdir>' ${.INCLUDEDFROMFILE} = `opt-debug-parse.mk'
-ParseEOF: returning to file opt-debug-parse.mk, line 25
+ParseEOF: returning to file opt-debug-parse.mk, line 26
 SetFilenameVars: ${.PARSEDIR} = `<curdir>' ${.PARSEFILE} = `opt-debug-parse.mk'
-Parsing line 26: .MAKEFLAGS: -d0
+Parsing line 27: .MAKEFLAGS: -d0
 ParseDependency(.MAKEFLAGS: -d0)
 exit status 0
diff -r 9d9c801ed011 -r 261ddf21f630 usr.bin/make/unit-tests/opt-debug-parse.mk
--- a/usr.bin/make/unit-tests/opt-debug-parse.mk        Sat Jan 08 23:30:41 2022 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-parse.mk        Sat Jan 08 23:41:43 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: opt-debug-parse.mk,v 1.4 2022/01/08 22:24:20 rillig Exp $
+# $NetBSD: opt-debug-parse.mk,v 1.5 2022/01/08 23:41:43 rillig Exp $
 #
 # Tests for the -dp command line option, which adds debug logging about
 # makefile parsing.
@@ -7,17 +7,18 @@
 
 # TODO: Implementation
 
-# In PrintStackTrace, the line number of the .for loop is wrong.  The actual
-# line number printed is the last line before the loop body, while it should
-# rather be the line number where the .for loop starts.
+# Before parse.c 1.639 from 2022-01-08, PrintStackTrace and other diagnostics
+# printed a wrong line number, using the last line before the loop body, while
+# it should rather be the line number where the .for loop starts.
+#
+# Before parse.c 1.643 from 2022-01-08, PrintStackTrace tried to be too clever
+# by merging stack trace entries, printing confusing line numbers as a result.
 .for \
     var \
     in \
     value
 .info trace with multi-line .for loop head
 .endfor
-# FIXME: The .exp file says 'in .include from opt-debug-parse.mk:18', which is
-# completely wrong.  It should rather say 'in .for loop from :13'.
 
 # Before parse.c 1.461 from 2022-01-08, the debug log said it returned to
 # the line of the '.include' instead of the line following it.



Home | Main Index | Thread Index | Old Index