使用gdb+qemu调试OpenWrt内核
1、下载源代码git clone https://github.com/openwrt/openwrt.git2、选择Targetmake menuconfig Target System (QEMU ARM Virtual Machine) ---> Subtarget (QEMU ARM Virtual Machine (cortex-a15)) ---&
1、下载源代码
git clone https://github.com/openwrt/openwrt.git2、选择Target
make menuconfigTarget System (QEMU ARM Virtual Machine) --->
Subtarget (QEMU ARM Virtual Machine (cortex-a15)) --->
3、编译
make -j44、安装工具qemu
apt-get install qemu qemu-system-arm5、用initramfs启动openwrt
qemu-system-arm -nographic -M virt -m 64 \-kernel bin/targets/armvirt/32/openwrt-armvirt-32-zImage-initramfs \
-device virtio-net-pci,netdev=lan -device virtio-net-pci,netdev=wan \
-netdev user,id=lan -netdev user,id=wan,hostfwd=tcp::5555-:22
有关网络的配置请参考:https://wiki.qemu.org/Documentation/Networking
6、在openwrt中修改防火墙配置
config zoneoption name wan
list network 'wan'
list network 'wan6'
option input ACCEPT
option output ACCEPT
option forward REJECT
option masq 1
option mtu_fix 1
使配置生效
/etc/init.d/firewall reload6、使用ssh连接openwrt
ssh root@localhost -p 55557、传文件到openwrt
scp -P 5555 test_file root@localhost:/tmp/
8、使用gdb远程调试内核
qemu-system-arm -nographic -M virt -m 64 \
-kernel bin/targets/armvirt/32/openwrt-armvirt-32-zImage-initramfs \
-device virtio-net-pci,netdev=lan -device virtio-net-pci,netdev=wan \
-netdev user,id=lan -netdev user,id=wan,hostfwd=tcp::5555-:22 \
-S -s
-S表示qemu虚拟机会冻结CPU,等待远程的gdb进行连接
-s表示在1234端口接受gdb连接
在另一个窗口执行gdb
./staging_dir/toolchain-arm_cortex-a15+neon-vfpv4_gcc-5.5.0_musl_eabi/bin/arm-openwrt-linux-gdb build_dir/target-arm_cortex-a15+neon-vfpv4_musl_eabi/linux-armvirt_32/vmlinux.debug
(gdb) target remote localhost:1234
(gdb) b ip_rcv
Breakpoint 1 at 0xc0408b50: file net/ipv4/ip_input.c, line 421.
(gdb) c
Continuing.
Breakpoint 1, ip_rcv (skb=0xc3a23000, dev=0xc0a05654, pt=0xc0a05654, orig_dev=0xc39a1000) at net/ipv4/ip_input.c:421
421 if (skb->pkt_type == PACKET_OTHERHOST)
target remote localhost:1234 远程连接到qemu
b ip_rcv 在ip_rcv处设置断点
c 继续执行
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)