【调试】vscode远程调试c程序
附加进程
PS:用附加进程的方式最好在vscode用root用户去登录服务器
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 附加",
"type": "cppdbg",
"request": "attach",
"program": "/usr/share/postgresql_v13.15/bin/postgres",
"processId":"${command:pickProcess}",
// "args": [
// "-D/home/m01e/vuln-debug/postgresql/pgdata"
// ],
// "stopAtEntry": false,
// "cwd": "/usr/share/postgresql_v13.15",
// "environment": [],
// "externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Ignore SIGUSR1",
"text": "handle SIGUSR1 nostop noprint",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
vscode启动调试时,会提示选择要附加的进程,这时候选择对应的进程即可,vscode罗列出来了,很明显是选择psql连接的那个进程。
在目标进程成功断下:
launch方式启动
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "/usr/share/postgresql_v13.15/bin/postgres",
// "args": [
// "-D/home/m01e/vuln-debug/postgresql/pgdata"
// ],
// "stopAtEntry": false,
// "cwd": "/usr/share/postgresql_v13.15",
// "environment": [],
// "externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Ignore SIGUSR1",
"text": "handle SIGUSR1 nostop noprint",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}