零基础学Java语言

Eclipse 调试

2017-12-26  本文已影响0人  追风剑007

1. Launching and Debugging a Java program

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead.
也可以直接在代码编辑区右键选择Debug As -> Java Application
https://eclipse.org/community/eclipse_newsletter/2017/june/images/Launching_debugging-1.PNG

图片.png

https://eclipse.org/community/eclipse_newsletter/2017/june/images/Launching_debugging-2.PNG

图片.png

Either actions mentioned above creates a new Debug Launch Configuration and uses it to start the Java application.
debug配置,选择一个要debug的主类Main class (*.java)
https://eclipse.org/community/eclipse_newsletter/2017/june/images/Launching_debugging-3.PNG

图片.png

In most cases, users can edit and save the code while debugging without restarting the program.This works with the support of HCR (Hot Code Replacement), which has been specifically added as a standard Java technique to facilitate experimental development and to foster iterative trial-and-error coding.

2. Breakpoints 设置断点

A breakpoint is a signal that tells the debugger to temporarily suspend execution of your program at a certain point in the code.

To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively, you can double-click on this position.

https://eclipse.org/community/eclipse_newsletter/2017/june/images/Breakpoints-1.PNG

图片.png

The Breakpoints view allows you to delete and deactivate Breakpoints and modify their properties.
https://eclipse.org/community/eclipse_newsletter/2017/june/images/Breakpoints-2.PNG

图片.png

All breakpoints can be enabled/disabled using Skip All Breakpoints. Breakpoints can also be imported/exported to and from a workspace.

3. Debug Perspective

The debug perspective offers additional views that can be used to troubleshoot an application like Breakpoints, Variables, Debug, Console etc. When a Java program is started in the debug mode, users are prompted to switch to the debug perspective.

4.Stepping commands

The Eclipse Platform helps developers debug by providing buttons in the toolbar and key binding shortcuts to control program execution.
https://eclipse.org/community/eclipse_newsletter/2017/june/images/Stepping_Commands.PNG

图片.png
Resume F8
step into F5 单步执行,进入子函数
就是在单步执行时,遇到子函数就进入并且在子函数内继续单步执行;
step over F6 单步执行,越过子函数
就是在单步执行时,在函数内遇到子函数时不会进入子函数内单步执行,而是将子函数整个执行完再停止,也就是把子函数整个作为一步。
step return F7 单步执行,跳出子函数
就是单步执行到子函数内时,执行完子函数余下部分,并返回到上一层函数。

在一般调试过程中,F6用的比较多。

For more information about debugging visit: Eclipse Stepping Commands Help

上一篇下一篇

猜你喜欢

热点阅读