-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrash_guard_example.cpp
More file actions
57 lines (46 loc) · 1.59 KB
/
Copy pathcrash_guard_example.cpp
File metadata and controls
57 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// -----------------------------------------------------------------------------
// _ __ __ _____ ___ __
// | | / / _/ ____/ _/ /
// | | / // // / __ / // / Logging and Diagnostics for C++
// | |/ // // /_/ // // /___ https://github.com/DMsuDev/vigil
// |___/___/\____/___/_____/
//
// Copyright (c) 2026 @DMsuDev. Licensed under the MIT License.
// See LICENSE file in the project root for full license text.
// -----------------------------------------------------------------------------
#include "vigil/vigil.h"
#include <cstdio>
#include <iostream>
#include <thread>
[[noreturn]] inline void TriggerSigSegV()
{
volatile int* p = nullptr;
*p = 42;
}
int main()
{
// CrashGuard can be installed independently of the logging system.
vigil::CrashHandler::Install(
[](const vigil::CrashInfo& info)
{
if (info.reportPath)
std::fprintf(stderr, "Crash report: %s\n", info.reportPath);
},
"logs/crash_guard");
std::cout << "CrashGuard installed.\n";
// Vigil logging can be initialized independently.
vigil::LogSystem::Init({
.Name = "crash_guard_example",
.LogDir = "logs/crash_guard",
.ConsoleLevel = vigil::LogLevel::Trace
});
// Repeated installation is safe; the first installation wins.
vigil::CrashHandler::Install();
std::thread worker([] {
vigil::CrashHandler::InstallThreadAltStack();
});
worker.join();
// Uncomment to trigger a crash and test CrashGuard.
// TriggerSigSegV();
std::cout << "CrashGuard setup completed successfully.\n";
}