内核中打印调用栈
do_page_fault
info [ft2CPU 0 Unable to handle kernel paging request at virtual address 00000000, epc == 801bcf00, ra == 801c0210
Oops[#1]:
CPU: 0 PID: 14190 Comm: date Not tainted 3.10.27+ #71
task: 8fd70600 ti: 88e9a000 task.ti: 88e9a000
$ 0 : 00000000 1000d000 8fee1eb8 8f5d9eb8
$ 4 : 00000000 80578b44 fffffffc 8fee1eb9
$ 8 : 00003bc4 e340f3f2 2d04acbd 562b5c3d
$12 : 00000000 00000000 00000000 00000000
$16 : 8ff05eb8 80578b44 00000002 80523478
$20 : 805b0000 80578b38 8ff05eb8 00000001
$24 : 00000000 77635ea4
$28 : 88e9a000 88e9bb78 8052471c 801c0210
Hi : 00000000
Lo : 000006cc
epc : 801bcf00 0x801bcf00
Not tainted
ra : 801c0210 0x801c0210
Status: 1000d000
Cause : 0000400c
BadVA : 00000000
PrId : 0000dc02
Process date (pid: 14190, threadinfo=88e9a000, task=8fd70600, tls=7796b460)
Stack : 8fd93040 00000000 00000006 805799a8 80578b38 8ff05eb8 00000002 80040478
80578b30 80578b30 3b9aca00 80523478 80578b30 80578b30 3b9aca00 80040fbc
805e0000 8004f91c 805ac528 00000000 00000000 00000000 a9d4a3c2 0e961d43
562b9802 1045a0af 8fd70600 00000000 00000000 00000000 00000000 88e677f8
805b0000 80524708 8052471c 8002b3c4 8fd70600 00000000 00000000 00000000
...
Call Trace:[<80040478>] 0x80040478
[<80040fbc>] 0x80040fbc
[<8004f91c>] 0x8004f91c
[<805b0000>] 0x805b0000
[<8002b3c4>] 0x8002b3c4
[<8002b40c>] 0x8002b40c
[<800548c4>] 0x800548c4
[<80054934>] 0x80054934
[<80059368>] 0x80059368
[<80016400>] 0x80016400
[<80010ab8>] 0x80010ab8
[<80059aa4>] 0x80059aa4
[<801f9f40>] 0x801f9f40
[<8005cc84>] 0x8005cc84
[<801c3284>] 0x801c3284
[<80059368>] 0x80059368
[<80013968>] 0x80013968
[<80012860>] 0x80012860
[<8007c774>] 0x8007c774
[<80018e98>] 0x80018e98
[<801c3260>] 0x801c3260
[<8007c938>] 0x8007c938
[<801bd644>] 0x801bd644
[<800180e8>] 0x800180e8
[<80081674>] 0x80081674
[<801bd784>] 0x801bd784
[<801c3284>] 0x801c3284
[<8007498c>] 0x8007498c
[<8007fb5c>] 0x8007fb5c
[<80012864>] 0x80012864
Code: 34470001 ac440004 ac620008 <ac870000> 8c480000 01063824 ac680000 10e00008 ac430000
_test_uart:226]: uart test!
inf---[ end trace 21a2434fd3af4cbd ]---
o [ft2_test_uart:236]: uart testKernel panic - not syncing: Fatal exception in interrupt
ok!
内核在发生crash的时候会打印上面这段信息,对应到内核中的代码的流程是:
do_page_fault
__do_page_fault arch/rlx/mm/fault.c
die
show_register arch/rlx/kernel/traps.c
__show_regs
show_stacktrace -> show_backtrace
show_code
if (in_interrupt())
panic("Fatal exception in interrupt");
dump_stack
dump_stack用于内核调试,打印内核堆栈段信息,需要在内核中配置DEBUG_KERNEL,可以在自己写的driver中加上这句话来查看函数调用流程。
注意在使用dump_stack要加上这两个头文件:
#include <linux/kprobes.h>
#include <asm/traps.h>
BUG()\WARN()
BUG与WARN不同,BUG里面会调用panic()函数,进入panic函数后如果panic_timeout设置大于0,那么会重启系统,否则的话panic()函数最后会进入一个死循环。
用户空间中打印调用栈
__builtin_frame_address(int level)
gcc中使用__builtin_frame_address(int level)可以打印函数调用的地址,然后可以通过符号表得到函数的名字。