Debugging method return value in a single step
Answered
Hi,
I want to be able to debug a return value from method with a single step. I have enabled "Show method return variables" (why isn't it on by default btw?) but I still need to set the breakpoint before the last line, then hit "Debug" and then "Step over" - so 2 steps.

Can I reduce this to a single step, where I hit "Debug" and see the return value immediately? Kind of like here:

I tried setting the breakpoint in the closing line of method (Line 8 in the first screenshot) but the debugger won't stop there to show the value.
How can I achieve this?
Please sign in to leave a comment.
Hi,
It's because of the debugger performance issue as described here: https://www.jetbrains.com/help/idea/2023.2/stepping-through-the-program.html#improve-stepping-speed
You can follow the guide here: https://stackoverflow.com/questions/5010362/can-i-find-out-the-return-value-before-returning-while-debugging-in-intellij
The value is not at the Threads and Values tab but at the right pane after you step out of that method:
https://imgur.com/a/nYc2zfh
So I do need to step out - an extra step that can be a pain if you do it often.
Would it be possible to allow setting breakpoints in this spot just to see the return values?
It's not possible, basically, it's a JVM problem:
a return statement is just one step byte code like this:
Infact now the value is captured after the areturn is finished(whole method is executed).
After the source code compiled to byte code, there will be no things like } exist in the final class file and the debugger always works with class file but not the source code:
Something to read is at here: https://en.wikipedia.org/wiki/List_of_Java_bytecode_instructions
And you can use this plugin to view the byte code: https://plugins.jetbrains.com/plugin/16970-byte-code-analyzer
I know it's maybe a bit hard to understand, hope this could help you a bit.
I understand. Thank you for the detailed explanation :)