How to attach to remote gdb with vscode?

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.

Leave a Comment