2

I 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)?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

yes, i tried that already... I am getting Error in re-setting breakpoint 17: No symbol flag in current context.
@dksjalk Have you compiled with debug information? gcc -g myfile.c
@dksjalk: or better — gcc -g3
yes, I compiled with debug information (using Eclipse though), but I am not sure the debug info is there. Is there some way to check?
@dksjalk The error you are getting is exactly the one you get if there is no debug info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.