Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting debugger breakpoints across all methods in an Xcode project

How do you trace all the methods invoked across different files in a particular user flow ?

Putting breakpoints at different points and observing the backtrace does not seem like the most efficient way.

Instead I would like to -

1) Put a breakpoint across all methods in the interested project.

2) Make all the breakpoints run a debugger command which prints out the file name and method name.

3) Edit the breakpoints such that the program continues to execute after a breakpoint is hit. (This option is available when you edit a particular breakpoint.) So we don't stop at any breakpoint.

4) Disable all the breakpoints until I reach the flow I need to work on.

5) Enable all the breakpoints right before starting the flow. With this approach, we don't have to manually put breakpoints at different places to understand the execution flow. Once the flow is complete, I can just look at the debugger console and figure out the execution flow.

Now, the question - How can we do this using lldb commands? Would appreciate any input/suggestions.

like image 246
newbie Avatar asked Jun 30 '26 07:06

newbie


1 Answers

You can't do this with the Xcode breakpoint interface, but in the lldb console you can do:

(lldb) break set -r . -s AppName
Breakpoint 1: 478 locations.
(lldb) br com add
Enter your debugger command(s).  Type 'DONE' to end.
> bt 
> continue 
> DONE
(lldb)

That sets a "symbol name match regular expression breakpoint" on all names ("." matches everything) in the binary/shared library called AppName. If you leave off the -s option, it will match all symbols everywhere. That will work but quite slowly...

The command prints a backtrace and continues.

This makes just ONE breakpoint, so you can do:

(lldb) break disable 1

Till you need it, and then enable it with:

(lldb) break enable 1

If you only want to catch some methods, you can adjust the regular expression, and if you find you aren't interested in some of the places you are hitting, you can individually disable locations within the breakpoint you've made this way.

(lldb) break list 1

Will show you all the locations, and:

(lldb) break disable 1.2-1.10 1.15

etc. will disable the locations.

This might get a little slow, because your app will be starting & stopping all the time. But it will do what you are asking.

like image 194
Jim Ingham Avatar answered Jul 02 '26 23:07

Jim Ingham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!