From 8e0225c3eb31636a0b84691411d3e851af2cbd78 Mon Sep 17 00:00:00 2001 From: Vasil Trifonov Date: Tue, 4 Jun 2019 17:08:43 +0300 Subject: [PATCH] Added a setting for enabling line breakpoints --- test-app/app/src/main/assets/app/package.json | 3 +- test-app/runtime/CMakeLists.txt | 1 + .../src/main/cpp/NSV8DebuggerAgentImpl.cpp | 38 +++++++++++++++++++ .../src/main/cpp/NSV8DebuggerAgentImpl.h | 29 ++++++++++++++ .../inspector/v8-inspector-session-impl.cc | 3 +- .../src/main/java/com/tns/AppConfig.java | 10 ++++- .../src/main/java/com/tns/Runtime.java | 9 +++++ 7 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 test-app/runtime/src/main/cpp/NSV8DebuggerAgentImpl.cpp create mode 100644 test-app/runtime/src/main/cpp/NSV8DebuggerAgentImpl.h diff --git a/test-app/app/src/main/assets/app/package.json b/test-app/app/src/main/assets/app/package.json index 65dedca60..04ed07324 100644 --- a/test-app/app/src/main/assets/app/package.json +++ b/test-app/app/src/main/assets/app/package.json @@ -9,7 +9,8 @@ "markingMode": "full", "maxLogcatObjectSize": 1024, "forceLog": false, - "suppressCallJSMethodExceptions": false + "suppressCallJSMethodExceptions": false, + "enableLineBreakpoints": false }, "discardUncaughtJsExceptions": false } \ No newline at end of file diff --git a/test-app/runtime/CMakeLists.txt b/test-app/runtime/CMakeLists.txt index e9557f14b..153ed6e0b 100644 --- a/test-app/runtime/CMakeLists.txt +++ b/test-app/runtime/CMakeLists.txt @@ -63,6 +63,7 @@ if (NOT OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD) src/main/cpp/JsV8InspectorClient.cpp src/main/cpp/DOMDomainCallbackHandlers.cpp src/main/cpp/NetworkDomainCallbackHandlers.cpp + src/main/cpp/NSV8DebuggerAgentImpl.cpp src/main/cpp/v8_inspector/src/inspector/protocol/CSS.cpp src/main/cpp/v8_inspector/src/inspector/protocol/Console.cpp diff --git a/test-app/runtime/src/main/cpp/NSV8DebuggerAgentImpl.cpp b/test-app/runtime/src/main/cpp/NSV8DebuggerAgentImpl.cpp new file mode 100644 index 000000000..52b5b4899 --- /dev/null +++ b/test-app/runtime/src/main/cpp/NSV8DebuggerAgentImpl.cpp @@ -0,0 +1,38 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "NSV8DebuggerAgentImpl.h" + +namespace v8_inspector { + +NSV8DebuggerAgentImpl::NSV8DebuggerAgentImpl( + V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, + protocol::DictionaryValue* state) + : V8DebuggerAgentImpl(session, frontendChannel, state), + m_env(tns::JEnv()){ + + auto runtimeClass = m_env.FindClass("com/tns/Runtime"); + assert(runtimeClass != nullptr); + + auto getLineBreakpointsEnabledMethodID = m_env.GetStaticMethodID(runtimeClass, "getLineBreakpointsEnabled", "()Z"); + assert(getLineBreakpointsEnabledMethodID != nullptr); + + auto lineBreakpointsEnabled = m_env.CallStaticBooleanMethod(runtimeClass, getLineBreakpointsEnabledMethodID); + m_lineBreakpointsEnabled = lineBreakpointsEnabled == JNI_TRUE; +} + +Response NSV8DebuggerAgentImpl::getPossibleBreakpoints( + std::unique_ptr start, + Maybe end, Maybe restrictToFunction, + std::unique_ptr>* + locations) { + if(m_lineBreakpointsEnabled) { + return V8DebuggerAgentImpl::getPossibleBreakpoints(std::move(start), std::move(end), std::move(restrictToFunction), locations); + } else { + *locations = protocol::Array::create(); + return Response::OK(); + } +} + +} // namespace v8_inspector diff --git a/test-app/runtime/src/main/cpp/NSV8DebuggerAgentImpl.h b/test-app/runtime/src/main/cpp/NSV8DebuggerAgentImpl.h new file mode 100644 index 000000000..c06604200 --- /dev/null +++ b/test-app/runtime/src/main/cpp/NSV8DebuggerAgentImpl.h @@ -0,0 +1,29 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_INSPECTOR_NS_V8_DEBUGGER_AGENT_IMPL_H_ +#define V8_INSPECTOR_NS_V8_DEBUGGER_AGENT_IMPL_H_ + +#include +#include "src/inspector/v8-debugger-agent-impl.h" + +namespace v8_inspector { + + class NSV8DebuggerAgentImpl : public V8DebuggerAgentImpl { + public: + NSV8DebuggerAgentImpl(V8InspectorSessionImpl *, protocol::FrontendChannel *, + protocol::DictionaryValue *state); + + Response getPossibleBreakpoints( + std::unique_ptr start, + Maybe end, Maybe restrictToFunction, + std::unique_ptr> * + locations) override; + DISALLOW_COPY_AND_ASSIGN(NSV8DebuggerAgentImpl); + private: + tns::JEnv m_env; + bool m_lineBreakpointsEnabled; + }; +} +#endif // V8_INSPECTOR_NS_V8_DEBUGGER_AGENT_IMPL_H_ diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/inspector/v8-inspector-session-impl.cc b/test-app/runtime/src/main/cpp/v8_inspector/src/inspector/v8-inspector-session-impl.cc index 1f01f78e3..1c07c3bb7 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/inspector/v8-inspector-session-impl.cc +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/inspector/v8-inspector-session-impl.cc @@ -24,6 +24,7 @@ #include "src/inspector/v8-css-agent-impl.h" #include "src/inspector/v8-overlay-agent-impl.h" #include "src/inspector/v8-log-agent-impl.h" +#include "NSV8DebuggerAgentImpl.h" namespace v8_inspector { @@ -106,7 +107,7 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, this, this, agentState(protocol::Runtime::Metainfo::domainName))); protocol::Runtime::Dispatcher::wire(&m_dispatcher, m_runtimeAgent.get()); - m_debuggerAgent.reset(new V8DebuggerAgentImpl( + m_debuggerAgent.reset(new NSV8DebuggerAgentImpl( this, this, agentState(protocol::Debugger::Metainfo::domainName))); protocol::Debugger::Dispatcher::wire(&m_dispatcher, m_debuggerAgent.get()); diff --git a/test-app/runtime/src/main/java/com/tns/AppConfig.java b/test-app/runtime/src/main/java/com/tns/AppConfig.java index 2994bf821..1b6dc5cec 100644 --- a/test-app/runtime/src/main/java/com/tns/AppConfig.java +++ b/test-app/runtime/src/main/java/com/tns/AppConfig.java @@ -20,7 +20,8 @@ protected enum KnownKeys { HandleTimeZoneChanges("handleTimeZoneChanges", false), MaxLogcatObjectSize("maxLogcatObjectSize", 1024), ForceLog("forceLog", false), - DiscardUncaughtJsExceptions("discardUncaughtJsExceptions", false); + DiscardUncaughtJsExceptions("discardUncaughtJsExceptions", false), + EnableLineBreakpoins("enableLineBreakpoints", false); private final String name; private final Object defaultValue; @@ -116,6 +117,9 @@ public AppConfig(File appDir) { if (androidObject.has(KnownKeys.ForceLog.getName())) { values[KnownKeys.ForceLog.ordinal()] = androidObject.getBoolean(KnownKeys.ForceLog.getName()); } + if (androidObject.has(KnownKeys.EnableLineBreakpoins.getName())) { + values[KnownKeys.EnableLineBreakpoins.ordinal()] = androidObject.getBoolean(KnownKeys.EnableLineBreakpoins.getName()); + } } } } catch (Exception e) { @@ -167,6 +171,10 @@ public boolean getForceLog() { return (boolean)values[KnownKeys.ForceLog.ordinal()]; } + public boolean getLineBreakpointsEnabled() { + return (boolean)values[KnownKeys.EnableLineBreakpoins.ordinal()]; + } + public boolean getDiscardUncaughtJsExceptions() { return (boolean)values[KnownKeys.DiscardUncaughtJsExceptions.ordinal()]; } diff --git a/test-app/runtime/src/main/java/com/tns/Runtime.java b/test-app/runtime/src/main/java/com/tns/Runtime.java index dd3881f06..1c42edb30 100644 --- a/test-app/runtime/src/main/java/com/tns/Runtime.java +++ b/test-app/runtime/src/main/java/com/tns/Runtime.java @@ -272,6 +272,15 @@ public DynamicConfiguration getDynamicConfig() { return dynamicConfig; } + @RuntimeCallable + public static boolean getLineBreakpointsEnabled() { + if (staticConfiguration != null && staticConfiguration.appConfig != null) { + return staticConfiguration.appConfig.getLineBreakpointsEnabled(); + } else { + return ((boolean) AppConfig.KnownKeys.EnableLineBreakpoins.getDefaultValue()); + } + } + @RuntimeCallable public int getMarkingModeOrdinal() { if (staticConfiguration != null && staticConfiguration.appConfig != null) {