GDB 使用

  what ?

    GDB 是啥玩意,如果没听说过请移步这里哈哈http://www.gnu.org/software/gdb/。。。。。。。。。。。。。。

    why?

  话说今天被人问过GDB 都用过那些命令,想了想其实很多时候都是有需求了去查,没有系统的整理过,在这里整理一下,便于记忆,哎,上了年纪了记性越来越差了哈哈

   

  How?

   

    GDB 最常用的命令:

  •   附加可执行文件

  gdb   xxx

  gdb -p  xxx

  gdb -c xxx.core xxx

  •   进入程序后:

    基本的:

  r arg  : run

  c    : continue

  b   :b func, b linenum , b +/- offset ,      b filename:linename ,  b  filename:func     ,b address, b  if  <condition>

  info   breakpoints, 

  d       : delete

  clear  : 

  disable : .....

  condition:

  ignore <bnum> <count>

  bt  : backtrace 

  f    : frame

  l    :list 

  n   : next 

  s       : Execute next program line (after stopping); step into any function calls in the line

  p   : print expr

  q   : exit

  这里知识简单的列出了每个参数,具体的使用说明,可以直接 help cmd, gdb和shell 一样,使用某个命令时候 输入前几个,tab 就可以啦。。。 

 观察点:

  watch    expr

  rwatch    expr

  awatch  expr

  info    watchpoints

   线程相关:

  info threads 

  thread n

  

  有了上面zhexie命令,大家可以很容易的去定位问题啦..............

  --------------------------------------------------------我是华丽的分割线------------------------------------------------------------

  有了上面的基础,就可以继续进阶了, Letgo

  参考:

  http://sourceware.org/gdb/current/onlinedocs/gdb/

  http://blog.csdn.net/haoel/article/details/2880

原文地址:https://www.cnblogs.com/songbingyu/p/3761555.html