mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2.6.12-rc1-mm3] [2/2] kprobes += function-return probes - example: probing arbitrary functions
@ 2005-03-29 22:29 Hien Nguyen
  0 siblings, 0 replies; only message in thread
From: Hien Nguyen @ 2005-03-29 22:29 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

Also include here is a test module

The testrprobe.ko is a generic test module. One could use this module to 
insert an exit probe to any function in the kernel.
For example :
insmod test_rprobe.ko <entryaddr=address for func entry>
or use the included loadtestrprobe.sh script
./loadtestrprobe.sh <function name>

One good example is to see what kind of page fault is encountered
./loadtestrprobe.sh handle_mm_fault

Signed-off-by: hien Nguyen <hien@us.ibm.com>

[-- Attachment #2: testrprobe.c --]
[-- Type: text/x-csrc, Size: 1072 bytes --]

#include <linux/module.h>
#include <linux/kprobes.h>

static unsigned long entryaddr;
module_param(entryaddr, ulong, 0);
MODULE_PARM_DESC(addr,
		 "\nfunction entry address.\n");

int inst_test_erprobe (void)
{
	jprobe_return();
	return 0;
}


int rp_handler(struct retprobe_instance *ri, struct pt_regs *regs)
{
	printk("rprobe handler: p->addr=0x%p, ret=0x%lx\n", ri->rp->kprobe->addr, regs->eax);
	return 0;
}
	
static struct jprobe jp = {
	.entry = (kprobe_opcode_t *) inst_test_erprobe,
};


static struct retprobe rp = {
	.handler = rp_handler,
	.maxactive = 1,
	.nmissed = 0
};


static int init_testrp(void)
{
  if (entryaddr == 0 ) {
    printk("Need to input an function entry address as parameter.\n");
    return -EINVAL;
  }
  jp.kp.addr = (kprobe_opcode_t *) entryaddr;

  register_jretprobe(&jp, &rp);
  printk("exit probe init: instrumentation is enabled...\n");
  return 0;
}

static void cleanup_testrp(void)
{
  unregister_jprobe(&jp);
  printk("exit probe cleanup.\n");
}

module_init(init_testrp);
module_exit(cleanup_testrp);
MODULE_LICENSE("GPL");


[-- Attachment #3: loadtestrprobe.sh --]
[-- Type: application/x-shellscript, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-03-29 22:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-29 22:29 [PATCH 2.6.12-rc1-mm3] [2/2] kprobes += function-return probes - example: probing arbitrary functions Hien Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®