Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is <value optimized out> in gdb a problem?

Tags:

c++

gcc

gdb

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!

like image 395
bbazso Avatar asked Feb 16 '10 15:02

bbazso


People also ask

Why does GDB say optimized out?

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.

What does optimized out mean?

(transitive, programming) To omit (some portion of program logic) through optimization, when it is found to be unused or unnecessary.

How do I get rid of optimized in GDB?

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'.

What is optimized value?

(definition) Definition: The minimum (or maximum) value of the objective function over the feasible region of an optimization problem.


1 Answers

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).

like image 178
Paul R Avatar answered Sep 23 '22 21:09

Paul R