IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    terminate called after throwing an instance of ‘std::length_error’ what(): basic_string::_S_create

    reille发表于 2019-03-05 15:02:50
    love 0

    调试嵌入式linux应用程序时,出现下述错误:

    terminate called after throwing an instance of ‘std::length_error’
    what():  basic_string::_S_create

    采用在gdb中运行,错误如下:

    [19-03-05 22:04:22.818][DBG][CHA_MAIN][powerIfBase.cpp,L0092] CIF-A send 0x18226401 2 00 00
    [19-03-05 22:04:22.986][DBG][CHA_MAIN][powerIfBase.cpp,L0135] CIF-A recv 0x18210164 0
    [19-03-05 22:04:22.986][DBG][CHA_MAIN][powerIfXpeng.cp,L0521] receive data of yx —————

    [19-03-05 22:04:23.183][DBG][CHA_MAIN][ccoreIfXpeng.cp,L0864] frame length [4] less than min [8]
    [19-03-05 22:04:23.183][DBG][CHA_MAIN][ccoreIfXpeng.cp,L0871] frame data length [22] mismatch frame length [29]
    [19-03-05 22:04:23.183][DBG][CHA_MAIN][ccoreIfXpeng.cp,L0914] << receive frame (30 bytes): 68 00 01 04 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FFFFFFA0 0F FFFFFFAF 16
    [19-03-05 22:04:23.183][DBG][CHA_MAIN][ccoreIfXpeng.cp,L0718] receive ccore-yc data (len [22])
    [New Thread 14748.0x5e78]
    [19-03-05 22:04:23.317][DBG][CHA_MAIN][powerIfBase.cpp,L0092] CIF-A send 0x18226401 2 00 00
    [New Thread 14748.0x2fbc]
    [19-03-05 22:04:23.470][DBG][CHA_MAIN][ccoreIfXpeng.cp,L0999] send yx to ccore [ok]
    [19-03-05 22:04:23.470][DBG][CHA_MAIN][ccoreIfXpeng.cp,L1051] send yc to ccore [ok]
    [New Thread 14748.0×6160]
    [19-03-05 22:04:23.474][DBG][CHA_MAIN][powerIfBase.cpp,L0092] CIF-A send 0x18416401 8 15 00 00 00 00 00 00 00
    terminate called after throwing an instance of ‘std::length_error’
    what():  basic_string::_S_create

    Program received signal SIGABRT, Aborted.
    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    0x00000000 in ?? ()
    warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)

    大体上应该是操作basic_string时发生了错误,根据错误描述,是basic_string抛出了个异常。

    在basic_string.h头文件中搜索“std::length_error”,如下:

    std::length_error  If @a res_arg exceeds @c max_size().
    std::length_error  If new length exceeds @c max_size().

    使用gdb查看core文件堆栈信息,如下:

    1551796783(1)

    没发现有啥有用信息。

    现在有如茫茫大海,无从查起的感觉。无耐之下,在偶然间重新运行,发现打印日志有异常,如下图红色所示:

    1551796696(1)

    这条日志输出是有异常的,本来是打印报文,都是2位十六进制,这里却出现了4个字节的报文打印,而且发送数据长度显示为32 bytes。找到代码如下,发现有异常,如红色框框所示。

    1551796206(1)

    增加数据类型强制转换即可解决问题:

    const int n = sprintf(buf, "%02X ", (__u8)frame[i]);

    参考文章:

    • Linux下gdb调试生成core文件并调试core文件
    • 这个C++错误STD::Length_Error的含义是什么?
    • std::length_error
    » 本文地址: http://velep.com/archives/1421.html
    » 文章出处: reille博客—http://velep.com , 如果没有特别声明,文章均为reille博客原创作品
    » 郑重声明: 原创作品未经允许不得转载,如需转载请联系reille#qq.com(#换成@)
    分享到:
    推荐阅读相关文章:
    • 编译错误:error: stray ‘\357’ in program
    • linux backtrace()详细使用说明,分析Segmentation fault
    • linux下统计代码执行时间
    • likely(x)与unlikely(x)函数,即__builtin_expect的使用
    • 干掉你程序中的僵尸代码
    • Linux平台下如何检测、调试C/C++程序内存泄漏?
    • ymodem源码(基于C语言实现)
    • jsoncpp按插入顺序排序和支持指定小数位数


沪ICP备19023445号-2号
友情链接