`cuda-gdb` adapter cannot start debugging without arguments when used with CMake Tools

Open Beginner friendly
#73 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
typescript
Domain
tooling

Research direction

Start in src/debugger/cudaGdbSession.ts around lines 684-686 and inspect how an empty args array is handled for LaunchRequest. Reproduce with the provided CMake Tools configuration and argc/argv program, then verify that CMake: Debug produces argc == 1 with no empty argument.

Written by the indexing model from the issue text.

Description

Problem

When using the cuda-gdb debug adapter from NVIDIA Nsight VS Code Edition, if args in the launch/debug configuration is an empty array:

{
  "type": "cuda-gdb",
  "request": "launch",
  "program": "<path-to-program>",
  "args": []
}

the debuggee program will receive one empty string argument, instead of “no arguments”.

That is, the program does not see:

argc == 1, argv[0] == <program>

but instead sees:

argc == 2, argv[0] == <program>, argv[1] == ""

If writing launch.json manually, this issue can be worked around by simply not writing args in the launch configuration object, to express “launch without arguments”.

However, when this plugin is used together with CMake Tools, the de facto standard CMake support extension in VS Code, CMake Tools always provides args in the dynamically generated launch configuration, with the default value being [].

The args semantics expected by CMake Tools are that an empty args array represents no arguments. In this case, the NVIDIA Nsight VS Code Edition plugin cannot start Debug in the expected no-argument way.

Reproduction steps

Prepare a minimal program that prints argc and argv:

#include <iostream>

int main(int argc, char** argv) {
    std::cout << "argc = " << argc << "\n";
    for (int i = 0; i < argc; ++i) {
        std::cout << "argv[" << i << "] = [" << argv[i] << "]\n";
    }
    return 0;
}

After configuring the CMake Tools extension in .vscode/settings.json, invoke NVIDIA Nsight VS Code Edition for debugging:

"cmake.debugConfig": {
    "type": "cuda-gdb",
    "request": "launch",
    "debuggerPath": "/opt/cuda/bin/cuda-gdb",
    "breakOnLaunch": false
}

Run the command CMake: Debug from Ctrl + Shift + P to start debugging. After that, the program will output something like:

argc = 2
argv[0] = [<program>]
argv[1] = []

Expected behavior

The program receives no arguments, and argc == 1.

Suggested fix

Consider modifying the check in src/debugger/cudaGdbSession.ts. Currently, the condition being used is args.args && requestType === 'LaunchRequest'.

https://github.com/NVIDIA/nsight-vscode-edition/blob/59561f98550d3347091adc9b26129c0932cdd32f/src/debugger/cudaGdbSession.ts#L684-L686

[] is truthy, causing the branch to be taken, and [] is converted into one empty string argument "". In fact, when it is [], this branch should not be entered.

Related information

You can check other implementations that support the Debug Adapter Protocol to see the correct semantic convention: for example, lldb-dap interprets an empty args array as empty arguments:

https://github.com/llvm/llvm-project/blob/441725611d0e166a144ac85665bf0ac3611851de/lldb/tools/lldb-dap/Handler/RequestHandler.cpp#L207-L210

Dominant language
TypeScript
Stars
105
Forks
20
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/nsight-vscode-edition

All issues in NVIDIA/nsight-vscode-edition

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.