Make libbacktrace crash reports append to file instead of overwriting. Add more info into libbacktrace crash reports

This commit is contained in:
indev committed 2023-11-03 15:04:38 +03:00
1 parent 9ed348c8a8
commit dc16f8b4a6
1 file changed
+48 -21
+48 -21
View File
@@ -67,12 +67,6 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
#define _MATH_DEFINES_DEFINED
#include "SDL.h"
#ifdef HAVE_LIBBACKTRACE
#include <backtrace.h>
// TODO - move this to some header file instead
extern struct backtrace_state *bt_state;
#endif
#ifdef HAVE_TTF
#include "i_ttf.h"
#endif
@@ -145,10 +139,13 @@ extern struct backtrace_state *bt_state;
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
#include <execinfo.h>
#include <time.h>
#define UNIXBACKTRACE
#endif
#if defined(UNIXBACKTRACE) || defined(HAVE_LIBBACKTRACE)
#include <time.h>
#endif
// Locations for searching the srb2.srb
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2Kart"
@@ -203,6 +200,48 @@ static char returnWadPath[256];
#include "../byteptr.h"
#endif
#ifdef HAVE_LIBBACKTRACE
#include <backtrace.h>
// TODO - move this to some header file instead
extern struct backtrace_state *bt_state;
static void write_backtrace_libbacktrace(INT32 num)
{
FILE *out = fopen(va("%s" PATHSEP "%s", srb2home, "crash-log-libbacktrace.txt"), "a");
time_t rawtime;
struct tm timeinfo;
char timestr[64];
if (!out)
{
fprintf(stderr, "\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n");
out = stderr;
}
// Get the current time as a string.
time(&rawtime);
localtime_r(&rawtime, &timeinfo);
strftime(timestr, 64, "%a, %d %b %Y %T %z", &timeinfo);
fprintf(out, "------------------------\n\n");
fprintf(out, "Time of crash: %s\n", timestr);
fprintf(out, "Caused by: %s\n", strsignal(num));
fprintf(out, "\nBacktrace:\n");
backtrace_print(bt_state, 2, out);
if (out != stderr)
{
fclose(out);
fprintf(stderr, "Crash report created, find crash-log-libbacktrace.txt in your SRB2Kart directory\n");
}
}
#endif
/** \brief The JoyReset function
\param JoySet Joystick info to reset
@@ -403,13 +442,7 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
D_QuitNetGame(); // Fix server freezes
#ifdef HAVE_LIBBACKTRACE
FILE *out = fopen(va("%s" PATHSEP "%s", srb2home, "crash-log-libbacktrace.txt"), "w");
if (out)
{
backtrace_print(bt_state, 2, out);
fclose(out);
}
write_backtrace_libbacktrace(num);
#endif
#ifdef UNIXBACKTRACE
@@ -810,13 +843,7 @@ static void signal_handler_child(INT32 num)
{
#ifdef HAVE_LIBBACKTRACE
FILE *out = fopen(va("%s" PATHSEP "%s", srb2home, "crash-log-libbacktrace.txt"), "w");
if (out)
{
backtrace_print(bt_state, 2, out);
fclose(out);
}
write_backtrace_libbacktrace(num);
#endif
#ifdef UNIXBACKTRACE