swift
Loading...
Searching...
No Matches
verify.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#include "misc/verify.h"
5
6#include <QLoggingCategory>
7#include <QString>
8#include <QtGlobal>
9
10#include "misc/logcategories.h"
11
12#ifdef SWIFT_USE_CRASHPAD
13# include "crashpad/client/simulate_crash.h"
14#endif
15
16#ifdef Q_CC_MSVC
17# include <Windows.h>
18# include <intrin.h>
19#endif
20
21#ifdef Q_CC_CLANG
22# ifndef CPPCHECK
23# if __has_builtin(__builtin_debugtrap)
24# define SWIFT_BUILTIN_DEBUGTRAP __builtin_debugtrap
25# elif __has_builtin(__builtin_debugger)
26# define SWIFT_BUILTIN_DEBUGTRAP __builtin_debugger
27# endif
28# endif
29#endif
30
31namespace swift::misc::private_ns
32{
33 // cppcheck-suppress unusedFunction
34 void failedVerify(const char *condition, const char *filename, int line, const char *context, const char *message,
35 bool audit)
36 {
37 Q_UNUSED(condition)
38 Q_UNUSED(filename)
39 Q_UNUSED(line)
40 Q_UNUSED(context)
41 Q_UNUSED(message)
42 Q_UNUSED(audit)
43
44#ifdef QT_DEBUG
45# ifdef Q_CC_MSVC
46 if (!audit || IsDebuggerPresent())
47 {
48 __debugbreak();
49 return;
50 }
51# elif defined(SWIFT_BUILTIN_DEBUGTRAP)
52 SWIFT_BUILTIN_DEBUGTRAP();
53# elif defined(Q_PROCESSOR_X86)
54 __asm__ volatile("int $0x03");
55# elif defined(Q_PROCESSOR_ARM)
56 __asm__ volatile(".inst 0xe7f001f0");
57# elif defined(Q_OS_UNIX)
58 raise(SIGTRAP);
59# else
60 Q_ASSERT(false);
61# endif
62#endif
63
64#if defined(QT_NO_DEBUG) || defined(Q_CC_MSVC)
65 QString log;
66 if (context && message)
67 {
68 log = QStringLiteral("Failed to verify: %1 (%2 in %3) in %4 line %5")
69 .arg(condition, message, context, filename, QString::number(line));
70 }
71 else
72 {
73 log = QStringLiteral("Failed to verify: %1 in %2 line %3").arg(condition, filename, QString::number(line));
74 }
75 QMessageLogger().warning(QLoggingCategory(qPrintable(CLogCategories::verification()))) << log;
76# if defined(SWIFT_USE_CRASHPAD)
77 CRASHPAD_SIMULATE_CRASH();
78# endif
79#endif
80 }
81} // namespace swift::misc::private_ns
static const QString & verification()
Verification.
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)