【问题标题】:How to read console input from VScode while live-debugging如何在实时调试时从 VScode 读取控制台输入
【发布时间】:2019-10-04 07:20:31
【问题描述】:

我正在尝试实时调试一个 C 程序,该程序使用 VScode 的 C/C++ 扩展,还允许我使用 scanf() 将直接输入写入控制台。但是,当我调试代码时,它会打开调试控制台,它不允许我输入任何输入。

我发现有人回答了这个问题的两个线程:

https://github.com/OmniSharp/omnisharp-vscode/issues/1053

Debug Console window cannot accept Console.ReadLine() input during debugging

两者都建议将 launch.json 文件中的“console”属性设置为“externalTerminal”或“integratedTerminal”。但是,我找不到该属性或为此创建它,因为它在我的文件中不存在。

我确实有“externalConsole”属性,它可以设置为真或假。但是这两个选项似乎都像以前一样打开了调试控制台。

launch.json 文件:

 {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "/mnt/c/Users/David/Documents/code/puc-rio/inf1010/lab8/teste.out",
            "args": [],
            "stopAtEntry": true,
            "cwd": "/mnt/c/Users/David/Documents/code/puc-rio/inf1010/lab8/",
            "environment": [],
            "externalConsole": true,
            "windows": {
                "MIMode": "gdb",
                "miDebuggerPath": "/usr/bin/gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            },
            "pipeTransport": {
                "pipeCwd": "",
                "pipeProgram": "c:\\windows\\sysnative\\bash.exe",
                "pipeArgs": [
                    "-c"
                ],
                "debuggerPath": "/usr/bin/gdb"
            },
            "sourceFileMap": {
                "/mnt/c": "${env:systemdrive}/",
                "/usr": "C:\\Users\\David\\AppData\\Local\\Packages\\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr"
            }
        }
    ]

当我尝试向调试控制台写入内容时会发生什么:

Unable to perform this action because the process is running.

【问题讨论】:

    标签: c debugging visual-studio-code


    【解决方案1】:

    在看到您的帖子之前,我也有同样的困惑。在我的 Windows 环境中,我将“externalConsole”设置为 true。之后,当开始调试时,我的程序会有一个cmd shell(不是VScode提供的“调试控制台”),可以在其中输入stdin。!(https://i.stack.imgur.com/KKlJP.jpg

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-15
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多