debug as java application_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

3dbc5534229c

图片.png

3dbc5534229c

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

3dbc5534229c

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

3dbc5534229c

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

3dbc5534229c

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

3dbc5534229c

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

3dbc5534229c

图片.png

Resume F8

step into F5 单步执行,进入子函数

就是在单步执行时,遇到子函数就进入并且在子函数内继续单步执行;

step over F6 单步执行,越过子函数

就是在单步执行时,在函数内遇到子函数时不会进入子函数内单步执行,而是将子函数整个执行完再停止,也就是把子函数整个作为一步。

step return F7 单步执行,跳出子函数

就是单步执行到子函数内时,执行完子函数余下部分,并返回到上一层函数。

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

For more information about debugging visit: Eclipse Stepping Commands Help

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值