如何在调试期间跳过 Eclipse 中的语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2861652/
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-09-10 19:24:51  来源:igfitidea点击:

How to skip a statement in Eclipse during debugging

eclipsedebugging

提问by Frank Fu

Is it possible to skip a statement in Eclipse while debugging? Suppose the process stopped at breakpoint and I want to skip the breakpoint line ( or maybe a few lines below), can I do it? On the debug tab, it only has "Step into", "Step over" and "Step return" buttons.

调试时是否可以跳过 Eclipse 中的语句?假设进程在断点处停止并且我想跳过断点行(或者可能是下面的几行),我可以这样做吗?在调试选项卡上,它只有“Step into”、“Step over”和“Step return”按钮。

I did google around but couldn't find anything, hopefully I can find an answer here.

我做了谷歌搜索,但找不到任何东西,希望我能在这里找到答案。

回答by akf

If you are debugging, you can comment out the line you want to skip and then recompile, which will hotswap the code and keep you within the method you are currently in, allowing you to skip the line.

如果您正在调试,您可以注释掉要跳过的行,然后重新编译,这将热交换代码并使您保持在当前所在的方法中,从而允许您跳过该行。

Depending on what you want to have happen, you could simply execute the line after the one you want to skip, select the code and choose Display from the r-click menu. This will execute the selected code and provide the result in a popup.

根据您想要发生的情况,您可以简单地在要跳过的行之后执行该行,选择代码并从 r-click 菜单中选择 Display。这将执行选定的代码并在弹出窗口中提供结果。

回答by nevets1219

You can set breakpoint conditions that will determine whether or not this breakpoint will stop or will continue on. I don't know of any way for you to tell it to skip the next few line without changing the code to something like:

您可以设置断点条件,以确定此断点是停止还是继续。我不知道你有什么方法可以告诉它跳过接下来的几行而不将代码更改为:

if ( !skip ) {
  // contents to be skipped 
}

and then at the breakpoint set skipto true.

然后在断点处设置skip为true。

For the breakpoint conditions, if you return truewill stop and return falsewill continue. In here you can actually execute code and do whatever you want (including setting the value of skip).

对于断点条件,如果您return true将停止return false并将继续。在这里,您可以实际执行代码并做任何您想做的事情(包括设置 的值skip)。

回答by LakeRunner

I had a similar problem in that I wanted skip some code so that I can get the result of the method call happening later in the code. I forgot that when you are debugging, you can create expressions and evaluate them at anytime. In Eclipse there is an "Expression" tab where you can enter any expressions (i.e. method calls) that you want evaluated.

我有一个类似的问题,因为我想跳过一些代码,以便我可以在代码中获得稍后发生的方法调用的结果。我忘记了,在调试时,您可以随时创建表达式并对其进行评估。在 Eclipse 中,有一个“表达式”选项卡,您可以在其中输入要计算的任何表达式(即方法调用)。

This meant that I did not have to skip the lines, as I was able to evaluate what I wanted as soon as I entered the appropriate method.

这意味着我不必跳过这些行,因为我能够在输入适当的方法后立即评估我想要什么。

回答by Damo

You could always change the value of the class that is about to have a method called to a Mock version of it.

您总是可以将即将调用方法的类的值更改为它的 Mock 版本。

You can do this by right clicking on it in the Variables panel and selecting Change Value. In the window you can then enter something like:

您可以通过在“变量”面板中右键单击它并选择 来执行此操作Change Value。在窗口中,您可以输入如下内容:

new SomeClassMock()

Of course this assumes that you have Mock classes already in your classpath (and it sounds like you don't.) However you could certainly create a JAR full of the Mock classes that you need and shove it in the Tomcat shared lib so that you can access it. Not sure if this works but you get the idea.

当然,这假设你的类路径中已经有 Mock 类(听起来你没有。)但是你当然可以创建一个充满你需要的 Mock 类的 JAR 并将它推送到 Tomcat 共享库中,以便你可以访问它。不确定这是否有效,但您明白了。