From 39c6c158f50ac7b4e5815fb9379c8a04d6c6fa98 Mon Sep 17 00:00:00 2001 From: lukai Date: Tue, 18 Jun 2024 12:03:22 +0800 Subject: [PATCH] ThreadState switch for debugger Add threadState switch for debugger Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IA699D?from=project-issue Signed-off-by: lukai Change-Id: I14188917a1de97c248b6ba19d5395aa1ae1d1f5a --- tooling/protocol_handler.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tooling/protocol_handler.cpp b/tooling/protocol_handler.cpp index 7c23c2f..4a370c8 100644 --- a/tooling/protocol_handler.cpp +++ b/tooling/protocol_handler.cpp @@ -54,7 +54,7 @@ void ProtocolHandler::ProcessCommand() { std::queue dispatchingQueue; do { - DebuggerApi::SwitchThreadStateRunningOrNative(vm_, ThreadState::NATIVE); + DebuggerApi::DebuggerNativeScope nativeScope(vm_); { std::unique_lock queueLock(requestLock_); if (requestQueue_.empty()) { @@ -67,15 +67,17 @@ void ProtocolHandler::ProcessCommand() } isDispatchingMessage_ = true; - DebuggerApi::SwitchThreadStateRunningOrNative(vm_, ThreadState::RUNNING); - while (!dispatchingQueue.empty()) { - std::string msg = std::move(dispatchingQueue.front()); - dispatchingQueue.pop(); + { + DebuggerApi::DebuggerManagedScope managedScope(vm_); + while (!dispatchingQueue.empty()) { + std::string msg = std::move(dispatchingQueue.front()); + dispatchingQueue.pop(); - [[maybe_unused]] LocalScope scope(vm_); - auto exception = DebuggerApi::GetAndClearException(vm_); - dispatcher_.Dispatch(DispatchRequest(msg)); - DebuggerApi::SetException(vm_, exception); + [[maybe_unused]] LocalScope scope(vm_); + auto exception = DebuggerApi::GetAndClearException(vm_); + dispatcher_.Dispatch(DispatchRequest(msg)); + DebuggerApi::SetException(vm_, exception); + } } isDispatchingMessage_ = false; } while (true);