c++boost-asiodebug-symbolsbacktracedebug-backtrace

Stack trace from backtrace didn't show method that caused the crash under multithreaded enviroment


I was trying to capture exactly which method, or at least which class crashed my code from
messages returned by backtrace after received the SIGSEGV signal. Is it because the crashed method was executing on another thread, therefore backtrace was unable to do so (see the first line of my log - process id is 7fdae0268700, i added code there to crash my app)? Any recommendation to this issue please?

    2013-03-07 17:43:42.863709502 [7fdae0268700] DEBUG data_service - I Crash You! Location
    2013-03-07 17:43:42.863804548 [7fdae7d1c720] INFO  service_runner - Receive signal 11
    2013-03-07 17:43:42.870357301 [7fdae7d1c720] DEBUG service_runner - [bt]: (0) ../Debug/MyAppService : my_app_service_lib::service_runner::handle_crash_stop(boost::system::error_code const&, int)+0x7e [0xcccf54]
    2013-03-07 17:43:42.870369392 [7fdae7d1c720] DEBUG service_runner - [bt]: (1) ../Debug/MyAppService : boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>::operator()(my_app_service_lib::service_runner*, boost::system::error_code const&, int) const+0x74 [0xcd8278]
    2013-03-07 17:43:42.870384611 [7fdae7d1c720] DEBUG service_runner - [bt]: (2) ../Debug/MyAppService : void boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> >::operator()<boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list2<boost::system::error_code const&, int const&> >(boost::_bi::type<void>, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>&, boost::_bi::list2<boost::system::error_code const&, int const&>&, int)+0x7c [0xcd80c6]
    2013-03-07 17:43:42.870395158 [7fdae7d1c720] DEBUG service_runner - [bt]: (3) ../Debug/MyAppService : void boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > >::operator()<boost::system::error_code, int>(boost::system::error_code const&, int const&)+0x4c [0xcd7f0e]
    2013-03-07 17:43:42.870405480 [7fdae7d1c720] DEBUG service_runner - [bt]: (4) ../Debug/MyAppService : boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > >, boost::system::error_code, int>::operator()()+0x2b [0xcd7e15]
    2013-03-07 17:43:42.870419010 [7fdae7d1c720] DEBUG service_runner - [bt]: (5) ../Debug/MyAppService : void boost::asio::asio_handler_invoke<boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > >, boost::system::error_code, int> >(boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > >, boost::system::error_code, int>, ...)+0x62 [0xcd7d2e]
    2013-03-07 17:43:42.870436180 [7fdae7d1c720] DEBUG service_runner - [bt]: (6) ../Debug/MyAppService : void boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > >, boost::system::error_code, int>, boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > > >(boost::asio::detail::binder2<boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > >, boost::system::error_code, int>&, boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > >&)+0x64 [0xcd7bea]
    2013-03-07 17:43:42.870447863 [7fdae7d1c720] DEBUG service_runner - [bt]: (7) ../Debug/MyAppService : boost::asio::detail::signal_handler<boost::_bi::bind_t<void, boost::_mfi::mf2<void, my_app_service_lib::service_runner, boost::system::error_code const&, int>, boost::_bi::list3<boost::_bi::value<my_app_service_lib::service_runner*>, boost::arg<1>, boost::arg<2> > > >::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long)+0xb9 [0xcd78db]
    2013-03-07 17:43:42.870454915 [7fdae7d1c720] DEBUG service_runner - [bt]: (8) ../Debug/MyAppService : boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long)+0x32 [0xcce3ba]
    2013-03-07 17:43:42.870462704 [7fdae7d1c720] DEBUG service_runner - [bt]: (9) ../Debug/MyAppService : boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service::thread_info&, boost::system::error_code const&)+0x1a1 [0xcd09b3]
    2013-03-07 17:43:42.870469226 [7fdae7d1c720] DEBUG service_runner - [bt]: (10) ../Debug/MyAppService : boost::asio::detail::task_io_service::run(boost::system::error_code&)+0x137 [0xcd050b]
    2013-03-07 17:43:42.870474974 [7fdae7d1c720] DEBUG service_runner - [bt]: (11) ../Debug/MyAppService : boost::asio::io_service::run()+0x2f [0xcd0d31]
    2013-03-07 17:43:42.870480654 [7fdae7d1c720] DEBUG service_runner - [bt]: (12) ../Debug/MyAppService : my_app_service_lib::service_runner::run()+0x97 [0xcccda9]
    2013-03-07 17:43:42.870486438 [7fdae7d1c720] DEBUG service_runner - [bt]: (13) ../Debug/MyAppService : main+0x4cc [0xcc5838]
    2013-03-07 17:43:42.870491274 [7fdae7d1c720] DEBUG service_runner - [bt]: (14) /lib64/libc.so.6 : __libc_start_main+0xfd [0x3f0f01ecdd]
    2013-03-07 17:43:42.870495884 [7fdae7d1c720] DEBUG service_runner - [bt]: (15) ../Debug/MyAppService() [0xcc5289]

Solution

  • If you're using a handler invoked by boost::asio::signal_set::async_wait to call backtrace_symbols(3) this won't work. The signal_set class uses a signalfd on Linux, other platforms may use the pipe-select-interrupt trick, I dontt know specifically. So when your handler is invoked it won't be from the thread that caused the SEGV.

    It's generally not adviseable to try and do anything smart/cute upon encountering a SEGV signal. You cannot reliably continue execution. I suggest not handling the SEGV signal and instead configure your system to core dump when a process has terminated abnormally, then analyze the core dump.