yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
crash_handler.h
Go to the documentation of this file.
1#ifndef YAZE_UTIL_CRASH_HANDLER_H
2#define YAZE_UTIL_CRASH_HANDLER_H
3
4#include <filesystem>
5#include <string>
6
7namespace yaze {
8namespace util {
9
34 public:
42 static void Initialize(const std::string& version);
43
48 static std::filesystem::path GetCrashLogDirectory();
49
54 static std::filesystem::path GetMostRecentCrashLog();
55
60 static bool HasUnacknowledgedCrashLog();
61
67 static void AcknowledgeCrashLog();
68
76 static void CleanupOldLogs(int keep_count = 5);
77
82 static bool IsHeaderOnlyCrashLog(const std::filesystem::path& path);
83
84 // Testing hooks: prepare the crash log path and header for `directory`
85 // without installing signal handlers, drive the signal-path writer, and
86 // release the file afterwards.
87 static void PrepareCrashLogForTesting(const std::string& version,
88 const std::filesystem::path& directory);
89 static void WriteCrashLogForTesting(const char* data);
90 static std::filesystem::path PendingCrashLogPathForTesting();
91 static void ResetForTesting();
92
93 private:
94 // Builds the log path and header in static buffers so the signal handler
95 // can create the file without allocating.
96 static void PrepareCrashLog(const std::string& version,
97 const std::filesystem::path& directory);
98
99 // Opens the log and writes the header on the first crash write. Uses only
100 // async-signal-safe calls.
101 static void OpenCrashLogFromSignalHandler();
102
103 // Custom writer function for absl failure signal handler
104 static void CrashLogWriter(const char* data);
105
106 static std::string version_;
107 static std::filesystem::path crash_log_path_;
108 static int crash_log_fd_;
109};
110
111} // namespace util
112} // namespace yaze
113
114#endif // YAZE_UTIL_CRASH_HANDLER_H
Manages crash logging for release builds.
static void CleanupOldLogs(int keep_count=5)
Clean up old crash logs, keeping only the most recent N logs.
static bool IsHeaderOnlyCrashLog(const std::filesystem::path &path)
True if the file holds only the report header, with nothing written by the signal handler after it.
static void OpenCrashLogFromSignalHandler()
static void CrashLogWriter(const char *data)
static void Initialize(const std::string &version)
Initialize the crash handler for the application.
static std::filesystem::path GetCrashLogDirectory()
Get the path where crash logs are stored.
static bool HasUnacknowledgedCrashLog()
Check if there's a crash log from a previous session.
static std::filesystem::path PendingCrashLogPathForTesting()
static void AcknowledgeCrashLog()
Mark the current crash log as acknowledged.
static std::string version_
static void PrepareCrashLog(const std::string &version, const std::filesystem::path &directory)
static std::filesystem::path GetMostRecentCrashLog()
Get the path to the most recent crash log, if any.
static std::filesystem::path crash_log_path_
static void WriteCrashLogForTesting(const char *data)
static void PrepareCrashLogForTesting(const std::string &version, const std::filesystem::path &directory)