From 3195f4f267467f1aa9339d2836125a260a364776 Mon Sep 17 00:00:00 2001 From: Mikhail Kurinnoi Date: Fri, 15 Sep 2023 15:53:55 +0300 Subject: [PATCH] Fix eval interop related logic. --- src/debugger/evalwaiter.cpp | 2 +- src/debugger/interop_debugging.cpp | 11 +++++++---- src/debugger/interop_debugging.h | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/debugger/evalwaiter.cpp b/src/debugger/evalwaiter.cpp index 8cc7ffa..d796f6a 100644 --- a/src/debugger/evalwaiter.cpp +++ b/src/debugger/evalwaiter.cpp @@ -147,7 +147,7 @@ HRESULT EvalWaiter::WaitEvalResult(ICorDebugThread *pThread, #ifdef INTEROP_DEBUGGING assert(!!m_sharedInteropDebugger); - if (m_sharedInteropDebugger->IsNativeThreadStopped((pid_t)evalThreadId)) + if (m_sharedInteropDebugger->IsManagedThreadWasStoppedInNativeCode((pid_t)evalThreadId)) return COR_E_THREADSTATE; #endif // INTEROP_DEBUGGING diff --git a/src/debugger/interop_debugging.cpp b/src/debugger/interop_debugging.cpp index 7141e54..a94de17 100644 --- a/src/debugger/interop_debugging.cpp +++ b/src/debugger/interop_debugging.cpp @@ -1668,18 +1668,21 @@ HRESULT InteropDebugger::GetFrameForAddr(std::uintptr_t addr, StackFrame &frame) return S_OK; } -bool InteropDebugger::IsNativeThreadStopped(pid_t pid) +bool InteropDebugger::IsManagedThreadWasStoppedInNativeCode(pid_t pid) { std::lock_guard lock(m_waitpidMutex); if (m_TIDs.empty()) - return S_OK; + return false; auto tid = m_TIDs.find(pid); if (tid == m_TIDs.end()) - return E_INVALIDARG; + { + LOGE("Requested native thread not found in process, TID: %i\n", pid); + // Note, in this case "not found" mean "not stopped" (same logic as we have for `m_TIDs.empty()`). + return false; + } - assert(tid->second.stat != thread_stat_e::stopped); return tid->second.stat != thread_stat_e::running; } diff --git a/src/debugger/interop_debugging.h b/src/debugger/interop_debugging.h index 80b28b2..d0aee41 100644 --- a/src/debugger/interop_debugging.h +++ b/src/debugger/interop_debugging.h @@ -191,7 +191,7 @@ class InteropDebugger final : InteropDebuggerHelpers HRESULT UnwindNativeFrames(pid_t pid, bool firstFrame, std::uintptr_t endAddr, CONTEXT *pStartContext, std::function nativeFramesCallback); - bool IsNativeThreadStopped(pid_t pid); + bool IsManagedThreadWasStoppedInNativeCode(pid_t pid); void WalkAllThreads(std::function cb); };