开发者

need help with conditional gdb debugging (of C code)

开发者 https://www.devze.com 2022-12-20 22:32 出处:网络
I 开发者_StackOverflow社区have a C code similar to: int f() { for (int i = 0; i < 100; i++) { scanf flag;

I 开发者_StackOverflow社区have a C code similar to:

int f() {
   for (int i = 0; i < 100; i++) {
   scanf flag;
   if(flag) 
      scanf data1;
   scanf data2;
   }
}

I want to break the execution only when flag == 0. How should I set the breakpoint (using gdb)?


In the gdb console type

b (some_line) if flag == 0

EDIT:
If you can't print flag while stopped at some-line, then either:
- (A) your code is compiled with optimization (likely), or
- (B) you have a buggy compiler

If it's (A), add -O0 in addition to -g3.

If you can print flag, then you have a buggy version of GDB. Try upgrading to current 7.0.1 release.

0

精彩评论

暂无评论...
验证码 换一张
取 消