c – GDB:运行到特定的断点

前端之家收集整理的这篇文章主要介绍了c – GDB:运行到特定的断点前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在GDB调试C代码中:我有15个断点在策略上设置,但我不希望任何一个激活,直到我打破断点#2. GDB中是否有run-until-breakpoint-n命令?

我发现自己在做两件事之一:

>删除所有其他断点,使#2全部存在,运行,重新添加所有断点;要么
>运行并反复继续经过所有休息,直到我看到#2的第一个休息.

我想要像run-until 2这样的东西,它将忽略除#2之外的所有其他断点,但不能删除它们.这是否存在?还有其他人有更好的处理方法吗?

解决方法

从7.0版开始,GDB支持 python脚本.我写了一个简单的脚本,它将临时禁用所有已启用的断点,除了具有指定数字的断点,并执行GDB运行命令.

将以下代码添加到.gdbinit文件中:

  1. python
  2. import gdb
  3.  
  4. class RunUntilCommand(gdb.Command):
  5. """Run until breakpoint and temporary disable other ones"""
  6.  
  7. def __init__ (self):
  8. super(RunUntilCommand,self).__init__ ("run-until",gdb.COMMAND_BREAKPOINTS)
  9.  
  10. def invoke(self,bp_num,from_tty):
  11. try:
  12. bp_num = int(bp_num)
  13. except (TypeError,ValueError):
  14. print "Enter breakpoint number as argument."
  15. return
  16.  
  17. all_breakpoints = gdb.breakpoints() or []
  18. breakpoints = [b for b in all_breakpoints
  19. if b.is_valid() and b.enabled and b.number != bp_num and
  20. b.visible == gdb.BP_BREAKPOINT]
  21.  
  22. for b in breakpoints:
  23. b.enabled = False
  24.  
  25. gdb.execute("run")
  26.  
  27. for b in breakpoints:
  28. b.enabled = True
  29.  
  30. RunUntilCommand()
  31. end

猜你在找的C&C++相关文章