利用 GDB Debug Android SurfaceFlinger

gdbclient

相关文件:android-4.1.1_r1/build/envsetup.sh

function gdbclient()
{
   local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
   local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
   local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
   local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
   local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
   local ARCH=$(get_build_var TARGET_ARCH)
   local GDB
   case "$ARCH" in
       x86) GDB=i686-android-linux-gdb;;
       arm) GDB=arm-linux-androideabi-gdb;;
       *) echo "Unknown arch $ARCH"; return 1;;
   esac
 
   if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
       local EXE="$1"
       if [ "$EXE" ] ; then
           EXE=$1
       else
           EXE="app_process"
       fi
 
       local PORT="$2"
       if [ "$PORT" ] ; then
           PORT=$2
       else
           PORT=":5039"
       fi
 
       local PID
       local PROG="$3"
       if [ "$PROG" ] ; then
           if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
               PID="$3"
           else
               PID=`pid $3`
           fi
           adb forward "tcp$PORT" "tcp$PORT"
           adb shell gdbserver $PORT --attach $PID &
           sleep 2
       else
               echo ""
               echo "If you haven't done so already, do this first on the device:"
               echo "    gdbserver $PORT /system/bin/$EXE"
                   echo " or"
               echo "    gdbserver $PORT --attach $PID"
               echo ""
       fi
 
       echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
       echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines"
       echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
       echo >>"$OUT_ROOT/gdbclient.cmds" ""
 
       $ANDROID_TOOLCHAIN/$GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
  else
       echo "Unable to determine build system output dir."
   fi
 
}
gdbclient.cmds

gdbclient.cmds包含如下信息:

set solib-absolute-prefix /local/r/android-4.1.1_r1/out/target/product/diablohd/symbols
set solib-search-path /local/r/android-4.1.1_r1/out/target/product/diablohd/symbols/system/lib:/local/r/android-4.1.1_r1/out/target/product/diablohd/symbols/system/lib/hw:/local/r/android-4.1.1_r1/out/target/product/diablohd/symbols/system/lib/ssl/engines
target remote :5039

脚本用来生成所需的gdbclient.cmds:

create_gdbclient_cmds.sh
#! /bin/bash
 
P=${1}
D=${2}
 
if [ -z "${P}" -o -z "${D}" ] ; then
	echo "usage: ${0} <path> <product>"
	echo "    ${0} /local/projects/android-4.1.1_r1 diablo"
	exit 1
fi
 
cat << EOF > gdbclient.cmds
set solib-absolute-prefix ${P}/out/target/product/${D}/symbols
set solib-search-path ${P}/out/target/product/${D}/symbols/system/lib:${P}/out/target/product/${D}/symbols/system/lib/hw:${P}/out/target/product/${D}/symbols/system/lib/ssl/engines
target remote :5039
 
EOF

在一个terminal上执行:
$ adb forward tcp:5039 tcp:5039
$ adb shell gdbserver :5039 --attach `adb shell ps surfaceflinger | grep surfaceflinger | awk '{ print $2 }'`

在另外一个terminal上执行:

$ cd /local/projects/diablo-china-v1.0-dint
$ ./create_gdbclient_cmds.sh `pwd` jrdsh77_cu_jb
$ prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gdb -x gdbclient.cmds out/target/product/jrdsh77_cu_jb/symbols/system/bin/surfaceflinger


你可能感兴趣的:(利用 GDB Debug Android SurfaceFlinger)