'Project Name' was compiled with optimizat

2019-01-03 22:22发布

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.

enter image description here

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.

enter image description here

UPDATE 2

Strip Debug Symbols Is off as well.

12条回答
来,给爷笑一个
2楼-- · 2019-01-03 23:04

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:

  1. Select your project in the Project Navigator pane
  2. Select your project's settings under the "PROJECT" tree
  3. Click "Build Settings" tab
  4. Search for "Optimization Level" and you'll see two settings, one for LLVM and one for swift.
  5. Set the appropriate setting (None [-O0] for LLVM and None [-0none] for Swift) for the build config in question.

was compiled with optimization stepping may behave oddlyvariables may not be available

Doing this resolved that warning for me.

查看更多
Explosion°爆炸
3楼-- · 2019-01-03 23:05

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:

  • Click on your scheme in the top-left corner of Xcode.

Click on your scheme in the top-left corner of Xcode.

  • Select "Edit Scheme..."

Select "Edit Scheme..."

  • Click on the "Build Configuration" dropdown. and change it to Debug mode.

Click on the "Build Configuration" dropdown.

查看更多
闹够了就滚
4楼-- · 2019-01-03 23:05

Editor -> Validate Settings then confirm all changes. Then you should get Swift Compiler Optimisation Level in place

Set Debug to None.

查看更多
乱世女痞
5楼-- · 2019-01-03 23:06

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.

enter image description here

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-03 23:08

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).

查看更多
该账号已被封号
7楼-- · 2019-01-03 23:09

It's been a long time but I finally solved the issue. There is a third optimization flag LTO or Link 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 the Optimization 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 :

  • LLVM Link Time Optimization (-flto)
  • LLVM Optimization Level (-O)
  • Swift Compiler Optimization Level

enter image description here

More information about LTO: http://llvm.org/docs/LinkTimeOptimization.html

查看更多
登录 后发表回答