/* * 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. */classCrashLog{private:/** Error message coming from #FatalError(format, ...). */staticstd::stringmessage;/** * Convert system crash reason to JSON. * * @param survey The JSON object. */virtualvoidSurveyCrash(nlohmann::json&survey)const=0;/** * Convert stacktrace to JSON. * * @param survey The JSON object. */virtualvoidSurveyStacktrace(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. */virtualboolTryExecute(std::string_viewsection_name,std::function<bool()>&&func)=0;protected:std::stringCreateFileName(constchar*ext,boolwith_dir=true)const;public:/** Stub destructor to silence some compilers. */virtual~CrashLog()=default;nlohmann::jsonsurvey;std::stringcrashlog_filename;std::stringcrashdump_filename;std::stringsavegame_filename;std::stringscreenshot_filename;voidFillCrashLog();voidPrintCrashLog()const;boolWriteCrashLog();virtualboolWriteCrashDump();boolWriteSavegame();boolWriteScreenshot();voidSendSurvey()const;voidMakeCrashLog();/** * 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. */staticvoidInitialiseCrashLog();/** * Prepare crash log handler for a newly started thread. * @note must be implemented by all implementers of CrashLog. */staticvoidInitThread();staticvoidSetErrorMessage(conststd::string&message);staticvoidAfterCrashLogCleanup();};#endif /* CRASHLOG_H */