在 Intellij 中使用 Java 调试器时,“丢帧”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2367816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:48:44  来源:igfitidea点击:

When using the Java debugger in Intellij what does "Drop Frame" mean?

javadebuggingintellij-idea

提问by benstpierre

I was using the Java debugger within Intellij 8 and noticed a button labeled "drop frame", does anybody know what purpose this serves? How/why would this be used/useful?

我在 Intellij 8 中使用 Java 调试器并注意到一个标记为“丢帧”的按钮,有人知道它的用途是什么吗?如何/为什么会使用/有用?

回答by Daniel Schneller

The call stack of your application can be viewed in the debugger. Using the "Drop Frame" functionality you can "fall back" to a previous stack frame, in a sense going back in time. This can be helpful to re-enter a function if you missed a critical spot you would like to see again.

可以在调试器中查看应用程序的调用堆栈。使用“Drop Frame”功能,您可以“回退”到前一个堆栈帧,从某种意义上说可以回到过去。如果您错过了想要再次查看的关键点,这有助于重新输入函数。

As the name "Stack Frame" suggests, changes that were already made to global state (like static variables, changes to field values and the like) will not be undone, only local variables are reset. This can lead to a different execution path than the one that originally led to your break point. You need to be aware of this - I often consider it a useful feature to explore different paths of execution without having to restart the application or a particular lengthy process that led to the current stack. Combined with the change of variable values also available through the debugger, you can do all sorts of interesting things.

正如名称“堆栈框架”所暗示的那样,已经对全局状态进行的更改(如静态变量、对字段值的更改等)不会被撤消,只会重置局部变量。这可能会导致与最初导致断点的执行路径不同。您需要意识到这一点 - 我经常认为这是一个有用的功能,可以探索不同的执行路径,而无需重新启动应用程序或导致当前堆栈的特定冗长进程。结合也可通过调试器获得的变量值的变化,您可以做各种有趣的事情。

Please note, that of course, any side effects that might have occurred - e. g. network traffic, file manipulations, console output etc. - cannot be rewound.

请注意,当然,任何可能发生的副作用 - 例如网络流量、文件操作、控制台输出等 - 都无法回滚。

回答by Jorge Ferreira

Drop Frame within the debugger pops the current stack frame and puts control back out to the calling method, resetting any local variables. This is very useful to repeatedly step through a function, but be warned: field mutations or global state changes will remain.

调试器中的 Drop Frame 弹出当前堆栈帧并将控制权交还给调用方法,重置所有局部变量。这对于重复单步执行函数非常有用,但要注意:字段突变或全局状态更改将保留。

See more info here.

在此处查看更多信息。

回答by Dolph

Dropping frames from the stack using the debugger essentially lets you "rewind" the execution of your application to reach a previous state. Variables outside the stack frame are not reverted.

使用调试器从堆栈中丢弃帧本质上可以让您“倒带”应用程序的执行以达到先前的状态。堆栈帧外的变量不会恢复。

As a side note, I believe this feature is called "Drop toFrame" in Eclipse, but it serves the same purpose.

作为旁注,我相信此功能在 Eclipse 中称为“Drop toFrame”,但它的用途相同。