VS CodeでGDB統合を使用するときに「launch.json」設定で環境変数を設定する方法

VS CodeでGDB統合を使用するときに「launch.json」設定で環境変数を設定する方法

vscodeの私の設定はlaunch.json次のとおりです。

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch 25.0_regeragpu",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/25.0_regeragpu/Blazer/MercuryImageComputer/KT/leaf/M31/BrightField/bin/LeafStandalone/Debug/12/LeafStandAlone.x86-64",
            "args": ["-noForcedPatches","${workspaceFolder}/virgo_algo_preq/JobDump/JobInfo_108"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/25.0_regeragpu/Blazer/MercuryImageComputer/KT/leaf/M31/BrightField/bin/LeafStandalone/Debug/12",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

この設定の目的は、vscodeでGDB統合を使用することです。特に、デバッグ時にvscode端末のbashセッションに設定されているすべての環境変数が継承されるように、次のペアを指定しました"externalConsole": false。また、environment構成に名前付きペアがあることも確認しました。私が理解しているように、デバッグのためにvscodeを介して新しいbashセッションを開始する場合は、すべての環境変数をこのペアenvironmentに割り当てる必要があります。デバッグ時に新しいbashオプションを試してみるように設定ファイルを修正しました。

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch 25.0_regeragpu",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/25.0_regeragpu/Blazer/MercuryImageComputer/KT/leaf/M31/BrightField/bin/LeafStandalone/Debug/12/LeafStandAlone.x86-64",
            "args": ["-noForcedPatches","${workspaceFolder}/virgo_algo_preq/JobDump/JobInfo_108"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/25.0_regeragpu/Blazer/MercuryImageComputer/KT/leaf/M31/BrightField/bin/LeafStandalone/Debug/12",
            "environment": [{"CUDA_VISIBLE_DEVICES":"0,1,2,3","CUDA_DEVICE_ORDER":"PCI_BUS_ID"}],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

"environment": [{"CUDA_VISIBLE_DEVICES":"0,1,2,3","CUDA_DEVICE_ORDER":"PCI_BUS_ID"}]特に、次のペアを指定したことがわかります"externalConsole": true。ただし、デバッグを開始すると、vscodeのデバッグツールは常に準備完了状態にあり、実際のデバッグセッションには入りません。 vscodeの新しいコンソールでデバッグするには、環境変数をどのように設定する必要がありますか?

ベストアンサー1

以下はあなたの例です。環境詰まった。

    {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "g++ - (GDB 9.2) Build and debug active file with RepoCodeInspection",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/bin/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [
            {
                "description": "same as commands below by using 'setenv ...",
                "info": "cant debug b/c of libBase/libRecipe now requiring dependency to boost for stacktrace dumps",
                "name": "LD_LIBRARY_PATH",
                "value": "/libs/:./"
            }
        ],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "logging": {
            "trace": false,
            "traceResponse": false
        },
        "preLaunchTask": "RepoCodeInspection",
        
    },
    {
        "name": "g++ - (GDB 9.2) Attach to a running process",
        "type": "cppdbg",
        "request": "attach",
        "processId":"${command:pickProcess}",
        "program": "${fileDirname}/bin/${fileBasenameNoExtension}",
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "logging": {
            "trace": false,
            "traceResponse": false
        },
        "preLaunchTask": "RepoCodeInspection",
       
    },
]

}

おすすめ記事