OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 # | 6 # |
7 # Attach gdb to a running content shell. Similar to ndk-gdb. | 7 # Attach gdb to a running content shell. Similar to ndk-gdb. |
8 # Run with --annotate=3 if running under emacs (M-x gdb). | 8 # Run with --annotate=3 if running under emacs (M-x gdb). |
9 # | 9 # |
10 # TODO(jrg): allow package_name and shared_lib_dir to be set on the | 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 | 11 # command line. Share the guts of this script with other Chromium |
12 # pieces (like base_unittests_apk) and friends (like WebKit bundles). | 12 # pieces (like base_unittests_apk) and friends (like WebKit bundles). |
13 | 13 |
14 adb=$(which adb) | 14 adb=$(which adb) |
15 if [[ "$adb" = "" ]] ; then | 15 if [[ "$adb" = "" ]] ; then |
16 echo "Need adb in your path" | 16 echo "Need adb in your path" |
17 exit 1 | 17 exit 1 |
18 fi | 18 fi |
19 | 19 |
20 # TODO(jrg): non-rooted path speculative and untested. | 20 rooted_phone=0 |
21 rooted_phone=1 | |
22 | 21 |
23 root=$(dirname $0)/../.. | 22 root=$(dirname $0)/../.. |
24 package_name=org.chromium.content_shell | 23 package_name=org.chromium.content_shell |
25 gdb_server_on_device=/data/data/$package_name/lib/gdbserver | 24 data_dir=/data/data/$package_name |
| 25 gdb_server_on_device=$data_dir/lib/gdbserver |
26 shared_lib_dir=$root/out/Release/lib.target | 26 shared_lib_dir=$root/out/Release/lib.target |
27 | 27 |
28 # Kill any running gdbserver | 28 # Kill any running gdbserver |
29 pid=$(adb shell ps | awk '/gdbserver/ {print $2}') | 29 pid=$(adb shell ps | awk '/gdbserver/ {print $2}') |
30 if [[ "$pid" != "" ]] ; then | 30 if [[ "$pid" != "" ]] ; then |
31 if [[ $rooted_phone -eq 1 ]] ; then | 31 if [[ $rooted_phone -eq 1 ]] ; then |
32 adb shell kill $pid | 32 adb shell kill $pid |
33 else | 33 else |
34 adb shell run-as $package_name kill $pid | 34 adb shell run-as $package_name kill $pid |
35 fi | 35 fi |
36 fi | 36 fi |
37 | 37 |
38 pid=$(adb shell ps | awk "/$package_name/ {print \$2}") | 38 pid=$(adb shell ps | awk "/$package_name/ {print \$2}") |
39 if [[ "$pid" = "" ]] ; then | 39 if [[ "$pid" = "" ]] ; then |
40 echo "No $package_name running?" | 40 echo "No $package_name running?" |
41 echo "Try this: adb shell am start -a android.intent.action.VIEW " \ | 41 echo "Try this: adb shell am start -a android.intent.action.VIEW " \ |
42 "-n $package_name/.SomethingActivity (Something might be ContentShell)" | 42 "-n $package_name/.SomethingActivity (Something might be ContentShell)" |
43 exit 2 | 43 exit 2 |
44 fi | 44 fi |
45 | 45 |
46 no_gdb_server=$(adb shell ls $gdb_server_on_device | grep 'No such file') | 46 no_gdb_server=$(adb shell ls $gdb_server_on_device | grep 'No such file') |
47 if [[ "$no_gdb_server" != "" ]] ; then | 47 if [[ "$no_gdb_server" != "" ]] ; then |
48 echo "No gdb server on device at $gdb_server_on_device" | 48 echo "No gdb server on device at $gdb_server_on_device" |
49 echo "Please install a debug build." | 49 echo "Please install a debug build." |
50 exit 3 | 50 exit 3 |
51 fi | 51 fi |
52 | 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 | 53 if [[ $rooted_phone -eq 1 ]] ; then |
59 adb shell $gdb_server_on_device :4321 --attach $pid & | 54 adb shell $gdb_server_on_device :4321 --attach $pid & |
| 55 adb forward tcp:4321 tcp:4321 |
60 else | 56 else |
61 adb shell run-as $package_name $gdb_server_on_device :4321 --attach $pid & | 57 adb shell run-as $package_name lib/gdbserver +debug-socket --attach $pid & |
| 58 adb forward tcp:4321 localfilesystem:$data_dir/debug-socket |
62 fi | 59 fi |
63 sleep 2 | 60 sleep 2 |
64 | 61 |
65 # Pull app_process and C libraries from device if needed | 62 # Pull app_process and C libraries from device if needed |
66 app_process=${shared_lib_dir}/app_process | 63 app_process=${shared_lib_dir}/app_process |
67 if [[ ! -f ${app_process} ]] ; then | 64 if [[ ! -f ${app_process} ]] ; then |
68 adb pull /system/bin/app_process ${app_process} | 65 adb pull /system/bin/app_process ${app_process} |
69 adb pull /system/lib/libc.so ${shared_lib_dir} | 66 adb pull /system/lib/libc.so ${shared_lib_dir} |
70 fi | 67 fi |
71 | 68 |
(...skipping 10 matching lines...) Expand all Loading... |
82 if [[ ! -f ${gdb} ]] ; then | 79 if [[ ! -f ${gdb} ]] ; then |
83 echo "Wow no gdb in env var ANDROID_TOOLCHAIN which is $ANDROID_TOOLCHAIN" | 80 echo "Wow no gdb in env var ANDROID_TOOLCHAIN which is $ANDROID_TOOLCHAIN" |
84 exit 4 | 81 exit 4 |
85 else | 82 else |
86 echo Using $gdb | 83 echo Using $gdb |
87 fi | 84 fi |
88 | 85 |
89 # ${gdb} -x $cmdfile $* $app_process | 86 # ${gdb} -x $cmdfile $* $app_process |
90 ${gdb} -x $cmdfile $* | 87 ${gdb} -x $cmdfile $* |
91 rm $cmdfile | 88 rm $cmdfile |
OLD | NEW |