XCode/LLDB: LLDB 可以中断调用函数吗?

XCode/LLDB: Can LLDB break on the calling function?

我在 -[CALayer setSpeed:] 上设置了一个符号断点,我希望该断点仅在特定函数

调用该函数时触发

-[UIPercentDrivenInteractiveTransition _updateInteractiveTransition:percent:isFinished:didComplete:]

有办法吗?

我可以手动查看调用函数的值,方法是 bt 2。是否有某种方法可以在断点条件中与此输出执行字符串比较?

谢谢!

您可以在断点处使用一些 python 脚本来完成此操作。这意味着 lldb 将在每次遇到断点时停止进程并恢复它——对于像 objc_msgSend 这样非常热门的函数,这将显着影响性能。

在您的主目录中创建一个 python 函数,例如 ~/lldb/stopifcaller.py 并使用这些内容

import lldb
def stop_if_caller(current_frame, function_of_interest):
  thread = current_frame.GetThread()
  if thread.GetNumFrames() > 1:
    if thread.GetFrameAtIndex(1).GetFunctionName() != function_of_interest:
      thread.GetProcess().Continue()

然后输入

command script import ~/lldb/stopifcaller.py

在您的 ~/.lldbinit 文件中。

在lldb中这样使用:

(lldb) br s -n bar
Breakpoint 1: where = a.out`bar + 15 at a.c:5, address = 0x0000000100000e7f
(lldb) br comm add --script-type python -o "stopifcaller.stop_if_caller(frame, 'foo')" 1

大功告成 - 断点 1(在 bar() 上)只会在调用方帧为 foo() 时停止。或者换句话说,如果调用者框架不是foo().

,它会继续