zoukankan      html  css  js  c++  java
  • dump_stack 分析使用

    dump_stack是用来回溯内核运行的信息的,打印内核信息堆栈段;

    dump_stack原型:

    void dump_stack(void);

    1、使用这个功能时需要将内核配置勾选上;

    make menuconfig -> kernel hacking--> kernel debug

    2、在函数中使用:

     1 #include <linux/module.h>
     2 #include <linux/init.h>
     3 #include <linux/kprobes.h>
     4 #include <asm/traps.h>
     5  
     6 MODULE_LICENSE("Dual BSD/GPL");
     7   
     8 static int __init hello_init(void)
     9 {
    10      printk(KERN_ALERT "dump_stack start
    ");
    11      dump_stack();
    12      printk(KERN_ALERT "dump_stack over
    ");
    13      return 0;
    14  }
    15  static void __exit hello_exit(void)
    16  {
    17       printk(KERN_ALERT "test module
    ");
    18  }
    19  
    20 module_init(hello_init);
    21 module_exit(hello_exit);
    View Code


    3、需要加入的头文件:

    1 #include <linux/kprobes.h>
    2 #include <asm/traps.h>
    View Code

    4、得到hello.ko之后,insmod hello.ko,打印信息如下:

     1 [ 3719.352022] usb 1-8: new high speed USB device number 11 using ehci_hcd
     2 [ 4266.252826] usb 1-8: USB disconnect, device number 11
     3 [ 5246.942980] dump_stack start
     4 [ 5246.942985] Pid: 3438, comm: insmod Not tainted 3.0.0-21-generic #35-Ubuntu
     5 [ 5246.942987] Call Trace:
     6 [ 5246.942993]  [] hello_init+0x17/0x1000 [hello]
     7 [ 5246.942999]  [] do_one_initcall+0x42/0x180
     8 [ 5246.943003]  [] sys_init_module+0xbe/0x230
     9 [ 5246.943006]  [] system_call_fastpath+0x16/0x1b
    10 [ 5246.943008] dump_stack over
    View Code

    在不同环境下,Call Trace也可能被称为Back Trace;

  • 相关阅读:
    影响上传、下载速度的原因
    JDK9环境变量配置
    CentOS配置Nginx及常见命令
    Docker基本命令
    selenium+java文件上传
    selenium java清空默认值时失效方法
    js常用 方法 封装
    Jvm的gc机制和算法
    Java正则总结
    枚举类
  • 原文地址:https://www.cnblogs.com/linhaostudy/p/6404197.html
Copyright © 2011-2022 走看看