目录
2.compile_commands.json生成:便于调试
makefile的生成方法:安装compiledbhttps://github.com/nickdiego/compiledb.git
此时,在xv6-riscv目录下,执行make qemu-gdb ,进程会阻塞.
配置tasks.json--->Terminal--->configure default build tasak
https://github.com/Aneureka/xv6-riscv
一天时间的教训---系统要ubuntu20.04的 ,用ubuntu18.04的搞了一天
学习资源:Xv6 代码导读 (调试工具配置;调试系统调用执行) [南京大学2022操作系统-P18]_哔哩哔哩_bilibili
下载源码
- git clone https://github.com/mit-pdos/xv6-riscv.git
- cd xv6-riscv
- 安装依赖
sudo apt install binutils-riscv64-linux-gnu
sudo apt install gcc-riscv64-linux-gnu
sudo apt install gdb-multiarch
sudo apt install qemu-system-misc u-boot-qemu qemu-utils
- 报错:
a725@ubuntu:~/Desktop/xv6/xv6-riscv$ make qemu qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 1 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 make: qemu-system-riscv64: Command not found Makefile:164: recipe for target 'qemu' failed make: *** [qemu] Error 127
解决方案: 249 wget https://download.qemu.org/qemu-5.1.0.tar.xz 251 tar -xvf qemu-5.1.0.tar.xz 253 cd qemu-5.1.0/ 275 ./configure --target-list=riscv64-softmmu,riscv64-linux-user 276 sudo make -j8 277 sudo make install 然后终端 输入 qemu-system-risv6 --version能打印即算ok看到shell即代表ok
a725@ubuntu:~/Desktop/xv6/xv6-riscv$ make qemu qemu-system-riscv64 -machine virt -bios none -kernel kernel/kernel -m 128M -smp 1 -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0 xv6 kernel is booting init: starting sh $ ls . 1 1 1024 .. 1 1 1024 README 2 2 2226 cat 2 3 23896 echo 2 4 22720 forktest 2 5 13016 grep 2 6 27256 init 2 7 23816 kill 2 8 22696 ln 2 9 22648 ls 2 10 26144 mkdir 2 11 22800 rm 2 12 22784 sh 2 13 41792 stressfs 2 14 23792 usertests 2 15 156240 grind 2 16 37992 wc 2 17 25000 zombie 2 18 22168 console 3 19 0 $退出方法
在 xv6 中按 Ctrl + a ,然后按 x 即可退出 xv6 系统。
makefile的生成方法:安装compiledbhttps://github.com/nickdiego/compiledb.git
针对makefile: 安装compiledb【git clone https://github.com/nickdiego/compiledb.git】来自动生成compile_commands.json
- sudo python3 setup.py install
- 将
sh-completion/compiledb.bash
文件的内容添加到.bashrc
文件中。- 然后在 xv6目录下 compiledb make 即可 ,可看到生成的 compile_commands.json
Cmake的生成方法
- 如果用CMAKE,加上参数DCMAKE_EXPORT_COMPILE_COMMANDS即可生成
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=True ..
- 修改xv6文件夹的Makefie 的 -smp 为1 便于调试
- 看Makefile来理解整个kernel的编译过程
make | less 或者 make | vim -
- Makefile的宏定义不能定义到 vscode
bear make ,让 vscode的宏生效
关于 .gdbinit
- gdb里面又gdb intit的配置,避免重复输入命令
开两个Terminal
- 另开一个终端,在
xv6-riscv
目录下,执行gdb-multiarch kernel/kernel
配置.gdbinit让其在gdb启动的时候生效
注意:.vdcode文件夹位置必须如下:
配置tasks.json--->Terminal--->configure default build tasak
task.json如下:用于编译
{ "version": "2.0.0", "options": { //指定make qemu的执行位置 "cwd": "/home/a123/Public/repo/gitee-xv6/xv6-labs-2020" }, "tasks": [ { "label": "xv6build", "type": "shell", "isBackground": true, "command": "make qemu-gdb", "problemMatcher": [ { "pattern": [ { "regexp": ".", "file": 1, "location": 2, "message": 3 } ], "background": { "beginsPattern": ".*Now run 'gdb' in another window.", "endsPattern": "." } } ], "group": { "kind": "build", "isDefault": true } } ] }配置launch.json[用于调试]
注意:由于有 "miDebuggerServerAddress": "127.0.0.1:26000", //所以需要吧.gdbinit 中 target remote xxxx:xx改为
@REM target remote xxxx:xx
{ "version": "0.2.0", "configurations": [ { "name": "xv6debug", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/kernel/kernel", "stopAtEntry": true, "cwd": "${workspaceFolder}", "miDebuggerServerAddress": "127.0.0.1:26000", //见.gdbinit 中 target remote xxxx:xx "miDebuggerPath": "/usr/bin/gdb-multiarch", // which gdb-multiarch "MIMode": "gdb", "preLaunchTask": "xv6build" } ] }如果一切顺利:将会这样