- 論壇徽章:
- 0
|
先放幾個(gè)鏈接:
An introduction to KProbes
使用 Kprobes 調(diào)試內(nèi)核
使用 SystemTap 調(diào)試內(nèi)核
用kprobes實(shí)現(xiàn)內(nèi)核反射機(jī)制
更詳細(xì)的內(nèi)容可以閱讀linux-2.6.21/Documentation/kprobes.txt
下面是自己寫的一個(gè)測試腳本: (和上文的eg雷同)
// 修改紅色部分內(nèi)容,以滿足自己需要。
#include
#include
#include
#define DPRINTK(fmt, args...) printk(KERN_ALERT fmt, ##args)
MODULE_AUTHOR("guqing");
MODULE_LICENSE("GPL");
struct kprobe kp;
/* pre_handler: this is called just before the probed instruction is
* executed.
*/
int handler_pre(struct kprobe *p, struct pt_regs *regs) {
DPRINTK("pre_handler: p->addr=0x%p, eflags=0x%lx\n",p->addr, regs->eflags);
return 0;
}
/* post_handler: this is called after the probed instruction is executed
* (provided no exception is generated).
*/
void handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long flags) {
DPRINTK("post_handler: p->addr=0x%p, eflags=0x%lx \n", p->addr, regs->eflags);
}
/* fault_handler: this is called if an exception is generated for any
* instruction within the fault-handler, or when Kprobes
* single-steps the probed instruction.
*/
int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr) {
DPRINTK("fault_handler:p->addr=0x%p, eflags=0x%lx\n", p->addr, regs->eflags);
return 0;
}
static int __init hello_init(void)
{
kp.pre_handler = handler_pre;
kp.post_handler = handler_post;
kp.fault_handler = handler_fault;
kp.symbol_name = "do_fork";
if (register_kprobe(&kp)
本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u/7356/showart_366157.html |
|