c++ - 断点函数执行 x 次
问题描述
我想在某个代码(函数)执行一定次数时使用断点。问题是我的简单代码被优化了,断点永远不会到达。执行一定次数后如何破解代码
static int count = 0;
static int test = 0;
if (count == 5) {
//Break here before getting stuck
count++;
test++;
count--;
};
解决方案
始终在编译调试时,关闭(或保持最小)所有优化( -O0 )。
或者,在使用 gcc 时,您可以使用函数属性告诉编译器不要优化函数( using attribute ((optimize(0))) )