zoukankan      html  css  js  c++  java
  • 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

    良辰美景补天漏,风雨雷电洗地尘
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  • 相关阅读:
    std::string构造函数
    shell命令-while语句
    shell命令-for语句
    shell命令-if语句
    softmax回归推导
    sigmod函数求导
    生成器面试题之一
    range和xrange的区别
    python里的input
    python中print和input的底层实现
  • 原文地址:https://www.cnblogs.com/welhzh/p/15294598.html
Copyright © 2011-2022 走看看