Merge "Rename libnativebridge-dummy-headers to libnativebridge-headers"
diff --git a/build/art.go b/build/art.go
index 4b63829..4db8da2 100644
--- a/build/art.go
+++ b/build/art.go
@@ -253,8 +253,10 @@
 	ctx.AppendProperties(p)
 }
 
+var testMapKey = android.NewOnceKey("artTests")
+
 func testMap(config android.Config) map[string][]string {
-	return config.Once("artTests", func() interface{} {
+	return config.Once(testMapKey, func() interface{} {
 		return make(map[string][]string)
 	}).(map[string][]string)
 }
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index 2910920..9d79a0b 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -30,7 +30,8 @@
 ANDROID_FLAGS=""
 GDB=""
 GDB_ARGS=""
-GDB_SERVER="gdbserver"
+GDBSERVER_DEVICE="gdbserver"
+GDBSERVER_HOST="gdbserver"
 HAVE_IMAGE="y"
 HOST="n"
 BIONIC="n"
@@ -60,6 +61,8 @@
   TIME_OUT_VALUE=1200  # 20 minutes.
 fi
 USE_GDB="n"
+USE_GDBSERVER="n"
+GDBSERVER_PORT=":5039"
 USE_JVM="n"
 USE_JVMTI="n"
 VERIFY="y" # y=yes,n=no,s=softfail
@@ -267,6 +270,23 @@
         DEBUGGER="y"
         TIME_OUT="n"
         shift
+    elif [ "x$1" = "x--gdbserver-port" ]; then
+        shift
+        GDBSERVER_PORT=$1
+        shift
+    elif [ "x$1" = "x--gdbserver-bin" ]; then
+        shift
+        GDBSERVER_HOST=$1
+        GDBSERVER_DEVICE=$1
+        shift
+    elif [ "x$1" = "x--gdbserver" ]; then
+        USE_GDBSERVER="y"
+        DEV_MODE="y"
+        TIME_OUT="n"
+        HOST="y"
+        ANDROID_ROOT="${ANDROID_HOST_OUT}"
+        ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
+        shift
     elif [ "x$1" = "x--gdb" ]; then
         USE_GDB="y"
         DEV_MODE="y"
@@ -342,7 +362,7 @@
         break
     elif [ "x$1" = "x--64" ]; then
         ISA="x86_64"
-        GDB_SERVER="gdbserver64"
+        GDBSERVER_DEVICE="gdbserver64"
         DALVIKVM="dalvikvm64"
         LIBRARY_DIRECTORY="lib64"
         TEST_DIRECTORY="nativetest64"
@@ -611,8 +631,11 @@
 
 
 if [ "$USE_GDB" = "y" ]; then
-  if [ "$HOST" = "n" ]; then
-    GDB="$GDB_SERVER :5039"
+  if [ "$USE_GDBSERVER" = "y" ]; then
+    echo "Cannot pass both --gdb and --gdbserver at the same time!" >&2
+    exit 1
+  elif [ "$HOST" = "n" ]; then
+    GDB="$GDBSERVER_DEVICE $GDBSERVER_PORT"
   else
     if [ `uname` = "Darwin" ]; then
         GDB=lldb
@@ -625,6 +648,12 @@
         # gdbargs="--annotate=3 $gdbargs"
     fi
   fi
+elif [ "$USE_GDBSERVER" = "y" ]; then
+  if [ "$HOST" = "n" ]; then
+    echo "Cannot use --gdbserver in non-host configs" >&2
+    exit 1
+  fi
+  GDB="$GDBSERVER_HOST $GDBSERVER_PORT"
 fi
 
 if [ "$INTERPRETER" = "y" ]; then
@@ -1084,7 +1113,10 @@
 
     if [ "$USE_GDB" = "y" ]; then
       # When running under gdb, we cannot do piping and grepping...
-      echo "Run 'gdbclient.py -p <pid printed below>' to debug."
+      $cmdline "$@"
+    elif [ "$USE_GDBSERVER" = "y" ]; then
+      echo "Connect to $GDBSERVER_PORT"
+      # When running under gdb, we cannot do piping and grepping...
       $cmdline "$@"
     else
       if [ "$TIME_OUT" != "gdb" ]; then
diff --git a/test/run-test b/test/run-test
index 67bcce7..5f78d17 100755
--- a/test/run-test
+++ b/test/run-test
@@ -306,6 +306,18 @@
         run_args="${run_args} --gdb"
         dev_mode="yes"
         shift
+    elif [ "x$1" = "x--gdbserver-bin" ]; then
+        shift
+        run_args="${run_args} --gdbserver-bin $1"
+        shift
+    elif [ "x$1" = "x--gdbserver-port" ]; then
+        shift
+        run_args="${run_args} --gdbserver-port $1"
+        shift
+    elif [ "x$1" = "x--gdbserver" ]; then
+        run_args="${run_args} --gdbserver"
+        dev_mode="yes"
+        shift
     elif [ "x$1" = "x--strace" ]; then
         strace="yes"
         run_args="${run_args} --timeout 1800 --invoke-with strace --invoke-with -o --invoke-with $tmp_dir/$strace_output"
@@ -716,7 +728,12 @@
         echo "    --with-agent <agent>  Run the test with the given agent loaded with -agentpath:"
         echo "    --debuggable          Whether to compile Java code for a debugger."
         echo "    --gdb                 Run under gdb; incompatible with some tests."
-        echo "    --gdb-arg             Pass an option to gdb."
+        echo "    --gdbserver           Start gdbserver (defaults to port :5039)."
+        echo "    --gdbserver-port <port>"
+        echo "                          Start gdbserver with the given COMM (see man gdbserver)."
+        echo "    --gdbserver-bin <binary>"
+        echo "                          Use the given binary as gdbserver."
+        echo "    --gdb-arg             Pass an option to gdb or gdbserver."
         echo "    --build-only          Build test files only (off by default)."
         echo "    --interpreter         Enable interpreter only mode (off by default)."
         echo "    --jit                 Enable jit (off by default)."