I ran the configure script with the --enable-debug flag, then ran make. I am running unit tests:

gdb --args src/test/test_bitcoin --log_level=all --run_test=script_standard_tests

I'm trying to step through the execution of the source files using gdb, but I am still getting <optimized out> for many variables, and it skips lines here and there. I thought that the --enable-debug flag would turn off optimization, but am I mistaken? I'm wondering if the optimization is always on for the tests or if there is a way to turn them off.

2 Answers 2


Bitcoin Core disables -O2 and enables -Og when --enable-debug is set. -Og is intended for debugging; however, it removes some of the debugging information and is buggy. To disable it and to improve debugging experience, I suggest changing between L256 and L278 to:

CXXFLAGS="-ggdb3 -ftrapv"

-ggdb3 is more powerful than -g3, it uses a GDB-only, LLDB-incompatible dialect for debugging. This will also get rid of -O2, except in libsecp256k1.

Edit: Sipa suggests a more elegant way without altering autoconf files, which is adding args for configuring.

./configure CXXFLAGS="-O0 -ggdb3"

O0 is needed in this case.

  • Nice workaround, thanks. I'm still getting <optimized out>, though, I must be missing something.
    – JBaczuk
    Nov 21, 2018 at 16:24
  • Now it is showing all variables. I must've not recompiled the file correctly.
    – JBaczuk
    Nov 21, 2018 at 16:39
  • Glad that I could help! :)
    – MCCCS
    Nov 21, 2018 at 16:40
  • 2
    Also there is no need to modify configure.ac, you can override things on the command line by using ./configure CXXFLAGS="-O0 -ggdb3" .... Nov 21, 2018 at 17:51
  • 1
    @MCCCS But --enable-debug will pass -Og which overrides the -O0 default. Nov 21, 2018 at 18:00

As of PR #16435 --enable-debug is actually setting "-O0", so there should be no optimization at all anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.