我在调试递归方法时面临的一个常见问题是,当我想要调试给定的一段代码时,我不可避免地陷入了越来越深入的堆栈中。避免陷入陷阱的唯一方法是手动禁用BP,然后在我感兴趣的代码块通过后重新设置它。
在上面的图片中,我只想在每次迭代中浏览一下循环的变量,看看它们是否表现正常,是否一切正常,但我目前只得到了每次调用combinations
的第一次迭代!
有什么聪明的主意来解决这个问题吗?
发布于 2014-07-25 23:28:13
如果您只想在某些条件或i
递归深度中命中断点,请尝试使用条件断点。如果您想在一些测试/验证之后解开递归,可以在调试时更改eclipse调试器中的基本条件变量的值。
发布于 2014-07-28 17:58:24
如果你有修改递归方法的能力,我经常做这样的事情。
int combinations(int, a1, int a2) {
return(combinationsImpl(a1,a2,0));
}
int combinationsImpl(int, a1, int a2, int level) {
if(done) {
// on done
return(value);
}
// you can use level to do conditional break points, prints etc
// you can save the value when it crashes or throws an exception etc
// if you need to see variables in the stack log the level and the variables
// to console or a file and then see on what level values become anomalous etc.
return(combinationsImpl(a1,a2,++level));
}
https://stackoverflow.com/questions/24965848
复制相似问题