【问题标题】:XCode/LLDB: Can LLDB break on the calling function?XCode/LLDB:LLDB 可以在调用函数上中断吗?
【发布时间】:2015-01-08 20:58:51
【问题描述】:

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

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

有没有办法做到这一点?

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

谢谢!

【问题讨论】:

标签: ios objective-c xcode debugging lldb


【解决方案1】:

您可以在断点上使用一些 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(),它将继续。

【讨论】:

  • 这太棒了!我也很幸运使用stop_if_caller_in 函数。一个问题:有没有办法告诉它执行指定的一系列断点命令(已经用 XCode 设置好了)?这似乎完全取代了旧断点
  • 我输入它为br comm add 2 --script-type... Breakpoint 2 有我想要运行的命令
  • 断点命令实际上有3种,lldb命令行命令,python命令和C++回调。但是 lldb 每个断点只支持一种风格。 Xcode 实际上使用 C++ 回调,然后运行您输入的 lldb 命令及其日志操作等。因此,目前确实没有办法同时使用 python 命令和 Xcode 已经设置的命令.
猜你喜欢
  • 2017-03-22
  • 2010-10-11
  • 2018-10-14
  • 2020-04-30
  • 2019-10-17
  • 2012-08-18
  • 2014-01-25
  • 2012-05-18
相关资源
最近更新 更多