qemu-kvm串口功能代码调试随笔
由于最近需要使用qemu的宿主机-客户机 串口映射功能(但还未找到合适方式),便开始学习这部分代码
首先,搭建vscode debug 环境:
- 打开qemu源码路径,
- 创建./bin/debug/文件路径并进入
- 配置并编译
../../configure --target-list=x86_64-softmmu --enable-kvm --disable-sdl --enable-linux-aio --enable-debug --enable-debug-info make -j4
- 替换 项目路径下的.vscode 下的 launch.json ,内容如下:
{ // 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": "qemu", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/bin/debug/x86_64-softmmu/qemu-system-x86_64", "args": [ "-boot", //-boot c 启动第一个硬盘 "c", "-drive", "file=./debian_squeeze_amd64_standard.qcow2,if=virtio", //-drive file=debian_squeeze_amd64_standard.qcow2,if=virtio //指定硬盘镜像为debian_squeeze_amd64_standard.qcow2, //同时指定此硬盘的接入方式,即virtio,virtio是基于kvm实现的,因此需要开启kvm "-net", "nic", "-net", "user,hostfwd=tcp::22222-:22", //-net nic -net user,hostfwd=tcp::22222-:22 //配置虚拟网卡、网络栈权限为用户权限和端口映射 "-m", "2G", // -m 2G 指定2G内存 "-nographic", //关闭图像功能 "-enable-kvm" //开启kvm加速 ], "stopAtEntry": false, "cwd": "${workspaceFolder}/bin/debug/x86_64-softmmu/workdir", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "disable user defined signal", "text": "handle SIGUSR1 SIGUSR2 noprint nostop", "ignoreFailures": true } ], "miDebuggerPath": "/usr/bin/gdb" } ] }
这样qemu-system-x86_64的vscode调试环境便搭建好了,其中的debian_squeeze_amd64_standard.qcow2镜像是在网上下载的。配置文件后续还会修改,因为串口的参数未添加,会持续进行更新。