工欲善其事必先利其器;
调试二进制文件
简单说:
被调试端:
./gdbserver :1234 ./a.out
调试端:
adb forward tcp:1234 tcp:1234
gdb >target remote localhost :1234
附加进程调试
如果是附加进程就是
./gdbserver :1234 --attach $pid_of_app
game=com.163.tmd.mobile/com.163.tmd.mobile.main
adb shell "am start -n $game " 1>/dev/null 2>&1
gamepid=`adb shell ps | grep speed | awk 'NR=="1"{print $2}'`
echo "game:$game.PID:$gamepid"
adb forward tcp:1234 tcp:1234
adb forward tcp:12345 jdwp:12345
#adb shell
gdbpid=`adb shell ps | grep gdbserver |awk 'NR=="1"{print $2}'`
if [ ! -z "$gdbpid" ]; then
echo "gdbserver is running:$gdbpid"
echo "gdbpid :"$gdbpid ."kill it!"
adb shell su -c "kill -9 $gdbpid"
else
echo "gdbserver first running! :=)"
fi
adb shell su -c "/data/local/tmp/gdbserver :1234 --attach $gamepid"
2018/9/27添加有一个脚本: