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

Debug for C++ No Output on Visual Studio #513

Closed
Shanz88 opened this issue Feb 21, 2017 · 32 comments
Closed

Debug for C++ No Output on Visual Studio #513

Shanz88 opened this issue Feb 21, 2017 · 32 comments
Assignees

Comments

@Shanz88
Copy link

@Shanz88 Shanz88 commented Feb 21, 2017

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?

@sean-mcmanus

This comment has been minimized.

Copy link
Collaborator

@sean-mcmanus sean-mcmanus commented Feb 21, 2017

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 ?

@Shanz88

This comment has been minimized.

Copy link
Author

@Shanz88 Shanz88 commented Feb 22, 2017

@sean-mcmanus

This comment has been minimized.

Copy link
Collaborator

@sean-mcmanus sean-mcmanus commented Feb 22, 2017

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.

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Feb 22, 2017

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

@pieandcakes pieandcakes self-assigned this Feb 22, 2017
@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Feb 24, 2017

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

@Shanz88

This comment has been minimized.

Copy link
Author

@Shanz88 Shanz88 commented Feb 27, 2017

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Mar 2, 2017

@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.

@seva0stapenko

This comment has been minimized.

Copy link

@seva0stapenko seva0stapenko commented Mar 22, 2017

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.

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Mar 28, 2017

@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.

@seva0stapenko

This comment has been minimized.

Copy link

@seva0stapenko seva0stapenko commented Mar 28, 2017

@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.

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Mar 28, 2017

@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

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Apr 29, 2017

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

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Jul 17, 2017

Please reopen if this is still an issue.

@veto-gh

This comment has been minimized.

Copy link

@veto-gh veto-gh commented Nov 21, 2017

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")

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Nov 21, 2017

@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.

@veto-gh

This comment has been minimized.

Copy link

@veto-gh veto-gh commented Nov 21, 2017

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.

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Nov 21, 2017

@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.

@veto-gh

This comment has been minimized.

Copy link

@veto-gh veto-gh commented Nov 21, 2017

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!

@DickvdBrink

This comment has been minimized.

Copy link

@DickvdBrink DickvdBrink commented Dec 5, 2017

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?

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Dec 8, 2017

@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.

@veto-gh

This comment has been minimized.

Copy link

@veto-gh veto-gh commented Dec 20, 2017

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?

@gurkanctn

This comment has been minimized.

Copy link

@gurkanctn gurkanctn commented May 29, 2018

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

@sghoshjr

This comment has been minimized.

Copy link

@sghoshjr sghoshjr commented Aug 22, 2018

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

@gurkanctn

This comment has been minimized.

Copy link

@gurkanctn gurkanctn commented Aug 26, 2018

@AnatoliShein

This comment has been minimized.

Copy link

@AnatoliShein AnatoliShein commented Oct 9, 2018

@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.

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Oct 9, 2018

I'm using #35 to track the item

@yi-ji

This comment has been minimized.

Copy link

@yi-ji yi-ji commented Oct 14, 2018

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

@radutomy

This comment has been minimized.

Copy link

@radutomy radutomy commented Jan 16, 2019

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.

@pieandcakes

This comment has been minimized.

Copy link
Collaborator

@pieandcakes pieandcakes commented Jan 16, 2019

@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.

@wohenniubi

This comment has been minimized.

Copy link

@wohenniubi wohenniubi commented Jun 27, 2019

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

@asreerama

This comment has been minimized.

Copy link

@asreerama asreerama commented Aug 20, 2019

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

@pkeir

This comment has been minimized.

Copy link

@pkeir pkeir commented Jan 17, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.