From db66b2e32a89e4d6cd4f0ef7c73c5d91255f26e6 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 Change-Id: I81ed7332f3ac11aefc249e46a2008aebf0ace16c Signed-off-by: kanghonglin --- tooling/static/debugger/debug_info_cache.cpp | 17 ++++++++++++++--- tooling/static/debugger/debug_info_cache.h | 4 +++- tooling/static/inspector.cpp | 8 ++++++-- tooling/static/tests/debug_info_cache.cpp | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/tooling/static/debugger/debug_info_cache.cpp b/tooling/static/debugger/debug_info_cache.cpp index af65685f..68add1ee 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()) { @@ -57,7 +58,7 @@ void DebugInfoCache::GetSourceLocation(const PtFrame &frame, std::string_view &s auto method = frame.GetMethod(); auto pandaFile = method->GetPandaFile(); auto debugInfo = GetDebugInfo(pandaFile); - if (debugInfo == nullptr) { + if (debugInfo == nullptr || !debugInfo->IsUserFile()) { lineNumber = 1; return; } @@ -419,4 +420,14 @@ const char *DebugInfoCache::GetSourceFile(Method *method) return debugInfo->GetSourceFile(method->GetFileId()); } +const char *DebugInfoCache::GetUserSourceFile(Method *method) +{ + auto pandaFile = method->GetPandaFile(); + auto debugInfo = GetDebugInfo(pandaFile); + if ((debugInfo == nullptr) || !debugInfo->IsUserFile()) { + return nullptr; + } + return debugInfo->GetSourceFile(method->GetFileId()); +} + } // namespace ark::tooling::inspector diff --git a/tooling/static/debugger/debug_info_cache.h b/tooling/static/debugger/debug_info_cache.h index 27b8dce3..f0180428 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); @@ -54,6 +54,8 @@ public: const char *GetSourceFile(Method *method); + const char *GetUserSourceFile(Method *method); + const panda_file::DebugInfoExtractor *GetDebugInfo(const panda_file::File *file) const; private: diff --git a/tooling/static/inspector.cpp b/tooling/static/inspector.cpp index 136a120b..cc55c7c0 100644 --- a/tooling/static/inspector.cpp +++ b/tooling/static/inspector.cpp @@ -134,6 +134,10 @@ void Inspector::MethodEntry(PtThread thread, Method * /* method */) auto *debuggableThread = GetDebuggableThread(thread); ASSERT(debuggableThread != nullptr); + auto stack = StackWalker::Create(thread.GetManagedThread()); + if (stack.IsCFrame()) { + return; + } if (debuggableThread->OnMethodEntry()) { HandleError(debugger_.NotifyFramePop(thread, 0)); } @@ -160,7 +164,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 +184,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; diff --git a/tooling/static/tests/debug_info_cache.cpp b/tooling/static/tests/debug_info_cache.cpp index ca96a741..57906985 100644 --- a/tooling/static/tests/debug_info_cache.cpp +++ b/tooling/static/tests/debug_info_cache.cpp @@ -53,7 +53,7 @@ protected: auto pf = panda_file::OpenPandaFile(ASM_FILE_NAME); ASSERT_NE(pf, nullptr); - cache.AddPandaFile(*pf); + cache.AddPandaFile(*pf, true); RuntimeOptions options; options.SetShouldInitializeIntrinsics(false); -- Gitee