gdb useful commands

Useful gdb commands

run [cmd-line-args] – starts your program running

break – sets a breakpoint (program stops at that point)

break function-name - break at start of function

break filename.c:23 - break at line 23 in file

       I Can omit filename if it is the “current” file

break file.c:56 if i==10 - break conditionally

backtrace or bt – show the function call stack I up/down – move up and down the call stack

next/step – execute next line after stopping step steps into functions, next steps over them

continue – continue running (until next breakpoint) I list – show the code around the current stopping point I print expression – print value of expression

info, help, quit, enable/disable, display, ignore, . . .

Ctrl-C – doesn’t exit your program – interrupts it 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
在使用gdb调试时,可以使用commands命令来设置断点,并指定在每次到达该断点时要执行的一组命令。该命令的使用方法如下: 1. 首先,使用gdb启动程序,例如:gdb ./gdbdebug 2. 接下来,使用break命令设置一个断点,例如:b abc.cpp:10 3. 然后,使用commands命令将以下命令添加到指定的断点上: commands breakpoint-number 命令1 命令2 ... end 这里的breakpoint-number是断点号,表示将以下命令添加到指定的断点上。可以添加任何有效的GDB命令,每行一个命令,以end结束。 例如,假设我们有以下示例代码: ```cpp using namespace std; void func1() // 行号为10 { cout << "before" <<endl; } int main() { func1(); return 0; } ``` 我们可以使用以下命令来设置断点并指定commands: ```bash gdb a.out b abc.cpp:10 commands 1 silent prints "after" return c end run ``` 这样,在运行程序时,当程序执行到这个断点时,GDB会执行commands中指定的命令列表,然后继续执行程序。在这个例子中,commands命令会将输出修改为"after",然后继续执行程序,最终输出结果为"after"。 参考资料: 1. [GDB]断点(breakpoint)命令列表:commands、silent 2. 书籍《软件调试的艺术.pdf》2.11节 3. gdb commands命令用法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [GDG调试技巧之命令列表(commands)](https://blog.csdn.net/warden007/article/details/82888035)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [GDB Commands用法](https://blog.csdn.net/qq_33726635/article/details/117199722)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

m0_64618175

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值