aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2010-09-14 15:10:38 +0200
committerDavid 'Digit' Turner <digit@google.com>2010-09-14 21:11:54 +0200
commitfd204377de03a20556b38acf0dc2bdb195729343 (patch)
tree571b6e69d92b3ecb7ab67768f0c721da63975411
parent7daefc38f01900f8a903d9955f7f8d6262d88f32 (diff)
downloadndk-fd204377de03a20556b38acf0dc2bdb195729343.tar.gz
Add easy native debugging support through NDK_DEBUG=1
"ndk-build NDK_DEBUG=1" will force the build of a debuggable application. This really copies gdbserver to the proper location, as if android:debuggable was set to "true" in the app's manifest. The value of NDK_DEBUG can be 0, 1, true or false, and will override the content of the manifest. The main benefit from this change is that you don't have to edit your manifest file just to rebuilt Change-Id: I3fafb620189ac53a72b492c963832dd0c7f8b7d7
-rw-r--r--.gitignore8
-rw-r--r--build/core/add-application.mk55
-rw-r--r--build/core/definitions.mk1
-rw-r--r--docs/CHANGES.TXT7
-rw-r--r--docs/NDK-BUILD.TXT2
-rwxr-xr-xndk-gdb55
6 files changed, 89 insertions, 39 deletions
diff --git a/.gitignore b/.gitignore
index f7b9ce038..37540a60f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,10 +4,6 @@
Thumbs.db
local.properties
build.xml
-samples/*
-build/platforms/*
-samples/*/libs/
-samples/*/bin/
-samples/*/obj/
-samples/*/gen/
+samples/
+platforms/
build/prebuilt/
diff --git a/build/core/add-application.mk b/build/core/add-application.mk
index 3e14f757c..6fd86c217 100644
--- a/build/core/add-application.mk
+++ b/build/core/add-application.mk
@@ -28,6 +28,24 @@ $(call ndk_log,Parsing $(_application_mk))
$(call clear-vars, $(NDK_APP_VARS))
+# Check that NDK_DEBUG is properly defined. If it is
+# the only valid states are: undefined, 0, 1, false and true
+#
+# We set APP_DEBUG to <undefined>, 'true' or 'false'.
+#
+APP_DEBUG := $(strip $(NDK_DEBUG))
+ifeq ($(APP_DEBUG),0)
+ APP_DEBUG:= false
+endif
+ifeq ($(APP_DEBUG),1)
+ APP_DEBUG := true
+endif
+ifdef APP_DEBUG
+ ifneq (,$(filter-out true false,$(APP_DEBUG)))
+ $(call __ndk_warning,NDK_DEBUG is defined to the unsupported value '$(NDK_DEBUG)', will be ignored!)
+ endif
+endif
+
include $(_application_mk)
$(call check-required-vars,$(NDK_APP_VARS_REQUIRED),$(_application_mk))
@@ -111,20 +129,33 @@ else
$(call ndk_log, Defaulted to APP_BUILD_SCRIPT=$(APP_BUILD_SCRIPT))
endif
-# Extract the debuggable flag from the application's manifest
-# NOTE: To make unit-testing simpler, handle the case where there is no manifest.
+# Determine whether the application should be debuggable.
+# - If APP_DEBUG is set to 'true', then it always should.
+# - If APP_DEBUG is set to 'false', then it never should
+# - Otherwise, extract the android:debuggable attribute from the manifest.
#
-APP_DEBUGGABLE := false
-APP_MANIFEST := $(strip $(wildcard $(APP_PROJECT_PATH)/AndroidManifest.xml))
-ifdef APP_MANIFEST
+ifdef APP_DEBUG
+ APP_DEBUGGABLE := $(APP_DEBUG)
+ ifdef NDK_LOG
+ ifeq ($(APP_DEBUG),true)
+ $(call ndk_log,Application '$(_app)' forced debuggable through NDK_DEBUG)
+ else
+ $(call ndk_log,Application '$(_app)' forced *not* debuggable through NDK_DEBUG)
+ endif
+ endif
+else
+ # NOTE: To make unit-testing simpler, handle the case where there is no manifest.
+ APP_DEBUGGABLE := false
+ APP_MANIFEST := $(strip $(wildcard $(APP_PROJECT_PATH)/AndroidManifest.xml))
+ ifdef APP_MANIFEST
APP_DEBUGGABLE := $(shell $(HOST_AWK) -f $(BUILD_AWK)/extract-debuggable.awk $(APP_MANIFEST))
-endif
-
-ifdef NDK_LOG
- ifeq ($(APP_DEBUGGABLE),true)
- $(call ndk_log,Application '$(_app)' *is* debuggable)
- else
- $(call ndk_log,Application '$(_app)' is not debuggable)
+ endif
+ ifdef NDK_LOG
+ ifeq ($(APP_DEBUGGABLE),true)
+ $(call ndk_log,Application '$(_app)' *is* debuggable)
+ else
+ $(call ndk_log,Application '$(_app)' is not debuggable)
+ endif
endif
endif
diff --git a/build/core/definitions.mk b/build/core/definitions.mk
index d749dd987..eb898652b 100644
--- a/build/core/definitions.mk
+++ b/build/core/definitions.mk
@@ -749,6 +749,7 @@ NDK_APP_VARS_OPTIONAL := APP_OPTIM APP_CPPFLAGS APP_CFLAGS APP_CXXFLAGS \
# or defined by the build scripts.
NDK_APP_VARS := $(NDK_APP_VARS_REQUIRED) \
$(NDK_APP_VARS_OPTIONAL) \
+ APP_DEBUG \
APP_DEBUGGABLE \
APP_MANIFEST
diff --git a/docs/CHANGES.TXT b/docs/CHANGES.TXT
index f392084eb..8867bccd3 100644
--- a/docs/CHANGES.TXT
+++ b/docs/CHANGES.TXT
@@ -61,6 +61,13 @@ IMPORTANT CHANGES:
LOCAL_FILTER_ASM in docs/ANDROID-MK.TXT for more details. This can be useful
for certain kinds of obfuscation tasks.
+- Easier native debugging support by using 'ndk-build NDK_DEBUG=1'. The main
+ idea is that if NDK_DEBUG is defined, its value overrides the value found
+ in the application's android:debuggable manifest attribute.
+
+ Valid values for NDK_DEBUG are '1', '0', 'true' or 'false' (anything else
+ will be ignored).
+
OTHER FIXES & CHANGES:
- The path to system headers is now included last in the compilation command
diff --git a/docs/NDK-BUILD.TXT b/docs/NDK-BUILD.TXT
index 445d1e65f..62a48534a 100644
--- a/docs/NDK-BUILD.TXT
+++ b/docs/NDK-BUILD.TXT
@@ -26,6 +26,8 @@ command that runs the NDK build scripts. Notable uses include:
ndk-build --> rebuild required machine code.
ndk-build clean --> clean all generated binaries.
+ ndk-build NDK_DEBUG=1 --> generate debuggable native code.
+
ndk-build V=1 --> launch build, displaying build commands.
ndk-build -B --> force a complete rebuild.
diff --git a/ndk-gdb b/ndk-gdb
index 4f9999669..6019a0862 100755
--- a/ndk-gdb
+++ b/ndk-gdb
@@ -330,15 +330,6 @@ if [ "$OPTION_LAUNCH_LIST" = "yes" ] ; then
exit 0
fi
-# Check that the application is debuggable, or nothing will work
-DEBUGGABLE=`run_awk_manifest_script extract-debuggable.awk`
-log "Found debuggable flag: $DEBUGGABLE"
-if [ $? != 0 -o "$DEBUGGABLE" != "true" ] ; then
- echo "ERROR: Package $PACKAGE_NAME is not debuggable ! Please fix your manifest,"
- echo " rebuild your application and re-install it to fix this."
- exit 1
-fi
-
APP_ABIS=`get_build_var APP_ABI`
log "ABIs targetted by application: $APP_ABIS"
@@ -356,14 +347,14 @@ fi
#
API_LEVEL=`adb_shell getprop ro.build.version.sdk`
if [ $? != 0 -o -z "$API_LEVEL" ] ; then
- echo "ERROR: Could not find target device's supported API level !"
+ echo "ERROR: Could not find target device's supported API level!"
echo "ndk-gdb will only work if your device is running Android 2.2 or higher."
exit 1
fi
log "Device API Level: $API_LEVEL"
if [ "$API_LEVEL" -lt "8" ] ; then
echo "ERROR: ndk-gdb requires a target device running Android 2.2 (API level 8) or higher."
- echo "The target device is running API level $API_LEVEL !"
+ echo "The target device is running API level $API_LEVEL!"
exit 1
fi
@@ -404,15 +395,37 @@ if [ "$COMPAT_ABI" = none ] ; then
fi
log "Compatible device ABI: $COMPAT_ABI"
-# Let's check that the user didn't change the debuggable flag in
-# the manifest without calling ndk-build afterwards.
-if [ ! -f $PROJECT/libs/$COMPAT_ABI/gdbserver ] ; then
- echo "ERROR: Could not find gdbserver binary under $PROJECT/libs/$COMPAT_ABI"
- echo " This usually means you modified your AndroidManifest.xml to set"
- echo " the android:debuggable flag to 'true' but did not rebuild the"
- echo " native binaries. Please call 'ndk-build' to do so,"
- echo " *then* re-install to the device !"
- exit 1
+# Check that the application is debuggable, or nothing will work
+DEBUGGABLE=`run_awk_manifest_script extract-debuggable.awk`
+log "Found debuggable flag: $DEBUGGABLE"
+if [ $? != 0 -o "$DEBUGGABLE" != "true" ] ; then
+ # If gdbserver exists, then we built with 'ndk-build NDK_DEBUG=1' and it's
+ # ok to not have android:debuggable set to true in the original manifest.
+ # However, if this is not the case, then complain!!
+ if [ -f $PROJECT/libs/$COMPAT_ABI/gdbserver ] ; then
+ log "Found gdbserver under libs/$COMPAT_ABI, assuming app was built with NDK_DEBUG=1"
+ else
+ echo "ERROR: Package $PACKAGE_NAME is not debuggable ! You can fix that in two ways:"
+ echo ""
+ echo " - Rebuilt with the NDK_DEBUG=1 option when calling 'ndk-build'."
+ echo ""
+ echo " - Modify your manifest to set android:debuggable attribute to \"true\","
+ echo " then rebuild normally."
+ echo ""
+ echo "After one of these, re-install to the device!"
+ exit 1
+ fi
+else
+ # DEBUGGABLE is true in the manifest. Let's check that the user didn't change the
+ # debuggable flag in the manifest without calling ndk-build afterwards.
+ if [ ! -f $PROJECT/libs/$COMPAT_ABI/gdbserver ] ; then
+ echo "ERROR: Could not find gdbserver binary under $PROJECT/libs/$COMPAT_ABI"
+ echo " This usually means you modified your AndroidManifest.xml to set"
+ echo " the android:debuggable flag to 'true' but did not rebuild the"
+ echo " native binaries. Please call 'ndk-build' to do so,"
+ echo " *then* re-install to the device!"
+ exit 1
+ fi
fi
# Let's check that 'gdbserver' is properly installed on the device too. If this
@@ -422,7 +435,7 @@ DEVICE_GDBSERVER=`adb_shell ls /data/data/$PACKAGE_NAME/lib/gdbserver`
log "Found device gdbserver: $DEVICE_GDBSERVER"
if pattern_match "No such file or directory" "$DEVICE_GDBSERVER" ] ; then
echo "ERROR: Non-debuggable application installed on the target device."
- echo " Please re-install the debuggable version !"
+ echo " Please re-install the debuggable version!"
exit 1
fi