0

How to use a Systemtap probe on a kernel module function while that module is loaded. I am trying to print the functions being called for a particular module while it is being loaded. Suppose I have a kernel module hello.ko which is not loaded. Now I want to trace a function hello_init() of that module. I tried with the following Systemtap script but it did not work.

Command:

stap test10.stp -c "modprobe hello" --> this printed nothing

Systemtap script:

#!/usr/bin/env stap

global traces

probe module("hello").function("hello_init") {
    printf("hello")
    print_stack(backtrace())
}

Kernel module:

#include <linux/module.h>       
#include <linux/kernel.h>       
#include <linux/init.h>         
MODULE_LICENSE("GPL");

static int __init hello_init(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}

static void __exit hello_exit(void)
{
printk(KERN_INFO "Done\n");
}

module_init(hello_init);
module_exit(hello_exit);

1 Answer 1

0

As far as I could see staprun sends only kallsyms_on_each_symbol in int send_relocation_kernel() in staprun.c to the generated kernel module, which in turn does not set the kprobe address in the kernel module because kallsyms_on_each_symbol does not find the probe symbol in the kernel module. For a quick "test" one could send the address of module_kallsyms_on_each_symbol in place of kallsyms_on_each_symbol in int send_relocation_kernel() it works since both functions have the same signature.

replace

else if (linesize - pos == sizeof "kallsyms_on_each_symbol"
        && !strcmp(line + pos, "kallsyms_on_each_symbol" "\n"))
  {
     rc = send_a_relocation ("kernel", "kallsyms_on_each_symbol", address);

with

else if (linesize - pos == sizeof "module_kallsyms_on_each_symbol"
        && !strcmp(line + pos, "module_kallsyms_on_each_symbol" "\n"))
  {
     rc = send_a_relocation ("kernel", "kallsyms_on_each_symbol", address);

With this change the probe in the init() function should print something.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .