VSCode standard output issue

I’ve just started to switch from Eclipse to Visual Studio Code when I ran into quite a prominent issue (e.g. see complaints here, here or here). Its regarding C++ standard output when debugging with GDB. Apparently GDBs output stream is not redirected properly, at least not to VSCodes internal terminal.

While the following launch.json configuration works

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(gdb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/main",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

it also opens an external terminal which is rather unpleasant if you’re working on a single screen. For some reason changing the “externalConsole” parameter to false did nothing for me. It still kept opening an external terminal.

The external console kept popping up with GDB

The first thing I tried was switching to the Native Debug plugin which was perfectly able to use the internal terminal for GDB output. What I did not like about it was that pretty-printing is only enabled for the variable, but not for the watch window (a design choice). I’d still recommend it though because it brings a lot more features to the table than Microsofts own integration does (e.g. specifying the GDB executable).

What I’d recommend first though is simply switching to LLDB by changing the “MIMode” option to “lldb”.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(lldb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/main",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

For some reason LLDB was perfectly able to redirect its output to the internal terminal. Happy debugging… 😉

LLDB was able to redirect its output correctly

Update 07/11/2018: As of version 1.28.2 standard out started working for me with GDB as well.