Manages crash logging for release builds. More...
#include <crash_handler.h>
Static Public Member Functions | |
| 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 std::filesystem::path | GetMostRecentCrashLog () |
| Get the path to the most recent crash log, if any. | |
| static bool | HasUnacknowledgedCrashLog () |
| Check if there's a crash log from a previous session. | |
| static void | AcknowledgeCrashLog () |
| Mark the current crash log as acknowledged. | |
| 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 | PrepareCrashLogForTesting (const std::string &version, const std::filesystem::path &directory) |
| static void | WriteCrashLogForTesting (const char *data) |
| static std::filesystem::path | PendingCrashLogPathForTesting () |
| static void | ResetForTesting () |
Static Private Member Functions | |
| static void | PrepareCrashLog (const std::string &version, const std::filesystem::path &directory) |
| static void | OpenCrashLogFromSignalHandler () |
| static void | CrashLogWriter (const char *data) |
Static Private Attributes | |
| static std::string | version_ |
| static std::filesystem::path | crash_log_path_ |
| static int | crash_log_fd_ = -1 |
Manages crash logging for release builds.
This class sets up signal handlers to capture crashes and write detailed crash reports to a log file in the user's data directory. The crash report includes:
Usage: CrashHandler::Initialize("0.3.3");
Crash logs are written to:
The log file is created only when the signal handler first writes, so a session that exits normally leaves no crash_*.log behind.
Definition at line 33 of file crash_handler.h.
|
static |
Initialize the crash handler for the application.
| version | The application version string. |
This should be called early in main() after initializing the symbolizer. In debug builds, this may be less aggressive to allow debugging.
Definition at line 162 of file crash_handler.cc.
References CrashLogWriter(), GetCrashLogDirectory(), and PrepareCrashLog().
Referenced by SetupCrashHandling().

|
static |
Get the path where crash logs are stored.
Definition at line 221 of file crash_handler.cc.
References yaze::util::PlatformPaths::GetAppDataSubdirectory(), and yaze::util::PlatformPaths::GetTempDirectory().
Referenced by AcknowledgeCrashLog(), CleanupOldLogs(), GetMostRecentCrashLog(), HasUnacknowledgedCrashLog(), and Initialize().

|
static |
Get the path to the most recent crash log, if any.
Definition at line 237 of file crash_handler.cc.
References GetCrashLogDirectory(), and IsHeaderOnlyCrashLog().
Referenced by HasUnacknowledgedCrashLog().

|
static |
Check if there's a crash log from a previous session.
Definition at line 267 of file crash_handler.cc.
References GetCrashLogDirectory(), and GetMostRecentCrashLog().

|
static |
Mark the current crash log as acknowledged.
Call this after showing the user the crash report dialog.
Definition at line 286 of file crash_handler.cc.
References GetCrashLogDirectory().

|
static |
Clean up old crash logs, keeping only the most recent N logs.
Header-only logs left by builds that created the file at startup are removed regardless of count; they never recorded a crash.
| keep_count | Number of recent logs to keep (default: 5). |
Definition at line 295 of file crash_handler.cc.
References GetCrashLogDirectory(), and IsHeaderOnlyCrashLog().
Referenced by SetupCrashHandling().

|
static |
True if the file holds only the report header, with nothing written by the signal handler after it.
Definition at line 202 of file crash_handler.cc.
Referenced by CleanupOldLogs(), and GetMostRecentCrashLog().
|
static |
Definition at line 177 of file crash_handler.cc.
References PrepareCrashLog(), and ResetForTesting().

|
static |
Definition at line 183 of file crash_handler.cc.
References CrashLogWriter().

|
static |
Definition at line 187 of file crash_handler.cc.
References crash_log_path_.
|
static |
Definition at line 191 of file crash_handler.cc.
References crash_log_fd_, and crash_log_path_.
Referenced by PrepareCrashLogForTesting().
|
staticprivate |
Definition at line 113 of file crash_handler.cc.
References crash_log_path_, and version_.
Referenced by Initialize(), and PrepareCrashLogForTesting().
|
staticprivate |
Definition at line 61 of file crash_handler.cc.
References crash_log_fd_.
Referenced by CrashLogWriter().
|
staticprivate |
Definition at line 81 of file crash_handler.cc.
References crash_log_fd_, and OpenCrashLogFromSignalHandler().
Referenced by Initialize(), and WriteCrashLogForTesting().

|
staticprivate |
Definition at line 106 of file crash_handler.h.
Referenced by PrepareCrashLog().
|
staticprivate |
Definition at line 107 of file crash_handler.h.
Referenced by PendingCrashLogPathForTesting(), PrepareCrashLog(), and ResetForTesting().
|
staticprivate |
Definition at line 108 of file crash_handler.h.
Referenced by CrashLogWriter(), OpenCrashLogFromSignalHandler(), and ResetForTesting().