Kprobe
linux内核源码Documentation目录下存在kprobe介绍文档如下

Kprobes allows multiple probes at the same address. Currently,
however, there cannot be multiple jprobes on the same function at
the same time.
If you install a probe in an inline-able function, Kprobes makes
no attempt to chase down all inline instances of the function and
install probes there. gcc may inline a function without being asked,
so keep this in mind if you're not seeing the probe hits you expect.
A probe handler can modify the environment of the probed function
-- e.g., by modifying kernel data structures, or by modifying the
contents of the pt_regs struct (which are restored to the registers
upon return from the breakpoint). So Kprobes can be used, for example,
to install a bug fix or to inject faults for testing. Kprobes, of
course, has no way to distinguish the deliberately injected faults
from the accidental ones. Don't drink and probe.
Kprobes makes no attempt to prevent probe handlers from stepping on
each other -- e.g., probing printk() and then calling printk() from a
probe handler. If a probe handler hits a probe, that second probe's
handlers won't be run in that instance, and the kprobe.nmissed member
of the second probe will be incremented.
Kprobes does not use mutexes or allocate memory except during
registration and unregistration.
/sys/kernel/debug/kprobes
crash> gdb disass /r tcp_v4_rcv #加载了tcp_debug模块 jprobeDump of assembler code forfunction tcp_v4_rcv:0xffffffff81782980<+0>: e8 7b c6 893e callq 0xffffffffc001f0000xffffffff81782985<+5>: 55 push %rbp0xffffffff81782986<+6>: 4889 e5 mov %rsp,%rbp0xffffffff81782989<+9>: 4157 push %r150xffffffff8178298b<+11>: 4156 push %r140xffffffff8178298d<+13>: 4155 push %r130xffffffff8178298f<+15>: 4154 push %r120xffffffff81782991<+17>: 53 push %rbx0xffffffff81782992<+18>: 4889 fb mov %rdi,%rbx0xffffffff81782995<+21>: 4883 ec 60 sub $0x60,%rspcrash>crash> gdb disass /r tcp_v4_rcv #卸载tcp_debug模块 jprobeDump of assembler code forfunction tcp_v4_rcv:0xffffffff81782980<+0>: 6666666690 data32 data32 data32 xchg %ax,%ax0xffffffff81782985<+5>: 55 push %rbp0xffffffff81782986<+6>: 4889 e5 mov %rsp,%rbp0xffffffff81782989<+9>: 4157 push %r150xffffffff8178298b<+11>: 4156 push %r140xffffffff8178298d<+13>: 4155 push %r130xffffffff8178298f<+15>: 4154 push %r120xffffffff81782991<+17>: 53 push %rbx0xffffffff81782992<+18>: 4889 fb mov %rdi,%rbx0xffffffff81782995<+21>: 4883 ec 60 sub $0x60,%rspcrash>
(gdb) disass /r tcp_v4_rcv #vmlinux中原始文件反汇编Dump of assembler code forfunction tcp_v4_rcv:0xffffffff81782980<+0>: e8 ab 9f0a00 callq 0xffffffff8182c930<__fentry__>0xffffffff81782985<+5>:55 push %rbp0xffffffff81782986<+6>:4889 e5 mov %rsp,%rbp0xffffffff81782989<+9>:4157 push %r150xffffffff8178298b<+11>:4156 push %r140xffffffff8178298d<+13>:4155 push %r130xffffffff8178298f<+15>:4154 push %r120xffffffff81782991<+17>:53 push %rbx0xffffffff81782992<+18>:4889 fb mov %rdi,%rbx0xffffffff81782995<+21>:4883 ec 60 sub $0x60,%rsp0xffffffff81782999<+25>: f6 879000000007 testb $0x7,0x90(%rdi)0xffffffff817829a0<+32>:7556 jne 0xffffffff817829f8<tcp_v4_rcv+120>
crash> gdb disass /r jprobe_returnDump of assembler code forfunction jprobe_return:0xffffffff8105dcc0<+0>: 6666666690 data32 data32 data32 xchg %ax,%ax0xffffffff8105dcc5<+5>: 55 push %rbp0xffffffff8105dcc6<+6>: 48 c7 c0 a0 d7 0000 mov $0xd7a0,%rax0xffffffff8105dccd<+13>: 4889 e5 mov %rsp,%rbp0xffffffff8105dcd0<+16>: 53 push %rbx0xffffffff8105dcd1<+17>: 65480305 af c4 fa 7e add %gs:0x7efac4af(%rip),%rax # 0xa1880xffffffff8105dcd9<+25>: 488b5818 mov 0x18(%rax),%rbx0xffffffff8105dcdd<+29>: 4887 dc xchg %rbx,%rsp0xffffffff8105dce0<+32>: cc int30xffffffff8105dce1<+33>: 90 nop0xffffffff8105dce2<+34>: 5b pop %rbx0xffffffff8105dce3<+35>: 5d pop %rbp0xffffffff8105dce4<+36>: c3 retqEnd of assembler dump.
对tcp_ack中0xffffffff817748bf位置进行kprobe前后对比

通过/proc/kallsyms查看的文件类型对应如下(./scripts/mksysmap):
# The second row specify the type of the symbol:
# A = Absolute
# B = Uninitialised data (.bss)
# C = Common symbol
# D = Initialised data
# G = Initialised data for small objects
# I = Indirect reference to another symbol
# N = Debugging symbol
# R = Read only
# S = Uninitialised data for small objects
# T = Text code symbol
# U = Undefined symbol
# V = Weak symbol
# W = Weak symbol
# Corresponding small letters are local symbols
# For System.map filter away:
# a - local absolute symbols
# U - undefined global symbols
# N - debugging symbols
# w - local weak symbols
__kstrtab节(保存符号名)、__ksymtab节(所有模块可使用的符号地址)和__ksymtab_gpl节(GPL兼容许可证下发布的模块可以使用的符号地址,其他的未找到
cat /proc/kallsyms | cut -d " "-f 2| sort -u //查看文件类型cat /proc/kallsyms | awk '$2=="a" {print $2 "\t" $3}' //查看某个文件类型对应的符号
附件列表
Kprobe的更多相关文章
- 哎呀,发现自己不会用模块的方式用kprobe啊,弱爆了
在内核外面编译模块,会报warning函数名undefined的错误,解决方法是把函数给export出来:EXPORT_SYMBOL 一直以来,用kprobe比较多的是kprobe event的用法, ...
- kprobe原理解析(二)
上一篇文章和大家简要说明了下kprobe到底应该怎样用,那么现在我们就揭开kprobe神秘的面纱,刨根问底,一睹kprobe的庐山真面目. kprobe的工作过程大致如下: 1)注册kprobe.注册 ...
- kprobe原理解析(一)
kprobe是linux内核的一个重要特性,是一个轻量级的内核调试工具,同时它又是其他一些更高级的内核调试工具(比如perf和systemtap)的“基础设施”,4.0版本的内核中,强大的eBPF特性 ...
- kprobe 内核模块
代码来自于linux内核sample/kprobe kprobe_example.c /* * NOTE: This example is works on x86 and powerpc. * He ...
- Linux 下的一个全新的性能测量和调式诊断工具 Systemtap,第 1 部分: kprobe
kprobe 的原理.编程接口.局限性和使用注意事项 本系列文章详细地介绍了一个Linux下的全新的调式.诊断和性能测量工具Systemtap和它所依赖的基础kprobe以及促使开发该工具的先驱DTr ...
- Linux kprobe调试技术使用
kprobe调试技术是为了便于跟踪内核函数执行状态所设计的一种轻量级内核调试技术. 利用kprobe技术,可以在内核绝大多数函数中动态插入探测点,收集调试状态所需信息而基本不影响原有执行流程. kpr ...
- kprobe原理解析
参考 http://www.cnblogs.com/honpey/p/4575928.html kprobe是linux内核的一个重要特性,是一个轻量级的内核调试工具,同时它又是其他一些更高级的内核 ...
- [转载] kprobe原理解析(一)
From: https://www.cnblogs.com/honpey/p/4575928.html kprobe原理解析(一) kprobe是linux内核的一个重要特性,是一个轻量级的内核调试工 ...
- Linux下 kprobe工具的使用
此处转载: 一.Kprobe简单介绍 kprobe是一个动态地收集调试和性能信息的工具,它从Dprobe项目派生而来,是一种非破坏性工具,用户用它差点儿能够跟踪不论什么函数或被运行的指令以及一些异步事 ...
随机推荐
- numpy如何使用
numpy介绍 创建numpy的数组 一维数组是什么样子 可以理解为格子纸的一行就是一个一维数据 two_arr = np.array([1, 2, 3]) 二维数组什么样子 理解为一张格子纸, 多个 ...
- 第6天 Java基础语法
第6天 Java基础语法 今日内容介绍 自定义类 ArrayList集合 引用数据类型(类) 引用数据类型分类 提到引用数据类型(类),其实我们对它并不陌生,如使用过的Scanner类.Random类 ...
- 《PHP发送邮件PHPMailer》系列分享专栏
<PHP发送邮件PHPMailer>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/201726.html 文章 PHPMailer ...
- 中国大学MOOC-C程序设计(浙大翁恺)—— 单词长度
题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以‘.’结束.你要输出这行文本中每个单词的长度.这里的单词与语言无关,可以包括各种符号,比如“it's”算一个单词,长度为4.注意,行中 ...
- BZOJ1011 莫比乌斯反演(基础题
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1101 [题目大意] 求[1,n][1,m]内gcd=k的情况 [题解] 考虑求[1,n ...
- 深入理解@RequestBody注解
我写文章历来追求通俗易懂,今天来深入探讨一下@RequestBody注解.提起这个,所有做过mvc开发的同学应该都不陌生,使用上面肯定也是信手拈来. 所以我这里就简单的提一下这个注解的使用: 1.当客 ...
- pascal 的字符串操作
1.ord 将字符转为 ascii码 2.chr 将ascii码转为字符 3.trunc 求整数部分 4.random , randomize 5.copy(s,i,l)从s串中截取第i个字符开始后长 ...
- js polyfill , to developing the cross browser js
https://github.com/paulmillr/console-polyfill https://github.com/Modernizr/Modernizr/wiki/HTML5-Cros ...
- [Jmeter]用Jmeter做压力测试(分布式)
Jmeter 是Java应用,对于CPU和内存的消耗比较大,因此,当需要模拟数以千计的并发用户时,使用单台机器模拟所有的并发用户就有些力不从心,甚至会引起JAVA内存溢出错误.为了让jmeter工具提 ...
- Python科学计算器(计算器)
说明 该计算器主要是为了练习正则表达式以及python基础所写:代码比较low! 运行过程 请输入你的计算公式, 计算器会将计算结果输出到屏幕上(此处会打印步骤); 退出(exit/quit) MyC ...