Skip to content

Commit

Permalink
feat(debug): add additional crashdump cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Silverlan committed Dec 13, 2024
1 parent a0200c5 commit 5f12f07
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions core/shared/include/pragma/debug/mdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace pragma::debug {
bool GenerateCrashDump() const;
std::string m_appName;
#ifdef _WIN32
static bool GenerateCrashDump(EXCEPTION_POINTERS *pExceptionPointers);
struct _EXCEPTION_POINTERS *m_pExceptionInfo = nullptr;
std::optional<std::string> GenerateMiniDump(std::string &outErr) const;
static LONG WINAPI TopLevelFilter(struct _EXCEPTION_POINTERS *pExceptionInfo);
Expand Down
43 changes: 39 additions & 4 deletions core/shared/src/debug/mdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "pragma/localization.h"
#ifdef _WIN32
#include <tchar.h>
#include <signal.h>
#else
#include <signal.h>
#include <execinfo.h>
Expand All @@ -33,10 +34,42 @@ using namespace pragma::debug;
std::string g_crashExceptionMessage = {};
static CrashHandler g_crashHandler {};
CrashHandler &CrashHandler::Get() { return g_crashHandler; }

CrashHandler::CrashHandler()
{
#ifdef _WIN32
::SetUnhandledExceptionFilter(TopLevelFilter);
_set_invalid_parameter_handler([](const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned int line, uintptr_t pReserved) {
__try {
// Trigger an exception
int *p = nullptr;
*p = 42;
}
__except(CrashHandler::GenerateCrashDump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) {
}
exit(1);
});
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
_set_purecall_handler([]() {
__try {
// Trigger an exception
int *p = nullptr;
*p = 42;
}
__except(CrashHandler::GenerateCrashDump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) {
}
exit(1);
});
signal(SIGABRT, [](int signal) {
__try {
// Trigger an exception
int *p = nullptr;
*p = 42;
}
__except(CrashHandler::GenerateCrashDump(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER) {
}
exit(signal);
});
#else
signal(
SIGSEGV, +[](int sig) {
Expand Down Expand Up @@ -76,10 +109,6 @@ BOOL CALLBACK MyMiniDumpCallback(PVOID pParam, const PMINIDUMP_CALLBACK_INPUT pI

std::optional<std::string> CrashHandler::GenerateMiniDump(std::string &outErr) const
{
if(!m_pExceptionInfo) {
outErr = "No exception info!";
return {};
}
LONG retval = EXCEPTION_CONTINUE_SEARCH;
HWND hParent = NULL; // find a better value for your app

Expand Down Expand Up @@ -220,6 +249,12 @@ BOOL CALLBACK MyMiniDumpCallback(PVOID pParam, const PMINIDUMP_CALLBACK_INPUT pI

return bRet;
}

bool CrashHandler::GenerateCrashDump(EXCEPTION_POINTERS *pExceptionPointers)
{
g_crashHandler.m_pExceptionInfo = pExceptionPointers;
return g_crashHandler.GenerateCrashDump();
}
#endif

bool CrashHandler::GenerateCrashDump() const
Expand Down

0 comments on commit 5f12f07

Please sign in to comment.