GDB:打破IF可变同等价值 [英] GDB: break if variable equal value

查看:135
本文介绍了GDB:打破IF可变同等价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢让GDB设置断点,当变量等于某个值我设置,我想这个例子:

I like to make GDB set a break point when a variable equal some value I set, I tried this example:

#include <stdio.h>
main()
{ 
     int i = 0;
     for(i=0;i<7;++i)
        printf("%d\n", i);

     return 0;
}

从GDB输出:

(gdb) break if ((int)i == 5)
No default breakpoint address now.
(gdb) run
Starting program: /home/SIFE/run 
0
1
2
3
4
5
6

Program exited normally.
(gdb)

就像你看到的,GDB没有做任何破发点,这可能与GDB?

Like you see, GDB didn't make any break point, is this possible with GDB?

推荐答案

除了观察点嵌套在一个断点内
您还可以设置一个断点在文件名:LINE_NUMBER和使用条件。
我发现它有时会更容易。

in addition to a watchpoint nested inside a breakpoint you can also set a single breakpoint on the 'filename:line_number' and use a condition. I find it sometimes easier.

(gdb) break iter.c:6 if i == 5
Breakpoint 2 at 0x4004dc: file iter.c, line 6.
(gdb) c
Continuing.
0
1
2
3
4

Breakpoint 2, main () at iter.c:6
6           printf("%d\n", i);

这篇关于GDB:打破IF可变同等价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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