OpenTTD Source
20241121-master-g67a0fccfad
|
Helper class for creating crash logs. More...
#include <crashlog.h>
Public Member Functions | |
virtual | ~CrashLog ()=default |
Stub destructor to silence some compilers. | |
void | FillCrashLog () |
Fill the crash log buffer with all data of a crash log. | |
void | PrintCrashLog () const |
bool | WriteCrashLog () |
Write the crash log to a file. More... | |
virtual bool | WriteCrashDump () |
Write the (crash) dump to a file. More... | |
bool | WriteSavegame () |
Write the (crash) savegame to a file. More... | |
bool | WriteScreenshot () |
Write the (crash) screenshot to a file. More... | |
void | SendSurvey () const |
Send the survey result, noting it was a crash. | |
void | MakeCrashLog () |
Makes the crash log, writes it to a file and then subsequently tries to make a crash dump and crash savegame. More... | |
Static Public Member Functions | |
static void | InitialiseCrashLog () |
Initialiser for crash logs; do the appropriate things so crashes are handled by our crash handler instead of returning straight to the OS. More... | |
static void | InitThread () |
Prepare crash log handler for a newly started thread. More... | |
static void | SetErrorMessage (const std::string &message) |
Sets a message for the error message handler. More... | |
static void | AfterCrashLogCleanup () |
Try to close the sound/video stuff so it doesn't keep lingering around incorrect video states or so, e.g. More... | |
Data Fields | |
nlohmann::json | survey |
std::string | crashlog_filename |
std::string | crashdump_filename |
std::string | savegame_filename |
std::string | screenshot_filename |
Protected Member Functions | |
std::string | CreateFileName (const char *ext, bool with_dir=true) const |
Create a timestamped filename. More... | |
Private Member Functions | |
virtual void | SurveyCrash (nlohmann::json &survey) const =0 |
Convert system crash reason to JSON. More... | |
virtual void | SurveyStacktrace (nlohmann::json &survey) const =0 |
Convert stacktrace to JSON. More... | |
virtual bool | TryExecute (std::string_view section_name, std::function< bool()> &&func)=0 |
Execute the func() and return its value. More... | |
Static Private Attributes | |
static std::string | message {} |
Error message coming from #FatalError(format, ...). | |
Helper class for creating crash logs.
Definition at line 18 of file crashlog.h.
|
static |
Try to close the sound/video stuff so it doesn't keep lingering around incorrect video states or so, e.g.
keeping dpmi disabled.
Definition at line 336 of file crashlog.cpp.
References MusicDriver::GetInstance(), SoundDriver::GetInstance(), VideoDriver::GetInstance(), and Driver::Stop().
Referenced by HandleCrash().
|
protected |
Create a timestamped filename.
ext | The extension for the filename. |
with_dir | Whether to prepend the filename with the personal directory. |
Definition at line 74 of file crashlog.cpp.
References _personal_dir.
Referenced by WriteCrashLog(), and WriteSavegame().
|
static |
Initialiser for crash logs; do the appropriate things so crashes are handled by our crash handler instead of returning straight to the OS.
Definition at line 233 of file crashlog_osx.cpp.
References HandleCrash(), and SetSignals().
|
static |
Prepare crash log handler for a newly started thread.
Definition at line 238 of file crashlog_osx.cpp.
void CrashLog::MakeCrashLog | ( | ) |
Makes the crash log, writes it to a file and then subsequently tries to make a crash dump and crash savegame.
It uses DEBUG to write information like paths to the console.
Definition at line 270 of file crashlog.cpp.
References FillCrashLog(), SendSurvey(), TryExecute(), WriteCrashDump(), WriteCrashLog(), WriteSavegame(), and WriteScreenshot().
Referenced by HandleCrash().
|
static |
Sets a message for the error message handler.
message | The error message of the error. |
Definition at line 327 of file crashlog.cpp.
References message.
|
privatepure virtual |
Convert system crash reason to JSON.
survey | The JSON object. |
Implemented in CrashLogWindows, CrashLogUnix, and CrashLogOSX.
Referenced by FillCrashLog().
|
privatepure virtual |
Convert stacktrace to JSON.
survey | The JSON object. |
Implemented in CrashLogWindows, and CrashLogOSX.
Referenced by FillCrashLog().
|
privatepure virtual |
Execute the func() and return its value.
If any exception / signal / crash happens, catch it and return false. This function should, in theory, never not return, even in the worst conditions.
section_name | The name of the section to be executed. Printed when a crash happens. |
func | The function to call. |
Implemented in CrashLogWindows, CrashLogUnix, and CrashLogOSX.
Referenced by FillCrashLog(), and MakeCrashLog().
|
virtual |
Write the (crash) dump to a file.
crashdump_filename
when there is a successful return. Definition at line 210 of file crashlog.cpp.
Referenced by MakeCrashLog().
bool CrashLog::WriteCrashLog | ( | ) |
Write the crash log to a file.
crashlog_filename
. Definition at line 189 of file crashlog.cpp.
References CreateFileName(), FioFOpenFile(), and NO_DIRECTORY.
Referenced by MakeCrashLog().
bool CrashLog::WriteSavegame | ( | ) |
Write the (crash) savegame to a file.
savegame_filename
. Definition at line 221 of file crashlog.cpp.
References _gamelog, CreateFileName(), DFT_GAME_FILE, Gamelog::Emergency(), Map::IsInitialized(), NO_DIRECTORY, SaveOrLoad(), SL_OK, and SLO_SAVE.
Referenced by MakeCrashLog().
bool CrashLog::WriteScreenshot | ( | ) |
Write the (crash) screenshot to a file.
screenshot_filename
. Definition at line 244 of file crashlog.cpp.
Referenced by MakeCrashLog().