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: print stack trace on fatal errors
details: https://anonhg.NetBSD.org/src/rev/6f816710a11a
branches: trunk
changeset: 359876:6f816710a11a
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 29 09:38:26 2022 +0000
description:
make: print stack trace on fatal errors
The only fatal error that occurs while the makefiles are read in is the
one about recursive variables, which didn't give any hint about the
location before.
If a recursive variable is detected while evaluating the commands of a
target to be made, there is no location information, as before.
diffstat:
usr.bin/make/main.c | 5 +++--
usr.bin/make/make.h | 3 ++-
usr.bin/make/parse.c | 18 ++++++++++++------
usr.bin/make/unit-tests/var-recursive.exp | 3 +++
4 files changed, 20 insertions(+), 9 deletions(-)
diffs (115 lines):
diff -r a228857aaa32 -r 6f816710a11a usr.bin/make/main.c
--- a/usr.bin/make/main.c Sat Jan 29 08:20:45 2022 +0000
+++ b/usr.bin/make/main.c Sat Jan 29 09:38:26 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.576 2022/01/27 06:02:59 sjg Exp $ */
+/* $NetBSD: main.c,v 1.577 2022/01/29 09:38:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.576 2022/01/27 06:02:59 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.577 2022/01/29 09:38:26 rillig Exp $");
#if defined(MAKE_NATIVE) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -1828,6 +1828,7 @@
va_end(ap);
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
+ PrintStackTrace(true);
PrintOnError(NULL, "\n");
diff -r a228857aaa32 -r 6f816710a11a usr.bin/make/make.h
--- a/usr.bin/make/make.h Sat Jan 29 08:20:45 2022 +0000
+++ b/usr.bin/make/make.h Sat Jan 29 09:38:26 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.292 2022/01/29 01:07:31 rillig Exp $ */
+/* $NetBSD: make.h,v 1.293 2022/01/29 09:38:26 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -832,6 +832,7 @@
void Parse_Init(void);
void Parse_End(void);
+void PrintStackTrace(bool);
void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE;
void Parse_AddIncludeDir(const char *);
diff -r a228857aaa32 -r 6f816710a11a usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sat Jan 29 08:20:45 2022 +0000
+++ b/usr.bin/make/parse.c Sat Jan 29 09:38:26 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.658 2022/01/29 01:07:31 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.659 2022/01/29 09:38: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.658 2022/01/29 01:07:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.659 2022/01/29 09:38:26 rillig Exp $");
/*
* A file being read.
@@ -348,8 +348,14 @@
return buf; /* may not be null-terminated */
}
-static void
-PrintStackTrace(void)
+/*
+ * Print the current chain of .include and .for directives. In Parse_Fatal
+ * or other functions that already print the location, includingInnermost
+ * would be redundant, but in other cases like Error or Fatal it needs to be
+ * included.
+ */
+void
+PrintStackTrace(bool includingInnermost)
{
const IncludedFile *entries;
size_t i, n;
@@ -359,7 +365,7 @@
if (n == 0)
return;
- if (entries[n - 1].forLoop == NULL)
+ if (!includingInnermost && entries[n - 1].forLoop == NULL)
n--; /* already in the diagnostic */
for (i = n; i-- > 0;) {
@@ -484,7 +490,7 @@
}
if (DEBUG(PARSE))
- PrintStackTrace();
+ PrintStackTrace(false);
}
static void MAKE_ATTR_PRINTFLIKE(4, 5)
diff -r a228857aaa32 -r 6f816710a11a usr.bin/make/unit-tests/var-recursive.exp
--- a/usr.bin/make/unit-tests/var-recursive.exp Sat Jan 29 08:20:45 2022 +0000
+++ b/usr.bin/make/unit-tests/var-recursive.exp Sat Jan 29 09:38:26 2022 +0000
@@ -1,12 +1,15 @@
make: "var-recursive.mk" line 20: still there
Variable DIRECT is recursive.
+ in var-recursive.mk:21
make: stopped in unit-tests
Variable INDIRECT1 is recursive.
+ in var-recursive.mk:28
make: stopped in unit-tests
make: "var-recursive.mk" line 35: ok
Variable V is recursive.
+ in var-recursive.mk:43
make: stopped in unit-tests
exit status 0
Home |
Main Index |
Thread Index |
Old Index