1#include "DebugFunctions.h"
8#include "Foundation/Logging/Logger.h"
9#include "Foundation/Platform/Unicode.h"
20 std::string getTimeStamp()
26 gmtime_s(&gmTime_s, ¤tTime);
27 auto gmTime = &gmTime_s;
29 auto gmTime = std::gmtime(¤tTime);
34 ss << std::setfill(
'0');
36 ss << 1900 + gmTime->tm_year <<
"-";
37 ss << std::setw(2) << gmTime->tm_mon + 1 <<
"-";
38 ss << std::setw(2) << gmTime->tm_mday <<
" ";
40 ss << std::setw(2) << gmTime->tm_hour <<
"-";
41 ss << std::setw(2) << gmTime->tm_min <<
"-";
42 ss << std::setw(2) << gmTime->tm_sec <<
" ";
51void createMiniDump(BridgeContext* ctx, EXCEPTION_POINTERS * exceptionPointers)
53 auto context =
static_cast<Context*
>(ctx);
54 LOG_ERROR(logger,
"Exception caught in native code. Creating mini dump file.");
56 auto path = context->debug.miniDumpPath + std::string(
"/") + getTimeStamp() + context->debug.miniDumpName + std::string(
".dmp");
58 auto fileHandle = ::CreateFileW(Cogs::widen(path).c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
60 if ((fileHandle != NULL) && (fileHandle != INVALID_HANDLE_VALUE)) {
61 MINIDUMP_EXCEPTION_INFORMATION exceptionInfo;
63 exceptionInfo.ThreadId = ::GetCurrentThreadId();
64 exceptionInfo.ExceptionPointers = exceptionPointers;
65 exceptionInfo.ClientPointers = FALSE;
67 MINIDUMP_TYPE miniDumpType = MiniDumpNormal;
69 auto result = ::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), fileHandle, miniDumpType, &exceptionInfo, 0, 0);
72 LOG_INFO(logger,
"Mini dump written successfully to %s.", path.c_str());
75 LOG_ERROR(logger,
"Error writing mini dump to %s. Possible reasons are stack corruption, insufficient disk space.", path.c_str());
78 ::CloseHandle(fileHandle);
81 LOG_ERROR(logger,
"Error accessing mini dump file path at %s. Check for sufficient disk permissions.", path.c_str());
87void createMiniDump(BridgeContext* )
99enableExecutionChecks(BridgeContext* ctx, CogsBool enabled)
101 auto context =
static_cast<Context*
>(ctx);
110setMiniDumpPath(BridgeContext* ctx,
const char * path)
112 auto context =
static_cast<Context*
>(ctx);
121setMiniDumpName(BridgeContext* ctx,
const char * name)
123 auto context =
static_cast<Context*
>(ctx);
133 void accessViolationMethod()
135 LOG_DEBUG(logger,
"Initiating access violation.");
137 int * iPtr = (
int *) 0;
141 LOG_ERROR(logger,
"Could not trigger access violation of variable %d.", i);
149triggerAccessViolation(BridgeContext* ctx)
151 auto context =
static_cast<Context*
>(ctx);
153 if (context->debug.enableExecutionChecks) {
154 CHECKED(context, accessViolationMethod());
156 accessViolationMethod();
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Log implementation class.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
constexpr Log getLogger(const char(&name)[LEN]) noexcept
COGSFOUNDATION_API Time currentTime()
High resolution clock time (NTP / UTC time). Returns an implementation defined absolute timestamp,...
std::string miniDumpName
Naming pattern for minidumps.
bool enableExecutionChecks
If execution checks should be enabled where applicable. See the CHECKED macro.
std::string miniDumpPath
Path to store minidump files at.