mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-05-26 13:50:37 +00:00
Flush log on terminate (#4429)
* Flush log on terminate * Flush on unhandeld signal * hexa code Co-authored-by: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> --------- Co-authored-by: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com>
This commit is contained in:
Vendored
+1
-1
Submodule externals/sdl3 updated: d5af35e3fb...7f12b975bb
@@ -4,6 +4,7 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fmt/std.h>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/config.h"
|
||||
@@ -15,6 +16,14 @@
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
// return codes above 'standard'
|
||||
// https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes
|
||||
enum class ShadPs4ReturnCode : u32 {
|
||||
TERMINATE_WITHOUT_EXCEPTION = 20'000,
|
||||
TERMINATE_WITH_EXCEPTION = 20'001,
|
||||
TERMINATE_WITH_UNKNOWN_EXCEPTION = 20'002,
|
||||
};
|
||||
|
||||
namespace Common::Log {
|
||||
bool g_should_append = false;
|
||||
|
||||
@@ -169,6 +178,7 @@ void Setup(std::string_view log_filename) {
|
||||
already_registered = true;
|
||||
std::atexit(Shutdown);
|
||||
std::at_quick_exit(Flush);
|
||||
std::set_terminate(Terminate);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -258,4 +268,24 @@ void Flush() {
|
||||
g_console_sink->flush();
|
||||
}
|
||||
}
|
||||
|
||||
void Terminate() {
|
||||
try {
|
||||
if (std::exception_ptr eptr{std::current_exception()}) {
|
||||
std::rethrow_exception(eptr);
|
||||
}
|
||||
|
||||
LOG_CRITICAL(Debug, "Exiting without exception");
|
||||
|
||||
std::quick_exit(std::to_underlying(ShadPs4ReturnCode::TERMINATE_WITHOUT_EXCEPTION));
|
||||
} catch (const std::exception& exception) {
|
||||
LOG_CRITICAL(Debug, "Exception: {}", exception);
|
||||
|
||||
std::quick_exit(std::to_underlying(ShadPs4ReturnCode::TERMINATE_WITH_EXCEPTION));
|
||||
} catch (...) {
|
||||
LOG_CRITICAL(Debug, "Unknown exception caught");
|
||||
|
||||
std::quick_exit(std::to_underlying(ShadPs4ReturnCode::TERMINATE_WITH_UNKNOWN_EXCEPTION));
|
||||
}
|
||||
}
|
||||
} // namespace Common::Log
|
||||
|
||||
@@ -35,6 +35,8 @@ void Shutdown();
|
||||
|
||||
void Flush();
|
||||
|
||||
void Terminate();
|
||||
|
||||
static constexpr std::array level_string_views{"Trace", "Debug", "Info", "Warning",
|
||||
"Error", "Critical", "Off"};
|
||||
|
||||
|
||||
@@ -210,6 +210,10 @@ static void* RunThread(void* arg) {
|
||||
|
||||
curthread->native_thr.Initialize();
|
||||
|
||||
#ifdef WIN32
|
||||
std::set_terminate(Common::Log::Terminate);
|
||||
#endif
|
||||
|
||||
/* Run the current thread's start routine with argument: */
|
||||
auto* const stack =
|
||||
(void*)(((size_t)curthread->attr.stackaddr_attr + curthread->attr.stacksize_attr) & (~15));
|
||||
|
||||
@@ -111,6 +111,8 @@ void Linker::Execute(const std::vector<std::string>& args) {
|
||||
|
||||
main_thread.Run([this, module, &args](std::stop_token) {
|
||||
Common::SetCurrentThreadName("Game:Main");
|
||||
std::set_terminate(Common::Log::Terminate);
|
||||
|
||||
#ifndef _WIN32 // Clear any existing signal mask for game threads.
|
||||
sigset_t emptyset;
|
||||
sigemptyset(&emptyset);
|
||||
|
||||
+16
-2
@@ -31,9 +31,16 @@ namespace Core {
|
||||
|
||||
static LONG WINAPI SignalHandler(EXCEPTION_POINTERS* pExp) noexcept {
|
||||
const auto* signals = Signals::Instance();
|
||||
DWORD code = 0;
|
||||
PVOID address = nullptr;
|
||||
|
||||
if (pExp != nullptr && pExp->ExceptionRecord != nullptr) {
|
||||
code = pExp->ExceptionRecord->ExceptionCode;
|
||||
address = pExp->ExceptionRecord->ExceptionAddress;
|
||||
}
|
||||
|
||||
bool handled = false;
|
||||
switch (pExp->ExceptionRecord->ExceptionCode) {
|
||||
switch (code) {
|
||||
case EXCEPTION_ACCESS_VIOLATION:
|
||||
handled = signals->DispatchAccessViolation(
|
||||
pExp, reinterpret_cast<void*>(pExp->ExceptionRecord->ExceptionInformation[1]));
|
||||
@@ -49,7 +56,14 @@ static LONG WINAPI SignalHandler(EXCEPTION_POINTERS* pExp) noexcept {
|
||||
break;
|
||||
}
|
||||
|
||||
return handled ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH;
|
||||
if (handled) {
|
||||
return EXCEPTION_CONTINUE_EXECUTION;
|
||||
}
|
||||
|
||||
LOG_CRITICAL(Debug, "Unhandled Exception code {:#x} at {}", code, address);
|
||||
Common::Log::Flush();
|
||||
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user