OpenTTD Source 20241224-master-gf74b0cf984
|
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. | |
virtual bool | WriteCrashDump () |
Write the (crash) dump to a file. | |
bool | WriteSavegame () |
Write the (crash) savegame to a file. | |
bool | WriteScreenshot () |
Write the (crash) screenshot to a file. | |
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. | |
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. | |
static void | InitThread () |
Prepare crash log handler for a newly started thread. | |
static void | SetErrorMessage (const std::string &message) |
Sets a message for the error message handler. | |
static void | AfterCrashLogCleanup () |
Try to close the sound/video stuff so it doesn't keep lingering around incorrect video states or so, e.g. | |
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. | |
Private Member Functions | |
virtual void | SurveyCrash (nlohmann::json &survey) const =0 |
Convert system crash reason to JSON. | |
virtual void | SurveyStacktrace (nlohmann::json &survey) const =0 |
Convert stacktrace to JSON. | |
virtual bool | TryExecute (std::string_view section_name, std::function< bool()> &&func)=0 |
Execute the func() and return its value. | |
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(), and 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(), WriteSavegame(), and WriteScreenshot().
void CrashLog::FillCrashLog | ( | ) |
Fill the crash log buffer with all data of a crash log.
Definition at line 87 of file crashlog.cpp.
References _current_company, _local_company, CRASHLOG_SURVEY_VERSION, message, SurveyCompanies(), SurveyCompiler(), SurveyConfiguration(), SurveyCrash(), SurveyFont(), SurveyGamelog(), SurveyGameScript(), SurveyGameSession(), SurveyGrfs(), SurveyLibraries(), SurveyOpenTTD(), SurveyPlugins(), SurveyRecentNews(), SurveySettings(), SurveyStacktrace(), SurveyTimers(), and TryExecute().
Referenced by MakeCrashLog().
|
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.
Referenced by StartNewThread().
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(), and HandleCrash().
void CrashLog::PrintCrashLog | ( | ) | const |
Definition at line 164 of file crashlog.cpp.
void CrashLog::SendSurvey | ( | ) | const |
Send the survey result, noting it was a crash.
Definition at line 258 of file crashlog.cpp.
References NetworkSurveyHandler::CRASH, and NetworkSurveyHandler::Transmit().
Referenced by MakeCrashLog().
|
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.
Referenced by FatalErrorI().
|
privatepure virtual |
Convert system crash reason to JSON.
survey | The JSON object. |
Implemented in CrashLogOSX, CrashLogUnix, and CrashLogWindows.
Referenced by FillCrashLog().
|
privatepure virtual |
Convert stacktrace to JSON.
survey | The JSON object. |
Implemented in CrashLogOSX, CrashLogUnix, and CrashLogWindows.
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 CrashLogOSX, CrashLogUnix, and CrashLogWindows.
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.
References _full_screenshot_path, CreateFileName(), MakeScreenshot(), and SC_CRASHLOG.
Referenced by MakeCrashLog().
std::string CrashLog::crashdump_filename |
Definition at line 57 of file crashlog.h.
std::string CrashLog::crashlog_filename |
Definition at line 56 of file crashlog.h.
|
staticprivate |
Error message coming from FatalError(format, ...).
Definition at line 32 of file crashlog.h.
Referenced by CrashLogOSX::DisplayCrashDialog(), FillCrashLog(), and SetErrorMessage().
std::string CrashLog::savegame_filename |
Definition at line 58 of file crashlog.h.
std::string CrashLog::screenshot_filename |
Definition at line 59 of file crashlog.h.
nlohmann::json CrashLog::survey |
Definition at line 55 of file crashlog.h.