vscode+vps调试c程序

当运行的程序出现问题时,我们通常通过调试来追踪和定位问题。但是,当运行错误的机器上没有调试工具,我们就需要实现远程调试。简单地说,就是要调试的程序和调试器不在一台机器上。

使用ssh实现vscode远程连接

在vscode安装插件remote-ssh,安装完后可以看到这个图标
fgfsdgs
输入vps ip就可以直接连上了

vscode调试c程序

这时候如果直接debug,选择chrome,在工作目录下会出现.vscode文件夹。
将下面这两个文件复制到vscode下,就可以远程调试了。
launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/skynet",
"args": ["examples/config"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build-debug"
}
]
}

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "make",
"args": ["linux"],
"type": "shell"
},
{
"label": "build-debug",
"command": "make",
"args": ["linux"],
"type": "shell"
},
{
"label": "clean",
"command": "make",
"args": ["clean"],
"type": "shell"
}
]
}

根据不同程序的需求,需要改写一些参数。


La raíz de todos los males es el amor al dinero.