bbazso
bbazso

Reputation: 2049

Is <value optimized out> in gdb a problem?

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!

Upvotes: 9

Views: 12435

Answers (5)

MikeW
MikeW

Reputation: 41

The one thing to watch is pointer aliasing, where the compiler can make assumptions that you do not comply with, for example that a pointer you pass into a function does not point to a global variable also used by that function. But you can control this with compiler options etc.

Upvotes: 0

Adam Goode
Adam Goode

Reputation: 7468

This is not a problem, it is more of an issue with the aggressive optimizations in newer versions of gcc.

See: A Plan to Fix Local Variable Debug Information in GCC.

Upvotes: 0

amo-ej1
amo-ej1

Reputation: 3307

If you can detect the error in your program flow you could do some printing yourself, if it has something to do with memory leaks and memory corruption, then valgrind is probably a better friend than gdb.

Upvotes: 2

Paul R
Paul R

Reputation: 212979

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

Upvotes: 11

Stefano Borini
Stefano Borini

Reputation: 143795

try info registers in gdb.

You can disable optimization with -O0, but there's something fishy and I suggest you to investigate further and eventually post the code.

Upvotes: 5

Related Questions