From 777ec66e5734f43f37cdbf6e23cc449ed455020f Mon Sep 17 00:00:00 2001 From: kanghonglin Date: Mon, 7 Jul 2025 17:14:11 +0800 Subject: [PATCH] Description: fix 1.2 debugger problem Issue:https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICKIRZ Signed-off-by: kanghonglin --- tooling/static/debugger/debug_info_cache.cpp | 5 +++-- tooling/static/debugger/debug_info_cache.h | 2 +- tooling/static/debugger/thread_state.cpp | 17 +++++++++-------- tooling/static/debugger/thread_state.h | 2 +- tooling/static/inspector.cpp | 9 +++------ 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/tooling/static/debugger/debug_info_cache.cpp b/tooling/static/debugger/debug_info_cache.cpp index af65685f..9e5ea857 100644 --- a/tooling/static/debugger/debug_info_cache.cpp +++ b/tooling/static/debugger/debug_info_cache.cpp @@ -22,10 +22,10 @@ #include "os/mutex.h" namespace ark::tooling::inspector { -void DebugInfoCache::AddPandaFile(const panda_file::File &file) +void DebugInfoCache::AddPandaFile(const panda_file::File &file, bool isUserPandafile) { os::memory::LockHolder lock(debugInfosMutex_); - const auto &debugInfo = + auto &debugInfo = debugInfos_ .emplace(std::piecewise_construct, std::forward_as_tuple(&file), std::forward_as_tuple(file, @@ -36,6 +36,7 @@ void DebugInfoCache::AddPandaFile(const panda_file::File &file) std::forward_as_tuple(file, methodId)); })) .first->second; + debugInfo.SetUserFile(isUserPandafile); // For all methods add non-empty source code read from debug-info for (auto methodId : debugInfo.GetMethodIdList()) { diff --git a/tooling/static/debugger/debug_info_cache.h b/tooling/static/debugger/debug_info_cache.h index 27b8dce3..208dd3f3 100644 --- a/tooling/static/debugger/debug_info_cache.h +++ b/tooling/static/debugger/debug_info_cache.h @@ -35,7 +35,7 @@ public: NO_COPY_SEMANTIC(DebugInfoCache); NO_MOVE_SEMANTIC(DebugInfoCache); - void AddPandaFile(const panda_file::File &file); + void AddPandaFile(const panda_file::File &file, bool isUserPandafile = false); void GetSourceLocation(const PtFrame &frame, std::string_view &sourceFile, std::string_view &methodName, size_t &lineNumber); std::unordered_set GetCurrentLineLocations(const PtFrame &frame); diff --git a/tooling/static/debugger/thread_state.cpp b/tooling/static/debugger/thread_state.cpp index 94554d9c..5ec453be 100644 --- a/tooling/static/debugger/thread_state.cpp +++ b/tooling/static/debugger/thread_state.cpp @@ -31,7 +31,7 @@ void ThreadState::Reset() { stepKind_ = StepKind::BREAK_ON_START; stepLocations_.clear(); - methodEntered_ = false; + methodEnterDepth_ = 0; skipAllPauses_ = false; mixedDebugEnabled_ = false; pauseOnExceptionsState_ = PauseOnExceptionsState::NONE; @@ -63,7 +63,7 @@ void ThreadState::ContinueTo(std::unordered_set locati void ThreadState::StepInto(std::unordered_set locations) { stepKind_ = StepKind::STEP_INTO; - methodEntered_ = false; + methodEnterDepth_ = 0; stepLocations_ = std::move(locations); paused_ = false; pauseReason_ = PauseReason::STEP; @@ -72,7 +72,7 @@ void ThreadState::StepInto(std::unordered_set location void ThreadState::StepOver(std::unordered_set locations) { stepKind_ = StepKind::STEP_OVER; - methodEntered_ = false; + methodEnterDepth_ = 0; stepLocations_ = std::move(locations); paused_ = false; pauseReason_ = PauseReason::STEP; @@ -81,7 +81,7 @@ void ThreadState::StepOver(std::unordered_set location void ThreadState::StepOut() { stepKind_ = StepKind::STEP_OUT; - methodEntered_ = true; + methodEnterDepth_ = 1; paused_ = false; pauseReason_ = PauseReason::STEP; } @@ -147,7 +147,7 @@ void ThreadState::OnFramePop() case StepKind::STEP_OUT: case StepKind::STEP_OVER: { - methodEntered_ = false; + methodEnterDepth_--; break; } } @@ -167,7 +167,8 @@ bool ThreadState::OnMethodEntry() case StepKind::STEP_OUT: case StepKind::STEP_OVER: { - return !std::exchange(methodEntered_, true); + methodEnterDepth_++; + return true; } } @@ -221,12 +222,12 @@ void ThreadState::OnSingleStep(const PtLocation &location, const char *sourceFil } case StepKind::STEP_OUT: { - paused_ = !methodEntered_; + paused_ = (methodEnterDepth_ <= 0); break; } case StepKind::STEP_OVER: { - paused_ = !methodEntered_ && stepLocations_.find(location) == stepLocations_.end(); + paused_ = (methodEnterDepth_ <= 0) && stepLocations_.find(location) == stepLocations_.end(); break; } } diff --git a/tooling/static/debugger/thread_state.h b/tooling/static/debugger/thread_state.h index b87f7710..edad9262 100644 --- a/tooling/static/debugger/thread_state.h +++ b/tooling/static/debugger/thread_state.h @@ -112,7 +112,7 @@ private: // (then, the locations we should leave to end the step). std::unordered_set stepLocations_; - bool methodEntered_ {false}; + int methodEnterDepth_ {0}; EvaluationEngine &engine_; BreakpointStorage &bpStorage_; diff --git a/tooling/static/inspector.cpp b/tooling/static/inspector.cpp index 136a120b..dbf99bf6 100644 --- a/tooling/static/inspector.cpp +++ b/tooling/static/inspector.cpp @@ -134,9 +134,7 @@ void Inspector::MethodEntry(PtThread thread, Method * /* method */) auto *debuggableThread = GetDebuggableThread(thread); ASSERT(debuggableThread != nullptr); - if (debuggableThread->OnMethodEntry()) { - HandleError(debugger_.NotifyFramePop(thread, 0)); - } + debuggableThread->OnMethodEntry(); } void Inspector::SourceNameInsert(const panda_file::DebugInfoExtractor *extractor) @@ -160,7 +158,7 @@ void Inspector::LoadModule(std::string_view fileName) Runtime::GetCurrent()->GetClassLinker()->EnumeratePandaFiles( [this, fileName](auto &file) { if (file.GetFilename() == fileName) { - debugInfoCache_.AddPandaFile(file); + debugInfoCache_.AddPandaFile(file, true); const auto *extractor = debugInfoCache_.GetDebugInfo(&file); SourceNameInsert(extractor); ResolveBreakpoints(file, extractor); @@ -180,7 +178,7 @@ void Inspector::SingleStep(PtThread thread, Method *method, const PtLocation &lo { os::memory::ReadLockHolder lock(debuggerEventsLock_); - auto sourceFile = debugInfoCache_.GetSourceFile(method); + auto sourceFile = debugInfoCache_.GetUserSourceFile(method); // NOTE(fangting, #IC98Z2): etsstdlib.ets should not call loadModule in pytest. if ((sourceFile == nullptr) || (strcmp(sourceFile, "etsstdlib.ets") == 0)) { return; @@ -483,7 +481,6 @@ void Inspector::StepOut(PtThread thread) return; } - HandleError(debugger_.NotifyFramePop(thread, 0)); debuggableThread->StepOut(); } } -- Gitee