1

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.

1

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 '18 at 16:24
  • Now it is showing all variables. I must've not recompiled the file correctly. – JBaczuk Nov 21 '18 at 16:39
  • Glad that I could help! :) – MCCCS Nov 21 '18 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" .... – Pieter Wuille Nov 21 '18 at 17:51
  • 1
    @MCCCS But --enable-debug will pass -Og which overrides the -O0 default. – Pieter Wuille Nov 21 '18 at 18:00

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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