debug學習
參考
- 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
- 談復雜軟件低概率問題定位和復現
- 測試工具
內核
工具
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
- 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:
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的腳本
decode_stacktrace.sh
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
反匯編
硬件斷點
- bpftrace
- 硬件斷點API
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
- 下面是一個.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
KMSAN
UBSAN
內存泄漏
- 內核檢查內存泄漏的工具 --- kmemleak
- Kernel Memory Leak Detector
- SystemTap 定位 Memory Leak
- page owner
- memory alloc profiler
slub_debug
死鎖
softlockup
hung task
hard lockup
應用
ASAN
Heaptrack
服務器故障排查
本文來自博客園,作者:dolinux,未經同意,禁止轉載

浙公網安備 33010602011771號