kprobe通过插入内核模块来做探测内核的工作。
使用offset成员,可以来指定从symbol指定的函数开始,距离该函数offset的位置的指令。
在kprobe的文档里有这么一句话:
Use the "offset" field of struct kprobe if the offset into the symbol to install a probepoint is known. This field is used to calculate the probepoint.
这里就存在一个问题。。兼容性。不同版本的内核,探测同一条指令时所需要的offset 是不一样的。
所以说如果使用kprobe来做内核探测,使用了offset之后,基本上只能在本系统中用。
把相同的代码(即不改变offset的情况)放到另外一个内核版本的系统中运行,插入模块时报错。
insmod:error inserting 'kprobe_switch_1.ko' : -1 Invalid or incomplete multibyte or wide character