[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Add --trace-variable=VAR as makefile debugging aid
From: |
Luke Diamand |
Subject: |
[PATCH] Add --trace-variable=VAR as makefile debugging aid |
Date: |
Sat, 20 Jun 2015 13:58:29 +0100 |
Add a debugging option for reporting where a make variable is
assigned to.
Signed-off-by: Luke Diamand <address@hidden>
---
doc/make.texi | 8 +++++++-
main.c | 6 ++++++
make.1 | 3 +++
variable.c | 5 +++++
variable.h | 1 +
5 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/doc/make.texi b/doc/make.texi
index b0f5af7..18c1429 100644
--- a/doc/make.texi
+++ b/doc/make.texi
@@ -8902,8 +8902,14 @@ imagination of @code{make}.
Issue a warning message whenever @code{make} sees a reference to an
undefined variable. This can be helpful when you are trying to debug
makefiles which use variables in complex ways.
address@hidden table
address@hidden address@hidden
address@hidden @code{--trace-variable}
address@hidden variables, tracing assignment
+Trace assignments to the specified variable, reporting the filename
+and line number, and the new value of the variable.
+
address@hidden table
@node Implicit Rules, Archives, Running, Top
@chapter Using Implicit Rules
@cindex implicit rule
diff --git a/main.c b/main.c
index c2d4a0c..f2e07e8 100644
--- a/main.c
+++ b/main.c
@@ -280,6 +280,9 @@ int job_rfd = -1;
char *sync_mutex = 0;
+/* Trace assignments to this variable. */
+char *trace_variable = 0;
+
/* Maximum load average at which multiple jobs will be run.
Negative values mean unlimited, while zero means limit to
zero load (which could be useful to start infinite jobs remotely
@@ -418,6 +421,8 @@ static const char *const usage[] =
Consider FILE to be infinitely new.\n"),
N_("\
--warn-undefined-variables Warn when an undefined variable is
referenced.\n"),
+ N_("\
+ --trace-variable=VARIABLE Trace assignments to VARIABLE\n"),
NULL
};
@@ -481,6 +486,7 @@ static const struct command_switch switches[] =
"warn-undefined-variables" },
{ CHAR_MAX+6, strlist, &eval_strings, 1, 0, 0, 0, 0, "eval" },
{ CHAR_MAX+7, string, &sync_mutex, 1, 1, 0, 0, 0, "sync-mutex" },
+ { CHAR_MAX+8, string, &trace_variable, 1, 1, 0, 0, 0, "trace-variable" },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
diff --git a/make.1 b/make.1
index ed04db9..033eacc 100644
--- a/make.1
+++ b/make.1
@@ -332,6 +332,9 @@ except that the modification time is changed only in the
imagination of
.TP 0.5i
.B \-\-warn\-undefined\-variables
Warn when an undefined variable is referenced.
+.TP 0.5i
+.B \-\-trace\-variable=VARIABLE
+Trace assignments to the given variable.
.SH "EXIT STATUS"
GNU
.B make
diff --git a/variable.c b/variable.c
index 0b89d37..9e4b920 100644
--- a/variable.c
+++ b/variable.c
@@ -199,6 +199,11 @@ define_variable_in_set (const char *name, unsigned int
length,
struct variable **var_slot;
struct variable var_key;
+ if (trace_variable &&
+ !strcmp(name, trace_variable))
+ printf (_("%s:%d: setting %s to %s\n"),
+ flocp->filenm, flocp->lineno, name, value);
+
if (set == NULL)
set = &global_variable_set;
diff --git a/variable.h b/variable.h
index fa2dbbd..a626525 100644
--- a/variable.h
+++ b/variable.h
@@ -110,6 +110,7 @@ struct pattern_var
extern char *variable_buffer;
extern struct variable_set_list *current_variable_set_list;
extern struct variable *default_goal_var;
+extern char *trace_variable;
/* expand.c */
char *variable_buffer_output (char *ptr, const char *string, unsigned int
length);
--
2.4.4.598.gd7bed1d