mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: put stack variables in global variables for gamelog/crashlog
This commit is contained in:
parent
ed7685910d
commit
d51d08ddcb
|
@ -67,9 +67,7 @@
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
/* static */ const char *CrashLog::message = nullptr;
|
/* static */ std::string CrashLog::message{ "<none>" };
|
||||||
/* static */ char *CrashLog::gamelog_buffer = nullptr;
|
|
||||||
/* static */ const char *CrashLog::gamelog_last = nullptr;
|
|
||||||
|
|
||||||
char *CrashLog::LogCompiler(char *buffer, const char *last) const
|
char *CrashLog::LogCompiler(char *buffer, const char *last) const
|
||||||
{
|
{
|
||||||
|
@ -279,15 +277,6 @@ char *CrashLog::LogLibraries(char *buffer, const char *last) const
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function for printing the gamelog.
|
|
||||||
* @param s the string to print.
|
|
||||||
*/
|
|
||||||
/* static */ void CrashLog::GamelogFillCrashLog(const char *s)
|
|
||||||
{
|
|
||||||
CrashLog::gamelog_buffer += seprintf(CrashLog::gamelog_buffer, CrashLog::gamelog_last, "%s\n", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the gamelog data to the buffer.
|
* Writes the gamelog data to the buffer.
|
||||||
* @param buffer The begin where to write at.
|
* @param buffer The begin where to write at.
|
||||||
|
@ -296,10 +285,10 @@ char *CrashLog::LogLibraries(char *buffer, const char *last) const
|
||||||
*/
|
*/
|
||||||
char *CrashLog::LogGamelog(char *buffer, const char *last) const
|
char *CrashLog::LogGamelog(char *buffer, const char *last) const
|
||||||
{
|
{
|
||||||
CrashLog::gamelog_buffer = buffer;
|
GamelogPrint([&buffer, last](const char *s) {
|
||||||
CrashLog::gamelog_last = last;
|
buffer += seprintf(buffer, last, "%s\n", s);
|
||||||
GamelogPrint(&CrashLog::GamelogFillCrashLog);
|
});
|
||||||
return CrashLog::gamelog_buffer + seprintf(CrashLog::gamelog_buffer, last, "\n");
|
return buffer + seprintf(buffer, last, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -358,7 +347,7 @@ char *CrashLog::FillCrashLog(char *buffer, const char *last) const
|
||||||
ConvertDateToYMD(_date, &ymd);
|
ConvertDateToYMD(_date, &ymd);
|
||||||
buffer += seprintf(buffer, last, "In game date: %i-%02i-%02i (%i)\n\n", ymd.year, ymd.month + 1, ymd.day, _date_fract);
|
buffer += seprintf(buffer, last, "In game date: %i-%02i-%02i (%i)\n\n", ymd.year, ymd.month + 1, ymd.day, _date_fract);
|
||||||
|
|
||||||
buffer = this->LogError(buffer, last, CrashLog::message);
|
buffer = this->LogError(buffer, last, CrashLog::message.c_str());
|
||||||
buffer = this->LogOpenTTDVersion(buffer, last);
|
buffer = this->LogOpenTTDVersion(buffer, last);
|
||||||
buffer = this->LogRegisters(buffer, last);
|
buffer = this->LogRegisters(buffer, last);
|
||||||
buffer = this->LogStacktrace(buffer, last);
|
buffer = this->LogStacktrace(buffer, last);
|
||||||
|
|
|
@ -15,16 +15,8 @@
|
||||||
*/
|
*/
|
||||||
class CrashLog {
|
class CrashLog {
|
||||||
private:
|
private:
|
||||||
/** Pointer to the error message. */
|
/** Error message coming from #error(const char *, ...). */
|
||||||
static const char *message;
|
static std::string message;
|
||||||
|
|
||||||
/** Temporary 'local' location of the buffer. */
|
|
||||||
static char *gamelog_buffer;
|
|
||||||
|
|
||||||
/** Temporary 'local' location of the end of the buffer. */
|
|
||||||
static const char *gamelog_last;
|
|
||||||
|
|
||||||
static void GamelogFillCrashLog(const char *s);
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Writes OS' version to the buffer.
|
* Writes OS' version to the buffer.
|
||||||
|
@ -46,7 +38,7 @@ protected:
|
||||||
* Writes actually encountered error to the buffer.
|
* Writes actually encountered error to the buffer.
|
||||||
* @param buffer The begin where to write at.
|
* @param buffer The begin where to write at.
|
||||||
* @param last The last position in the buffer to write to.
|
* @param last The last position in the buffer to write to.
|
||||||
* @param message Message passed to use for possible errors. Can be nullptr.
|
* @param message Message passed to use for errors.
|
||||||
* @return the position of the \c '\0' character after the buffer.
|
* @return the position of the \c '\0' character after the buffer.
|
||||||
*/
|
*/
|
||||||
virtual char *LogError(char *buffer, const char *last, const char *message) const = 0;
|
virtual char *LogError(char *buffer, const char *last, const char *message) const = 0;
|
||||||
|
|
|
@ -189,7 +189,7 @@ typedef SmallMap<uint32, GRFPresence> GrfIDMapping;
|
||||||
* Prints active gamelog
|
* Prints active gamelog
|
||||||
* @param proc the procedure to draw with
|
* @param proc the procedure to draw with
|
||||||
*/
|
*/
|
||||||
void GamelogPrint(GamelogPrintProc *proc)
|
void GamelogPrint(std::function<void(const char*)> proc)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
GrfIDMapping grf_names;
|
GrfIDMapping grf_names;
|
||||||
|
@ -341,25 +341,14 @@ void GamelogPrint(GamelogPrintProc *proc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void GamelogPrintConsoleProc(const char *s)
|
|
||||||
{
|
|
||||||
IConsolePrint(CC_WARNING, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Print the gamelog data to the console. */
|
/** Print the gamelog data to the console. */
|
||||||
void GamelogPrintConsole()
|
void GamelogPrintConsole()
|
||||||
{
|
{
|
||||||
GamelogPrint(&GamelogPrintConsoleProc);
|
GamelogPrint([](const char *s) {
|
||||||
|
IConsolePrint(CC_WARNING, s);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _gamelog_print_level = 0; ///< gamelog debug level we need to print stuff
|
|
||||||
|
|
||||||
static void GamelogPrintDebugProc(const char *s)
|
|
||||||
{
|
|
||||||
Debug(gamelog, _gamelog_print_level, "{}", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints gamelog to debug output. Code is executed even when
|
* Prints gamelog to debug output. Code is executed even when
|
||||||
* there will be no output. It is called very seldom, so it
|
* there will be no output. It is called very seldom, so it
|
||||||
|
@ -368,8 +357,9 @@ static void GamelogPrintDebugProc(const char *s)
|
||||||
*/
|
*/
|
||||||
void GamelogPrintDebug(int level)
|
void GamelogPrintDebug(int level)
|
||||||
{
|
{
|
||||||
_gamelog_print_level = level;
|
GamelogPrint([level](const char *s) {
|
||||||
GamelogPrint(&GamelogPrintDebugProc);
|
Debug(gamelog, level, "{}", s);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#ifndef GAMELOG_H
|
#ifndef GAMELOG_H
|
||||||
#define GAMELOG_H
|
#define GAMELOG_H
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include "newgrf_config.h"
|
#include "newgrf_config.h"
|
||||||
|
|
||||||
/** The actions we log. */
|
/** The actions we log. */
|
||||||
|
@ -32,13 +33,7 @@ void GamelogStopAnyAction();
|
||||||
void GamelogFree(struct LoggedAction *gamelog_action, uint gamelog_actions);
|
void GamelogFree(struct LoggedAction *gamelog_action, uint gamelog_actions);
|
||||||
void GamelogReset();
|
void GamelogReset();
|
||||||
|
|
||||||
/**
|
void GamelogPrint(std::function<void(const char *)> proc);
|
||||||
* Callback for printing text.
|
|
||||||
* @param s The string to print.
|
|
||||||
*/
|
|
||||||
typedef void GamelogPrintProc(const char *s);
|
|
||||||
void GamelogPrint(GamelogPrintProc *proc); // needed for WIN32 crash.log
|
|
||||||
|
|
||||||
void GamelogPrintDebug(int level);
|
void GamelogPrintDebug(int level);
|
||||||
void GamelogPrintConsole();
|
void GamelogPrintConsole();
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ class CrashLogOSX : public CrashLog {
|
||||||
" Message: %s\n\n",
|
" Message: %s\n\n",
|
||||||
strsignal(this->signum),
|
strsignal(this->signum),
|
||||||
this->signum,
|
this->signum,
|
||||||
message == nullptr ? "<none>" : message
|
message
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class CrashLogUnix : public CrashLog {
|
||||||
" Message: %s\n\n",
|
" Message: %s\n\n",
|
||||||
strsignal(this->signum),
|
strsignal(this->signum),
|
||||||
this->signum,
|
this->signum,
|
||||||
message == nullptr ? "<none>" : message
|
message
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ public:
|
||||||
" Message: %s\n\n",
|
" Message: %s\n\n",
|
||||||
(int)ep->ExceptionRecord->ExceptionCode,
|
(int)ep->ExceptionRecord->ExceptionCode,
|
||||||
(size_t)ep->ExceptionRecord->ExceptionAddress,
|
(size_t)ep->ExceptionRecord->ExceptionAddress,
|
||||||
message == nullptr ? "<none>" : message
|
message
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue