Launch.json 'args' not passing correctly

This has had me confused for a while, was stopping me from using the debugger. Found a workaround but still can’t quite solve the why of it. The following line in launch.json wouldn’t pass my “args”:[“”,…] array correctly

CASE 1: "args": ["arg1", "arg2"], // correct way to pass args? CASE 1, doesn’t work.
CASE 2: "args": ["arg1 arg2"], // incorrect way to pass args? CASE 2, works.

CASE 1 example:

"args": ["arg1", "arg2"], // correct way to pass args? CASE 1

with verbose on, gdb reports the following with “;” in between the args in -exec-arguments

Type "apropos word" to search for commands related to "word".
GDB command: 0 -gdb-set non-stop off
GDB result: 0 done
GDB command: 1 -gdb-set mi-async on
GDB result: 1 done
GDB command: 2 -file-exec-and-symbols "/path/to/executable/test"
GDB result: 2 done
GDB command: 3 -enable-pretty-printing
GDB result: 3 done
GDB command: 4 -exec-arguments arg1;arg2
GDB result: 4 done

and trying to print argv in main() gives this:

Number of arguments: 2
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Argument 0: /path/to/executable/test\n"}}
Argument 0: /path/to/executable/test
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Argument 1: arg1\n"}}
Argument 1: arg1
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"argc 2\n"}}

CASE 2 example:

"args": ["arg1 arg2"], // incorrect way to pass args? CASE 2

with verbose on, gdb reports the following -exec-arguments

To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"For help, type \"help\".\n"}}
For help, type "help".
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Type \"apropos word\" to search for commands related to \"word\".\n"}}
Type "apropos word" to search for commands related to "word".
GDB command: 0 -gdb-set non-stop off
GDB result: 0 done
GDB command: 1 -gdb-set mi-async on
GDB result: 1 done
GDB command: 2 -file-exec-and-symbols "/path/to/executable/test"
GDB result: 2 done
GDB command: 3 -enable-pretty-printing
GDB result: 3 done
GDB command: 4 -exec-arguments arg1 arg2
GDB result: 4 done

and trying to print argv in main() gives this:

Number of arguments: 3
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Argument 0: /path/to/executable/test\n"}}
Argument 0: /path/to/executable/test
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Argument 1: arg1\n"}}
Argument 1: arg1
To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Argument 2: arg2\n"}}
Argument 2: arg2

Full launch.json

{
    "version": "0.2.0",
        "configurations": [
          

          {
            "name": "CUDA C++: Launch",
            "type": "cuda-gdb",
            "request": "launch",   
            "program": "${workspaceFolder}/test",
            //"args": ["arg1", "arg2"], // correct way to pass args? CASE 1
            "args": ["arg1 arg2"], // incorrect way to pass args? CASE 2
            "stopAtEntry": false,                     
            "verboseLogging": true      
          }
        ]
      
}

main entry and print

int main(int argc, char **argv) {
  

  std::cout << "Number of arguments: " << argc << std::endl;

    for (int i = 0; i < argc; ++i) {
        std::cout << "Argument " << i << ": " << argv[i] << std::endl;
    }

Versions:
Ubuntu 22.04.5 LTS; 6.8.0-49-generic

nvcc: NVIDIA (R) Cuda compiler driver Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0

Nsight VSCE v2024.1.34572442

Compiled with g++ -g -O0 for .cpp files, nvcc -g -G -0O for .cu files

g++/gcc 9.5.0

Additional gdb version details:

Summary

Logger successfully initialized

Confirmed that we are on a Linux system

cuda-gdb found and accessible

Calling launch request in super class

GDB notify async: thread-group-added,id=“i1”

To client: {“seq”:0,“type”:“event”,“event”:“output”,“body”:{“category”:“stdout”,“output”:“NVIDIA (R) CUDA Debugger\n”}}

NVIDIA (R) CUDA Debugger

To client: {“seq”:0,“type”:“event”,“event”:“output”,“body”:{“category”:“stdout”,“output”:“11.5 release\nPortions Copyright (C) 2007-”}}

11.5 release Portions Copyright (C) 2007-To client: {“seq”:0,“type”:“event”,“event”:“output”,“body”:{“category”:“stdout”,“output”:“2021 NVIDIA Corporation\n”}}

2021 NVIDIA Corporation

To client: {“seq”:0,“type”:“event”,“event”:“output”,“body”:{“category”:“stdout”,“output”:“GNU gdb (GDB) 10.1\n”}}

GNU gdb (GDB) 10.1

To client: {“seq”:0,“type”:“event”,“event”:“output”,“body”:{“category”:“stdout”,“output”:“Copyright (C) 2020 Free Software Foundation, Inc.\n”}}

Copyright (C) 2020 Free Software Foundation, Inc.

To client: {“seq”:0,“type”:“event”,“event”:“output”,“body”:{“category”:“stdout”,“output”:“License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.”}}

License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.To client: {“seq”:0,“type”:“event”,“event”:“output”,“body”:{“category”:“stdout”,“output”:“\nType "show copying" and "show warranty" for details.\n”}}

Hi, @jsev24

Thanks for reporting this !
This is a known issue and we have a internal bug for tracking. If there is any update, I will let you know.

1 Like