Skip to content

How to debug CPU exceptions

leafy.myeh@xradiotech.com edited this page Mar 9, 2018 · 3 revisions

现象

exception:6 happen!!
appos pstack:0x53d30 msp:0x7ffe0 psp:0x53d50
usage fault happen, UFSR:0x1
CPU registers:
R00:[0x53d50]: 0x00000015
R01:[0x53d54]: 0x0005bf48
R02:[0x53d58]: 0xffff67c9
R03:[0x53d5c]: 0x00058ff0
R04:[0x53d30]: 0xd7e33f4a
R05:[0x53d34]: 0x00058b28
R06:[0x53d38]: 0xffffb7b9
R07:[0x53d3c]: 0x00000000
R08:[0x53d40]: 0x00000016
R09:[0x53d44]: 0xfe2ebdc6
R10:[0x53d48]: 0x7ffcb263
R11:[0x53d4c]: 0x6dc253f0
R12:[0x53d60]: 0xff86c25d
R14(LR):[0x53d64]: 0x00000000
R15(PC):[0x53d68]: 0x10006fe2
xPSR:[0x53d6c]: 0x41000000
SHCSR:0x00070008 step:0
FPSCR:0xe000ed38

stack info:
[0x53d70]: 0x00000000 0x00000004 0x00000002 0xbe2500aa 
[0x53d80]: 0x00058688 0x70dcebe4 0xc39e4949 0x00033460 
[0x53d90]: 0x798d6e73 0xd7e33f4a 0x00000000 0x00058b28 
[0x53da0]: 0x7ddd40a7 0xe8b71176 0x7f6d20b7 0xf3e4fe2f 
[0x53db0]: 0x7fe47e40 0xfac1a3c7 0x7fffc694 0x00000012 
[0x53dc0]: 0x0000003c 0x00000016 0x00000013 0x10003c99 
[0x53dd0]: 0x000000b1 0x000587d8 0x00058572 0x00058b28 
[0x53de0]: 0x00059d28 0x00000004 0x00058518 0xffff7d7d 
[0x53df0]: 0xffff7db5 0xffff74fc 0xffff6d43 0x00000012 
[0x53e00]: 0x0000abba 0x00000000 0x00058560 0x00058b28 
[0x53e10]: 0x00000000 0x00058518 0x00000000 0x00058560 
[0x53e20]: 0x000574b8 0x000587d8 0x00058688 0x10003897 
[0x53e30]: 0x000586b0 0x00058560 0x00058af0 0x1000481e 
[0x53e40]: 0x00000000 0x00058b28 0x00058b28 0x00058af0 
[0x53e50]: 0x000586f8 0x00059d2c 0x00000000 0x00059d2c 
[0x53e60]: 0x00000000 0x00000000 0x000584f4 0x000574b8 

[LR]:0x0
[PC]:0x10006fe2
tasks state:
Name            State   Pri     HWM     Idx     StkCur  StkBot
pthread         R       3       1333    14      0x53f1c 0x52828
IDLE            R       0       97      2       0x43014 0x42e80
ServersTask     B       3       2411    12      0x512a4 0x4ec30
SchedulerTask   B       3       2270    11      0x4ea1c 0x4c3c0
ad_button_ctrl  B       3       659     8       0x483f4 0x47860
pthread         B       3       961     9       0x4b32c 0x49dd8
tcpip           B       3       385     5       0x45514 0x44de0
                B       3       471     7       0x46904 0x461a8
pthread         B       3       629     10      0x4c194 0x4b6c8
                B       4       371     6       0x4608c 0x45938
Publish Thread  B       4       387     4       0x44ae4 0x44398
pthread         B       3       598     15      0x551ec 0x54830
Tmr Svc         B       6       479     3       0x4396c 0x431f0

原因分析

通常产生CPU异常大部分都是因为内存访问出错造成的,内存访问出错可能有空指针, 数组越界, 栈溢出以及其他操作

追查步骤

  1. 查看log中产生异常之前的打印看是否有各种warning,error, fail等不正常的信息,确定是否有逻辑错误
  2. 根据上下文逻辑臆测错误的位置,通过增加UART打印定位
  3. 通过反汇编定位
    <1> arm-none-eabi-objdump -d -S xxx.axf > xxx.asm 或通过
    <2> 查找上面log中的LR和PC,确定跑飞的上下文位置
    <3> 通过增加UART打印辅助调试
R14(LR):[0x53d64]: 0x00000000    >>>> 这个全0为非法,数据已被破坏,无法追查
R15(PC):[0x53d68]: 0x10006fe2    >>>> 这个地址落在.xip段,为code的合法地址,可追查  
Clone this wiki locally