Vscode-cpptools: External terminal when debugging in WSL

Created on 2 Apr 2018  路  15Comments  路  Source: microsoft/vscode-cpptools

Hello,
Firstly I would like to say thank you for this awesome text editor and the C/C++ extension :)

I tried debugging C/C++ program in Windows Subsystem for Linux. The debugging session works fine but the only problem is that VS Code won't open an external terminal so I could not get stdout and stdin from a terminal during the debugging session.

So I have two questions:

  1. How can I open an external terminal for WSL debugging?
  2. Even there is not external terminal, how to get output from stdout and input to stdin during the debugging session?

Here is my launch.json, as you can see I set "externalConsole": true but an external terminal won't appear:


        {
            "name": "maze_solver",
            "type": "cppdbg",
            "request": "launch",
            "program": "maze_solver",
            "args": [],
            "stopAtEntry": false,
            "cwd": "./",
            "environment": [],
            "externalConsole": true,
            "pipeTransport": {
                "debuggerPath": "/usr/bin/gdb",
                "pipeProgram": "C:\\Windows\\sysnative\\bash.exe",
                "pipeArgs": ["-c"],
                "pipeCwd": "${workspaceFolder}/simulation/maze_solver"
            },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "sourceFileMap": {
                "/mnt/d": "d:\\"
            },
            "logging": { "engineLogging": true }
        }

Thank you very much!

Feature Request debugger

All 15 comments

How can I open an external terminal for WSL debugging?

Because it is a pipe communication, there isn't a way to do it currently.

Even there is not external terminal, how to get output from stdout and input to stdin during the debugging session?

You can try and use an input file and an output file, but I don't think we have a solution for this yet.

Thank you for the answer. So do you think there is no way to debug ELF-compiled program with an external terminal currently, I mean on Windows?

Is there a way to add this?

I'm trying to debug a program that uses console input, scrolling, cursor movement.

it's pretty much useless for this as it is.

same problem here

As a workaround I was able to have the tty configuration in GDB point to the result of tty in a separate bash terminal, have the terminal sleep infinity, and then start debugging. To make it a little quicker I set up a script to find the tty for a new terminal, create a symlink to it. In launch.json I set GDB's tty configuration to that symlink and made the script my prelaunch task so as to not have to potentially change launch.json every time. But it feels like a hack, so it'd be nice to have a built-in way to do this.

Alternately, start the process separately and attach the debugger to it, but I'm not sure if there's a way to have it break at the beginning of execution that way.

@youngspe I'm interested in trying out your workaround, do u mind providing some more detailed information on how to set it up?

@yalshekerchi
It's a bit of a hack, I haven't touched it in a while, but here's my setup: https://github.com/youngspe/vscode-wsl-debug

Same issue here. Seems to be kind of a basic feature. Hope to see it fixed in the near future.

Same issue here.

Have it be solved?

Same issue here

Same here. When "externalConsole": true the debugger gets stuck.

vscode_debugger_stuck

EDIT:
For those who want to activate the external console to be able to stream a file to stdin like < in.txt and debug it, I've managed to do so including a piece of code.

freopen("in.txt", "r", stdin);
// code who read from stdin piped from in.txt
fclose(stdin);

Same issue here. Even when I tried to make g++ output an .exe file in tasks.json, the debugger still get stuck.

I would like to see this added as well, running into this issue

I'm having same issue. I hope someone can pay attention to this some day. It's been two years and no answers so far

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arl picture arl  路  3Comments

chrisckc picture chrisckc  路  3Comments

ecbrodie picture ecbrodie  路  3Comments

montery8 picture montery8  路  3Comments

vicatcu picture vicatcu  路  3Comments