I have an application that only crashes in -O2 optimization (compiled with gcc 4.2.4). When I step through the code and get to the spot that crashes and try to inspect the value, I get a "value optimized out" in gdb.
I read on the internet that this means that the value is stored in the register. I was wondering if my crash could be related to the fact that some information is placed in registers? Is there a way to print what is in the registers to see if it has been corrupted? Is there a way to keep optimizations but not use registers?
Thanks!
It means you compiled with e.g. gcc -O3 and the gcc optimiser found that some of your variables were redundant in some way that allowed them to be optimised away.
(transitive, programming) To omit (some portion of program logic) through optimization, when it is found to be unused or unnecessary.
Another option to see all <optimized out> variables in gdb is of course disabling gccoptimization altogether. Look for compilation flags (e.g., in CFLAGS) in your Makefile. You will find something like '-O1', '-O2' or '-O3', which defines various levels of gcc optimization. Remove this flag, or change it to '-O0'.
(definition) Definition: The minimum (or maximum) value of the objective function over the feasible region of an optimization problem.
It's 99% likely to be a bug in your code and 1% likely to be a compiler code generation bug. So spend a proportionate amount of time looking for latent bugs in your code but be aware that you just may have found a code generation bug (in which case you'll need to study the compiler generated code carefully to see what the problem is).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With