When I want to do debugging of C or C++ programs, I\'ve been taught to use -O0
to turn optimization OFF, and -ggdb
to insert symbols into the execu
@kaylum just provided some great insight in their comment under my question! And the key part I really care about the most is this:
[
-Og
] is a better choice than -O0 for producing debuggable code because some compiler passes that collect debug information are disabled at -O0.
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options
So, from now on I'm using -Og
(NOT -O0
) in addition to -ggdb
.
UDPATE 13 Aug. 2020:
Heck with this! Nevermind. I'm sticking with -O0
.
With -Og
I get <optimized out>
and Can't take address of "var" which isn't an lvalue.
errors all over the place! I can't print my variables or examine their memory anymore! Ex:
(gdb) print &angle
Can't take address of "angle" which isn't an lvalue.
(gdb) print angle_fixed_p
$6 = <optimized out>
With -O0
, however, everything works fine!
(gdb) print angle
$7 = -1.34869879e+20
(gdb) print &angle
$8 = (float *) 0x7ffffffefbbc
(gdb) x angle
0x8000000000000000: Cannot access memory at address 0x8000000000000000
(gdb) x &angle
0x7ffffffefbbc: 0xe0e9f642
So, back to using -O0
instead of -Og
it is!
-O0
, and I concur] What does <value optimized out> mean in gdb?