lldb breakpoint on all methods in class objective c

后端 未结 2 1302
鱼传尺愫
鱼传尺愫 2021-02-01 21:49

How can I automate setting a breakpoint on all methods in an Objective C class using lldb?

This is useful for learning the behavior of a complicated legacy class. I am u

相关标签:
2条回答
  • 2021-02-01 22:38

    One option is to use regex breakpoints.

    breakpoint set -r '\[ClassName .*\]$'
    

    You can play around with the regexp to suit your needs.

    The command will create a breakpoint that stops on all methods implemented by that class. However, there will be no breakpoints on methods inherited from superclasses.

    To get methods on the superclass, you'll have to use a conditional breakpoint. For example, if the superclass is UIViewController, you could do something like:

    br s -r '\[UIViewController .*\]$' -c '(BOOL)[(id)$arg1 isKindOfClass:[CustomVC class]]'
    

    For x86 change (id)$arg1 to *(id*)($ebp+8).

    Finally, if you really want to learn about the control flow through various classes, check out dtrace. It's probably more suited to this than a debugger.

    0 讨论(0)
  • 2021-02-01 22:50
    br se -f FooViewController.m -p '^@property|^ *- *\('
    

    "br se" is short for "breakpoint set", pass your own filename to the -f argument, and the -p argument is a crude regex for properties and methods in Objective C.

    Caveats: This doesn't seem to work for .h files, so if you have properties declared in the header that you want to watch then you may need to set watchpoints on their backing instance variables.

    This is the best solution I have found so far, please post alternative solutions if you think they will be helpful.

    0 讨论(0)
提交回复
热议问题