/* ******************************************************************1* debug2* Part of FSE library3* Copyright (c) Meta Platforms, Inc. and affiliates.4*5* You can contact the author at :6* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy7*8* This source code is licensed under both the BSD-style license (found in the9* LICENSE file in the root directory of this source tree) and the GPLv2 (found10* in the COPYING file in the root directory of this source tree).11* You may select, at your option, one of the above-listed licenses.12****************************************************************** */131415/*16* The purpose of this header is to enable debug functions.17* They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,18* and DEBUG_STATIC_ASSERT() for compile-time.19*20* By default, DEBUGLEVEL==0, which means run-time debug is disabled.21*22* Level 1 enables assert() only.23* Starting level 2, traces can be generated and pushed to stderr.24* The higher the level, the more verbose the traces.25*26* It's possible to dynamically adjust level using variable g_debug_level,27* which is only declared if DEBUGLEVEL>=2,28* and is a global variable, not multi-thread protected (use with care)29*/3031#ifndef DEBUG_H_1298798321732#define DEBUG_H_129879832173334#if defined (__cplusplus)35extern "C" {36#endif373839/* static assert is triggered at compile time, leaving no runtime artefact.40* static assert only works with compile-time constants.41* Also, this variant can only be used inside a function. */42#define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])434445/* DEBUGLEVEL is expected to be defined externally,46* typically through compiler command line.47* Value must be a number. */48#ifndef DEBUGLEVEL49# define DEBUGLEVEL 050#endif515253/* recommended values for DEBUGLEVEL :54* 0 : release mode, no debug, all run-time checks disabled55* 1 : enables assert() only, no display56* 2 : reserved, for currently active debug path57* 3 : events once per object lifetime (CCtx, CDict, etc.)58* 4 : events once per frame59* 5 : events once per block60* 6 : events once per sequence (verbose)61* 7+: events at every position (*very* verbose)62*63* It's generally inconvenient to output traces > 5.64* In which case, it's possible to selectively trigger high verbosity levels65* by modifying g_debug_level.66*/6768#if (DEBUGLEVEL>=1)69# define ZSTD_DEPS_NEED_ASSERT70# include "zstd_deps.h"71#else72# ifndef assert /* assert may be already defined, due to prior #include <assert.h> */73# define assert(condition) ((void)0) /* disable assert (default) */74# endif75#endif7677#if (DEBUGLEVEL>=2)78# define ZSTD_DEPS_NEED_IO79# include "zstd_deps.h"80extern int g_debuglevel; /* the variable is only declared,81it actually lives in debug.c,82and is shared by the whole process.83It's not thread-safe.84It's useful when enabling very verbose levels85on selective conditions (such as position in src) */8687# define RAWLOG(l, ...) { \88if (l<=g_debuglevel) { \89ZSTD_DEBUG_PRINT(__VA_ARGS__); \90} }91# define DEBUGLOG(l, ...) { \92if (l<=g_debuglevel) { \93ZSTD_DEBUG_PRINT(__FILE__ ": " __VA_ARGS__); \94ZSTD_DEBUG_PRINT(" \n"); \95} }96#else97# define RAWLOG(l, ...) {} /* disabled */98# define DEBUGLOG(l, ...) {} /* disabled */99#endif100101102#if defined (__cplusplus)103}104#endif105106#endif /* DEBUG_H_12987983217 */107108109