diff --git a/tooling/static/debugger/debug_info_cache.cpp b/tooling/static/debugger/debug_info_cache.cpp index af65685fade0f6af92d892f2c55e4011d19c1113..68add1eebb35f73a1602e9b637a13a6aebabec59 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 27b8dce3b33fa2917900836cb33f730fa34550d5..f018042832a390e05b62ed650ebedc92c761b5ad 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 136a120b5f9aec028fdc671e4ebbc2d2d42702ed..cc55c7c02d0e053e04650416edec6db8af47d33a 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 ca96a741908bcbe88f0c9cbbec05d76a93a22998..57906985c6e538e265e6fb1aa7b7bd685ee29dce 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);