Lines Matching +full:ndk +full:- +full:path
4 # Use of this source code is governed by a BSD-style license that can be
12 # Use --help to print full usage instructions.
21 # Location of Chromium-top-level sources.
35 kill -9 $GDBSERVER_PID >/dev/null 2>&1
36 rm -f "$GDBSERVER_PIDFILE"
44 rm -rf "$TMPDIR"
50 # Ensure clean exit on Ctrl-C or normal exit.
64 if [ "$VERBOSE" -gt 0 ]; then
69 DEFAULT_PULL_LIBS_DIR="/tmp/adb-gdb-support-$USER"
77 PROGNAME=${ADB_GDB_PROGNAME:-$(basename "$0")}
104 --adb=*)
107 --device=*)
110 --annotate=3)
113 --gdbserver=*)
116 --gdb=*)
119 --help|-h|-?)
122 --ide)
125 --ndk-dir=*)
128 --no-pull-libs)
131 --package-name=*)
134 --pid=*)
137 --port=*)
140 --program-name=*)
143 --pull-libs)
146 --pull-libs-dir=*)
149 --script=*)
152 --attach-delay=*)
155 --su-prefix=*)
158 --symbol-dir=*)
161 --output-directory=*)
164 --target-arch=*)
167 --toolchain=*)
170 --cgdb)
173 --cgdb=*)
176 --verbose)
179 -*)
180 panic "Unknown option $opt, see --help." >&2
185 See --help."
203 Usage: $PROGNAME [options] [<package-name>]
207 If provided, <package-name> must be the name of the Android application's
208 package name to be debugged. You can also use --package-name=<name> to
220 - target gdbserver binary
221 - host gdb client (e.g. arm-linux-androideabi-gdb)
222 - directory with symbolic version of $PROGRAM_NAME's shared libraries.
224 You can also use --ndk-dir=<path> to specify an alternative NDK installation
233 Where <out> is determined by CHROMIUM_OUTPUT_DIR, or --output-directory.
235 You can set the path manually via --symbol-dir.
238 but if this fails, will default to 'arm'. Use --target-arch=<name> to force
241 Otherwise, the script will complain, but you can use the --gdbserver,
242 --gdb and --symbol-lib options to specify everything manually.
244 An alternative to --gdb=<file> is to use --toollchain=<path> to specify
245 the path to the host target-specific cross-toolchain.
247 You will also need the 'adb' tool in your path. Otherwise, use the --adb
249 and a device is not specified with either --device or ANDROID_SERIAL).
259 But you can use the --pull-libs-dir=<path> option to specify an
261 and will re-pull the libraries only in this case. You can however force it
262 with the --pull-libs option.
265 gdb command script with the --script=<file> option. Note that its commands
270 --help|-h|-? Print this message.
271 --verbose Increase verbosity.
273 --cgdb[=<file>] Use cgdb (an interface for gdb that shows the code).
274 --symbol-dir=<path> Specify directory with symbol shared libraries.
275 --output-directory=<path> Specify the output directory (e.g. "out/Debug").
276 --package-name=<name> Specify package name (alternative to 1st argument).
277 --program-name=<name> Specify program name (cosmetic only).
278 --pid=<pid> Specify application process pid.
279 --attach-delay=<num> Seconds to wait for gdbserver to attach to the
282 --annotate=<num> Enable gdb annotation.
283 --script=<file> Specify extra GDB init script.
285 --gdbserver=<file> Specify target gdbserver binary.
286 --gdb=<file> Specify host gdb client binary.
287 --target-arch=<name> Specify NDK target arch.
288 --adb=<file> Specify host ADB binary.
289 --device=<file> ADB device serial to use (-s flag).
290 --port=<port> Specify the tcp port to use.
291 --ide Forward gdb port, but do not enter gdb console.
293 --su-prefix=<prefix> Prepend <prefix> to 'adb shell' commands that are
296 e.g. --su-prefix="su -c"
298 --pull-libs Force system libraries extraction.
299 --no-pull-libs Do not extract any system library.
300 --libs-dir=<path> Specify system libraries extraction directory.
306 if [ -z "$PACKAGE_NAME" ]; then
307 panic "Please specify a package name on the command line. See --help."
310 if [[ -z "$SYMBOL_DIR" && -z "$CHROMIUM_OUTPUT_DIR" ]]; then
311 if [[ -e "build.ninja" ]]; then
315 --output-directory=out/Debug
318 See --help."
328 # the most recent sub-directory containing debug shared libraries under
337 if [[ ! -e "$PARENT_DIR" ]]; then
341 if [[ -z "$(ls "$SYMBOL_DIR"/lib*.so 2>/dev/null)" ]]; then
343 if [[ -z "$(ls "$SYMBOL_DIR"/lib*.so 2>/dev/null)" ]]; then
348 log "Auto-config: --symbol-dir=$SYMBOL_DIR"
351 if [ -z "$SYMBOL_DIR" ]; then
353 elif [[ -z "$(ls "$SYMBOL_DIR"/lib*.so 2>/dev/null)" ]]; then
357 if [ -z "$NDK_DIR" ]; then
358 ANDROID_NDK_ROOT=$(PYTHONPATH=$CHROMIUM_SRC/build/android python3 -c \
361 if [ ! -d "$NDK_DIR" ]; then
364 if [ ! -f "$NDK_DIR/ndk-build" ]; then
365 panic "Not a valid NDK directory: $NDK_DIR"
370 if [ "$GDBINIT" -a ! -f "$GDBINIT" ]; then
371 panic "Unknown --script file: $GDBINIT"
374 # Check that ADB is in our path
375 if [ -z "$ADB" ]; then
377 if [ -z "$ADB" ]; then
378 panic "Can't find 'adb' tool in your path. Install it or use \
379 --adb=<file>"
381 log "Auto-config: --adb=$ADB"
386 echo "$ADB_VERSION" | fgrep -q -e "Android Debug Bridge"
388 panic "Your 'adb' tool seems invalid, use --adb=<file> to specify a \
394 NUM_DEVICES_PLUS2=$($ADB devices 2>/dev/null | wc -l)
395 if [ "$NUM_DEVICES_PLUS2" -gt 3 -a -z "$ANDROID_SERIAL" ]; then
411 local ADB=${ADB:-adb}
418 sed -e 's![[:cntrl:]]!!g' > $TMPOUT
420 LASTLINE=$(sed -e '$!d' $TMPOUT)
424 awk '{ if (match($0, "%%[0-9]+$")) { print substr($0,RSTART+2); } }')
428 awk '{ if (match($0, "%%[0-9]+$")) { print substr($0,1,RSTART-1); } }')
430 sed -e '$d' $TMPOUT && printf "%s" "$LASTLINE"
432 rm -f $TMPOUT
438 # This returns an NDK-compatible architecture name.
439 # out: NDK Architecture name, or empty string.
442 local RANDOM_LIB=$(ls "$SYMBOL_DIR"/lib*.so 2>/dev/null| head -n1)
445 *32-bit*ARM,*) echo "arm";;
446 *64-bit*ARM,*) echo "arm64";;
447 *32-bit*Intel,*) echo "x86";;
448 *x86-64,*) echo "x86_64";;
449 *32-bit*MIPS,*) echo "mips";;
454 if [ -z "$TARGET_ARCH" ]; then
456 if [ -z "$TARGET_ARCH" ]; then
461 # script prefers the NDK 'x86' name instead because it uses it to find
462 # NDK-specific files (host gdb) with it.
465 log "Auto-config: --arch=$TARGET_ARCH (equivalent to ia32)"
469 # Detect the NDK system name, i.e. the name used to identify the host.
470 # out: NDK system name (e.g. 'linux' or 'darwin')
473 if [ -z "$NDK_HOST_SYSTEM" ]; then
474 HOST_OS=$(uname -s)
484 # Detect the NDK host architecture name.
485 # out: NDK arch name (e.g. 'x86' or 'x86_64')
488 if [ -z "$NDK_HOST_ARCH" ]; then
490 HOST_ARCH=$(uname -p)
492 # In case where "-p" returns "unknown" just use "-m" (machine hardware
493 # name). According to this patch from Fedora "-p" is equivalent to "-m"
495 HOST_ARCH=$(uname -m)
502 # Darwin trick: "uname -p" always returns i386 on 64-bit installations.
503 if [ "$HOST_OS" = darwin -a "$NDK_HOST_ARCH" = "x86" ]; then
506 HOST_64BITS=$(/usr/bin/file -L "$SHELL" | grep -e "x86[_-]64")
515 # Convert an NDK architecture name into a GNU configure triplet.
516 # $1: NDK architecture name (e.g. 'arm')
517 # Out: Android GNU configure triplet (e.g. 'arm-linux-androideabi')
521 echo "arm-linux-androideabi"
524 echo "aarch64-linux-android"
527 echo "i686-linux-android"
530 echo "x86_64-linux-android"
533 echo "mipsel-linux-android"
536 echo "$ARCH-linux-android"
541 # Convert an NDK architecture name into a toolchain name prefix
542 # $1: NDK architecture name (e.g. 'arm')
543 # Out: NDK toolchain name prefix (e.g. 'arm-linux-androideabi')
546 if [ "$1" = "x86" -o "$1" = "x86_64" ]; then
553 # Find a NDK toolchain prebuilt file or sub-directory.
554 # This will probe the various arch-specific toolchain directories
555 # in the NDK for the needed file.
556 # $1: NDK install path
557 # $2: NDK architecture name
558 # $3: prebuilt sub-path to look for.
559 # Out: file path, or empty if none is found.
566 FILE=$NDK_DIR/toolchains/$NAME-4.9/prebuilt/$SUBPATH
567 if [ ! -f "$FILE" ]; then
568 FILE=$NDK_DIR/toolchains/$NAME-4.8/prebuilt/$SUBPATH
569 if [ ! -f "$FILE" ]; then
576 # $1: NDK install path
583 echo "$NDK_DIR/prebuilt/$HOST_OS-$HOST_ARCH/bin/gdb"
586 # $1: NDK install path
593 # The location has moved after NDK r8
594 BINARY=$NDK_DIR/prebuilt/android-$ARCH/gdbserver/gdbserver
595 if [ ! -f "$BINARY" ]; then
602 if [ -z "$GDB" ]; then
604 if [ -z "$GDB" ]; then
605 panic "Can't find Android gdb client in your path, check your \
606 --toolchain or --gdb path."
615 if [ -z "$GDBSERVER" ]; then
617 if [ -z "$GDBSERVER" ]; then
618 panic "Can't find NDK gdbserver binary. use --gdbserver to specify \
621 log "Auto-config: --gdbserver=$GDBSERVER"
625 # sub-shell commands we're going to launch, so take the PID of the launcher
630 TMPDIR=/tmp/$USER-adb-gdb-tmp-$TMP_ID
631 mkdir -p "$TMPDIR" && rm -rf "$TMPDIR"/*
633 GDBSERVER_PIDFILE="$TMPDIR"/gdbserver-$TMP_ID.pid
636 # $1: file path
639 stat -c %Y "$1" 2>/dev/null
643 APP_DATA_DIR=$(adb_shell run-as $PACKAGE_NAME /system/bin/sh -c pwd)
644 fail_panic "Failed to run-as $PACKAGE_NAME, is the app debuggable?"
645 TARGET_GDBSERVER="$APP_DATA_DIR/gdbserver-adb-gdb-$TMP_ID"
646 TMP_TARGET_GDBSERVER=/data/local/tmp/gdbserver-adb-gdb-$TMP_ID
655 # Default to app_process if bit-width specific process isn't found.
670 if [[ -n "$ANDROID_SERIAL" ]]; then
671 DEFAULT_PULL_LIBS_DIR="$DEFAULT_PULL_LIBS_DIR/$ANDROID_SERIAL-$SUFFIX_64_BIT"
673 PULL_LIBS_DIR=${PULL_LIBS_DIR:-$DEFAULT_PULL_LIBS_DIR}
680 if [ ! -f "$PULL_LIBS_DIR/build.fingerprint" ]; then
681 log "Auto-config: --pull-libs (no cached libraries)"
687 log "Auto-config: --no-pull-libs (fingerprint match)"
690 log "Auto-config: --pull-libs (fingerprint mismatch)"
695 # If requested, work for M-x gdb. The gdb indirections make it
696 # difficult to pass --annotate=3 to the gdb binary itself.
698 GDB_ARGS=$GDB_ARGS" --annotate=$ANNOTATE"
703 if [ -z "$PID" ]; then
705 if [ -z "$PID" ]; then
707 awk '$9 == "'$PROCESSNAME'" { print $2; }' | head -1)
709 if [ -z "$PID" ]; then
717 # use run-as $PACKAGE_NAME ..., which requires the package to be debuggable.
721 SU_PREFIX_TEST_LOG=$TMPDIR/su-prefix.log
723 if [ $? != 0 -o "$(cat $SU_PREFIX_TEST_LOG)" != "foo" ]; then
735 if [ "$SHELL_UID" != 0 -o -n "$NO_ROOT" ]; then
736 COMMAND_PREFIX="run-as $PACKAGE_NAME"
746 mkdir -p "$PULL_LIBS_DIR"
747 fail_panic "Can't create --libs-dir directory: $PULL_LIBS_DIR"
752 if [ "$PULL_LIBS" -a -z "$NO_PULL_LIBS" ]; then
758 panic "Are you sure your --su-prefix is correct?"
760 panic "Use --su-prefix if the application is not debuggable."
764 rm -f "$PULL_LIBS_DIR/build.fingerprint"
766 awk '$6 ~ /\/(system|apex|vendor)\/.*\.so$/ { print $6; }' | sort -u)
771 mkdir -p "$DST_DIR" && "$ADB" pull $SYSLIB "$DST_FILE" 2>/dev/null
783 # Find all the sub-directories of $PULL_LIBS_DIR, up to depth 4
784 # so we can add them to solib-search-path later.
785 SOLIB_DIRS=$(find $PULL_LIBS_DIR -mindepth 1 -maxdepth 4 -type d | \
786 grep -v "^$" | tr '\n' ':')
790 # created with rwx------ permissions, preventing adbd from forwarding to
801 if [ -z "$PORT" ]; then
806 TARGET_DOMAIN_SOCKET=$APP_DATA_DIR/gdb-socket-$HOST_PORT
809 log "Setting network redirection (host:$HOST_PORT -> device:$TARGET_DOMAIN_SOCKET)"
815 # Note that using run-as requires the package to be debuggable.
819 # Maybe we should add a --root option to enable this?
824 GDBSERVER_LOG=$TMPDIR/gdbserver-$TMP_ID.log
826 --once +$TARGET_DOMAIN_SOCKET \
827 --attach $PID $COMMAND_SUFFIX"
829 --once +$TARGET_DOMAIN_SOCKET \
830 --attach $PID $COMMAND_SUFFIX > $GDBSERVER_LOG 2>&1 &
839 log "Job control: $(jobs -l)"
840 STATE=$(jobs -l | awk '$2 == "'$GDBSERVER_PID'" { print $3; }')
843 if [[ -n "$pid_msg" ]]; then
847 adb_shell $COMMAND_PREFIX kill -9 $old_pid $COMMAND_SUFFIX
851 echo "Here is the output from gdbserver (also try --verbose for more):"
864 set osabi GNU/Linux # Copied from ndk-gdb.py.
868 sys.path.insert(0, '$CHROMIUM_SRC/tools/gdb/')
872 sys.path.pop(0)
876 set solib-absolute-prefix $PULL_LIBS_DIR
877 set solib-search-path $SOLIB_DIRS:$PULL_LIBS_DIR:$SYMBOL_DIR
880 # Copied from ndk-gdb.py:
889 time_left = end_time - time.time()
906 if [ "$VERBOSE" -gt 0 ]; then
913 mkdir -p "$IDE_DIR"
917 ln -sf "$TMPDIR/$GDBEXEC" "$SYM_EXE"
918 ln -sf "$COMMANDS" "$SYM_INIT"
931 … with vscode: https://chromium.googlesource.com/chromium/src/+/main/docs/vscode.md#Launch-Commands"
932 echo "Showing gdbserver logs. Press Ctrl-C to disconnect."
933 tail -f "$GDBSERVER_LOG"
935 log "Launching gdb client: $GDB $GDB_ARGS -x $COMMANDS"
938 $CGDB -d $GDB -- $GDB_ARGS -x "$COMMANDS"
940 $GDB $GDB_ARGS -x "$COMMANDS"