How to automatically set breakpoints on all methods in Xcode?
Solution 1
- Run your app in Xcode.
- Press ⌘⌃Y (Debug -> Pause).
- Go to the debugger console: ⌘⇧C
- Type
breakpoint set -r . -s <PRODUCT_NAME>
(insert your app's name).
lldb will answer with something like...
Breakpoint 1: 4345 locations
Now just press the Continue button.
breakpoint set
is lldb's command to create breakpoints. The location is specified using a regular expression (-r
) on function/method names, in this case .
which matches any method. The -s
option is used to limit the scope to your executable (needed to exclude frameworks).
When you run your app lldb will now break whenever the app hits a function from your main executable.
To disable the breakpoints type breakpoint delete 1
(insert proper breakpoint number).
Solution 2
In some cases, it is more convenient to set breakpoints only on some of the methods.
Using LLDB we can put breakpoint on all ViewDidLoad methods by name, for example.
(lldb) breakpoint set -n ViewDidLoad
Here "-n" means by name.
Also, we can put breakpoints by selector name:
(lldb) breakpoint set -S alignLeftEdges:
Here "-S" means by selector.
Solution 3
There is many possibilities but there is no way to set breakpoints only to your functions. You can try:
breakpoint set -r '\[ClassName .*\]$'
to add breakpoints to all methods in class
breakpoint set -f file.m -p ' *- *\('
to add breakpoints to all methods in file
You can also use it with many files:
breakpoint set -f file1.m -f file2.m -p ' *- *\('
Shortcut:
br se -f file1.m -f file2.m -p ' *- *\('
You can add breakpoints to all methods in all classes with some prefix (and it could me only your classes)
br se -r . -s Prefix
This line (wzbozon answer):
breakpoint set -n viewDidLoad
will set breakpoints on all methods viewDidLoad
in all classes.
I tried but I couldn't set breakpoints only on our own methods.
![Matrosov Oleksandr](https://i.stack.imgur.com/vacMY.jpg?s=256&g=1)
Matrosov Oleksandr
Updated on June 02, 2022Comments
-
Matrosov Oleksandr about 2 years
How do I automatically set breakpoints on all methods in Xcode? I want to know how my program works, and which methods invoke when I interact with the user interface.
-
Matrosov Oleksandr over 12 yearsThanks for the detailed explanation. I tried to show list of the breakpoints and it worked, but how to set breakpoints on all methods with lldb?
-
Nikolai Ruhe over 12 yearsIt's point three in the description above: If your app is named "MyFooApp", type
breakpoint set -r . -s MyFooApp
in the debugger console. -
Matrosov Oleksandr over 12 yearsThanks it's work now (it was my mistake - I made a mistake in entering the name of the project :) sorry). Thank you very much - it's work great!
-
William Entriken over 10 yearsWill this update the breakpoints shown in the code editor? I would like to remove the breakpoints after seeing them... essentially running a code coverage test
-
Chris Paveglio over 8 yearsIs it possible to do this only on a certain group of files or classes? For example I only want my classes, not imported/CocoaPod files.