利用mips-linux-objdump工具解决一个crash问题的全过程

在Linux系统,如果遇到crash问题,是很致命的!!

系统分析方法:

一.定位问题

1.crash日志处理(需要什么工具?分为几步?)

2.问题如何放入到代码中(源代码反汇编,要使用什么工具?)

3.确定crash问题位置(使用crash日志中的反汇编地址在源码中查找对应的位置)

二.分析问题

根据相关的函数以及对应行,进行问题分析。crash的原因很多,一般crash的原因有:

1、最常见的问题是野指针的问题

2、资源找不到的情况

3、内存泄漏的问题

还有很多其他的原因,这里不详细叙述!在未来的日子中慢慢补充!!可以参考下面两篇文章!!

https://blog.csdn.net/yearnedsun/article/details/51210576

https://blog.csdn.net/ivolcano/article/details/90929884

经过对上述问题的定位于分析,确认大致属于什么类型的问题

三.解决方案与实现

根据上述的问题类型,确认类型,然后查找相关的知识,找到对应的解决方案。

案列如下:

一般解决crash的方法有:

1.工具

crash_analyze.pl

mips-linux-objdump

 

2.过程

在调试程序中遇到下面的crash,log如下:

Cpu 0
$ 0   : 00000000 00000001 00000000 005e79a0
$ 4   : 00000000 005e7998 00000004 00000001
$ 8   : 006d8c3c 00000000 00000001 00000024
$12   : fffffffe 00000001 00000000 006d0000
$16   : 005e0000 00000000 007af997 00000001
$20   : 005eb388 00000000 007af7c8 005f0000
$24   : 006c8930 2adfafe0                  
$28   : 2adcd6f0 7f7ff3e8 00702f10 0042a7e0
Hi    : 00000009
Lo    : 00000000
epc   : 2adfaff8     Tainted: P      
ra    : 0042a7e0 Status: 0100fc13    USER EXL IE 
Cause : 00800008
BadVA : 00000000
PrId  : 00019556
Modules linked in: ifxmips_usif_uart_mod ifxusb_driver_mod qos_ingress(P) btn(P) ac494_mod(P) phone_mod(P) silabs_fxs_3226_drv_mod(P) ac49x_dsp_mod(P) watchdog_mod(P) rg_pppoe_relay(P) pppoe_relay(P) rg_ipv4(P) rg_auth1x_pktfil(P) rg_usfs(P) igmp_proxy_mod(P) rtp(P) tcp_mss(P) log_chardev(P) rg_klog_chardev(P) kleds_mod(P) one_module(P) ifxmips_ppa_datapath_d5_mod ifxmips_ppa_hal_d5_mod be_pppos_mod rg_klog_ram_be(P) rg_klog(P)
Process voip_task (pid: 365, threadinfo=858f4000, task=85c78be8)
Stack : 00703468 2adab1a0 005eb388 0000134f 00000000 00000245 2adcd6f0 00779c9c
        00000245 007af9b6 007af9b5 ffffffff ffffffff ffffffff ffffffff ffffffff
        ffffffff ffffffff ffffffff ffffffff 2adcd6f0 7f7ff51c 00000001 2ada8b0c
        61726473 00da8b0c 2aac4920 3d227472 2adcd6f0 005e0000 007af7c8 0000000b
        007af7c8 2ae0825c 005e7ad8 00598e6c 006d0000 7f7ff51c 2ae33630 7f7ff51c
        2ae0fa84 2ae2b510 00000000 00000000 007af9ad 0042aaf4 007af7c8 0042ac50
        005eb428 0000114a 0000000b 007af9ad 005f0000 7f7ff51c 00765a28 00000001
        005f0000 00000000 00702f10 005f0000 7f7ff890 0042f8f8 00000000 006d8760
        005eb91c 000013b1 0000000b 7f7ff51c 00000000 005bae14 006ffe94 00000001
        2adcd6f0 006d87ce 006fbc3c 2adab1a0 006fe688 75612d70 726f6669 6c650d00
        2adcd6f0 00765ac4 006ffe94 005baf48 00000000 00765a88 00765ac4 005a96e0
        00000001 005a9e70 006fc1f8 00000004 006d87ff 00765a88 00765a88 00765358
        00765a28 0051ad28 00000001 00000005 00000000 35034ab1 00702f10 005abd0c
        00000001 00000001 00000005 00765a28 7f7ff5f4 00765a28 005f0000 7f7ff5f8
        00765a28 00000001 00000005 00000000 35034ab1 00702f10 7f7ff890 0042fe10
        006fe688 00000001 005eb8f8 00000722 00000001 00000005 00765a28 00000000
        00000004 00765a28 00000004 00702f10 4e4f5449 46590000 00000000 00000000
        00000000 005abd0c 00765a28 00765a28 00765438 00000001 00000005 00765a88
        00000000 00520a54 00702f10 005abd40 00765a28 00000001 00000005 0042fcec
        00000001 00000000 ffffffff 00517874 00000001 00765a28 00000005 00765a28
        00765364 00702f10 00765358 00574d24 00702f10 00575f58 007034a8 00765358
        00000005 00000005 00000000 00576524 2adcd6f0 00765364 00765a28 00000000
        00000000 00000001 00000402 00765a8c 006fe684 005a9e70 00000000 00765380
        000001e6 00000000 00765364 00000001 00765358 00528ee8 2ae33630 00702f10
        00702f10 00000000 00000000 00000000 00765a28 ffffffff 7f7ff790 00703108
        007031d0 00000001 00700168 00702ef8 0000019f 00000001 00000000 00000000
        00000000 00000000 00000000 00000000 00000000 7f7ff7fa 00000005 7f7ff890
        0072b370 00000002 00702f10 00000000 7f7ff890 00000000 00740f78 0072b370
        2ae33090 00545f50 0072b370 00702f10 00000000 00740f78 7f7ff890 00000002
        00000000 000000e2 00000001 00000000 0072b370 7f7ff890 00740f78 00000475
        00740f78 005395c8 7f7ffe20 00741318 00741318 00000001 7f7ff890 00000002
        00000000 00000000 7f7ff7dc 7f7ff68c 00702f10 00000000 00000001 00000002
        00000000 00740f78 00000000 00000000 13c43232 312e3132 362e3232 312e3232
        36000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
        00000000 00000000 00000000 ffffffff 00000002 00000000 0072b370 00741fb0
        7f7ff890 00000000 00000000 0057f6c4 00000000 00000000 00000000 00000000
        00740f78 7f7ff890 7f7ff88c 7f7ff7d8 2ae33630 7f7ff754 00000008 00000008
        00741fb0 00000000 00000001 dd7edde2 13c40000 00000000 00000000 00000000
        00000000 00000000 7f7ff8ec 7f7ff8e0 7f7ff8f9 006fe684 006ffeac 0072b6e8
        0072b820 7f7ff8f9 0072c030 006a8b54 00000001 005b74a0 2ae1926b 7f7ffad0
        00000000 2adf98c4 00000057 fffffff6 01e33630 7f7ffb68 2ae33630 00000000
        00000010 0000000b 00000000 2adf42dc 006fe688 006fbb30 006d87ce 006fe684
        fffffff6 00000057 2ae33630 2adab1a0 20dcd6f0 7f7ffa30 00000000 00741368
        00741368 7f7ffa00 2adcd6f0 2adab608 2adcd6f0 2adab1a0 000003b5 006d87ce
        2adcd6f0 005ac8b0 2adcd6f0 00741368 00741318 005baf48 006fe68c 00000002
        2adcd6f0 005abc18 2ae33630 00000001 00000014 2adaf170 2adcd6f0 00000402
        00741318 007413c0 2adcd6f0 0059bfd8 00000000 2adab608 006ffeac 0072b6e8
        006fe634 32393439 36373239 36303030 30303000 00741240 006a4b24 ffffffff
        00000000 00000064 00000800 00000020 00000000 00000001 00000006 00000100
        00000800 00000008 00000008 00000008 00000008 00000008 00000008 00000008
        ...

Code: 00001821  10000026  00001021 <90820000> 24e7ffff  1040000d  90a30000  1443000b  00000000 
Cpu 0
$ 0   : 00000000 00000000 00000004 000002b9
$ 4   : 007aea58 00000008 0000ea60 00000001
$ 8   : 00000000 7f000001 7f000001 00001b58
$12   : 00000001 00000001 00000000 006d0000
$16   : 00000008 007aea58 ffffffff 2ab42948
$20   : 40ed4c00 00000000 2ab43480 2ab43564
$24   : 006c8b80 2add4a90                  
$28   : 2ae33630 7ff00d30 2ab43474 2ab214c0
Hi    : 00000140
Lo    : 00000118
epc   : 2add4ab4     Tainted: P      
ra    : 2ab214c0 Status: 0100fc13    USER EXL IE 
Cause : 10800020
PrId  : 00019556
Modules linked in: ifxmips_usif_uart_mod ifxusb_driver_mod qos_ingress(P) btn(P) ac494_mod(P) phone_mod(P) silabs_fxs_3226_drv_mod(P) ac49x_dsp_mod(P) watchdog_mod(P) rg_pppoe_relay(P) pppoe_relay(P) rg_ipv4(P) rg_auth1x_pktfil(P) rg_usfs(P) igmp_proxy_mod(P) rtp(P) tcp_mss(P) log_chardev(P) rg_klog_chardev(P) kleds_mod(P) one_module(P) ifxmips_ppa_datapath_d5_mod ifxmips_ppa_hal_d5_mod be_pppos_mod rg_klog_ram_be(P) rg_klog(P)
Process voip_task (pid: 291, threadinfo=8030c000, task=8798abe8)
Stack : 00000003 00000000 007aea58 00000008 2ae33630 0000040e 00000008 2ab214c0
        1d4c0000 00000000 00000002 00000000 2ab4a940 00000000 007af420 007a3dc0
        ffffffff 2ab42948 40ed4c00 2aaf56b0 006cb098 7ff00f04 2ab4a940 00404374
        2ab4a940 00000000 00000006 00000000 00000006 7ff00e48 7ff00f04 00000001
        7fd1dd18 2aaac5c0 00000000 00000006 7ff00e48 7ff00f04 00000001 00404374
        00405e18 00acb820 7fd1dd18 00406010 2aac4920 7ff00f04 7ff00f0c 7ff00f8c
        00000000 7ff00f04 00000001 00404374 7fd1dd18 2aaac558 2adfa060 004043b0
        2aac4920 00000000 006c0000 7ff00f94 2adcd6f0 7ff00f94 2adfa060 2ae1008c
        2aaa86a4 2aaa8334 00000000 00000000 2ae33630 00000335 00000000 00000000
        00000000 00000000 00000000 00000000 00000003 00400034 00000004 00000020
        00000005 00000008 00000006 00001000 00000007 2aaa8000 00000008 00000000
        00000009 004054d0 00000000 00000000 0000000b 00000000 0000000c 00000000
        0000000d 00000000 0000000e 00000000 2aac4920 004054d0 00000033 00000000
        00000000 00000002 00000003 00405518 00000033 00000000 7fd1dd18 2aaa8a54
        005d9de0 2aaa8c60 7ff00ee0 7ff00f00 00000001 7ff00fa1 00000000 7ff00fb0
        7ff00fb7 7ff00fc2 7ff00fcb 7ff00fdf 00000000 00000010 00000000 00000006
        00001000 00000011 00000064 00000003 00400034 00000004 00000020 00000005
        00000008 00000007 2aaa8000 00000008 00000000 00000009 004054d0 0000000b
        00000000 0000000c 00000000 0000000d 00000000 0000000e 00000000 00000017
        00000000 00000000 00000000 00000000 002f6269 6e2f766f 69705f74 61736b00
        484f4d45 3d2f0054 45524d3d 6c696e75 78006372 616d6673 3d300076 7065315f
        6d656d3d 30783030 32303030 30300061 7369646d 61736b3d 30786666 002f6269
        6e2f766f 69705f74 61736b00 00000000

Code: afbc0010  2402105c  0000000c <10e00007> 00408021  8f9987a8  0320f809  00000000  8fbc0010 

将上述内容保存到系统工程的文件下面,使用如下命令:

vim crash_log.txt

./pkg/tools/crash_analyze.pl -p voip_task < crash_log.txt

 

可以获得:

Function stack which led to the crash:


pc: 0x2adfaff8 undefined
lr: HandleUaProfile           + 0x3d8 (0x42a7e0 : voip_task[.text] + 0x42a7e0)
    RPOOL_FreePage            + 0xdc (0x598e6c : voip_task[.text] + 0x598e6c)
    AclSipMsgGetEventHeader   + 0x1d4 (0x42aaf4 : voip_task[.text] + 0x42aaf4)
    AppPrintMessage           + 0x134 (0x42ac50 : voip_task[.text] + 0x42ac50)
    handleNotification        + 0x1e0 (0x42f8f8 : voip_task[.text] + 0x42f8f8)
    RvAdLockRelease           + 0x10 (0x5bae14 : voip_task[.text] + 0x5bae14)
    RvAdMutexUnlock           + 0x18 (0x5baf48 : voip_task[.text] + 0x5baf48)
    RvSemaphoreTryWait        + 0x90 (0x5a96e0 : voip_task[.text] + 0x5a96e0)
    RvMutexUnlock             + 0xd4 (0x5a9e70 : voip_task[.text] + 0x5a9e70)
    TransactionUnLockAPI      + 0x128 (0x51ad28 : voip_task[.text] + 0x51ad28)
    RvLogTextDebug            + 0x28 (0x5abd0c : voip_task[.text] + 0x5abd0c)
    AclAppTransStateChangedEvHandler + 0x124 (0x42fe10 : voip_task[.text] + 0x42fe10)
    RvLogTextDebug            + 0x28 (0x5abd0c : voip_task[.text] + 0x5abd0c)
    TransactionCallbackStateChangedEv + 0x130 (0x520a54 : voip_task[.text] + 0x520a54)
    RvLogTextInfo             + 0x28 (0x5abd40 : voip_task[.text] + 0x5abd40)
    AclAppTransStateChangedEvHandler + 0x0  (0x42fcec : voip_task[.text] + 0x42fcec)
    TransactionChangeState    + 0x60 (0x517874 : voip_task[.text] + 0x517874)
    TransactionStateSrvGeneralReqRecvd + 0x30 (0x574d24 : voip_task[.text] + 0x574d24)
    HandleGeneralInInitialState + 0x14 (0x575f58 : voip_task[.text] + 0x575f58)
    TransactionMsgReceived    + 0x2e4 (0x576524 : voip_task[.text] + 0x576524)
    RvMutexUnlock             + 0xd4 (0x5a9e70 : voip_task[.text] + 0x5a9e70)
    SipTransactionMgrMessageReceivedEv + 0x91c (0x528ee8 : voip_task[.text] + 0x528ee8)
    TransportCallbackMsgRcvdEv + 0xe0 (0x545f50 : voip_task[.text] + 0x545f50)
    TransportMsgBuilderParseUdpMsg + 0x174 (0x5395c8 : voip_task[.text] + 0x5395c8)
    TransportProcessingQueueDispatchEvents + 0x260 (0x57f6c4 : voip_task[.text] + 0x57f6c4)
    rvFdPreemptionCallback    + 0x114 (0x5b74a0 : voip_task[.text] + 0x5b74a0)
    RvLockRelease             + 0x90 (0x5ac8b0 : voip_task[.text] + 0x5ac8b0)
    RvAdMutexUnlock           + 0x18 (0x5baf48 : voip_task[.text] + 0x5baf48)
    RvLogTextAny              + 0x188 (0x5abc18 : voip_task[.text] + 0x5abc18)
    RA_Alloc                  + 0x218 (0x59bfd8 : voip_task[.text] + 0x59bfd8)

定位到crash的地址为0x42a7e0 

使用反汇编工具,包含HandleUaProfile 函数的编译文件。

mips-linux-objdump -axSDT build/pkg/voip/voip_task > voip_task.lst

运行需要一段时间。然后使用notepad工具或者其他自己习惯的工具打开,使用0x42a7e0搜索

这样定位到了crash在程序中的具体行。再进行分析发现strncmp函数调用引起的。

分析发现应该是犹豫szTok指针可能是null引起的,使用打印log的方式查看一下szTok指针值。

在此确实有null的情况。

然后去参考一下C库中的strncmp函数原型。

/*
*copyright@nciaebupt 转载请注明出处
*原型:int strcmp(const char *s1,const char * s2,size_t n);
*用法:#include <string.h>
*功能:比较字符串s1和s2的前n个字符。
*说明:
*   当s1<s2时,返回值<0
*   当s1=s2时,返回值=0
*   当s1>s2时,返回值>0
*自己实现strncmp
*/
#include <cstdio>
int _strncmp(const char *src,const char *dest,size_t count)
{
    if(count == 0)
        return 0;
    while(count-- && *src && *src == *dest)
    {
        src++;
        dest++;
    }
    return (*(unsigned char *)src - *(unsigned char *)dest);
}

总结:在使用strncmp()函数之前,增加if(szTok != NULL) ,即可解决该问题。

在使用int strncmp ( const char * str1, const char * str2, size_t n )函数时,要确定指针不能为空。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值