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

Boost异常代码生成ec字符串时崩溃问题排查求助

Boost Unix域套接字初始化崩溃排查:ec.what()触发只读内存写入错误

我在排查基于Boost实现的Unix域套接字初始化崩溃问题时,发现反常现象:崩溃帧出现在解析ec.what()(生成错误字符串消息的函数)过程中。

崩溃调用栈

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   P 0x104919660 boost::system::error_code::what() const (in P_arm64.dsym) + 528 + 251488
1   P 0x104919654 boost::system::error_code::what() const (in P_arm64.dsym) + 516 + 251476
2   P 0x104918ea8 boost::system::system_error::system_error(boost::system::error_code const&, char const*) (in P_arm64.dsym) + 308 + 249512
3   P 0x104adbd10 boost::asio::basic_socket<boost::asio::local::stream_protocol, boost::asio::any_io_executor>::connect(boost::asio::local::basic_endpoint<boost::asio::local::stream_protocol> const&) (in P_arm64.dsym) + 1808 + 2096400
(--> 这是我初始化Unix域套接字的构造函数) 
4   P 0x104ad9ed4 service::api::Instance(std::__1::function<void (std::__1:: 

终止原因及内存区域信息

Termination Reason:    Namespace SIGNAL, Code 10 Bus error: 10
Terminating Process:   exc handler [2253]

VM Region Info: 0x107008fa8 is in 0x107006000-0x10705e000;  bytes after start: 12200  bytes before end: 348247
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      __TEXT                      10664e000-107006000    [ 9952K] r-x/r-x SM=COW  ...s/MacOS/P
---&gt;  __DATA_CONST                107006000-10705e000    [  352K] r--/rw- SM=COW  ...s/MacOS/P
      __DATA                      10705e000-107072000    [   80K] rw-/rw- SM=COW  ...s/MacOS/P

从内存信息可以看出,崩溃是因为程序尝试向只读的__DATA_CONST内存区域写入数据,而这一操作发生在生成错误消息的过程中。

怀疑的相关代码

location()函数实现:

source_location const & location() const BOOST_NOEXCEPT
{
   BOOST_STATIC_CONSTEXPR source_location loc;
   return lc_flags_ >= 4? *reinterpret_cast<source_location const*>( lc_flags_ &~ static_cast<boost::uintptr_t>( 1 ) ): loc;
}

该函数被what()调用,崩溃点指向location().to_string():

std::string what() const
{
    std::string r = message();
    r += " [";
    r += to_string();
    if( has_location() )
    {
        r += " at ";
-->     r += location().to_string();
    }

    r += "]";
    return r;
}

我不清楚程序到底在哪里尝试写入const表达式loc,请问可能的原因是什么?


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 07:50:48