From: Eugene Syromiatnikov Date: Fri, 4 Aug 2017 06:03:03 +0000 (+0200) Subject: error_prints.h: add debug print macros X-Git-Tag: v4.21~275 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=859bc3444ca932c04c2715194beda6b0b6af55dc;p=strace error_prints.h: add debug print macros * defs.h (debug_flag): Move the declaration... * error_prints.h (debug_flag): ... here. (debug_msg, debug_perror_msg): New macro definitions. Include for the debug_flag declaration. --- diff --git a/defs.h b/defs.h index 0187863e..867f1f68 100644 --- 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; diff --git a/error_prints.h b/error_prints.h index 7ddcb50b..19ecb8f7 100644 --- a/error_prints.h +++ b/error_prints.h @@ -33,8 +33,12 @@ #ifndef STRACE_ERROR_PRINTS_H #define STRACE_ERROR_PRINTS_H +#include + #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 */