【问题标题】:Why crash inside boost log when program terminate为什么程序终止时在boost日志内崩溃
【发布时间】:2021-01-01 02:00:58
【问题描述】:

我的应用程序使用 boost logger。当我使用 killall myApplication 终止我的程序时。有生成核心文件。然后我使用gdb 并查看跟踪。我也尝试了一些相关的修复,但没有用。 link

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ff95f9aa801 in __GI_abort () at abort.c:79
#2  0x00007ff96240f84a in __gnu_cxx::__verbose_terminate_handler ()
    at /home/nwani/m3/conda-bld/compilers_linux-64_1560109574129/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#3  0x00007ff96240df47 in __cxxabiv1::__terminate (handler=<optimized out>)
    at /home/nwani/m3/conda-bld/compilers_linux-64_1560109574129/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4  0x00007ff96240d3a5 in __cxa_call_terminate (ue_header=ue_header@entry=0x55c83e48bfd0)
    at /home/nwani/m3/conda-bld/compilers_linux-64_1560109574129/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/libstdc++-v3/libsupc++/eh_call.cc:54
#5  0x00007ff96240dbd8 in __cxxabiv1::__gxx_personality_v0 (version=<optimized out>, actions=6, exception_class=5138137972254386944, ue_header=0x55c83e48bfd0, context=0x7ffc786aaa90)
    at /home/nwani/m3/conda-bld/compilers_linux-64_1560109574129/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/libstdc++-v3/libsupc++/eh_personality.cc:677
#6  0x00007ff96235aaab in _Unwind_RaiseException_Phase2 (exc=exc@entry=0x55c83e48bfd0, context=context@entry=0x7ffc786aaa90, frames_p=frames_p@entry=0x7ffc786aa998)
    at /home/nwani/m3/conda-bld/compilers_linux-64_1560109574129/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/libgcc/unwind.inc:64
#7  0x00007ff96235af49 in _Unwind_Resume (exc=0x55c83e48bfd0) at /home/nwani/m3/conda-bld/compilers_linux-64_1560109574129/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/libgcc/unwind.inc:241
#8  0x000055c83c2e5be1 in boost::log::v2_mt_posix::aux::light_rw_mutex::unlock_shared (this=<optimized out>) at /usr/include/boost/log/detail/light_rw_mutex.hpp:115
#9  boost::log::v2_mt_posix::sources::multi_thread_model<boost::log::v2_mt_posix::aux::light_rw_mutex>::unlock_shared (this=<optimized out>) at /usr/include/boost/log/sources/threading_models.hpp:78
#10 boost::log::v2_mt_posix::aux::shared_lock_guard<boost::log::v2_mt_posix::sources::multi_thread_model<boost::log::v2_mt_posix::aux::light_rw_mutex> >::~shared_lock_guard (this=<optimized out>,
    __in_chrg=<optimized out>) at /usr/include/boost/log/detail/locks.hpp:146
#11 boost::log::v2_mt_posix::sources::basic_composite_logger<char, boost::log::v2_mt_posix::sources::severity_logger_mt<severity_level>, boost::log::v2_mt_posix::sources::multi_thread_model<boost::log::v2_mt_posix::aux::light_rw_mutex>, boost::log::v2_mt_posix::sources::features<boost::log::v2_mt_posix::sources::severity<severity_level> > >::open_record<boost::parameter::aux::tagged_argument<boost::log::v2_mt_posix::keywords::tag::severity, severity_level const> > (this=this@entry=0x55c83e46b798, args=...) at /usr/include/boost/log/sources/basic_logger.hpp:458

我的应用程序在 linux 上运行。在类析构函数中,我有日志打印。核心文件显示这是崩溃点。请问是配置问题还是boost库的错误使用?

【问题讨论】:

  • 您可能需要在关机前告诉 boost 日志停止记录。这可能是相关的:stackoverflow.com/questions/42368720/…
  • 您遇到了未捕获的异常。尝试捕捉并检查它,以找出它被抛出的位置和原因。
  • 谢谢,如果有进展我会试试并更新这个帖子
  • 我打印了异常并得到Failed to set TLS value: Invalid argument,我猜这与`_Unwind_RaiseException_Phase2`有关?但我不确定为什么以及如何解决它。
  • @SvenNilsson,谢谢,我试过了。但问题仍然存在。

标签: c++ boost


【解决方案1】:

问题在于,当你的类析构函数被调用时,用于严重级别的线程本地存储已经被破坏了。因此,启动日志记录失败并出现异常,并且由于您没有捕获它,因此程序中止。

recommended 在程序终止期间避免记录。但是,如果您确实需要该日志记录实例,您可以尝试将记录器类型更改为logger_mt。这将从通过该记录器发出的日志记录中删除严重性级别,但您可以使用scoped logger attributes 模拟它。

【讨论】:

  • 谢谢,我试试看。
猜你喜欢
  • 1970-01-01
  • 2018-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-03
  • 1970-01-01
相关资源
最近更新 更多