Add some helpful features to jdwp test runners

Add --verbose support to run-libjdwp-tests.sh. This makes it use the
libjdwp logging on the debuggee with by default log level 0xC0. This
can be changed using --verbose-level and --verbose-all.

Add an --instant-jit flag to both runners. This forces the debuggee to
run with -Xjitthreshold:0.

Test: manual
Change-Id: Iff9884b0cfbc5d32ff40c5c2d8f48b7876944509
diff --git a/tools/run-jdwp-tests.sh b/tools/run-jdwp-tests.sh
index eb33da2..a435f2e 100755
--- a/tools/run-jdwp-tests.sh
+++ b/tools/run-jdwp-tests.sh
@@ -68,6 +68,7 @@
 mode="target"
 # Use JIT compiling by default.
 use_jit=true
+instant_jit=false
 variant_cmdline_parameter="--variant=X32"
 dump_command="/bin/true"
 # Timeout of JDWP test in ms.
@@ -129,6 +130,11 @@
   elif [[ $1 == -Ximage:* ]]; then
     image="$1"
     shift
+  elif [[ "$1" == "--instant-jit" ]]; then
+    instant_jit=true
+    # Remove the --instant-jit from the arguments.
+    args=${args/$1}
+    shift
   elif [[ "$1" == "--no-jit" ]]; then
     use_jit=false
     # Remove the --no-jit from the arguments.
@@ -310,6 +316,10 @@
   debuggee_args="$debuggee_args -Xcompiler-option --compiler-filter=quicken"
 fi
 
+if $instant_jit; then
+  debuggee_args="$debuggee_args -Xjitthreshold:0"
+fi
+
 if [[ $mode != "ri" ]]; then
   vm_args="$vm_args --vm-arg -Xusejit:$use_jit"
   debuggee_args="$debuggee_args -Xusejit:$use_jit"
diff --git a/tools/run-libjdwp-tests.sh b/tools/run-libjdwp-tests.sh
index e116fac..bd05251 100755
--- a/tools/run-libjdwp-tests.sh
+++ b/tools/run-libjdwp-tests.sh
@@ -24,13 +24,18 @@
   exit 2
 fi
 
-args=("$@")
+declare -a args=("$@")
 debug="no"
 has_variant="no"
 has_mode="no"
 mode="target"
 has_timeout="no"
+has_verbose="no"
+# The bitmap of log messages in libjdwp. See list in the help message for more
+# info on what these are. The default is 'errors | callbacks'
+verbose_level=0xC0
 
+arg_idx=0
 while true; do
   if [[ $1 == "--debug" ]]; then
     debug="yes"
@@ -38,6 +43,7 @@
   elif [[ $1 == --test-timeout-ms ]]; then
     has_timeout="yes"
     shift
+    arg_idx=$((arg_idx + 1))
     shift
   elif [[ "$1" == "--mode=jvm" ]]; then
     has_mode="yes"
@@ -47,6 +53,22 @@
     has_mode="yes"
     mode="host"
     shift
+  elif [[ $1 == --verbose-all ]]; then
+    has_verbose="yes"
+    verbose_level=0xFFF
+    unset args[arg_idx]
+    shift
+  elif [[ $1 == --verbose ]]; then
+    has_verbose="yes"
+    shift
+  elif [[ $1 == --verbose-level ]]; then
+    shift
+    verbose_level=$1
+    # remove both the --verbose-level and the argument.
+    unset args[arg_idx]
+    arg_idx=$((arg_idx + 1))
+    unset args[arg_idx]
+    shift
   elif [[ $1 == --variant=* ]]; then
     has_variant="yes"
     shift
@@ -55,6 +77,7 @@
   else
     shift
   fi
+  arg_idx=$((arg_idx + 1))
 done
 
 if [[ "$has_mode" = "no" ]];  then
@@ -68,7 +91,17 @@
 if [[ "$has_timeout" = "no" ]]; then
   # Double the timeout to 20 seconds
   args+=(--test-timeout-ms)
-  args+=(20000)
+  if [[ "$has_verbose" = "no" ]]; then
+    args+=(20000)
+  else
+    # Even more time if verbose is set since those can be quite heavy.
+    args+=(200000)
+  fi
+fi
+
+if [[ "$has_verbose" = "yes" ]]; then
+  args+=(--vm-arg)
+  args+=(-Djpda.settings.debuggeeAgentExtraOptions=directlog=y,logfile=/proc/self/fd/2,logflags=$verbose_level)
 fi
 
 # We don't use full paths since it is difficult to determine them for device