From caea2f74403e616e281cf2f31117365f238d0214 Mon Sep 17 00:00:00 2001 From: fangting Date: Thu, 14 Aug 2025 21:07:31 +0800 Subject: [PATCH] fix stepinto bug Issue:#ICT16U Signed-off-by: fangting --- inspector/inspector.cpp | 23 +++++++++++-- tooling/dynamic/backend/js_pt_hooks.cpp | 21 ++++++------ .../dynamic/test/client_utils/test_list.cpp | 2 -- tooling/static/debugger/thread_state.cpp | 8 +++++ tooling/static/init.cpp | 2 +- tooling/static/inspector.cpp | 32 ++++++++++++------- 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/inspector/inspector.cpp b/inspector/inspector.cpp index 0ef5bba2..724551b0 100644 --- a/inspector/inspector.cpp +++ b/inspector/inspector.cpp @@ -36,6 +36,9 @@ #include "ffrt.h" #endif +#include +#include + namespace OHOS::ArkCompiler::Toolchain { namespace { enum DispatchStatus : int32_t { @@ -315,9 +318,17 @@ bool InitializeArkFunctions() void Inspector::OnMessage(std::string&& msg, bool isHybrid) { if (isHybrid) { - HandleMessage(std::move(msg)); + std::regex pattern("\"sessionId\":\\s*(\\d)"); + std::smatch matches; + if (std::regex_search(msg, matches, pattern)) { + HandleMessage(std::move(msg)); + } else { + HandleMessage(std::move(msg)); // IDE not adjusted + g_onMessage(vm_, std::move(msg)); + } + } else { + g_onMessage(vm_, std::move(msg)); } - g_onMessage(vm_, std::move(msg)); // message will be processed soon if the debugger thread is in running or waiting status if (g_getDispatchStatus(vm_) != DispatchStatus::UNKNOWN) { @@ -501,8 +512,14 @@ void StopDebug(void* vm, bool isHybrid) if (debuggerInfo != g_debuggerInfo.end()) { g_debuggerInfo.erase(debuggerInfo); } - ResetServiceLocked(vm, true); + ResetServiceLocked(vm, false); g_uninitializeDebugger(vm); +#if !defined(IOS_PLATFORM) + if (g_handle != nullptr) { + CloseHandle(g_handle); + g_handle = nullptr; + } +#endif if (isHybrid) { StopDebuggerForStatic(); } diff --git a/tooling/dynamic/backend/js_pt_hooks.cpp b/tooling/dynamic/backend/js_pt_hooks.cpp index c72be824..1ccb46ec 100644 --- a/tooling/dynamic/backend/js_pt_hooks.cpp +++ b/tooling/dynamic/backend/js_pt_hooks.cpp @@ -20,14 +20,14 @@ namespace panda::ecmascript::tooling { void JSPtHooks::DebuggerStmt([[maybe_unused]] const JSPtLocation &location) { - LOG_DEBUGGER(VERBOSE) << "JSPHooks: Debugger Statement"; + LOG_DEBUGGER(DEBUG) << "JSPHooks: Debugger Statement"; [[maybe_unused]] LocalScope scope(debugger_->vm_); debugger_->NotifyPaused({}, DEBUGGERSTMT); } void JSPtHooks::Breakpoint(const JSPtLocation &location) { - LOG_DEBUGGER(VERBOSE) << "JSPtHooks: Breakpoint => " << location.GetMethodId() << ": " + LOG_DEBUGGER(DEBUG) << "JSPtHooks: Breakpoint => " << location.GetMethodId() << ": " << location.GetBytecodeOffset(); [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -36,7 +36,7 @@ void JSPtHooks::Breakpoint(const JSPtLocation &location) void JSPtHooks::Exception([[maybe_unused]] const JSPtLocation &location) { - LOG_DEBUGGER(VERBOSE) << "JSPtHooks: Exception"; + LOG_DEBUGGER(DEBUG) << "JSPtHooks: Exception"; [[maybe_unused]] LocalScope scope(debugger_->vm_); debugger_->NotifyPaused({}, EXCEPTION); @@ -44,13 +44,16 @@ void JSPtHooks::Exception([[maybe_unused]] const JSPtLocation &location) bool JSPtHooks::SingleStep(const JSPtLocation &location) { - LOG_DEBUGGER(VERBOSE) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); + LOG_DEBUGGER(DEBUG) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); [[maybe_unused]] LocalScope scope(debugger_->vm_); + DebugStepFlags::Get().SetDyn2StatInto(true); if (DebugStepFlags::Get().GetStat2DynInto()) { - debugger_->NotifyPaused({}, BREAK_ON_START); + LOG_DEBUGGER(DEBUG) << "SingleStep from Static"; + debugger_->NotifyPaused({}, OTHER); DebugStepFlags::Get().SetStat2DynInto(false); + return false; } if (UNLIKELY(firstTime_)) { firstTime_ = false; @@ -90,7 +93,7 @@ bool JSPtHooks::NativeOut() void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entryPoint) { - LOG_DEBUGGER(VERBOSE) << "JSPtHooks: LoadModule: " << pandaFileName; + LOG_DEBUGGER(DEBUG) << "JSPtHooks: LoadModule: " << pandaFileName; [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -103,7 +106,7 @@ void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entr void JSPtHooks::NativeCalling(const void *nativeAddress) { - LOG_DEBUGGER(VERBOSE) << "JSPtHooks: NativeCalling, addr = " << nativeAddress; + LOG_DEBUGGER(DEBUG) << "JSPtHooks: NativeCalling, addr = " << nativeAddress; [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -119,7 +122,7 @@ void JSPtHooks::NativeReturn(const void *nativeAddress) void JSPtHooks::SendableMethodEntry(JSHandle method) { - LOG_DEBUGGER(VERBOSE) << "JSPtHooks: MethodEntry"; + LOG_DEBUGGER(DEBUG) << "JSPtHooks: MethodEntry"; [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -144,7 +147,7 @@ void JSPtHooks::GenerateAsyncFrames(std::shared_ptr asyncStack, bool void JSPtHooks::HitSymbolicBreakpoint() { - LOG_DEBUGGER(VERBOSE) << "JSPtHooks: HitSymbolicBreakpoint"; + LOG_DEBUGGER(DEBUG) << "JSPtHooks: HitSymbolicBreakpoint"; breakOnSymbol_ = true; diff --git a/tooling/dynamic/test/client_utils/test_list.cpp b/tooling/dynamic/test/client_utils/test_list.cpp index d7d0df59..31b7562c 100644 --- a/tooling/dynamic/test/client_utils/test_list.cpp +++ b/tooling/dynamic/test/client_utils/test_list.cpp @@ -22,7 +22,6 @@ #include "tooling/dynamic/test/testcases/js_allocationtrack_loop_test.h" #include "tooling/dynamic/test/testcases/js_allocationtrack_recursion_test.h" #include "tooling/dynamic/test/testcases/js_allocationtrack_test.h" -#include "tooling/dynamic/test/testcases/js_asyn_stack_test.h" #include "tooling/dynamic/test/testcases/js_breakpoint_arrow_test.h" #include "tooling/dynamic/test/testcases/js_breakpoint_async_test.h" #include "tooling/dynamic/test/testcases/js_breakpoint_cannot_hit_test.h" @@ -143,7 +142,6 @@ static void RegisterTests() TestUtil::RegisterTest("JsHeapusageRecursionTest", GetJsHeapusageRecursionTest()); TestUtil::RegisterTest("JsSmartStepoutTest", GetJsSmartStepoutTest()); TestUtil::RegisterTest("JsAccelerateLaunchTest", GetJsAccelerateLaunchTest()); - TestUtil::RegisterTest("JsAsynStackTest", GetJsAsynStackTest()); TestUtil::RegisterTest("JsSymbolicBreakpointTest", GetJsSymbolicBreakpointTest()); } diff --git a/tooling/static/debugger/thread_state.cpp b/tooling/static/debugger/thread_state.cpp index 94554d9c..5ddee141 100644 --- a/tooling/static/debugger/thread_state.cpp +++ b/tooling/static/debugger/thread_state.cpp @@ -25,6 +25,7 @@ #include "error.h" #include "types/numeric_id.h" +#include "../../hybrid_step/debug_step_flags.h" namespace ark::tooling::inspector { void ThreadState::Reset() @@ -177,6 +178,13 @@ bool ThreadState::OnMethodEntry() void ThreadState::OnSingleStep(const PtLocation &location, const char *sourceFile) { ASSERT(!paused_); + DebugStepFlags::Get().SetStat2DynInto(true); + if (DebugStepFlags::Get().GetDyn2StatInto()) { + LOG(DEBUG, DEBUGGER) << "SingleStep from Dynamic"; + paused_ = true; + DebugStepFlags::Get().SetDyn2StatInto(false); + return; + } if (breakOnStart_) { std::string_view file = sourceFile; diff --git a/tooling/static/init.cpp b/tooling/static/init.cpp index 9c336696..ccaf3099 100644 --- a/tooling/static/init.cpp +++ b/tooling/static/init.cpp @@ -112,6 +112,6 @@ void WaitForDebugger() void HandleMessage(std::string &&msg) { - LOG(ERROR, DEBUGGER) << "FTDEG HandleMessage start"; + LOG(ERROR, DEBUGGER) << "Static OnMessage start"; g_inspector->Run(msg); } \ No newline at end of file diff --git a/tooling/static/inspector.cpp b/tooling/static/inspector.cpp index 641f5fd8..38fa534a 100644 --- a/tooling/static/inspector.cpp +++ b/tooling/static/inspector.cpp @@ -102,8 +102,14 @@ void Inspector::ConsoleCall(PtThread thread, ConsoleCallType type, uint64_t time os::memory::ReadLockHolder lock(debuggerEventsLock_); auto *debuggableThread = GetDebuggableThread(thread); - ASSERT(debuggableThread != nullptr); - inspectorServer_.CallRuntimeConsoleApiCalled(thread, type, timestamp, debuggableThread->OnConsoleCall(arguments)); + if (debuggableThread != nullptr) { + inspectorServer_.CallRuntimeConsoleApiCalled( + thread, + type, + timestamp, + debuggableThread->OnConsoleCall(arguments) + ); + } } // CC-OFFNXT(G.FUN.01-CPP) Decreasing the number of arguments will decrease the clarity of the code. @@ -113,8 +119,9 @@ void Inspector::Exception(PtThread thread, Method * /* method */, const PtLocati os::memory::ReadLockHolder lock(debuggerEventsLock_); auto *debuggableThread = GetDebuggableThread(thread); - ASSERT(debuggableThread != nullptr); - debuggableThread->OnException(catchLocation.GetBytecodeOffset() == panda_file::INVALID_OFFSET); + if (debuggableThread != nullptr) { + debuggableThread->OnException(catchLocation.GetBytecodeOffset() == panda_file::INVALID_OFFSET); + } } void Inspector::FramePop(PtThread thread, Method * /* method */, bool /* was_popped_by_exception */) @@ -122,8 +129,9 @@ void Inspector::FramePop(PtThread thread, Method * /* method */, bool /* was_pop os::memory::ReadLockHolder lock(debuggerEventsLock_); auto *debuggableThread = GetDebuggableThread(thread); - ASSERT(debuggableThread != nullptr); - debuggableThread->OnFramePop(); + if (debuggableThread != nullptr) { + debuggableThread->OnFramePop(); + } } void Inspector::MethodEntry(PtThread thread, Method * /* method */) @@ -131,7 +139,6 @@ void Inspector::MethodEntry(PtThread thread, Method * /* method */) os::memory::ReadLockHolder lock(debuggerEventsLock_); auto *debuggableThread = GetDebuggableThread(thread); - ASSERT(debuggableThread != nullptr); auto stack = StackWalker::Create(thread.GetManagedThread()); if (stack.IsCFrame()) { return; @@ -139,8 +146,10 @@ void Inspector::MethodEntry(PtThread thread, Method * /* method */) if (debuggableThread == nullptr) { return; } - if (debuggableThread->OnMethodEntry()) { - HandleError(debugger_.NotifyFramePop(thread, 0)); + if (debuggableThread != nullptr) { + if (debuggableThread->OnMethodEntry()) { + HandleError(debugger_.NotifyFramePop(thread, 0)); + } } } @@ -189,8 +198,9 @@ void Inspector::SingleStep(PtThread thread, Method *method, const PtLocation &lo } auto *debuggableThread = GetDebuggableThread(thread); - ASSERT(debuggableThread != nullptr); - debuggableThread->OnSingleStep(location, sourceFile); + if (debuggableThread != nullptr) { + debuggableThread->OnSingleStep(location, sourceFile); + } } void Inspector::ThreadStart(PtThread thread) -- Gitee