CMake: Reverse debug macros

Originally WS_DISABLE_DEBUG was chosen to be
similar to G_DISABLE_ASSERT and NDEBUG.

However generator expressions are essential for modern CMake
but the syntax is weird and having to use negations makes it
ten-fold worse.

Remove the negation. Instead of changing the CMake variable
reverse the macro definition for WS_DISABLE_DEBUG.

The $<CONFIG:cgs> generator expression with multiple config arguments
requires CMake >= 3.19 so we can't use that yet for a further
syntactical simplification.
This commit is contained in:
João Valverde 2023-01-09 12:58:45 +00:00
parent 25d4a099f7
commit 4c9b0d846c
10 changed files with 36 additions and 37 deletions

View File

@ -457,8 +457,8 @@ set_property(DIRECTORY
PROPERTY COMPILE_DEFINITIONS PROPERTY COMPILE_DEFINITIONS
"G_DISABLE_DEPRECATED" "G_DISABLE_DEPRECATED"
"G_DISABLE_SINGLE_INCLUDES" "G_DISABLE_SINGLE_INCLUDES"
$<$<OR:$<NOT:$<BOOL:${ENABLE_DEBUG}>>,$<CONFIG:Release>>:WS_DISABLE_DEBUG> $<$<OR:$<BOOL:${ENABLE_DEBUG}>,$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:WS_DEBUG>
$<$<OR:$<BOOL:${ENABLE_DEBUG_MBS}>,$<CONFIG:Debug>>:WS_DEBUG_UTF_8> $<$<OR:$<BOOL:${ENABLE_DEBUG_UTF_8}>,$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:WS_DEBUG_UTF_8>
) )
if(WIN32) if(WIN32)

View File

@ -52,8 +52,10 @@ option(BUILD_mmdbresolve "Build MaxMind DB resolver" ON)
option(BUILD_fuzzshark "Build fuzzshark" OFF) option(BUILD_fuzzshark "Build fuzzshark" OFF)
option(ENABLE_WERROR "Treat warnings as errors" ON) option(ENABLE_WERROR "Treat warnings as errors" ON)
option(ENABLE_DEBUG "Enable debug code" ON) # Debugging is enabled for "Debug" and "RelWithDebInfo" build types.
option(ENABLE_DEBUG_MBS "Enable extra debug checks for detecting invalid multibyte (UTF-8) strings" OFF) option(ENABLE_DEBUG "Enable debugging for all build configurations" OFF)
# UTF-8 debugging is enabled for "Debug" and "RelWithDebInfo" build types.
option(ENABLE_DEBUG_UTF_8 "Enable UTF-8 sanity checks for all build configurations" OFF)
option(ENABLE_DEBUG_A2W "Enable line directive from .cnf file" OFF) option(ENABLE_DEBUG_A2W "Enable line directive from .cnf file" OFF)
option(ENABLE_CCACHE "Speed up compiling and linking using ccache if possible" OFF) option(ENABLE_CCACHE "Speed up compiling and linking using ccache if possible" OFF)

View File

@ -17,16 +17,16 @@
/******************************************************************************/ /******************************************************************************/
/* Debug section: internal function to print debug information */ /* Debug section: internal function to print debug information */
/* */ /* */
#ifndef WS_DISABLE_DEBUG #ifdef WS_DEBUG
#define DEBUG_DUMP(name, ptr, size, level) \ #define DEBUG_DUMP(name, ptr, size, level) \
ws_log_buffer_full(WS_LOG_DOMAIN, level, __FILE__, __LINE__, G_STRFUNC, ptr, size, 72, name); ws_log_buffer_full(WS_LOG_DOMAIN, level, __FILE__, __LINE__, G_STRFUNC, ptr, size, 72, name);
#else /* defined WS_DISABLE_DEBUG */ #else /* defined WS_DEBUG */
#define DEBUG_DUMP(name, ptr, size, level) #define DEBUG_DUMP(name, ptr, size, level)
#endif /* ?defined WS_DISABLE_DEBUG */ #endif /* ?defined WS_DEBUG */
#endif /* ?defined _DOT11DECRYPT_DEBUG_H */ #endif /* ?defined _DOT11DECRYPT_DEBUG_H */

View File

@ -150,7 +150,7 @@ dfilter_log_full(const char *domain, enum ws_log_level level,
const char *file, long line, const char *func, const char *file, long line, const char *func,
dfilter_t *dfcode, const char *msg); dfilter_t *dfcode, const char *msg);
#ifndef WS_DISABLE_DEBUG #ifdef WS_DEBUG
#define dfilter_log(dfcode, msg) \ #define dfilter_log(dfcode, msg) \
dfilter_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_NOISY, \ dfilter_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_NOISY, \
__FILE__, __LINE__, __func__, \ __FILE__, __LINE__, __func__, \

View File

@ -190,11 +190,7 @@ log_test_full(enum ws_log_level level,
const char *file, int line, const char *func, const char *file, int line, const char *func,
stnode_t *node, const char *msg); stnode_t *node, const char *msg);
#ifdef WS_DISABLE_DEBUG #ifdef WS_DEBUG
#define log_node(node) (void)0;
#define log_test(node) (void)0;
#define LOG_NODE(node) (void)0;
#else
#define log_node(node) \ #define log_node(node) \
log_node_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node) log_node_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node)
#define log_test(node) \ #define log_test(node) \
@ -206,6 +202,10 @@ log_test_full(enum ws_log_level level,
else \ else \
log_node(node); \ log_node(node); \
} while (0) } while (0)
#else
#define log_node(node) (void)0
#define log_test(node) (void)0
#define LOG_NODE(node) (void)0
#endif #endif
char * char *
@ -214,9 +214,7 @@ dump_syntax_tree_str(stnode_t *root);
void void
log_syntax_tree(enum ws_log_level, stnode_t *root, const char *msg, char **cache_ptr); log_syntax_tree(enum ws_log_level, stnode_t *root, const char *msg, char **cache_ptr);
#ifdef WS_DISABLE_DEBUG #ifdef WS_DEBUG
#define ws_assert_magic(obj, mnum) (void)0
#else
#define ws_assert_magic(obj, mnum) \ #define ws_assert_magic(obj, mnum) \
do { \ do { \
ws_assert(obj); \ ws_assert(obj); \
@ -228,6 +226,8 @@ log_syntax_tree(enum ws_log_level, stnode_t *root, const char *msg, char **cache
(obj)->magic, (mnum)); \ (obj)->magic, (mnum)); \
} \ } \
} while(0) } while(0)
#else
#define ws_assert_magic(obj, mnum) (void)0
#endif #endif
#endif /* SYNTAX_TREE_H */ #endif /* SYNTAX_TREE_H */

View File

@ -583,10 +583,7 @@ proto_init(GSList *register_all_plugin_protocols_list,
register_type_length_mismatch(); register_type_length_mismatch();
register_number_string_decodinws_error(); register_number_string_decodinws_error();
register_string_errors(); register_string_errors();
#ifndef WS_DISABLE_DEBUG
ftypes_register_pseudofields(); ftypes_register_pseudofields();
#endif
/* Have each built-in dissector register its protocols, fields, /* Have each built-in dissector register its protocols, fields,
dissector tables, and dissectors to be called through a dissector tables, and dissectors to be called through a

View File

@ -207,10 +207,10 @@ get_compiled_version_info(gather_feature_func gather_compile)
g_string_append(str, ", without binary plugins"); g_string_append(str, ", without binary plugins");
#endif #endif
#ifdef WS_DISABLE_DEBUG #ifdef WS_DEBUG
g_string_append(str, ", release build (");
#else
g_string_append(str, ", debug build ("); g_string_append(str, ", debug build (");
#else
g_string_append(str, ", release build (");
#endif #endif
#ifdef WS_DEBUG_UTF_8 #ifdef WS_DEBUG_UTF_8

View File

@ -15,10 +15,10 @@
#include <glib.h> #include <glib.h>
#ifdef WS_DISABLE_DEBUG #ifdef WS_DEBUG
#define ASSERT(...) (void)0
#else
#define ASSERT(...) g_assert(__VA_ARGS__) #define ASSERT(...) g_assert(__VA_ARGS__)
#else
#define ASSERT(...) (void)0
#endif /* WS_DISABLE_DEBUG */ #endif /* WS_DISABLE_DEBUG */
#endif /* __WMEM_INT_H__ */ #endif /* __WMEM_INT_H__ */

View File

@ -16,10 +16,10 @@
#include <string.h> #include <string.h>
#include <wsutil/wslog.h> #include <wsutil/wslog.h>
#ifdef WS_DISABLE_DEBUG #ifdef WS_DEBUG
#define _ASSERT_ENABLED false
#else
#define _ASSERT_ENABLED true #define _ASSERT_ENABLED true
#else
#define _ASSERT_ENABLED false
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
@ -27,9 +27,9 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* /*
* We don't want to execute the expression with WS_DISABLE_DEBUG because * We don't want to execute the expression with !WS_DEBUG because
* it might be time and space costly and the goal here is to optimize for * it might be time and space costly and the goal here is to optimize for
* WS_DISABLE_DEBUG. However removing it completely is not good enough * !WS_DEBUG. However removing it completely is not good enough
* because it might generate many unused variable warnings. So we use * because it might generate many unused variable warnings. So we use
* if (false) and let the compiler optimize away the dead execution branch. * if (false) and let the compiler optimize away the dead execution branch.
*/ */
@ -40,7 +40,7 @@ extern "C" {
} while (0) } while (0)
/* /*
* ws_abort_if_fail() is not conditional on WS_DISABLE_DEBUG. * ws_abort_if_fail() is not conditional on WS_DEBUG.
* Usually used to appease a static analyzer. * Usually used to appease a static analyzer.
*/ */
#define ws_abort_if_fail(expr) \ #define ws_abort_if_fail(expr) \
@ -48,7 +48,7 @@ extern "C" {
/* /*
* ws_assert() cannot produce side effects, otherwise code will * ws_assert() cannot produce side effects, otherwise code will
* behave differently because of WS_DISABLE_DEBUG, and probably introduce * behave differently because of WS_DEBUG, and probably introduce
* some difficult to track bugs. * some difficult to track bugs.
*/ */
#define ws_assert(expr) \ #define ws_assert(expr) \
@ -70,7 +70,7 @@ extern "C" {
} while (0) } while (0)
/* /*
* We don't want to disable ws_assert_not_reached() with WS_DISABLE_DEBUG. * We don't want to disable ws_assert_not_reached() with WS_DEBUG.
* That would blast compiler warnings everywhere for no benefit, not * That would blast compiler warnings everywhere for no benefit, not
* even a miniscule performance gain. Reaching this function is always * even a miniscule performance gain. Reaching this function is always
* a programming error and will unconditionally abort execution. * a programming error and will unconditionally abort execution.

View File

@ -30,10 +30,10 @@
#define _LOG_DOMAIN "" #define _LOG_DOMAIN ""
#endif #endif
#ifdef WS_DISABLE_DEBUG #ifdef WS_DEBUG
#define _LOG_DEBUG_ENABLED false
#else
#define _LOG_DEBUG_ENABLED true #define _LOG_DEBUG_ENABLED true
#else
#define _LOG_DEBUG_ENABLED false
#endif #endif
/* /*
@ -308,7 +308,7 @@ void ws_log_fatal_full(const char *domain, enum ws_log_level level,
/* /*
* The if condition avoids -Wunused warnings for variables used only with * The if condition avoids -Wunused warnings for variables used only with
* !WS_DISABLE_DEBUG, typically inside a ws_debug() call. The compiler will * WS_DEBUG, typically inside a ws_debug() call. The compiler will
* optimize away the dead execution branch. * optimize away the dead execution branch.
*/ */
#define _LOG_IF_ACTIVE(active, level, file, line, func, ...) \ #define _LOG_IF_ACTIVE(active, level, file, line, func, ...) \