天天看点

GDB+GDBServer调试技巧

调试文件

NDK中有对应文件

  • GDB客户端:android-ndk-r21b/prebuilt/linux-x86_64/bin/gdb
  • GDB Sever:prebuilt/android-arm/gdbserver、 prebuilt/android-arm64/gdbserver、

GDBServer启动

  • gd bserver --no-startup-with-shell :1234 my_program
  • adb forward tcp:1234 tcp:1234
  • target remote:1234
  • file my_program

设置库和源码搜索路径

  • set solib-search-path 设置so库查找路径
  • dir 设置源码搜索路径

具体搜索原理可参考下面文章

https://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html (source搜索路径)

https://blog.csdn.net/_xiao/article/details/23289971 (so库搜索路径)

常见命令:

命令名 命令缩写 命令说明

backtrace bt 查看函数调用堆栈

frame f 查看栈帧

list l 查看源码

print p 打印内部变量值

info i 查看程序状态

display disp 跟踪某变量,每次停下来则显示值

run r 开始运行程序

continue c 继续程序运行,直到下一个断点

break b 设置断点

start s 开始执行程序

step s 执行下一条语句,若该语句为函数调用,则进入函数内的第一条语句

next n 执行下一条语句,不会进入函数内部执行

watch

监视变量值的变化

file

装入需要调试的程序

set var name=v

设置变量的值

kill k 杀掉正在调试的程序

quit q 退出GDB环境

命令 含义

bt 打印当前线程调用栈

bt 10 打印tid=10的线程调用栈

thread apply all bt 打印所有线程的调用栈

f 5 切换到调用栈的第5层

t 10 切换到tid=10的线程

disassemble 查看汇编代码

info reg 查看当前的寄存器值

info threads 查看当前进程的所有线程

x /32wx 0x7198eb48 查看内存

p (Method)0x6d682328 查看符号

参考文档

http://gityuan.com/2017/09/09/gdb/ (常见命令)

https://sourceware.org/gdb/current/onlinedocs/gdb.pdf (官方文档)

https://sourceware.org/gdb/onlinedocs/gdb/Source-Path.html (source搜索路径)

https://blog.csdn.net/_xiao/article/details/23289971 (so库搜索路径)

继续阅读