Search code examples
c++debuggingboostgdbboost-test

Boost.Test: How to automatically attach debugger (GDB)?


When executing Boost tests for a project, I see

Test command: ...
Environment variables:
 BOOST_TEST_AUTO_START_DBG=yes
 BOOST_TEST_BUILD_INFO=yes
 BOOST_TEST_CATCH_SYSTEM_ERRORS=yes
 BOOST_TEST_COLOR_OUTPUT=yes
 BOOST_TEST_DETECT_FP_EXCEPTIONS=yes
 BOOST_TEST_LOG_FORMAT=HRF
 BOOST_TEST_LOG_LEVEL=test_suite
 BOOST_TEST_LOG_SINK=stdout
 BOOST_TEST_RANDOM=1
 BOOST_TEST_REPORT_FORMAT=XML
 BOOST_TEST_REPORT_LEVEL=detailed
 BOOST_TEST_REPORT_SINK=...
 BOOST_TEST_RESULT_CODE=yes
...

what confirms that the auto_start_dbg option is set properly. Then, for example, the following failure happens:

unknown location(0): fatal error: in "...": boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::ios_base::failure[abi:cxx11]> >: failed opening file: No such file or directory: iostream error

I would have expected to automatically jump into the interactive debugger instance (GDB, in this case) that traps this exception.

Are my expectations wrong or is there a misconfiguration on my side? How do you use this option?


Solution

  • Are my expectations wrong or is there a misconfiguration on my side? How do you use this option?

    Your expectations are wrong. This option is related to signals only. Try dereferencing a NULL pointer and you'll see gdb autostart for you.

    EDIT (2017/02/21)

    I just thought about a better example. Use assert. Much more convenient to use. It'll raise a SIGABRT.