逐行调试Java代码

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

Debugging Java code line by line

javaeclipsedebugging

提问by fesam

Is it possible to debug code line by line in Eclipse showing which line is executing so that I understand the logic of the code? I'm new to programming, please give me suitable advice.

是否可以在 Eclipse 中逐行调试代码以显示正在执行的行,以便我了解代码的逻辑?我是编程新手,请给我合适的建议。

采纳答案by VonC

It is possible if you launch your program in debug mode:

如果您在调试模式下启动程序,则有可能:

Eclipse Debug

Eclipse 调试

put a breakpoint in the section you want to debug.

在要调试的部分中放置一个断点。

Here is a quick tutorialto make a Debug launch configuration:

这是进行调试启动配置的快速教程

Debug launch configuration

调试启动配置

回答by spa

Yes set a break point and step through the code.

是的,设置一个断点并逐步执行代码。

回答by pstanton

you need to:

你需要:

  1. create a breakpoint by double clicking the left margin of the code
  2. launch your program in debug mode
  3. use the stepping buttons or F5-F8 to step in different ways
  1. 通过双击代码的左边距创建断点
  2. 在调试模式下启动您的程序
  3. 使用步进按钮或 F5-F8 以不同方式步进

回答by Thilo

Sure. You can set a breakpoint, at then step line-by-line in the debugger.

当然。您可以在调试器中逐行设置断点。

This works by running your program in debug mode (the easiest way is to launch it with the Debug button as opposed to the Run button).

这是通过在调试模式下运行程序来实现的(最简单的方法是使用调试按钮而不是运行按钮启动它)。

In the Java source code view, you can click in the line number gutter to enable breakpoints.

在 Java 源代码视图中,您可以在行号间距中单击以启用断点。

When execution hits that line, the Debug perspective will open, where you can inspect (and change!) all variables, and continue execution step by step.

当执行到达该行时,Debug 透视图将打开,您可以在其中检查(和更改!)所有变量,并逐步继续执行。