vscode ssh 如何调试
时间: 2025-01-14 14:49:57 浏览: 37
### 如何在VSCode中通过SSH进行调试
为了实现在Visual Studio Code (VSCode) 中通过SSH进行远程调试,需遵循特定配置流程[^1]。
#### 配置环境
安装必要的扩展程序对于设置远程开发至关重要。这涉及到使用Remote - SSH 扩展来连接到目标机器并部署所需的工作空间文件夹。确保本地和远端计算机上都已正确安装了VSCode及其服务器组件。
#### 创建SSH配置文件
编辑`~/.ssh/config` 文件以定义要连接的目标主机参数:
```bash
Host target-machine
HostName your.remote.machine.ip.or.name
User your_username_on_remote_machine
IdentityFile ~/.ssh/id_rsa_or_other_private_key_path
```
此操作简化了后续命令行中的连接过程,并提高了安全性。
#### 设置launch.json
创建或修改项目根目录下的`.vscode/launch.json` 文件,加入如下JSON对象之一作为配置项的一部分:
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch via SSH",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/your_program_name",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb", // 或者其他路径取决于GDB位置
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"pipeTransport": {
"pipeProgram": "plink.exe", // Windows 用户应指定 PuTTY Link 的路径;Linux/macOS 可省略此项
"pipeArgs": ["target-machine"],
"debuggerPath": "/usr/bin/gdb"
},
"sourceFileMap": {
"/remote/path/to/source/files": "${workspaceRoot}"
}
}
]
}
```
上述配置允许开发者利用GDB调试器执行远程应用程序实例的同时,在本地IDE界面内查看源码与变量状态变化情况。
阅读全文
相关推荐


















