Linux crash 调试环境搭建

在网上找了很多linux crash 调试工具安装的相关文章都没有成功,最后断断续续花时间去搭建这个环境,做个笔记,顺便分享下,本文记录的是ubuntu 18.04.4 LTS (Bionic Beaver) ,内核版本为5.4.0-42-generic

curits@curits-virtual-machine:~/Desktop/crash-master$ uname -r
5.4.0-42-generic
curits@curits-virtual-machine:~/Desktop/crash-master$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

0x01:首先安装需要调试系统,我这里是在虚拟机里安装了ubuntu 18.04

0x02:要进行crash调试,需要安装带有调试信息的内核,这个在官网都可以下载到的,这里附上此版本dbgsym包的下载路径

https://launchpad.net/ubuntu/bionic/amd64/linux-image-unsigned-5.4.0-42-generic-dbgsym/5.4.0-42.46~18.04.1

其他版本ddeb包可以在以下链接搜索:

https://launchpad.net/ubuntu/bionic

附:针对不同的系统内核调试安装包的形式是不一样的,ubuntu为发布的ddeb包,centos为debuginfo包

Ubuntu dbg包样例:

linux-image-unsigned-5.4.0-42-generic-dbgsym_5.4.0-42.46_18.04.1_amd64.ddeb

Centos dbg包样例:

kernel-debuginfo-common-x86_64-3.10.0-693.el7.x86_64.rpm
kernel-debug-debuginfo-3.10.0-693.el7.x86_64.rpm
kernel-debuginfo-3.10.0-693.el7.x86_64.rpm

下载地址:

http://debuginfo.centos.org/7/x86_64/

可能有些内核版本在官网找不到,但是还有一些其他网点可以下载到(亲测其他网站下载更快)
在这里插入图片描述

vmlinux路径为:

/usr/lib/debug/lib/modules/3.10.0-693.el7.x86_64/vmlinux

0x03:虽然有些系统有自带的crash,但是这个系统默认是没有自带的crash工具,直接从github上下载最新的源码进行编译得到crash二进制文件(我是在物理编译出来的,因为虚拟机里编译太慢了,直接把编译的crash-master拷贝到此系统)

github地址:

https://github.com/crash-utility/crash.git

编译方式:

make target=x86
make install

0x04:下载好ddeb包之后,那就是安装,安装很简单直接:

sudo dpkg -i linux-image-unsigned-5.4.0-42-generic-dbgsym_5.4.0-42.46_18.04.1_amd64.ddeb 

安装完之后可以在 /usr/lib/debug/boot/vmlinux-5.4.0-42-generic ,这个就是带有调试信息的内核

0x05:最后一步就是让crash 跑起来

curits@curits-virtual-machine:~/Desktop/crash-master$ sudo ./crash /usr/lib/debug/boot/vmlinux-5.4.0-42-generic 

crash 7.2.8++
Copyright (C) 2002-2020  Red Hat, Inc.
Copyright (C) 2004, 2005, 2006, 2010  IBM Corporation
Copyright (C) 1999-2006  Hewlett-Packard Co
Copyright (C) 2005, 2006, 2011, 2012  Fujitsu Limited
Copyright (C) 2006, 2007  VA Linux Systems Japan K.K.
Copyright (C) 2005, 2011  NEC Corporation
Copyright (C) 1999, 2002, 2007  Silicon Graphics, Inc.
Copyright (C) 1999, 2000, 2001, 2002  Mission Critical Linux, Inc.
This program is free software, covered by the GNU General Public License,
and you are welcome to change it and/or distribute copies of it under
certain conditions.  Enter "help copying" to see the conditions.
This program has absolutely no warranty.  Enter "help warranty" for details.
 
GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu"...

WARNING: kernel relocated [330MB]: patching 111021 gdb minimal_symbol values

      KERNEL: /usr/lib/debug/boot/vmlinux-5.4.0-42-generic             
    DUMPFILE: /proc/kcore
        CPUS: 2
        DATE: Wed Aug 26 11:44:40 2020
      UPTIME: 05:12:39
LOAD AVERAGE: 0.28, 0.06, 0.02
       TASKS: 499
    NODENAME: curits-virtual-machine
     RELEASE: 5.4.0-42-generic
     VERSION: #46~18.04.1-Ubuntu SMP Fri Jul 10 07:21:24 UTC 2020
     MACHINE: x86_64  (3407 Mhz)
      MEMORY: 4 GB
         PID: 9051
     COMMAND: "crash"
        TASK: ffff9489f43caf80  [THREAD_INFO: ffff9489f43caf80]
         CPU: 0
       STATE: TASK_RUNNING (ACTIVE)

crash> 

成功进入crash,接下来就是使用crash工具辣,这个下篇文章再唠唠

猜你喜欢

转载自blog.csdn.net/qq_42931917/article/details/108236139