Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JetBrains: How to watch the return value of a function?

I have a question about debugging mode in JetBrains IDEs (PyCharm, WebStorm, IntelliJ ..). Let's say I have a line in the code that looks like this:

....func1()...func2()...func3()...

Several functinos are called in the same line, and none of them is assigned to a variable. Now, I want to know what is the return value of each of these functions. I know the feature Evaluate Expression, but I don't want to use it, since it may invoke these functions again.

Do you know any way to find the return values of a function without assigning its value to a variable and checking its value in debugger?

like image 369
CrazySynthax Avatar asked Jul 25 '16 11:07

CrazySynthax


3 Answers

As of PyCharm 2016.2, you can show function return values; to do so, you need to:

  • Click on the Settings gear icon in the left-hand toolbar of the Debug panel
  • Ensure that Show Return Values is checked

Then when a Return Value is present, you will see it listed under Return Values at the top of the Variables section of the Debug panel (and that information is retained while still in the calling function)

like image 176
David Fraser Avatar answered Sep 22 '22 14:09

David Fraser


I don't think that this is possible right now but you could set breakpoints inside the functions itself.

Additionally you could add a "Disable until selected breakpoint is hit" + "Disable again" and join them with a breakpoint above the line you posted to make sure they are only called from this line.

Or simply refactor your code:

foobar.huey()
.dewey()
.louie();

and set line breakpoints as usual.

like image 34
Sebastian Avatar answered Sep 22 '22 14:09

Sebastian


I was looking also for this, and I can link you an answer I found, extending the answer of David Fraser: in IntelliJ, someone replied with screenshots to a similar question in this same site: java - Can I find out the return value before returning while debugging in Intellij Remember to put a breakpoint inside the function and step out :)

As said there (although it includes screenshots, much better than this) by the user Birchlabs:

On IntelliJ IDEA 2016.3: it's hidden inside the cog button of the debug panel. Ensure Show Method Return Values is checked.

IntelliJ IDEA 2016.3 "Show Method Return Values"

Use the debugger to break somewhere inside the function whose return value you'd like to see.

step into function

Step out of the function (or step over until you escape):

step out

Observe that the return value appears in your variables:

observe the return value

like image 27
xCovelus Avatar answered Sep 22 '22 14:09

xCovelus