Trying to step into AFNetworking code generates following warning:
[Project Name] was compiled with optimization - stepping may behave oddly; variables may not be available.
And of course I'm not able to debug the code. To be specific I'm trying to debug UIImageView+AFNetworking
category which seems impossible. Changing the code has no effect (tried NSLog
, etc) and when trying to step in compilers goes to assembly code and shows UIImageView+TVASTAFNetworking
as category name which does not exist anywhere in the code base.
Using Xcode 7. iOS 9 & 8. Cocoapods (no Framework)
UPDATE
I forgot to mention that Optimizer is set to none
for both release and debug configuration and I am in fact using Debug
config.
UPDATE 2
Strip Debug Symbols
Is off as well.
If your project is using Swift, there are two separate "Optimization Level" settings in the project/target configuration.
Make sure you set them both correctly:
None [-O0]
for LLVM andNone [-0none]
for Swift) for the build config in question.Doing this resolved that warning for me.
It looks like your project is in Release mode. Release mode compiles the app with lots of optimizations, but debuggers hate optimizations, so to reliably debug the app, you need to switch it to Debug mode which reduces optimization and adds a bunch of debugging information. To switch it to Debug mode:
Editor
->Validate Settings
then confirm all changes. Then you should getSet Debug to
None
.This warning only appear when you hit a breakpoint and the source is in a project where optimization is enabled, preventing you from watching real variable values (every object is shown as nil, even if it's not)
In my case, it only happened when debugging step by step through a cocoapod dependency.
So even if you have your main target and project settings correctly set (Strip Debug Symbol=OFF, and Optimization level None), you need to make sure it is the same for the Pod project your hitting the breakpoint from.
This may be an oversimplification, but are you building for Release or with optimization (which remove symbols from Swift or LLVM) too high? If so edit your scheme and switch to Debug, or edit your Build Settings for swift or LLVM optimization to None (0).
It's been a long time but I finally solved the issue. There is a third optimization flag
LTO
orLink Time Optimization
and Surprisingly no one have mentioned it here and for some reason I didn't pay attention to it either. It's right there above theOptimization Level
setting as you can see in many screen shots posted here.So to summarize it there are 3 different optimization flags you want to turn off for debugging :
-flto
)-O
)More information about LTO: http://llvm.org/docs/LinkTimeOptimization.html