钟铉温流梦话资源:MyEclipse下的Debug调试!

来源:百度文库 编辑:九乡新闻网 时间:2024/05/02 07:45:27

MyEclipse下的Debug调试

http://hi.baidu.com/stresume/blog/item/df904fee0a70adfcb2fb9549.html

首先以debug模式启动tomcat,并文件中设断点,然后运行,当程序走到断点处就会转到debug视图下

[1]快捷键(F8)直接执行程序。
[2]快捷键(F5)单步执行程序,遇到方法时进入。
[3]快捷键(F6)单步执行程序,遇到方法时跳过。
[4]快捷键(F7)单步执行程序,从当前方法跳出。
=====================================

1.Step Into (also F5) 跳入
2.Step Over (also F6) 跳过
3.Step Return (also F7) 执行完当前method,然后return跳出此method
4.step Filter 逐步过滤一直执行直到遇到未经过滤的位置或断点(设置Filter:window-preferences-java-Debug-step Filtering)
5.resume 重新开始执行debug,一直运行直到遇到breakpoint
6.hit count 设置执行次数 适合程序中的for循环(设置 breakpoint view-右键hit count)
7.inspect 检查 运算。执行一个表达式显示执行值
8.watch 实时地监视变量的变化
9.我们常说的断点(breakpoints)是指line breakpoints,除了line breakpoints,还有其他的断点类型:field(watchpoint)breakpoint,method breakpoint,exception breakpoint.
10.field breakpoint 也叫watchpoint(监视点) 当成员变量被读取或修改时暂挂
11.添加method breakpoint 进入/离开此方法时暂挂(Run-method breakpoint)
12.添加Exception breakpoint 捕抓到Execption时暂挂(待续...)

断点属性:
1.hit count 执行多少次数后暂挂 用于循环
2.enable condition 遇到符合你输入条件(为ture\改变时)就暂挂
3.suspend thread 多线程时暂挂此线程
4.suspend VM 暂挂虚拟机
13.variables 视图里的变量可以改变变量值,在variables 视图选择变量点击右键--change value.一次来进行快速调试。
14.debug 过程中修改了某些code后--〉save&build-->resume-->重新暂挂于断点


===========================
例如你有如下程序:
public static void main(String args[]) {

MyDate aa = new MyDate();
aa.addDays(day); =============》(1)
System.out.println("eeeeeeeeeeeeeee");=============》(2)
}

public String addDays(int more_days) {
System.out.println("1"); =============》(3)
String result = ""; =============》(4)
System.out.println("2"); =============》(5)
return result;
}

你在(1)处加断点,运行到此处时如果Step Into (also F5)为跳入,则接着执行到(3)。再执行Step Over (also F6)执行本行,则执行到(4)。最后执行Step Return (also F7),则跳出addDays方法,跳到(2)



Eclipse 中 drop to frame 的调试技巧:
http://www.cnblogs.com/william-lee/archive/2010/09/03/1816645.html引用Select the Drop to Frame command [] to re-enter the selected stack frame in the Debug View.
Note this command is only available if the current VM supports drop to frame and the selected stackframe is not the top frame or a frame in a native method.

就是说,这个功能可以重新跳到当前方法的开始处重新执行,并且所有上下文变量的值也回到那个时候。不一定是当前方法,可以点击当前调用栈中的任何一个frame跳到那里(除了最开始的那个frame)。主要用途是所有变量状态快速恢复到方法开始时候的样子重新执行一遍,即可以一遍又一遍地在那个你关注的上下文中进行多次调试(结合改变变量值等其它功能),而不用重来一遍调试到哪里了。当然,原来执行过程中产生的副作用是不可逆的(比如你往数据库中插入了一条记录)

Eclipse: Dealing with Frames:
http://www.javalobby.org/forums/thread.jspa?threadID=15271&tstart=0