From 4260e788611f0d37542c313b5a271a1f6c9189e4 Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Sun, 22 Mar 2020 20:59:48 +0100 Subject: [PATCH] android: add gdb.sh This script setup a dummy android native app folder and call ndk-gdb from it. It needs a modification in ANDROID_NDK since ndk-gdb may attach to the wrong pid, cf. comments in the script. --- android/gdb.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 android/gdb.sh diff --git a/android/gdb.sh b/android/gdb.sh new file mode 100755 index 000000000..5e576c7ff --- /dev/null +++ b/android/gdb.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# This script need the following modification in ANDROID_NDK in order to attach +# to the good :main pid +#--- a/prebuilt/linux-x86_64/bin/ndk-gdb.py +#+++ b/prebuilt/linux-x86_64/bin/ndk-gdb.py +#@@ -669,7 +669,7 @@ +# log("Sleeping for {} seconds.".format(args.delay)) +# time.sleep(args.delay) +# +#- pids = gdbrunner.get_pids(device, pkg_name) +#+ pids = gdbrunner.get_pids(device, pkg_name + ":main") +# if len(pids) == 0: +# error("Failed to find running process '{}'".format(pkg_name)) +# if len(pids) > 1: + +SCRIPT_PATH=$(dirname $0) +BUILD_PATH="`pwd`" +TMP_PATH="$BUILD_PATH/gdb" +NDK_GDB_ARGS="--force" +ANDROID_NDK=$1 + +if [ ! -f $ANDROID_NDK/source.properties ];then + echo "usage: $0 ANDROID_NDK" + exit 1 +fi + +if [ ! -f $BUILD_PATH/libmpd.so ];then + echo "This script need to be executed from the android build directory" + exit 1 +fi + +rm -rf "$TMP_PATH" +mkdir -p "$TMP_PATH" + +ANDROID_MANIFEST="$SCRIPT_PATH/AndroidManifest.xml" +ABI=`ls "$BUILD_PATH/android/apk/apk/lib" --sort=time | head -n 1` + +if [ ! -f "$ANDROID_MANIFEST" -o "$ABI" = "" ]; then + echo "Invalid manifest/ABI, did you try building first ?" + exit 1 +fi + +mkdir -p "$TMP_PATH"/jni +touch "$TMP_PATH"/jni/Android.mk +echo "APP_ABI := $ABI" > "$TMP_PATH"/jni/Application.mk + +DEST=obj/local/$ABI +mkdir -p "$TMP_PATH/$DEST" + +cp "$BUILD_PATH/libmpd.so" "$TMP_PATH/$DEST" +cp "$ANDROID_MANIFEST" "$TMP_PATH" + +(cd "$TMP_PATH" && bash $ANDROID_NDK/ndk-gdb $NDK_GDB_ARGS)