microsoft / microsoft/vscode-cpptools

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

Offen
#10,100 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

debugger question
Vorherrschende Sprache
TypeScript
Sterne
6.2k
Forks
1.7k
Ø Merge
14 Std. 46 Min.
Gemergte PRs (30 T.)
61

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der launch.json-Konfiguration cppdbg und dem Beispiel-C-Programm; vergleiche die Einstellungen externalConsole und args, während du den Hänger mit /etc/group als stdin reproduzierst. Prüfe, wie die Erweiterung LLDB unter macOS 12.6 startet. Als erledigt gilt dies, wenn die Dateieingabe stdin erreicht, ohne Umleitungstoken zu argv hinzuzufügen oder bei fgets() zu blockieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, macos, vscode
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.