qemu + vscode linux内核调试

linux 内核代码调试

前言

本文记录在搭建qemu+vscode的linux内核调试环境所进行的步骤与遇到的问题。

环境介绍

*ubuntu 20.04
*linux 内核版本 linux-4.15.2
*gcc 版本 gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf

内核的配置

内核的配置

Kernel hacking  --->
    [*] Kernel debugging
    Compile-time checks and compiler options  --->
        [*] Compile the kernel with debug info
        [*]   Provide GDB scripts for kernel debugging

禁止内核优化,见 之前的文章 linux内核禁止优化的设置

编译内核的脚本

#!/bin/bash
cd linux-4.15.2

export ARCH=arm
export CROSS_COMPILE=/home/liu/tool/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-

make vexpress_defconfig
make zImage -j16
#make modules -j16
make dtbs -j16

使用的板选择 vexpress

qemu 的安装与启动

安装qemu

sudo apt install qemu qemu-system qemu-kvm

安装好qemu 后,编译完成内核

qemu-system-arm -M vexpress-a9 -m 512M -kernel /实际路径/linux-4.15.2/arch/arm/boot/zImage -dtb /实际路径/linux-4.15.2/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "rdinit=/linuxrc console=ttyAMA0" -S -s

相对于运行命令,加入-S和-s参数:
-s: 在1234端口接受GDB调试
-S:冻结CPU直到远程GDB输入相应命令

** 这里要注意的地方,要指定zImage **

vscode的配置

lanuch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/xx/work/linux_src/linux-4.15.2/vmlinux",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb-multiarch",
            "miDebuggerServerAddress": "localhost:1234",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值