diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index fcd48504b7329b49747a4440ead110b7bab7df5b..8ead6a851cc00e8ec872da60c3d44485169b1bae 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 61786a22acb18e3c76963ece45e88c1856d61e3d..f71632442211453ead54c1a18963a63061941ea5 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 a54aa0685afa9e047472d3ccf3bdd161e7a51e1a..9d4b2caf402fd65bcf8eb52bd2d1340d0731602a 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 62c52cf98bc07e3cd92ab4e571767a2fc7e9ca24..d1a54908a724073490921d81abe6b5c821d50f0f 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;