Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
16 | ** | - |
17 | ** GNU Lesser General Public License Usage | - |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
19 | ** General Public License version 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qlogging.h" | - |
43 | #include "qlist.h" | - |
44 | #include "qbytearray.h" | - |
45 | #include "qstring.h" | - |
46 | #include "qvarlengtharray.h" | - |
47 | #include "qdebug.h" | - |
48 | #include "qmutex.h" | - |
49 | #ifndef QT_BOOTSTRAPPED | - |
50 | #include "qcoreapplication.h" | - |
51 | #include "qthread.h" | - |
52 | #endif | - |
53 | #ifdef Q_OS_WIN | - |
54 | #include <qt_windows.h> | - |
55 | #endif | - |
56 | #ifdef QT_USE_SLOG2 | - |
57 | #include <slog2.h> | - |
58 | #endif | - |
59 | | - |
60 | #include <stdio.h> | - |
61 | | - |
62 | QT_BEGIN_NAMESPACE | - |
63 | | - |
64 | #if !defined(Q_CC_MSVC) | - |
65 | Q_NORETURN | - |
66 | #endif | - |
67 | static void qt_message_fatal(QtMsgType, const QMessageLogContext &context, const QString &message); | - |
68 | static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message); | - |
69 | | - |
70 | static bool isFatal(QtMsgType msgType) | - |
71 | { | - |
72 | if (msgType == QtFatalMsg) partially evaluated: msgType == QtFatalMsg no Evaluation Count:0 | yes Evaluation Count:2146 |
| 0-2146 |
73 | return true; never executed: return true; | 0 |
74 | | - |
75 | if (msgType == QtWarningMsg) { evaluated: msgType == QtWarningMsg yes Evaluation Count:910 | yes Evaluation Count:1236 |
| 910-1236 |
76 | static bool fatalWarnings = qEnvironmentVariableIsSet("QT_FATAL_WARNINGS"); | - |
77 | return fatalWarnings; executed: return fatalWarnings; Execution Count:910 | 910 |
78 | } | - |
79 | | - |
80 | return false; executed: return false; Execution Count:1236 | 1236 |
81 | } | - |
82 | | - |
83 | /*! | - |
84 | \class QMessageLogContext | - |
85 | \inmodule QtCore | - |
86 | \brief The QMessageLogContext class provides additional information about a log message. | - |
87 | \since 5.0 | - |
88 | | - |
89 | The class provides information about the source code location a qDebug(), qWarning(), | - |
90 | qCritical() or qFatal() message was generated. | - |
91 | | - |
92 | \sa QMessageLogger, QtMessageHandler, qInstallMessageHandler() | - |
93 | */ | - |
94 | | - |
95 | /*! | - |
96 | \class QMessageLogger | - |
97 | \inmodule QtCore | - |
98 | \brief The QMessageLogger class generates log messages. | - |
99 | \since 5.0 | - |
100 | | - |
101 | QMessageLogger is used to generate messages for the Qt logging framework. Usually one uses | - |
102 | it through qDebug(), qWarning(), qCritical, or qFatal() functions, | - |
103 | which are actually macros that expand to QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug() | - |
104 | et al. | - |
105 | | - |
106 | One example of direct use is to forward errors that stem from a scripting language, e.g. QML: | - |
107 | | - |
108 | \snippet code/qlogging/qlogging.cpp 1 | - |
109 | | - |
110 | \sa QMessageLogContext, qDebug(), qWarning(), qCritical(), qFatal() | - |
111 | */ | - |
112 | | - |
113 | #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) | - |
114 | // defined in qcoreapplication_win.cpp | - |
115 | extern bool usingWinMain; | - |
116 | #endif | - |
117 | | - |
118 | static inline void convert_to_wchar_t_elided(wchar_t *d, size_t space, const char *s) Q_DECL_NOEXCEPT | - |
119 | { | - |
120 | size_t len = qstrlen(s); never executed (the execution status of this line is deduced): size_t len = qstrlen(s); | - |
121 | if (len + 1 > space) { never evaluated: len + 1 > space | 0 |
122 | const size_t skip = len - space + 4; // 4 for "..." + '\0' never executed (the execution status of this line is deduced): const size_t skip = len - space + 4; | - |
123 | s += skip; never executed (the execution status of this line is deduced): s += skip; | - |
124 | for (int i = 0; i < 3; ++i) | 0 |
125 | *d++ = L'.'; never executed: *d++ = L'.'; | 0 |
126 | } | 0 |
127 | while (*s) | 0 |
128 | *d++ = *s++; never executed: *d++ = *s++; | 0 |
129 | *d++ = 0; never executed (the execution status of this line is deduced): *d++ = 0; | - |
130 | } | 0 |
131 | | - |
132 | #if !defined(QT_NO_EXCEPTIONS) | - |
133 | /*! | - |
134 | \internal | - |
135 | Uses a local buffer to output the message. Not locale safe + cuts off | - |
136 | everything after character 255, but will work in out of memory situations. | - |
137 | Stop the execution afterwards. | - |
138 | */ | - |
139 | static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap) Q_DECL_NOEXCEPT | - |
140 | { | - |
141 | char emergency_buf[256] = { '\0' }; never executed (the execution status of this line is deduced): char emergency_buf[256] = { '\0' }; | - |
142 | emergency_buf[sizeof emergency_buf - 1] = '\0'; never executed (the execution status of this line is deduced): emergency_buf[sizeof emergency_buf - 1] = '\0'; | - |
143 | #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) && defined(Q_OS_WINCE) \ | - |
144 | || defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) | - |
145 | wchar_t emergency_bufL[sizeof emergency_buf]; | - |
146 | #endif | - |
147 | | - |
148 | if (msg) | 0 |
149 | qvsnprintf(emergency_buf, sizeof emergency_buf - 1, msg, ap); never executed: qvsnprintf(emergency_buf, sizeof emergency_buf - 1, msg, ap); | 0 |
150 | | - |
151 | #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) | - |
152 | # ifdef Q_OS_WINCE | - |
153 | convert_to_wchar_t_elided(emergency_bufL, sizeof emergency_buf, emergency_buf); | - |
154 | OutputDebugStringW(emergency_bufL); | - |
155 | # else | - |
156 | if (usingWinMain) { | - |
157 | OutputDebugStringA(emergency_buf); | - |
158 | } else { | - |
159 | fprintf(stderr, "%s", emergency_buf); | - |
160 | fflush(stderr); | - |
161 | } | - |
162 | # endif | - |
163 | #else | - |
164 | fprintf(stderr, "%s", emergency_buf); never executed (the execution status of this line is deduced): fprintf(stderr, "%s", emergency_buf); | - |
165 | fflush(stderr); never executed (the execution status of this line is deduced): fflush(stderr); | - |
166 | #endif | - |
167 | | - |
168 | if (msgType == QtFatalMsg never evaluated: msgType == QtFatalMsg | 0 |
169 | || (msgType == QtWarningMsg never evaluated: msgType == QtWarningMsg | 0 |
170 | && qEnvironmentVariableIsSet("QT_FATAL_WARNINGS"))) { never evaluated: qEnvironmentVariableIsSet("QT_FATAL_WARNINGS") | 0 |
171 | #if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) | - |
172 | // get the current report mode | - |
173 | int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW); | - |
174 | _CrtSetReportMode(_CRT_ERROR, reportMode); | - |
175 | # ifndef Q_OS_WINCE // otherwise already converted to wchar_t above | - |
176 | convert_to_wchar_t_elided(emergency_bufL, sizeof emergency_buf, emergency_buf); | - |
177 | # endif | - |
178 | int ret = _CrtDbgReportW(_CRT_ERROR, _CRT_WIDE(__FILE__), __LINE__, | - |
179 | _CRT_WIDE(QT_VERSION_STR), | - |
180 | emergency_bufL); | - |
181 | if (ret == 1) | - |
182 | _CrtDbgBreak(); | - |
183 | #endif | - |
184 | | - |
185 | #if (defined(Q_OS_UNIX) || defined(Q_CC_MINGW)) | - |
186 | abort(); // trap; generates core dump | 0 |
187 | #else | - |
188 | exit(1); // goodbye cruel world | - |
189 | #endif | - |
190 | } | - |
191 | } | 0 |
192 | #endif | - |
193 | | - |
194 | /*! | - |
195 | \internal | - |
196 | */ | - |
197 | static void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, | - |
198 | va_list ap, QString &buf) | - |
199 | { | - |
200 | #if !defined(QT_NO_EXCEPTIONS) | - |
201 | if (std::uncaught_exception()) { partially evaluated: std::uncaught_exception() no Evaluation Count:0 | yes Evaluation Count:935 |
| 0-935 |
202 | qEmergencyOut(msgType, msg, ap); never executed (the execution status of this line is deduced): qEmergencyOut(msgType, msg, ap); | - |
203 | return; | 0 |
204 | } | - |
205 | #endif | - |
206 | if (msg) { partially evaluated: msg yes Evaluation Count:935 | no Evaluation Count:0 |
| 0-935 |
207 | QT_TRY { | - |
208 | buf = QString().vsprintf(msg, ap); executed (the execution status of this line is deduced): buf = QString().vsprintf(msg, ap); | - |
209 | } QT_CATCH(const std::bad_alloc &) { executed: } Execution Count:935 | 935 |
210 | #if !defined(QT_NO_EXCEPTIONS) | - |
211 | qEmergencyOut(msgType, msg, ap); never executed (the execution status of this line is deduced): qEmergencyOut(msgType, msg, ap); | - |
212 | // don't rethrow - we use qWarning and friends in destructors. | - |
213 | return; | 0 |
214 | #endif | - |
215 | } | - |
216 | } executed: } Execution Count:935 | 935 |
217 | qt_message_print(msgType, context, buf); executed (the execution status of this line is deduced): qt_message_print(msgType, context, buf); | - |
218 | } executed: } Execution Count:935 | 935 |
219 | | - |
220 | #undef qDebug | - |
221 | /*! | - |
222 | Logs a debug message specified with format \a msg. Additional | - |
223 | parameters, specified by \a msg, may be used. | - |
224 | | - |
225 | \sa qDebug() | - |
226 | */ | - |
227 | void QMessageLogger::debug(const char *msg, ...) const | - |
228 | { | - |
229 | QString message; executed (the execution status of this line is deduced): QString message; | - |
230 | | - |
231 | va_list ap; executed (the execution status of this line is deduced): va_list ap; | - |
232 | va_start(ap, msg); // use variable arg list executed (the execution status of this line is deduced): __builtin_va_start(ap,msg); | - |
233 | qt_message(QtDebugMsg, context, msg, ap, message); executed (the execution status of this line is deduced): qt_message(QtDebugMsg, context, msg, ap, message); | - |
234 | va_end(ap); executed (the execution status of this line is deduced): __builtin_va_end(ap); | - |
235 | | - |
236 | if (isFatal(QtDebugMsg)) partially evaluated: isFatal(QtDebugMsg) no Evaluation Count:0 | yes Evaluation Count:46 |
| 0-46 |
237 | qt_message_fatal(QtDebugMsg, context, message); never executed: qt_message_fatal(QtDebugMsg, context, message); | 0 |
238 | } executed: } Execution Count:46 | 46 |
239 | | - |
240 | #ifndef QT_NO_DEBUG_STREAM | - |
241 | | - |
242 | /*! | - |
243 | Logs a debug message using a QDebug stream | - |
244 | | - |
245 | \sa qDebug(), QDebug | - |
246 | */ | - |
247 | QDebug QMessageLogger::debug() const | - |
248 | { | - |
249 | QDebug dbg = QDebug(QtDebugMsg); executed (the execution status of this line is deduced): QDebug dbg = QDebug(QtDebugMsg); | - |
250 | QMessageLogContext &ctxt = dbg.stream->context; executed (the execution status of this line is deduced): QMessageLogContext &ctxt = dbg.stream->context; | - |
251 | ctxt.copy(context); executed (the execution status of this line is deduced): ctxt.copy(context); | - |
252 | return dbg; executed: return dbg; Execution Count:1188 | 1188 |
253 | } | - |
254 | | - |
255 | /*! | - |
256 | \internal | - |
257 | | - |
258 | Returns a QNoDebug object, which is used to ignore debugging output. | - |
259 | | - |
260 | \sa QNoDebug, qDebug() | - |
261 | */ | - |
262 | QNoDebug QMessageLogger::noDebug() const Q_DECL_NOTHROW | - |
263 | { | - |
264 | return QNoDebug(); never executed: return QNoDebug(); | 0 |
265 | } | - |
266 | | - |
267 | #endif | - |
268 | | - |
269 | #undef qWarning | - |
270 | /*! | - |
271 | Logs a warning message specified with format \a msg. Additional | - |
272 | parameters, specified by \a msg, may be used. | - |
273 | | - |
274 | \sa qWarning() | - |
275 | */ | - |
276 | void QMessageLogger::warning(const char *msg, ...) const | - |
277 | { | - |
278 | QString message; executed (the execution status of this line is deduced): QString message; | - |
279 | | - |
280 | va_list ap; executed (the execution status of this line is deduced): va_list ap; | - |
281 | va_start(ap, msg); // use variable arg list executed (the execution status of this line is deduced): __builtin_va_start(ap,msg); | - |
282 | qt_message(QtWarningMsg, context, msg, ap, message); executed (the execution status of this line is deduced): qt_message(QtWarningMsg, context, msg, ap, message); | - |
283 | va_end(ap); executed (the execution status of this line is deduced): __builtin_va_end(ap); | - |
284 | | - |
285 | if (isFatal(QtWarningMsg)) partially evaluated: isFatal(QtWarningMsg) no Evaluation Count:0 | yes Evaluation Count:884 |
| 0-884 |
286 | qt_message_fatal(QtWarningMsg, context, message); never executed: qt_message_fatal(QtWarningMsg, context, message); | 0 |
287 | } executed: } Execution Count:884 | 884 |
288 | | - |
289 | #ifndef QT_NO_DEBUG_STREAM | - |
290 | /*! | - |
291 | Logs a debug message using a QDebug stream | - |
292 | | - |
293 | \sa qWarning(), QDebug | - |
294 | */ | - |
295 | QDebug QMessageLogger::warning() const | - |
296 | { | - |
297 | QDebug dbg = QDebug(QtWarningMsg); executed (the execution status of this line is deduced): QDebug dbg = QDebug(QtWarningMsg); | - |
298 | QMessageLogContext &ctxt = dbg.stream->context; executed (the execution status of this line is deduced): QMessageLogContext &ctxt = dbg.stream->context; | - |
299 | ctxt.copy(context); executed (the execution status of this line is deduced): ctxt.copy(context); | - |
300 | return dbg; executed: return dbg; Execution Count:25 | 25 |
301 | } | - |
302 | #endif | - |
303 | | - |
304 | #undef qCritical | - |
305 | | - |
306 | /*! | - |
307 | Logs a critical message specified with format \a msg. Additional | - |
308 | parameters, specified by \a msg, may be used. | - |
309 | | - |
310 | \sa qCritical() | - |
311 | */ | - |
312 | void QMessageLogger::critical(const char *msg, ...) const | - |
313 | { | - |
314 | QString message; never executed (the execution status of this line is deduced): QString message; | - |
315 | | - |
316 | va_list ap; never executed (the execution status of this line is deduced): va_list ap; | - |
317 | va_start(ap, msg); // use variable arg list never executed (the execution status of this line is deduced): __builtin_va_start(ap,msg); | - |
318 | qt_message(QtCriticalMsg, context, msg, ap, message); never executed (the execution status of this line is deduced): qt_message(QtCriticalMsg, context, msg, ap, message); | - |
319 | va_end(ap); never executed (the execution status of this line is deduced): __builtin_va_end(ap); | - |
320 | | - |
321 | if (isFatal(QtCriticalMsg)) never evaluated: isFatal(QtCriticalMsg) | 0 |
322 | qt_message_fatal(QtCriticalMsg, context, message); never executed: qt_message_fatal(QtCriticalMsg, context, message); | 0 |
323 | } | 0 |
324 | | - |
325 | #ifndef QT_NO_DEBUG_STREAM | - |
326 | /*! | - |
327 | Logs a critical message using a QDebug stream | - |
328 | | - |
329 | \sa qCritical(), QDebug | - |
330 | */ | - |
331 | QDebug QMessageLogger::critical() const | - |
332 | { | - |
333 | QDebug dbg = QDebug(QtCriticalMsg); executed (the execution status of this line is deduced): QDebug dbg = QDebug(QtCriticalMsg); | - |
334 | QMessageLogContext &ctxt = dbg.stream->context; executed (the execution status of this line is deduced): QMessageLogContext &ctxt = dbg.stream->context; | - |
335 | ctxt.copy(context); executed (the execution status of this line is deduced): ctxt.copy(context); | - |
336 | return dbg; executed: return dbg; Execution Count:1 | 1 |
337 | } | - |
338 | #endif | - |
339 | | - |
340 | #undef qFatal | - |
341 | /*! | - |
342 | Logs a fatal message specified with format \a msg. Additional | - |
343 | parameters, specified by \a msg, may be used. | - |
344 | | - |
345 | \sa qFatal() | - |
346 | */ | - |
347 | void QMessageLogger::fatal(const char *msg, ...) const Q_DECL_NOTHROW | - |
348 | { | - |
349 | QString message; never executed (the execution status of this line is deduced): QString message; | - |
350 | | - |
351 | va_list ap; never executed (the execution status of this line is deduced): va_list ap; | - |
352 | va_start(ap, msg); // use variable arg list never executed (the execution status of this line is deduced): __builtin_va_start(ap,msg); | - |
353 | QT_TERMINATE_ON_EXCEPTION(qt_message(QtFatalMsg, context, msg, ap, message)); executed: } Execution Count:5 never executed: } executed: } Execution Count:5 partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:5 |
| 0-5 |
354 | va_end(ap); never executed (the execution status of this line is deduced): __builtin_va_end(ap); | - |
355 | | - |
356 | qt_message_fatal(QtFatalMsg, context, message); never executed (the execution status of this line is deduced): qt_message_fatal(QtFatalMsg, context, message); | - |
357 | } | 0 |
358 | | - |
359 | /*! | - |
360 | \internal | - |
361 | */ | - |
362 | Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) | - |
363 | { | - |
364 | // Strip the function info down to the base function name | - |
365 | // note that this throws away the template definitions, | - |
366 | // the parameter types (overloads) and any const/volatile qualifiers. | - |
367 | | - |
368 | if (info.isEmpty()) never evaluated: info.isEmpty() | 0 |
369 | return info; never executed: return info; | 0 |
370 | | - |
371 | int pos; never executed (the execution status of this line is deduced): int pos; | - |
372 | | - |
373 | // skip trailing [with XXX] for templates (gcc) | - |
374 | pos = info.size() - 1; never executed (the execution status of this line is deduced): pos = info.size() - 1; | - |
375 | if (info.endsWith(']')) { never evaluated: info.endsWith(']') | 0 |
376 | while (--pos) { | 0 |
377 | if (info.at(pos) == '[') never evaluated: info.at(pos) == '[' | 0 |
378 | info.truncate(pos); never executed: info.truncate(pos); | 0 |
379 | } | 0 |
380 | } | 0 |
381 | | - |
382 | // operator names with '(', ')', '<', '>' in it | - |
383 | static const char operator_call[] = "operator()"; | - |
384 | static const char operator_lessThan[] = "operator<"; | - |
385 | static const char operator_greaterThan[] = "operator>"; | - |
386 | static const char operator_lessThanEqual[] = "operator<="; | - |
387 | static const char operator_greaterThanEqual[] = "operator>="; | - |
388 | | - |
389 | // canonize operator names | - |
390 | info.replace("operator ", "operator"); never executed (the execution status of this line is deduced): info.replace("operator ", "operator"); | - |
391 | | - |
392 | // remove argument list | - |
393 | forever { never executed (the execution status of this line is deduced): for(;;) { | - |
394 | int parencount = 0; never executed (the execution status of this line is deduced): int parencount = 0; | - |
395 | pos = info.lastIndexOf(')'); never executed (the execution status of this line is deduced): pos = info.lastIndexOf(')'); | - |
396 | if (pos == -1) { never evaluated: pos == -1 | 0 |
397 | // Don't know how to parse this function name | - |
398 | return info; never executed: return info; | 0 |
399 | } | - |
400 | | - |
401 | // find the beginning of the argument list | - |
402 | --pos; never executed (the execution status of this line is deduced): --pos; | - |
403 | ++parencount; never executed (the execution status of this line is deduced): ++parencount; | - |
404 | while (pos && parencount) { never evaluated: pos never evaluated: parencount | 0 |
405 | if (info.at(pos) == ')') never evaluated: info.at(pos) == ')' | 0 |
406 | ++parencount; never executed: ++parencount; | 0 |
407 | else if (info.at(pos) == '(') never evaluated: info.at(pos) == '(' | 0 |
408 | --parencount; never executed: --parencount; | 0 |
409 | --pos; never executed (the execution status of this line is deduced): --pos; | - |
410 | } | 0 |
411 | if (parencount != 0) never evaluated: parencount != 0 | 0 |
412 | return info; never executed: return info; | 0 |
413 | | - |
414 | info.truncate(++pos); never executed (the execution status of this line is deduced): info.truncate(++pos); | - |
415 | | - |
416 | if (info.at(pos - 1) == ')') { never evaluated: info.at(pos - 1) == ')' | 0 |
417 | if (info.indexOf(operator_call) == pos - (int)strlen(operator_call)) never evaluated: info.indexOf(operator_call) == pos - (int)strlen(operator_call) | 0 |
418 | break; | 0 |
419 | | - |
420 | // this function returns a pointer to a function | - |
421 | // and we matched the arguments of the return type's parameter list | - |
422 | // try again | - |
423 | info.remove(0, info.indexOf('(')); never executed (the execution status of this line is deduced): info.remove(0, info.indexOf('(')); | - |
424 | info.chop(1); never executed (the execution status of this line is deduced): info.chop(1); | - |
425 | continue; never executed: continue; | 0 |
426 | } else { | - |
427 | break; | 0 |
428 | } | - |
429 | } | - |
430 | | - |
431 | // find the beginning of the function name | - |
432 | int parencount = 0; never executed (the execution status of this line is deduced): int parencount = 0; | - |
433 | int templatecount = 0; never executed (the execution status of this line is deduced): int templatecount = 0; | - |
434 | --pos; never executed (the execution status of this line is deduced): --pos; | - |
435 | | - |
436 | // make sure special characters in operator names are kept | - |
437 | if (pos > -1) { never evaluated: pos > -1 | 0 |
438 | switch (info.at(pos)) { | - |
439 | case ')': | - |
440 | if (info.indexOf(operator_call) == pos - (int)strlen(operator_call) + 1) never evaluated: info.indexOf(operator_call) == pos - (int)strlen(operator_call) + 1 | 0 |
441 | pos -= 2; never executed: pos -= 2; | 0 |
442 | break; | 0 |
443 | case '<': | - |
444 | if (info.indexOf(operator_lessThan) == pos - (int)strlen(operator_lessThan) + 1) never evaluated: info.indexOf(operator_lessThan) == pos - (int)strlen(operator_lessThan) + 1 | 0 |
445 | --pos; | 0 |
446 | break; | 0 |
447 | case '>': | - |
448 | if (info.indexOf(operator_greaterThan) == pos - (int)strlen(operator_greaterThan) + 1) never evaluated: info.indexOf(operator_greaterThan) == pos - (int)strlen(operator_greaterThan) + 1 | 0 |
449 | --pos; | 0 |
450 | break; | 0 |
451 | case '=': { | - |
452 | int operatorLength = (int)strlen(operator_lessThanEqual); never executed (the execution status of this line is deduced): int operatorLength = (int)strlen(operator_lessThanEqual); | - |
453 | if (info.indexOf(operator_lessThanEqual) == pos - operatorLength + 1) never evaluated: info.indexOf(operator_lessThanEqual) == pos - operatorLength + 1 | 0 |
454 | pos -= 2; never executed: pos -= 2; | 0 |
455 | else if (info.indexOf(operator_greaterThanEqual) == pos - operatorLength + 1) never evaluated: info.indexOf(operator_greaterThanEqual) == pos - operatorLength + 1 | 0 |
456 | pos -= 2; never executed: pos -= 2; | 0 |
457 | break; | 0 |
458 | } | - |
459 | default: | - |
460 | break; | 0 |
461 | } | - |
462 | } | 0 |
463 | | - |
464 | while (pos > -1) { never evaluated: pos > -1 | 0 |
465 | if (parencount < 0 || templatecount < 0) never evaluated: parencount < 0 never evaluated: templatecount < 0 | 0 |
466 | return info; never executed: return info; | 0 |
467 | | - |
468 | char c = info.at(pos); never executed (the execution status of this line is deduced): char c = info.at(pos); | - |
469 | if (c == ')') never evaluated: c == ')' | 0 |
470 | ++parencount; never executed: ++parencount; | 0 |
471 | else if (c == '(') never evaluated: c == '(' | 0 |
472 | --parencount; never executed: --parencount; | 0 |
473 | else if (c == '>') never evaluated: c == '>' | 0 |
474 | ++templatecount; never executed: ++templatecount; | 0 |
475 | else if (c == '<') never evaluated: c == '<' | 0 |
476 | --templatecount; never executed: --templatecount; | 0 |
477 | else if (c == ' ' && templatecount == 0 && parencount == 0) never evaluated: c == ' ' never evaluated: templatecount == 0 never evaluated: parencount == 0 | 0 |
478 | break; | 0 |
479 | | - |
480 | --pos; never executed (the execution status of this line is deduced): --pos; | - |
481 | } | 0 |
482 | info = info.mid(pos + 1); never executed (the execution status of this line is deduced): info = info.mid(pos + 1); | - |
483 | | - |
484 | // remove trailing '*', '&' that are part of the return argument | - |
485 | while ((info.at(0) == '*') never evaluated: (info.at(0) == '*') | 0 |
486 | || (info.at(0) == '&')) never evaluated: (info.at(0) == '&') | 0 |
487 | info = info.mid(1); never executed: info = info.mid(1); | 0 |
488 | | - |
489 | // we have the full function name now. | - |
490 | // clean up the templates | - |
491 | while ((pos = info.lastIndexOf('>')) != -1) { never evaluated: (pos = info.lastIndexOf('>')) != -1 | 0 |
492 | if (!info.contains('<')) never evaluated: !info.contains('<') | 0 |
493 | break; | 0 |
494 | | - |
495 | // find the matching close | - |
496 | int end = pos; never executed (the execution status of this line is deduced): int end = pos; | - |
497 | templatecount = 1; never executed (the execution status of this line is deduced): templatecount = 1; | - |
498 | --pos; never executed (the execution status of this line is deduced): --pos; | - |
499 | while (pos && templatecount) { never evaluated: pos never evaluated: templatecount | 0 |
500 | register char c = info.at(pos); never executed (the execution status of this line is deduced): register char c = info.at(pos); | - |
501 | if (c == '>') never evaluated: c == '>' | 0 |
502 | ++templatecount; never executed: ++templatecount; | 0 |
503 | else if (c == '<') never evaluated: c == '<' | 0 |
504 | --templatecount; never executed: --templatecount; | 0 |
505 | --pos; never executed (the execution status of this line is deduced): --pos; | - |
506 | } | 0 |
507 | ++pos; never executed (the execution status of this line is deduced): ++pos; | - |
508 | info.remove(pos, end - pos + 1); never executed (the execution status of this line is deduced): info.remove(pos, end - pos + 1); | - |
509 | } | 0 |
510 | | - |
511 | return info; never executed: return info; | 0 |
512 | } | - |
513 | | - |
514 | // tokens as recognized in QT_MESSAGE_PATTERN | - |
515 | static const char categoryTokenC[] = "%{category}"; | - |
516 | static const char typeTokenC[] = "%{type}"; | - |
517 | static const char messageTokenC[] = "%{message}"; | - |
518 | static const char fileTokenC[] = "%{file}"; | - |
519 | static const char lineTokenC[] = "%{line}"; | - |
520 | static const char functionTokenC[] = "%{function}"; | - |
521 | static const char pidTokenC[] = "%{pid}"; | - |
522 | static const char appnameTokenC[] = "%{appname}"; | - |
523 | static const char threadidTokenC[] = "%{threadid}"; | - |
524 | static const char emptyTokenC[] = ""; | - |
525 | | - |
526 | static const char defaultPattern[] = "%{message}"; | - |
527 | | - |
528 | | - |
529 | struct QMessagePattern { | - |
530 | QMessagePattern(); | - |
531 | ~QMessagePattern(); | - |
532 | | - |
533 | void setPattern(const QString &pattern); | - |
534 | | - |
535 | // 0 terminated arrays of literal tokens / literal or placeholder tokens | - |
536 | const char **literals; | - |
537 | const char **tokens; | - |
538 | | - |
539 | bool fromEnvironment; | - |
540 | static QBasicMutex mutex; | - |
541 | }; | - |
542 | | - |
543 | QBasicMutex QMessagePattern::mutex; | - |
544 | | - |
545 | QMessagePattern::QMessagePattern() | - |
546 | : literals(0) | - |
547 | , tokens(0) | - |
548 | , fromEnvironment(false) | - |
549 | { | - |
550 | const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); never executed (the execution status of this line is deduced): const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); | - |
551 | if (envPattern.isEmpty()) { never evaluated: envPattern.isEmpty() | 0 |
552 | setPattern(QLatin1String(defaultPattern)); never executed (the execution status of this line is deduced): setPattern(QLatin1String(defaultPattern)); | - |
553 | } else { | 0 |
554 | setPattern(envPattern); never executed (the execution status of this line is deduced): setPattern(envPattern); | - |
555 | fromEnvironment = true; never executed (the execution status of this line is deduced): fromEnvironment = true; | - |
556 | } | 0 |
557 | } | - |
558 | | - |
559 | QMessagePattern::~QMessagePattern() | - |
560 | { | - |
561 | for (int i = 0; literals[i] != 0; ++i) partially evaluated: literals[i] != 0 no Evaluation Count:0 | yes Evaluation Count:185 |
| 0-185 |
562 | delete [] literals[i]; never executed: delete [] literals[i]; | 0 |
563 | delete [] literals; executed (the execution status of this line is deduced): delete [] literals; | - |
564 | literals = 0; executed (the execution status of this line is deduced): literals = 0; | - |
565 | delete [] tokens; executed (the execution status of this line is deduced): delete [] tokens; | - |
566 | tokens = 0; executed (the execution status of this line is deduced): tokens = 0; | - |
567 | } executed: } Execution Count:185 | 185 |
568 | | - |
569 | void QMessagePattern::setPattern(const QString &pattern) | - |
570 | { | - |
571 | delete [] tokens; never executed (the execution status of this line is deduced): delete [] tokens; | - |
572 | delete [] literals; never executed (the execution status of this line is deduced): delete [] literals; | - |
573 | | - |
574 | // scanner | - |
575 | QList<QString> lexemes; never executed (the execution status of this line is deduced): QList<QString> lexemes; | - |
576 | QString lexeme; never executed (the execution status of this line is deduced): QString lexeme; | - |
577 | bool inPlaceholder = false; never executed (the execution status of this line is deduced): bool inPlaceholder = false; | - |
578 | for (int i = 0; i < pattern.size(); ++i) { never evaluated: i < pattern.size() | 0 |
579 | const QChar c = pattern.at(i); never executed (the execution status of this line is deduced): const QChar c = pattern.at(i); | - |
580 | if ((c == QLatin1Char('%')) never evaluated: (c == QLatin1Char('%')) | 0 |
581 | && !inPlaceholder) { never evaluated: !inPlaceholder | 0 |
582 | if ((i + 1 < pattern.size()) never evaluated: (i + 1 < pattern.size()) | 0 |
583 | && pattern.at(i + 1) == QLatin1Char('{')) { never evaluated: pattern.at(i + 1) == QLatin1Char('{') | 0 |
584 | // beginning of placeholder | - |
585 | if (!lexeme.isEmpty()) { never evaluated: !lexeme.isEmpty() | 0 |
586 | lexemes.append(lexeme); never executed (the execution status of this line is deduced): lexemes.append(lexeme); | - |
587 | lexeme.clear(); never executed (the execution status of this line is deduced): lexeme.clear(); | - |
588 | } | 0 |
589 | inPlaceholder = true; never executed (the execution status of this line is deduced): inPlaceholder = true; | - |
590 | } | 0 |
591 | } | 0 |
592 | | - |
593 | lexeme.append(c); never executed (the execution status of this line is deduced): lexeme.append(c); | - |
594 | | - |
595 | if ((c == QLatin1Char('}') && inPlaceholder)) { never evaluated: c == QLatin1Char('}') never evaluated: inPlaceholder | 0 |
596 | // end of placeholder | - |
597 | lexemes.append(lexeme); never executed (the execution status of this line is deduced): lexemes.append(lexeme); | - |
598 | lexeme.clear(); never executed (the execution status of this line is deduced): lexeme.clear(); | - |
599 | inPlaceholder = false; never executed (the execution status of this line is deduced): inPlaceholder = false; | - |
600 | } | 0 |
601 | } | 0 |
602 | if (!lexeme.isEmpty()) never evaluated: !lexeme.isEmpty() | 0 |
603 | lexemes.append(lexeme); never executed: lexemes.append(lexeme); | 0 |
604 | | - |
605 | // tokenizer | - |
606 | QVarLengthArray<const char*> literalsVar; never executed (the execution status of this line is deduced): QVarLengthArray<const char*> literalsVar; | - |
607 | tokens = new const char*[lexemes.size() + 1]; never executed (the execution status of this line is deduced): tokens = new const char*[lexemes.size() + 1]; | - |
608 | tokens[lexemes.size()] = 0; never executed (the execution status of this line is deduced): tokens[lexemes.size()] = 0; | - |
609 | | - |
610 | for (int i = 0; i < lexemes.size(); ++i) { never evaluated: i < lexemes.size() | 0 |
611 | const QString lexeme = lexemes.at(i); never executed (the execution status of this line is deduced): const QString lexeme = lexemes.at(i); | - |
612 | if (lexeme.startsWith(QLatin1String("%{")) never evaluated: lexeme.startsWith(QLatin1String("%{")) | 0 |
613 | && lexeme.endsWith(QLatin1Char('}'))) { never evaluated: lexeme.endsWith(QLatin1Char('}')) | 0 |
614 | // placeholder | - |
615 | if (lexeme == QLatin1String(typeTokenC)) { never evaluated: lexeme == QLatin1String(typeTokenC) | 0 |
616 | tokens[i] = typeTokenC; never executed (the execution status of this line is deduced): tokens[i] = typeTokenC; | - |
617 | } else if (lexeme == QLatin1String(categoryTokenC)) never executed: } never evaluated: lexeme == QLatin1String(categoryTokenC) | 0 |
618 | tokens[i] = categoryTokenC; never executed: tokens[i] = categoryTokenC; | 0 |
619 | else if (lexeme == QLatin1String(messageTokenC)) never evaluated: lexeme == QLatin1String(messageTokenC) | 0 |
620 | tokens[i] = messageTokenC; never executed: tokens[i] = messageTokenC; | 0 |
621 | else if (lexeme == QLatin1String(fileTokenC)) never evaluated: lexeme == QLatin1String(fileTokenC) | 0 |
622 | tokens[i] = fileTokenC; never executed: tokens[i] = fileTokenC; | 0 |
623 | else if (lexeme == QLatin1String(lineTokenC)) never evaluated: lexeme == QLatin1String(lineTokenC) | 0 |
624 | tokens[i] = lineTokenC; never executed: tokens[i] = lineTokenC; | 0 |
625 | else if (lexeme == QLatin1String(functionTokenC)) never evaluated: lexeme == QLatin1String(functionTokenC) | 0 |
626 | tokens[i] = functionTokenC; never executed: tokens[i] = functionTokenC; | 0 |
627 | else if (lexeme == QLatin1String(pidTokenC)) never evaluated: lexeme == QLatin1String(pidTokenC) | 0 |
628 | tokens[i] = pidTokenC; never executed: tokens[i] = pidTokenC; | 0 |
629 | else if (lexeme == QLatin1String(appnameTokenC)) never evaluated: lexeme == QLatin1String(appnameTokenC) | 0 |
630 | tokens[i] = appnameTokenC; never executed: tokens[i] = appnameTokenC; | 0 |
631 | else if (lexeme == QLatin1String(threadidTokenC)) never evaluated: lexeme == QLatin1String(threadidTokenC) | 0 |
632 | tokens[i] = threadidTokenC; never executed: tokens[i] = threadidTokenC; | 0 |
633 | else { | - |
634 | tokens[i] = emptyTokenC; never executed (the execution status of this line is deduced): tokens[i] = emptyTokenC; | - |
635 | | - |
636 | QString error = QStringLiteral("QT_MESSAGE_PATTERN: Unknown placeholder %1\n") never executed (the execution status of this line is deduced): QString error = QString::fromUtf8("" "QT_MESSAGE_PATTERN: Unknown placeholder %1\n" "", sizeof("QT_MESSAGE_PATTERN: Unknown placeholder %1\n") - 1) | - |
637 | .arg(lexeme); never executed (the execution status of this line is deduced): .arg(lexeme); | - |
638 | | - |
639 | #if defined(Q_OS_WINCE) | - |
640 | OutputDebugString(reinterpret_cast<const wchar_t*>(error.utf16())); | - |
641 | continue; | - |
642 | #elif defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) | - |
643 | if (usingWinMain) { | - |
644 | OutputDebugString(reinterpret_cast<const wchar_t*>(error.utf16())); | - |
645 | continue; | - |
646 | } | - |
647 | #endif | - |
648 | fprintf(stderr, "%s", error.toLocal8Bit().constData()); never executed (the execution status of this line is deduced): fprintf(stderr, "%s", error.toLocal8Bit().constData()); | - |
649 | fflush(stderr); never executed (the execution status of this line is deduced): fflush(stderr); | - |
650 | } | 0 |
651 | } else { | - |
652 | char *literal = new char[lexeme.size() + 1]; never executed (the execution status of this line is deduced): char *literal = new char[lexeme.size() + 1]; | - |
653 | strncpy(literal, lexeme.toLatin1().constData(), lexeme.size()); never executed (the execution status of this line is deduced): strncpy(literal, lexeme.toLatin1().constData(), lexeme.size()); | - |
654 | literal[lexeme.size()] = '\0'; never executed (the execution status of this line is deduced): literal[lexeme.size()] = '\0'; | - |
655 | literalsVar.append(literal); never executed (the execution status of this line is deduced): literalsVar.append(literal); | - |
656 | tokens[i] = literal; never executed (the execution status of this line is deduced): tokens[i] = literal; | - |
657 | } | 0 |
658 | } | - |
659 | literals = new const char*[literalsVar.size() + 1]; never executed (the execution status of this line is deduced): literals = new const char*[literalsVar.size() + 1]; | - |
660 | literals[literalsVar.size()] = 0; never executed (the execution status of this line is deduced): literals[literalsVar.size()] = 0; | - |
661 | memcpy(literals, literalsVar.constData(), literalsVar.size() * sizeof(const char*)); never executed (the execution status of this line is deduced): memcpy(literals, literalsVar.constData(), literalsVar.size() * sizeof(const char*)); | - |
662 | } | 0 |
663 | | - |
664 | #if defined(QT_USE_SLOG2) | - |
665 | #ifndef QT_LOG_CODE | - |
666 | #define QT_LOG_CODE 9000 | - |
667 | #endif | - |
668 | | - |
669 | extern char *__progname; | - |
670 | | - |
671 | static void slog2_default_handler(QtMsgType msgType, const char *message) | - |
672 | { | - |
673 | if (slog2_set_default_buffer((slog2_buffer_t)-1) == 0) { | - |
674 | slog2_buffer_set_config_t buffer_config; | - |
675 | slog2_buffer_t buffer_handle; | - |
676 | | - |
677 | buffer_config.buffer_set_name = __progname; | - |
678 | buffer_config.num_buffers = 1; | - |
679 | buffer_config.verbosity_level = SLOG2_INFO; | - |
680 | buffer_config.buffer_config[0].buffer_name = "default"; | - |
681 | buffer_config.buffer_config[0].num_pages = 8; | - |
682 | | - |
683 | if (slog2_register(&buffer_config, &buffer_handle, 0) == -1) { | - |
684 | fprintf(stderr, "Error registering slogger2 buffer!\n"); | - |
685 | fprintf(stderr, "%s", message); | - |
686 | fflush(stderr); | - |
687 | return; | - |
688 | } | - |
689 | | - |
690 | // Set as the default buffer | - |
691 | slog2_set_default_buffer(buffer_handle); | - |
692 | } | - |
693 | int severity; | - |
694 | //Determines the severity level | - |
695 | switch (msgType) { | - |
696 | case QtDebugMsg: | - |
697 | severity = SLOG2_INFO; | - |
698 | break; | - |
699 | case QtWarningMsg: | - |
700 | severity = SLOG2_NOTICE; | - |
701 | break; | - |
702 | case QtCriticalMsg: | - |
703 | severity = SLOG2_WARNING; | - |
704 | break; | - |
705 | case QtFatalMsg: | - |
706 | severity = SLOG2_ERROR; | - |
707 | break; | - |
708 | } | - |
709 | //writes to the slog2 buffer | - |
710 | slog2c(NULL, QT_LOG_CODE, severity, message); | - |
711 | } | - |
712 | #endif // QT_USE_SLOG2 | - |
713 | | - |
714 | Q_GLOBAL_STATIC(QMessagePattern, qMessagePattern) never executed: delete x; never executed: return thisGlobalStatic.pointer.load(); never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) never evaluated: !thisGlobalStatic.pointer.load() never evaluated: !thisGlobalStatic.destroyed | 0 |
715 | | - |
716 | /*! | - |
717 | \internal | - |
718 | */ | - |
719 | Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type, const QMessageLogContext &context, | - |
720 | const QString &str) | - |
721 | { | - |
722 | QString message; never executed (the execution status of this line is deduced): QString message; | - |
723 | | - |
724 | QMutexLocker lock(&QMessagePattern::mutex); never executed (the execution status of this line is deduced): QMutexLocker lock(&QMessagePattern::mutex); | - |
725 | | - |
726 | QMessagePattern *pattern = qMessagePattern(); never executed (the execution status of this line is deduced): QMessagePattern *pattern = qMessagePattern(); | - |
727 | if (!pattern) { never evaluated: !pattern | 0 |
728 | // after destruction of static QMessagePattern instance | - |
729 | message.append(str); never executed (the execution status of this line is deduced): message.append(str); | - |
730 | message.append(QLatin1Char('\n')); never executed (the execution status of this line is deduced): message.append(QLatin1Char('\n')); | - |
731 | return message; never executed: return message; | 0 |
732 | } | - |
733 | | - |
734 | // don't print anything if pattern was empty | - |
735 | if (pattern->tokens[0] == 0) never evaluated: pattern->tokens[0] == 0 | 0 |
736 | return message; never executed: return message; | 0 |
737 | | - |
738 | // we do not convert file, function, line literals to local encoding due to overhead | - |
739 | for (int i = 0; pattern->tokens[i] != 0; ++i) { never evaluated: pattern->tokens[i] != 0 | 0 |
740 | const char *token = pattern->tokens[i]; never executed (the execution status of this line is deduced): const char *token = pattern->tokens[i]; | - |
741 | if (token == messageTokenC) { never evaluated: token == messageTokenC | 0 |
742 | message.append(str); never executed (the execution status of this line is deduced): message.append(str); | - |
743 | } else if (token == categoryTokenC) { never executed: } never evaluated: token == categoryTokenC | 0 |
744 | message.append(QLatin1String(context.category)); never executed (the execution status of this line is deduced): message.append(QLatin1String(context.category)); | - |
745 | } else if (token == typeTokenC) { never executed: } never evaluated: token == typeTokenC | 0 |
746 | switch (type) { | - |
747 | case QtDebugMsg: message.append(QLatin1String("debug")); break; | 0 |
748 | case QtWarningMsg: message.append(QLatin1String("warning")); break; | 0 |
749 | case QtCriticalMsg:message.append(QLatin1String("critical")); break; | 0 |
750 | case QtFatalMsg: message.append(QLatin1String("fatal")); break; | 0 |
751 | } | - |
752 | } else if (token == fileTokenC) { never executed: } never evaluated: token == fileTokenC | 0 |
753 | if (context.file) never evaluated: context.file | 0 |
754 | message.append(QLatin1String(context.file)); never executed: message.append(QLatin1String(context.file)); | 0 |
755 | else | - |
756 | message.append(QLatin1String("unknown")); never executed: message.append(QLatin1String("unknown")); | 0 |
757 | } else if (token == lineTokenC) { never evaluated: token == lineTokenC | 0 |
758 | message.append(QString::number(context.line)); never executed (the execution status of this line is deduced): message.append(QString::number(context.line)); | - |
759 | } else if (token == functionTokenC) { never executed: } never evaluated: token == functionTokenC | 0 |
760 | if (context.function) never evaluated: context.function | 0 |
761 | message.append(QString::fromLatin1(qCleanupFuncinfo(context.function))); never executed: message.append(QString::fromLatin1(qCleanupFuncinfo(context.function))); | 0 |
762 | else | - |
763 | message.append(QLatin1String("unknown")); never executed: message.append(QLatin1String("unknown")); | 0 |
764 | #ifndef QT_BOOTSTRAPPED | - |
765 | } else if (token == pidTokenC) { never evaluated: token == pidTokenC | 0 |
766 | message.append(QString::number(QCoreApplication::applicationPid())); never executed (the execution status of this line is deduced): message.append(QString::number(QCoreApplication::applicationPid())); | - |
767 | } else if (token == appnameTokenC) { never executed: } never evaluated: token == appnameTokenC | 0 |
768 | message.append(QCoreApplication::applicationName()); never executed (the execution status of this line is deduced): message.append(QCoreApplication::applicationName()); | - |
769 | } else if (token == threadidTokenC) { never executed: } never evaluated: token == threadidTokenC | 0 |
770 | message.append(QLatin1String("0x")); never executed (the execution status of this line is deduced): message.append(QLatin1String("0x")); | - |
771 | message.append(QString::number(qlonglong(QThread::currentThread()->currentThread()), 16)); never executed (the execution status of this line is deduced): message.append(QString::number(qlonglong(QThread::currentThread()->currentThread()), 16)); | - |
772 | #endif | - |
773 | } else { | 0 |
774 | message.append(QLatin1String(token)); never executed (the execution status of this line is deduced): message.append(QLatin1String(token)); | - |
775 | } | 0 |
776 | } | - |
777 | message.append(QLatin1Char('\n')); never executed (the execution status of this line is deduced): message.append(QLatin1Char('\n')); | - |
778 | return message; never executed: return message; | 0 |
779 | } | - |
780 | | - |
781 | #if !QT_DEPRECATED_SINCE(5, 0) | - |
782 | // make sure they're defined to be exported | - |
783 | typedef void (*QtMsgHandler)(QtMsgType, const char *); | - |
784 | Q_CORE_EXPORT QtMsgHandler qInstallMsgHandler(QtMsgHandler); | - |
785 | #endif | - |
786 | | - |
787 | static QtMsgHandler msgHandler = 0; // pointer to debug handler (without context) | - |
788 | static QtMessageHandler messageHandler = 0; // pointer to debug handler (with context) | - |
789 | | - |
790 | /*! | - |
791 | \internal | - |
792 | */ | - |
793 | static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, | - |
794 | const QString &buf) | - |
795 | { | - |
796 | QString logMessage = qMessageFormatString(type, context, buf); never executed (the execution status of this line is deduced): QString logMessage = qMessageFormatString(type, context, buf); | - |
797 | | - |
798 | #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) | - |
799 | #if !defined(Q_OS_WINCE) | - |
800 | if (usingWinMain) | - |
801 | #endif | - |
802 | { | - |
803 | OutputDebugString(reinterpret_cast<const wchar_t *>(logMessage.utf16())); | - |
804 | return; | - |
805 | } | - |
806 | #endif // Q_OS_WIN | - |
807 | | - |
808 | #if defined(QT_USE_SLOG2) | - |
809 | slog2_default_handler(type, logMessage.toLocal8Bit().constData()); | - |
810 | #else | - |
811 | fprintf(stderr, "%s", logMessage.toLocal8Bit().constData()); never executed (the execution status of this line is deduced): fprintf(stderr, "%s", logMessage.toLocal8Bit().constData()); | - |
812 | fflush(stderr); never executed (the execution status of this line is deduced): fflush(stderr); | - |
813 | #endif | - |
814 | } | 0 |
815 | | - |
816 | /*! | - |
817 | \internal | - |
818 | */ | - |
819 | static void qDefaultMsgHandler(QtMsgType type, const char *buf) | - |
820 | { | - |
821 | QMessageLogContext emptyContext; never executed (the execution status of this line is deduced): QMessageLogContext emptyContext; | - |
822 | qDefaultMessageHandler(type, emptyContext, QLatin1String(buf)); never executed (the execution status of this line is deduced): qDefaultMessageHandler(type, emptyContext, QLatin1String(buf)); | - |
823 | } | 0 |
824 | | - |
825 | static void qt_message_print(QtMsgType msgType, const QMessageLogContext &context, const QString &message) | - |
826 | { | - |
827 | if (!msgHandler) evaluated: !msgHandler yes Evaluation Count:1 | yes Evaluation Count:2150 |
| 1-2150 |
828 | msgHandler = qDefaultMsgHandler; executed: msgHandler = qDefaultMsgHandler; Execution Count:1 | 1 |
829 | if (!messageHandler) evaluated: !messageHandler yes Evaluation Count:63 | yes Evaluation Count:2088 |
| 63-2088 |
830 | messageHandler = qDefaultMessageHandler; executed: messageHandler = qDefaultMessageHandler; Execution Count:63 | 63 |
831 | | - |
832 | // prefer new message handler over the old one | - |
833 | if (msgHandler == qDefaultMsgHandler evaluated: msgHandler == qDefaultMsgHandler yes Evaluation Count:1 | yes Evaluation Count:2150 |
| 1-2150 |
834 | || messageHandler != qDefaultMessageHandler) { evaluated: messageHandler != qDefaultMessageHandler yes Evaluation Count:154 | yes Evaluation Count:1996 |
| 154-1996 |
835 | (*messageHandler)(msgType, context, message); executed (the execution status of this line is deduced): (*messageHandler)(msgType, context, message); | - |
836 | } else { executed: } Execution Count:155 | 155 |
837 | (*msgHandler)(msgType, message.toLocal8Bit().constData()); executed (the execution status of this line is deduced): (*msgHandler)(msgType, message.toLocal8Bit().constData()); | - |
838 | } executed: } Execution Count:1996 | 1996 |
839 | } | - |
840 | | - |
841 | static void qt_message_fatal(QtMsgType, const QMessageLogContext &context, const QString &message) | - |
842 | { | - |
843 | #if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) | - |
844 | wchar_t contextFileL[256]; | - |
845 | // we probably should let the compiler do this for us, by | - |
846 | // declaring QMessageLogContext::file to be const wchar_t * in | - |
847 | // the first place, but the #ifdefery above is very complex | - |
848 | // and we wouldn't be able to change it later on... | - |
849 | convert_to_wchar_t_elided(contextFileL, sizeof contextFileL / sizeof *contextFileL, context.file); | - |
850 | // get the current report mode | - |
851 | int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW); | - |
852 | _CrtSetReportMode(_CRT_ERROR, reportMode); | - |
853 | | - |
854 | int ret = _CrtDbgReportW(_CRT_ERROR, contextFileL, | - |
855 | context.line, _CRT_WIDE(QT_VERSION_STR), | - |
856 | reinterpret_cast<const wchar_t *> ( | - |
857 | message.utf16())); | - |
858 | if (ret == 0 && reportMode & _CRTDBG_MODE_WNDW) | - |
859 | return; // ignore | - |
860 | else if (ret == 1) | - |
861 | _CrtDbgBreak(); | - |
862 | #else | - |
863 | Q_UNUSED(context); executed (the execution status of this line is deduced): (void)context;; | - |
864 | Q_UNUSED(message); executed (the execution status of this line is deduced): (void)message;; | - |
865 | #endif | - |
866 | | - |
867 | #if (defined(Q_OS_UNIX) || defined(Q_CC_MINGW)) | - |
868 | abort(); // trap; generates core dump executed: abort(); Execution Count:5 | 5 |
869 | #else | - |
870 | exit(1); // goodbye cruel world | - |
871 | #endif | - |
872 | } | - |
873 | | - |
874 | | - |
875 | /*! | - |
876 | \internal | - |
877 | */ | - |
878 | void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const QString &message) | - |
879 | { | - |
880 | qt_message_print(msgType, context, message); executed (the execution status of this line is deduced): qt_message_print(msgType, context, message); | - |
881 | if (isFatal(msgType)) partially evaluated: isFatal(msgType) no Evaluation Count:0 | yes Evaluation Count:1216 |
| 0-1216 |
882 | qt_message_fatal(msgType, context, message); never executed: qt_message_fatal(msgType, context, message); | 0 |
883 | } executed: } Execution Count:1216 | 1216 |
884 | | - |
885 | void qErrnoWarning(const char *msg, ...) | - |
886 | { | - |
887 | // qt_error_string() will allocate anyway, so we don't have | - |
888 | // to be careful here (like we do in plain qWarning()) | - |
889 | QString buf; never executed (the execution status of this line is deduced): QString buf; | - |
890 | va_list ap; never executed (the execution status of this line is deduced): va_list ap; | - |
891 | va_start(ap, msg); never executed (the execution status of this line is deduced): __builtin_va_start(ap,msg); | - |
892 | if (msg) | 0 |
893 | buf.vsprintf(msg, ap); never executed: buf.vsprintf(msg, ap); | 0 |
894 | va_end(ap); never executed (the execution status of this line is deduced): __builtin_va_end(ap); | - |
895 | | - |
896 | buf += QLatin1String(" (") + qt_error_string(-1) + QLatin1Char(')'); never executed (the execution status of this line is deduced): buf += QLatin1String(" (") + qt_error_string(-1) + QLatin1Char(')'); | - |
897 | QMessageLogContext context; never executed (the execution status of this line is deduced): QMessageLogContext context; | - |
898 | qt_message_output(QtCriticalMsg, context, buf); never executed (the execution status of this line is deduced): qt_message_output(QtCriticalMsg, context, buf); | - |
899 | } | 0 |
900 | | - |
901 | void qErrnoWarning(int code, const char *msg, ...) | - |
902 | { | - |
903 | // qt_error_string() will allocate anyway, so we don't have | - |
904 | // to be careful here (like we do in plain qWarning()) | - |
905 | QString buf; never executed (the execution status of this line is deduced): QString buf; | - |
906 | va_list ap; never executed (the execution status of this line is deduced): va_list ap; | - |
907 | va_start(ap, msg); never executed (the execution status of this line is deduced): __builtin_va_start(ap,msg); | - |
908 | if (msg) | 0 |
909 | buf.vsprintf(msg, ap); never executed: buf.vsprintf(msg, ap); | 0 |
910 | va_end(ap); never executed (the execution status of this line is deduced): __builtin_va_end(ap); | - |
911 | | - |
912 | buf += QLatin1String(" (") + qt_error_string(code) + QLatin1Char(')'); never executed (the execution status of this line is deduced): buf += QLatin1String(" (") + qt_error_string(code) + QLatin1Char(')'); | - |
913 | QMessageLogContext context; never executed (the execution status of this line is deduced): QMessageLogContext context; | - |
914 | qt_message_output(QtCriticalMsg, context, buf); never executed (the execution status of this line is deduced): qt_message_output(QtCriticalMsg, context, buf); | - |
915 | } | 0 |
916 | | - |
917 | /*! | - |
918 | \typedef QtMsgHandler | - |
919 | \relates <QtGlobal> | - |
920 | \deprecated | - |
921 | | - |
922 | This is a typedef for a pointer to a function with the following | - |
923 | signature: | - |
924 | | - |
925 | \snippet code/src_corelib_global_qglobal.cpp 7 | - |
926 | | - |
927 | This typedef is deprecated, you should use QtMessageHandler instead. | - |
928 | \sa QtMsgType, QtMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() | - |
929 | */ | - |
930 | | - |
931 | /*! | - |
932 | \typedef QtMessageHandler | - |
933 | \relates <QtGlobal> | - |
934 | \since 5.0 | - |
935 | | - |
936 | This is a typedef for a pointer to a function with the following | - |
937 | signature: | - |
938 | | - |
939 | \snippet code/src_corelib_global_qglobal.cpp 49 | - |
940 | | - |
941 | \sa QtMsgType, qInstallMessageHandler() | - |
942 | */ | - |
943 | | - |
944 | /*! | - |
945 | \fn QtMessageHandler qInstallMessageHandler(QtMessageHandler handler) | - |
946 | \relates <QtGlobal> | - |
947 | \since 5.0 | - |
948 | | - |
949 | Installs a Qt message \a handler which has been defined | - |
950 | previously. Returns a pointer to the previous message handler | - |
951 | (which may be 0). | - |
952 | | - |
953 | The message handler is a function that prints out debug messages, | - |
954 | warnings, critical and fatal error messages. The Qt library (debug | - |
955 | mode) contains hundreds of warning messages that are printed | - |
956 | when internal errors (usually invalid function arguments) | - |
957 | occur. Qt built in release mode also contains such warnings unless | - |
958 | QT_NO_WARNING_OUTPUT and/or QT_NO_DEBUG_OUTPUT have been set during | - |
959 | compilation. If you implement your own message handler, you get total | - |
960 | control of these messages. | - |
961 | | - |
962 | The default message handler prints the message to the standard | - |
963 | output under X11 or to the debugger under Windows. If it is a | - |
964 | fatal message, the application aborts immediately. | - |
965 | | - |
966 | Only one message handler can be defined, since this is usually | - |
967 | done on an application-wide basis to control debug output. | - |
968 | | - |
969 | To restore the message handler, call \c qInstallMessageHandler(0). | - |
970 | | - |
971 | Example: | - |
972 | | - |
973 | \snippet code/src_corelib_global_qglobal.cpp 23 | - |
974 | | - |
975 | \sa QtMessageHandler, QtMsgType, qDebug(), qWarning(), qCritical(), qFatal(), | - |
976 | {Debugging Techniques} | - |
977 | */ | - |
978 | | - |
979 | /*! | - |
980 | \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler) | - |
981 | \relates <QtGlobal> | - |
982 | \deprecated | - |
983 | | - |
984 | Installs a Qt message \a handler which has been defined | - |
985 | previously. This method is deprecated, use qInstallMessageHandler | - |
986 | instead. | - |
987 | \sa QtMsgHandler, qInstallMessageHandler() | - |
988 | */ | - |
989 | /*! | - |
990 | \fn void qSetMessagePattern(const QString &pattern) | - |
991 | \relates <QtGlobal> | - |
992 | \since 5.0 | - |
993 | | - |
994 | \brief Changes the output of the default message handler. | - |
995 | | - |
996 | Allows to tweak the output of qDebug(), qWarning(), qCritical() and qFatal(). | - |
997 | | - |
998 | Following placeholders are supported: | - |
999 | | - |
1000 | \table | - |
1001 | \header \li Placeholder \li Description | - |
1002 | \row \li \c %{appname} \li QCoreApplication::applicationName() | - |
1003 | \row \li \c %{file} \li Path to source file | - |
1004 | \row \li \c %{function} \li Function | - |
1005 | \row \li \c %{line} \li Line in source file | - |
1006 | \row \li \c %{message} \li The actual message | - |
1007 | \row \li \c %{pid} \li QCoreApplication::applicationPid() | - |
1008 | \row \li \c %{threadid} \li ID of current thread | - |
1009 | \row \li \c %{type} \li "debug", "warning", "critical" or "fatal" | - |
1010 | \endtable | - |
1011 | | - |
1012 | The default \a pattern is "%{message}". | - |
1013 | | - |
1014 | The \a pattern can also be changed at runtime by setting the QT_MESSAGE_PATTERN | - |
1015 | environment variable; if both qSetMessagePattern() is called and QT_MESSAGE_PATTERN is | - |
1016 | set, the environment variable takes precedence. | - |
1017 | | - |
1018 | qSetMessagePattern() has no effect if a custom message handler is installed. | - |
1019 | | - |
1020 | \sa qInstallMessageHandler(), {Debugging Techniques} | - |
1021 | */ | - |
1022 | | - |
1023 | QtMessageHandler qInstallMessageHandler(QtMessageHandler h) | - |
1024 | { | - |
1025 | if (!messageHandler) evaluated: !messageHandler yes Evaluation Count:7 | yes Evaluation Count:316 |
| 7-316 |
1026 | messageHandler = qDefaultMessageHandler; executed: messageHandler = qDefaultMessageHandler; Execution Count:7 | 7 |
1027 | QtMessageHandler old = messageHandler; executed (the execution status of this line is deduced): QtMessageHandler old = messageHandler; | - |
1028 | messageHandler = h; executed (the execution status of this line is deduced): messageHandler = h; | - |
1029 | return old; executed: return old; Execution Count:323 | 323 |
1030 | } | - |
1031 | | - |
1032 | QtMsgHandler qInstallMsgHandler(QtMsgHandler h) | - |
1033 | { | - |
1034 | //if handler is 0, set it to the | - |
1035 | //default message handler | - |
1036 | if (!msgHandler) evaluated: !msgHandler yes Evaluation Count:214 | yes Evaluation Count:589 |
| 214-589 |
1037 | msgHandler = qDefaultMsgHandler; executed: msgHandler = qDefaultMsgHandler; Execution Count:214 | 214 |
1038 | QtMsgHandler old = msgHandler; executed (the execution status of this line is deduced): QtMsgHandler old = msgHandler; | - |
1039 | msgHandler = h; executed (the execution status of this line is deduced): msgHandler = h; | - |
1040 | return old; executed: return old; Execution Count:803 | 803 |
1041 | } | - |
1042 | | - |
1043 | void qSetMessagePattern(const QString &pattern) | - |
1044 | { | - |
1045 | QMutexLocker lock(&QMessagePattern::mutex); never executed (the execution status of this line is deduced): QMutexLocker lock(&QMessagePattern::mutex); | - |
1046 | | - |
1047 | if (!qMessagePattern()->fromEnvironment) never evaluated: !qMessagePattern()->fromEnvironment | 0 |
1048 | qMessagePattern()->setPattern(pattern); never executed: qMessagePattern()->setPattern(pattern); | 0 |
1049 | } | 0 |
1050 | | - |
1051 | /*! | - |
1052 | Copies context information from \a logContext into this QMessageLogContext | - |
1053 | \internal | - |
1054 | */ | - |
1055 | void QMessageLogContext::copy(const QMessageLogContext &logContext) | - |
1056 | { | - |
1057 | this->category = logContext.category; executed (the execution status of this line is deduced): this->category = logContext.category; | - |
1058 | this->file = logContext.file; executed (the execution status of this line is deduced): this->file = logContext.file; | - |
1059 | this->line = logContext.line; executed (the execution status of this line is deduced): this->line = logContext.line; | - |
1060 | this->function = logContext.function; executed (the execution status of this line is deduced): this->function = logContext.function; | - |
1061 | } executed: } Execution Count:1214 | 1214 |
1062 | | - |
1063 | /*! | - |
1064 | \fn QMessageLogger::QMessageLogger() | - |
1065 | | - |
1066 | Constructs a default QMessageLogger. See the other constructors to specify | - |
1067 | context information. | - |
1068 | */ | - |
1069 | | - |
1070 | /*! | - |
1071 | \fn QMessageLogger::QMessageLogger(const char *file, int line, const char *function) | - |
1072 | | - |
1073 | Constructs a QMessageLogger to record log messages for \a file at \a line | - |
1074 | in \a function. The is equivalent to QMessageLogger(file, line, function, "default") | - |
1075 | */ | - |
1076 | /*! | - |
1077 | \fn QMessageLogger::QMessageLogger(const char *file, int line, const char *function, const char *category) | - |
1078 | | - |
1079 | Constructs a QMessageLogger to record \a category messages for \a file at \a line | - |
1080 | in \a function. | - |
1081 | */ | - |
1082 | | - |
1083 | /*! | - |
1084 | \fn void QMessageLogger::noDebug(const char *, ...) const | - |
1085 | \internal | - |
1086 | | - |
1087 | Ignores logging output | - |
1088 | | - |
1089 | \sa QNoDebug, qDebug() | - |
1090 | */ | - |
1091 | | - |
1092 | /*! | - |
1093 | \fn QMessageLogContext::QMessageLogContext() | - |
1094 | \internal | - |
1095 | | - |
1096 | Constructs a QMessageLogContext | - |
1097 | */ | - |
1098 | | - |
1099 | /*! | - |
1100 | \fn QMessageLogContext::QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) | - |
1101 | \internal | - |
1102 | | - |
1103 | Constructs a QMessageLogContext with for file \a fileName at line | - |
1104 | \a lineNumber, in function \a functionName, and category \a CategoryName. | - |
1105 | */ | - |
1106 | | - |
1107 | QT_END_NAMESPACE | - |
1108 | | - |
| | |