MrMaxP
MrMaxP

Reputation: 503

XCode 4 breakpoints not breaking at correct line

My breakpoints have stopped working properly in the latest XCode 4 release. With no change to the project settings, the breakpoints no longer break at the line they are set.

For instance, in one function I can set a breakpoint anywhere within it's body, but the code will always break at the last line of the function.

In another instance, I can set a breakpoint anywhere in one function and the code will break at a line in the middle of a different function in the same file! Tracing through after the break shows that it did break in the wrong place and it's not just a file / debugger sync issue.

I have no idea why this has started. It did however seem to start on new breakpoints while old ones worked. Any new breakpoints I add break in the wrong place. And recently, some files now don't even break at all! I can only assume the breakpoint is so wrong it's moved into code that's not called. I have done numerous internet searches and forum searches for this problem, and although I have found people with similar issues, there was either no solution or the solution listed (rebooting device, swapping debug output, turning off optimization etc.) haven't worked for me.

It is worth mentioninig I'm mostly coding in C++ using .mm files. For the past year of development in XCode 3, and for the last few months in XCode 4 things have been fine! I have debug set up correctly. No optimization on a debug run, no dead code stripping and I'm using the LLVM compiler 2.0 with DWARD with dSYM debug file. However, changing these values makes no difference.

Please help, it's driving me mad!!

An update to this. It's started happening again on a brand new machine with a fresh Lion and xcode install. The whole editor is out of whack. Example below of the errors appearing on the wrong lines.

Errors on the wrong lines!

Upvotes: 6

Views: 4773

Answers (6)

MrMaxP
MrMaxP

Reputation: 503

I have figured out why this happens now. As mentioned in one of the replies you can fix it by deleting the derived data. This will always fix the problem. The editor for some reason loses it's relationship between the source code and the markup of the code it uses to cross reference breakpoints and errors etc. Deleting the derived data forces it to recreate this.

I believe that this only happens with files using C or C++ code. Apple seem to ignore C++ developers on iOS. I know a lot of professional game developers and every single one uses C++ to write games. Apple's lack of support is annoying.

Upvotes: 0

Oliver Pearmain
Oliver Pearmain

Reputation: 20590

With-in "Build Settings" under the project target change the "Optimization Level" for "Debug" to "None".

I found that this fixed the issue for me.

Upvotes: 3

VE2BXA
VE2BXA

Reputation: 51

From what I've read all around, Xcode tend to get confused with breakpoints and the way to get rid of the out-of-sync problem is to clean the "Derived Data"; two ways of cleaning it so far I've found (instructions are valid for Xcode 4.x) :

a) go in the organiser, under the Projects, choose your project and hit that delete on the Derived Data

or

b) go in the Product menu, hold the ALT button on the keyboard and observe that the menu are changing... so the clean transform to "Clean Build Folder..."

Upvotes: 4

Kwexi
Kwexi

Reputation: 1011

This started happening to me after I upgraded to XCode 4. I just deleted all breakpoints, did a clean, then re-added my breakpoints. Seems to work OK now.

Upvotes: 0

MrMaxP
MrMaxP

Reputation: 503

I have fixed this, although I haven't found the root cause.

I removed the references from the project for the files that were not working with breakpoints. I then did a full clean and went into the folders and deleted any build and temporary data. I then opened the project bundle and deleted all data except for the project file itself. I then compiled so it threw up errors due to the missing files. I then put the files back in the project.

Now, the exact same files work fine with breakpoints!

No idea why but happy it's fixed.

Upvotes: 1

Joshua Nozzi
Joshua Nozzi

Reputation: 61228

Have you cleaned your targets? Shift-Cmd-K.

Upvotes: 0

Related Questions