ndk-gdb revision 201486c71651b4750d3cd8b7c4cd9a9c823f2e71
1#!/bin/sh 2# 3# Copyright (C) 2010 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18# This wrapper script is used to launch a native debugging session 19# on a given NDK application. The application must be debuggable, i.e. 20# its android:debuggable attribute must be set to 'true' in the 21# <application> element of its manifest. 22# 23# See docs/NDK-GDB.TXT for usage description. Essentially, you just 24# need to launch ndk-gdb from your application project directory 25# after doing ndk-build && ant install && <start-application-on-device> 26# 27. `dirname $0`/build/core/ndk-common.sh 28 29force_32bit_binaries 30 31# Find if a given shell program is available. 32# We need to take care of the fact that the 'which <foo>' command 33# may return either an empty string (Linux) or something like 34# "no <foo> in ..." (Darwin). Also, we need to redirect stderr 35# to /dev/null for Cygwin 36# 37# $1: program name 38# Out: program path, or empty string 39# Return: 0 on success, != 0 on error 40# 41find_program () 42{ 43 local PROG RET 44 PROG=$(which "$1" 2>/dev/null) 45 RET=$? 46 if [ $RET != 0 ]; then 47 PROG= 48 fi 49 echo "$PROG" 50 return $RET 51} 52 53quote_spaces () 54{ 55 echo "$@" | sed -e 's! !\ !g' 56} 57 58# If ADB_CMD is not defined, try to find a program named 'adb' 59# in our path. 60ADB_CMD=${ADB_CMD:-$(find_program adb)} 61ADB_FLAGS=${ADB_FLAGS:-} 62 63AWK_CMD=${AWK_CMD:-$(find_program awk)} 64 65DEBUG_PORT=5039 66 67# Delay in seconds between launching the activity and attaching gdbserver on it. 68# This is needed because there is no way to know when the activity has really 69# started, and sometimes this takes a few seconds. 70DELAY=2 71 72PARAMETERS= 73OPTION_HELP=no 74OPTION_PROJECT= 75OPTION_FORCE=no 76OPTION_ADB= 77OPTION_EXEC= 78OPTION_START=no 79OPTION_LAUNCH= 80OPTION_LAUNCH_LIST=no 81OPTION_DELAY= 82 83check_parameter () 84{ 85 if [ -z "$2" ]; then 86 echo "ERROR: Missing parameter after option '$1'" 87 exit 1 88 fi 89} 90 91check_adb_flags () 92{ 93 if [ -n "$ADB_FLAGS" ] ; then 94 echo "ERROR: Only one of -e, -d or -s <serial> can be used at the same time!" 95 exit 1 96 fi 97} 98 99get_build_var () 100{ 101 if [ -z "$GNUMAKE" ] ; then 102 GNUMAKE=make 103 fi 104 $GNUMAKE --no-print-dir -f $ANDROID_NDK_ROOT/build/core/build-local.mk -C $PROJECT DUMP_$1 105} 106 107get_build_var_for_abi () 108{ 109 if [ -z "$GNUMAKE" ] ; then 110 GNUMAKE=make 111 fi 112 $GNUMAKE --no-print-dir -f $ANDROID_NDK_ROOT/build/core/build-local.mk -C $PROJECT DUMP_$1 APP_ABI=$2 113} 114 115# Used to run an awk script on the manifest 116run_awk_manifest_script () 117{ 118 $AWK_CMD -f $AWK_SCRIPTS/$1 $PROJECT/$MANIFEST 119} 120 121if [ "$HOST_OS" = "cygwin" ] ; then 122# Return native path representation from cygwin one 123# $1: a cygwin-compatible path (e.g. /cygdrive/c/some/thing) 124# Return: path in host windows representation, e.g. C:/some/thing 125# 126# We use mixed mode (i.e. / as the directory separator) because 127# all the tools we use recognize it properly, and it avoids lots 128# of escaping nonsense associated with "\" 129# 130native_path () 131{ 132 cygpath -m $1 133} 134else # HOST_OS != windows 135native_path () 136{ 137 echo "$1" 138} 139fi # HOST_OS != windows 140 141# We need to ensure the ANDROID_NDK_ROOT is absolute, otherwise calls 142# to get_build_var, get_build_var_for_abi and run_awk_manifest_script 143# might fail, e.g. when invoked with: 144# 145# cd $NDKROOT 146# ./ndk-gdb --project=/path/to/project 147# 148path_is_absolute () 149{ 150 local P P2 151 P=$1 # copy path 152 P2=${P#/} # remove / prefix, if any 153 [ "$P" != "$P2" ] 154} 155 156if ! path_is_absolute "$ANDROID_NDK_ROOT"; then 157 ANDROID_NDK_ROOT=$(pwd)/$ANDROID_NDK_ROOT 158fi 159 160 161VERBOSE=no 162while [ -n "$1" ]; do 163 opt="$1" 164 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` 165 case "$opt" in 166 --help|-h|-\?) 167 OPTION_HELP=yes 168 ;; 169 --verbose) 170 VERBOSE=yes 171 ;; 172 -s) 173 check_parameter $1 $2 174 check_adb_flags 175 ADB_FLAGS=" -s $2" 176 shift 177 ;; 178 -s*) 179 check_adb_flags 180 optarg=`expr -- "$opt" : '-s\(.*\)'` 181 ADB_FLAGS=" -s $optarg" 182 ;; 183 -p) 184 check_parameter $1 $2 185 OPTION_PROJECT="$2" 186 shift 187 ;; 188 -p*) 189 optarg=`expr -- "$opt" : '-p\(.*\)'` 190 OPTION_PROJECT="$optarg" 191 ;; 192 --exec=*) 193 OPTION_EXEC="$optarg" 194 ;; 195 -x) 196 check_parameter $1 $2 197 OPTION_EXEC="$2" 198 shift 199 ;; 200 -x*) 201 optarg=`expr -- "$opt" : '-x\(.*\)'` 202 OPTION_EXEC="$optarg" 203 ;; 204 -e) 205 check_adb_flags 206 ADB_FLAGS=" -e" 207 ;; 208 -d) 209 check_adb_flags 210 ADB_FLAGS=" -d" 211 ;; 212 --adb=*) # specify ADB command 213 OPTION_ADB="$optarg" 214 ;; 215 --awk=*) 216 AWK_CMD="$optarg" 217 ;; 218 --project=*) 219 OPTION_PROJECT="$optarg" 220 ;; 221 --port=*) 222 DEBUG_PORT="$optarg" 223 ;; 224 --force) 225 OPTION_FORCE="yes" 226 ;; 227 --launch-list) 228 OPTION_LAUNCH_LIST="yes" 229 ;; 230 --launch=*) 231 OPTION_LAUNCH="$optarg" 232 ;; 233 --start) 234 OPTION_START=yes 235 ;; 236 --delay=*) 237 OPTION_DELAY="$optarg" 238 ;; 239 -*) # unknown options 240 echo "ERROR: Unknown option '$opt', use --help for list of valid ones." 241 exit 1 242 ;; 243 *) # Simply record parameter 244 if [ -z "$PARAMETERS" ] ; then 245 PARAMETERS="$opt" 246 else 247 PARAMETERS="$PARAMETERS $opt" 248 fi 249 ;; 250 esac 251 shift 252done 253 254if [ "$OPTION_HELP" = "yes" ] ; then 255 echo "Usage: $PROGNAME [options]" 256 echo "" 257 echo "Setup a gdb debugging session for your Android NDK application." 258 echo "Read $$NDK/docs/NDK-GDB.TXT for complete usage instructions." 259 echo "" 260 echo "Valid options:" 261 echo "" 262 echo " --help|-h|-? Print this help" 263 echo " --verbose Enable verbose mode" 264 echo " --force Kill existing debug session if it exists" 265 echo " --start Launch application instead of attaching to existing one" 266 echo " --launch=<name> Same as --start, but specify activity name (see below)" 267 echo " --launch-list List all launchable activity names from manifest" 268 echo " --delay=<secs> Delay in seconds between activity start and gdbserver attach." 269 echo " --project=<path> Specify application project path" 270 echo " -p <path> Same as --project=<path>" 271 echo " --port=<port> Use tcp:localhost:<port> to communicate with gdbserver [$DEBUG_PORT]" 272 echo " --exec=<file> Execute gdb initialization commands in <file> after connection" 273 echo " -x <file> Same as --exec=<file>" 274 echo " --adb=<file> Use specific adb command [$ADB_CMD]" 275 echo " --awk=<file> Use specific awk command [$AWK_CMD]" 276 echo " -e Connect to single emulator instance" 277 echo " -d Connect to single target device" 278 echo " -s <serial> Connect to specific emulator or device" 279 echo "" 280 exit 0 281fi 282 283log "Android NDK installation path: $ANDROID_NDK_ROOT" 284 285if [ -n "$OPTION_EXEC" ] ; then 286 if [ ! -f "$OPTION_EXEC" ]; then 287 echo "ERROR: Invalid initialization file: $OPTION_EXEC" 288 exit 1 289 fi 290fi 291 292if [ -n "$OPTION_DELAY" ] ; then 293 DELAY="$OPTION_DELAY" 294fi 295 296# Check ADB tool version 297if [ -n "$OPTION_ADB" ] ; then 298 ADB_CMD=$OPTION_ADB 299 log "Using specific adb command: $ADB_CMD" 300else 301 if [ -z "$ADB_CMD" ] ; then 302 echo "ERROR: The 'adb' tool is not in your path." 303 echo " You can change your PATH variable, or use" 304 echo " --adb=<executable> to point to a valid one." 305 exit 1 306 fi 307 log "Using default adb command: $ADB_CMD" 308fi 309 310ADB_CMD=$(quote_spaces $ADB_CMD) 311ADB_VERSION=$("$ADB_CMD" version 2>/dev/null) 312if [ $? != 0 ] ; then 313 echo "ERROR: Could not run ADB with: $ADB_CMD" 314 exit 1 315fi 316log "ADB version found: $ADB_VERSION" 317 318log "Using ADB flags: $ADB_FLAGS" 319 320# Run an ADB command with the right ADB flags 321# $1+: adb command parameter 322adb_cmd () 323{ 324 # NOTE: We escape $ADB_CMD in case the command's path contains spaces. 325 "$ADB_CMD" $ADB_FLAGS "$@" 326} 327 328# Used internally by adb_var_shell and adb_var_shell2. 329# $1: 1 to redirect stderr to $1, 0 otherwise. 330# $2: Variable name that will contain the result 331# $3+: Command options 332_adb_var_shell () 333{ 334 # We need a temporary file to store the output of our command 335 local CMD_OUT RET OUTPUT VARNAME REDIRECT_STDERR 336 REDIRECT_STDERR=$1 337 VARNAME=$2 338 shift; shift; 339 CMD_OUT=`mktemp /tmp/ndk-gdb-cmdout-XXXXXX` 340 # Run the command, while storing the standard output to CMD_OUT 341 # and appending the exit code as the last line. 342 if [ "$REDIRECT_STDERR" != 0 ]; then 343 adb_cmd shell "$@" ";" echo \$? | sed -e 's![[:cntrl:]]!!g' > $CMD_OUT 2>&1 344 else 345 adb_cmd shell "$@" ";" echo \$? | sed -e 's![[:cntrl:]]!!g' > $CMD_OUT 346 fi 347 # Get last line in log, which contains the exit code from the command 348 RET=`sed -e '$!d' $CMD_OUT` 349 # Get output, which corresponds to everything except the last line 350 OUT=`sed -e '$d' $CMD_OUT` 351 rm -f $CMD_OUT 352 eval $VARNAME=\"\$OUT\" 353 return $RET 354} 355 356# Run a command through 'adb shell' and captures its standard output 357# into a variable. The function's exit code is the same than the command's. 358# 359# This is required because there is a bug where "adb shell" always returns 360# 0 on the host, even if the command fails on the device. 361# 362# $1: Variable name (e.g. FOO) 363# On exit, $FOO is set to the command's standard output 364# 365# The return status will be 0 (success) if the command succeeded 366# or 1 (failure) otherwise. 367adb_var_shell () 368{ 369 _adb_var_shell 0 "$@" 370} 371 372# A variant of adb_var_shell that stores both stdout and stderr in the output 373# $1: Variable name 374adb_var_shell2 () 375{ 376 _adb_var_shell 1 "$@" 377} 378 379# Return the PID of a given package or program, or 0 if it doesn't run 380# $1: Package name ("com.example.hellojni") or program name ("/lib/gdbserver") 381# Out: PID number, or 0 if not running 382get_pid_of () 383{ 384 adb_cmd shell ps | $AWK_CMD -f $AWK_SCRIPTS/extract-pid.awk -v PACKAGE="$1" 385} 386 387# Check the awk tool 388AWK_SCRIPTS=$ANDROID_NDK_ROOT/build/awk 389AWK_TEST=`$AWK_CMD -f $AWK_SCRIPTS/check-awk.awk` 390if [ $? != 0 ] ; then 391 echo "ERROR: Could not run '$AWK_CMD' command. Do you have it installed properly?" 392 exit 1 393fi 394if [ "$AWK_TEST" != "Pass" ] ; then 395 echo "ERROR: Your version of 'awk' is obsolete. Please use --awk=<file> to point to Nawk or Gawk!" 396 exit 1 397fi 398 399# Name of the manifest file 400MANIFEST=AndroidManifest.xml 401 402# Find the root of the application project. 403if [ -n "$OPTION_PROJECT" ] ; then 404 PROJECT=$OPTION_PROJECT 405 log "Using specified project path: $PROJECT" 406 if [ ! -d "$PROJECT" ] ; then 407 echo "ERROR: Your --project option does not point to a directory!" 408 exit 1 409 fi 410 if [ ! -f "$PROJECT/$MANIFEST" ] ; then 411 echo "ERROR: Your --project does not point to an Android project path!" 412 echo " It is missing a $MANIFEST file." 413 exit 1 414 fi 415else 416 # Assume we are in the project directory 417 if [ -f "$MANIFEST" ] ; then 418 PROJECT=. 419 else 420 PROJECT= 421 CURDIR=`pwd` 422 while [ "$CURDIR" != "/" ] ; do 423 if [ -f "$CURDIR/$MANIFEST" ] ; then 424 PROJECT="$CURDIR" 425 break 426 fi 427 CURDIR=`dirname $CURDIR` 428 done 429 if [ -z "$PROJECT" ] ; then 430 echo "ERROR: Launch this script from an application project directory, or use --project=<path>." 431 exit 1 432 fi 433 fi 434 log "Using auto-detected project path: $PROJECT" 435fi 436 437# Extract the package name from the manifest 438PACKAGE_NAME=`run_awk_manifest_script extract-package-name.awk` 439log "Found package name: $PACKAGE_NAME" 440if [ $? != 0 -o "$PACKAGE_NAME" = "<none>" ] ; then 441 echo "ERROR: Could not extract package name from $PROJECT/$MANIFEST." 442 echo " Please check that the file is well-formed!" 443 exit 1 444fi 445 446# If --launch-list is used, list all launchable activities, and be done with it 447if [ "$OPTION_LAUNCH_LIST" = "yes" ] ; then 448 log "Extracting list of launchable activities from manifest:" 449 run_awk_manifest_script extract-launchable.awk 450 exit 0 451fi 452 453APP_ABIS=`get_build_var APP_ABI` 454log "ABIs targetted by application: $APP_ABIS" 455 456# Check the ADB command, and that we can connect to the device/emulator 457ADB_TEST=`adb_cmd shell ls` 458if [ $? != 0 ] ; then 459 echo "ERROR: Could not connect to device or emulator!" 460 echo " Please check that an emulator is running or a device is connected" 461 echo " through USB to this machine. You can use -e, -d and -s <serial>" 462 echo " in case of multiple ones." 463 exit 1 464fi 465 466# Check that the device is running Froyo (API Level 8) or higher 467# 468adb_var_shell API_LEVEL getprop ro.build.version.sdk 469if [ $? != 0 -o -z "$API_LEVEL" ] ; then 470 echo "ERROR: Could not find target device's supported API level!" 471 echo "ndk-gdb will only work if your device is running Android 2.2 or higher." 472 exit 1 473fi 474log "Device API Level: $API_LEVEL" 475if [ "$API_LEVEL" -lt "8" ] ; then 476 echo "ERROR: ndk-gdb requires a target device running Android 2.2 (API level 8) or higher." 477 echo "The target device is running API level $API_LEVEL!" 478 exit 1 479fi 480 481# Get the target device's supported ABI(s) 482# And check that they are supported by the application 483# 484COMPAT_ABI=none 485adb_var_shell CPU_ABI getprop ro.product.cpu.abi 486for ABI in $APP_ABIS; do 487 if [ "$ABI" = "$CPU_ABI" ] ; then 488 COMPAT_ABI=$CPU_ABI 489 break 490 fi 491done 492 493adb_var_shell CPU_ABI2 getprop ro.product.cpu.abi2 494if [ $? != 0 -o -z "$CPU_ABI2" ] ; then 495 CPU_ABI2= 496 log "Device CPU ABI: $CPU_ABI" 497else 498 log "Device CPU ABIs: $CPU_ABI $CPU_ABI2" 499 if [ "$COMPAT_ABI" = "none" ] ; then 500 for ABI in $APP_ABIS; do 501 if [ "$ABI" = "$CPU_ABI2" ] ; then 502 COMPAT_ABI=$CPU_ABI2 503 break 504 fi 505 done 506 fi 507fi 508if [ "$COMPAT_ABI" = none ] ; then 509 echo "ERROR: The device does not support the application's targetted CPU ABIs!" 510 if [ "$CPU_ABI2" = "$CPU_ABI" ] ; then 511 CPU_ABI2= 512 fi 513 echo " Device supports: $CPU_ABI $CPU_ABI2" 514 echo " Package supports: $APP_ABIS" 515 exit 1 516fi 517log "Compatible device ABI: $COMPAT_ABI" 518 519# Get information from the build system 520GDBSETUP_INIT=`get_build_var_for_abi NDK_APP_GDBSETUP $COMPAT_ABI` 521log "Using gdb setup init: $GDBSETUP_INIT" 522 523TOOLCHAIN_PREFIX=`get_build_var_for_abi TOOLCHAIN_PREFIX $COMPAT_ABI` 524log "Using toolchain prefix: $TOOLCHAIN_PREFIX" 525 526APP_OUT=`get_build_var_for_abi TARGET_OUT $COMPAT_ABI` 527log "Using app out directory: $APP_OUT" 528 529# Check that the application is debuggable, or nothing will work 530DEBUGGABLE=`run_awk_manifest_script extract-debuggable.awk` 531log "Found debuggable flag: $DEBUGGABLE" 532if [ $? != 0 -o "$DEBUGGABLE" != "true" ] ; then 533 # If gdbserver exists, then we built with 'ndk-build NDK_DEBUG=1' and it's 534 # ok to not have android:debuggable set to true in the original manifest. 535 # However, if this is not the case, then complain!! 536 if [ -f $PROJECT/libs/$COMPAT_ABI/gdbserver ] ; then 537 log "Found gdbserver under libs/$COMPAT_ABI, assuming app was built with NDK_DEBUG=1" 538 else 539 echo "ERROR: Package $PACKAGE_NAME is not debuggable ! You can fix that in two ways:" 540 echo "" 541 echo " - Rebuilt with the NDK_DEBUG=1 option when calling 'ndk-build'." 542 echo "" 543 echo " - Modify your manifest to set android:debuggable attribute to \"true\"," 544 echo " then rebuild normally." 545 echo "" 546 echo "After one of these, re-install to the device!" 547 exit 1 548 fi 549else 550 # DEBUGGABLE is true in the manifest. Let's check that the user didn't change the 551 # debuggable flag in the manifest without calling ndk-build afterwards. 552 if [ ! -f $PROJECT/libs/$COMPAT_ABI/gdbserver ] ; then 553 echo "ERROR: Could not find gdbserver binary under $PROJECT/libs/$COMPAT_ABI" 554 echo " This usually means you modified your AndroidManifest.xml to set" 555 echo " the android:debuggable flag to 'true' but did not rebuild the" 556 echo " native binaries. Please call 'ndk-build' to do so," 557 echo " *then* re-install to the device!" 558 exit 1 559 fi 560fi 561 562# Let's check that 'gdbserver' is properly installed on the device too. If this 563# is not the case, the user didn't install the proper package after rebuilding. 564# 565adb_var_shell2 DEVICE_GDBSERVER ls /data/data/$PACKAGE_NAME/lib/gdbserver 566if [ $? != 0 ]; then 567 echo "ERROR: Non-debuggable application installed on the target device." 568 echo " Please re-install the debuggable version!" 569 exit 1 570fi 571log "Found device gdbserver: $DEVICE_GDBSERVER" 572 573# Find the <dataDir> of the package on the device 574adb_var_shell2 DATA_DIR run-as $PACKAGE_NAME /system/bin/sh -c pwd 575if [ $? != 0 -o -z "$DATA_DIR" ] ; then 576 echo "ERROR: Could not extract package's data directory. Are you sure that" 577 echo " your installed application is debuggable?" 578 exit 1 579fi 580log "Found data directory: '$DATA_DIR'" 581 582# Launch the activity if needed 583if [ "$OPTION_START" = "yes" ] ; then 584 # If --launch is used, ignore --start, otherwise extract the first 585 # launchable activity name from the manifest and use it as if --launch=<name> 586 # was used instead. 587 # 588 if [ -z "$OPTION_LAUNCH" ] ; then 589 OPTION_LAUNCH=`run_awk_manifest_script extract-launchable.awk | sed 2q` 590 if [ $? != 0 ] ; then 591 echo "ERROR: Could not extract name of launchable activity from manifest!" 592 echo " Try to use --launch=<name> directly instead as a work-around." 593 exit 1 594 fi 595 log "Found first launchable activity: $OPTION_LAUNCH" 596 if [ -z "$OPTION_LAUNCH" ] ; then 597 echo "ERROR: It seems that your Application does not have any launchable activity!" 598 echo " Please fix your manifest file and rebuild/re-install your application." 599 exit 1 600 fi 601 fi 602fi 603 604if [ -n "$OPTION_LAUNCH" ] ; then 605 log "Launching activity: $PACKAGE_NAME/$OPTION_LAUNCH" 606 run adb_cmd shell am start -n $PACKAGE_NAME/$OPTION_LAUNCH 607 if [ $? != 0 ] ; then 608 echo "ERROR: Could not launch specified activity: $OPTION_LAUNCH" 609 echo " Use --launch-list to dump a list of valid values." 610 exit 1 611 fi 612 # Sleep a bit, it sometimes take one second to start properly 613 # Note that we use the 'sleep' command on the device here. 614 run adb_cmd shell sleep $DELAY 615fi 616 617# Find the PID of the application being run 618PID=$(get_pid_of "$PACKAGE_NAME") 619log "Found running PID: $PID" 620if [ $? != 0 -o "$PID" = "0" ] ; then 621 echo "ERROR: Could not extract PID of application on device/emulator." 622 if [ -n "$OPTION_LAUNCH" ] ; then 623 echo " Weird, this probably means one of these:" 624 echo "" 625 echo " - The installed package does not match your current manifest." 626 echo " - The application process was terminated." 627 echo "" 628 echo " Try using the --verbose option and look at its output for details." 629 else 630 echo " Are you sure the application is already started?" 631 echo " Consider using --start or --launch=<name> if not." 632 fi 633 exit 1 634fi 635 636# Check that there is no other instance of gdbserver running 637GDBSERVER_PID=$(get_pid_of lib/gdbserver) 638if [ "$GDBSERVER_PID" != "0" ]; then 639 if [ "$OPTION_FORCE" = "no" ] ; then 640 echo "ERROR: Another debug session running, Use --force to kill it." 641 exit 1 642 fi 643 log "Killing existing debugging session" 644 run adb_cmd shell kill -9 $GDBSERVER_PID 645fi 646 647# Launch gdbserver now 648DEBUG_SOCKET=debug-socket 649run adb_cmd shell run-as $PACKAGE_NAME lib/gdbserver +$DEBUG_SOCKET --attach $PID & 650if [ $? != 0 ] ; then 651 echo "ERROR: Could not launch gdbserver on the device?" 652 exit 1 653fi 654log "Launched gdbserver succesfully." 655 656# Setup network redirection 657log "Setup network redirection" 658run adb_cmd forward tcp:$DEBUG_PORT localfilesystem:$DATA_DIR/$DEBUG_SOCKET 659if [ $? != 0 ] ; then 660 echo "ERROR: Could not setup network redirection to gdbserver?" 661 echo " Maybe using --port=<port> to use a different TCP port might help?" 662 exit 1 663fi 664 665# Get the app_server binary from the device 666APP_PROCESS=$APP_OUT/app_process 667run adb_cmd pull /system/bin/app_process `native_path $APP_PROCESS` 668log "Pulled app_process from device/emulator." 669 670run adb_cmd pull /system/lib/libc.so `native_path $APP_OUT/libc.so` 671log "Pulled libc.so from device/emulator." 672 673# Now launch the appropriate gdb client with the right init commands 674# 675GDBCLIENT=${TOOLCHAIN_PREFIX}gdb 676GDBSETUP=$APP_OUT/gdb.setup 677cp -f $GDBSETUP_INIT $GDBSETUP 678#uncomment the following to debug the remote connection only 679#echo "set debug remote 1" >> $GDBSETUP 680echo "file `native_path $APP_PROCESS`" >> $GDBSETUP 681echo "target remote :$DEBUG_PORT" >> $GDBSETUP 682if [ -n "$OPTION_EXEC" ] ; then 683 cat $OPTION_EXEC >> $GDBSETUP 684fi 685$GDBCLIENT -x `native_path $GDBSETUP` 686