K_TGTK
K_TGTK

Reputation: 815

GDB breakpoint on function arguments

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?

Upvotes: 4

Views: 2287

Answers (1)

blue112
blue112

Reputation: 56402

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

Upvotes: 6

Related Questions