r/iOSProgramming • • Oct 31 '20

Discussion Efficiently debugging code using Xcode Breakpoint

207 Upvotes

11 comments sorted by

13

u/SirensToGo Objective-C / Swift Oct 31 '20

You can also do all of this from the lldb itself:

  1. Set a breakpoint somewhere (br s -n "-[Class func]")

  2. Configure the condition with breakpoint modify -c '<<condition>>' 1

  3. Configure expressions to evaluate/actions to perform when the breakpoint is hit with breakpoint command add <<breakpoint ID>>

Knowing how to use lldb for this is really great because not only can it be faster, but Xcode's graphical debugger breaks ALL THE TIME and gives slow and sometimes inaccurate information. lldb directly is faster and also works well on all sorts of different languages

1

u/shubham_iosdev Oct 31 '20

Oh okay, I still haven't explored lldb a lot. Thanks you sharing.

I completely agree, knowing how to do anything via code like say git, is always quicker and efficient :D

1

u/etaionshrd Objective-C / Swift Oct 31 '20

Xcode’s graphical debugger uses the LLDB APIs, though…

2

u/SirensToGo Objective-C / Swift Oct 31 '20

It does, just not well. Have you ever hit a breakpoint in a function with a ton of variables? Xcode just freezes for a like ten seconds while it runs a recursive inspection on every single variable, no matter how complex it is.

2

u/thisura98 Nov 01 '20

Thank you so much. I foune these really useful!!

2

u/shubham_iosdev Nov 01 '20

Its my pleasure u/thisura98 :D

2

u/freakysheep Oct 31 '20

I just do not have the time for fancy breakpoints. The time I would spent to configure special conditions would go to waste for all those "oh, there are 200+ pleasurepoints after 10 minutes of debugging again, lets just delete them all and start over again" moments.

10

u/etaionshrd Objective-C / Swift Oct 31 '20

The time that a good conditional breakpoint saves can be orders of magnitude more than the time it would take to set it, especially if you’re doing things like “on the seventh iteration I need to stop…oops, wrong one, I need to re-run”. Plus, at a certain point you start using the debugger as a REPL: you try out a bunch of things in the debugger and then “commit” them by putting them into the actual code and recompiling. This is especially useful if your build cycle takes more than a few seconds.

1

u/shubham_iosdev Oct 31 '20

Discussion

Hahaha I feel the pain, oh adding and removing breakpoints all the time :P

8

u/[deleted] Oct 31 '20

[removed] — view removed comment

4

u/shubham_iosdev Oct 31 '20

Thank you, yeah I feel this is better, easy to follow and no tab change :D