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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 224,014评论 6 522
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 95,832评论 3 402
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 171,062评论 0 366
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 60,620评论 1 300
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 69,636评论 6 399
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 53,148评论 1 314
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 41,522评论 3 427
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 40,501评论 0 278
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 47,032评论 1 324
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 39,069评论 3 344
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 41,211评论 1 354
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,848评论 5 350
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 42,541评论 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 33,013评论 0 25
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 34,136评论 1 275
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 49,712评论 3 380
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 46,240评论 2 363

推荐阅读更多精彩内容

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