Debugging method return value in a single step

已回答

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?

0

Hi,

Show method return variables" (why isn't it on by default btw)

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

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.

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 

 

0

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?

0

It's not possible, basically, it's a JVM problem: 

a return statement is just one step byte code like this:

put some value to stack(the returned value)

areturn

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:

 

  private static foo()I
   L0
    LINENUMBER 11 L0
    ICONST_5
    IRETURN
    MAXSTACK = 1
    MAXLOCALS = 0

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.

0

I understand. Thank you for the detailed explanation :)

0

请先登录再写评论。