gdb条件断点的值一定会断吗,如何让GDB断点在指定点数达到指定次数后才会中断?...

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值