1

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 specific function

-[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. Is there perhaps some way to perform a string comparison with this output in a breakpoint conditional?

Thanks!

Mario Marinato
  • 4,561
  • 3
  • 29
  • 49
bcattle
  • 12,115
  • 6
  • 62
  • 82
  • 3
    Take a look at the question [Is there any way to set a breakpoint in gdb that is conditional on the call stack?](http://stackoverflow.com/questions/5336403/is-there-any-way-to-set-a-breakpoint-in-gdb-that-is-conditional-on-the-call-stac) - this applies to GDB but the techniques should all (including Python scripting) be convertible to LLDB. – CRD Jan 08 '15 at 21:43

1 Answers1

4

You can do this with a bit of python scripting on the breakpoint. 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.

Create a python function in your homedir like ~/lldb/stopifcaller.py with these contents

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.

Use it like this in 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(). Or to put it another way, it will continue if the caller frame is not foo().

Jason Molenda
  • 14,835
  • 1
  • 59
  • 61
  • This is fantastic! I'm also having good luck with a `stop_if_caller_in` function. One question: is there a way to tell it to execute the specified series of breakpoint commands (already set up with XCode)? This appears to replace the old breakpoint entirely – bcattle Jan 08 '15 at 23:37
  • I'm entering it as `br comm add 2 --script-type...` Breakpoint 2 has the commands I want to run – bcattle Jan 08 '15 at 23:43
  • 1
    There are actually 3 kinds of breakpoint commands, lldb command-line commands, python commands and a C++ callback. But lldb only supports one flavor per breakpoint. Xcode actually uses a C++ callback which then runs through the lldb commands you've entered, and its log actions, etc. So there really isn't a way at present to use BOTH the python command and the command that Xcode has already set up. – Jim Ingham Jan 09 '15 at 21:52