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

}

답변2

여러 환경 변수를 설정하려면 쉼표로 구분된 "name"쌍을  사용하세요 "value".

예:

"environment": [{"name": "LD_LIBRARY_PATH", "value": "/ld/library/path/"},
                {"name": "CUDA_VISIBLE_DEVICES", "value": "0"}
               ]

답변3

문제를 디버깅해 보겠습니다. 먼저 기억하세요. 이것은 JSON 파일이므로 다음이 필요합니다.생각하다JSON 파일로 받아보세요.

이것은 우리가 고려하고 있는 초기 JSON 객체입니다:

  "environment": [
    {
      "CUDA_VISIBLE_DEVICES": "0,1,2,3",
      "CUDA_DEVICE_ORDER": "PCI_BUS_ID"
    }
  ]

[따라서 우리는 다음을 포함하는 "environment"(&로 표시됨) 라는 JSON 배열을 갖게 됩니다.]단일 객체{(표시된 & }). 저것하나의그런 다음 개체에는 다음이 포함됩니다.키/값 쌍. 그것이 문제이다.

여러 키-값 쌍이 있는 단일 객체는 다음과 같습니다.structC에서는 단순한 변수 대신에하나의키/값 쌍.

논리적으로 말하자면, 우리는욕구이것은:

  • 우리의 "환경"은 많은 "환경 변수"를 보유하게 됩니다.
  • 환경 변수에는 각각 키와 값이 있습니다.

[]& 조합의 크기를 조정하면 {}다음과 같은 결과가 나타납니다.

  "environment": [
    {
      "CUDA_VISIBLE_DEVICES": "0,1,2,3"
    },
    {
      "CUDA_DEVICE_ORDER": "PCI_BUS_ID"
    }
  ]

관련 정보