]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Provide a maintainer-only debug method
authorPaul Smith <psmith@gnu.org>
Sun, 23 Oct 2022 22:36:44 +0000 (18:36 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 23 Oct 2022 22:41:50 +0000 (18:41 -0400)
Generating debug logs to stdout or stderr makes it impossible to
run tests etc. so create a dumb DBG facility to log to a temp file.
This exists only in maintainer mode and the DBG macro gives a
compile error if it's used in non-maintainer mode.

* src/makeint.h (DBG): Call dbg() in maintainer mode, else error.
(dbg): Define it in maintainer mode.
* src/misc.c (dbg): Open a log file for append, write, then close.

src/makeint.h
src/misc.c

index f9de63d081aeedf8e532e76bb7370c41d8c49e71..e345011b9e80e6ae915779f852d12144f67b73a4 100644 (file)
@@ -658,8 +658,12 @@ int unload_file (const char *name);
 #ifdef MAKE_MAINTAINER_MODE
 # define SPIN(_s) spin (_s)
 void spin (const char* suffix);
+# define DBG(_f) dbg _f
+void dbg (const char *fmt, ...);
 #else
 # define SPIN(_s)
+/* Never put this code into Git or a release.  */
+# define DBG(_f) compile-error
 #endif
 
 /* We omit these declarations on non-POSIX systems which define _POSIX_VERSION,
index 18728f3531e5cbb0bb1dc042fa2d38e4566e4407..4f52e78c8acbbb2828ebe1edde33a98ffaa6bb3e 100644 (file)
@@ -530,6 +530,22 @@ spin (const char* type)
     }
 }
 
+void
+dbg (const char *fmt, ...)
+{
+  FILE *fp = fopen ("/tmp/gmkdebug.log", "a+");
+  va_list args;
+  char buf[4096];
+
+  va_start (args, fmt);
+  vsprintf (buf, fmt, args);
+  va_end (args);
+
+  fprintf(fp, "%u: %s\n", (unsigned) make_pid (), buf);
+  fflush (fp);
+  fclose (fp);
+}
+
 #endif
 
 \f