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 sysLogStartCrash(void);
|
||||
void sysLogPrintf(s32 level, const char *fmt, ...);
|
||||
|
||||
void sysGetExecutablePath(char *outPath, const u32 outLen);
|
||||
|
||||
@@ -128,6 +128,9 @@ static long __stdcall crashHandler(PEXCEPTION_POINTERS exinfo)
|
||||
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);
|
||||
|
||||
fflush(stderr);
|
||||
|
||||
+27
-13
@@ -11,6 +11,7 @@
|
||||
#include "system.h"
|
||||
|
||||
#define LOG_FNAME "pd.log"
|
||||
#define CRASHLOG_FNAME "pd.crash.log"
|
||||
#define USEC_IN_SEC 1000000ULL
|
||||
|
||||
static u64 startTick = 0;
|
||||
@@ -19,6 +20,24 @@ static char logPath[2048];
|
||||
static s32 sysArgc;
|
||||
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)
|
||||
{
|
||||
sysArgc = argc;
|
||||
@@ -30,19 +49,7 @@ void sysInit(void)
|
||||
startTick = sysGetMicroseconds();
|
||||
|
||||
if (sysArgCheck("--log")) {
|
||||
// figure out where the log is and clear it
|
||||
// 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);
|
||||
}
|
||||
sysLogSetPath(LOG_FNAME);
|
||||
}
|
||||
|
||||
#ifdef VERSION_HASH
|
||||
@@ -96,6 +103,13 @@ u64 sysGetMicroseconds(void)
|
||||
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, ...)
|
||||
{
|
||||
static const char *prefix[3] = {
|
||||
|
||||
Reference in new issue
Block a user