Vscode-cpptools: Debug for C++ No Output on Visual Studio

Created on 21 Feb 2017  Â·  34Comments  Â·  Source: microsoft/vscode-cpptools

Hi,

I just downloaded the newest version of Visual Studio. I added the C++ app to the program languages. However, when I select the environment for C++ when I try to Debug, theres no output. I am trying to run just a simple Hello World program.

Can anyone tell me whats going on?

debugger more info needed

Most helpful comment

@Shanz88 If you enable "externalConsole": true in your launch.json do you see a window popping up with your output?

All 34 comments

Do you mean Visual Studio Code? Do you mean the C++ extension? Are you building your app? How exactly are you invoking the debugger? Have you looked at some of the docs/blogs, such as https://blogs.msdn.microsoft.com/vcblog/2016/03/31/cc-extension-for-visual-studio-code/#debugging ?

Hi Sean,

Yeah I'm using Visual Studio Code with the C++ extension on a Windows PC.

I just read from the article you sent me:
"The debugging experience currently only works out-of-the-box for Linux –
Ubuntu 14.04 (x64). We are working on OS X support as well, the current
experience requires manual installation steps and has some limitations
https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools.
Debugging on windows with VSCode for C/C++ code is currently not supported."

Does that mean that I will not be able to use VSCode for windows using C++?

I've only made a simple "Hello World" program as a test to see the output.
So when I'm trying to use the debug function, nothing happens.

Thanks!
-Shannon

On Tue, Feb 21, 2017 at 9:42 PM, Sean McManus notifications@github.com
wrote:

Do you mean Visual Studio Code? Do you mean the C++ extension? Are you
building your app? How exactly are you invoking the debugger? Have you
looked at some of the docs/blogs, such as https://blogs.msdn.microsoft.
com/vcblog/2016/03/31/cc-extension-for-visual-studio-code/#debugging .

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode-cpptools/issues/513#issuecomment-281347313,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AYuZESNWxlgo0-ESD-PDZPhRB2m4PBq-ks5reumugaJpZM4MHK6f
.

Oh, that article is a little out-of-date. You can debug on Windows now. You just select C++ (Windows) when selecting the debug configuration. You can either launch the app or attach to an already running app. Make sure you build with debug info. Can you show some screenshots or something? I don't understand what step you're stuck at. You should see output in the Debug Console.

@Shanz88 If you enable "externalConsole": true in your launch.json do you see a window popping up with your output?

@Shanz88 also, are you using g++/gdb or Visual C++ with our extension on Windows? Can you post your launch.json ?

Hi Pierson,

I'm using Visual studio code, with the C++ (GDB//LLDB) extension.

My json settings are below:
// Associate schemas to JSON files in the current project
"json.schemas": [],
// Enable/disable default JSON formatter (requires restart)
"json.format.enable": true,
// Traces the communication between VS Code and the JSON language server.
"json.trace.server": "off",

Is this what you want to see? I'm not sure how to enable "externalConsole":
true in my user settings.

Thanks!

-Shannon

On Sat, Feb 25, 2017 at 6:48 AM, Pierson Lee notifications@github.com
wrote:

@Shanz88 https://github.com/Shanz88 also, are you using g++/gdb or Visual
C++ with our extension on Windows? Can you post your launch.json ?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode-cpptools/issues/513#issuecomment-282426869,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AYuZEZtPiwSqLUGhq7sZ1hxCe57KyNB8ks5rf148gaJpZM4MHK6f
.

@Shanz88 please try and locate your launch.json file. If you switch to the Debug view, when you hit the gear, it should open the launch.json file which will launch the debugger against your application. You will need to create a task.json to compile your code OR manually compile it from the command line.

Not sure if it's the same issue as original post describes, but I don't see any output being produced in the OUTPUT window during build or debug on OS X 10.12.3 with VS Code 1.10.1 and C++ extension 0.10.4.
tasks.json contains
"showOutput": "always",
"echoCommand": true
But only the command is being echoed, no output from the gcc compiler/linker is produced.
launch.json in the "C++ Launch" entry contains
"externalConsole": true,
"osx": {
"MIMode": "lldb"
},
During debug session no printf output is produced in the OUTPUT window.
So, yes, on Mac there is no output.

@seva0stapenko This is not the same issue Task.json build commands and their outputs are not owned by our extension, that is a feature of core VSCode. Please file an issue with them at https://github.com/Microsoft/VSCode/issues. During debug session, when you say there is no output, are you seeing it in the Terminal window that opens when debugging starts? that is where the output should be.

@pieandcakes Thanks for the pointer in the right direction. I have to admit that I was looking for an output from the program being debugged in the OUTPUT window. Now I see that the debugger opens in a completely separate terminal window, which conveniently stays hidden behind a dozen or so other windows that I have open at any given time.
Regarding the output from Task.json, thanks for pointing this out too, though it's not immediately obvious where all the boundaries of responsibilities of different teams lay. OK, I'll see if they have a settings for that or if there is already an issue open, if not, then I'll file an issue with them.

@seva0stapenko We have an issue on the backlog to incorporate within VSCodes Debugger Terminal so that experience will change when we get to fixing it but for now, its in the separate console window.

@Shanz88 I haven't heard back from you yet. Can you provide your launch.json configuration please?

Please reopen if this is still an issue.

This is still relevant for me.

My launch.json:

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

No difference if I set externalConsole to true or false.
Gnome Terminal pops up and closes for a millisecond on both settings.

I can successfully run the debugger (variables, watches, ...) with my program called "test" but I see no output in the "Debug Console" or the "Output"-Panel.
Also no output with "Ctrl+F5" (run without debugging) which strangely enough also stops at breakpoints.

If I run it externally everything prints as expected.

Ubuntu 14.04
VSCode 1.18.1
C/C++ extension 0.14.2 (no other extension installed)

EDIT: The problem persists even after a complete reinstall of VSCode and the extension (wiped /.vscode and /.config/Code and "apt-get purge")

@veto-gh Your output should be in Gnome Terminal.

Also no output with "Ctrl+F5" (run without debugging) which strangely enough also stops at breakpoints.

We have not implemented Run without Debugging yet, so Ctrl+F5 will do the same thing as F5.

Thank you for your answer @pieandcakes.

I'm sorry I misunderstood.
You are correct, as long as the debugger has stopped, Gnome Terminal stays open and I can see the output until I continue. I missed this.

Any pointers on how to keep the terminal open though?
I would need to have set a breakpoint only to see output of a simple application without a main loop.

@veto-gh Set a read in the last line using cin or scanf? Otherwise, it seems to be a common complaint that we haven't figured out how to address yet. If you disable externalConsole it MAY show up in the debugger console instead but there's no guarantee.

Thank you.

If you disable externalConsole it MAY show up in the debugger console

Had no luck with this. cin/scanf works though.

Otherwise, it seems to be a common complaint that we haven't figured out how to address yet

I see. Would be great for starters to have that functionality some day. Otherwise great work on the extension!

Just to let you guys know, I had the same issue here and I was really searching for what was wrong but the application did print something to stdout and called exit(0) from some internal function :S causing the external console to exit.
So I would love this feature as well - should this issue be reopened?

@DickvdBrink The issue is with gdb which opens the console on our behalf. We don't have much control over it but you can try and file a feature request against gdb.

Hope you don't understand this wrong, only trying to be helpful:
Codeblocks has an option to "Pause when execution ends" (Project Properties/Build targets).
Maybe you can find something in their source?

Can anyone on Win10 debug their C++ codes with standard inputs/outputs? I cannot. NetBeans can do it.

@gurkanctn It works on Win10. Set externalconsole to true and flush your stdout after writing to it, otherwise you may not get an output.

Hello, thanks for the response. I had already tried this method but it doesn’t work — at least for me.

(I have tried it about a month ago, and the latest update may have solved it? I don’t know)

Gürkan Çetin

Saptarshi Ghosh notifications@github.com şunları yazdı (22 Ağu 2018 16:20):

@gurkanctn It works on Win10. Set externalconsole to true and flush your stdout after writing to it, otherwise you may not get an output.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@seva0stapenko We have an issue on the backlog to incorporate within VSCodes Debugger Terminal so that experience will change when we get to fixing it but for now, its in the separate console window.

@pieandcakes Do you have an issue number for this? I cannot find it.

I'm using #35 to track the item

Having the same problem... changing externalConsole does not help

In my case, I only saw output in "DEBUG CONSOLE", like:

Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
Breakpoint 1, main (argc=1, argv=0x7fffffffddf8) at main.cpp:40
40  {
[Inferior 1 (process 8967) exited normally]
The program '/home/jiy/Desktop/matching/matching' has exited with code 0 (0x00000000).

but the "OUTPUT" is empty. I saw the expected std::cout ouputs in a poped up terminal window for less than 1 second though. Don't know how to redirect them into vscode output window.

Linux Ubuntu 18, VScode 1.28.1

Having the same problem... changing externalConsole does not help

In my case, I only saw output in "DEBUG CONSOLE", like:

Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
Breakpoint 1, main (argc=1, argv=0x7fffffffddf8) at main.cpp:40
40    {
[Inferior 1 (process 8967) exited normally]
The program '/home/jiy/Desktop/matching/matching' has exited with code 0 (0x00000000).

but the "OUTPUT" is empty. I saw the expected std::cout ouputs in a poped up terminal window for less than 1 second though. Don't know how to redirect them into vscode output window.

Linux Ubuntu 18, VScode 1.28.1

I'm experiencing the same problem. I'm compiling with -g tags, configured tasks.json correctly, yet debugger does not hit... I get edxactly the same message as the above user.

@yi-ji @radutomy If you want to see output, it will show up in the Output window if you set externalConsole to false. This was changed in our release 0.20.1.

If you aren't able to set a breakpoint and have the debugger stop, please open a new issue and provide logging.

@pieandcakes set externalConsole to false in the launch.json file is the solution.

I finally found something that worked for me:
Simply add
setbuf(stdout, 0); cout << "blah blah";
before printing any statements to the console.

In Windows 10, VS Code 1.41.1, setting "externalConsole": true in my launch.json does indeed produce an external console...and is helpfully updated after each usage of std::cout. This is significant when I am step debugging existing code which uses std::cout. In general I would though rather use the internal console ("DEBUG CONSOLE") of VS Code. Alas, output to std::cout seems only to be displayed within the internal console when it is flushed (unlike the external console).

If you enable "externalConsole": true in your launch.json do you see a window popping up with your output?

not at all. it just launch my macOS default terminal window but nothing happen. It's 100% same as I open terminal by myself.

image
image

(white dots on filename are relevant because I deleted some comments for clearness)

Was this page helpful?
0 / 5 - 0 ratings