yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::util::CrashHandler Class Reference

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
 

Detailed Description

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:

  • Timestamp
  • Signal information
  • Stack trace (if available)
  • Application version

Usage: CrashHandler::Initialize("0.3.3");

Crash logs are written to:

  • Windows: APPDATA%/yaze/crash_logs/
  • macOS: ~/.yaze/crash_logs/
  • Linux: ~/.yaze/crash_logs/

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.

Member Function Documentation

◆ Initialize()

void yaze::util::CrashHandler::Initialize ( const std::string & version)
static

Initialize the crash handler for the application.

Parameters
versionThe 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().

Here is the call graph for this function:

◆ GetCrashLogDirectory()

std::filesystem::path yaze::util::CrashHandler::GetCrashLogDirectory ( )
static

Get the path where crash logs are stored.

Returns
The crash log directory path.

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().

Here is the call graph for this function:

◆ GetMostRecentCrashLog()

std::filesystem::path yaze::util::CrashHandler::GetMostRecentCrashLog ( )
static

Get the path to the most recent crash log, if any.

Returns
Path to the most recent crash log, or empty path if none exists.

Definition at line 237 of file crash_handler.cc.

References GetCrashLogDirectory(), and IsHeaderOnlyCrashLog().

Referenced by HasUnacknowledgedCrashLog().

Here is the call graph for this function:

◆ HasUnacknowledgedCrashLog()

bool yaze::util::CrashHandler::HasUnacknowledgedCrashLog ( )
static

Check if there's a crash log from a previous session.

Returns
True if a crash log exists that hasn't been acknowledged.

Definition at line 267 of file crash_handler.cc.

References GetCrashLogDirectory(), and GetMostRecentCrashLog().

Here is the call graph for this function:

◆ AcknowledgeCrashLog()

void yaze::util::CrashHandler::AcknowledgeCrashLog ( )
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().

Here is the call graph for this function:

◆ CleanupOldLogs()

void yaze::util::CrashHandler::CleanupOldLogs ( int keep_count = 5)
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.

Parameters
keep_countNumber of recent logs to keep (default: 5).

Definition at line 295 of file crash_handler.cc.

References GetCrashLogDirectory(), and IsHeaderOnlyCrashLog().

Referenced by SetupCrashHandling().

Here is the call graph for this function:

◆ IsHeaderOnlyCrashLog()

bool yaze::util::CrashHandler::IsHeaderOnlyCrashLog ( const std::filesystem::path & path)
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().

◆ PrepareCrashLogForTesting()

void yaze::util::CrashHandler::PrepareCrashLogForTesting ( const std::string & version,
const std::filesystem::path & directory )
static

Definition at line 177 of file crash_handler.cc.

References PrepareCrashLog(), and ResetForTesting().

Here is the call graph for this function:

◆ WriteCrashLogForTesting()

void yaze::util::CrashHandler::WriteCrashLogForTesting ( const char * data)
static

Definition at line 183 of file crash_handler.cc.

References CrashLogWriter().

Here is the call graph for this function:

◆ PendingCrashLogPathForTesting()

std::filesystem::path yaze::util::CrashHandler::PendingCrashLogPathForTesting ( )
static

Definition at line 187 of file crash_handler.cc.

References crash_log_path_.

◆ ResetForTesting()

void yaze::util::CrashHandler::ResetForTesting ( )
static

Definition at line 191 of file crash_handler.cc.

References crash_log_fd_, and crash_log_path_.

Referenced by PrepareCrashLogForTesting().

◆ PrepareCrashLog()

void yaze::util::CrashHandler::PrepareCrashLog ( const std::string & version,
const std::filesystem::path & directory )
staticprivate

Definition at line 113 of file crash_handler.cc.

References crash_log_path_, and version_.

Referenced by Initialize(), and PrepareCrashLogForTesting().

◆ OpenCrashLogFromSignalHandler()

void yaze::util::CrashHandler::OpenCrashLogFromSignalHandler ( )
staticprivate

Definition at line 61 of file crash_handler.cc.

References crash_log_fd_.

Referenced by CrashLogWriter().

◆ CrashLogWriter()

void yaze::util::CrashHandler::CrashLogWriter ( const char * data)
staticprivate

Definition at line 81 of file crash_handler.cc.

References crash_log_fd_, and OpenCrashLogFromSignalHandler().

Referenced by Initialize(), and WriteCrashLogForTesting().

Here is the call graph for this function:

Member Data Documentation

◆ version_

std::string yaze::util::CrashHandler::version_
staticprivate

Definition at line 106 of file crash_handler.h.

Referenced by PrepareCrashLog().

◆ crash_log_path_

std::filesystem::path yaze::util::CrashHandler::crash_log_path_
staticprivate

◆ crash_log_fd_

int yaze::util::CrashHandler::crash_log_fd_ = -1
staticprivate

Definition at line 108 of file crash_handler.h.

Referenced by CrashLogWriter(), OpenCrashLogFromSignalHandler(), and ResetForTesting().


The documentation for this class was generated from the following files: