1

I'm trying to debug a test program with VS CODE, CMake in Ubuntu 20. I referred mainly to the CUDA debugger document: https://docs.nvidia.com/nsight-visual-studio-code-edition/cuda-debugger/index.html. However, I'm not sure about how to write a correct launch.json in a project based on CMake. Here is my CMakeLists.txt

cmake_minimum_required(VERSION 3.2)
project(cudaDebug CXX CUDA)
find_package(CUDA REQUIRED)
add_executable(main main.cu)

Here is my launch.json generated by VS CODE

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "CUDA C++: Launch",
            "type": "cuda-gdb",
            "request": "launch",
            "program": "main.cu"
        },
        {
            "name": "CUDA C++: Attach",
            "type": "cuda-gdb",
            "request": "attach"
        }
    ]
}

When I press F5 to start debugging, an error information poped up:

main.cu: 346262241346234211351202243344270252346226207344273266346210226347233256345275225.

2 Answers 2

2

I think you have to change the following line:

         "program": "main.cu"

to

         "program": "${command:cmake.launchTargetPath}"

and select the executable in VSCode (usually on the bottom row where you can also select build targets).

Have also a look here:

https://vector-of-bool.github.io/docs/vscode-cmake-tools/debugging.html

Sign up to request clarification or add additional context in comments.

Comments

2

you can try to update your cmake version to higher than 3.10, which no longer need to use find_package(CUDA)
here is one template for vscode and cmake to use cuda-gdb
CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(your_project_name CUDA CXX C)  # enable cuda language
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} "-g -G")  # enable cuda-gdb

add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE your_source_files)
set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)

tasks.json

{
    "options": {
       "cwd": "${workspaceFolder}/build"  
    },
    "tasks": [
       {
          "label": "cmake",  
          "command":"cmake",  
          "args": ["-DCMAKE_BUILD_TYPE=Debug", ".."]  
       },
       {
          "label": "make",  
          "command":"make",  
       },
       {
          "label": "cmake build", 
          "dependsOn":[  
             "cmake",
             "make"
          ],
       }
    ],
    "version": "2.0.0"
 }

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "CUDA C++: Launch",
            "type": "cuda-gdb",
            "request": "launch",
            "program": "${workspaceFolder}/build/your_executable_file",
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "cmake build"
        }
     ]
}

wish it could help you :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.