1 /* ******************************************************************
4 * Copyright (c) Meta Platforms, Inc. and affiliates.
6 * You can contact the author at :
7 * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
9 * This source code is licensed under both the BSD-style license (found in the
10 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
11 * in the COPYING file in the root directory of this source tree).
12 * You may select, at your option, one of the above-listed licenses.
13 ****************************************************************** */
17 * The purpose of this header is to enable debug functions.
18 * They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
19 * and DEBUG_STATIC_ASSERT() for compile-time.
21 * By default, DEBUGLEVEL==0, which means run-time debug is disabled.
23 * Level 1 enables assert() only.
24 * Starting level 2, traces can be generated and pushed to stderr.
25 * The higher the level, the more verbose the traces.
27 * It's possible to dynamically adjust level using variable g_debug_level,
28 * which is only declared if DEBUGLEVEL>=2,
29 * and is a global variable, not multi-thread protected (use with care)
32 #ifndef DEBUG_H_12987983217
33 #define DEBUG_H_12987983217
35 #if defined (__cplusplus)
40 /* static assert is triggered at compile time, leaving no runtime artefact.
41 * static assert only works with compile-time constants.
42 * Also, this variant can only be used inside a function. */
43 #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
46 /* DEBUGLEVEL is expected to be defined externally,
47 * typically through compiler command line.
48 * Value must be a number. */
54 /* recommended values for DEBUGLEVEL :
55 * 0 : release mode, no debug, all run-time checks disabled
56 * 1 : enables assert() only, no display
57 * 2 : reserved, for currently active debug path
58 * 3 : events once per object lifetime (CCtx, CDict, etc.)
59 * 4 : events once per frame
60 * 5 : events once per block
61 * 6 : events once per sequence (verbose)
62 * 7+: events at every position (*very* verbose)
64 * It's generally inconvenient to output traces > 5.
65 * In which case, it's possible to selectively trigger high verbosity levels
66 * by modifying g_debug_level.
70 # define ZSTD_DEPS_NEED_ASSERT
71 # include "zstd_deps.h"
73 # ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
74 # define assert(condition) ((void)0) /* disable assert (default) */
79 # define ZSTD_DEPS_NEED_IO
80 # include "zstd_deps.h"
81 extern int g_debuglevel; /* the variable is only declared,
82 it actually lives in debug.c,
83 and is shared by the whole process.
85 It's useful when enabling very verbose levels
86 on selective conditions (such as position in src) */
88 # define RAWLOG(l, ...) \
90 if (l<=g_debuglevel) { \
91 ZSTD_DEBUG_PRINT(__VA_ARGS__); \
95 #define STRINGIFY(x) #x
96 #define TOSTRING(x) STRINGIFY(x)
97 #define LINE_AS_STRING TOSTRING(__LINE__)
99 # define DEBUGLOG(l, ...) \
101 if (l<=g_debuglevel) { \
102 ZSTD_DEBUG_PRINT(__FILE__ ":" LINE_AS_STRING ": " __VA_ARGS__); \
103 ZSTD_DEBUG_PRINT(" \n"); \
107 # define RAWLOG(l, ...) do { } while (0) /* disabled */
108 # define DEBUGLOG(l, ...) do { } while (0) /* disabled */
112 #if defined (__cplusplus)
116 #endif /* DEBUG_H_12987983217 */