Back to home page

OSCL-LXR

 
 

    


0001 /* ******************************************************************
0002  * debug
0003  * Part of FSE library
0004  * Copyright (c) Yann Collet, Facebook, Inc.
0005  *
0006  * You can contact the author at :
0007  * - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
0008  *
0009  * This source code is licensed under both the BSD-style license (found in the
0010  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
0011  * in the COPYING file in the root directory of this source tree).
0012  * You may select, at your option, one of the above-listed licenses.
0013 ****************************************************************** */
0014 
0015 
0016 /*
0017  * The purpose of this header is to enable debug functions.
0018  * They regroup assert(), DEBUGLOG() and RAWLOG() for run-time,
0019  * and DEBUG_STATIC_ASSERT() for compile-time.
0020  *
0021  * By default, DEBUGLEVEL==0, which means run-time debug is disabled.
0022  *
0023  * Level 1 enables assert() only.
0024  * Starting level 2, traces can be generated and pushed to stderr.
0025  * The higher the level, the more verbose the traces.
0026  *
0027  * It's possible to dynamically adjust level using variable g_debug_level,
0028  * which is only declared if DEBUGLEVEL>=2,
0029  * and is a global variable, not multi-thread protected (use with care)
0030  */
0031 
0032 #ifndef DEBUG_H_12987983217
0033 #define DEBUG_H_12987983217
0034 
0035 
0036 
0037 /* static assert is triggered at compile time, leaving no runtime artefact.
0038  * static assert only works with compile-time constants.
0039  * Also, this variant can only be used inside a function. */
0040 #define DEBUG_STATIC_ASSERT(c) (void)sizeof(char[(c) ? 1 : -1])
0041 
0042 
0043 /* DEBUGLEVEL is expected to be defined externally,
0044  * typically through compiler command line.
0045  * Value must be a number. */
0046 #ifndef DEBUGLEVEL
0047 #  define DEBUGLEVEL 0
0048 #endif
0049 
0050 
0051 /* recommended values for DEBUGLEVEL :
0052  * 0 : release mode, no debug, all run-time checks disabled
0053  * 1 : enables assert() only, no display
0054  * 2 : reserved, for currently active debug path
0055  * 3 : events once per object lifetime (CCtx, CDict, etc.)
0056  * 4 : events once per frame
0057  * 5 : events once per block
0058  * 6 : events once per sequence (verbose)
0059  * 7+: events at every position (*very* verbose)
0060  *
0061  * It's generally inconvenient to output traces > 5.
0062  * In which case, it's possible to selectively trigger high verbosity levels
0063  * by modifying g_debug_level.
0064  */
0065 
0066 #if (DEBUGLEVEL>=1)
0067 #  define ZSTD_DEPS_NEED_ASSERT
0068 #  include "zstd_deps.h"
0069 #else
0070 #  ifndef assert   /* assert may be already defined, due to prior #include <assert.h> */
0071 #    define assert(condition) ((void)0)   /* disable assert (default) */
0072 #  endif
0073 #endif
0074 
0075 #if (DEBUGLEVEL>=2)
0076 #  define ZSTD_DEPS_NEED_IO
0077 #  include "zstd_deps.h"
0078 extern int g_debuglevel; /* the variable is only declared,
0079                             it actually lives in debug.c,
0080                             and is shared by the whole process.
0081                             It's not thread-safe.
0082                             It's useful when enabling very verbose levels
0083                             on selective conditions (such as position in src) */
0084 
0085 #  define RAWLOG(l, ...) {                                       \
0086                 if (l<=g_debuglevel) {                           \
0087                     ZSTD_DEBUG_PRINT(__VA_ARGS__);               \
0088             }   }
0089 #  define DEBUGLOG(l, ...) {                                     \
0090                 if (l<=g_debuglevel) {                           \
0091                     ZSTD_DEBUG_PRINT(__FILE__ ": " __VA_ARGS__); \
0092                     ZSTD_DEBUG_PRINT(" \n");                     \
0093             }   }
0094 #else
0095 #  define RAWLOG(l, ...)      {}    /* disabled */
0096 #  define DEBUGLOG(l, ...)    {}    /* disabled */
0097 #endif
0098 
0099 
0100 
0101 #endif /* DEBUG_H_12987983217 */