使用GDB调试android模拟器

来源:互联网 发布:java培训工资 编辑:程序博客网 时间:2024/05/22 15:14

使用android的模拟器可以调试应用,也可以调试C/C++代码库。

调试C/C++代码时,还可以使用GDB单步调试代码,跟linux上一样方便。

1. 准备android代码:从官网上下载代码,编译整个系统,最好选X86的选项

   $source buid/envsetup.sh

   $lunch

    Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. aosp_shamu-userdebug
     8. aosp_hammerhead-userdebug
     9. aosp_mako-userdebug
     10. aosp_flounder-userdebug
     11. aosp_manta-userdebug
     12. aosp_grouper-userdebug
     13. aosp_tilapia-userdebug
     14. aosp_deb-userdebug
     15. aosp_flo-userdebug
     16. full_fugu-userdebug
     17. aosp_fugu-userdebug
     18. m_e_arm-userdebug
     19. mini_emulator_x86-userdebug
     20. mini_emulator_arm64-userdebug
     21. mini_emulator_mips-userdebug
     22. mini_emulator_x86_64-userdebug

不同的系统,选项次序可能不同。在PC机上用模拟器调试最好直接选用x86的编译选项

2. 编译得到的系统便可以启动模拟器运行,如果要启用GPU加快渲染速度,使用: emulator -gpu on

 以调试httplive为例,说明如何调试C/C++代码

1. 由于httplive属于android多媒体服务,因此,可以查看media的线程号来调试

   $adb shell ps

system    937   1     10204  848   813e089c b2eda017 S /system/bin/servicemanager
root      938   1     16184  2608  ffffffff 9c993ab7 S /system/bin/vold
system    939   1     37664  4168  ffffffff d13ee93a S /system/bin/surfaceflinger
root      941   1     9924   760   8110c261 acaa993a S /system/bin/qemud
shell     944   1     10156  1104  81237267 5621c9f7 S /system/bin/sh
root      945   1     13244  524   ffffffff 0042472a D /sbin/adbd
root      946   1     12012  1604  8103d5cc 67b16a7a D /system/bin/netd
root      947   1     10884  1060  813f581c f7684003 S /system/bin/debuggerd
root      948   1     11084  1224  813f581c eac4cc7a S /system/bin/debuggerd64
radio     949   1     15736  1864  ffffffff b9313ab7 S /system/bin/rild
drm       950   1     24192  4492  ffffffff f761fe66 S /system/bin/drmserver
media     951   1     30272  6608  8109bebb f776dbd9 D /system/bin/mediaserver
install   952   1     10216  876   813f581c e9026c7a S /system/bin/installd
keystore  953   1     14616  2728  813e089c 2738d017 S /system/bin/keystore
root      954   1     382728 27000 ffffffff 2461825d D zygote64
root      955   1     358568 21804 ffffffff f3a03246 D zygote
root      963   2     0      0     8106d1a8 00000000 S kauditd
graphics  983   1     34252  7780  ffffffff 6e130017 S /system/bin/bootanimation
root      1242  945   12264  1476  00000000 6cbf59f7 R ps
root      1244  946   12012  464   00000000 67ab91a8 R /system/bin/netd

   $gdbclient 951

   在某一行打断点:b xxx.cpp:35

   接着继续运行: c

2. 启动应用上的播放器,可以看到gdb已经可以运行了,这个时候的调试就跟linux上的gdb完全一样了

3. 由于android上的gdb 调试属于远程调试,因此,无法像linux上一样继续重新运行:run

    需要退出当前的gdb,重新进入,这个时候就需要把media进程杀掉,重新看一下media属于那个线程号,重复步骤1


尽管gdb的调试比linux上要麻烦点,但是能够单步调试,对于开发者来说已经很方便了。

0 0
原创粉丝点击