#!/bin/bash # Script to start gdbserver on Android device and attach to retroshare-service # # Copyright (C) 2020 Gioacchino Mazzurco # Copyright (C) 2020 AsociaciĆ³n Civil Altermundi # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU Affero General Public License as published by the # Free Software Foundation, version 3. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License along # with this program. If not, see <<"ASCIIDOC" Start gdbserver on Android device and attach it to the retroshare service process Inspired by: https://fw4spl-org.github.io/fw4spl-blog/2015/07/27/Native-debugging-on-Android-with-QtCreator.html ASCIIDOC ## Define default value for variable, take two arguments, $1 variable name, ## $2 default variable value, if the variable is not already define define it ## with default value. function define_default_value() { VAR_NAME="${1}" DEFAULT_VALUE="${2}" [ -z "${!VAR_NAME}" ] && export ${VAR_NAME}="${DEFAULT_VALUE}" } define_default_value ANDROID_APK_PACKAGE "org.retroshare.service" define_default_value ANDROID_PROCESS_NAME "org.retroshare.service:rs" define_default_value ANDROID_SERIAL "$(adb devices | head -n 2 | tail -n 1 | awk '{print $1}')" define_default_value GDB_SERVER_PORT 5039 adb_shell() { adb shell run-as ${ANDROID_APK_PACKAGE} $@ } ## If not passed as environement variable try to determine gdbserver path ## shipped withing Android package [ -z "${LIB_GDB_SERVER_PATH}" ] && { for mUsualPath in \ "/data/data/${ANDROID_APK_PACKAGE}/lib/libgdbserver.so" \ "/data/app/${ANDROID_APK_PACKAGE}"*"/lib/arm64/libgdbserver.so" do adb_shell ls "${mUsualPath}" && export LIB_GDB_SERVER_PATH="${mUsualPath}" && break done } [ -z "${LIB_GDB_SERVER_PATH}" ] && { cat <