Java Eclipse 调试器中的 Step Into 和 Step Over 有什么区别?

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

What is the difference between Step Into and Step Over in the Eclipse debugger?

javaeclipsedebugging

提问by JavaUser

I want to debug the whole flow of a Java program. What is the difference between F5(step into) and F6(step over) in eclipse?

我想调试一个 Java 程序的整个流程。eclipse中的F5(step into)和F6(step over)有什么区别?

采纳答案by paxdiablo

Consider the following code with your current instruction pointer (the line that will be executed next, indicated by ->) at the f(x)line in g(), having been called by the g(2)line in main():

考虑以下代码,其中当前指令指针(接下来将执行的行,由 表示->)位于f(x)in 行g(),已被g(2)in 行调用main()

public class testprog {
    static void f (int x) {
        System.out.println ("num is " + (x+0)); // <- STEP INTO
    }

    static void g (int x) {
->      f(x); //
        f(1); // <----------------------------------- STEP OVER
    }

    public static void main (String args[]) {
        g(2);
        g(3); // <----------------------------------- STEP OUT OF
    }
}

If you were to step intoat that point, you will move to the println()line in f(), stepping into the function call.

如果您要在那时进入,您将移动到 中的println()f(),进入函数调用。

If you were to step overat that point, you will move to the f(1)line in g(), stepping over the function call.

如果您要跳过该点,您将移动到 中的f(1)g(),跳过函数调用。

Another useful feature of debuggers is the step out ofor step return.In that case, a step return will basically run you through the current function until you go back up one level. In other words, it will step through f(x)and f(1), then back out to the calling function to end up at g(3)in main().

调试器的另一个有用功能是单步退出或单步返回。在这种情况下,单步返回基本上会让您遍历当前函数,直到您返回一个级别。换句话说,它将单步执行f(x)and f(1),然后返回到调用函数以结束g(3)in main()

Eclipse (at least Europa, which is the only one I have handy at the moment) uses F5for step into, F6for step overand F7for step return.

Eclipse(至少 Europa,这是我目前唯一F5可用的)使用for step intoF6forstep overF7for step return

回答by Jean-Bernard Pellerin

step into will dig into method calls
step over will just execute the line and go to the next one

step into 将深入研究方法调用
step over 将只执行该行并转到下一个

回答by polygenelubricants

When debugging lines of code, here are the usual scenarios:

在调试代码行时,以下是通常的场景:

  • (Step Into) A method is about to be invoked, and you want to debug into the code of that method, so the next step is to go into that method and continue debugging step-by-step.
  • (Step Over) A method is about to be invoked, but you're not interested in debugging this particular invocation, so you want the debugger to execute that method completely as one entire step.
  • (Step Return) You're done debugging this method step-by-step, and you just want the debugger to run the entire method until it returns as one entire step.
  • (Resume) You want the debugger to resume "normal" execution instead of step-by-step
  • (Line Breakpoint) You don't care how it got there, but if execution reaches a particular line of code, you want the debugger to temporarily pause execution there so you can decide what to do.
  • ( Step Into) 一个方法即将被调用,你想调试到那个方法的代码中,所以下一步就是进入那个方法,继续一步步调试。
  • ( Step Over) 一个方法即将被调用,但您对调试这个特定的调用不感兴趣,因此您希望调试器作为一个完整的步骤来完全执行该方法。
  • ( Step Return) 您已经完成了该方法的逐步调试,并且您只希望调试器运行整个方法,直到它作为一个完整的步骤返回。
  • ( Resume) 您希望调试器恢复“正常”执行而不是逐步执行
  • ( Line Breakpoint) 您不关心它是如何到达那里的,但是如果执行到达特定的代码行,您希望调试器在那里暂时暂停执行,以便您可以决定要做什么。

Eclipse has other advanced debugging features, but these are the basic fundamentals.

Eclipse 具有其他高级调试功能,但这些是基本的基础知识。

See also

也可以看看

回答by wanana

You can't go through the details of the method by using the step over. If you want to skip the current line, you can use step over, then you only need to press the F6for only once to move to the next line. And if you think there's someting wrong within the method, use F5to examine the details.

您无法通过使用 step over 来查看方法的详细信息。如果你想跳过当前行,你可以使用step over,那么你只需要按F6一次就可以移动到下一行。如果您认为方法中存在错误,请使用F5来检查细节。

回答by Yogesh Yadav

Step IntoThe next expression on the currently-selected line to be executed is invoked, and execution suspends at the next executable line in the method that is invoked.

Step Into调用当前选定行上要执行的下一个表达式,并在调用的方法中的下一个可执行行暂停执行。

Step OverThe currently-selected line is executed and suspends on the next executable line.

Step Over当前选择的行被执行并在下一个可执行行上挂起。