问题
I want to do remote C/C++ gdb debug with vscode. I use "Native Debug" extension where I do configuration. Here is my launch.json configuration
{
"type": "gdb",
"request": "launch",
"name": "Launch Program (SSH)",
"target": "./hello",
"cwd": "/home/root/test1/",
"ssh": {
"host": "192.168.15.130",
"cwd": "/home/root/test1/",
"password": "",
"user": "root"
}
And at target I run
gdbserver localhost:2000 ./hello
Unfortunately after I can't sill connect with remote device to debug. Is there someone with experience on configuring of this?
回答1:
I found the answer of this question here: Is it possible to attach to a remote gdb target with vscode?
Summary:
First you need to install the Native Debug extension for VS Code.
Then edit launch.json file and add:
{
"type": "gdb",
"request": "attach",
"name": "Attach to gdbserver",
"executable": "<path to the elf/exe file relative to workspace root in order to load the symbols>",
"target": "X.X.X.X:9999",
"remote": true,
"cwd": "${workspaceRoot}",
"gdbpath": "path/to/your/gdb",
"autorun": [
"any gdb commands to initiate your environment, if it is needed"
]
}
Then you can restart the VS Code and start debugging. Make sure there is no other client is connected to the gdb-server otherwise you will get time-out error.
回答2:
You have to install gdbserver on the remote machine. E.g.
apt-get install gdbserver
start the gdbserver on the remote machine
gdbserver :1234 ./mybinary
pick any port you like - here 1234
test the connection to gdbserver from your local machine by typing
gdb
(gdb) target remote myremotehostname:1234
trigger any gdb command to check whether it works - e.g. c
(or continue
) to continue running mybinary
.
Put the following into your .vscode/launch.json
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/mybinary",
"miDebuggerServerAddress": "myremotehostname:1234",
"cwd": "${workspaceRoot}",
"externalConsole": true,
"linux": {
"MIMode": "gdb"
}
}
Or use the "type": "gdb"
launch config as given in the other answer(s).
In order to get code browsing and stuff working, it's important to have the source directories in sync on the local and remote side. Use a network filesystem, manual copying, git triggers or anything like that to set this up.
来源:https://stackoverflow.com/questions/53519668/how-to-attach-to-remote-gdb-with-vscode