qemu调试linux内核

qemu -kernel arch/x86/boot/bzImage -s -S

#-S freeze CPU at startup

#-s shorthandfor-gdb tcp::1234若 不想使用1234端口,则可以使用-gdb tcp:xxxx来取代-s选项

(gdb)file linux-3.18.6/vmlinux # 在gdb界面中targe remote之前加载符号表

(gdb)target remote:1234 # 建立gdb和gdbserver之间的连接

(gdb)breakstart_kernel # 断点的设置可以在target remote之前,也可以在之后

(gdb)continue # 让qemu上的Linux继续运行

kernel 内核地址随机化原因分析,及解决方式

开启内核地址随机化KASLR后, qemu 调试 kernel 不能设置断点_qemu不能断点-CSDN博客

https://groups.google.com/g/zh-kernel/c/1A5nk5pExwI

qemu调试l内核在start_kernel打了断点,为何不会停到start_kernel? - 知乎

方案一:重新编bzImage

Kernel hacking  ---> 
    [*] Kernel debugging
    Compile-time checks and compiler options  --->
        [*] Compile the kernel with debug info
        [*]   Provide GDB scripts for kernel debuggin
​
Processor type and features ---->
[] Randomize the address of the kernel image (KASLR)

方案二:加-append nokaslr disables KASRL.

qemu-system-x86_64 -kernel ./linux-4.14.191/arch/x86/boot/bzImage -initrd ./busybox-1.35.0/initramfs.cpio.gz -s -S -nographic -append "init=/init console=ttyS0" -append nokaslr

GDB使用进阶 - 简书

tui 关联源码失败,则用layout src

重新关联源码

set substitute-path 原路径 新路径

vscode 调试

利用vscode远程调试Linux内核-良许Linux教程网

eclipse图形化调试

使用 GDB + Qemu 调试 Linux 内核 | 深入浅出 eBPF

高级本地调试

linux驱动之调试技巧--- 应用程序远程gdb+vscode调试应用程序, 串口kgdboc调试.ko驱动程序_gdb linux 驱动-CSDN博客

你可能感兴趣的:(linux)