OpenTTD Source: src/crashlog.h Source File

OpenTTD Source 15.3

crashlog.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef CRASHLOG_H
11#define CRASHLOG_H
12
13#include "3rdparty/nlohmann/json.hpp"
14
18 class CrashLog {
19private:
21 static std::string message;
22
28 virtual void SurveyCrash(nlohmann::json &survey) const = 0;
29
35 virtual void SurveyStacktrace(nlohmann::json &survey) const = 0;
36
46 virtual bool TryExecute(std::string_view section_name, std::function<bool()> &&func) = 0;
47
48protected:
49 std::string CreateFileName(std::string_view ext, bool with_dir = true) const;
50
51public:
53 virtual ~CrashLog() = default;
54
55 nlohmann::json survey;
56 std::string crashlog_filename;
57 std::string crashdump_filename;
58 std::string savegame_filename;
59 std::string screenshot_filename;
60
61 void FillCrashLog();
62 void PrintCrashLog() const;
63
64 bool WriteCrashLog();
65 virtual bool WriteCrashDump();
66 bool WriteSavegame();
67 bool WriteScreenshot();
68
69 void SendSurvey() const;
70
71 void MakeCrashLog();
72
78 static void InitialiseCrashLog();
79
84 static void InitThread();
85
86 static void SetErrorMessage(const std::string &message);
87 static void AfterCrashLogCleanup();
88};
89
90#endif /* CRASHLOG_H */
CrashLog
Helper class for creating crash logs.
Definition crashlog.h:18
CrashLog::MakeCrashLog
void MakeCrashLog()
Makes the crash log, writes it to a file and then subsequently tries to make a crash dump and crash s...
Definition crashlog.cpp:272
CrashLog::WriteCrashLog
bool WriteCrashLog()
Write the crash log to a file.
Definition crashlog.cpp:191
CrashLog::SurveyStacktrace
virtual void SurveyStacktrace(nlohmann::json &survey) const =0
Convert stacktrace to JSON.
CrashLog::message
static std::string message
Error message coming from FatalError(format, ...).
Definition crashlog.h:33
CrashLog::SendSurvey
void SendSurvey() const
Send the survey result, noting it was a crash.
Definition crashlog.cpp:260
CrashLog::TryExecute
virtual bool TryExecute(std::string_view section_name, std::function< bool()> &&func)=0
Execute the func() and return its value.
CrashLog::WriteCrashDump
virtual bool WriteCrashDump()
Write the (crash) dump to a file.
Definition crashlog.cpp:212
CrashLog::WriteSavegame
bool WriteSavegame()
Write the (crash) savegame to a file.
Definition crashlog.cpp:223
CrashLog::WriteScreenshot
bool WriteScreenshot()
Write the (crash) screenshot to a file.
Definition crashlog.cpp:246
CrashLog::FillCrashLog
void FillCrashLog()
Fill the crash log buffer with all data of a crash log.
Definition crashlog.cpp:89
CrashLog::InitThread
static void InitThread()
Prepare crash log handler for a newly started thread.
Definition crashlog_osx.cpp:237
CrashLog::SetErrorMessage
static void SetErrorMessage(const std::string &message)
Sets a message for the error message handler.
Definition crashlog.cpp:329
CrashLog::~CrashLog
virtual ~CrashLog()=default
Stub destructor to silence some compilers.
CrashLog::SurveyCrash
virtual void SurveyCrash(nlohmann::json &survey) const =0
Convert system crash reason to JSON.
CrashLog::AfterCrashLogCleanup
static void AfterCrashLogCleanup()
Try to close the sound/video stuff so it doesn't keep lingering around incorrect video states or so,...
Definition crashlog.cpp:338
CrashLog::CreateFileName
std::string CreateFileName(std::string_view ext, bool with_dir=true) const
Create a timestamped filename.
Definition crashlog.cpp:76
CrashLog::InitialiseCrashLog
static void InitialiseCrashLog()
Initialiser for crash logs; do the appropriate things so crashes are handled by our crash handler ins...
Definition crashlog_osx.cpp:232