gdb 调试器最棘手/有用的命令

发布于 2024-08-05 21:34:43 字数 43 浏览 6 评论 0原文

您可以在运行 gdb 或 dbx 等调试器时发布最棘手和最有用的命令吗?

Can you post your most tricky and useful commands while you run a debugger like gdb or dbx.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

北风几吹夏 2024-08-12 21:34:43
  1. backtrace full:使用局部变量完成回溯
  2. updownframe:在帧之间移动
  3. watch< /em>:满足特定条件时暂停进程
  4. 设置打印漂亮:打印出格式漂亮的C源代码
  5. 设置日志记录:记录调试会话以向其他人显示支持
  6. 设置打印数组:漂亮的数组打印
  7. 完成:继续直到函数结束
  8. 启用禁用:启用/disable Breakpoints
  9. tbreak:中断一次,然后删除断点
  10. where:当前执行的行号
  11. info locals:查看所有局部变量
  12. >info args:查看所有函数参数
  13. list:查看源代码
  14. rbreak:在函数匹配正则表达式时中断
  1. backtrace full: Complete backtrace with local variables
  2. up, down, frame: Move through frames
  3. watch: Suspend the process when a certain condition is met
  4. set print pretty on: Prints out prettily formatted C source code
  5. set logging on: Log debugging session to show to others for support
  6. set print array on: Pretty array printing
  7. finish: Continue till end of function
  8. enable and disable: Enable/disable breakpoints
  9. tbreak: Break once, and then remove the breakpoint
  10. where: Line number currently being executed
  11. info locals: View all local variables
  12. info args: View all function arguments
  13. list: view source
  14. rbreak: break on function matching regular expression
何其悲哀 2024-08-12 21:34:43

使用文本用户界面启动 gdb

gdb -tui

Start gdb with a textual user interface

gdb -tui
小鸟爱天空丶 2024-08-12 21:34:43

从 gdb 7.0 开始,有可逆调试,因此您最喜欢的新命令是:

* reverse-continue ('rc') -- Continue program being debugged but run it in reverse
* reverse-finish -- Execute backward until just before the selected stack frame is called
* reverse-next ('rn') -- Step program backward, proceeding through subroutine calls.
* reverse-nexti ('rni') -- Step backward one instruction, but proceed through called subroutines.
* reverse-step ('rs') -- Step program backward until it reaches the beginning of a previous source line
* reverse-stepi -- Step backward exactly one instruction
* set exec-direction (forward/reverse) -- Set direction of execution.

Starting in gdb 7.0, there is reversible debugging, so your new favourite commands are:

* reverse-continue ('rc') -- Continue program being debugged but run it in reverse
* reverse-finish -- Execute backward until just before the selected stack frame is called
* reverse-next ('rn') -- Step program backward, proceeding through subroutine calls.
* reverse-nexti ('rni') -- Step backward one instruction, but proceed through called subroutines.
* reverse-step ('rs') -- Step program backward until it reaches the beginning of a previous source line
* reverse-stepi -- Step backward exactly one instruction
* set exec-direction (forward/reverse) -- Set direction of execution.
葬花如无物 2024-08-12 21:34:43

您也可以在使用一段时间后通过键入“wh”切换到文本模式,而不是使用“-tui”参数启动 GDB。

Instead of launching GDB with "-tui" param you can also switch to text mode after a while using by typing "wh".

栀子花开つ 2024-08-12 21:34:43

thread apply all btthread apply all print $pc:用于快速找出所有线程正在做什么。

thread apply all bt or thread apply all print $pc: For finding out quickly what all threads are doing.

悲凉≈ 2024-08-12 21:34:43

For example the macros defined in stl-views.gdb

小耗子 2024-08-12 21:34:43

编写 gdb 脚本是一个好技巧,除此之外我还喜欢
设置调度程序锁定开/关,以防止在单步执行某个线程时运行其他线程。

scripting gdb is a good trick, other than that I like
set scheduler locking on / off to prevent the running of other threads when you are stepping in one.

是伱的 2024-08-12 21:34:43

启动 gdb 时使用 -command=<带有 gdb 命令的文件> 选项。与 -x <命令文件> 相同。该命令文件可以包含断点、选项等 gdb 命令。在需要使用 gdb 连续调试运行特定可执行文件的情况下非常有用。

Using the -command=<file with gdb commands> option while firing up gdb. Same as -x <command file>. This command file can contain gdb commands like breakpoints, options, etc. Useful in case a particular executable needs to be put through successive debug runs using gdb.

∝单色的世界 2024-08-12 21:34:43
  • 使用.gdbinit(启动文件,您可以在其中编写宏并从gdb调用)。将 .gdbinit 放在您的主目录中,以便每次加载 gdb 时都会拾取它
  • 信息线程以列出所有活动线程,并且 f(#) ->; # 要切换到的线程号

  • 有时我使用gdb从十六进制转换为十进制或二进制,它非常方便,而不是打开计算器

    • p/d 0x10 ->给出 0x10 等值的十进制
    • p/t 0x10 -> 0x10 的二进制等价物
    • p/x 256 ->相当于 256 的十六进制
  • Using .gdbinit (start up file where you can write macros and call from gdb). Place .gdbinit in your home directory so that it is picked up every time gdb is loaded
  • info threads to list all the active threads, and f(#) -> # thread number you want to switch to

  • sometime i use gdb to convert from hex to decimal or binary, its very handy instead of opening up a calculator

    • p/d 0x10 -> gives decimal equivalent of 0x10
    • p/t 0x10 -> binary equivalent of 0x10
    • p/x 256 -> hex equivalent of 256
友谊不毕业 2024-08-12 21:34:43

不要使用选项 -tui 启动 gdb 来查看包含突出显示程序中执行代码行位置的屏幕的子进程,而是使用 Cx o 和 Cx a 跳入和跳出此功能。如果您正在使用该功能以及暂时不使用该功能,那么这非常有用,以便您可以使用向上箭头获取上一个命令。

Instead of starting gdb with the option -tui to see a child process that contains a screen that highlights where the executing line of code is in your program, jump in and out of this feature with C-x o and C-x a. This is useful if you're using the feature and what to temporarily not use it so you can use the up-arrow to get a previous command.

你如我软肋 2024-08-12 21:34:43

这可能很有用,我相信它可以改进,欢迎帮助:

define mallocinfo
  set $__f = fopen("/dev/tty", "w")
  call malloc_info(0, $__f)
  call fclose($__f)

This can be useful, I am sure it could be improved though, help welcome:

define mallocinfo
  set $__f = fopen("/dev/tty", "w")
  call malloc_info(0, $__f)
  call fclose($__f)
忆依然 2024-08-12 21:34:43

要调试 STL,请将内容添加到 .gdbinit,请按照以下说明操作:

http://www .yolinux.com/TUTORIALS/GDB-Commands.html#STLDEREF

To debug STL, add content to .gdbinit, follow these instructions:

http://www.yolinux.com/TUTORIALS/GDB-Commands.html#STLDEREF

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文