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
");
    dump_stack();
    printk(KERN_ALERT "dump_stack over
");
    return 0;
}

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

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。

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

微信公众号:  共鸣圈
欢迎讨论,邮件:  924948$qq.com       请把$改成@
QQ群:263132197
QQ:    924948

良辰美景补天漏,风雨雷电洗地尘
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
原文地址:https://www.cnblogs.com/welhzh/p/15294598.html