• Linux crash调试(一)



    前言

    在这篇文章中搭建了crash的调试环境,简单的描述了crash的使用:centos7 kdump、crash调试内核,接下来详细描述crash的功能,主要是调试系统正在运行的内核虚拟地址空间。

      crash [OPTION]... [NAMELIST]                          (live system form)
    
    • 1

    1.dis

    disassembles memory, either entire kernel functions, from a location for a specified number of instructions, or from the start of a function up to a specified memory location.
    
    • 1

    反汇编整个内核函数,内存地址、从指定数量的指令的位置,或从函数的开始到指定的内存位置

    cat /proc/kallsyms | grep '\<_text\>'
    cat /proc/kallsyms | grep '\<startup_64\>'
    
    • 1
    • 2

    _text是内核代码段的起始地址,也就是 startup_64 函数
    在这里插入图片描述

    (1)
    反汇编整个函数:

    dis startup_64
    
    • 1

    在这里插入图片描述
    (2)
    分别从startup_64函数开始反汇编 一条指令,两条指令,三条指令
    在这里插入图片描述
    (3)
    从startup_64函数指定的偏移位置开始反汇编
    在这里插入图片描述
    (4)
    从指定内存地址开始反汇编
    在这里插入图片描述

    2.rd

     displays the contents of memory, with the output formatted in several different manners.
    
    • 1
    Enter "help rd" for details.
    
    • 1

    显示内存的内容,并以几种不同的方式格式化输出。
    (1)
    我用castone反汇编出来的三条跳转指令为例,包括其地址,操作码,操作数,和机器码。
    在这里插入图片描述
    分别从对应的内存地址读取32位,64位,16位内容进行对比机器码,经过对比机器码一样。

     -8  display output in 8-bit values.
     -16  display output in 16-bit values.
     -32  display output in 32-bit values (default on 32-bit machines).
     -64  display output in 64-bit values (default on 64-bit machines).
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述
    (2)
    rd读取jiffies全局变量,显示其地址和值:
    在这里插入图片描述

    Read jiffies in hexadecimal and decimal format:
    
    • 1

    在这里插入图片描述
    (3)

    Read Linux version
    
    • 1

    在这里插入图片描述
    在这里插入图片描述

    3.struct

    在这里插入图片描述

    查看结构体成员:
    在这里插入图片描述
    在这里插入图片描述
    查看结构体成员以及其各个成员的相对偏移位置:

     -o  show member offsets when displaying structure definitions;
     if used with an address or symbol argument, each member will be preceded by its virtual address.
    
    • 1
    • 2

    在这里插入图片描述
    (2)
    查看packet套接字:
    在这里插入图片描述
    把指定地址的内容以 struct sock结构体解析打印:
    在这里插入图片描述

    include/linux/socket.h
    #define AF_PACKET	17	/* Packet family		*/
    #define PF_PACKET	AF_PACKET
    
    • 1
    • 2
    • 3

    查看结构体成员以及其各个成员的绝对虚拟地址位置:
    在这里插入图片描述

    4.mod

    查看已经加载的模块信息:
    在这里插入图片描述

    在这里插入图片描述

    5.set

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    6.task

    查看指定任务的task_struct和thread_thread信息
    在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述

    7.ps

    在这里插入图片描述

    查看活跃的进程:
    在这里插入图片描述
    查看用户态进程:

     -u  restrict the output to only user tasks.
    
    • 1

    在这里插入图片描述
    查看内核态进程:

     -k  restrict the output to only kernel threads.
    
    • 1

    在这里插入图片描述
    查看线程组中的线程组领导者:

     -G  display only the thread group leader in a thread group.
     Display only the thread group leader in the crash session:
    
    • 1
    • 2

    在这里插入图片描述

    查看进程的资源限制:

     -r  display resource limits (rlimits) of selected, or all, tasks.
    
    • 1

    在这里插入图片描述
    查看进程的子进程:

     -c  display the children of selected, or all, tasks.
    
    • 1

    在这里插入图片描述
    查看进程的父进程:
    在这里插入图片描述
    在这里插入图片描述

    8.p

    查看全局变量的值:
    在这里插入图片描述
    (1)

      Print the contents of jiffies
    
    • 1

    在这里插入图片描述
    (2)

     Print the contents of the vm_area_struct "init_mm"
    
    • 1

    在这里插入图片描述
    (3)

     If a per-cpu symbol is entered as a argument, its data type and all of its per-cpu addresses are displayed:
    
    
    • 1
    • 2

    在这里插入图片描述

     To display the contents a per-cpu symbol for CPU 1, appenda cpu-specifier:
    
    • 1

    在这里插入图片描述

    (4)打印TCP缓冲区参数
    在这里插入图片描述

    在这里插入图片描述
    可以看到通过crash和/proc/sys/看到的全局变量值是一样的。

    总结

    通过help查看crash支持的命令:
    在这里插入图片描述
    对于每个命令的使用和说明可以用help查看:
    在这里插入图片描述

    参考资料

    https://www.jianshu.com/p/ad03152a0a53
    https://blog.csdn.net/KingOfMyHeart/article/details/98240185

  • 相关阅读:
    设计神经网络的基本原则,如何设计神经网络结构
    【Spring】——9、如何指定初始化和销毁的方法?
    基于区块链的隐私保护数据共享
    LVS负载均衡群集(NAT模式、IP隧道模式、DR模式)
    superset study day01 (本地启动superset项目)
    golang冒泡排序代码实现
    正点原子嵌入式linux驱动开发——异步通知
    LeetCode:205. 同构字符串————简单
    天空卫士C++ 一面(技术面、61min)
    【Kubernetes三大核心概念】
  • 原文地址:https://blog.csdn.net/weixin_45030965/article/details/125453418