summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gdbclient35
1 files changed, 21 insertions, 14 deletions
diff --git a/scripts/gdbclient b/scripts/gdbclient
index 19a6949fb..e4fbfffe1 100755
--- a/scripts/gdbclient
+++ b/scripts/gdbclient
@@ -49,15 +49,6 @@ function gdbclient() {
fi
local DEVICE=$(adb_get_product_device)
- if [ -z "$DEVICE" ]; then
- echo "Error: Unable to get device name. Please check if device is connected and ANDROID_SERIAL is set."
- return -2
- fi
-
- if [ -n "$2" ]; then
- PORT=$2
- fi
-
local ROOT=$(gettop)
if [ -z "$ROOT" ]; then
# This is for the situation with downloaded symbols (from the build server)
@@ -65,6 +56,19 @@ function gdbclient() {
ROOT=`realpath .`
fi
+
+ if [[ -z "$DEVICE" || ! -d "$ROOT/out/target/product/$DEVICE" ]]; then
+ if [ -z "$CM_BUILD" ]; then
+ echo "Error: Unable to get device name. Please check if device is connected and ANDROID_SERIAL is set."
+ return -2
+ fi
+ DEVICE=$CM_BUILD
+ fi
+
+ if [ -n "$2" ]; then
+ PORT=$2
+ fi
+
local SYS_OUT_ROOT=$(get_build_var OUT_DIR)
local OUT_ROOT="${SYS_OUT_ROOT:-${OUT_DIR:-$ROOT/out}}/target/product/$DEVICE"
local SYMBOLS_DIR="$OUT_ROOT/symbols"
@@ -85,17 +89,20 @@ function gdbclient() {
fi
# let's figure out which executable we are about to debug
-
# check if user specified a name -> resolve to pid
if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
PROCESS_NAME=$PID
- PID=$(pid --exact $PROCESS_NAME)
- if [ -z "$PID" ]; then
+ PIDS=( $(adb shell "pidof $PROCESS_NAME 2> /dev/null" | tr -d '\r\n') )
+ if [[ ${#PIDS[@]} == 0 ]]; then
echo "Error: couldn't resolve pid by process name: $PROCESS_NAME"
return -4
- else
- echo "Resolved pid for $PROCESS_NAME is $PID"
+ elif [[ ${#PIDS[@]} != 1 ]]; then
+ echo "Error: more than one 1 PID resolved by process name: $PROCESS_NAME"
+ echo " PIDs -> ${PIDS[@]}"
+ return -5
fi
+ PID="${PIDS[0]}"
+ echo "Resolved pid for $PROCESS_NAME is [$PID]"
fi
local ID=`adb shell id -u`