diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp index b4fa204bc..e7a786396 100644 --- a/src/common/logging/text_formatter.cpp +++ b/src/common/logging/text_formatter.cpp @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2014 Citra Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -13,6 +14,7 @@ #include "common/logging/log.h" #include "common/logging/log_entry.h" #include "common/logging/text_formatter.h" +#include "common/thread.h" namespace Common::Log { @@ -23,8 +25,9 @@ std::string FormatLogMessage(const Entry& entry) { const char* class_name = GetLogClassName(entry.log_class); const char* level_name = GetLevelName(entry.log_level); - return fmt::format("[{}] <{}> {}:{} {}: {}", class_name, level_name, entry.filename, - entry.line_num, entry.function, entry.message); + return fmt::format("[{}] <{}> ({}) {}:{} {}: {}", class_name, level_name, + Common::GetCurrentThreadName(), entry.filename, entry.line_num, + entry.function, entry.message); } void PrintMessage(const Entry& entry) { diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 982041ebb..54194186c 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp @@ -1,11 +1,14 @@ // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project // SPDX-FileCopyrightText: 2014 Citra Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include #include #include +#include "core/libraries/kernel/threads/pthread.h" + #include "common/error.h" #include "common/logging/log.h" #include "common/thread.h" @@ -237,4 +240,22 @@ void AccurateTimer::End() { target_interval - std::chrono::duration_cast(now - start_time); } +std::string GetCurrentThreadName() { + using namespace Libraries::Kernel; + if (g_curthread && !g_curthread->name.empty()) { + return g_curthread->name; + } +#ifdef _WIN32 + PWSTR name; + GetThreadDescription(GetCurrentThread(), &name); + return Common::UTF16ToUTF8(name); +#else + char name[256]; + if (pthread_getname_np(pthread_self(), name, sizeof(name)) != 0) { + return ""; + } + return std::string{name}; +#endif +} + } // namespace Common diff --git a/src/common/thread.h b/src/common/thread.h index 5bd83d35c..a300d10c3 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project // SPDX-FileCopyrightText: 2014 Citra Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once @@ -46,4 +47,6 @@ public: } }; +std::string GetCurrentThreadName(); + } // namespace Common diff --git a/src/core/signals.cpp b/src/core/signals.cpp index 4099ac237..db6e4b6cc 100644 --- a/src/core/signals.cpp +++ b/src/core/signals.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-FileCopyrightText: Copyright 2024-2026 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "common/arch.h" @@ -42,14 +42,6 @@ static LONG WINAPI SignalHandler(EXCEPTION_POINTERS* pExp) noexcept { #else -static std::string GetThreadName() { - char name[256]; - if (pthread_getname_np(pthread_self(), name, sizeof(name)) != 0) { - return ""; - } - return std::string{name}; -} - static std::string DisassembleInstruction(void* code_address) { char buffer[256] = ""; @@ -80,18 +72,16 @@ static void SignalHandler(int sig, siginfo_t* info, void* raw_context) { case SIGBUS: { const bool is_write = Common::IsWriteError(raw_context); if (!signals->DispatchAccessViolation(raw_context, info->si_addr)) { - UNREACHABLE_MSG( - "Unhandled access violation in thread '{}' at code address {}: {} address {}", - GetThreadName(), fmt::ptr(code_address), is_write ? "Write to" : "Read from", - fmt::ptr(info->si_addr)); + UNREACHABLE_MSG("Unhandled access violation at code address {}: {} address {}", + fmt::ptr(code_address), is_write ? "Write to" : "Read from", + fmt::ptr(info->si_addr)); } break; } case SIGILL: if (!signals->DispatchIllegalInstruction(raw_context)) { - UNREACHABLE_MSG("Unhandled illegal instruction in thread '{}' at code address {}: {}", - GetThreadName(), fmt::ptr(code_address), - DisassembleInstruction(code_address)); + UNREACHABLE_MSG("Unhandled illegal instruction at code address {}: {}", + fmt::ptr(code_address), DisassembleInstruction(code_address)); } break; case SIGUSR1: { // Sleep thread until signal is received