diff macro.c @ 199:1d2bad7151f9

Add a -debuglog option to send an execution trace to a file. Intended to be used when debugging imake templates and other complex input, not for debugging tradcpp itself.
author David A. Holland
date Sun, 04 Sep 2016 17:14:42 -0400
parents 255db24bc29b
children 3a25180d3a5c
line wrap: on
line diff
--- a/macro.c	Sat Dec 05 18:08:24 2015 -0500
+++ b/macro.c	Sun Sep 04 17:14:42 2016 -0400
@@ -876,6 +876,7 @@
 expand_domacro(struct expstate *es, struct place *p)
 {
 	struct macro *m;
+	const char *name, *val;
 	char *newbuf, *newbuf2;
 
 	if (es->curmacro == NULL) {
@@ -886,8 +887,11 @@
 			expand_send(es, p, "0", 1);
 			return;
 		}
-		m = macrotable_find(stringarray_get(&es->args, 0), false);
-		expand_send(es, p, (m != NULL) ? "1" : "0", 1);
+		name = stringarray_get(&es->args, 0);
+		m = macrotable_find(name, false);
+		val = (m != NULL) ? "1" : "0";
+		debuglog(p, "defined(%s): %s", name, val); 
+		expand_send(es, p, val, 1);
 		expstate_destroyargs(es);
 		return;
 	}
@@ -896,10 +900,15 @@
 	assert(m->inuse == false);
 	m->inuse = true;
 
+	debuglog(p, "Expanding macro %s", m->name);
 	newbuf = expand_substitute(p, es);
+	debuglog(p, "Substituting for %s: %s", m->name, newbuf);
+
 	newbuf2 = macroexpand(p, newbuf, strlen(newbuf), false);
 	dostrfree(newbuf);
 	expstate_destroyargs(es);
+	debuglog(p, "Complete expansion for %s: %s", m->name, newbuf2);
+
 	doexpand(es, p, newbuf2, strlen(newbuf2));
 	dostrfree(newbuf2);