在Intellij中调试时返回之前可以找出返回值吗? [英] Can I find out the return value before returning while debugging in Intellij?

查看:130
本文介绍了在Intellij中调试时返回之前可以找出返回值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用:

 对象方法(){
...
return / *一些复杂表达式* /
}

有没有办法可以看到什么值会被返回调试?像以某种方式设置一个断点,将在返回后立即命中,但在执行到调用代码之前?我希望能够知道返回值是什么,并且能够看到所有局部变量的值。



我这样做的方式现在是通过创建一个临时变量: Object ret = / * something complex * /;返回ret; 。但这很麻烦,并且还增加了额外的不必要的代码行。



注意:这与在Visual Studio中调试时返回值之前可以找出返回值,但对于intellij。

解决方案

似乎有几种方法可以做到这一点。第一个涉及在方法签名上设置断点,在您的情况下,您将在Object method(){)上设置断点。这将允许您观察该方法的入口和出口。我相信你必须像上面所说的那样将它与 Watch方法返回值结合使用,但是由于计算时间太长,我无法完全测试它。请注意,这确实会大大降低调试器的性能,并且调试时间会更长。



您也可以手动执行以下操作。


  1. 在返回行上设置断点。
  2. 当返回行被点击时,点击返回行,特别是将光标置于您想要查看的操作上,然后转到Run-> Evaluate Expression(或Alt-F8),它应该在该位置运行表达式并返回它返回的内容。

注意:如果您创建了一个断点,您可以通过IDEA处理很多事情,例如就好像你在断点上断开一样,你可以告诉他们执行一个表达式并记录下来。如果您右键单击断点并单击属性,则可以查看您可以执行的操作。

更新
与第一种方法一起尝试此操作。不要使用Watch方法返回值,因为它似乎会减慢或冻结调试会话。请执行以下操作:


  1. 右键单击要查看的返回表达式,然后点击添加到手表

  2. 接下来添加一个类似上述的方法断点。

  3. 调试您的程序,您的方法将在方法签名上断开。

  4. 按F9键继续,它会再次破坏 AFTER 返回表达式已计算出来,并且返回表达式应为请注意,方法断点较慢,所以可能需要更多时间,如果您注意到了这一点,可以采用一种棘手的方法来改善这一点。
  5. 性能问题太多了,只需设置返回语句断点(不带方法断点),然后添加方法断点 AFTER ,返回语句断点便会继续,然后继续。



    希望这有助于,


    With:

    Object method(){
        ...
        return /* some complex expression */
    }
    

    Is there a way I can see what value will be returned while debugging? Like somehow set a breakpoint that would be hit right after the return, but before execution goes to the calling code? I'd like to be able to know what the return value is and also be able to see what values of all of the local variables are.

    The way I do it now is by making a temporary variable: Object ret = /* something complex */; return ret;. But thats a hassle and also adds an extra unnecessary line of code.

    Note: This is the same question as Can I find out the return value before returning while debugging in Visual Studio, but for intellij.

    解决方案

    There seems to be a couple ways you can do this. The first one involves setting up the breakpoint on the method signature, in your case you would setup a breakpoint on Object method(){ . This will allow you to watch for the entrance and exit of the method. I believe you have to use this in conjunction with "Watch method return values" like stated above, but I haven't been able to completely test this as it takes too long to compute. Beware, this does dramatically decrease the performance of the debugger and it will take longer to debug.

    Also you can do the following manually.

    1. Setup the breakpoint on the return line.
    2. When the return line is hit, click on the return line, specifically put the cursor on the operation that you want to see, then go to Run->Evaluate Expression (or Alt-F8) and it should run the expression at that point and return what it's returning.

    Note: If you create a breakpoint, there are a lot of things you can tell IDEA to do with them, such as if you break on a breakpoint, you can tell them to perform an expression and log it. You can look around with what you can do if you right-click on a breakpoint and click properties.

    UPDATE: Try this in conjunction with the first way of doing it. Don't use "Watch method return values" as it seems to slow down or freeze up the debugging session. Instead do the following

    1. Right-click on the return expression you want to see and click "Add to Watches"
    2. Next add a method breakpoint like stated above.
    3. Debug your program and your method will break on the method signature.
    4. Hit the F9 key for continue and it should break again AFTER the return expression has been computed and your return expression should be in the watch column.

    Remember that method breakpoints are slower so it might take more time, a tricky way to improve this if you are noticing too much of a performance hit is by just setting the return statement breakpoint (without having a method breakpoint) and then adding the method breakpoint AFTER the return statement breakpoint hits and then continuing.

    Hope this helps,

    这篇关于在Intellij中调试时返回之前可以找出返回值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆