Unrolled Loops, the Debugger, and YOU

I’ve just completed a 16-hour (off and on) “what the fuck?!” session with Xcode (3 and 4). Specifically, when debugging a specific class, gdb kept telling me, “Unable to access variable…” any time I’d “po” a variable or hover over the symbol in the editor. I blamed plenty of different possible culprits.

I didn’t remember having changed any of the target’s settings, but I tried playing with various combinations of compiler, debugging symbol levels, etc. to no avail. Because I’ve been testing Xcode 4 heavily, I then assumed the problem had something to do with having 3 and 4 installed alongside each other. To test this, I tried simply reinstalling 3. No luck. Uninstalled 4 and 3, reinstalled 3. Still no luck.

Frustrated beyond all fucking reason, I started stepping through every single call that lead up to the problem area. An interesting pattern emerged. Everything worked fine (po and hover-over-symbol) until I’d get inside a loop in certain files. Now it took awhile for me to notice this because of its apparent intermittence. Then it hit me. Those were files I … er … optimized.

Long story short: the “unroll loops” compiler flag and the debugger don’t get along very well.

I had forgotten that for some of the “loopier” classes I’d set this complier flag and gained measurable performance increases. I did this by clicking the file, then hitting Cmd-I for the file’s info. Under the build tab, I added this:

-funroll-loops

So once I removed this, magically the debugger (and Xcode’s editor) began providing helpful information once again. As I said on Twitter, it’s quite a stupid thing to lose two days over.

(sigh)

Update: For other causes and cures for debugger problems, see my post titled “Buggered Debugger“.

Related Posts