forked from Ports/perfect_dark
port: write crash info to log file even without --log
This commit is contained in:
1 parent
c487e423b1
commit
b1b17e21c1
3 files changed
+31
-13
No files matched your search
@@ -24,6 +24,7 @@ u64 sysGetMicroseconds(void);
|
|||||||
|
|
||||||
void sysFatalError(const char *fmt, ...) __attribute__((noreturn));
|
void sysFatalError(const char *fmt, ...) __attribute__((noreturn));
|
||||||
|
|
||||||
|
void sysLogStartCrash(void);
|
||||||
void sysLogPrintf(s32 level, const char *fmt, ...);
|
void sysLogPrintf(s32 level, const char *fmt, ...);
|
||||||
|
|
||||||
void sysGetExecutablePath(char *outPath, const u32 outLen);
|
void sysGetExecutablePath(char *outPath, const u32 outLen);
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ static long __stdcall crashHandler(PEXCEPTION_POINTERS exinfo)
|
|||||||
return EXCEPTION_CONTINUE_EXECUTION;
|
return EXCEPTION_CONTINUE_EXECUTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start writing to a crash log file
|
||||||
|
sysLogStartCrash();
|
||||||
|
|
||||||
sysLogPrintf(LOG_ERROR, "FATAL: Crashed: PC=%p CODE=0x%08lx", exinfo->ExceptionRecord->ExceptionAddress, exinfo->ExceptionRecord->ExceptionCode);
|
sysLogPrintf(LOG_ERROR, "FATAL: Crashed: PC=%p CODE=0x%08lx", exinfo->ExceptionRecord->ExceptionAddress, exinfo->ExceptionRecord->ExceptionCode);
|
||||||
|
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|||||||
+27
-13
@@ -11,6 +11,7 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
#define LOG_FNAME "pd.log"
|
#define LOG_FNAME "pd.log"
|
||||||
|
#define CRASHLOG_FNAME "pd.crash.log"
|
||||||
#define USEC_IN_SEC 1000000ULL
|
#define USEC_IN_SEC 1000000ULL
|
||||||
|
|
||||||
static u64 startTick = 0;
|
static u64 startTick = 0;
|
||||||
@@ -19,6 +20,24 @@ static char logPath[2048];
|
|||||||
static s32 sysArgc;
|
static s32 sysArgc;
|
||||||
static const char **sysArgv;
|
static const char **sysArgv;
|
||||||
|
|
||||||
|
static inline void sysLogSetPath(const char *fname)
|
||||||
|
{
|
||||||
|
// figure out where the log is and clear it
|
||||||
|
// try working dir first
|
||||||
|
snprintf(logPath, sizeof(logPath), "./%s", fname);
|
||||||
|
FILE *f = fopen(logPath, "wb");
|
||||||
|
if (!f) {
|
||||||
|
// try home dir
|
||||||
|
sysGetHomePath(logPath, sizeof(logPath) - 1);
|
||||||
|
strncat(logPath, "/", sizeof(logPath) - 1);
|
||||||
|
strncat(logPath, fname, sizeof(logPath) - 1);
|
||||||
|
f = fopen(logPath, "wb");
|
||||||
|
}
|
||||||
|
if (f) {
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sysInitArgs(s32 argc, const char **argv)
|
void sysInitArgs(s32 argc, const char **argv)
|
||||||
{
|
{
|
||||||
sysArgc = argc;
|
sysArgc = argc;
|
||||||
@@ -30,19 +49,7 @@ void sysInit(void)
|
|||||||
startTick = sysGetMicroseconds();
|
startTick = sysGetMicroseconds();
|
||||||
|
|
||||||
if (sysArgCheck("--log")) {
|
if (sysArgCheck("--log")) {
|
||||||
// figure out where the log is and clear it
|
sysLogSetPath(LOG_FNAME);
|
||||||
// try working dir first
|
|
||||||
snprintf(logPath, sizeof(logPath), "./%s", LOG_FNAME);
|
|
||||||
FILE *f = fopen(logPath, "wb");
|
|
||||||
if (!f) {
|
|
||||||
// try home dir
|
|
||||||
sysGetHomePath(logPath, sizeof(logPath) - 1);
|
|
||||||
strncat(logPath, "/" LOG_FNAME, sizeof(logPath) - 1);
|
|
||||||
f = fopen(logPath, "wb");
|
|
||||||
}
|
|
||||||
if (f) {
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERSION_HASH
|
#ifdef VERSION_HASH
|
||||||
@@ -96,6 +103,13 @@ u64 sysGetMicroseconds(void)
|
|||||||
return ((u64)tv.tv_sec * USEC_IN_SEC + (u64)tv.tv_usec) - startTick;
|
return ((u64)tv.tv_sec * USEC_IN_SEC + (u64)tv.tv_usec) - startTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sysLogStartCrash(void)
|
||||||
|
{
|
||||||
|
if (!logPath[0]) {
|
||||||
|
sysLogSetPath(CRASHLOG_FNAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sysLogPrintf(s32 level, const char *fmt, ...)
|
void sysLogPrintf(s32 level, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
static const char *prefix[3] = {
|
static const char *prefix[3] = {
|
||||||
|
|||||||
Reference in new issue
Block a user