我想在GDB断点上设置条件,仅当在backtrace中出现某个函数名称时才断开。最好的方法是什么?

有帮助吗?

解决方案

我不确定如何准确地做您的要求,但是如果您可以访问相关函数的源代码,则可能的解决方法是将一些全局boolean变量设置为 true 在功能的开头,并将其设置为 false 在功能退出之前。然后,您可以设置有条件的断点(使用 condition 命令)仅在此布尔变量为 true.

其他提示

比Python脚本更简单的解决方案是使用 临时断点.

看起来像这样:

b ParentFunction
command 1
  tb FunctionImInterestedIn
  c
end

每次你突破 ParentFunction, ,您将在您实际感兴趣的功能上设置一个一次性断点,然后继续运行(大概要直到达到断点为止)。

因为您会完全突破一次 FunctionImInterestedIn, ,如果这不起作用 FunctionImInterestedIn 在上下文中被称为多次 ParentFunction 您想打破每个调用。

替代Rix0RRR的答案:

b main
commands
set $inParentFunction = 0
c
end

b ParentFunction
commands
set $inParentFunction = 1
c
end

b FunctionImInterestedIn if ($inParentFunction)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top