如何高效学习debug技能,提升编程能力?

摘要:参考 https:blog.csdn.netrikeyonecategory_10354155.html Linux内核故障分类和排查 Linux内核中oops 错误解析以及问题定位 panic和oops的区别 内核问题分析文章 L
参考 https://blog.csdn.net/rikeyone/category_10354155.html Linux内核故障分类和排查 Linux内核中oops 错误解析以及问题定位 panic和oops的区别 内核问题分析文章 Linux中的错误码 Remote Serial Console HOWTO 配置串口 Internet FAQ Archives 服务器案例查询助手 Welcome to learning debugging All GDB Content 谈复杂软件低概率问题定位和复现 测试工具 LTP:https://linux-test-project.readthedocs.io/en/latest/index.html 内核 工具 kdump&crash openEuler kernel 技术分享 - 第1期 - kdump 基本原理、使用及案例介绍 openEuler kernel 技术分享 - 第3期 - Crash工具基本使用及实战分享 crash、kdump工具学习 crash工具和x86-64汇编基础 使用crash工具分析高通ramdump early kdump Documentation for Kdump - The kexec-based Crash Dumping Solution VMCOREINFO Linux Kdump 机制详解 crash实战:手把手教你使用crash分析内核dump drgn github: https://github.com/osandov/drgn 使用手册 User Guide A kernel debugger in Python: drgn Powerful and Programmable Kernel Debugging with drgn BPF drgn tools drgn: How the Linux Kernel Team at Meta Debugs the Kernel at Scale drgn - Linux 调试的另一只翅膀 [上] drgn - Linux 调试的另一只翅膀 [下] Enter the drgn 使用drgn分析kdump: https://www.cnblogs.com/pengdonglin137/articles/18377649 示例: sudo drgn -s /mnt/linux-6.10/vmlinux -c /var/crash/202408232354/dump.202408232354 使用drgn分析live kernel: -示例: sudo drgn -s /mnt/linux-6.10/vmlinux 内核中的一些基于drgn的脚本 tools/rcu: Add drgn script to dump number of RCU callbacks tools/cgroup: add memcg_slabinfo.py tool blkcg: add tools/cgroup/iocost_monitor.py decode_stacktrace.sh 使用decode_stacktrace.sh解析内核调用栈 faddr2line 内核脚本faddr2line pengdl@ubuntu:~/x86/linux-5.19$ ./scripts/faddr2line ./vmlinux proc_reg_open+255 blk_mq_dispatch_rq_list+599 proc_reg_open+255/0x1f0: proc_reg_open at fs/proc/inode.c:524 blk_mq_dispatch_rq_list+599/0x850: blk_mq_dispatch_rq_list at block/blk-mq.c:1897 pengdl@ubuntu:~/x86/linux-5.19$ ./scripts/faddr2line ./fs/proc/inode.o proc_reg_open+255 proc_reg_open+255/0x1f0: proc_reg_open at /home/pengdl/work/Qemu/x86/linux-5.19/fs/proc/inode.c:524 stack canary Linux 内核安全增强—— stack canary __stack_chk_fail 栈溢出问题定位 反汇编 用objdump只反汇编想要的函数 硬件断点 bpftrace watchpoint/asyncwatchpoint 硬件断点API Linux 监测内存访问的方法汇总 GDB gdb Debugging Full Example (Tutorial) Bug hunting 使用gdb查看结构体成员偏移 Debugging with GDB Debugging kernel and modules via gdb gdb 一行命令gdb -ex 'info functions' -ex 'info files' -e 'quit' ./hello.ko The GDB developer's GNU Debugger tutorial Part1 Part2 Part3 下面是一个.gdbinit的参考:# 保存历史命令 set history filename ~/.gdb_history set history save on # 退出时不显示提示信息 set confirm off # 按照派生类型打印对象 set print object on # 打印数组的索引下标 set print array-indexes on # 每行打印一个结构体成员 set print pretty on set print array on set logging on set logging file ~/gdb_output.log set logging overwrite on # set logging redirect on set logging off set logging on debugfs 命令 modprobe ice dyndbg=+p echo "module ice +p" > /sys/kernel/debug/dynamic_debug/control sudo insmod ice.ko dyndbg="+p" fwlog_events=0x0FFFFFFF fwlog_level=2 dmesg 命令 # 等待输出新的内容日志: -w dmesg -w file.log # 将内核日志重定向到文件中,并且等待输出新的日志 修改loglevel dmesg -n 1 # 将console的loglevel设置为1 向内核日志缓冲区写入日志 # echo hello > /dev/kmsg trace 向trace缓冲区写日志 # echo helo > trace_marker dynamic debug 开机启动时打开日志:Debug messages during Boot Process 如果要控制多个,那么可以写多个"dyndbg=",或者在一个"dyndbg="里用分号分隔开:dyndbg="file params.c +p;file cpufreq.c +p" 打印coredump发生时的上下文 echo 1 > /proc/sys/kernel/print-fatal-signals 当发生段错误时,会从内核日志里看到: 01-01 08:07:45.954 22394 22394 I : potentially unexpected fatal signal 11. 01-01 08:07:45.954 22394 22394 I : CPU: 4 PID: 22394 Comm: Thread-19 Tainted: G S WC OE 6.1.25-android14-11-maybe-dirty-qki-consolidate #1 01-01 08:07:45.954 22394 22394 I Hardware name: Qualcomm Technologies, Inc. Houji based on SM8650 (DT) 01-01 08:07:45.954 22394 22394 I pstate : 20001000 (nzCv daif -PAN -UAO -TCO -DIT +SSBS BTYPE=--) 01-01 08:07:45.954 22394 22394 I pc : 000000009c3db42c 01-01 08:07:45.954 22394 22394 I lr : 0000006fc90109a8 01-01 08:07:45.954 22394 22394 I sp : 0000006faf7391a0 01-01 08:07:45.954 22394 22394 I : x29: 0000006faf7391f0 x28: 000000000000206e x27: 0000006faf739300 01-01 08:07:45.954 22394 22394 I : x26: 000000006fc8f9e8 x25: 0000000000000002 x24: 0000006fd2244800 01-01 08:07:45.954 22394 22394 I : x23: 0000006faf7392b0 x22: 0000006fd22448b0 x21: 0000000000000000 01-01 08:07:45.954 22394 22394 I : x20: 0000000000000000 x19: 0000006fd2244800 x18: 0000006faf739af0 01-01 08:07:45.954 22394 22394 I : x17: 000000000000f3e4 x16: 0000006fb1188b70 x15: 0000000000000002 01-01 08:07:45.954 22394 22394 I : x14: 0000006fc9010908 x13: 0000006fc9010888 x12: 0000006fc9010838 01-01 08:07:45.954 22394 22394 I : x11: 0000006fc90107d8 x10: 0000006fc8c05314 x9 : 000000009c3db400 01-01 08:07:45.954 22394 22394 I : x8 : 0000006faf7392f0 x7 : 3a656d614e646165 x6 : 0000006faf739658 01-01 08:07:45.954 22394 22394 I : x5 : 0000006fc8c05311 x4 : 0000006faf739658 x3 : 0000006fd2244800 01-01 08:07:45.954 22394 22394 I : x2 : 00000000138b24f0 x1 : 00000000138b24b8 x0 : 000000006fc8f9e8 查看系统调用的参数 $ cat /proc/self/syscall 0 0x3 0x75ee8c1e8000 0x20000 0x22 0x75ee8c1e7010 0x75ee8c1e7010 0x7fff6fe00c88 0x75ee8bf147e2 需要注意的是,如果要查看的进程此时正在执行,那么会返回错误。参数含义参考proc_pid_syscall,第一个表示系统调用号,接下来的6个表示系统调用的参数,最后2个分别表示用户的SP和PC寄存器的值 内存类 kasan 内核地址消毒剂(KASAN) KASAN实现原理 内存错误检测 (KASAN) 详解 Linux内核中使用内存检测 案例分析(二)内存越界检测工具kasan DEBUG memory问题的一些工具以及注意事项 ASan Memory Tagging for the kernel — Tag-Based KASAN 台湾Linux骇客分享:使用KASAN DEBUG内存问题 Hardware Tag-Based KASAN OOB UAF kfence OOB UAF KCSAN The Kernel Concurrency Sanitizer (KCSAN) KMSAN The Kernel Memory Sanitizer (KMSAN) UBSAN The Undefined Behavior Sanitizer - UBSAN 内存泄漏 内核检查内存泄漏的工具 --- kmemleak Kernel Memory Leak Detector SystemTap 定位 Memory Leak page owner memory alloc profiler slub_debug SLUB DEBUG原理 linux kernel内存泄漏检测工具之slub debug 死锁 softlockup Linux系列之soft lockup机制 浅析 soft lockup问题的定位方法 Softlockup detector and hardlockup detector hung task hard lockup 应用 ASAN https://www.cnblogs.com/pengdonglin137/p/17203518.html Heaptrack https://milianw.de/blog/heaptrack-a-heap-memory-profiler-for-linux.html ubuntu20.04安装heaptrack 服务器故障排查 服务器案例查询助手 > 典型场景案例指导