dump_stack可以用来查看函数调用关系,即便在内核里也可以。

// hello.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kprobes.h>
#include <asm/traps.h>

static int __init hello_init(void)
{
    printk(KERN_ALERT "dump_stack start\n");
    dump_stack();
    printk(KERN_ALERT "dump_stack over\n");
    return 0;
}

static void __exit hello_exit(void)
{
    printk(KERN_ALERT "test module\n");
}

module_init(hello_init);
module_exit(hello_exit);

makefile:

obj-m :=hello.o
KERNELDIR :=/lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
all:
    make -C $(KERNELDIR) M=$(PWD) modules
    
.PHONY :clean
clean:
    rm -rf *.o *ko

insmod hello.ko之前运行dmesg即可得到call trace。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-10-24
  • 2021-06-27
  • 2021-11-12
猜你喜欢
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案