Skip to content

Commit

Permalink
port: don't use the existing log system in crashlog in case it crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfdsfgs committed Jan 7, 2024
1 parent ba52580 commit 8645d0a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion port/include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ u64 sysGetMicroseconds(void);

void sysFatalError(const char *fmt, ...) __attribute__((noreturn));

void sysLogStartCrash(void);
s32 sysLogIsOpen(void);
void sysLogPrintf(s32 level, const char *fmt, ...);

void sysGetExecutablePath(char *outPath, const u32 outLen);
Expand Down
13 changes: 10 additions & 3 deletions port/src/crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "system.h"
#include "platform.h"

#define CRASH_LOG_FNAME "pd.crash.log"
#define CRASH_MAX_MSG 8192
#define CRASH_MAX_SYM 256
#define CRASH_MAX_FRAMES 32
Expand Down Expand Up @@ -132,16 +133,22 @@ 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);
fflush(stdout);

crashStackTrace(msg, exinfo);

// open log file for the crash dump if one hasn't been opened yet
if (!sysLogIsOpen()) {
FILE *f = fopen(CRASH_LOG_FNAME, "wb");
if (f) {
fprintf(f, "Crash!\n\n%s", msg);
fclose(f);
}
}

sysFatalError("Crash!\n\n%s", msg);

return EXCEPTION_CONTINUE_EXECUTION;
Expand Down
6 changes: 2 additions & 4 deletions port/src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ u64 sysGetMicroseconds(void)
return ((u64)tv.tv_sec * USEC_IN_SEC + (u64)tv.tv_usec) - startTick;
}

void sysLogStartCrash(void)
s32 sysLogIsOpen(void)
{
if (!logPath[0]) {
sysLogSetPath(CRASHLOG_FNAME);
}
return (logPath[0] != '\0');
}

void sysLogPrintf(s32 level, const char *fmt, ...)
Expand Down

0 comments on commit 8645d0a

Please sign in to comment.