c - 哪些特定的优化标志负责优化变量

标签 c debugging gcc gdb compiler-optimization

我想专门选择优化标志来防止 <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:

来自GCC documentation :

-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/

相关文章:

c - 如何为不同的机器编译 Linux 可执行文件?

c - 客户端完成消息传递后,服务器无法退出接受循环

c - (int *) 和 (int []) 是一样的吗?

c - SQLite:错误调用 sqlite3_prepare_v2 -> SIGSEGV

c# - 当 .dll 在 Debug模式下请求源代码时

android - Eclipse 未检测到 Nexus 7 平板电脑进行调试

c - 指导我使用套接字 : server-client program that multiplies 2x2-arrays

debugging - System.Data.DataRow.ObjectID在此上下文中不可访问,因为它是 'friend'

c - 附加两个结构

gcc - 使用 g++ 编译 GSL odeiv2