4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file crashlog.h Functions to be called to log a crash */
16 * Helper class for creating crash logs.
20 /** Pointer to the error message. */
21 static const char *message
;
23 /** Temporary 'local' location of the buffer. */
24 static char *gamelog_buffer
;
26 /** Temporary 'local' location of the end of the buffer. */
27 static const char *gamelog_last
;
29 static void GamelogFillCrashLog(const char *s
);
32 * Writes OS' version to the buffer.
33 * @param buffer The begin where to write at.
34 * @param last The last position in the buffer to write to.
35 * @return the position of the \c '\0' character after the buffer.
37 virtual char *LogOSVersion(char *buffer
, const char *last
) const = 0;
40 * Writes compiler (and its version, if available) to the buffer.
41 * @param buffer The begin where to write at.
42 * @param last The last position in the buffer to write to.
43 * @return the position of the \c '\0' character after the buffer.
45 virtual char *LogCompiler(char *buffer
, const char *last
) const;
48 * Writes actually encountered error to the buffer.
49 * @param buffer The begin where to write at.
50 * @param last The last position in the buffer to write to.
51 * @param message Message passed to use for possible errors. Can be NULL.
52 * @return the position of the \c '\0' character after the buffer.
54 virtual char *LogError(char *buffer
, const char *last
, const char *message
) const = 0;
57 * Writes the stack trace to the buffer, if there is information about it
59 * @param buffer The begin where to write at.
60 * @param last The last position in the buffer to write to.
61 * @return the position of the \c '\0' character after the buffer.
63 virtual char *LogStacktrace(char *buffer
, const char *last
) const = 0;
66 * Writes information about the data in the registers, if there is
67 * information about it available.
68 * @param buffer The begin where to write at.
69 * @param last The last position in the buffer to write to.
70 * @return the position of the \c '\0' character after the buffer.
72 virtual char *LogRegisters(char *buffer
, const char *last
) const;
75 * Writes the dynamically linked libaries/modules to the buffer, if there
76 * is information about it available.
77 * @param buffer The begin where to write at.
78 * @param last The last position in the buffer to write to.
79 * @return the position of the \c '\0' character after the buffer.
81 virtual char *LogModules(char *buffer
, const char *last
) const;
84 char *LogOpenTTDVersion(char *buffer
, const char *last
) const;
85 char *LogConfiguration(char *buffer
, const char *last
) const;
86 char *LogLibraries(char *buffer
, const char *last
) const;
87 char *LogGamelog(char *buffer
, const char *last
) const;
90 /** Stub destructor to silence some compilers. */
91 virtual ~CrashLog() {}
93 char *FillCrashLog(char *buffer
, const char *last
) const;
94 bool WriteCrashLog(const char *buffer
, char *filename
, const char *filename_last
) const;
97 * Write the (crash) dump to a file.
98 * @note On success the filename will be filled with the full path of the
99 * crash dump file. Make sure filename is at least \c MAX_PATH big.
100 * @param filename Output for the filename of the written file.
101 * @param filename_last The last position in the filename buffer.
102 * @return if less than 0, error. If 0 no dump is made, otherwise the dump
103 * was successful (not all OSes support dumping files).
105 virtual int WriteCrashDump(char *filename
, const char *filename_last
) const;
106 bool WriteSavegame(char *filename
, const char *filename_last
) const;
107 bool WriteScreenshot(char *filename
, const char *filename_last
) const;
109 bool MakeCrashLog() const;
112 * Initialiser for crash logs; do the appropriate things so crashes are
113 * handled by our crash handler instead of returning straight to the OS.
114 * @note must be implemented by all implementers of CrashLog.
116 static void InitialiseCrashLog();
118 static void SetErrorMessage(const char *message
);
119 static void AfterCrashLogCleanup();
122 #endif /* CRASHLOG_H */