3
votes

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?

1
It could be operating system specific. What OS are you using? - Basile Starynkevitch
Can you explain why you have a problem with specifying the executable path? Does it change between builds? - ChatterOne
I am debugging multiple shared objects called from python. So, not sure what "program" is expecting for this case. But, the main question I have is why is it even needed given gdb -p PID is sufficient and is there a workaround? It looks like it is simply that the VSC C++ extension is not appropriate for this use case, which is disappointing. - Gaf
Same problem here, specifying "program" will make it impossible to set breakpoint - Suen

1 Answers

0
votes

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
        }
    ]
}