如何让GDB只在被调用一定时间之后才能破解它?

Yan*_*Chi 20 gdb

例如,我的程序中有一个函数NamespaceA :: ClassB :: FunctionC().我知道我可以通过"break NamespaceA :: ClassB :: FunctionC"让GDB打破它.但是,如果我只想让GDB在那里打破,我会怎么办?

我认为解决方案的解决方案是在程序中再添加一个变量,然后我可以使用GDB中的"break ... if cond"命令.但是我可以在不向程序中添加变量的情况下实现相同的功能吗?

谢谢.

seh*_*ehe 24

(gdb) continue 100
Run Code Online (Sandbox Code Playgroud)

应该做的伎俩

(gdb) help continue
Continue program being debugged, after signal or breakpoint.
 If proceeding from breakpoint, a number N may be used as an argument,
 which means to set the ignore count of that breakpoint to N – 1 (so that
 the breakpoint won’t break until the Nth time it is reached).
Run Code Online (Sandbox Code Playgroud)

  • 这假设您已经处于给定的断点.您还可以使用`ignore <n> <count>`直接设置忽略计数,其中`n`是要忽略`count`次的断点的编号. (16认同)
  • @Jefromi 恕我直言,您的评论值得成为另一个答案。 (2认同)