You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用boost::system::error_code::message()触发__cxa_pure_virtual()崩溃求助

问题描述

环境信息:

  • Boost版本:1.68.0
  • 操作系统:Linux IVI 5.4.134 #1 SMP PREEMPT Tue Mar 18 01:00:37 CST 2025 aarch64 GNU/Linux
  • 编译器:gcc7.3

多次调用boost::system::error_code.message()(示例代码:LOG("open error: %d, %s", ec.value(), ec.message().c_str()))时程序崩溃,核心转储信息如下:

#0  __GI_raise (sig=sig@entry=6) at /usr/src/debug/glibc/2.27-r0/git/sysdeps/unix/sysv/linux/raise.c:51
#1  0x0000ffff8c0f91d0 in __GI_abort () at /usr/src/debug/glibc/2.27-r0/git/stdlib/abort.c:79
#2  0x0000ffff8c3b5a94 in __gnu_cxx::__verbose_terminate_handler () at /usr/src/debug/gcc-runtime/7.3.0-r0/libstdc++-v3/libsupc++/vterminate.cc:95
#3  0x0000ffff8c3b36d4 in __cxxabiv1::__terminate (handler=<optimized out>)
    at /usr/src/debug/gcc-runtime/7.3.0-r0/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4  0x0000ffff8c3b3720 in std::terminate () at /usr/src/debug/gcc-runtime/7.3.0-r0/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5  0x0000ffff8c3b45b0 in __cxxabiv1::__cxa_pure_virtual () at /usr/src/debug/gcc-runtime/7.3.0-r0/libstdc++-v3/libsupc++/pure.cc:50
#6  0x0000ffff7438e084 in boost::system::error_code::message[abi:cxx11]() const (this=<optimized out>)

排查细节

通过gdb检查system_category()返回的静态变量:

(gdb) p boost::system::system_category()::system_category_instance
$1 = {<boost::system::error_category> = {<boost::noncopyable_::noncopyable> = {<No data fields>}, 
    _vptr.error_category = 0xffff743c4bd0 <vtable for boost::system::error_category+16>, 
    std_cat_ = {<std::_V2::error_category> = {
        _vptr.error_category = 0xffff743c4c18 <vtable for boost::system::error_category::std_category+16>}, 
      pc_ = 0xffff743c8088 <boost::system::system_category()::system_category_instance>}}, <No data fields>}
(gdb) x /8a 0xffff743c4bd0
0xffff743c4bd0 <_ZTVN5boost6system14error_categoryE+16>:        0x0     0x0
0xffff743c4be0 <_ZTVN5boost6system14error_categoryE+32>:        0xffff8c3b4590 <__cxxabiv1::__cxa_pure_virtual()> 0xffff8c3b4590 <__cxxabiv1::__cxa_pure_virtual()>
0xffff743c4bf0 <_ZTVN5boost6system14error_categoryE+48>:        0xffff74364838 <boost::system::error_category::default_error_condition(int) const> 0xffff74364880 <boost::system::error_category::equivalent(int, boost::system::error_condition const&) const>
0xffff743c4c00 <_ZTVN5boost6system14error_categoryE+64>:        0xffff743648e8 <boost::system::error_category::equivalent(boost::system::error_code const&, int) const>    0x0

发现该实例的虚表指向boost::system::error_category+16,但正常情况下应该指向boost::system::detail::system_error_category+16。第5帧的PC地址位于该虚表中__cxa_pure_virtual()的位置,说明实际调用了纯虚函数,这是崩溃的直接原因。

查看正确的system_error_category虚表信息,其中对应位置的第4个函数地址应为system_error_category::message():

(gdb) x /16a 0x0000ffff743c4ca0
0xffff743c4ca0 <_ZTVN5boost6system6detail21system_error_categoryE>:     0x0     0xffff743c4a48 <_ZTIN5boost6system6detail21system_error_categoryE>
0xffff743c4cb0 <_ZTVN5boost6system6detail21system_error_categoryE+16>:  0xffff743650e0 <boost::system::detail::system_error_category::~system_error_category()> 0xffff74365140 <boost::system::detail::system_error_category::~system_error_category()>
0xffff743c4cc0 <_ZTVN5boost6system6detail21system_error_categoryE+32>:  0xffff743647f8 <boost::system::detail::system_error_category::name() const>     0xffff74366320 <boost::system::detail::system_error_category::message[abi:cxx11](int) const>
0xffff743c4cd0 <_ZTVN5boost6system6detail21system_error_categoryE+48>:  0xffff74367608 <boost::system::detail::system_error_category::default_error_condition(int) const>       0xffff74364880 <boost::system::error_category::equivalent(int, boost::system::error_condition const&) const>
0xffff743c4ce0 <_ZTVN5boost6system6detail21system_error_categoryE+64>:  0xffff743648e8 <boost::system::error_category::equivalent(boost::system::error_code const&, int) const> 0x0
0xffff743c4cf0 <_ZTVN5boost9exceptionE+8>:      0xffff743c4a60 <_ZTIN5boost9exceptionE> 0xffff8c3b4590 <__cxxabiv1::__cxa_pure_virtual()>
0xffff743c4d00 <_ZTVN5boost9exceptionE+24>:     0xffff8c3b4590 <__cxxabiv1::__cxa_pure_virtual()>       0x0
0xffff743c4d10 <_ZTVN5boost16exception_detail10clone_baseE+8>:  0xffff743c4a70 <_ZTIN5boost16exception_detail10clone_baseE>     0xffff8c3b4590 <__cxxabiv1::__cxa_pure_virtual()>

目前无法确定问题根因,寻求分析帮助。


内容的提问来源于stack exchange,提问作者Ryan Wong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 18:47:05