Skip to the content.

安装crash工具

# There are other precondition to do, check https://www.ibm.com/developerworks/cn/linux/l-cn-dumpanalyse/index.html
yum install crash

Crash工具的使用

Debug live kernel

# just execute crash process to enter crash shell
$ crash
crash> net_namespace_list
net_namespace_list = $3 = {
  next = 0xffffffff81fc1b10 <init_net+16>, 
  prev = 0xffff8808243b9d90
}
crash> net_namespace_list
net_namespace_list = $4 = {
  next = 0xffffffff81fc1b10 <init_net+16>, 
  prev = 0xffff8808243b9d90
}
crash> list net_namespace_list
ffffffff81fc29c0
ffffffff81fc1b10
ffff880807c09d90
ffff8808243b9d90
crash> struct net.count ffffffff81fc1b10
  count = {
    counter = -30712
  }
crash> struct net ffffffff81fc1b10                                                                                                                            
struct net {
  passive = {
    counter = 130063760
  }, 
  count = {
    counter = -30712
  }, 
  rules_mod_lock = {
    {
      rlock = {
        raw_lock = {
          {
            head_tail = 2180786624, 
            tickets = {
              head = 10688, 
              tail = 33276
            }
          }
        }
      }
    }
  }, 
  list = {
    next = 0x0, 
    prev = 0x0
  }, 
  ...

list 命令可以列举list类型的全局变量

比如 list first_device first_device,列举所有的network device

Debug crashed file

# 这里 vmlinux 是带调试信息的内核。如果一切正常,将会进入到 crash 中
$ crash vmlinux mydumpfile
crash> bt -f
PID: 2462   TASK: ffff88080c790000  CPU: 1   COMMAND: "crash"
(active)

crash 使用 gdb 作为它的内部引擎,crash 中的很多命令和语法都与 gdb 相同。如果你曾经使用过 gdb,就会发现 crash 并不是很陌生。如果想获得 crash 更多的命令和相关命令的详细说明,可以使用 crash 的内部命令 help来获取。

参考

使用 Crash 工具分析 Linux dump 文件