你如何使用gdb? [英] How do you use gdb?

查看:18
本文介绍了你如何使用gdb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定了解我们的 C/C+ *nix 实践者如何使用 gdb 调试器.

I decided to find out how our C/C+ *nix practitioners use the gdb debugger.

这是我通常使用的:

  1. b - break filename.c:line #, function, filename.cpp:function, className::Member
  2. n, c, s -- 下一步继续
  3. gdb程序名=>设置断点==>运行[参数列表](我这样做是为了在程序启动前设置断点)
  4. l - 列出周围的源代码.
  5. 附加进程ID6 休息 [地点]
  6. gdb programName corefile.core(检查应用崩溃的原因)
  7. 我有时也会在退出函数(break exit)处设置断点来检查程序堆栈
  8. info b 检查所有断点
  9. 清除[断点列表]

你如何使用它?

推荐答案

我认为最有用的 gdb 命令(除了所有已经列出的):

Most useful gdb commands in my opinion (aside from all already listed):

  • 线程信息 - 关于线程的信息
  • 线程N - 切换到线程N
  • catch throw - 中断任何抛出的异常.当您仅在堆栈展开后发现错误时很有用.
  • printf,print - 检查所有表达式,printf 接受 C 样式格式说明符
  • info threads - information about threads
  • thread N - switch to thread N
  • catch throw - break on any thrown exception. Useful when you caught the bug only after the stack unwound.
  • printf,print - examine any and all expressions, printf accepts C-style formatting specifiers

最后,如果通过慢速链接进行调试,文本 UI 可能会派上用场.要使用它,请使用 --tui 命令行开关启动 gdb.

Finally, if debugging over a slow link, the text UI might be of use. To use it, start gdb with the --tui command-line switch.

这篇关于你如何使用gdb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆