Make the runtime default to not allowing JDWP again.
This was unintentionally changed a while ago and is causing a CTS test
to fail. Changed to make the runtime default to disabling jdwp if a
provider isn't given. Note this does not stop one from starting a
debugger with -agentpath. If jdwp options are given with jdwp disabled
the runtime will print a warning.
Test: atest CtsJdwpSecurityHostTestCases
Test: ./test/run-test --host --debug 001-HelloWorld
Bug: 72400560
Change-Id: I6561f269d9279eba0c1ac0b0f593ece867dab49e
diff --git a/cmdline/cmdline_parser_test.cc b/cmdline/cmdline_parser_test.cc
index 1e79fdf..3cb9731 100644
--- a/cmdline/cmdline_parser_test.cc
+++ b/cmdline/cmdline_parser_test.cc
@@ -369,7 +369,7 @@
*/
TEST_F(CmdlineParserTest, TestJdwpProviderEmpty) {
{
- EXPECT_SINGLE_PARSE_DEFAULT_VALUE(JdwpProvider::kInternal, "", M::JdwpProvider);
+ EXPECT_SINGLE_PARSE_DEFAULT_VALUE(JdwpProvider::kNone, "", M::JdwpProvider);
}
} // TEST_F
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 6d065d6..3e7133e 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1253,7 +1253,20 @@
jdwp_provider_ = runtime_options.GetOrDefault(Opt::JdwpProvider);
switch (jdwp_provider_) {
case JdwpProvider::kNone: {
- LOG(WARNING) << "Disabling all JDWP support.";
+ LOG(INFO) << "Disabling all JDWP support.";
+ if (!jdwp_options_.empty()) {
+ bool has_transport = jdwp_options_.find("transport") != std::string::npos;
+ const char* transport_internal = !has_transport ? "transport=dt_android_adb," : "";
+ std::string adb_connection_args =
+ std::string(" -XjdwpProvider:adbconnection -XjdwpOptions:") + jdwp_options_;
+ LOG(WARNING) << "Jdwp options given when jdwp is disabled! You probably want to enable "
+ << "jdwp with one of:" << std::endl
+ << " -XjdwpProvider:internal "
+ << "-XjdwpOptions:" << transport_internal << jdwp_options_ << std::endl
+ << " -Xplugin:libopenjdkjvmti" << (kIsDebugBuild ? "d" : "") << ".so "
+ << "-agentpath:libjdwp.so=" << jdwp_options_ << std::endl
+ << (has_transport ? "" : adb_connection_args);
+ }
break;
}
case JdwpProvider::kInternal: {
diff --git a/runtime/runtime_options.def b/runtime/runtime_options.def
index 6e1a68b..e78d952 100644
--- a/runtime/runtime_options.def
+++ b/runtime/runtime_options.def
@@ -44,7 +44,7 @@
RUNTIME_OPTIONS_KEY (Unit, CheckJni)
RUNTIME_OPTIONS_KEY (Unit, JniOptsForceCopy)
RUNTIME_OPTIONS_KEY (std::string, JdwpOptions, "")
-RUNTIME_OPTIONS_KEY (JdwpProvider, JdwpProvider, JdwpProvider::kInternal)
+RUNTIME_OPTIONS_KEY (JdwpProvider, JdwpProvider, JdwpProvider::kNone)
RUNTIME_OPTIONS_KEY (MemoryKiB, MemoryMaximumSize, gc::Heap::kDefaultMaximumSize) // -Xmx
RUNTIME_OPTIONS_KEY (MemoryKiB, MemoryInitialSize, gc::Heap::kDefaultInitialSize) // -Xms
RUNTIME_OPTIONS_KEY (MemoryKiB, HeapGrowthLimit) // Default is 0 for unlimited
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index 5e40b86..ca24471 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -436,7 +436,13 @@
msg " adb forward tcp:$PORT tcp:$PORT"
fi
msg " jdb -attach localhost:$PORT"
- DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
+ if [ "$USE_JVM" = "n" ]; then
+ # TODO We should switch over to using the jvmti agent by default.
+ # Need to tell the runtime to enable the internal jdwp implementation.
+ DEBUGGER_OPTS="-XjdwpOptions:transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
+ else
+ DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
+ fi
elif [ "$DEBUGGER" = "agent" ]; then
PORT=12345
# TODO Support ddms connection and support target.