如何让GDB断点在指定点数达到指定次数后才会中断? [英] How to make a GDB breakpoint only break after the point is reached a given number times?
问题描述
我有一个被调用了很多次的函数,并最终发生了段错误。
然而,我不想在这个函数中设置断点,并且
我听说我可以设置一个计数器
作为断点,并且每次命中断点时,计数器递减,并且只有在计数器
= 0时触发。
这是否准确?如果是,我该怎么做?请给gdb代码设置这样一个断点。 解决方案
阅读 GDB手册第5.1.6节。你需要做的是首先设置一个断点,然后为该断点号设置一个忽略计数,例如, ignore 23 1000
。
如果您不知道忽略断点的次数,想要手动计数,以下可能会有所帮助:
忽略23 1000000#set ignore count非常高。
运行#在达到忽略计数之前,程序将SIGSEGV。
#一旦SIGSEGV停止:
info break 23#告诉你断点有多少次被触发,
#这正是你想要的数字
I have a function that is called some large number of times, and eventually segfaults.
However, I don't want to set a breakpoint at this function and stop after every time it's called, because I will be here for years.
I've heard that I can set a counter
in GDB for a breakpoint, and each time the breakpoint is hit, the counter is decremented, and only gets triggered when the counter
= 0.
Is this accurate, and if so how do I do it? Please give the gdb code for setting such a breakpoint.
Read section 5.1.6 of the GDB manual. What you have to do is first set a breakpoint, then set an 'ignore count' for that breakpoint number, e.g. ignore 23 1000
.
If you don't know how many times to ignore the breakpoint, and don't want to count manually, the following may help:
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
这篇关于如何让GDB断点在指定点数达到指定次数后才会中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!