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

图片.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.

  • 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

图片.png

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

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

For more information about debugging visit: Eclipse Stepping Commands Help

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 要在内部类里面打断点,这样出错的时候会进入到exception类里面,f6可以看exception的参数,找到为什...
    哈哈111阅读 675评论 0 1
  • 在程序开发过程中,Bug可以说难以避免。如果定位Bug、分析Bug可以说是快速解决问题的关键。而定位Bug最重要的...
    就是一个个人笔记阅读 1,886评论 0 4
  • 本篇是数据分析连载四篇中的第三篇,在前面两篇中我们学习了PC端和移动端的数据分析思路,本次我们以UGC和电商类产品...
    红猪先生阅读 2,384评论 0 3
  • 1.放苗前后“气泡病”防控 气泡病是指池塘中溶解的气体(氧气、氮气等)过饱和(过量),在池底产生气泡或在虾体内产生...
    利洋王凯强阅读 9,398评论 0 7
  • 曾记否,那个冬天我做了爸爸。是的,我记得,我记得在产房的走廊里,听见女儿的第一声啼哭,我开心的一蹦三尺高。时...
    娜朵蔷薇阅读 736评论 9 6