Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lldb breakpoint on all methods in class objective c

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 using Xcode (includes lldb) for iOS development, and it is cumbersome to manually go through the (large) file in Xcode and click the gutter next to each method to set breakpoints.

like image 955
tboyce12 Avatar asked Apr 16 '15 23:04

tboyce12


People also ask

How to set breakpoint in lldb?

In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )

How do I quit LLDB?

Type quit to exit the lldb session.

What is LLDB in Xcode?

LLDB is a debugging component used in the LLVM project which was developed by the LLVM developer group. Xcode uses the LLDB as the default debugging tool. The full form of LLDB is Low-level debugger. Breakpoints help a developer to stop the execution of the program at any point.


1 Answers

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.

like image 74
Dave Lee Avatar answered Oct 15 '22 21:10

Dave Lee