microsoft / microsoft/vscode-cpptools

Locals in Variables spinning forever when the below attached program is debugged

Open
#12,800 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

debugger help wanted
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Environment
  • OS and version: macos
  • VS Code: 1.93.1
  • C/C++ extension: v1.21.6
  • OS and version of remote machine (if applicable):
  • GDB / LLDB version: lldb-1500.0.404.7
    Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Bug Summary and Steps to Reproduce

Bug Summary:

Steps to reproduce:

  1. Run the below program in gdb debugger
  2. set break at function subarr
  3. when breakpoint is hit, the locals variable starts to spin
Debugger Configurations
{
    "tasks": [
        {
            "label": "compile and run cpp",
            "type": "shell",
            "command": "g++ -std=c++17 -o ${fileBasenameNoExtension} ${file} && ./${fileBasenameNoExtension} < input.txt > output.txt && cat output.txt",
            "group": {
                "kind": "build",
                "isDefault": false
            }
        },
        {
            "label": "compile and run no input",
            "type": "shell",
            "command": "g++ -std=c++17 -o ${fileBasenameNoExtension} ${file} && ./${fileBasenameNoExtension}",
            "group": {
                "kind": "build",
                "isDefault": false
            }
        },
        {
            "label": "compile and run c",
            "type": "shell",
            "command": "gcc -o ${fileBasenameNoExtension} ${file} && ./${fileBasenameNoExtension} < input.txt > output.txt && cat output.txt",
            "group": {
                "kind": "build",
                "isDefault": false
            }
        },
        {
            "label": "compile and run python",
            "type": "shell",
            "command": "python3 ${file} < input.txt > output.txt && cat output.txt",
            "group": {
                "kind": "build",
                "isDefault": false
            }
        },
        {
            "type": "cppbuild",
            "label": "C/C++: clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: clang build active file",
            "command": "/usr/bin/clang",
            "args": [
                "-fcolor-diagnostics",
                "-fansi-escape-codes",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": false
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
Debugger Logs
This is no launch.json file
Other Extensions

No response

Additional Information

Program being run
`#include <bits/stdc++.h>

int subarr(vector& nums, int p) {
int sum = 0;
int sz = nums.size();
for (int i = 0; i < sz; i++)
{
sum+=nums[i];
}
int target = sum % p;
unordered_map<int, int> umap; //<csum, idx>
umap[0] = -1;
int csum = 0;
int res = INT_MAX;
for (int i = 0; i < sz; i++)
{
csum += nums[i];
int other_half = (csum % p - target + p) % p;
if (umap.find(other_half) != umap.end())
{
res = min(res, i - umap[other_half]);
}
umap[csum] = i;
}
return res != INT_MAX ? res : -1;
}

int main(int argc, char const *argv[])
{
vector v{3,1,4,2};
int p = 6;
auto res = subarr(v, p);
cout << res << endl;
return 0;
}
`
Screenshot 2024-10-03 at 10 39 55 PM

Contributor guide

Open the contributing guide

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.

Research direction

Reproduce the issue with the attached C++ program, setting a breakpoint in subarr and observing the Locals view when execution stops. Check the debugger configuration and available logs first; done means the Locals view renders instead of spinning indefinitely.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.