我有一个被称为大量次数的函数,最终是段错误.
但是,我不想在这个函数上设置一个断点,并且每次调用它都会停止,因为我会在这里待多年.
我听说我可以counter在GDB中为断点设置一个,并且每次遇到断点时,计数器都会递减,并且只有在counter= 0 时才会被触发.
这是否准确,如果是这样,我该怎么做?请提供gdb代码来设置这样的断点.
Kil*_*oth 154
阅读GDB手册的5.1.6节.您需要做的是首先设置一个断点,然后为该断点号设置一个"忽略计数",例如ignore 23 1000.
如果您不知道忽略断点的次数,并且不想手动计数,则以下内容可能会有所帮助:
ignore 23 1000000 # set ignore count very high.
run # the program will SIGSEGV before reaching the ignore count.
# Once it stops with SIGSEGV:
info break 23 # tells you how many times the breakpoint has been hit,
# which is exactly the count you want
Run Code Online (Sandbox Code Playgroud)
Cir*_*四事件 13
continue <n>
这是一个方便的方法,可以跳过最后一次命中断点n - 1时间:
#include <stdio.h>
int main(void) {
int i = 0;
while (1) {
i++; /* Line 6 */
printf("%d\n", i);
}
}
Run Code Online (Sandbox Code Playgroud)