Initial implementation of scope guard logging for including in crash logs.

This adds a mechanism to create scope guards with an associated std::function
which is called to output diagnostic info in the event of a crash.
Add a macro to make it easy to efficiently capture variables on the stack
and output a formatted message.
Requires C++11, #ifdefed out for legacy compilers.
This commit is contained in:
Jonathan G Rennison
2016-02-17 19:45:07 +00:00
parent e89efa8581
commit 5cf2b04f6a
5 changed files with 148 additions and 0 deletions

View File

@@ -28,6 +28,8 @@
#include "network/network.h"
#include "language.h"
#include "fontcache.h"
#include "scope_info.h"
#include "thread/thread.h"
#include "ai/ai_info.hpp"
#include "game/game.hpp"
@@ -327,6 +329,13 @@ char *CrashLog::FillCrashLog(char *buffer, const char *last) const
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);
#ifdef USE_SCOPE_INFO
if (IsMainThread()) {
buffer += WriteScopeLog(buffer, last);
}
#endif
buffer = this->LogOpenTTDVersion(buffer, last);
buffer = this->LogRegisters(buffer, last);
buffer = this->LogStacktrace(buffer, last);