[Android] [PATCH 2/2] gdb.sh: debug an apk

Thomas Guillem thomas at gllm.fr
Tue Apr 7 17:57:55 CEST 2015


"./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
---
 compile-libvlc.sh | 11 +++++++++++
 gdb.sh            | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/compile-libvlc.sh b/compile-libvlc.sh
index 48cdb13..b5bd816 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..003c033 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,60 @@ 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
+
+    if [ -z "$DBGFILE_PATH" ];then
+        version=$($aapt l -a "$APK_PATH"|grep versionName|cut -d\" -f 2)
+        dbgfile_path="$SCRIPT_PATH/.dbg/$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")
+    arch=$(echo $lib_path|cut -d"/" -f 2)
+
+    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 +81,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"
-- 
2.1.3



More information about the Android mailing list