dump_stack使用

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。

 

posted @ 2021-09-16 17:58  微信公众号--共鸣圈  阅读(147)  评论(0编辑  收藏  举报