Module Name: src
Committed By: rillig
Date: Sat Jan 8 23:41:43 UTC 2022
Modified Files:
src/usr.bin/make: parse.c
src/usr.bin/make/unit-tests: include-main.exp include-main.mk
include-sub.mk opt-debug-parse.exp opt-debug-parse.mk
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.642 -r1.643 src/usr.bin/make/parse.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/include-main.exp \
src/usr.bin/make/unit-tests/include-sub.mk
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/include-main.mk
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/opt-debug-parse.exp
cvs rdiff -u -r1.4 -r1.5 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/parse.c
diff -u src/usr.bin/make/parse.c:1.642 src/usr.bin/make/parse.c:1.643
--- src/usr.bin/make/parse.c:1.642 Sat Jan 8 22:42:27 2022
+++ src/usr.bin/make/parse.c Sat Jan 8 23:41:43 2022
@@ -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 @@ PrintStackTrace(void)
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 @@ PrintStackTrace(void)
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);
+ }
}
}
Index: src/usr.bin/make/unit-tests/include-main.exp
diff -u src/usr.bin/make/unit-tests/include-main.exp:1.8 src/usr.bin/make/unit-tests/include-main.exp:1.9
--- src/usr.bin/make/unit-tests/include-main.exp:1.8 Tue Dec 28 15:49:00 2021
+++ src/usr.bin/make/unit-tests/include-main.exp Sat Jan 8 23:41:43 2022
@@ -7,7 +7,8 @@ make: "include-subsub.mk" line 5: subsub
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
Index: src/usr.bin/make/unit-tests/include-sub.mk
diff -u src/usr.bin/make/unit-tests/include-sub.mk:1.8 src/usr.bin/make/unit-tests/include-sub.mk:1.9
--- src/usr.bin/make/unit-tests/include-sub.mk:1.8 Fri Jan 7 13:56:09 2022
+++ src/usr.bin/make/unit-tests/include-sub.mk Sat Jan 8 23:41:43 2022
@@ -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))
Index: src/usr.bin/make/unit-tests/include-main.mk
diff -u src/usr.bin/make/unit-tests/include-main.mk:1.6 src/usr.bin/make/unit-tests/include-main.mk:1.7
--- src/usr.bin/make/unit-tests/include-main.mk:1.6 Fri Jan 22 00:44:55 2021
+++ src/usr.bin/make/unit-tests/include-main.mk Sat Jan 8 23:41:43 2022
@@ -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.
Index: src/usr.bin/make/unit-tests/opt-debug-parse.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-parse.exp:1.5 src/usr.bin/make/unit-tests/opt-debug-parse.exp:1.6
--- src/usr.bin/make/unit-tests/opt-debug-parse.exp:1.5 Sat Jan 8 22:24:20 2022
+++ src/usr.bin/make/unit-tests/opt-debug-parse.exp Sat Jan 8 23:41:43 2022
@@ -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
Index: src/usr.bin/make/unit-tests/opt-debug-parse.mk
diff -u src/usr.bin/make/unit-tests/opt-debug-parse.mk:1.4 src/usr.bin/make/unit-tests/opt-debug-parse.mk:1.5
--- src/usr.bin/make/unit-tests/opt-debug-parse.mk:1.4 Sat Jan 8 22:24:20 2022
+++ src/usr.bin/make/unit-tests/opt-debug-parse.mk Sat Jan 8 23:41:43 2022
@@ -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.