From 84207b4627339085565ec21cb8bc3c009f85fadc Mon Sep 17 00:00:00 2001 From: yangyang Date: Thu, 30 Mar 2023 16:15:07 +0800 Subject: [PATCH 1/2] Add proxy variable to UT testcase Issue:#I6RN4V Signed-off-by: yangyang Change-Id: Iced6651451dfd0efd3f05cde8a18b83470180eb9 --- tooling/test/testcases/js/variable_second.js | 11 +++++++++++ .../test/testcases/js_variable_second_test.h | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/tooling/test/testcases/js/variable_second.js b/tooling/test/testcases/js/variable_second.js index fc16c3a9..c128bd1a 100644 --- a/tooling/test/testcases/js/variable_second.js +++ b/tooling/test/testcases/js/variable_second.js @@ -105,6 +105,17 @@ var o = { var weakMap = new WeakMap(); var weakSet = new WeakSet(); + var proxy0 = new Proxy(obj0, {}); + var proxy1 = new Proxy(map0, {}); + var proxy2 = new Proxy(set0, {}); + var proxy3 = new Proxy(array0, {}); + var proxy4 = new Proxy(dataview0, {}); + var proxy5 = new Proxy(arraybuffer0, {}); + var proxy6 = new Proxy(weakref0, {}); + var proxy7 = new Proxy(sharedarraybuffer0, {}); + var proxy8 = new Proxy(weakMap, {}); + var proxy9 = new Proxy(weakSet, {}); + var nop = undefined; } } diff --git a/tooling/test/testcases/js_variable_second_test.h b/tooling/test/testcases/js_variable_second_test.h index 1f7170b6..7d4beefb 100644 --- a/tooling/test/testcases/js_variable_second_test.h +++ b/tooling/test/testcases/js_variable_second_test.h @@ -36,8 +36,8 @@ public: std::string panfaFile = DEBUGGER_ABC_DIR "variable_second.abc"; std::string sourceFile = DEBUGGER_JS_DIR "variable_second.js"; static_cast(channel_)->Initial(vm_, runtime_); - // 107: breakpointer line - location_ = TestUtil::GetLocation(sourceFile.c_str(), 107, 0, panfaFile.c_str()); + // 118: breakpointer line + location_ = TestUtil::GetLocation(sourceFile.c_str(), 118, 0, panfaFile.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, panfaFile); @@ -128,7 +128,8 @@ private: auto value = property->GetValue(); std::vector infos; PushValueInfo(value, infos); - if (value->GetType() == RemoteObject::TypeName::Object) { + if (value->GetType() == RemoteObject::TypeName::Object && (!value->HasSubType() || + value->GetSubType() != RemoteObject::SubTypeName::Proxy)) { std::vector> outPropertyDescInner; ASSERT_TRUE(value->HasObjectId()); params.SetObjectId(value->GetObjectId()).SetOwnProperties(true); @@ -370,6 +371,16 @@ private: { "iterator19", { "undefined" } }, { "weakMap", { "object", "weakmap", "Weakmap", "WeakMap", "[object WeakMap]", "none" } }, { "weakSet", { "object", "weakset", "Weakset", "WeakSet", "[object WeakSet]", "none" } }, + { "proxy0", { "object", "proxy", "Object", "Proxy", "[object Object]" }}, + { "proxy1", { "object", "proxy", "Object", "Proxy", "[object Map]" }}, + { "proxy2", { "object", "proxy", "Object", "Proxy", "[object Set]" }}, + { "proxy3", { "object", "proxy", "Object", "Proxy", "Apple,Banana" }}, + { "proxy4", { "object", "proxy", "Object", "Proxy", "[object DataView]" }}, + { "proxy5", { "object", "proxy", "Object", "Proxy", "[object ArrayBuffer]" }}, + { "proxy6", { "object", "proxy", "Object", "Proxy", "[object WeakRef]" }}, + { "proxy7", { "object", "proxy", "Object", "Proxy", "[object SharedArrayBuffer]" }}, + { "proxy8", { "object", "proxy", "Object", "Proxy", "[object WeakMap]" }}, + { "proxy9", { "object", "proxy", "Object", "Proxy", "[object WeakSet]" }}, }; int32_t index_ {0}; -- Gitee From 802c28c49225bcfc1ba321681170895216875146 Mon Sep 17 00:00:00 2001 From: yangyang Date: Thu, 23 Mar 2023 16:35:06 +0800 Subject: [PATCH 2/2] Support for mixed debugging Issue:#I6PLVS Signed-off-by: yangyang Change-Id: I9498ce032c37a39a0fea57a2f636f070d8b7cf5f --- inspector/inspector.cpp | 15 +++++++++++++ tooling/agent/debugger_impl.cpp | 29 +++++++++++++++++++++++++- tooling/agent/debugger_impl.h | 3 ++- tooling/base/pt_params.cpp | 22 ++++++++++++++++++++ tooling/base/pt_params.h | 18 ++++++++++++++++ tooling/protocol_handler.cpp | 37 ++++++++++++++++++++++++++------- tooling/protocol_handler.h | 7 +++++-- 7 files changed, 120 insertions(+), 11 deletions(-) diff --git a/inspector/inspector.cpp b/inspector/inspector.cpp index 3769358e..59a64ce7 100644 --- a/inspector/inspector.cpp +++ b/inspector/inspector.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include "log_wrapper.h" #include "library_loader.h" @@ -99,6 +101,13 @@ void* GetArkDynFunction(const char* symbol) } #endif +#if !defined(WINDOWS_PLATFORM) +void DispatchMessage(int) +{ + g_processMessage(g_vm); +} +#endif + void SendReply(const void* vm, const std::string& message) { std::shared_lock lock(g_mutex); @@ -271,6 +280,12 @@ bool StartDebug(const std::string& componentName, void* vm, bool isDebugMode, in return false; } +#if !defined(WINDOWS_PLATFORM) + if (signal(SIGALRM, &DispatchMessage) == SIG_ERR) { + LOGW("Install signal handler failed"); + } +#endif + if (isDebugMode) { g_waitForDebugger(vm); } diff --git a/tooling/agent/debugger_impl.cpp b/tooling/agent/debugger_impl.cpp index a72cde9c..5b709ba7 100644 --- a/tooling/agent/debugger_impl.cpp +++ b/tooling/agent/debugger_impl.cpp @@ -294,7 +294,8 @@ void DebuggerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { "stepOver", &DebuggerImpl::DispatcherImpl::StepOver }, { "setMixedDebugEnabled", &DebuggerImpl::DispatcherImpl::SetMixedDebugEnabled }, { "setBlackboxPatterns", &DebuggerImpl::DispatcherImpl::SetBlackboxPatterns }, - { "replyNativeCalling", &DebuggerImpl::DispatcherImpl::ReplyNativeCalling } + { "replyNativeCalling", &DebuggerImpl::DispatcherImpl::ReplyNativeCalling }, + { "setFastRequest", &DebuggerImpl::DispatcherImpl::SetFastRequest } }; const std::string &method = request.GetMethod(); @@ -483,6 +484,17 @@ void DebuggerImpl::DispatcherImpl::ReplyNativeCalling(const DispatchRequest &req SendResponse(request, response); } +void DebuggerImpl::DispatcherImpl::SetFastRequest(const DispatchRequest &request) +{ + std::unique_ptr params = SetFastRequestParams::Create(request.GetParams()); + if (params == nullptr) { + SendResponse(request, DispatchResponse::Fail("wrong params")); + return; + } + DispatchResponse response = debugger_->SetFastRequest(*params); + SendResponse(request, response); +} + void DebuggerImpl::DispatcherImpl::SetBlackboxPatterns(const DispatchRequest &request) { DispatchResponse response = debugger_->SetBlackboxPatterns(); @@ -522,6 +534,15 @@ void DebuggerImpl::Frontend::NativeCalling(const EcmaVM *vm, const tooling::Nati channel_->SendNotification(nativeCalling); } +// void DebuggerImpl::Frontend::FastRequest(const EcmaVM *vm, const tooling::NativeCalling &fastRe) +// { +// if (!AllowNotify(vm)) { +// return; +// } + +// channel_->SendNotification(nativeCalling); +// } + void DebuggerImpl::Frontend::Resumed(const EcmaVM *vm) { if (!AllowNotify(vm)) { @@ -862,6 +883,12 @@ DispatchResponse DebuggerImpl::ReplyNativeCalling([[maybe_unused]] const ReplyNa return DispatchResponse::Ok(); } +DispatchResponse DebuggerImpl::SetFastRequest([[maybe_unused]] const SetFastRequestParams ¶ms) +{ + frontend_.Resumed(vm_); + return DispatchResponse::Ok(); +} + void DebuggerImpl::CleanUpOnPaused() { runtime_->curObjectId_ = 0; diff --git a/tooling/agent/debugger_impl.h b/tooling/agent/debugger_impl.h index 337f3034..9944bf10 100644 --- a/tooling/agent/debugger_impl.h +++ b/tooling/agent/debugger_impl.h @@ -64,6 +64,7 @@ public: DispatchResponse SetBlackboxPatterns(); DispatchResponse SetMixedDebugEnabled(const SetMixedDebugParams ¶ms); DispatchResponse ReplyNativeCalling(const ReplyNativeCallingParams ¶ms); + DispatchResponse SetFastRequest(const SetFastRequestParams ¶ms); /** * @brief: match first script and callback @@ -124,7 +125,7 @@ public: void SetMixedDebugEnabled(const DispatchRequest &request); void SetBlackboxPatterns(const DispatchRequest &request); void ReplyNativeCalling(const DispatchRequest &request); - + void SetFastRequest(const DispatchRequest &request); private: NO_COPY_SEMANTIC(DispatcherImpl); NO_MOVE_SEMANTIC(DispatcherImpl); diff --git a/tooling/base/pt_params.cpp b/tooling/base/pt_params.cpp index 7b719471..4b90bc60 100644 --- a/tooling/base/pt_params.cpp +++ b/tooling/base/pt_params.cpp @@ -471,6 +471,28 @@ std::unique_ptr ReplyNativeCallingParams::Create(const return paramsObject; } +std::unique_ptr SetFastRequestParams::Create(const PtJson ¶ms) +{ + auto paramsObject = std::make_unique(); + std::string error; + Result ret; + + bool isFastDispatch = false; + ret = params.GetBool("isFastDispatch", &isFastDispatch); + if (ret == Result::SUCCESS) { + paramsObject->isFastDispatch_ = isFastDispatch; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'isFastDispatch';"; + } + + if (!error.empty()) { + LOG_DEBUGGER(ERROR) << "SetFastRequestParams::Create " << error; + return nullptr; + } + + return paramsObject; +} + std::unique_ptr GetPropertiesParams::Create(const PtJson ¶ms) { auto paramsObject = std::make_unique(); diff --git a/tooling/base/pt_params.h b/tooling/base/pt_params.h index 56bd93be..e0a62da2 100644 --- a/tooling/base/pt_params.h +++ b/tooling/base/pt_params.h @@ -447,6 +447,24 @@ private: bool userCode_ { false }; }; +class SetFastRequestParams : public PtBaseParams { +public: + SetFastRequestParams() = default; + ~SetFastRequestParams() override = default; + static std::unique_ptr Create(const PtJson ¶ms); + + bool GetIsFastDispatch() const + { + return isFastDispatch_; + } + +private: + NO_COPY_SEMANTIC(SetFastRequestParams); + NO_MOVE_SEMANTIC(SetFastRequestParams); + + bool isFastDispatch_ { false }; +}; + class GetPropertiesParams : public PtBaseParams { public: GetPropertiesParams() = default; diff --git a/tooling/protocol_handler.cpp b/tooling/protocol_handler.cpp index d685a4e7..a8def091 100644 --- a/tooling/protocol_handler.cpp +++ b/tooling/protocol_handler.cpp @@ -17,6 +17,8 @@ #include "agent/debugger_impl.h" +#include + namespace panda::ecmascript::tooling { void ProtocolHandler::WaitForDebugger() { @@ -33,8 +35,31 @@ void ProtocolHandler::DispatchCommand(std::string &&msg) { LOG_DEBUGGER(DEBUG) << "ProtocolHandler::DispatchCommand: " << msg; std::unique_lock queueLock(requestLock_); - requestQueue_.push(std::move(msg)); - requestQueueCond_.notify_one(); + requestQueue_.emplace(std::move(msg)); +#if !defined(WINDOWS_PLATFORM) + if (CheckNeedFastDispatch(requestQueue_.front())) { + LOG_DEBUGGER(INFO) << "ProtocolHandler::CheckNeedFastDispatch"; + queueLock.unlock(); + pthread_kill(tid_, SIGALRM); + } else { + requestQueueCond_.notify_one(); + } +#endif +} + +bool ProtocolHandler::CheckNeedFastDispatch(const DispatchRequest &request) +{ + if (request.GetDomain() == "Debugger" && request.GetMethod() == "setFastRequest") { + bool isFastDispatch = false; + if (request.GetParams().GetBool("isFastDispatch", &isFastDispatch) == Result::SUCCESS) { + isFastDispatch_ = isFastDispatch; + // should not dispatch setFastRequest + requestQueue_.pop(); + } + return false; + } + + return isFastDispatch_; } // called after DispatchCommand @@ -52,7 +77,7 @@ int32_t ProtocolHandler::GetDispatchStatus() void ProtocolHandler::ProcessCommand() { - std::queue dispatchingQueue; + std::queue dispatchingQueue; do { { std::unique_lock queueLock(requestLock_); @@ -67,12 +92,10 @@ void ProtocolHandler::ProcessCommand() isDispatchingMessage_ = true; while (!dispatchingQueue.empty()) { - std::string msg = std::move(dispatchingQueue.front()); - dispatchingQueue.pop(); - [[maybe_unused]] LocalScope scope(vm_); auto exception = DebuggerApi::GetAndClearException(vm_); - dispatcher_.Dispatch(DispatchRequest(msg)); + dispatcher_.Dispatch(dispatchingQueue.front()); + dispatchingQueue.pop(); DebuggerApi::SetException(vm_, exception); } isDispatchingMessage_ = false; diff --git a/tooling/protocol_handler.h b/tooling/protocol_handler.h index ee7a046a..c8decb90 100644 --- a/tooling/protocol_handler.h +++ b/tooling/protocol_handler.h @@ -33,7 +33,7 @@ public: }; ProtocolHandler(std::function callback, const EcmaVM *vm) - : callback_(std::move(callback)), dispatcher_(vm, this), vm_(vm) {} + : callback_(std::move(callback)), dispatcher_(vm, this), vm_(vm), tid_(pthread_self()) {} ~ProtocolHandler() override = default; void WaitForDebugger() override; @@ -51,15 +51,18 @@ private: NO_COPY_SEMANTIC(ProtocolHandler); std::unique_ptr CreateErrorReply(const DispatchResponse &response); void SendReply(const PtJson &reply); + bool CheckNeedFastDispatch(const DispatchRequest &request); std::function callback_; Dispatcher dispatcher_; bool waitingForDebugger_ {false}; const EcmaVM *vm_ {nullptr}; + pthread_t tid_ {0}; + bool isFastDispatch_ {false}; std::condition_variable requestQueueCond_; - std::queue requestQueue_; + std::queue requestQueue_; std::mutex requestLock_; std::atomic isDispatchingMessage_ {false}; }; -- Gitee