调试器中的 Step Into 和 Step Over 有什么区别
我想调试(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
设置:
执行:
Setup:
Execution:
???? annotates lines you have your breakpoints on.
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:
请考虑在
g 中的
,已被f(x)
行处使用当前指令指针(接下来将执行的行,由->
指示)的以下代码()main()
中的g(2)
行调用:如果您要单步进入此时,您将移至
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 thef(x)
line ing()
, having been called by theg(2)
line inmain()
:If you were to step into at that point, you will move to the
println()
line inf()
, 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 ing()
, 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)
andf(1)
, then back out to the calling function to end up atg(3)
inmain()
.调试代码行时,常见的情况如下:
单步执行
一个方法即将被调用,并且您想要调试到该方法的代码中,因此下一步就是进入该方法方法并继续逐步调试。
单步执行
即将调用一个方法,但您对调试此特定调用不感兴趣,因此您希望调试器将该方法作为一个完整步骤完全执行。
单步返回
您已经完成了该方法的逐步调试,您只希望调试器运行整个方法,直到它作为一个完整的步骤返回。
恢复
您希望调试器恢复“正常”执行,而不是逐步执行
行断点
您不关心它是如何到达那里的,但如果执行到达特定的行代码时,您希望调试器暂时暂停执行,以便您可以决定要做什么。
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
step into 将深入研究方法调用
步骤越过只会执行该行并转到下一行
step into will dig into method calls
step over will just execute the line and go to the next one
与调试器通信的方法
(或者,我如何向我的祖母解释我的公路旅行)
步入:“当下一个语句执行时到达方法调用时,不要执行整个方法,而是执行该方法的第一行并停止“
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:
您无法使用单步执行来查看该方法的详细信息。
如果你想跳过当前行,可以使用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.
单步执行 调用当前选择的要执行的行上的下一个表达式,并在调用的方法中的下一个可执行行处暂停执行。
单步执行 当前选定的行被执行并挂起到下一个可执行行。
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.