case_使用systemtap和kprobe跟踪自己开发的模块.txt
因为之前看到有篇文档说systemtap跟踪不了内核模块,所以看个究竟,发现是错误的说法
1.sles11sp1:/opt/proc_mtest # ls
Makefile mtest.stp proc_mtest.c proc_mtest.ko.debug trace_mtest.c
2.kprobe 正常跟踪, 结论:kprobe可以跟踪模块中的函数。
Jan 1 07:41:34 sles11sp1 kernel: [ 3898.313236] Registered a jprobe.
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475312] mtest_openprocess cat pid=4432
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475352] Pid: 4432, comm: cat Tainted: P N 2.6.32.59-0.7-default #1
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475355] Call Trace:
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475370] [] dump_trace+0x6c/0x2d0
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475377] [] dump_stack+0x69/0x73
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475385] [] jmtest_read+0x2d/0x38 [trace_mtest]
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475413] [] proc_reg_read+0x77/0xc0
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475428] [] vfs_read+0xc7/0x130
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475434] [] sys_read+0x53/0xa0
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475440] [] system_call_fastpath+0x16/0x1b
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475454] [<00007f9c06205f30>] 0x7f9c06205f30
Jan 1 07:42:31 sles11sp1 kernel: [ 3955.475471] mtest_read
2.systemtap跟踪
sles11sp1:/opt/proc_mtest # cat mtest.stp
probe module("proc_mtest").function("mtest_read")
{
printf( "mtest read by traced")
}
sles11sp1:/opt/proc_mtest # stap mtest.stp
semantic error: missing x86_64 kernel/module debuginfo under '/lib/modules/2.6.32.59-0.7-default/build' while resolving probe point module("proc_mtest").function("mtest_read")
Pass 2: analysis failed. Try again with another '--vp 01' option.
失败。
定位:strace 一下
sles11sp1:/opt/proc_mtest # strace -o a stap mtest.stp
semantic error: missing x86_64 kernel/module debuginfo under '/lib/modules/2.6.32.59-0.7-default/build' while resolving probe point module("proc_mtest").function("mtest_read")
Pass 2: analysis failed. Try again with another '--vp 01' option.
发现去找/lib/modules/2.6.32.59-0.7-default/kernel 下面的各个ko,于是乎
sles11sp1:/opt/proc_mtest # cp proc_mtest.ko /lib/modules/2.6.32.59-0.7-default/kernel/drivers/
sles11sp1:/opt/proc_mtest # strace -o b stap mtest.stp
^Csles11sp1:/opt/proc_mtest # stap mtest.stp
mtest read by traced
OK,解决。
阅读(3526) | 评论(0) | 转发(0) |