1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QTESTCRASHHANDLER_H
16#define QTESTCRASHHANDLER_H
17
18#include <QtCore/qnamespace.h>
19#include <QtTest/qttestglobal.h>
20
21#include <QtCore/private/qtools_p.h>
22
23#ifdef Q_OS_UNIX
24#include <sys/mman.h> // for MAP_FAILED
25#endif
26
27QT_BEGIN_NAMESPACE
28namespace QTest {
29namespace CrashHandler {
30 enum DebuggerProgram {
31 None,
32 Gdb,
33 Lldb,
34#ifdef Q_OS_WIN
35 Cdb,
36#endif
37 };
38
39 bool alreadyDebugging();
40 void blockUnixSignals();
41
42#if !defined(Q_OS_WASM) || QT_CONFIG(thread)
43 void printTestRunTime();
44 void generateStackTrace(quintptr ip = 0);
45#endif
46
47 void maybeDisableCoreDump();
48 Q_TESTLIB_EXPORT void prepareStackTrace();
49
50#if defined(Q_OS_WIN)
51 class Q_TESTLIB_EXPORT WindowsFaultHandler
52 {
53 public:
54 WindowsFaultHandler();
55 };
56 using FatalSignalHandler = WindowsFaultHandler;
57#elif defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
58 class Q_TESTLIB_EXPORT FatalSignalHandler
59 {
60 public:
61 FatalSignalHandler();
62 ~FatalSignalHandler();
63
64 private:
65 Q_DISABLE_COPY_MOVE(FatalSignalHandler)
66
67 int setupAlternateStack();
68 void freeAlternateStack();
69 void *alternateStackBase = MAP_FAILED;
70 };
71#else // Q_OS_WASM or weird systems
72class Q_TESTLIB_EXPORT FatalSignalHandler {};
73inline void blockUnixSignals() {}
74#endif // Q_OS_* choice
75} // namespace CrashHandler
76} // namespace QTest
77QT_END_NAMESPACE
78
79#endif // QTESTCRASHHANDLER_H
80

source code of qtbase/src/testlib/qtestcrashhandler_p.h