Files
@ r28828:76c6b8ce3c7c
Branch filter:
Location: cpp/openttd-patchpack/source/src/crashlog.h - annotation
r28828:76c6b8ce3c7c
2.7 KiB
text/x-c
Fix f6dd505: Missing savegame conversion for current_order (#12188)
r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r27914:bfd64f30ccdf r27914:bfd64f30ccdf r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r27160:192bc991c2e6 r26818:9df12eaf020a r14293:a7858a5997d3 r14293:a7858a5997d3 r27914:bfd64f30ccdf r27914:bfd64f30ccdf r27914:bfd64f30ccdf r12947:776ad783fe07 r27914:bfd64f30ccdf r12947:776ad783fe07 r12947:776ad783fe07 r27914:bfd64f30ccdf r27914:bfd64f30ccdf r27914:bfd64f30ccdf r12947:776ad783fe07 r27914:bfd64f30ccdf r26170:40e0ba47161b r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27829:4c64d91d66c7 r27914:bfd64f30ccdf r27914:bfd64f30ccdf r27914:bfd64f30ccdf r12947:776ad783fe07 r12947:776ad783fe07 r27372:06d384d76bd2 r12947:776ad783fe07 r27914:bfd64f30ccdf r27433:f785ea80973e r27433:f785ea80973e r27433:f785ea80973e r27433:f785ea80973e r27433:f785ea80973e r27914:bfd64f30ccdf r27914:bfd64f30ccdf r27914:bfd64f30ccdf r27433:f785ea80973e r27829:4c64d91d66c7 r27433:f785ea80973e r27433:f785ea80973e r13622:200502780bca r27402:8e5c6e9c8a2d r27402:8e5c6e9c8a2d r27833:7f1a953dfadf r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r25047:a8e131d1e25b r25047:a8e131d1e25b r25047:a8e131d1e25b r25047:a8e131d1e25b r25047:a8e131d1e25b r25047:a8e131d1e25b r27160:192bc991c2e6 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 r12947:776ad783fe07 | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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 <http://www.gnu.org/licenses/>.
*/
/** @file crashlog.h Functions to be called to log a crash */
#ifndef CRASHLOG_H
#define CRASHLOG_H
#include "3rdparty/nlohmann/json.hpp"
/**
* Helper class for creating crash logs.
*/
class CrashLog {
private:
/** Error message coming from #FatalError(format, ...). */
static std::string message;
/**
* Convert system crash reason to JSON.
*
* @param survey The JSON object.
*/
virtual void SurveyCrash(nlohmann::json &survey) const = 0;
/**
* Convert stacktrace to JSON.
*
* @param survey The JSON object.
*/
virtual void SurveyStacktrace(nlohmann::json &survey) const = 0;
/**
* 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.
*
* @param section_name The name of the section to be executed. Printed when a crash happens.
* @param func The function to call.
* @return true iff the function returned true.
*/
virtual bool TryExecute(std::string_view section_name, std::function<bool()> &&func) = 0;
protected:
std::string CreateFileName(const char *ext, bool with_dir = true) const;
public:
/** Stub destructor to silence some compilers. */
virtual ~CrashLog() = default;
nlohmann::json survey;
std::string crashlog_filename;
std::string crashdump_filename;
std::string savegame_filename;
std::string screenshot_filename;
void FillCrashLog();
void PrintCrashLog() const;
bool WriteCrashLog();
virtual bool WriteCrashDump();
bool WriteSavegame();
bool WriteScreenshot();
void SendSurvey() const;
void MakeCrashLog();
/**
* Initialiser for crash logs; do the appropriate things so crashes are
* handled by our crash handler instead of returning straight to the OS.
* @note must be implemented by all implementers of CrashLog.
*/
static void InitialiseCrashLog();
/**
* Prepare crash log handler for a newly started thread.
* @note must be implemented by all implementers of CrashLog.
*/
static void InitThread();
static void SetErrorMessage(const std::string &message);
static void AfterCrashLogCleanup();
};
#endif /* CRASHLOG_H */
|