
10

使用 VSCode 对 Linux 内核进行调试
source link: https://blog.zhengzi.me/debug-linux-kernel-with-vscode/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用 VSCode 对 Linux 内核进行调试
在上一篇博客使用 Qemu 和 GDB 对 Linux 内核进行调试中已经介绍了使用 Qemu 和 GDB 对 Linux 内核进行调试的方法,但是 GDB 调试对于用惯了 GUI 工具的人(比如我)来说并不是很直观,所以就希望尝试使用比较熟悉的 GUI 编辑器,如 VSCode,对内核进行调试。
由于 VSCode 的调试方式同样基于 GDB,所以需要先在 GDB 中测试没有问题。
需要在 VSCode 的插件市场中安装微软官方的 C/C++ 插件,该插件可用于 IntellSence 和 GDB 调试。
为了使 VSCode 支持内核的调试,需要配置 launch.json,特备注意需要配置 setupCommands
属性,以便在 GDB 启动后对其进行设置,大致的配置文件如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) linux",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/vmlinux",
"miDebuggerServerAddress": "localhost:1234",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerArgs": "-n",
"targetArchitecture": "x64",
"setupCommands": [
{
"text": "set arch i386:x86-64:intel",
"ignoreFailures": false
},
{
"text": "dir .",
"ignoreFailures": false
},
{
"text": "add-auto-load-safe-path ./",
"ignoreFailures": false
},
{
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
在添加配置后,直接在 VSCode 中设置断点,然后启动 Qemu,最后在 VSCode 中启动调试即可。
如果不仅需要使用 VSCode 对内核进行调试,还希望进行编辑,特别是激活 IntelliSence 以及格式化等功能,还需要对 VSCode 进行进一步的配置,具体配置已经置于 GitHub 仓库 https://github.com/imaginezz/vscode_config_debug_kernel 中,可以直接 Clone 为内核文件夹中的.vscode
目录。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK