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

发布于 2024-09-16 01:32:21 字数 83 浏览 2 评论 0原文

我想调试(Java)程序的整个流程。我看到有几个选项可以单步执行我的程序。 步入跨过有什么区别?

I want to debug the whole flow of a (Java) program. I see there are several options for stepping through my program. What is the difference between step into and step over?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

遥远的绿洲 2024-09-23 01:32:22

设置:

func aa() {
   a1()
}

func bb() {
   b1()
}

func cc() {
   c1()
}

执行:

Setup:

func aa() {
   a1()
}

func bb() {
   b1()
}

func cc() {
   c1()
}

Execution:

???? annotates lines you have your breakpoints on.

1: ????aa() 
2:   bb()
3: ????cc()

Here's what happens:

Continue:
Continues with the app flow. Will stop at the next breakpoint. In this case it will stop at Line 3.

Step Over:
Will move onto the next line. In this case it will stop at Line 2

Step Into:
Will go into the aa() function. Will Stop at line a1()

Step Out:
If you did step into, then step out, will take you back to Line 1

If you want to visualize this more:

Continue: Just jumps
Step Over: Moves Down
Step Into: Moves Right
Step Over: Moves Left

The directions above correlate more or less with the direction that you read your code. Or how you read a book (or watch a movie). Continue jumps to a specific page of the book. Step Over, moves to the next chapter of the book. Doesn't care what's inside the chapter. Step Into moves within the chapter. Step out, gets back to the previous hierarchical level you were at.

Why are there so much differences?

Essentially any time you hit a breakpoint you could be like:

  • Jump to another breakpoint ==> "Got it. Let's move on"
  • Step Over ==> "Ok I have a decent understanding of what's happening, but let's just see what happens next
  • Step Into ==> "Hmmm...let's just see what this function is doing things internally
  • Step Out ==> "Ahhh I see what this function is doing, "let's get out of this function and just go back where we were and navigate around again"
静谧 2024-09-23 01:32:21

请考虑在 g 中的 f(x) 行处使用当前指令指针(接下来将执行的行,由 -> 指示)的以下代码(),已被 main() 中的 g(2) 行调用:

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
    }
}

如果您要单步进入此时,您将移至 f() 中的 println() 行,单步执行函数调用。您可以单步执行您准备调用的任何函数。

如果您要在此时单步执行,您将移至 g() 中的 f(1) 行,单步执行该函数称呼。

请注意,如果您要执行的代码不是某种函数调用,那么单步执行和单步执行之间没有真正的区别。例如,它们都将简单地执行语句xyzzy = 42;,然后继续执行下一条语句。

调试器的另一个有用功能是“退出”步骤或“返回”步骤。在这种情况下,它基本上会运行当前函数,直到返回上一级。换句话说,它将逐步执行 f(x)f(1),然后返回到调用函数,最终到达 g(3)main()中。

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():

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 into at that point, you will move to the println() line in f(), stepping into the function call. You step into any function that you're ready to call.

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

Note that there is no real difference between step-into and step-over if the code you're about to execute is not a function invocation of some sort. For example, both of them would simply execute the statement xyzzy = 42; and move on to the next statement.

Another useful feature of debuggers is the step out of or step return. In that case, it 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().

ぶ宁プ宁ぶ 2024-09-23 01:32:21

调试代码行时,常见的情况如下:

单步执行

一个方法即将被调用,并且您想要调试到该方法的代码中,因此下一步就是进入该方法方法并继续逐步调试。

单步执行

即将调用一个方法,但您对调试此特定调用不感兴趣,因此您希望调试器将该方法作为一个完整步骤完全执行。

单步返回

您已经完成了该方法的逐步调试,您只希望调试器运行整个方法,直到它作为一个完整的步骤返回。

恢复

您希望调试器恢复“正常”执行,而不是逐步执行

行断点

您不关心它是如何到达那里的,但如果执行到达特定的行代码时,您希望调试器暂时暂停执行,以便您可以决定要做什么。

Eclipse 还有其他高级调试功能,但这些是基本原理。

另请参阅

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.

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

See also

天邊彩虹 2024-09-23 01:32:21

step into 将深入研究方法调用
步骤越过只会执行该行并转到下一行

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

浪荡不羁 2024-09-23 01:32:21

与调试器通信的方法

(或者,我如何向我的祖母解释我的公路旅行)

步入:“当下一个语句执行时到达方法调用时,不要执行整个方法,而是执行该方法的第一行并停止“

Step Over:”当下一条要执行的语句到达方法调用时,执行方法作为一个整体并停止”

Step Out: “完成被调用者代码的执行,并在执行返回到调用者时停止”

Continue: “执行到下一个断点”

这是一个很好的例子,可以实际演示上述概念:

在此处输入图像描述

Method of Communicating with a Debugger

(Or, how I explain my road trip to my grandmother)

Step Into: "When the next statement to execute reaches a method call, dont execute the method as a whole, but rather, execute the first line of that method and stop"

Step Over: "When the next statement to execute reaches a method call, execute the method as a whole and stop"

Step Out: "Finish off executing the callee's code and stop when execution returns to the caller"

Continue: "Execute up until the next breakpoint"

Here is a great example to practically demonstrate the concepts above:

enter image description here

旧时浪漫 2024-09-23 01:32:21

您无法使用单步执行来查看该方法的详细信息。
如果你想跳过当前行,可以使用step over,那么你只需要按F6一次即可移动到下一行。
如果您认为该方法有问题,请使用F5检查详细信息。

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 F6 for only once to move to the next line.
And if you think there's someting wrong within the method, use F5 to examine the details.

月亮坠入山谷 2024-09-23 01:32:21

单步执行 调用当前选择的要执行的行上的下一个表达式,并在调用的方法中的下一个可执行行处暂停执行。

单步执行 当前选定的行被执行并挂起到下一个可执行行。

Step Into The 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 Over The currently-selected line is executed and suspends on the next executable line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文