常用gdb指令

44 阅读1分钟

一、调试方法

1.程序未启动 gdb bin_name

2.程序已启动 gdb attach pid (dettach)

3.crash: gdb bin_nanme core_file

二、断点

  1. break(b) function_name
  2. break filename:line_num
  3. enable n 开启第n个断点 disable n
  4. delete

三、查看

  1. info locals
  2. info threads
  3. info source
  4. info args

. bt 查看堆栈 . list 查看当前断点附近代码 l -10 往前显示10行; l +10 list 180 查看180行代码

四、打印

print (p) 输出变量的值

p this 输出当前对象的地址

p *this 输出各成员变量的值

p a+b+c 输出3个变量的结果

p func()

p server.port=8000

五、多线程

intfo threads

t 2 切换到线程2

f 2 查看2号堆栈