From 5871c4e93f06b233abe9c54411e4e0fec8bff1d2 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 29 Feb 2020 08:14:01 +0200 Subject: [PATCH] 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. --- Utilities/Thread.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 3615ef19fc..9c79539f33 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -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(vm::g_base_addr); const u64 exec64 = (pExp->ExceptionRecord->ExceptionInformation[1] - reinterpret_cast(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 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()) {