Add options for building/testing with coverage.

    acov --clean
    mm -B NATIVE_COVERAGE=true ART_COVERAGE=true test-art-host
    acov --host

-B is needed because you need to be sure you rebuild *all* of ART with
coverage.

Change-Id: Ib94ef610bd1b44dc45624877710ed733051b7a50
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 1f040d6..0f756ef 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -20,6 +20,21 @@
 ART_TARGET_SUPPORTED_ARCH := arm arm64 mips mips64 x86 x86_64
 ART_HOST_SUPPORTED_ARCH := x86 x86_64
 
+ART_COVERAGE := false
+
+ifeq ($(ART_COVERAGE),true)
+# https://gcc.gnu.org/onlinedocs/gcc/Cross-profiling.html
+GCOV_PREFIX := /data/local/tmp/gcov
+# GCOV_PREFIX_STRIP is an integer that defines how many levels should be
+# stripped off the beginning of the path. We want the paths in $GCOV_PREFIX to
+# be relative to $ANDROID_BUILD_TOP so we can just adb pull from the top and not
+# have to worry about placing things ourselves.
+GCOV_PREFIX_STRIP := $(shell echo $(ANDROID_BUILD_TOP) | grep -o / | wc -l)
+GCOV_ENV := GCOV_PREFIX=$(GCOV_PREFIX) GCOV_PREFIX_STRIP=$(GCOV_PREFIX_STRIP)
+else
+GCOV_ENV :=
+endif
+
 ifeq (,$(filter $(TARGET_ARCH),$(ART_TARGET_SUPPORTED_ARCH)))
 $(warning unsupported TARGET_ARCH=$(TARGET_ARCH))
 endif
diff --git a/build/Android.common_build.mk b/build/Android.common_build.mk
index ad4c987..3000cdf 100644
--- a/build/Android.common_build.mk
+++ b/build/Android.common_build.mk
@@ -238,10 +238,14 @@
 
 ifeq ($(HOST_OS),linux)
   # Larger frame-size for host clang builds today
-  ifndef SANITIZE_HOST
-    art_host_non_debug_cflags += -Wframe-larger-than=2700
+  ifneq ($(ART_COVERAGE),true)
+    ifneq ($(NATIVE_COVERAGE),true)
+      ifndef SANITIZE_HOST
+        art_host_non_debug_cflags += -Wframe-larger-than=2700
+      endif
+      art_target_non_debug_cflags += -Wframe-larger-than=1728
+    endif
   endif
-  art_target_non_debug_cflags += -Wframe-larger-than=1728
 endif
 
 ifndef LIBART_IMG_HOST_BASE_ADDRESS
diff --git a/build/Android.executable.mk b/build/Android.executable.mk
index 4bb2cb1..dfea6e1 100644
--- a/build/Android.executable.mk
+++ b/build/Android.executable.mk
@@ -129,6 +129,8 @@
     endif
   endif
 
+  LOCAL_NATIVE_COVERAGE := $(ART_COVERAGE)
+
   ifeq ($$(art_target_or_host),target)
     include $(BUILD_EXECUTABLE)
     ART_TARGET_EXECUTABLES := $(ART_TARGET_EXECUTABLES) $$(foreach name,$$(art_out_binary_name),$(TARGET_OUT_EXECUTABLES)/$$(name))
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index a5cfcba..b4eb0c0 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -275,7 +275,7 @@
 	$(hide) adb shell rm $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID
 	$(hide) adb shell chmod 755 $(ART_TARGET_NATIVETEST_DIR)/$(TARGET_$(2)ARCH)/$(1)
 	$(hide) $$(call ART_TEST_SKIP,$$@) && \
-	  (adb shell "LD_LIBRARY_PATH=$(3) ANDROID_ROOT=$(ART_GTEST_TARGET_ANDROID_ROOT) \
+	  (adb shell "$(GCOV_ENV) LD_LIBRARY_PATH=$(3) ANDROID_ROOT=$(ART_GTEST_TARGET_ANDROID_ROOT) \
 	    $(ART_TARGET_NATIVETEST_DIR)/$(TARGET_$(2)ARCH)/$(1) && touch $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID" \
 	  && (adb pull $(ART_TARGET_TEST_DIR)/$(TARGET_$(2)ARCH)/$$@-$$$$PPID /tmp/ \
 	      && $$(call ART_TEST_PASSED,$$@)) \