1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Segfault/exceptions reports: Get rid of unhandled exeption handler, log memory bases

* Getting rid of handled exception handler fixes 2 things:
- Visual Studio debugger won't force it's own handler on unhandled exception.
- SPU segfaults in recompiler can now be reported.

* Log vm memory bases.
This commit is contained in:
Eladash 2020-02-29 08:14:01 +02:00 committed by Ivan
parent 50f51be06a
commit 5871c4e93f

View File

@ -1506,6 +1506,11 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no
static LONG exception_handler(PEXCEPTION_POINTERS pExp) noexcept
{
if (pExp->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT && IsDebuggerPresent())
{
return EXCEPTION_CONTINUE_SEARCH;
}
const u64 addr64 = pExp->ExceptionRecord->ExceptionInformation[1] - reinterpret_cast<u64>(vm::g_base_addr);
const u64 exec64 = (pExp->ExceptionRecord->ExceptionInformation[1] - reinterpret_cast<u64>(vm::g_exec_addr)) / 2;
const bool is_writing = pExp->ExceptionRecord->ExceptionInformation[0] != 0;
@ -1525,11 +1530,7 @@ static LONG exception_handler(PEXCEPTION_POINTERS pExp) noexcept
return EXCEPTION_CONTINUE_EXECUTION;
}
}
return EXCEPTION_CONTINUE_SEARCH;
}
static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept
{
std::string msg = fmt::format("Unhandled Win32 exception 0x%08X.\n", pExp->ExceptionRecord->ExceptionCode);
if (pExp->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
@ -1562,6 +1563,9 @@ static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept
fmt::append(msg, "Thread id = %s.\n", std::this_thread::get_id());
sys_log.notice("Memory bases:\nvm::g_base_addr = %p\nvm::g_sudo_addr = %p\nvm::g_exec_addr = %p\nvm::g_stat_addr = %p\nvm::g_reservations = %p\n",
vm::g_base_addr, vm::g_sudo_addr, vm::g_exec_addr, vm::g_stat_addr, vm::g_reservations);
std::vector<HMODULE> modules;
for (DWORD size = 256; modules.size() != size; size /= sizeof(HMODULE))
{
@ -1617,9 +1621,13 @@ static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept
// TODO: print registers and the callstack
// Report fatal error
sys_log.fatal("\n%s", msg);
report_fatal_error(msg);
if (!IsDebuggerPresent())
{
report_fatal_error(msg);
}
return EXCEPTION_CONTINUE_SEARCH;
}
@ -1630,11 +1638,6 @@ const bool s_exception_handler_set = []() -> bool
report_fatal_error("AddVectoredExceptionHandler() failed.");
}
if (!SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)exception_filter))
{
report_fatal_error("SetUnhandledExceptionFilter() failed.");
}
return true;
}();
@ -1682,7 +1685,10 @@ static void signal_handler(int sig, siginfo_t* info, void* uct) noexcept
sys_log.notice("\n%s", cpu->dump());
}
std::string msg = fmt::format("Segfault %s location %p at %p.", cause, info->si_addr, RIP(context));
sys_log.notice("Memory bases:\nvm::g_base_addr = %p\nvm::g_sudo_addr = %p\nvm::g_exec_addr = %p\nvm::g_stat_addr = %p\nvm::g_reservations = %p\n",
vm::g_base_addr, vm::g_sudo_addr, vm::g_exec_addr, vm::g_stat_addr, vm::g_reservations);
std::string msg = fmt::format("Segfault %s location %p at %p.\n", cause, info->si_addr, RIP(context));
if (thread_ctrl::get_current())
{