Eclipse 调试
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

https://eclipse.org/community/eclipse_newsletter/2017/june/images/Launching_debugging-2.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

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

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

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.
- Debug view – Visualizes call stack and provides operations on that.
- Breakpoints view – Shows all the breakpoints. 可以勾选要设置的断点。
- Variables/Expression view – Shows the declared variables and their values. Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show its value. You can also add a permanent watch on an expression/variable that will then be shown in the Expressions view when debugging is on. 在程序单步运行过程中,可以查看变量的值。
- Display view – Allows to Inspect the value of a variable, expression or selected text during debugging.
-
Console view – Program output is shown here. 程序执行情况就显示在Console控制台中。
进入debug 透视图后,有时候可能看不到Console view。这时,需要把它调出来,拖放到一个合适的位置,便于输入操作数、显示程序运行结果。
https://eclipse.org/community/eclipse_newsletter/2017/june/images/Debug_Perspective.PNG图片.png
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

Resume F8
step into F5 单步执行,进入子函数
就是在单步执行时,遇到子函数就进入并且在子函数内继续单步执行;
step over F6 单步执行,越过子函数
就是在单步执行时,在函数内遇到子函数时不会进入子函数内单步执行,而是将子函数整个执行完再停止,也就是把子函数整个作为一步。
step return F7 单步执行,跳出子函数
就是单步执行到子函数内时,执行完子函数余下部分,并返回到上一层函数。
在一般调试过程中,F6用的比较多。
For more information about debugging visit: Eclipse Stepping Commands Help