From 0688662466a14f18c7954751a7beb68890e44550 Mon Sep 17 00:00:00 2001 From: yangyang Date: Fri, 14 Apr 2023 17:28:11 +0800 Subject: [PATCH] Cherry-pick to 3.2-release Issue:#I6VT4X Signed-off-by: yangyang Change-Id: Id12a7a6639f4dd750389636d2aa2711a3792ecf2 --- tooling/agent/debugger_impl.cpp | 10 ++++--- tooling/backend/debugger_executor.cpp | 38 +++++++++++++++++++++++++++ tooling/backend/debugger_executor.h | 3 +++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index 88bf1129..0779fe70 100644 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -973,11 +973,12 @@ bool DebuggerImpl::GenerateCallFrame(CallFrame *callFrame, std::unique_ptr thisObj = std::make_unique(); thisObj->SetType(ObjectType::Undefined); + JSThread *thread = vm_->GetJSThread(); std::vector> scopeChain; scopeChain.emplace_back(GetLocalScopeChain(frameHandler, &thisObj)); if (jsPandaFile != nullptr && !jsPandaFile->IsBundlePack() && jsPandaFile->IsNewVersion()) { - JSTaggedValue currentModule = DebuggerApi::GetCurrentModule(vm_); - if (currentModule.IsSourceTextModule()) { + JSHandle currentModule(thread, DebuggerApi::GetCurrentModule(vm_)); + if (currentModule->IsSourceTextModule()) { // CJS module is string scopeChain.emplace_back(GetModuleScopeChain()); } } @@ -1056,7 +1057,10 @@ std::unique_ptr DebuggerImpl::GetModuleScopeChain() moduleScope->SetType(Scope::Type::Module()).SetObject(std::move(module)); runtime_->properties_[runtime_->curObjectId_++] = Global(vm_, moduleObj); JSThread *thread = vm_->GetJSThread(); - DebuggerApi::GetModuleVariables(vm_, moduleObj, thread); + JSHandle currentModule(thread, DebuggerApi::GetCurrentModule(vm_)); + DebuggerApi::GetLocalExportVariables(vm_, moduleObj, currentModule, false); + DebuggerApi::GetIndirectExportVariables(vm_, moduleObj, currentModule); + DebuggerApi::GetImportVariables(vm_, moduleObj, currentModule); return moduleScope; } diff --git a/tooling/backend/debugger_executor.cpp b/tooling/backend/debugger_executor.cpp index 02e85449..d56afec0 100644 --- a/tooling/backend/debugger_executor.cpp +++ b/tooling/backend/debugger_executor.cpp @@ -96,6 +96,10 @@ Local DebuggerExecutor::GetValue(const EcmaVM *vm, const FrameHandle if (!value.IsEmpty()) { return value; } + value = GetModuleValue(vm, frameHandler, name); + if (!value.IsEmpty()) { + return value; + } value = GetGlobalValue(vm, name); if (!value.IsEmpty()) { return value; @@ -113,6 +117,9 @@ bool DebuggerExecutor::SetValue(const EcmaVM *vm, FrameHandler *frameHandler, if (SetLexicalValue(vm, frameHandler, name, value)) { return true; } + if (SetModuleValue(vm, frameHandler, name, value)) { + return true; + } if (SetGlobalValue(vm, name, value)) { return true; } @@ -192,4 +199,35 @@ bool DebuggerExecutor::SetGlobalValue(const EcmaVM *vm, Local name, L { return DebuggerApi::SetGlobalValue(vm, name, value); } + +Local DebuggerExecutor::GetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, + Local name) +{ + Local result; + std::string varName = name->ToString(); + Method *method = DebuggerApi::GetMethod(frameHandler); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + if (jsPandaFile != nullptr && (jsPandaFile->IsBundlePack() || !jsPandaFile->IsNewVersion())) { + return result; + } + JSThread *thread = vm->GetJSThread(); + JSHandle currentModule(thread, DebuggerApi::GetCurrentModule(vm)); + result = DebuggerApi::GetModuleValue(vm, currentModule, varName); + return result; +} + +bool DebuggerExecutor::SetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, + Local name, Local value) +{ + std::string varName = name->ToString(); + Method *method = DebuggerApi::GetMethod(frameHandler); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + if (jsPandaFile != nullptr && (jsPandaFile->IsBundlePack() || !jsPandaFile->IsNewVersion())) { + return false; + } + JSThread *thread = vm->GetJSThread(); + JSHandle currentModule(thread, DebuggerApi::GetCurrentModule(vm)); + DebuggerApi::SetModuleValue(vm, currentModule, varName, value); + return true; +} } // namespace panda::ecmascript::tooling diff --git a/tooling/backend/debugger_executor.h b/tooling/backend/debugger_executor.h index 491cc3de..b8acb51c 100644 --- a/tooling/backend/debugger_executor.h +++ b/tooling/backend/debugger_executor.h @@ -44,12 +44,15 @@ private: static Local GetLocalValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local name); static Local GetLexicalValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local name); + static Local GetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local name); static Local GetGlobalValue(const EcmaVM *vm, Local name); static bool SetLocalValue(const EcmaVM *vm, FrameHandler *frameHandler, Local name, Local value); static bool SetLexicalValue(const EcmaVM *vm, const FrameHandler *frameHandler, Local name, Local value); + static bool SetModuleValue(const EcmaVM *vm, const FrameHandler *frameHandler, + Local name, Local value); static bool SetGlobalValue(const EcmaVM *vm, Local name, Local value); constexpr static uint32_t NUM_ARGS = 2; -- Gitee