Conditional breakpoint: condition at return statement, checking return value
Answered
Is it possible to set conditional breakpoint such way, that it will stop at return statement iff the value being returned matches condition?
For example:
int foo() {
return bar();
}
I would like to stop inside foo method if it goes to return 0. What I'm usually doing now - is editing the code and splitting this statement into 2 lines:
int res = bar();
return res;
First of all - it's very annoying to edit the code just for debugging. Second it does not allow me to stop there if I'd like to stop at third-party library's code. So I wonder if there is a more convenient way to accomplish this?
Thanks
Please sign in to leave a comment.
Hello Denis,
You may set "bar()==0" condition.
Thanks, Yaroslav. I'm aware of this possibility, but If I understand correctly the way Intellij debugger works, in this case bar() will be actually evaluated twice - once in the code and one more time in the debugger. So if calling bar has side effects, such breakpoint might affect the behavior. Am I wrong?
Denis,
Yes, you're right. bar() will be evaluated twice. Please create feature request on YouTrack for better handling of such cases:
http://youtrack.jetbrains.com/issues/IDEA.
@... Has an issue been created for that feature?