From 4905cd425ff98b9449ed024a57892b9523c431e5 Mon Sep 17 00:00:00 2001 From: Eladash <18193363+elad335@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:59:27 +0300 Subject: [PATCH] Thread.cpp: Prevent repeatedly halting the debugger --- Utilities/Thread.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 62bd43ed19..6293785d60 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -2664,7 +2664,30 @@ void thread_base::exec() if (IsDebuggerPresent()) { - utils::trap(); + // Prevent repeatedly halting the debugger in case multiple threads crashed at once + static atomic_t s_last_break = 0; + const u64 current_break = get_system_time() & -2; + + if (s_last_break.fetch_op([current_break](u64& v) + { + if (current_break >= (v & -2) && current_break - (v & -2) >= 20'000'000) + { + v = current_break; + return true; + } + + // Let's allow a single more thread to halt the debugger so the programmer sees the pattern + if (!(v & 1)) + { + v |= 1; + return true; + } + + return false; + }).second) + { + utils::trap(); + } } if (const auto _this = g_tls_this_thread)