microsoft / microsoft/vscode-cpptools

cannot debug C program reading large file from stdin on macOS 12.6 Monterey

Open
#10,100 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Environment
  • OS and version: macOS 12.6 Monterey
  • VS Code: 1.72.2
  • C/C++ extension: unsure, but downloaded approx. Oct. 28 2022
  • OS and version of remote machine (if applicable):n/a
  • GDB / LLDB version: lldb-1400.0.30.3
Bug Summary and Steps to Reproduce

Bug Summary:

I have been unable to find a way to connect large datasets to the stdin of a C code program being debugged by vscode -- it seems possible only to use the launch.json "externalConsole": true setting to input small amounts of manually entered input via an opened terminal window. (Such manual input is entirely unsuited to debugging a program with very large multi-column numerical input datasets.) This problem occurs on both Intel and Apple M1 macOS 12.6 systems.

I have seen recommendations in various places to use a launch.json args setting for this, e.g., "args": ["<", "/tmp/somefile"] , but this simply does not work (other than to corrupt the program's main() argv[] array by appending spurious < and /tmp/somefile arguments, which should obviously not be visible to any program actually reading stdin ). Here is the launch.json entry I tried unsuccessfully to use:

        {
            "name": "vscstdio-stdin-test",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/vscstdio",
            "args": ["<", "/etc/group"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }

(Note that specifying "externalConsole": true in that configuration only improved the situation to the extent of allowing manually typed input to be sent to stdin , which is not sufficient for my purposes.)

Here is a small sample program which demonstrates the problem. It simply prints out the contents of the main() argv[] array, including the spurious < and /etc/group arguments, and then echoes to stdout whatever is read from stdin :

#include <stdio.h>
#include <stdlib.h>
    
char buf[512];

int main(int argc, char **argv) {       
        int i;
            
        for (i= 0; i < argc; i++)
                (void) fprintf(stderr, "%1d: %s\n", i, argv[i]);
        (void) fflush(stderr);
            
        for (i= 0; fgets(buf, (int) 512, stdin) != (char *) 0; i++)
                (void) fprintf(stdout, "[%3d] _%s", i, buf);

        (void) fprintf(stdout, "At EOF\n");
        
        exit(0);
}

When run with the above launch.json configuration it hangs indefinitely on the first call to fgets() instead of properly reading the redirected /etc/group through stdin .

I truly hope you can either fix this problem or tell me what I am doing wrong, otherwise vscode is not usable to me for debugging a lot of my project's software which makes heavy use of stdio. Thanks!

Debugger Configurations
See launch.json above.

tasks.json:
{
    "tasks": [
        {
            "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": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
Debugger Logs
None.
Other Extensions

No response

Additional Information

No response

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

Start with the launch.json cppdbg configuration and the sample C program; compare the externalConsole and args settings while reproducing the hang with /etc/group as stdin. Check how the extension launches LLDB on macOS 12.6. Done means file input reaches stdin without adding redirection tokens to argv or blocking at fgets().

Written by the indexing model from the issue text.

Assessment

Tech stack
c, macos, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.