]> granicus.if.org Git - strace/commitdiff
error_prints.h: add debug print macros
authorEugene Syromiatnikov <esyr@redhat.com>
Fri, 4 Aug 2017 06:03:03 +0000 (08:03 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 13 Dec 2017 00:35:31 +0000 (00:35 +0000)
* defs.h (debug_flag): Move the declaration...
* error_prints.h (debug_flag): ... here.
(debug_msg, debug_perror_msg): New macro definitions.
Include <stdbool.h> for the debug_flag declaration.

defs.h
error_prints.h

diff --git a/defs.h b/defs.h
index 0187863ea2307e2ba0ae8c694394fcb0aff67656..867f1f680ba4c4ffe39199db08b5d7db4455dd91 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -355,7 +355,6 @@ typedef enum {
        CFLAG_BOTH
 } cflag_t;
 extern cflag_t cflag;
-extern bool debug_flag;
 extern bool Tflag;
 extern bool iflag;
 extern bool count_wallclock;
index 7ddcb50bedc89ddc8365d4efc1282ed484d0834b..19ecb8f78ab04a2e3e7db4d7c234ebbb99b25d6c 100644 (file)
 #ifndef STRACE_ERROR_PRINTS_H
 #define STRACE_ERROR_PRINTS_H
 
+#include <stdbool.h>
+
 #include "gcc_compat.h"
 
+extern bool debug_flag;
+
 void die(void) ATTRIBUTE_NORETURN;
 
 void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
@@ -46,4 +50,16 @@ void error_msg_and_help(const char *fmt, ...)
 void error_msg_and_die(const char *fmt, ...)
        ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
 
+/* Wrappers for if (debug_flag) error_msg(...) */
+#define debug_msg(...) \
+       do { \
+               if (debug_flag) \
+                       error_msg(__VA_ARGS__); \
+       } while (0)
+#define debug_perror_msg(...) \
+       do { \
+               if (debug_flag) \
+                       perror_msg(__VA_ARGS__); \
+       } while (0)
+
 #endif /* !STRACE_ERROR_PRINTS_H */