简体   繁体   English

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

[英]XCode/LLDB: Can LLDB break on the calling function?

I'm setting a symbolic breakpoint on -[CALayer setSpeed:] , and I'd like the breakpoint to only be triggered when the function is called by a sepcific function 我在-[CALayer setSpeed:]上设置了一个符号断点,并且我希望仅当该函数由另一个函数调用时才触发断点

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

Is there a way to do this? 有没有办法做到这一点?

I can see the value of the calling function manually, by doing bt 2 . 通过执行bt 2 ,我可以手动看到调用函数的值。 Is there perhaps some way to perform a string comparison with this output in a breakpoint conditional? 在断点条件下,也许有某种方法可以对此输出执行字符串比较吗?

Thanks! 谢谢!

You can do this with a bit of python scripting on the breakpoint. 您可以在断点上使用一些python脚本来做到这一点。 It means that lldb will stop the process every time the breakpoint is hit and resume it -- for a really hot function like objc_msgSend, this will impact performance dramatically. 这意味着lldb每次遇到断点时都会停止该过程并恢复它-对于像objc_msgSend这样的真正热门的函数,这将极大地影响性能。

Create a python function in your homedir like ~/lldb/stopifcaller.py with these contents 使用以下内容在您的homedir中创建一个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()

Then put 然后放

command script import ~/lldb/stopifcaller.py

in your ~/.lldbinit file. ~/.lldbinit文件中。

Use it like this in lldb: 在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

and you're done - breakpoint 1 (on bar() ) will only stop if the caller frame is foo() . 完成了-断点1(在bar() )仅在调用者框架为foo()停止。 Or to put it another way, it will continue if the caller frame is not foo() . 换句话说,如果调用者框架不是foo() ,它将继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM