OpenTTD Source  20241121-master-g67a0fccfad
crashlog_win.cpp File Reference

Implementation of a crashlogger for Windows. More...

#include "../../stdafx.h"
#include "../../crashlog.h"
#include "win32.h"
#include "../../core/math_func.hpp"
#include "../../string_func.h"
#include "../../fileio_func.h"
#include "../../strings_func.h"
#include "../../gamelog.h"
#include "../../saveload/saveload.h"
#include "../../video/video_driver.hpp"
#include "../../library_loader.h"
#include <windows.h>
#include <mmsystem.h>
#include <signal.h>
#include <psapi.h>
#include <setjmp.h>
#include "../../safeguards.h"

Go to the source code of this file.

Data Structures

class  CrashLogWindows
 Windows implementation for the crash logger. More...
 

Functions

static void ImmediateExitProcess (uint exit_code)
 Forcefully try to terminate the application. More...
 
bool CloseConsoleLogIfActive ()
 
static void ShowCrashlogWindow ()
 
static LONG WINAPI ExceptionHandler (EXCEPTION_POINTERS *ep)
 
static LONG WINAPI VectoredExceptionHandler (EXCEPTION_POINTERS *ep)
 
static void CDECL CustomAbort (int)
 
static void SetWndSize (HWND wnd, int mode)
 
static INT_PTR CALLBACK CrashDialogFunc (HWND wnd, UINT msg, WPARAM wParam, LPARAM)
 

Variables

static constexpr DWORD CUSTOM_ABORT_EXCEPTION = 0xE1212012
 Exception code used for custom abort.
 
static const std::map< DWORD, std::string > exception_code_to_name
 A map between exception code and its name. More...
 
thread_local void * _safe_esp = nullptr
 Stack pointer for use when 'starting' the crash handler. More...
 
static bool _expanded
 
static const wchar_t _crash_desc []
 
static const wchar_t *const _expand_texts [] = {L"S&how report >>", L"&Hide report <<" }
 

Detailed Description

Implementation of a crashlogger for Windows.

Definition in file crashlog_win.cpp.

Function Documentation

◆ ImmediateExitProcess()

static void ImmediateExitProcess ( uint  exit_code)
static

Forcefully try to terminate the application.

Parameters
exit_codeThe exit code to return.

Definition at line 74 of file crashlog_win.cpp.

Variable Documentation

◆ _crash_desc

const wchar_t _crash_desc[]
static
Initial value:
=
L"A serious fault condition occurred in the game. The game will shut down.\n"
L"Please send crash.json.log, crash.dmp, and crash.sav to the developers.\n"
L"This will greatly help debugging.\n\n"
L"https://github.com/OpenTTD/OpenTTD/issues\n\n"
L"%s\n%s\n%s\n%s\n"

Definition at line 438 of file crashlog_win.cpp.

◆ _safe_esp

thread_local void* _safe_esp = nullptr

Stack pointer for use when 'starting' the crash handler.

Not static as gcc's inline assembly needs it that way.

Definition at line 307 of file crashlog_win.cpp.

◆ exception_code_to_name

const std::map<DWORD, std::string> exception_code_to_name
static
Initial value:
{
{EXCEPTION_ACCESS_VIOLATION, "EXCEPTION_ACCESS_VIOLATION"},
{EXCEPTION_ARRAY_BOUNDS_EXCEEDED, "EXCEPTION_ARRAY_BOUNDS_EXCEEDED"},
{EXCEPTION_BREAKPOINT, "EXCEPTION_BREAKPOINT"},
{EXCEPTION_DATATYPE_MISALIGNMENT, "EXCEPTION_DATATYPE_MISALIGNMENT"},
{EXCEPTION_FLT_DENORMAL_OPERAND, "EXCEPTION_FLT_DENORMAL_OPERAND"},
{EXCEPTION_FLT_DIVIDE_BY_ZERO, "EXCEPTION_FLT_DIVIDE_BY_ZERO"},
{EXCEPTION_FLT_INEXACT_RESULT, "EXCEPTION_FLT_INEXACT_RESULT"},
{EXCEPTION_FLT_INVALID_OPERATION, "EXCEPTION_FLT_INVALID_OPERATION"},
{EXCEPTION_FLT_OVERFLOW, "EXCEPTION_FLT_OVERFLOW"},
{EXCEPTION_FLT_STACK_CHECK, "EXCEPTION_FLT_STACK_CHECK"},
{EXCEPTION_FLT_UNDERFLOW, "EXCEPTION_FLT_UNDERFLOW"},
{EXCEPTION_GUARD_PAGE, "EXCEPTION_GUARD_PAGE"},
{EXCEPTION_ILLEGAL_INSTRUCTION, "EXCEPTION_ILLEGAL_INSTRUCTION"},
{EXCEPTION_IN_PAGE_ERROR, "EXCEPTION_IN_PAGE_ERROR"},
{EXCEPTION_INT_DIVIDE_BY_ZERO, "EXCEPTION_INT_DIVIDE_BY_ZERO"},
{EXCEPTION_INT_OVERFLOW, "EXCEPTION_INT_OVERFLOW"},
{EXCEPTION_INVALID_DISPOSITION, "EXCEPTION_INVALID_DISPOSITION"},
{EXCEPTION_INVALID_HANDLE, "EXCEPTION_INVALID_HANDLE"},
{EXCEPTION_NONCONTINUABLE_EXCEPTION, "EXCEPTION_NONCONTINUABLE_EXCEPTION"},
{EXCEPTION_PRIV_INSTRUCTION, "EXCEPTION_PRIV_INSTRUCTION"},
{EXCEPTION_SINGLE_STEP, "EXCEPTION_SINGLE_STEP"},
{EXCEPTION_STACK_OVERFLOW, "EXCEPTION_STACK_OVERFLOW"},
{STATUS_UNWIND_CONSOLIDATE, "STATUS_UNWIND_CONSOLIDATE"},
}

A map between exception code and its name.

Definition at line 43 of file crashlog_win.cpp.

Referenced by CrashLogWindows::SurveyCrash().