'Can Visual Studio Code use GDB to attach to process without the "Program" property?

I am debugging a shared C++ library called from python on Ubuntu 18.04. I can attach GDB to this using gdb -p PID (where PID is the python process ID).

I like the promises of Visual Studio Code, but the default debug launch.json requires "program" property attach, but gdb does not need this.

    { 
        "name": "(gdb) Attach",
        "type": "cppdbg",
        "request": "attach",
        "program": "enter program name, for example ${workspaceFolder}/a.out",
        "processId": "${command:pickProcess}",
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    }

In this case, what should program be and why is it even required?



Solution 1:[1]

Just use python (or optionally the full path to your python executable)

{ 
    "name": "(gdb) Attach",
    "type": "cppdbg",
    "request": "attach",
    "program": "/path/to/pythonX.Y",
    "processId": "${command:pickProcess}",
    "MIMode": "gdb",
    "setupCommands": [
        {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
        }
    ]
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Silmathoron