Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System("cls") doesn't work in the debugger terminal. #13110

Open
RabbitSeries opened this issue Jan 6, 2025 · 2 comments
Open

System("cls") doesn't work in the debugger terminal. #13110

RabbitSeries opened this issue Jan 6, 2025 · 2 comments
Labels
bug debugger help wanted Can be fixed in the public (open source) repo. tasks/build/debug An issue relating to tasks.json (e.g. build issues)

Comments

@RabbitSeries
Copy link

Environment

  • OS and version: Microsoft Windows 11 Pro 10.0.26100 N/A Build 26100
  • VS Code: 1.96.2
  • C/C++ extension: [email protected]
  • OS and version of remote machine (if applicable): NONE
  • GDB / LLDB version: GNU gdb (GDB) 14.2

Bug Summary and Steps to Reproduce

Bug Summary:
In terminal std::system( "cls" ); or std::system( "pause" );, such command does not work as expected on windows OS.
However, manually execute the command still works, execute the program without the debugger still works, enable externalConsole works, on linux platform also works.

Image

Image

Steps to reproduce:

Minimal reproduce code:

#include "iostream"
#include "cstdlib"
int main(){
    std::cout << "This line should be cleared." << std::endl;    
    std::system( "cls" );
    std::cout << "This line will be the one and only line left." << std::endl;
    return 0;
}

launch config:

        {
            "name": "C/C++: g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\Build_Tool_Lib\\x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        },

Steps to reproduce:

Minimal reproduce code:

#include "iostream"
#include "cstdlib"
int main(){
    std::cout << "This line should be cleared." << std::endl;    
    // std::cout.flush();
    std::system( "cls" );
    std::cout << "This line will be the one and only line left." << std::endl;
    // std::cout.flush();
    return 0;
}

Debugger Configurations

{
            "name": "C/C++: g++.exe build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\Build_Tool_Lib\\x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "logging": { "engineLogging": true, "trace": true, "traceResponse": true },
            "preLaunchTask": "C/C++: g++.exe build active file"
        },

Debugger Logs

Unable to find /usr/bin/g++. [ArchLinux] C/C++: g++ build active file task is ignored.
Unable to find /usr/bin/g++. [ArchLinux] [Release] C/C++: g++ build active file task is ignored.
Unable to find /usr/bin/g++. [ArchLinux] C/C++: gcc build active file task is ignored.
Unable to find /usr/bin/g++. [ArchLinux] C/C++: g++ build active file task is ignored.
Unable to find /usr/bin/g++. [ArchLinux] [Release] C/C++: g++ build active file task is ignored.
Unable to find /usr/bin/g++. [ArchLinux] C/C++: gcc build active file task is ignored.
Launch configuration:
{
  "name": "C/C++: g++.exe build and debug active file",
  "type": "cppdbg",
  "request": "launch",
  "program": "D:\\back_up\\ProgrammingEvents\\AdventOfCode\\2024\\Day20\\test.exe",
  "args": [],
  "stopAtEntry": false,
  "cwd": "D:\\back_up\\ProgrammingEvents\\AdventOfCode\\2024\\Day20",
  "environment": [],
  "externalConsole": true,
  "MIMode": "gdb",
  "miDebuggerPath": "D:\\Build_Tool_Lib\\x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0\\mingw64\\bin\\gdb.exe",
  "setupCommands": [
    {
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
    },
    {
      "description": "Set Disassembly Flavor to Intel",
      "text": "-gdb-set disassembly-flavor intel",
      "ignoreFailures": true
    }
  ],
  "logging": {
    "engineLogging": true,
    "trace": true,
    "traceResponse": true
  },
  "preLaunchTask": "C/C++: g++.exe build active file",
  "__configurationTarget": 6,
  "configSource": "workspaceFolder",
  "debugType": "debug"
}
Launch configuration:
{
  "name": "C/C++: g++.exe build and debug active file",
  "type": "cppdbg",
  "request": "launch",
  "program": "D:\\back_up\\ProgrammingEvents\\AdventOfCode\\2024\\Day20\\test.exe",
  "args": [],
  "stopAtEntry": false,
  "cwd": "D:\\back_up\\ProgrammingEvents\\AdventOfCode\\2024\\Day20",
  "environment": [],
  "externalConsole": false,
  "MIMode": "gdb",
  "miDebuggerPath": "D:\\Build_Tool_Lib\\x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0\\mingw64\\bin\\gdb.exe",
  "setupCommands": [
    {
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
    },
    {
      "description": "Set Disassembly Flavor to Intel",
      "text": "-gdb-set disassembly-flavor intel",
      "ignoreFailures": true
    }
  ],
  "logging": {
    "engineLogging": true,
    "trace": true,
    "traceResponse": true
  },
  "preLaunchTask": "C/C++: g++.exe build active file",
  "__configurationTarget": 6,
  "configSource": "workspaceFolder",
  "debugType": "debug"
}
Launch configuration:
{
  "name": "C/C++: g++.exe build and debug active file",
  "type": "cppdbg",
  "request": "launch",
  "program": "D:\\back_up\\ProgrammingEvents\\AdventOfCode\\2024\\Day20\\test.exe",
  "args": [],
  "stopAtEntry": false,
  "cwd": "D:\\back_up\\ProgrammingEvents\\AdventOfCode\\2024\\Day20",
  "environment": [],
  "externalConsole": false,
  "MIMode": "gdb",
  "miDebuggerPath": "D:\\Build_Tool_Lib\\x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0\\mingw64\\bin\\gdb.exe",
  "setupCommands": [
    {
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
    },
    {
      "description": "Set Disassembly Flavor to Intel",
      "text": "-gdb-set disassembly-flavor intel",
      "ignoreFailures": true
    }
  ],
  "logging": {
    "engineLogging": true,
    "trace": true,
    "traceResponse": true
  },
  "preLaunchTask": "C/C++: g++.exe build active file",
  "__configurationTarget": 6,
  "configSource": "workspaceFolder",
  "debugType": "debug"
}

Other Extensions

No response

Additional Information

No response

@sean-mcmanus sean-mcmanus added debugger help wanted Can be fixed in the public (open source) repo. tasks/build/debug An issue relating to tasks.json (e.g. build issues) bug labels Jan 7, 2025
@RabbitSeries
Copy link
Author

This alternative output will work.

#include "iostream"
#include "cstdlib"
int main(){
    std::cout << "This line should be cleared." << std::endl;    
    //std::system( "cls" );
    std::cout << "\033[2J\033[1;1H";
    std::cout << "This line will be the one and only line left." << std::endl;
    return 0;
}

And the folloing is supplement screenshot for the behaviour comparison of system("pause") after launch from debugger and manually execution. Some output characters may even cause the program to stuck for a while (don't know which yet).
Image

Copy link

github-actions bot commented Jan 7, 2025

Thank you for reporting this issue. We’ll let you know if we need more information to investigate it. Additionally, if you're working with GDB/LLDB, please note that the code is open source at https://github.com/microsoft/MIEngine/wiki/Contributing-Code . Your contributions are always welcome and appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug debugger help wanted Can be fixed in the public (open source) repo. tasks/build/debug An issue relating to tasks.json (e.g. build issues)
Projects
None yet
Development

No branches or pull requests

2 participants