From 8b8f11032667e25e2a2329c761ec4eb25dc1aaed Mon Sep 17 00:00:00 2001 From: oh_ci Date: Tue, 19 Aug 2025 11:03:44 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!1207=20?= =?UTF-8?q?:=20fix=20stepinto=20bug'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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, 26 insertions(+), 62 deletions(-) diff --git a/inspector/inspector.cpp b/inspector/inspector.cpp index 724551b0..0ef5bba2 100644 --- a/inspector/inspector.cpp +++ b/inspector/inspector.cpp @@ -36,9 +36,6 @@ #include "ffrt.h" #endif -#include -#include - namespace OHOS::ArkCompiler::Toolchain { namespace { enum DispatchStatus : int32_t { @@ -318,17 +315,9 @@ bool InitializeArkFunctions() void Inspector::OnMessage(std::string&& msg, bool isHybrid) { if (isHybrid) { - 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)); + HandleMessage(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) { @@ -512,14 +501,8 @@ void StopDebug(void* vm, bool isHybrid) if (debuggerInfo != g_debuggerInfo.end()) { g_debuggerInfo.erase(debuggerInfo); } - ResetServiceLocked(vm, false); + ResetServiceLocked(vm, true); 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 1ccb46ec..c72be824 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(DEBUG) << "JSPHooks: Debugger Statement"; + LOG_DEBUGGER(VERBOSE) << "JSPHooks: Debugger Statement"; [[maybe_unused]] LocalScope scope(debugger_->vm_); debugger_->NotifyPaused({}, DEBUGGERSTMT); } void JSPtHooks::Breakpoint(const JSPtLocation &location) { - LOG_DEBUGGER(DEBUG) << "JSPtHooks: Breakpoint => " << location.GetMethodId() << ": " + LOG_DEBUGGER(VERBOSE) << "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(DEBUG) << "JSPtHooks: Exception"; + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: Exception"; [[maybe_unused]] LocalScope scope(debugger_->vm_); debugger_->NotifyPaused({}, EXCEPTION); @@ -44,16 +44,13 @@ void JSPtHooks::Exception([[maybe_unused]] const JSPtLocation &location) bool JSPtHooks::SingleStep(const JSPtLocation &location) { - LOG_DEBUGGER(DEBUG) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); [[maybe_unused]] LocalScope scope(debugger_->vm_); - DebugStepFlags::Get().SetDyn2StatInto(true); if (DebugStepFlags::Get().GetStat2DynInto()) { - LOG_DEBUGGER(DEBUG) << "SingleStep from Static"; - debugger_->NotifyPaused({}, OTHER); + debugger_->NotifyPaused({}, BREAK_ON_START); DebugStepFlags::Get().SetStat2DynInto(false); - return false; } if (UNLIKELY(firstTime_)) { firstTime_ = false; @@ -93,7 +90,7 @@ bool JSPtHooks::NativeOut() void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entryPoint) { - LOG_DEBUGGER(DEBUG) << "JSPtHooks: LoadModule: " << pandaFileName; + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: LoadModule: " << pandaFileName; [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -106,7 +103,7 @@ void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entr void JSPtHooks::NativeCalling(const void *nativeAddress) { - LOG_DEBUGGER(DEBUG) << "JSPtHooks: NativeCalling, addr = " << nativeAddress; + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: NativeCalling, addr = " << nativeAddress; [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -122,7 +119,7 @@ void JSPtHooks::NativeReturn(const void *nativeAddress) void JSPtHooks::SendableMethodEntry(JSHandle method) { - LOG_DEBUGGER(DEBUG) << "JSPtHooks: MethodEntry"; + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: MethodEntry"; [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -147,7 +144,7 @@ void JSPtHooks::GenerateAsyncFrames(std::shared_ptr asyncStack, bool void JSPtHooks::HitSymbolicBreakpoint() { - LOG_DEBUGGER(DEBUG) << "JSPtHooks: HitSymbolicBreakpoint"; + LOG_DEBUGGER(VERBOSE) << "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 31b7562c..d7d0df59 100644 --- a/tooling/dynamic/test/client_utils/test_list.cpp +++ b/tooling/dynamic/test/client_utils/test_list.cpp @@ -22,6 +22,7 @@ #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" @@ -142,6 +143,7 @@ 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 5ddee141..94554d9c 100644 --- a/tooling/static/debugger/thread_state.cpp +++ b/tooling/static/debugger/thread_state.cpp @@ -25,7 +25,6 @@ #include "error.h" #include "types/numeric_id.h" -#include "../../hybrid_step/debug_step_flags.h" namespace ark::tooling::inspector { void ThreadState::Reset() @@ -178,13 +177,6 @@ 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 ccaf3099..9c336696 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) << "Static OnMessage start"; + LOG(ERROR, DEBUGGER) << "FTDEG HandleMessage start"; g_inspector->Run(msg); } \ No newline at end of file diff --git a/tooling/static/inspector.cpp b/tooling/static/inspector.cpp index 38fa534a..641f5fd8 100644 --- a/tooling/static/inspector.cpp +++ b/tooling/static/inspector.cpp @@ -102,14 +102,8 @@ void Inspector::ConsoleCall(PtThread thread, ConsoleCallType type, uint64_t time os::memory::ReadLockHolder lock(debuggerEventsLock_); auto *debuggableThread = GetDebuggableThread(thread); - if (debuggableThread != nullptr) { - inspectorServer_.CallRuntimeConsoleApiCalled( - thread, - type, - timestamp, - debuggableThread->OnConsoleCall(arguments) - ); - } + ASSERT(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. @@ -119,9 +113,8 @@ void Inspector::Exception(PtThread thread, Method * /* method */, const PtLocati os::memory::ReadLockHolder lock(debuggerEventsLock_); auto *debuggableThread = GetDebuggableThread(thread); - if (debuggableThread != nullptr) { - debuggableThread->OnException(catchLocation.GetBytecodeOffset() == panda_file::INVALID_OFFSET); - } + ASSERT(debuggableThread != nullptr); + debuggableThread->OnException(catchLocation.GetBytecodeOffset() == panda_file::INVALID_OFFSET); } void Inspector::FramePop(PtThread thread, Method * /* method */, bool /* was_popped_by_exception */) @@ -129,9 +122,8 @@ void Inspector::FramePop(PtThread thread, Method * /* method */, bool /* was_pop os::memory::ReadLockHolder lock(debuggerEventsLock_); auto *debuggableThread = GetDebuggableThread(thread); - if (debuggableThread != nullptr) { - debuggableThread->OnFramePop(); - } + ASSERT(debuggableThread != nullptr); + debuggableThread->OnFramePop(); } void Inspector::MethodEntry(PtThread thread, Method * /* method */) @@ -139,6 +131,7 @@ 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; @@ -146,10 +139,8 @@ void Inspector::MethodEntry(PtThread thread, Method * /* method */) if (debuggableThread == nullptr) { return; } - if (debuggableThread != nullptr) { - if (debuggableThread->OnMethodEntry()) { - HandleError(debugger_.NotifyFramePop(thread, 0)); - } + if (debuggableThread->OnMethodEntry()) { + HandleError(debugger_.NotifyFramePop(thread, 0)); } } @@ -198,9 +189,8 @@ void Inspector::SingleStep(PtThread thread, Method *method, const PtLocation &lo } auto *debuggableThread = GetDebuggableThread(thread); - if (debuggableThread != nullptr) { - debuggableThread->OnSingleStep(location, sourceFile); - } + ASSERT(debuggableThread != nullptr); + debuggableThread->OnSingleStep(location, sourceFile); } void Inspector::ThreadStart(PtThread thread) -- Gitee