Eclipse 简明教程
Eclipse - Debugging Program
Debugging a Java Program
调试一个 Java 程序最快速的方法是使用包资源管理器视图。在包资源管理器视图 −
The quickest way to debug a Java program is to using the Package Explorer view. In the Package Explorer view −
-
Right click on the java class that contains the main method.
-
Select Debug As → Java Application.
可以通过使用包资源管理器选择包含主方法的类并单击 Alt+Shift+D、J 执行同样的操作。
The same action can be performed using the Package Explorer by selecting the class that contains the main method and clicking Alt + Shift + D, J.
上面提到的两个操作都会创建一个新的 Debug Configuration ,并使用它启动 Java 应用程序。
Either actions mentioned above create a new Debug Configuration and use it to start the Java application.
如果一个调试配置已经创建,你可以通过从“运行”菜单中选择“调试配置”,单击调试配置的名称,然后单击“调试”按钮来使用它启动 Java 应用程序。
If a Debug configuration has already been created you can use it to start the Java application by selecting Debug Configurations from the Run menu, clicking on the name of the debug configuration and then clicking on the Debug button.
“运行”菜单中的“调试”菜单项可用于重新启动先前在调试模式中启动的 Java 应用程序。
The Debug menu item on the Run menu can be used to restart the java application that was previously started in the debug mode.
以调试模式启动先前启动的 Java 应用程序的快捷键是 F11。当一个 Java 程序在调试模式中启动时,会提示用户切换到调试透视图。调试透视图提供了额外的视图,可用于对应用程序进行故障排除。
The shortcut key to launch the previously launched Java application in the debug mode is F11. When a java program is started in the debug mode, users are prompted to switch to the debug perspective. The debug perspective offers additional views that can be used to troubleshoot an application.
Java 编辑器允许用户在 Java 代码中放置断点。要设置一个断点,在编辑器区域右键单击标记栏并选择“切换断点”。
The java editor allows users to place break points in the java code. To set a break point, in the editor area right click on the marker bar and select Toggle Breakpoint.
断点显示在标记栏。它们也会在“断点”视图中可见。
Breakpoints are shown on the marker bar. They are also visible in the Breakpoints View.
当执行代码到达断点时,JVM 会暂停程序的执行。此时,你可以检查内存并在受控方式中执行程序。
When the execution of code reaches a break point the JVM suspends the execution of the program. At this point, you can inspect the memory and execute the program in a controlled manner.
当暂停程序执行时,可以利用调试视图来检查调用堆栈。
When the execution of a program is paused, the debug view can be used to inspect the call stack.
利用变量视图可以检查变量的值。
The variables view can be used to inspect the value of variables.
运行菜单有允许你恢复执行、跨越一行代码、进入函数等的菜单项。
The run menu has menu items that allow you to Resume execution, step over a line of code, step into a function etc.
上面给出的图片展示了与恢复、进入和跨越等动作关联的快捷键。
The picture given above shows the shortcut keys associated with actions such as Resume, Step Into and Step Over, etc.