主机是WIN10,远程机器是Ubuntu20.04,使用attach附加远程进程,示例launch.json文件如下:
"configurations": [
{
"name": "(gdb) 附加",
"type": "cppdbg",
"request": "attach",
"processId":"${command:pickProcess}",
"program": "xxx/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"sourceFileMap":{
"/AAA/": "/BBB/"
},
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
其中"processId":"${command:pickProcess}"可以使你选择远程进程。但如果你不是以root账户调试,会有下面提示需要管理员权限
com@com-Nuvo-5501:/usr/share/polkit-1/actions$ /usr/bin/env /bin/sh /tmp/Microsoft-MIEngine-Cmd-nkcnhtb0.4i