Xcode中Build Settings Level的设置

LLDB中使用po打印变量时,变量为空,且会抛出如下报错信息:

error: warning: couldn’t get cmd pointer (substituting NULL): extracting data from value failed
Couldn’t materialize: couldn’t get the value of variable now: no location, value may have been optimized out
Errored out in Execute, couldn’t PrepareToExecuteJITExpression

解决方案:

1.Produc-> Scheme-> Edit Scheme -> run ,Build Configuration 改为Debug.
2.如果scheme已经是Debug, 则在Build Settings > Optimization Level项,将Debug的值设置为None[-O0]

什么是Optimization Level

下面是苹果的官方解释:

Specifies the degree to which the generated code is optimized for speed and binary size.

  • None[-O0]: Do not optimize. With this setting, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code.

  • Fast[-O1]: Optimizing compilation takes somewhat more time, and a lot more memory for a large function. With this setting, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time. In Apple's compiler, strict aliasing, block reordering, and inter-block scheduling are disabled by default when optimizing.

  • Faster[-O2]: The compiler performs nearly all supported optimizations that do not involve a space-speed tradeoff. With this setting, the compiler does not perform loop unrolling or function inlining, or register renaming. As compared to the 'Fast' setting, this setting increases both compilation time and the performance of the generated code.

  • Fastest[-O3]: Turns on all optimizations specified by the 'Faster' setting and also turns on function inlining and register renaming options. This setting may result in a larger binary.

  • Fastest, Smallest[-Os]: Optimize for size. This setting enables all 'Faster' optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.

  • Fastest, Aggressive Optimizations[-Ofast]: This setting enables 'Fastest' but also enables aggressive optimizations that may break strict standards compliance but should work well on well-behaved code.

在Xcode中,为了方便调试,通常Debug模式默认为None[-O0],Release模式默认为Fastest, Smallest[-Os],在实际的项目中,可以根据项目的情况设置优化级别。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,157评论 0 10
  • 问题 LLDB中使用po打印变量时,变量为空,且会抛出如下报错信息: 解决方案: Produc-> Scheme-...
    木小土阅读 14,040评论 0 13
  • 基本的PHP语法## PHP脚本可以放在文档中的任何位置。PHP脚本以<?php开始,以?>结束:<?php// ...
    love颜文字阅读 3,093评论 0 0
  • 布林 OR || 你可以寫 sony OR 索尼,或sony || 索尼,兩者的意思都是一樣的,找出有sony或索...
    Rolence阅读 1,345评论 0 0