Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/bash | |
| 2 # | |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 # | |
| 7 # Attach gdb to a running content shell. Similar to ndk-gdb. | |
| 8 # Run with --annotate=3 if running under emacs (M-x gdb). | |
| 9 # | |
| 10 # TODO(jrg): allow package_name and shared_lib_dir to be set on the | |
| 11 # command line. Share the guts of this script with other Chromium | |
| 12 # pieces (like base_unittests_apk) and friends (like WebKit bundles). | |
| 13 | |
| 14 adb=$(which adb) | |
| 15 if [[ "$adb" = "" ]] ; then | |
| 16 echo "Need adb in your path" | |
| 17 exit 1 | |
| 18 fi | |
| 19 | |
| 20 # TODO(jrg): non-rooted path speculative and untested. | |
| 21 rooted_phone=1 | |
| 22 | |
| 23 root=$(dirname $0)/../.. | |
| 24 package_name=org.chromium.content_shell | |
| 25 gdb_server_on_device=/data/data/$package_name/lib/gdbserver | |
| 26 shared_lib_dir=$root/out/Release/lib.target | |
| 27 | |
| 28 # Kill any running gdbserver | |
| 29 pid=$(adb shell ps | awk '/gdbserver/ {print $2}') | |
| 30 if [[ "$pid" != "" ]] ; then | |
| 31 if [[ $rooted_phone -eq 1 ]] ; then | |
| 32 adb shell kill $pid | |
|
Satish
2012/05/03 10:28:03
indentation
John Grabowski
2012/05/07 12:40:16
emacs sees [[ as double indent. Sigh.
| |
| 33 else | |
| 34 adb shell run-as $package_name kill $pid | |
|
Satish
2012/05/03 10:28:03
ditto
| |
| 35 fi | |
| 36 fi | |
| 37 | |
| 38 pid=$(adb shell ps | awk "/$package_name/ {print \$2}") | |
| 39 if [[ "$pid" = "" ]] ; then | |
| 40 echo "No $package_name running?" | |
| 41 echo "Try this: adb shell am start -a android.intent.action.VIEW " \ | |
| 42 "-n $package_name/.SomethingActivity (Something might be ContentShell)" | |
| 43 exit 2 | |
| 44 fi | |
| 45 | |
| 46 no_gdb_server=$(adb shell ls $gdb_server_on_device | grep 'No such file') | |
| 47 if [[ "$no_gdb_server" != "" ]] ; then | |
| 48 echo "No gdb server on device at $gdb_server_on_device" | |
| 49 echo "Please install a debug build." | |
| 50 exit 3 | |
| 51 fi | |
| 52 | |
| 53 adb forward tcp:4321 tcp:4321 | |
| 54 | |
| 55 # TODO(jrg): Consider a closer match to ndk-gdb which uses subtly | |
| 56 # different semantics for both port forwarding and launching | |
| 57 # gdbserver. | |
| 58 if [[ $rooted_phone -eq 1 ]] ; then | |
| 59 adb shell $gdb_server_on_device :4321 --attach $pid & | |
|
Satish
2012/05/03 10:28:03
ditto
| |
| 60 else | |
| 61 adb shell run-as $package_name $gdb_server_on_device :4321 --attach $pid & | |
|
Satish
2012/05/03 10:28:03
ditto
| |
| 62 fi | |
| 63 sleep 2 | |
|
Satish
2012/05/03 10:28:03
is this sleep required? are there other ways to wa
John Grabowski
2012/05/07 12:40:16
There is no logcat output. There is stdio output
| |
| 64 | |
| 65 # Pull app_process and C libraries from device if needed | |
| 66 app_process=${shared_lib_dir}/app_process | |
| 67 if [[ ! -f ${app_process} ]] ; then | |
| 68 adb pull /system/bin/app_process ${app_process} | |
| 69 adb pull /system/lib/libc.so ${shared_lib_dir} | |
| 70 fi | |
| 71 | |
| 72 # gdb commands | |
| 73 cmdfile=$(mktemp /tmp/gdb_android_XXXXXXXX) | |
| 74 cat >$cmdfile<<EOF | |
| 75 set solib-absolute-prefix null | |
| 76 set solib-search-path ${shared_lib_dir} | |
| 77 target remote :4321 | |
| 78 EOF | |
| 79 | |
| 80 gdb=$(echo $ANDROID_TOOLCHAIN/*gdb) | |
| 81 if [[ ! -f ${gdb} ]] ; then | |
| 82 echo "Wow no gdb in env var ANDROID_TOOLCHAIN which is $ANDROID_TOOLCHAIN" | |
|
Satish
2012/05/03 10:28:03
indentation
| |
| 83 exit 4 | |
| 84 else | |
| 85 echo Using $gdb | |
|
Satish
2012/05/03 10:28:03
ditto
| |
| 86 fi | |
| 87 | |
| 88 ${gdb} -x $cmdfile $* $app_process | |
| 89 rm $cmdfile | |
| OLD | NEW |