eclipse Debug 使用

Resume F8 :一直往下执行,遇到breakpoint则暂停,否则程序执行完毕。移动到下一个断点处。

Terminate : 中断执行(结束,不再执行了)

Step Into F5: 单步执行,遇到子函数就进入子函数。移动到下一步,如果当前的行是一个方法调用,将进入这个方法的第一行

Step Over F6: 单步执行,遇到子函数就“越过”子函数(不进入,仍执行)。移动到下一行。如果当前行有方法调用,这个方法将被执行完毕返回,然后到下一行。

Step Return F7:  when we want to finish our current method and go back to the caller,we press the "Step Return " 。继续执行当前方法,当当前方法执行完毕的时候,控制将转到当前方法被调用的行。

Drop to Frame:  Select the Drop to Frame command [ Drop to Frame ] to re-enter the selected stack frame in the Debug View.

可以点击当前调用栈中的任何一个 frame跳到那里(除了最开始的那个frame)。主要用途是所有变量状态快速恢复到方法开始时候的样子重新执行一遍。这种调试的回退不是万能的,只能在当前线程的栈帧中回退,也就说最多只能退回到当前线程的调用的开始处。


Special Breakpoints and Watching Expressions

可以设置当出现某个Exception时,程序暂停,可以此时查看相关变量的值

在breakpoint  view  点击 () 添加某个 Exception ,debug执行出现,在抛出该异常时,程序挂起。

想追踪某个表达式的值,选中表达式,右键“watch”,如果只想看下值而不追踪,只要“display”就可以。


条件断点:在 Breakpoint View 下,当满足某个条件时程序暂停。

		//程序中代码
		for(int j=0;j<10;j++){ //如果breakpoint在这一行会报错,因为debug会先执行conditional的代码,此时j还未被声明成变量
			p("j normal:"+j);  //breakpoint line
		}
		
		//conditional
		if(j<5){
			return false; //当j<5时,false,即不满足条件,程序继续执行不暂停,
		}
		System.out.println("j interrupt:"+j); //否则程序暂停,执行完这行代码暂停
		return true; //true,告诉debug,此时暂停


异常断点当出现某个Exception时,程序暂停,可以此时查看相关变量的值

观察点(watchpoint):观察点是针对全局变量的,不管何时何地只要它的值被访问或者被修改都会暂停程序的执行。

A watchpoint is a special breakpoint that stops the execution of an application whenever the value of a given expression changes, without specifying where it might occur. Unlike breakpoints (which are line-specific), watchpoints are associated with files. They take effect whenever a specified condition is true, regardless of when or where it occurred. You can set a watchpoint on a global variable by highlighting the variable in the editor, or by selecting it in the Outline view. 

To set a watchpoint on a global variable: 

  1. Highlight the variable in the editor, or select it in the Outline view.
  2. Click Run > Toggle Watchpoint.
  3. Do any of the following:
    • To stop execution when the watch expression is read, select the Read check box.
    • To stop execution when the watch expression is written to, select the Write check box.
  4. The watchpoint appears in the Breakpoints view list 
line-specific  : breakpoint
expression :  watchpoint

改变变量值:在debug过程中可以改变variable的值,但不能改变expression的值,在debug过程中也可以在源代码中添加breakpoint。

代码停在了断点处,但是传过来的值不正确,如何修改一下变量值保证代码继续走正确的流程,或是说有一个异常分支老是进不去,能不能调试时改一下条件,看一下异常分支代码是否正确?

在Main方法中停止:在Debug Confusions中可以设置在 main 方法中停止,当程序运行到main的第一行时暂停。


++++++++++++

Step Filter:

当按F5要进入方法时,如果不想进入某些方法,可以用Step Filter过滤掉,在Preference-java-debug-step filtering,或者在Preference直接搜索step filtering


方法断点:

选中方法名,再选择Run-Toggle Method Breakpoint. 程序会在该方法第一行暂停。牛叉的是方法断点可以打在jdk里,便于查看方法调用。

可以设置是否Entry、Exit时暂停。


加载类断点:

在类的声明行或者outline里可以打个classload breakpoint,A class load breakpoint stops when the class is loaded.


远程调试:

http://www.ibm.com/developerworks/cn/opensource/os-eclipse-javadebug/


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值