From 23dab71eb00167fcb81b833f3ba470b197a0e1b2 Mon Sep 17 00:00:00 2001 From: yang-19970325 Date: Fri, 23 Aug 2024 15:53:02 +0800 Subject: [PATCH] Fix breakpoint fail in worker thread Issue: #IAM1WQ Signed-off-by: yang-19970325 --- tooling/agent/debugger_impl.cpp | 26 ++++++++++++++++++++++++++ tooling/agent/debugger_impl.h | 4 ++++ tooling/backend/js_pt_hooks.cpp | 22 +++++++++++++++++----- tooling/backend/js_pt_hooks.h | 1 + 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index fcd48504..8ead6a85 100755 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -127,6 +127,31 @@ bool DebuggerImpl::NotifyScriptParsed(ScriptId scriptId, const std::string &file return true; } +void DebuggerImpl::StoreMethod(const JSPandaFile *jsPandaFile, EntityId methodId) +{ + JSPtLocation location{jsPandaFile, methodId}; + parsedLoactions_.emplace_back(location); +} + +void DebuggerImpl::RemoveMethodFromParsedLocation(const JSPandaFile *jsPandaFile, EntityId methodId) +{ + JSPtLocation location{jsPandaFile, methodId}; + auto loca = find(parsedLoactions_.begin(), parsedLoactions_.end(), location); + if (loca != parsedLoactions_.end()) { + parsedLoactions_.erase(loca); + } +} + +bool DebuggerImpl::IsMethodFoundInParsedLocation(const JSPandaFile *jsPandaFile, EntityId methodId) +{ + for (auto location : parsedLoactions_) { + if (location.GetJsPandaFile() == jsPandaFile && location.GetMethodId() == methodId) { + return true; + } + } + return false; +} + bool DebuggerImpl::NotifyNativeOut() { if (nativeOutPause_) { @@ -1000,6 +1025,7 @@ DispatchResponse DebuggerImpl::Enable([[maybe_unused]] const EnableParams ¶m for (auto &script : scripts_) { frontend_.ScriptParsed(vm_, *script.second); } + parsedLoactions_.clear(); debuggerState_ = DebuggerState::ENABLED; return DispatchResponse::Ok(); } diff --git a/tooling/agent/debugger_impl.h b/tooling/agent/debugger_impl.h index 61786a22..f7163244 100644 --- a/tooling/agent/debugger_impl.h +++ b/tooling/agent/debugger_impl.h @@ -40,6 +40,9 @@ public: // event bool NotifyScriptParsed(ScriptId scriptId, const std::string &fileName, std::string_view entryPoint = "func_main_0"); + void StoreMethod(const JSPandaFile *jsPandaFile, EntityId methodId); + void RemoveMethodFromParsedLocation(const JSPandaFile *jsPandaFile, EntityId methodId); + bool IsMethodFoundInParsedLocation(const JSPandaFile *jsPandaFile, EntityId methodId); bool NotifySingleStep(const JSPtLocation &location); void NotifyPaused(std::optional location, PauseReason reason); void GeneratePausedInfo(PauseReason reason, @@ -303,6 +306,7 @@ private: std::unordered_map> recordNames_ {}; std::unordered_map> scripts_ {}; + std::vector parsedLoactions_ {}; PauseOnExceptionsState pauseOnException_ {PauseOnExceptionsState::NONE}; DebuggerState debuggerState_ {DebuggerState::ENABLED}; bool pauseOnNextByteCode_ {false}; diff --git a/tooling/backend/js_pt_hooks.cpp b/tooling/backend/js_pt_hooks.cpp index a54aa068..9d4b2caf 100644 --- a/tooling/backend/js_pt_hooks.cpp +++ b/tooling/backend/js_pt_hooks.cpp @@ -47,11 +47,14 @@ bool JSPtHooks::SingleStep(const JSPtLocation &location) LOG_DEBUGGER(VERBOSE) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); [[maybe_unused]] LocalScope scope(debugger_->vm_); - if (UNLIKELY(firstTime_)) { - firstTime_ = false; - - debugger_->NotifyPaused({}, BREAK_ON_START); - return false; + if (!debugger_->parsedLoactions_.empty()) { + auto jsPandaFile = location.GetJsPandaFile(); + auto methodId = location.GetMethodId(); + if (debugger_->IsMethodFoundInParsedLocation(jsPandaFile, methodId)) { + debugger_->RemoveMethodFromParsedLocation(jsPandaFile, methodId); + debugger_->NotifyPaused({}, BREAK_ON_START); + return false; + } } // pause or step complete @@ -88,6 +91,15 @@ void JSPtHooks::LoadModule(std::string_view pandaFileName, std::string_view entr } } +void JSPtHooks::StoreMethod(const JSPandaFile *jsPandaFile, EntityId methodId) +{ + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: StoreMethod: " << methodId; + + [[maybe_unused]] LocalScope scope(debugger_->vm_); + + debugger_->StoreMethod(jsPandaFile, methodId); +} + void JSPtHooks::NativeCalling(const void *nativeAddress) { LOG_DEBUGGER(VERBOSE) << "JSPtHooks: NativeCalling, addr = " << nativeAddress; diff --git a/tooling/backend/js_pt_hooks.h b/tooling/backend/js_pt_hooks.h index 62c52cf9..d1a54908 100644 --- a/tooling/backend/js_pt_hooks.h +++ b/tooling/backend/js_pt_hooks.h @@ -35,6 +35,7 @@ public: void DebuggerStmt(const JSPtLocation &location) override; void Breakpoint(const JSPtLocation &location) override; void LoadModule(std::string_view pandaFileName, std::string_view entryPoint) override; + void StoreMethod(const JSPandaFile *jsPandaFile, EntityId methodId) override; void Exception(const JSPtLocation &location) override; bool SingleStep(const JSPtLocation &location) override; bool NativeOut() override; -- Gitee