NVIDIA / nsight-vscode-edition

A Visual Studio Code extension for building and debugging CUDA applications.
Other
68 stars 11 forks source link

Unable to parse multiple args in launch configuration for CTest #47

Open agrinh opened 2 weeks ago

agrinh commented 2 weeks ago

I have a simple CTest debug configuration where I'm expecting to be able to launch the debugger for a certain test with the given program and arguments. This works fine for tests with 1 argument. However, with multiple args only the first is provided to the program. This seems to be related to CTest representing the argument list as a semicolon-separated string.

# launch.json
{"configurations": [{
        "name": "CUDA C++: CTest",
        "type": "cuda-gdb",
        "request": "launch",
        "logFile": "${workspaceFolder}/log.txt",
        "program": "${cmake.testProgram}",
        "args": ["${cmake.testArgs}"]
}]}

E.g., for the test

# CMakeLists.txt
    ...
    add_test(NAME test_foo COMMAND test_foo_cuda 1 2 3)

which simply does

# test_foo_cuda.cu
int main(int argc, char** argv) {
  // Print all command-line arguments
  std::cout << "Command-line arguments: (" << argc << ")" << std::endl;
  for (int i = 0; i < argc; ++i) {
    std::cout << "argv[" << i << "]: " << argv[i] << std::endl;
  }
}

the output is

Command-line arguments: (2)
argv[0]: /workspaces/project/build/test_foo_cuda
argv[1]:1

Looking in the log I see that all args are picked up:

# log.txt
...
[13:21:04.132 UTC] GDB command: 4 -exec-arguments 1;2;3
...

Any suggestions? I am able to work-around this issue by adding the arguments as a single string in CTest, though this breaks test running without a debugger.

# CMakeLists.txt
    ...
    add_test(NAME test_foo COMMAND test_foo_cuda "1 2 3")

and results in following execution and log

Command-line arguments: (4)
argv[0]: /workspaces/project/build/test_foo_cuda
argv[1]: 1
argv[2]: 2
argv[3]: 3
# log.txt
...
[13:26:01.195 UTC] GDB command: 4 -exec-arguments 1 2 3
...
yczhang1028 commented 2 weeks ago

Hi @agrinh, args input in array format is an known bug for this version. Args allow string & array format. I thought you can directly use string format.