Visual Studio Code 可以使用 GDB 附加到没有“程序”属性的进程吗?

Gaf*_*Gaf 7 gdb visual-studio-code

我正在 Ubuntu 18.04 上调试从 python 调用的共享 C++ 库。我可以使用 gdb -p PID(其中 PID 是 python 进程 ID)将 GDB 附加到此。

我喜欢 Visual Studio Code 的承诺,但默认的调试 launch.json 需要附加“program”属性,但 gdb 不需要这个。

    { 
        "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
            }
        ]
    }
Run Code Online (Sandbox Code Playgroud)

在这种情况下,程序应该是什么?为什么需要它?

Sil*_*ron 1

只需使用python(或者可选地使用 python 可执行文件的完整路径)

{ 
    "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
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)