Debug XV6
·
Jahjah
Clone 代码
git clone https://github.com/mit-pdos/xv6-riscv
下载工具
# Debian or Ubuntu
sudo apt-get install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
编译
make qemu
调试
gdb
make qemu-gdb
然后在另一个窗口打开gdb
gdb-multiarch
常用的一些命令
加载配置文件
gdb-multiarch -x .gdbinit
指定要调试的可执行文件
file kernel/kernel
设置断点
b kernel/main.c:100
打印变量
p i
查看调用栈
bt
vscode
生成compile commands
bear -- make qemu
vscode调试配置文件
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug xv6",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/kernel/kernel",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb-multiarch",
"miDebuggerServerAddress": "localhost:25000",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
},
]
}
]
}