Rework the way the ReinitSeparation command is called. The old way was way too danger...
[openttd-joker.git] / src / crashlog.h
blob3844e94c5d76345371c8c4acee2544a53ccc48f8
1 /* $Id: crashlog.h 24900 2013-01-08 22:46:42Z planetmaker $ */
3 /*
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/>.
8 */
10 /** @file crashlog.h Functions to be called to log a crash */
12 #ifndef CRASHLOG_H
13 #define CRASHLOG_H
15 /**
16 * Helper class for creating crash logs.
18 class CrashLog {
19 private:
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);
30 protected:
31 /**
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;
39 /**
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;
47 /**
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 nullptr.
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;
56 /**
57 * Writes the stack trace to the buffer, if there is information about it
58 * available.
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;
65 /**
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;
74 /**
75 * Writes the dynamically linked libraries/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;
88 char *LogCommandLog(char *buffer, const char *last) const;
90 public:
91 /** Stub destructor to silence some compilers. */
92 virtual ~CrashLog() {}
94 char *FillCrashLog(char *buffer, const char *last) const;
95 bool WriteCrashLog(const char *buffer, char *filename, const char *filename_last) const;
97 /**
98 * Write the (crash) dump to a file.
99 * @note On success the filename will be filled with the full path of the
100 * crash dump file. Make sure filename is at least \c MAX_PATH big.
101 * @param filename Output for the filename of the written file.
102 * @param filename_last The last position in the filename buffer.
103 * @return if less than 0, error. If 0 no dump is made, otherwise the dump
104 * was successful (not all OSes support dumping files).
106 virtual int WriteCrashDump(char *filename, const char *filename_last) const;
107 bool WriteSavegame(char *filename, const char *filename_last) const;
108 bool WriteScreenshot(char *filename, const char *filename_last) const;
110 bool MakeCrashLog() const;
113 * Initialiser for crash logs; do the appropriate things so crashes are
114 * handled by our crash handler instead of returning straight to the OS.
115 * @note must be implemented by all implementers of CrashLog.
117 static void InitialiseCrashLog();
119 static void SetErrorMessage(const char *message);
120 static void AfterCrashLogCleanup();
122 static const char *GetAbortCrashlogReason();
125 #endif /* CRASHLOG_H */