Reputation: 22670
I would like to specifically select optimizations flags to prevent <optimized out>
variables (parameters) in gdb, without resorting to -O0
.
My background is debugging glibc, which cannot be built with -O0
, as it requires some sort of function inlining. However I can see this being useful in general, e.g. to enable useful debugging without totally killing performance.
According to gcc -c -Q -O0 --help=optimizers
, the following 31 optimization flags are enabled by -O1
in addition to the ones enabled at -O0
(with 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
Note: I am aware of selective optimization / volatile as a manual fix, but I am looking for a more general solution.
Upvotes: 1
Views: 301
Reputation: 70981
Not directly answering your question, but what you are probably after is -Og
:
From the 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.
Using --help=optimizers
on -Og
and comparing it with what you get for --help=optimizers
on -O0
then gives you the answer to your question.
Upvotes: 1