28
28
#include <QtGlobal>
30
#include "kvi_sysconfig.h"
31
33
* \file kvi_debug.h
32
34
* \author Szymon Stefanek
33
35
* \brief This file contains the definition of the debug macros;
34
* You can enable ALL the debugging output by uncommenting the line that defines _KVI_DEBUG_CHECK_RANGE_
37
//=============================================================================
39
// You can enable ALL the debugging output by uncommenting the next line
40
// #define _KVI_DEBUG_CHECK_RANGE_
42
//=============================================================================
47
* \def __range_valid Assert that ensures that its parameter is true
48
* \def __range_invalid Assert that ensures that its parameter is false
49
* \def __ASSERT Assert that ensures that its parameter is true; enabled only if _KVI_DEBUG_or __KVI_DEBUG__ is defined
53
#ifdef _KVI_DEBUG_CHECK_RANGE_
54
#define __range_valid(_expr) if(!(_expr))debug("[kvirc]: ASSERT FAILED: \"%s\" is false in %s (%d)",#_expr,__FILE__,__LINE__)
55
#define __range_invalid(_expr) if(_expr)debug("[kvirc]: ASSERT FAILED: \"%s\" is true in %s (%d)",#_expr,__FILE__,__LINE__)
57
#define __range_valid(_expr)
58
#define __range_invalid(_expr)
61
#if defined(_KVI_DEBUG_) || defined(__KVI_DEBUG__)
62
#define __ASSERT(_expr) if(!(_expr))debug("[kvirc]: ASSERT FAILED: \"%s\" is false in %s (%d)",#_expr,__FILE__,__LINE__)
64
#define __ASSERT(_expr)
38
#include <stdlib.h> // abort
42
#define kvi_debug(fmt,arg...) qDebug(fmt,##arg)
43
#define kvi_warning(fmt,arg...) qWarning(fmt,##arg)
44
#define kvi_fatal(fmt,arg...) do { qFatal(fmt,##arg); abort(); } while(0)
45
#define KVI_PRETTY_FUNCTION __PRETTY_FUNCTION__
51
#define kvi_debug(fmt,...) qDebug(fmt,__VA_ARGS__)
52
#define kvi_warning(fmt,...) qWarning(fmt,__VA_ARGS__)
53
#define kvi_fatal(fmt,...) do { qFatal(fmt,__VA_ARGS__); abort(); } while(0)
54
#define KVI_PRETTY_FUNCTION __FUNCTION__
58
#ifdef COMPILE_DEBUG_MODE
60
#define KVI_ASSERT(__condition__) \
62
if(!(__condition__)) \
63
qFatal("[ASSERT FAILED] (" # __condition__ ") in %s at %s:%u",KVI_PRETTY_FUNCTION,__FILE__,__LINE__); \
66
#define KVI_ASSERT_MSG(__condition__,__message__) \
68
if(!(__condition__)) \
70
qFatal("[ASSERT FAILED] (" # __condition__ ") in %s at %s:%u",KVI_PRETTY_FUNCTION,__FILE__,__LINE__); \
71
qFatal("[ASSERT FAILED] " __message__); \
75
#include "KviDebugContext.h"
77
// The following two macros are used to create unique variable names
78
// by the means of the __LINE__ builtin macro.
79
// The ## token paste operator must be called inside a macro and must
80
// preceede a macro parameter. This is why we can't use directly
82
// #define UNIQUEVARIABLE int name ## __LINE__
84
// We need something like
86
// #define PASTE(x,y) x ## y
87
// #define UNIQUEVARIABLE int PASTE(x,__LINE__)
89
// But this doesn't work since the specification of the token pasting operator is
91
// "If a formal parameter in a macro definition is preceded or followed by the token-pasting operator,
92
// the formal parameter is immediately replaced by the __unexpanded__ actual argument. Macro expansion
93
// is __not performed__ on the argument prior to replacement."
95
// So to actually have __LINE__ expanded we need another level of indirection
97
// #define PASTE(x,y) x ## y
98
// #define EXPAND_Y_AND_THEN_PASTE(x,y) PASTE(x,y)
99
// #define UNIQUEVARIABLE int EXPAND_Y_AND_THEN_PASTE(x,__LINE__)
101
#define KVI_TRACE_HACK_TOKENPASTE_2(x,y) x ## y
102
#define KVI_TRACE_HACK_TOKENPASTE_1(x,y) KVI_TRACE_HACK_TOKENPASTE_2(x,y)
105
#define KVI_TRACE_FUNCTION \
106
KviDebugContext KVI_TRACE_HACK_TOKENPASTE_1(ctx,__LINE__)(__PRETTY_FUNCTION__)
108
#define KVI_TRACE_BLOCK(_szBlockDescription) \
109
KviDebugContext KVI_TRACE_HACK_TOKENPASTE_1(ctx,__LINE__)("%s - %s",__PRETTY_FUNCTION__,_szBlockDescription)
111
#define KVI_TRACE(_szFmt,arg...) KviDebugContext::trace(_szFmt,##arg)
114
#define KVI_TRACE_FUNCTION \
115
KviDebugContext KVI_TRACE_HACK_TOKENPASTE_1(ctx,__LINE__)(__FUNCTION__)
117
#define KVI_TRACE_BLOCK(_szBlockDescription) \
118
KviDebugContext KVI_TRACE_HACK_TOKENPASTE_1(ctx,__LINE__)("%s - %s",__FUNCTION__,_szBlockDescription)
120
#define KVI_TRACE(_szFmt,...) KviDebugContext::trace(_szFmt,__VA_ARGS__)
124
#else //!COMPILE_DEBUG_MODE
126
#define KVI_ASSERT(__condition__) do { } while(0)
127
#define KVI_ASSERT_MSG(__condition__,__message__) do { } while(0)
129
#define KVI_TRACE_FUNCTION \
132
#define KVI_TRACE_BLOCK(_szBlockDescription) \
136
#define KVI_TRACE(_szFmt,arg...) do { } while(0)
138
#define KVI_TRACE(_szFmt,...) do { } while(0)
141
#endif //!COMPILE_DEBUG_MODE
67
147
#endif //_KVI_DEBUG_H_