Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB breakpoint on function arguments

Tags:

gdb

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?

like image 310
kartik Avatar asked Oct 23 '25 23:10

kartik


1 Answers

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
like image 169
blue112 Avatar answered Oct 26 '25 05:10

blue112