[Android] gdb.sh: debug an apk
Thomas Guillem
git at videolan.org
Wed Apr 8 09:35:46 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Apr 7 17:55:28 2015 +0200| [dca7e6b9bbf26cab08278780f3fad8a52b0424d7] | committer: Thomas Guillem
gdb.sh: debug an apk
"./gdb.sh --apk <file.apk> --dbg-file <file.so.dbg>" to run gdb on a specified
lib from the apk using a file containing the debugging info
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=dca7e6b9bbf26cab08278780f3fad8a52b0424d7
---
compile-libvlc.sh | 11 +++++++++++
gdb.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/compile-libvlc.sh b/compile-libvlc.sh
index 0d92167..0a73299 100755
--- a/compile-libvlc.sh
+++ b/compile-libvlc.sh
@@ -17,6 +17,7 @@ checkfail()
#############
RELEASE=0
+GDB_FILE=""
while [ $# -gt 0 ]; do
case $1 in
help|--help)
@@ -34,6 +35,10 @@ while [ $# -gt 0 ]; do
release|--release)
RELEASE=1
;;
+ --gdb)
+ GDB_FILE="$2"
+ shift
+ ;;
esac
shift
done
@@ -295,6 +300,12 @@ SRC_DIR=$PWD
# stub libraries
NDK_TOOLCHAIN_PATH=`echo ${ANDROID_NDK}/toolchains/${PATH_HOST}-${GCCVER}/prebuilt/\`uname|tr A-Z a-z\`-*/bin`
CROSS_COMPILE=${NDK_TOOLCHAIN_PATH}/${TARGET_TUPLE}-
+
+if [ ! -z "$GDB_FILE" ];then
+ ${CROSS_COMPILE}gdb "$GDB_FILE"
+ exit 0
+fi
+
export PATH=${NDK_TOOLCHAIN_PATH}:${PATH}
###############
diff --git a/gdb.sh b/gdb.sh
index b72b08c..ad08b39 100755
--- a/gdb.sh
+++ b/gdb.sh
@@ -10,6 +10,7 @@ while [ $# -gt 0 ]; do
case $1 in
help|--help|-h)
echo "Use -f to set the flavour. Default is vanillaARMv7."
+ echo "Use --apk-file <file.apk> [--dbg-file <file.so.dbg>] to debug an apk via a file containing the debugging info"
exit 0
;;
-f)
@@ -19,10 +20,61 @@ while [ $# -gt 0 ]; do
-s)
NDK_GDB_ARGS="$NDK_GDB_ARGS --nowait --start"
;;
+ --apk)
+ APK_PATH=$2
+ shift
+ ;;
+ --dbg-file)
+ DBGFILE_PATH=$2
+ shift
+ ;;
esac
shift
done
+rm -rf "$TMP_PATH"
+mkdir -p "$TMP_PATH"
+
+if [ ! -z "$APK_PATH" ]; then
+ if [ ! -f "$APK_PATH" ];then
+ echo "invalid --apk"
+ exit 1
+ fi
+
+ aapt=$(ls -1 --sort=time $ANDROID_SDK/build-tools/*/aapt|head -n 1)
+ if [ -z "$aapt" ];then
+ echo "aapt not found in \$ANDROID_SDK"
+ exit 1
+ fi
+
+ arch=$($aapt l -a "$APK_PATH"|grep "libvlcjni.so"|cut -d"/" -f 2)
+
+ if [ -z "$DBGFILE_PATH" ];then
+ version=$($aapt l -a "$APK_PATH"|grep versionName|cut -d\" -f 2)
+ dbgfile_path="$SCRIPT_PATH/.dbg/$arch/$version/libvlcjni.so.dbg"
+ else
+ dbgfile_path="$DBGFILE_PATH"
+ fi
+ if [ ! -f "$dbgfile_path" ];then
+ echo "invalid --dbg-file"
+ exit 1
+ fi
+
+ lib_name=$(basename "$dbgfile_path")
+ lib_name=${lib_name%.dbg}
+ lib_path=$($aapt l -a "$APK_PATH"|grep "$lib_name")
+
+ unzip -p "$APK_PATH" $lib_path > "$TMP_PATH"/$lib_name
+ cp $dbgfile_path "$TMP_PATH"
+
+ echo ""
+ echo "\"list *0x<pc_address>\" to know where the specified apk crashed"
+ echo ""
+
+ ./compile-libvlc.sh -a $arch --gdb "$TMP_PATH"/$lib_name
+ exit 0
+fi
+
ANDROID_MANIFEST="$SCRIPT_PATH"/vlc-android/build/intermediates/manifests/full/$FLAVOUR/debug/AndroidManifest.xml
if [ ! -f "$ANDROID_MANIFEST" ]; then
@@ -30,7 +82,6 @@ if [ ! -f "$ANDROID_MANIFEST" ]; then
exit 1
fi
-rm -rf "$TMP_PATH"
mkdir -p "$TMP_PATH"/jni
cp -r "$SCRIPT_PATH"/libvlc/jni/libs "$TMP_PATH"
More information about the Android
mailing list