When using the Java debugger in Intellij what does

2019-01-21 15:50发布

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?

3条回答
霸刀☆藐视天下
2楼-- · 2019-01-21 16:19

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.

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.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-21 16:20

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.

See more info here.

查看更多
Summer. ? 凉城
4楼-- · 2019-01-21 16:24

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 to Frame" in Eclipse, but it serves the same purpose.

查看更多
登录 后发表回答