diff options
author | shouqun.liu@intel.com <shouqun.liu@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-12 08:16:25 +0000 |
---|---|---|
committer | shouqun.liu@intel.com <shouqun.liu@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-12 08:16:25 +0000 |
commit | 2b9a064c4e640291d7cb1d8f43afe3b42eea1c64 (patch) | |
tree | 8a119e7c171cffd87fc24c964f5bcc773ca07cd9 /build | |
parent | f638994b4b074b894c848d132225c5b49b22e2d4 (diff) | |
download | chromium_src-2b9a064c4e640291d7cb1d8f43afe3b42eea1c64.zip chromium_src-2b9a064c4e640291d7cb1d8f43afe3b42eea1c64.tar.gz chromium_src-2b9a064c4e640291d7cb1d8f43afe3b42eea1c64.tar.bz2 |
Enhancement for gdb_content_shell, allow package_name and shared_lib_dir to be
set from arguments. This enables debug other pieces such as base_unittests_apk
For example, to debug native tests, run with:
gdb_apk -p org.chromium.native_test -l $CHROME_SRC/out/Release/lib.target -r
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10736027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146299 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rwxr-xr-x | build/android/gdb_apk | 139 | ||||
-rwxr-xr-x | build/android/gdb_content_shell | 83 |
2 files changed, 144 insertions, 78 deletions
diff --git a/build/android/gdb_apk b/build/android/gdb_apk new file mode 100755 index 0000000..bcdcd24 --- /dev/null +++ b/build/android/gdb_apk @@ -0,0 +1,139 @@ +#!/bin/bash +# +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Attach gdb to a running android application. Similar to ndk-gdb. +# Run with --annotate=3 if running under emacs (M-x gdb). +# +# By default it is used to debug content shell, if it is used to +# debug other piceces, '-p' and '-l' options are needed. +# For *unittests_apk (like base_unittests_apk), run with: +# "gdb_apk -p org.chromium.native_test -l out/Release/lib.target -r" + +adb=$(which adb) +if [[ "$adb" = "" ]] ; then + echo "Need adb in your path" + exit 1 +fi + +usage() { + echo "usage: ${0##*/} [-p package_name] [-l shared_lib_dir] [-g gdb] [-r]" + echo "-p package_name the android APK package to be debugged" + echo "-l shared_lib_dir directory containes native shared library" + echo "-g gdb_args agruments for gdb, eg: -g '-n -write'" + echo "-r the target device is rooted" +} + +process_options() { + local OPTNAME OPTIND OPTERR OPTARG + while getopts ":p:l:g:r" OPTNAME; do + case "$OPTNAME" in + p) + package_name="$OPTARG" + ;; + l) + shared_lib_dir="$OPTARG" + ;; + g) + gdb_args="$OPTARG" + ;; + r) + rooted_phone=1 + ;; + \:) + echo "'-$OPTARG' needs an argument." + usage + exit 1 + ;; + *) + echo "invalid command line option: $OPTARG" + usage + exit 1 + ;; + esac + done + + if [ $# -ge ${OPTIND} ]; then + eval echo "Unexpected command line argument: \${${OPTIND}}" + usage + exit 1 + fi +} + +rooted_phone=0 + +root=$(dirname $0)/../.. +package_name=org.chromium.content_shell +shared_lib_dir=$root/out/Release/lib.target +gdb_args='' + +#process options +process_options "$@" +echo "Debug package $package_name" + +data_dir=/data/data/$package_name +gdb_server_on_device=$data_dir/lib/gdbserver + +# Kill any running gdbserver +pid=$(adb shell ps | awk '/gdbserver/ {print $2}') +if [[ "$pid" != "" ]] ; then + if [[ $rooted_phone -eq 1 ]] ; then + adb shell kill $pid + else + adb shell run-as $package_name kill $pid + fi +fi + +pid=$(adb shell ps | awk "/$package_name/ {print \$2}") +if [[ "$pid" = "" ]] ; then + echo "No $package_name running?" + echo "Try this: adb shell am start -a android.intent.action.VIEW " \ + "-n $package_name/.SomethingActivity (Something might be ContentShell)" + exit 2 +fi + +no_gdb_server=$(adb shell ls $gdb_server_on_device | grep 'No such file') +if [[ "$no_gdb_server" != "" ]] ; then + echo "No gdb server on device at $gdb_server_on_device" + echo "Please install a debug build." + exit 3 +fi + +if [[ $rooted_phone -eq 1 ]] ; then + adb shell $gdb_server_on_device :4321 --attach $pid & + adb forward tcp:4321 tcp:4321 +else + adb shell run-as $package_name lib/gdbserver +debug-socket --attach $pid & + adb forward tcp:4321 localfilesystem:$data_dir/debug-socket +fi +sleep 2 + +# Pull app_process and C libraries from device if needed +app_process=${shared_lib_dir}/app_process +if [[ ! -f ${app_process} ]] ; then + adb pull /system/bin/app_process ${app_process} + adb pull /system/lib/libc.so ${shared_lib_dir} +fi + +# gdb commands +cmdfile=$(mktemp /tmp/gdb_android_XXXXXXXX) +cat >$cmdfile<<EOF +# set solib-absolute-prefix null +set solib-search-path ${shared_lib_dir} +file ${app_process} +target remote :4321 +EOF + +gdb=$(echo $ANDROID_TOOLCHAIN/*gdb) +if [[ ! -f ${gdb} ]] ; then + echo "Wow no gdb in env var ANDROID_TOOLCHAIN which is $ANDROID_TOOLCHAIN" + exit 4 +else + echo Using $gdb +fi + +# ${gdb} -x $cmdfile $* $app_process +${gdb} -x $cmdfile $gdb_args +rm $cmdfile diff --git a/build/android/gdb_content_shell b/build/android/gdb_content_shell index 2f0b983..27cc3b4 100755 --- a/build/android/gdb_content_shell +++ b/build/android/gdb_content_shell @@ -4,85 +4,12 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # -# Attach gdb to a running content shell. Similar to ndk-gdb. -# Run with --annotate=3 if running under emacs (M-x gdb). -# -# TODO(jrg): allow package_name and shared_lib_dir to be set on the -# command line. Share the guts of this script with other Chromium -# pieces (like base_unittests_apk) and friends (like WebKit bundles). - -adb=$(which adb) -if [[ "$adb" = "" ]] ; then - echo "Need adb in your path" - exit 1 -fi +# Attach gdb to a running content shell. Redirect to the shell gdb_apk -rooted_phone=0 +ROOT=$(cd "$(dirname $0)"; pwd) -root=$(dirname $0)/../.. -package_name=org.chromium.content_shell -data_dir=/data/data/$package_name -gdb_server_on_device=$data_dir/lib/gdbserver -shared_lib_dir=$root/out/Release/lib.target - -# Kill any running gdbserver -pid=$(adb shell ps | awk '/gdbserver/ {print $2}') -if [[ "$pid" != "" ]] ; then - if [[ $rooted_phone -eq 1 ]] ; then - adb shell kill $pid - else - adb shell run-as $package_name kill $pid - fi -fi - -pid=$(adb shell ps | awk "/$package_name/ {print \$2}") -if [[ "$pid" = "" ]] ; then - echo "No $package_name running?" - echo "Try this: adb shell am start -a android.intent.action.VIEW " \ - "-n $package_name/.SomethingActivity (Something might be ContentShell)" - exit 2 -fi - -no_gdb_server=$(adb shell ls $gdb_server_on_device | grep 'No such file') -if [[ "$no_gdb_server" != "" ]] ; then - echo "No gdb server on device at $gdb_server_on_device" - echo "Please install a debug build." - exit 3 -fi - -if [[ $rooted_phone -eq 1 ]] ; then - adb shell $gdb_server_on_device :4321 --attach $pid & - adb forward tcp:4321 tcp:4321 -else - adb shell run-as $package_name lib/gdbserver +debug-socket --attach $pid & - adb forward tcp:4321 localfilesystem:$data_dir/debug-socket -fi -sleep 2 - -# Pull app_process and C libraries from device if needed -app_process=${shared_lib_dir}/app_process -if [[ ! -f ${app_process} ]] ; then - adb pull /system/bin/app_process ${app_process} - adb pull /system/lib/libc.so ${shared_lib_dir} -fi - -# gdb commands -cmdfile=$(mktemp /tmp/gdb_android_XXXXXXXX) -cat >$cmdfile<<EOF -# set solib-absolute-prefix null -set solib-search-path ${shared_lib_dir} -file ${app_process} -target remote :4321 -EOF - -gdb=$(echo $ANDROID_TOOLCHAIN/*gdb) -if [[ ! -f ${gdb} ]] ; then - echo "Wow no gdb in env var ANDROID_TOOLCHAIN which is $ANDROID_TOOLCHAIN" - exit 4 +if [ $# -gt 0 ]; then + exec $ROOT/gdb_apk -r -g "$*" else - echo Using $gdb + exec $ROOT/gdb_apk -r fi - -# ${gdb} -x $cmdfile $* $app_process -${gdb} -x $cmdfile $* -rm $cmdfile |