diff --git a/ecmascript/tooling/agent/js_backend.cpp b/ecmascript/tooling/agent/js_backend.cpp index 5a97e51c34fb11b2739ac27ff074bf8ca99a66ea..cd47454a7a390c9bd0eac6bf1ddbaf0a40d2ebdd 100644 --- a/ecmascript/tooling/agent/js_backend.cpp +++ b/ecmascript/tooling/agent/js_backend.cpp @@ -193,27 +193,53 @@ bool JSBackend::NotifyScriptParsed(ScriptId scriptId, const CString &fileName) } bool JSBackend::StepComplete(const JSPtLocation &location) +{ + if (UNLIKELY(pauseOnNextByteCode_)) { + if (IsSkipLine(location)) { + return false; + } + pauseOnNextByteCode_ = false; + LOG(INFO, DEBUGGER) << "StepComplete: pause on next bytecode"; + return true; + } + + if (LIKELY(singleStepper_ == nullptr)) { + return false; + } + + // step not complete + if (!singleStepper_->StepComplete(location.GetBytecodeOffset())) { + return false; + } + + // skip unknown file or special line -1 + if (IsSkipLine(location)) { + return false; + } + + LOG(INFO, DEBUGGER) << "StepComplete: pause on current byte_code"; + return true; +} + +bool JSBackend::IsSkipLine(const JSPtLocation &location) { JSPtExtractor *extractor = nullptr; auto scriptFunc = [this, &extractor](PtScript *script) -> bool { extractor = GetExtractor(script->GetUrl()); return true; }; + if (!MatchScripts(scriptFunc, location.GetPandaFile(), ScriptMatchType::FILE_NAME) || extractor == nullptr) { + LOG(INFO, DEBUGGER) << "StepComplete: skip unknown file"; + return true; + } + auto callbackFunc = [](int32_t line) -> bool { return line == SPECIAL_LINE_MARK; }; File::EntityId methodId = location.GetMethodId(); uint32_t offset = location.GetBytecodeOffset(); - if (MatchScripts(scriptFunc, location.GetPandaFile(), ScriptMatchType::FILE_NAME) && - extractor != nullptr && extractor->MatchLineWithOffset(callbackFunc, methodId, offset)) { + if (extractor->MatchLineWithOffset(callbackFunc, methodId, offset)) { LOG(INFO, DEBUGGER) << "StepComplete: skip -1"; - return false; - } - - if (pauseOnNextByteCode_ || - (singleStepper_ != nullptr && singleStepper_->StepComplete(location.GetBytecodeOffset()))) { - LOG(INFO, DEBUGGER) << "StepComplete: pause on current byte_code"; - pauseOnNextByteCode_ = false; return true; } diff --git a/ecmascript/tooling/agent/js_backend.h b/ecmascript/tooling/agent/js_backend.h index 480c7bd8cd17e1ca3ae6ac484b1d327a695bdc08..9949def98f13a078569a07875addb09bb9e7a06b 100644 --- a/ecmascript/tooling/agent/js_backend.h +++ b/ecmascript/tooling/agent/js_backend.h @@ -140,6 +140,7 @@ private: const char* name, CVector> *outPropertyDesc); void GetAdditionalProperties(const Local &value, CVector> *outPropertyDesc); + bool IsSkipLine(const JSPtLocation &location); constexpr static int32_t SPECIAL_LINE_MARK = -1; diff --git a/ecmascript/tooling/agent/js_pt_hooks.cpp b/ecmascript/tooling/agent/js_pt_hooks.cpp index 7550633be579ade442b82f915b93addf8778827e..92582758ea8f2029161027660393fe217b8fe06a 100644 --- a/ecmascript/tooling/agent/js_pt_hooks.cpp +++ b/ecmascript/tooling/agent/js_pt_hooks.cpp @@ -47,7 +47,7 @@ bool JSPtHooks::SingleStep(const JSPtLocation &location) LOG(DEBUG, DEBUGGER) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); [[maybe_unused]] LocalScope scope(backend_->ecmaVm_); - if (firstTime_) { + if (UNLIKELY(firstTime_)) { firstTime_ = false; backend_->NotifyPaused({}, BREAK_ON_START); diff --git a/ecmascript/tooling/test/utils/test_util.h b/ecmascript/tooling/test/utils/test_util.h index f12e991e3e591068d5636263a868510f0459615e..77f8cd78538a602e0e082ffcbd50da909cae99f6 100644 --- a/ecmascript/tooling/test/utils/test_util.h +++ b/ecmascript/tooling/test/utils/test_util.h @@ -140,20 +140,15 @@ public: static bool SuspendUntilContinue(DebugEvent reason, JSPtLocation location) { - { - os::memory::LockHolder lock(suspendMutex_); - suspended_ = true; - } + os::memory::LockHolder lock(suspendMutex_); + suspended_ = true; // Notify the debugger thread about the suspend event Event(reason, location); // Wait for continue - { - os::memory::LockHolder lock(suspendMutex_); - while (suspended_) { - suspendCv_.Wait(&suspendMutex_); - } + while (suspended_) { + suspendCv_.Wait(&suspendMutex_); } return true; @@ -176,7 +171,7 @@ private: if (lastEvent_ == DebugEvent::VM_DEATH) { return false; } - constexpr uint64_t TIMEOUT_MSEC = 100000U; + constexpr uint64_t TIMEOUT_MSEC = 10000U; bool timeExceeded = eventCv_.TimedWait(&eventMutex_, TIMEOUT_MSEC); if (timeExceeded) { LOG(FATAL, DEBUGGER) << "Time limit exceeded while waiting " << event;