microsoft / microsoft/vscode-cpptools

[WSL] Unable to input data during debugging

Open
#2,013 11 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

My Windows 10 version: 17134.48
VS Code: 1.23.1
C/C++ extension version: 0.17.1

I use VS Code (on windows) with WSL.
I found something wrong with debug.
my launch.json


            "name": "(gdb) WSL Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "/mnt/c/Users/xx/outAsciiCode",
            "args": [],
            "stopAtEntry": false,
            "cwd": "/mnt/c/Users/xx",
            "environment": [],
            "externalConsole": true,
            "logging": { "engineLogging": true},
            "pipeTransport": {
                "debuggerPath": "/usr/bin/gdb",
                "pipeProgram": "${env:windir}\\system32\\bash.exe",
                "pipeArgs": ["-c"],
                "pipeCwd": "/"
            },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "sourceFileMap": {
                "/mnt/c/Users/xx": "C:\\Users\\xx"
            }

and my main program:

int main(void)
{
    int a1, a2;
    scanf("%d %d", &a1, &a2);

    printf("%d\n%d\n", a1, a2);
    return 0;
}

and set breakpoints in scanf function and printf function.

First, when I use VS Code to debug this program
I CANNOT input two numbers to debug!

1: (2003) <-1020-stack-list-frames 0 1000
1: (2003) ->1020^done,stack=[frame={level="0",addr="0x0000000000400675",func="main",file="outAsciiCode.cpp",fullname="/mnt/c/Users/xx/outAsciiCode.cpp",line="23"}]
1: (2003) ->(gdb)
1: (2003) 1020: elapsed time 0
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
Breakpoint 2, main () at outAsciiCode.cpp:23
23	    scanf("%d %d", &a1, &a2);
1: (2070) <-1021-stack-list-arguments 0 0 0
1: (2072) ->1021^done,stack-args=[frame={level="0",args=[]}]
1: (2073) ->(gdb)
1: (2073) 1021: elapsed time 2
1: (2123) <-1022-stack-list-variables 0
1: (2125) ->1022^done,variables=[{name="a1"},{name="a2"}]
1: (2125) ->(gdb)
1: (2127) 1022: elapsed time 3
1: (2139) <-1023-var-create - * "a1"
1: (2155) ->1023^done,name="var1",numchild="0",value="-71472",type="int",thread-id="1",has_more="0"
1: (2155) ->(gdb)
1: (2155) 1023: elapsed time 15
1: (2156) <-1024-var-create - * "a2"
1: (2159) ->1024^done,name="var2",numchild="0",value="32767",type="int",thread-id="1",has_more="0"
1: (2159) ->(gdb)
1: (2159) 1024: elapsed time 2

1: (131012) <--exec-continue
1: (131013) ->^running
1: (131014) ->*running,thread-id="all"
1: (131015) ->(gdb)

I try to input two numbers, but show

78 5
Unable to perform this action because the process is running.

and running without end.

Finally, I use terminal to debug the same program, and it works

Breakpoint 1, main () at outAsciiCode.cpp:21

(gdb) b main
Breakpoint 1 at 0x400661: file outAsciiCode.cpp, line 21.
(gdb) r
Starting program: /mnt/c/Users/xx/outAsciiCode
21      {
(gdb) n
23          scanf("%d %d", &a1, &a2);
(gdb) n
45 78
31          printf("%d\n%d\n", a1, a2);
(gdb) n
45
78
33      }
(gdb)

So, can you fix it? Thanks

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 by reproducing the issue with the shown launch.json, especially pipeTransport, externalConsole, and the C++ program's scanf call under WSL. Compare input behavior with the terminal GDB session; done means numbers can be entered while debugging and execution proceeds to printf.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.