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 <http://www.gnu.org/licenses/>.
8 /** @file crashlog.h Functions to be called to log a crash */
14 * Helper class for creating crash logs.
18 /** Pointer to the error message. */
19 static const char *message
;
21 /** Temporary 'local' location of the buffer. */
22 static char *gamelog_buffer
;
24 /** Temporary 'local' location of the end of the buffer. */
25 static const char *gamelog_last
;
27 static void GamelogFillCrashLog(const char *s
);
30 * Writes OS' version to the buffer.
31 * @param buffer The begin where to write at.
32 * @param last The last position in the buffer to write to.
33 * @return the position of the \c '\0' character after the buffer.
35 virtual char *LogOSVersion(char *buffer
, const char *last
) const = 0;
38 * Writes compiler (and its version, if available) to the buffer.
39 * @param buffer The begin where to write at.
40 * @param last The last position in the buffer to write to.
41 * @return the position of the \c '\0' character after the buffer.
43 virtual char *LogCompiler(char *buffer
, const char *last
) const;
46 * Writes actually encountered error to the buffer.
47 * @param buffer The begin where to write at.
48 * @param last The last position in the buffer to write to.
49 * @param message Message passed to use for possible errors. Can be nullptr.
50 * @return the position of the \c '\0' character after the buffer.
52 virtual char *LogError(char *buffer
, const char *last
, const char *message
) const = 0;
55 * Writes the stack trace to the buffer, if there is information about it
57 * @param buffer The begin where to write at.
58 * @param last The last position in the buffer to write to.
59 * @return the position of the \c '\0' character after the buffer.
61 virtual char *LogStacktrace(char *buffer
, const char *last
) const = 0;
64 * Writes information about the data in the registers, if there is
65 * information about it available.
66 * @param buffer The begin where to write at.
67 * @param last The last position in the buffer to write to.
68 * @return the position of the \c '\0' character after the buffer.
70 virtual char *LogRegisters(char *buffer
, const char *last
) const;
73 * Writes the dynamically linked libraries/modules to the buffer, if there
74 * is information about it available.
75 * @param buffer The begin where to write at.
76 * @param last The last position in the buffer to write to.
77 * @return the position of the \c '\0' character after the buffer.
79 virtual char *LogModules(char *buffer
, const char *last
) const;
82 char *LogOpenTTDVersion(char *buffer
, const char *last
) const;
83 char *LogConfiguration(char *buffer
, const char *last
) const;
84 char *LogLibraries(char *buffer
, const char *last
) const;
85 char *LogGamelog(char *buffer
, const char *last
) const;
86 char *LogRecentNews(char *buffer
, const char *list
) const;
89 /** Stub destructor to silence some compilers. */
90 virtual ~CrashLog() {}
92 char *FillCrashLog(char *buffer
, const char *last
) const;
93 bool WriteCrashLog(const char *buffer
, char *filename
, const char *filename_last
) const;
96 * Write the (crash) dump to a file.
97 * @note On success the filename will be filled with the full path of the
98 * crash dump file. Make sure filename is at least \c MAX_PATH big.
99 * @param filename Output for the filename of the written file.
100 * @param filename_last The last position in the filename buffer.
101 * @return if less than 0, error. If 0 no dump is made, otherwise the dump
102 * was successful (not all OSes support dumping files).
104 virtual int WriteCrashDump(char *filename
, const char *filename_last
) const;
105 bool WriteSavegame(char *filename
, const char *filename_last
) const;
106 bool WriteScreenshot(char *filename
, const char *filename_last
) const;
108 bool MakeCrashLog() const;
111 * Initialiser for crash logs; do the appropriate things so crashes are
112 * handled by our crash handler instead of returning straight to the OS.
113 * @note must be implemented by all implementers of CrashLog.
115 static void InitialiseCrashLog();
117 static void SetErrorMessage(const char *message
);
118 static void AfterCrashLogCleanup();
121 #endif /* CRASHLOG_H */