Common: Add assertion failure message to crashlogs

This commit is contained in:
TellowKrinkle 2022-05-30 00:49:07 -05:00 committed by tellowkrinkle
parent e63c068720
commit 04681babf1
3 changed files with 31 additions and 1 deletions

View File

@ -138,7 +138,7 @@ void pxOnAssertFail(const char* file, int line, const char* func, const char* ms
fputs(full_msg, stderr);
fputs("\nAborting application.\n", stderr);
fflush(stderr);
abort();
AbortWithMessage(full_msg);
#endif
ResumeThreads(handle);

View File

@ -160,6 +160,8 @@ extern u64 GetPhysicalMemory();
extern u32 ShortSpin();
/// Number of ns to spin for before sleeping a thread
extern const u32 SPIN_TIME_NS;
/// Like C abort() but adds the given message to the crashlog
[[noreturn]] void AbortWithMessage(const char* msg);
extern std::string GetOSVersionString();

View File

@ -71,3 +71,31 @@ static u32 GetSpinTime()
}
const u32 SPIN_TIME_NS = GetSpinTime();
#ifdef __APPLE__
// https://alastairs-place.net/blog/2013/01/10/interesting-os-x-crash-report-tidbits/
// https://opensource.apple.com/source/WebKit2/WebKit2-7608.3.10.0.3/Platform/spi/Cocoa/CrashReporterClientSPI.h.auto.html
struct crash_info_t
{
u64 version;
u64 message;
u64 signature;
u64 backtrace;
u64 message2;
u64 reserved;
u64 reserved2;
};
#define CRASH_ANNOTATION __attribute__((section("__DATA,__crash_info")))
#define CRASH_VERSION 4
extern "C" crash_info_t gCRAnnotations CRASH_ANNOTATION = { CRASH_VERSION };
#endif
void AbortWithMessage(const char* msg)
{
#ifdef __APPLE__
gCRAnnotations.message = reinterpret_cast<size_t>(msg);
// Some macOS's seem to have issues displaying non-static `message`s, so throw it in here too
gCRAnnotations.backtrace = gCRAnnotations.message;
#endif
abort();
}