歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Qemu kgdb調試內核

Qemu kgdb調試內核

日期:2017/2/28 16:01:40   编辑:Linux教程

1,編譯內核
按 linux-2.6.30 內核配置 版本5 編譯內核 http://www.linuxidc.com/Linux/2011-12/49118.htm

2,用Qemu 啟動Linux
/usr/local/qemu/bin/qemu -kernel ./linux-2.6.30/arch/i386/boot/bzImage -hda ./1248179541.img -boot c -append "root=/dev/sda kgdboc=ttyS0,115200 kgdbwait" -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/etc/qemu-ifup -serial tcp::4321,server -alt-grab

a,/usr/local/qemu/bin/qemu : qemu 程序,下邊為參數
b,-kernel ./linux-2.6.30/arch/i386/boot/bzImage : 指定內核
c,-hda ./1248179541.img :指定磁盤文件
d,-boot c :qemu 啟動參數
e,-append "root=/dev/sda kgdboc=ttyS0,115200 kgdbwait" : 內核啟動參數
f,-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/etc/qemu-ifup :網絡接口參數
g,-serial tcp::4321,server :串口參數
h,-alt-grab :使用ctrl + Shift + Alt 作為熱鍵

3,啟動GDB
gdb vmlinux

設定波特率
set remotebaud 115200

連接到調試系統
target remote localhost:4321

當調試系統就緒時,會有如下信息
Remote debugging using localhost:4321
Malformed response to offset query, QC0000000000000001

重新連接到調試系統
target remote localhost:4321

4,讓系統啟動完成(不打算調試啟動過程的話)
continue

5,讓系統陷入調試
在目標系統上輸入
echo g > /proc/sysrq-trigge

=======================
使用qemu gdb-stub使用:

A Qemu debug memo 0) 安裝qemu sudo apt-get install qemu qtemu1) 創建rootfs imgqemu-img create rootfs.img 5G mkfs.ext3 -b 2048 rootfs.img sudo mount -o loop rootfs.img /mnt2) 創建根文件系統沒有?在虛擬機內安裝一個精簡的Ubuntu算了....3)啟動qemu (-S 讓qemu停止,並等待gdb的鏈接)qemu -kernel export/common_pc-bzImage-WR2.0zz_cgl -hda rootfs.img -append "root=/dev/hda" -S4) 在qemu窗口輸入ctrl+alt+2 切換到qemu 控制台輸入gdbserver 64435) 啟動gdbgdb common_pc-vmlinux-symbols-WR2.0zz_cgl>target remote 127.0.0.1:6443> b start_kernel> c 6)tips---比如設置了運行b fork, 在啟動的時候可以c 50, 代表忽略50各種break point. ---Ctrl+C 即可停止內核運行, bt可以看到當前運行的函數

Copyright © Linux教程網 All Rights Reserved