首页 > 代码库 > GDB + gdbserver 远程调试android native code

GDB + gdbserver 远程调试android native code

以调试模拟器中的native library code为例。

Host: ubuntu
Target: Android ICS

1.将gdbserver放入设备。

确保系统有arm-*-gdb,及存在设备端将要运行的gdbserver,gdbserver可以由google ndk中获取,在ndk的如下目录可以找到这个文件:

点击(此处)折叠或打开

  1. android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt

然后,通过adb shell进入设备,在/data下创建bin 目录:

点击(此处)折叠或打开

  1. hanpfei@hanpfei-F6Ve:/mnt/android_proj/android_src$ adb shell
  2. #mkdir /data/bin/

再通过adb push命令将gdbserver 放入设备:

点击(此处)折叠或打开

  1. hanpfei@hanpfei-F6Ve:/mnt/android_proj/softwares/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt$ ls
  2. gdbserver linux-x86
  3. hanpfei@hanpfei-F6Ve:/mnt/android_proj/softwares/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt$ adb remount
  4. remount succeeded
  5. hanpfei@hanpfei-F6Ve:/mnt/android_proj/softwares/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt$ adb push gdbserver /data/bin/
  6. 543 KB/s (125208 bytes in 0.225s)

2、在设备端启动gdbserver并attach到所要debug的进程

点击(此处)折叠或打开

  1. system 1168 37 156620 31924 ffffffff 40011384 S com.android.keychain
  2. app_34 2758 37 158360 34572 ffffffff 40011384 S com.hanpfei.text
  3. root 2774 617 900 348 00000000 40010438 R ps
  4. # gdbserver :1234 --attach 2758
  5. Attached; pid = 2758
  6. Listening on port 1234

gdbserver后面跟的第一个参数为端口号,之后的--atach 为gdbserver的选项,之后的数字为所要调试的进程的PID。

3、在Host端启动arm-*-gdb

网上有高手build的各种交叉编译工具链来方便大家的嵌入式开发,单这个工具链中的gdb命令实际文件名称的前缀和后缀都会是相同的,中间的那个*可以见到各种各样的形式,比如linux,linux-androideabi,none-linux-gnueabi等等。

点击(此处)折叠或打开

  1. hanpfei@hanpfei-F6Ve:/mnt/android_proj/softwares/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin$ ./arm-linux-androideabi-gdb
  2. GNU gdb 6.6
  3. Copyright (C) 2006 Free Software Foundation, Inc.
  4. GDB is free software, covered by the GNU General Public License, and you are
  5. welcome to change it and/or distribute copies of it under certain conditions.
  6. Type "show copying" to see the conditions.
  7. There is absolutely no warranty for GDB. Type "show warranty" for details.
  8. This GDB was configured as "--host=i386-linux-gnu --target=arm-elf-linux".
  9. (gdb) shell adb forward tcp:1234 tcp:1234
  10. (gdb) target remote localhost:1234
  11. Remote debugging using localhost:1234
  12. [New Thread 2758]
  13. Malformed packet(b) (missing colon): re:0;
  14. Packet: ‘T050b:7476b6be;0d:b874b6be;0f:84130140;thread:ac6;core:0;‘
  15. (gdb)

使用ndk中所带的交叉编译工具链,会出现报错信息,意为畸形数据包:

点击(此处)折叠或打开

  1. [New Thread 2758]
  2. Malformed packet(b) (missing colon): re:0;
  3. Packet: ‘T050b:7476b6be;0d:b874b6be;0f:84130140;thread:ac6;core:0;‘

同时,在设备端也可以看到有如下的输出,来显示着这server端与client端难以协调的步调:

点击(此处)折叠或打开

  1. # gdbserver :1234 --attach 2758
  2. Attached; pid = 2758
  3. Listening on port 1234
  4. Remote debugging from host 127.0.0.1
  5. readchar: Got EOF
  6. Remote side has terminated connection. GDBserver will reopen the connection.
  7. Listening on port 1234

出现这样的状况,是由于gdbserver和arm-*-gdb版本不对应所致。由上面我们启动arm-linux-androideabi-gdb时的输出可以看到,其版本为GNU gdb 6.6。在设备上,我们可以查看gdbserver的版本信息:

点击(此处)折叠或打开

  1. # gdbserver --version
  2. GNU gdbserver (GDB) 7.1-android-gg2
  3. Copyright (C) 2010 Free Software Foundation, Inc.
  4. gdbserver is free software, covered by the GNU General Public License.
  5. This gdbserver was configured as "arm-elf-linux"
  6. #

我们可以看到gdbserver版本为GNU gdbserver (GDB) 7.1-android-gg2。这也就是症结所在。

我们可以换用和gdbserver版本较为接近的arm-*-gdb。此时在host端所需输入的命令及相应的输出如下:

点击(此处)折叠或打开

  1. hanpfei@hanpfei-F6Ve:~/develop_tool_chain/arm-2011.03/bin$ ./arm-none-linux-gnueabi-gdb
  2. GNU gdb (Sourcery G++ Lite 2011.03-41) 7.2.50.20100908-cvs
  3. Copyright (C) 2010 Free Software Foundation, Inc.
  4. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  5. This is free software: you are free to change and redistribute it.
  6. There is NO WARRANTY, to the extent permitted by law. Type "show copying"
  7. and "show warranty" for details.
  8. This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi".
  9. For bug reporting instructions, please see:
  10. <https://support.codesourcery.com/GNUToolchain/>.
  11. (gdb) shell adb forward tcp:1234 tcp:1234
  12. (gdb) target remote localhost:1234
  13. Remote debugging using localhost:1234
  14. 0x40011384 in ?? ()
  15. (gdb)
启动gdb,然后是执行shell命令(shell adb forward tcp:1234 tcp:1234) , 以完成端口映射的任务,靠前的那个为local端的端口,靠后的那个为remote端的。
 
于此同时,在设备端也将看到有如下的输出:

点击(此处)折叠或打开

  1. Listening on port 1234
  2. Remote debugging from host 127.0.0.1

这即是表明,gdb client端和server端有成功的链接。

 

接下来通过file命令来加载将要调试的可执行文件,对于android application来说,均为 out/target/product/generic/symbols/system/bin/app_process 这个文件,及设置搜索solib的搜索路径

点击(此处)折叠或打开

  1. (gdb) target remote localhost:1234
  2. Remote debugging using localhost:1234
  3. 0x40011384 in ?? ()
  4. (gdb) /mnt/android_proj/android_src/out/target/product/generic/symbols/system/bin/app_process
  5. Undefined command: "". Try "help".
  6. (gdb) file /mnt/android_proj/android_src/out/target/product/generic/symbols/system/bin/app_process
  7. A program is being debugged already.
  8. Are you sure you want to change the file? (y or n) y
  9. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/bin/app_process...done.
  10. (gdb) set solib-search-path /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib
  11. warning: Could not load shared library symbols for 3 libraries, e.g. /system/bin/linker.
  12. Use the "info sharedlibrary" command to see the complete listing.
  13. Do you need "set solib-search-path" or "set sysroot"?
  14. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libc.so...done.
  15. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libc.so
  16. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstdc++.so...done.
  17. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstdc++.so
  18. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libm.so...done.
  19. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libm.so
  20. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/liblog.so...done.
  21. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/liblog.so
  22. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libcutils.so...done.
  23. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libcutils.so
  24. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libz.so...done.
  25. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libz.so
  26. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libutils.so...done.
  27. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libutils.so
  28. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libbinder.so...done.
  29. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libbinder.so
  30. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libexpat.so...done.
  31. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libexpat.so
  32. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libcrypto.so...done.
  33. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libcrypto.so
  34. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libgabi++.so...done.
  35. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libgabi++.so
  36. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libicuuc.so...done.
  37. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libicuuc.so
  38. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libicui18n.so...done.
  39. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libicui18n.so
  40. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libssl.so...done.
  41. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libssl.so
  42. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstlport.so...done.
  43. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstlport.so
  44. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libnativehelper.so...done.
  45. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libnativehelper.so
  46. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libnetutils.so...done.
  47. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libnetutils.so
  48. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv2_dbg.so...done.
  49. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv2_dbg.so
  50. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libEGL.so...done.
  51. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libEGL.so
  52. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libwpa_client.so...done.
  53. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libwpa_client.so
  54. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libhardware_legacy.so...done.
  55. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libhardware_legacy.so
  56. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libpixelflinger.so...done.
  57. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libpixelflinger.so
  58. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libhardware.so...done.
  59. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libhardware.so
  60. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libemoji.so...done.
  61. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libemoji.so
  62. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libjpeg.so...done.
  63. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libjpeg.so
  64. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libskia.so...done.
  65. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libskia.so
  66. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libui.so...done.
  67. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libui.so
  68. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv2.so...done.
  69. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv2.so
  70. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libgui.so...done.
  71. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libgui.so
  72. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libcamera_client.so...done.
  73. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libcamera_client.so
  74. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libsqlite.so...done.
  75. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libsqlite.so
  76. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libdvm.so...done.
  77. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libdvm.so
  78. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv1_CM.so...done.
  79. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv1_CM.so
  80. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libETC1.so...done.
  81. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libETC1.so
  82. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libsonivox.so...done.
  83. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libsonivox.so
  84. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_foundation.so...done.
  85. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_foundation.so
  86. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libmedia.so...done.
  87. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libmedia.so
  88. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libnfc_ndef.so...done.
  89. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libnfc_ndef.so
  90. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libusbhost.so...done.
  91. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libusbhost.so
  92. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libharfbuzz.so...done.
  93. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libharfbuzz.so
  94. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libandroid_runtime.so...done.
  95. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libandroid_runtime.so
  96. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libvorbisidec.so...done.
  97. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libvorbisidec.so
  98. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_yuv.so...done.
  99. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_yuv.so
  100. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libdrmframework.so...done.
  101. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libdrmframework.so
  102. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libchromium_net.so...done.
  103. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libchromium_net.so
  104. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_amrnb_common.so...done.
  105. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_amrnb_common.so
  106. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_enc_common.so...done.
  107. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_enc_common.so
  108. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_avc_common.so...done.
  109. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright_avc_common.so
  110. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright.so...done.
  111. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libstagefright.so
  112. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libmtp.so...done.
  113. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libmtp.so
  114. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libexif.so...done.
  115. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libexif.so
  116. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libmedia_jni.so...done.
  117. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libmedia_jni.so
  118. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libbcc.so...done.
  119. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libbcc.so
  120. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libbcinfo.so...done.
  121. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libbcinfo.so
  122. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libRS.so...done.
  123. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libRS.so
  124. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/librs_jni.so...done.
  125. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/librs_jni.so
  126. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libandroid.so...done.
  127. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libandroid.so
  128. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libwebcore.so...done.
  129. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libwebcore.so
  130. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/lib_renderControl_enc.so...done.
  131. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/lib_renderControl_enc.so
  132. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv2_enc.so...done.
  133. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv2_enc.so
  134. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv1_enc.so...done.
  135. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libGLESv1_enc.so
  136. Reading symbols from /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libOpenglSystemCommon.so...done.
  137. Loaded symbols for /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib/libOpenglSystemCommon.so
  138. warning: Unable to find dynamic linker.
  139. GDB will be unable to debug shared library initializers
  140. and track explicitly loaded dynamic code.
  141. (gdb) set solib-absolute-prefix /mnt/android_proj/android_src/out/target/product/generic/symbols/system/lib
  142. warning: Unable to find dynamic linker.
  143. GDB will be unable to debug shared library initializers
  144. and track explicitly loaded dynamic code.
  145. (gdb)
此处所设置的路径下应该存在有编译好的带有符号的链接库文件,此处的设置,回事gdb读取这些库文件中的符号。可以通过directory命令来为gdb增加搜索原代码的路径。
 

之后,即可如调试PC端的C/C++ code一样,下断点,执行,查看内存内容,查看back trace等,来进行对library的debug工作:

点击(此处)折叠或打开

  1. (gdb) break HB_ShapeItem
  2. Note: breakpoint 1 also set at pc 0x4094bf2c.
  3. Breakpoint 2 at 0x4094bf2c: file external/harfbuzz/src/harfbuzz-shaper.cpp, line 1340.
  4. (gdb) info break
  5. Num Type Disp Enb Address What
  6. 2 breakpoint keep y 0x4094bf2c in HB_ShapeItem(HB_ShaperItem*) at external/harfbuzz/src/harfbuzz-shaper.cpp:1340
  7. (gdb) continue
  8. Continuing.
  9. Breakpoint 2, HB_ShapeItem (shaper_item=0xbeb6729c) at external/harfbuzz/src/harfbuzz-shaper.cpp:1340
  10. 1340     if (shaper_item->num_glyphs < shaper_item->item.length) {
  11. (gdb) n
  12. 1338    {
  13. (gdb) s
  14. 1340     if (shaper_item->num_glyphs < shaper_item->item.length) {
  15. (gdb) list
  16. 1335    }
  17. 1336    
  18. 1337    HB_Bool HB_ShapeItem(HB_ShaperItem *shaper_item)
  19. 1338    {
  20. 1339     HB_Bool result = false;
  21. 1340     if (shaper_item->num_glyphs < shaper_item->item.length) {
  22. 1341     shaper_item->num_glyphs = shaper_item->item.length;
  23. 1342     return false;
  24. 1343     }
  25. 1344     assert(shaper_item->item.script < HB_ScriptCount);
  26. (gdb)

 

gdb常用调试命令

0、查看程序源代码

    directory(dir) DIR

    Add directory DIR to beginning of search path for source files.Forget cached info on

          source file locations and line positions. DIR can also be $cwd for the current working directory, or $cdir for
          the directory in which the source file was compiled into object code.  With no argument, reset the search path

          to $cdir:$cwd, the default.

    show directories Current search path for finding source files.
    list 
    List specified function or line. With no argument, lists ten more lines
    after or around previous listing. "list -" lists the ten lines before a
    previous ten-line listing. One argument specifies a line, and ten lines 
    are listed around that line. Two arguments with comma between specify
    starting and ending lines to list. Lines can be specified in these ways:
      LINENUM, to list around that line in current file,
      FILE:LINENUM, to list around that line in that file,
      FUNCTION, to list around beginning of that function,
      FILE:FUNCTION, to distinguish among like-named static functions.
      *ADDRESS, to list around the line containing that address.
     set listsize Num Set number of source lines gdb will list by default.
     disassemble Disassemble a specified section of memory.

1、程序运行时参数。
    set args 可指定运行时参数。(如:set args 10 20 30 40 50)
    show args 命令可以查看设置好的运行参数。

2、运行环境。
    path <dir>  Add directory DIR(s) to beginning of search path for object files.
    show paths  Current search path for finding object files.
    set environment VAR [=value] 设置环境变量。如:set env HOME=/home

    unset environment VAR Cancel environment variable VAR for the program.
    show environment [varname] 查看环境变量。

3、工作目录。
    cd <dir> 相当于shell的cd命令。
    pwd 显示当前的所在目录。

4、程序的输入输出
    info terminal 显示你程序用到的终端的模式。
    使用重定向控制程序输出。如:run > outfile
    tty命令可以指写输入输出的终端设备。如:tty /dev/ttyb

5、设置断点(BreakPoint)
    我们用break命令来设置断点。正面有几点设置断点的方法:
    break <function> 
    在进入指定函数时停住。C++中可以使用class::function或function(type,type)格式来指定函数名。

    break <linenum> 在指定行号设置断点。

    break +offset 
    break -offset 
    在当前行号的前面或后面的offset行停住。offiset为自然数。

    break filename:linenum  在特定源文件filename的特定行linenum处设置断点。

    break filename:function 在源文件filename的function函数的入口处停住。

    break *address          在程序运行的内存地址处停住。

    break                   break命令没有参数时,表示在下一条指令处停住。

    break ... if <condition>
    ...可以是上述的参数,condition表示条件,在条件成立时停住。比如在循环体中,可以设置break if i=100,表示当i为100时停住程序。

    查看断点,可使用info命令,如下所示:(注:n表示断点号)
    info breakpoints [n] 
    info break [n] 

    delete Delete some breakpoints or auto-display expressions.

    disable Disable some breakpoints.

    enable Enable some breakpoints.

6、设置观察点(WatchPoint)
    观察点一般用来观察某个表达式(变量也是一种表达式)的值是否有变化,如果有变化,马上停住程序。我们有下面的几种方法来设置观察点:
    watch <expr>       为表达式(变量)expr设置一个观察点。一旦表达式值有变化,马上停住程序。
    rwatch <expr>      当表达式(变量)expr被读时,停住程序。
    awatch <expr>     当表达式(变量)的值被读或被写时,停住程序。
    info watchpoints   列出当前所设置了的所有观察点。

7、设置捕捉点(CatchPoint)

    可设置捕捉点来补捉程序运行时的一些事件。如:载入共享库(动态链接库)或是C++的异常。设置捕捉点的格式为:
    catch <event>   当event发生时,停住程序。event可以是下面的内容:
    1、throw 一个C++抛出的异常。(throw为关键字)
    2、catch 一个C++捕捉到的异常。(catch为关键字)
    3、exec 调用系统调用exec时。(exec为关键字,目前此功能只在HP-UX下有用)
    4、fork 调用系统调用fork时。(fork为关键字,目前此功能只在HP-UX下有用)
    5、vfork 调用系统调用vfork时。(vfork为关键字,目前此功能只在HP-UX下有用)
    6、load 或 load <libname> 载入共享库(动态链接库)时。(load为关键字,目前此功能只在HP-UX下有用)
    7、unload 或 unload <libname> 卸载共享库(动态链接库)时。(unload为关键字,目前此功能只在HP-UX下有用)

    tcatch <event> 设置一次捕捉点,当程序停住以后,相应捕捉点被自动删除。

8、运行程序

    run(r) Start debugged program.。

    continue(c) [ignore-count]

    fg [ignore-count]
    恢复程序运行,直到程序结束,或是下一个断点到来。ignore-count表示其后
忽略断点的次数。continue,c,fg三个命令都是一样的意思。

    step N  Step program until it reaches a different source line.

    Argument N means do this N times (or till program stops for another reason).单步跟踪,如果有函数调用,他会进入该函数。进入函数的前提是,此函数被编译有debug信息。

    next N
    同样单步跟踪,如果有函数调用,他不会进入该函数。
后面的count参数可选,不加表示一条条地执行,加表示执行后面的count行code,然后再停住。

    kill Kill execution of program being debugged.

    set step-mode
    set step-mode on
    打开step-mode模式,在进行单步跟踪时,程序不会因为没有debug信息而不停住。这个参数有很利于查看机器码。

    set step-mod off  关闭step-mode模式。

    finish            运行程序,直到当前函数完成返回。并打印函数返回时的堆栈地址和返回值及参数值等信息。

    until(u)          这个命令可以运行程序直到退出循环体。

    stepi(si)
    nexti(ni)

    单步跟踪一条机器指令!一条程序代码有可能由数条机器指令完成,stepi和nexti可以单步执行机器指令。与之一样有相同功能的命令是“display/i $pc” ,当运行完这个命令后,单步跟踪会在打出程序代码的同时打出机器指令(也就是汇编代码).

9、查看表达式的值

   print EXP Print value of expression EXP.

   display EXP Print value of expression EXP each time the program stops.

   undisplay Cancel some expressions to be displayed when program stops.

   info display Expressions to display when program stops, with code numbers.

   whatis EXP Print data type of expression EXP.

   ptype TYPE Print definition of type TYPE.

   info locals Local variables of current stack frame.

10、查看Call Stack

   backtrace(bt)/where COUNT Print backtrace of all stack frames, or innermost COUNT frames.

   frame Select and print a stack frame.

   up Select and print stack frame that called this one.

   down Select and print stack frame called by this one.

   info args Argument variables of current stack frame.

11、Files

   file FILE Use FILE as program to be debugged.

   add-symbol-file FILE ADDR [-s <SECT> <SECT_ADDR> -s <SECT> <SECT_ADDR> ...]

   Load symbols from FILE, assuming FILE has been dynamically loaded. ADDR is the starting address of the file‘s text.

12、共享库

   sharedlibrary Load shared object library symbols for files matching REGEXP.

   info sharedlibrary Status of loaded shared object libraries.

   set solib-search-path Set the search path for loading non-absolute shared library symbol files.This takes precedence over the environment variables PATH and LD_LIBRARY_PATH.

   set solib-absolute-prefix Set an alternate system root. The system root is used to load absolute shared library symbol files.

13、Support

   shell Execute the rest of the line as a shell command.

   source [-s] [-v] FILE Read commands from a file named FILE.用于执行gdb调试脚本

   dump memory FILE START STOP Write contents of memory to a raw binary file. Writes the contents of memory within the range [START .. STOP) to the specifed FILE in raw target ordered bytes.

   info threads IDs of currently known threads.

   thread thread_ID Use this command to switch between threads. The new thread ID must be currently known.

   target remote ip:port Use a remote computer via a serial line, using a gdb-specific protocol. Specify the serial device it is connected to

GDB + gdbserver 远程调试android native code