虚拟机 / 云服务器
vscode remote-ssh
相关资源:
代码仓库:参考http://archeng.top/pa/0.6.html
实验文档: 参考http://archeng.top/pa
完成后的调试环境大概这样,和调试本地文件的步骤和方法基本一致
安装虚拟机环境/云服务器,centos7或者其他均可
虚拟机上安装好ssh,安装方式自己搜,安装相关工具链,包括gdb/cgdb,gcc,make~
本地vscode安装好remote ssh 插件,连上虚拟机,在本地vscode能写程序 算成功
调试方式可以有这两种
cgdb / gdb中调试(有门槛)
Vscode 界面调试(推荐)
按照实验文档完成首次编译和运行,中间可能会对makefile做一定修改,问题太杂不记录
在完成首次运行以后可以配置以下的配置文件
在项目根目录下创建 .vscode文件夹,文件夹下包括以下两个文件
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "make nemu",
"type": "shell",
"command": "cd nemu && make app",
}
]
}
lanuch.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": "gcc - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "/home/zhuzhicheng/project/PA/ics2019/nemu/build/mips32-nemu",
"args": [
"-l","/home/zhuzhicheng/project/PA/ics2019/nemu/build/nemu-log.txt",
"-d","/home/zhuzhicheng/project/PA/ics2019/nemu/tools/qemu-diff/build/mips32-qemu-so"],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make nemu",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
launch.json中 program 和 args 项 的目录 /home/zhuzhicheng/project/PA/ 需要替换成自己的代码仓库目录
-l 参数 后跟的是日志路径
-d 参数 后跟的是nemu运行时加载程序的路径
这里的参数 和 makefile 中 make run 参数 保持一致即可
后续即可开启正常调试
原文:https://www.cnblogs.com/ar-cheng/p/14050377.html