调试嵌入式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]);

参考文章:

» 文章出处: reille博客—http://velep.com , 如果没有特别声明,文章均为reille博客原创作品
» 郑重声明: 原创作品未经允许不得转载,如需转载请联系reille#qq.com(#换成@)
分享到:

 Leave a Reply

(必须)

(我会替您保密的)(必须)

*

   
© 2012 velep.com | reille blog | 管理| 粤ICP备12094833号-2| 谷歌地图| 百度地图| Suffusion theme|Sayontan Sinha

无觅相关文章插件,快速提升流量