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文件中:

python
import gdb

class RunUntilCommand(gdb.Command):
    """Run until breakpoint and temporary disable other ones"""

    def __init__ (self):
        super(RunUntilCommand,self).__init__ ("run-until",gdb.COMMAND_BREAKPOINTS)

    def invoke(self,bp_num,from_tty):
        try:
            bp_num = int(bp_num)
        except (TypeError,ValueError):
            print "Enter breakpoint number as argument."
            return

        all_breakpoints = gdb.breakpoints() or []
        breakpoints = [b for b in all_breakpoints
                       if b.is_valid() and b.enabled and b.number != bp_num and
                       b.visible == gdb.BP_BREAKPOINT]

        for b in breakpoints:
            b.enabled = False

        gdb.execute("run")

        for b in breakpoints:
            b.enabled = True

RunUntilCommand()
end
原文链接:https://www.f2er.com/c/114556.html

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