我想专门选择优化标志来防止 <optimized out>
gdb 中的变量(参数),无需求助于 -O0
.
我的背景是调试 glibc,它不能用 -O0
构建,因为它需要某种函数内联。但是我可以看到这通常很有用,例如在不完全破坏性能的情况下启用有用的调试。
根据 gcc -c -Q -O0 --help=optimizers
,以下 31 个优化标志由 -O1
启用除了在 -O0
启用的那些(使用 gcc 5.3.1):
-fbranch-count-reg
-fcombine-stack-adjustments
-fcompare-elim
-fcprop-registers
-fdefer-pop
-fforward-propagate
-fguess-branch-probability
-fif-conversion
-fif-conversion2
-finline-functions-called-once
-fipa-profile
-fipa-pure-const
-fipa-reference
-fmove-loop-invariants
-fshrink-wrap
-fsplit-wide-types
-fssa-phiopt
-ftree-bit-ccp
-ftree-ccp
-ftree-ch
-ftree-copy-prop
-ftree-copyrename
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-fre
-ftree-pta
-ftree-sink
-ftree-slsr
-ftree-sra
-ftree-ter
注意:我知道选择性优化/volatile 是一种手动修复,但我正在寻找更通用的解决方案。
最佳答案
没有直接回答你的问题,但你可能想要的是-Og
:
-Og
Optimize debugging experience.
-Og
enables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.
在 -Og
上使用 --help=optimizers
并将其与在 上为
然后给出问题的答案。--help=optimizers
获得的结果进行比较-O0
关于c - 哪些特定的优化标志负责优化变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37236752/