4

Can we set a GDB breakpoint on a function such that it will break into only if the function argument matches the value specified? Ex

int foo(int i) {
return i*i;
}

int main() {
  foo(0);
  ................
  foo(9);
}

How do I set a breakpoint on foo only when the argument i of foo is 5?

1

1 Answer 1

6

Sure, use "break if"

break foo if i == 5

If you have multiple variable if need to break on, just use classic if syntax :

break foo if i == 5 && j == 3
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks! what if I have to match multiple arguments in foo(i,j,k) ?
break foo if i == 5 && j == 3, as simply as that.
@kartik: use the syntax familiar from C ... I.e. i == 5 && j == 3 (on occasion it is picky about parentheses being added and how).
@kartik No problem, be sure to validate the answer if it fits your needs.
@blue112 Yes waiting for 5 minute time limit to choose the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.