VS Code start gdbserver
Asked Answered
L

2

7

I am trying to write a launch configuration for VS Code that can start gdbserver as a preLaunchTask.

When I start debugging, everything just stalls when gdbserver says "Listening on port XXXX"

I found many examples online of methods for other debuggers, but nothing specific for gdbserver.

I have tried setting isBackground to true to no avail, along with trying to set up a problemMatcher

I couldn't find any documentation that seemed to explain how to write your own problemMatcher either.

So, how do I write a task that can start gdbserver as part of a preLaunchTask for my debugger?

Here is my task to start gdbserver

{
    "label": "run",
    "type": "shell",
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "dedicated"
        },
    "options": {
        "cwd": "${workspaceRoot}/build"
    },
    "command": "ssh",
    "args": [
            "root@remote",
            "'gdbserver localhost:9091 program'"
    ]     
}

Here is my launch configuration

{
    "name": "Remote Debug",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceRoot}/build/program",
    "args": [],
    "stopAtEntry": false,
    "cwd": "${workspaceRoot}",
    "environment": [],
    "externalConsole": true,
    "MIMode": "gdb",
    "setupCommands": [
        {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        }
    ],
    "preLaunchTask": "run",
    "miDebuggerServerAddress": "remote:9091",
    "miDebuggerPath": "aarch64-sbs-linux-gdb"
}
]
Louella answered 28/6, 2021 at 20:54 Comment(0)
L
6

I had the same issues as you. I got it running using a pattern matcher and running it in the background. The task only starts the gdbserver on the remote target. It doesn't compiles or send the files to the remote target.

{
        "type": "shell",
        "label": "Start gdbserver",
        "command": "ssh",
        "args": [
            "root@remote",
            "gdbserver localhost:3000 ${fileBasenameNoExtension}"
        ],
        // "dependsOn": [
        //     "optional build task"
        // ],
        "presentation": {
            "echo": true,
            "reveal": "always",
            "focus": false,
            "panel": "shared",
            "showReuseMessage": true,
            "clear": false
        },
        "group": "build",
        "detail": "Starts the gdbserver and waits for success",
        "isBackground": true,
        "problemMatcher": {
            "pattern": [
                {
                    "regexp": ".",
                    "file": 1,
                    "location": 2,
                    "message": 3
                }
            ],
            "background": {
                "activeOnStart": true,
                "beginsPattern": "^.*Process*",
                "endsPattern": "^.*Listening*"
            }
        }
    },
Loper answered 26/10, 2021 at 9:18 Comment(0)
L
0

In my case, I am using VS Code to start the GDBServer in a DOCKER container on a remote embedded device.

Adding this part specifically from the other answer worked for me:

   "problemMatcher": {
            "pattern": [
                {
                    "regexp": ".",
                    "file": 1,
                    "location": 2,
                    "message": 3
                }
            ],
            "background": {
                "activeOnStart": true,
                "beginsPattern": "^.*Process*",
                "endsPattern": "^.*Listening*"
            }
        }
  

This had me end up with this final Task configuration!:

        {
            "label": "start-gdbserver",
            "type": "shell",
            "command": "docker",
            "args": [
                "exec",
                "-it",
                "container-name",
                "gdbserver",
                ":1234",
                "<path-to-executable>"
            ],
            "isBackground": true,
            "problemMatcher": {
                "pattern": [
                    {
                        "regexp": ".",
                        "file": 1,
                        "location": 2,
                        "message": 3
                    }
                ],
                "background": {
                    "activeOnStart": true,
                    "beginsPattern": "^.*Process*",
                    "endsPattern": "^.*Listening*"
                }
            },
            "presentation": {
                "reveal": "always",
                "panel": "shared",
                "clear": false
            },
            "runOptions": {
                "instanceLimit": 1
            },
            "icon": {
                "id": "debug-disconnect",
                "color": "terminal.ansiCyan"
            },
            "dependsOn": "stop-gdbserver"
        }
Lathrope answered 7/10, 2024 at 18:35 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.