KVIrc
4.9.2
DeveloperAPIs
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
kvilib
config
kvi_debug.h
Go to the documentation of this file.
1
#ifndef _KVI_DEBUG_H_
2
#define _KVI_DEBUG_H_
3
4
//=============================================================================
5
//
6
// File : kvi_debug.h
7
// Creation date : Fri Mar 19 1999 03:10:39 CEST by Szymon Stefanek
8
//
9
// This file is part of the KVIrc IRC client distribution
10
// Copyright (C) 1999-2010 Szymon Stefanek (pragma at kvirc dot net)
11
//
12
// This program is FREE software. You can redistribute it and/or
13
// modify it under the terms of the GNU General Public License
14
// as published by the Free Software Foundation; either version 2
15
// of the License, or (at your option) any later version.
16
//
17
// This program is distributed in the HOPE that it will be USEFUL,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
// See the GNU General Public License for more details.
21
//
22
// You should have received a copy of the GNU General Public License
23
// along with this program. If not, write to the Free Software Foundation,
24
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
//
26
//=============================================================================
27
28
#include <QtGlobal>
29
30
#include "kvi_sysconfig.h"
31
38
#include <stdlib.h>
// abort
39
40
#ifdef __GNUC__
41
42
#define kvi_debug(fmt, arg...) qDebug(fmt, ##arg)
43
#define kvi_warning(fmt, arg...) qWarning(fmt, ##arg)
44
#define kvi_fatal(fmt, arg...) \
45
do \
46
{ \
47
qFatal(fmt, ##arg); \
48
abort(); \
49
} while(0)
50
#define KVI_PRETTY_FUNCTION __PRETTY_FUNCTION__
51
52
#else
53
54
// assume MSVC
55
56
#define kvi_debug(fmt, ...) qDebug(fmt, __VA_ARGS__)
57
#define kvi_warning(fmt, ...) qWarning(fmt, __VA_ARGS__)
58
#define kvi_fatal(fmt, ...) \
59
do \
60
{ \
61
qFatal(fmt, __VA_ARGS__); \
62
abort(); \
63
} while(0)
64
#define KVI_PRETTY_FUNCTION __FUNCTION__
65
66
#endif
67
68
#ifdef COMPILE_DEBUG_MODE
69
70
#define KVI_ASSERT(__condition__) \
71
do \
72
{ \
73
if(!(__condition__)) \
74
qFatal("[ASSERT FAILED] (" #__condition__ ") in %s at %s:%u", KVI_PRETTY_FUNCTION, __FILE__, __LINE__); \
75
} while(0)
76
77
#define KVI_ASSERT_MSG(__condition__, __message__) \
78
do \
79
{ \
80
if(!(__condition__)) \
81
{ \
82
qFatal("[ASSERT FAILED] (" #__condition__ ") in %s at %s:%u", KVI_PRETTY_FUNCTION, __FILE__, __LINE__); \
83
qFatal("[ASSERT FAILED] " __message__); \
84
} \
85
} while(0)
86
87
#include "
KviDebugContext.h
"
88
89
// The following two macros are used to create unique variable names
90
// by the means of the __LINE__ builtin macro.
91
// The ## token paste operator must be called inside a macro and must
92
// precede a macro parameter. This is why we can't use directly
93
//
94
// #define UNIQUEVARIABLE int name ## __LINE__
95
//
96
// We need something like
97
//
98
// #define PASTE(x,y) x ## y
99
// #define UNIQUEVARIABLE int PASTE(x,__LINE__)
100
//
101
// But this doesn't work since the specification of the token pasting operator is
102
//
103
// "If a formal parameter in a macro definition is preceded or followed by the token-pasting operator,
104
// the formal parameter is immediately replaced by the __unexpanded__ actual argument. Macro expansion
105
// is __not performed__ on the argument prior to replacement."
106
//
107
// So to actually have __LINE__ expanded we need another level of indirection
108
//
109
// #define PASTE(x,y) x ## y
110
// #define EXPAND_Y_AND_THEN_PASTE(x,y) PASTE(x,y)
111
// #define UNIQUEVARIABLE int EXPAND_Y_AND_THEN_PASTE(x,__LINE__)
112
113
#define KVI_TRACE_HACK_TOKENPASTE_2(x, y) x##y
114
#define KVI_TRACE_HACK_TOKENPASTE_1(x, y) KVI_TRACE_HACK_TOKENPASTE_2(x, y)
115
116
#ifdef __GNUC__
117
#define KVI_TRACE_FUNCTION \
118
KviDebugContext KVI_TRACE_HACK_TOKENPASTE_1(ctx, __LINE__)(__PRETTY_FUNCTION__)
119
120
#define KVI_TRACE_BLOCK(_szBlockDescription) \
121
KviDebugContext KVI_TRACE_HACK_TOKENPASTE_1(ctx, __LINE__)("%s - %s", __PRETTY_FUNCTION__, _szBlockDescription)
122
123
#define KVI_TRACE(_szFmt, arg...) KviDebugContext::trace(_szFmt, ##arg)
124
125
#else
126
#define KVI_TRACE_FUNCTION \
127
KviDebugContext KVI_TRACE_HACK_TOKENPASTE_1(ctx, __LINE__)(__FUNCTION__)
128
129
#define KVI_TRACE_BLOCK(_szBlockDescription) \
130
KviDebugContext KVI_TRACE_HACK_TOKENPASTE_1(ctx, __LINE__)("%s - %s", __FUNCTION__, _szBlockDescription)
131
132
#define KVI_TRACE(_szFmt, ...) KviDebugContext::trace(_szFmt, __VA_ARGS__)
133
134
#endif
135
136
#else
137
138
#define KVI_ASSERT(__condition__) \
139
do \
140
{ \
141
} while(0)
142
#define KVI_ASSERT_MSG(__condition__, __message__) \
143
do \
144
{ \
145
} while(0)
146
147
#define KVI_TRACE_FUNCTION \
148
do \
149
{ \
150
} while(0)
151
152
#define KVI_TRACE_BLOCK(_szBlockDescription) \
153
do \
154
{ \
155
} while(0)
156
157
#ifdef __GNUC__
158
#define KVI_TRACE(_szFmt, arg...) \
159
do \
160
{ \
161
} while(0)
162
#else
163
#define KVI_TRACE(_szFmt, ...) \
164
do \
165
{ \
166
} while(0)
167
#endif
168
169
#endif
170
171
#endif //_KVI_DEBUG_H_
KviDebugContext.h
Debug context.
Generated on Mon May 16 2016 22:48:40 for KVIrc by
1.8.7